fix(brain): strip claw save/merge trigger prefix in edit-sync re-extraction#52
Merged
Merged
Conversation
…action When a user edits a message originally sent via `claw save <text>`, the edit envelope carries the FULL edited body (`claw save <new text>`), not just the tail. The original ingest path stripped `claw save ` before emitting `chat.message.saved`, but PR 4's edit-sync handler re-ran extractPipeline on the raw new_text — producing KUs whose text included the literal `claw save ` prefix, inconsistent with the original. Live repro on 2026-04-28: - Original: `claw save Pay $5,000 to Acme by Friday` → KU text: `Pay $5,000 to Acme by Friday` ✓ - Edit: `claw save Pay $7,500 to Acme by Monday` → New KU text: `claw save Pay $7,500 to Acme by Monday` ✗ Add a small `stripClawTriggerPrefix(text)` helper used both for the single-message path and inside `rebuildWindowTranscript`. Same regex shape the channel-side text trigger uses, so KU text stays consistent across original ingest + edit re-extraction. Two regression tests cover save and merge prefixes; LLM caller used as a spy to verify the prompt doesn't carry the prefix. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
Spotted during PR 47/PR 51 live verification on 2026-04-28: edits to claw-saved messages produce KUs whose text starts with the literal `claw save ` prefix, whereas the original ingest correctly stripped it.
Live repro (KUs from real Signal Note-to-Self traffic):
The original ingest path (signal.ts/discord.ts text triggers) emits `chat.message.saved` with `text = body.match(/^claw\s+save\b\s*(.*)$/i)[1].trim()`. The edit-sync handler in src/brain/chat-edit-sync.ts re-ran `extractPipeline` on `evt.new_text` directly, which carries the full edited body including the `claw save ` prefix. Result: prompt and KU text drift.
Fix
Tiny helper `stripClawTriggerPrefix(s)` mirroring the channel-side regex. Applied to:
Test plan
Related
Surfaced after merging #41 (PR 4 chat edit/delete sync) and #51 (sync envelope timestamp fallback). Verified live by #47 (sendReply ack wiring).
🤖 Generated with Claude Code