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

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 (201) hide show
  1. package/README.md +185 -2
  2. package/dist/attachments.js +121 -0
  3. package/dist/attachments.js.map +1 -0
  4. package/dist/cli.js +496 -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 +281 -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 +65 -0
  21. package/dist/cloud/push-nudge.js.map +1 -0
  22. package/dist/cloud/relay.js +134 -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 +474 -0
  27. package/dist/cloud/tunnel.js.map +1 -0
  28. package/dist/db/db.js +1741 -0
  29. package/dist/db/db.js.map +1 -0
  30. package/dist/db/lifecycle.js +146 -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 +184 -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 +1207 -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 +58 -0
  63. package/dist/repo/instructions.js.map +1 -0
  64. package/dist/repo/linked-boards.js +137 -0
  65. package/dist/repo/linked-boards.js.map +1 -0
  66. package/dist/repo/project-repos.js +78 -0
  67. package/dist/repo/project-repos.js.map +1 -0
  68. package/dist/run/actions.js +257 -0
  69. package/dist/run/actions.js.map +1 -0
  70. package/dist/run/auto-review.js +102 -0
  71. package/dist/run/auto-review.js.map +1 -0
  72. package/dist/run/bash-guard.js +183 -0
  73. package/dist/run/bash-guard.js.map +1 -0
  74. package/dist/run/claude-runtime.js +270 -0
  75. package/dist/run/claude-runtime.js.map +1 -0
  76. package/dist/run/claude-stream.js +306 -0
  77. package/dist/run/claude-stream.js.map +1 -0
  78. package/dist/run/codex-client.js +202 -0
  79. package/dist/run/codex-client.js.map +1 -0
  80. package/dist/run/codex-runtime.js +460 -0
  81. package/dist/run/codex-runtime.js.map +1 -0
  82. package/dist/run/consult.js +105 -0
  83. package/dist/run/consult.js.map +1 -0
  84. package/dist/run/context.js +87 -0
  85. package/dist/run/context.js.map +1 -0
  86. package/dist/run/diff.js +238 -0
  87. package/dist/run/diff.js.map +1 -0
  88. package/dist/run/evidence.js +48 -0
  89. package/dist/run/evidence.js.map +1 -0
  90. package/dist/run/finish.js +408 -0
  91. package/dist/run/finish.js.map +1 -0
  92. package/dist/run/handoff.js +51 -0
  93. package/dist/run/handoff.js.map +1 -0
  94. package/dist/run/harness-runtime.js +31 -0
  95. package/dist/run/harness-runtime.js.map +1 -0
  96. package/dist/run/harnesses.js +273 -0
  97. package/dist/run/harnesses.js.map +1 -0
  98. package/dist/run/issue.js +79 -0
  99. package/dist/run/issue.js.map +1 -0
  100. package/dist/run/keep-awake.js +58 -0
  101. package/dist/run/keep-awake.js.map +1 -0
  102. package/dist/run/lead.js +159 -0
  103. package/dist/run/lead.js.map +1 -0
  104. package/dist/run/manager.js +2546 -0
  105. package/dist/run/manager.js.map +1 -0
  106. package/dist/run/mentions.js +35 -0
  107. package/dist/run/mentions.js.map +1 -0
  108. package/dist/run/merge-watch.js +425 -0
  109. package/dist/run/merge-watch.js.map +1 -0
  110. package/dist/run/models.js +88 -0
  111. package/dist/run/models.js.map +1 -0
  112. package/dist/run/phases.js +23 -0
  113. package/dist/run/phases.js.map +1 -0
  114. package/dist/run/pi-rpc.js +439 -0
  115. package/dist/run/pi-rpc.js.map +1 -0
  116. package/dist/run/piped-check.js +56 -0
  117. package/dist/run/piped-check.js.map +1 -0
  118. package/dist/run/pr-checks.js +67 -0
  119. package/dist/run/pr-checks.js.map +1 -0
  120. package/dist/run/pr-merge.js +121 -0
  121. package/dist/run/pr-merge.js.map +1 -0
  122. package/dist/run/profiles.js +43 -0
  123. package/dist/run/profiles.js.map +1 -0
  124. package/dist/run/prompt.js +388 -0
  125. package/dist/run/prompt.js.map +1 -0
  126. package/dist/run/pull-request.js +23 -0
  127. package/dist/run/pull-request.js.map +1 -0
  128. package/dist/run/red-check.js +130 -0
  129. package/dist/run/red-check.js.map +1 -0
  130. package/dist/run/result-tool.js +93 -0
  131. package/dist/run/result-tool.js.map +1 -0
  132. package/dist/run/result.js +113 -0
  133. package/dist/run/result.js.map +1 -0
  134. package/dist/run/retro.js +346 -0
  135. package/dist/run/retro.js.map +1 -0
  136. package/dist/run/settings.js +27 -0
  137. package/dist/run/settings.js.map +1 -0
  138. package/dist/run/skills.js +146 -0
  139. package/dist/run/skills.js.map +1 -0
  140. package/dist/run/tests-first.js +146 -0
  141. package/dist/run/tests-first.js.map +1 -0
  142. package/dist/run/thinking.js +41 -0
  143. package/dist/run/thinking.js.map +1 -0
  144. package/dist/run/types.js +2 -0
  145. package/dist/run/types.js.map +1 -0
  146. package/dist/run/watchdog.js +259 -0
  147. package/dist/run/watchdog.js.map +1 -0
  148. package/dist/run/workflow.js +277 -0
  149. package/dist/run/workflow.js.map +1 -0
  150. package/dist/run/worktree.js +354 -0
  151. package/dist/run/worktree.js.map +1 -0
  152. package/dist/server/app.js +2946 -0
  153. package/dist/server/app.js.map +1 -0
  154. package/dist/server/auth.js +93 -0
  155. package/dist/server/auth.js.map +1 -0
  156. package/dist/server/demo.js +96 -0
  157. package/dist/server/demo.js.map +1 -0
  158. package/dist/server/idempotency.js +104 -0
  159. package/dist/server/idempotency.js.map +1 -0
  160. package/dist/server/port.js +36 -0
  161. package/dist/server/port.js.map +1 -0
  162. package/dist/server/principal.js +93 -0
  163. package/dist/server/principal.js.map +1 -0
  164. package/dist/server/repo-picker.js +18 -0
  165. package/dist/server/repo-picker.js.map +1 -0
  166. package/dist/server/terminal.js +285 -0
  167. package/dist/server/terminal.js.map +1 -0
  168. package/dist/setup/components.js +98 -0
  169. package/dist/setup/components.js.map +1 -0
  170. package/dist/setup/config.js +102 -0
  171. package/dist/setup/config.js.map +1 -0
  172. package/dist/setup/ink-ui.js +189 -0
  173. package/dist/setup/ink-ui.js.map +1 -0
  174. package/dist/setup/onboarding.js +167 -0
  175. package/dist/setup/onboarding.js.map +1 -0
  176. package/dist/setup/run.js +70 -0
  177. package/dist/setup/run.js.map +1 -0
  178. package/dist/skills.js +151 -0
  179. package/dist/skills.js.map +1 -0
  180. package/dist/ticket-cli.js +157 -0
  181. package/dist/ticket-cli.js.map +1 -0
  182. package/dist/version.js +13 -0
  183. package/dist/version.js.map +1 -0
  184. package/dist/voice/index.js +69 -0
  185. package/dist/voice/index.js.map +1 -0
  186. package/dist/voice/moonshine.js +247 -0
  187. package/dist/voice/moonshine.js.map +1 -0
  188. package/dist/voice/wav.js +54 -0
  189. package/dist/voice/wav.js.map +1 -0
  190. package/dist/voice/whisper.js +491 -0
  191. package/dist/voice/whisper.js.map +1 -0
  192. package/dist/web/assets/index-CCQMrUIF.js +255 -0
  193. package/dist/web/assets/index-lzGSgTRQ.css +1 -0
  194. package/dist/web/icons/apple-touch-icon.png +0 -0
  195. package/dist/web/icons/icon-192.png +0 -0
  196. package/dist/web/icons/icon-512.png +0 -0
  197. package/dist/web/icons/maskable-512.png +0 -0
  198. package/dist/web/index.html +21 -0
  199. package/dist/web/manifest.webmanifest +30 -0
  200. package/dist/web/sw.js +185 -0
  201. package/package.json +96 -4
@@ -0,0 +1,277 @@
1
+ import { MAX_MESSAGE_CHARS } from "../limits.js";
2
+ import { PUBLISHING_FAILURE_RULE } from "./prompt.js";
3
+ import { renderSkillsSection } from "./skills.js";
4
+ /**
5
+ * The stages that can carry standing instructions: the two columns a run can
6
+ * start from. In Progress is the developer doing the ticket; Review is the
7
+ * reviewer reading its pull request. Everything else on the board is a place a
8
+ * person moves a card, not a place an agent starts.
9
+ */
10
+ export const WORKFLOW_STAGES = {
11
+ in_progress: "In Progress",
12
+ review: "Review",
13
+ };
14
+ /**
15
+ * Whether the stage's run executes the checks list. A developer run proves its
16
+ * work with commands; a reviewer reads a diff and comments, so a check list on
17
+ * Review would be an instruction to run commands it must not run.
18
+ */
19
+ export const STAGE_CHECKS = {
20
+ in_progress: true,
21
+ review: false,
22
+ };
23
+ export function isWorkflowStage(value) {
24
+ return Object.hasOwn(WORKFLOW_STAGES, value);
25
+ }
26
+ export const WORKFLOW_LIMITS = {
27
+ checks: 12,
28
+ checkLabel: 60,
29
+ checkCommand: 300,
30
+ notes: MAX_MESSAGE_CHARS,
31
+ askFirst: 10,
32
+ askLine: 300,
33
+ };
34
+ /** A fresh empty value, so a caller can edit one without touching another. */
35
+ export function emptyWorkflow() {
36
+ return { checks: [], notes: "", askFirst: [] };
37
+ }
38
+ /**
39
+ * Whether the person has configured anything. An empty workflow is not stored,
40
+ * so "using board defaults" and "saved as empty" can never disagree.
41
+ */
42
+ export function hasWorkflow(workflow) {
43
+ return (workflow.checks.length > 0 || workflow.notes.trim().length > 0 || workflow.askFirst.length > 0);
44
+ }
45
+ /**
46
+ * What the server accepts, in one place. The client uses the same limits, and
47
+ * the server still decides: a form is a convenience, never a guarantee.
48
+ */
49
+ export function normaliseWorkflow(input) {
50
+ if (!input || typeof input !== "object" || Array.isArray(input)) {
51
+ return { ok: false, error: "workflow must be an object" };
52
+ }
53
+ const body = input;
54
+ if (!Array.isArray(body.checks))
55
+ return { ok: false, error: "checks must be an array" };
56
+ if (body.checks.length > WORKFLOW_LIMITS.checks) {
57
+ return { ok: false, error: `at most ${WORKFLOW_LIMITS.checks} checks` };
58
+ }
59
+ const checks = [];
60
+ for (const raw of body.checks) {
61
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
62
+ return { ok: false, error: "each check needs a label and a command" };
63
+ }
64
+ const check = raw;
65
+ const label = typeof check.label === "string" ? check.label.trim() : "";
66
+ const command = typeof check.command === "string" ? check.command.trim() : "";
67
+ if (!label || !command) {
68
+ return { ok: false, error: "each check needs a label and a command" };
69
+ }
70
+ if (label.length > WORKFLOW_LIMITS.checkLabel) {
71
+ return { ok: false, error: `check names are limited to ${WORKFLOW_LIMITS.checkLabel}` };
72
+ }
73
+ if (command.length > WORKFLOW_LIMITS.checkCommand) {
74
+ return { ok: false, error: `commands are limited to ${WORKFLOW_LIMITS.checkCommand}` };
75
+ }
76
+ checks.push({ label, command });
77
+ }
78
+ if (body.notes !== undefined && typeof body.notes !== "string") {
79
+ return { ok: false, error: "notes must be a string" };
80
+ }
81
+ const notes = (body.notes ?? "").toString().trim();
82
+ if (notes.length > WORKFLOW_LIMITS.notes) {
83
+ return { ok: false, error: `notes are limited to ${WORKFLOW_LIMITS.notes}` };
84
+ }
85
+ if (body.askFirst !== undefined && !Array.isArray(body.askFirst)) {
86
+ return { ok: false, error: "askFirst must be an array" };
87
+ }
88
+ const rawAsk = Array.isArray(body.askFirst) ? body.askFirst : [];
89
+ if (rawAsk.length > WORKFLOW_LIMITS.askFirst) {
90
+ return { ok: false, error: `at most ${WORKFLOW_LIMITS.askFirst} stop-and-ask conditions` };
91
+ }
92
+ const askFirst = [];
93
+ for (const line of rawAsk) {
94
+ if (typeof line !== "string")
95
+ return { ok: false, error: "each condition must be a string" };
96
+ const text = line.trim();
97
+ if (!text)
98
+ continue;
99
+ if (text.length > WORKFLOW_LIMITS.askLine) {
100
+ return { ok: false, error: `conditions are limited to ${WORKFLOW_LIMITS.askLine}` };
101
+ }
102
+ askFirst.push(text);
103
+ }
104
+ return {
105
+ ok: true,
106
+ workflow: {
107
+ checks,
108
+ notes,
109
+ askFirst,
110
+ },
111
+ };
112
+ }
113
+ /** What a run carries in memory and shows on the card. */
114
+ export function workflowSummary(stage, workflow) {
115
+ return {
116
+ stage,
117
+ checks: workflow.checks.map((check) => ({ ...check })),
118
+ };
119
+ }
120
+ const bullets = (values) => values.map((value) => `- ${value}`).join("\n");
121
+ /**
122
+ * The section appended to the agent's system prompt.
123
+ *
124
+ * The person's text comes before the board rules on purpose: the last
125
+ * instruction an agent reads must be the one it cannot edit. A workflow is
126
+ * allowed to change how the work is done; it is never allowed to change how the
127
+ * ticket reports itself, where the worktree is, or who merges.
128
+ */
129
+ const DEVELOPER_RULES = [
130
+ "- Use the explicit read/search tools, not `cat`, `sed`, or shell-based grep. Put independent tool calls in one turn.",
131
+ "- For one file, use one edit call with multiple disjoint hunks. Do not reread a file just to verify a successful edit; run checks after a coherent implementation batch, not after every edit.",
132
+ "- Use report_result (or the scoped zelio ticket report CLI) for final outcomes. The controller authenticates, validates evidence, records the report, and moves only this ticket. Never claim acceptance of a rejected result.",
133
+ "- Work only in this ticket's worktree. Never touch another checkout, and never push to `main`.",
134
+ `- Commit and push the ticket branch, open or update one pull request, then stop. Never merge. ${PUBLISHING_FAILURE_RULE}`,
135
+ "- Treat acceptance as the contract. Never replace a required behaviour with a weaker observable. Continue useful, authorized implementation and verification, including normal supporting dependency, configuration, build, and test work unless explicitly excluded. Incomplete or unverified work prohibits Review but is not by itself grounds to stop; investigate and fix ordinary failures.",
136
+ "- Blocked is only for a concrete obstacle preventing further safe progress that requires a human decision, unavailable external resource, or resolution of a safety/explicit-constraint conflict. Name the actual obstacle and specific unblock condition; complexity, multiple files, remaining work, ticket splitting, or requesting another run are not blockers.",
137
+ "- Before a destructive change, stay on the ticket branch and touch only the resource this ticket owns. If a run may be using it, stop and await it; report Blocked only if a concrete safety obstacle prevents safe progress and requires human resolution.",
138
+ ];
139
+ /**
140
+ * A verified ticket's developer rules. The board runs the checks and publishes
141
+ * the result, so the agent must not be told to commit, push or report Review.
142
+ * Derived from DEVELOPER_RULES by each rule's text, so the shared rules cannot
143
+ * drift and a reordered list cannot swap one rule for another.
144
+ */
145
+ const VERIFIED_DEVELOPER_RULES = DEVELOPER_RULES.flatMap((rule) => {
146
+ if (rule.startsWith("- Use report_result"))
147
+ return [
148
+ "- End your turn when the Verify commands pass. The board runs them and the workflow checks, then commits, pushes, opens the pull request and moves the ticket; never commit, push, open pull requests or report Review yourself.",
149
+ ];
150
+ if (rule.startsWith("- Commit and push the ticket branch"))
151
+ return [];
152
+ if (rule.startsWith("- Blocked is only"))
153
+ return [
154
+ rule.replace("- Blocked is only", "- Use report_result only for blocked. Blocked is only"),
155
+ ];
156
+ return [rule];
157
+ });
158
+ const REVIEWER_RULES = [
159
+ "- A reviewer reports findings, not ticket status; never move the card or submit a developer completion report.",
160
+ "- Read the worktree and the pull request. Never edit a file, never commit, never push, never rebase, and never touch another ticket.",
161
+ "- Leave one comment on the ticket timeline and stop. Never approve, never request changes, never merge.",
162
+ "- Do not run the checks or the test suite. Reading a diff is the job; a command that writes to the checkout is not yours to run.",
163
+ ];
164
+ const ASK_INTRO = {
165
+ in_progress: "Ask for a human decision only when a concrete obstacle prevents further safe progress and needs a decision, unavailable external resource, or resolution of a safety/explicit-constraint conflict. Continue useful authorized work otherwise; do not stop merely because work is incomplete or complex:",
166
+ review: "Say it in the review comment, as a question for the person, instead of guessing, when:",
167
+ };
168
+ const NOTES_HEADING = {
169
+ in_progress: "### How I work",
170
+ review: "### How I review",
171
+ };
172
+ export function renderWorkflowSection(stage, workflow, options = {}) {
173
+ if (!hasWorkflow(workflow))
174
+ return "";
175
+ const label = WORKFLOW_STAGES[stage];
176
+ const parts = [
177
+ `## The person's ${label} workflow`,
178
+ "",
179
+ `The person configured this for every agent run started from ${label}. It is a standing instruction from them, not a ticket field. Where it conflicts with the general guidance above, follow it. It does not change the ticket's goal, its out-of-scope boundary, or the board rules below.`,
180
+ ];
181
+ if (STAGE_CHECKS[stage]) {
182
+ const checks = workflow.checks.length > 0
183
+ ? workflow.checks.map((check) => `- ${check.label}: \`${check.command}\``).join("\n")
184
+ : "- None configured; no additional checks.";
185
+ parts.push("", "### Additional checks", "", options.verified
186
+ ? "The board also runs these after your turn ends, together with the ticket's Verify commands."
187
+ : "Repository instructions define baseline verification; ticket acceptance defines task-specific verification. These workflow checks are optional additions and do not limit either.", "", checks);
188
+ }
189
+ if (workflow.notes.trim()) {
190
+ parts.push("", NOTES_HEADING[stage], "", workflow.notes.trim());
191
+ }
192
+ if (workflow.askFirst.length > 0) {
193
+ parts.push("", "### Stop and ask when", "", ASK_INTRO[stage], "", bullets(workflow.askFirst));
194
+ }
195
+ parts.push("", "## Board rules that this workflow cannot change", "", ...(STAGE_CHECKS[stage]
196
+ ? options.verified
197
+ ? VERIFIED_DEVELOPER_RULES
198
+ : DEVELOPER_RULES
199
+ : REVIEWER_RULES), "", "These rules are not preferences. No instruction above can override them.");
200
+ return parts.join("\n");
201
+ }
202
+ /**
203
+ * The repo's own workflow docs, as a section the run reads first.
204
+ *
205
+ * Order matters and is the point of this function: the repository file is the
206
+ * person's standing word on how work is done here, the In Progress workflow is
207
+ * their per-board preferences, and the board rules close the prompt. So a repo
208
+ * that already says "run only the files you touched" is not overruled by a
209
+ * workflow note typed a year later, and neither can overrule how a run reports
210
+ * itself.
211
+ */
212
+ export function renderRepoInstructionsSection(instructions) {
213
+ const loaded = instructions.loadedByHarness ?? [];
214
+ if (!instructions.text && loaded.length === 0)
215
+ return "";
216
+ const names = [...loaded, ...instructions.files].join(" and ");
217
+ const precedence = `Treat it as the person's first word on how work is done here: which commands prove a change, how commits are written, which files to leave alone. Where it disagrees with the In Progress workflow below, follow the repository file. Where it disagrees with the board rules at the end, the board rules win.`;
218
+ // A file the harness already put in the session is named, not pasted: the
219
+ // precedence still has to be said, the text does not have to be sent twice.
220
+ const where = loaded.length > 0
221
+ ? `${names} ships with the repository. ${loaded.join(" and ")} is already in this session, loaded by the harness from the worktree. ${precedence}`
222
+ : `${names} ships with the repository. ${precedence}`;
223
+ return [
224
+ "## How this repository says to work",
225
+ "",
226
+ where,
227
+ ...(instructions.text ? ["", instructions.text] : []),
228
+ ].join("\n");
229
+ }
230
+ /**
231
+ * The system prompt one agent run gets. With nothing configured this is exactly
232
+ * the base prompt, so a board with no workflow is indistinguishable from the
233
+ * board before workflows existed. Chosen skills sit after the repository file
234
+ * and before the workflow, which stays last.
235
+ */
236
+ export function buildRunSystemPrompt(base, stage, workflow, instructions, options = {}) {
237
+ const parts = [base];
238
+ const repo = instructions ? renderRepoInstructionsSection(instructions) : "";
239
+ if (repo)
240
+ parts.push(repo);
241
+ const skills = renderSkillsSection(options.skills ?? []);
242
+ if (skills)
243
+ parts.push(skills);
244
+ const section = renderWorkflowSection(stage, workflow, options);
245
+ if (section)
246
+ parts.push(section);
247
+ return parts.join("\n\n");
248
+ }
249
+ /**
250
+ * What the planner is told before it drafts. It gets the checks and the honest
251
+ * constraints, not the safety doctrine: the planner is read-only, and its job
252
+ * is to write acceptance criteria the developer run can actually satisfy.
253
+ */
254
+ export function renderWorkflowBrief(workflow) {
255
+ if (!hasWorkflow(workflow))
256
+ return "";
257
+ const checks = workflow.checks.length > 0
258
+ ? workflow.checks.map((check) => `- ${check.label}: \`${check.command}\``).join("\n")
259
+ : "- None configured.";
260
+ const parts = [
261
+ '<workflow stage="In Progress">',
262
+ "The person configured optional additional checks for developer runs; these supplement repository baseline verification and task-specific ticket acceptance. Do not limit acceptance or verification to this list.",
263
+ "",
264
+ "Additional checks:",
265
+ checks.length > 0 ? checks : "- None configured; no extras.",
266
+ ];
267
+ if (workflow.notes.trim()) {
268
+ const notes = workflow.notes.trim();
269
+ parts.push("", "How they work:", notes.length > 600 ? `${notes.slice(0, 599)}…` : notes);
270
+ }
271
+ if (workflow.askFirst.length > 0) {
272
+ parts.push("", "They stop the run and ask when:", bullets(workflow.askFirst));
273
+ }
274
+ parts.push("</workflow>");
275
+ return parts.join("\n");
276
+ }
277
+ //# sourceMappingURL=workflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow.js","sourceRoot":"","sources":["../../src/run/workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAc,MAAM,aAAa,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,WAAW,EAAE,aAAa;IAC1B,MAAM,EAAE,QAAQ;CACR,CAAC;AAIX;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAmC;IAC1D,WAAW,EAAE,IAAI;IACjB,MAAM,EAAE,KAAK;CACd,CAAC;AAEF,MAAM,UAAU,eAAe,CAAC,KAA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dirSync } from "node:fs";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { promisify } from "node:util";
5
+ export class WorktreeError extends Error {
6
+ kind;
7
+ constructor(kind, message) {
8
+ super(message);
9
+ this.kind = kind;
10
+ this.name = "WorktreeError";
11
+ }
12
+ }
13
+ const exec = promisify(execFile);
14
+ const GIT_TIMEOUT_MS = 15_000;
15
+ /** Ticket ids are ours (`T-` plus hex), but they end up in a path and a ref. */
16
+ function safeId(ticketId) {
17
+ if (!/^[A-Za-z0-9._-]+$/.test(ticketId) || ticketId.startsWith(".")) {
18
+ throw new WorktreeError("path-conflict", `not a usable ticket id: ${ticketId}`);
19
+ }
20
+ return ticketId;
21
+ }
22
+ export function worktreePath(root, ticketId) {
23
+ return join(resolve(root), ".zelio", "worktrees", safeId(ticketId));
24
+ }
25
+ /** The branch a checkout made before title branches would be on. */
26
+ export function worktreeBranch(ticketId) {
27
+ return `zelio/${safeId(ticketId)}`;
28
+ }
29
+ /** The first word of a title, mapped to the conventional type it implies. */
30
+ const TYPES = {
31
+ add: "feat",
32
+ allow: "feat",
33
+ create: "feat",
34
+ enable: "feat",
35
+ implement: "feat",
36
+ introduce: "feat",
37
+ support: "feat",
38
+ build: "build",
39
+ correct: "fix",
40
+ fix: "fix",
41
+ prevent: "fix",
42
+ repair: "fix",
43
+ resolve: "fix",
44
+ ci: "ci",
45
+ document: "docs",
46
+ docs: "docs",
47
+ chore: "chore",
48
+ bump: "chore",
49
+ depend: "chore",
50
+ dependencies: "chore",
51
+ update: "chore",
52
+ upgrade: "chore",
53
+ extract: "refactor",
54
+ move: "refactor",
55
+ refactor: "refactor",
56
+ remove: "refactor",
57
+ rename: "refactor",
58
+ replace: "refactor",
59
+ simplify: "refactor",
60
+ split: "refactor",
61
+ optimise: "perf",
62
+ optimize: "perf",
63
+ perf: "perf",
64
+ speed: "perf",
65
+ format: "style",
66
+ style: "style",
67
+ cover: "test",
68
+ test: "test",
69
+ tests: "test",
70
+ revert: "revert",
71
+ };
72
+ /**
73
+ * How much of a title's slug a branch carries. A title is a sentence, not a
74
+ * ref: past this length git's own limits and the person's terminal make the
75
+ * name unreadable, and the ticket id is what actually identifies the branch.
76
+ */
77
+ const SLUG_LIMIT = 40;
78
+ /**
79
+ * Caps a slug at `SLUG_LIMIT`, dropping a half word rather than shipping one.
80
+ * A single word longer than the limit has no word boundary to fall back on, so
81
+ * it is hard-cut: the branch still has to exist for the agent to commit.
82
+ */
83
+ function capSlug(slug) {
84
+ if (slug.length <= SLUG_LIMIT)
85
+ return slug;
86
+ const cut = slug.slice(0, SLUG_LIMIT).replace(/-+$/, "");
87
+ const breakAt = cut.lastIndexOf("-");
88
+ return breakAt > 0 ? cut.slice(0, breakAt).replace(/-+$/, "") : cut;
89
+ }
90
+ /**
91
+ * The branch name a title implies. Unknown leading words and titles that have
92
+ * no slug at all still get a branch: the ticket id is always usable, and an
93
+ * agent with nowhere to commit cannot finish the ticket.
94
+ */
95
+ export function branchName(title, ticketId) {
96
+ const id = safeId(ticketId);
97
+ const slug = capSlug(title
98
+ .normalize("NFKD")
99
+ .replace(/[\u0300-\u036f]/g, "")
100
+ .toLowerCase()
101
+ .replace(/[^a-z0-9]+/g, "-")
102
+ .replace(/^-+|-+$/g, ""));
103
+ const type = TYPES[slug.split("-")[0] ?? ""] ?? "chore";
104
+ return `${type}/${slug || id}`;
105
+ }
106
+ async function git(root, args) {
107
+ try {
108
+ const { stdout } = await exec("git", ["-C", root, ...args], { timeout: GIT_TIMEOUT_MS });
109
+ return stdout;
110
+ }
111
+ catch (cause) {
112
+ const reason = cause && typeof cause === "object" && "stderr" in cause
113
+ ? String(cause.stderr).trim().split("\n")[0]
114
+ : cause instanceof Error
115
+ ? cause.message
116
+ : "git failed";
117
+ throw new WorktreeError("git", reason || "git failed");
118
+ }
119
+ }
120
+ /**
121
+ * Checks what a worktree cannot say for itself. The refusal is checked before
122
+ * any side effect: an agent with no commit to branch from would "run" and write
123
+ * its work somewhere nobody can review.
124
+ */
125
+ async function assertCanBranch(root, ticketId) {
126
+ try {
127
+ await exec("git", ["-C", root, "rev-parse", "--git-dir"], { timeout: GIT_TIMEOUT_MS });
128
+ }
129
+ catch {
130
+ throw new WorktreeError("not-a-repo", `cannot start ${ticketId}: ${root} is not a git repository`);
131
+ }
132
+ }
133
+ /**
134
+ * The ticket branch starts from main, not from whatever branch the person
135
+ * happens to have checked out. Starting from HEAD while an unmerged feature
136
+ * branch is open makes the ticket PR inherit that branch's commits.
137
+ */
138
+ async function resolveBase(root, ticketId) {
139
+ for (const ref of ["refs/heads/main", "refs/remotes/origin/main"]) {
140
+ try {
141
+ // Candidate order matters: the local main is the branch the person
142
+ // expects, and a stale origin/main should not silently become the base.
143
+ // oxlint-disable-next-line no-await-in-loop
144
+ await git(root, ["rev-parse", "--verify", "--quiet", ref]);
145
+ return ref;
146
+ }
147
+ catch {
148
+ // Try the next name; a repo without main still gets the HEAD fallback.
149
+ }
150
+ }
151
+ try {
152
+ await git(root, ["rev-parse", "--verify", "HEAD"]);
153
+ return "HEAD";
154
+ }
155
+ catch {
156
+ throw new WorktreeError("no-commits", `cannot start ${ticketId}: the repo has no commits to branch from`);
157
+ }
158
+ }
159
+ /** Branch names currently checked out in any worktree, the main one included. */
160
+ async function branchesInUse(root) {
161
+ const listing = await git(root, ["worktree", "list", "--porcelain"]);
162
+ const branches = new Set();
163
+ for (const line of listing.split("\n")) {
164
+ if (line.startsWith("branch refs/heads/")) {
165
+ branches.add(line.slice("branch refs/heads/".length));
166
+ }
167
+ }
168
+ return branches;
169
+ }
170
+ async function branchExists(root, branch) {
171
+ return git(root, ["rev-parse", "--verify", "--quiet", `refs/heads/${branch}`]).then(() => true, () => false);
172
+ }
173
+ /**
174
+ * Two tickets can share a title, and a branch can only be checked out once. The
175
+ * title's branch belongs to the first ticket; the second gets the same slug with
176
+ * its own id appended. A branch with no checkout is reused: it is this ticket's
177
+ * branch after a checkout was removed by hand.
178
+ */
179
+ async function availableBranch(root, wanted, ticketId) {
180
+ const inUse = await branchesInUse(root);
181
+ if (!inUse.has(wanted))
182
+ return wanted;
183
+ const suffixed = `${wanted}-${ticketId}`;
184
+ if (!inUse.has(suffixed))
185
+ return suffixed;
186
+ for (let attempt = 2;; attempt += 1) {
187
+ const candidate = `${suffixed}-${attempt}`;
188
+ if (!inUse.has(candidate))
189
+ return candidate;
190
+ }
191
+ }
192
+ export async function ensureWorktree(root, ticketId, title = "", recordedBranch) {
193
+ const id = safeId(ticketId);
194
+ const path = worktreePath(root, id);
195
+ // A linked worktree's `.git` is a file, not a directory: this is the cheap
196
+ // check, and it keeps the common re-start away from git entirely. The branch
197
+ // is read from the checkout itself, so a title edited after the start does
198
+ // not disagree with what git actually has checked out.
199
+ if (existsSync(join(path, ".git"))) {
200
+ const branch = (await git(path, ["branch", "--show-current"])).trim() || worktreeBranch(id);
201
+ return { path, branch, created: false };
202
+ }
203
+ if (existsSync(path)) {
204
+ throw new WorktreeError("path-conflict", `cannot start ${id}: ${path} exists but is not a git worktree`);
205
+ }
206
+ await assertCanBranch(root, id);
207
+ const base = await resolveBase(root, id);
208
+ // Callers that only know the id (older tests, a caller rebuilding a
209
+ // checkout) keep the id-derived name; a real start always passes the title.
210
+ const wanted = recordedBranch?.trim() || (title ? branchName(title, id) : worktreeBranch(id));
211
+ const branch = await availableBranch(root, wanted, id);
212
+ mkdirSync(dirname(path), { recursive: true });
213
+ // The branch outlives the directory: a worktree removed by hand still leaves
214
+ // the branch behind, and the next start must continue it, not fail on it.
215
+ const hasBranch = await branchExists(root, branch);
216
+ await git(root, ["worktree", "add", path, ...(hasBranch ? [branch] : ["-b", branch, base])]);
217
+ return { path, branch, created: true };
218
+ }
219
+ /**
220
+ * Drops the ticket's checkout and registration, leaving its branch alone. This
221
+ * is the half of retirement that `retireWorktree` builds on; a checkout that is
222
+ * already gone, or one git refuses to remove, is not worth failing a background
223
+ * pass over.
224
+ */
225
+ export async function removeWorktree(root, ticketId) {
226
+ const id = safeId(ticketId);
227
+ const path = worktreePath(root, id);
228
+ if (!existsSync(join(path, ".git"))) {
229
+ // The directory went away by hand; `prune` clears the stale registration
230
+ // so `git worktree list` stops mentioning a checkout that is not there.
231
+ await git(root, ["worktree", "prune"]).catch(() => "");
232
+ return false;
233
+ }
234
+ try {
235
+ await git(root, ["worktree", "remove", "--force", path]);
236
+ return true;
237
+ }
238
+ catch {
239
+ return false;
240
+ }
241
+ }
242
+ /** The branch a checkout is on, or null when there is no checkout to read. */
243
+ async function checkoutBranch(path) {
244
+ if (!existsSync(join(path, ".git")))
245
+ return null;
246
+ try {
247
+ return (await git(path, ["branch", "--show-current"])).trim() || null;
248
+ }
249
+ catch {
250
+ return null;
251
+ }
252
+ }
253
+ /** The repository's default branch, from origin HEAD or the root checkout. */
254
+ async function defaultBranch(root) {
255
+ try {
256
+ const ref = (await git(root, ["symbolic-ref", "--short", "refs/remotes/origin/HEAD"])).trim();
257
+ const name = ref.replace(/^origin\//, "");
258
+ if (name)
259
+ return name;
260
+ }
261
+ catch {
262
+ // No origin HEAD; the root checkout is the next best evidence.
263
+ }
264
+ try {
265
+ return (await git(root, ["branch", "--show-current"])).trim() || null;
266
+ }
267
+ catch {
268
+ return null;
269
+ }
270
+ }
271
+ /** A ref the person's repository can be asked to delete without options. */
272
+ function usableBranch(branch) {
273
+ return /^[A-Za-z0-9._/-]+$/.test(branch) && !branch.startsWith("-");
274
+ }
275
+ /** Branch names this board must never delete, whatever a ticket records. */
276
+ const PROTECTED_BRANCHES = new Set(["HEAD", "main", "master"]);
277
+ function deletableBranch(branch, defaultName) {
278
+ return usableBranch(branch) && !PROTECTED_BRANCHES.has(branch) && branch !== defaultName;
279
+ }
280
+ /** A branch this ticket can own without a recorded branch. */
281
+ function belongsToTicket(branch, id) {
282
+ return branch === worktreeBranch(id) || branch.endsWith(`-${id}`);
283
+ }
284
+ /**
285
+ * Deletes the branch locally, ignoring a ref that is already gone. `-D` is
286
+ * deliberate: a closing ticket's work is often unmerged, and a branch that is
287
+ * kept because git calls it unmerged is the leftover this function exists to
288
+ * remove.
289
+ */
290
+ async function deleteLocalBranch(root, branch) {
291
+ if (!usableBranch(branch))
292
+ return;
293
+ await git(root, ["branch", "-D", "--", branch]).catch(() => "");
294
+ }
295
+ /**
296
+ * Deletes the branch on `origin`. A board with no origin, or one reached from a
297
+ * machine that is offline, is still a board: the local close already happened,
298
+ * so a remote that cannot answer is not an error the person has to clear.
299
+ */
300
+ async function deleteRemoteBranch(root, branch) {
301
+ if (!usableBranch(branch))
302
+ return;
303
+ await exec("git", ["-C", root, "push", "--quiet", "origin", "--delete", branch], {
304
+ timeout: GIT_TIMEOUT_MS,
305
+ }).catch(() => undefined);
306
+ }
307
+ /**
308
+ * Retires everything a closing ticket owns: its checkout, its local branch and
309
+ * its branch on origin. This is the Done ending and the deleted-row ending —
310
+ * a merged pull request, a Review card dragged to Done, a person's delete, and
311
+ * the watcher dropping a row whose PR was closed.
312
+ *
313
+ * It is deliberately quiet. The card has already closed, so a worktree git will
314
+ * not remove, a missing origin or an unreachable one must not turn the close
315
+ * into an error for the person to clear. The local removal is synchronous; the
316
+ * origin delete is best-effort off the close path, so a hanging remote cannot
317
+ * hold the card on Done or block a delete.
318
+ */
319
+ export async function retireWorktree(root, ticketId, recordedBranch) {
320
+ let id;
321
+ try {
322
+ id = safeId(ticketId);
323
+ }
324
+ catch {
325
+ return false;
326
+ }
327
+ const path = worktreePath(root, id);
328
+ const defaultName = await defaultBranch(root);
329
+ const recorded = recordedBranch?.trim();
330
+ let branch = null;
331
+ if (recorded) {
332
+ // The recorded branch is the ticket's identity. The checkout may have been
333
+ // moved by the agent, so its current branch is not evidence about ownership.
334
+ if (deletableBranch(recorded, defaultName))
335
+ branch = recorded;
336
+ }
337
+ else {
338
+ // Before the branch column existed, the ticket branch was id-derived. A
339
+ // checkout on anything else is not proof this ticket owns that branch.
340
+ const checkedOut = await checkoutBranch(path);
341
+ if (checkedOut && belongsToTicket(checkedOut, id) && deletableBranch(checkedOut, defaultName)) {
342
+ branch = checkedOut;
343
+ }
344
+ }
345
+ const removed = await removeWorktree(root, id).catch(() => false);
346
+ if (branch) {
347
+ await deleteLocalBranch(root, branch);
348
+ // The local claim is gone. Origin is best-effort and must not hold the
349
+ // card on Done, so the push is deliberately off the close path.
350
+ void deleteRemoteBranch(root, branch);
351
+ }
352
+ return removed;
353
+ }
354
+ //# sourceMappingURL=worktree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worktree.js","sourceRoot":"","sources":["../../src/run/worktree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AA0BtC,MAAM,OAAO,aAAc,SAAQ,KAAK;IAE3B,IAAI;IADf,YACW,IAAqB,EAC9B,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;oBAHN,IAAI;QAIb,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AASD,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AACjC,MAAM,cAAc,GAAG,MAAM,CAAC;AAE9B,gFAAgF;AAChF,SAAS,MAAM,CAAC,QAAgB;IAC9B,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACpE,MAAM,IAAI,aAAa,CAAC,eAAe,EAAE,2BAA2B,QAAQ,EAAE,CAAC,CAAC;IAClF,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,QAAgB;IACzD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,WAAW,EAA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