-
Notifications
You must be signed in to change notification settings - Fork 6
Use usertoken for slack search when bot search token expires #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
IzieStratt
wants to merge
7
commits into
techwithanirudh:main
Choose a base branch
from
IzieStratt:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f6bc4ea
changed desc for search_slack tool since it is not needed anymore and…
IzieStratt d6460f5
gorkie do searchie
IzieStratt c49c2eb
rawr
IzieStratt 2796119
codex added `*` filters so it wont get added to the link
IzieStratt a196ab0
fix: scope the Slack search user-token fallback to public channels
techwithanirudh 8cf2273
fix: keep the search-token docs off the cspell dictionary
techwithanirudh 0ce9445
Merge branch 'main' into main
IzieStratt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { describe, expect, test } from 'bun:test'; | ||
| import { | ||
| moveAsterisksAfterMarkdownLinks, | ||
| moveAsterisksAfterMarkdownLinksInStream, | ||
| } from './markdown'; | ||
|
|
||
| describe('moveAsterisksAfterMarkdownLinks', () => { | ||
| test('moves every asterisk after the closing link delimiter', () => { | ||
| expect( | ||
| moveAsterisksAfterMarkdownLinks( | ||
| 'See [one](https://example.com/*path*) and [two](https://two.test*).' | ||
| ) | ||
| ).toBe( | ||
| 'See [one](https://example.com/path)** and [two](https://two.test)*.' | ||
| ); | ||
| }); | ||
|
|
||
| test('supports parentheses and escaped parentheses in link destinations', () => { | ||
| expect( | ||
| moveAsterisksAfterMarkdownLinks( | ||
| String.raw`[nested](https://example.com/a(*b)) [escaped](https://example.com/a\)*b)` | ||
| ) | ||
| ).toBe( | ||
| String.raw`[nested](https://example.com/a(b))* [escaped](https://example.com/a\)b)*` | ||
| ); | ||
| }); | ||
|
|
||
| test('preserves incomplete links', () => { | ||
| expect( | ||
| moveAsterisksAfterMarkdownLinks('[label](https://example.com/*') | ||
| ).toBe('[label](https://example.com/*'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('moveAsterisksAfterMarkdownLinksInStream', () => { | ||
| test('normalizes links split across stream chunks', async () => { | ||
| async function* chunks() { | ||
| yield 'See [la'; | ||
| await Promise.resolve(); | ||
| yield 'bel](https://example'; | ||
| yield { type: 'markdown_text' as const, text: '.com*) next' }; | ||
| } | ||
|
|
||
| const normalized: Array<string | { type: 'markdown_text'; text: string }> = | ||
| []; | ||
| for await (const chunk of moveAsterisksAfterMarkdownLinksInStream({ | ||
| stream: chunks(), | ||
| })) { | ||
| if (typeof chunk === 'string' || chunk.type === 'markdown_text') { | ||
| normalized.push(chunk); | ||
| } | ||
| } | ||
|
|
||
| expect(normalized).toEqual([ | ||
| 'See [la', | ||
| 'bel', | ||
| { type: 'markdown_text', text: '](https://example.com)* next' }, | ||
| ]); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| import type { AdapterPostableMessage, StreamChunk } from 'chat'; | ||
|
|
||
| class MarkdownLinkNormalizer { | ||
| private bufferedLink = ''; | ||
| private parenthesisDepth = 0; | ||
| private readonly state = new Set<'pendingCloseBracket'>(); | ||
|
|
||
| push(markdown: string): string { | ||
| let normalized = ''; | ||
|
|
||
| for (const character of markdown) { | ||
| if (this.parenthesisDepth === 0) { | ||
| if (this.state.has('pendingCloseBracket')) { | ||
| if (character === '(') { | ||
| this.bufferedLink = ']('; | ||
| this.parenthesisDepth = 1; | ||
| this.state.delete('pendingCloseBracket'); | ||
| continue; | ||
| } | ||
| normalized += ']'; | ||
| this.state.delete('pendingCloseBracket'); | ||
| } | ||
| if (character === ']') { | ||
| this.state.add('pendingCloseBracket'); | ||
| continue; | ||
| } | ||
| normalized += character; | ||
| continue; | ||
| } | ||
|
|
||
| this.bufferedLink += character; | ||
| let precedingBackslashes = 0; | ||
| for ( | ||
| let index = this.bufferedLink.length - 2; | ||
| this.bufferedLink[index] === '\\'; | ||
| index -= 1 | ||
| ) { | ||
| precedingBackslashes += 1; | ||
| } | ||
| if (precedingBackslashes % 2 === 1) { | ||
| continue; | ||
| } | ||
| if (character === '(') { | ||
| this.parenthesisDepth += 1; | ||
| continue; | ||
| } | ||
| if (character !== ')') { | ||
| continue; | ||
| } | ||
|
|
||
| this.parenthesisDepth -= 1; | ||
| if (this.parenthesisDepth > 0) { | ||
| continue; | ||
| } | ||
|
|
||
| const asterisks = this.bufferedLink.match(/\*/g)?.join('') ?? ''; | ||
| normalized += this.bufferedLink.replaceAll('*', '') + asterisks; | ||
| this.bufferedLink = ''; | ||
| } | ||
|
|
||
| return normalized; | ||
| } | ||
|
|
||
| finish(): string { | ||
| const remainder = `${this.state.has('pendingCloseBracket') ? ']' : ''}${this.bufferedLink}`; | ||
| this.bufferedLink = ''; | ||
| this.parenthesisDepth = 0; | ||
| this.state.clear(); | ||
| return remainder; | ||
| } | ||
| } | ||
|
|
||
| export function moveAsterisksAfterMarkdownLinks(markdown: string): string { | ||
| const normalizer = new MarkdownLinkNormalizer(); | ||
| return normalizer.push(markdown) + normalizer.finish(); | ||
| } | ||
|
|
||
| export function normalizeMarkdownMessage( | ||
| message: AdapterPostableMessage | ||
| ): AdapterPostableMessage { | ||
| if (typeof message === 'string') { | ||
| return moveAsterisksAfterMarkdownLinks(message); | ||
| } | ||
| if ('markdown' in message) { | ||
| return { | ||
| ...message, | ||
| markdown: moveAsterisksAfterMarkdownLinks(message.markdown), | ||
| }; | ||
| } | ||
| return message; | ||
| } | ||
|
|
||
| export async function* moveAsterisksAfterMarkdownLinksInStream({ | ||
| stream, | ||
| }: { | ||
| stream: AsyncIterable<string | StreamChunk>; | ||
| }): AsyncGenerator<string | StreamChunk> { | ||
| const normalizer = new MarkdownLinkNormalizer(); | ||
|
|
||
| for await (const chunk of stream) { | ||
| if (typeof chunk === 'string') { | ||
| const normalized = normalizer.push(chunk); | ||
| if (normalized) { | ||
| yield normalized; | ||
| } | ||
| continue; | ||
| } | ||
| if (chunk.type === 'markdown_text') { | ||
| const text = normalizer.push(chunk.text); | ||
| if (text) { | ||
| yield { ...chunk, text }; | ||
| } | ||
| continue; | ||
| } | ||
| yield chunk; | ||
| } | ||
|
|
||
| const remainder = normalizer.finish(); | ||
| if (remainder) { | ||
| yield remainder; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Require a matching opening bracket before normalizing a destination.
Line 23 marks every
]as a possible link close. Input such asliteral ](path*)becomesliteral ](path)*, even though it is not a Markdown link. This corrupts plain-text or code-like Slack messages.Track an unescaped opening
[before entering destination mode. Add regressions for unmatched and escaped closing brackets.🤖 Prompt for AI Agents