Repository navigation
✨ agents: drain CLI memory into draft knowledge entries before clearing - #17086
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
cafd17f to
66f1228
Compare
66f1228 to
f1a4d07
Compare
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor. @clubanderson this PR is held at Failing checks:
Next: the hive does not push to your branch. Push a new head (or reply here); CI and the review swarm re-run automatically and the PR returns to the normal path. |
f1a4d07 to
2117c26
Compare
|
Two separate things on this head ( 1. Shared CI incident (not this diff): 2. PR-local —
func (d *Drainer) Drain(req Request) Result {
res := Result{Store: d.Dir} // <- dereferences d
if d == nil || d.Dir == "" {The test is right to pin the nil-receiver contract — it just found the bug. Suggested fix is to move the guard first: func (d *Drainer) Drain(req Request) Result {
if d == nil || d.Dir == "" {
return Result{Errors: []error{errors.New("cli-memory drain: no target directory")}}
}
res := Result{Store: d.Dir}(With 🐝 Hive Agent: — hive: agent=quality backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
|
The hive's GitHub App lacks |
|
Needs a decision, not a merge: Clear the cause and the hive re-evaluates on its next pass; the stage moves to |
There was a problem hiding this comment.
Read at head 2117c26. One real defect, and it is the reason test (rest 3/4) (and therefore coverage) is red; the other red check is inherited from v5.
Nil-receiver guard dereferences before it checks — medium
src/pkg/knowledge/climemory/drain.go:83-86
res := Result{Store: d.Dir}
if d == nil || d.Dir == "" {d.Dir is read on line 83, so a nil *Drainer panics before the d == nil test on line 84 ever runs. TestDrainRejectsMissingTarget (drain_edge_test.go:11-13) calls exactly that — var nilDrainer *Drainer; nilDrainer.Drain(Request{}) — and CI shows the SIGSEGV at drain.go:83 (run 42410650591). The production path is not affected today: boot_cli_memory_drain.go always builds a non-nil Drainer and the manager calls through the CLIMemoryDrainer func hook, so this is a wrong guard plus a red suite rather than a runtime crash. Fix is to move the nil check first:
if d == nil || d.Dir == "" {
return Result{Errors: []error{errors.New("cli-memory drain: no target directory")}}
}
res := Result{Store: d.Dir}(If you want Store populated on the Dir == "" branch, split the two conditions.)
relative links and anchors resolve is not yours — it reports CHANGELOG.md: broken link 'url', a file this PR does not touch; the same workflow failed on v5 at 30468b7 and passed again at 2d96de7. A rebase/merge of current v5 clears it.
The rest of what I traced matches the body: the drainer only writes under d.Dir with hash-derived cli-memory-<hash16>.md names, inputs are bounded (maxMemoryFileBytes, maxFactsPerDrain, drain.go:38,42), and the Crux side only classifies store paths and calls the installed hook, so the pkg/* import boundary holds.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
Adds agents.cli_memory.drain_to_knowledge (default false, per-agent override). Before every non-resume kick, and before clear_on_kick wipes the store, the manager lists the agent's own CLI memory stores (Claude ~/.claude/projects/*/memory, Codex $CODEX_HOME/memories*, Gemini ~/.gemini/GEMINI.md) and the hive converts each bullet or paragraph into a state: draft entry in the bead-synth vault the Primer already reads, with source: cli-memory, agent:, cli:, repo: (from the Claude project slug when it matches one of the agent's repos) and a SHA-256 memhash that makes repeated drains idempotent across states and file names. Drafts are never promoted automatically; the approved-only Primer default keeps them out of kicks until a human approves them. The parser and vault writer live in pkg/knowledge/climemory (root module); the Crux manager only collects sources and calls the drainer installed via crux.CLIMemoryDrainHost, so the Crux module imports no knowledge package. One log line per drain: cli-memory: drained N facts from <agent> into <store> (dupes K). Proposed by @gregoryhunt at the 2026-11-05 community meeting. Fixes #17033 Signed-off-by: Andrew Anderson <andy@clubanderson.com>
…matter hash scan and parser structure Signed-off-by: Andrew Anderson <andy@clubanderson.com>
…ng; boot drain installer tests
Drain built Result{Store: d.Dir} before the nil-receiver guard, so the
nil-drainer edge test panicked in CI (test rest 3/4). Return the error
result first.
Add cmd/hive tests for cliMemoryDrainEnabled and installCLIMemoryDrainer:
vault connected without bead stores, drainer installed on a hosted runtime
and writes a draft entry with repo/agent tags, dedupes on second drain, and
the stand-down paths (disabled, sidecar-like runtime, no knowledge API,
unmkdirable vault path).
Signed-off-by: Andrew Anderson <andy@clubanderson.com>
2117c26 to
939d230
Compare
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
Fixes #17033
Proposed by @gregoryhunt at the 2026-11-05 community meeting: he migrated ~60% of his CLI memory into beads by hand and asked whether Hive can hook memory writes so they land in beads/knowledge instead of the CLI's opaque memory store. This PR does that at kick time.
What
New
agents.cli_memory.drain_to_knowledge: bool(default false, per-agent override). When on, before every non-resume kick — and beforeclear_on_kickwipes the store — the manager drains the agent's own CLI memory into draft knowledge entries:~/.claude/projects/<slug>/memory/MEMORY.md+ topic files (index links skipped)*.mdunder$CODEX_HOME/memories*/## Gemini Added Memoriessection of~/.gemini/GEMINI.mdEach bullet / paragraph becomes one entry in the
bead-synth-wikivault the Primer already reads (registerKnowledgeStores), written ascli-memory-<hash16>.mdwith:state: draft— never promoted automatically; the approved-only Primer default keeps drafts out of kicks until an operator approves them viaPUT /api/knowledge/entry/{id}/state. Human review is the point.source: cli-memory,agent: <name>,cli: <claude|codex|gemini>,repo: <org/repo>when the Claude project slug ends in one of the agent's repos,source_path,drained.memhash: <sha256 of normalised text>— dedupe across repeated drains, in any lifecycle state and under any filename, so approving an entry does not cause it to be re-drafted.One activity-log line per drain:
cli-memory: drained N facts from <agent> into bead-synth-wiki (dupes K).Bounds: 200 facts per drain, 512 KB per file, symlinks / hidden files / shared homes skipped. The bead-synth vault is now connected and registered when the drain is enabled even with no bead stores configured.
How
src/pkg/knowledge/climemory/(root module): parsers for the three formats,Drainerthat writes into aknowledge.FileStoreand reindexes. Table-driven tests with fixtures undertestdata/, dedupe/rewrap, "draft never approved" invariant (uses the realFileStore+FilterByLifecycle), symlink/missing handling, repo-slug derivation. Notime.Sleep.src/crux/cli_memory_drain.go+src/crux/agent/cli_memory_drain.go: the Crux module cannot importpkg/*, so the manager only classifiescliMemoryStorePathsinto sources and calls a drainer installed through the optionalcrux.CLIMemoryDrainHostinterface (in-process runtime; the sidecar runtime logs a warning and only wipes). New files keepmanager.goat its ratchet baseline.src/cmd/hive/boot_cli_memory_drain.go: builds theclimemory.Draineragainst the bead-synth vault and installs it.agent-configuration.md,agent-knowledge-and-memory.md(moved ✨ knowledge: drain CLI auto-memory into beads/knowledge at session end instead of hidden MEMORY.md #17033 from "Known gaps" into the main flow;SessionEndhook and one-shot shared-store drain remain as [scanner] ✨ knowledge: Claude Code SessionEnd/PostToolUse auto-memory drain hook (phase 2 of #17033) #17057/[scanner] ✨ knowledge: review flow + never-prime for auto-memory drafts, legacy migration, operator docs (phase 3 of #17033) #17058),operator-reference/.Relation to #17089
Builds on
agents.cli_memory: {auto_memory, clear_on_kick}from #17089, which is already merged intov5; this PR contains only the drain commits.Not in scope:
scope:frontmatter from #17060 (not merged — plain frontmatter used).