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.
- package/README.md +185 -2
- package/dist/attachments.js +121 -0
- package/dist/attachments.js.map +1 -0
- package/dist/cli.js +496 -0
- package/dist/cli.js.map +1 -0
- package/dist/cloud/board.js +311 -0
- package/dist/cloud/board.js.map +1 -0
- package/dist/cloud/command.js +281 -0
- package/dist/cloud/command.js.map +1 -0
- package/dist/cloud/config.js +132 -0
- package/dist/cloud/config.js.map +1 -0
- package/dist/cloud/credentials.js +134 -0
- package/dist/cloud/credentials.js.map +1 -0
- package/dist/cloud/login.js +165 -0
- package/dist/cloud/login.js.map +1 -0
- package/dist/cloud/pair.js +110 -0
- package/dist/cloud/pair.js.map +1 -0
- package/dist/cloud/pkce.js +16 -0
- package/dist/cloud/pkce.js.map +1 -0
- package/dist/cloud/push-nudge.js +65 -0
- package/dist/cloud/push-nudge.js.map +1 -0
- package/dist/cloud/relay.js +134 -0
- package/dist/cloud/relay.js.map +1 -0
- package/dist/cloud/token.js +66 -0
- package/dist/cloud/token.js.map +1 -0
- package/dist/cloud/tunnel.js +474 -0
- package/dist/cloud/tunnel.js.map +1 -0
- package/dist/db/db.js +1741 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/lifecycle.js +146 -0
- package/dist/db/lifecycle.js.map +1 -0
- package/dist/limits.js +35 -0
- package/dist/limits.js.map +1 -0
- package/dist/metrics.js +30 -0
- package/dist/metrics.js.map +1 -0
- package/dist/orchestrator/claude-session.js +208 -0
- package/dist/orchestrator/claude-session.js.map +1 -0
- package/dist/orchestrator/codex-session.js +326 -0
- package/dist/orchestrator/codex-session.js.map +1 -0
- package/dist/orchestrator/contract.js +184 -0
- package/dist/orchestrator/contract.js.map +1 -0
- package/dist/orchestrator/explore.js +176 -0
- package/dist/orchestrator/explore.js.map +1 -0
- package/dist/orchestrator/new-task-prompt.js +51 -0
- package/dist/orchestrator/new-task-prompt.js.map +1 -0
- package/dist/orchestrator/pi-session.js +228 -0
- package/dist/orchestrator/pi-session.js.map +1 -0
- package/dist/orchestrator/prompt.js +110 -0
- package/dist/orchestrator/prompt.js.map +1 -0
- package/dist/orchestrator/research.js +178 -0
- package/dist/orchestrator/research.js.map +1 -0
- package/dist/orchestrator/runtime.js +1207 -0
- package/dist/orchestrator/runtime.js.map +1 -0
- package/dist/orchestrator/session.js +2 -0
- package/dist/orchestrator/session.js.map +1 -0
- package/dist/orchestrator/types.js +2 -0
- package/dist/orchestrator/types.js.map +1 -0
- package/dist/orchestrator/web.js +276 -0
- package/dist/orchestrator/web.js.map +1 -0
- package/dist/repo/index.js +188 -0
- package/dist/repo/index.js.map +1 -0
- package/dist/repo/instructions.js +58 -0
- package/dist/repo/instructions.js.map +1 -0
- package/dist/repo/linked-boards.js +137 -0
- package/dist/repo/linked-boards.js.map +1 -0
- package/dist/repo/project-repos.js +78 -0
- package/dist/repo/project-repos.js.map +1 -0
- package/dist/run/actions.js +257 -0
- package/dist/run/actions.js.map +1 -0
- package/dist/run/auto-review.js +102 -0
- package/dist/run/auto-review.js.map +1 -0
- package/dist/run/bash-guard.js +183 -0
- package/dist/run/bash-guard.js.map +1 -0
- package/dist/run/claude-runtime.js +270 -0
- package/dist/run/claude-runtime.js.map +1 -0
- package/dist/run/claude-stream.js +306 -0
- package/dist/run/claude-stream.js.map +1 -0
- package/dist/run/codex-client.js +202 -0
- package/dist/run/codex-client.js.map +1 -0
- package/dist/run/codex-runtime.js +460 -0
- package/dist/run/codex-runtime.js.map +1 -0
- package/dist/run/consult.js +105 -0
- package/dist/run/consult.js.map +1 -0
- package/dist/run/context.js +87 -0
- package/dist/run/context.js.map +1 -0
- package/dist/run/diff.js +238 -0
- package/dist/run/diff.js.map +1 -0
- package/dist/run/evidence.js +48 -0
- package/dist/run/evidence.js.map +1 -0
- package/dist/run/finish.js +408 -0
- package/dist/run/finish.js.map +1 -0
- package/dist/run/handoff.js +51 -0
- package/dist/run/handoff.js.map +1 -0
- package/dist/run/harness-runtime.js +31 -0
- package/dist/run/harness-runtime.js.map +1 -0
- package/dist/run/harnesses.js +273 -0
- package/dist/run/harnesses.js.map +1 -0
- package/dist/run/issue.js +79 -0
- package/dist/run/issue.js.map +1 -0
- package/dist/run/keep-awake.js +58 -0
- package/dist/run/keep-awake.js.map +1 -0
- package/dist/run/lead.js +159 -0
- package/dist/run/lead.js.map +1 -0
- package/dist/run/manager.js +2546 -0
- package/dist/run/manager.js.map +1 -0
- package/dist/run/mentions.js +35 -0
- package/dist/run/mentions.js.map +1 -0
- package/dist/run/merge-watch.js +425 -0
- package/dist/run/merge-watch.js.map +1 -0
- package/dist/run/models.js +88 -0
- package/dist/run/models.js.map +1 -0
- package/dist/run/phases.js +23 -0
- package/dist/run/phases.js.map +1 -0
- package/dist/run/pi-rpc.js +439 -0
- package/dist/run/pi-rpc.js.map +1 -0
- package/dist/run/piped-check.js +56 -0
- package/dist/run/piped-check.js.map +1 -0
- package/dist/run/pr-checks.js +67 -0
- package/dist/run/pr-checks.js.map +1 -0
- package/dist/run/pr-merge.js +121 -0
- package/dist/run/pr-merge.js.map +1 -0
- package/dist/run/profiles.js +43 -0
- package/dist/run/profiles.js.map +1 -0
- package/dist/run/prompt.js +388 -0
- package/dist/run/prompt.js.map +1 -0
- package/dist/run/pull-request.js +23 -0
- package/dist/run/pull-request.js.map +1 -0
- package/dist/run/red-check.js +130 -0
- package/dist/run/red-check.js.map +1 -0
- package/dist/run/result-tool.js +93 -0
- package/dist/run/result-tool.js.map +1 -0
- package/dist/run/result.js +113 -0
- package/dist/run/result.js.map +1 -0
- package/dist/run/retro.js +346 -0
- package/dist/run/retro.js.map +1 -0
- package/dist/run/settings.js +27 -0
- package/dist/run/settings.js.map +1 -0
- package/dist/run/skills.js +146 -0
- package/dist/run/skills.js.map +1 -0
- package/dist/run/tests-first.js +146 -0
- package/dist/run/tests-first.js.map +1 -0
- package/dist/run/thinking.js +41 -0
- package/dist/run/thinking.js.map +1 -0
- package/dist/run/types.js +2 -0
- package/dist/run/types.js.map +1 -0
- package/dist/run/watchdog.js +259 -0
- package/dist/run/watchdog.js.map +1 -0
- package/dist/run/workflow.js +277 -0
- package/dist/run/workflow.js.map +1 -0
- package/dist/run/worktree.js +354 -0
- package/dist/run/worktree.js.map +1 -0
- package/dist/server/app.js +2946 -0
- package/dist/server/app.js.map +1 -0
- package/dist/server/auth.js +93 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/demo.js +96 -0
- package/dist/server/demo.js.map +1 -0
- package/dist/server/idempotency.js +104 -0
- package/dist/server/idempotency.js.map +1 -0
- package/dist/server/port.js +36 -0
- package/dist/server/port.js.map +1 -0
- package/dist/server/principal.js +93 -0
- package/dist/server/principal.js.map +1 -0
- package/dist/server/repo-picker.js +18 -0
- package/dist/server/repo-picker.js.map +1 -0
- package/dist/server/terminal.js +285 -0
- package/dist/server/terminal.js.map +1 -0
- package/dist/setup/components.js +98 -0
- package/dist/setup/components.js.map +1 -0
- package/dist/setup/config.js +102 -0
- package/dist/setup/config.js.map +1 -0
- package/dist/setup/ink-ui.js +189 -0
- package/dist/setup/ink-ui.js.map +1 -0
- package/dist/setup/onboarding.js +167 -0
- package/dist/setup/onboarding.js.map +1 -0
- package/dist/setup/run.js +70 -0
- package/dist/setup/run.js.map +1 -0
- package/dist/skills.js +151 -0
- package/dist/skills.js.map +1 -0
- package/dist/ticket-cli.js +157 -0
- package/dist/ticket-cli.js.map +1 -0
- package/dist/version.js +13 -0
- package/dist/version.js.map +1 -0
- package/dist/voice/index.js +69 -0
- package/dist/voice/index.js.map +1 -0
- package/dist/voice/moonshine.js +247 -0
- package/dist/voice/moonshine.js.map +1 -0
- package/dist/voice/wav.js +54 -0
- package/dist/voice/wav.js.map +1 -0
- package/dist/voice/whisper.js +491 -0
- package/dist/voice/whisper.js.map +1 -0
- package/dist/web/assets/index-CCQMrUIF.js +255 -0
- package/dist/web/assets/index-lzGSgTRQ.css +1 -0
- package/dist/web/icons/apple-touch-icon.png +0 -0
- package/dist/web/icons/icon-192.png +0 -0
- package/dist/web/icons/icon-512.png +0 -0
- package/dist/web/icons/maskable-512.png +0 -0
- package/dist/web/index.html +21 -0
- package/dist/web/manifest.webmanifest +30 -0
- package/dist/web/sw.js +185 -0
- package/package.json +96 -4
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { readMergeCommit, worktreeHead } from "./diff.js";
|
|
6
|
+
import { retireWorktree, worktreePath } from "./worktree.js";
|
|
7
|
+
/**
|
|
8
|
+
* A review card is waiting on something that happens outside Zelio: the pull
|
|
9
|
+
* request on GitHub. So the board reads that one fact back, and reconciles the
|
|
10
|
+
* card with it — `review` is only true while a diff is actually waiting.
|
|
11
|
+
*
|
|
12
|
+
* The outcomes:
|
|
13
|
+
*
|
|
14
|
+
* - **merged** — `done`, the checkout and its branch go, locally and on
|
|
15
|
+
* `origin`. The card stops pretending the ticket is still someone's job
|
|
16
|
+
* without a person clicking.
|
|
17
|
+
* - **closed without merging** — the work is not landing, so the card is deleted
|
|
18
|
+
* rather than parked, and its checkout and branch go with it. There is no diff
|
|
19
|
+
* to review and no merge to approve, and leaving it would fill the review
|
|
20
|
+
* column with cards that can never leave it.
|
|
21
|
+
*
|
|
22
|
+
* This is a read-only observer. It asks `gh` about the ticket's recorded PR, and
|
|
23
|
+
* only the facts it needs come back. It never merges, never pushes the ticket's
|
|
24
|
+
* work, and never touches the local base branch. The close it writes is the
|
|
25
|
+
* card's ending and the retirement of the checkout and branch that went with it.
|
|
26
|
+
*
|
|
27
|
+
* The one outcome that runs anything is a pull request that no longer merges
|
|
28
|
+
* into main: that conflict is work the board can hand to an agent in the
|
|
29
|
+
* ticket's own worktree. It
|
|
30
|
+
* starts one run per main commit, records what happened from the run's own
|
|
31
|
+
* trace, and leaves the card in Review either way. It never rebases, never
|
|
32
|
+
* force-pushes, and never merges the pull request itself.
|
|
33
|
+
*/
|
|
34
|
+
const exec = promisify(execFile);
|
|
35
|
+
const GH_TIMEOUT_MS = 10_000;
|
|
36
|
+
/** How often a board in the background checks its review column. */
|
|
37
|
+
export const MERGE_POLL_MS = 5_000;
|
|
38
|
+
const STATES = new Set(["OPEN", "CLOSED", "MERGED"]);
|
|
39
|
+
/** A `gh` field that may be absent; an empty string is the same as missing. */
|
|
40
|
+
const asText = (value) => typeof value === "string" && value ? value : null;
|
|
41
|
+
/**
|
|
42
|
+
* What `gh` thinks of the recorded pull request. Everything that is not a
|
|
43
|
+
* clean answer — no `gh`, no login, no network, no PR, output that does not
|
|
44
|
+
* parse — becomes `null`: an observation that could not be made is not an
|
|
45
|
+
* error the person needs to see.
|
|
46
|
+
*
|
|
47
|
+
* `mergedAt` outranks `state`. GitHub has been seen reporting `CLOSED` for a
|
|
48
|
+
* moment around a merge; a PR with a merge timestamp is merged, whatever the
|
|
49
|
+
* state says, and this watcher must never delete work that landed.
|
|
50
|
+
*/
|
|
51
|
+
export async function readPullRequest(path, prUrl, ghCommand = "gh") {
|
|
52
|
+
// Never let an empty value or a branch name select the checkout's PR.
|
|
53
|
+
if (!/^https:\/\/[^/\s]+\/[^/\s]+\/[^/\s]+\/pull\/[1-9]\d*\/?$/.test(prUrl))
|
|
54
|
+
return null;
|
|
55
|
+
try {
|
|
56
|
+
const { stdout } = await exec(ghCommand, [
|
|
57
|
+
"pr",
|
|
58
|
+
"view",
|
|
59
|
+
prUrl,
|
|
60
|
+
"--json",
|
|
61
|
+
"state,url,mergedAt,mergeable,mergeStateStatus,baseRefOid,headRefOid",
|
|
62
|
+
], {
|
|
63
|
+
cwd: path,
|
|
64
|
+
timeout: GH_TIMEOUT_MS,
|
|
65
|
+
});
|
|
66
|
+
const parsed = JSON.parse(String(stdout));
|
|
67
|
+
const mergedAt = typeof parsed.mergedAt === "string" && parsed.mergedAt ? parsed.mergedAt : null;
|
|
68
|
+
const reported = typeof parsed.state === "string" ? parsed.state.toUpperCase() : "";
|
|
69
|
+
const state = mergedAt ? "MERGED" : reported;
|
|
70
|
+
if (!STATES.has(state))
|
|
71
|
+
return null;
|
|
72
|
+
const mergeable = parsed.mergeable === "MERGEABLE" ||
|
|
73
|
+
parsed.mergeable === "CONFLICTING" ||
|
|
74
|
+
parsed.mergeable === "UNKNOWN"
|
|
75
|
+
? parsed.mergeable
|
|
76
|
+
: null;
|
|
77
|
+
return {
|
|
78
|
+
state: state,
|
|
79
|
+
url: asText(parsed.url),
|
|
80
|
+
mergeable,
|
|
81
|
+
mergeStateStatus: asText(parsed.mergeStateStatus),
|
|
82
|
+
baseRefOid: asText(parsed.baseRefOid),
|
|
83
|
+
headRefOid: asText(parsed.headRefOid),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* GitHub says a conflict two ways; either is enough to hand the branch to an
|
|
92
|
+
* agent. `UNKNOWN` is not a conflict: it means GitHub has not computed the
|
|
93
|
+
* answer yet, and starting a run on a guess would spend a ticket's time on a
|
|
94
|
+
* problem that may not exist.
|
|
95
|
+
*/
|
|
96
|
+
export function hasMergeConflict(pr) {
|
|
97
|
+
return pr.mergeable === "CONFLICTING" || pr.mergeStateStatus === "DIRTY";
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* What the resolution run actually did, in the words of its own trace: the
|
|
101
|
+
* files it opened and the commands it ran. This is a decision the board writes
|
|
102
|
+
* for the person, so it never asks the agent to describe itself.
|
|
103
|
+
*/
|
|
104
|
+
export function conflictDigest(actions) {
|
|
105
|
+
const read = [];
|
|
106
|
+
const edited = [];
|
|
107
|
+
const commands = [];
|
|
108
|
+
const seen = new Set();
|
|
109
|
+
const add = (target, value) => {
|
|
110
|
+
const detail = value.trim();
|
|
111
|
+
if (!detail)
|
|
112
|
+
return;
|
|
113
|
+
const key = `${target === commands ? "ran" : "touched"}:${detail}`;
|
|
114
|
+
if (seen.has(key))
|
|
115
|
+
return;
|
|
116
|
+
seen.add(key);
|
|
117
|
+
target.push(detail);
|
|
118
|
+
};
|
|
119
|
+
for (const action of actions.slice(-12)) {
|
|
120
|
+
const tool = action.tool ?? "";
|
|
121
|
+
if (tool === "read" || tool === "grep" || tool === "find" || tool === "ls") {
|
|
122
|
+
add(read, action.detail || action.label);
|
|
123
|
+
}
|
|
124
|
+
else if (tool === "edit" || tool === "write") {
|
|
125
|
+
add(edited, action.detail || action.label);
|
|
126
|
+
}
|
|
127
|
+
else if (tool === "bash") {
|
|
128
|
+
add(commands, action.detail || action.label);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const parts = [];
|
|
132
|
+
if (read.length > 0)
|
|
133
|
+
parts.push(`read ${read.join(", ")}`);
|
|
134
|
+
if (edited.length > 0)
|
|
135
|
+
parts.push(`edited ${edited.join(", ")}`);
|
|
136
|
+
if (commands.length > 0)
|
|
137
|
+
parts.push(`ran ${commands.map((command) => `\`${command}\``).join(", ")}`);
|
|
138
|
+
if (parts.length === 0)
|
|
139
|
+
return "The conflict run left no tool calls in its trace.";
|
|
140
|
+
return `What the conflict run did, from its own trace: it ${parts.join("; it ")}.`;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Watches the `review` column against GitHub, so a card is only in it while a
|
|
144
|
+
* diff is really waiting for a person. One pass reads each review ticket's own
|
|
145
|
+
* checkout, so a ticket whose worktree is gone (or a person's unrelated PR in
|
|
146
|
+
* the repo root) can never move the wrong card.
|
|
147
|
+
*/
|
|
148
|
+
export class MergeWatcher {
|
|
149
|
+
db;
|
|
150
|
+
root;
|
|
151
|
+
rootFor;
|
|
152
|
+
ghCommand;
|
|
153
|
+
intervalMs;
|
|
154
|
+
isBusy;
|
|
155
|
+
resolveConflict;
|
|
156
|
+
onMergeabilityChange;
|
|
157
|
+
polling = null;
|
|
158
|
+
timer;
|
|
159
|
+
/**
|
|
160
|
+
* The base commit each ticket's conflict was last handed to a run for. One
|
|
161
|
+
* attempt per main commit is the rule: a resolution that failed must not be
|
|
162
|
+
* retried against the same main, and a poll must not start a second run for a
|
|
163
|
+
* conflict that is already being repaired.
|
|
164
|
+
*/
|
|
165
|
+
attemptedBase = new Map();
|
|
166
|
+
/** Tickets with a resolution run in flight, before `isBusy` can see it. */
|
|
167
|
+
resolving = new Set();
|
|
168
|
+
/**
|
|
169
|
+
* Tickets seen closed on the previous pass. Deleting a card is destructive, so
|
|
170
|
+
* one observation is not enough: GitHub can report `CLOSED` for a moment
|
|
171
|
+
* around a merge, and the next pass sees `MERGED`. Only a close that survives
|
|
172
|
+
* two passes is treated as the person saying the work is not landing.
|
|
173
|
+
*/
|
|
174
|
+
closedOnce = new Map();
|
|
175
|
+
observations = new Map();
|
|
176
|
+
getMergeability(ticketId) {
|
|
177
|
+
return this.observations.get(ticketId) ?? "unknown";
|
|
178
|
+
}
|
|
179
|
+
constructor({ db, root, rootFor, ghCommand = "gh", intervalMs = MERGE_POLL_MS, isBusy = () => false, resolveConflict, onMergeabilityChange, }) {
|
|
180
|
+
this.db = db;
|
|
181
|
+
this.root = root;
|
|
182
|
+
this.rootFor = rootFor;
|
|
183
|
+
this.ghCommand = ghCommand;
|
|
184
|
+
this.intervalMs = intervalMs;
|
|
185
|
+
this.isBusy = isBusy;
|
|
186
|
+
this.resolveConflict = resolveConflict;
|
|
187
|
+
this.onMergeabilityChange = onMergeabilityChange;
|
|
188
|
+
}
|
|
189
|
+
/** The checkout root a ticket lives in, or null when its repo is unreachable. */
|
|
190
|
+
rootOf(ticket) {
|
|
191
|
+
if (!this.rootFor)
|
|
192
|
+
return this.root;
|
|
193
|
+
try {
|
|
194
|
+
return this.rootFor(ticket);
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** Starts the background poll. Unref'd, so a board does not pin the process. */
|
|
201
|
+
start() {
|
|
202
|
+
if (this.timer)
|
|
203
|
+
return;
|
|
204
|
+
this.timer = setInterval(() => {
|
|
205
|
+
// A background observation must never surface as an unhandled rejection:
|
|
206
|
+
// the person did not ask for this pass and cannot act on it.
|
|
207
|
+
void this.poll().catch(() => { });
|
|
208
|
+
}, this.intervalMs);
|
|
209
|
+
this.timer.unref?.();
|
|
210
|
+
}
|
|
211
|
+
stop() {
|
|
212
|
+
if (!this.timer)
|
|
213
|
+
return;
|
|
214
|
+
clearInterval(this.timer);
|
|
215
|
+
this.timer = undefined;
|
|
216
|
+
}
|
|
217
|
+
/** One pass. Overlapping calls share the pass already in flight. */
|
|
218
|
+
poll() {
|
|
219
|
+
if (this.polling)
|
|
220
|
+
return this.polling;
|
|
221
|
+
this.polling = this.scan().finally(() => {
|
|
222
|
+
this.polling = null;
|
|
223
|
+
});
|
|
224
|
+
return this.polling;
|
|
225
|
+
}
|
|
226
|
+
async scan() {
|
|
227
|
+
for (const ticket of this.db.listTickets()) {
|
|
228
|
+
if (ticket.state !== "review")
|
|
229
|
+
continue;
|
|
230
|
+
// A run is still finishing with this checkout in hand.
|
|
231
|
+
if (this.isBusy(ticket.id))
|
|
232
|
+
continue;
|
|
233
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
234
|
+
await this.observe(ticket);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
async observe(ticket) {
|
|
238
|
+
const setObservation = (value) => {
|
|
239
|
+
if (this.observations.get(ticket.id) === value)
|
|
240
|
+
return;
|
|
241
|
+
this.observations.set(ticket.id, value);
|
|
242
|
+
this.onMergeabilityChange?.();
|
|
243
|
+
};
|
|
244
|
+
let path;
|
|
245
|
+
try {
|
|
246
|
+
const repoRoot = this.rootOf(ticket);
|
|
247
|
+
if (!repoRoot)
|
|
248
|
+
return;
|
|
249
|
+
path = worktreePath(repoRoot, ticket.id);
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
return; // An id that cannot name a checkout cannot have one either.
|
|
253
|
+
}
|
|
254
|
+
// Only observe tickets with an existing checkout; never create one to poll.
|
|
255
|
+
if (!existsSync(join(path, ".git"))) {
|
|
256
|
+
setObservation("unknown");
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const prUrl = ticket.pr_url;
|
|
260
|
+
if (!prUrl) {
|
|
261
|
+
this.closedOnce.delete(ticket.id);
|
|
262
|
+
setObservation("unknown");
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const pr = await readPullRequest(path, prUrl, this.ghCommand);
|
|
266
|
+
// The card or its recorded PR may have changed while `gh` was answering.
|
|
267
|
+
const current = this.db.getTicket(ticket.id);
|
|
268
|
+
if (!current || current.state !== "review" || current.pr_url !== prUrl) {
|
|
269
|
+
this.closedOnce.delete(ticket.id);
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (!pr) {
|
|
273
|
+
this.closedOnce.delete(ticket.id);
|
|
274
|
+
setObservation("unknown");
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
setObservation(pr.mergeable === "MERGEABLE" && pr.mergeStateStatus !== "DIRTY"
|
|
278
|
+
? "mergeable"
|
|
279
|
+
: hasMergeConflict(pr)
|
|
280
|
+
? "conflicting"
|
|
281
|
+
: "unknown");
|
|
282
|
+
// A close is destructive, so it needs two passes: a merged PR can report
|
|
283
|
+
// `CLOSED` for one poll and `MERGED` on the next, and the card must not be
|
|
284
|
+
// deleted for a state GitHub was still settling.
|
|
285
|
+
if (pr.state === "CLOSED") {
|
|
286
|
+
if (this.closedOnce.get(ticket.id) !== prUrl) {
|
|
287
|
+
this.closedOnce.set(ticket.id, prUrl);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
this.closedOnce.delete(ticket.id);
|
|
291
|
+
await this.discard(current);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
this.closedOnce.delete(ticket.id);
|
|
295
|
+
if (pr.state === "MERGED") {
|
|
296
|
+
await this.finish(current, pr);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
if (pr.state !== "OPEN")
|
|
300
|
+
return;
|
|
301
|
+
// A pull request that still merges is the normal case: nothing to repair.
|
|
302
|
+
if (!hasMergeConflict(pr))
|
|
303
|
+
return;
|
|
304
|
+
this.repair(current, pr, path);
|
|
305
|
+
}
|
|
306
|
+
/** The merge already happened on GitHub; the card says so and the ticket retires. */
|
|
307
|
+
async finish(ticket, pr) {
|
|
308
|
+
let closed;
|
|
309
|
+
try {
|
|
310
|
+
closed = this.db.transition(ticket.id, "done");
|
|
311
|
+
}
|
|
312
|
+
catch {
|
|
313
|
+
// Another actor won the race, or the state machine refused. Either way
|
|
314
|
+
// the ticket is not ours to move, and a background pass must not throw.
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
this.db.addComment({
|
|
318
|
+
ticket_id: ticket.id,
|
|
319
|
+
type: "system",
|
|
320
|
+
author: "github",
|
|
321
|
+
text: `Pull request merged: ${pr.url ?? "the ticket branch"}`,
|
|
322
|
+
});
|
|
323
|
+
// The merge is the review, so there is nothing left to check out or review.
|
|
324
|
+
const repoRoot = this.rootOf(closed);
|
|
325
|
+
if (repoRoot)
|
|
326
|
+
await retireWorktree(repoRoot, ticket.id, closed.branch);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Hand a conflicted branch to an agent, once per main commit. The pass does
|
|
330
|
+
* not wait for the run: a repair takes minutes, and the rest of the review
|
|
331
|
+
* column still has to be observed meanwhile. The run's ending is reconciled
|
|
332
|
+
* by the promise below, not by a later poll.
|
|
333
|
+
*/
|
|
334
|
+
repair(ticket, pr, path) {
|
|
335
|
+
const resolve = this.resolveConflict;
|
|
336
|
+
if (!resolve)
|
|
337
|
+
return;
|
|
338
|
+
if (this.resolving.has(ticket.id) || this.isBusy(ticket.id))
|
|
339
|
+
return;
|
|
340
|
+
const base = pr.baseRefOid ?? "";
|
|
341
|
+
if (this.attemptedBase.get(ticket.id) === base)
|
|
342
|
+
return;
|
|
343
|
+
this.resolving.add(ticket.id);
|
|
344
|
+
const startHead = worktreeHead(path);
|
|
345
|
+
void this.resolveConflictRun(resolve, ticket, pr, path, startHead)
|
|
346
|
+
.catch(() => { })
|
|
347
|
+
.finally(() => {
|
|
348
|
+
this.resolving.delete(ticket.id);
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
async resolveConflictRun(resolve, ticket, pr, path, startHead) {
|
|
352
|
+
const base = pr.baseRefOid ?? "";
|
|
353
|
+
let settled;
|
|
354
|
+
try {
|
|
355
|
+
settled = await resolve(ticket, {
|
|
356
|
+
baseRefOid: pr.baseRefOid,
|
|
357
|
+
baseBranch: "main",
|
|
358
|
+
startHead,
|
|
359
|
+
headRefOid: pr.headRefOid,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
catch {
|
|
363
|
+
// A run that could not start is not a failed resolution: leave the base
|
|
364
|
+
// unclaimed so a later pass can try when the board has room.
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
// `null` is "not now" — the card keeps waiting for a free slot.
|
|
368
|
+
if (!settled)
|
|
369
|
+
return;
|
|
370
|
+
// The attempt is spent whether it worked or not. A second run against the
|
|
371
|
+
// same main commit would pay twice for the same conflict.
|
|
372
|
+
this.attemptedBase.set(ticket.id, base);
|
|
373
|
+
this.note(ticket.id, `Main moved and the pull request now has a merge conflict. Resolving it in the ticket's own worktree.`);
|
|
374
|
+
// The person may have moved the card while the run worked; a repair never
|
|
375
|
+
// overrules them.
|
|
376
|
+
const current = this.db.getTicket(ticket.id);
|
|
377
|
+
if (!current || current.state !== "review")
|
|
378
|
+
return;
|
|
379
|
+
const facts = await readMergeCommit(path, startHead);
|
|
380
|
+
const fixed = facts.moved && facts.merge && facts.pushed && facts.conflicts.length === 0;
|
|
381
|
+
// The run's own trace is the record of what it did, whether or not the
|
|
382
|
+
// merge landed.
|
|
383
|
+
this.db.addComment({
|
|
384
|
+
ticket_id: ticket.id,
|
|
385
|
+
type: "decision",
|
|
386
|
+
author: "zelio",
|
|
387
|
+
text: conflictDigest(settled.actions ?? []),
|
|
388
|
+
});
|
|
389
|
+
if (fixed) {
|
|
390
|
+
this.note(ticket.id, `Merge conflict resolved: main is now merged into the ticket branch at ${facts.head?.slice(0, 7) ?? "a new commit"} and the branch is pushed. The card stays in Review.`);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
const reason = facts.conflicts.length > 0
|
|
394
|
+
? `git still reports ${facts.conflicts.length} unmerged ${facts.conflicts.length === 1 ? "path" : "paths"}`
|
|
395
|
+
: !facts.moved
|
|
396
|
+
? "the branch did not move"
|
|
397
|
+
: !facts.merge
|
|
398
|
+
? "the branch has no merge commit"
|
|
399
|
+
: "the merge was not pushed";
|
|
400
|
+
this.note(ticket.id, `The merge conflict is still open: ${reason}. The card is back in Review, and the board will not try this main commit again.`);
|
|
401
|
+
}
|
|
402
|
+
/** One board event, in the board's own voice. */
|
|
403
|
+
note(ticketId, text) {
|
|
404
|
+
this.db.addComment({ ticket_id: ticketId, type: "system", author: "zelio", text });
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Somebody closed the pull request, which is the person saying this work is
|
|
408
|
+
* not landing. The card was waiting for a diff, so it stops waiting: the row
|
|
409
|
+
* goes and the checkout and branch go with it.
|
|
410
|
+
*
|
|
411
|
+
* The branch is retired too. With the row gone nothing on the board would ever
|
|
412
|
+
* point at it again, and a close is the person saying this work is not landing.
|
|
413
|
+
* A checkout git refuses to remove is not worth failing a background pass over
|
|
414
|
+
* — retiring is quiet by design.
|
|
415
|
+
*/
|
|
416
|
+
async discard(ticket) {
|
|
417
|
+
const removed = this.db.deleteTicket(ticket.id);
|
|
418
|
+
if (!removed)
|
|
419
|
+
return;
|
|
420
|
+
const repoRoot = this.rootOf(removed);
|
|
421
|
+
if (repoRoot)
|
|
422
|
+
await retireWorktree(repoRoot, ticket.id, removed.branch);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
//# sourceMappingURL=merge-watch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;;;;;;OASG;IACK,KAAK,CAAC,OAAO,CAAC,MAAc;QAClC,MAAM,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAChD,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACtC,IAAI,QAAQ;YAAE,MAAM,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1E,CAAC;CACF"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { stripVTControlCharacters } from "node:util";
|
|
3
|
+
/** A stuck harness must not make the Agents page hang forever. */
|
|
4
|
+
const DEFAULT_TIMEOUT_MS = 10_000;
|
|
5
|
+
const MAX_STDERR = 400;
|
|
6
|
+
/**
|
|
7
|
+
* Pi prints a provider/model table, not a list of bare IDs. Keep both columns
|
|
8
|
+
* so models from the same provider remain distinct and --model selects the
|
|
9
|
+
* intended provider. Custom wrappers may still print IDs in the first column.
|
|
10
|
+
*/
|
|
11
|
+
export function parseModelList(stdout) {
|
|
12
|
+
const lines = stripVTControlCharacters(stdout)
|
|
13
|
+
.split("\n")
|
|
14
|
+
.map((line) => line.trim())
|
|
15
|
+
.filter(Boolean);
|
|
16
|
+
if (lines.some((line) => /^No models (?:available|matching)\b/.test(line)))
|
|
17
|
+
return [];
|
|
18
|
+
const header = lines.findIndex((line) => /^provider\s+model(?:\s|$)/.test(line));
|
|
19
|
+
const seen = new Set();
|
|
20
|
+
for (const line of header < 0 ? lines : lines.slice(header + 1)) {
|
|
21
|
+
const [first, model] = line.split(/\s+/);
|
|
22
|
+
if (!first)
|
|
23
|
+
continue;
|
|
24
|
+
if (header >= 0) {
|
|
25
|
+
if (model)
|
|
26
|
+
seen.add(`${first}/${model}`);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
seen.add(first);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return [...seen];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Asks one harness which models it knows. Every failure — no such command, a
|
|
36
|
+
* non-zero exit, a timeout — becomes an `error` string, because the caller is a
|
|
37
|
+
* page that has to keep working with a free-text model field.
|
|
38
|
+
*/
|
|
39
|
+
export function listAgentModels(command, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
40
|
+
return new Promise((resolve) => {
|
|
41
|
+
let stdout = "";
|
|
42
|
+
let stderr = "";
|
|
43
|
+
let settled = false;
|
|
44
|
+
let child;
|
|
45
|
+
const finish = (result) => {
|
|
46
|
+
if (settled)
|
|
47
|
+
return;
|
|
48
|
+
settled = true;
|
|
49
|
+
clearTimeout(timer);
|
|
50
|
+
resolve(result);
|
|
51
|
+
};
|
|
52
|
+
try {
|
|
53
|
+
child = spawn(command, ["--list-models"], { stdio: ["ignore", "pipe", "pipe"] });
|
|
54
|
+
}
|
|
55
|
+
catch (cause) {
|
|
56
|
+
const message = cause instanceof Error ? cause.message : "the harness could not start";
|
|
57
|
+
resolve({ models: [], error: `${command}: ${message}` });
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const timer = setTimeout(() => {
|
|
61
|
+
child.kill("SIGKILL");
|
|
62
|
+
finish({ models: [], error: `${command} --list-models timed out` });
|
|
63
|
+
}, timeoutMs);
|
|
64
|
+
child.stdout?.setEncoding("utf8");
|
|
65
|
+
child.stdout?.on("data", (chunk) => {
|
|
66
|
+
stdout += chunk;
|
|
67
|
+
});
|
|
68
|
+
child.stderr?.setEncoding("utf8");
|
|
69
|
+
child.stderr?.on("data", (chunk) => {
|
|
70
|
+
stderr = (stderr + chunk).slice(-MAX_STDERR);
|
|
71
|
+
});
|
|
72
|
+
child.on("error", (cause) => {
|
|
73
|
+
finish({ models: [], error: `${command}: ${cause.message}` });
|
|
74
|
+
});
|
|
75
|
+
child.on("close", (code) => {
|
|
76
|
+
if (code === 0) {
|
|
77
|
+
finish({ models: parseModelList(stdout), error: null });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const detail = stderr.trim().replace(/\s+/g, " ");
|
|
81
|
+
finish({
|
|
82
|
+
models: [],
|
|
83
|
+
error: `${command} --list-models exited ${code ?? "without a code"}${detail ? `: ${detail}` : ""}`,
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/run/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAErD,kEAAkE;AAClE,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,MAAM,UAAU,GAAG,GAAG,CAAC;AASvB;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,MAAM,KAAK,GAAG,wBAAwB,CAAC,MAAM,CAAC;SAC3C,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,MAAM,CAAC,OAAO,CAAC,CAAC;IACnB,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,qCAAqC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,EAAE,CAAC;IAEtF,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACjF,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,IAAI,IAAI,MAAM,GAAG,CAAC,CAAC,C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,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;gBACxD,OAAO;YACT,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;YAClD,MAAM,CAAC;gBACL,MAAM,EAAE,EAAE;gBACV,KAAK,EAAE,GAAG,OAAO,yBAAyB,IAAI,IAAI,gBAAgB,GAChE,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,EAC3B,EAAE;aACH,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Best-effort trace phase; validation failures deliberately reopen implementation. */
|
|
2
|
+
export function phaseForTool(current, tool, args, failed = false) {
|
|
3
|
+
if (failed && current === "validate")
|
|
4
|
+
return "implement";
|
|
5
|
+
if (tool === "read" ||
|
|
6
|
+
tool === "grep" ||
|
|
7
|
+
tool === "find" ||
|
|
8
|
+
tool === "ls" ||
|
|
9
|
+
tool === "inspect") {
|
|
10
|
+
return current === "inspect" ? "inspect" : current;
|
|
11
|
+
}
|
|
12
|
+
if (tool === "edit" || tool === "write")
|
|
13
|
+
return "implement";
|
|
14
|
+
if (tool !== "bash")
|
|
15
|
+
return current;
|
|
16
|
+
const command = String(args?.command ?? "");
|
|
17
|
+
if (/\b(pnpm\s+(check|test|typecheck|lint|fmt:check)|npm\s+test|vitest|pytest|cargo\s+test)\b/.test(command))
|
|
18
|
+
return "validate";
|
|
19
|
+
if (/\b(git\s+(add|commit|push)|gh\s+pr\s+|zelio\s+ticket\s+comment|ZELIO_STATUS_URL)\b/.test(command))
|
|
20
|
+
return "finish";
|
|
21
|
+
return current;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=phases.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phases.js","sourceRoot":"","sources":["../../src/run/phases.ts"],"names":[],"mappings":"AAEA,uFAAuF;AACvF,MAAM,UAAU,YAAY,CAC1B,OAAgC,EAChC,IAAY,EACZ,IAAa,EACb,MAAM,GAAG,KAAK;IAEd,IAAI,MAAM,IAAI,OAAO,KAAK,UAAU;QAAE,OAAO,WAAW,CAAC;IACzD,IACE,IAAI,KAAK,MAAM;QACf,IAAI,KAAK,MAAM;QACf,IAAI,KAAK,MAAM;QACf,IAAI,KAAK,IAAI;QACb,IAAI,KAAK,SAAS,EAClB,CAAC;QACD,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;IACrD,CAAC;IACD,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,OAAO;QAAE,OAAO,WAAW,CAAC;IAC5D,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,OAAO,CAAC;IACpC,MAAM,OAAO,GAAG,MAAM,CAAE,IAAqC,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC;IAC9E,IACE,0FAA0F,CAAC,IAAI,CAC7F,OAAO,CACR;QAED,OAAO,UAAU,CAAC;IACpB,IACE,oFAAoF,CAAC,IAAI,CACvF,OAAO,CACR;QAED,OAAO,QAAQ,CAAC;IAClB,OAAO,OAAO,CAAC;AACjB,CAAC"}
|