@join-pantheon/cli 0.38.1 → 0.38.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.
@@ -0,0 +1,324 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { accessSync, closeSync, constants as fsConstants, existsSync, openSync, readSync, statSync } from "node:fs";
3
+ import { platform, tmpdir, homedir } from "node:os";
4
+ import { posix } from "node:path";
5
+ import { agentSpawn, inspectCmdShim } from "./which.js";
6
+ export const START_PROBE_MS = 5_000;
7
+ export const STARTS_TTL_MS = 4 * 3_600_000;
8
+ export const UNKNOWN_TTL_MS = 30 * 60_000;
9
+ export const CANNOT_START_TTL_MS = 5 * 60_000;
10
+ export const START_CONFIRM_MS = 45_000;
11
+ export const RUN_PROVEN_TTL_MS = 3_600_000;
12
+ export const RUN_PROVEN_MAX_MS = 8 * 3_600_000;
13
+ export const START_FAILURE_MAX_MS = 30_000;
14
+ export const START_ARGS = ["--version"];
15
+ const COPILOT_PLACEHOLDER = /^GitHub Copilot CLI was not found\./;
16
+ const ENV_MISSING = /^(?:\/usr\/bin\/|\/bin\/)?env: ['‘"]?([^'‘’":\s]+)['’"]?: No such file or directory$/;
17
+ const BAD_INTERPRETER = /: ([^\s:]+): bad interpreter: /;
18
+ const NOT_RECOGNIZED = /^'([^']{1,120})' is not recognized as an internal or external command,?$/;
19
+ const NAME = /^[A-Za-z0-9][A-Za-z0-9._+-]{0,40}$/;
20
+ const IDENTITY_SECRETS = ["PANTHEON_TOKEN", "PANTHEON_PRIVKEY"];
21
+ export function programOf(binary) {
22
+ return binary.replace(/^.*[\\/]/, "").replace(/\.(?:exe|cmd|bat|com|ps1)$/i, "") || binary;
23
+ }
24
+ const nameOf = (word) => {
25
+ const n = word ? programOf(word) : "";
26
+ return NAME.test(n) ? n : undefined;
27
+ };
28
+ export function startWhy(kind, program, needs) {
29
+ const p = NAME.test(program) ? program : "its command";
30
+ switch (kind) {
31
+ case "placeholder": return `the \`${p}\` command here is the stand-in VS Code installs, not the Copilot CLI itself`;
32
+ case "needs": return `it needs \`${needs ?? "another program"}\` to start, and that cannot be found here`;
33
+ case "missing": return `its program (\`${p}\`) is not there to run`;
34
+ case "off_path": return `its program (\`${p}\`) is not in any folder Pantheon's worker looks in`;
35
+ case "not_runnable": return `its program (\`${p}\`) is there but cannot be run`;
36
+ case "shim_target": return `its \`${p}\` command points at a program that is no longer there`;
37
+ case "not_found": return `it stops at once, saying a program was not found`;
38
+ }
39
+ }
40
+ const linesOf = (out) => out.split(/\r?\n/).map((l) => l.replace(/\x1b\[[0-9;?]*[A-Za-z]/g, "").trim()).filter(Boolean);
41
+ function neededProgram(lines, os) {
42
+ for (const l of lines) {
43
+ const m = ENV_MISSING.exec(l) ?? BAD_INTERPRETER.exec(l) ?? (os === "win32" ? NOT_RECOGNIZED.exec(l) : null);
44
+ const n = nameOf(m?.[1]);
45
+ if (n)
46
+ return n;
47
+ }
48
+ return undefined;
49
+ }
50
+ export function classifyStart(agent, r, os = platform(), program) {
51
+ if (r.error) {
52
+ if (r.error === "ENOENT" || r.error === "ENOTDIR")
53
+ return { verdict: "cannot_start", kind: "missing" };
54
+ if (r.error === "EACCES" || r.error === "ENOEXEC")
55
+ return { verdict: "cannot_start", kind: "not_runnable" };
56
+ return { verdict: "unknown", reason: `it could not be asked (${r.error.replace(/[^A-Za-z0-9_]/g, "").slice(0, 24)})` };
57
+ }
58
+ if (r.timedOut)
59
+ return { verdict: "unknown", reason: `its --version did not answer in ${Math.round(START_PROBE_MS / 1000)} s` };
60
+ const lines = linesOf(r.out);
61
+ if (agent === "copilot" && lines.some((l) => COPILOT_PLACEHOLDER.test(l)))
62
+ return { verdict: "cannot_start", kind: "placeholder" };
63
+ if (r.status === 0)
64
+ return { verdict: "starts" };
65
+ if (r.status === null)
66
+ return { verdict: "unknown", reason: "its --version was stopped before it answered" };
67
+ const needs = neededProgram(lines, os);
68
+ const other = needs && program && needs.toLowerCase() === programOf(program).toLowerCase() ? undefined : needs;
69
+ const notFound = () => (other ? { verdict: "cannot_start", kind: "needs", needs: other } : { verdict: "cannot_start", kind: "not_found" });
70
+ if (r.status === 127)
71
+ return notFound();
72
+ if (r.status === 126)
73
+ return other ? { verdict: "cannot_start", kind: "needs", needs: other } : { verdict: "cannot_start", kind: "not_runnable" };
74
+ if (os === "win32" && (r.status === 9009 || (lines.length <= 3 && NOT_RECOGNIZED.test(lines[0] ?? ""))))
75
+ return notFound();
76
+ return { verdict: "unknown", reason: `its --version ended with exit ${r.status}` };
77
+ }
78
+ const isRunnableFile = (f) => {
79
+ try {
80
+ if (!statSync(f).isFile())
81
+ return false;
82
+ accessSync(f, fsConstants.X_OK);
83
+ return true;
84
+ }
85
+ catch {
86
+ return false;
87
+ }
88
+ };
89
+ const stamp = (f) => {
90
+ try {
91
+ const s = statSync(f);
92
+ return `${s.mtimeMs}:${s.size}:${s.ino}`;
93
+ }
94
+ catch {
95
+ return "-";
96
+ }
97
+ };
98
+ export function startFile(binary, os = platform(), env = process.env, shim = (f) => inspectCmdShim(f)) {
99
+ if (os === "win32") {
100
+ if (!/^(?:[A-Za-z]:[\\/]|\\\\)/.test(binary))
101
+ return { path: null, sig: "-" };
102
+ let target = "";
103
+ if (/\.(?:cmd|bat)$/i.test(binary)) {
104
+ const r = shim(binary);
105
+ target = "command" in r ? `>${r.args[r.args.length - 1] ?? r.command}|${stamp(r.args[r.args.length - 1] ?? r.command)}` : `>${"missing" in r && r.missing ? `gone:${r.missing}` : "unread"}`;
106
+ }
107
+ return { path: binary, sig: `${binary}|${stamp(binary)}${target}` };
108
+ }
109
+ if (binary.includes("/"))
110
+ return { path: binary, sig: `${binary}|${stamp(binary)}` };
111
+ for (const dir of (env.PATH ?? "").split(":")) {
112
+ if (!dir)
113
+ continue;
114
+ const f = posix.join(dir, binary);
115
+ if (isRunnableFile(f))
116
+ return { path: f, sig: `${f}|${stamp(f)}` };
117
+ }
118
+ return { path: null, sig: "-" };
119
+ }
120
+ function shebangOf(file) {
121
+ let fd = null;
122
+ try {
123
+ fd = openSync(file, "r");
124
+ const buf = Buffer.alloc(256);
125
+ const n = readSync(fd, buf, 0, 256, 0);
126
+ const first = buf.subarray(0, n).toString("utf8").split("\n", 1)[0] ?? "";
127
+ const m = /^#!\s*(\/[^\s]+)/.exec(first);
128
+ return m ? m[1] : null;
129
+ }
130
+ catch {
131
+ return null;
132
+ }
133
+ finally {
134
+ if (fd !== null) {
135
+ try {
136
+ closeSync(fd);
137
+ }
138
+ catch { }
139
+ }
140
+ }
141
+ }
142
+ export function staticStart(binary, o = {}) {
143
+ const os = o.os ?? platform();
144
+ const exists = o.exists ?? existsSync;
145
+ if (os === "win32") {
146
+ if (!/^(?:[A-Za-z]:[\\/]|\\\\)/.test(binary))
147
+ return null;
148
+ if (!exists(binary))
149
+ return { verdict: "cannot_start", kind: "missing" };
150
+ if (/\.(?:cmd|bat)$/i.test(binary)) {
151
+ const r = (o.shim ?? ((f) => inspectCmdShim(f)))(binary);
152
+ if (!("command" in r) && r.missing)
153
+ return { verdict: "cannot_start", kind: "shim_target" };
154
+ }
155
+ return null;
156
+ }
157
+ const path = binary.includes("/") ? binary : o.file?.path ?? null;
158
+ if (!path)
159
+ return null;
160
+ if (binary.includes("/")) {
161
+ if (!existsSync(path))
162
+ return { verdict: "cannot_start", kind: "missing" };
163
+ if (!isRunnableFile(path))
164
+ return { verdict: "cannot_start", kind: "not_runnable" };
165
+ }
166
+ const interp = shebangOf(path);
167
+ if (interp && !/\/env$/.test(interp) && !exists(interp)) {
168
+ const n = nameOf(interp);
169
+ return n ? { verdict: "cannot_start", kind: "needs", needs: n } : { verdict: "cannot_start", kind: "not_runnable" };
170
+ }
171
+ return null;
172
+ }
173
+ export const startRunner = (timeoutMs = START_PROBE_MS) => (binary, args) => {
174
+ let sp;
175
+ try {
176
+ sp = agentSpawn(binary, args);
177
+ }
178
+ catch (e) {
179
+ return { status: null, out: "", error: e.name || "Error" };
180
+ }
181
+ const env = { ...process.env, NO_COLOR: "1" };
182
+ for (const k of IDENTITY_SECRETS)
183
+ delete env[k];
184
+ const cwd = [tmpdir(), homedir()].find((d) => { try {
185
+ return statSync(d).isDirectory();
186
+ }
187
+ catch {
188
+ return false;
189
+ } });
190
+ const r = spawnSync(sp.command, sp.args, {
191
+ encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: timeoutMs, killSignal: "SIGKILL", windowsHide: true,
192
+ maxBuffer: 256 * 1024, env, ...(cwd ? { cwd } : {}), ...sp.options,
193
+ });
194
+ if (r.error) {
195
+ const code = r.error.code ?? "";
196
+ if (code === "ETIMEDOUT")
197
+ return { status: null, out: "", timedOut: true };
198
+ if (code === "ENOBUFS")
199
+ return { status: null, out: "" };
200
+ return { status: null, out: "", error: String(code || "Error") };
201
+ }
202
+ return { status: r.status, out: `${r.stdout ?? ""}\n${r.stderr ?? ""}` };
203
+ };
204
+ const cache = new Map();
205
+ const keyOf = (agent, binary) => `${agent}\0${binary}`;
206
+ function ttlOf(e, confirmMs) {
207
+ if (e.check.verdict === "starts")
208
+ return STARTS_TTL_MS;
209
+ if (e.check.verdict === "unknown")
210
+ return UNKNOWN_TTL_MS;
211
+ if (e.byRun)
212
+ return Math.min(RUN_PROVEN_TTL_MS * 2 ** Math.max(0, (e.strikes ?? 1) - 1), RUN_PROVEN_MAX_MS);
213
+ return e.check.confirmed ? CANNOT_START_TTL_MS : confirmMs;
214
+ }
215
+ function inWords(binary, f) {
216
+ if (f.verdict === "starts")
217
+ return { verdict: "starts", detail: "starts" };
218
+ if (f.verdict === "unknown" || !f.kind)
219
+ return { verdict: "unknown", detail: `could not tell (${f.reason ?? "no answer"})` };
220
+ const why = startWhy(f.kind, programOf(binary), f.needs);
221
+ return { verdict: "cannot_start", kind: f.kind, ...(f.needs ? { needs: f.needs } : {}), why, detail: `cannot start here: ${why}` };
222
+ }
223
+ function ask(agent, binary, file, o) {
224
+ const os = o.os ?? platform();
225
+ const still = staticStart(binary, { os, file, ...(o.shim ? { shim: o.shim } : {}), ...(o.exists ? { exists: o.exists } : {}) });
226
+ const asked = () => (o.run ?? startRunner())(binary, [...START_ARGS]);
227
+ let found;
228
+ if (still?.kind === "shim_target") {
229
+ const r = asked();
230
+ const said = classifyStart(agent, r, os, binary);
231
+ found = said.verdict !== "unknown" ? said : typeof r.status === "number" && r.status !== 0 && !r.error && !r.timedOut ? still : said;
232
+ }
233
+ else
234
+ found = still ?? classifyStart(agent, asked(), os, binary);
235
+ if (found.kind === "missing" && os !== "win32" && !binary.includes("/"))
236
+ return { ...found, kind: "off_path" };
237
+ return found;
238
+ }
239
+ export function canStart(backend, binary, o = {}) {
240
+ const now = o.now ?? Date.now();
241
+ const os = o.os ?? platform();
242
+ const confirmMs = o.confirmMs ?? START_CONFIRM_MS;
243
+ const file = startFile(binary, os, o.env ?? process.env, o.shim);
244
+ const key = keyOf(backend.id, binary);
245
+ const hit = cache.get(key);
246
+ const same = hit && hit.sig === file.sig ? hit : undefined;
247
+ if (same && !same.stale) {
248
+ const age = now - same.at;
249
+ if (age >= 0 && age < ttlOf(same, confirmMs))
250
+ return same.check;
251
+ }
252
+ const words = inWords(binary, ask(backend.id, binary, file, o));
253
+ let check = words;
254
+ if (words.verdict === "cannot_start") {
255
+ const was = same?.check.verdict === "cannot_start" ? same.check : undefined;
256
+ const since = was?.since ?? now;
257
+ check = { ...words, since, confirmed: !!was?.confirmed || (!!was && now - since >= confirmMs) };
258
+ }
259
+ cache.set(key, { check, at: now, sig: file.sig, ...(same?.strikes ? { strikes: same.strikes } : {}) });
260
+ return check;
261
+ }
262
+ export function markCannotStart(backend, binary, died, o = {}) {
263
+ const now = o.now ?? Date.now();
264
+ const os = o.os ?? platform();
265
+ const file = startFile(binary, os, o.env ?? process.env, o.shim);
266
+ const key = keyOf(backend.id, binary);
267
+ const hit = cache.get(key);
268
+ const same = hit && hit.sig === file.sig ? hit : undefined;
269
+ const asked = inWords(binary, ask(backend.id, binary, file, o));
270
+ if (asked.verdict === "cannot_start") {
271
+ const since = same?.check.verdict === "cannot_start" && same.check.since ? same.check.since : now;
272
+ const check = { ...asked, since, confirmed: true };
273
+ cache.set(key, { check, at: now, sig: file.sig });
274
+ return check;
275
+ }
276
+ const check = { ...inWords(binary, { verdict: "cannot_start", kind: died.kind, ...(died.needs ? { needs: died.needs } : {}) }), since: now, confirmed: true };
277
+ cache.set(key, { check, at: now, sig: file.sig, byRun: true, strikes: (same?.strikes ?? 0) + 1 });
278
+ return check;
279
+ }
280
+ export function startWorked(backend, binary, o = {}) {
281
+ const key = keyOf(backend.id, binary);
282
+ const hit = cache.get(key);
283
+ if (!hit || (hit.check.verdict === "starts" && !hit.strikes))
284
+ return;
285
+ const os = o.os ?? platform();
286
+ const file = startFile(binary, os, o.env ?? process.env, o.shim);
287
+ cache.set(key, { check: { verdict: "starts", detail: "starts" }, at: o.now ?? Date.now(), sig: file.sig });
288
+ }
289
+ export function forgetStart(o = {}) {
290
+ for (const e of cache.values()) {
291
+ if (e.check.verdict === "starts")
292
+ continue;
293
+ if (e.byRun && !o.runProven)
294
+ continue;
295
+ e.stale = true;
296
+ if (e.byRun)
297
+ delete e.byRun;
298
+ }
299
+ }
300
+ export function resetStartCache() { cache.clear(); }
301
+ export function startFailureOf(detail, o = {}) {
302
+ const os = o.os ?? platform();
303
+ const all = detail.split(/\r?\n/);
304
+ const first = (all[0] ?? "").trim();
305
+ const spawn = /^could not start "[^"\n]*": .*\b(ENOENT|ENOTDIR|EACCES|ENOEXEC)\b/.exec(first);
306
+ if (spawn)
307
+ return { kind: spawn[1] === "EACCES" || spawn[1] === "ENOEXEC" ? "not_runnable" : "missing" };
308
+ const exit = /^exit (\d+)$/.exec(first);
309
+ if (!exit)
310
+ return null;
311
+ const code = Number(exit[1]);
312
+ if (code === 0)
313
+ return null;
314
+ const lines = linesOf(all.slice(1).join("\n"));
315
+ const f = classifyStart(o.agent ?? "", { status: code, out: lines.join("\n") }, os, o.binary);
316
+ if (f.verdict !== "cannot_start" || !f.kind)
317
+ return null;
318
+ if (f.kind === "placeholder")
319
+ return lines.length <= 4 ? { kind: "placeholder" } : null;
320
+ if (o.ranMs !== undefined && o.ranMs > START_FAILURE_MAX_MS)
321
+ return null;
322
+ return { kind: f.kind, ...(f.needs ? { needs: f.needs } : {}) };
323
+ }
324
+ //# sourceMappingURL=agent-start.js.map
package/dist/agents.js CHANGED
@@ -10,6 +10,7 @@ import { launcher, kiroDir } from "./install.js";
10
10
  import { agentSpawn, loginShellEnv, loginShellLookup, loginShellRunner, which } from "./which.js";
11
11
  import { probeLinuxSandbox, sandboxAdvice } from "./linux-sandbox.js";
12
12
  import { earliest, isSignOut, whenAgain } from "./agent-outage.js";
13
+ import { canStart } from "./agent-start.js";
13
14
  import { PANTHEON_TOOL_NAMES, PANTHEON_TOOLS } from "./tools.js";
14
15
  import { claudeRunSettings, NO_CLAUDE_FEATURES, runTmpDir, sandboxCacheEnv, versionAtLeast } from "./claude-confine.js";
15
16
  export function launchArgs(agent, prompt, name) {
@@ -278,10 +279,23 @@ export function signedIn(backend, binary, run = runStatus, home = homedir()) {
278
279
  }
279
280
  return r.status === 0 ? { ok: true, detail: "signed in" } : { ok: false, detail: "not signed in" };
280
281
  }
282
+ export function startsHere(backend, binary, home = homedir()) {
283
+ if (backend.id === "cursor" && !existsSync(join(home, AGENT_HOME_DIR.cursor)))
284
+ return { verdict: "unknown", detail: "could not tell (not asked: never set up on this machine)" };
285
+ return canStart(backend, binary);
286
+ }
281
287
  export function chooseAgent(preferred, opts = {}) {
282
288
  const available = opts.available ?? detectAvailable();
283
289
  const check = opts.check === null ? null : (opts.check ?? ((b, bin) => signedIn(b, bin, undefined, opts.home)));
284
290
  const state = (b, bin) => (check ? check(b, bin) : undefined);
291
+ const starts = opts.startCheck === null ? null
292
+ : opts.startCheck ?? (opts.check === undefined ? (b, bin) => startsHere(b, bin, opts.home) : null);
293
+ const cannot = (b, bin) => {
294
+ if (!starts || NOT_FOR_UNATTENDED_RUNS.has(b.id))
295
+ return undefined;
296
+ const st = starts(b, bin);
297
+ return st.verdict === "cannot_start" ? st : undefined;
298
+ };
285
299
  if (preferred && preferred !== "auto") {
286
300
  const backend = agentById(preferred);
287
301
  if (!backend)
@@ -290,6 +304,9 @@ export function chooseAgent(preferred, opts = {}) {
290
304
  if (!hit)
291
305
  throw new Error(`${backend.label} is not on PATH (looked for ${backend.binaries.join(", ")})`);
292
306
  const out = opts.outages?.[backend.id];
307
+ const stuck = cannot(backend, hit.binary);
308
+ if (stuck)
309
+ return { backend, binary: hit.binary, because: "pinned", skipped: [], cannotStart: stuck, ...(out ? { outage: out } : {}) };
293
310
  return { backend, binary: hit.binary, signIn: state(backend, hit.binary), because: "pinned", skipped: [], ...(out ? { outage: out } : {}) };
294
311
  }
295
312
  if (!available.length)
@@ -317,12 +334,19 @@ export function chooseAgent(preferred, opts = {}) {
317
334
  if (boxed.length)
318
335
  order.splice(0, order.length, ...boxed);
319
336
  }
337
+ const unstartable = new Map();
320
338
  for (const c of order) {
321
339
  const out = opts.outages?.[c.backend.id];
322
340
  if (out) {
323
341
  skipped.push({ backend: c.backend, why: isSignOut(out) ? "signed out — until it is signed in again" : `unavailable until ${whenAgain(out.until)} — ${out.why}` });
324
342
  continue;
325
343
  }
344
+ const stuck = cannot(c.backend, c.binary);
345
+ if (stuck) {
346
+ skipped.push({ backend: c.backend, why: stuck.detail, cannotStart: stuck });
347
+ unstartable.set(c.backend.id, stuck);
348
+ continue;
349
+ }
326
350
  const s = state(c.backend, c.binary);
327
351
  if (!s || s.ok || s.unknown)
328
352
  return { backend: c.backend, binary: c.binary, ...(s ? { signIn: s } : {}), because: c.because, skipped };
@@ -339,13 +363,20 @@ export function chooseAgent(preferred, opts = {}) {
339
363
  const first = order.find((o) => outs[o.backend.id] === soonest);
340
364
  return { backend: first.backend, binary: first.binary, because: `${first.because} (every agent here is unavailable for now)`, skipped, outage: soonest };
341
365
  }
342
- const live = order;
366
+ const live = order.filter((o) => !unstartable.has(o.backend.id));
367
+ if (!live.length) {
368
+ const first = order[0];
369
+ return { backend: first.backend, binary: first.binary, because: order.length === 1 ? first.because : `${first.because} (none here can start)`,
370
+ skipped: skipped.filter((x) => x.backend.id !== first.backend.id), cannotStart: unstartable.get(first.backend.id) };
371
+ }
343
372
  const first = live.find((o) => !NEEDS_SIGN_IN_BEFORE_SPAWN.has(o.backend.id)) ?? live[0];
344
373
  return { backend: first.backend, binary: first.binary, signIn: state(first.backend, first.binary), because: `${first.because} (none signed in)`, skipped };
345
374
  }
346
375
  export function unattendedRefusalOf(c, o = {}) {
347
376
  if (NOT_FOR_UNATTENDED_RUNS.has(c.backend.id))
348
377
  return { cause: "not_for_unattended", says: KIRO_UNATTENDED_REFUSAL };
378
+ if (c.cannotStart)
379
+ return { cause: "cannot_start", says: `${c.backend.label} cannot start on this computer: ${c.cannotStart.why ?? "its program could not be started"}` };
349
380
  if (!SANDBOXED_FOR_UNATTENDED.has(c.backend.id) && !o.unsandboxedOk) {
350
381
  return { cause: "unsandboxed_off", says: c.because === "pinned"
351
382
  ? `woken runs here are pinned to ${c.backend.label} (a persona's agent: line, or the worker's --agent), which is set to leave teammates' requests for you, so this one waits for your next session. ` +
@@ -385,6 +416,37 @@ export function knownUserBinary(name, home = homedir(), os = platform()) {
385
416
  return null;
386
417
  }
387
418
  export const gitMissing = (os = platform()) => os === "win32" && !cliOnPath("git");
419
+ const INSTALL_LINE = {
420
+ codex: "npm install -g @openai/codex",
421
+ copilot: "npm install -g @github/copilot",
422
+ kiro: "curl -fsSL https://cli.kiro.dev/install | bash",
423
+ };
424
+ const cliName = (b) => (b.id === "copilot" ? "the Copilot CLI" : b.id === "cursor" ? "Cursor's command-line agent (cursor-agent)" : b.id === "kiro" ? "the Kiro CLI" : b.label);
425
+ export function cannotStartWords(backend, start, o = {}) {
426
+ const os = o.os ?? platform();
427
+ const why = start.why ?? "its program could not be started";
428
+ const line = backend.id === "claude-code" ? claudeInstallCommand(os) : INSTALL_LINE[backend.id];
429
+ const signIn = SIGN_IN_CHECK[backend.id].fix.replace(/^run\s+/, "type ").replace(/`/g, "").replace(/\s*\(.*\)$/, "");
430
+ let fix;
431
+ if (start.kind === "needs" && start.needs && backend.id === "claude-code") {
432
+ fix = `Install Claude Code with its own installer, which needs no ${start.needs === "node" ? "Node" : start.needs}: ${line}`;
433
+ }
434
+ else if (start.kind === "needs" && start.needs) {
435
+ fix = start.needs === "node"
436
+ ? `Install Node.js with the installer from nodejs.org, which puts \`node\` where Pantheon's worker finds it${os === "win32" ? " (if it still cannot start after that, sign out of Windows and back in)" : ""}`
437
+ : `Install \`${start.needs}\` where background programs find it, not only your terminal`;
438
+ }
439
+ else if (start.kind === "placeholder") {
440
+ fix = `Install ${cliName(backend)}: ${line} — then ${signIn}`;
441
+ }
442
+ else {
443
+ fix = line ? `Install ${cliName(backend)} again: ${line}` : `Install ${cliName(backend)} again`;
444
+ }
445
+ const round = o.pinned
446
+ ? ` — or unpin it (remove the persona's agent: line, or the worker's --agent) so ${o.other ? o.other.label : "another agent here"} takes teammates' requests`
447
+ : backend.id !== "claude-code" && !o.claudeHere ? ` — or install Claude Code instead (${claudeInstallCommand(os)}): Pantheon uses whichever agent starts` : "";
448
+ return { why, says: `${backend.label} cannot start on this computer: ${why}.`, fix: `${fix}${round}. Pantheon checks again by itself; pantheon doctor checks now.` };
449
+ }
388
450
  export function unattendedReadiness(o = {}) {
389
451
  if (o.available)
390
452
  return readinessFrom(o.available, o);
@@ -392,7 +454,8 @@ export function unattendedReadiness(o = {}) {
392
454
  let probed = null;
393
455
  const probe = o.sandboxProbe ?? probeLinuxSandbox;
394
456
  const probeOnce = () => (probed ??= { p: probe() }).p;
395
- o = { ...o, sandboxProbe: probeOnce };
457
+ const realStart = o.startCheck === undefined && o.check === undefined && !o.choose ? (b, bin) => startsHere(b, bin, o.home) : undefined;
458
+ o = { ...o, sandboxProbe: probeOnce, ...(realStart ? { startCheck: realStart } : {}) };
396
459
  const seen = new Map();
397
460
  const base = o.check === null ? null : (o.check ?? ((b, bin) => signedIn(b, bin, undefined, o.home)));
398
461
  const check = base === null ? null : (b, bin) => { const k = `${b.id}|${bin}`; let r = seen.get(k); if (!r) {
@@ -465,6 +528,12 @@ function readinessFrom(given, o) {
465
528
  return { ok: false, code: /no agent CLI on PATH|is not on PATH/.test(m) ? "no_agent" : "no_agent_choice", short: m.replace(/ \(looked for .*\)$/, "").slice(0, 120), says: m, fix: "pantheon doctor names what is missing" };
466
529
  }
467
530
  const refused = unattendedRefusalOf(choice, { ...(o.unsandboxedOk !== undefined ? { unsandboxedOk: o.unsandboxedOk } : {}), ...(o.needsSignIn ? { needsSignIn: o.needsSignIn } : {}) });
531
+ if (refused?.cause === "cannot_start" && choice.cannotStart) {
532
+ const pinned = choice.because === "pinned";
533
+ const w = cannotStartWords(choice.backend, choice.cannotStart, { os, pinned, ...(pinned ? { other: others().first } : {}), claudeHere: choice.backend.id === "claude-code" || given.some((a) => a.backend.id === "claude-code") });
534
+ return { ok: false, code: "cannot_start", short: `${choice.backend.label} can't start there`, says: `${w.says} A request while you're away would fail, so teammates' requests wait.`, fix: w.fix,
535
+ agent: choice.backend.id, ...(choice.cannotStart.confirmed ? { certain: true } : {}) };
536
+ }
468
537
  if (refused && refused.cause !== "not_signed_in") {
469
538
  const pinnedOff = choice.because === "pinned" && refused.cause === "unsandboxed_off";
470
539
  const fix = pinnedOff
@@ -486,14 +555,15 @@ function readinessFrom(given, o) {
486
555
  return { ok: true, short: "", says: `${choice.backend.label} takes teammates' requests while you're away.`, fix: "", agent: choice.backend.id, ...(choice.signIn?.unknown ? { unknown: true } : {}) };
487
556
  }
488
557
  export function describeChoice(c) {
489
- const head = `${c.backend.label}${c.signIn ? ` — ${c.signIn.detail}` : ""} (${c.because})`;
558
+ const head = `${c.backend.label}${c.cannotStart ? ` — ${c.cannotStart.detail}` : c.signIn ? ` — ${c.signIn.detail}` : ""} (${c.because})`;
490
559
  return c.skipped.length ? `${head}; skipped ${c.skipped.map((s) => `${s.backend.label} — ${s.why}`).join("; ")}` : head;
491
560
  }
492
561
  export function skippedSummary(c) {
493
562
  if (!c.skipped.length)
494
563
  return "";
495
564
  const why = [...new Set(c.skipped.map((s) => (s.why === KIRO_UNATTENDED_REFUSAL ? `${s.backend.label} cannot run unattended yet`
496
- : s.why === unsandboxedRefusal(s.backend.label) ? `${s.backend.label} has no sandbox` : "not signed in")))];
565
+ : s.why === unsandboxedRefusal(s.backend.label) ? `${s.backend.label} has no sandbox`
566
+ : s.cannotStart ? `${s.backend.label} cannot start here` : "not signed in")))];
497
567
  return `${c.skipped.length} skipped (${why.join("; ")})`;
498
568
  }
499
569
  export function resolveAgent(preferred) {
package/dist/cli.js CHANGED
@@ -2553,8 +2553,20 @@ let workerAlerts = null;
2553
2553
  let workerAlertsSaid = false;
2554
2554
  async function trackServiceStart(kind, noNotify) {
2555
2555
  try {
2556
- const { trackService, composeCrashLoop, loopLine } = await import("./crash-loop.js");
2556
+ const { trackService, composeCrashLoop, loopLine, watchProbation } = await import("./crash-loop.js");
2557
+ let probation = null;
2558
+ try {
2559
+ probation = watchProbation(kind, {
2560
+ version: VERSION,
2561
+ relayAnswers: async (relay) => (await (await import("./version-health.js")).fetchRelayPkg(relay, 5000)) !== null,
2562
+ exit: () => { process.exit(1); },
2563
+ log: (line) => console.error(line),
2564
+ onKept: () => console.error(D(` pantheon ${VERSION} works here: the upgrade is kept`)),
2565
+ });
2566
+ }
2567
+ catch { }
2557
2568
  trackService(kind, {
2569
+ ...(probation ? { onConnectedHealthy: probation.onConnectedHealthy } : {}),
2558
2570
  onLoop: (loop) => {
2559
2571
  console.error(`! ${loopLine(kind, loop)}`);
2560
2572
  if (kind === "worker") {
@@ -3413,6 +3425,10 @@ async function main() {
3413
3425
  console.error(`\n${B("nothing installed")} — npm has no ${asked}. Check the version (\`npm view @join-pantheon/cli versions\`).`);
3414
3426
  process.exit(1);
3415
3427
  }
3428
+ if (r.heldBack) {
3429
+ console.error(`\n${B("nothing installed")} ${D(`(still ${r.from}; Pantheon updates by itself when a newer release is out)`)}`);
3430
+ return;
3431
+ }
3416
3432
  if (r.alreadyCurrent) {
3417
3433
  console.error(`\n${B("already up to date")} ${D(`(${r.from})`)}`);
3418
3434
  if (process.platform === "darwin") {
@@ -3,6 +3,7 @@ import { join } from "node:path";
3
3
  import { readStateText, withFileLock } from "./file-lock.js";
4
4
  import { atomicWrite } from "./worker-policy.js";
5
5
  import { BUDGET } from "./notice.js";
6
+ import { probationPassed, probationStopExpected, watchNeverOnline } from "./upgrade-probation.js";
6
7
  export const WATCHED = ["worker", "notifier"];
7
8
  export const LOOP_WINDOW_MS = 10 * 60_000;
8
9
  export const LOOP_STARTS = 3;
@@ -115,6 +116,12 @@ export function markExpectedExit(kind, o = {}) {
115
116
  export function stopIsExpected(kind, o = {}) {
116
117
  if (kind === "worker" || kind === "notifier")
117
118
  markExpectedExit(kind, o);
119
+ if (kind === "worker") {
120
+ try {
121
+ probationStopExpected();
122
+ }
123
+ catch { }
124
+ }
118
125
  }
119
126
  export function activeLoop(kind, o = {}) {
120
127
  const loop = (o.file ?? readStarts(o.home))[kind]?.loop;
@@ -157,7 +164,10 @@ export function trackService(kind, o = {}) {
157
164
  r = recordStart(kind, { ...(o.home ? { home: o.home } : {}), now: now() });
158
165
  }
159
166
  catch { }
160
- tracking = { kind, ...(o.home ? { home: o.home } : {}), startedAt: now(), healthy: false, expectExit: false, connected: false, timers: [] };
167
+ tracking = {
168
+ kind, ...(o.home ? { home: o.home } : {}), startedAt: now(), healthy: false, expectExit: false, connected: false, tried: new Set(), reached: false,
169
+ ...(o.onConnectedHealthy ? { onConnectedHealthy: o.onConnectedHealthy } : {}), timers: [], timer: o.timer ?? ((fn, ms) => setTimeout(fn, ms)),
170
+ };
161
171
  const t = tracking;
162
172
  if (!o.passive) {
163
173
  const steady = setTimeout(() => healthyNow(t), STEADY_AFTER_MS);
@@ -192,15 +202,55 @@ function healthyNow(t) {
192
202
  }
193
203
  export function noteServiceConnected() {
194
204
  const t = tracking;
195
- if (!t || t.healthy || t.connected)
205
+ if (!t || t.connected)
196
206
  return;
197
207
  t.connected = true;
198
- const timer = setTimeout(() => healthyNow(t), HEALTHY_AFTER_CONNECT_MS);
208
+ t.reached = true;
209
+ const timer = t.timer(() => {
210
+ healthyNow(t);
211
+ try {
212
+ t.onConnectedHealthy?.();
213
+ }
214
+ catch { }
215
+ }, HEALTHY_AFTER_CONNECT_MS);
199
216
  timer.unref?.();
200
217
  t.timers.push(timer);
201
218
  }
202
- export function expectServiceExit() { if (tracking)
203
- tracking.expectExit = true; }
219
+ export function serviceConnected() { return !!tracking?.connected; }
220
+ export function noteServiceTried(relay) { tracking?.tried.add(relay); }
221
+ export function serviceTried() { return tracking ? [...tracking.tried] : []; }
222
+ export function noteServiceReached() { if (tracking)
223
+ tracking.reached = true; }
224
+ export function serviceReached() { return !!tracking?.reached; }
225
+ export function watchProbation(kind, o) {
226
+ const mo = o.m === undefined ? {} : { m: o.m };
227
+ const watch = kind !== "worker" ? null : watchNeverOnline({
228
+ version: o.version, ...mo,
229
+ tried: () => serviceTried().length > 0,
230
+ reached: serviceReached,
231
+ relayAnswers: async () => {
232
+ for (const relay of serviceTried()) {
233
+ try {
234
+ if (await o.relayAnswers(relay))
235
+ return true;
236
+ }
237
+ catch { }
238
+ }
239
+ return false;
240
+ },
241
+ exit: o.exit, log: o.log,
242
+ ...(o.now ? { now: o.now } : {}), ...(o.manual ? { manual: true } : {}),
243
+ });
244
+ return { watch, onConnectedHealthy: () => { if (probationPassed(o.version, mo)) {
245
+ watch?.stop();
246
+ o.onKept?.();
247
+ } } };
248
+ }
249
+ export function expectServiceExit() {
250
+ if (tracking)
251
+ tracking.expectExit = true;
252
+ globalThis.__pantheonExpectedExit = true;
253
+ }
204
254
  export function resetServiceTracking() { if (tracking)
205
255
  for (const t of tracking.timers)
206
256
  clearTimeout(t); tracking = null; }