--- name: ai-agents-docs-of-record version: 1.0.0 license: Apache-2.0 description: "Runbook for documents of record: session logs, ADRs, retrospectives, Serena memories, handoffs. Use when you say `write the session log`, `fill the retro`, or `save this to memory`. Do NOT use to write an ADR (use `adr-generator`), author skills (use `SkillForge`), or write research (use `ai-agents-research-methodology`)." metadata: distribution: repo-local routing: role: conditional-adjunct invoker: ai-agents-research-methodology trigger: ai-agents-research-methodology routes write-ups through the documents of record user-facing: false --- # ai-agents-docs-of-record This repo runs on verification-based governance. Continuity lives in per-issue handoffs and Serena memory. Session log creation is discontinued; transcript and pull request evidence remain valid, and the ~1,500 historical logs under `.project-toolkit/sessions/` stay in the repo as history. ## Triggers - `write the session log` - `fill the retro` - `save this to memory` - `which document of record does this go in` ## The Record System Map | Record | Location | Create with | Validated by | |--------|----------|-------------|--------------| | Session log (historical only, creation discontinued) | `.project-toolkit/sessions/YYYY-MM-DD-session-NN[-slug].json` | do not create new ones | `scripts/validate_session_json.py`, validate-if-present via the `session-policy` pre-commit hook, applies only if one is somehow staged | | Per-issue handoff | `.project-toolkit/sessions/handoffs/{YYYY-MM-DD}-{ISSUE}-handoff.md` | copy `.agents/templates/HANDOFF.md` | resume-verification checklist at next session start | | ADR | `.project-toolkit/architecture/ADR-NNN-slug.md` | `adr-generator` skill | `scripts/validation/check_adr_uniqueness.py`; `adr-review` debate gate | | Retrospective | `.project-toolkit/retrospective/` | `retrospective` skill on one of the four triggers (HIGH-tier reflect finding, `main` red, reverted or force-fixed merge, explicit user correction), or `/retrospective fill` on a historical skeleton | `INDEX.md` row (auto-appended, incomplete; see Phase 4) | | Serena memory | `.serena/memories/[domain]-[name].md` | `memory` skill write conventions | `memory` skill, references/curating-memories.md; `memory-index` routing | ## Process ### Phase 1: Pick the right record | Situation | Record | Why | |-----------|--------|-----| | Issue spans multiple sessions | Per-issue handoff | Cold-start continuity (95.8% protocol failure without file-based gates) | | Architectural or irreversible decision | ADR | Fires `adr-review` multi-agent debate | | Incident, failure, or "what went wrong" | Retrospective | Feeds the failure canon; see `ai-agents-failure-archaeology` | | Reusable pattern, correction, gotcha | Serena memory | Only memories are read by future sessions at start | | User corrected you mid-session | `reflect` skill, then memory | Corrections not persisted are lost | | A doc you touched is stale | Fix on contact (Phase 7) | Broken-windows rule | One fact can need two records: an incident gets a retrospective AND a memory distilling the rule. The retro is the evidence; the memory is the searchable lesson. ### Phase 2: Session logs (historical only) Session log creation is discontinued (`.claude/rules/session-logs.md` MUST 1): do not create a new `.project-toolkit/sessions/*.json` file. The ~1,500 existing logs stay in the repo as history, schema at `.agents/schemas/session-log.schema.json` (top-level required: `session`, `protocolCompliance` with `sessionStart` and `sessionEnd` subsections), and remain readable by `retrospective`, memory extraction, and the PreCompact hook. If a historical log is staged anyway (for example, cherry-picked from an older branch), it still needs to pass: ```bash uv run python3 scripts/validate_session_json.py .project-toolkit/sessions/.json ``` Hard requirements enforced by `scripts/validate_session_json.py`: - Required `session` fields: `number`, `date`, `branch`, `startingCommit`, `objective`. - Branch must match `^(feat|fix|docs|chore|refactor|test|ci)/`. - `startingCommit` must be a 7-40 char lowercase hex SHA. Historical naming may carry a slug: `2026-06-30-session-2600-skill-tooling-hygiene-taste-lints-naming.json`. Never resolve a session-log merge conflict with `git checkout --ours`; the settled rule from the session 1187 incident is take `--theirs` and rename your own log to the next free number (see `ai-agents-failure-archaeology`). ### Phase 3: ADRs Numbering collides here; treat numbers as claims, not identity. History: concurrent ADR PRs each picked the same "next" number, and ADR-058/062/063 each existed twice until the duplicates were renumbered to 069/070/071 (per the docstring of `scripts/validation/check_adr_uniqueness.py`). ADR-055 and ADR-024 share the slug `github-actions-runner-selection` (055 supersedes 024). Rule: when citing an ADR, verify the file content says what you claim, not just the number. ```bash ( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/ai-agents-docs-of-record/scripts/instruments.py --repo . run adr-next-number; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 ) ``` This runs `scripts/validation/check_adr_uniqueness.py --print-next` and prints the next free ADR number. It does not check that a cited ADR says what you claim. Workflow: 1. Search first: `memory-search` for prior decisions, then read neighbors in `.project-toolkit/architecture/` (ADR-007 memory-first: retrieval precedes reasoning). 2. Generate with `adr-generator` against `.project-toolkit/architecture/ADR-TEMPLATE.md`. 3. Claim the number from `--print-next` at the last moment before commit. 4. Expect the gate: any `ADR-*.md` create or edit fires the `adr-review` multi-agent debate (AGENTS.md, "ADR Review"). Governance-level changes also need human approval (AGENTS.md Boundaries: "Ask First: Architecture|New ADRs|Breaking|Security"). 5. Lifecycle frontmatter per ADR-073 (accepted 2026-06-19): optional, unenforced Phase-1 fields `id`, `status`, `date`, `decision-makers`, `supersedes`, `superseded-by`, `explainer`, `implemented`. Use them on new ADRs; do not backfill mechanically. ### Phase 4: Retrospectives Two skills, different jobs. `reflect` captures corrections and praise mid-conversation while context is hot. `retrospective` produces the full artifact (timeline, Five Whys, learning matrix) in `.project-toolkit/retrospective/`. Retrospectives are written on demand with `/retrospective`. The Post-PR Retrospective workflow was deleted on 2026-11-25. Until a later change a Stop hook also wrote a skeleton at session end stamped ``; that hook is deleted, but skeletons it already wrote are still placeholders rather than records, so fill them with `/retrospective fill YYYY-MM-DD`. `INDEX.md` was auto-appended by that hook and is incomplete: it covers 11 of 241 retro files at 42e409325 (2026-10-31). Nothing appends to it now. Never treat INDEX.md as the catalog; list the directory. Also note retro-cited short SHAs do not resolve locally even with full history present (~1471 commits as of 2026-07-03), so retros and memories, not git archaeology, are the durable history (depth in `ai-agents-failure-archaeology`). Retro learnings MUST be persisted to Serena in the same session, not left as prose in the artifact (`.serena/memories/agent-behavior/retrospective-accuracy.md`: "learnings were proposed in the retrospective but then not persisted to Serena, so they will be lost"). ### Phase 5: Serena memories Write conventions (canonical text: `.claude/skills/memory/SKILL.md`, "Serena Write Conventions"): - File name: `[domain]-[descriptive-name].md`, lowercase, hyphens. Example: `pr-review-security.md`. - Entity ID inside the file: `{domain}-{description}`, kebab-case, no prefix. File name and entity ID are separate things; do not conflate them. - Domain index files (`skills-*-index.md`) are a two-column table ONLY. Insert new rows AFTER the last existing data row, never after the header or delimiter row. - Register new memories where `memory-index` (the keyword-to-memory routing map read at session start) will find them. Curation (marking obsolete, dedupe, bidirectional links) is the `memory` skill's references/curating-memories.md. Search is `memory-search` (Tier 1). ADR-063 split the memory skill by operation; ADR-089 removed Tier 3, so the live tiers are Tier 1 and Tier 2. Separate-PR rule: `.claude/rules/claude-agents.md` MUST NOT item 2: "MUST NOT bundle skill code changes with memory changes in the same PR (separate concerns)." Memory edits ride their own PR. The cautionary tale is the scope-explosion PR, where 53 memory files changed in a PR that started as one CI fix (`.project-toolkit/retrospective/2026-01-15-pr-908-comprehensive-retrospective.md`). ### Phase 6: Handoffs Tier model per ADR-014 and `.project-toolkit/sessions/handoffs/README.md`: | Tier | Location | Scope | |------|----------|-------| | Session log | `.project-toolkit/sessions/*.json` | Historical only; creation discontinued | | Per-issue handoff | `.project-toolkit/sessions/handoffs/{date}-{issue}-handoff.md` | One issue across sessions; rewritten each session | | Per-branch handoff | `.project-toolkit/handoffs/{branch}/{session}.md` | Multi-session branch coordination | Start from the template `.agents/templates/HANDOFF.md`. A handoff must carry a "Verification on Resume" checklist; the next session executes it before it changes any file. The old project-wide `.agents/HANDOFF.md` dashboard is deleted: it had grown to 122KB with an 80%+ per-PR merge conflict rate before ADR-014 froze it, and per-issue handoffs plus Serena memory now carry the continuity it used to (`.project-toolkit/architecture/ADR-014-distributed-handoff-architecture.md:13-16`). ### Phase 7: House style and stale docs Prose rules (canonical: `.claude/rules/voice.md`, `.claude/rules/universal.md`): - Lead with the point. Name file, line, command, number, or say you do not know. - No em-dashes or en-dashes anywhere in authored text (universal.md MUST NOT item 4; only `tests/hooks/fixtures/` is exempt). Every dash costs a bot review thread. - No banned vocabulary (voice.md "Banned Vocabulary" section). - No auto-generated headers or timestamps-as-headers in any authored or generated file (universal.md MUST NOT item 5; rejected by the user three times as of 2025-12-17). - Block-style YAML arrays only in frontmatter (`.agents/governance/PROJECT-CONSTRAINTS.md`, Frontmatter constraints table; ADR-040 Amendment). Inline `['a', 'b']` breaks Copilot CLI parsing. - Run `prose-self-check` before emitting any session-log narrative, ADR context section, retro, or PR description. The following text defines these rules: Use commas, periods, colons, parentheses, hyphens, or restructure. Do not use these words in prose. They mark AI output and add nothing: `delve`, `crucial`, `robust`, `comprehensive`, `nuanced`, `multifaceted`, `furthermore`, `moreover`, `additionally`, `pivotal`, `landscape`, `tapestry`, `underscore`, `foster`, `showcase`, `intricate`, `vibrant`, `fundamental`, `significant`. Replacements: be specific instead. "Robust error handling" becomes "handles network timeout, schema mismatch, and partial write." "Significant performance improvement" becomes "p99 drops from 1.2s to 180ms." MUST NOT add auto-generated headers, generation timestamps, or "do not edit" comments to any file. Generated output must read as hand-written: headers waste tokens and hide the content. If a script emits one, delete the emitter. Markdown lint is SCOPED to files you changed. The scope-explosion PR Five Whys traced 53 unrelated memory-file changes to `markdownlint --fix **/*.md` run repo-wide (retro, Q1-Q4). Lefthook filters staged Markdown and runs the named validator declared in `lefthook.yml`. Config is `.markdownlint-cli2.yaml`. Never widen the glob. Mirror claims (FM-9): any statement that a file "matches", "mirrors", or "aligns with" another source MUST cite the canonical path and quote the load-bearing fragment character-for-character; intentional divergence gets a named divergence section (`.agents/governance/FAILURE-MODES.md`, failure mode 9; rule text in `.claude/rules/canonical-source-mirror.md`; heuristic gate `scripts/validation/check_canonical_citations.py`, warn-only unless `STRICT_CANONICAL_CHECK=1`). Cost of ignoring it: one PR took 7 fix commits on confident-incorrectness claims. Fix stale docs on contact. Worked example from before commit b320f4ac1: `CONTRIBUTING.md` line 155 said `build/Generate-Agents.ps1` PowerShell invocation until that commit repointed it to `build/generate_agents.py`. Zero `.ps1` build scripts exist (ADR-042 Python migration). When you touch a stale doc: fix the lines on your path, quote the canonical source per FM-9, and flag (do not silently expand into) the rest. Behavioral claims in docs are verified with `doc-accuracy`. ## Anti-Patterns | Anti-pattern | Why it burns you | Evidence | |--------------|------------------|----------| | Creating any new session log | Session log creation is discontinued | `.claude/rules/session-logs.md` MUST 1 | | Trusting an ADR number without reading the file | Numbers collided (058/062/063 dupes; 024 vs 055 same slug) | `check_adr_uniqueness.py` docstring | | Repo-wide `markdownlint --fix` | Reformatted 53 unrelated memory files in the scope-explosion PR | Scope-explosion retro Five Whys | | Bundling memory changes with skill code in one PR | Violates `claude-agents.md` MUST NOT 2; scope explosion | Scope-explosion retro | | "Matches X" without a verbatim quote | FM-9 confident-incorrectness; 7 fix commits on one PR | FAILURE-MODES.md section 9 | | Leaving learnings only in the retro artifact | Never read by future sessions | `retrospective-accuracy` memory | | Treating INDEX.md or `git log` as complete history | INDEX.md covers a fraction of the retro files (run `retro-index-coverage`); retro-cited SHAs do not resolve locally | Phase 4 | | `git checkout --ours` on session-log conflicts | Corrupted the main session log once | session 1187 incident | | Em/en dashes, banned vocab, generated headers | One bot thread per dash, every PR | universal.md MUST NOT 4 and 5 | ## Verification Before ending any session that produced records: - [ ] Any staged or supplied session log passes `uv run python scripts/validate_session_json.py `. - [ ] Any new ADR number came from `check_adr_uniqueness.py --print-next` and the `adr-review` gate ran. - [ ] Retro learnings are persisted as Serena memories, not just prose in the retro file. - [ ] New memories follow `[domain]-[name].md` naming and their index row sits after the last data row. - [ ] Open-issue work has a per-issue handoff with a Verification on Resume checklist. - [ ] `grep -rPn '[\x{2013}\x{2014}]' ` returns nothing; lint ran scoped to changed files only. - [ ] Every "matches/mirrors" claim quotes its canonical source verbatim. ## Scripts `scripts/instruments.py` lists and runs the checks this skill links (ADR next number, retro index coverage, session-log validation, drift). Exit codes: 0 ok, 1 a listed instrument file is missing, 2 bad arguments or unknown id, 3 the run target failed to start. A `run` passes the child exit code through unchanged. ```bash ( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/ai-agents-docs-of-record/scripts/instruments.py --repo . list; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 ) ( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/ai-agents-docs-of-record/scripts/instruments.py --repo . run ; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 ) ``` ## Provenance and Maintenance Verified 2026-10-31 (HEAD 42e409325) against the working tree. Re-verify volatile facts before relying on them: | Fact | Source | Re-verify | |------|--------|-----------| | Session-log creation discontinued | `.claude/rules/session-logs.md` MUST 1 | `grep -n "Do not create a new session log" .claude/rules/session-logs.md` | | Branch naming pattern | `scripts/validate_session_json.py` (`BRANCH_PATTERN`) | `grep -n "^BRANCH_PATTERN = re.compile" scripts/validate_session_json.py` | | Schema required keys, top level and nested session | `.agents/schemas/session-log.schema.json` | `python3 -c "import json;s=json.load(open('.agents/schemas/session-log.schema.json'));print(s['required'], s['properties']['session']['required'])"` | | ADR collision history, next-number helper | `scripts/validation/check_adr_uniqueness.py` docstring | `instruments.py run adr-next-number` | | ADR-073 lifecycle fields (`implemented`) | `.project-toolkit/architecture/ADR-073-adr-lifecycle-frontmatter.md:1-9` | `head -10 .project-toolkit/architecture/ADR-073-adr-lifecycle-frontmatter.md` | | adr-review fires on ADR edits | `AGENTS.md` "ADR review" (line 12) | `grep -n "ADR review" AGENTS.md` | | Auto-retro skeleton + marker + /retrospective fill | `.claude/skills/retrospective/references/skeleton-fill.md` (RETRO-STATE marker) | `grep -n "RETRO-STATE" .claude/skills/retrospective/references/skeleton-fill.md` | | Retro corpus size vs INDEX.md coverage | `.project-toolkit/retrospective/` | `( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/ai-agents-failure-archaeology/scripts/corpus_index.py --repo .; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )` | | Memory naming + index-row hazard | `.claude/skills/memory/SKILL.md` "Serena Write Conventions" | `grep -n "Serena Write Conventions" .claude/skills/memory/SKILL.md` | | Memory/skill separate-PR rule | `.claude/rules/claude-agents.md` MUST NOT item 2 | `grep -n "same PR" .claude/rules/claude-agents.md` | | Handoff tiers (session log, per-issue, per-branch) | `.project-toolkit/sessions/handoffs/README.md` tier table; ADR-014 | `grep -n "Tier" .project-toolkit/sessions/handoffs/README.md` | | FM-9 verbatim-quote rule | `.agents/governance/FAILURE-MODES.md:288-311` | `grep -n "character-for-character" .agents/governance/FAILURE-MODES.md` | | Scope-explosion lint scope story | `.project-toolkit/retrospective/2026-01-15-pr-908-comprehensive-retrospective.md:281-296` | `grep -n "markdownlint" .project-toolkit/retrospective/2026-01-15-pr-908-comprehensive-retrospective.md` | | CONTRIBUTING.md staleness example | Commit b320f4ac1 repointed `CONTRIBUTING.md` to `build/generate_agents.py` | `git show b320f4ac1 -- CONTRIBUTING.md` | | Serena is the only memory backend | `.project-toolkit/architecture/ADR-106-serena-only-memory-architecture.md:87` | `grep -n "the only memory backend" .project-toolkit/architecture/ADR-106-serena-only-memory-architecture.md` | Instruments (`list` shows each row and whether its file exists; `run ` passes the child exit code through): ```bash ( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/ai-agents-docs-of-record/scripts/instruments.py --repo . list; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 ) ``` Rows: `adr-next-number`, `retro-index-coverage` (exits 1 at HEAD `42e409325`, 2026-10-31, because INDEX.md covers 11 of 241 retros; read the JSON, not the exit code), `session-log-validate` (write `run session-log-validate -- ` inside the locator), and `drift-self-check`. Drift check, with `reverify.json`: `( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/skill-bootstrap/scripts/bootstrap_drift.py check --repo . --skills-root .claude/skills --name ai-agents-docs-of-record --require; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )` Maintenance: when a validator, template path, or protocol phase changes, update the matching row here in the same PR. This file is itself a document of record; it obeys everything it prescribes.