zelio-cli 0.0.0-stage → 0.1.0-beta.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.
Files changed (175) hide show
  1. package/README.md +178 -2
  2. package/dist/attachments.js +121 -0
  3. package/dist/attachments.js.map +1 -0
  4. package/dist/cli.js +469 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/cloud/board.js +311 -0
  7. package/dist/cloud/board.js.map +1 -0
  8. package/dist/cloud/command.js +260 -0
  9. package/dist/cloud/command.js.map +1 -0
  10. package/dist/cloud/config.js +132 -0
  11. package/dist/cloud/config.js.map +1 -0
  12. package/dist/cloud/credentials.js +134 -0
  13. package/dist/cloud/credentials.js.map +1 -0
  14. package/dist/cloud/login.js +165 -0
  15. package/dist/cloud/login.js.map +1 -0
  16. package/dist/cloud/pair.js +110 -0
  17. package/dist/cloud/pair.js.map +1 -0
  18. package/dist/cloud/pkce.js +16 -0
  19. package/dist/cloud/pkce.js.map +1 -0
  20. package/dist/cloud/push-nudge.js +63 -0
  21. package/dist/cloud/push-nudge.js.map +1 -0
  22. package/dist/cloud/relay.js +129 -0
  23. package/dist/cloud/relay.js.map +1 -0
  24. package/dist/cloud/token.js +66 -0
  25. package/dist/cloud/token.js.map +1 -0
  26. package/dist/cloud/tunnel.js +410 -0
  27. package/dist/cloud/tunnel.js.map +1 -0
  28. package/dist/db/db.js +1614 -0
  29. package/dist/db/db.js.map +1 -0
  30. package/dist/db/lifecycle.js +133 -0
  31. package/dist/db/lifecycle.js.map +1 -0
  32. package/dist/limits.js +35 -0
  33. package/dist/limits.js.map +1 -0
  34. package/dist/metrics.js +30 -0
  35. package/dist/metrics.js.map +1 -0
  36. package/dist/orchestrator/claude-session.js +208 -0
  37. package/dist/orchestrator/claude-session.js.map +1 -0
  38. package/dist/orchestrator/codex-session.js +326 -0
  39. package/dist/orchestrator/codex-session.js.map +1 -0
  40. package/dist/orchestrator/contract.js +181 -0
  41. package/dist/orchestrator/contract.js.map +1 -0
  42. package/dist/orchestrator/explore.js +176 -0
  43. package/dist/orchestrator/explore.js.map +1 -0
  44. package/dist/orchestrator/new-task-prompt.js +51 -0
  45. package/dist/orchestrator/new-task-prompt.js.map +1 -0
  46. package/dist/orchestrator/pi-session.js +228 -0
  47. package/dist/orchestrator/pi-session.js.map +1 -0
  48. package/dist/orchestrator/prompt.js +110 -0
  49. package/dist/orchestrator/prompt.js.map +1 -0
  50. package/dist/orchestrator/research.js +178 -0
  51. package/dist/orchestrator/research.js.map +1 -0
  52. package/dist/orchestrator/runtime.js +1054 -0
  53. package/dist/orchestrator/runtime.js.map +1 -0
  54. package/dist/orchestrator/session.js +2 -0
  55. package/dist/orchestrator/session.js.map +1 -0
  56. package/dist/orchestrator/types.js +2 -0
  57. package/dist/orchestrator/types.js.map +1 -0
  58. package/dist/orchestrator/web.js +276 -0
  59. package/dist/orchestrator/web.js.map +1 -0
  60. package/dist/repo/index.js +188 -0
  61. package/dist/repo/index.js.map +1 -0
  62. package/dist/repo/instructions.js +52 -0
  63. package/dist/repo/instructions.js.map +1 -0
  64. package/dist/repo/linked-boards.js +252 -0
  65. package/dist/repo/linked-boards.js.map +1 -0
  66. package/dist/run/actions.js +233 -0
  67. package/dist/run/actions.js.map +1 -0
  68. package/dist/run/bash-guard.js +183 -0
  69. package/dist/run/bash-guard.js.map +1 -0
  70. package/dist/run/claude-runtime.js +242 -0
  71. package/dist/run/claude-runtime.js.map +1 -0
  72. package/dist/run/claude-stream.js +306 -0
  73. package/dist/run/claude-stream.js.map +1 -0
  74. package/dist/run/codex-client.js +200 -0
  75. package/dist/run/codex-client.js.map +1 -0
  76. package/dist/run/codex-runtime.js +366 -0
  77. package/dist/run/codex-runtime.js.map +1 -0
  78. package/dist/run/context.js +87 -0
  79. package/dist/run/context.js.map +1 -0
  80. package/dist/run/diff.js +196 -0
  81. package/dist/run/diff.js.map +1 -0
  82. package/dist/run/evidence.js +48 -0
  83. package/dist/run/evidence.js.map +1 -0
  84. package/dist/run/finish.js +393 -0
  85. package/dist/run/finish.js.map +1 -0
  86. package/dist/run/harness-runtime.js +28 -0
  87. package/dist/run/harness-runtime.js.map +1 -0
  88. package/dist/run/harnesses.js +273 -0
  89. package/dist/run/harnesses.js.map +1 -0
  90. package/dist/run/issue.js +79 -0
  91. package/dist/run/issue.js.map +1 -0
  92. package/dist/run/keep-awake.js +58 -0
  93. package/dist/run/keep-awake.js.map +1 -0
  94. package/dist/run/lead.js +200 -0
  95. package/dist/run/lead.js.map +1 -0
  96. package/dist/run/manager.js +1709 -0
  97. package/dist/run/manager.js.map +1 -0
  98. package/dist/run/mentions.js +35 -0
  99. package/dist/run/mentions.js.map +1 -0
  100. package/dist/run/merge-watch.js +394 -0
  101. package/dist/run/merge-watch.js.map +1 -0
  102. package/dist/run/models.js +88 -0
  103. package/dist/run/models.js.map +1 -0
  104. package/dist/run/phases.js +23 -0
  105. package/dist/run/phases.js.map +1 -0
  106. package/dist/run/pi-rpc.js +412 -0
  107. package/dist/run/pi-rpc.js.map +1 -0
  108. package/dist/run/pr-merge.js +121 -0
  109. package/dist/run/pr-merge.js.map +1 -0
  110. package/dist/run/profiles.js +43 -0
  111. package/dist/run/profiles.js.map +1 -0
  112. package/dist/run/prompt.js +345 -0
  113. package/dist/run/prompt.js.map +1 -0
  114. package/dist/run/pull-request.js +23 -0
  115. package/dist/run/pull-request.js.map +1 -0
  116. package/dist/run/result-tool.js +93 -0
  117. package/dist/run/result-tool.js.map +1 -0
  118. package/dist/run/result.js +113 -0
  119. package/dist/run/result.js.map +1 -0
  120. package/dist/run/retro.js +346 -0
  121. package/dist/run/retro.js.map +1 -0
  122. package/dist/run/settings.js +25 -0
  123. package/dist/run/settings.js.map +1 -0
  124. package/dist/run/thinking.js +41 -0
  125. package/dist/run/thinking.js.map +1 -0
  126. package/dist/run/types.js +2 -0
  127. package/dist/run/types.js.map +1 -0
  128. package/dist/run/workflow.js +266 -0
  129. package/dist/run/workflow.js.map +1 -0
  130. package/dist/run/worktree.js +354 -0
  131. package/dist/run/worktree.js.map +1 -0
  132. package/dist/server/app.js +2503 -0
  133. package/dist/server/app.js.map +1 -0
  134. package/dist/server/auth.js +93 -0
  135. package/dist/server/auth.js.map +1 -0
  136. package/dist/server/demo.js +96 -0
  137. package/dist/server/demo.js.map +1 -0
  138. package/dist/server/idempotency.js +104 -0
  139. package/dist/server/idempotency.js.map +1 -0
  140. package/dist/server/port.js +36 -0
  141. package/dist/server/port.js.map +1 -0
  142. package/dist/server/principal.js +90 -0
  143. package/dist/server/principal.js.map +1 -0
  144. package/dist/server/terminal.js +285 -0
  145. package/dist/server/terminal.js.map +1 -0
  146. package/dist/setup/components.js +98 -0
  147. package/dist/setup/components.js.map +1 -0
  148. package/dist/setup/config.js +102 -0
  149. package/dist/setup/config.js.map +1 -0
  150. package/dist/setup/ink-ui.js +188 -0
  151. package/dist/setup/ink-ui.js.map +1 -0
  152. package/dist/setup/onboarding.js +183 -0
  153. package/dist/setup/onboarding.js.map +1 -0
  154. package/dist/setup/run.js +70 -0
  155. package/dist/setup/run.js.map +1 -0
  156. package/dist/ticket-cli.js +116 -0
  157. package/dist/ticket-cli.js.map +1 -0
  158. package/dist/voice/index.js +69 -0
  159. package/dist/voice/index.js.map +1 -0
  160. package/dist/voice/moonshine.js +247 -0
  161. package/dist/voice/moonshine.js.map +1 -0
  162. package/dist/voice/wav.js +54 -0
  163. package/dist/voice/wav.js.map +1 -0
  164. package/dist/voice/whisper.js +491 -0
  165. package/dist/voice/whisper.js.map +1 -0
  166. package/dist/web/assets/index-ChuS3qKc.js +254 -0
  167. package/dist/web/assets/index-DR6WkmzI.css +1 -0
  168. package/dist/web/icons/apple-touch-icon.png +0 -0
  169. package/dist/web/icons/icon-192.png +0 -0
  170. package/dist/web/icons/icon-512.png +0 -0
  171. package/dist/web/icons/maskable-512.png +0 -0
  172. package/dist/web/index.html +21 -0
  173. package/dist/web/manifest.webmanifest +30 -0
  174. package/dist/web/sw.js +183 -0
  175. package/package.json +96 -4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WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC3C,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,iDAAiD,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,mCAAmC,CAAC;IACxJ,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACzB,CAAC"}
@@ -0,0 +1,252 @@
1
+ /**
2
+ * Other Zelio boards on this machine, and how to file a card on one.
3
+ *
4
+ * A task can need a change in two repositories — a client here and the API it
5
+ * talks to there — and each repository runs its own board, with its own agents,
6
+ * worktrees and AGENTS.md. A card never spans both: the planner drafts one card
7
+ * per repository, and the card for the other one is filed on that board through
8
+ * its own API, so its allocator, validation and live updates see it exactly as
9
+ * if the person had typed it there.
10
+ *
11
+ * Boards find each other through a machine-wide registry, `~/.zelio/boards.json`
12
+ * (or `$ZELIO_HOME/boards.json`), that every board writes itself into when it
13
+ * starts listening. Nothing is configured: a repository whose board has run on
14
+ * this machine is a candidate, and the person decides per task whether a card
15
+ * goes there.
16
+ */
17
+ import { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, writeFileSync, } from "node:fs";
18
+ import { homedir } from "node:os";
19
+ import { basename, dirname, join, resolve } from "node:path";
20
+ /** The planner is told about this many boards at most; past it, the list is noise. */
21
+ export const MAX_LINKED_BOARDS = 5;
22
+ const MAX_DESCRIPTION_CHARS = 200;
23
+ export function defaultRegistryFile() {
24
+ const home = process.env.ZELIO_HOME?.trim() || join(homedir(), ".zelio");
25
+ return join(home, "boards.json");
26
+ }
27
+ function canonical(root) {
28
+ try {
29
+ return realpathSync(resolve(root));
30
+ }
31
+ catch {
32
+ return resolve(root);
33
+ }
34
+ }
35
+ export function readRegistry(file) {
36
+ let raw;
37
+ try {
38
+ raw = JSON.parse(readFileSync(file, "utf8"));
39
+ }
40
+ catch {
41
+ return [];
42
+ }
43
+ const boards = raw?.boards;
44
+ if (!Array.isArray(boards))
45
+ return [];
46
+ const entries = [];
47
+ for (const item of boards) {
48
+ if (!item || typeof item !== "object")
49
+ continue;
50
+ const entry = item;
51
+ if (typeof entry.root !== "string" || !entry.root)
52
+ continue;
53
+ if (!Number.isInteger(entry.port) || !Number.isInteger(entry.pid))
54
+ continue;
55
+ entries.push({
56
+ root: entry.root,
57
+ port: entry.port,
58
+ pid: entry.pid,
59
+ updatedAt: typeof entry.updatedAt === "string" ? entry.updatedAt : "",
60
+ });
61
+ }
62
+ return entries;
63
+ }
64
+ function writeRegistry(file, entries) {
65
+ mkdirSync(dirname(file), { recursive: true });
66
+ // Two boards starting together must not leave half a file for a third to read.
67
+ const temporary = `${file}.${process.pid}.tmp`;
68
+ writeFileSync(temporary, `${JSON.stringify({ boards: entries }, null, 2)}\n`, { mode: 0o600 });
69
+ renameSync(temporary, file);
70
+ }
71
+ /** Upserts this board by its repository root. Never throws: a board runs without it. */
72
+ export function registerBoard(file, board) {
73
+ try {
74
+ const root = canonical(board.root);
75
+ const others = readRegistry(file).filter((entry) => canonical(entry.root) !== root);
76
+ writeRegistry(file, [
77
+ ...others,
78
+ { root, port: board.port, pid: board.pid, updatedAt: new Date().toISOString() },
79
+ ]);
80
+ }
81
+ catch {
82
+ // Linking is a convenience; an unwritable home directory is not a failed start.
83
+ }
84
+ }
85
+ /**
86
+ * Forgets this board when it closes. Only its own row: another process that
87
+ * has since registered the same repository keeps its entry.
88
+ */
89
+ export function unregisterBoard(file, board) {
90
+ try {
91
+ const root = canonical(board.root);
92
+ const entries = readRegistry(file);
93
+ const kept = entries.filter((entry) => !(canonical(entry.root) === root && entry.pid === board.pid));
94
+ if (kept.length !== entries.length)
95
+ writeRegistry(file, kept);
96
+ }
97
+ catch {
98
+ // Same as registering: never the reason a board fails to close.
99
+ }
100
+ }
101
+ export function processAlive(pid) {
102
+ if (!Number.isInteger(pid) || pid <= 0)
103
+ return false;
104
+ try {
105
+ process.kill(pid, 0);
106
+ return true;
107
+ }
108
+ catch (error) {
109
+ // EPERM: the process exists and belongs to someone else.
110
+ return error.code === "EPERM";
111
+ }
112
+ }
113
+ function clipLine(text) {
114
+ const line = text.replace(/\s+/g, " ").trim();
115
+ return line.length > MAX_DESCRIPTION_CHARS
116
+ ? `${line.slice(0, MAX_DESCRIPTION_CHARS - 1)}…`
117
+ : line;
118
+ }
119
+ /** One line about a repository: its package description, else its README's first sentence. */
120
+ export function describeRepo(root) {
121
+ try {
122
+ const manifest = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
123
+ if (typeof manifest.description === "string" && manifest.description.trim()) {
124
+ return clipLine(manifest.description);
125
+ }
126
+ }
127
+ catch {
128
+ // No manifest, or not JSON: try the README.
129
+ }
130
+ for (const name of ["README.md", "readme.md", "README"]) {
131
+ try {
132
+ const lines = readFileSync(join(root, name), "utf8").split("\n");
133
+ const prose = lines.find((line) => {
134
+ const trimmed = line.trim();
135
+ return trimmed && !/^(#|!\[|\[!|<|```|---|===)/.test(trimmed);
136
+ });
137
+ if (prose)
138
+ return clipLine(prose);
139
+ }
140
+ catch {
141
+ // Next candidate.
142
+ }
143
+ }
144
+ return "";
145
+ }
146
+ /**
147
+ * Every other board the registry knows about whose repository still holds a
148
+ * `.zelio/` folder. Names are folder names; a second repository with the same
149
+ * folder name gets its parent's name in front, so a name always means one root.
150
+ */
151
+ export function listLinkedBoards(options) {
152
+ const self = canonical(options.self);
153
+ const alive = options.alive ?? processAlive;
154
+ const seen = new Set();
155
+ const roots = [];
156
+ for (const entry of readRegistry(options.file)) {
157
+ const root = canonical(entry.root);
158
+ if (root === self || seen.has(root))
159
+ continue;
160
+ if (!existsSync(join(root, ".zelio")))
161
+ continue;
162
+ seen.add(root);
163
+ roots.push({ ...entry, root });
164
+ }
165
+ const names = new Map();
166
+ for (const entry of roots) {
167
+ const name = basename(entry.root);
168
+ names.set(name, (names.get(name) ?? 0) + 1);
169
+ }
170
+ return roots
171
+ .map((entry) => {
172
+ const name = basename(entry.root);
173
+ return {
174
+ name: (names.get(name) ?? 0) > 1 ? `${basename(dirname(entry.root))}-${name}` : name,
175
+ root: entry.root,
176
+ description: describeRepo(entry.root),
177
+ port: entry.port,
178
+ running: alive(entry.pid),
179
+ };
180
+ })
181
+ .toSorted((a, b) => a.name.localeCompare(b.name))
182
+ .slice(0, MAX_LINKED_BOARDS);
183
+ }
184
+ /** A linked board refused or could not be reached; `status` is what this board answers with. */
185
+ export class LinkedBoardError extends Error {
186
+ status;
187
+ constructor(status, message) {
188
+ super(message);
189
+ this.status = status;
190
+ this.name = "LinkedBoardError";
191
+ }
192
+ }
193
+ async function errorOf(response) {
194
+ const body = (await response.json().catch(() => null));
195
+ return typeof body?.error === "string" ? body.error : `HTTP ${response.status}`;
196
+ }
197
+ /**
198
+ * Creates the card on the other board and confirms it there, the same two
199
+ * requests the dialog makes against its own board. The other board's token is
200
+ * read from its `.zelio/token`, which only this machine's user can read.
201
+ */
202
+ export async function fileOnLinkedBoard(board, ticket, fetchImpl = (input, init) => fetch(input, init)) {
203
+ if (!board.running) {
204
+ throw new LinkedBoardError(409, `The ${board.name} board is not running. Start zelio in ${board.root} and confirm again.`);
205
+ }
206
+ let token;
207
+ try {
208
+ token = readFileSync(join(board.root, ".zelio", "token"), "utf8").trim();
209
+ }
210
+ catch {
211
+ throw new LinkedBoardError(409, `The ${board.name} board has no token yet.`);
212
+ }
213
+ const base = `http://127.0.0.1:${board.port}`;
214
+ const headers = {
215
+ host: `127.0.0.1:${board.port}`,
216
+ "x-zelio-token": token,
217
+ "content-type": "application/json",
218
+ };
219
+ const unreachable = (cause) => new LinkedBoardError(502, `Could not reach the ${board.name} board on port ${board.port}: ${cause instanceof Error ? cause.message : String(cause)}`);
220
+ let created;
221
+ try {
222
+ created = await fetchImpl(`${base}/api/tickets`, {
223
+ method: "POST",
224
+ headers,
225
+ body: JSON.stringify(ticket),
226
+ });
227
+ }
228
+ catch (cause) {
229
+ throw unreachable(cause);
230
+ }
231
+ if (!created.ok) {
232
+ throw new LinkedBoardError(502, `The ${board.name} board refused the card: ${await errorOf(created)}`);
233
+ }
234
+ const { ticket: draft } = (await created.json());
235
+ let confirmed;
236
+ try {
237
+ confirmed = await fetchImpl(`${base}/api/tickets/${encodeURIComponent(draft.id)}/confirm`, {
238
+ method: "POST",
239
+ headers,
240
+ body: "{}",
241
+ });
242
+ }
243
+ catch (cause) {
244
+ throw unreachable(cause);
245
+ }
246
+ if (!confirmed.ok) {
247
+ throw new LinkedBoardError(502, `The ${board.name} board created ${draft.id} but would not start it: ${await errorOf(confirmed)}`);
248
+ }
249
+ const { ticket: started } = (await confirmed.json());
250
+ return started;
251
+ }
252
+ //# sourceMappingURL=linked-boards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linked-boards.js","sourceRoot":"","sources":["../../src/repo/linked-boards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EACL,UAAU,EACV,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsB7D,sFAAsF;AACtF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAEnC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAElC,MAAM,UAAU,mBAAmB;IACjC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;IACzE,OAAO,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,SAAS,CAAC,IAAY;IAC7B,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC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AgB,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC,UAAU,EAAE;YACzF,MAAM,EAAE,MAAM;YACd,OAAO;YACP,IAAI,EAAE,IAAI;SACX,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,WAAW,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IACD,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC;QAClB,MAAM,IAAI,gBAAgB,CACxB,GAAG,EACH,OAAO,KAAK,CAAC,IAAI,kBAAkB,KAAK,CAAC,EAAE,4BAA4B,MAAM,OAAO,CAAC,SAAS,CAAC,EAAE,CAClG,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,SAAS,CAAC,IAAI,EAAE,CAElD,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,233 @@
1
+ /**
2
+ * The activity trace both agents share. A run is a sequence of tool calls, and
3
+ * a row per call is the part a person can act on: what it touched, whether it
4
+ * worked, and what it said when it did not. Raw output is not a surface; it is
5
+ * evidence attached to the failed row that produced it.
6
+ */
7
+ /** Bounded, because a turn that ran for ten minutes is not ten minutes of rows. */
8
+ export const MAX_ACTIONS = 12;
9
+ /** The tail of a failed call is enough to name the cause; the head is context. */
10
+ export const MAX_ACTION_OUTPUT = 1200;
11
+ /** A row names the tests that broke, not every assertion in the file. */
12
+ export const MAX_FAILED_TESTS = 5;
13
+ /** Enough of the failure body to see the assertion, not the whole stack. */
14
+ export const MAX_TEST_EXCERPT = 400;
15
+ /** Long paths and commands are clipped: a trace row is one line, not a paragraph. */
16
+ export const clip = (value, max) => {
17
+ const text = value.replace(/\s+/g, " ").trim();
18
+ return text.length > max ? `${text.slice(0, max - 1)}…` : text;
19
+ };
20
+ /** Color codes are not part of a test's name. */
21
+ const ANSI = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
22
+ /**
23
+ * Vitest names a failing test on a `FAIL` line (default reporter) or a `×` line
24
+ * (verbose one). Both carry the file and the test path; a tsc error carries
25
+ * neither, which is how a compiler failure stays a plain failed row.
26
+ */
27
+ const FAILURE_LINE = /^\s*(?:FAIL|×|✗|✕)\s+(\S.*)$/;
28
+ const excerpt = (lines) => {
29
+ const body = lines.join("\n").trim();
30
+ return body.length > MAX_TEST_EXCERPT ? `${body.slice(0, MAX_TEST_EXCERPT - 1)}…` : body;
31
+ };
32
+ /**
33
+ * The tests a failed call named, in the order the reporter printed them. Only
34
+ * the harness's failed state reaches this function with output at all, so a
35
+ * `done` row full of failure-looking prose is never marked.
36
+ */
37
+ export function failedTests(output) {
38
+ const body = output?.replace(ANSI, "").trim();
39
+ if (!body)
40
+ return [];
41
+ const lines = body.split(/\r?\n/);
42
+ const found = [];
43
+ const seen = new Set();
44
+ for (let index = 0; index < lines.length; index += 1) {
45
+ const match = FAILURE_LINE.exec(lines[index] ?? "");
46
+ if (!match)
47
+ continue;
48
+ const name = clip((match[1] ?? "").replace(/\s+\d+(?:\.\d+)?m?s$/, ""), 160);
49
+ if (!name || seen.has(name))
50
+ continue;
51
+ const following = [];
52
+ for (let next = index + 1; next < lines.length; next += 1) {
53
+ const line = lines[next] ?? "";
54
+ if (FAILURE_LINE.test(line))
55
+ break;
56
+ // The body ends at the reporter's blank separator; the run summary that
57
+ // follows is not this test's excerpt.
58
+ if (!line.trim() && following.length > 0)
59
+ break;
60
+ following.push(line);
61
+ if (following.join("\n").length >= MAX_TEST_EXCERPT)
62
+ break;
63
+ }
64
+ const detail = excerpt(following);
65
+ if (!detail)
66
+ continue;
67
+ seen.add(name);
68
+ found.push({ name, excerpt: detail });
69
+ if (found.length >= MAX_FAILED_TESTS)
70
+ break;
71
+ }
72
+ return found;
73
+ }
74
+ /**
75
+ * A ticket command usually opens with `cd <worktree> &&` or `cd <worktree>;`.
76
+ * The worktree is already implied by the ticket, so drop it and keep the rest.
77
+ */
78
+ export const stripWorktreeCd = (command) => command
79
+ .trim()
80
+ .replace(/^cd\s+(?:"[^"]*"|'[^']*'|[^\s;&|]+)\s*(?:&&|;)\s*/, "")
81
+ .trim();
82
+ const text = (args, ...keys) => {
83
+ const fields = (args ?? {});
84
+ for (const key of keys) {
85
+ if (typeof fields[key] === "string")
86
+ return fields[key];
87
+ }
88
+ return "";
89
+ };
90
+ /**
91
+ * The tool's short name. An unknown tool keeps its own name, title-cased: the
92
+ * row still says what ran, and inventing a friendlier word would be a guess.
93
+ */
94
+ export function actionName(tool) {
95
+ if (!tool)
96
+ return "Think";
97
+ const words = tool.replace(/[_-]+/g, " ").trim();
98
+ return words ? words.charAt(0).toUpperCase() + words.slice(1) : "Tool";
99
+ }
100
+ /**
101
+ * What the call touched, in the tool's own terms: the command for a shell, the
102
+ * path for a file, the query for a search. Empty when the harness gave nothing
103
+ * worth showing, and the row then falls back to its label.
104
+ */
105
+ export function actionDetail(tool, args) {
106
+ switch (tool) {
107
+ case "read":
108
+ case "edit":
109
+ case "write":
110
+ return clip(text(args, "path", "file_path"), 120);
111
+ case "bash":
112
+ return clip(stripWorktreeCd(text(args, "command")), 160);
113
+ case "grep":
114
+ return clip(text(args, "pattern", "query"), 120);
115
+ case "find":
116
+ return clip(text(args, "pattern"), 120);
117
+ case "ls":
118
+ return clip(text(args, "path") || ".", 120);
119
+ case "web_search":
120
+ return clip(text(args, "query", "q"), 120);
121
+ case "web_fetch": {
122
+ const url = text(args, "url");
123
+ if (!url)
124
+ return "";
125
+ try {
126
+ return clip(new URL(url).host, 120);
127
+ }
128
+ catch {
129
+ return clip(url, 120);
130
+ }
131
+ }
132
+ default:
133
+ return "";
134
+ }
135
+ }
136
+ /**
137
+ * The raw file a file-tool call names, unclipped, so two reads of one file can
138
+ * be matched. Null for every other tool and for a file tool with no path.
139
+ */
140
+ export function actionPath(tool, args) {
141
+ switch (tool) {
142
+ case "read":
143
+ case "edit":
144
+ case "write": {
145
+ const path = text(args, "path", "file_path").trim();
146
+ return path || null;
147
+ }
148
+ default:
149
+ return null;
150
+ }
151
+ }
152
+ /**
153
+ * Tool results arrive as `content` parts. Only text is useful on the board, and
154
+ * a huge result is cut from the head: the last lines are what just happened.
155
+ */
156
+ export function toolResultText(result, max = 8_000) {
157
+ const content = result?.content;
158
+ if (!Array.isArray(content))
159
+ return "";
160
+ const body = content
161
+ .map((part) => {
162
+ if (!part || typeof part !== "object")
163
+ return "";
164
+ const { type, text: value } = part;
165
+ return type === "text" && typeof value === "string" ? value : "";
166
+ })
167
+ .join("");
168
+ return body.length > max ? body.slice(-max) : body;
169
+ }
170
+ let sequence = 0;
171
+ /**
172
+ * Correlated calls may run in parallel. Adapters without call IDs retain the
173
+ * legacy sequential behavior, closing the preceding row before starting one.
174
+ */
175
+ export function startAction(actions, start) {
176
+ const startedAt = start.startedAt ?? Date.now();
177
+ const closed = start.callId
178
+ ? actions
179
+ : finishAction(actions, { endedAt: startedAt, isError: false });
180
+ const action = {
181
+ id: start.callId ?? `action-${++sequence}`,
182
+ tool: start.tool,
183
+ name: actionName(start.tool),
184
+ detail: start.detail || "",
185
+ label: start.label,
186
+ state: "running",
187
+ startedAt,
188
+ };
189
+ return [...closed, action].slice(-MAX_ACTIONS);
190
+ }
191
+ /**
192
+ * Close the correlated row, or the latest legacy row. Only a failure keeps output: everything else is already
193
+ * said by the row itself, and a trace that carries every file body is a tail
194
+ * with extra steps.
195
+ */
196
+ export function finishAction(actions, end) {
197
+ const index = actions.findLastIndex((action) => action.state === "running" && (!end.callId || action.id === end.callId));
198
+ if (index === -1)
199
+ return actions;
200
+ const action = actions[index];
201
+ if (!action)
202
+ return actions;
203
+ const output = end.isError && end.output?.trim() ? end.output.trim().slice(-MAX_ACTION_OUTPUT) : "";
204
+ const next = actions.slice();
205
+ next[index] = {
206
+ ...action,
207
+ state: end.isError ? "failed" : "done",
208
+ endedAt: end.endedAt ?? Date.now(),
209
+ ...(output ? { output } : {}),
210
+ };
211
+ return next;
212
+ }
213
+ /**
214
+ * A run or turn that ends with a call still live is saying the process is gone,
215
+ * not that the call finished. The caller names the honest state — cancelled for
216
+ * a stop, failed for a process that died mid-call — and the row stops claiming
217
+ * to be running.
218
+ */
219
+ export function closeActions(actions, state, endedAt = Date.now(), output) {
220
+ const next = actions.map((action) => {
221
+ if (action.state !== "running")
222
+ return action;
223
+ const evidence = state === "failed" && output?.trim() ? output.trim().slice(-MAX_ACTION_OUTPUT) : "";
224
+ return {
225
+ ...action,
226
+ state,
227
+ endedAt,
228
+ ...(evidence ? { output: evidence } : {}),
229
+ };
230
+ });
231
+ return next;
232
+ }
233
+ //# sourceMappingURL=actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/run/actions.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,mFAAmF;AACnF,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,CAAC;AAE9B,kFAAkF;AAClF,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAEtC,yEAAyE;AACzE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,4EAA4E;AAC5E,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAEpC,qFAAqF;AACrF,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,KAAa,EAAE,GAAW,EAAU,EAAE;IACzD,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/C,OAAO,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AACjE,CAAC,CAAC;AAYF,iDAAiD;AACjD,MAAM,IAAI,GAAG,IAAI,MAAM,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;A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