Repository navigation
Description
Why
#59 Phase 2 plans capture: memory written from what a session did, not only from what the agent chose to retain. Its first slice, S1 (#128), shipped the hook-path collapse; S2 is the capture core. The owner's decisions on #59 (2026-11-15, recorded in the slicing plan) set the frame:
- D2: the transcript reader lives in memkernel, behind a port;
- D3: capture extracted signals only, no transcript excerpts;
- D4: no model-written distillation;
- D5: one issue per slice.
The first extractor is failed-then-fixed commands, which also gives the #120 count something to measure: errors captured, and repeats after capture.
Checked facts (main at 7f26012, memkernel 0.9.0)
- The spool drains every ended session but reports only some.
session_spool.drain()removes every ended session from the spool. It returns only the windows with no checkpoint (DrainResult.unsaved), which the session-start block lists. The other ended sessions are deleted without being returned. - The spool already records the transcript. The SessionEnd hook writes the session's
transcript_pathinto itsendedline (templates/hooks/session-end.py), butSessionWindowdoes not carry it. - The drain runs at normal startup only (
MemoryLifecycle.on_session_start,source == "startup"), inside the SessionStart hook. - A transcript reader exists, temporary, in
eval/repeat-mistakes/transcripts.py(Make repeated mistakes countable: a recall log and a counting script #120). It reads Claude Code's JSONL bysessionId, with each session's window, its ownBashoutputs, and itsrecallcalls. - memkernel has no redaction code in
src/.
Requirements (the owner's, 2026-11-15)
- Expose all ended windows. The spool exposes every ended session's window, including its
transcript_path, not only the unsaved ones. The unsaved report keeps working. - Commit only after a durable store. An ended session leaves the spool, or a cursor advances past it, only after its extracted records are durably stored. A capture that fails or is interrupted leaves the session to be captured again.
- Idempotent. Each extracted record is keyed by
(session, record UUID, extractor version), where the record UUID is the failing command's transcript record (itstool_resultentry'suuid). Capturing the same session twice, or retrying after a failure, neither loses nor duplicates a signal.- An extractor-version bump changes the key, so a session captured again under the new version gets new records. The new record supersedes the old-version record for the same session and failing record UUID, so there is never one record per version. Sessions already gone from the spool are not re-scanned; a bump affects only sessions captured after it.
- The transcript reader is behind a port. A
TranscriptReaderPortincore/ports.py, with a Claude Code adapter that graduates the Make repeated mistakes countable: a recall log and a counting script #120 reader intosrc/. The Make repeated mistakes countable: a recall log and a counting script #120 count then uses the adapter instead of its own copy.
Proposed (for a spec)
-
Opt-in. Capture is off by default, behind a setting (for example
MEMKERNEL_CAPTURE), because it reads transcripts and stores their text. If the spec prefers another default, that is its first decision. -
Extractor: failed-then-fixed commands. A
Bashcommand whose output shows an error, followed later in the same session by a run of the same command, or the same tool target, that succeeds. It is stored as a short-termobservation, with:- the error text and the fixing command;
origin:tags (the session, the extractor and its version);- the idempotency key.
Only command output and structured fields are used, never free text from tool or web results (Context rescue: fix the compaction hooks, then capture session knowledge before it is lost (0.5.1 → 0.6) #59's prompt-injection rules).
-
Redaction of secrets in what is stored, before writing.
-
Caps: records per session and per run.
-
When capture runs: at normal startup, after the drain, within a time budget. Sessions it doesn't reach stay for the next start (requirement 2). Whether a detached worker is needed is for the spec.
-
A missing or unreadable transcript is retried at a bounded number of startups (the spec sets the number). After that, the session leaves the spool with one logged warning and a count in the startup report, so a deleted transcript never blocks the spool.
-
At session start:
- Captured records stay out of the promotion candidates, or are capped there (the spec decides which), so capture does not crowd out what the agent stored itself.
- Wherever a hook block shows a captured record, it is quoted as stored memory, inside a
<stored-memory>element (Injected memory is untrusted text: present it as data, and ship a recommended Claude Code permissions example #85), like every other injected memory.
-
How captured records feed the Make repeated mistakes countable: a recall log and a counting script #120 count:
- A captured record quotes the error in backticks, so it is a stored error under the count's rule.
- Its
origin:tags let the count report captured errors apart from errors the agent stored itself. - The report then shows how often a captured error came back after capture, and whether a recall or hook block showed it first: shown, missed, other store or unknown.
Out of scope
- More extractors (owner turns, PRs, commits, files changed), supersede suggestions and canonical hashing: S3.
- Readers for tools other than Claude Code (One memkernel store across several coding tools (Claude Code, Codex, Cursor, Antigravity) #107).
- Promoting captured records automatically.
- Transcript excerpts (D3).
Acceptance (sketch)
- Every ended session in the spool is offered to capture, not only the unsaved ones, and the unsaved report is unchanged.
- A capture killed after extraction but before the store, or after the store but before the spool commit, loses no signal and duplicates none on the next start.
- Capturing the same session twice stores each signal once. After an extractor-version bump, a newly captured session holds one record per failing command, under the new version.
- A session whose transcript is missing leaves the spool after the bounded retries, and the startup report counts it.
- With capture off (the default), nothing is read or stored.
- At session start, captured records are left out of, or capped in, the promotion candidates, and quoted as stored memory wherever they are shown.
- The Make repeated mistakes countable: a recall log and a counting script #120 count reports captured errors separately from agent-stored ones.
- A fixture transcript with a failed-then-fixed command yields one record; one with a failure and no fix yields none.
- The Make repeated mistakes countable: a recall log and a counting script #120 count runs on the adapter, and its fixture test still passes.
Related: #59 (Phase 2, slicing plan), #128 (S1), #120 (the reader and the count), #107 (other tools).
Activity
gosha70 commentedon Nov 17, 2026
Key change (the owner's decision, 2026-11-16). Requirement 3's key becomes
(session, record UUID, extractor), where extractor is the extractor's name, not its version. The extractor version is kept as a tag on each record.The supersede rule for version bumps is dropped. A session leaves the spool once its records are stored, so it is captured again only when a capture is interrupted, possibly across an upgrade. With the version out of the key, that retry skips the records already stored, whatever version wrote them. So a session is captured once, under the version installed at the time, and nothing is superseded or re-scanned.
The spec also records the owner's other decisions for this issue: capture is off by default; it runs in the startup hook within a time budget and a per-run record cap; redaction is best-effort; and captured records stay out of the promotion candidates.
spec: D7 rerun and exit-code rules, the corrected yield (#134)
spec: D8, S2 ships as the first slice; README states the extractor's …
spec: review fixes R1-R6 and the count fixes R7-R11 (#134, #136)
spec: R12 sidechain and agent id on steps, R13, the order note (#134, #…
spec: R14 subagent 'shown' rule, R15 recursive subagent files and age…
Merge pull request #135 from gosha70/spec/134-capture-core
Merge pull request #137 from gosha70/feat/134-capture-core
gosha70 commentedon Nov 18, 2026
Built in #137 (spec #135,
specs/memkernel-0-12-capture-core/spec.md). Two points differ from this issue's text, by decisions recorded in the spec:tool_use_id, not the entry'suuid, because one transcript entry can hold several results (R2).Merge pull request #151 from massimiliano1991/diade/sc8-fixtures-main