Skip to content

The agent that grows with you

fix(desktop): quoted or pasted stop words no longer hold a group-chat member (#117040)

kokhloc5b27c4c8c20
diff --git a/apps/desktop/src/plugins/hermes-bots/group-rounds.test.ts b/apps/desktop/src/plugins/hermes-bots/group-rounds.test.ts
index bf40048056f..790fae95adc 100644
--- a/apps/desktop/src/plugins/hermes-bots/group-rounds.test.ts
+++ b/apps/desktop/src/plugins/hermes-bots/group-rounds.test.ts
@@ -1090,6 +1090,44 @@ describe('member holds (#93129)', () => {
expect([...rounds.classifyGroupHoldDirective('@impl please halt', ['conn::impl'], false).hold]).toEqual(['conn::impl'])
})
+ // #117040: proximity is measured on what the user directs at the room, not
+ // on content they quote or paste. A stop word inside a fenced block, inline
+ // code span, straight-quoted span or blockquote line is content — reporting
+ // or debugging a hold must not re-hold the addressed member.
+ it('holds nobody when the stop word sits inside quoted or pasted content', async () => {
+ const { rounds } = await loadRoom()
+
+ for (const text of [
+ '```text\nstop @impl\n```',
+ 'The log printed `@impl pause` here',
+ 'Why did "pause @impl" hold the bot?',
+ // A cut-short paste leaves the fence unclosed; the rest is still content.
+ 'look what the docs say:\n```js\nstop @impl\n',
+ '> stop @impl'
+ ]) {
+ const action = rounds.classifyGroupHoldDirective(text, ['impl'], false)
+
+ expect([...action.hold]).toEqual([])
+ // The mention itself still reaches the member: quoting AT the bot is a
+ // direct address, which releases a held member like any other mention.
+ expect([...action.release]).toEqual(['impl'])
+ }
+ })
+
+ it('still holds on the plain directive forms once masking is active', async () => {
+ const { rounds } = await loadRoom()
+
+ for (const text of ['stop @impl', '@impl stop', '@impl please halt', '@all stop']) {
+ const action = rounds.classifyGroupHoldDirective(text, ['impl'], text.startsWith('@all'))
+
+ expect([...action.hold]).toEqual(['impl'])
+ }
+
+ // A masked span collapses to one word, so a genuine directive with pasted
+ // content between the stop word and the mention keeps its proximity.
+ expect([...rounds.classifyGroupHoldDirective('stop `service` @impl', ['impl'], false).hold]).toEqual(['impl'])
+ })
+
// A genuine stop whose stop word sits 3+ tokens from the mention may miss the
// hold, but it must never RELEASE (re-dispatch) the member it tells to stop.
it('never releases the addressed member on a distant genuine stop', async () => {
diff --git a/apps/desktop/src/plugins/hermes-bots/group-rounds.ts b/apps/desktop/src/plugins/hermes-bots/group-rounds.ts
index c2b7db9a80b..50f4a0d9271 100644
--- a/apps/desktop/src/plugins/hermes-bots/group-rounds.ts
+++ b/apps/desktop/src/plugins/hermes-bots/group-rounds.ts
@@ -264,10 +264,57 @@ export function classifyGroupHoldDirective(
}
}
+/** #117040: what a fenced block, inline code span, straight-quoted span or
+ * blockquote line says is content the user quotes or pastes, not a room
+ * directive — its stop words must not hold a member. Mask each span down to
+ * the @tokens it contains (mentions resolve from the raw text and must keep
+ * their place in the proximity window, so an address like "…"@impl"…" still
+ * releases a held member) or to one neutral filler word when it has none. */
+function maskQuotedAndCodeSpans(value: string): string {
+ const mentionsOnly = (span: string): string => (span.match(/@[\p{L}\p{N}._-]+/gu) || []).join(' ') || 'quoted'
+ const kept: string[] = []
+ let fence = ''
+
+ for (const line of value.split('\n')) {
+ if (fence) {
+ // Closing fence rows carry no content; an unterminated fence (a
+ // cut-short paste) simply swallows the rest of the message.
+ const closing = line.trim().startsWith(fence)
+
+ kept.push(closing ? '' : mentionsOnly(line))
+
+ if (closing) {
+ fence = ''
+ }
+
+ continue
+ }
+
+ const opened = line.match(/^\s*(`{3,}|~{3,})/)
+
+ if (opened) {
+ fence = opened[1]
+
+ continue
+ }
+
+ if (/^\s*>/.test(line)) {
+ kept.push(mentionsOnly(line))
+
+ continue
+ }
+
+ kept.push(line.replace(/`[^`\n]*`/g, mentionsOnly).replace(/"[^"\n]*"/g, mentionsOnly))
+ }
+
+ return kept.join('\n')
+}
+
/** #103893: where the stop/halt/pause tokens sit relative to the @tokens —
* `adjacent` when one is within two words of ANY mention, `distant` when
* the message carries a stop word but none that close, null without one.
- * Proximity is measured against the raw @tokens,
+ * Proximity is measured against the raw @tokens of the DIRECTIVE surface —
+ * quoted/pasted spans are masked first (#117040) —
* not the resolved member keys the caller passes (those are roster keys
* such as `<connectionId>::<name>`, and a mention resolves through titles
* and friendly names too, so the @token text rarely equals the key). The
@@ -275,7 +322,7 @@ export function classifyGroupHoldDirective(
* halt" = 2, "@x go, das ist halt ein Test" = 4); widen only with measured
* cases, never by guessing. */
function stopWordPlacement(value: string): 'adjacent' | 'distant' | null {
- const tokens = value.toLowerCase().match(/@[\p{L}\p{N}._-]+|[\p{L}\p{N}_-]+/gu) || []
+ const tokens = maskQuotedAndCodeSpans(value).toLowerCase().match(/@[\p{L}\p{N}._-]+|[\p{L}\p{N}_-]+/gu) || []
const mentionAt: number[] = []
const stopAt: number[] = []