feat(status): show session compaction count

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.
This commit is contained in:
AlexKucera committed 2026-11-16 17:20:24 +01:00
1 parent 8599ae8176
commit dc75ef8a7b
7 files changed
+113 -5

No files matched your search

@@ -0,0 +1,52 @@
# 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`: new `sessionCompactions` counter, incremented in the existing `session_compact` handler (alongside `resetCycle()`).
- `index.ts`: `countCompactions()` in the status command handler — primary source counts persisted `type === "compaction"` entries via `ctx.sessionManager.getEntries()`; falls back to the in-memory counter when `sessionManager` is unavailable or unreadable.
- `index.ts`: new `compactions` panel row (padded to the shared label column), rendered last; command doc-comment updated.
- `harness.ts`: `makeCtx` now mocks `sessionManager.getEntries()` (new `entries` override, default `[]`); the status-panel test asserts `compactions 0` on a fresh session; new test verifies entry-tree counting (3 compaction entries of 5) and the in-memory fallback after `sessionManager` is 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*