@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,130 @@
1
+ import { cells, fitCells, padCells, wrapCells } from "./TerminalCells.js";
2
+ const blockRows = new WeakMap();
3
+ const overlayRows = new WeakMap();
4
+ const clipStyled = (text, width) => {
5
+ let result = "", remaining = width;
6
+ for (const part of text.split(/(\x1b\[[0-9;]*m)/g)) {
7
+ if (/^\x1b\[[0-9;]*m$/.test(part)) {
8
+ result += part;
9
+ continue;
10
+ }
11
+ const visible = fitCells(part, remaining);
12
+ result += visible;
13
+ remaining -= cells(visible);
14
+ if (visible !== part)
15
+ break;
16
+ }
17
+ return result + (text.includes("\x1b[") ? "\x1b[0m" : "");
18
+ };
19
+ export const renderTerminalScreen = (state, columns, rows, color = true) => {
20
+ columns = Math.max(1, Math.floor(columns));
21
+ rows = Math.max(1, Math.floor(rows));
22
+ const paint = (code, text) => color ? `\x1b[${code}m${text}\x1b[0m` : text;
23
+ const dim = (text) => paint("2", text);
24
+ if (columns < 24 || rows < 10)
25
+ return { lines: [fitCells("Codali · enlarge terminal", columns), ...Array(Math.max(0, rows - 1)).fill("")], transcriptRows: 0, viewportRows: 0 };
26
+ const width = columns - 4;
27
+ const draftRows = wrapCells(state.draft || " ", width - 4);
28
+ const cursorRows = wrapCells(state.draft.slice(0, state.cursor), width - 4);
29
+ let cursorLine = cursorRows.length - 1, cursorCell = cells(cursorRows.at(-1) ?? "");
30
+ if (cursorCell === width - 4) {
31
+ cursorLine++;
32
+ cursorCell = 0;
33
+ if (cursorLine >= draftRows.length)
34
+ draftRows.push("");
35
+ }
36
+ const editorRows = Math.min(Math.max(1, draftRows.length), Math.max(1, Math.min(6, rows - 12)));
37
+ const editorOffset = Math.max(0, cursorLine - editorRows + 1);
38
+ const viewportRows = Math.max(1, rows - editorRows - 8);
39
+ const transcript = [];
40
+ for (const block of state.blocks) {
41
+ const label = block.kind === "user" ? "YOU" : block.kind === "assistant" ? "CODALI" : block.title;
42
+ const tone = block.kind === "error" ? "31" : block.kind === "user" ? "36" : block.kind === "tool" ? "2" : "1;36";
43
+ transcript.push(paint(tone, fitCells(label, width)));
44
+ let cached = blockRows.get(block);
45
+ if (!cached || cached.text !== block.text || cached.width !== width) {
46
+ cached = { text: block.text, width, rows: wrapCells(block.text.replace(/\t/g, " "), width) };
47
+ blockRows.set(block, cached);
48
+ }
49
+ const content = cached.rows;
50
+ const visible = block.kind === "tool" && !state.expanded ? block.summary ? wrapCells(block.summary, width).slice(0, 3) : content.slice(0, 3) : content;
51
+ let code = false, language = "";
52
+ for (const line of visible) {
53
+ if (line.startsWith("```")) {
54
+ code = !code;
55
+ if (code)
56
+ language = line.slice(3).trim();
57
+ transcript.push(dim(code ? `┌ ${language || "code"}` : "└"));
58
+ }
59
+ else if ((!code || language === "diff") && /^\+[^+]/.test(line))
60
+ transcript.push(paint("32", line));
61
+ else if ((!code || language === "diff") && /^-[^-]/.test(line))
62
+ transcript.push(paint("31", line));
63
+ else if (code)
64
+ transcript.push(paint("37", line));
65
+ else if (/^#{1,6} /.test(line))
66
+ transcript.push(paint("1", line.replace(/^#+ /, "")));
67
+ else
68
+ transcript.push(line.replace(/\*\*([^*]+)\*\*/g, (_match, value) => paint("1", value)).replace(/`([^`]+)`/g, (_match, value) => paint("36", value)));
69
+ }
70
+ if (visible.length < content.length && !(block.kind === "tool" && !state.expanded && block.summary))
71
+ transcript.push(dim(`… ${content.length - visible.length} more lines · Ctrl+O expand`));
72
+ transcript.push("");
73
+ }
74
+ if (!transcript.length)
75
+ transcript.push("", paint("1", "What would you like to build?"), "", ...wrapCells("Describe a change, investigate a problem, or ask about this project.", width).map(dim), "", dim("/ commands @ files Ctrl+P command palette"));
76
+ const maximumScroll = Math.max(0, transcript.length - viewportRows);
77
+ const scroll = Math.max(0, Math.min(maximumScroll, state.scroll));
78
+ const start = Math.max(0, transcript.length - viewportRows - scroll);
79
+ const view = transcript.slice(start, start + viewportRows);
80
+ while (view.length < viewportRows)
81
+ view.push("");
82
+ const lines = [
83
+ " " + paint("1;36", "◈ CODALI") + dim(` ${fitCells(state.version, width - 10)}`),
84
+ " " + dim(fitCells(state.workspace + (state.branch ? ` · ${state.branch}` : "") + (state.session ? ` · ${state.session.slice(0, 8)}` : ""), width)),
85
+ " " + dim("─".repeat(width)),
86
+ ...view.map(line => " " + line),
87
+ " " + paint(state.busy ? "33" : "2", fitCells(`${state.busy ? "● " : "○ "}${state.activity || (state.busy ? "Working" : "Ready")}${state.queued ? ` · ${state.queued} queued` : ""}${scroll ? " · scrollback" : ""}`, width)),
88
+ " " + paint("36", "╭" + "─".repeat(width - 2) + "╮"),
89
+ ];
90
+ const editorTop = lines.length;
91
+ for (let i = 0; i < editorRows; i++) {
92
+ const line = draftRows[editorOffset + i] ?? "";
93
+ const placeholder = !state.draft && i === 0;
94
+ lines.push(" " + paint("36", "│" + (i === 0 ? "› " : " ")) + (placeholder ? dim(padCells(state.busy ? "Queue a message…" : "Ask Codali anything…", width - 4)) : padCells(line, width - 4)) + paint("36", "│"));
95
+ }
96
+ lines.push(" " + paint("36", "╰" + "─".repeat(width - 2) + "╯"));
97
+ const tokens = state.tokens >= 1000 ? `${(state.tokens / 1000).toFixed(1)}k` : String(state.tokens);
98
+ lines.push(" " + dim(fitCells(`${state.route || state.profile} · ${state.effort} · ${state.permissions} · ${tokens} tokens`, width)));
99
+ lines.push(" " + dim(fitCells(state.busy ? "Enter queue · Ctrl+S steer · Esc cancel · Wheel/PgUp scroll" : "Enter send · Alt+Enter newline · Ctrl+P commands · Wheel/PgUp scroll", width)));
100
+ let cursor = { row: editorTop + cursorLine - editorOffset, column: 5 + cursorCell };
101
+ const overlay = state.overlay;
102
+ if (overlay) {
103
+ const bodyWidth = width - 4, available = Math.max(1, rows - 5 - (overlay.choices ? overlay.choices.length + 1 : 0));
104
+ let cached = overlayRows.get(overlay);
105
+ if (!cached || cached.lines !== overlay.lines || cached.width !== bodyWidth) {
106
+ cached = { lines: overlay.lines, width: bodyWidth, rows: overlay.lines.flatMap(line => wrapCells(line.replace(/\t/g, " "), bodyWidth)) };
107
+ overlayRows.set(overlay, cached);
108
+ }
109
+ const contents = cached.rows;
110
+ const offset = Math.min(Math.max(0, contents.length - available), Math.max(0, overlay.offset));
111
+ const panel = [paint("1;36", fitCells(overlay.title, bodyWidth)), ...contents.slice(offset, offset + available).map(line => /^[A-Z][A-Z &/]+$/.test(line) ? paint("1;36", line) : line)];
112
+ if (overlay.choices)
113
+ panel.push("", ...overlay.choices.map((choice, i) => paint(i === overlay.selected ? "7" : "0", fitCells(`${i === overlay.selected ? "›" : " "} ${choice}`, bodyWidth))));
114
+ panel.push("", dim(fitCells(overlay.hint ?? "↑↓ scroll · PgUp/PgDn page · Esc close", bodyWidth)));
115
+ const visible = panel.slice(0, rows - 2);
116
+ const top = Math.max(0, Math.floor((rows - visible.length - 2) / 2));
117
+ for (let i = 0; i < visible.length + 2; i++) {
118
+ const edge = i === 0 || i === visible.length + 1;
119
+ const content = edge ? "─".repeat(width - 2) : " " + padCells(visible[i - 1], width - 4) + " ";
120
+ lines[top + i] = " " + paint("36", edge ? (i === 0 ? "╭" : "╰") : "│") + content + paint("36", edge ? (i === 0 ? "╮" : "╯") : "│");
121
+ }
122
+ cursor = undefined;
123
+ }
124
+ else if (state.suggestions?.length) {
125
+ const suggestions = state.suggestions.slice(0, Math.min(5, viewportRows));
126
+ const top = 3 + viewportRows - suggestions.length;
127
+ suggestions.forEach((item, i) => { lines[top + i] = " " + paint(i === state.selectedSuggestion ? "7" : "2", padCells(item, width)); });
128
+ }
129
+ return { lines: lines.slice(0, rows).map(line => clipStyled(line, columns)), cursor, transcriptRows: transcript.length, viewportRows };
130
+ };
@@ -0,0 +1,78 @@
1
+ import type { SessionEvent } from "../../runtime/SessionController.js";
2
+ import { TerminalEditor } from "./TerminalEditor.js";
3
+ import { type TerminalScreenState } from "./TerminalScreen.js";
4
+ export interface TuiCommand {
5
+ name: string;
6
+ description: string;
7
+ }
8
+ export interface TerminalTuiOptions {
9
+ workspace: string;
10
+ branch?: string;
11
+ version: string;
12
+ profile: string;
13
+ effort: string;
14
+ permissions: string;
15
+ history: string[];
16
+ commands: TuiCommand[];
17
+ submit: (text: string, intent: "queue" | "steer") => void;
18
+ cancel: () => void;
19
+ close: () => void;
20
+ }
21
+ /** One terminal owner; controller events are rendered as data, never executable escape codes. */
22
+ export declare class TerminalTui {
23
+ private readonly options;
24
+ readonly editor: TerminalEditor;
25
+ readonly state: TerminalScreenState;
26
+ private input;
27
+ private timer?;
28
+ private live;
29
+ private previousRaw;
30
+ private previousFrame;
31
+ private picker?;
32
+ private approval?;
33
+ private stream;
34
+ private assistant?;
35
+ private lastTool?;
36
+ private sequence;
37
+ private closedPromise;
38
+ private resolveClosed;
39
+ private frameRows;
40
+ private transcriptRows;
41
+ private outputBlocked;
42
+ private pendingInspection?;
43
+ constructor(options: TerminalTuiOptions);
44
+ start(): void;
45
+ wait(): Promise<void>;
46
+ stop(): void;
47
+ private resize;
48
+ private drain;
49
+ private schedule;
50
+ private draw;
51
+ private append;
52
+ private scroll;
53
+ notice(text: string): void;
54
+ error(text: string): void;
55
+ user(text: string): void;
56
+ result(text: string): void;
57
+ show(value: unknown, title?: string): void;
58
+ update(status: {
59
+ busy?: boolean;
60
+ activity?: string;
61
+ effort?: string;
62
+ permissions?: string;
63
+ tokens?: number;
64
+ queued?: number;
65
+ session?: string;
66
+ }): void;
67
+ restore(events: SessionEvent[]): void;
68
+ event(event: SessionEvent): void;
69
+ approve(title: string, details: string, signal?: AbortSignal): Promise<"once" | "session" | "deny">;
70
+ private pickerItems;
71
+ private showPicker;
72
+ private openPicker;
73
+ private completeFile;
74
+ private onKey;
75
+ private key;
76
+ }
77
+ export declare const formatInspection: (value: unknown, depth?: number) => string;
78
+ //# sourceMappingURL=TerminalTui.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TerminalTui.d.ts","sourceRoot":"","sources":["../../../src/cli/tui/TerminalTui.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAIvE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAA8C,KAAK,mBAAmB,EAAwB,MAAM,qBAAqB,CAAC;AAEjI,MAAM,WAAW,UAAU;IAAG,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EA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