sync local pi changes

This commit is contained in:
alex wiesner
2026-04-09 23:14:57 +01:00
parent 18245c778e
commit ec378ebd28
128 changed files with 22510 additions and 3436 deletions

View File

@@ -0,0 +1,31 @@
# Context Manager Task 2 Fix Report
## Status
Completed.
## What changed
- Updated `.pi/agent/extensions/context-manager/src/ledger.ts` so `mergeCandidates()` only supersedes the current active item when the incoming candidate is at least as new by `timestamp`.
- Stale same-slot candidates now remain archived instead of reactivating older state when merges arrive out of order.
- Kept `createId(candidate)` intact and added a small internal uniqueness guard so same-slot same-timestamp candidates receive distinct item IDs in practice.
- Added regression coverage in `.pi/agent/extensions/context-manager/src/ledger.test.ts` for:
- out-of-order same-slot merges, and
- same-slot same-timestamp ID collisions.
## Test results
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npx tsx --test src/ledger.test.ts`
- Result: 5/5 tests passed.
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npm test`
- Result: 10/10 tests passed.
## Files changed
- `.pi/agent/extensions/context-manager/src/ledger.ts`
- `.pi/agent/extensions/context-manager/src/ledger.test.ts`
- `.pi/reviews/context-manager-task2-fix-report.md`
## Self-review findings
- Scope stayed limited to the two reviewed correctness issues and their regression tests.
- Public API and overall Task 2 structure were preserved.
- `createId(candidate)` remains the base ID format from the original Task 2 implementation.
## Any concerns
- None.

View File

@@ -0,0 +1,38 @@
# Context Manager Task 2 Implementer Report
## Status
Completed.
## What you implemented
- Added `src/ledger.ts` with the branch-aware memory ledger types and helpers:
- `createEmptyLedger()`
- `mergeCandidates()`
- `getActiveItems()`
- Implemented supersession behavior so a new active item archives the previous active item in the same `kind` + `scope` + `subject` slot.
- Preserved coexistence between branch-scoped and session-scoped memory items.
- Added `src/ledger.test.ts` with the required ledger coverage.
## What you tested and results
1. Ran the ledger test command before the files existed.
- Result: failed because `src/ledger.test.ts` did not exist.
2. Added `src/ledger.test.ts` and ran the ledger test command again before implementing the module.
- Result: failed with `ERR_MODULE_NOT_FOUND` because `src/ledger.ts` did not exist.
3. Ran the ledger test file after implementing the module.
- Command: `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npx tsx --test src/ledger.test.ts`
- Result: 3/3 tests passed.
4. Ran the full package test suite.
- Command: `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npm test`
- Result: 8/8 tests passed.
## Files changed
- `.pi/agent/extensions/context-manager/src/ledger.ts`
- `.pi/agent/extensions/context-manager/src/ledger.test.ts`
- `.pi/reviews/context-manager-task2-implementer-report.md`
## Self-review findings
- Implementation matches the required API and logic exactly.
- Test style matches the existing `src/config.test.ts` style.
- Scope stayed limited to the ledger work only.
## Any concerns
- The task text referenced `/home/alex/dotfiles/.pi/agent/extensions/context-manager`, but that path does not exist in this worktree. I ran the equivalent commands in the requested worktree path instead.

View File

@@ -0,0 +1,30 @@
# Context Manager Task 2 Minor Fix Report
## Status
- Completed.
- Added a deterministic exact-timestamp tie-break for same-slot candidates in `mergeCandidates()`.
- Added regression coverage for reversed input order.
## Changes
- Updated `.pi/agent/extensions/context-manager/src/ledger.ts` so same-slot candidates with identical timestamps no longer fall back to caller order.
- Added a narrow tie-break helper that compares candidate data (`text`, `sourceType`, `sourceEntryId`, then `confidence`) when timestamps match.
- Kept the public API unchanged and limited the behavior change to exact-timestamp same-slot comparisons.
- Added a regression test in `.pi/agent/extensions/context-manager/src/ledger.test.ts` that verifies the same candidate stays active regardless of input order.
## Tests
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npx tsx --test src/ledger.test.ts`
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npm test`
## Files Changed
- `.pi/agent/extensions/context-manager/src/ledger.ts`
- `.pi/agent/extensions/context-manager/src/ledger.test.ts`
- `.pi/reviews/context-manager-task2-minor-fix-report.md`
## Self-Review Findings
- The fix is narrowly scoped to same-slot exact-timestamp winner selection.
- Existing out-of-order merge coverage and same-timestamp ID-collision coverage still pass.
- The new regression test fails on the pre-fix code path and passes with the tie-break in place.
## Concerns
- None blocking.
- Same-slot collision IDs remain unique, but sequential `:2` / `:3` suffix assignment is still derived from insertion order across separate incremental merges; I left that behavior unchanged to keep this fix narrowly scoped to the requested active-item determinism issue.

View File

@@ -0,0 +1,35 @@
# Context Manager Task 2 Snapshot Fix Report
## Status
Completed.
## Changes
- Updated `.pi/agent/extensions/context-manager/src/ledger.ts` so affected ledger slots are normalized after merges instead of preserving same-slot insertion order.
- Added deterministic slot ordering by:
- newer `timestamp` first,
- existing exact-timestamp tie-break fields (`text`, `sourceType`, `sourceEntryId`, then `confidence`) for same-timestamp candidates.
- Reassigned same-slot same-timestamp IDs from that canonical order, so `:2` / `:3` suffixes no longer depend on input order.
- Recomputed slot-level `active`, `freshness`, and `supersedesId` from the canonical slot order so forward vs reversed tie merges produce the same stored snapshot and lineage.
- Strengthened `.pi/agent/extensions/context-manager/src/ledger.test.ts` to compare the resulting ledger snapshot, not only the active winner text.
- Updated the existing same-timestamp ID test to assert lineage against the archived tied item rather than insertion position.
## Tests
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npx tsx --test src/ledger.test.ts`
- Result: 6/6 tests passed.
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npm test`
- Result: 11/11 tests passed.
## Files Changed
- `.pi/agent/extensions/context-manager/src/ledger.ts`
- `.pi/agent/extensions/context-manager/src/ledger.test.ts`
- `.pi/reviews/context-manager-task2-snapshot-fix-report.md`
## Self-Review Findings
- Scope stayed inside the requested ledger merge path and regression tests.
- Public function signatures and exported types remain unchanged.
- The deterministic normalization preserves the earlier out-of-order timestamp protection while also making stored tie snapshots replay-stable.
- Regression coverage now locks the exact stored state for the tied slot, including IDs and `supersedesId` values.
## Concerns
- None blocking.
- I attempted to invoke the requested code-review subagent workflow, but no `code-reviewer` agent is available in this harness, so this pass relied on direct verification plus self-review.

View File

@@ -0,0 +1,44 @@
# Context Manager Task 3 Durable Constraint Fix Report
## Status
- Done
- Fixed the remaining durable-constraint extraction gaps in the context-manager extractor.
- Kept the change narrowly scoped and preserved the earlier source-stable subject behavior plus the narrowed ambiguous-scope behavior.
## Changes
1. **Allowed explicit durable file-specific constraints to remain session-scoped in `.pi/agent/extensions/context-manager/src/extract.ts`**
- Updated `inferConstraintScope()` so branch-local cues still win first.
- Checked durable session-wide phrasing before falling back to file-path-based branch scoping.
- This keeps ambiguous file-specific lines branch-scoped while allowing explicit durable lines such as `Avoid touching docs/extensions.md across the whole session.` to resolve to `session`.
2. **Expanded the constraint trigger in `.pi/agent/extensions/context-manager/src/extract.ts`**
- Introduced a shared `CONSTRAINT_RE`.
- Added support for the spelled-out `do not` form alongside the existing `must`, `should`, `don't`, `avoid`, and `prefer` triggers.
3. **Added regression coverage in `.pi/agent/extensions/context-manager/src/extract.test.ts`**
- Extended the user-constraint scope test with both:
- `Avoid touching docs/extensions.md.``branch`
- `Avoid touching docs/extensions.md across the whole session.``session`
- Added a dedicated regression test for:
- `Do not add new LLM-facing tools across the whole session.` → extracted `constraint`
## Tests
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npx tsx --test src/extract.test.ts`
- Result: 5 tests passed, 0 failed
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npm test`
- Result: 16 tests passed, 0 failed
## Files Changed
- Modified: `.pi/agent/extensions/context-manager/src/extract.ts`
- Modified: `.pi/agent/extensions/context-manager/src/extract.test.ts`
- Created: `.pi/reviews/context-manager-task3-durable-fix-report.md`
## Self-Review Findings
- The fix is limited to constraint detection and scope inference; no public APIs or ledger merge behavior changed.
- Source-stable `subject` generation remains untouched.
- Ambiguous file-specific instructions without explicit durable phrasing still stay `branch` scoped.
- Explicit durable session-wide wording now correctly overrides file-path presence for constraint scope.
## Concerns
- Constraint extraction remains heuristic-based by design, so contradictory phrasing that mixes branch-local and session-wide cues will still resolve conservatively to `branch`.
- No additional blocking concerns found after the targeted and full test runs.

View File

@@ -0,0 +1,41 @@
# Context Manager Task 3 Fix Report
## Status
- Done
- Fixed the Task 3 review findings in the extractor and strengthened coverage around extractor/ledger interaction.
## Changes
1. **Stopped cross-slice subject collisions in extracted memory**
- Updated `.pi/agent/extensions/context-manager/src/extract.ts` so synthetic subjects for decisions, constraints, and active tasks include the source `entryId` (for example `decision-u1-0`).
- This keeps independently extracted facts from different transcript slices in separate ledger slots without changing public APIs or the ledger merge contract.
2. **Refined user-constraint scoping**
- Added a small `inferConstraintScope()` heuristic.
- User constraints now default to `branch` scope unless they include durable session-wide signals.
- Branch-local cues such as `this branch`, `for now`, `in this file`, or explicit file references stay branch-scoped.
- Durable cues such as `whole session`, `across branches`, `MVP`, or `context window` stay session-scoped.
3. **Strengthened regression coverage**
- Expanded `.pi/agent/extensions/context-manager/src/extract.test.ts` to verify source metadata, stable per-slice subject generation, extractor/ledger interaction, and the refined scope heuristic.
- Added regression coverage proving independently extracted constraints, decisions, and active tasks all remain active after `mergeCandidates()`.
## Tests
- Focused extractor tests:
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npx tsx --test src/extract.test.ts`
- Result: 4 tests passed
- Full extension suite:
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npm test`
- Result: 15 tests passed
## Files Changed
- Modified: `.pi/agent/extensions/context-manager/src/extract.ts`
- Modified: `.pi/agent/extensions/context-manager/src/extract.test.ts`
- Created: `.pi/reviews/context-manager-task3-fix-report.md`
## Self-Review Findings
- The fix stays focused on Task 3 behavior and keeps all public function signatures unchanged.
- No ledger changes were needed; Task 2 deterministic merge behavior remains covered by the existing ledger tests and the full suite still passes.
- The new interaction test exercises the real extractor-to-ledger path that the review flagged as missing.
## Concerns
- The extractor still uses heuristic subject generation for independently extracted items, so semantically related decisions restated in different messages will coexist unless a future task adds stronger semantic matching. That is intentional for this focused fix and avoids the reported overwrite bug.

View File

@@ -0,0 +1,40 @@
# Context Manager Task 3 Implementer Report
## Status
- Done
- Implemented heuristic transcript-slice extraction in `.pi/agent/extensions/context-manager/src/extract.ts`
- Added focused tests in `.pi/agent/extensions/context-manager/src/extract.test.ts`
## Changes
- Added `TranscriptSlice` and `extractCandidates()`.
- Reused `MemoryCandidate`, `MemoryScope`, and `MemorySourceType` from `src/ledger.ts`.
- Added heuristics for:
- user goal extraction
- role-aware constraint extraction
- decision extraction
- next-step / task extraction
- file reference extraction
- Kept constraint extraction from duplicating structured `Goal:`, `Decision:`, and `Next:` lines so the output matches the requested candidate set.
## Tests
- Verified red state first:
- `cd .pi/agent/extensions/context-manager && npx tsx --test src/extract.test.ts`
- Result: failed with `ERR_MODULE_NOT_FOUND` because `src/extract.ts` did not exist
- Verified green state after implementation:
- `cd .pi/agent/extensions/context-manager && npx tsx --test src/extract.test.ts`
- Ran full extension test suite:
- `cd .pi/agent/extensions/context-manager && npm test`
## Files Changed
- Created `.pi/agent/extensions/context-manager/src/extract.ts`
- Created `.pi/agent/extensions/context-manager/src/extract.test.ts`
- Created `.pi/reviews/context-manager-task3-implementer-report.md`
## Self-Review Findings
- The implementation is tightly scoped to extraction only.
- Test coverage matches the task requirements and verifies both user and non-user sources.
- File reference extraction is intentionally heuristic and limited to the requested extensions.
## Concerns
- The provided implementation snippet would also classify `Decision: ... avoid ...` as a constraint; I prevented that duplicate extraction so the required tests pass.
- No other concerns.

View File

@@ -0,0 +1,42 @@
# Context Manager Task 3 Scope Fix Report
## Status
- Done
- Tightened the remaining user-constraint scope heuristic so ambiguous constraint lines stay `branch` scoped.
- Preserved the source-stable subject behavior introduced in the prior Task 3 fix.
## Changes
1. **Narrowed durable session promotion in `.pi/agent/extensions/context-manager/src/extract.ts`**
- Removed the bare-keyword session promotion behavior for terms such as `MVP` and `context window`.
- Kept `session` scope promotion limited to clearer durability signals such as `whole session`, `across branches`, `session-wide`, `project-wide`, and similar explicit phrasing.
2. **Strengthened local-scope detection**
- Treated `this module` / `in this module` as branch-local cues so module-local rename instructions do not leak across branch switches.
3. **Added regression coverage in `.pi/agent/extensions/context-manager/src/extract.test.ts`**
- Updated the existing extraction expectation so `We must adapt to the active model context window.` remains `branch` scoped.
- Added explicit regression assertions for the reviewers false-positive examples:
- `We should keep the MVP branch experimental.``branch`
- `We should rename the context window helper in this module.``branch`
- Kept a durable-session control case to verify explicit session phrasing still promotes correctly.
## Tests
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npx tsx --test src/extract.test.ts`
- Result: 4 tests passed, 0 failed
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npm test`
- Result: 15 tests passed, 0 failed
## Files Changed
- Modified: `.pi/agent/extensions/context-manager/src/extract.ts`
- Modified: `.pi/agent/extensions/context-manager/src/extract.test.ts`
- Created: `.pi/reviews/context-manager-task3-scope-fix-report.md`
## Self-Review Findings
- The fix stays narrowly scoped to `inferConstraintScope()` heuristics and targeted regression coverage.
- Public APIs and exported function signatures are unchanged.
- The previously fixed source-stable `subject` generation remains untouched.
- The updated tests cover both the reviewers concrete false positives and an existing ambiguous `context window` example.
## Concerns
- Constraint scoping remains heuristic-based by design, so the extractor is intentionally conservative: unclear user constraints now stay `branch` scoped unless the text explicitly signals broader durability.
- No additional blocking concerns found after the targeted and full test runs.

View File

@@ -0,0 +1,13 @@
# Task 4 Boundary Fix Report
- **Status:** DONE
- **Changes:** Updated `.pi/agent/extensions/context-manager/src/prune.ts` so `isBulky()` does not count the final empty split segment when content ends with a trailing newline. This keeps exactly-150-line tool output at the non-bulky boundary while preserving the existing byte and over-threshold line behavior. Added a regression test in `.pi/agent/extensions/context-manager/src/prune.test.ts` covering an old tool result with exactly 150 real lines plus a trailing newline.
- **Tests:**
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npx tsx --test src/packet.test.ts src/prune.test.ts` → 8 passed, 0 failed
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npm test` → 24 passed, 0 failed
- **Files changed:**
- `.pi/agent/extensions/context-manager/src/prune.ts`
- `.pi/agent/extensions/context-manager/src/prune.test.ts`
- `.pi/reviews/context-manager-task4-boundary-fix-report.md`
- **Self-review findings:** The fix is narrowly scoped to line counting inside `isBulky()`, keeps the public API unchanged, and preserves the existing prune-window behavior for bulky vs. non-bulky tool results outside this exact trailing-newline boundary case.
- **Concerns:** None.

View File

@@ -0,0 +1,46 @@
# Context Manager Task 4 Fix Report
## Status
- Fixed
- Packet trimming now selects facts under the cap instead of skipping whole sections.
- Targeted packet/prune tests and the full package test suite pass.
## Changes
- Updated `.pi/agent/extensions/context-manager/src/packet.ts` to:
- score active facts globally with the existing kind weights
- select facts one at a time under `packetTokenCap`
- render the final packet in the existing stable section order
- keep per-section bullet ordering priority-based
- Replaced the weak packet test in `.pi/agent/extensions/context-manager/src/packet.test.ts` with cap-edge assertions that check exact output and prove:
- a tight cap keeps the highest-priority fact from a partially fitting section
- cross-kind weights prefer `activeTask` over `decision` when only one can fit
- Expanded `.pi/agent/extensions/context-manager/src/prune.test.ts` to cover:
- old bulky tool results being pruned
- recent bulky tool results being preserved
- old non-bulky tool results being preserved
- the `recentUserTurns` boundary behavior
## Tests
- Red check before the packet fix:
- `cd .pi/agent/extensions/context-manager && npx tsx --test src/packet.test.ts`
- Result: 2 failing packet tests, showing whole-section trimming and cross-kind selection problems
- Focused verification:
- `cd .pi/agent/extensions/context-manager && npx tsx --test src/packet.test.ts src/prune.test.ts`
- Result: 6/6 passing
- Full package verification:
- `cd .pi/agent/extensions/context-manager && npm test`
- Result: 22/22 passing
## Files Changed
- `.pi/agent/extensions/context-manager/src/packet.ts`
- `.pi/agent/extensions/context-manager/src/packet.test.ts`
- `.pi/agent/extensions/context-manager/src/prune.test.ts`
- `.pi/reviews/context-manager-task4-fix-report.md`
## Self-Review Findings
- The packet builder now applies weights meaningfully across kinds because selection happens from a global priority list before rendering.
- Rendered output still uses the original section headings and section order.
- `prune.ts` behavior did not need logic changes; the missing boundary coverage is now explicit in tests.
## Concerns
- None.

View File

@@ -0,0 +1,37 @@
# Context Manager Task 4 Implementer Report
## Status
- Done
- Implemented packet building in `.pi/agent/extensions/context-manager/src/packet.ts`
- Implemented context pruning in `.pi/agent/extensions/context-manager/src/prune.ts`
- Added focused tests for both modules
## Changes
- Added `buildContextPacket()` with ordered section emission, priority sorting, and packet token-cap enforcement.
- Added `pruneContextMessages()` with recent-turn preservation and bulky old tool-result pruning.
- Reused existing policy and ledger types from `src/config.ts` and `src/ledger.ts`.
- Kept the implementation scoped to Task 4 only.
## Tests
- Verified red state first:
- `cd .pi/agent/extensions/context-manager && npx tsx --test src/packet.test.ts src/prune.test.ts`
- Result: failed with `ERR_MODULE_NOT_FOUND` because `src/packet.ts` and `src/prune.ts` did not exist yet
- Verified green state after implementation:
- `cd .pi/agent/extensions/context-manager && npx tsx --test src/packet.test.ts src/prune.test.ts`
- Ran full extension test suite:
- `cd .pi/agent/extensions/context-manager && npm test`
## Files Changed
- Created `.pi/agent/extensions/context-manager/src/packet.ts`
- Created `.pi/agent/extensions/context-manager/src/prune.ts`
- Created `.pi/agent/extensions/context-manager/src/packet.test.ts`
- Created `.pi/agent/extensions/context-manager/src/prune.test.ts`
- Created `.pi/reviews/context-manager-task4-implementer-report.md`
## Self-Review Findings
- Section ordering and token-cap behavior are covered by the packet test.
- Pruning behavior is covered by the prune test and preserves the latest user turn.
- No unrelated files in the extension package were modified.
## Concerns
- No known concerns.

View File

@@ -0,0 +1,21 @@
# Task 5 Fix Report
- **Status:** DONE
- **Changes:**
- Updated `.pi/agent/extensions/context-manager/src/runtime.ts` to store the last observed token count, recompute `lastZone` whenever policy changes, and return a cloned policy from `getPolicy()`.
- Updated `.pi/agent/extensions/context-manager/src/persist.ts` to validate and sanitize snapshot data before restoring it, skip malformed newer snapshot entries, and preserve backward compatibility by keeping `lastObservedTokens` optional.
- Expanded `.pi/agent/extensions/context-manager/src/runtime.test.ts` with zone recomputation, restore-policy, and no-alias policy/snapshot coverage.
- Expanded `.pi/agent/extensions/context-manager/src/persist.test.ts` with malformed snapshot skipping and deep clone coverage.
- Expanded `.pi/agent/extensions/context-manager/src/summaries.test.ts` with exact summary content and ordering assertions.
- **Tests:**
- `cd .pi/agent/extensions/context-manager && npx tsx --test src/runtime.test.ts src/persist.test.ts src/summaries.test.ts` → 9 passed, 0 failed
- `cd .pi/agent/extensions/context-manager && npm test` → 33 passed, 0 failed
- **Files changed:**
- `.pi/agent/extensions/context-manager/src/runtime.ts`
- `.pi/agent/extensions/context-manager/src/persist.ts`
- `.pi/agent/extensions/context-manager/src/runtime.test.ts`
- `.pi/agent/extensions/context-manager/src/persist.test.ts`
- `.pi/agent/extensions/context-manager/src/summaries.test.ts`
- `.pi/reviews/context-manager-task5-fix-report.md`
- **Self-review findings:** The fix stays within Task 5 scope, keeps the existing runtime API surface intact, and adds regression coverage for each review finding that previously slipped through.
- **Concerns:** None.

View File

@@ -0,0 +1,55 @@
# Context Manager Task 5 Implementer Report
## Status
- Completed Task 5.
- Required tests pass.
- Full extension test suite passes.
## What you implemented
- Added `src/summaries.ts` with:
- `buildCompactionSummary()`
- `buildBranchSummary()`
- `buildResumePacket()`
- Added `src/persist.ts` with:
- `SNAPSHOT_ENTRY_TYPE`
- `RuntimeSnapshot`
- `serializeSnapshot()`
- `deserializeLatestSnapshot()`
- Added `src/runtime.ts` with `createContextManagerRuntime()` to:
- ingest transcript slices via `extractCandidates()` + `mergeCandidates()`
- observe token pressure via `zoneForTokens()`
- build packets via `buildContextPacket()`
- expose compaction, branch, and resume summaries
- update mode and context window
- snapshot and restore runtime state
- Added the required tests for summaries, persistence, and runtime.
## What you tested and results
1. Confirmed the new tests initially failed because the new source files did not exist.
- Command: `cd .pi/agent/extensions/context-manager && npx tsx --test src/summaries.test.ts src/persist.test.ts src/runtime.test.ts`
- Result: failed with `ERR_MODULE_NOT_FOUND` for `summaries.ts`, `persist.ts`, and `runtime.ts`
2. Ran the required Task 5 tests after implementation.
- Command: `cd .pi/agent/extensions/context-manager && npx tsx --test src/summaries.test.ts src/persist.test.ts src/runtime.test.ts`
- Result: 5/5 passing
3. Ran the full extension test suite.
- Command: `cd .pi/agent/extensions/context-manager && npm test`
- Result: 29/29 passing
## Files changed
- Created `.pi/agent/extensions/context-manager/src/summaries.ts`
- Created `.pi/agent/extensions/context-manager/src/persist.ts`
- Created `.pi/agent/extensions/context-manager/src/runtime.ts`
- Created `.pi/agent/extensions/context-manager/src/summaries.test.ts`
- Created `.pi/agent/extensions/context-manager/src/persist.test.ts`
- Created `.pi/agent/extensions/context-manager/src/runtime.test.ts`
- Created `.pi/reviews/context-manager-task5-implementer-report.md`
## Self-review findings
- Implementation matches the task-provided API and file list.
- Reused existing `config`, `ledger`, `extract`, and `packet` modules as requested.
- Kept scope to Task 5 only; did not start Task 6.
- Verified the red/green cycle for the new tests.
## Any concerns
- No functional concerns from this task.
- There are unrelated untracked review files already present in `.pi/reviews/`; they were not included in this tasks changes.

View File

@@ -0,0 +1,29 @@
# Context Manager Task 5 Legacy Fix Report
## Status
- DONE
## Changes
- Updated `.pi/agent/extensions/context-manager/src/runtime.ts` so `syncSnapshotZone()` no longer preserves a stored legacy `lastZone` when `lastObservedTokens` is missing.
- Legacy snapshots without token observations now normalize back to `lastZone: "green"`, which matches the runtime's safe default when pressure cannot be recomputed.
- Added regression coverage in `.pi/agent/extensions/context-manager/src/runtime.test.ts` for both direct restore of a legacy snapshot and the real persisted path of `deserializeLatestSnapshot(...)` followed by `runtime.restore(...)`.
- Left new-schema snapshot behavior unchanged: snapshots that include `lastObservedTokens` still recompute `lastZone` against the receiving runtime policy.
## Tests
- `cd .pi/agent/extensions/context-manager && npx tsx --test src/runtime.test.ts` → 6 passed, 0 failed
- `cd .pi/agent/extensions/context-manager && npx tsx --test src/runtime.test.ts src/persist.test.ts src/summaries.test.ts` → 11 passed, 0 failed
- `cd .pi/agent/extensions/context-manager && npm test` → 35 passed, 0 failed
## Files Changed
- `.pi/agent/extensions/context-manager/src/runtime.ts`
- `.pi/agent/extensions/context-manager/src/runtime.test.ts`
- `.pi/reviews/context-manager-task5-legacy-fix-report.md`
## Self-Review Findings
- The fix is narrowly scoped to restore/policy resync behavior for snapshots missing `lastObservedTokens`.
- The public API stays the same.
- New-schema snapshots keep the existing recompute behavior.
- Legacy snapshots no longer carry a stale red/yellow/compact zone into a runtime that lacks the data needed to validate it.
## Concerns
- None.

View File

@@ -0,0 +1,30 @@
# Context Manager Task 6 Fix 2 Report
## Status
Done. Fixed the remaining branch rehydration and `/ctx-mode` persistence regressions and verified them with targeted and full test runs.
## Changes
- Updated `.pi/agent/extensions/context-manager/index.ts` rehydration to restore the latest valid snapshot ledger as the base state and replay only tracked messages that occur after that snapshot entry.
- Kept empty-ledger startup behavior when a branch has no valid snapshot.
- Preserved live in-memory mode changes during `turn_end` so `/ctx-mode aggressive` wins over an older persisted snapshot mode before the next snapshot is appended.
- Strengthened `.pi/agent/extensions/context-manager/src/extension.test.ts` with integration-style regressions for:
- `session_tree` on a snapshot-only branch producing a hidden packet from snapshot-backed ledger state.
- `/ctx-mode aggressive` persisting `mode: "aggressive"` and the corresponding aggressive-zone token classification on the next `turn_end`.
## Tests
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npx tsx --test src/extension.test.ts`
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npm test`
## Files Changed
- `.pi/agent/extensions/context-manager/index.ts`
- `.pi/agent/extensions/context-manager/src/extension.test.ts`
- `.pi/reviews/context-manager-task6-fix-2-report.md`
## Self-review Findings
- Snapshot-only branches now retain snapshot ledger contents for packet injection and command inspection instead of dropping to an empty ledger.
- Rehydration no longer replays pre-snapshot transcript entries, which avoids rebuilding stale state on top of a newer snapshot.
- The `/ctx-mode` fix is narrowly scoped to `turn_end`; public commands and extension hook API stay unchanged.
## Concerns
- None with the fix itself.
- The worktree still contains unrelated untracked historical review files under `.pi/reviews/`; they were left untouched and excluded from the focused commit.

View File

@@ -0,0 +1,44 @@
# Context Manager Task 6 Fix Report
## Status
- Completed
- Task 6 review findings addressed in the context-manager extension
- Verification commands requested in the task were run and passed
## Changes
- Added authoritative branch rebuild logic in `.pi/agent/extensions/context-manager/index.ts`.
- Syncs the runtime context window
- Reads the latest valid snapshot from `ctx.sessionManager.getBranch()`
- Restores snapshot metadata with an empty ledger
- Replays `user`, `assistant`, and `toolResult` messages from the active branch into the runtime
- Refreshes the footer status from the rebuilt runtime
- Hooked that rebuild logic into:
- `session_start`
- `turn_end` (before snapshot persistence)
- `session_tree`
- Kept incremental `tool_result` ingestion for in-turn responsiveness, but the branch rebuild is now authoritative at synchronization points.
- Tightened some extension-boundary typing in `index.ts` while making the fix.
- Replaced the shallow registration-only test with integration-style coverage that exercises the registered handlers.
## Tests
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npx tsx --test src/extension.test.ts`
- Passed: 3/3
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npm test`
- Passed: 38/38
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension && git diff --check -- .pi/agent/extensions/context-manager/index.ts .pi/agent/extensions/context-manager/src/extension.test.ts`
- Passed with no diff/whitespace errors
## Files Changed
- `.pi/agent/extensions/context-manager/index.ts`
- `.pi/agent/extensions/context-manager/src/extension.test.ts`
- `.pi/reviews/context-manager-task6-fix-report.md`
## Self-review Findings
- `turn_end` now persists snapshots built from the actual current branch, so the ledger includes facts extracted from branch `user` and `assistant` messages instead of depending on `tool_result` events alone.
- `session_tree` now resets runtime state immediately after navigation, so the next `context` packet reflects the destination branch instead of the abandoned one.
- The new tests invoke real registered handlers and verify behavior, not just registration names.
- Public command names and extension surface area remained unchanged.
## Concerns
- No blocking concerns.
- Note: branch-local mode changes made via `/ctx-mode` are still persisted on the next `turn_end` snapshot. If a branch has no snapshot yet, restoration falls back to default branch state until a snapshot exists. This was left unchanged to keep the Task 6 fix focused.

View File

@@ -0,0 +1,48 @@
# Context Manager Task 6 Implementer Report
## Status
Implemented and verified.
## What you implemented
- Wired the context manager runtime into the extension entrypoint in `.pi/agent/extensions/context-manager/index.ts`.
- Registered the required slash commands through new `src/commands.ts`:
- `/ctx-status`
- `/ctx-memory`
- `/ctx-refresh`
- `/ctx-compact`
- `/ctx-mode`
- Registered the required pi hooks in `index.ts`:
- `session_start`
- `tool_result`
- `turn_end`
- `context`
- `session_before_compact`
- `session_before_tree`
- Added `src/extension.test.ts` to verify the extension registers the expected commands and hooks.
## What you tested and results
1. Wrote `src/extension.test.ts` first and ran:
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npx tsx --test src/extension.test.ts`
- Result before implementation: **FAIL** as expected because the extension registered no commands/hooks yet.
2. Ran the required targeted test again after implementation:
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npx tsx --test src/extension.test.ts`
- Result: **PASS**
3. Ran the full package test suite:
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npm test`
- Result: **PASS** (`36` tests passed, `0` failed)
## Files changed
- Modified: `.pi/agent/extensions/context-manager/index.ts`
- Created: `.pi/agent/extensions/context-manager/src/commands.ts`
- Created: `.pi/agent/extensions/context-manager/src/extension.test.ts`
- Created: `.pi/reviews/context-manager-task6-implementer-report.md`
## Self-review findings
- Implementation matches the required command names and hook names exactly.
- The runtime is restored from persisted snapshots on `session_start` and persisted again on `turn_end`.
- The context hook prunes bulky tool results and injects the built packet as a hidden custom message only when packet text exists.
- Compaction and tree hooks delegate summary generation to the runtime helpers without introducing unrelated scope.
## Any concerns
- No functional concerns with Task 6 implementation.
- The worktree already contained unrelated untracked review artifacts before this task; they were not part of this implementation.

View File

@@ -0,0 +1,20 @@
# Context Manager Task 6 Mode Fix Report
- **Status:** DONE
- **Changes:**
- Updated `.pi/agent/extensions/context-manager/src/commands.ts` so a successful `/ctx-mode` immediately appends a serialized `context-manager.snapshot` entry after `runtime.setMode(...)`.
- Kept the public command contract stable: the command name is unchanged, the invalid-usage warning string is unchanged, and the existing `turn_end` snapshot persistence path is still active.
- Added an integration-style regression test in `.pi/agent/extensions/context-manager/src/extension.test.ts` that starts from a `balanced` snapshot, runs `/ctx-mode aggressive`, and verifies the branch immediately persists a new snapshot with `mode: "aggressive"` before any `turn_end`.
- Updated the existing `/ctx-mode` + `turn_end` test to assert both snapshots: the immediate command-path snapshot and the later `turn_end` snapshot with refreshed token pressure data.
- **Tests:**
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npx tsx --test src/extension.test.ts` → 5 passed, 0 failed
- `cd /home/alex/dotfiles/.worktrees/context-manager-extension/.pi/agent/extensions/context-manager && npm test` → 40 passed, 0 failed
- **Files changed:**
- `.pi/agent/extensions/context-manager/src/commands.ts`
- `.pi/agent/extensions/context-manager/src/extension.test.ts`
- `.pi/reviews/context-manager-task6-mode-fix-report.md`
- **Self-review findings:**
- The fix is narrowly scoped to the `/ctx-mode` success path and reuses the existing snapshot serializer and append-entry persistence mechanism.
- The regression coverage exercises the actual command path instead of only verifying later `turn_end` behavior.
- `turn_end` persistence remains intact and now appends a fresh follow-up snapshot with updated token usage, which is explicitly covered by the adjusted integration test.
- **Concerns:** None.