Your team of AI agents, on your Mac, Windows or Linux. Agents that talk in channels, write code, review each other and use your tools, on the Claude Code, Codex, OpenCode or Pi you already have. Anything that touches the real world waits for your yes.
TypeScript agent-teamagentic-aiai-agentsai-assistantclaude-codecodexcursorelectrongrokgrok-bot-alternativelinuxlocal-firstmacosmcpmulti-agentopenclaw-alternativeopencodewindows
Don't trigger agents for handles quoted inside code (#16)
Gian Moraesf48fb5c6877f
diff --git a/src/core/context.ts b/src/core/context.tsindex 73863cb..43b343a 100644--- a/src/core/context.ts+++ b/src/core/context.ts@@ -269,9 +269,13 @@ export function transcriptBlocks(opts: TranscriptOpts): { blocks: string[]; bloc}// @handles in the text that belong to the given agents, in order of appearance.+// Handles inside code (fenced or inline) are quoted content, not a call — e.g. a prompt shown in a fenced block.+// A fence closes on the same run of backticks or tildes it opened with, so a ```` block can show a ``` one.+const CODE_SPANS = /(`{3,}|~{3,})[\s\S]*?(?:\1|$)|`[^`\n]*`/g+export function mentioned(text: string, agents: Agent[]): Agent[] {const found: Agent[] = []- for (const m of text.matchAll(/(^|[^\w@])@([a-z0-9][a-z0-9_-]{1,31})\b/gi)) {+ for (const m of text.replace(CODE_SPANS, ' ').matchAll(/(^|[^\w@])@([a-z0-9][a-z0-9_-]{1,31})\b/gi)) {const a = agents.find((x) => x.handle.toLowerCase() === m[2]!.toLowerCase())if (a && !found.includes(a)) found.push(a)}diff --git a/test/context.test.ts b/test/context.test.tsindex c9c1621..44e00c3 100644--- a/test/context.test.ts+++ b/test/context.test.ts@@ -33,6 +33,21 @@ describe('mentioned', () => {it('does not match emails', () => {expect(mentioned('manda pra [email protected]', [lia])).toEqual([])})++ it('ignores handles inside fenced code blocks and inline code', () => {+ const text = 'veja:\n```\nchame a @lia pra revisar\n```\ne inline `chame a @lia aqui` fim'+ expect(mentioned(text, [lia])).toEqual([])+ })++ it('still finds handles around code, and an unterminated fence stops the scan', () => {+ expect(mentioned('```\ncódigo\n```\nfala com @lia', [lia]).map((a) => a.id)).toEqual(['a1'])+ expect(mentioned('bloco:\n```\n@lia sem fechar', [lia])).toEqual([])+ })++ it('ignores a fenced block shown inside a longer fence', () => {+ expect(mentioned('````\n```\n@lia revisa\n```\n````\nfala com @lia', [lia]).map((a) => a.id)).toEqual(['a1'])+ expect(mentioned('````md\n```\n@lia revisa\n```\n````', [lia])).toEqual([])+ })})describe('systemPrompt', () => {diff --git a/test/runner.test.ts b/test/runner.test.tsindex 35a5a6c..9f16b11 100644--- a/test/runner.test.ts+++ b/test/runner.test.ts@@ -159,6 +159,15 @@ describe('Runner', () => {expect(db.messages().at(-1)?.text).toContain('Parei a conversa entre agentes')})+ it('does not hand the turn for a handle quoted inside a code block', async () => {+ // The reply shows a prompt in a fenced block that mentions the other agent (the case that made an agent answer twice).+ const quoted = fakeEngine('claude', { delayMs: 1, reply: (t) => (t.system.startsWith('Você é lia') ? 'O prompt é este:\n```\n@theo, pode ajudar aqui?\n```' : 'ok') })+ const r = runner(quoted)+ await r.send('c1', '@lia começa')+ await r.idle()+ expect(agentMessages().map((m) => (m.author as { id: string }).id)).toEqual(['a1'])+ })+it('retries a failed reply in place', async () => {let fail = trueconst flaky: Engine = {