@iowarp/clio-coder 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/CHANGELOG.md +407 -0
  2. package/CODE_OF_CONDUCT.md +21 -0
  3. package/CONTRIBUTING.md +224 -0
  4. package/LICENSE +202 -0
  5. package/NOTICE +9 -0
  6. package/README.md +798 -0
  7. package/SECURITY.md +72 -0
  8. package/assets/clio-coder-logo-128.webp +0 -0
  9. package/damage-control-rules.yaml +419 -0
  10. package/dist/acp-UMLFVA3F.js +92 -0
  11. package/dist/agents-Q4MYPMUW.js +91 -0
  12. package/dist/auth-O6HYIJ6J.js +521 -0
  13. package/dist/chunk-262G75JS.js +35 -0
  14. package/dist/chunk-26BZQOAD.js +1281 -0
  15. package/dist/chunk-2J63S4SF.js +508 -0
  16. package/dist/chunk-3DANZDGR.js +717 -0
  17. package/dist/chunk-4UQA7NCT.js +29 -0
  18. package/dist/chunk-527KG6XR.js +497 -0
  19. package/dist/chunk-5LDRNKX2.js +1063 -0
  20. package/dist/chunk-5N2FG33Q.js +25 -0
  21. package/dist/chunk-67MTHP2E.js +135 -0
  22. package/dist/chunk-6CWDTGUC.js +20 -0
  23. package/dist/chunk-7BHLZB3A.js +2115 -0
  24. package/dist/chunk-7RBKDI66.js +348 -0
  25. package/dist/chunk-AMFR5YA3.js +541 -0
  26. package/dist/chunk-BBUH4VAA.js +1224 -0
  27. package/dist/chunk-BYEU76JP.js +899 -0
  28. package/dist/chunk-CLJ5HLUD.js +458 -0
  29. package/dist/chunk-D5YD55AR.js +116 -0
  30. package/dist/chunk-DXQNI4PC.js +61 -0
  31. package/dist/chunk-E3NYWENM.js +1004 -0
  32. package/dist/chunk-GNGDQYDU.js +34688 -0
  33. package/dist/chunk-GOTUR54M.js +9 -0
  34. package/dist/chunk-HBU5MTAM.js +41 -0
  35. package/dist/chunk-HMYNFFY4.js +28 -0
  36. package/dist/chunk-JPOWPFCU.js +1010 -0
  37. package/dist/chunk-JWHCJDCI.js +1215 -0
  38. package/dist/chunk-KBR4MZZR.js +41 -0
  39. package/dist/chunk-KKKPTZLM.js +93 -0
  40. package/dist/chunk-ME6DNWIU.js +66 -0
  41. package/dist/chunk-NI4DEJMC.js +88 -0
  42. package/dist/chunk-O4EJEDHO.js +659 -0
  43. package/dist/chunk-PIDUD6M2.js +31 -0
  44. package/dist/chunk-PS4PFJQP.js +29459 -0
  45. package/dist/chunk-QV47YRF4.js +48 -0
  46. package/dist/chunk-RQDWMVRB.js +279 -0
  47. package/dist/chunk-TFSSEXL6.js +136 -0
  48. package/dist/chunk-TKHQ4DGZ.js +8290 -0
  49. package/dist/chunk-TPOCL34A.js +2876 -0
  50. package/dist/chunk-UGYAX5YI.js +565 -0
  51. package/dist/chunk-UHTSULZS.js +461 -0
  52. package/dist/chunk-UU3R62TT.js +128 -0
  53. package/dist/chunk-UWIJNAOB.js +3906 -0
  54. package/dist/chunk-VOO7NYPP.js +914 -0
  55. package/dist/chunk-VPAWTYLY.js +117 -0
  56. package/dist/chunk-WD6AJM35.js +1216 -0
  57. package/dist/chunk-X3BR7HWV.js +115 -0
  58. package/dist/chunk-X3NE4WVW.js +120 -0
  59. package/dist/chunk-XNISANGE.js +1395 -0
  60. package/dist/chunk-XV4ZJ6ZM.js +3177 -0
  61. package/dist/cli/index.js +236 -0
  62. package/dist/clio-KIQ5SNDS.js +53 -0
  63. package/dist/components-JVHMUBEB.js +653 -0
  64. package/dist/config-ZFCDBMDC.js +372 -0
  65. package/dist/configure-G4E3A2PG.js +27 -0
  66. package/dist/context-CDXTP2MP.js +293 -0
  67. package/dist/context-E3KIFVXI.js +185 -0
  68. package/dist/context-clear-3F4PLXOS.js +102 -0
  69. package/dist/context-index-Q7YSYTR3.js +106 -0
  70. package/dist/docs-YIETIWZI.js +280 -0
  71. package/dist/doctor-M5HJJZOL.js +61 -0
  72. package/dist/domains/agents/builtins/architect.md +33 -0
  73. package/dist/domains/agents/builtins/coder.md +31 -0
  74. package/dist/domains/agents/builtins/context-bootstrap.md +38 -0
  75. package/dist/domains/agents/builtins/debugger.md +30 -0
  76. package/dist/domains/agents/builtins/documenter.md +31 -0
  77. package/dist/domains/agents/builtins/git-master.md +30 -0
  78. package/dist/domains/agents/builtins/provenance.md +30 -0
  79. package/dist/domains/agents/builtins/researcher.md +71 -0
  80. package/dist/domains/agents/builtins/scout.md +42 -0
  81. package/dist/domains/agents/builtins/tester.md +31 -0
  82. package/dist/domains/agents/builtins/verifier.md +30 -0
  83. package/dist/domains/agents/builtins/wiki-writer.md +41 -0
  84. package/dist/eval-B3KZZESM.js +2674 -0
  85. package/dist/evidence-V67CHM35.js +233 -0
  86. package/dist/evolve-YDZSUQYA.js +518 -0
  87. package/dist/extensions-SRG7XCAH.js +207 -0
  88. package/dist/fleet-CA2CRTVG.js +760 -0
  89. package/dist/fleet-preflight-CLIAX7YR.js +21 -0
  90. package/dist/init-2OZDJE2D.js +227 -0
  91. package/dist/memory-3PIQQAKX.js +207 -0
  92. package/dist/models-DY35XI7Y.js +237 -0
  93. package/dist/paths-5OMXW7Z4.js +57 -0
  94. package/dist/preload-KZVHET2B.js +11 -0
  95. package/dist/reset-PIFYNOS3.js +216 -0
  96. package/dist/run-3VSPP24F.js +735 -0
  97. package/dist/share-D36RQCXM.js +241 -0
  98. package/dist/skills-F2MRLELY.js +445 -0
  99. package/dist/skills-eval-E2ZTW4PL.js +932 -0
  100. package/dist/targets-DZMEZAH4.js +977 -0
  101. package/dist/trace-7NYCUI2J.js +250 -0
  102. package/dist/uninstall-AD3JWHBB.js +322 -0
  103. package/dist/upgrade-WYYBKGDY.js +301 -0
  104. package/dist/usage-ULIDAGFF.js +755 -0
  105. package/dist/version-ROZ6CZKH.js +16 -0
  106. package/dist/wiki-generate-PKFIX6OB.js +377 -0
  107. package/dist/worker/entry.js +1739 -0
  108. package/docs/README.md +93 -0
  109. package/docs/acp.md +120 -0
  110. package/docs/alcf-provider.md +72 -0
  111. package/docs/architecture.md +172 -0
  112. package/docs/artifact-versions.md +54 -0
  113. package/docs/built-in-agents.md +265 -0
  114. package/docs/capacity-and-scheduling.md +97 -0
  115. package/docs/commands-and-modes.md +554 -0
  116. package/docs/config-knobs-audit.md +115 -0
  117. package/docs/configuration-and-targets.md +812 -0
  118. package/docs/context-engine.md +236 -0
  119. package/docs/dispatch-architecture-rationale.md +126 -0
  120. package/docs/documentation-coverage.md +46 -0
  121. package/docs/documentation-guide.md +166 -0
  122. package/docs/environment-variables.md +105 -0
  123. package/docs/eval-runner.md +205 -0
  124. package/docs/evals-internal.md +298 -0
  125. package/docs/evidence-and-memory.md +243 -0
  126. package/docs/evolution.md +143 -0
  127. package/docs/exit-codes-and-output.md +74 -0
  128. package/docs/extensions-and-sharing.md +306 -0
  129. package/docs/fleet-demo-runbook.md +179 -0
  130. package/docs/fleet-dispatch.md +591 -0
  131. package/docs/glossary.md +75 -0
  132. package/docs/html/agents_blueprint.html +936 -0
  133. package/docs/html/alcf_blueprint.html +324 -0
  134. package/docs/html/architecture_blueprint.html +850 -0
  135. package/docs/html/commands_blueprint.html +794 -0
  136. package/docs/html/config_knobs_audit_blueprint.html +178 -0
  137. package/docs/html/configuration_blueprint.html +1080 -0
  138. package/docs/html/context_blueprint.html +603 -0
  139. package/docs/html/documentation_blueprint.html +832 -0
  140. package/docs/html/environment_blueprint.html +404 -0
  141. package/docs/html/eval_blueprint.html +743 -0
  142. package/docs/html/evals_internal_blueprint.html +190 -0
  143. package/docs/html/evolution_blueprint.html +674 -0
  144. package/docs/html/extensions_blueprint.html +2065 -0
  145. package/docs/html/fleet_dispatch_blueprint.html +286 -0
  146. package/docs/html/index.html +919 -0
  147. package/docs/html/lifecycle_blueprint.html +723 -0
  148. package/docs/html/memory_blueprint.html +699 -0
  149. package/docs/html/middleware_blueprint.html +664 -0
  150. package/docs/html/models_blueprint.html +2366 -0
  151. package/docs/html/observability_blueprint.html +683 -0
  152. package/docs/html/provider_adapter_blueprint.html +245 -0
  153. package/docs/html/safety_blueprint.html +1386 -0
  154. package/docs/html/shared.css +571 -0
  155. package/docs/html/shared.js +143 -0
  156. package/docs/html/skills_blueprint.html +671 -0
  157. package/docs/html/soak_blueprint.html +182 -0
  158. package/docs/html/tool_usage_blueprint.html +350 -0
  159. package/docs/html/tools_blueprint.html +2249 -0
  160. package/docs/html/trace_blueprint.html +235 -0
  161. package/docs/html/tui_design_blueprint.html +314 -0
  162. package/docs/html/validation_blueprint.html +961 -0
  163. package/docs/html/worker_dispatch_blueprint.html +231 -0
  164. package/docs/installation-and-lifecycle.md +308 -0
  165. package/docs/middleware-and-components.md +148 -0
  166. package/docs/model-catalog.md +189 -0
  167. package/docs/observability.md +233 -0
  168. package/docs/proactive-memory.md +452 -0
  169. package/docs/prompt-envelope-and-tools.md +142 -0
  170. package/docs/provider-adapter-cookbook.md +148 -0
  171. package/docs/release-cut-checklist.md +138 -0
  172. package/docs/safety-model.md +357 -0
  173. package/docs/scientific-validation.md +105 -0
  174. package/docs/session-lifecycle.md +156 -0
  175. package/docs/skills-marketplace.md +46 -0
  176. package/docs/tool-usage.md +527 -0
  177. package/docs/trace-store.md +132 -0
  178. package/docs/troubleshooting.md +33 -0
  179. package/docs/tui-design.md +239 -0
  180. package/docs/worker-dispatch-mechanics.md +242 -0
  181. package/package.json +132 -0
  182. package/skills/README.md +408 -0
  183. package/skills/git/commit-crafting/SKILL.md +79 -0
  184. package/skills/git/commit-crafting/evals.md +92 -0
  185. package/skills/git/create-pr/SKILL.md +116 -0
  186. package/skills/git/create-pr/evals.md +114 -0
  187. package/skills/git/investigate-issue/SKILL.md +139 -0
  188. package/skills/git/investigate-issue/evals.md +94 -0
  189. package/skills/git/resolve-merge-conflicts/SKILL.md +96 -0
  190. package/skills/git/resolve-merge-conflicts/evals.md +58 -0
  191. package/skills/git/review-changes/SKILL.md +103 -0
  192. package/skills/git/review-changes/evals.md +85 -0
  193. package/skills/git/worktree-create/SKILL.md +92 -0
  194. package/skills/git/worktree-create/evals.md +97 -0
  195. package/skills/git/worktree-create/references/worktree-setup.md +66 -0
  196. package/skills/git/worktree-merge/SKILL.md +95 -0
  197. package/skills/git/worktree-merge/evals.md +114 -0
  198. package/skills/skill-marketplace.json +261 -0
  199. package/skills/workflow/cut-it/SKILL.md +86 -0
  200. package/skills/workflow/cut-it/evals.md +42 -0
  201. package/src/domains/agents/builtins/architect.md +33 -0
  202. package/src/domains/agents/builtins/coder.md +31 -0
  203. package/src/domains/agents/builtins/context-bootstrap.md +38 -0
  204. package/src/domains/agents/builtins/debugger.md +30 -0
  205. package/src/domains/agents/builtins/documenter.md +31 -0
  206. package/src/domains/agents/builtins/git-master.md +30 -0
  207. package/src/domains/agents/builtins/provenance.md +30 -0
  208. package/src/domains/agents/builtins/researcher.md +71 -0
  209. package/src/domains/agents/builtins/scout.md +42 -0
  210. package/src/domains/agents/builtins/tester.md +31 -0
  211. package/src/domains/agents/builtins/verifier.md +30 -0
  212. package/src/domains/agents/builtins/wiki-writer.md +41 -0
  213. package/src/domains/agents/fleets/build-review.md +34 -0
  214. package/src/domains/agents/fleets/build-test.md +35 -0
  215. package/src/domains/agents/fleets/sdlc.md +86 -0
  216. package/src/domains/prompts/fragments/identity/clio-worker.md +11 -0
  217. package/src/domains/prompts/fragments/identity/clio.md +26 -0
  218. package/src/domains/prompts/fragments/operating/contract.md +64 -0
  219. package/src/domains/prompts/fragments/safety/auto-edit.md +14 -0
  220. package/src/domains/prompts/fragments/safety/full-auto.md +14 -0
  221. package/src/domains/prompts/fragments/safety/read-only.md +13 -0
  222. package/src/domains/prompts/fragments/safety/suggest.md +13 -0
  223. package/src/domains/prompts/fragments/wiki/page.md +75 -0
  224. package/src/domains/prompts/fragments/wiki/plan.md +48 -0
  225. package/src/domains/providers/models/cloud-models/alcf.yaml +40 -0
  226. package/src/domains/providers/models/local-models/clio-local-coding-targets.yaml +993 -0
@@ -0,0 +1,735 @@
1
+ import {
2
+ flushRawStdout,
3
+ projectDispatchJsonEvent,
4
+ readFileArgsAsync,
5
+ restoreStdout,
6
+ runClioCommand,
7
+ setupSteerChannel,
8
+ takeOverStdout
9
+ } from "./chunk-PS4PFJQP.js";
10
+ import "./chunk-AMFR5YA3.js";
11
+ import "./chunk-O4EJEDHO.js";
12
+ import "./chunk-4UQA7NCT.js";
13
+ import {
14
+ SchedulingDomainModule,
15
+ createPromptsDomainModule
16
+ } from "./chunk-3DANZDGR.js";
17
+ import {
18
+ AgentsDomainModule,
19
+ SafetyDomainModule
20
+ } from "./chunk-JPOWPFCU.js";
21
+ import {
22
+ LifecycleDomainModule
23
+ } from "./chunk-NI4DEJMC.js";
24
+ import {
25
+ ensureClioState
26
+ } from "./chunk-7RBKDI66.js";
27
+ import {
28
+ ConfigDomainModule,
29
+ loadDomains
30
+ } from "./chunk-527KG6XR.js";
31
+ import "./chunk-UU3R62TT.js";
32
+ import "./chunk-6CWDTGUC.js";
33
+ import "./chunk-BYEU76JP.js";
34
+ import "./chunk-HMYNFFY4.js";
35
+ import {
36
+ createContextDomainModule
37
+ } from "./chunk-UWIJNAOB.js";
38
+ import "./chunk-X3BR7HWV.js";
39
+ import {
40
+ buildMemoryPromptSection,
41
+ canonicalMemoryRepositoryIdentity,
42
+ loadMemoryRecordsSync
43
+ } from "./chunk-VOO7NYPP.js";
44
+ import {
45
+ MiddlewareDomainModule,
46
+ ObservabilityDomainModule,
47
+ SessionDomainModule,
48
+ assistantTextFromEvent,
49
+ createDispatchDomainModule,
50
+ isToolProfileName
51
+ } from "./chunk-GNGDQYDU.js";
52
+ import {
53
+ ResourcesDomainModule
54
+ } from "./chunk-2J63S4SF.js";
55
+ import "./chunk-RQDWMVRB.js";
56
+ import {
57
+ agentRoleFactsResolver,
58
+ requestExecutionRole
59
+ } from "./chunk-7BHLZB3A.js";
60
+ import "./chunk-TPOCL34A.js";
61
+ import "./chunk-E3NYWENM.js";
62
+ import {
63
+ AUTONOMY_LEVELS
64
+ } from "./chunk-XV4ZJ6ZM.js";
65
+ import {
66
+ loadSkills
67
+ } from "./chunk-26BZQOAD.js";
68
+ import "./chunk-WD6AJM35.js";
69
+ import "./chunk-QV47YRF4.js";
70
+ import "./chunk-CLJ5HLUD.js";
71
+ import "./chunk-BBUH4VAA.js";
72
+ import "./chunk-GOTUR54M.js";
73
+ import "./chunk-KBR4MZZR.js";
74
+ import "./chunk-XNISANGE.js";
75
+ import "./chunk-KKKPTZLM.js";
76
+ import "./chunk-ME6DNWIU.js";
77
+ import "./chunk-262G75JS.js";
78
+ import "./chunk-TFSSEXL6.js";
79
+ import "./chunk-PIDUD6M2.js";
80
+ import {
81
+ globalFlagPositionHint
82
+ } from "./chunk-67MTHP2E.js";
83
+ import {
84
+ ProvidersDomainModule,
85
+ withRunOverrides
86
+ } from "./chunk-TKHQ4DGZ.js";
87
+ import "./chunk-D5YD55AR.js";
88
+ import {
89
+ readSettings
90
+ } from "./chunk-JWHCJDCI.js";
91
+ import {
92
+ THINKING_LEVELS
93
+ } from "./chunk-UHTSULZS.js";
94
+ import "./chunk-5LDRNKX2.js";
95
+ import "./chunk-UGYAX5YI.js";
96
+ import "./chunk-5N2FG33Q.js";
97
+ import "./chunk-VPAWTYLY.js";
98
+ import {
99
+ clioDataDir
100
+ } from "./chunk-X3NE4WVW.js";
101
+ import "./chunk-DXQNI4PC.js";
102
+
103
+ // src/cli/args.ts
104
+ var VALID_THINKING = THINKING_LEVELS;
105
+ function parseRunCliArgs(argv) {
106
+ const parsed = {
107
+ help: false,
108
+ json: false,
109
+ jsonEvents: "full",
110
+ required: [],
111
+ noSkills: false,
112
+ continueSession: false,
113
+ skillPaths: [],
114
+ fileArgs: [],
115
+ messages: [],
116
+ diagnostics: []
117
+ };
118
+ for (let i = 0; i < argv.length; i += 1) {
119
+ const arg = argv[i];
120
+ const need = (flag) => {
121
+ const value = argv[i + 1];
122
+ if (value === void 0 || value.startsWith("-") && !isNumericLiteral(value)) {
123
+ parsed.diagnostics.push({ type: "error", message: `${flag} requires a value` });
124
+ return null;
125
+ }
126
+ i += 1;
127
+ return value;
128
+ };
129
+ if (arg === "--help" || arg === "-h") {
130
+ parsed.help = true;
131
+ continue;
132
+ }
133
+ if (arg === "--json") {
134
+ parsed.json = true;
135
+ continue;
136
+ }
137
+ if (arg === "--json-events") {
138
+ const value = need(arg);
139
+ if (value !== null) {
140
+ parsed.json = true;
141
+ if (value === "full" || value === "terminal") parsed.jsonEvents = value;
142
+ else parsed.diagnostics.push({ type: "error", message: "--json-events must be one of: full|terminal" });
143
+ }
144
+ continue;
145
+ }
146
+ if (arg === "--target") {
147
+ const value = need(arg);
148
+ if (value !== null) parsed.target = value;
149
+ continue;
150
+ }
151
+ if (arg === "--model") {
152
+ const value = need(arg);
153
+ if (value !== null) parsed.model = value;
154
+ continue;
155
+ }
156
+ if (arg === "--thinking") {
157
+ const value = need(arg);
158
+ if (value !== null) {
159
+ if (VALID_THINKING.includes(value)) parsed.thinking = value;
160
+ else
161
+ parsed.diagnostics.push({
162
+ type: "error",
163
+ message: "--thinking must be one of: off|minimal|low|medium|high|xhigh|max"
164
+ });
165
+ }
166
+ continue;
167
+ }
168
+ if (arg === "--autonomy") {
169
+ const value = need(arg);
170
+ if (value !== null) {
171
+ if (AUTONOMY_LEVELS.includes(value)) parsed.autonomy = value;
172
+ else
173
+ parsed.diagnostics.push({
174
+ type: "error",
175
+ message: "--autonomy must be one of: read-only|suggest|auto-edit|full-auto"
176
+ });
177
+ }
178
+ continue;
179
+ }
180
+ if (arg === "--temperature") {
181
+ const value = need(arg);
182
+ if (value !== null) setNumberOption(parsed, "temperature", value, { min: 0 });
183
+ continue;
184
+ }
185
+ if (arg === "--top-p") {
186
+ const value = need(arg);
187
+ if (value !== null) setNumberOption(parsed, "topP", value, { min: 0, max: 1 });
188
+ continue;
189
+ }
190
+ if (arg === "--top-k") {
191
+ const value = need(arg);
192
+ if (value !== null) setNumberOption(parsed, "topK", value, { min: 0, integer: true });
193
+ continue;
194
+ }
195
+ if (arg === "--min-p") {
196
+ const value = need(arg);
197
+ if (value !== null) setNumberOption(parsed, "minP", value, { min: 0, max: 1 });
198
+ continue;
199
+ }
200
+ if (arg === "--presence-penalty") {
201
+ const value = need(arg);
202
+ if (value !== null) setNumberOption(parsed, "presencePenalty", value);
203
+ continue;
204
+ }
205
+ if (arg === "--frequency-penalty") {
206
+ const value = need(arg);
207
+ if (value !== null) setNumberOption(parsed, "frequencyPenalty", value);
208
+ continue;
209
+ }
210
+ if (arg === "--repeat-penalty") {
211
+ const value = need(arg);
212
+ if (value !== null) setNumberOption(parsed, "repeatPenalty", value);
213
+ continue;
214
+ }
215
+ if (arg === "--agent") {
216
+ const value = need(arg);
217
+ if (value !== null) parsed.agentId = value;
218
+ continue;
219
+ }
220
+ if (arg === "--agent-profile" || arg === "--worker-profile" || arg === "--worker") {
221
+ const value = need(arg);
222
+ if (value !== null) parsed.agentProfile = value;
223
+ continue;
224
+ }
225
+ if (arg === "--agent-runtime" || arg === "--worker-runtime" || arg === "--runtime") {
226
+ const value = need(arg);
227
+ if (value !== null) parsed.agentRuntime = value;
228
+ continue;
229
+ }
230
+ if (arg === "--tool-profile") {
231
+ const value = need(arg);
232
+ if (value !== null) parsed.toolProfile = value;
233
+ continue;
234
+ }
235
+ if (arg === "--require") {
236
+ const value = need(arg);
237
+ if (value !== null) parsed.required.push(value);
238
+ continue;
239
+ }
240
+ if (arg === "--no-skills") {
241
+ parsed.noSkills = true;
242
+ continue;
243
+ }
244
+ if (arg === "--skill") {
245
+ const value = need(arg);
246
+ if (value !== null) parsed.skillPaths.push(value);
247
+ continue;
248
+ }
249
+ if (arg === "--max-context-tokens") {
250
+ const value = need(arg);
251
+ if (value !== null) {
252
+ const n = Number(value);
253
+ if (Number.isInteger(n) && n > 0) {
254
+ parsed.maxContextTokens = n;
255
+ } else {
256
+ parsed.diagnostics.push({ type: "error", message: "--max-context-tokens must be a positive integer" });
257
+ }
258
+ }
259
+ continue;
260
+ }
261
+ if (arg === "--kv-cache-mode") {
262
+ const value = need(arg);
263
+ if (value !== null) {
264
+ parsed.kvCacheMode = value;
265
+ }
266
+ continue;
267
+ }
268
+ if (arg === "--session") {
269
+ const value = need(arg);
270
+ if (value !== null) {
271
+ parsed.sessionId = value;
272
+ }
273
+ continue;
274
+ }
275
+ if (arg === "--continue") {
276
+ parsed.continueSession = true;
277
+ continue;
278
+ }
279
+ if (arg === "--steer-channel") {
280
+ const value = need(arg);
281
+ if (value !== null) {
282
+ parsed.steerChannel = value;
283
+ }
284
+ continue;
285
+ }
286
+ if (arg?.startsWith("-")) {
287
+ parsed.diagnostics.push({
288
+ type: "error",
289
+ message: globalFlagPositionHint(arg, "run") ?? `unknown clio-coder run option: ${arg}`
290
+ });
291
+ continue;
292
+ }
293
+ if (arg !== void 0) {
294
+ if (arg.startsWith("@") && arg.length > 1) parsed.fileArgs.push(arg.slice(1));
295
+ else parsed.messages.push(arg);
296
+ }
297
+ }
298
+ return parsed;
299
+ }
300
+ function setNumberOption(parsed, key, raw, limits = {}) {
301
+ const value = Number(raw);
302
+ if (!Number.isFinite(value)) {
303
+ parsed.diagnostics.push({ type: "error", message: `--${kebab(key)} must be a number` });
304
+ return;
305
+ }
306
+ if (limits.min !== void 0 && value < limits.min) {
307
+ parsed.diagnostics.push({ type: "error", message: `--${kebab(key)} must be >= ${limits.min}` });
308
+ return;
309
+ }
310
+ if (limits.max !== void 0 && value > limits.max) {
311
+ parsed.diagnostics.push({ type: "error", message: `--${kebab(key)} must be <= ${limits.max}` });
312
+ return;
313
+ }
314
+ const normalized = limits.integer === true ? Math.floor(value) : value;
315
+ parsed.sampling = { ...parsed.sampling ?? {}, [key]: normalized };
316
+ }
317
+ function kebab(value) {
318
+ return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
319
+ }
320
+ function isNumericLiteral(value) {
321
+ return value.startsWith("-") && !value.startsWith("--") && Number.isFinite(Number(value));
322
+ }
323
+
324
+ // src/cli/initial-message.ts
325
+ async function readPipedStdin() {
326
+ if (process.stdin.isTTY) return void 0;
327
+ return new Promise((resolve) => {
328
+ let data = "";
329
+ process.stdin.setEncoding("utf8");
330
+ process.stdin.on("data", (chunk) => {
331
+ data += chunk;
332
+ });
333
+ process.stdin.on("end", () => {
334
+ resolve(data.length > 0 ? data : void 0);
335
+ });
336
+ process.stdin.resume();
337
+ });
338
+ }
339
+ function shouldReadPipedStdin(messages) {
340
+ return messages.length === 0;
341
+ }
342
+ function buildInitialMessage(input) {
343
+ const parts = [];
344
+ if (input.stdinContent !== void 0) parts.push(input.stdinContent);
345
+ if (input.fileText) parts.push(input.fileText);
346
+ const [first, ...rest] = input.messages;
347
+ if (first !== void 0) parts.push(first);
348
+ const result = { remainingMessages: rest };
349
+ if (parts.length > 0) result.initialMessage = parts.join("");
350
+ if (input.fileImages && input.fileImages.length > 0) result.initialImages = [...input.fileImages];
351
+ return result;
352
+ }
353
+
354
+ // src/cli/run.ts
355
+ var USAGE = 'usage: clio-coder run [--target <id>] [--model <wireId>] [--thinking <level>] [--autonomy <level>] [--json] [--json-events full|terminal] [--session <id>|--continue] [--agent <recipe-id>] "<task>"\n';
356
+ var HELP = `clio-coder run [flags] "<task>"
357
+
358
+ Run one headless main-agent turn. Fleet dispatch is explicit with --agent.
359
+
360
+ Flags:
361
+ --target <id> one-run main-agent or dispatch target override
362
+ --model <wireId> one-run model override
363
+ --thinking <level> one-run thinking level: off|minimal|low|medium|high|xhigh|max
364
+ --autonomy <level> one-run autonomy: read-only|suggest|auto-edit|full-auto
365
+ --temperature <N> one-run sampler override for supported local/OpenAI-compatible runtimes
366
+ --top-p <N> one-run nucleus sampling override (0..1)
367
+ --top-k <N> one-run top-k override
368
+ --min-p <N> one-run min-p override (0..1)
369
+ --presence-penalty <N> one-run presence penalty override
370
+ --frequency-penalty <N> one-run frequency penalty override
371
+ --repeat-penalty <N> one-run repeat penalty override
372
+ --max-context-tokens <N> one-run context-window override for supported local runtimes
373
+ --kv-cache-mode <mode> one-run KV-cache mode override: f16|f32|none|false|q8_0|q4_0|q4_1|iq4_nl|q5_0|q5_1
374
+ --json stream JSONL events for the main-agent path; dispatch streams events and receipt JSON
375
+ --json-events <mode> main-agent JSON stream mode: full|terminal; implies --json
376
+ --steer-channel <path> read live steering lines from a FIFO or appended regular file
377
+ --session <id> append this turn to an existing session
378
+ --continue append this turn to the most recent session for this cwd
379
+ --agent <recipe-id> dispatch a fleet agent instead of the main agent
380
+ --agent-profile <name> named fleet profile for dispatch
381
+ --agent-runtime <id> pick the first fleet profile whose target uses this runtime
382
+ --tool-profile <name> restrict dispatched-agent tools: minimal-local|science-local|full-agent
383
+ --require <capability> capability the dispatch target must advertise (repeatable)
384
+ --skill <path> load one explicit skill for this run, repeatable
385
+ --no-skills disable skill discovery while still honoring --skill
386
+
387
+ A headless turn starts a fresh session unless --session or --continue names one
388
+ to append to. A named session that cannot be resumed fails the run: an answer
389
+ written without the history the caller asked for is worse than no answer. The
390
+ session id is reported on stderr, and as the "session" event under --json.
391
+
392
+ There is no operator in a headless run: permission asks are denied, and the
393
+ ask_user interview tool is not registered. Skills that interview fall back to
394
+ their stated defaults; supply decisions in the task prompt instead.
395
+
396
+ A turn that ends by writing an artifact (plan/review/report) has no assistant
397
+ message after it, because writing the artifact is the answer. Text mode prints
398
+ that tool's result line, naming what was written and where; --json carries the
399
+ artifact content itself in the event stream.
400
+ `;
401
+ function hasDispatchOnlyOptions(parsed) {
402
+ return parsed.agentProfile !== void 0 || parsed.agentRuntime !== void 0 || parsed.toolProfile !== void 0 || parsed.required.length > 0;
403
+ }
404
+ function explicitTargetMissing(targetId) {
405
+ try {
406
+ return !readSettings().targets.some((target) => target.id === targetId);
407
+ } catch {
408
+ return false;
409
+ }
410
+ }
411
+ async function assemblePrompt(parsed) {
412
+ const messages = parsed.messages.length > 0 ? [parsed.messages.join(" ")] : [];
413
+ const stdinContent = shouldReadPipedStdin(messages) ? await readPipedStdin() : void 0;
414
+ const fileRefs = await readFileArgsAsync(parsed.fileArgs, { cwd: process.cwd(), missing: "error" });
415
+ for (const diagnostic of fileRefs.diagnostics) {
416
+ process.stderr.write(`error: ${diagnostic.message}
417
+ `);
418
+ }
419
+ if (fileRefs.diagnostics.some((diagnostic) => diagnostic.type === "error")) return null;
420
+ const initial = buildInitialMessage({
421
+ messages,
422
+ ...stdinContent !== void 0 ? { stdinContent } : {},
423
+ ...fileRefs.text.length > 0 ? { fileText: fileRefs.text } : {},
424
+ ...fileRefs.images.length > 0 ? { fileImages: fileRefs.images } : {}
425
+ });
426
+ if (!initial.initialMessage || initial.initialMessage.trim().length === 0) {
427
+ process.stderr.write("clio-coder run: empty task\n");
428
+ process.stderr.write(USAGE);
429
+ return null;
430
+ }
431
+ return {
432
+ prompt: initial.initialMessage,
433
+ ...initial.initialImages && initial.initialImages.length > 0 ? { images: initial.initialImages } : {},
434
+ ...fileRefs.referencedPaths.length > 0 ? { workingContextPaths: fileRefs.referencedPaths } : {}
435
+ };
436
+ }
437
+ function explicitSkillPathErrors(skillPaths) {
438
+ const errors = [];
439
+ for (const skillPath of skillPaths) {
440
+ const list = loadSkills({ disableDiscovery: true, explicitSkillPaths: [skillPath] });
441
+ if (list.items.length > 0) continue;
442
+ const detail = list.diagnostics.map((diagnostic) => diagnostic.message).join("; ");
443
+ errors.push(detail.length > 0 ? detail : `explicit skill path loaded no skills: ${skillPath}`);
444
+ }
445
+ return errors;
446
+ }
447
+ async function runClioRun(args, options = {}) {
448
+ const parsed = parseRunCliArgs(args);
449
+ return withRunOverrides(
450
+ {
451
+ ...parsed.maxContextTokens !== void 0 ? { maxContextTokens: parsed.maxContextTokens } : {},
452
+ ...parsed.kvCacheMode !== void 0 ? { kvCacheMode: parsed.kvCacheMode } : {}
453
+ },
454
+ async () => {
455
+ if (parsed.help) {
456
+ process.stdout.write(HELP);
457
+ return 0;
458
+ }
459
+ for (const diagnostic of parsed.diagnostics) {
460
+ process.stderr.write(`clio-coder run: ${diagnostic.message}
461
+ `);
462
+ }
463
+ if (parsed.diagnostics.some((diagnostic) => diagnostic.type === "error")) {
464
+ process.stderr.write(USAGE);
465
+ return 2;
466
+ }
467
+ if (parsed.agentId === void 0 && hasDispatchOnlyOptions(parsed)) {
468
+ process.stderr.write("clio-coder run: fleet dispatch flags require --agent <recipe-id>\n");
469
+ process.stderr.write(USAGE);
470
+ return 2;
471
+ }
472
+ if (parsed.sessionId !== void 0 && parsed.continueSession) {
473
+ process.stderr.write("clio-coder run: --session and --continue name different sessions; pass one\n");
474
+ process.stderr.write(USAGE);
475
+ return 2;
476
+ }
477
+ if ((parsed.sessionId !== void 0 || parsed.continueSession) && parsed.agentId !== void 0) {
478
+ process.stderr.write("clio-coder run: --session and --continue apply to the main agent, not --agent dispatch\n");
479
+ process.stderr.write(USAGE);
480
+ return 2;
481
+ }
482
+ const noSkills = options.noSkills === true || parsed.noSkills === true;
483
+ const skillPaths = Array.from(/* @__PURE__ */ new Set([...options.skillPaths ?? [], ...parsed.skillPaths]));
484
+ const skillPathErrors = explicitSkillPathErrors(skillPaths);
485
+ if (skillPathErrors.length > 0) {
486
+ for (const message of skillPathErrors) {
487
+ process.stderr.write(`clio-coder run: --skill ${message}
488
+ `);
489
+ }
490
+ return 2;
491
+ }
492
+ const assembled = await assemblePrompt(parsed);
493
+ if (!assembled) return 2;
494
+ if (parsed.agentId === void 0) {
495
+ if (parsed.target !== void 0 && explicitTargetMissing(parsed.target)) {
496
+ process.stderr.write(`clio-coder run: target '${parsed.target}' not found in settings.targets
497
+ `);
498
+ return 2;
499
+ }
500
+ takeOverStdout();
501
+ try {
502
+ const code = await runClioCommand({
503
+ ...options.apiKey === void 0 ? {} : { apiKey: options.apiKey },
504
+ ...options.noContextFiles ? { noContextFiles: true } : {},
505
+ ...noSkills ? { noSkills: true } : {},
506
+ ...skillPaths.length > 0 ? { skillPaths } : {},
507
+ headless: {
508
+ prompt: assembled.prompt,
509
+ mode: parsed.json ? "json" : "text",
510
+ jsonEvents: parsed.jsonEvents,
511
+ ...noSkills ? { noSkills: true } : {},
512
+ ...skillPaths.length > 0 ? { skillPaths } : {},
513
+ ...assembled.images && assembled.images.length > 0 ? { images: assembled.images } : {},
514
+ ...assembled.workingContextPaths && assembled.workingContextPaths.length > 0 ? { workingContextPaths: assembled.workingContextPaths } : {},
515
+ ...parsed.target !== void 0 ? { target: parsed.target } : {},
516
+ ...parsed.model !== void 0 ? { model: parsed.model } : {},
517
+ ...parsed.thinking !== void 0 ? { thinking: parsed.thinking } : {},
518
+ ...parsed.autonomy !== void 0 ? { autonomy: parsed.autonomy } : {},
519
+ ...parsed.sampling !== void 0 ? { sampling: parsed.sampling } : {},
520
+ ...parsed.steerChannel !== void 0 ? { steerChannel: parsed.steerChannel } : {},
521
+ ...parsed.sessionId !== void 0 ? { resumeSession: { kind: "id", id: parsed.sessionId } } : parsed.continueSession ? { resumeSession: { kind: "latest" } } : {}
522
+ }
523
+ });
524
+ await flushRawStdout();
525
+ return code;
526
+ } finally {
527
+ restoreStdout();
528
+ }
529
+ }
530
+ return await runDispatch(parsed, assembled.prompt, {
531
+ ...options,
532
+ noSkills,
533
+ skillPaths
534
+ });
535
+ }
536
+ );
537
+ }
538
+ async function runDispatch(parsed, task, options) {
539
+ if (parsed.toolProfile !== void 0 && !isToolProfileName(parsed.toolProfile)) {
540
+ process.stderr.write("clio-coder run: --tool-profile must be one of: minimal-local|science-local|full-agent\n");
541
+ process.stderr.write(USAGE);
542
+ return 2;
543
+ }
544
+ if (parsed.target && parsed.agentProfile) {
545
+ process.stderr.write(
546
+ `clio-coder run: --target ${parsed.target} takes precedence; --agent-profile ${parsed.agentProfile} will be ignored
547
+ `
548
+ );
549
+ }
550
+ if (parsed.target && parsed.agentRuntime) {
551
+ process.stderr.write(
552
+ `clio-coder run: --target ${parsed.target} takes precedence; --agent-runtime ${parsed.agentRuntime} will be ignored
553
+ `
554
+ );
555
+ }
556
+ ensureClioState();
557
+ let effectiveSettings;
558
+ const loaded = await loadDomains([
559
+ ConfigDomainModule,
560
+ ResourcesDomainModule,
561
+ createContextDomainModule({ noContextFiles: options.noContextFiles === true }),
562
+ ProvidersDomainModule,
563
+ SafetyDomainModule,
564
+ createPromptsDomainModule({ noContextFiles: options.noContextFiles === true }),
565
+ AgentsDomainModule,
566
+ MiddlewareDomainModule,
567
+ SessionDomainModule,
568
+ // Observability subscribes to the dispatch terminal events so a headless
569
+ // run auto-builds its forensic evidence bundle and sidecar index, the same
570
+ // as an interactive session. It depends only on providers + session, both
571
+ // loaded above.
572
+ ObservabilityDomainModule,
573
+ SchedulingDomainModule,
574
+ createDispatchDomainModule({
575
+ getSettings: () => effectiveSettings,
576
+ autonomyOverride: parsed.autonomy !== void 0
577
+ }),
578
+ LifecycleDomainModule
579
+ ]);
580
+ const config = loaded.getContract("config");
581
+ const baseSettings = config?.get() ?? readSettings();
582
+ effectiveSettings = parsed.autonomy === void 0 ? baseSettings : { ...structuredClone(baseSettings), autonomy: parsed.autonomy };
583
+ const dispatch = loaded.getContract("dispatch");
584
+ if (!dispatch) {
585
+ process.stderr.write("dispatch domain unavailable\n");
586
+ await loaded.stop();
587
+ return 1;
588
+ }
589
+ if (options.apiKey) {
590
+ const providers = loaded.getContract("providers");
591
+ if (!providers) {
592
+ process.stderr.write("clio-coder run: --api-key supplied but providers domain unavailable\n");
593
+ await loaded.stop();
594
+ return 1;
595
+ }
596
+ const settings = effectiveSettings;
597
+ const profileTargetId = parsed.agentProfile ? settings.workers?.profiles?.[parsed.agentProfile]?.target : void 0;
598
+ const runtimeByTarget = new Map(settings.targets.map((target2) => [target2.id, target2.runtime]));
599
+ const runtimeTargetId = parsed.agentRuntime ? [settings.workers?.default, ...Object.values(settings.workers?.profiles ?? {})].find(
600
+ (profile) => profile?.target && runtimeByTarget.get(profile.target) === parsed.agentRuntime
601
+ )?.target : void 0;
602
+ const targetId = parsed.target ?? profileTargetId ?? runtimeTargetId ?? settings.workers?.default?.target ?? settings.orchestrator?.target;
603
+ const target = targetId ? providers.getTarget(targetId) : null;
604
+ const runtime = target ? providers.getRuntime(target.runtime) : null;
605
+ if (!target || !runtime) {
606
+ process.stderr.write("clio-coder run: --api-key supplied but no target resolved; pass --target <id>\n");
607
+ await loaded.stop();
608
+ return 2;
609
+ }
610
+ providers.auth.setRuntimeOverrideForTarget(target, runtime, options.apiKey);
611
+ }
612
+ const noSkills = options.noSkills === true || parsed.noSkills === true;
613
+ const skillPaths = Array.from(/* @__PURE__ */ new Set([...options.skillPaths ?? [], ...parsed.skillPaths]));
614
+ const runAgents = loaded.getContract("agents");
615
+ const dispatchReq = {
616
+ agentId: parsed.agentId,
617
+ executionRole: requestExecutionRole({
618
+ agentId: parsed.agentId,
619
+ ...runAgents ? { resolveFacts: agentRoleFactsResolver((id) => runAgents.getSpec(id)) } : {}
620
+ }),
621
+ task,
622
+ requestOrigin: "user"
623
+ };
624
+ if (parsed.agentProfile) dispatchReq.workerProfile = parsed.agentProfile;
625
+ if (parsed.agentRuntime) dispatchReq.workerRuntime = parsed.agentRuntime;
626
+ if (parsed.target) dispatchReq.target = parsed.target;
627
+ if (parsed.model) dispatchReq.model = parsed.model;
628
+ if (parsed.thinking) dispatchReq.thinkingLevel = parsed.thinking;
629
+ if (parsed.toolProfile) dispatchReq.toolProfile = parsed.toolProfile;
630
+ if (parsed.required.length > 0) dispatchReq.requiredCapabilities = parsed.required;
631
+ if (noSkills) dispatchReq.noSkills = true;
632
+ if (skillPaths.length > 0) dispatchReq.skillPaths = skillPaths;
633
+ try {
634
+ const settings = effectiveSettings;
635
+ if (settings.skills?.trustProjectCompatRoots) {
636
+ dispatchReq.trustProjectCompatRoots = true;
637
+ }
638
+ } catch {
639
+ }
640
+ let memorySection = "";
641
+ try {
642
+ const records = loadMemoryRecordsSync(clioDataDir());
643
+ memorySection = buildMemoryPromptSection(records, {
644
+ activeRepository: canonicalMemoryRepositoryIdentity(process.cwd())
645
+ }).section;
646
+ } catch (err) {
647
+ process.stderr.write(
648
+ `clio-coder run: memory load failed: ${err instanceof Error ? err.message : String(err)}; continuing without memory
649
+ `
650
+ );
651
+ }
652
+ if (memorySection.length > 0) dispatchReq.memorySection = memorySection;
653
+ let cleanupSteer;
654
+ try {
655
+ const handle = await dispatch.dispatch(dispatchReq);
656
+ if (parsed.steerChannel) {
657
+ cleanupSteer = setupSteerChannel(parsed.steerChannel, (line) => {
658
+ try {
659
+ dispatch.steer(handle.runId, line);
660
+ } catch {
661
+ }
662
+ });
663
+ }
664
+ const onSignal = () => dispatch.abort(handle.runId);
665
+ process.on("SIGINT", onSignal);
666
+ process.on("SIGTERM", onSignal);
667
+ let accumulatedText = "";
668
+ let lastAssistantText = "";
669
+ for await (const event of handle.events) {
670
+ if (parsed.json) {
671
+ process.stdout.write(`${JSON.stringify(projectDispatchJsonEvent(event))}
672
+ `);
673
+ continue;
674
+ }
675
+ const e = event;
676
+ if (e.type === "attempt_start") {
677
+ accumulatedText = "";
678
+ lastAssistantText = "";
679
+ continue;
680
+ }
681
+ if (e.type === "text_delta" && typeof e.text === "string") {
682
+ accumulatedText += e.text;
683
+ }
684
+ const assistantText = assistantTextFromEvent(event);
685
+ if (assistantText.length > 0) lastAssistantText = assistantText;
686
+ }
687
+ const receipt = await handle.finalPromise;
688
+ if (cleanupSteer) {
689
+ cleanupSteer();
690
+ cleanupSteer = void 0;
691
+ }
692
+ if (parsed.json) {
693
+ process.stdout.write(`
694
+ ${JSON.stringify(receipt, null, 2)}
695
+ `);
696
+ } else {
697
+ const answer = lastAssistantText.length > 0 ? lastAssistantText : accumulatedText.trim();
698
+ if (answer.length > 0) process.stdout.write(`${answer}
699
+ `);
700
+ process.stdout.write(`${formatReceipt(receipt)}
701
+ `);
702
+ }
703
+ process.off("SIGINT", onSignal);
704
+ process.off("SIGTERM", onSignal);
705
+ await dispatch.drain();
706
+ await loaded.stop();
707
+ return mapExitCode(receipt);
708
+ } catch (err) {
709
+ if (cleanupSteer) {
710
+ cleanupSteer();
711
+ }
712
+ const msg = err instanceof Error ? err.message : String(err);
713
+ process.stderr.write(`clio-coder run failed: ${msg}
714
+ `);
715
+ await loaded.stop();
716
+ if (/target '.+' not found/.test(msg)) return 2;
717
+ if (msg.includes("unknown agent recipe") || msg.includes("admission") || msg.includes("capability") || msg.includes("budget"))
718
+ return 2;
719
+ return 1;
720
+ }
721
+ }
722
+ function formatReceipt(r) {
723
+ const reasoning = typeof r.reasoningTokenCount === "number" && r.reasoningTokenCount > 0 ? ` reasoning=${r.reasoningTokenCount}` : "";
724
+ const failure = r.failureMessage ? ` error=${r.failureMessage}` : "";
725
+ return `receipt: ${r.runId} agent=${r.agentId} exit=${r.exitCode} target=${r.targetId} model=${r.wireModelId} tokens=${r.tokenCount}${reasoning}${failure} start=${r.startedAt} end=${r.endedAt}`;
726
+ }
727
+ function mapExitCode(r) {
728
+ if (r.exitCode === 0) return 0;
729
+ return r.exitCode === 2 ? 2 : 1;
730
+ }
731
+ export {
732
+ explicitSkillPathErrors,
733
+ runClioRun
734
+ };
735
+ //# sourceMappingURL=run-3VSPP24F.js.map