@iowarp/clio-coder 0.3.0 → 0.3.1
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.
- package/CHANGELOG.md +33 -0
- package/README.md +50 -53
- package/dist/acp-FPR54DGL.js +138 -0
- package/dist/{agents-Q4MYPMUW.js → agents-OGPIHPJH.js} +33 -25
- package/dist/assets/codewiki.json +1 -0
- package/dist/assets/grammars/notices/@vscode__tree-sitter-wasm/LICENSE +21 -0
- package/dist/assets/grammars/notices/@vscode__tree-sitter-wasm/cgmanifest.json +16 -0
- package/dist/assets/grammars/notices/tree-sitter-wasms/LICENSE +24 -0
- package/dist/assets/grammars/tree-sitter-c-sharp.wasm +0 -0
- package/dist/assets/grammars/tree-sitter-c.wasm +0 -0
- package/dist/assets/grammars/tree-sitter-cpp.wasm +0 -0
- package/dist/assets/grammars/tree-sitter-go.wasm +0 -0
- package/dist/assets/grammars/tree-sitter-java.wasm +0 -0
- package/dist/assets/grammars/tree-sitter-javascript.wasm +0 -0
- package/dist/assets/grammars/tree-sitter-python.wasm +0 -0
- package/dist/assets/grammars/tree-sitter-ruby.wasm +0 -0
- package/dist/assets/grammars/tree-sitter-rust.wasm +0 -0
- package/dist/assets/grammars/tree-sitter-tsx.wasm +0 -0
- package/dist/assets/grammars/tree-sitter-typescript.wasm +0 -0
- package/dist/assets/grammars/tree-sitter.wasm +0 -0
- package/dist/{auth-O6HYIJ6J.js → auth-IC3K6NIZ.js} +22 -15
- package/dist/{chunk-KKKPTZLM.js → chunk-2STGEDFV.js} +8 -1
- package/dist/chunk-3I7MS7N2.js +40 -0
- package/dist/chunk-3R73A4XB.js +69 -0
- package/dist/{chunk-26BZQOAD.js → chunk-474KN5II.js} +86 -115
- package/dist/{chunk-NI4DEJMC.js → chunk-4QKXUHSR.js} +26 -3
- package/dist/{chunk-X3BR7HWV.js → chunk-5WIGXA4T.js} +7 -1
- package/dist/{chunk-TFSSEXL6.js → chunk-673JJUWJ.js} +14 -4
- package/dist/{chunk-GNGDQYDU.js → chunk-7SS2CTV2.js} +27922 -1249
- package/dist/{chunk-7RBKDI66.js → chunk-ASND7OZK.js} +104 -12
- package/dist/{chunk-X3NE4WVW.js → chunk-BNAZZHFG.js} +7 -1
- package/dist/{chunk-RQDWMVRB.js → chunk-BSU2YIWB.js} +9 -3
- package/dist/{chunk-CLJ5HLUD.js → chunk-C4PTHK7P.js} +24 -5
- package/dist/{chunk-QV47YRF4.js → chunk-CGKSTWHD.js} +7 -1
- package/dist/{chunk-BYEU76JP.js → chunk-DKGKUHFA.js} +34 -9
- package/dist/chunk-EYOKLTMF.js +170 -0
- package/dist/{chunk-PS4PFJQP.js → chunk-FCIH3BIZ.js} +15258 -14130
- package/dist/{chunk-2J63S4SF.js → chunk-FST4FYJB.js} +82 -14
- package/dist/{chunk-3DANZDGR.js → chunk-G34LV2PF.js} +34 -9
- package/dist/{chunk-BBUH4VAA.js → chunk-GAEBEQVI.js} +34 -21
- package/dist/chunk-GB6QRBXN.js +8543 -0
- package/dist/chunk-GEP36Y4X.js +12796 -0
- package/dist/{chunk-TKHQ4DGZ.js → chunk-H6F6BYOH.js} +496 -121
- package/dist/{chunk-UGYAX5YI.js → chunk-HQQID6OA.js} +10 -5
- package/dist/chunk-IHXBNWMM.js +137 -0
- package/dist/{chunk-ME6DNWIU.js → chunk-IS3ONKU3.js} +7 -1
- package/dist/{chunk-DXQNI4PC.js → chunk-IWHMRKLL.js} +8 -1
- package/dist/chunk-K2ITRMHZ.js +642 -0
- package/dist/{chunk-KBR4MZZR.js → chunk-K5XEMXTI.js} +7 -1
- package/dist/{chunk-AMFR5YA3.js → chunk-KKNLWXI6.js} +24 -10
- package/dist/{chunk-JWHCJDCI.js → chunk-KY56HMHH.js} +145 -61
- package/dist/{chunk-E3NYWENM.js → chunk-LU4TK2PR.js} +52 -7
- package/dist/{chunk-UWIJNAOB.js → chunk-M5T5VO65.js} +109 -42
- package/dist/{chunk-JPOWPFCU.js → chunk-MAR7Y6HW.js} +38 -16
- package/dist/chunk-N6F52NLF.js +6951 -0
- package/dist/{chunk-UHTSULZS.js → chunk-NMOX6HFD.js} +20 -7
- package/dist/{chunk-WD6AJM35.js → chunk-OLBBMFRD.js} +30 -13
- package/dist/{chunk-VOO7NYPP.js → chunk-PFEFKVGL.js} +22 -6
- package/dist/{chunk-6CWDTGUC.js → chunk-PIUMUEMV.js} +7 -1
- package/dist/chunk-PV4JUBVJ.js +462 -0
- package/dist/{chunk-527KG6XR.js → chunk-Q3RUPKEJ.js} +22 -4
- package/dist/{chunk-D5YD55AR.js → chunk-Q5WJOSJ7.js} +11 -1
- package/dist/{chunk-5N2FG33Q.js → chunk-R346GLFC.js} +7 -1
- package/dist/{chunk-4UQA7NCT.js → chunk-R5KLMSBV.js} +7 -2
- package/dist/{chunk-PIDUD6M2.js → chunk-RDLVBZEO.js} +11 -6
- package/dist/{chunk-O4EJEDHO.js → chunk-RPTR2H26.js} +40 -31
- package/dist/{chunk-HBU5MTAM.js → chunk-SVNXH4L2.js} +7 -1
- package/dist/{chunk-XNISANGE.js → chunk-TEKV33Q5.js} +122 -57
- package/dist/chunk-TXOTCRLG.js +15 -0
- package/dist/{chunk-VPAWTYLY.js → chunk-WEPFGWHJ.js} +7 -1
- package/dist/{chunk-HMYNFFY4.js → chunk-XPLRXC72.js} +7 -2
- package/dist/{chunk-UU3R62TT.js → chunk-XYWBQRDM.js} +13 -4
- package/dist/{chunk-7BHLZB3A.js → chunk-ZPY3JZ5E.js} +32 -10
- package/dist/cli/index.js +39 -33
- package/dist/clio-BZVGEUFJ.js +58 -0
- package/dist/{components-JVHMUBEB.js → components-DMAOEKFB.js} +26 -9
- package/dist/{config-ZFCDBMDC.js → config-IRUQ7SE4.js} +42 -31
- package/dist/configure-S7S6F6CL.js +32 -0
- package/dist/{context-CDXTP2MP.js → context-3KWFLHJG.js} +17 -11
- package/dist/{context-E3KIFVXI.js → context-5RADCKTR.js} +33 -28
- package/dist/{context-clear-3F4PLXOS.js → context-clear-7TSNPAAI.js} +36 -28
- package/dist/{context-index-Q7YSYTR3.js → context-index-W4RLWOQH.js} +10 -4
- package/dist/{docs-YIETIWZI.js → docs-5AWSPS37.js} +16 -10
- package/dist/doctor-UC5NAJYQ.js +77 -0
- package/dist/{eval-B3KZZESM.js → eval-U6TJHRLX.js} +77 -24
- package/dist/{evidence-V67CHM35.js → evidence-YEGUW4L3.js} +34 -26
- package/dist/{evolve-YDZSUQYA.js → evolve-TXARCTPG.js} +39 -26
- package/dist/{extensions-SRG7XCAH.js → extensions-OZFJ3A3G.js} +13 -7
- package/dist/{fleet-CA2CRTVG.js → fleet-6G3DHNYE.js} +45 -37
- package/dist/fleet-preflight-DSNT37JK.js +23 -0
- package/dist/{init-2OZDJE2D.js → init-KZ5QTF6M.js} +42 -34
- package/dist/{memory-3PIQQAKX.js → memory-73ESV5YC.js} +35 -27
- package/dist/{models-DY35XI7Y.js → models-A4PVNWJK.js} +34 -23
- package/dist/{paths-5OMXW7Z4.js → paths-C4H6IV77.js} +12 -6
- package/dist/preload-6WVMHX3A.js +13 -0
- package/dist/{reset-PIFYNOS3.js → reset-BGW6OGMV.js} +17 -11
- package/dist/{run-3VSPP24F.js → run-YTPEYQOH.js} +60 -48
- package/dist/{share-D36RQCXM.js → share-YIFFV4NQ.js} +16 -10
- package/dist/{skills-F2MRLELY.js → skills-2V6RA3OQ.js} +18 -11
- package/dist/{skills-eval-E2ZTW4PL.js → skills-eval-S2TVJO4F.js} +45 -36
- package/dist/{targets-DZMEZAH4.js → targets-TYXLPB23.js} +61 -59
- package/dist/{trace-7NYCUI2J.js → trace-GGOJ6Q6Z.js} +9 -3
- package/dist/{uninstall-AD3JWHBB.js → uninstall-LLLT4F4W.js} +14 -8
- package/dist/{upgrade-WYYBKGDY.js → upgrade-33G2LMM5.js} +45 -23
- package/dist/{usage-ULIDAGFF.js → usage-ZAFSXKKG.js} +35 -27
- package/dist/version-KGEG7EPO.js +21 -0
- package/dist/{wiki-generate-PKFIX6OB.js → wiki-generate-NUQCVOQ3.js} +55 -45
- package/dist/worker/entry.js +101 -43
- package/docs/README.md +12 -9
- package/docs/acp.md +28 -5
- package/docs/alcf-provider.md +1 -1
- package/docs/architecture.md +23 -2
- package/docs/artifact-placement.md +101 -0
- package/docs/artifact-versions.md +1 -1
- package/docs/built-in-agents.md +4 -2
- package/docs/capacity-and-scheduling.md +1 -1
- package/docs/commands-and-modes.md +125 -41
- package/docs/configuration-and-targets.md +88 -18
- package/docs/context-engine.md +6 -2
- package/docs/development-pipeline.md +77 -0
- package/docs/documentation-coverage.md +4 -4
- package/docs/documentation-guide.md +3 -3
- package/docs/environment-variables.md +2 -1
- package/docs/eval-runner.md +3 -3
- package/docs/evals-internal.md +2 -2
- package/docs/evidence-and-memory.md +6 -2
- package/docs/evolution.md +1 -1
- package/docs/exit-codes-and-output.md +1 -1
- package/docs/extensions-and-sharing.md +18 -11
- package/docs/fleet-demo-runbook.md +22 -23
- package/docs/fleet-dispatch.md +111 -12
- package/docs/glossary.md +107 -15
- package/docs/html/agents_blueprint.html +3 -3
- package/docs/html/alcf_blueprint.html +3 -3
- package/docs/html/architecture_blueprint.html +3 -3
- package/docs/html/commands_blueprint.html +187 -42
- package/docs/html/configuration_blueprint.html +7 -7
- package/docs/html/context_blueprint.html +3 -3
- package/docs/html/documentation_blueprint.html +1 -1
- package/docs/html/environment_blueprint.html +3 -3
- package/docs/html/eval_blueprint.html +4 -4
- package/docs/html/evals_internal_blueprint.html +3 -3
- package/docs/html/evolution_blueprint.html +3 -3
- package/docs/html/extensions_blueprint.html +3 -3
- package/docs/html/fleet_dispatch_blueprint.html +8 -8
- package/docs/html/index.html +5 -5
- package/docs/html/lifecycle_blueprint.html +4 -4
- package/docs/html/memory_blueprint.html +3 -3
- package/docs/html/middleware_blueprint.html +3 -3
- package/docs/html/models_blueprint.html +2 -2
- package/docs/html/observability_blueprint.html +2 -2
- package/docs/html/provider_adapter_blueprint.html +3 -3
- package/docs/html/safety_blueprint.html +3 -3
- package/docs/html/skills_blueprint.html +2 -2
- package/docs/html/soak_blueprint.html +3 -3
- package/docs/html/tool_usage_blueprint.html +4 -4
- package/docs/html/tools_blueprint.html +2 -2
- package/docs/html/trace_blueprint.html +3 -3
- package/docs/html/tui_design_blueprint.html +100 -40
- package/docs/html/validation_blueprint.html +1 -1
- package/docs/html/worker_dispatch_blueprint.html +3 -3
- package/docs/installation-and-lifecycle.md +62 -11
- package/docs/middleware-and-components.md +1 -1
- package/docs/model-catalog.md +2 -2
- package/docs/observability.md +3 -3
- package/docs/proactive-memory.md +12 -12
- package/docs/prompt-envelope-and-tools.md +2 -2
- package/docs/provider-adapter-cookbook.md +1 -1
- package/docs/release-cut-checklist.md +4 -0
- package/docs/safety-model.md +21 -5
- package/docs/scientific-validation.md +3 -3
- package/docs/session-lifecycle.md +2 -2
- package/docs/skills-marketplace.md +1 -1
- package/docs/time-conventions.md +101 -0
- package/docs/tool-usage.md +5 -4
- package/docs/trace-store.md +1 -1
- package/docs/troubleshooting.md +1 -1
- package/docs/tui-design.md +83 -27
- package/docs/worker-dispatch-mechanics.md +3 -3
- package/package.json +16 -16
- package/skills/README.md +5 -6
- package/skills/git/file-ticket/SKILL.md +107 -0
- package/skills/git/file-ticket/evals.md +54 -0
- package/skills/git/fix-issue/SKILL.md +106 -0
- package/skills/git/fix-issue/evals.md +71 -0
- package/skills/git/ship/SKILL.md +92 -0
- package/skills/git/ship/evals.md +72 -0
- package/skills/skill-marketplace.json +12 -20
- package/src/cli/acp.ts +88 -0
- package/src/cli/agents.ts +60 -0
- package/src/cli/args.ts +280 -0
- package/src/cli/argv.ts +170 -0
- package/src/cli/ask.ts +34 -0
- package/src/cli/auth.ts +468 -0
- package/src/cli/bootstrap-generate.ts +498 -0
- package/src/cli/clio.ts +34 -0
- package/src/cli/components.ts +195 -0
- package/src/cli/config-inspect.ts +330 -0
- package/src/cli/config.ts +72 -0
- package/src/cli/configure-interop.ts +67 -0
- package/src/cli/configure-layout.ts +172 -0
- package/src/cli/configure.ts +1487 -0
- package/src/cli/context-clear.ts +76 -0
- package/src/cli/context-index.ts +102 -0
- package/src/cli/context.ts +316 -0
- package/src/cli/default-target.ts +63 -0
- package/src/cli/docs.ts +340 -0
- package/src/cli/doctor.ts +54 -0
- package/src/cli/eval.ts +315 -0
- package/src/cli/evidence.ts +222 -0
- package/src/cli/evolve.ts +219 -0
- package/src/cli/extensions.ts +205 -0
- package/src/cli/fleet.ts +827 -0
- package/src/cli/index.ts +309 -0
- package/src/cli/init.ts +219 -0
- package/src/cli/initial-message.ts +47 -0
- package/src/cli/internal-dispatch.ts +55 -0
- package/src/cli/memory.ts +180 -0
- package/src/cli/models.ts +257 -0
- package/src/cli/modes/json-stream.ts +85 -0
- package/src/cli/modes/jsonl.ts +9 -0
- package/src/cli/modes/print.ts +589 -0
- package/src/cli/oauth-manual-input.ts +72 -0
- package/src/cli/oauth-select.ts +36 -0
- package/src/cli/output-guard.ts +48 -0
- package/src/cli/paths.ts +44 -0
- package/src/cli/provider-target.ts +113 -0
- package/src/cli/removal.ts +72 -0
- package/src/cli/reset.ts +253 -0
- package/src/cli/run.ts +497 -0
- package/src/cli/share.ts +243 -0
- package/src/cli/shared.ts +60 -0
- package/src/cli/skills-eval.ts +1225 -0
- package/src/cli/skills.ts +470 -0
- package/src/cli/steer-channel.ts +86 -0
- package/src/cli/targets.ts +1150 -0
- package/src/cli/text-layout.ts +102 -0
- package/src/cli/trace.ts +274 -0
- package/src/cli/uninstall.ts +405 -0
- package/src/cli/upgrade.ts +270 -0
- package/src/cli/usage.ts +869 -0
- package/src/cli/validate-model.ts +28 -0
- package/src/cli/version.ts +7 -0
- package/src/cli/wiki-generate.ts +509 -0
- package/src/core/artifact-paths.ts +43 -0
- package/src/core/bash-exec.ts +242 -0
- package/src/core/boot-trace.ts +37 -0
- package/src/core/bus-events.ts +728 -0
- package/src/core/bus-trace.ts +53 -0
- package/src/core/c-header-language.ts +265 -0
- package/src/core/clio-repo.ts +78 -0
- package/src/core/config.ts +1593 -0
- package/src/core/context-floor.ts +33 -0
- package/src/core/defaults.ts +625 -0
- package/src/core/domain-loader.ts +170 -0
- package/src/core/event-bus.ts +94 -0
- package/src/core/file-references.ts +282 -0
- package/src/core/guardrails.ts +185 -0
- package/src/core/headless-permission.ts +21 -0
- package/src/core/init.ts +223 -0
- package/src/core/json-payload.ts +58 -0
- package/src/core/package-root.ts +54 -0
- package/src/core/path-canonical.ts +37 -0
- package/src/core/process-identity.ts +41 -0
- package/src/core/recent-models.ts +91 -0
- package/src/core/release.ts +2 -0
- package/src/core/residency-protection.ts +56 -0
- package/src/core/resolve-config-value.ts +88 -0
- package/src/core/response-schema.ts +279 -0
- package/src/core/run-overrides.ts +77 -0
- package/src/core/safe-exec.ts +193 -0
- package/src/core/safe-id.ts +37 -0
- package/src/core/safe-resource-write.ts +162 -0
- package/src/core/session-routing.ts +339 -0
- package/src/core/settings-layers.ts +220 -0
- package/src/core/shared-bus.ts +8 -0
- package/src/core/shell-quote.ts +26 -0
- package/src/core/skill-activation.ts +190 -0
- package/src/core/startup-timer.ts +37 -0
- package/src/core/state-file-lock.ts +207 -0
- package/src/core/termination.ts +202 -0
- package/src/core/timers.ts +38 -0
- package/src/core/tool-names.ts +65 -0
- package/src/core/verification-scripts.ts +13 -0
- package/src/core/workspace-files.ts +492 -0
- package/src/core/xdg.ts +177 -0
- package/src/domains/agents/builtins/architect.md +4 -4
- package/src/domains/agents/builtins/coder.md +3 -2
- package/src/domains/agents/builtins/debugger.md +1 -1
- package/src/domains/agents/builtins/documenter.md +1 -1
- package/src/domains/agents/builtins/git-master.md +3 -3
- package/src/domains/agents/builtins/provenance.md +1 -1
- package/src/domains/agents/builtins/researcher.md +1 -1
- package/src/domains/agents/builtins/scout.md +1 -1
- package/src/domains/agents/builtins/tester.md +1 -1
- package/src/domains/agents/builtins/verifier.md +1 -1
- package/src/domains/agents/builtins/wiki-writer.md +1 -1
- package/src/domains/agents/catalog.ts +172 -0
- package/src/domains/agents/contract.ts +16 -0
- package/src/domains/agents/extension.ts +110 -0
- package/src/domains/agents/fleet-commands.ts +154 -0
- package/src/domains/agents/fleet-contract.ts +797 -0
- package/src/domains/agents/frontmatter.ts +40 -0
- package/src/domains/agents/index.ts +102 -0
- package/src/domains/agents/manifest.ts +6 -0
- package/src/domains/agents/recipe-schema.ts +202 -0
- package/src/domains/agents/recipe.ts +125 -0
- package/src/domains/agents/registry.ts +111 -0
- package/src/domains/agents/result-contract.ts +1265 -0
- package/src/domains/agents/spec.ts +371 -0
- package/src/domains/agents/write-boundary.ts +109 -0
- package/src/domains/components/diff.ts +99 -0
- package/src/domains/components/hash.ts +21 -0
- package/src/domains/components/index.ts +3 -0
- package/src/domains/components/scan.ts +304 -0
- package/src/domains/components/snapshot.ts +108 -0
- package/src/domains/components/types.ts +82 -0
- package/src/domains/config/agent-namespace.ts +13 -0
- package/src/domains/config/classify.ts +94 -0
- package/src/domains/config/contract.ts +22 -0
- package/src/domains/config/extension.ts +136 -0
- package/src/domains/config/index.ts +13 -0
- package/src/domains/config/keybindings.ts +164 -0
- package/src/domains/config/manifest.ts +6 -0
- package/src/domains/config/watcher.ts +41 -0
- package/src/domains/context/adoption.ts +880 -0
- package/src/domains/context/bootstrap-prompt.ts +273 -0
- package/src/domains/context/bootstrap.ts +1409 -0
- package/src/domains/context/clear.ts +86 -0
- package/src/domains/context/clio-md.ts +327 -0
- package/src/domains/context/codewiki/cmake.ts +356 -0
- package/src/domains/context/codewiki/cooperative.ts +46 -0
- package/src/domains/context/codewiki/digest.ts +135 -0
- package/src/domains/context/codewiki/grammar-assets.ts +33 -0
- package/src/domains/context/codewiki/indexer.ts +1614 -0
- package/src/domains/context/codewiki/tree-sitter.ts +771 -0
- package/src/domains/context/contract.ts +62 -0
- package/src/domains/context/excluded-dirs.ts +1 -0
- package/src/domains/context/extension.ts +407 -0
- package/src/domains/context/fingerprint.ts +196 -0
- package/src/domains/context/index.ts +164 -0
- package/src/domains/context/init-options.ts +69 -0
- package/src/domains/context/manifest.ts +6 -0
- package/src/domains/context/operator-profile.ts +157 -0
- package/src/domains/context/project-metadata.ts +510 -0
- package/src/domains/context/project-rules.ts +227 -0
- package/src/domains/context/prompt-context.ts +62 -0
- package/src/domains/context/refresh.ts +170 -0
- package/src/domains/context/sibling-files.ts +10 -0
- package/src/domains/context/state.ts +237 -0
- package/src/domains/context/wiki/assemble.ts +303 -0
- package/src/domains/context/wiki/frontmatter.ts +210 -0
- package/src/domains/context/wiki/generate.ts +590 -0
- package/src/domains/context/wiki/layout.ts +111 -0
- package/src/domains/context/wiki/meta.ts +221 -0
- package/src/domains/context/wiki/plan-store.ts +217 -0
- package/src/domains/context/wiki/plan.ts +250 -0
- package/src/domains/context/wiki/prompts.ts +270 -0
- package/src/domains/context/wiki/staleness.ts +198 -0
- package/src/domains/dispatch/active-route-planner.ts +168 -0
- package/src/domains/dispatch/admission-queue.ts +150 -0
- package/src/domains/dispatch/admission.ts +334 -0
- package/src/domains/dispatch/agent-candidates.ts +307 -0
- package/src/domains/dispatch/agent-ledger-hub.ts +71 -0
- package/src/domains/dispatch/agent-ledger-store.ts +257 -0
- package/src/domains/dispatch/agent-ledger.ts +212 -0
- package/src/domains/dispatch/agent-plan-adapter.ts +85 -0
- package/src/domains/dispatch/assignment-events.ts +132 -0
- package/src/domains/dispatch/assignment-reconcile.ts +76 -0
- package/src/domains/dispatch/assignment-store.ts +162 -0
- package/src/domains/dispatch/assignment.ts +278 -0
- package/src/domains/dispatch/backoff.ts +59 -0
- package/src/domains/dispatch/batch-store.ts +134 -0
- package/src/domains/dispatch/batch-tracker.ts +66 -0
- package/src/domains/dispatch/capability-match.ts +155 -0
- package/src/domains/dispatch/capacity-lease.ts +413 -0
- package/src/domains/dispatch/code-step-store.ts +52 -0
- package/src/domains/dispatch/code-step.ts +368 -0
- package/src/domains/dispatch/contract.ts +278 -0
- package/src/domains/dispatch/dedup.ts +133 -0
- package/src/domains/dispatch/event-pump.ts +251 -0
- package/src/domains/dispatch/execution-handoff.ts +29 -0
- package/src/domains/dispatch/execution-plan.ts +328 -0
- package/src/domains/dispatch/execution-role.ts +277 -0
- package/src/domains/dispatch/execution-scheduler.ts +583 -0
- package/src/domains/dispatch/extension.ts +5869 -0
- package/src/domains/dispatch/failure-classification.ts +141 -0
- package/src/domains/dispatch/fleet-plan.ts +225 -0
- package/src/domains/dispatch/fleet-preflight.ts +394 -0
- package/src/domains/dispatch/gate-decisions.ts +1040 -0
- package/src/domains/dispatch/gate-role-prompts.ts +58 -0
- package/src/domains/dispatch/heartbeat.ts +27 -0
- package/src/domains/dispatch/index.ts +137 -0
- package/src/domains/dispatch/joint-route-adapter.ts +114 -0
- package/src/domains/dispatch/joint-route-resolver.ts +283 -0
- package/src/domains/dispatch/manifest.ts +6 -0
- package/src/domains/dispatch/orphan-recovery.ts +224 -0
- package/src/domains/dispatch/outcome.ts +109 -0
- package/src/domains/dispatch/phase-timing.ts +47 -0
- package/src/domains/dispatch/placement.ts +202 -0
- package/src/domains/dispatch/receipt-findings.ts +255 -0
- package/src/domains/dispatch/receipt-integrity.ts +378 -0
- package/src/domains/dispatch/recovery-candidates.ts +74 -0
- package/src/domains/dispatch/reproducibility.ts +48 -0
- package/src/domains/dispatch/reservation-store.ts +501 -0
- package/src/domains/dispatch/route-approval.ts +177 -0
- package/src/domains/dispatch/route-candidates.ts +57 -0
- package/src/domains/dispatch/route-decision.ts +1079 -0
- package/src/domains/dispatch/route-facts.ts +187 -0
- package/src/domains/dispatch/route-history.ts +238 -0
- package/src/domains/dispatch/route-observer.ts +488 -0
- package/src/domains/dispatch/route-policy.ts +327 -0
- package/src/domains/dispatch/route-quality.ts +256 -0
- package/src/domains/dispatch/route-readiness.ts +120 -0
- package/src/domains/dispatch/routing-intent.ts +287 -0
- package/src/domains/dispatch/run-identity.ts +56 -0
- package/src/domains/dispatch/scout-transition.ts +130 -0
- package/src/domains/dispatch/state.ts +277 -0
- package/src/domains/dispatch/tool-stats.ts +132 -0
- package/src/domains/dispatch/transport.ts +209 -0
- package/src/domains/dispatch/types.ts +785 -0
- package/src/domains/dispatch/validation-grounding.ts +154 -0
- package/src/domains/dispatch/validation.ts +721 -0
- package/src/domains/dispatch/worker-protocol.ts +275 -0
- package/src/domains/dispatch/worker-spawn.ts +566 -0
- package/src/domains/dispatch/write-boundary-enforcer.ts +97 -0
- package/src/domains/dispatch/write-boundary.ts +426 -0
- package/src/domains/eval/artifacts/redact.ts +42 -0
- package/src/domains/eval/artifacts/store.ts +173 -0
- package/src/domains/eval/compare/compare.ts +33 -0
- package/src/domains/eval/compare/gates.ts +66 -0
- package/src/domains/eval/compare/thresholds.ts +92 -0
- package/src/domains/eval/harness-metrics.ts +62 -0
- package/src/domains/eval/index.ts +66 -0
- package/src/domains/eval/metrics/chaos-stream.ts +93 -0
- package/src/domains/eval/metrics/context.ts +34 -0
- package/src/domains/eval/metrics/coverage.ts +21 -0
- package/src/domains/eval/metrics/evidence.ts +182 -0
- package/src/domains/eval/metrics/fleet-loop-stream.ts +196 -0
- package/src/domains/eval/metrics/invariants.ts +736 -0
- package/src/domains/eval/metrics/latency.ts +4 -0
- package/src/domains/eval/metrics/token-stream.ts +139 -0
- package/src/domains/eval/metrics/tokens.ts +51 -0
- package/src/domains/eval/metrics/tool-calls.ts +7 -0
- package/src/domains/eval/proactive-memory.ts +279 -0
- package/src/domains/eval/provenance.ts +35 -0
- package/src/domains/eval/report.ts +234 -0
- package/src/domains/eval/reports/json.ts +5 -0
- package/src/domains/eval/reports/junit.ts +23 -0
- package/src/domains/eval/reports/markdown.ts +20 -0
- package/src/domains/eval/reports/swe-jsonl.ts +16 -0
- package/src/domains/eval/reports/text.ts +25 -0
- package/src/domains/eval/run-compare.ts +274 -0
- package/src/domains/eval/runner.ts +244 -0
- package/src/domains/eval/runners/clio-run.ts +148 -0
- package/src/domains/eval/runners/context-index.ts +56 -0
- package/src/domains/eval/runners/context-init.ts +203 -0
- package/src/domains/eval/runners/external-command.ts +350 -0
- package/src/domains/eval/runtime-paths.ts +171 -0
- package/src/domains/eval/schema/artifact.ts +75 -0
- package/src/domains/eval/schema/suite.ts +235 -0
- package/src/domains/eval/schema/validate.ts +339 -0
- package/src/domains/eval/store.ts +392 -0
- package/src/domains/eval/suites/load.ts +74 -0
- package/src/domains/eval/suites/matrix.ts +19 -0
- package/src/domains/eval/suites/resolve.ts +44 -0
- package/src/domains/eval/suites/run.ts +325 -0
- package/src/domains/eval/task-file.ts +186 -0
- package/src/domains/eval/types.ts +141 -0
- package/src/domains/eval/verifiers/command.ts +27 -0
- package/src/domains/eval/verifiers/file-exists.ts +6 -0
- package/src/domains/eval/verifiers/patch.ts +22 -0
- package/src/domains/eval/workspaces/git.ts +41 -0
- package/src/domains/eval/workspaces/local.ts +17 -0
- package/src/domains/eval/workspaces/temp-copy.ts +29 -0
- package/src/domains/evidence/build.ts +1714 -0
- package/src/domains/evidence/eval.ts +605 -0
- package/src/domains/evidence/failure-attribution.ts +54 -0
- package/src/domains/evidence/finish-contract-map.ts +42 -0
- package/src/domains/evidence/index.ts +55 -0
- package/src/domains/evidence/provenance.ts +200 -0
- package/src/domains/evidence/redact.ts +81 -0
- package/src/domains/evidence/store.ts +291 -0
- package/src/domains/evidence/types.ts +325 -0
- package/src/domains/evolution/SELF_EDIT_GATE.md +91 -0
- package/src/domains/evolution/index.ts +26 -0
- package/src/domains/evolution/manifest.ts +154 -0
- package/src/domains/evolution/validate.ts +304 -0
- package/src/domains/extensions/contract.ts +22 -0
- package/src/domains/extensions/discovery.ts +193 -0
- package/src/domains/extensions/extension.ts +46 -0
- package/src/domains/extensions/index.ts +34 -0
- package/src/domains/extensions/manager.ts +30 -0
- package/src/domains/extensions/manifest.ts +6 -0
- package/src/domains/extensions/resources.ts +38 -0
- package/src/domains/extensions/state.ts +224 -0
- package/src/domains/extensions/types.ts +83 -0
- package/src/domains/interop/consent.ts +185 -0
- package/src/domains/interop/contract.ts +29 -0
- package/src/domains/interop/detect.ts +173 -0
- package/src/domains/interop/extension.ts +59 -0
- package/src/domains/interop/index.ts +34 -0
- package/src/domains/interop/manifest.ts +6 -0
- package/src/domains/interop/registry.ts +139 -0
- package/src/domains/interop/state.ts +92 -0
- package/src/domains/interop/types.ts +109 -0
- package/src/domains/lifecycle/contract.ts +11 -0
- package/src/domains/lifecycle/doctor.ts +536 -0
- package/src/domains/lifecycle/extension.ts +23 -0
- package/src/domains/lifecycle/index.ts +21 -0
- package/src/domains/lifecycle/install-method.ts +51 -0
- package/src/domains/lifecycle/manifest.ts +6 -0
- package/src/domains/lifecycle/migrations/index.ts +94 -0
- package/src/domains/lifecycle/state.ts +93 -0
- package/src/domains/lifecycle/upgrade-notice.ts +35 -0
- package/src/domains/lifecycle/version.ts +35 -0
- package/src/domains/memory/index.ts +128 -0
- package/src/domains/memory/operations.ts +143 -0
- package/src/domains/memory/prompt-section.ts +86 -0
- package/src/domains/memory/proposal.ts +180 -0
- package/src/domains/memory/store.ts +163 -0
- package/src/domains/memory/task-bank.ts +229 -0
- package/src/domains/memory/task-memory-handoff.ts +222 -0
- package/src/domains/memory/task-memory-policy.ts +602 -0
- package/src/domains/memory/task-memory-status.ts +58 -0
- package/src/domains/memory/task-memory-telemetry.ts +346 -0
- package/src/domains/memory/task-memory-trace.ts +89 -0
- package/src/domains/memory/types.ts +74 -0
- package/src/domains/memory/validate.ts +297 -0
- package/src/domains/middleware/budget.ts +216 -0
- package/src/domains/middleware/contract.ts +35 -0
- package/src/domains/middleware/dispatch-nudge.ts +469 -0
- package/src/domains/middleware/extension.ts +129 -0
- package/src/domains/middleware/hook-receipts.ts +70 -0
- package/src/domains/middleware/hooks-io.ts +174 -0
- package/src/domains/middleware/hooks.ts +432 -0
- package/src/domains/middleware/index.ts +154 -0
- package/src/domains/middleware/manifest.ts +6 -0
- package/src/domains/middleware/memory-intervention.ts +701 -0
- package/src/domains/middleware/rules.ts +42 -0
- package/src/domains/middleware/runtime.ts +333 -0
- package/src/domains/middleware/skills-reminder.ts +187 -0
- package/src/domains/middleware/snapshot.ts +71 -0
- package/src/domains/middleware/stalled-turn.ts +71 -0
- package/src/domains/middleware/task-board-reminder.ts +87 -0
- package/src/domains/middleware/task-nudge.ts +77 -0
- package/src/domains/middleware/tool-choice-control.ts +42 -0
- package/src/domains/middleware/types.ts +131 -0
- package/src/domains/middleware/validate.ts +329 -0
- package/src/domains/observability/accountability.ts +67 -0
- package/src/domains/observability/contract.ts +168 -0
- package/src/domains/observability/cost.ts +206 -0
- package/src/domains/observability/evidence-index.ts +123 -0
- package/src/domains/observability/extension.ts +281 -0
- package/src/domains/observability/index.ts +78 -0
- package/src/domains/observability/manifest.ts +10 -0
- package/src/domains/observability/metrics.ts +37 -0
- package/src/domains/observability/projection.ts +477 -0
- package/src/domains/observability/telemetry.ts +89 -0
- package/src/domains/observability/trace-store.ts +1454 -0
- package/src/domains/prompts/compiler.ts +556 -0
- package/src/domains/prompts/contract.ts +30 -0
- package/src/domains/prompts/extension.ts +304 -0
- package/src/domains/prompts/fragment-loader.ts +139 -0
- package/src/domains/prompts/fragments/identity/clio.md +3 -2
- package/src/domains/prompts/fragments/identity/self-awareness.md +63 -0
- package/src/domains/prompts/fragments/operating/contract.md +10 -1
- package/src/domains/prompts/hash.ts +73 -0
- package/src/domains/prompts/index.ts +32 -0
- package/src/domains/prompts/manifest.ts +8 -0
- package/src/domains/prompts/memory-intervention.ts +57 -0
- package/src/domains/prompts/preload.ts +82 -0
- package/src/domains/providers/auth/api-key.ts +47 -0
- package/src/domains/providers/auth/backend-file.ts +69 -0
- package/src/domains/providers/auth/backend-memory.ts +17 -0
- package/src/domains/providers/auth/index.ts +37 -0
- package/src/domains/providers/auth/oauth.ts +36 -0
- package/src/domains/providers/auth/storage.ts +667 -0
- package/src/domains/providers/capabilities.ts +50 -0
- package/src/domains/providers/catalog.ts +162 -0
- package/src/domains/providers/contract.ts +151 -0
- package/src/domains/providers/credentials.ts +20 -0
- package/src/domains/providers/eligibility.ts +24 -0
- package/src/domains/providers/errors.ts +64 -0
- package/src/domains/providers/extension.ts +536 -0
- package/src/domains/providers/index.ts +142 -0
- package/src/domains/providers/knowledge-base-path.ts +102 -0
- package/src/domains/providers/manifest.ts +6 -0
- package/src/domains/providers/model-capabilities.ts +136 -0
- package/src/domains/providers/model-discovery.ts +144 -0
- package/src/domains/providers/model-family.ts +32 -0
- package/src/domains/providers/model-runtime-capabilities.ts +712 -0
- package/src/domains/providers/models/local-models/clio-local-coding-targets.yaml +2 -2
- package/src/domains/providers/plugins.ts +59 -0
- package/src/domains/providers/probe/fingerprint.ts +44 -0
- package/src/domains/providers/probe/http.ts +114 -0
- package/src/domains/providers/probe/reasoning.ts +111 -0
- package/src/domains/providers/registry.ts +166 -0
- package/src/domains/providers/resolver.ts +156 -0
- package/src/domains/providers/runtime-resolution.ts +720 -0
- package/src/domains/providers/runtimes/antigravity/antigravity-code.ts +90 -0
- package/src/domains/providers/runtimes/builtins.ts +78 -0
- package/src/domains/providers/runtimes/claude/claude-code.ts +38 -0
- package/src/domains/providers/runtimes/claude/claude-sdk.ts +38 -0
- package/src/domains/providers/runtimes/claude/common.ts +55 -0
- package/src/domains/providers/runtimes/cloud/alcf.ts +171 -0
- package/src/domains/providers/runtimes/cloud/anthropic-max.ts +71 -0
- package/src/domains/providers/runtimes/cloud/anthropic.ts +43 -0
- package/src/domains/providers/runtimes/cloud/bedrock.ts +35 -0
- package/src/domains/providers/runtimes/cloud/deepseek.ts +50 -0
- package/src/domains/providers/runtimes/cloud/google.ts +41 -0
- package/src/domains/providers/runtimes/cloud/groq.ts +46 -0
- package/src/domains/providers/runtimes/cloud/mistral.ts +46 -0
- package/src/domains/providers/runtimes/cloud/openai-codex.ts +49 -0
- package/src/domains/providers/runtimes/cloud/openai.ts +46 -0
- package/src/domains/providers/runtimes/cloud/openrouter.ts +111 -0
- package/src/domains/providers/runtimes/common/lmstudio-logger.ts +32 -0
- package/src/domains/providers/runtimes/common/local-synth.ts +165 -0
- package/src/domains/providers/runtimes/common/probe-helpers.ts +474 -0
- package/src/domains/providers/runtimes/local-native/lemonade-anthropic.ts +27 -0
- package/src/domains/providers/runtimes/local-native/lemonade-openai.ts +26 -0
- package/src/domains/providers/runtimes/local-native/llamacpp-anthropic.ts +88 -0
- package/src/domains/providers/runtimes/local-native/llamacpp-completion.ts +207 -0
- package/src/domains/providers/runtimes/local-native/llamacpp-embed.ts +180 -0
- package/src/domains/providers/runtimes/local-native/llamacpp-rerank.ts +126 -0
- package/src/domains/providers/runtimes/local-native/llamacpp.ts +98 -0
- package/src/domains/providers/runtimes/local-native/lmstudio-native.ts +491 -0
- package/src/domains/providers/runtimes/local-native/ollama-native.ts +117 -0
- package/src/domains/providers/runtimes/local-native/sglang.ts +26 -0
- package/src/domains/providers/runtimes/local-native/vllm.ts +27 -0
- package/src/domains/providers/runtimes/protocol/anthropic-compat.ts +104 -0
- package/src/domains/providers/runtimes/protocol/anthropic-messages.ts +28 -0
- package/src/domains/providers/runtimes/protocol/bedrock.ts +26 -0
- package/src/domains/providers/runtimes/protocol/google.ts +27 -0
- package/src/domains/providers/runtimes/protocol/openai-compat.ts +145 -0
- package/src/domains/providers/support.ts +238 -0
- package/src/domains/providers/thinking-control-policy.ts +85 -0
- package/src/domains/providers/types/capability-flags.ts +114 -0
- package/src/domains/providers/types/cost-provenance.ts +7 -0
- package/src/domains/providers/types/inference.ts +41 -0
- package/src/domains/providers/types/knowledge-base.ts +156 -0
- package/src/domains/providers/types/local-model-quirks.ts +218 -0
- package/src/domains/providers/types/runtime-descriptor.ts +170 -0
- package/src/domains/providers/types/target-descriptor.ts +38 -0
- package/src/domains/resources/collision.ts +92 -0
- package/src/domains/resources/common-loader.ts +140 -0
- package/src/domains/resources/contract.ts +25 -0
- package/src/domains/resources/extension.ts +61 -0
- package/src/domains/resources/index.ts +74 -0
- package/src/domains/resources/loader.ts +86 -0
- package/src/domains/resources/manifest.ts +6 -0
- package/src/domains/resources/prompts/loader.ts +232 -0
- package/src/domains/resources/prompts/substitute.ts +65 -0
- package/src/domains/resources/skills/content-hash.ts +105 -0
- package/src/domains/resources/skills/evals.ts +175 -0
- package/src/domains/resources/skills/install.ts +410 -0
- package/src/domains/resources/skills/loader.ts +978 -0
- package/src/domains/resources/skills/marketplace.ts +255 -0
- package/src/domains/resources/skills/provenance-pin.ts +115 -0
- package/src/domains/safety/action-classifier.ts +268 -0
- package/src/domains/safety/approval-axis.ts +23 -0
- package/src/domains/safety/audit.ts +487 -0
- package/src/domains/safety/autonomy.ts +174 -0
- package/src/domains/safety/call-target.ts +59 -0
- package/src/domains/safety/contract.ts +65 -0
- package/src/domains/safety/damage-control.ts +44 -0
- package/src/domains/safety/default-path-policy.ts +117 -0
- package/src/domains/safety/extension.ts +383 -0
- package/src/domains/safety/finish-contract-registration.ts +128 -0
- package/src/domains/safety/finish-contract.ts +554 -0
- package/src/domains/safety/index.ts +44 -0
- package/src/domains/safety/loop-detector.ts +143 -0
- package/src/domains/safety/manifest.ts +6 -0
- package/src/domains/safety/path-policy.ts +164 -0
- package/src/domains/safety/policy-engine.ts +994 -0
- package/src/domains/safety/project-policy.ts +391 -0
- package/src/domains/safety/protected-artifacts-registration.ts +189 -0
- package/src/domains/safety/protected-artifacts.ts +993 -0
- package/src/domains/safety/rejection-feedback.ts +102 -0
- package/src/domains/safety/rigor.ts +72 -0
- package/src/domains/safety/rule-compiler.ts +48 -0
- package/src/domains/safety/rule-pack-loader.ts +92 -0
- package/src/domains/safety/run-effects.ts +197 -0
- package/src/domains/safety/scope.ts +61 -0
- package/src/domains/scheduling/budget.ts +35 -0
- package/src/domains/scheduling/cluster.ts +175 -0
- package/src/domains/scheduling/contract.ts +30 -0
- package/src/domains/scheduling/extension.ts +91 -0
- package/src/domains/scheduling/index.ts +12 -0
- package/src/domains/scheduling/manifest.ts +6 -0
- package/src/domains/session/archive-readers.ts +208 -0
- package/src/domains/session/checkpoint.ts +38 -0
- package/src/domains/session/compaction/auto.ts +89 -0
- package/src/domains/session/compaction/branch-summary.ts +186 -0
- package/src/domains/session/compaction/compact.ts +493 -0
- package/src/domains/session/compaction/cut-point.ts +171 -0
- package/src/domains/session/compaction/defaults.ts +34 -0
- package/src/domains/session/compaction/mask-observations.ts +265 -0
- package/src/domains/session/compaction/session-entries.ts +18 -0
- package/src/domains/session/compaction/tokens.ts +147 -0
- package/src/domains/session/context-accounting.ts +583 -0
- package/src/domains/session/context-ledger.ts +348 -0
- package/src/domains/session/contract.ts +144 -0
- package/src/domains/session/cwd-fallback.ts +65 -0
- package/src/domains/session/entries.ts +509 -0
- package/src/domains/session/extension.ts +322 -0
- package/src/domains/session/history.ts +172 -0
- package/src/domains/session/index.ts +84 -0
- package/src/domains/session/manager.ts +128 -0
- package/src/domains/session/manifest.ts +6 -0
- package/src/domains/session/migrations/index.ts +27 -0
- package/src/domains/session/prompt-manifest.ts +173 -0
- package/src/domains/session/protected-artifact-journal.ts +241 -0
- package/src/domains/session/protected-artifacts.ts +90 -0
- package/src/domains/session/retry.ts +238 -0
- package/src/domains/session/task-board.ts +375 -0
- package/src/domains/session/tree/active-path.ts +98 -0
- package/src/domains/session/tree/fork.ts +160 -0
- package/src/domains/session/tree/manager.ts +128 -0
- package/src/domains/session/tree/navigator.ts +177 -0
- package/src/domains/session/tree/preview.ts +259 -0
- package/src/domains/session/usage.ts +148 -0
- package/src/domains/session/workspace/git-probe.ts +161 -0
- package/src/domains/session/workspace/index.ts +4 -0
- package/src/domains/session/workspace/project-type.ts +217 -0
- package/src/domains/session/workspace/snapshot.ts +74 -0
- package/src/domains/share/archive.ts +684 -0
- package/src/domains/share/contract.ts +9 -0
- package/src/domains/share/extension.ts +26 -0
- package/src/domains/share/index.ts +28 -0
- package/src/domains/share/manifest.ts +6 -0
- package/src/engine/acp/adapter.ts +397 -0
- package/src/engine/acp/errors.ts +32 -0
- package/src/engine/acp/event-mapper.ts +154 -0
- package/src/engine/acp/server.ts +656 -0
- package/src/engine/acp/tool-mediator.ts +686 -0
- package/src/engine/acp/transport.ts +654 -0
- package/src/engine/acp/types.ts +170 -0
- package/src/engine/agent.ts +29 -0
- package/src/engine/ai.ts +202 -0
- package/src/engine/alcf-oauth.ts +198 -0
- package/src/engine/antigravity/subprocess-runtime.ts +205 -0
- package/src/engine/apis/degraded-inference.ts +95 -0
- package/src/engine/apis/index.ts +20 -0
- package/src/engine/apis/llamacpp-residency.ts +252 -0
- package/src/engine/apis/lmstudio-native.ts +1438 -0
- package/src/engine/apis/lmstudio-residency.ts +92 -0
- package/src/engine/apis/ollama-native.ts +507 -0
- package/src/engine/apis/openai-completions.ts +716 -0
- package/src/engine/apis/output-budget.ts +99 -0
- package/src/engine/apis/residency-lock.ts +29 -0
- package/src/engine/apis/residency.ts +640 -0
- package/src/engine/apis/resident-models.ts +42 -0
- package/src/engine/apis/sampling-overrides.ts +38 -0
- package/src/engine/apis/thinking-replay.ts +11 -0
- package/src/engine/claude/sdk-runtime.ts +685 -0
- package/src/engine/claude/session-id.ts +5 -0
- package/src/engine/claude/subprocess-runtime.ts +316 -0
- package/src/engine/claude/tool-safety.ts +400 -0
- package/src/engine/external-subprocess.ts +23 -0
- package/src/engine/harmony-response.ts +165 -0
- package/src/engine/loop-guard.ts +1127 -0
- package/src/engine/oauth.ts +192 -0
- package/src/engine/pi-mono-names.ts +13 -0
- package/src/engine/provider-payload.ts +315 -0
- package/src/engine/select-list.ts +53 -0
- package/src/engine/session.ts +834 -0
- package/src/engine/strip-tokenizer-sentinels.ts +125 -0
- package/src/engine/tui.ts +103 -0
- package/src/engine/types.ts +66 -0
- package/src/engine/worker-events.ts +100 -0
- package/src/engine/worker-runtime.ts +1022 -0
- package/src/engine/worker-tools.ts +203 -0
- package/src/entry/orchestrator.ts +1873 -0
- package/src/interactive/application-controller.ts +346 -0
- package/src/interactive/bus-notices.ts +265 -0
- package/src/interactive/chat-loop-messages.ts +626 -0
- package/src/interactive/chat-loop-policy.ts +18 -0
- package/src/interactive/chat-loop.ts +865 -0
- package/src/interactive/chat-panel.ts +1694 -0
- package/src/interactive/chat-renderer.ts +1038 -0
- package/src/interactive/clio-editor.ts +166 -0
- package/src/interactive/command-fallbacks.ts +23 -0
- package/src/interactive/command-output.ts +85 -0
- package/src/interactive/context-activity.ts +203 -0
- package/src/interactive/context-meter.ts +223 -0
- package/src/interactive/context-overlay.ts +220 -0
- package/src/interactive/cost-overlay.ts +279 -0
- package/src/interactive/dispatch-board.ts +1319 -0
- package/src/interactive/dispatch-steering.ts +86 -0
- package/src/interactive/editor-bash.ts +46 -0
- package/src/interactive/editor-steer.ts +51 -0
- package/src/interactive/editor-submit.ts +303 -0
- package/src/interactive/external-editor.ts +67 -0
- package/src/interactive/follow-up-queue-panel.ts +75 -0
- package/src/interactive/footer/dashboard.ts +534 -0
- package/src/interactive/footer/notifications.ts +275 -0
- package/src/interactive/footer/widgets.ts +1246 -0
- package/src/interactive/footer-panel.ts +187 -0
- package/src/interactive/format-time.ts +85 -0
- package/src/interactive/index.ts +11 -0
- package/src/interactive/interactive-application.ts +755 -0
- package/src/interactive/interactive-event-projection.ts +380 -0
- package/src/interactive/interactive-input-runtime.ts +261 -0
- package/src/interactive/interactive-presentation.ts +452 -0
- package/src/interactive/interactive-shell.ts +134 -0
- package/src/interactive/interactive-slash-runtime.ts +492 -0
- package/src/interactive/interactive-subscriptions.ts +111 -0
- package/src/interactive/interactive-tickers.ts +152 -0
- package/src/interactive/keybinding-manager.ts +496 -0
- package/src/interactive/layout.ts +20 -0
- package/src/interactive/leader-key.ts +143 -0
- package/src/interactive/loop-guard-interrupt.ts +101 -0
- package/src/interactive/memory-overlay.ts +280 -0
- package/src/interactive/overlay-ask-user-lifecycle.ts +110 -0
- package/src/interactive/overlay-auth-lifecycle.ts +308 -0
- package/src/interactive/overlay-frame.ts +502 -0
- package/src/interactive/overlay-general-openers.ts +217 -0
- package/src/interactive/overlay-key-routing.ts +213 -0
- package/src/interactive/overlay-lifecycle.ts +413 -0
- package/src/interactive/overlay-model-selectors.ts +127 -0
- package/src/interactive/overlay-permission-lifecycle.ts +344 -0
- package/src/interactive/overlay-resource-openers.ts +112 -0
- package/src/interactive/overlay-session-lifecycle.ts +270 -0
- package/src/interactive/overlay-transitions.ts +57 -0
- package/src/interactive/overlays/agents.ts +69 -0
- package/src/interactive/overlays/ask-user.ts +921 -0
- package/src/interactive/overlays/auth-dialog.ts +221 -0
- package/src/interactive/overlays/context-reset.ts +108 -0
- package/src/interactive/overlays/cwd-fallback.ts +141 -0
- package/src/interactive/overlays/extensions.ts +54 -0
- package/src/interactive/overlays/help-reference.ts +140 -0
- package/src/interactive/overlays/interop.ts +139 -0
- package/src/interactive/overlays/keybinding-detail.ts +90 -0
- package/src/interactive/overlays/list-overlay.ts +606 -0
- package/src/interactive/overlays/message-picker.ts +155 -0
- package/src/interactive/overlays/model-selector.ts +1091 -0
- package/src/interactive/overlays/prompts.ts +72 -0
- package/src/interactive/overlays/session-selector-search.ts +31 -0
- package/src/interactive/overlays/session-selector.ts +266 -0
- package/src/interactive/overlays/settings.ts +3363 -0
- package/src/interactive/overlays/skills-hub.ts +237 -0
- package/src/interactive/overlays/tree-selector.ts +387 -0
- package/src/interactive/permission-overlay.ts +170 -0
- package/src/interactive/render-trace.ts +125 -0
- package/src/interactive/renderers/branch-summary.ts +86 -0
- package/src/interactive/renderers/code-ink.ts +420 -0
- package/src/interactive/renderers/compaction-summary.ts +112 -0
- package/src/interactive/renderers/diff.ts +126 -0
- package/src/interactive/renderers/notice.ts +28 -0
- package/src/interactive/renderers/retry-status.ts +31 -0
- package/src/interactive/renderers/structured.ts +89 -0
- package/src/interactive/renderers/tool-execution.ts +1104 -0
- package/src/interactive/renderers/worker-entry.ts +264 -0
- package/src/interactive/session-last-turn.ts +186 -0
- package/src/interactive/session-transcript.ts +105 -0
- package/src/interactive/session-usage-reseed.ts +74 -0
- package/src/interactive/slash-autocomplete.ts +364 -0
- package/src/interactive/slash-commands.ts +1319 -0
- package/src/interactive/slash-spec.ts +453 -0
- package/src/interactive/status/controller.ts +256 -0
- package/src/interactive/status/index.ts +23 -0
- package/src/interactive/status/state-machine.ts +530 -0
- package/src/interactive/status/summary.ts +170 -0
- package/src/interactive/status/types.ts +121 -0
- package/src/interactive/status/verbs.ts +163 -0
- package/src/interactive/status/watchdog.ts +24 -0
- package/src/interactive/tasks-overlay.ts +186 -0
- package/src/interactive/theme/components.ts +55 -0
- package/src/interactive/theme/glyphs.ts +70 -0
- package/src/interactive/theme/index.ts +15 -0
- package/src/interactive/theme/labels.ts +88 -0
- package/src/interactive/theme/rules.ts +138 -0
- package/src/interactive/theme/segments.ts +88 -0
- package/src/interactive/theme/tokens.ts +121 -0
- package/src/interactive/thinking-level-policy.ts +6 -0
- package/src/interactive/tool-prose-loop.ts +122 -0
- package/src/interactive/tool-prose-registration.ts +48 -0
- package/src/interactive/turn-context.ts +854 -0
- package/src/interactive/turn-middleware.ts +283 -0
- package/src/interactive/turn-persistence.ts +441 -0
- package/src/interactive/turn-queues.ts +169 -0
- package/src/interactive/turn-recovery.ts +306 -0
- package/src/interactive/turn-runtime.ts +802 -0
- package/src/interactive/turn-state.ts +123 -0
- package/src/interactive/view/artifacts.ts +1342 -0
- package/src/interactive/view/view-overlay.ts +732 -0
- package/src/interactive/welcome-dashboard.ts +536 -0
- package/src/interactive/worker-receipts.ts +94 -0
- package/src/interactive/worker-replay.ts +111 -0
- package/src/interactive/worker-share.ts +100 -0
- package/src/interactive/worker-stream.ts +442 -0
- package/src/interactive/workspace-facts.ts +141 -0
- package/src/tools/agent-tools.ts +382 -0
- package/src/tools/artifact.ts +103 -0
- package/src/tools/ask-user.ts +656 -0
- package/src/tools/bash.ts +176 -0
- package/src/tools/bootstrap.ts +474 -0
- package/src/tools/codewiki/code-nav.ts +563 -0
- package/src/tools/codewiki/shared.ts +115 -0
- package/src/tools/compete-worktrees.ts +898 -0
- package/src/tools/context/docs-engine.ts +619 -0
- package/src/tools/context/index.ts +435 -0
- package/src/tools/credential-present.ts +151 -0
- package/src/tools/dispatch-arguments.ts +228 -0
- package/src/tools/dispatch-plan.ts +741 -0
- package/src/tools/dispatch-scout.ts +461 -0
- package/src/tools/dispatch.ts +3338 -0
- package/src/tools/edit-diff.ts +534 -0
- package/src/tools/edit.ts +128 -0
- package/src/tools/executables.ts +22 -0
- package/src/tools/file-mutation-queue.ts +35 -0
- package/src/tools/find.ts +292 -0
- package/src/tools/grep.ts +495 -0
- package/src/tools/ignore-policy.ts +169 -0
- package/src/tools/ledger.ts +206 -0
- package/src/tools/ls.ts +110 -0
- package/src/tools/monitor.ts +797 -0
- package/src/tools/network-policy.ts +29 -0
- package/src/tools/observation.ts +421 -0
- package/src/tools/observers.ts +99 -0
- package/src/tools/path-utils.ts +79 -0
- package/src/tools/policy.ts +154 -0
- package/src/tools/profiles.ts +108 -0
- package/src/tools/read.ts +173 -0
- package/src/tools/registry.ts +1157 -0
- package/src/tools/result-shaping.ts +204 -0
- package/src/tools/safe-exec.ts +128 -0
- package/src/tools/spawn-hygiene.ts +182 -0
- package/src/tools/steer.ts +88 -0
- package/src/tools/string-enum.ts +15 -0
- package/src/tools/tasks.ts +168 -0
- package/src/tools/truncate-utf8.ts +17 -0
- package/src/tools/truncate.ts +202 -0
- package/src/tools/verify/frontend.ts +685 -0
- package/src/tools/verify/index.ts +66 -0
- package/src/tools/verify/scripts.ts +108 -0
- package/src/tools/web-fetch.ts +777 -0
- package/src/tools/worker-evidence.ts +215 -0
- package/src/tools/write.ts +52 -0
- package/src/utils/exif-orientation.ts +192 -0
- package/src/utils/git.ts +24 -0
- package/src/utils/image-resize.ts +148 -0
- package/src/utils/photon.ts +103 -0
- package/src/worker/control-lane.ts +22 -0
- package/src/worker/entry.ts +257 -0
- package/src/worker/event-projection.ts +56 -0
- package/src/worker/heartbeat.ts +24 -0
- package/src/worker/ledger-mirror.ts +95 -0
- package/src/worker/ndjson.ts +40 -0
- package/src/worker/protocol.ts +529 -0
- package/src/worker/resource-facts.ts +79 -0
- package/src/worker/runtime-registry.ts +12 -0
- package/src/worker/spec-contract.ts +654 -0
- package/src/worker/stdin-demux.ts +316 -0
- package/dist/acp-UMLFVA3F.js +0 -92
- package/dist/chunk-262G75JS.js +0 -35
- package/dist/chunk-5LDRNKX2.js +0 -1063
- package/dist/chunk-67MTHP2E.js +0 -135
- package/dist/chunk-GOTUR54M.js +0 -9
- package/dist/chunk-TPOCL34A.js +0 -2876
- package/dist/chunk-XV4ZJ6ZM.js +0 -3177
- package/dist/clio-KIQ5SNDS.js +0 -53
- package/dist/configure-G4E3A2PG.js +0 -27
- package/dist/doctor-M5HJJZOL.js +0 -61
- package/dist/domains/agents/builtins/architect.md +0 -33
- package/dist/domains/agents/builtins/coder.md +0 -31
- package/dist/domains/agents/builtins/context-bootstrap.md +0 -38
- package/dist/domains/agents/builtins/debugger.md +0 -30
- package/dist/domains/agents/builtins/documenter.md +0 -31
- package/dist/domains/agents/builtins/git-master.md +0 -30
- package/dist/domains/agents/builtins/provenance.md +0 -30
- package/dist/domains/agents/builtins/researcher.md +0 -71
- package/dist/domains/agents/builtins/scout.md +0 -42
- package/dist/domains/agents/builtins/tester.md +0 -31
- package/dist/domains/agents/builtins/verifier.md +0 -30
- package/dist/domains/agents/builtins/wiki-writer.md +0 -41
- package/dist/fleet-preflight-CLIAX7YR.js +0 -21
- package/dist/preload-KZVHET2B.js +0 -11
- package/dist/version-ROZ6CZKH.js +0 -16
- package/skills/git/commit-crafting/SKILL.md +0 -79
- package/skills/git/commit-crafting/evals.md +0 -92
- package/skills/git/create-pr/SKILL.md +0 -116
- package/skills/git/create-pr/evals.md +0 -114
- package/skills/git/investigate-issue/SKILL.md +0 -139
- package/skills/git/investigate-issue/evals.md +0 -94
- package/skills/git/review-changes/SKILL.md +0 -103
- package/skills/git/review-changes/evals.md +0 -85
|
@@ -0,0 +1,1342 @@
|
|
|
1
|
+
import { createReadStream, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { readFile, stat } from "node:fs/promises";
|
|
3
|
+
import { basename, isAbsolute, join, resolve } from "node:path";
|
|
4
|
+
import type { DispatchContract } from "../../domains/dispatch/contract.js";
|
|
5
|
+
import {
|
|
6
|
+
isReceiptIntegrity,
|
|
7
|
+
type ReceiptIntegrityResult,
|
|
8
|
+
verifyReceiptIntegrity,
|
|
9
|
+
} from "../../domains/dispatch/receipt-integrity.js";
|
|
10
|
+
import type { RunEnvelope, RunReceipt } from "../../domains/dispatch/types.js";
|
|
11
|
+
import { evidenceDirectory, inspectEvidence, listEvidenceOverviews } from "../../domains/evidence/store.js";
|
|
12
|
+
import type { EvidenceFinding, EvidenceOverview, EvidenceSource } from "../../domains/evidence/types.js";
|
|
13
|
+
import { type AccountabilitySummary, readAccountabilitySummary } from "../../domains/observability/index.js";
|
|
14
|
+
import type {
|
|
15
|
+
BashExecutionEntry,
|
|
16
|
+
MessageEntry,
|
|
17
|
+
ProtectedArtifactEntry,
|
|
18
|
+
SessionEntry,
|
|
19
|
+
TaskLedgerEntry,
|
|
20
|
+
TaskLedgerGoal,
|
|
21
|
+
TaskLedgerValidationEvidence,
|
|
22
|
+
} from "../../domains/session/entries.js";
|
|
23
|
+
import {
|
|
24
|
+
type AuditJsonRow,
|
|
25
|
+
type AuditReadResult,
|
|
26
|
+
readAuditRows,
|
|
27
|
+
type SessionMeta,
|
|
28
|
+
} from "../../domains/session/index.js";
|
|
29
|
+
import {
|
|
30
|
+
getPromptManifestFilePath,
|
|
31
|
+
readPromptCompileManifest,
|
|
32
|
+
type SessionPromptCompileRecord,
|
|
33
|
+
} from "../../domains/session/prompt-manifest.js";
|
|
34
|
+
import { formatUsd } from "../footer/widgets.js";
|
|
35
|
+
import { formatFooterTokens } from "../footer-panel.js";
|
|
36
|
+
import { clockLocal } from "../format-time.js";
|
|
37
|
+
import { abbreviateModelId } from "../theme/index.js";
|
|
38
|
+
|
|
39
|
+
export type ViewArtifactCategory =
|
|
40
|
+
| "accountability"
|
|
41
|
+
| "evidence"
|
|
42
|
+
| "receipt"
|
|
43
|
+
| "dispatch"
|
|
44
|
+
| "task-ledger"
|
|
45
|
+
| "tool-output"
|
|
46
|
+
| "protected-artifact"
|
|
47
|
+
| "compaction"
|
|
48
|
+
| "prompt-manifest"
|
|
49
|
+
| "audit";
|
|
50
|
+
export type ViewArtifactFormat = "markdown" | "text" | "json";
|
|
51
|
+
|
|
52
|
+
export interface ViewArtifactLoadResult {
|
|
53
|
+
lines: string[];
|
|
54
|
+
format: ViewArtifactFormat;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface ViewArtifact {
|
|
58
|
+
id: string;
|
|
59
|
+
category: ViewArtifactCategory;
|
|
60
|
+
title: string;
|
|
61
|
+
timestamp: number;
|
|
62
|
+
sizeBytes?: number | undefined;
|
|
63
|
+
/** Absolute backing path when one exists. Session-entry artifacts point at current.jsonl. */
|
|
64
|
+
path?: string | undefined;
|
|
65
|
+
description?: string;
|
|
66
|
+
runId?: string;
|
|
67
|
+
sessionId?: string;
|
|
68
|
+
correlationId?: string;
|
|
69
|
+
toolName?: string;
|
|
70
|
+
searchText?: readonly string[];
|
|
71
|
+
load(): Promise<ViewArtifactLoadResult>;
|
|
72
|
+
verify?(): Promise<{ ok: boolean; detail: string }>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface ArtifactProvider {
|
|
76
|
+
category: ViewArtifactCategory;
|
|
77
|
+
list(): Promise<ViewArtifact[]>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface ArtifactProviderDeps {
|
|
81
|
+
stateDir: string;
|
|
82
|
+
dataDir?: string | undefined;
|
|
83
|
+
dispatch?: Pick<DispatchContract, "listRuns" | "getRun"> | undefined;
|
|
84
|
+
sessionMeta?: SessionMeta | null | undefined;
|
|
85
|
+
readSessionEntries?: (() => ReadonlyArray<SessionEntry>) | undefined;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export const VIEW_ARTIFACT_CATEGORIES: readonly ViewArtifactCategory[] = [
|
|
89
|
+
"accountability",
|
|
90
|
+
"evidence",
|
|
91
|
+
"receipt",
|
|
92
|
+
"dispatch",
|
|
93
|
+
"task-ledger",
|
|
94
|
+
"tool-output",
|
|
95
|
+
"protected-artifact",
|
|
96
|
+
"compaction",
|
|
97
|
+
"prompt-manifest",
|
|
98
|
+
"audit",
|
|
99
|
+
] as const;
|
|
100
|
+
|
|
101
|
+
/** Cap on failure-cause tags rendered in the accountability artifact. */
|
|
102
|
+
const ACCOUNTABILITY_TOP_CAUSES = 8;
|
|
103
|
+
|
|
104
|
+
export const VIEW_ARTIFACT_LINE_CAP = 50_000;
|
|
105
|
+
const JSON_PRETTY_MAX_BYTES = 10 * 1024 * 1024;
|
|
106
|
+
|
|
107
|
+
export type ReceiptVerifyResult = ReceiptIntegrityResult;
|
|
108
|
+
|
|
109
|
+
const RECEIPT_REQUIRED_KEYS = [
|
|
110
|
+
"runId",
|
|
111
|
+
"agentId",
|
|
112
|
+
"task",
|
|
113
|
+
"targetId",
|
|
114
|
+
"wireModelId",
|
|
115
|
+
"runtimeId",
|
|
116
|
+
"runtimeKind",
|
|
117
|
+
"startedAt",
|
|
118
|
+
"endedAt",
|
|
119
|
+
"exitCode",
|
|
120
|
+
"tokenCount",
|
|
121
|
+
"costUsd",
|
|
122
|
+
"compiledPromptHash",
|
|
123
|
+
"staticCompositionHash",
|
|
124
|
+
"clioVersion",
|
|
125
|
+
"piMonoVersion",
|
|
126
|
+
"platform",
|
|
127
|
+
"nodeVersion",
|
|
128
|
+
"toolCalls",
|
|
129
|
+
"toolStats",
|
|
130
|
+
"sessionId",
|
|
131
|
+
"integrity",
|
|
132
|
+
] as const;
|
|
133
|
+
|
|
134
|
+
const ISO_8601_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
135
|
+
|
|
136
|
+
function isIso8601(value: unknown): value is string {
|
|
137
|
+
return typeof value === "string" && ISO_8601_REGEX.test(value) && !Number.isNaN(Date.parse(value));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
141
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function isNonEmptyString(value: unknown): value is string {
|
|
145
|
+
return typeof value === "string" && value.length > 0;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function isNonNegativeInteger(value: unknown): value is number {
|
|
149
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 0;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function isNonNegativeFiniteNumber(value: unknown): value is number {
|
|
153
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function isNullableString(value: unknown): value is string | null {
|
|
157
|
+
return value === null || typeof value === "string";
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function parseTime(value: string | null | undefined): number {
|
|
161
|
+
if (!value) return 0;
|
|
162
|
+
const parsed = Date.parse(value);
|
|
163
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function formatLocalTime(value: string | null | undefined): string {
|
|
167
|
+
const timestamp = parseTime(value);
|
|
168
|
+
return timestamp <= 0 ? "unknown time" : clockLocal(timestamp);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function safeTitle(value: string, fallback: string): string {
|
|
172
|
+
const trimmed = value.replace(/\s+/g, " ").trim();
|
|
173
|
+
return trimmed.length > 0 ? trimmed : fallback;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function shortValue(value: string, maxLength = 12): string {
|
|
177
|
+
const trimmed = value.replace(/\s+/g, " ").trim();
|
|
178
|
+
if (trimmed.length <= maxLength) return trimmed;
|
|
179
|
+
return trimmed.slice(0, maxLength);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function formatList(values: ReadonlyArray<string>, fallback = "none"): string {
|
|
183
|
+
const cleaned = values.map((value) => value.trim()).filter((value) => value.length > 0);
|
|
184
|
+
return cleaned.length > 0 ? cleaned.join(", ") : fallback;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function formatOptionalString(value: string | null | undefined, fallback = "none"): string {
|
|
188
|
+
return typeof value === "string" && value.length > 0 ? value : fallback;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function formatDurationMs(value: number): string {
|
|
192
|
+
if (!Number.isFinite(value) || value < 0) return "unknown";
|
|
193
|
+
if (value < 1000) return `${Math.round(value)}ms`;
|
|
194
|
+
const seconds = value / 1000;
|
|
195
|
+
if (seconds < 60) return `${seconds.toFixed(1)}s`;
|
|
196
|
+
const minutes = Math.floor(seconds / 60);
|
|
197
|
+
const remainder = Math.round(seconds % 60);
|
|
198
|
+
return `${minutes}m ${remainder}s`;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function readStringField(record: Record<string, unknown>, key: string): string | null {
|
|
202
|
+
const value = record[key];
|
|
203
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function maybeSizeBytes(path: string): number | undefined {
|
|
207
|
+
try {
|
|
208
|
+
const info = statSync(path);
|
|
209
|
+
return info.isFile() ? info.size : undefined;
|
|
210
|
+
} catch {
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function sessionCurrentPath(stateDir: string, meta: SessionMeta | null | undefined): string | undefined {
|
|
216
|
+
if (!meta) return undefined;
|
|
217
|
+
return join(stateDir, "sessions", meta.cwdHash, meta.id, "current.jsonl");
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function protectedArtifactPath(path: string): string | undefined {
|
|
221
|
+
return isAbsolute(path) ? path : undefined;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function receiptFilePath(stateDir: string, runId: string): string {
|
|
225
|
+
return join(stateDir, "receipts", `${runId}.json`);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function runLedgerPath(stateDir: string): string {
|
|
229
|
+
return join(stateDir, "runs.json");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function readRunLedger(stateDir: string): RunEnvelope[] {
|
|
233
|
+
try {
|
|
234
|
+
const raw = readFileSync(runLedgerPath(stateDir), "utf8").trim();
|
|
235
|
+
if (raw.length === 0) return [];
|
|
236
|
+
const parsed = JSON.parse(raw) as unknown;
|
|
237
|
+
return Array.isArray(parsed) ? (parsed.filter(isRecord) as unknown as RunEnvelope[]) : [];
|
|
238
|
+
} catch {
|
|
239
|
+
return [];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function listRunEnvelopes(deps: ArtifactProviderDeps): RunEnvelope[] {
|
|
244
|
+
// The in-process dispatch ledger only sees runs created by this process.
|
|
245
|
+
// A headless `clio-coder run` in another process writes runs.json and receipts/
|
|
246
|
+
// directly, so every listing re-reads the disk ledger and merges runs the
|
|
247
|
+
// in-memory mirror has not hydrated.
|
|
248
|
+
let fromMemory: RunEnvelope[] = [];
|
|
249
|
+
try {
|
|
250
|
+
fromMemory = [...(deps.dispatch?.listRuns() ?? [])];
|
|
251
|
+
} catch {
|
|
252
|
+
fromMemory = [];
|
|
253
|
+
}
|
|
254
|
+
const seen = new Set(fromMemory.map((env) => env.id));
|
|
255
|
+
const fromDisk = readRunLedger(deps.stateDir).filter((env) => !seen.has(env.id));
|
|
256
|
+
return [...fromMemory, ...fromDisk];
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function validateToolStats(value: unknown): ReceiptVerifyResult {
|
|
260
|
+
if (!Array.isArray(value)) {
|
|
261
|
+
return { ok: false, reason: `toolStats not an array: ${String(value)}` };
|
|
262
|
+
}
|
|
263
|
+
for (let i = 0; i < value.length; i++) {
|
|
264
|
+
const entry = value[i];
|
|
265
|
+
if (!isRecord(entry)) {
|
|
266
|
+
return { ok: false, reason: `toolStats[${i}] not an object` };
|
|
267
|
+
}
|
|
268
|
+
if (!isNonEmptyString(entry.tool)) {
|
|
269
|
+
return { ok: false, reason: `toolStats[${i}].tool invalid: ${String(entry.tool)}` };
|
|
270
|
+
}
|
|
271
|
+
for (const key of ["count", "ok", "errors", "blocked"] as const) {
|
|
272
|
+
if (!isNonNegativeInteger(entry[key])) {
|
|
273
|
+
return { ok: false, reason: `toolStats[${i}].${key} invalid: ${String(entry[key])}` };
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (!isNonNegativeFiniteNumber(entry.totalDurationMs)) {
|
|
277
|
+
return { ok: false, reason: `toolStats[${i}].totalDurationMs invalid: ${String(entry.totalDurationMs)}` };
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return { ok: true };
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
type ReadLedgerResult = { ok: true; envelope: RunEnvelope } | { ok: false; reason: string };
|
|
284
|
+
|
|
285
|
+
function readRunEnvelope(stateDir: string, runId: string): ReadLedgerResult {
|
|
286
|
+
const runs = readRunLedger(stateDir);
|
|
287
|
+
for (const entry of runs) {
|
|
288
|
+
if (entry.id === runId) return { ok: true, envelope: entry };
|
|
289
|
+
}
|
|
290
|
+
return { ok: false, reason: runs.length === 0 ? "run ledger not found" : "run not found in ledger" };
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export function verifyReceiptFile(stateDir: string, runId: string): ReceiptVerifyResult {
|
|
294
|
+
const target = receiptFilePath(stateDir, runId);
|
|
295
|
+
let raw: string;
|
|
296
|
+
try {
|
|
297
|
+
raw = readFileSync(target, "utf8");
|
|
298
|
+
} catch (err) {
|
|
299
|
+
const e = err as NodeJS.ErrnoException;
|
|
300
|
+
if (e.code === "ENOENT") return { ok: false, reason: "receipt file not found" };
|
|
301
|
+
return { ok: false, reason: `read error: ${e.message ?? String(e)}` };
|
|
302
|
+
}
|
|
303
|
+
let parsed: unknown;
|
|
304
|
+
try {
|
|
305
|
+
parsed = JSON.parse(raw);
|
|
306
|
+
} catch (err) {
|
|
307
|
+
return { ok: false, reason: `invalid json: ${(err as Error).message}` };
|
|
308
|
+
}
|
|
309
|
+
if (!isRecord(parsed)) {
|
|
310
|
+
return { ok: false, reason: "receipt is not an object" };
|
|
311
|
+
}
|
|
312
|
+
const r = parsed;
|
|
313
|
+
for (const key of RECEIPT_REQUIRED_KEYS) {
|
|
314
|
+
if (!(key in r)) return { ok: false, reason: `missing field: ${key}` };
|
|
315
|
+
}
|
|
316
|
+
if (!isNonEmptyString(r.runId)) {
|
|
317
|
+
return { ok: false, reason: `runId invalid: ${String(r.runId)}` };
|
|
318
|
+
}
|
|
319
|
+
if (r.runId !== runId) {
|
|
320
|
+
return { ok: false, reason: `runId mismatch: file has ${String(r.runId)}` };
|
|
321
|
+
}
|
|
322
|
+
if (!isNonEmptyString(r.agentId)) {
|
|
323
|
+
return { ok: false, reason: `agentId invalid: ${String(r.agentId)}` };
|
|
324
|
+
}
|
|
325
|
+
if (!isNonEmptyString(r.task)) {
|
|
326
|
+
return { ok: false, reason: `task invalid: ${String(r.task)}` };
|
|
327
|
+
}
|
|
328
|
+
if (!isNonEmptyString(r.targetId)) {
|
|
329
|
+
return { ok: false, reason: `targetId invalid: ${String(r.targetId)}` };
|
|
330
|
+
}
|
|
331
|
+
if (!isNonEmptyString(r.wireModelId)) {
|
|
332
|
+
return { ok: false, reason: `wireModelId invalid: ${String(r.wireModelId)}` };
|
|
333
|
+
}
|
|
334
|
+
if (!isNonEmptyString(r.runtimeId)) {
|
|
335
|
+
return { ok: false, reason: `runtimeId invalid: ${String(r.runtimeId)}` };
|
|
336
|
+
}
|
|
337
|
+
if (
|
|
338
|
+
r.runtimeKind !== "http" &&
|
|
339
|
+
r.runtimeKind !== "sdk" &&
|
|
340
|
+
r.runtimeKind !== "subprocess" &&
|
|
341
|
+
r.runtimeKind !== "acp-delegation"
|
|
342
|
+
) {
|
|
343
|
+
return { ok: false, reason: `runtimeKind invalid: ${String(r.runtimeKind)}` };
|
|
344
|
+
}
|
|
345
|
+
const exitCode = r.exitCode;
|
|
346
|
+
if (typeof exitCode !== "number" || !(exitCode === 0 || exitCode === 1 || exitCode === 2)) {
|
|
347
|
+
return { ok: false, reason: `exitCode out of range: ${String(exitCode)}` };
|
|
348
|
+
}
|
|
349
|
+
const tokenCount = r.tokenCount;
|
|
350
|
+
if (typeof tokenCount !== "number" || !Number.isFinite(tokenCount) || tokenCount < 0) {
|
|
351
|
+
return { ok: false, reason: `tokenCount out of range: ${String(tokenCount)}` };
|
|
352
|
+
}
|
|
353
|
+
for (const key of ["inputTokenCount", "outputTokenCount", "cacheReadTokenCount", "cacheWriteTokenCount"] as const) {
|
|
354
|
+
if (key in r && !isNonNegativeFiniteNumber(r[key])) {
|
|
355
|
+
return { ok: false, reason: `${key} out of range: ${String(r[key])}` };
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
const costUsd = r.costUsd;
|
|
359
|
+
if (typeof costUsd !== "number" || !Number.isFinite(costUsd) || costUsd < 0) {
|
|
360
|
+
return { ok: false, reason: `costUsd out of range: ${String(costUsd)}` };
|
|
361
|
+
}
|
|
362
|
+
if ("reasoningTokenCount" in r && !isNonNegativeFiniteNumber(r.reasoningTokenCount)) {
|
|
363
|
+
return { ok: false, reason: `reasoningTokenCount out of range: ${String(r.reasoningTokenCount)}` };
|
|
364
|
+
}
|
|
365
|
+
if (!isIso8601(r.startedAt)) {
|
|
366
|
+
return { ok: false, reason: `startedAt not ISO-8601: ${String(r.startedAt)}` };
|
|
367
|
+
}
|
|
368
|
+
if (!isIso8601(r.endedAt)) {
|
|
369
|
+
return { ok: false, reason: `endedAt not ISO-8601: ${String(r.endedAt)}` };
|
|
370
|
+
}
|
|
371
|
+
if (typeof r.clioVersion !== "string" || r.clioVersion.length === 0) {
|
|
372
|
+
return { ok: false, reason: "clioVersion empty" };
|
|
373
|
+
}
|
|
374
|
+
if (!isNonEmptyString(r.piMonoVersion)) {
|
|
375
|
+
return { ok: false, reason: `piMonoVersion invalid: ${String(r.piMonoVersion)}` };
|
|
376
|
+
}
|
|
377
|
+
if (!isNonEmptyString(r.platform)) {
|
|
378
|
+
return { ok: false, reason: `platform invalid: ${String(r.platform)}` };
|
|
379
|
+
}
|
|
380
|
+
if (!isNonEmptyString(r.nodeVersion)) {
|
|
381
|
+
return { ok: false, reason: `nodeVersion invalid: ${String(r.nodeVersion)}` };
|
|
382
|
+
}
|
|
383
|
+
if (typeof r.toolCalls !== "number" || !Number.isInteger(r.toolCalls) || r.toolCalls < 0) {
|
|
384
|
+
return { ok: false, reason: `toolCalls out of range: ${String(r.toolCalls)}` };
|
|
385
|
+
}
|
|
386
|
+
const toolStatsCheck = validateToolStats(r.toolStats);
|
|
387
|
+
if (!toolStatsCheck.ok) return toolStatsCheck;
|
|
388
|
+
if (!isNullableString(r.compiledPromptHash)) {
|
|
389
|
+
return { ok: false, reason: `compiledPromptHash invalid: ${String(r.compiledPromptHash)}` };
|
|
390
|
+
}
|
|
391
|
+
if (!isNullableString(r.staticCompositionHash)) {
|
|
392
|
+
return { ok: false, reason: `staticCompositionHash invalid: ${String(r.staticCompositionHash)}` };
|
|
393
|
+
}
|
|
394
|
+
if (!isNullableString(r.sessionId)) {
|
|
395
|
+
return { ok: false, reason: `sessionId invalid: ${String(r.sessionId)}` };
|
|
396
|
+
}
|
|
397
|
+
if (!isReceiptIntegrity(r.integrity)) {
|
|
398
|
+
return { ok: false, reason: "integrity invalid" };
|
|
399
|
+
}
|
|
400
|
+
const ledger = readRunEnvelope(stateDir, runId);
|
|
401
|
+
if (!ledger.ok) return ledger;
|
|
402
|
+
return verifyReceiptIntegrity(r as unknown as RunReceipt, ledger.envelope);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function pushCapped(lines: string[], line: string, maxLines: number): boolean {
|
|
406
|
+
if (lines.length >= maxLines) return false;
|
|
407
|
+
lines.push(line);
|
|
408
|
+
return lines.length < maxLines;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
async function readTextFileLinesCapped(
|
|
412
|
+
path: string,
|
|
413
|
+
maxLines = VIEW_ARTIFACT_LINE_CAP,
|
|
414
|
+
): Promise<{ lines: string[]; truncated: boolean }> {
|
|
415
|
+
const lines: string[] = [];
|
|
416
|
+
let pending = "";
|
|
417
|
+
let truncated = false;
|
|
418
|
+
const stream = createReadStream(path, { encoding: "utf8", highWaterMark: 64 * 1024 });
|
|
419
|
+
outer: for await (const chunk of stream) {
|
|
420
|
+
pending += chunk;
|
|
421
|
+
for (;;) {
|
|
422
|
+
const nextBreak = pending.indexOf("\n");
|
|
423
|
+
if (nextBreak < 0) break;
|
|
424
|
+
const line = pending.slice(0, nextBreak).replace(/\r$/, "");
|
|
425
|
+
pending = pending.slice(nextBreak + 1);
|
|
426
|
+
if (!pushCapped(lines, line, maxLines)) {
|
|
427
|
+
truncated = true;
|
|
428
|
+
stream.destroy();
|
|
429
|
+
break outer;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
if (!truncated && pending.length > 0 && !pushCapped(lines, pending.replace(/\r$/, ""), maxLines)) {
|
|
434
|
+
truncated = true;
|
|
435
|
+
}
|
|
436
|
+
if (truncated) {
|
|
437
|
+
lines.push(`[truncated, open file directly: ${path}]`);
|
|
438
|
+
}
|
|
439
|
+
return { lines, truncated };
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function splitLinesCapped(text: string, path?: string, maxLines = VIEW_ARTIFACT_LINE_CAP): string[] {
|
|
443
|
+
const lines = text.split(/\r?\n/);
|
|
444
|
+
if (lines.length <= maxLines) return lines;
|
|
445
|
+
return [...lines.slice(0, maxLines), `[truncated, open file directly${path ? `: ${path}` : ""}]`];
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
export async function loadJsonFileLines(path: string): Promise<ViewArtifactLoadResult> {
|
|
449
|
+
let canPrettyPrint = false;
|
|
450
|
+
try {
|
|
451
|
+
const info = await stat(path);
|
|
452
|
+
canPrettyPrint = info.size <= JSON_PRETTY_MAX_BYTES;
|
|
453
|
+
} catch {
|
|
454
|
+
return { lines: [`unable to read ${path}`], format: "text" };
|
|
455
|
+
}
|
|
456
|
+
if (canPrettyPrint) {
|
|
457
|
+
try {
|
|
458
|
+
const raw = await readFile(path, "utf8");
|
|
459
|
+
const pretty = JSON.stringify(JSON.parse(raw), null, 2);
|
|
460
|
+
return { lines: splitLinesCapped(pretty, path), format: "json" };
|
|
461
|
+
} catch {
|
|
462
|
+
return loadTextPath(path);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
const { lines } = await readTextFileLinesCapped(path);
|
|
466
|
+
return { lines, format: "json" };
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
async function loadTextPath(path: string): Promise<ViewArtifactLoadResult> {
|
|
470
|
+
try {
|
|
471
|
+
const { lines } = await readTextFileLinesCapped(path);
|
|
472
|
+
return { lines, format: "text" };
|
|
473
|
+
} catch (err) {
|
|
474
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
475
|
+
return { lines: [`unable to read ${path}: ${message}`], format: "text" };
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function evidenceBundlePath(dataDir: string, evidenceId: string): string | undefined {
|
|
480
|
+
try {
|
|
481
|
+
return evidenceDirectory(dataDir, evidenceId);
|
|
482
|
+
} catch {
|
|
483
|
+
return undefined;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function evidenceSourceLabel(source: EvidenceSource): string {
|
|
488
|
+
switch (source.kind) {
|
|
489
|
+
case "run":
|
|
490
|
+
return `run ${source.runId}`;
|
|
491
|
+
case "session":
|
|
492
|
+
return `session ${source.sessionId}`;
|
|
493
|
+
case "eval":
|
|
494
|
+
return `eval ${source.evalId}`;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function evidenceSourceTitle(source: EvidenceSource): string {
|
|
499
|
+
switch (source.kind) {
|
|
500
|
+
case "run":
|
|
501
|
+
return `run ${shortValue(source.runId)}`;
|
|
502
|
+
case "session":
|
|
503
|
+
return `session ${shortValue(source.sessionId)}`;
|
|
504
|
+
case "eval":
|
|
505
|
+
return `eval ${shortValue(source.evalId)}`;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function renderEvidenceMarkdown(
|
|
510
|
+
overview: EvidenceOverview,
|
|
511
|
+
findings: ReadonlyArray<EvidenceFinding>,
|
|
512
|
+
path: string | undefined,
|
|
513
|
+
loadError?: string,
|
|
514
|
+
): string[] {
|
|
515
|
+
const lines = [
|
|
516
|
+
"# Evidence Bundle",
|
|
517
|
+
"",
|
|
518
|
+
`- evidence id: ${overview.evidenceId}`,
|
|
519
|
+
`- source: ${evidenceSourceLabel(overview.source)}`,
|
|
520
|
+
`- generated: ${overview.generatedAt}`,
|
|
521
|
+
`- run ids: ${formatList(overview.runIds)}`,
|
|
522
|
+
`- session id: ${formatOptionalString(overview.sessionId)}`,
|
|
523
|
+
`- statuses: ${formatList(overview.statuses)}`,
|
|
524
|
+
"",
|
|
525
|
+
"## Tasks",
|
|
526
|
+
];
|
|
527
|
+
if (overview.tasks.length === 0) {
|
|
528
|
+
lines.push("- none");
|
|
529
|
+
} else {
|
|
530
|
+
for (const task of overview.tasks) lines.push(`- ${task}`);
|
|
531
|
+
}
|
|
532
|
+
lines.push(
|
|
533
|
+
"",
|
|
534
|
+
"## Targets / Models",
|
|
535
|
+
"",
|
|
536
|
+
`- targets: ${formatList(overview.targetIds)}`,
|
|
537
|
+
`- runtimes: ${formatList(overview.runtimeIds)}`,
|
|
538
|
+
`- models: ${formatList(overview.modelIds)}`,
|
|
539
|
+
`- agents: ${formatList(overview.agentIds)}`,
|
|
540
|
+
"",
|
|
541
|
+
"## Totals",
|
|
542
|
+
"",
|
|
543
|
+
`- runs: ${overview.totals.runs}`,
|
|
544
|
+
`- receipts: ${overview.totals.receipts}`,
|
|
545
|
+
`- tool calls: ${overview.totals.toolCalls}`,
|
|
546
|
+
`- tool errors: ${overview.totals.toolErrors}`,
|
|
547
|
+
`- blocked tool calls: ${overview.totals.blockedToolCalls}`,
|
|
548
|
+
`- tokens: ${formatFooterTokens(overview.totals.tokens)}`,
|
|
549
|
+
`- cost: ${formatUsd(overview.totals.costUsd)}`,
|
|
550
|
+
`- protected artifacts: ${overview.totals.protectedArtifacts}`,
|
|
551
|
+
`- wall time: ${formatDurationMs(overview.totals.wallTimeMs)}`,
|
|
552
|
+
"",
|
|
553
|
+
"## Tags",
|
|
554
|
+
);
|
|
555
|
+
if (overview.tags.length === 0) {
|
|
556
|
+
lines.push("- none");
|
|
557
|
+
} else {
|
|
558
|
+
for (const tag of overview.tags) lines.push(`- ${tag}`);
|
|
559
|
+
}
|
|
560
|
+
lines.push("", "## Findings");
|
|
561
|
+
if (findings.length === 0) {
|
|
562
|
+
lines.push("- none");
|
|
563
|
+
} else {
|
|
564
|
+
for (const finding of findings) {
|
|
565
|
+
const run = finding.runId ? ` run ${finding.runId}` : "";
|
|
566
|
+
lines.push(`- ${finding.severity} ${finding.tag}${run}: ${finding.message}`);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
lines.push("", "## Files", "", `- backing path: ${path ?? "unknown"}`);
|
|
570
|
+
if (overview.files.length === 0) {
|
|
571
|
+
lines.push("- files: none");
|
|
572
|
+
} else {
|
|
573
|
+
for (const file of overview.files) lines.push(`- ${file}`);
|
|
574
|
+
}
|
|
575
|
+
if (loadError !== undefined) {
|
|
576
|
+
lines.push("", "## Load Error", "", loadError);
|
|
577
|
+
}
|
|
578
|
+
return lines;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
export class EvidenceArtifactProvider implements ArtifactProvider {
|
|
582
|
+
readonly category = "evidence" as const;
|
|
583
|
+
|
|
584
|
+
constructor(private readonly deps: ArtifactProviderDeps) {}
|
|
585
|
+
|
|
586
|
+
async list(): Promise<ViewArtifact[]> {
|
|
587
|
+
const dataDir = this.deps.dataDir;
|
|
588
|
+
if (!dataDir) return [];
|
|
589
|
+
let overviews: EvidenceOverview[];
|
|
590
|
+
try {
|
|
591
|
+
overviews = await listEvidenceOverviews(dataDir);
|
|
592
|
+
} catch {
|
|
593
|
+
return [];
|
|
594
|
+
}
|
|
595
|
+
return overviews.map((overview) => {
|
|
596
|
+
const path = evidenceBundlePath(dataDir, overview.evidenceId);
|
|
597
|
+
const artifact: ViewArtifact = {
|
|
598
|
+
id: overview.evidenceId,
|
|
599
|
+
category: this.category,
|
|
600
|
+
title: safeTitle(`Evidence · ${evidenceSourceTitle(overview.source)}`, "Evidence bundle"),
|
|
601
|
+
timestamp: parseTime(overview.generatedAt),
|
|
602
|
+
searchText: [
|
|
603
|
+
overview.evidenceId,
|
|
604
|
+
evidenceSourceTitle(overview.source),
|
|
605
|
+
...overview.runIds,
|
|
606
|
+
...(overview.sessionId ? [overview.sessionId] : []),
|
|
607
|
+
...overview.tasks,
|
|
608
|
+
...overview.cwds,
|
|
609
|
+
...overview.agentIds,
|
|
610
|
+
...overview.targetIds,
|
|
611
|
+
...overview.runtimeIds,
|
|
612
|
+
...overview.modelIds,
|
|
613
|
+
...overview.statuses,
|
|
614
|
+
...overview.tags,
|
|
615
|
+
...overview.files,
|
|
616
|
+
],
|
|
617
|
+
load: async () => {
|
|
618
|
+
try {
|
|
619
|
+
const inspected = await inspectEvidence(dataDir, overview.evidenceId);
|
|
620
|
+
return {
|
|
621
|
+
format: "markdown" as const,
|
|
622
|
+
lines: renderEvidenceMarkdown(inspected.overview, inspected.findings, path),
|
|
623
|
+
};
|
|
624
|
+
} catch (err) {
|
|
625
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
626
|
+
return {
|
|
627
|
+
format: "markdown" as const,
|
|
628
|
+
lines: renderEvidenceMarkdown(overview, [], path, `unable to inspect evidence: ${message}`),
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
},
|
|
632
|
+
};
|
|
633
|
+
if (path !== undefined) artifact.path = path;
|
|
634
|
+
if (overview.runIds.length === 1 && overview.runIds[0] !== undefined) artifact.runId = overview.runIds[0];
|
|
635
|
+
if (overview.sessionId !== null) artifact.sessionId = overview.sessionId;
|
|
636
|
+
return artifact;
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
function receiptTitle(env: RunEnvelope): string {
|
|
642
|
+
return safeTitle(`${env.agentId} · ${env.task}`, env.id);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
export class ReceiptArtifactProvider implements ArtifactProvider {
|
|
646
|
+
readonly category = "receipt" as const;
|
|
647
|
+
|
|
648
|
+
constructor(private readonly deps: ArtifactProviderDeps) {}
|
|
649
|
+
|
|
650
|
+
async list(): Promise<ViewArtifact[]> {
|
|
651
|
+
const runs = listRunEnvelopes(this.deps);
|
|
652
|
+
return runs
|
|
653
|
+
.filter(
|
|
654
|
+
(env) => env.receiptPath !== null || maybeSizeBytes(receiptFilePath(this.deps.stateDir, env.id)) !== undefined,
|
|
655
|
+
)
|
|
656
|
+
.map((env) => {
|
|
657
|
+
const path = env.receiptPath ?? receiptFilePath(this.deps.stateDir, env.id);
|
|
658
|
+
return {
|
|
659
|
+
id: env.id,
|
|
660
|
+
category: this.category,
|
|
661
|
+
title: receiptTitle(env),
|
|
662
|
+
timestamp: parseTime(env.endedAt ?? env.startedAt),
|
|
663
|
+
sizeBytes: maybeSizeBytes(path),
|
|
664
|
+
path,
|
|
665
|
+
description: env.task,
|
|
666
|
+
runId: env.id,
|
|
667
|
+
...(env.sessionId ? { sessionId: env.sessionId } : {}),
|
|
668
|
+
searchText: [env.id, env.agentId, env.task, env.targetId, env.runtimeId, env.runtimeKind, env.cwd],
|
|
669
|
+
load: () => loadJsonFileLines(path),
|
|
670
|
+
verify: async () => {
|
|
671
|
+
const result = verifyReceiptFile(this.deps.stateDir, env.id);
|
|
672
|
+
if (!result.ok) return { ok: false, detail: result.reason };
|
|
673
|
+
return { ok: true, detail: "integrity verified" };
|
|
674
|
+
},
|
|
675
|
+
};
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
function resultText(result: unknown): string {
|
|
681
|
+
if (!isRecord(result)) return "";
|
|
682
|
+
if (result.kind === "ok" && typeof result.output === "string") return result.output;
|
|
683
|
+
if (result.kind === "error" && typeof result.message === "string") return result.message;
|
|
684
|
+
return "";
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
function resultDetails(result: unknown): Record<string, unknown> | null {
|
|
688
|
+
return isRecord(result) && isRecord(result.details) ? result.details : null;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
function messagePayload(entry: SessionEntry): Record<string, unknown> | null {
|
|
692
|
+
if (entry.kind !== "message") return null;
|
|
693
|
+
return isRecord(entry.payload) ? entry.payload : null;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
function toolNameFor(entry: SessionEntry): string {
|
|
697
|
+
const payload = messagePayload(entry);
|
|
698
|
+
const name = payload?.toolName ?? payload?.name;
|
|
699
|
+
return typeof name === "string" && name.length > 0 ? name : "tool";
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
function pathFromToolResult(entry: SessionEntry): string | null {
|
|
703
|
+
const payload = messagePayload(entry);
|
|
704
|
+
const details = payload ? resultDetails(payload.result) : null;
|
|
705
|
+
if (!details) return null;
|
|
706
|
+
for (const key of ["fullOutputPath", "outputPath", "artifactPath"] as const) {
|
|
707
|
+
const value = details[key];
|
|
708
|
+
if (typeof value === "string" && value.length > 0) return resolve(value);
|
|
709
|
+
}
|
|
710
|
+
return null;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
function dispatchResultForRun(entries: ReadonlyArray<SessionEntry>, runId: string): string | null {
|
|
714
|
+
for (const entry of entries) {
|
|
715
|
+
const payload = messagePayload(entry);
|
|
716
|
+
if (!payload) continue;
|
|
717
|
+
const toolName = typeof payload.toolName === "string" ? payload.toolName : "";
|
|
718
|
+
if (toolName !== "dispatch") continue;
|
|
719
|
+
const details = resultDetails(payload.result);
|
|
720
|
+
const detailRunId = details?.runId;
|
|
721
|
+
const runIds = details?.runIds;
|
|
722
|
+
const matches =
|
|
723
|
+
detailRunId === runId ||
|
|
724
|
+
(Array.isArray(runIds) && runIds.some((item) => item === runId)) ||
|
|
725
|
+
(Array.isArray(details?.runs) && details.runs.some((item) => isRecord(item) && item.runId === runId));
|
|
726
|
+
if (!matches) continue;
|
|
727
|
+
const text = resultText(payload.result);
|
|
728
|
+
if (text.length > 0) return text;
|
|
729
|
+
}
|
|
730
|
+
return null;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
function sessionEntries(deps: ArtifactProviderDeps): ReadonlyArray<SessionEntry> {
|
|
734
|
+
try {
|
|
735
|
+
return deps.readSessionEntries?.() ?? [];
|
|
736
|
+
} catch {
|
|
737
|
+
return [];
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
export class DispatchArtifactProvider implements ArtifactProvider {
|
|
742
|
+
readonly category = "dispatch" as const;
|
|
743
|
+
|
|
744
|
+
constructor(private readonly deps: ArtifactProviderDeps) {}
|
|
745
|
+
|
|
746
|
+
async list(): Promise<ViewArtifact[]> {
|
|
747
|
+
const runs = listRunEnvelopes(this.deps);
|
|
748
|
+
const entries = sessionEntries(this.deps);
|
|
749
|
+
const ledgerPath = runLedgerPath(this.deps.stateDir);
|
|
750
|
+
return runs.map((env) => {
|
|
751
|
+
const receiptPath = env.receiptPath ?? receiptFilePath(this.deps.stateDir, env.id);
|
|
752
|
+
const path = maybeSizeBytes(receiptPath) !== undefined ? receiptPath : ledgerPath;
|
|
753
|
+
return {
|
|
754
|
+
id: env.id,
|
|
755
|
+
category: this.category,
|
|
756
|
+
title: receiptTitle(env),
|
|
757
|
+
timestamp: parseTime(env.endedAt ?? env.startedAt),
|
|
758
|
+
sizeBytes: maybeSizeBytes(path),
|
|
759
|
+
path,
|
|
760
|
+
description: env.task,
|
|
761
|
+
runId: env.id,
|
|
762
|
+
...(env.sessionId ? { sessionId: env.sessionId } : {}),
|
|
763
|
+
searchText: [env.id, env.agentId, env.task, env.targetId, env.runtimeId, env.runtimeKind, env.cwd],
|
|
764
|
+
load: async () => {
|
|
765
|
+
const text = dispatchResultForRun(entries, env.id);
|
|
766
|
+
const lines = [
|
|
767
|
+
`Dispatch run ${env.id}`,
|
|
768
|
+
`agent: ${env.agentId}`,
|
|
769
|
+
`task: ${env.task}`,
|
|
770
|
+
`status: ${env.status}`,
|
|
771
|
+
`outcome: ${env.outcome ?? "unknown"}`,
|
|
772
|
+
`exit: ${env.exitCode ?? "?"}`,
|
|
773
|
+
`target: ${env.targetId}`,
|
|
774
|
+
`model: ${abbreviateModelId(env.wireModelId)}`,
|
|
775
|
+
`runtime: ${env.runtimeKind}:${env.runtimeId}`,
|
|
776
|
+
`started: ${formatLocalTime(env.startedAt)}`,
|
|
777
|
+
`ended: ${env.endedAt ? formatLocalTime(env.endedAt) : "running"}`,
|
|
778
|
+
`tokens: ${formatFooterTokens(env.tokenCount)}`,
|
|
779
|
+
`cost: ${formatUsd(env.costUsd)}`,
|
|
780
|
+
`receipt: ${env.receiptPath ?? receiptFilePath(this.deps.stateDir, env.id)}`,
|
|
781
|
+
"",
|
|
782
|
+
"agent output:",
|
|
783
|
+
...(text ? text.split(/\r?\n/) : ["(no session dispatch tool output found)"]),
|
|
784
|
+
];
|
|
785
|
+
return { lines: splitLinesCapped(lines.join("\n"), path), format: "text" };
|
|
786
|
+
},
|
|
787
|
+
};
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
function taskLedgerStatusSummary(entry: TaskLedgerEntry): string {
|
|
793
|
+
const items = [...entry.goals, ...entry.subgoals];
|
|
794
|
+
if (items.length === 0) return "no goals";
|
|
795
|
+
const completed = items.filter((item) => item.status === "completed").length;
|
|
796
|
+
const active = items.filter((item) => item.status === "active").length;
|
|
797
|
+
const blocked = items.filter((item) => item.status === "blocked").length;
|
|
798
|
+
const parts = [`${completed}/${items.length} done`];
|
|
799
|
+
if (active > 0) parts.push(`${active} active`);
|
|
800
|
+
if (blocked > 0) parts.push(`${blocked} blocked`);
|
|
801
|
+
return parts.join(" · ");
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
function taskLedgerTitle(entry: TaskLedgerEntry): string {
|
|
805
|
+
const boardTitle = entry.goals[0]?.title ?? "Task ledger";
|
|
806
|
+
return safeTitle(`Task ledger · ${boardTitle} · ${taskLedgerStatusSummary(entry)}`, "Task ledger");
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
function renderTaskLedgerGoals(lines: string[], heading: string, goals: ReadonlyArray<TaskLedgerGoal>): void {
|
|
810
|
+
lines.push("", heading);
|
|
811
|
+
if (goals.length === 0) {
|
|
812
|
+
lines.push("- none");
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
for (const goal of goals) {
|
|
816
|
+
const parent = goal.parentGoalId ? ` parent ${goal.parentGoalId}` : "";
|
|
817
|
+
lines.push(`- [${goal.status}] ${goal.id} ${goal.title}${parent}`);
|
|
818
|
+
if (goal.description) lines.push(` - description: ${goal.description}`);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
function renderValidationEvidence(lines: string[], evidence: ReadonlyArray<TaskLedgerValidationEvidence>): void {
|
|
823
|
+
lines.push("", "## Required Validation Evidence");
|
|
824
|
+
if (evidence.length === 0) {
|
|
825
|
+
lines.push("- none");
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
for (const item of evidence) {
|
|
829
|
+
lines.push(`- [${item.status}] ${item.id} ${item.description}`);
|
|
830
|
+
if (item.command) lines.push(` - command: ${item.command}`);
|
|
831
|
+
if (item.artifactPath) lines.push(` - artifact: ${item.artifactPath}`);
|
|
832
|
+
if (item.observedAt) lines.push(` - observed: ${item.observedAt}`);
|
|
833
|
+
if (item.notes) lines.push(` - notes: ${item.notes}`);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
function renderTaskLedgerMarkdown(entry: TaskLedgerEntry): string[] {
|
|
838
|
+
const lines = [
|
|
839
|
+
"# Task Ledger",
|
|
840
|
+
"",
|
|
841
|
+
`- turn id: ${entry.turnId}`,
|
|
842
|
+
`- timestamp: ${entry.timestamp}`,
|
|
843
|
+
`- status: ${taskLedgerStatusSummary(entry)}`,
|
|
844
|
+
];
|
|
845
|
+
renderTaskLedgerGoals(lines, "## Board Goals", entry.goals);
|
|
846
|
+
renderTaskLedgerGoals(lines, "## Subgoals", entry.subgoals);
|
|
847
|
+
lines.push("", "## Active Runs");
|
|
848
|
+
if (entry.activeRunIds.length === 0) {
|
|
849
|
+
lines.push("- none");
|
|
850
|
+
} else {
|
|
851
|
+
for (const runId of entry.activeRunIds) lines.push(`- ${runId}`);
|
|
852
|
+
}
|
|
853
|
+
renderValidationEvidence(lines, entry.requiredValidationEvidence);
|
|
854
|
+
return lines;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
export class TaskLedgerArtifactProvider implements ArtifactProvider {
|
|
858
|
+
readonly category = "task-ledger" as const;
|
|
859
|
+
|
|
860
|
+
constructor(private readonly deps: ArtifactProviderDeps) {}
|
|
861
|
+
|
|
862
|
+
async list(): Promise<ViewArtifact[]> {
|
|
863
|
+
const entries = sessionEntries(this.deps);
|
|
864
|
+
const path = sessionCurrentPath(this.deps.stateDir, this.deps.sessionMeta);
|
|
865
|
+
return entries
|
|
866
|
+
.filter((entry): entry is TaskLedgerEntry => entry.kind === "taskLedger")
|
|
867
|
+
.map((entry) => ({
|
|
868
|
+
id: `task-ledger:${entry.turnId}`,
|
|
869
|
+
category: this.category,
|
|
870
|
+
title: taskLedgerTitle(entry),
|
|
871
|
+
timestamp: parseTime(entry.timestamp),
|
|
872
|
+
sizeBytes: Buffer.byteLength(JSON.stringify(entry), "utf8"),
|
|
873
|
+
...(path ? { path } : {}),
|
|
874
|
+
searchText: [
|
|
875
|
+
entry.turnId,
|
|
876
|
+
...entry.activeRunIds,
|
|
877
|
+
...entry.goals.flatMap((goal) => [goal.id, goal.title, goal.description ?? "", goal.parentGoalId ?? ""]),
|
|
878
|
+
...entry.subgoals.flatMap((goal) => [goal.id, goal.title, goal.description ?? "", goal.parentGoalId ?? ""]),
|
|
879
|
+
...entry.requiredValidationEvidence.flatMap((item) => [
|
|
880
|
+
item.id,
|
|
881
|
+
item.description,
|
|
882
|
+
item.command ?? "",
|
|
883
|
+
item.artifactPath ?? "",
|
|
884
|
+
item.notes ?? "",
|
|
885
|
+
]),
|
|
886
|
+
].filter(isNonEmptyString),
|
|
887
|
+
load: async () => ({
|
|
888
|
+
format: "markdown" as const,
|
|
889
|
+
lines: renderTaskLedgerMarkdown(entry),
|
|
890
|
+
}),
|
|
891
|
+
}));
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
export class ToolOutputArtifactProvider implements ArtifactProvider {
|
|
896
|
+
readonly category = "tool-output" as const;
|
|
897
|
+
|
|
898
|
+
constructor(private readonly deps: ArtifactProviderDeps) {}
|
|
899
|
+
|
|
900
|
+
async list(): Promise<ViewArtifact[]> {
|
|
901
|
+
const entries = sessionEntries(this.deps);
|
|
902
|
+
const out: ViewArtifact[] = [];
|
|
903
|
+
const seen = new Set<string>();
|
|
904
|
+
for (const entry of entries) {
|
|
905
|
+
if (entry.kind === "bashExecution" && entry.fullOutputPath) {
|
|
906
|
+
const artifact = this.bashArtifact(entry);
|
|
907
|
+
if (!seen.has(artifact.path ?? artifact.id)) {
|
|
908
|
+
seen.add(artifact.path ?? artifact.id);
|
|
909
|
+
out.push(artifact);
|
|
910
|
+
}
|
|
911
|
+
continue;
|
|
912
|
+
}
|
|
913
|
+
if (entry.kind !== "message" || entry.role !== "tool_result") continue;
|
|
914
|
+
const path = pathFromToolResult(entry);
|
|
915
|
+
if (!path || seen.has(path)) continue;
|
|
916
|
+
seen.add(path);
|
|
917
|
+
out.push(this.toolResultArtifact(entry, path));
|
|
918
|
+
}
|
|
919
|
+
return out;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
private bashArtifact(entry: BashExecutionEntry): ViewArtifact {
|
|
923
|
+
const path = resolve(entry.fullOutputPath ?? "");
|
|
924
|
+
return {
|
|
925
|
+
id: `bash:${entry.turnId}`,
|
|
926
|
+
category: this.category,
|
|
927
|
+
title: safeTitle(`Bash · ${entry.command}`, "Bash output"),
|
|
928
|
+
timestamp: parseTime(entry.timestamp),
|
|
929
|
+
sizeBytes: maybeSizeBytes(path),
|
|
930
|
+
path,
|
|
931
|
+
toolName: "bash",
|
|
932
|
+
searchText: ["bash", entry.turnId, entry.command, path, basename(path)],
|
|
933
|
+
load: () => loadTextPath(path),
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
private toolResultArtifact(entry: MessageEntry, path: string): ViewArtifact {
|
|
938
|
+
const toolName = toolNameFor(entry);
|
|
939
|
+
const artifact: ViewArtifact = {
|
|
940
|
+
id: `tool:${entry.turnId}`,
|
|
941
|
+
category: this.category,
|
|
942
|
+
title: safeTitle(`${toolName} · ${basename(path)}`, `${toolName} output`),
|
|
943
|
+
timestamp: parseTime(entry.timestamp),
|
|
944
|
+
sizeBytes: maybeSizeBytes(path),
|
|
945
|
+
path,
|
|
946
|
+
toolName,
|
|
947
|
+
searchText: [toolName, entry.turnId, path, basename(path)],
|
|
948
|
+
load: () => loadTextPath(path),
|
|
949
|
+
};
|
|
950
|
+
const payload = messagePayload(entry);
|
|
951
|
+
const details = payload ? resultDetails(payload.result) : null;
|
|
952
|
+
const runId = readStringField(payload ?? {}, "runId") ?? readStringField(details ?? {}, "runId");
|
|
953
|
+
if (runId !== null) artifact.runId = runId;
|
|
954
|
+
return artifact;
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
function protectedArtifactTitle(entry: ProtectedArtifactEntry): string {
|
|
959
|
+
const name = basename(entry.artifact.path) || entry.artifact.path || entry.turnId;
|
|
960
|
+
return safeTitle(`Protected · ${name}`, "Protected artifact");
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
function renderProtectedArtifactMarkdown(entry: ProtectedArtifactEntry): string[] {
|
|
964
|
+
return [
|
|
965
|
+
"# Protected Artifact",
|
|
966
|
+
"",
|
|
967
|
+
`- turn id: ${entry.turnId}`,
|
|
968
|
+
`- action: ${entry.action}`,
|
|
969
|
+
`- path: ${entry.artifact.path}`,
|
|
970
|
+
`- source: ${entry.artifact.source}`,
|
|
971
|
+
`- protectedAt: ${entry.artifact.protectedAt}`,
|
|
972
|
+
`- reason: ${entry.artifact.reason}`,
|
|
973
|
+
`- validation command: ${entry.artifact.validationCommand ?? "none"}`,
|
|
974
|
+
`- validation exit code: ${entry.artifact.validationExitCode ?? "none"}`,
|
|
975
|
+
`- tool name: ${entry.toolName ?? "none"}`,
|
|
976
|
+
`- tool call id: ${entry.toolCallId ?? "none"}`,
|
|
977
|
+
`- run id: ${entry.runId ?? "none"}`,
|
|
978
|
+
`- correlation id: ${entry.correlationId ?? "none"}`,
|
|
979
|
+
];
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
export class ProtectedArtifactProvider implements ArtifactProvider {
|
|
983
|
+
readonly category = "protected-artifact" as const;
|
|
984
|
+
|
|
985
|
+
constructor(private readonly deps: ArtifactProviderDeps) {}
|
|
986
|
+
|
|
987
|
+
async list(): Promise<ViewArtifact[]> {
|
|
988
|
+
const entries = sessionEntries(this.deps);
|
|
989
|
+
return entries
|
|
990
|
+
.filter((entry): entry is ProtectedArtifactEntry => entry.kind === "protectedArtifact")
|
|
991
|
+
.map((entry) => {
|
|
992
|
+
const path = protectedArtifactPath(entry.artifact.path);
|
|
993
|
+
const artifact: ViewArtifact = {
|
|
994
|
+
id: `protected:${entry.turnId}`,
|
|
995
|
+
category: this.category,
|
|
996
|
+
title: protectedArtifactTitle(entry),
|
|
997
|
+
timestamp: parseTime(entry.timestamp),
|
|
998
|
+
sizeBytes: path ? maybeSizeBytes(path) : Buffer.byteLength(JSON.stringify(entry), "utf8"),
|
|
999
|
+
description: entry.artifact.reason,
|
|
1000
|
+
...(entry.runId ? { runId: entry.runId } : {}),
|
|
1001
|
+
...(entry.correlationId ? { correlationId: entry.correlationId } : {}),
|
|
1002
|
+
...(entry.toolName ? { toolName: entry.toolName } : {}),
|
|
1003
|
+
searchText: [
|
|
1004
|
+
entry.turnId,
|
|
1005
|
+
entry.parentTurnId ?? "",
|
|
1006
|
+
entry.artifact.path,
|
|
1007
|
+
entry.artifact.source,
|
|
1008
|
+
entry.artifact.reason,
|
|
1009
|
+
entry.artifact.validationCommand ?? "",
|
|
1010
|
+
entry.toolName ?? "",
|
|
1011
|
+
entry.toolCallId ?? "",
|
|
1012
|
+
entry.runId ?? "",
|
|
1013
|
+
entry.correlationId ?? "",
|
|
1014
|
+
].filter(isNonEmptyString),
|
|
1015
|
+
load: async () => ({
|
|
1016
|
+
format: "markdown" as const,
|
|
1017
|
+
lines: renderProtectedArtifactMarkdown(entry),
|
|
1018
|
+
}),
|
|
1019
|
+
};
|
|
1020
|
+
if (path !== undefined) artifact.path = path;
|
|
1021
|
+
return artifact;
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
export class CompactionArtifactProvider implements ArtifactProvider {
|
|
1027
|
+
readonly category = "compaction" as const;
|
|
1028
|
+
|
|
1029
|
+
constructor(private readonly deps: ArtifactProviderDeps) {}
|
|
1030
|
+
|
|
1031
|
+
async list(): Promise<ViewArtifact[]> {
|
|
1032
|
+
const entries = sessionEntries(this.deps);
|
|
1033
|
+
const path = sessionCurrentPath(this.deps.stateDir, this.deps.sessionMeta);
|
|
1034
|
+
return entries
|
|
1035
|
+
.filter((entry) => entry.kind === "compactionSummary")
|
|
1036
|
+
.map((entry) => ({
|
|
1037
|
+
id: `compaction:${entry.turnId}`,
|
|
1038
|
+
category: this.category,
|
|
1039
|
+
title: safeTitle(`Compaction · ${entry.trigger ?? "summary"}`, "Compaction summary"),
|
|
1040
|
+
timestamp: parseTime(entry.timestamp),
|
|
1041
|
+
sizeBytes: Buffer.byteLength(entry.summary, "utf8"),
|
|
1042
|
+
...(path ? { path } : {}),
|
|
1043
|
+
load: async () => ({
|
|
1044
|
+
format: "markdown" as const,
|
|
1045
|
+
lines: [
|
|
1046
|
+
"# Compaction Summary",
|
|
1047
|
+
"",
|
|
1048
|
+
`- trigger: ${entry.trigger ?? "unknown"}`,
|
|
1049
|
+
`- tokens before: ${formatFooterTokens(entry.tokensBefore)}`,
|
|
1050
|
+
...(entry.tokensAfter !== undefined ? [`- tokens after: ${formatFooterTokens(entry.tokensAfter)}`] : []),
|
|
1051
|
+
...(entry.messagesSummarized !== undefined ? [`- messages summarized: ${entry.messagesSummarized}`] : []),
|
|
1052
|
+
`- continues at turn: ${entry.firstKeptTurnId}`,
|
|
1053
|
+
"",
|
|
1054
|
+
entry.summary,
|
|
1055
|
+
],
|
|
1056
|
+
}),
|
|
1057
|
+
}));
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
function promptManifestSearchText(record: SessionPromptCompileRecord): string[] {
|
|
1062
|
+
return [
|
|
1063
|
+
record.systemPromptHash,
|
|
1064
|
+
record.previousHash ?? "",
|
|
1065
|
+
record.thinkingLevel ?? "",
|
|
1066
|
+
record.projectPreload?.mode ?? "",
|
|
1067
|
+
record.projectPreload?.reason ?? "",
|
|
1068
|
+
record.projectPreload?.label ?? "",
|
|
1069
|
+
...record.sections.map((section) => section.id),
|
|
1070
|
+
...record.fragments.flatMap((fragment) => [fragment.id, fragment.relPath, fragment.contentHash]),
|
|
1071
|
+
].filter(isNonEmptyString);
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
export class PromptManifestArtifactProvider implements ArtifactProvider {
|
|
1075
|
+
readonly category = "prompt-manifest" as const;
|
|
1076
|
+
|
|
1077
|
+
constructor(private readonly deps: ArtifactProviderDeps) {}
|
|
1078
|
+
|
|
1079
|
+
async list(): Promise<ViewArtifact[]> {
|
|
1080
|
+
const meta = this.deps.sessionMeta;
|
|
1081
|
+
if (!meta) return [];
|
|
1082
|
+
const path = getPromptManifestFilePath(meta, this.deps.stateDir);
|
|
1083
|
+
const read = readPromptCompileManifest(meta, this.deps.stateDir);
|
|
1084
|
+
const artifacts = read.records.map(
|
|
1085
|
+
(record, index): ViewArtifact => ({
|
|
1086
|
+
id: `prompt-manifest:${index + 1}:${shortValue(record.systemPromptHash)}`,
|
|
1087
|
+
category: this.category,
|
|
1088
|
+
title: `Prompt compile · ${shortValue(record.systemPromptHash)} · ${formatFooterTokens(record.tokenEstimate)}`,
|
|
1089
|
+
timestamp: parseTime(record.at),
|
|
1090
|
+
sizeBytes: Buffer.byteLength(JSON.stringify(record), "utf8"),
|
|
1091
|
+
path,
|
|
1092
|
+
sessionId: meta.id,
|
|
1093
|
+
description: `thinking ${record.thinkingLevel ?? "off"} · ${record.sections.length} sections · ${record.fragments.length} fragments`,
|
|
1094
|
+
searchText: promptManifestSearchText(record),
|
|
1095
|
+
load: async () => ({
|
|
1096
|
+
format: "json" as const,
|
|
1097
|
+
lines: splitLinesCapped(JSON.stringify(record, null, 2), path),
|
|
1098
|
+
}),
|
|
1099
|
+
}),
|
|
1100
|
+
);
|
|
1101
|
+
if (read.errors.length === 0) return artifacts;
|
|
1102
|
+
return [
|
|
1103
|
+
...artifacts,
|
|
1104
|
+
{
|
|
1105
|
+
id: "prompt-manifest:read-errors",
|
|
1106
|
+
category: this.category,
|
|
1107
|
+
title: `Prompt manifest · ${read.errors.length} read error${read.errors.length === 1 ? "" : "s"}`,
|
|
1108
|
+
timestamp: Date.now(),
|
|
1109
|
+
path,
|
|
1110
|
+
sessionId: meta.id,
|
|
1111
|
+
load: async () => ({
|
|
1112
|
+
format: "markdown" as const,
|
|
1113
|
+
lines: [
|
|
1114
|
+
"# Prompt Manifest Read Errors",
|
|
1115
|
+
"",
|
|
1116
|
+
...read.errors.map((error) =>
|
|
1117
|
+
error.line === null ? `- ${error.message}` : `- line ${error.line}: ${error.message}`,
|
|
1118
|
+
),
|
|
1119
|
+
],
|
|
1120
|
+
}),
|
|
1121
|
+
},
|
|
1122
|
+
];
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
function renderAccountabilitySummary(summary: AccountabilitySummary): string[] {
|
|
1127
|
+
const pct = Math.round(summary.firstPassRate * 100);
|
|
1128
|
+
const lines = [
|
|
1129
|
+
"# Accountability",
|
|
1130
|
+
"",
|
|
1131
|
+
`first-pass success: ${summary.firstPassRuns}/${summary.totalRuns} (${pct}%)`,
|
|
1132
|
+
"",
|
|
1133
|
+
"## Top failure causes",
|
|
1134
|
+
"",
|
|
1135
|
+
];
|
|
1136
|
+
if (summary.failureCauses.length === 0) {
|
|
1137
|
+
lines.push("none");
|
|
1138
|
+
return lines;
|
|
1139
|
+
}
|
|
1140
|
+
for (const { tag, count } of summary.failureCauses.slice(0, ACCOUNTABILITY_TOP_CAUSES)) {
|
|
1141
|
+
lines.push(`- ${tag}: ${count}`);
|
|
1142
|
+
}
|
|
1143
|
+
return lines;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
export class AccountabilityArtifactProvider implements ArtifactProvider {
|
|
1147
|
+
readonly category = "accountability" as const;
|
|
1148
|
+
|
|
1149
|
+
constructor(private readonly deps: ArtifactProviderDeps) {}
|
|
1150
|
+
|
|
1151
|
+
async list(): Promise<ViewArtifact[]> {
|
|
1152
|
+
const stateDir = this.deps.stateDir;
|
|
1153
|
+
return [
|
|
1154
|
+
{
|
|
1155
|
+
id: "session",
|
|
1156
|
+
category: this.category,
|
|
1157
|
+
title: "Session accountability",
|
|
1158
|
+
timestamp: Date.now(),
|
|
1159
|
+
load: async () => ({
|
|
1160
|
+
format: "markdown" as const,
|
|
1161
|
+
lines: renderAccountabilitySummary(readAccountabilitySummary(stateDir)),
|
|
1162
|
+
}),
|
|
1163
|
+
},
|
|
1164
|
+
];
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
const SAFETY_AUDIT_ARTIFACT_LIMIT = 200;
|
|
1169
|
+
|
|
1170
|
+
function compareAuditRowsNewestFirst(left: AuditJsonRow, right: AuditJsonRow): number {
|
|
1171
|
+
const time = parseTime(right.ts) - parseTime(left.ts);
|
|
1172
|
+
if (time !== 0) return time;
|
|
1173
|
+
const file = right.file.localeCompare(left.file);
|
|
1174
|
+
if (file !== 0) return file;
|
|
1175
|
+
return right.line - left.line;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
function currentSessionAuditRows(
|
|
1179
|
+
rows: ReadonlyArray<AuditJsonRow>,
|
|
1180
|
+
sessionId: string | null | undefined,
|
|
1181
|
+
): ReadonlyArray<AuditJsonRow> {
|
|
1182
|
+
if (!sessionId) return rows;
|
|
1183
|
+
const matching = rows.filter((row) => readStringField(row.row, "sessionId") === sessionId);
|
|
1184
|
+
return matching.length > 0 ? matching : rows;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
function auditRowSubject(row: AuditJsonRow): string {
|
|
1188
|
+
const subjectParts: string[] = [];
|
|
1189
|
+
const tool = readStringField(row.row, "tool");
|
|
1190
|
+
if (tool !== null) subjectParts.push(tool);
|
|
1191
|
+
const actionClass = readStringField(row.row, "actionClass");
|
|
1192
|
+
if (actionClass !== null) subjectParts.push(actionClass);
|
|
1193
|
+
const decision =
|
|
1194
|
+
readStringField(row.row, "decision") ??
|
|
1195
|
+
readStringField(row.row, "status") ??
|
|
1196
|
+
readStringField(row.row, "source") ??
|
|
1197
|
+
readStringField(row.row, "phase");
|
|
1198
|
+
if (decision !== null) subjectParts.push(decision);
|
|
1199
|
+
const runId = readStringField(row.row, "runId");
|
|
1200
|
+
const sessionId = readStringField(row.row, "sessionId");
|
|
1201
|
+
const correlationId = readStringField(row.row, "correlationId") ?? row.correlationId;
|
|
1202
|
+
if (runId !== null) {
|
|
1203
|
+
subjectParts.push(`run ${shortValue(runId)}`);
|
|
1204
|
+
} else if (sessionId !== null) {
|
|
1205
|
+
subjectParts.push(`session ${shortValue(sessionId)}`);
|
|
1206
|
+
} else if (correlationId.length > 0) {
|
|
1207
|
+
subjectParts.push(`corr ${shortValue(correlationId)}`);
|
|
1208
|
+
}
|
|
1209
|
+
return subjectParts.join(" · ");
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
function auditRowTitle(row: AuditJsonRow): string {
|
|
1213
|
+
const subject = auditRowSubject(row);
|
|
1214
|
+
return safeTitle(`Audit · ${row.auditKind}${subject ? ` · ${subject}` : ""}`, "Audit row");
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
function auditRowPayload(row: AuditJsonRow): Record<string, unknown> {
|
|
1218
|
+
return {
|
|
1219
|
+
file: row.file,
|
|
1220
|
+
line: row.line,
|
|
1221
|
+
auditKind: row.auditKind,
|
|
1222
|
+
correlationId: row.correlationId,
|
|
1223
|
+
row: row.row,
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
function auditReadErrorsArtifact(stateDir: string, errors: ReadonlyArray<string>): ViewArtifact | null {
|
|
1228
|
+
if (errors.length === 0) return null;
|
|
1229
|
+
const path = join(stateDir, "audit");
|
|
1230
|
+
return {
|
|
1231
|
+
id: "audit:read-errors",
|
|
1232
|
+
category: "audit",
|
|
1233
|
+
title: `Audit · ${errors.length} read error${errors.length === 1 ? "" : "s"}`,
|
|
1234
|
+
timestamp: Date.now(),
|
|
1235
|
+
path,
|
|
1236
|
+
load: async () => ({
|
|
1237
|
+
format: "markdown" as const,
|
|
1238
|
+
lines: ["# Audit Read Errors", "", ...errors.map((error) => `- ${error}`)],
|
|
1239
|
+
}),
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
export class SafetyAuditArtifactProvider implements ArtifactProvider {
|
|
1244
|
+
readonly category = "audit" as const;
|
|
1245
|
+
|
|
1246
|
+
constructor(private readonly deps: ArtifactProviderDeps) {}
|
|
1247
|
+
|
|
1248
|
+
async list(): Promise<ViewArtifact[]> {
|
|
1249
|
+
let read: AuditReadResult;
|
|
1250
|
+
try {
|
|
1251
|
+
read = await readAuditRows(this.deps.stateDir);
|
|
1252
|
+
} catch {
|
|
1253
|
+
return [];
|
|
1254
|
+
}
|
|
1255
|
+
const selected = [...currentSessionAuditRows(read.rows, this.deps.sessionMeta?.id)]
|
|
1256
|
+
.sort(compareAuditRowsNewestFirst)
|
|
1257
|
+
.slice(0, SAFETY_AUDIT_ARTIFACT_LIMIT);
|
|
1258
|
+
const artifacts: ViewArtifact[] = selected.map((row) => {
|
|
1259
|
+
const path = join(this.deps.stateDir, "audit", row.file);
|
|
1260
|
+
const runId = readStringField(row.row, "runId");
|
|
1261
|
+
const sessionId = readStringField(row.row, "sessionId");
|
|
1262
|
+
const correlationId = readStringField(row.row, "correlationId") ?? row.correlationId;
|
|
1263
|
+
const tool = readStringField(row.row, "tool");
|
|
1264
|
+
const actionClass = readStringField(row.row, "actionClass");
|
|
1265
|
+
const decision = readStringField(row.row, "decision");
|
|
1266
|
+
const status = readStringField(row.row, "status");
|
|
1267
|
+
const source = readStringField(row.row, "source");
|
|
1268
|
+
const phase = readStringField(row.row, "phase");
|
|
1269
|
+
return {
|
|
1270
|
+
id: `audit:${row.file}:${row.line}`,
|
|
1271
|
+
category: this.category,
|
|
1272
|
+
title: auditRowTitle(row),
|
|
1273
|
+
timestamp: parseTime(row.ts),
|
|
1274
|
+
sizeBytes: maybeSizeBytes(path),
|
|
1275
|
+
path,
|
|
1276
|
+
...(runId ? { runId } : {}),
|
|
1277
|
+
...(sessionId ? { sessionId } : {}),
|
|
1278
|
+
...(correlationId ? { correlationId } : {}),
|
|
1279
|
+
...(tool ? { toolName: tool } : {}),
|
|
1280
|
+
searchText: [
|
|
1281
|
+
row.file,
|
|
1282
|
+
String(row.line),
|
|
1283
|
+
row.auditKind,
|
|
1284
|
+
row.correlationId,
|
|
1285
|
+
runId ?? "",
|
|
1286
|
+
sessionId ?? "",
|
|
1287
|
+
correlationId,
|
|
1288
|
+
tool ?? "",
|
|
1289
|
+
actionClass ?? "",
|
|
1290
|
+
decision ?? "",
|
|
1291
|
+
status ?? "",
|
|
1292
|
+
source ?? "",
|
|
1293
|
+
phase ?? "",
|
|
1294
|
+
].filter(isNonEmptyString),
|
|
1295
|
+
load: async () => ({
|
|
1296
|
+
format: "json" as const,
|
|
1297
|
+
lines: splitLinesCapped(JSON.stringify(auditRowPayload(row), null, 2), path),
|
|
1298
|
+
}),
|
|
1299
|
+
};
|
|
1300
|
+
});
|
|
1301
|
+
const errors = auditReadErrorsArtifact(this.deps.stateDir, read.errors);
|
|
1302
|
+
return errors ? [...artifacts, errors] : artifacts;
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1306
|
+
export function createDefaultArtifactProviders(deps: ArtifactProviderDeps): ArtifactProvider[] {
|
|
1307
|
+
return [
|
|
1308
|
+
new AccountabilityArtifactProvider(deps),
|
|
1309
|
+
new EvidenceArtifactProvider(deps),
|
|
1310
|
+
new ReceiptArtifactProvider(deps),
|
|
1311
|
+
new DispatchArtifactProvider(deps),
|
|
1312
|
+
new TaskLedgerArtifactProvider(deps),
|
|
1313
|
+
new ToolOutputArtifactProvider(deps),
|
|
1314
|
+
new ProtectedArtifactProvider(deps),
|
|
1315
|
+
new CompactionArtifactProvider(deps),
|
|
1316
|
+
new PromptManifestArtifactProvider(deps),
|
|
1317
|
+
new SafetyAuditArtifactProvider(deps),
|
|
1318
|
+
];
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
export function sortViewArtifacts(artifacts: ReadonlyArray<ViewArtifact>): ViewArtifact[] {
|
|
1322
|
+
return [...artifacts].sort((a, b) => {
|
|
1323
|
+
const time = b.timestamp - a.timestamp;
|
|
1324
|
+
if (time !== 0) return time;
|
|
1325
|
+
const category = VIEW_ARTIFACT_CATEGORIES.indexOf(a.category) - VIEW_ARTIFACT_CATEGORIES.indexOf(b.category);
|
|
1326
|
+
if (category !== 0) return category;
|
|
1327
|
+
return a.id.localeCompare(b.id);
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
export async function listViewArtifacts(providers: ReadonlyArray<ArtifactProvider>): Promise<ViewArtifact[]> {
|
|
1332
|
+
const groups = await Promise.all(
|
|
1333
|
+
providers.map(async (provider) => {
|
|
1334
|
+
try {
|
|
1335
|
+
return await provider.list();
|
|
1336
|
+
} catch {
|
|
1337
|
+
return [];
|
|
1338
|
+
}
|
|
1339
|
+
}),
|
|
1340
|
+
);
|
|
1341
|
+
return sortViewArtifacts(groups.flat());
|
|
1342
|
+
}
|