@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,105 @@
1
+ # Clio Coder Scientific Validation Contracts
2
+
3
+ > [!TIP]
4
+ > **Interactive Spec Available:** An interactive numerical tolerance calculator and HPC queue execution simulator is located at [docs/html/validation_blueprint.html](html/validation_blueprint.html) (Version: 0.3.0).
5
+
6
+ Scientific software development cannot treat simple file presence as proof of correctness. A simulation script that crashes on rank 48, or writes out NetCDF arrays filled with `NaN`s, may still successfully write a file to the disk.
7
+
8
+ Clio Coder recognizes **scientific validation contract files** as an opt-in signal for a higher evidence bar. In v0.3.0, core Clio does not parse or enforce a scientific contract schema. The presence of `.clio-coder/validation.yaml`, `.clio-coder/validation.yml`, `validation.yaml`, `validation.yml`, or `VALIDATION.md` at the workspace root raises the default rigor level to `high`; the file contents are advisory material for developers, project agents, and external validators.
9
+
10
+ The convention below is a recommended shape for scientific projects that need to document expected dimensions, attributes, numerical tolerances, scheduler context, and verification commands for scientific artifacts. Developed at the [Gnosis Research Center (GRC)](https://grc.iit.edu) at Illinois Tech as part of the NSF-funded scientific-software context (NSF Award [#2411318](https://www.nsf.gov/awardsearch/showAward?AWD_ID=2411318)), this convention links execution metadata with physical output checks without claiming that the current harness executes those checks automatically.
11
+
12
+ ---
13
+
14
+ ## Validation Contract Convention
15
+
16
+ A validation contract can be stored as YAML or Markdown. A custom or project-level agent (such as a local `scientific-validator` agent example under `.clio-coder/agents/`) or the developer can draft these files and commit them next to the research code. Clio core currently checks only for the documented filenames at the workspace root.
17
+
18
+ ### Example netCDF / Slurm validation contract:
19
+ ```yaml
20
+ version: 1
21
+ task: "Regenerate the regional climate output and confirm grid metadata."
22
+ runtime:
23
+ kind: slurm
24
+ nodes: 4
25
+ ranks: 64
26
+ walltime: "01:30:00"
27
+ modules:
28
+ - "intel/2024"
29
+ - "openmpi/5.0"
30
+ - "netcdf-c/4.9"
31
+ artifacts:
32
+ - path: out/region_west.nc
33
+ format: NetCDF
34
+ expected_dimensions:
35
+ time: 8760
36
+ lat: 360
37
+ lon: 720
38
+ expected_attributes:
39
+ Conventions: "CF-1.10"
40
+ numerical_tolerances:
41
+ relative: 1.0e-6
42
+ preserve: false
43
+ - path: ckpt/run-0042.chk
44
+ format: Checkpoint files
45
+ preserve: true
46
+ validators:
47
+ - "ncdump -h out/region_west.nc"
48
+ - "python tools/check_grid.py out/region_west.nc"
49
+ notes: |
50
+ The run is submitted with sbatch; queue exit status is not a completion check.
51
+ Re-run check_grid.py after job completion is observed.
52
+ ```
53
+
54
+ ### Suggested Fields:
55
+ 1. **`version`:** Set to `1` for project-local compatibility.
56
+ 2. **`runtime.kind`:** Document execution mode (`local`, `slurm`, `mpi`, or `other`).
57
+ 3. **`artifacts`:** List output files or directories the validation plan should inspect.
58
+ 4. **`preserve`:** Project convention for artifacts that should not be deleted by cleanup workflows. Clio's built-in protected-artifact guard is separate and is driven by live `protect_path` effects, not by this YAML field.
59
+ 5. **`validators`:** List shell commands or scripts a verifier should run to validate the generated files.
60
+
61
+ ---
62
+
63
+ ## Numerical Tolerances
64
+
65
+ Comparing floating-point values in scientific computations must accommodate round-offs, hardware differences, and compiler optimizations. Project validators can document any tolerance vocabulary they enforce. A common convention is:
66
+
67
+ | Tolerance Type | Formula / Check | Purpose |
68
+ | :--- | :--- | :--- |
69
+ | **`relative`** | $\frac{|val - ref|}{|ref|} \le relative$ | Fractional difference check. Crucial for scaling datasets. |
70
+ | **`absolute`** | $|val - ref| \le absolute$ | Additive difference check. Used when reference value is close to `0`. |
71
+ | **`ulp`** | $StepsBetween(val, ref) \le ulp$ | Unit in the Last Place. Measures floating-point representation steps. |
72
+
73
+ > [!NOTE]
74
+ > Clio core does not currently execute tolerance comparisons and does not apply a default numerical tolerance. Put defaults directly in project validators or contract text.
75
+
76
+ ---
77
+
78
+ ## Common Scientific Artifact Families
79
+
80
+ The following labels are useful project conventions for validation contracts and reports. They are not a closed, core-enforced enum in v0.3.0:
81
+
82
+ - **`HDF5` / `NetCDF` / `Zarr`:** Multi-dimensional scientific array files.
83
+ - **`FITS`:** Flexible Image Transport System (used in astrophysics).
84
+ - **`CSV` / `Parquet`:** Structured tabular data and datasets.
85
+ - **`VTK and ParaView`:** Visualizations and mesh outputs.
86
+ - **`Slurm job output`:** Standard logs emitted by Slurm queue managers.
87
+ - **`MPI rank-sensitive tests`:** Diagnostic outputs matching multi-rank jobs.
88
+ - **`Checkpoint files` / `Simulation restart artifacts`:** Stateful binary dumps.
89
+ - **`Plots and generated figures`:** Output graphics (verified via path + checksum metadata).
90
+
91
+ ## HPC Schedulers and Validation Lifecycle
92
+
93
+ Scheduler-driven runs require distinct validation handling compared to local unit tests:
94
+ - **Queue status is not validation**: Checking if a Slurm command like `sbatch` exits successfully only proves that the Slurm scheduler accepted the job script. A good contract tells the verifier how to check actual simulation artifacts inside `out/` or `ckpt/` after job completion.
95
+ - **Environment module loading**: The `runtime.modules` array can document the exact software stack dependencies (such as `intel/2024`, `openmpi/5.0`) that must be loaded before running the validators.
96
+ - **HPC and Data Integration**: For large-scale allocations such as those at the Argonne Leadership Computing Facility (ALCF), projects can archive verification logs through their own storage or data-transfer workflow. Clio core does not manage Globus transfers.
97
+ - **Validator execution**: In the current alpha version, contract validation is advisory. Quality/verification agents (such as the base `verifier` agent or custom project-level agents) read the contract to guide developers and write out verification receipts. Automated in-harness contract execution is not implemented yet.
98
+
99
+ ### How a Validation Contract Raises Session Rigor
100
+
101
+ Clio Coder integrates scientific validation contracts directly into its safety model to raise the evidence standard automatically:
102
+ - **Automatic Escalation**: At startup, Clio scans the workspace root. The presence of any validation contract (e.g. `.clio-coder/validation.yaml`, `.clio-coder/validation.yml`, `validation.yaml`, `validation.yml`, or `VALIDATION.md`) automatically escalates the session's rigor level from `normal` to `high`.
103
+ - **High-Rigor Gate Requirements**: Once the rigor is raised to `high`, the finish gate is active. It engages on a settled `turn_end` only when the recent window contains successful workspace mutation evidence and no validation evidence or explicit limitation. The window is entries since the last user message, capped at 80 entries:
104
+ - Clio issues a `request_continuation` middleware effect to keep the session running.
105
+ - Clio injects a dynamic warning reminder (`HIGH_RIGOR_REVALIDATION_MESSAGE`) instructing the agent to run a verification command or to declare a limitation before it can conclude the turn.
@@ -0,0 +1,156 @@
1
+ # Session Lifecycle
2
+
3
+ This document is the authoritative specification for Clio Coder interactive and headless session lifecycles, on-disk ledger structures, tree-based conversation branching, checkpoints, and recovery protocols in `v0.3.0`.
4
+
5
+ Source implementations: `src/engine/session.ts` and `src/domains/session/`.
6
+
7
+ ---
8
+
9
+ ## 1. On-Disk Session Layout
10
+
11
+ Sessions are persisted durably on disk under the platform state root (`clioStateDir()`, resolving to `~/.local/state/clio-coder` on Linux, `~/Library/Application Support/clio-coder/state` on macOS, or `%LOCALAPPDATA%\clio-coder\state` on Windows):
12
+
13
+ ```text
14
+ <stateDir>/sessions/<cwdHash>/<sessionId>/
15
+ meta.json # ClioSessionMeta JSON document
16
+ current.jsonl # Append-only structured session event ledger
17
+ tree.json # SessionTreeNode[] conversation tree graph
18
+ ```
19
+
20
+ - `<cwdHash>`: First 16 hexadecimal characters of SHA-256 of canonical workspace root path (`createHash("sha256").update(resolve(cwd)).digest("hex").slice(0, 16)`).
21
+ - `<sessionId>`: UUIDv7 generated at session initialization.
22
+
23
+ ---
24
+
25
+ ## 2. Session Metadata (`meta.json`)
26
+
27
+ Session metadata is written atomically (`.tmp` + `fsyncSync` + `renameSync`) by `src/engine/session.ts:atomicWrite` and updated without closing via `src/domains/session/manager.ts:persistSessionMeta`.
28
+
29
+ ```typescript
30
+ export interface ClioSessionMeta {
31
+ id: string;
32
+ cwd: string;
33
+ cwdHash: string;
34
+ createdAt: string;
35
+ endedAt: string | null;
36
+ model: string | null;
37
+ target: string | null;
38
+ clioVersion: string;
39
+ piMonoVersion: string;
40
+ platform: string;
41
+ nodeVersion: string;
42
+ sessionFormatVersion?: number; // CURRENT_SESSION_FORMAT_VERSION = 3
43
+ }
44
+ ```
45
+
46
+ Format version `CURRENT_SESSION_FORMAT_VERSION = 3` (`src/engine/session.ts:66`) is stamped on all sessions created in `v0.3.0`. Sessions with missing or earlier format versions trigger schema migrations in `src/domains/session/migrations/` on `/resume`.
47
+
48
+ ---
49
+
50
+ ## 3. Append-Only Context Ledger (`current.jsonl`)
51
+
52
+ The session ledger `current.jsonl` records all conversation events, model turns, tool executions, and checkpoints in strict append-only order.
53
+
54
+ ### Header Line
55
+
56
+ The first line of `current.jsonl` is the canonical session header:
57
+
58
+ ```json
59
+ {"type":"session","version":3,"id":"01912a34-b567-7890-abcd-ef0123456789","timestamp":"2026-08-14T12:00:00.000Z","cwd":"/path/to/project"}
60
+ ```
61
+
62
+ ### Entry Taxonomy
63
+
64
+ Subsequent lines represent typed `SessionEntry` objects (`src/domains/session/entries.ts`):
65
+
66
+ 1. **`message`**: User inputs, assistant responses, and tool calls/results.
67
+ ```typescript
68
+ export interface MessageEntry {
69
+ kind: "message";
70
+ turnId: string;
71
+ parentTurnId: string | null;
72
+ timestamp: string;
73
+ role: "user" | "assistant" | "tool_call" | "tool_result" | "system" | "checkpoint";
74
+ payload: unknown;
75
+ }
76
+ ```
77
+ 2. **`label`**: User-defined turn bookmark or tag anchored to `targetTurnId`.
78
+ 3. **`sessionInfo`**: Metadata event (such as model switch, target change, or thinking level adjustment).
79
+ 4. **`compactionSummary`**: Progressive compaction snapshot retaining historical context up to `firstKeptTurnId`.
80
+
81
+ ### Write Durability & Atomicity
82
+
83
+ - Appends hold an open `O_APPEND` file descriptor across the writer lifetime (`src/engine/session.ts:openSync`).
84
+ - Each line append is executed via a single `write(2)` call.
85
+ - `fsyncSync` is debounced during high-frequency streaming turns and unconditionally forced on checkpoint (`persistTree`) and session shutdown (`close`).
86
+ - Torn last lines resulting from abrupt system crashes or power losses are tolerated by the ledger reader (`src/engine/session.ts:readSessionFileEntries`), which logs a warning and skips the incomplete trailing record.
87
+
88
+ ---
89
+
90
+ ## 4. Conversation Tree Graph (`tree.json`) & Lineage
91
+
92
+ Clio Coder tracks all conversation turns as a directed tree graph, enabling non-destructive branching, navigation, and message forking.
93
+
94
+ ### Tree Structure
95
+
96
+ `tree.json` stores the complete node linkage:
97
+
98
+ ```typescript
99
+ export interface SessionTreeNode {
100
+ id: string; // UUIDv7 turn identifier
101
+ parentId: string | null; // UUIDv7 parent turn identifier
102
+ at: string; // ISO-8601 creation timestamp
103
+ kind: "user" | "assistant" | "tool_call" | "tool_result" | "system" | "checkpoint";
104
+ }
105
+ ```
106
+
107
+ ### Active Path Lineage Selection
108
+
109
+ When an operator branches or switches turns using `/tree` or `Alt+T`, the next append point changes without mutating or deleting historical entries in `current.jsonl`.
110
+
111
+ The active path filter (`src/domains/session/tree/active-path.ts:filterEntriesToActivePath`) traces ancestry back from the active leaf:
112
+ 1. Retains all message entries on the direct ancestral path from leaf to root.
113
+ 2. Retains sidecar entries anchored to turns on the active path (`targetTurnId`, `parentTurnId`, or `firstKeptTurnId`).
114
+ 3. Retains unanchored global sidecars (`parentTurnId: null`).
115
+ 4. Prunes abandoned sibling branches from the context window supplied to the LLM.
116
+
117
+ ### Branch Forking (`/fork`)
118
+
119
+ The `/fork` command (`src/domains/session/tree/fork.ts:forkFromParentTurn`) initializes an independent session branched from an arbitrary turn:
120
+ 1. Closes the current session writer.
121
+ 2. Creates a new session directory and metadata inheriting `cwd`, `model`, and `target` from the parent.
122
+ 3. Traces ancestry up to `parentTurnId` and copies only the active path entries into the new session ledger.
123
+ 4. Stamps `parentSession` and `parentTurnId` in the new session header.
124
+
125
+ ---
126
+
127
+ ## 5. Session Resumption (`/resume`) & Working Directory Fallback
128
+
129
+ When resuming a session via `/resume <sessionId>` or `CLIO_CODER_RESUME_SESSION_ID`:
130
+ 1. `src/domains/session/manager.ts:resumeSessionState` loads `meta.json` and runs migrations.
131
+ 2. `src/domains/session/cwd-fallback.ts:resolveSessionCwd` probes the recorded `meta.cwd` against the filesystem.
132
+ 3. If the directory is invalid, it returns a typed failure reason:
133
+ - `no-cwd`: `meta.cwd` is missing or empty.
134
+ - `missing`: The directory no longer exists on disk.
135
+ - `not-a-directory`: The path points to a non-directory file or broken symlink.
136
+ 4. The interactive layer displays the `cwd-fallback` overlay prompting the operator to choose a valid workspace directory.
137
+
138
+ ---
139
+
140
+ ## 6. Protected-Artifact Write-Ahead Journal
141
+
142
+ To guarantee that protected artifacts and validation locks survive unexpected crashes between tool execution and ledger commitment, Clio Coder maintains a write-ahead journal (`src/domains/session/protected-artifact-journal.ts`):
143
+
144
+ - Location: `<stateDir>/protected-artifact-pending/<sessionKey>/<recordId>.json`
145
+ - Lifecycle:
146
+ 1. **Stage**: Before a mutating tool result is returned, the protected artifact registration is staged atomically to the journal directory.
147
+ 2. **Commit**: Once the turn completes and appends to `current.jsonl`, the staged journal file is unlinked.
148
+ 3. **Reconcile**: During session startup or resume, `reconcilePendingProtectedArtifacts` reads any leftover staged records and injects them into the protection engine before accepting user commands.
149
+
150
+ ---
151
+
152
+ ## 7. In-Session Task Board & Usage Accounting
153
+
154
+ - **Task Board** (`src/domains/session/task-board.ts`): Maintains session task items with states (`todo`, `in_progress`, `done`, `failed`). Emits middleware reminders when uncompleted tasks remain before turn end.
155
+ - **Usage Accounting** (`src/domains/session/usage.ts`): Aggregates session token counts across input, output, cache read, cache write, and reasoning tokens. Anchors against provider-reported totals on settled turns.
156
+ - **Aborted Turn Persistence**: When a turn is interrupted by `Ctrl+C` or a SIGINT signal, partial assistant output and completed tool executions are committed to `current.jsonl` with `interrupted: true` before yielding the prompt.
@@ -0,0 +1,46 @@
1
+ # Skills Marketplace
2
+
3
+ > [!TIP]
4
+ > **Interactive Spec Available:** An interactive dashboard is located at [docs/html/skills_blueprint.html](html/skills_blueprint.html) (Version: 0.3.0).
5
+
6
+ The Skills Hub (`/skill`) shows project skills, user skills, and the marketplace. Every marketplace row comes from the same local lookup that `clio-coder skills install <name>` and `/skill:<name>` resolve through, so the hub lists nothing it cannot install.
7
+
8
+ ## Where marketplace rows come from
9
+
10
+ There is one source, `discoverMarketplaceSkills()` in `src/domains/resources/skills/marketplace.ts`, and it reads two kinds of real local data:
11
+
12
+ 1. **A catalog directory** of actual `SKILL.md` packages: `CLIO_CODER_SKILL_CATALOG_DIR`, or a `skills/` directory in the working tree when it holds packages. Metadata comes from the packages themselves through the skill loader, so a row's version, category, and audit state are the package's own.
13
+ 2. **A JSON index** at `CLIO_CODER_SKILL_MARKETPLACE_INDEX` or `<configDir>/skill-marketplace.json`, whose entries name a `sourceUrl` that `clio-coder skills install` accepts. `npm run skills:pin` publishes that file's `version`, `audit`, and `category` fields.
14
+
15
+ Catalog packages win over index entries on a name collision, because the local files are the thing that installs. Neither source reaches the network; the hub opens on local data and never blocks.
16
+
17
+ When both sources are absent the hub has nothing to list and says so, naming the remedy:
18
+
19
+ ```
20
+ no skills installed and no local marketplace configured. install one with
21
+ `clio-coder skills install <path|github-url>`, or point CLIO_CODER_SKILL_CATALOG_DIR at a
22
+ skills/ catalog.
23
+ ```
24
+
25
+ The CLI reports the same state as `no local skill marketplace catalog or index configured`. A marketplace source that exists but fails (an unreadable index, a broken catalog package) is a diagnostic row in the hub, not a silent omission.
26
+
27
+ ## Using the hub
28
+
29
+ | Key | Action |
30
+ |---|---|
31
+ | type | Filter all groups |
32
+ | `Enter` | Insert `/skill:<name> ` into the editor for the task text |
33
+ | `Tab` | Toggle the detail pane (split layout on wide terminals) |
34
+ | `i` | Install the selected marketplace skill into the project scope through the local marketplace resolver |
35
+ | `PgUp`/`PgDn` | Scroll the detail pane |
36
+
37
+ Invoking an uninstalled marketplace skill with `/skill:<name>` prompts before installing it. `i` runs the same install path eagerly from the hub.
38
+
39
+ The CLI `clio-coder skills` commands manage local skill discovery, validation, and
40
+ creation. Extension resource roots and share archives are documented in
41
+ [extensions-and-sharing.md](extensions-and-sharing.md); this page owns the TUI
42
+ Hub and marketplace behavior.
43
+
44
+ ## Publishing a skill
45
+
46
+ Add a directory under `skills/<category>/<name>/` (or `skills/<name>/`) in the repo containing a `SKILL.md` with `name` and `description` frontmatter. The directory name must match `[A-Za-z0-9][A-Za-z0-9._-]*`. Run `npm run skills:pin` to republish `skills/skill-marketplace.json`, which is the index consumers point `CLIO_CODER_SKILL_MARKETPLACE_INDEX` at or copy to `<configDir>/skill-marketplace.json`. Scientific and niche coding domains are the marketplace's focus; see the existing `skills/` tree for the house format.