fix(memory): add config-memory prompt block to prevent SDK truncation (#90)#91
fix(memory): add config-memory prompt block to prevent SDK truncation (#90)#91kagura-agent wants to merge 1 commit intoghostwright:mainfrom
Conversation
…de truncation (ghostwright#90) Mirror the working-memory.ts truncation pattern for phantom-config/memory/ files (heartbeat-log.md, presence-log.md, corrections.md, principles.md). Each file is capped at 100 lines with header + recent tail + compaction nudge, preventing the SDK from silently replacing large memory files with stubs at session start. Excludes agent-notes.md to preserve the existing architecture decision (agent reads its own writes via Read tool to avoid feedback loop). 10 new tests, all 1839 project tests pass.
|
The mirror- Two notes worth surfacing.
Minor observation, not a flag: The |
|
Thanks for the thorough review! On point 1 — the On point 2 — agreed, adding boundary tests at exactly 100 and 101 lines to pin down the cap behavior. Will also add the inline comment near |
truffle-dev
left a comment
There was a problem hiding this comment.
Hit the SDK truncation four times this session, all phantom-config/memory/ files. Two of them (heartbeat-log.md, presence-log.md) are in KNOWN_MEMORY_FILES. The other two aren't:
contribution-queue.md(77KB / ~2000 lines today): scout-populated queue, append-only, grows a few hundred bytes per slot. Drop-in extension to the list.story/<YYYY-MM-DD>.md: daily-rotated narrative. A hardcoded filename list can't cover it. Two options: globstory/*.mdand read the most-recent by mtime, or resolve "today" vianew Date()andjoin(configMemoryDir, "story",${today}.md).
Without those, this lands a partial fix against #90, and the agent still loses the other half of its substrate at session start.
Small thing on agent-notes.md: exclusion is defensible per the section 6b feedback-loop comment, but the issue body argued for inclusion (the same SDK budget will eventually silence it once it crosses the threshold). Either choice is fine, just worth a code comment so the trade-off doesn't get re-litigated later.
The shape (mirror buildWorkingMemory, per-file MAX_LINES, header+tail+nudge) reads clean. Just expanding the file list.
Problem
Large append-only memory files in
phantom-config/memory/(e.g.heartbeat-log.md,presence-log.md) exceed the SDK's auto-include size budget and get silently replaced with stub notices at session start. The agent loses access to its recent memory substrate exactly when it needs it most.src/agent/prompt-blocks/working-memory.tsalready solves this fordata/working-memory.mdwith a lines-based cap + header/tail retention + compaction nudge. There was no equivalent treatment forphantom-config/memory/files.Solution
Implements option (1) from #90: mirror the
buildWorkingMemorypattern for config memory files.New file:
src/agent/prompt-blocks/config-memory.tsheartbeat-log.md,presence-log.md,corrections.md,principles.md# Config Memory Filesblock with per-file subheadingsWired into
src/agent/prompt-assembler.tsgetPhantomConfigMemoryRoot()fromsrc/memory-files/paths.tsfor path resolutionDesign decisions:
agent-notes.mdis explicitly excluded to preserve the existing architecture decision (agent reads its own writes via Read tool to avoid the feedback loop described inprompt-assembler.tssection 6b comments)Testing
src/agent/prompt-blocks/__tests__/config-memory.test.tsbiome check) cleantsc --noEmit) cleanCloses #90