Skip to content

feat(brain): identity merge + claw merge + window attachment summaries (PR 3)#45

Merged
topcoder1 merged 9 commits into
mainfrom
worktree-pr3-identity-merge
Apr 28, 2026
Merged

feat(brain): identity merge + claw merge + window attachment summaries (PR 3)#45
topcoder1 merged 9 commits into
mainfrom
worktree-pr3-identity-merge

Conversation

@topcoder1
Copy link
Copy Markdown
Owner

Summary

PR 3 of the Discord/Signal brain ingest series — finishes the chat-ingest UX layer with three sub-features:

1. Identity-merge engine (Tasks 1-2)

`mergeEntities(keptId, mergedId, opts)` atomically pivots all `ku_entities`, `entity_aliases`, and `entity_relationships` rows from loser → winner, writes a row to `entity_merge_log` with snapshot + evidence. Both entity rows survive (soft-delete via merge log). Rejects: self-merge, missing entities, type mismatch, re-merging an already-merged loser.

2. `claw merge` chat command (Tasks 3-7)

  • New `EntityMergeRequestedEvent` type
  • Signal + Discord channels detect `claw merge ` text trigger (with shared `parseMergeArgs` supporting bare words and double-quoted phrases)
  • Brain-side handler resolves both handles by alias `field_value` or canonical name (case-insensitive), rejects ambiguity, calls `mergeEntities`
  • Sends ack reply via optional `sendReply` callback (production wiring deferred to follow-up; merges still run end-to-end)
  • Lifecycle wired into `startChatIngest`/`stopChatIngest`

3. Window attachment summaries (Tasks 8-9)

  • `summarizeAttachment(att, opts)` — three tiers: vision-summary for images when `BRAIN_IMAGE_VISION=true` and `local_path` exists, else `[: ]` fallback, else `[attachment]`. Vision failures fall back silently.
  • `window-flusher` now appends summary lines per attachment in the transcript so the LLM extractor sees their content. `flushOne`/`flushIdle`/`flushAll` became async; cap-flush, daily-check, ticker, shutdown use fire-and-forget `void flushOne(...)`.

Test plan

  • `npm run build` clean
  • All 2474 tests pass (263 files; 33 new tests for PR 3)
  • Identity merge: 8 engine tests + 9 handler tests (including lifecycle)
  • claw merge: 4 channel tests (signal + discord, both happy + arg-count rejection)
  • Attachment summary: 7 unit tests + 1 window-flusher integration test
  • Operator-run e2e: send `claw merge ` in a brain-opted chat, verify `entity_merge_log` row + ku_entities rebound
  • Operator-run e2e: send a windowed message with image attachment, verify `signal_window` payload `transcript` field contains `[image: ]` line

Schema

No new migrations — leverages existing `entity_merge_log` table from PR 1.

Out of scope

  • Auto-merge engine (deterministic / Splink) — `BRAIN_MERGE_AUTO_LOW_CONF_REJECT` env reserved but unused
  • `claw unmerge` — `pre_merge_snapshot` is captured for future undo
  • Production `sendReply` wiring (channel router access for ack replies in chat) — handler runs no-op reply today

🤖 Generated with Claude Code

topcoder1 and others added 9 commits April 28, 2026 09:45
…ically

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ed parser

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@topcoder1 topcoder1 merged commit 63ee6a5 into main Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant