Add a compactions row to the /smart-compact overlay counting the session's persisted compaction entries via ctx.sessionManager, so the number stays correct across resume and restart. An in-memory session_compact counter remains as the fallback where sessionManager is unavailable.
3.2 KiB
3.2 KiB
Status overlay: session compaction count
Date: 2026-11-16 Type: generic Reference: None
Goal
Extend the /smart-compact status overlay with a row showing how many times the session has already been compacted.
What Was Done
index.ts: newsessionCompactionscounter, incremented in the existingsession_compacthandler (alongsideresetCycle()).index.ts:countCompactions()in the status command handler — primary source counts persistedtype === "compaction"entries viactx.sessionManager.getEntries(); falls back to the in-memory counter whensessionManageris unavailable or unreadable.index.ts: newcompactionspanel row (padded to the shared label column), rendered last; command doc-comment updated.harness.ts:makeCtxnow mockssessionManager.getEntries()(newentriesoverride, default[]); the status-panel test assertscompactions 0on a fresh session; new test verifies entry-tree counting (3 compaction entries of 5) and the in-memory fallback aftersessionManageris removed.README.md: command paragraph mentions the compaction count and its persisted-entry source; stale "14-test harness" corrected to 23.CHANGELOG.md: Added entry under Unreleased.
Decisions & Rationale
| Decision | Rationale |
|---|---|
Count persisted compaction entries (ctx.sessionManager.getEntries()), not just an in-memory session_compact counter |
An in-memory counter resets to 0 on --resume/restart and would report "0 compactions" for a session compacted N times in a prior process — actively misleading for a status panel. Persisted entries are authoritative across resume/restart/fork. |
| Keep the in-memory counter as a fallback | Hosts without sessionManager still get a number (compactions seen this process) instead of nothing; costs two lines inside the already-registered session_compact handler. |
Count all entries (all branches), not getBranch() |
"How many times has the session been compacted" is session-lifetime semantics: every compaction that ever happened in this session file, independent of /tree navigation. |
session_compact_failed does not increment |
A failed compaction persists no entry; only successful compactions count. |
Gotchas & Fixes
| Problem | Root Cause | Fix |
|---|---|---|
| README claimed a "14-test committed harness" while the suite had grown to 22 | The overlay-panel session updated the harness without refreshing the README count | Corrected to 23 as part of this change |
Files Changed
| File | Change Summary |
|---|---|
index.ts |
sessionCompactions counter, countCompactions() helper, compactions panel row |
harness.ts |
sessionManager.getEntries() mock; new counting/fallback test; fresh-session assertion |
README.md |
Command section + harness test count |
CHANGELOG.md |
Unreleased → Added entry |
docs/devlog/INDEX.md |
New log row (newest first) |
AGENTS.md |
Session-log window refreshed |
Open Items & Next Steps
- Live-session validation still pending (as before): confirm the row shows the true count after a real compaction and after
--resume.
Log written by write-log skill