@iowarp/clio-coder 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/CHANGELOG.md +407 -0
  2. package/CODE_OF_CONDUCT.md +21 -0
  3. package/CONTRIBUTING.md +224 -0
  4. package/LICENSE +202 -0
  5. package/NOTICE +9 -0
  6. package/README.md +798 -0
  7. package/SECURITY.md +72 -0
  8. package/assets/clio-coder-logo-128.webp +0 -0
  9. package/damage-control-rules.yaml +419 -0
  10. package/dist/acp-UMLFVA3F.js +92 -0
  11. package/dist/agents-Q4MYPMUW.js +91 -0
  12. package/dist/auth-O6HYIJ6J.js +521 -0
  13. package/dist/chunk-262G75JS.js +35 -0
  14. package/dist/chunk-26BZQOAD.js +1281 -0
  15. package/dist/chunk-2J63S4SF.js +508 -0
  16. package/dist/chunk-3DANZDGR.js +717 -0
  17. package/dist/chunk-4UQA7NCT.js +29 -0
  18. package/dist/chunk-527KG6XR.js +497 -0
  19. package/dist/chunk-5LDRNKX2.js +1063 -0
  20. package/dist/chunk-5N2FG33Q.js +25 -0
  21. package/dist/chunk-67MTHP2E.js +135 -0
  22. package/dist/chunk-6CWDTGUC.js +20 -0
  23. package/dist/chunk-7BHLZB3A.js +2115 -0
  24. package/dist/chunk-7RBKDI66.js +348 -0
  25. package/dist/chunk-AMFR5YA3.js +541 -0
  26. package/dist/chunk-BBUH4VAA.js +1224 -0
  27. package/dist/chunk-BYEU76JP.js +899 -0
  28. package/dist/chunk-CLJ5HLUD.js +458 -0
  29. package/dist/chunk-D5YD55AR.js +116 -0
  30. package/dist/chunk-DXQNI4PC.js +61 -0
  31. package/dist/chunk-E3NYWENM.js +1004 -0
  32. package/dist/chunk-GNGDQYDU.js +34688 -0
  33. package/dist/chunk-GOTUR54M.js +9 -0
  34. package/dist/chunk-HBU5MTAM.js +41 -0
  35. package/dist/chunk-HMYNFFY4.js +28 -0
  36. package/dist/chunk-JPOWPFCU.js +1010 -0
  37. package/dist/chunk-JWHCJDCI.js +1215 -0
  38. package/dist/chunk-KBR4MZZR.js +41 -0
  39. package/dist/chunk-KKKPTZLM.js +93 -0
  40. package/dist/chunk-ME6DNWIU.js +66 -0
  41. package/dist/chunk-NI4DEJMC.js +88 -0
  42. package/dist/chunk-O4EJEDHO.js +659 -0
  43. package/dist/chunk-PIDUD6M2.js +31 -0
  44. package/dist/chunk-PS4PFJQP.js +29459 -0
  45. package/dist/chunk-QV47YRF4.js +48 -0
  46. package/dist/chunk-RQDWMVRB.js +279 -0
  47. package/dist/chunk-TFSSEXL6.js +136 -0
  48. package/dist/chunk-TKHQ4DGZ.js +8290 -0
  49. package/dist/chunk-TPOCL34A.js +2876 -0
  50. package/dist/chunk-UGYAX5YI.js +565 -0
  51. package/dist/chunk-UHTSULZS.js +461 -0
  52. package/dist/chunk-UU3R62TT.js +128 -0
  53. package/dist/chunk-UWIJNAOB.js +3906 -0
  54. package/dist/chunk-VOO7NYPP.js +914 -0
  55. package/dist/chunk-VPAWTYLY.js +117 -0
  56. package/dist/chunk-WD6AJM35.js +1216 -0
  57. package/dist/chunk-X3BR7HWV.js +115 -0
  58. package/dist/chunk-X3NE4WVW.js +120 -0
  59. package/dist/chunk-XNISANGE.js +1395 -0
  60. package/dist/chunk-XV4ZJ6ZM.js +3177 -0
  61. package/dist/cli/index.js +236 -0
  62. package/dist/clio-KIQ5SNDS.js +53 -0
  63. package/dist/components-JVHMUBEB.js +653 -0
  64. package/dist/config-ZFCDBMDC.js +372 -0
  65. package/dist/configure-G4E3A2PG.js +27 -0
  66. package/dist/context-CDXTP2MP.js +293 -0
  67. package/dist/context-E3KIFVXI.js +185 -0
  68. package/dist/context-clear-3F4PLXOS.js +102 -0
  69. package/dist/context-index-Q7YSYTR3.js +106 -0
  70. package/dist/docs-YIETIWZI.js +280 -0
  71. package/dist/doctor-M5HJJZOL.js +61 -0
  72. package/dist/domains/agents/builtins/architect.md +33 -0
  73. package/dist/domains/agents/builtins/coder.md +31 -0
  74. package/dist/domains/agents/builtins/context-bootstrap.md +38 -0
  75. package/dist/domains/agents/builtins/debugger.md +30 -0
  76. package/dist/domains/agents/builtins/documenter.md +31 -0
  77. package/dist/domains/agents/builtins/git-master.md +30 -0
  78. package/dist/domains/agents/builtins/provenance.md +30 -0
  79. package/dist/domains/agents/builtins/researcher.md +71 -0
  80. package/dist/domains/agents/builtins/scout.md +42 -0
  81. package/dist/domains/agents/builtins/tester.md +31 -0
  82. package/dist/domains/agents/builtins/verifier.md +30 -0
  83. package/dist/domains/agents/builtins/wiki-writer.md +41 -0
  84. package/dist/eval-B3KZZESM.js +2674 -0
  85. package/dist/evidence-V67CHM35.js +233 -0
  86. package/dist/evolve-YDZSUQYA.js +518 -0
  87. package/dist/extensions-SRG7XCAH.js +207 -0
  88. package/dist/fleet-CA2CRTVG.js +760 -0
  89. package/dist/fleet-preflight-CLIAX7YR.js +21 -0
  90. package/dist/init-2OZDJE2D.js +227 -0
  91. package/dist/memory-3PIQQAKX.js +207 -0
  92. package/dist/models-DY35XI7Y.js +237 -0
  93. package/dist/paths-5OMXW7Z4.js +57 -0
  94. package/dist/preload-KZVHET2B.js +11 -0
  95. package/dist/reset-PIFYNOS3.js +216 -0
  96. package/dist/run-3VSPP24F.js +735 -0
  97. package/dist/share-D36RQCXM.js +241 -0
  98. package/dist/skills-F2MRLELY.js +445 -0
  99. package/dist/skills-eval-E2ZTW4PL.js +932 -0
  100. package/dist/targets-DZMEZAH4.js +977 -0
  101. package/dist/trace-7NYCUI2J.js +250 -0
  102. package/dist/uninstall-AD3JWHBB.js +322 -0
  103. package/dist/upgrade-WYYBKGDY.js +301 -0
  104. package/dist/usage-ULIDAGFF.js +755 -0
  105. package/dist/version-ROZ6CZKH.js +16 -0
  106. package/dist/wiki-generate-PKFIX6OB.js +377 -0
  107. package/dist/worker/entry.js +1739 -0
  108. package/docs/README.md +93 -0
  109. package/docs/acp.md +120 -0
  110. package/docs/alcf-provider.md +72 -0
  111. package/docs/architecture.md +172 -0
  112. package/docs/artifact-versions.md +54 -0
  113. package/docs/built-in-agents.md +265 -0
  114. package/docs/capacity-and-scheduling.md +97 -0
  115. package/docs/commands-and-modes.md +554 -0
  116. package/docs/config-knobs-audit.md +115 -0
  117. package/docs/configuration-and-targets.md +812 -0
  118. package/docs/context-engine.md +236 -0
  119. package/docs/dispatch-architecture-rationale.md +126 -0
  120. package/docs/documentation-coverage.md +46 -0
  121. package/docs/documentation-guide.md +166 -0
  122. package/docs/environment-variables.md +105 -0
  123. package/docs/eval-runner.md +205 -0
  124. package/docs/evals-internal.md +298 -0
  125. package/docs/evidence-and-memory.md +243 -0
  126. package/docs/evolution.md +143 -0
  127. package/docs/exit-codes-and-output.md +74 -0
  128. package/docs/extensions-and-sharing.md +306 -0
  129. package/docs/fleet-demo-runbook.md +179 -0
  130. package/docs/fleet-dispatch.md +591 -0
  131. package/docs/glossary.md +75 -0
  132. package/docs/html/agents_blueprint.html +936 -0
  133. package/docs/html/alcf_blueprint.html +324 -0
  134. package/docs/html/architecture_blueprint.html +850 -0
  135. package/docs/html/commands_blueprint.html +794 -0
  136. package/docs/html/config_knobs_audit_blueprint.html +178 -0
  137. package/docs/html/configuration_blueprint.html +1080 -0
  138. package/docs/html/context_blueprint.html +603 -0
  139. package/docs/html/documentation_blueprint.html +832 -0
  140. package/docs/html/environment_blueprint.html +404 -0
  141. package/docs/html/eval_blueprint.html +743 -0
  142. package/docs/html/evals_internal_blueprint.html +190 -0
  143. package/docs/html/evolution_blueprint.html +674 -0
  144. package/docs/html/extensions_blueprint.html +2065 -0
  145. package/docs/html/fleet_dispatch_blueprint.html +286 -0
  146. package/docs/html/index.html +919 -0
  147. package/docs/html/lifecycle_blueprint.html +723 -0
  148. package/docs/html/memory_blueprint.html +699 -0
  149. package/docs/html/middleware_blueprint.html +664 -0
  150. package/docs/html/models_blueprint.html +2366 -0
  151. package/docs/html/observability_blueprint.html +683 -0
  152. package/docs/html/provider_adapter_blueprint.html +245 -0
  153. package/docs/html/safety_blueprint.html +1386 -0
  154. package/docs/html/shared.css +571 -0
  155. package/docs/html/shared.js +143 -0
  156. package/docs/html/skills_blueprint.html +671 -0
  157. package/docs/html/soak_blueprint.html +182 -0
  158. package/docs/html/tool_usage_blueprint.html +350 -0
  159. package/docs/html/tools_blueprint.html +2249 -0
  160. package/docs/html/trace_blueprint.html +235 -0
  161. package/docs/html/tui_design_blueprint.html +314 -0
  162. package/docs/html/validation_blueprint.html +961 -0
  163. package/docs/html/worker_dispatch_blueprint.html +231 -0
  164. package/docs/installation-and-lifecycle.md +308 -0
  165. package/docs/middleware-and-components.md +148 -0
  166. package/docs/model-catalog.md +189 -0
  167. package/docs/observability.md +233 -0
  168. package/docs/proactive-memory.md +452 -0
  169. package/docs/prompt-envelope-and-tools.md +142 -0
  170. package/docs/provider-adapter-cookbook.md +148 -0
  171. package/docs/release-cut-checklist.md +138 -0
  172. package/docs/safety-model.md +357 -0
  173. package/docs/scientific-validation.md +105 -0
  174. package/docs/session-lifecycle.md +156 -0
  175. package/docs/skills-marketplace.md +46 -0
  176. package/docs/tool-usage.md +527 -0
  177. package/docs/trace-store.md +132 -0
  178. package/docs/troubleshooting.md +33 -0
  179. package/docs/tui-design.md +239 -0
  180. package/docs/worker-dispatch-mechanics.md +242 -0
  181. package/package.json +132 -0
  182. package/skills/README.md +408 -0
  183. package/skills/git/commit-crafting/SKILL.md +79 -0
  184. package/skills/git/commit-crafting/evals.md +92 -0
  185. package/skills/git/create-pr/SKILL.md +116 -0
  186. package/skills/git/create-pr/evals.md +114 -0
  187. package/skills/git/investigate-issue/SKILL.md +139 -0
  188. package/skills/git/investigate-issue/evals.md +94 -0
  189. package/skills/git/resolve-merge-conflicts/SKILL.md +96 -0
  190. package/skills/git/resolve-merge-conflicts/evals.md +58 -0
  191. package/skills/git/review-changes/SKILL.md +103 -0
  192. package/skills/git/review-changes/evals.md +85 -0
  193. package/skills/git/worktree-create/SKILL.md +92 -0
  194. package/skills/git/worktree-create/evals.md +97 -0
  195. package/skills/git/worktree-create/references/worktree-setup.md +66 -0
  196. package/skills/git/worktree-merge/SKILL.md +95 -0
  197. package/skills/git/worktree-merge/evals.md +114 -0
  198. package/skills/skill-marketplace.json +261 -0
  199. package/skills/workflow/cut-it/SKILL.md +86 -0
  200. package/skills/workflow/cut-it/evals.md +42 -0
  201. package/src/domains/agents/builtins/architect.md +33 -0
  202. package/src/domains/agents/builtins/coder.md +31 -0
  203. package/src/domains/agents/builtins/context-bootstrap.md +38 -0
  204. package/src/domains/agents/builtins/debugger.md +30 -0
  205. package/src/domains/agents/builtins/documenter.md +31 -0
  206. package/src/domains/agents/builtins/git-master.md +30 -0
  207. package/src/domains/agents/builtins/provenance.md +30 -0
  208. package/src/domains/agents/builtins/researcher.md +71 -0
  209. package/src/domains/agents/builtins/scout.md +42 -0
  210. package/src/domains/agents/builtins/tester.md +31 -0
  211. package/src/domains/agents/builtins/verifier.md +30 -0
  212. package/src/domains/agents/builtins/wiki-writer.md +41 -0
  213. package/src/domains/agents/fleets/build-review.md +34 -0
  214. package/src/domains/agents/fleets/build-test.md +35 -0
  215. package/src/domains/agents/fleets/sdlc.md +86 -0
  216. package/src/domains/prompts/fragments/identity/clio-worker.md +11 -0
  217. package/src/domains/prompts/fragments/identity/clio.md +26 -0
  218. package/src/domains/prompts/fragments/operating/contract.md +64 -0
  219. package/src/domains/prompts/fragments/safety/auto-edit.md +14 -0
  220. package/src/domains/prompts/fragments/safety/full-auto.md +14 -0
  221. package/src/domains/prompts/fragments/safety/read-only.md +13 -0
  222. package/src/domains/prompts/fragments/safety/suggest.md +13 -0
  223. package/src/domains/prompts/fragments/wiki/page.md +75 -0
  224. package/src/domains/prompts/fragments/wiki/plan.md +48 -0
  225. package/src/domains/providers/models/cloud-models/alcf.yaml +40 -0
  226. package/src/domains/providers/models/local-models/clio-local-coding-targets.yaml +993 -0
@@ -0,0 +1,236 @@
1
+ # Context Engine
2
+
3
+ > [!TIP]
4
+ > **Interactive Spec Available:** An interactive dashboard is located at [docs/html/context_blueprint.html](html/context_blueprint.html) (Version: 0.3.0).
5
+
6
+ Clio Coder tracks context pressure, records per-turn snapshots, and protects the provider context with bounded tool results plus single-threshold compaction.
7
+
8
+ Source of truth lives in `src/domains/session/context-accounting.ts`, `src/domains/session/context-ledger.ts`, `src/domains/session/compaction/`, `src/domains/session/migrations/index.ts`, and the chat-loop integration in `src/interactive/chat-loop.ts`.
9
+
10
+ ## Context window resolution
11
+
12
+ Each target has a declared, desired, and effective context window. The effective window is the operating ceiling used by budget checks and compaction. It can come from a live loaded model config, a probe, a target override, a model hint, catalog knowledge, a local-native default, or a descriptor default.
13
+
14
+ Local-native runtimes use a recommended minimum desired window of 128,000 tokens. If the live model reports a smaller loaded context window, Clio re-resolves the target so accounting uses the actual ceiling.
15
+
16
+ ## Token accounting and snapshots
17
+
18
+ The estimator in `context-accounting.ts` uses a four-characters-per-token family for hot-path accounting. It estimates system prompt, tools, messages, pending input, and runtime categories without calling a model tokenizer on every TUI refresh.
19
+
20
+ At submit time, Clio captures a context snapshot and persists a slim JSONL record under the session directory as `context-snapshots.jsonl`. The slim record keeps token counts, segment metadata, signatures, and hashes, not the heavy prompt or transcript text. When provider usage arrives, `reconcileSnapshot` folds actual input and output counts back into the ledger.
21
+
22
+ Session metadata enforces session format version 3 (`CURRENT_SESSION_FORMAT_VERSION = 3`). Before resuming any session, Clio checks `sessionFormatVersion`; earlier formats are rejected outright with an error rather than silently migrated.
23
+
24
+ The `/context` overlay and footer meter read the same ledger categories: `system`, `tools`, `agents`, `skills`, `memory`, `project`, `messages`, `pending`, `reserve`, `free`, and `streaming`.
25
+
26
+ ## Single-threshold compaction
27
+
28
+ Auto-compaction is controlled by one pressure threshold. Pressure is `estimated_tokens / context_window`. The default threshold is `0.8`.
29
+
30
+ When `compaction.auto` is enabled and pressure crosses the threshold before a request, Clio first masks stale tool observations and stale thinking older than `excludeLastTurns`. This is a cheap local rewrite. Tool call and result structure remain present, but the observation body is replaced with a marker and stale assistant thinking content is dropped from replay.
31
+
32
+ Marker format:
33
+
34
+ ```text
35
+ [Observation masked: <tool> output was <lines> lines, <chars> chars - contents masked to save context. Re-run the tool for current content.] Preview: <preview>
36
+ ```
37
+
38
+ Already-compacted entries are not masked again. Recent turns keep their full observations and thinking. If masking drops pressure below the threshold, Clio sends the request without an LLM summary. If pressure remains above the threshold, Clio runs the summary compaction path, appends a compaction summary entry, refreshes replay messages from the session, and continues.
39
+
40
+ Manual `/context compact`, `CLIO_CODER_FORCE_COMPACT=1`, and overflow recovery force the LLM summary path directly. The overflow guard runs before the user turn is committed, so a blocked oversized request does not leave an unanswered user entry in the ledger.
41
+
42
+ ## Cache-divergence honesty
43
+
44
+ Compaction rewrites the replayed history. On a local backend with a single prefix-cache slot, the next turn after compaction is expected to be cold because the byte prefix changed. Dispatch traffic can disturb the same slot.
45
+
46
+ Clio records these disturbances once on the next assistant entry as `promptCache.expectedColdReasons`. The user sees one dim notice, and the same reasons persist on that entry in the session ledger next to the per-call cache data.
47
+
48
+ Per-call cache verdicts are `hot`, `partial`, `cold`, and `small`. They are derived from provider usage and persisted with `timing { ttftMs, apiMs }` and `promptCache { input, cacheRead, cacheWrite, backendVerdict }` when available.
49
+
50
+ ## Settings
51
+
52
+ The public settings block has one threshold and one recent-turn horizon:
53
+
54
+ ```yaml
55
+ compaction:
56
+ auto: true
57
+ threshold: 0.8
58
+ excludeLastTurns: 6
59
+ # model: provider/summary-model-id
60
+ # systemPrompt: ~/.config/clio-coder/prompts/compaction.md
61
+ ```
62
+
63
+ `auto` controls the pre-request trigger. Manual `/context compact` still runs when `auto` is false. `model` optionally selects a dedicated summarization model. `systemPrompt` optionally points at a prompt override file for compaction.
64
+
65
+ Settings validation is strict: an older file still carrying the removed `compaction.thresholds` block fails to load with the exact key path during normal startup. Edit removed or unknown keys deliberately; `clio-coder doctor --fix` does not transform settings into the current schema.
66
+
67
+ ---
68
+
69
+ ## Project-context preload class
70
+
71
+ The compiled session prompt preloads the full rendered project context (the `CLIO-CODER.md` fragment plus project-type and codewiki markers) only when a parseable `CLIO-CODER.md` exists and the rendered text stays within 8000 characters and 220 lines; otherwise it preloads a compact synopsis. The rule lives in `src/domains/prompts/preload.ts` and every reporting surface classifies with it:
72
+
73
+ - `/context init` and `clio-coder context init` print `preload: full (N.NkB, N lines)` or `preload: synopsis (reason: size|lines)` after the summary, and warn when a full preload is within 10% of either limit.
74
+ - `clio-coder config inspect` shows the preload class in the `CLIO-CODER.md` entry's detail.
75
+ - The `/context` overlay shows a `project preload:` line under the category legend once a session prompt has compiled.
76
+
77
+ ## Context refresh
78
+
79
+ `/context refresh` and `clio-coder context refresh` rebuild the structural codewiki
80
+ and restamp `.clio-coder/state.json` without reading or writing `CLIO-CODER.md`. The CLI
81
+ flag `--wiki` is the only refresh path that may update the Markdown wiki, and
82
+ it only runs when an existing wiki metadata file is present. Regenerating or
83
+ updating handbook prose stays with `/context init`.
84
+
85
+ `clio-coder context init` is model-driven by default. The `--heuristic` flag is the sole deterministic flag for offline handbook generation. The `--propose` flag writes ignored drafts to `.clio-coder/proposals/`, `--apply` updates from the existing handbook, and `--rewrite` generates a fresh handbook.
86
+
87
+ When bootstrapping across local runtimes such as `llamacpp` where strict grammar/schema enforcement might be rejected by the endpoint, generator logic retries automatically using a bounded prompt-parser fallback. If `--rewrite` was requested but the model generation fails to produce a valid handbook rewrite, `clio-coder context init` prints a notice and exits with code 1 rather than leaving an inconsistent state.
88
+
89
+
90
+ ---
91
+
92
+ ## Codewiki and Wiki
93
+
94
+ Project context has two local layers. The structural layer is model-free and
95
+ feeds navigation. The Markdown wiki layer is agent-authored and exists only
96
+ when the operator explicitly asks for it.
97
+
98
+ | Layer | Artifact | Producer | Model use | Prompt surfacing |
99
+ | --- | --- | --- | --- | --- |
100
+ | Structural codewiki | `.clio-coder/codewiki.json` plus `.clio-coder/state.json` | `context init`, `context refresh`, `context index`, session freshness checks, and incremental mutation observers | None | `<codewiki>available...; use code_nav</codewiki>` |
101
+ | Markdown wiki | `.clio-coder/wiki/**/*.md` plus `.clio-coder/wiki/meta.json` | `clio-coder context wiki` or `clio-coder context refresh --wiki` | Yes, one planning dispatch plus one dispatch per page | `<wiki>N pages at .clio-coder/wiki (start: quickstart.md)...</wiki>` |
102
+
103
+ ### Structural Index
104
+
105
+ `.clio-coder/codewiki.json` uses schema v5 and is written as compact JSON. File
106
+ records contain a stable id, path, language, line count, role, per-file content
107
+ hash, extracted import specifiers, and an optional first docstring/JSDoc
108
+ summary. Symbol records store declaration-level symbols only (such as classes, interfaces, types, global functions, and methods) and intentionally skip function-local symbols. Each record stores name, kind, file id, line, and optional signature. Edges are built from imports and record either an internal file id target or an external module string.
109
+
110
+ In Git workspaces, the indexer uses the same visible file set across full builds,
111
+ incremental updates, fingerprints, and project profiles: tracked files plus
112
+ untracked, unignored work in progress. It excludes symlinks, submodule gitlinks,
113
+ generated output, scratch space, and local-state directories such as `.git`,
114
+ `.clio-coder`, `.superpowers`, `.codex`, `.claude`, `.clio-coder-benchmark`, `node_modules`,
115
+ `dist`, `build`, `coverage`, virtualenvs, `target`, and `vendor`. Non-Git
116
+ workspaces use a bounded filesystem walk with the same directory exclusions.
117
+ Source coverage spans TypeScript, JavaScript, Python, Rust, Go, C, C++, CUDA
118
+ (`.cu` and `.cuh`), Java, Ruby, and C#, with config entries for manifests such
119
+ as `package.json`, `pyproject.toml`, `Cargo.toml`, `go.mod`, `pom.xml`,
120
+ `CMakeLists.txt`, `Gemfile`, and `*.csproj`.
121
+
122
+ Extraction is async and tree-sitter-first. Clio loads WASM grammars for the ten
123
+ source language grammars above, extracts symbols/imports/exports from the parsed tree,
124
+ and merges regex import extraction for languages with regex extractors. If a
125
+ tree-sitter parse fails for one file, that file falls back to the available
126
+ regex extractor instead of aborting the whole build. C# is covered by the
127
+ tree-sitter C# grammar.
128
+
129
+ Ambiguous `.h` files are classified deterministically by `classifyCHeaderLanguage` (`src/core/c-header-language.ts`). The scanner removes comments before checking C++-only standard-library includes, and removes comments and literals before checking C++ syntax markers such as templates, namespaces, class/member declarations, scope resolution, C++ casts, and C++ qualifiers. If any C++ marker is present, the header is indexed as `c++`; otherwise, it defaults to `c`. This guarantees that both full indexing and incremental file syncs assign identical language tags to `.h` files. Declaration-only C/C++ APIs are indexed so header-heavy MPI, CUDA, and scientific libraries remain navigable even when implementations live elsewhere.
130
+
131
+ Incremental updates are real updates, not a full rebuild hidden behind the
132
+ name. Successful file-mutating tools report changed paths through the
133
+ middleware observer. The context domain coalesces those paths, checks per-file
134
+ content hashes and reparses only changed files (`perf(context)` optimization),
135
+ reads only the changed indexable files for path-based updates, replaces their file and symbol records, removes
136
+ deleted records, and rebuilds edges from the merged import set. Non-indexable
137
+ paths are no-ops.
138
+
139
+ ### Markdown Wiki & `code_nav` Resolution
140
+
141
+ The wiki lives under `.clio-coder/wiki/` as a nested tree and is written by the
142
+ `wiki-writer` agent. Model agents resolve pages dynamically through `code_nav`
143
+ with `mode: "wiki"`; an optional query resolves a page id or title, where the id
144
+ is the page's path without its extension (`domains/dispatch`), and returns its
145
+ summary and path. That gives deterministic on-demand navigation without loading
146
+ whole pages into prompt context.
147
+
148
+ The unit of work is one page, not one wiki. A run makes a single planning
149
+ dispatch, then one dispatch per page, each with a fresh context holding only that
150
+ page's plan entry, its anchor sources, and the sibling paths it may link to. The
151
+ repository-wide payload, including the codewiki digest, appears only in the
152
+ planning prompt. Because a static prompt is re-sent on every round of a run, this
153
+ is what keeps prefill cost from growing quadratically with the size of the wiki.
154
+
155
+ `_plan.json` is the skeleton and the checkpoint. It is derived deterministically
156
+ from the codewiki index, so a usable plan exists before any model runs; the
157
+ planning dispatch may merge, split, rename, drop, or re-anchor entries by
158
+ rewriting it, and a malformed rewrite falls back to the candidate. The harness
159
+ owns each entry's status and rewrites the file after every page, so a run that
160
+ ends early records exactly which pages are still owed. Staging survives such a
161
+ run and the next one resumes from it.
162
+
163
+ Every page opens with front matter carrying `title`, `summary`, `sources`,
164
+ `symbols`, `tests`, `invariants`, and `validate`. That is the retrieval layer:
165
+ `quickstart.md`, every directory `index.md`, and the task-routing table are
166
+ generated from it after each run, so navigation cannot drift or miss a page and
167
+ no writer has to remember to update it.
168
+
169
+ Assembly repairs rather than rejects. A missing H1, absent or malformed front
170
+ matter, a dangling `sources` entry, a link to a page that was never written, and
171
+ a citation to a path that does not exist are all mechanically fixable, so each is
172
+ fixed or recorded in a `<!-- clio:wiki ... -->` marker and reported; none fails a
173
+ run. An empty page is dropped and its plan entry stays owed. An update run's
174
+ scope is computed, not guessed: a page is rewritten when git reports a change to
175
+ one of the sources its own front matter claims.
176
+
177
+ `meta.json` records `updatedAt`, `gitHead`, the indexed source-tree hash, the
178
+ model label, a content hash over the page tree, the page list, and the plan.
179
+ `generation.pagesPlanned` and `generation.pagesWritten` say whether a run
180
+ finished; when they differ, `clio-coder context wiki --update` completes the rest.
181
+
182
+ `clio-coder context wiki` creates a wiki when no metadata exists and updates one when metadata is present. During wiki generation, Clio automatically refreshes a stale codewiki index before grounding the model run. The decision to write new pages and update metadata is a no-op if the newly generated content's hash matches the existing content hash. `clio-coder context wiki --update` requests update mode explicitly. `clio-coder context wiki --status` only reads metadata and does not run a model. `clio-coder context refresh --wiki` first rebuilds the structural codewiki and then updates an existing wiki when `.clio-coder/wiki/meta.json` exists; when no wiki metadata exists, it performs no wiki generation.
183
+
184
+ ### Lifecycle Matrix
185
+
186
+ | Event | Structural codewiki behavior | Markdown wiki behavior |
187
+ | --- | --- | --- |
188
+ | Session start | If state or `.clio-coder/codewiki.json` already exists, Clio checks freshness best-effort and performs a full rebuild when the index is stale, missing, unreadable, or needs v5 backfill. Never-indexed directories are skipped. | No generation or update. Existing wiki status may surface in the welcome dashboard. |
189
+ | In-session edits | Successful file mutations enqueue changed paths for incremental `updateCodewikiPaths`; the queue is serialized and best-effort. | No automatic update. |
190
+ | Session stop | Drains the incremental queue, then rebuilds only when state is stale, the index is missing, or v5 backfill is needed. State records `lastSessionAt`, `lastIndexedAt` when applicable, and `codewikiVersion`. | No automatic update. |
191
+ | `/context init` or `clio-coder context init` | Performs a full codewiki rebuild before generating, preserving, proposing, or previewing `CLIO-CODER.md`; writes state with the fingerprint and codewiki version when it writes state. | No wiki generation. |
192
+ | `/context refresh` or `clio-coder context refresh` | Performs a full codewiki rebuild and writes state. Does not touch `CLIO-CODER.md`. | If an existing wiki is stale and `--wiki` was not passed on the CLI, prints a hint to run `clio-coder context refresh --wiki` or `clio-coder context wiki --update`. |
193
+ | `clio-coder context refresh --wiki` | Performs the same full codewiki rebuild and state write. | Updates an existing wiki through the model-backed page dispatches. No wiki metadata means no wiki model call. |
194
+ | `clio-coder context wiki` | Automatically refreshes the codewiki index if stale before composing the wiki prompt. | Plans, then writes each owed page in its own dispatch, assembles and promotes whatever landed (no-op if content hashes match), and records any pages still owed. |
195
+ | `clio-coder context wiki --status` | No index rebuild. | Reads metadata and reports page count, update time, recorded git head, git-head drift, and how many planned pages remain unwritten. |
196
+
197
+ ### Staleness
198
+
199
+ Codewiki staleness is controlled by one predicate:
200
+ `isStale(prev, curr)` compares only `fingerprint.treeHash`. The fingerprint
201
+ hash is mtime-aware: it walks the repository, excludes generated/local-state
202
+ directories and lock/archive files, and hashes each included relative path,
203
+ file size, and floored `mtimeMs`. The fingerprint also records `gitHead` and
204
+ `loc`; `loc` comes from the codewiki artifact when available, otherwise from a
205
+ line count over source extensions. Those fields are reporting data, not the
206
+ stale predicate.
207
+
208
+ `.clio-coder/state.json` stores the fingerprint and optional `codewikiVersion`.
209
+ Legacy v2/v3/v4 codewiki files can still be read as degraded v5 artifacts, but
210
+ their missing or deliberately invalidated per-file hashes make `codewikiNeedsBackfill` true. The
211
+ next session freshness check, `code_nav` demand load, wiki generation, or
212
+ explicit refresh rebuilds them into full v5.
213
+
214
+ Wiki staleness is separate. New `.clio-coder/wiki/meta.json` files record both the git
215
+ head and the indexed source-tree hash used when the wiki content last changed.
216
+ Clio reports drift at the same git head when tracked or untracked source files
217
+ change, and combines committed and working-tree evidence in its changed-file
218
+ count. Older metadata without a source-tree hash retains the git-head-only
219
+ check. Git-less or unreadable git states degrade to `fresh` with a warning when
220
+ Clio cannot prove drift.
221
+
222
+ ### Surfacing and Navigation
223
+
224
+ The compiled prompt surfaces only markers, never the codewiki JSON or wiki page
225
+ contents. Fresh codewiki renders as `<codewiki>available; use code_nav</codewiki>`.
226
+ A stale codewiki marker adds `(stale; run /context refresh)`. A valid wiki marker
227
+ names the page count and `quickstart.md`; a stale wiki marker adds `(stale; run
228
+ clio-coder context wiki --update)`.
229
+
230
+ `clio-coder context` prints a structural digest from `renderCodewikiDigest`: schema
231
+ version, project language, file/config/symbol/edge counts, language and role
232
+ counts, top areas, entry points, key symbols, and dependency samples. The
233
+ welcome dashboard shows module count, wiki page count and freshness, and a
234
+ small entry-point excerpt from the same digest. Agents query the structural
235
+ layer through the read-only `code_nav` tool. See [tool-usage.md](tool-usage.md)
236
+ for the full mode reference.
@@ -0,0 +1,126 @@
1
+ # Dispatch Architecture Rationale
2
+
3
+ Why `src/domains/dispatch/` is one domain, why one import out of it looks
4
+ irregular and is allowed to, and why the repository has no barrel-only import
5
+ convention. No code moved as a result of this document. It exists so that a
6
+ later split is argued from invariants rather than from file counts.
7
+
8
+ Counts verified against the current tree: 65 TypeScript files in
9
+ `src/domains/dispatch/`, a 137-line barrel at `src/domains/dispatch/index.ts`,
10
+ and one dispatch → eval import.
11
+
12
+ ---
13
+
14
+ ## Size does not argue for a split
15
+
16
+ A five-way split by responsibility label is the obvious proposal and the wrong
17
+ one. The invariants in this domain are not partitioned by the labels such a
18
+ split would use. They cross them.
19
+
20
+ ### Invariants that cross the proposed seams
21
+
22
+ | Invariant | Crosses | Evidence |
23
+ | --- | --- | --- |
24
+ | A retry is `recovery`, and rebinds its reservation to the node and cost bound it actually resolved | routing, admission, retries, receipts | `execution-role.ts`, `capacity-lease.ts`, `routing-intent.ts` |
25
+ | A plan slot belongs to an assignment, never an attempt, so a retry never queues behind itself | admission, scheduling, retries | `admission-queue.ts` |
26
+ | Whole-plan preflight and reservation happen before any spawn | scheduling, admission, write boundaries | `execution-scheduler.ts` |
27
+ | Route history keys on capability, and a receipt's `quality` block must be run-local | routing, receipts, quality | `route-history.ts`, `route-quality.ts` |
28
+ | Write-boundary attribution is per scheduling *window*, so the compiler refuses a wave with two writers | scheduling, write boundaries, plan compilation | `execution-plan.ts`, `write-boundary.ts` |
29
+ | A loop's later nodes are `unneeded`, decided by the scheduler, not the plan | plan compilation, scheduling, receipts | `fleet-plan.ts`, `execution-scheduler.ts` |
30
+ | Staleness revalidation re-runs a verification a later workspace step invalidated | scheduling, plan compilation, code steps | `execution-scheduler.ts` |
31
+ | Receipt integrity v15 seals normalized routing intent | routing, receipts | `receipt-integrity.ts`, `routing-intent.ts` |
32
+
33
+ The write-boundary and loop rows are the sharpest. Both are properties of a
34
+ *wave*, which is a scheduling concept computed by the plan compiler and enforced
35
+ by the scheduler. A split putting plan compilation and scheduling in different
36
+ modules puts the two halves of one invariant on opposite sides of a module
37
+ boundary, where nothing but convention keeps them agreeing.
38
+
39
+ ### What a split would have to preserve
40
+
41
+ Any future split must carry these forward. A split proposal that does not
42
+ address every one of them is not ready:
43
+
44
+ 1. **One hashed plan.** `compileExecutionPlan` produces one deterministic hashed
45
+ DAG including unrolled loops. Wave computation, boundary-attribution refusal,
46
+ and authority grants are all decided there. Splitting compilation from
47
+ scheduling requires the wave contract to become an explicit, versioned
48
+ interface rather than an in-process assumption.
49
+ 2. **Admission is serialized by one cross-process lock.** Lease acquisition,
50
+ retry rebinding, heartbeat, drain, and reservation transfer are one critical
51
+ section. A split that puts any of them behind a separate module's API must
52
+ not introduce a second lock or a lock-free path.
53
+ 3. **Attempt identity.** Assignment id and terminal run id are distinct, and
54
+ role derivation (`recovery` for every attempt after the first) is read by
55
+ routing, receipts, history, and the ledger. This is a shared vocabulary, not a
56
+ routing detail.
57
+ 4. **Fail-closed defaults.** No-ready-candidate, manual pins, `failover: none`,
58
+ missing authority grants, and unverifiable boundaries all refuse. A split must
59
+ not create a module whose default answer is permissive.
60
+ 5. **Receipt sealing is the authority.** The orchestrator's validation, not the
61
+ worker's, decides conformance. Any split must keep sealing on the
62
+ orchestrator side of the new seam.
63
+
64
+ ### Recommendation
65
+
66
+ Do not split cross-domain, and do not split `dispatch` on responsibility labels.
67
+ Internal cohesion is available and safe: extracting a pure reducer or a
68
+ single-owner helper into another file *within* `src/domains/dispatch` costs
69
+ nothing and needs only the existing tests. `route-quality.ts` and
70
+ `routing-intent.ts` are already this shape and are the model to follow.
71
+
72
+ A genuine split, if it is ever wanted, should be argued from the wave contract
73
+ outward, because that is the one seam the invariants above actually respect.
74
+
75
+ ---
76
+
77
+ ## Dispatch reads an eval parser the eval barrel does not export
78
+
79
+ `src/domains/dispatch/route-observer.ts` imports `parseEvalArtifactV4` from
80
+ `../eval/artifacts/store.js`. The eval barrel does not export it. This is the
81
+ only dispatch → eval import in the domain.
82
+
83
+ This is coupling worth recording, not a violation. It breaks none of the five
84
+ enforced boundary rules, and the direction is defensible: the routing quality
85
+ reducer treats an eval artifact as evidence, so it must parse one, and
86
+ `parseEvalArtifactV4` is the strict fail-closed parser rather than a convenience
87
+ reader. Routing quality reading eval evidence through the artifact's own
88
+ validating parser is better than routing quality inventing a second reader that
89
+ could accept an artifact the eval domain would reject.
90
+
91
+ Widening the eval barrel to export it would be a public-surface change made only
92
+ to satisfy import form, which is exactly what the barrel decision below rejects.
93
+ If the coupling is ever to be removed, the honest fix is for the eval domain to
94
+ own a narrow "read an artifact as routing evidence" function and export that,
95
+ which is a design change needing its own justification.
96
+
97
+ ---
98
+
99
+ ## The repository has no barrel-only import convention
100
+
101
+ Direct subpath imports are permitted. This is a decision, not a postponement.
102
+
103
+ The evidence that decides it:
104
+
105
+ - Measured across `src/domains/**`, counting an import as cross-domain when the
106
+ importing file and the resolved target sit in different `src/domains/<name>`
107
+ directories: **110** cross-domain subpath imports against **29** cross-domain
108
+ barrel imports. Direct subpath import is the majority pattern by roughly four
109
+ to one, not an exception to a rule.
110
+ - All five enforced boundary rules
111
+ (`tests/boundaries/check-boundaries.ts`) constrain dependency **direction**:
112
+ who may depend on whom. Not one constrains import **form**. There is no rule
113
+ to be half-consistent with.
114
+ - `src/domains/dispatch/execution-plan.ts` imports `AgentAutomationAuthority`
115
+ from `../agents/spec.js`, and `src/domains/agents/index.ts` does not export
116
+ it. A barrel-only rule would have to widen the agents barrel for no reason but
117
+ import style.
118
+
119
+ A barrel-only sixth rule would require widening many barrels to re-export
120
+ symbols currently reached directly. Every one of those is a public-surface
121
+ addition justified by nothing but import style, and it would rewrite every
122
+ affected import site for no behavioral gain. A boundary rule should protect an
123
+ invariant. "Always import through the barrel" protects a preference.
124
+
125
+ What is *not* permitted is anything the five direction rules forbid, and those
126
+ stay enforced by `npm run check:boundaries`.
@@ -0,0 +1,46 @@
1
+ # Clio Coder Documentation Coverage Matrix
2
+
3
+ This matrix maps every top-level directory in `src/` and every domain directory under `src/domains/` to its authoritative documentation page. It records coverage status (`documented`, `partial`, `undocumented`), missing concepts, and key source contracts for `v0.3.0`.
4
+
5
+ ## Coverage Matrix
6
+
7
+ | Source Area | Primary Subsystems / Modules | Owning Documentation | Status | Coverage Details & Gap Analysis |
8
+ | :--- | :--- | :--- | :--- | :--- |
9
+ | `src/cli/` | Command line routing, subcommands, flag parsing, exit codes, machine-readable JSON streaming | [commands-and-modes.md](commands-and-modes.md), [exit-codes-and-output.md](exit-codes-and-output.md) | `documented` | Covered by CLI reference and the dedicated exit codes and machine-readable output contract guide. |
10
+ | `src/core/` | Invariants, constants, configuration defaults, headless permissions, tool definitions, response schema contracts | [architecture.md](architecture.md), [configuration-and-targets.md](configuration-and-targets.md), [installation-and-lifecycle.md](installation-and-lifecycle.md), [safety-model.md](safety-model.md) | `documented` | Fully documented across architecture, configuration, lifecycle, and safety model pages. |
11
+ | `src/engine/` (Core) | Engine turn loop, prompt priming, streaming message adapters, turn execution | [architecture.md](architecture.md), [context-engine.md](context-engine.md) | `documented` | Documented across architecture and context engine guides. |
12
+ | `src/engine/acp/` | ACP protocol server, transport adapters, tool mediators, permission forwarding, error taxonomy | [acp.md](acp.md) | `documented` | Dedicated ACP specification covering server wiring, permission mediation, timeouts, error taxonomy, and security boundaries. |
13
+ | `src/entry/` | Application bootstrapping, CLI router, interactive loop entry point | [architecture.md](architecture.md), [installation-and-lifecycle.md](installation-and-lifecycle.md) | `documented` | Documented in architecture compilation boundaries and lifecycle guides. |
14
+ | `src/interactive/` | TUI architecture, screens, overlays, keybindings, panels, theme tokens, width matrices | [tui-design.md](tui-design.md), [commands-and-modes.md](commands-and-modes.md) | `documented` | Fully documented in TUI design specification and commands reference. |
15
+ | `src/tools/` | 19 built-in tools across 7 planes, registry, policy engine bindings, observation envelope bounds | [tool-usage.md](tool-usage.md), [prompt-envelope-and-tools.md](prompt-envelope-and-tools.md) | `documented` | Comprehensive 19-tool reference with schemas, examples, and envelope size constraints. |
16
+ | `src/utils/` | Image manipulation, photon operations, git execution utilities | [architecture.md](architecture.md), [tool-usage.md](tool-usage.md) | `documented` | Utility helpers documented within tool usage and architectural boundaries. |
17
+ | `src/worker/` | Worker subprocess lifecycle, NDJSON transport, heartbeat timers, control lane demuxing, spec contracts | [worker-dispatch-mechanics.md](worker-dispatch-mechanics.md) | `documented` | Complete reference for NDJSON socket protocols, watchdog timers, and exit status mapping. |
18
+ | `src/domains/agents/` | 12 built-in recipes, agent catalog, recipe schema, fleet commands, fleet contract v4 | [built-in-agents.md](built-in-agents.md), [fleet-dispatch.md](fleet-dispatch.md) | `documented` | Documented in built-in agent recipes guide and fleet dispatch architecture. |
19
+ | `src/domains/components/` | Component scanning, snapshots, hashing, diffing | [middleware-and-components.md](middleware-and-components.md) | `documented` | Documented in active component snapshot and middleware guide. |
20
+ | `src/domains/config/` | Configuration contracts, file watcher, keybinding definitions, setting classifiers | [configuration-and-targets.md](configuration-and-targets.md), [commands-and-modes.md](commands-and-modes.md) | `documented` | Documented in configuration targets and command/keybinding reference. |
21
+ | `src/domains/context/` | `CLIO-CODER.md` bootstrap, codewiki generation, prompt context assembly, project rules | [context-engine.md](context-engine.md) | `documented` | Documented in context window, token accounting, and compaction reference. |
22
+ | `src/domains/dispatch/` | Fleet orchestration, assignment store, batch tracker, admission, route planner, receipt integrity v15 | [fleet-dispatch.md](fleet-dispatch.md), [dispatch-architecture-rationale.md](dispatch-architecture-rationale.md), [worker-dispatch-mechanics.md](worker-dispatch-mechanics.md) | `documented` | Multi-node fleet dispatch, admission invariants, and receipt verification fully documented. |
23
+ | `src/domains/eval/` | Suite v2 YAML schema, eval runner, metrics, reporters, workspace sandboxing | [eval-runner.md](eval-runner.md), [evals-internal.md](evals-internal.md) | `documented` | Documented in eval runner and soak benchmark guides. |
24
+ | `src/domains/evidence/` | Evidence bundles, findings taxonomy, provenance store, failure attribution | [evidence-and-memory.md](evidence-and-memory.md) | `documented` | Documented in evidence directory structures and memory retrieval guide. |
25
+ | `src/domains/evolution/` | Falsifiable Change Manifest JSON templates and `clio-coder evolve` self-edit gates | [evolution.md](evolution.md) | `documented` | Documented in evolution manifest reference and mutation validation rules. |
26
+ | `src/domains/extensions/` | Extension manifest schemas, resource roots, portable share archives | [extensions-and-sharing.md](extensions-and-sharing.md) | `documented` | Documented in extensions and sharing guide. |
27
+ | `src/domains/lifecycle/` | Platform initialization, upgrade, reset, uninstall, migrations, doctor diagnostics | [installation-and-lifecycle.md](installation-and-lifecycle.md) | `documented` | Platform directories, permissions, initialization, and diagnostic commands documented. |
28
+ | `src/domains/memory/` | Proactive task memory, three-tier bank, two-phase policy grammar, handoffs | [proactive-memory.md](proactive-memory.md), [evidence-and-memory.md](evidence-and-memory.md) | `documented` | Proactive task bank, intervention rules, and persistence fully documented. |
29
+ | `src/domains/middleware/` | Middleware hooks (`turn_start`, `tool_call`, `tool_result`, `turn_end`), reminders, budgets | [middleware-and-components.md](middleware-and-components.md) | `documented` | Documented in middleware hooks and active component snapshot guide. |
30
+ | `src/domains/observability/` | Trace store (`node:sqlite` WAL mirror), metrics, cost accounting, evidence index | [trace-store.md](trace-store.md), [observability.md](observability.md) | `documented` | Database schema, rowid cursor queries, and receipt provenance documented. |
31
+ | `src/domains/prompts/` | Prompt compiler, fragment loaders, static cache stability, memory intervention injection | [prompt-envelope-and-tools.md](prompt-envelope-and-tools.md) | `documented` | Documented in prompt envelope and tool delivery guide. |
32
+ | `src/domains/providers/` | Runtime adapters, capability probes, model catalog, thinking control, ALCF OAuth | [configuration-and-targets.md](configuration-and-targets.md), [model-catalog.md](model-catalog.md), [provider-adapter-cookbook.md](provider-adapter-cookbook.md), [alcf-provider.md](alcf-provider.md) | `documented` | Complete provider adapter contracts, model catalogs, and ALCF Globus targets documented. |
33
+ | `src/domains/resources/` | Skill package discovery, marketplace index resolution, prompt resources | [skills-marketplace.md](skills-marketplace.md), [extensions-and-sharing.md](extensions-and-sharing.md) | `documented` | Skills marketplace, publishing flows, and resource managers documented. |
34
+ | `src/domains/safety/` | Policy engine, action classifiers, damage-control rules, path policies, finish contract, audit log | [safety-model.md](safety-model.md), [scientific-validation.md](scientific-validation.md) | `documented` | Policy evaluation order, 10-step sequence, write containment, and finish contract documented. |
35
+ | `src/domains/scheduling/` | Capacity lease acquisition, heartbeats, expiry, cross-process locks, cluster scheduling | [capacity-and-scheduling.md](capacity-and-scheduling.md), [fleet-dispatch.md](fleet-dispatch.md) | `documented` | Dedicated capacity leasing, heartbeat TTL, and cross-process lock reference. |
36
+ | `src/domains/session/` | Context ledger v3, tree branching (`/tree`), `/fork`, `/resume`, checkpoints, protected-artifact journal | [session-lifecycle.md](session-lifecycle.md) | `documented` | Dedicated session lifecycle guide covering ledger format v3, branching, journal, and recovery. |
37
+ | `src/domains/share/` | Portable share archive bundles, manifest verification, import/export flows | [extensions-and-sharing.md](extensions-and-sharing.md) | `documented` | Share archives and portable bundle formats documented in extensions guide. |
38
+ | `src/domains/webhook/` | Empty directory | None (Inert) | `inert` | Directory contains no active modules or exports in v0.3.0. |
39
+
40
+ ## Cross-Cutting Reference Guides
41
+
42
+ In addition to source subsystem mappings, the documentation set includes cross-cutting contracts:
43
+
44
+ 1. [artifact-versions.md](artifact-versions.md): Canonical version registry and migration contract for all 9 serialized artifact schemas across Clio Coder.
45
+ 2. [glossary.md](glossary.md): Formal definitions of 17 core architectural concepts mapped to their TypeScript types in `src/`.
46
+ 3. [troubleshooting.md](troubleshooting.md): Comprehensive diagnostic and remediation guide keyed by exact user-facing error strings.
@@ -0,0 +1,166 @@
1
+ # Documentation Standards and Codebase Alignment
2
+
3
+ > [!TIP]
4
+ > **Interactive Spec Available:** An interactive documentation link linter, phrasing/claim evaluator, and alignment portal is located at [docs/html/documentation_blueprint.html](html/documentation_blueprint.html) (Version: 0.3.0).
5
+
6
+ Clio Coder is an experimental community alpha. Documentation should help contributors and early users work from the source of truth without overstating maturity. When docs drift, prefer the current source and tests over older prose or aspirational roadmap notes.
7
+
8
+ ---
9
+
10
+ ## Source-first documentation rule
11
+
12
+ Before changing public docs, inspect the relevant implementation:
13
+
14
+ 1. `git log --oneline -- <area>` for recent intent and release context.
15
+ 2. `src/**` for current behavior.
16
+ 3. `tests/**` for executable contracts and edge cases.
17
+ 4. `README.md`, `CHANGELOG.md`, and `docs/*.md` for existing public wording.
18
+
19
+ Classify claims clearly:
20
+
21
+ | Claim class | How to word it |
22
+ | --- | --- |
23
+ | Shipped and tested | State directly and link to source/tests. |
24
+ | Implemented but experimental | Say alpha/experimental and name sharp edges. |
25
+ | Typed contract exists, default runtime is inert | Say the schema exists but no public loader/rules are active. |
26
+ | Planned/future | Put in roadmap language; do not present as available behavior. |
27
+
28
+ ---
29
+
30
+ ## Documentation map
31
+
32
+ | Guide | Primary source references | What it should cover |
33
+ | --- | --- | --- |
34
+ | [README.md](../README.md) | `CHANGELOG.md`, package metadata, release receipts | Product overview, install, first run, alpha framing, and release status. |
35
+ | [docs/README.md](README.md) | This docs directory | Documentation hub. |
36
+ | [commands-and-modes.md](commands-and-modes.md) | `src/cli/index.ts`, `src/cli/args.ts`, `src/interactive/slash-commands.ts`, `src/domains/dispatch/**` | CLI commands, headless run flags (`--session`, `--continue`, `--json-events`), session continuity, `--json` wire projection promise, slash commands, keybindings, live steering. |
37
+ | [context-engine.md](context-engine.md) | `src/domains/context/**`, `src/domains/session/context-accounting.ts`, `src/domains/session/context-ledger.ts`, `src/domains/session/compaction/` | Context window resolution, per-model probe capabilities, token accounting, snapshots, progressive compaction, model-driven `clio-coder context init`, format v3 session enforcement. |
38
+ | [architecture.md](architecture.md) | `tests/boundaries/check-boundaries.ts`, `src/core/domain-loader.ts`, `src/engine/**`, `src/worker/**` | Source layout, 5 enforced boundary rules (dependency direction vs import form), runtime flow mermaid diagram, event/audit model, detect-and-rollback write boundaries. |
39
+ | [dispatch-architecture-rationale.md](dispatch-architecture-rationale.md) | `src/domains/dispatch/**`, `tests/boundaries/check-boundaries.ts` | Design rationale, not behavior: invariants that cross the seams a dispatch split would use, what any future split must preserve, the one dispatch→eval import, and the closed barrel-import decision. |
40
+ | [configuration-and-targets.md](configuration-and-targets.md) | `src/core/defaults.ts`, `src/core/config.ts`, `src/domains/providers/**`, `src/cli/configure.ts`, `src/cli/targets.ts`, `src/cli/models.ts`, `src/cli/auth.ts` | TargetDescriptor, contextWindowProvenance (`configured`, `discovered`, `catalog`, `runtime-default`), settings.yaml, strict validation, saved defaults vs live routing. |
41
+ | [safety-model.md](safety-model.md) | `src/domains/safety/**`, `src/tools/registry.ts`, `src/tools/policy.ts`, `src/tools/verify/**`, `src/entry/orchestrator.ts`, `src/domains/dispatch/write-boundary.ts` | Operating posture, `resolveEffectiveAutonomy` / `resolveBaselineAutonomy`, detect-and-rollback write boundaries, approval axes, damage control, typed validation. |
42
+ | [prompt-envelope-and-tools.md](prompt-envelope-and-tools.md) | `src/domains/prompts/compiler.ts`, `src/interactive/chat-loop.ts`, `src/core/tool-names.ts`, `src/tools/registry.ts`, `src/tools/observation.ts`, `src/tools/agent-tools.ts` | Prompt envelope reuse, canonical tool delivery via single `agent-tools.ts` adapter, seven-plane tool surface, observation envelope, strict `ToolName` keying. |
43
+ | [tool-usage.md](tool-usage.md) | `src/tools/agent-tools.ts`, `src/tools/registry.ts`, `src/tools/observation.ts` | In-depth reference for all 19 worker tools: parameters, typical payloads, `prepareArguments` normalizers, and error examples. |
44
+ | [provider-adapter-cookbook.md](provider-adapter-cookbook.md) | `src/domains/providers/registry.ts`, `src/domains/providers/types/runtime-descriptor.ts` | RuntimeDescriptor, probe(), probeReasoning(), synthesizeModel(), thinking mechanisms. |
45
+ | [alcf-provider.md](alcf-provider.md) | `src/domains/providers/runtimes/cloud/alcf.ts`, `src/engine/alcf-oauth.ts` | Globus PKCE OAuth, openAuthStorage(), Sophia vLLM, Metis API, chatTemplateKwargsUnsupported. |
46
+ | [environment-variables.md](environment-variables.md) | `src/core/guardrails.ts`, `src/core/xdg.ts`, `src/domains/providers/knowledge-base-path.ts` | Comprehensive env var matrix: guardrail overrides, directory layout (CLIO_CODER_HOME), debug toggles, and internal plumbing. |
47
+ | [built-in-agents.md](built-in-agents.md) | `src/domains/agents/**`, `src/domains/agents/builtins/*.md`, `src/domains/dispatch/**` | Builtin agent recipes, discovery roots, frontmatter schema, fleet contract shadowing (`.clio-coder/fleets/<name>.md`), active route automation. |
48
+ | [fleet-dispatch.md](fleet-dispatch.md) | `src/domains/dispatch/**` | Multi-node SSH dispatch: process-safe admission, capacity leases, Contract v4 write boundaries (detect-and-rollback), bounded check/repair loops (`loop_bound_exhausted`), deterministic code steps, attestation, receipts v15. |
49
+ | [capacity-and-scheduling.md](capacity-and-scheduling.md) | `src/domains/scheduling/**`, `src/domains/dispatch/capacity-lease.ts`, `src/domains/dispatch/reservation-store.ts` | Multi-process capacity leases (`dispatch-admission.json`), heartbeat TTLs, cross-process transaction locks (`dispatch-admission.json.lock`), and cluster drain controls. |
50
+ | [worker-dispatch-mechanics.md](worker-dispatch-mechanics.md) | `src/worker/**` | NDJSON parent-child socket protocols, control/bulk lane demuxing, watchdog timers, worker attestation (13 protocol fields), permission parking, exit codes. |
51
+ | [fleet-demo-runbook.md](fleet-demo-runbook.md) | `src/domains/dispatch/**` | Multi-node fleet demo: SSH setup, C++ build/repair workflow, reviewer gates, receipt verification v15. |
52
+ | [session-lifecycle.md](session-lifecycle.md) | `src/engine/session.ts`, `src/domains/session/**` | Session lifecycle, on-disk ledger format v3 (`current.jsonl`), tree branching (`tree.json`), active-path lineage selection, `/fork`, `/resume`, checkpoints, and write-ahead protected-artifact journal. |
53
+ | [acp.md](acp.md) | `src/engine/acp/**`, `src/cli/acp.ts` | Agent Client Protocol (ACP) server over stdio, tool mediation, non-stall permission handling, timeout bounds, and error taxonomy. |
54
+ | [artifact-versions.md](artifact-versions.md) | `src/domains/dispatch/receipt-integrity.ts`, `src/engine/session.ts`, `src/worker/spec-contract.ts`, `src/domains/agents/fleet-contract.ts`, `src/domains/eval/schema/`, `src/domains/observability/trace-store.ts` | Version registry and migration policies for all 9 serialized artifact schemas across Clio Coder. |
55
+ | [exit-codes-and-output.md](exit-codes-and-output.md) | `src/cli/**`, `src/entry/**` | Global process exit codes (0, 1, 2, 3), `--help` standard on stdout, machine-readable JSON streaming (`--json`, `--json-events`), and headless stdout deliverable contracts. |
56
+ | [troubleshooting.md](troubleshooting.md) | `src/core/**`, `src/cli/**`, `src/domains/**` | Actionable error remediation and diagnostics keyed by exact user-facing messages. |
57
+ | [glossary.md](glossary.md) | `src/domains/dispatch/types.ts`, `src/tools/**`, `src/domains/agents/**`, `src/core/**` | Canonical definitions of 17 core architectural concepts mapped to `src/` types. |
58
+ | [documentation-coverage.md](documentation-coverage.md) | `src/**` | Complete source-to-documentation mapping matrix and subsystem coverage status. |
59
+ | [tui-design.md](tui-design.md) | `src/interactive/theme/tokens.ts`, `src/interactive/theme/glyphs.ts` | TUI color system, glyph vocabulary (`contextReserve`), structural layouts, state choreography, code ink. |
60
+ | [installation-and-lifecycle.md](installation-and-lifecycle.md) | `src/cli/paths.ts`, `src/cli/doctor.ts`, `src/cli/uninstall.ts`, `src/cli/removal.ts` | Installation, upgrade, reset, uninstallation, launcher ownership and what `--remove-binary` will and will not remove, partial-failure behavior, configuration folders (`credentials.yaml` `0o600`), and permissions. |
61
+ | [release-cut-checklist.md](release-cut-checklist.md) | `scripts/check-release.mjs`, `scripts/lifecycle-matrix.mjs`, `package.json` | Ordered release-cut steps with an explicit authorization boundary: everything external or irreversible is marked not run and needs an operator decision. |
62
+ | [observability.md](observability.md) | `src/domains/observability/**`, `src/interactive/view/**`, `src/domains/dispatch/**`, `src/core/bus-events.ts` | `/view` artifact browsing, receipt verification, worker diagnostics, event routing, and cost snapshots. |
63
+ | [evidence-and-memory.md](evidence-and-memory.md) | `src/domains/evidence/**`, `src/domains/memory/**`, `src/cli/evidence.ts`, `src/cli/memory.ts` | Evidence corpus layout, findings, memory lifecycle and prompt injection. |
64
+ | [proactive-memory.md](proactive-memory.md) | `src/domains/memory/**` | Proactive task memory architecture, session task bank, intervention rules, and handoff carrying. |
65
+ | [trace-store.md](trace-store.md) | `src/cli/trace.ts`, `src/domains/observability/trace-store.ts` | WAL SQLite trace mirror database schema, rowid cursor queries, rebuildability, 6 `clio-coder trace` subcommands (`runs`, `phases`, `tail`, `procs`, read-only `sql` SELECT, `ui`). |
66
+ | [eval-runner.md](eval-runner.md) | `src/domains/eval/**`, `src/cli/eval.ts` | Local YAML eval tasks, dual token accountings (`tokens.*` wire vs `receiptUsage.*` journal), fail-closed null totals, EvalArtifactV4 format, `verify.measure` task outcome recording. |
67
+ | [evals-internal.md](evals-internal.md) | `src/domains/eval/**`, `benchmarks/soak/**` | Private context index determinism, target smoke matrices, soak machinery benchmark suite (4 suites: `clio-soak`, `clio-soak-boundary`, `clio-soak-chaos`, `clio-soak-loop`). |
68
+ | [extensions-and-sharing.md](extensions-and-sharing.md) | `src/domains/extensions/**`, `src/domains/resources/**`, `src/domains/share/**`, `src/cli/extensions.ts`, `src/cli/share.ts` | Prompt and skill resources, extension manifests, portable share archives. |
69
+ | [skills-marketplace.md](skills-marketplace.md) | `src/interactive/overlays/skills-hub.ts`, `src/domains/resources/skills/marketplace.ts` | Skills Hub marketplace discovery through the install resolver, empty state, install actions, publishing flow. |
70
+ | [model-catalog.md](model-catalog.md) | `src/domains/providers/catalog.ts`, `src/domains/providers/models/**`, `src/domains/providers/probe/**`, `src/domains/providers/model-capabilities.ts` | Model catalog, live probes (`--offline` toggle), exact-id selector `probeCapabilitiesForModel`, field-note promotion. |
71
+ | [middleware-and-components.md](middleware-and-components.md) | `src/domains/components/**`, `src/domains/middleware/**`, `src/cli/components.ts` | Active component snapshots, phase-aware middleware hook budgets (`DEFAULT_MIDDLEWARE_HOOK_BUDGETS_MS`). |
72
+ | [scientific-validation.md](scientific-validation.md) | `src/domains/safety/rigor.ts`, `src/domains/safety/finish-contract.ts` | Advisory validation-contract patterns for scientific artifacts and HPC assumptions. |
73
+ | [evolution.md](evolution.md) | `src/domains/evolution/**`, `src/cli/evolve.ts` | Falsifiable Change Manifest JSON templates, evidence-linked validation, and `clio-coder evolve`. |
74
+ | [config-knobs-audit.md](config-knobs-audit.md) | `src/cli/config.ts` | Point-in-time inventory of legacy environment variables (Historical Appendix). |
75
+
76
+ ---
77
+
78
+ ## Style conventions
79
+
80
+ ### Alpha framing
81
+
82
+ Use direct, honest language:
83
+
84
+ - "experimental community alpha"
85
+ - "source-build path"
86
+ - "current runtime is conservative/inert"
87
+ - "advisory contract"
88
+ - "planned/future milestone"
89
+
90
+ Avoid phrases that imply managed production stability, full plugin maturity, or automatic scientific validation when the current code does not provide it.
91
+
92
+ ### Markdown structure
93
+
94
+ - Prefer short sections with tables for command and schema references.
95
+ - Use fenced examples that can be copied.
96
+ - Keep links relative and repository-portable; do not use absolute `file:///home/...` links.
97
+ - Mention source file paths in backticks instead of editor-specific absolute URLs.
98
+
99
+ ### GitHub alerts
100
+
101
+ Use alerts sparingly:
102
+
103
+ > [!NOTE]
104
+ > Context or caveats that prevent misinterpretation.
105
+
106
+ > [!WARNING]
107
+ > Sharp edges, alpha limitations, or behavior that can surprise contributors.
108
+
109
+ > [!CAUTION]
110
+ > Safety, data loss, or security-sensitive constraints.
111
+
112
+ ---
113
+
114
+ ## Blueprint Coverage & Format Strategy
115
+
116
+ Clio Coder maintains two complementary documentation formats:
117
+
118
+ 1. **Markdown Documents (`docs/*.md`)**: The single canonical reference for coding agents, developers, and maintainers. They optimize for retrievability, exact enumerations, schema tables, typed TypeScript contracts, and source citations (`src/...:line`).
119
+ 2. **Interactive HTML Blueprints (`docs/html/*.html`)**: Visual reference cards and client-side simulators designed for human operators exploring dynamic behaviors (such as safety rule evaluation, token compaction calculation, YAML target validation, and prompt structure).
120
+
121
+ ### Blueprint Creation Policy
122
+
123
+ Not every markdown document earns a standalone interactive HTML blueprint. Reference specifications—such as `artifact-versions.md`, `exit-codes-and-output.md`, `glossary.md`, `troubleshooting.md`, `session-lifecycle.md`, `acp.md`, `capacity-and-scheduling.md`, and `documentation-coverage.md`—are authoritative tabular contracts and state machine specifications. Building client-side JavaScript simulators for these documents would duplicate runtime validation logic and introduce synchronization hazards across releases. These pages are therefore linked directly from `docs/html/index.html` as Markdown Reference Specifications with explicit visual distinction from interactive simulator blueprints.
124
+
125
+ ---
126
+
127
+ ## Update checklist
128
+
129
+ When a feature changes:
130
+
131
+ 1. Identify the source owner (`src/cli`, `src/interactive`, `src/tools`, or a domain).
132
+ 2. Check whether public CLI help changed.
133
+ 3. Update the mapped guide in the same PR.
134
+ 4. If behavior affects safety, sessions, receipts, prompts, targets, or dispatch, update both README-level user docs and the deeper guide.
135
+ 5. Run a lightweight link check for changed Markdown.
136
+ 6. For release docs, verify version badges/sections match `package.json` and `CHANGELOG.md`.
137
+
138
+ Suggested local link check:
139
+
140
+ ```bash
141
+ python3 - <<'PY'
142
+ import pathlib, re
143
+ for md in list(pathlib.Path('docs').glob('*.md')) + [pathlib.Path('README.md')]:
144
+ text = md.read_text()
145
+ for m in re.finditer(r'\[[^\]]+\]\(([^)]+)\)', text):
146
+ link = m.group(1)
147
+ if link.startswith(('http://', 'https://', 'mailto:', '#')):
148
+ continue
149
+ target = link.split('#')[0]
150
+ if target and not (md.parent / target).exists():
151
+ line = text.count('\n', 0, m.start()) + 1
152
+ print(f'{md}:{line}: missing {link}')
153
+ PY
154
+ ```
155
+
156
+ ---
157
+
158
+ ## Community documentation priorities
159
+
160
+ Clio users tend to be early adopters running real repositories, local models, and scientific/HPC code. Good docs should therefore prioritize:
161
+
162
+ - reproducible first-run and target configuration;
163
+ - local model/runtime field notes with exact versions and serving settings;
164
+ - safety receipts and redaction guidance for issue reports;
165
+ - small examples for project-local `CLIO-CODER.md`, `.clio-coder/safety.yaml`, prompts, skills, and agents;
166
+ - clear labels for experimental surfaces such as middleware and scientific validation contracts.