@mcoda/mswarm 0.1.135-codali.13 → 0.1.135-codali.18

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 (50) hide show
  1. package/dist/vendor/codali/cli/TerminalArtifacts.d.ts +5 -0
  2. package/dist/vendor/codali/cli/TerminalArtifacts.d.ts.map +1 -0
  3. package/dist/vendor/codali/cli/TerminalArtifacts.js +26 -0
  4. package/dist/vendor/codali/cli/TerminalCommand.d.ts.map +1 -1
  5. package/dist/vendor/codali/cli/TerminalCommand.js +363 -62
  6. package/dist/vendor/codali/cli/TerminalInput.d.ts +7 -0
  7. package/dist/vendor/codali/cli/TerminalInput.d.ts.map +1 -1
  8. package/dist/vendor/codali/cli/TerminalInput.js +53 -7
  9. package/dist/vendor/codali/cli/TerminalModels.d.ts +6 -0
  10. package/dist/vendor/codali/cli/TerminalModels.d.ts.map +1 -0
  11. package/dist/vendor/codali/cli/TerminalModels.js +45 -0
  12. package/dist/vendor/codali/cli/TerminalPlan.d.ts +40 -0
  13. package/dist/vendor/codali/cli/TerminalPlan.d.ts.map +1 -0
  14. package/dist/vendor/codali/cli/TerminalPlan.js +37 -0
  15. package/dist/vendor/codali/cli/tui/TerminalCells.d.ts +6 -0
  16. package/dist/vendor/codali/cli/tui/TerminalCells.d.ts.map +1 -0
  17. package/dist/vendor/codali/cli/tui/TerminalCells.js +47 -0
  18. package/dist/vendor/codali/cli/tui/TerminalEditor.d.ts +22 -0
  19. package/dist/vendor/codali/cli/tui/TerminalEditor.d.ts.map +1 -0
  20. package/dist/vendor/codali/cli/tui/TerminalEditor.js +88 -0
  21. package/dist/vendor/codali/cli/tui/TerminalPresentation.d.ts +4 -0
  22. package/dist/vendor/codali/cli/tui/TerminalPresentation.d.ts.map +1 -0
  23. package/dist/vendor/codali/cli/tui/TerminalPresentation.js +68 -0
  24. package/dist/vendor/codali/cli/tui/TerminalScreen.d.ts +49 -0
  25. package/dist/vendor/codali/cli/tui/TerminalScreen.d.ts.map +1 -0
  26. package/dist/vendor/codali/cli/tui/TerminalScreen.js +130 -0
  27. package/dist/vendor/codali/cli/tui/TerminalTui.d.ts +78 -0
  28. package/dist/vendor/codali/cli/tui/TerminalTui.d.ts.map +1 -0
  29. package/dist/vendor/codali/cli/tui/TerminalTui.js +469 -0
  30. package/dist/vendor/codali/cli.d.ts.map +1 -1
  31. package/dist/vendor/codali/cli.js +4 -2
  32. package/dist/vendor/codali/config/OrchestrationConfig.d.ts +15 -0
  33. package/dist/vendor/codali/config/OrchestrationConfig.d.ts.map +1 -1
  34. package/dist/vendor/codali/config/OrchestrationConfig.js +19 -1
  35. package/dist/vendor/codali/connectors/media/MediaJobStore.d.ts +2 -1
  36. package/dist/vendor/codali/connectors/media/MediaJobStore.d.ts.map +1 -1
  37. package/dist/vendor/codali/connectors/media/MediaJobStore.js +11 -3
  38. package/dist/vendor/codali/runtime/InteractionRouter.d.ts +30 -0
  39. package/dist/vendor/codali/runtime/InteractionRouter.d.ts.map +1 -0
  40. package/dist/vendor/codali/runtime/InteractionRouter.js +53 -0
  41. package/dist/vendor/codali/runtime/PreparedMemory.d.ts +3 -0
  42. package/dist/vendor/codali/runtime/PreparedMemory.d.ts.map +1 -0
  43. package/dist/vendor/codali/runtime/PreparedMemory.js +30 -0
  44. package/dist/vendor/codali/runtime/SessionController.d.ts +27 -1
  45. package/dist/vendor/codali/runtime/SessionController.d.ts.map +1 -1
  46. package/dist/vendor/codali/runtime/SessionController.js +275 -33
  47. package/dist/vendor/codali/session/SessionStore.d.ts +5 -1
  48. package/dist/vendor/codali/session/SessionStore.d.ts.map +1 -1
  49. package/dist/vendor/codali/session/SessionStore.js +11 -2
  50. package/package.json +7 -4
@@ -0,0 +1,469 @@
1
+ import { emitKeypressEvents } from "node:readline";
2
+ import { promises as fs } from "node:fs";
3
+ import path from "node:path";
4
+ import { TerminalInput } from "../TerminalInput.js";
5
+ import { terminalText, TerminalTextStream } from "../TerminalText.js";
6
+ import { terminalHelp, terminalUsage, toolActivity } from "./TerminalPresentation.js";
7
+ import { TerminalEditor } from "./TerminalEditor.js";
8
+ import { renderTerminalScreen } from "./TerminalScreen.js";
9
+ /** One terminal owner; controller events are rendered as data, never executable escape codes. */
10
+ export class TerminalTui {
11
+ constructor(options) {
12
+ this.options = options;
13
+ this.live = false;
14
+ this.previousRaw = false;
15
+ this.previousFrame = [];
16
+ this.stream = new TerminalTextStream();
17
+ this.sequence = 0;
18
+ this.frameRows = 12;
19
+ this.transcriptRows = 0;
20
+ this.outputBlocked = false;
21
+ this.resize = () => { this.previousFrame = []; this.schedule(); };
22
+ this.drain = () => { this.outputBlocked = false; this.schedule(); };
23
+ this.onKey = (text, key) => {
24
+ try {
25
+ this.key(text, key);
26
+ }
27
+ catch (error) {
28
+ this.error(error instanceof Error ? error.message : String(error));
29
+ }
30
+ this.schedule();
31
+ };
32
+ this.editor = new TerminalEditor(options.history.filter(value => Buffer.byteLength(value) <= 262144).map(value => terminalText(value).replace(/\t/g, " ")));
33
+ this.state = { ...options, workspace: terminalText(options.workspace), branch: options.branch ? terminalText(options.branch) : undefined, profile: terminalText(options.profile), version: terminalText(options.version), busy: false, activity: "Ready", route: "", tokens: 0, queued: 0, draft: "", cursor: 0, blocks: [], scroll: 0, expanded: false };
34
+ this.closedPromise = new Promise(resolve => { this.resolveClosed = resolve; });
35
+ this.input = new TerminalInput({ onPaste: text => {
36
+ if (this.approval || this.picker || this.state.overlay)
37
+ return;
38
+ if (!this.editor.insert(terminalText(text).replace(/\t/g, " ")))
39
+ this.notice("Input exceeds 256 KiB");
40
+ this.schedule();
41
+ }, onRejected: text => this.notice(text), onWheel: direction => this.scroll(direction * -3), onEscape: () => this.onKey("", { name: "escape" }) });
42
+ }
43
+ start() {
44
+ if (this.live)
45
+ return;
46
+ this.live = true;
47
+ this.previousRaw = !!process.stdin.isRaw;
48
+ process.stdout.write("\x1b[?1049h\x1b[?25l\x1b[?2004h\x1b[?1000h\x1b[?1006h\x1b[2J");
49
+ process.stdin.setRawMode(true);
50
+ emitKeypressEvents(this.input);
51
+ this.input.on("keypress", this.onKey);
52
+ process.stdin.pipe(this.input);
53
+ process.stdin.resume();
54
+ process.stdout.on("resize", this.resize);
55
+ process.stdout.on("drain", this.drain);
56
+ this.draw();
57
+ }
58
+ wait() { return this.closedPromise; }
59
+ stop() {
60
+ if (!this.live) {
61
+ this.resolveClosed();
62
+ return;
63
+ }
64
+ this.live = false;
65
+ if (this.timer)
66
+ clearTimeout(this.timer);
67
+ this.timer = undefined;
68
+ this.approval?.resolve("deny");
69
+ this.approval = undefined;
70
+ process.stdout.off("resize", this.resize);
71
+ process.stdout.off("drain", this.drain);
72
+ process.stdin.unpipe(this.input);
73
+ this.input.off("keypress", this.onKey);
74
+ this.input.destroy();
75
+ process.stdin.setRawMode(this.previousRaw);
76
+ process.stdin.pause();
77
+ process.stdout.write("\x1b[0m\x1b[?1006l\x1b[?1000l\x1b[?2004l\x1b[?25h\x1b[?1049l");
78
+ this.resolveClosed();
79
+ }
80
+ schedule() {
81
+ if (!this.live || this.timer)
82
+ return;
83
+ this.timer = setTimeout(() => { this.timer = undefined; this.draw(); }, 24);
84
+ }
85
+ draw() {
86
+ if (!this.live || this.outputBlocked)
87
+ return;
88
+ this.state.draft = this.editor.text;
89
+ this.state.cursor = this.editor.cursor;
90
+ this.state.suggestions = undefined;
91
+ if (!this.state.overlay && !this.approval && this.editor.text.startsWith("/") && !/\s/.test(this.editor.text)) {
92
+ this.state.suggestions = this.options.commands.filter(command => command.name.startsWith(this.editor.text)).slice(0, 5).map(command => `${command.name} ${command.description}`);
93
+ this.state.selectedSuggestion = 0;
94
+ }
95
+ let frame = renderTerminalScreen(this.state, process.stdout.columns || 80, process.stdout.rows || 24, process.env.NO_COLOR === undefined);
96
+ if (this.state.scroll > 0 && frame.transcriptRows > this.transcriptRows) {
97
+ this.state.scroll += frame.transcriptRows - this.transcriptRows;
98
+ frame = renderTerminalScreen(this.state, process.stdout.columns || 80, process.stdout.rows || 24, process.env.NO_COLOR === undefined);
99
+ }
100
+ this.frameRows = frame.viewportRows;
101
+ this.transcriptRows = frame.transcriptRows;
102
+ let output = "\x1b[?25l";
103
+ frame.lines.forEach((line, i) => { if (this.previousFrame[i] !== line)
104
+ output += `\x1b[${i + 1};1H\x1b[2K${line}`; });
105
+ if (frame.cursor)
106
+ output += `\x1b[${frame.cursor.row + 1};${frame.cursor.column + 1}H\x1b[?25h`;
107
+ this.outputBlocked = !process.stdout.write(output);
108
+ this.previousFrame = frame.lines;
109
+ }
110
+ append(kind, title, text) {
111
+ const block = { id: `ui-${++this.sequence}`, kind, title: terminalText(title), text: terminalText(text).slice(-262144) };
112
+ this.state.blocks.push(block);
113
+ while (this.state.blocks.length > 200 || (this.state.blocks.length > 1 && this.state.blocks.reduce((sum, item) => sum + item.text.length, 0) > 262144))
114
+ this.state.blocks.shift();
115
+ this.schedule();
116
+ return block;
117
+ }
118
+ scroll(lines) {
119
+ if (this.picker)
120
+ return;
121
+ if (this.state.overlay)
122
+ this.state.overlay.offset = Math.max(0, this.state.overlay.offset - lines);
123
+ else
124
+ this.state.scroll = Math.max(0, Math.min(Math.max(0, this.transcriptRows - this.frameRows), this.state.scroll + lines));
125
+ this.schedule();
126
+ }
127
+ notice(text) { this.append("notice", "NOTICE", text); }
128
+ error(text) {
129
+ const message = text === "fetch failed" ? "Could not reach the requested service. Check your connection or service status, then try again." : text;
130
+ this.append("error", "NEEDS ATTENTION", message);
131
+ }
132
+ user(text) { this.state.scroll = 0; this.append("user", "YOU", text); }
133
+ result(text) {
134
+ const clean = terminalText(text);
135
+ if (this.assistant && this.assistant.text.trim() === clean.trim())
136
+ return;
137
+ this.assistant = this.append("assistant", "CODALI", clean);
138
+ }
139
+ show(value, title = "Details") {
140
+ const text = title.toLowerCase() === "help" ? terminalHelp() : title.toLowerCase() === "usage" ? terminalUsage(value) : typeof value === "string" ? value : formatInspection(value);
141
+ const overlay = { title: terminalText(title.slice(0, 1).toUpperCase() + title.slice(1)), lines: terminalText(text).split("\n"), offset: 0 };
142
+ if (this.approval)
143
+ this.pendingInspection = overlay;
144
+ else {
145
+ this.picker = undefined;
146
+ this.state.overlay = overlay;
147
+ }
148
+ this.schedule();
149
+ }
150
+ update(status) { Object.assign(this.state, status); this.schedule(); }
151
+ restore(events) {
152
+ this.state.blocks = [];
153
+ this.assistant = undefined;
154
+ this.lastTool = undefined;
155
+ this.stream.reset();
156
+ this.state.tokens = 0;
157
+ this.state.route = "";
158
+ this.state.session = undefined;
159
+ for (const event of events.slice(-3000)) {
160
+ if (!event?.data || typeof event.type !== "string")
161
+ continue;
162
+ if (event.sessionId)
163
+ this.state.session = event.sessionId;
164
+ if (event.type === "conversation_history" && Array.isArray(event.data.messages)) {
165
+ this.state.blocks = [];
166
+ for (const message of event.data.messages) {
167
+ if (message.role === "user")
168
+ this.user(message.content);
169
+ else if (message.role === "assistant")
170
+ this.result(message.content);
171
+ }
172
+ }
173
+ else if (event.type === "interaction_request" && typeof event.data.prompt === "string")
174
+ this.user(event.data.prompt);
175
+ else if (event.type === "session_started" && !event.data.interactionId && typeof event.data.objective === "string")
176
+ this.user(event.data.objective);
177
+ else if (event.type === "goal_amended" && !event.data.interactionId && typeof event.data.instruction === "string")
178
+ this.user(event.data.instruction);
179
+ else if (event.type === "turn_result" && typeof event.data.content === "string")
180
+ this.result(event.data.content);
181
+ else if (event.type === "turn_failed" && typeof event.data.message === "string")
182
+ this.error(event.data.message);
183
+ else if (["tool_intent", "tool_receipt", "usage", "model_route"].includes(event.type))
184
+ this.event(event);
185
+ }
186
+ this.state.busy = false;
187
+ this.state.activity = "Session resumed";
188
+ this.state.scroll = 0;
189
+ this.schedule();
190
+ }
191
+ event(event) {
192
+ const data = event.data;
193
+ if (event.sessionId)
194
+ this.state.session = event.sessionId;
195
+ if (event.type === "turn_started") {
196
+ this.stream.reset();
197
+ this.assistant = undefined;
198
+ this.state.busy = true;
199
+ this.state.activity = "Thinking";
200
+ }
201
+ else if (event.type === "token" && typeof data.content === "string") {
202
+ if (!this.assistant)
203
+ this.assistant = this.append("assistant", "CODALI", "");
204
+ this.assistant.text = (this.assistant.text + this.stream.write(data.content)).slice(-262144);
205
+ }
206
+ else if (event.type === "model_route") {
207
+ this.state.route = terminalText(`${data.modelId ?? "Model"}${data.host ? ` on ${data.host}` : ""}`);
208
+ this.state.activity = "Thinking";
209
+ }
210
+ else if (event.type === "interaction_progress" && typeof data.message === "string")
211
+ this.state.activity = terminalText(data.message);
212
+ else if (event.type === "usage") {
213
+ const usage = data.usage;
214
+ if (Number.isFinite(usage?.tokens))
215
+ this.state.tokens = usage.tokens;
216
+ }
217
+ else if (event.type === "tool_intent") {
218
+ const receipt = data.receipt;
219
+ this.lastTool = this.append("tool", `● ${toolActivity(receipt.tool, receipt.args)}`, receipt.args ? JSON.stringify(receipt.args, null, 2) : "Running…");
220
+ this.lastTool.id = receipt.id;
221
+ this.lastTool.summary = toolActivity(receipt.tool, receipt.args);
222
+ this.state.activity = terminalText(this.lastTool.summary);
223
+ }
224
+ else if (event.type === "process_output" && typeof data.content === "string") {
225
+ if (!this.lastTool)
226
+ this.lastTool = this.append("tool", "Process output", "");
227
+ this.lastTool.text = (this.lastTool.text + terminalText(data.content)).slice(-65536);
228
+ }
229
+ else if (event.type === "tool_receipt") {
230
+ const receipt = data.receipt;
231
+ const block = this.state.blocks.find(item => item.id === receipt.id);
232
+ if (block) {
233
+ block.title = terminalText(`${receipt.status === "success" ? "✓" : "!"} ${toolActivity(receipt.tool, receipt.args)} · ${receipt.status === "success" ? "done" : "needs attention"}`);
234
+ block.summary = receipt.status === "success" ? "Finished. Ctrl+O shows the details." : terminalText(receipt.error ?? receipt.output ?? "This step needs attention. Ctrl+O shows the details.").slice(0, 600);
235
+ if (typeof receipt.output === "string")
236
+ block.text = terminalText([receipt.args ? JSON.stringify(receipt.args, null, 2) : "", receipt.output].filter(Boolean).join("\n\n")).slice(-65536);
237
+ else if (receipt.error)
238
+ block.text += "\n" + terminalText(receipt.error);
239
+ }
240
+ }
241
+ else if (event.type === "status" && typeof data.message === "string")
242
+ this.state.activity = terminalText(data.message);
243
+ else if (event.type === "turn_result" || event.type === "turn_failed") {
244
+ if (this.assistant)
245
+ this.assistant.text += this.stream.finish();
246
+ this.state.busy = false;
247
+ this.state.activity = event.type === "turn_failed" ? "Turn stopped" : data.mode && data.mode !== "execute" ? "Ready" : data.completed ? "Goal completed" : "Ready to continue";
248
+ }
249
+ this.schedule();
250
+ }
251
+ approve(title, details, signal) {
252
+ this.approval?.resolve("deny");
253
+ this.picker = undefined;
254
+ return new Promise(resolve => {
255
+ const abort = () => finish("deny");
256
+ const finish = (choice) => {
257
+ signal?.removeEventListener("abort", abort);
258
+ this.approval = undefined;
259
+ this.state.overlay = this.pendingInspection;
260
+ this.pendingInspection = undefined;
261
+ this.schedule();
262
+ resolve(choice);
263
+ };
264
+ const overlay = { title: terminalText(title.slice(0, 1).toUpperCase() + title.slice(1)), lines: terminalText(details).split("\n"), offset: 0, choices: ["Allow once", "Allow for this session", "Deny"], selected: 2, hint: "←→ choose · Enter confirm · PgUp/PgDn inspect · Esc deny" };
265
+ this.approval = { resolve: finish, selected: 2, overlay };
266
+ this.state.overlay = overlay;
267
+ signal?.addEventListener("abort", abort, { once: true });
268
+ if (signal?.aborted)
269
+ abort();
270
+ this.schedule();
271
+ });
272
+ }
273
+ pickerItems() {
274
+ if (!this.picker)
275
+ return [];
276
+ return this.picker.items.filter(item => item.label.toLowerCase().includes(this.picker.query.toLowerCase()));
277
+ }
278
+ showPicker() {
279
+ const picker = this.picker;
280
+ const items = this.pickerItems();
281
+ picker.selected = Math.max(0, Math.min(items.length - 1, picker.selected));
282
+ const count = Math.max(1, (process.stdout.rows || 24) - 10);
283
+ const offset = Math.max(0, picker.selected - count + 1);
284
+ this.state.overlay = { title: `${picker.kind === "command" ? "Commands" : picker.kind === "history" ? "History" : "Workspace files"} › ${picker.query}`, lines: items.length ? items.slice(offset, offset + count).map((item, i) => `${i + offset === picker.selected ? "›" : " "} ${item.label}`) : ["No matches"], offset: 0, hint: "Type to search · ↑↓ choose · Enter select · Esc close" };
285
+ this.schedule();
286
+ }
287
+ openPicker(kind) {
288
+ this.picker = { kind, query: "", selected: 0, items: kind === "command" ? this.options.commands.map(command => ({ label: `${command.name} ${command.description}`, value: command.name })) : this.editor.history.map(value => ({ label: value.replace(/\n/g, " ↵ "), value })) };
289
+ this.showPicker();
290
+ }
291
+ async completeFile() {
292
+ const draft = this.editor.text, cursor = this.editor.cursor;
293
+ const before = draft.slice(0, cursor);
294
+ const match = before.match(/(?:^|\s)@([^\n]*)$/u);
295
+ if (!match)
296
+ return;
297
+ const token = match[1], directory = token.endsWith("/") ? token : path.dirname(token), fragment = token.endsWith("/") ? "" : path.basename(token);
298
+ const relative = directory === "." ? "" : directory;
299
+ const root = await fs.realpath(this.options.workspace);
300
+ const target = await fs.realpath(path.resolve(root, relative));
301
+ if (target !== root && !target.startsWith(root + path.sep))
302
+ throw new Error("File completion is confined to this workspace");
303
+ const entries = await fs.readdir(target, { withFileTypes: true });
304
+ if (this.editor.text !== draft || this.editor.cursor !== cursor || this.approval || this.state.overlay)
305
+ return;
306
+ this.picker = { kind: "file", query: fragment, selected: 0, prefix: before.slice(0, before.length - token.length - 1), suffix: draft.slice(cursor), items: entries.filter(item => item.name !== ".git" && !item.isSymbolicLink() && !/[\x00-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/.test(item.name)).slice(0, 1000).map(item => { const value = path.join(relative, item.name) + (item.isDirectory() ? "/" : ""); return { label: value, value }; }).sort((a, b) => a.label.localeCompare(b.label)) };
307
+ this.showPicker();
308
+ }
309
+ key(text, key) {
310
+ if (key.ctrl && key.name === "c") {
311
+ this.options.cancel();
312
+ return;
313
+ }
314
+ if (this.approval) {
315
+ if (key.name === "escape")
316
+ this.approval.resolve("deny");
317
+ else if ((process.stdout.columns || 80) < 24 || (process.stdout.rows || 24) < 10)
318
+ return;
319
+ else if (key.name === "left" || key.name === "right") {
320
+ this.approval.selected = (this.approval.selected + (key.name === "left" ? 2 : 1)) % 3;
321
+ this.approval.overlay.selected = this.approval.selected;
322
+ }
323
+ else if (key.name === "return")
324
+ this.approval.resolve(["once", "session", "deny"][this.approval.selected]);
325
+ else if (["pageup", "pagedown", "up", "down"].includes(key.name ?? ""))
326
+ this.approval.overlay.offset = Math.max(0, this.approval.overlay.offset + (["pageup", "up"].includes(key.name) ? -1 : 1) * (key.name.startsWith("page") ? 6 : 1));
327
+ return;
328
+ }
329
+ if (this.picker) {
330
+ if (key.name === "escape") {
331
+ this.picker = undefined;
332
+ this.state.overlay = undefined;
333
+ return;
334
+ }
335
+ if (key.name === "up" || key.name === "down")
336
+ this.picker.selected += key.name === "up" ? -1 : 1;
337
+ else if (key.name === "backspace")
338
+ this.picker.query = [...this.picker.query].slice(0, -1).join("");
339
+ else if (key.name === "return") {
340
+ const selected = this.pickerItems()[this.picker.selected];
341
+ if (!selected)
342
+ return;
343
+ const picker = this.picker;
344
+ this.picker = undefined;
345
+ this.state.overlay = undefined;
346
+ if (picker.kind === "command")
347
+ this.options.submit(selected.value, "queue");
348
+ else if (picker.kind === "history")
349
+ this.editor.set(selected.value);
350
+ else {
351
+ const prefix = (picker.prefix ?? "") + "@" + selected.value;
352
+ this.editor.set(prefix + (picker.suffix ?? ""));
353
+ this.editor.cursor = prefix.length;
354
+ if (selected.value.endsWith("/"))
355
+ void this.completeFile().catch(error => this.error(String(error)));
356
+ }
357
+ return;
358
+ }
359
+ else if (!key.ctrl && !key.meta && text && !/[\x00-\x1f\x7f]/.test(text)) {
360
+ this.picker.query += text;
361
+ this.picker.selected = 0;
362
+ }
363
+ this.showPicker();
364
+ return;
365
+ }
366
+ if (this.state.overlay) {
367
+ if (key.name === "escape" || key.name === "q")
368
+ this.state.overlay = undefined;
369
+ else if (["up", "down", "pageup", "pagedown"].includes(key.name ?? ""))
370
+ this.state.overlay.offset = Math.max(0, this.state.overlay.offset + (["up", "pageup"].includes(key.name) ? -1 : 1) * (key.name.startsWith("page") ? 8 : 1));
371
+ return;
372
+ }
373
+ if (key.ctrl && key.name === "end") {
374
+ this.state.scroll = 0;
375
+ return;
376
+ }
377
+ if (key.ctrl && key.name === "p") {
378
+ this.openPicker("command");
379
+ return;
380
+ }
381
+ if (key.ctrl && key.name === "r") {
382
+ this.openPicker("history");
383
+ return;
384
+ }
385
+ if (key.ctrl && key.name === "o") {
386
+ this.state.expanded = !this.state.expanded;
387
+ return;
388
+ }
389
+ if (key.ctrl && key.name === "l") {
390
+ this.previousFrame = [];
391
+ return;
392
+ }
393
+ if (key.name === "escape") {
394
+ if (this.state.busy)
395
+ this.options.cancel();
396
+ else
397
+ this.editor.clear();
398
+ return;
399
+ }
400
+ if (key.name === "pageup" || key.name === "pagedown") {
401
+ this.state.scroll = Math.max(0, Math.min(Math.max(0, this.transcriptRows - this.frameRows), this.state.scroll + (key.name === "pageup" ? 1 : -1) * Math.max(1, this.frameRows - 2)));
402
+ return;
403
+ }
404
+ if (key.ctrl && key.name === "s") {
405
+ const value = this.editor.submit();
406
+ if (value.trim())
407
+ this.options.submit(value, "steer");
408
+ return;
409
+ }
410
+ if (key.name === "return") {
411
+ if (key.meta || key.shift)
412
+ this.editor.insert("\n");
413
+ else {
414
+ const value = this.editor.submit();
415
+ if (value.trim())
416
+ this.options.submit(value, "queue");
417
+ }
418
+ }
419
+ else if (key.ctrl && key.name === "j")
420
+ this.editor.insert("\n");
421
+ else if (key.name === "backspace")
422
+ this.editor.delete(true);
423
+ else if (key.name === "delete")
424
+ this.editor.delete(false);
425
+ else if (key.name === "left")
426
+ this.editor.move(-1);
427
+ else if (key.name === "right")
428
+ this.editor.move(1);
429
+ else if (key.name === "home" || (key.ctrl && key.name === "a"))
430
+ this.editor.home();
431
+ else if (key.name === "end" || (key.ctrl && key.name === "e"))
432
+ this.editor.end();
433
+ else if (key.ctrl && key.name === "u")
434
+ this.editor.clear();
435
+ else if (key.ctrl && key.name === "w")
436
+ this.editor.killWord();
437
+ else if (key.ctrl && key.name === "d" && !this.editor.text)
438
+ this.options.close();
439
+ else if (key.name === "up" || key.name === "down") {
440
+ const direction = key.name === "up" ? -1 : 1;
441
+ if (!this.editor.vertical(direction))
442
+ this.editor.previous(direction);
443
+ }
444
+ else if (key.name === "tab") {
445
+ const matches = this.options.commands.filter(command => command.name.startsWith(this.editor.text));
446
+ if (this.editor.text.startsWith("/") && matches.length)
447
+ this.editor.set(matches[0].name + " ");
448
+ else
449
+ void this.completeFile().catch(error => this.error(error instanceof Error ? error.message : String(error)));
450
+ }
451
+ else if (!key.ctrl && !key.meta && text && !/[\x00-\x1f\x7f]/.test(text))
452
+ this.editor.insert(terminalText(text));
453
+ }
454
+ }
455
+ export const formatInspection = (value, depth = 0) => {
456
+ if (value === null || value === undefined)
457
+ return "—";
458
+ if (typeof value !== "object")
459
+ return String(value);
460
+ if (Array.isArray(value))
461
+ return value.length ? value.map((item, index) => `${index + 1}. ${formatInspection(item, depth + 1)}`).join("\n\n") : "None";
462
+ const entries = Object.entries(value);
463
+ if (depth > 4)
464
+ return JSON.stringify(value);
465
+ return entries.map(([key, item]) => {
466
+ const label = key.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/_/g, " ");
467
+ return `${label[0]?.toUpperCase() ?? ""}${label.slice(1)}: ${item && typeof item === "object" ? "\n" : ""}${formatInspection(item, depth + 1)}`;
468
+ }).join("\n");
469
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AA2FA,eAAO,MAAM,MAAM,GAAU,OAAM,MAAM,EAA0B,KAAG,OAAO,CAAC,IAAI,CAyEjF,CAAC"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AA6FA,eAAO,MAAM,MAAM,GAAU,OAAM,MAAM,EAA0B,KAAG,OAAO,CAAC,IAAI,CAyEjF,CAAC"}
@@ -14,6 +14,8 @@ import { ImprovementCommand } from "./cli/ImprovementCommand.js";
14
14
  import { TerminalCommand, terminalDoctor } from "./cli/TerminalCommand.js";
15
15
  const HELP_TEXT = "Usage: codali [chat] [prompt] [--effort low|medium|high|max] [--permissions plan|ask|workspace]\n" +
16
16
  " or: codali exec <prompt> [--json] [--config <path>]\n" +
17
+ " or: codali exec <prompt> --output-format jsonl --permission-profile workspace\n" +
18
+ " or: codali config validate --file <path>\n" +
17
19
  " or: codali setup | login [--stdin] | logout | auth status\n" +
18
20
  " or: codali sessions | resume <id> | inspect <id>\n" +
19
21
  " or: codali ask \"<question>\" [--trace] [--json] [--workspace-root <path>]\n" +
@@ -108,11 +110,11 @@ export const runCli = async (argv = process.argv.slice(2)) => {
108
110
  console.log(JSON.stringify(await terminalDoctor(rest.includes("--config") ? rest[rest.indexOf("--config") + 1] : undefined), null, 2));
109
111
  return;
110
112
  }
111
- if (["chat", "exec", "setup", "login", "logout", "sessions", "resume", "status", "inspect", "checkpoint", "amend"].includes(command)) {
113
+ if (["chat", "exec", "config", "setup", "login", "logout", "sessions", "resume", "status", "inspect", "checkpoint", "amend"].includes(command)) {
112
114
  await TerminalCommand.run(argv);
113
115
  return;
114
116
  }
115
- if (["--effort", "--permissions", "--config", "--workspace-root", "--plain", "--json", "--stdin"].includes(command)) {
117
+ if (["--effort", "--permissions", "--permission-profile", "--output-format", "--config", "--workspace-root", "--plain", "--json", "--stdin"].includes(command)) {
116
118
  await TerminalCommand.run(["chat", ...argv]);
117
119
  return;
118
120
  }
@@ -54,6 +54,20 @@ export interface TaskControlConfig {
54
54
  checkpointOn: string[];
55
55
  reviewPolicy: "risk-and-evidence";
56
56
  }
57
+ export interface InteractionConfig {
58
+ routerBinding?: string;
59
+ answerBinding?: string;
60
+ promptVersion?: string;
61
+ routerPrompt?: string;
62
+ answerPrompt?: string;
63
+ maxInputChars?: number;
64
+ historyChars?: number;
65
+ maxOutputTokens?: number;
66
+ maxTotalTokens?: number;
67
+ maxModelCalls?: number;
68
+ maxInspectionSteps?: number;
69
+ timeoutMs?: number;
70
+ }
57
71
  export interface OrchestrationConfig {
58
72
  schemaVersion: 1;
59
73
  profile: string;
@@ -66,6 +80,7 @@ export interface OrchestrationConfig {
66
80
  };
67
81
  effort?: Partial<Record<EffortLevel, Partial<EffortBudget>>>;
68
82
  taskControl?: TaskControlConfig;
83
+ interaction?: InteractionConfig;
69
84
  docdex?: {
70
85
  binary?: string;
71
86
  binarySha256?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"OrchestrationConfig.d.ts","sourceRoot":"","sources":["../../src/config/OrchestrationConfig.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAC;AAC5D,MAAM,MAAM,cAAc,GAAG,kBAAkB,GAAG,YAAY,GAAG,oBAAoB,GAAG,mBAAmB,GAAG,oBAAoB,CAAC;AACnI,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AACD,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC,CAK/E,CAAC;AAEH,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,QAAQ,GAAG,mBAAmB,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AACD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IAC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,OAAO,KAAG,mBAwG5D,CAAC;AAEF,gFAAgF;AAChF,eAAO,MAAM,wBAAwB,GAAI,QAAQ,mBAAmB,EAAE,gBAAqB;;iBAvL9D,MAAM;oBAAkB,MAAM;mBAAiB,MAAM,GAAG,IAAI;aAAW,MAAM;;;;CA2MzG,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,QAAQ,mBAAmB,EAAE,MAAM,MAAM,EAAE,YAAY,cAAc,KAAG,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,CAerJ,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAU,aAAuG,KAAG,OAAO,CAAC,2BAA2B,CAI1L,CAAC;AACF,eAAO,MAAM,YAAY,GAAI,QAAQ,mBAAmB,EAAE,OAAO,WAAW,KAAG,YAAyE,CAAC"}
@@ -49,7 +49,7 @@ const canonical = (v) => Array.isArray(v) ? v.map(canonical) : isRecord(v)
49
49
  export const orchestrationHash = (config) => createHash("sha256").update(JSON.stringify(canonical(config))).digest("hex");
50
50
  export const validateOrchestrationConfig = (input) => {
51
51
  const root = object(input, "orchestration");
52
- fields(root, ["schemaVersion", "profile", "providers", "models", "bindings", "routing", "effort", "taskControl", "docdex"], "orchestration");
52
+ fields(root, ["schemaVersion", "profile", "providers", "models", "bindings", "routing", "effort", "taskControl", "docdex", "interaction"], "orchestration");
53
53
  if (root.schemaVersion !== 1)
54
54
  throw new Error("Unsupported orchestration schemaVersion");
55
55
  nonempty(root.profile, "profile");
@@ -172,6 +172,24 @@ export const validateOrchestrationConfig = (input) => {
172
172
  if (!Array.isArray(t.checkpointOn) || t.checkpointOn.some(v => !["task-transition", "before-compaction", "before-exit"].includes(String(v))))
173
173
  throw new Error("Invalid checkpointOn policy");
174
174
  }
175
+ if (root.interaction !== undefined) {
176
+ const value = object(root.interaction, "interaction");
177
+ fields(value, ["routerBinding", "answerBinding", "promptVersion", "routerPrompt", "answerPrompt", "maxInputChars", "historyChars", "maxOutputTokens", "maxTotalTokens", "maxModelCalls", "maxInspectionSteps", "timeoutMs"], "interaction");
178
+ for (const key of ["routerBinding", "answerBinding"])
179
+ if (value[key] !== undefined) {
180
+ nonempty(value[key], `interaction.${key}`);
181
+ if (!hasOwn(bindings, String(value[key])) || object(bindings[String(value[key])], key).enabled === false)
182
+ throw new Error(`interaction.${key}: unavailable binding`);
183
+ }
184
+ if (value.promptVersion !== undefined)
185
+ nonempty(value.promptVersion, "interaction.promptVersion");
186
+ for (const key of ["routerPrompt", "answerPrompt"])
187
+ if (value[key] !== undefined && (typeof value[key] !== "string" || !String(value[key]).trim() || String(value[key]).length > 16000))
188
+ throw new Error(`interaction.${key}: expected bounded nonempty prompt`);
189
+ for (const key of ["maxInputChars", "historyChars", "maxOutputTokens", "maxTotalTokens", "maxModelCalls", "maxInspectionSteps", "timeoutMs"])
190
+ if (value[key] !== undefined)
191
+ positive(value[key], `interaction.${key}`);
192
+ }
175
193
  if (root.docdex !== undefined) {
176
194
  const d = object(root.docdex, "docdex");
177
195
  fields(d, ["binary", "binarySha256", "startupTimeoutMs"], "docdex");
@@ -62,7 +62,8 @@ export declare class MediaJobStore {
62
62
  /** Trusted user/host action, deliberately unavailable as an agent tool. */
63
63
  reconcileFailure(id: string, note: string): Promise<MediaJob>;
64
64
  reconcileProcess(id: string, signal?: AbortSignal): Promise<MediaJob>;
65
- exportArtifact(id: string, workspaceRoot: string, destination: string, checkPath?: (resolvedPath: string) => Promise<void>): Promise<MediaArtifact>;
65
+ verifiedArtifact(id: string): Promise<MediaArtifact>;
66
+ exportArtifact(id: string, workspaceRoot: string, destination: string, checkPath?: (resolvedPath: string) => Promise<void>, signal?: AbortSignal): Promise<MediaArtifact>;
66
67
  }
67
68
  export declare const validateMediaRequest: (request: Record<string, unknown>, descriptor: Record<string, unknown>, operation: ModelOperation) => Record<string, unknown>;
68
69
  //# sourceMappingURL=MediaJobStore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MediaJob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,YAAY,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,cAAc,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAuB7J,CAAC"}
@@ -136,11 +136,18 @@ export class MediaJobStore {
136
136
  });
137
137
  return recovery.acquired ? recovery.value : job;
138
138
  }
139
- async exportArtifact(id, workspaceRoot, destination, checkPath) {
139
+ async verifiedArtifact(id) {
140
140
  const job = await this.read(id);
141
- const artifact = job.artifact;
142
- if (job.status !== "succeeded" || !artifact)
141
+ if (job.status !== "succeeded" || !job.artifact)
143
142
  throw new Error("Media artifact is not ready");
143
+ const artifact = await recoverMediaArtifact(path.dirname(this.file(id)), job);
144
+ if (!artifact || Object.entries(artifact).some(([key, value]) => job.artifact[key] !== value))
145
+ throw new Error("Media artifact does not match its durable receipt");
146
+ return artifact;
147
+ }
148
+ async exportArtifact(id, workspaceRoot, destination, checkPath, signal) {
149
+ signal?.throwIfAborted();
150
+ const artifact = await this.verifiedArtifact(id);
144
151
  const target = path.resolve(workspaceRoot, destination);
145
152
  const root = await fs.realpath(workspaceRoot);
146
153
  const parent = await fs.realpath(path.dirname(target));
@@ -153,6 +160,7 @@ export class MediaJobStore {
153
160
  const bytes = await fs.readFile(artifact.path);
154
161
  if (createHash("sha256").update(bytes).digest("hex") !== artifact.sha256)
155
162
  throw new Error("Artifact checksum mismatch");
163
+ signal?.throwIfAborted();
156
164
  await fs.writeFile(canonicalTarget, bytes, { flag: "wx", mode: 0o600 });
157
165
  return { ...artifact, path: canonicalTarget };
158
166
  }