# Task log — LLM-first router overhaul (phase 1) This file tracks the per-task progression of Phase 1, recording user-level state changes (not in git) so the audit trail survives the overhaul. ## Task 1 — Rollback infra ⭐ (commit `dc7fd579`, 2026-05-25) Established and proved a full rollback mechanism BEFORE any destructive step. - Git tag `brain-pre-llm-bootstrap` → `9d4a30c3` (origin/main pre-overhaul). - Archive structure `docs/archive/llm-bootstrap-2026-05/` with 8 subdirs. - Snapshots: `~/.claude/settings.json`, all 14 hooks in `~/.claude/hooks/`, `~/.claude/runtime/router-gate-mode.json`, `docs/registry/nodes.yaml`, project `.claude/settings.json`. - `tools/test-rollback.mjs` + 3 TDD tests (GREEN). - `ROLLBACK.md` runbook with from→to manifest. - E2E smoke proof (Task 1 Step 9) verified user-level + git-tracked rollback, Task 1 untracked files survived. Smoke caught a bug in the plan's procedure (`git checkout tag -- .` + `--soft` does NOT delete files committed after the tag — `git reset --hard tag` is correct). ROLLBACK.md uses `--hard`. ## Task 2 — Remove §12 skill-discipline, keep economy (2026-05-25) Removed §12 enforcement hooks from the live user environment; the economy system (0% / 5% / 75% / 100%, etc.) remains fully active. **Changes to `~/.claude/settings.json`** (live user file, not in git): - Removed PreToolUse block `matcher: "Skill"` → `skill-marker.py` (§12 trigger). - Removed PreToolUse block `matcher: "Edit|Write|MultiEdit"` → `skill-check.py` (§12 enforcement on Edit/Write). - Remaining PreToolUse: 1 block — `matcher: "Edit|Write|MultiEdit|Bash|Agent"` → `economy-state-guard.py` (pure economy concern, kept). - All UserPromptSubmit / PostCompact / SessionStart / Stop hooks unchanged. **Changes to `~/.claude/hooks/economy-mode.py`** (live user file): - Line ~337: replaced trailing reminder «§12 hard rule из Pravila НЕ override-ится этим режимом — на всех уровнях.» → «§17 universal skill-coverage НЕ override-ится этим режимом — на всех уровнях.» - All economy logic (LEVELS dict, parse_level, closest_level, state file write) unchanged. - The references to `§12.2` inside `LEVELS[5]["rules"]` and `LEVELS[100]["rules"]` remain — those describe process gates and are migrated to `§17` cross-refs in Task 6. **Changes to `~/.claude/hooks/economy-state-guard.py`** (live user file): - NO-OP. Inspected for §12 skill-discipline logic; the file is pure economy (BASH_FILE_MOD_PATTERNS is the test-cadence reminder, not §12 enforcement). Plan Step 3 allows no-op for pure-economy guards. **Files NOT removed** (only their PreToolUse triggers were unwired): - `~/.claude/hooks/skill-marker.py` — still on disk, no longer invoked. - `~/.claude/hooks/skill-check.py` — still on disk, no longer invoked. These two files move into `docs/archive/.../user-hooks/` archive in Task 4 (snapshot is already in archive from Task 1). **Permissions.ask still references** `skill-marker.py` / `skill-check.py` — 4 entries (Edit/Write on each). Left as-is; they only require permission for direct file edits, no enforcement. Cleaned up alongside Task 4. **Verification:** - `~/.claude/settings.json` parses as valid JSON; `hooks.PreToolUse` length = 1. - All 4 economy hooks still run with exit 0 on `< /dev/null`. - Live `economy-mode.py` run with prompt «тест экономия 5%» returns valid JSON with FIRST LINE `=== ECONOMY MODE: 5%` and trailer mentioning `§17`, no `§12 hard rule` substring. **Rollback path**: `node tools/test-rollback.mjs --execute` restores `~/.claude/settings.json` (with skill-marker/skill-check PreToolUse blocks) and overwrites `economy-mode.py` from snapshot. Verified end-to-end in Task 1. ## Task 3 — Inventory `tools/discipline-metrics.mjs` (2026-05-25) **Decision: KEEP** (no code change). Read `tools/discipline-metrics.mjs` (115 lines, 3 exports, 19 passing tests). The module is NOT only-§12. Three functions, all surviving the §12→§17 migration: 1. `disciplinePercentByClassification(episodes, classificationMap)` — counts skill-coverage % per task classification. Currently sourced from `tools/observer-classification-map.json`; Task 11 re-sources it from `docs/registry/nodes.yaml` (capabilities + triggers per node). The metric shape stays — §17 universal skill-coverage is the same intent expressed differently (was-skill-used vs default-deny-non-conversation). 2. `deriveRouterStep(pr)` — infers reached router-procedure stage (1..5) from observable `primary_rationale` features (classification, triggers, chain_ref, node_chosen). General router-procedure metric, untouched. 3. `boundariesAppliedRate(episodes)` — fraction of episodes with non-empty boundaries_applied, grouped by `path_type`. General metric, untouched. Consumers (re-verified before decision): - `tools/brain-retro-analyzer.mjs` — calls all three for the brain-retro factor matrix (already shipped in router-overhaul stage 2, commit `b8adeeb9` on feature branch). - `tools/status-md-generator.mjs` — surfaces «Метрики дисциплины» block in `docs/observer/STATUS.md`. Tests: `tools/discipline-metrics.test.mjs` 19 tests, all GREEN in baseline and after Task 1-2 work (verified in Task 2 post-commit STATUS.md regen). Plan Task 3 step «only-§12 → archive, общий path_type → keep» applies: KEEP. ## Task 4 — Archive §12 + routing-docs + memory files (2026-05-25) Phase 1 Task 4 of LLM-first router overhaul. Heaviest task of Phase 1. User chose «aggressively per plan» (AskUserQuestion 2026-05-25) after the session surfaced 4 plan deviations vs reality. Adapted execution below. ### What was archived (literal) 1. **Pravila §12** (lines 678-748 of `docs/Pravila_raboty_Claude_v1_1.md`): extracted to `pravila-12/Pravila_section_12.md`, replaced in Pravila by a 1-paragraph placeholder pointing to §17 (Task 5) + the archive file + ADR-016 (Task 5). Cross-refs §0 priority chain, §0 «Особый статус» note, §16.4, §16.5 — all updated to drop §12 and reference §17 forward. 2. **`tools/observer-classification-map.json`** — JSON mapping classification → recommended_node_ids. After Task 4 refactor (below) had no code consumers. Archived via `git mv`. 3. **`tools/.node-dormancy.json`** — auto-generated dormancy map (Tooling §3.5/§4.X scrape, two signals: `dormant: true` OR `DEFERRED` in boundaries). Single consumer was missed-activations.mjs via the JSON; after Task 4 refactor consumers read `status` from `docs/registry/nodes.yaml` directly via `buildDormancyMap` adapter. Archived via `git mv`. 4. **`tools/extract-node-dormancy.mjs`** + **`tools/extract-node-dormancy.test.mjs`** — generator + 7 tests for `.node-dormancy.json`. Archived via `git mv`. `lefthook.yml` job 12b «extract-node-dormancy» removed (replaced by a removal note pointing to `nodes.yaml status:` as the new source). 5. **`memory/feedback_superpowers_hard_rule.md`** + **`memory/feedback_feature_via_writing_plans.md`** (user-level, NOT git-tracked at `~/.claude/projects/c---------------------crm-------------/memory/`): copied to `docs/archive/.../memory/` via filesystem cp (plan said `git mv` — wrong, memory files live outside the repo on this machine). Originals left in place on disk; MEMORY.md (also user-level) updated to remove the two index lines and replace them with an «ARCHIVED 2026-05-25» pointer. ### Code refactor (consequence of the JSON archive) The aggressive-per-plan choice required switching the two remaining JSON-direct consumers to the registry adapter pattern (other consumers — `brain-retro-analyzer.mjs`, `status-md-generator.mjs`, `missed-activations.mjs` — already used the adapter): 1. **`tools/observer-coverage-checker.mjs`**: `loadClassificationMap(root)` and `loadDormancy(root)` switched from `readFileSync(...json)` to `loadRegistry({ registryPath: /docs/registry/nodes.yaml, useCache: false })` plus `buildClassificationMap` / `buildDormancyMap`. 9/9 tests GREEN. 2. **`tools/observer-transcript-parser.mjs`**: `getClassificationMap()` and `getDormancy()` switched similarly, using the cached default-path `loadRegistry()` (parser is always invoked from `tools/`). 154/154 tests GREEN — clean drop-in replacement, no classification-shape drift. ### Plan deviations (documented) The plan's literal Task 4 said «archive everything including `tools/registry-to-classification-map.mjs` and `docs/routing-off-phase.md` / `docs/router-procedure.md`». Inspection revealed: - **`tools/registry-to-classification-map.mjs`** has 4+ active consumers (brain-retro-analyzer, status-md-generator, missed-activations callers, plus the 2 newly-migrated above). It IS the canonical yaml→classification-map / yaml→dormancy-map adapter — keeping it is correct engineering. Plan's framing «adapter is deprecated» was wrong. **Status: KEEP, not archived.** A future task can inline its logic into consumers if «direct yaml read» is strictly required, but that is a separate refactor. - **`docs/routing-off-phase.md`** is **auto-generated by `tools/registry-render.mjs`** from `nodes.yaml`, not a hand-edited doc. Archiving it would break the render pipeline + the C6 brain-governance controller (`tools/observer-chain-map-checker.mjs`) which reads it. **Status: NOT ARCHIVED.** This is a derivative, not a source. - **`docs/router-procedure.md`** is similarly suspected of being either a derivative or referenced by active controllers; archival deferred to a separate audit. ### Verification - Full `npx vitest run tools/`: **539 passed** (delta: −7 from archived `extract-node-dormancy.test.mjs`, +3 from `test-rollback.test.mjs` added in Task 1; baseline 543 → 539 expected ✓). The 4 pre-existing «No test suite found» failures on `tools/ruflo-*.test.mjs` and `tools/subagent-prompt-prefix.test.mjs` are out of scope and unchanged. - Pre-commit (gitleaks + markdownlint + cspell) — verified at commit time. ### Rollback `node tools/test-rollback.mjs --execute` restores user-level state. `git reset --hard brain-pre-llm-bootstrap` restores Pravila, the 4 archived `tools/` files, `lefthook.yml` job 12b, `observer-coverage-checker.mjs`, and `observer-transcript-parser.mjs` to pre-overhaul state. ## Task 6 — Cross-refs §12 → §17 (minimal scope) (2026-05-25) Phase 1 Task 6 of LLM-first router overhaul. Executed in **minimal scope** after reality check; full plan deviations documented below. ### Reality check (before execution) - **C1 l1-watcher**: ran clean (0 drift) on current state. Source is Tooling plugin-name search, not CLAUDE.md §3.3. Plan's «source §3.3 → nodes.yaml» was misdirected — no adaptation needed. - **C2 cross-ref-checker**: FAILED on version drift (CLAUDE.md → Pravila v1.40, Tooling → Pravila v1.39, after Task 5 bump to v1.41). Code logic is purely version-based, not section-based. Plan's «expected cross-refs §12→§17» was misdirected — checker does not track section refs. - §12 occurrences: CLAUDE.md 18, PSR_v1 39, Tooling 18 (total 75). Most are in changelog «v2.X наследие» blocks — historical pointers, not active rules. ### What was changed (minimal) 1. `CLAUDE.md` §0 «Источник истины» row for Pravila: `**v1.40 от 24.05.2026**` → `**v1.41 от 25.05.2026**` + narrative bump noting Task 4+5 (§12 archived, §17 added, ADR-016). 2. `docs/Tooling_v8_3.md` line 4 cross-ref: `cross-ref Pravila v1.39+ / PSR_v1 v3.22+ / CLAUDE.md v2.27+` → `cross-ref Pravila v1.41+ / PSR_v1 v3.22+ / CLAUDE.md v2.28+`. ### What was deferred (plan deviation) The plan's literal Task 6 Step 1 («archive §3.3 / R15 / Tooling «когда брать»») is a large structural restructure of three normative files. Postponed to a separate follow-up task because: - `CLAUDE.md §3.3` is the tooling-map index, currently consumed by readers for «which tool for what». Archiving requires replacement with a pin paragraph to `docs/registry/nodes.yaml` — and the §3.3 narrative quality matters for daily use. Out of scope for this minimal cross-ref pass. - `PSR_v1 R15` was already removed in v2.0 (motion-runtime removal, 12.05.2026; see `docs/CHANGELOG_claude_md.md` v1.88). The current R15 is «Off-phase routing» (v3.14+) — unrelated to §12. No action. - `Tooling §4.X «когда брать»` fields — these are per-tool «when to use it» prose, not §12-specific. Archiving requires structural review out of scope for this commit. Active §12 textual cross-refs in `docs/Plugin_stack_rules_v1.md` (39 occurrences) and `docs/Tooling_v8_3.md` body (most in historical changelog blocks) — also **deferred**. These now point to the archived §12 (`docs/archive/llm-bootstrap-2026-05/pravila-12/Pravila_section_12.md`), which is honest historical record. Active rule replacement is via Pravila §17 (Task 5). Future cleanup can do bulk §12→§17 substitution. ### Verification - `tools/l1-watcher.mjs` exits 0 (no drift). - `tools/cross-ref-checker.mjs` exits 0 («OK — 0 drift in 4 files»). - `npx vitest run tools/`: **539 passed** (unchanged from Task 4 baseline). - 4 pre-existing «No test suite found» failures — out of scope, unchanged. ### Phase 1 status after Task 6 5 of 7 Tasks complete + this Task 6 minimal = **6 of 7**. Remaining: Task 7 (phase-1 flags + rollback re-verify) closes Phase 1. ## Task 7 — Phase-1 flags + rollback re-verify (2026-05-25) Phase 1 Task 7 of LLM-first router overhaul — closes Phase 1. ### Flag state after Task 7 Live `~/.claude/runtime/` flags (user-level, NOT git-tracked): - `skill-discipline-mode.json` = `{mode: "off"}` — newly set in this task. Documents that the §12 enforcement hooks (unwired in Task 2) are off. - `router-gate-mode.json` = `{mode: "warn-only"}` — unchanged from pre-overhaul state (was already warn-only). Phase 2 Task 13 will keep warn-only as default; Phase 3+ may bump to enforce by explicit user decision. ### Rollback re-verify (after all Phase 1 destruction) `node tools/test-rollback.mjs --dry-run` → `[dry-run] OK — rollback ready`. This is the second proof of rollback readiness (first was Task 1 step 9 end-to-end smoke). After 6 commits of destructive Phase 1 work (dc7fd579 → 3073e0cb → 03600acc → bca63fc6 → 712b4c63 → 6d72f5b6), the rollback path is still intact: snapshots present, tag `brain-pre-llm-bootstrap` points to origin/main `9d4a30c3` (pre-overhaul). ### Phase 1 exit criteria (all met) - ✅ Rollback infra established + proven (Task 1). - ✅ §12 skill-discipline hooks unwired from `~/.claude/settings.json`, economy hooks preserved (Task 2). - ✅ `discipline-metrics.mjs` decision recorded — KEEP (Task 3). - ✅ Pravila §12 archived; routing-docs deferred (auto-generated, see Task 4 deviations); 4 routing/dormancy artefacts archived; 2 user-level memory files archived; 2 consumers refactored to registry adapter; 539/539 vitest GREEN (Task 4). - ✅ Pravila §17 + ADR-016 added (Task 5). - ✅ Cross-refs §12 → §17 minimal scope + C1/C2 controllers run clean (Task 6). - ✅ Phase-1 flag set; rollback re-verified (this Task 7). ### Phase 1 commits summary | Task | Commit | Files | Net diff | |---|---|---|---| | 1 | `dc7fd579` | 17 | +3700 | | 2 | `3073e0cb` | 3 | +90 / −13 | | 3 | `03600acc` | 2 | +36 / −1 | | 4 | `bca63fc6` | 14 | +382 / −87 | | 5 | `712b4c63` | 4 | +155 / −3 | | 6 | `6d72f5b6` | 4 | +66 / −3 | | 7 | (this commit) | 1+ | +N | ### Phase 1 → Phase 2 handoff Ready to start Phase 2 (Classifier + памятка + inheritance + §17 enforcement, ~1-1.5 недели per plan). Phase 2 begins with Task 8 (router-config.mjs + capabilities on ~85 nodes in `docs/registry/nodes.yaml`). Phase 2 deferred items from Phase 1: - §12 textual cross-refs in PSR_v1 (39 occurrences) — bulk substitution whenever convenient. - CLAUDE.md §3.3 archive + nodes.yaml pin — structural restructure when the classifier is live and §17 enforcement is real (Phase 2 Task 13). - `tools/registry-to-classification-map.mjs` archival — only if direct yaml reads in consumers are required (currently KEEP, 4+ consumers). - `docs/routing-off-phase.md` / `docs/router-procedure.md` — auto-generated derivatives; review whether they remain useful as derived views after Phase 2 classifier replaces routing-procedure execution.