You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 9685f27
Browse filesBrowse the repository at this point in the historyBrowse files
authored
fix: queue-based working memory capture (#179) (#180)
## Summary
- Replaces broken transcript extraction with queue-based turn capture
from hook inputs
- UserPromptSubmit (`preamble`) captures user prompts to
`.memory/.pending-turns.jsonl`
- Stop hook captures `assistant_message` (on `end_turn` only) to same
queue, decouples throttle from capture
- Background updater uses `mv`-based atomic handoff with crash recovery
via `.pending-turns.processing`
## What was wrong
The previous implementation extracted user/assistant messages from
session transcript JSONL, but most entries are `tool_result`/`tool_use`
with no text content. In a typical session (89 "user" messages, only 8
with actual text), the `tail -3` windowing almost always missed real
content.
## Design
Hook inputs already provide both data points directly — no transcript
needed:
- **UserPromptSubmit** → `prompt` (user's text)
- **Stop** → `assistant_message` (full response) + `stop_reason`
Queue accumulates turns; throttle only gates background processing (not
capture). 10-turn batch cap, overflow safety, crash recovery.
## Test plan
- [x] 5 new queue behavior tests in `shell-hooks.test.ts`
- [x] 618/618 tests passing
- [x] `bash -n` syntax validation on all 3 modified hooks
- [x] 16 acceptance scenarios (stop_reason filtering, dual format,
capture before throttle, DEVFLOW_BG_UPDATER guard, crash recovery,
missing .memory/)
- [x] Evaluator: 5/5 plan requirements aligned
Closes#179
---------
Co-authored-by: Dean Sharon <deanshrn@gmain.com>
Co-authored-by: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CLAUDE.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,7 @@ Commands with Teams Variant ship as `{name}.md` (parallel subagents) and `{name}
38
38
39
39
**Build-time asset distribution**: Skills and agents are stored once in `shared/skills/` and `shared/agents/`, then copied to each plugin at build time based on `plugin.json` manifests. This eliminates duplication in git.
40
40
41
-
**Working Memory**: Three shell-script hooks (`scripts/hooks/`) provide automatic session continuity. Toggleable via `devflow memory --enable/--disable/--status` or `devflow init --memory/--no-memory`. Stop hook → reads last turn from session transcript (`~/.claude/projects/{encoded-cwd}/{session_id}.jsonl`), spawns background `claude -p --model haiku` to update `.memory/WORKING-MEMORY.md` with structured sections (`## Now`, `## Progress`, `## Decisions`, `## Modified Files`, `## Context`, `## Session Log`; throttled: skips if triggered <2min ago; concurrent sessions serialize via mkdir-based lock). SessionStart hook → injects previous memory + git state as `additionalContext` on `/clear`, startup, or compact (warns if >1h stale; injects pre-compact memory snapshot when compaction happened mid-session). PreCompact hook → saves git state + WORKING-MEMORY.md snapshot + bootstraps minimal WORKING-MEMORY.md if none exists. Zero-ceremony context preservation.
41
+
**Working Memory**: Four shell-script hooks (`scripts/hooks/`) provide automatic session continuity. Toggleable via `devflow memory --enable/--disable/--status` or `devflow init --memory/--no-memory`. UserPromptSubmit (`prompt-capture-memory`) captures user prompt to `.memory/.pending-turns.jsonl` queue. Stop hook captures `assistant_message` (on `end_turn` only) to same queue, then spawns throttled background `claude -p --model haiku` updater (skips if triggered <2min ago; concurrent sessions serialize via mkdir-based lock). Background updater uses `mv`-based atomic handoff to process all pending turns in batch (capped at 10 most recent), with crash recovery via `.pending-turns.processing` file. Updates `.memory/WORKING-MEMORY.md` with structured sections (`## Now`, `## Progress`, `## Decisions`, `## Modified Files`, `## Context`, `## Session Log`). SessionStart hook → injects previous memory + git state as `additionalContext` on `/clear`, startup, or compact (warns if >1h stale; injects pre-compact memory snapshot when compaction happened mid-session). PreCompact hook → saves git state + WORKING-MEMORY.md snapshot + bootstraps minimal WORKING-MEMORY.md if none exists. Disabling memory removes all four hooks. Use `devflow memory --clear` to clean up pending queue files across projects. Zero-ceremony context preservation.
42
42
43
43
**Ambient Mode**: Three-layer architecture for always-on intent classification. SessionStart hook (`session-start-classification`) reads lean classification rules (`~/.claude/skills/devflow:router/references/classification-rules.md`, ~30 lines) and injects as `additionalContext` — once per session, deterministic, zero model overhead. UserPromptSubmit hook (`preamble`) injects a one-sentence prompt per message triggering classification + router loading via Skill tool. Router SKILL.md is a pure skill lookup table (~50 lines) loaded on-demand only for GUIDED/ORCHESTRATED depth — maps intent×depth to domain and orchestration skills. Toggleable via `devflow ambient --enable/--disable/--status` or `devflow init`.
-`env.ENABLE_LSP_TOOL` - Language Server Protocol support
150
153
-`env.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` - Agent Teams for peer-to-peer collaboration
@@ -153,17 +156,21 @@ Included settings:
153
156
154
157
## Working Memory Hooks
155
158
156
-
Three hooks in `scripts/hooks/` provide automatic session continuity. Toggleable via `devflow memory --enable/--disable/--status` or `devflow init --memory/--no-memory`.
159
+
Four hooks in `scripts/hooks/` provide automatic session continuity. Toggleable via `devflow memory --enable/--disable/--status` or `devflow init --memory/--no-memory`.
157
160
158
-
A fourth hook (`session-end-learning`) provides self-learning. Toggleable via `devflow learn --enable/--disable/--status` or `devflow init --learn/--no-learn`:
161
+
A fifth hook (`session-end-learning`) provides self-learning. Toggleable via `devflow learn --enable/--disable/--status` or `devflow init --learn/--no-learn`:
159
162
160
163
| Hook | Event | File | Purpose |
161
164
|------|-------|------|---------|
162
-
|`stop-update-memory`| Stop |`.memory/WORKING-MEMORY.md`| Throttled (skips if <2min fresh). Slim instruction after first write. |
165
+
|`prompt-capture-memory`| UserPromptSubmit |`.memory/.pending-turns.jsonl`| Captures user prompts to queue. Zero classification overhead. |
166
+
|`stop-update-memory`| Stop |`.memory/.pending-turns.jsonl`| Captures assistant turns to queue. Throttled (skips if <2min fresh). Spawns background updater. |
|`session-start-memory`| SessionStart | reads WORKING-MEMORY.md | Injects previous memory + git state as `additionalContext`. Warns if >1h stale. Injects pre-compact snapshot when compaction occurred mid-session. |
164
169
|`pre-compact-memory`| PreCompact |`.memory/backup.json`| Saves git state + WORKING-MEMORY.md snapshot. Bootstraps minimal WORKING-MEMORY.md if none exists. |
165
170
166
-
**Flow**: Session ends → Stop hook checks throttle (skips if <2min fresh) → spawns background updater → background updater reads session transcript + git state → fresh `claude -p --model haiku` writes WORKING-MEMORY.md. On `/clear` or new session → SessionStart injects memory as `additionalContext` (system context, not user-visible) with staleness warning if >1h old.
171
+
**Flow**: User sends prompt → UserPromptSubmit hook (prompt-capture-memory) appends user turn to `.memory/.pending-turns.jsonl`. Session ends → Stop hook appends assistant turn to queue, checks throttle (skips if <2min fresh), spawns background updater → background updater reads queued turns + git state → fresh `claude -p --model haiku` writes WORKING-MEMORY.md. On `/clear` or new session → SessionStart injects memory as `additionalContext` (system context, not user-visible) with staleness warning if >1h old.
172
+
173
+
`devflow memory --disable` removes all four hooks. Use `devflow memory --clear` to clean up pending queue files (`.pending-turns.jsonl`, `.pending-turns.processing`) across all projects.
167
174
168
175
Hooks auto-create `.memory/` on first run — no manual setup needed per project.
0 commit comments