From 54ee2a57ebbbabf1e13d8a7e132d0f5f0efc83fa Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Sun, 15 Nov 2026 19:27:40 +0100 Subject: [PATCH] docs: add session log, learnings, and glossary Devlog for the 4-round reviewer-fanout audit with decisions and gotchas; AGENTS.md gains GitNexus code-intelligence boilerplate plus Project Learnings and Session Logs sections; GLOSSARY.md defines warn/force tiers and the compaction cycle. --- AGENTS.md | 63 +++++++++++++++++++ GLOSSARY.md | 18 ++++++ ...115-reviewer-fanout-audit-hardening_log.md | 59 +++++++++++++++++ docs/devlog/INDEX.md | 8 +++ 4 files changed, 148 insertions(+) create mode 100644 AGENTS.md create mode 100644 GLOSSARY.md create mode 100644 docs/devlog/20261115-reviewer-fanout-audit-hardening_log.md create mode 100644 docs/devlog/INDEX.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..448011b --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,63 @@ + +# GitNexus — Code Intelligence + +This project is indexed by GitNexus as **smart-compact** (44 symbols, 65 relationships, 2 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely. + +> Index stale? Run `node .gitnexus/run.cjs analyze` from the project root — it auto-selects an available runner. No `.gitnexus/run.cjs` yet? `npx gitnexus analyze` (npm 11 crash → `npm i -g gitnexus`; #1939). + +## Always Do + +- **MUST run impact analysis before editing any symbol.** Before modifying a function, class, or method, run `impact({target: "symbolName", direction: "upstream"})` and report the blast radius (direct callers, affected processes, risk level) to the user. +- **MUST run `detect_changes()` before committing** to verify your changes only affect expected symbols and execution flows. For regression review, compare against the default branch: `detect_changes({scope: "compare", base_ref: "main"})`. +- **MUST warn the user** if impact analysis returns HIGH or CRITICAL risk before proceeding with edits. +- When exploring unfamiliar code, use `query({query: "concept"})` to find execution flows instead of grepping. It returns process-grouped results ranked by relevance. +- When you need full context on a specific symbol — callers, callees, which execution flows it participates in — use `context({name: "symbolName"})`. + +## Never Do + +- NEVER edit a function, class, or method without first running `impact` on it. +- NEVER ignore HIGH or CRITICAL risk warnings from impact analysis. +- NEVER rename symbols with find-and-replace — use `rename` which understands the call graph. +- NEVER commit changes without running `detect_changes()` to check affected scope. + +## Resources + +| Resource | Use for | +|----------|---------| +| `gitnexus://repo/smart-compact/context` | Codebase overview, check index freshness | +| `gitnexus://repo/smart-compact/clusters` | All functional areas | +| `gitnexus://repo/smart-compact/processes` | All execution flows | +| `gitnexus://repo/smart-compact/process/{name}` | Step-by-step execution trace | + +## CLI + +| Task | Read this skill file | +|------|---------------------| +| Understand architecture / "How does X work?" | `.claude/skills/gitnexus/gitnexus-exploring/SKILL.md` | +| Blast radius / "What breaks if I change X?" | `.claude/skills/gitnexus/gitnexus-impact-analysis/SKILL.md` | +| Trace bugs / "Why is X failing?" | `.claude/skills/gitnexus/gitnexus-debugging/SKILL.md` | +| Rename / extract / split / refactor | `.claude/skills/gitnexus/gitnexus-refactoring/SKILL.md` | +| Tools, resources, schema reference | `.claude/skills/gitnexus/gitnexus-guide/SKILL.md` | +| Index, status, clean, wiki CLI commands | `.claude/skills/gitnexus/gitnexus-cli/SKILL.md` | + + + +## Project Learnings + + + +### Testing +- Run `node --test harness.ts` after any `index.ts` change — the harness imports the extension and covers every guard path (thresholds, locks, cooldown, validation) (`20261115-reviewer-fanout-audit-hardening`) + +### Audit Conventions +- Treat `~/.pi/agent/settings.json` and project `.pi/settings.json` as trusted operator input — config validation is robustness, not a security boundary (audit ruling, `20261115-reviewer-fanout-audit-hardening`) + +## Session Logs + +Session logs live in `docs/devlog/` (one per completed task/issue/milestone). Full history: [`docs/devlog/INDEX.md`](docs/devlog/INDEX.md). The 10 most recent: + + +| Date | Log | +|------|-----| +| 2026-11-15 | [20261115-reviewer-fanout-audit-hardening_log.md](docs/devlog/20261115-reviewer-fanout-audit-hardening_log.md) | + \ No newline at end of file diff --git a/GLOSSARY.md b/GLOSSARY.md new file mode 100644 index 0000000..eded355 --- /dev/null +++ b/GLOSSARY.md @@ -0,0 +1,18 @@ +# Glossary + +Domain terms for the smart-compact extension. + +## Terms + +## Discovered Terms + + + +### Warn tier +Tier 1: a one-shot `custom_message` injected at `turn_end` once per compaction cycle when context crosses `min(warnTokens, warnFraction × window)` — invisible in the UI (`display: false`), nudges the agent to be economical. + +### Force tier +Tier 2: `ctx.compact()` triggered from `agent_settled` (idle-guaranteed boundary) when context crosses `min(forceTokens, forceFraction × window)` — never from `turn_end`, because manual compaction aborts the active run and never resumes it. + +### Compaction cycle +The span between compactions. `session_compact` (any cause: manual `/compact`, forced, threshold, overflow recovery) resets the warn flag, the in-flight lock, and the cached token count; guards fire at most once per cycle. diff --git a/docs/devlog/20261115-reviewer-fanout-audit-hardening_log.md b/docs/devlog/20261115-reviewer-fanout-audit-hardening_log.md new file mode 100644 index 0000000..0459a67 --- /dev/null +++ b/docs/devlog/20261115-reviewer-fanout-audit-hardening_log.md @@ -0,0 +1,59 @@ +# Reviewer-fanout audit of smart-compact initial commit + +> **Date:** 2026-11-15 +> **Type:** generic +> **Reference:** commit `2c6d989` (initial) → working tree; review rounds 1–4 + +## Goal + +Audit the smart-compact extension (two-tier context management for Pi) with a fresh-context reviewer fanout — one reviewer each for ponytail-review, security-review, and review — then fix every accepted finding and repeat until all reviewers report no issues. + +## What Was Done + +- Ran 4 review rounds via `runs.all([...])` fanout (3 reviewer children per round, `context: "fresh"`, read-only, diff artifacts materialized to `/tmp`). +- Fixed 12 accepted findings total; round 4 returned "No issues found" from all three reviewers. +- `index.ts` — force tier moved from `turn_end` to `agent_settled` (manual compaction aborts active runs); settled handler now awaits compaction completion; per-field config validation with default fallback; `lastKnownTokens` cleared on `session_compact`; deleted duplicate `SmartCompactUserConfig` interface (use `Partial`); removed unreachable `"DISABLED"` status branch. +- `harness.ts` — new committed mock harness, 15 tests, `node --test harness.ts`, 15/15 green (Node 26.12.1, type stripping). +- `README.md` — corrected precedence claim (threshold ordering ≠ execution ordering), documented `agent_settled` trigger, honest verification section. +- Rebuilt GitNexus index (44 nodes, 65 edges, 2 flows) — generated `AGENTS.md`/`CLAUDE.md`/`.claude/` boilerplate alongside. + +## Decisions & Rationale + +| Decision | Rationale | +|----------|-----------| +| Force tier fires on `agent_settled`, never `turn_end` | Pi 1.5.2 `AgentSession.compact()` aborts the active run and never resumes the interrupted turn (`dist/core/agent-session.js:2321–2327`); built-in mid-run compaction preserves the run instead. `agent_settled` is idle-guaranteed (`ctx.isIdle()` true), so compaction aborts nothing. | +| Settled handler awaits compaction completion (promise around `onComplete`/`onError`) | `ctx.compact()` returns immediately; prompts deferred from settled handlers (and print-mode message loops) otherwise race an in-flight compaction and can be rejected. Awaiting also keeps the in-flight lock honest. | +| Built-in threshold stays the mid-run actor; docs claim narrowed | `(1 − forceFraction) × window > reserveTokens` orders thresholds, not execution — a run crossing both before settling lets Pi compact first. Safe: it preserves the run. | +| Per-field config validation (finite positive tokens, fractions in (0,1), boolean enabled; fall back to defaults) | `forceTokens: null` made `Math.min(null, …) → 0` (compaction every turn); non-numeric strings → `NaN` silently disabled tiers. Robustness, not security (trust ruling below). | +| Settings files ruled trusted operator input | Locally-installed extension; repo write access already implies stronger channels (AGENTS.md instructions, source itself). Security reviewer filed validation as robustness only. | +| Harness = `node:test` + type stripping, zero deps | Node ≥ 22.18 runs `.ts` natively; keeps "single file, no dependencies" property of the extension. Config injected via temp project `.pi/settings.json` (all fields set, so global user config can't leak into assertions). | + +## Gotchas & Fixes + +| Problem | Root Cause | Fix | +|---------|------------|-----| +| Reviewer children blocked asking for `git show` artifacts (3 supervisor requests) | Reviewer agents have no shell/git; `watchdog_diff` excludes committed ranges | Materialize diffs to `/tmp/*.diff` up front; for untracked files use `git add -N` (intent-to-add) so `git diff HEAD` includes them | +| `subagent({workflow: true})` rejected: "no text" / reads only the calling message | The ```js workflow block must be in the SAME message as the call | Re-issue with `options: { script: "..." }` instead of `workflow: true` | +| Harness deadlocked after the await fix (test run hung 120s) | The in-flight-lock test awaited a handler whose mock compaction never calls a callback — the awaited promise never settles | Don't await never-settling handler promises in tests; fire without awaiting, then assert the lock blocks the second call | +| `edit` replace failed on header comment | `old_text` dropped two leading spaces (` * ` comment continuation) — exact match required | Re-read the region, edit via LINE:HASH anchors (`set_line`/`replace_lines`) | + +## Files Changed + +| File | Change Summary | +|------|----------------| +| `index.ts` | Force tier → `agent_settled` with awaited compaction; config validation; token-cache clearing; interface dedupe; dead branch removed | +| `README.md` | Corrected trigger docs, precedence caveat, guards, verification section | +| `harness.ts` | New: 15-test mock harness (`node --test harness.ts`) | +| `AGENTS.md` | GitNexus boilerplate + Session Logs / Project Learnings sections | +| `CLAUDE.md`, `.claude/` | Generated by `gitnexus analyze` (boilerplate mirror + skills copies) | +| `docs/devlog/` | This log + INDEX.md | + +## Open Items & Next Steps + +- [ ] Live-session validation of the first real warn crossing (100k) and first force compaction at settle — wording of the notice message may need tuning (`index.ts` single string) +- [ ] Policy decision: keep regenerating vs gitignoring `CLAUDE.md`/`.claude/` on future `gitnexus analyze` runs +- [ ] Consider a `pi -p` end-to-end smoke test script if the harness ever grows beyond mock-level + +--- + +*Log written by write-log skill* diff --git a/docs/devlog/INDEX.md b/docs/devlog/INDEX.md new file mode 100644 index 0000000..0202eb7 --- /dev/null +++ b/docs/devlog/INDEX.md @@ -0,0 +1,8 @@ +# Session Log Index + +Complete history of session logs in this directory, newest first. One-line summaries — open a log for full detail. + + +| Date | Type | File | Summary | +|------|------|------|---------| +| 2026-11-15 | generic | [20261115-reviewer-fanout-audit-hardening_log.md](20261115-reviewer-fanout-audit-hardening_log.md) | Reviewer fanout converged in 4 rounds: force tier moved to agent_settled, config validated, 15-test harness added |