zelio-cli 0.0.0-stage → 0.1.0-beta.10

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 (223) hide show
  1. package/README.md +71 -2
  2. package/dist/attachments.js +121 -0
  3. package/dist/attachments.js.map +1 -0
  4. package/dist/cli-main.js +521 -0
  5. package/dist/cli-main.js.map +1 -0
  6. package/dist/cli.js +22 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/cloud/account.js +109 -0
  9. package/dist/cloud/account.js.map +1 -0
  10. package/dist/cloud/board.js +311 -0
  11. package/dist/cloud/board.js.map +1 -0
  12. package/dist/cloud/command.js +265 -0
  13. package/dist/cloud/command.js.map +1 -0
  14. package/dist/cloud/config.js +132 -0
  15. package/dist/cloud/config.js.map +1 -0
  16. package/dist/cloud/credentials.js +134 -0
  17. package/dist/cloud/credentials.js.map +1 -0
  18. package/dist/cloud/login.js +166 -0
  19. package/dist/cloud/login.js.map +1 -0
  20. package/dist/cloud/pair.js +110 -0
  21. package/dist/cloud/pair.js.map +1 -0
  22. package/dist/cloud/pkce.js +16 -0
  23. package/dist/cloud/pkce.js.map +1 -0
  24. package/dist/cloud/push-nudge.js +65 -0
  25. package/dist/cloud/push-nudge.js.map +1 -0
  26. package/dist/cloud/relay.js +134 -0
  27. package/dist/cloud/relay.js.map +1 -0
  28. package/dist/cloud/token.js +66 -0
  29. package/dist/cloud/token.js.map +1 -0
  30. package/dist/cloud/tunnel.js +474 -0
  31. package/dist/cloud/tunnel.js.map +1 -0
  32. package/dist/db/db.js +1838 -0
  33. package/dist/db/db.js.map +1 -0
  34. package/dist/db/lifecycle.js +146 -0
  35. package/dist/db/lifecycle.js.map +1 -0
  36. package/dist/limits.js +35 -0
  37. package/dist/limits.js.map +1 -0
  38. package/dist/metrics.js +30 -0
  39. package/dist/metrics.js.map +1 -0
  40. package/dist/orchestrator/area-notes.js +87 -0
  41. package/dist/orchestrator/area-notes.js.map +1 -0
  42. package/dist/orchestrator/claude-session.js +208 -0
  43. package/dist/orchestrator/claude-session.js.map +1 -0
  44. package/dist/orchestrator/codex-session.js +327 -0
  45. package/dist/orchestrator/codex-session.js.map +1 -0
  46. package/dist/orchestrator/contract.js +189 -0
  47. package/dist/orchestrator/contract.js.map +1 -0
  48. package/dist/orchestrator/explore.js +176 -0
  49. package/dist/orchestrator/explore.js.map +1 -0
  50. package/dist/orchestrator/new-task-prompt.js +51 -0
  51. package/dist/orchestrator/new-task-prompt.js.map +1 -0
  52. package/dist/orchestrator/pi-session.js +234 -0
  53. package/dist/orchestrator/pi-session.js.map +1 -0
  54. package/dist/orchestrator/prompt.js +110 -0
  55. package/dist/orchestrator/prompt.js.map +1 -0
  56. package/dist/orchestrator/research.js +193 -0
  57. package/dist/orchestrator/research.js.map +1 -0
  58. package/dist/orchestrator/retrieval.js +333 -0
  59. package/dist/orchestrator/retrieval.js.map +1 -0
  60. package/dist/orchestrator/runtime.js +1217 -0
  61. package/dist/orchestrator/runtime.js.map +1 -0
  62. package/dist/orchestrator/session.js +2 -0
  63. package/dist/orchestrator/session.js.map +1 -0
  64. package/dist/orchestrator/types.js +2 -0
  65. package/dist/orchestrator/types.js.map +1 -0
  66. package/dist/orchestrator/web.js +276 -0
  67. package/dist/orchestrator/web.js.map +1 -0
  68. package/dist/repo/code-map.js +152 -0
  69. package/dist/repo/code-map.js.map +1 -0
  70. package/dist/repo/index.js +188 -0
  71. package/dist/repo/index.js.map +1 -0
  72. package/dist/repo/instructions.js +58 -0
  73. package/dist/repo/instructions.js.map +1 -0
  74. package/dist/repo/linked-boards.js +149 -0
  75. package/dist/repo/linked-boards.js.map +1 -0
  76. package/dist/repo/project-repos.js +78 -0
  77. package/dist/repo/project-repos.js.map +1 -0
  78. package/dist/run/actions.js +257 -0
  79. package/dist/run/actions.js.map +1 -0
  80. package/dist/run/auto-review.js +116 -0
  81. package/dist/run/auto-review.js.map +1 -0
  82. package/dist/run/bash-guard.js +183 -0
  83. package/dist/run/bash-guard.js.map +1 -0
  84. package/dist/run/claude-runtime.js +284 -0
  85. package/dist/run/claude-runtime.js.map +1 -0
  86. package/dist/run/claude-stream.js +306 -0
  87. package/dist/run/claude-stream.js.map +1 -0
  88. package/dist/run/codex-client.js +213 -0
  89. package/dist/run/codex-client.js.map +1 -0
  90. package/dist/run/codex-planner-config.js +26 -0
  91. package/dist/run/codex-planner-config.js.map +1 -0
  92. package/dist/run/codex-runtime.js +469 -0
  93. package/dist/run/codex-runtime.js.map +1 -0
  94. package/dist/run/consult.js +109 -0
  95. package/dist/run/consult.js.map +1 -0
  96. package/dist/run/context.js +87 -0
  97. package/dist/run/context.js.map +1 -0
  98. package/dist/run/developer-sandbox.js +67 -0
  99. package/dist/run/developer-sandbox.js.map +1 -0
  100. package/dist/run/diff.js +238 -0
  101. package/dist/run/diff.js.map +1 -0
  102. package/dist/run/evidence.js +48 -0
  103. package/dist/run/evidence.js.map +1 -0
  104. package/dist/run/finish.js +430 -0
  105. package/dist/run/finish.js.map +1 -0
  106. package/dist/run/handoff.js +51 -0
  107. package/dist/run/handoff.js.map +1 -0
  108. package/dist/run/harness-runtime.js +31 -0
  109. package/dist/run/harness-runtime.js.map +1 -0
  110. package/dist/run/harnesses.js +293 -0
  111. package/dist/run/harnesses.js.map +1 -0
  112. package/dist/run/issue.js +79 -0
  113. package/dist/run/issue.js.map +1 -0
  114. package/dist/run/keep-awake.js +58 -0
  115. package/dist/run/keep-awake.js.map +1 -0
  116. package/dist/run/lead.js +183 -0
  117. package/dist/run/lead.js.map +1 -0
  118. package/dist/run/manager.js +2737 -0
  119. package/dist/run/manager.js.map +1 -0
  120. package/dist/run/mentions.js +35 -0
  121. package/dist/run/mentions.js.map +1 -0
  122. package/dist/run/merge-watch.js +425 -0
  123. package/dist/run/merge-watch.js.map +1 -0
  124. package/dist/run/models.js +88 -0
  125. package/dist/run/models.js.map +1 -0
  126. package/dist/run/phases.js +23 -0
  127. package/dist/run/phases.js.map +1 -0
  128. package/dist/run/pi-packages.js +72 -0
  129. package/dist/run/pi-packages.js.map +1 -0
  130. package/dist/run/pi-rpc.js +464 -0
  131. package/dist/run/pi-rpc.js.map +1 -0
  132. package/dist/run/piped-check.js +56 -0
  133. package/dist/run/piped-check.js.map +1 -0
  134. package/dist/run/pr-checks.js +67 -0
  135. package/dist/run/pr-checks.js.map +1 -0
  136. package/dist/run/pr-merge.js +121 -0
  137. package/dist/run/pr-merge.js.map +1 -0
  138. package/dist/run/profiles.js +43 -0
  139. package/dist/run/profiles.js.map +1 -0
  140. package/dist/run/prompt.js +405 -0
  141. package/dist/run/prompt.js.map +1 -0
  142. package/dist/run/pull-request.js +23 -0
  143. package/dist/run/pull-request.js.map +1 -0
  144. package/dist/run/red-check.js +130 -0
  145. package/dist/run/red-check.js.map +1 -0
  146. package/dist/run/result-tool.js +93 -0
  147. package/dist/run/result-tool.js.map +1 -0
  148. package/dist/run/result.js +113 -0
  149. package/dist/run/result.js.map +1 -0
  150. package/dist/run/retro.js +346 -0
  151. package/dist/run/retro.js.map +1 -0
  152. package/dist/run/settings.js +28 -0
  153. package/dist/run/settings.js.map +1 -0
  154. package/dist/run/skills.js +146 -0
  155. package/dist/run/skills.js.map +1 -0
  156. package/dist/run/tests-first.js +146 -0
  157. package/dist/run/tests-first.js.map +1 -0
  158. package/dist/run/thinking.js +41 -0
  159. package/dist/run/thinking.js.map +1 -0
  160. package/dist/run/types.js +2 -0
  161. package/dist/run/types.js.map +1 -0
  162. package/dist/run/watchdog.js +266 -0
  163. package/dist/run/watchdog.js.map +1 -0
  164. package/dist/run/workflow.js +277 -0
  165. package/dist/run/workflow.js.map +1 -0
  166. package/dist/run/worktree.js +354 -0
  167. package/dist/run/worktree.js.map +1 -0
  168. package/dist/server/app.js +3286 -0
  169. package/dist/server/app.js.map +1 -0
  170. package/dist/server/auth.js +93 -0
  171. package/dist/server/auth.js.map +1 -0
  172. package/dist/server/demo.js +96 -0
  173. package/dist/server/demo.js.map +1 -0
  174. package/dist/server/idempotency.js +104 -0
  175. package/dist/server/idempotency.js.map +1 -0
  176. package/dist/server/port.js +36 -0
  177. package/dist/server/port.js.map +1 -0
  178. package/dist/server/principal.js +93 -0
  179. package/dist/server/principal.js.map +1 -0
  180. package/dist/server/provider-auth.js +206 -0
  181. package/dist/server/provider-auth.js.map +1 -0
  182. package/dist/server/repo-picker.js +18 -0
  183. package/dist/server/repo-picker.js.map +1 -0
  184. package/dist/server/terminal.js +285 -0
  185. package/dist/server/terminal.js.map +1 -0
  186. package/dist/setup/components.js +98 -0
  187. package/dist/setup/components.js.map +1 -0
  188. package/dist/setup/config.js +71 -0
  189. package/dist/setup/config.js.map +1 -0
  190. package/dist/setup/ink-ui.js +189 -0
  191. package/dist/setup/ink-ui.js.map +1 -0
  192. package/dist/setup/onboarding.js +157 -0
  193. package/dist/setup/onboarding.js.map +1 -0
  194. package/dist/setup/run.js +69 -0
  195. package/dist/setup/run.js.map +1 -0
  196. package/dist/skills.js +151 -0
  197. package/dist/skills.js.map +1 -0
  198. package/dist/ticket-cli.js +157 -0
  199. package/dist/ticket-cli.js.map +1 -0
  200. package/dist/version.js +13 -0
  201. package/dist/version.js.map +1 -0
  202. package/dist/voice/index.js +69 -0
  203. package/dist/voice/index.js.map +1 -0
  204. package/dist/voice/moonshine.js +247 -0
  205. package/dist/voice/moonshine.js.map +1 -0
  206. package/dist/voice/wav.js +54 -0
  207. package/dist/voice/wav.js.map +1 -0
  208. package/dist/voice/whisper.js +491 -0
  209. package/dist/voice/whisper.js.map +1 -0
  210. package/dist/web/assets/index-TN5sUF2z.css +1 -0
  211. package/dist/web/assets/index-vB3Cucuc.js +258 -0
  212. package/dist/web/icons/apple-touch-icon.png +0 -0
  213. package/dist/web/icons/icon-192.png +0 -0
  214. package/dist/web/icons/icon-512.png +0 -0
  215. package/dist/web/icons/maskable-512.png +0 -0
  216. package/dist/web/index.html +21 -0
  217. package/dist/web/manifest.webmanifest +30 -0
  218. package/dist/web/sw.js +185 -0
  219. package/media/board.png +0 -0
  220. package/media/mobile.png +0 -0
  221. package/media/new-task.png +0 -0
  222. package/media/review.png +0 -0
  223. package/package.json +105 -4
@@ -0,0 +1,430 @@
1
+ import { execFile, spawn } from "node:child_process";
2
+ import { createHash } from "node:crypto";
3
+ import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { promisify } from "node:util";
7
+ const execFileAsync = promisify(execFile);
8
+ const GIT_TIMEOUT_MS = 15_000;
9
+ const GH_TIMEOUT_MS = 30_000;
10
+ const PUSH_TIMEOUT_MS = 60_000;
11
+ const ERROR_TAIL_CHARS = 1_000;
12
+ const KILL_GRACE_MS = 1_000;
13
+ /** How long one Verify check may run before the board stops it and calls it timed out. */
14
+ export const CHECK_TIMEOUT_MS = 240_000;
15
+ const SECRET_EXAMPLES = new Set([".env.example", ".env.sample", ".env.template"]);
16
+ /**
17
+ * Runs the checks one after another in `cwd` and stops at the first one that
18
+ * fails, so later checks never run against a tree already known to be broken.
19
+ * A check that cannot start is a failed result, never a thrown error.
20
+ */
21
+ export async function runChecks(cwd, checks, options = {}) {
22
+ const results = [];
23
+ for (const check of checks) {
24
+ let result = await runCheck(cwd, check, options);
25
+ if (!result.passed &&
26
+ options.rerunFailed &&
27
+ !result.timedOut &&
28
+ !options.signal?.aborted &&
29
+ result.exitCode !== null) {
30
+ const rerun = await runCheck(cwd, check, options);
31
+ result = { ...rerun, flaky: rerun.passed };
32
+ }
33
+ results.push(result);
34
+ if (!result.passed)
35
+ break;
36
+ }
37
+ return results;
38
+ }
39
+ /**
40
+ * A fingerprint of the ticket's uncommitted work: tracked changes, the status
41
+ * listing, and the bytes of every untracked file. Two equal fingerprints mean
42
+ * the developer left the work exactly as it was. Null when it cannot be read,
43
+ * which callers must treat as changed, never as unchanged.
44
+ */
45
+ export async function worktreeFingerprint(cwd) {
46
+ try {
47
+ const status = await git(cwd, ["status", "--porcelain", "-z", "--untracked-files=all"]);
48
+ const hash = createHash("sha256");
49
+ hash.update(await git(cwd, ["diff", "HEAD", "--binary"]));
50
+ hash.update(status);
51
+ for (const entry of status.split("\0")) {
52
+ if (!entry.startsWith("?? "))
53
+ continue;
54
+ hash.update(await readFile(join(cwd, entry.slice(3))).catch(() => "missing"));
55
+ }
56
+ return hash.digest("hex");
57
+ }
58
+ catch {
59
+ return null;
60
+ }
61
+ }
62
+ function runCheck(cwd, check, options) {
63
+ const timeoutMs = options.timeoutMs ?? CHECK_TIMEOUT_MS;
64
+ const maxOutput = options.maxOutput ?? 4_000;
65
+ const env = options.env ?? process.env;
66
+ const started = Date.now();
67
+ return new Promise((resolve) => {
68
+ let output = "";
69
+ let exitCode = null;
70
+ let timedOut = false;
71
+ let aborted = false;
72
+ let failedToStart = false;
73
+ let settled = false;
74
+ let child;
75
+ let timer;
76
+ let fallback;
77
+ function finish() {
78
+ if (settled)
79
+ return;
80
+ settled = true;
81
+ clearTimeout(timer);
82
+ clearTimeout(fallback);
83
+ options.signal?.removeEventListener("abort", onAbort);
84
+ if (aborted)
85
+ output += "\naborted";
86
+ resolve({
87
+ label: check.label,
88
+ command: check.command,
89
+ passed: !failedToStart && !timedOut && !aborted && exitCode === 0,
90
+ exitCode,
91
+ timedOut,
92
+ output: output.slice(-maxOutput),
93
+ durationMs: Date.now() - started,
94
+ });
95
+ }
96
+ // Kill the whole group so a `sh -c` wrapper cannot leave its children
97
+ // running. If 'close' never arrives (a stuck pipe), finish anyway.
98
+ function kill() {
99
+ if (child.pid) {
100
+ try {
101
+ process.kill(-child.pid, "SIGKILL");
102
+ }
103
+ catch {
104
+ try {
105
+ child.kill("SIGKILL");
106
+ }
107
+ catch {
108
+ /* already gone */
109
+ }
110
+ }
111
+ }
112
+ fallback = setTimeout(finish, KILL_GRACE_MS);
113
+ }
114
+ function onAbort() {
115
+ aborted = true;
116
+ kill();
117
+ }
118
+ if (options.signal?.aborted) {
119
+ aborted = true;
120
+ finish();
121
+ return;
122
+ }
123
+ try {
124
+ child = spawn("/bin/sh", ["-c", check.command], {
125
+ cwd,
126
+ env,
127
+ detached: true,
128
+ stdio: ["ignore", "pipe", "pipe"],
129
+ });
130
+ }
131
+ catch (error) {
132
+ output += `${errorMessage(error)}\n`;
133
+ failedToStart = true;
134
+ finish();
135
+ return;
136
+ }
137
+ const onData = (chunk) => {
138
+ output += chunk.toString("utf8");
139
+ if (output.length > maxOutput * 2)
140
+ output = output.slice(-maxOutput);
141
+ };
142
+ child.stdout?.on("data", onData);
143
+ child.stderr?.on("data", onData);
144
+ child.on("error", (error) => {
145
+ output += `${error.message}\n`;
146
+ failedToStart = true;
147
+ finish();
148
+ });
149
+ child.on("close", (code) => {
150
+ exitCode = code;
151
+ finish();
152
+ });
153
+ timer = setTimeout(() => {
154
+ timedOut = true;
155
+ kill();
156
+ }, timeoutMs);
157
+ options.signal?.addEventListener("abort", onAbort, { once: true });
158
+ });
159
+ }
160
+ /**
161
+ * The text the developer agent reads when checks fail: one block per failed
162
+ * check, with its exit code or timeout and its output. Empty when all passed.
163
+ */
164
+ export function failureReport(results) {
165
+ return results
166
+ .filter((result) => !result.passed)
167
+ .map((result) => {
168
+ // A timeout is not a failing test: the board stopped a check that was
169
+ // still running, and the report says so instead of calling it failed.
170
+ const how = result.timedOut
171
+ ? `timed out after ${(result.durationMs / 1000).toFixed(1)}s`
172
+ : result.exitCode === null
173
+ ? "did not finish"
174
+ : `failed (exit code ${result.exitCode})`;
175
+ const fence = result.output.includes("```") ? "````" : "```";
176
+ return `Check "${result.label}" ${how}: ${result.command}\n\n${fence}text\n${result.output}\n${fence}`;
177
+ })
178
+ .join("\n\n");
179
+ }
180
+ /**
181
+ * Paths a ticket commit must never carry: env files with secrets, key
182
+ * material, and the board's own state directory. Example env files are fine.
183
+ */
184
+ export function isSecretPath(path) {
185
+ const segments = path.split(/[\\/]/).filter(Boolean);
186
+ const name = segments[segments.length - 1] ?? "";
187
+ if (segments.includes(".zelio"))
188
+ return true;
189
+ if (name === ".env" || (name.startsWith(".env.") && !SECRET_EXAMPLES.has(name)))
190
+ return true;
191
+ if (/\.(pem|key|p12|pfx)$/.test(name))
192
+ return true;
193
+ return /^id_(rsa|ed25519|ecdsa)/.test(name);
194
+ }
195
+ /**
196
+ * Stages everything except secret-looking files and commits what is left. The
197
+ * refused files stay untracked in the working tree, so the person can decide
198
+ * about them; nothing here ever pushes them.
199
+ */
200
+ export async function commitTicketWork(cwd, message) {
201
+ const refused = [];
202
+ try {
203
+ await git(cwd, ["add", "-A"]);
204
+ const staged = (await git(cwd, ["diff", "--cached", "--name-only", "-z"]))
205
+ .split("\0")
206
+ .filter(Boolean);
207
+ for (const path of staged) {
208
+ if (!isSecretPath(path))
209
+ continue;
210
+ await git(cwd, ["reset", "-q", "--", path]);
211
+ refused.push(path);
212
+ }
213
+ if (staged.every((path) => refused.includes(path))) {
214
+ return { committed: false, head: await headOf(cwd), refused, error: null };
215
+ }
216
+ // Keep the repo's own identity when it has one; the fallback only fills in
217
+ // what a fresh machine lacks.
218
+ const hasIdentity = await git(cwd, ["config", "user.email"]).then((value) => value.trim() !== "", () => false);
219
+ const identity = hasIdentity
220
+ ? []
221
+ : ["-c", "user.name=zelio", "-c", "user.email=zelio@localhost"];
222
+ await git(cwd, [...identity, "commit", "-m", message]);
223
+ return { committed: true, head: await headOf(cwd), refused, error: null };
224
+ }
225
+ catch (error) {
226
+ return {
227
+ committed: false,
228
+ head: await headOf(cwd),
229
+ refused,
230
+ error: tail(errorText(error), ERROR_TAIL_CHARS),
231
+ };
232
+ }
233
+ }
234
+ /**
235
+ * Whether the ticket has work to commit or commits past its base. The base is
236
+ * the remote's default branch when it resolves, else the local main. With no
237
+ * base to compare against, a checkout that has a HEAD counts as changed, so an
238
+ * unknown base never blocks the board. Never throws.
239
+ */
240
+ export async function hasTicketChanges(cwd, base) {
241
+ try {
242
+ // A refused secret is never committed, so it is not a change the ticket can ship.
243
+ const changed = (await git(cwd, ["status", "--porcelain", "-z", "--untracked-files=all"]))
244
+ .split("\0")
245
+ .filter((entry) => entry.length > 3)
246
+ .map((entry) => entry.slice(3))
247
+ .some((path) => !isSecretPath(path));
248
+ if (changed)
249
+ return true;
250
+ const ref = base ?? (await baseRef(cwd));
251
+ if (!ref)
252
+ return (await headOf(cwd)) !== null;
253
+ const count = await git(cwd, ["rev-list", "--count", `${ref}..HEAD`]);
254
+ return Number(count.trim()) > 0;
255
+ }
256
+ catch {
257
+ return (await headOf(cwd)) !== null;
258
+ }
259
+ }
260
+ /**
261
+ * The ticket's diff since it branched from its base (the merge-base), for the
262
+ * lead and the automatic review: commits the base gained since never show, and committed and uncommitted
263
+ * tracked changes both show. The base is the ref whose fork point with HEAD is
264
+ * nearest, so a local main carrying an unpushed commit is not mistaken for the
265
+ * remote's older tip. Untracked files are named, never read, and
266
+ * secret-looking paths are left out of both. Truncated to `maxChars`, with the
267
+ * untracked list kept at the end. Never throws; an error reads as no diff.
268
+ */
269
+ export async function ticketDiffWithBase(cwd, maxChars = 12_000) {
270
+ try {
271
+ // Compare with where the ticket branched, not the base's tip: a commit that
272
+ // lands on the base after the branch was cut would otherwise read as this
273
+ // ticket reverting it, and a reviewer would ask the developer to undo a
274
+ // change it never made.
275
+ const ref = await baseRef(cwd);
276
+ const base = ref ? (await git(cwd, ["merge-base", "HEAD", ref])).trim() || null : null;
277
+ const start = base ?? "HEAD";
278
+ const status = await git(cwd, ["status", "--porcelain", "-z", "--untracked-files=all"]);
279
+ const untracked = status
280
+ .split("\0")
281
+ .filter((entry) => entry.startsWith("?? "))
282
+ .map((entry) => entry.slice(3))
283
+ .filter((path) => !isSecretPath(path));
284
+ const tracked = (await git(cwd, ["diff", "--name-only", "-z", start]))
285
+ .split("\0")
286
+ .filter(Boolean)
287
+ .filter((path) => !isSecretPath(path));
288
+ const diff = tracked.length === 0 ? "" : await git(cwd, ["diff", start, "--", ...tracked]);
289
+ const marker = "\n… (diff truncated)";
290
+ const listing = untracked.length ? `Untracked: ${untracked.slice(0, 50).join(", ")}` : "";
291
+ const room = Math.max(0, maxChars - listing.length - marker.length - 1);
292
+ const body = diff.length > room ? `${diff.slice(0, room)}${marker}` : diff;
293
+ return { diff: [body.trimEnd(), listing].filter(Boolean).join("\n"), base };
294
+ }
295
+ catch {
296
+ return { diff: "", base: null };
297
+ }
298
+ }
299
+ export async function ticketDiff(cwd, maxChars = 12_000) {
300
+ return (await ticketDiffWithBase(cwd, maxChars)).diff;
301
+ }
302
+ /**
303
+ * The base the ticket is compared with: of `origin/<default>`, local `main`
304
+ * and `master`, the one whose fork point with HEAD is nearest. A local main
305
+ * can carry a commit the remote has not received; preferring the remote then
306
+ * would put that commit in the ticket's diff, so the nearer fork point wins
307
+ * and the remote only breaks a tie.
308
+ */
309
+ export async function baseRef(cwd) {
310
+ const name = await defaultBase(cwd, "origin");
311
+ const candidates = [...new Set([`origin/${name}`, "main", "master"])];
312
+ let best = null;
313
+ for (const candidate of candidates) {
314
+ const base = await git(cwd, ["merge-base", "HEAD", candidate]).then((value) => value.trim(), () => "");
315
+ if (!base)
316
+ continue;
317
+ const ahead = await git(cwd, ["rev-list", "--count", `${base}..HEAD`]).then((value) => Number(value.trim()), () => Number.NaN);
318
+ if (!Number.isFinite(ahead))
319
+ continue;
320
+ if (best === null || ahead < best.ahead)
321
+ best = { ref: candidate, ahead };
322
+ }
323
+ return best?.ref ?? null;
324
+ }
325
+ /**
326
+ * Pushes the ticket branch and makes sure a pull request exists for it. A push
327
+ * failure means nothing was published; a `gh` failure after a good push means
328
+ * the branch is on the remote and only the PR is missing.
329
+ */
330
+ export async function publishBranch(cwd, branch, pr, options = {}) {
331
+ const remote = options.remote ?? "origin";
332
+ try {
333
+ await git(cwd, ["push", "-u", remote, branch], options.timeoutMs ?? PUSH_TIMEOUT_MS);
334
+ }
335
+ catch (error) {
336
+ return {
337
+ pushed: false,
338
+ prUrl: null,
339
+ error: tail(redactCredentials(errorText(error)), ERROR_TAIL_CHARS),
340
+ };
341
+ }
342
+ try {
343
+ const prUrl = await pullRequestUrl(cwd, branch, pr, { ...options, remote });
344
+ return { pushed: true, prUrl, error: null };
345
+ }
346
+ catch (error) {
347
+ return {
348
+ pushed: true,
349
+ prUrl: null,
350
+ error: `pull request: ${tail(redactCredentials(errorText(error)), ERROR_TAIL_CHARS)}`,
351
+ };
352
+ }
353
+ }
354
+ async function pullRequestUrl(cwd, branch, pr, options) {
355
+ const gh = options.gh ?? "gh";
356
+ const env = { ...process.env, GH_PROMPT_DISABLED: "1" };
357
+ const existing = await execFileAsync(gh, ["pr", "view", branch, "--json", "url", "--jq", ".url"], { cwd, env, timeout: GH_TIMEOUT_MS }).then(({ stdout }) => urlIn(String(stdout)), () => null);
358
+ if (existing)
359
+ return existing;
360
+ const dir = await mkdtemp(join(tmpdir(), "zelio-pr-"));
361
+ try {
362
+ const bodyFile = join(dir, "body.md");
363
+ await writeFile(bodyFile, pr.body, "utf8");
364
+ const base = options.base ?? (await defaultBase(cwd, options.remote ?? "origin"));
365
+ const { stdout } = await execFileAsync(gh, [
366
+ "pr",
367
+ "create",
368
+ "--head",
369
+ branch,
370
+ "--base",
371
+ base,
372
+ "--title",
373
+ pr.title,
374
+ "--body-file",
375
+ bodyFile,
376
+ ], { cwd, env, timeout: GH_TIMEOUT_MS });
377
+ const url = urlIn(String(stdout));
378
+ if (!url)
379
+ throw new Error("gh did not print a pull request URL");
380
+ return url;
381
+ }
382
+ finally {
383
+ await rm(dir, { recursive: true, force: true });
384
+ }
385
+ }
386
+ /** The remote's default branch, read from its HEAD ref; "main" when unknown. */
387
+ async function defaultBase(cwd, remote) {
388
+ const ref = await git(cwd, ["symbolic-ref", "--short", `refs/remotes/${remote}/HEAD`]).then((value) => value.trim(), () => "");
389
+ const prefix = `${remote}/`;
390
+ const name = ref.startsWith(prefix) ? ref.slice(prefix.length) : ref;
391
+ return name || "main";
392
+ }
393
+ /** Hides credentials that git, gh or a remote URL may have echoed back. */
394
+ export function redactCredentials(text) {
395
+ return text
396
+ .replace(/https:\/\/[^\s/]+@/g, "https://***@")
397
+ .replace(/\bgh[pousr]_[A-Za-z0-9]{20,}\b/g, "***")
398
+ .replace(/\bgithub_pat_[A-Za-z0-9_]{20,}\b/g, "***");
399
+ }
400
+ async function git(cwd, args, timeout = GIT_TIMEOUT_MS) {
401
+ const { stdout } = await execFileAsync("git", ["-C", cwd, ...args], {
402
+ timeout,
403
+ maxBuffer: 10 * 1024 * 1024,
404
+ });
405
+ return String(stdout);
406
+ }
407
+ async function headOf(cwd) {
408
+ return git(cwd, ["rev-parse", "HEAD"]).then((value) => value.trim() || null, () => null);
409
+ }
410
+ function urlIn(text) {
411
+ return text.match(/https:\/\/\S+/)?.[0] ?? null;
412
+ }
413
+ function errorMessage(error) {
414
+ return error instanceof Error ? error.message : String(error);
415
+ }
416
+ /**
417
+ * git and gh put their reason in stderr, but a failing commit or push hook
418
+ * often prints to stdout; both are kept, and the message is the fallback.
419
+ */
420
+ export function errorText(error) {
421
+ const failed = error;
422
+ const parts = [failed?.stdout, failed?.stderr]
423
+ .map((value) => (typeof value === "string" ? value.trim() : ""))
424
+ .filter(Boolean);
425
+ return parts.length > 0 ? parts.join("\n") : errorMessage(error);
426
+ }
427
+ export function tail(text, length) {
428
+ return text.length > length ? text.slice(-length) : text;
429
+ }
430
+ //# sourceMappingURL=finish.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"finish.js","sourceRoot":"","sources":["../../src/run/finish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ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SAAS,KAAK,CAAC,IAAY;IACzB,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAClD,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,MAAM,MAAM,GAAG,KAAsD,CAAC;IACtE,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;SAC3C,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SAC/D,MAAM,CAAC,OAAO,CAAC,CAAC;IACnB,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,IAAY,EAAE,MAAc;IAC/C,OAAO,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { basename } from "node:path";
2
+ export function handoffHarness(command) {
3
+ const name = basename(command?.trim() || "");
4
+ return name === "claude" || name === "codex" ? name : null;
5
+ }
6
+ /** POSIX single quoting: safe in zsh and bash for any text, newlines included. */
7
+ export function shellQuote(value) {
8
+ return `'${value.replaceAll("'", `'\\''`)}'`;
9
+ }
10
+ /**
11
+ * The first message the resumed agent reads. The board's run told it about
12
+ * report_result and board verification; neither applies once the person has
13
+ * the ticket, so this says what does.
14
+ */
15
+ export function handoffBrief(ticket, resumed) {
16
+ const id = ticket.id;
17
+ const lines = resumed
18
+ ? [
19
+ `The person has taken Zelio ticket ${id} into their own terminal. The board stopped its run and will not start another while you have it.`,
20
+ ]
21
+ : [
22
+ `You are working Zelio ticket ${id}: ${ticket.title}`,
23
+ "",
24
+ `Goal: ${ticket.goal}`,
25
+ `Acceptance: ${ticket.acceptance}`,
26
+ "",
27
+ "The person handed this ticket to you from the board; the board will not run its own agent while you have it.",
28
+ ];
29
+ lines.push("", "Keep the card current with the zelio CLI (it is on PATH and already authorised for this ticket):", `- progress: zelio ticket comment ${id} --type comment --text "..."`, `- a question for the person: zelio ticket comment ${id} --type blocker --text "..."`, `- finished: zelio ticket comment ${id} --type done --text "<summary>. Verification: <command you ran>"`, ` then: zelio ticket status ${id} --to review`, "", "Ignore earlier instructions about report_result or the board running verify checks; they belonged to the board's run. Wait for the person before acting.");
30
+ return lines.join("\n");
31
+ }
32
+ /**
33
+ * One line the person pastes into a terminal. It carries the ticket token in
34
+ * the environment because the board's run environment died with its process.
35
+ */
36
+ export function handoffCommand(input) {
37
+ const env = [
38
+ `ZELIO_TICKET_ID=${shellQuote(input.ticketId)}`,
39
+ `ZELIO_BOARD_URL=${shellQuote(input.boardUrl)}`,
40
+ `ZELIO_TICKET_TOKEN=${shellQuote(input.token)}`,
41
+ ];
42
+ if (input.agentPath)
43
+ env.push(`PATH=${shellQuote(input.agentPath)}:"$PATH"`);
44
+ const resume = input.session
45
+ ? input.harness === "claude"
46
+ ? `claude --resume ${shellQuote(input.session)}`
47
+ : `codex resume ${shellQuote(input.session)}`
48
+ : input.harness;
49
+ return `cd ${shellQuote(input.worktree)} && ${env.join(" ")} ${resume} ${shellQuote(input.brief)}`;
50
+ }
51
+ //# sourceMappingURL=handoff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handoff.js","sourceR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KAAK,CAAC,QAAQ,CAAC,EAAE;QAC/C,mBAAmB,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;QAC/C,sBAAsB,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;KAChD,CAAC;IACF,IAAI,KAAK,CAAC,SAAS;QAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,UAAU,CAAC,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IAC7E,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO;QAC1B,CAAC,CAAC,KAAK,CAAC,OAAO,KAAK,QAAQ;YAC1B,CAAC,CAAC,mBAAmB,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;YAChD,CAAC,CAAC,gBAAgB,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;QAC/C,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC;IAClB,OAAO,MAAM,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,MAAM,IAAI,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;AACrG,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { basename } from "node:path";
2
+ import { ClaudeRuntime } from "./claude-runtime.js";
3
+ import { CODEX_INSTRUCTION_FILES, CodexRuntime } from "./codex-runtime.js";
4
+ import { PiRpcRuntime } from "./pi-rpc.js";
5
+ /**
6
+ * The one runtime the manager holds. It picks the adapter from the effective
7
+ * command; the manager never branches on a harness id.
8
+ */
9
+ export class HarnessRuntime {
10
+ options;
11
+ constructor(options = {}) {
12
+ this.options = options;
13
+ }
14
+ sessionIdFromHarness(command) {
15
+ return basename(command?.trim() || "") === "codex";
16
+ }
17
+ instructionFilesFromHarness(command) {
18
+ return basename(command?.trim() || "") === "codex" ? CODEX_INSTRUCTION_FILES : [];
19
+ }
20
+ spawn(cwd, prompt, options = {}) {
21
+ const command = options.command?.trim() || "pi";
22
+ if (basename(command) === "claude") {
23
+ return new ClaudeRuntime({ command, timeoutMs: this.options.timeoutMs }).spawn(cwd, prompt, options);
24
+ }
25
+ if (basename(command) === "codex") {
26
+ return new CodexRuntime({ command, timeoutMs: this.options.timeoutMs }).spawn(cwd, prompt, options);
27
+ }
28
+ return new PiRpcRuntime({ command, timeoutMs: this.options.timeoutMs }).spawn(cwd, prompt, options);
29
+ }
30
+ }
31
+ //# sourceMappingURL=harness-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness-runtime.js","sourceRoot":"","sources":["../../src/run/harness-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQ3C;;;GAGG;AACH,MAAM,OAAO,cAAc;IACI,OAAO;IAApC,YAA6B,OAAO,GAA2B,EAAE;uBAApC,OAAO;IAAgC,CAAC;IAErE,oBAAoB,CAAC,OAAgB;QACnC,OAAO,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC;IACrD,CAAC;IAED,2BAA2B,CAAC,OAAgB;QAC1C,OAAO,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,EAAE,CAAC;IACpF,CAAC;IAED,KAAK,CAAC,GAAW,EAAE,MAAc,EAAE,OAAO,GAAsB,EAAE;QAChE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC;QAChD,IAAI,QAAQ,CAAC,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;YACnC,OAAO,IAAI,aA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