@join-pantheon/cli 0.38.2 → 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.
- package/README.md +10 -1
- package/bin/upgrade-guard.js +314 -57
- package/dist/admin-pages.js +1 -0
- package/dist/agent-start.js +324 -0
- package/dist/agents.js +74 -4
- package/dist/cli.js +16 -19
- package/dist/crash-loop.js +36 -3
- package/dist/doctor.js +78 -6
- package/dist/ledger.js +6 -0
- package/dist/leftovers.js +5 -1
- package/dist/notice.js +2 -1
- package/dist/pickup.js +1 -0
- package/dist/protocol.js +1 -1
- package/dist/readiness-alert.js +17 -2
- package/dist/relay.js +31 -14
- package/dist/run-failure.js +12 -1
- package/dist/store.js +89 -18
- package/dist/update-check.js +17 -2
- package/dist/upgrade-probation.js +235 -51
- package/dist/upgrade.js +43 -9
- package/dist/which.js +1 -1
- package/dist/worker.js +244 -54
- package/helper/macos/prebuilt/manifest.json +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/doctor.js
CHANGED
|
@@ -11,11 +11,12 @@ import { commandState } from "./command-state.js";
|
|
|
11
11
|
import { existsSync, readFileSync, readdirSync, realpathSync } from "node:fs";
|
|
12
12
|
import { homedir, platform } from "node:os";
|
|
13
13
|
import { dirname, join, resolve, sep } from "node:path";
|
|
14
|
-
import { expectedLauncher, managedLayout, runtimeNodeFit, runtimeVerdict } from "./managed.js";
|
|
14
|
+
import { expectedLauncher, installerLineHere, managedLayout, runtimeNodeFit, runtimeVerdict } from "./managed.js";
|
|
15
|
+
import { heldBack, heldUpgradeSentence, readProbation, readRolledBack } from "./upgrade-probation.js";
|
|
15
16
|
import { compareVersions } from "./installer.js";
|
|
16
17
|
import { PKG_NAME } from "./upgrade.js";
|
|
17
18
|
import { PantheonClient } from "./client.js";
|
|
18
|
-
import { load, resolveFor, loadAll, configFor, CONFIG_PATH } from "./config.js";
|
|
19
|
+
import { load, resolveFor, loadAll, configFor, CONFIG_DIR, CONFIG_PATH } from "./config.js";
|
|
19
20
|
import { fingerprint, signChallenge, verifyChallenge } from "./identity.js";
|
|
20
21
|
import { approvalSummary, briefState, chosenApproval, copilotMcpConfigFile, kiroMcpConfigFile, onPath } from "./install.js";
|
|
21
22
|
import { hookState, readIntent, agentHookStates, repairNote } from "./notify.js";
|
|
@@ -24,7 +25,7 @@ import { workerProc, menubarProc, notifierProc, workerFlagRunMinutes } from "./m
|
|
|
24
25
|
import { isCatchAllDomain } from "./protocol.js";
|
|
25
26
|
import { probeLinuxSandbox, sandboxDoctorRow } from "./linux-sandbox.js";
|
|
26
27
|
import { goneLine, leaveCommand, removalKey, removalRefusal, removals, removalWords, teamsOf } from "./removed.js";
|
|
27
|
-
import { agentById, chooseAgent, describeChoice, detectAvailable, folderReaderLine, knownUserBinary, unattendedReadiness, unattendedRefusal, skippedSummary, SANDBOXED_FOR_UNATTENDED } from "./agents.js";
|
|
28
|
+
import { agentById, cannotStartWords, chooseAgent, describeChoice, detectAvailable, folderReaderLine, knownUserBinary, unattendedReadiness, unattendedRefusal, skippedSummary, SANDBOXED_FOR_UNATTENDED } from "./agents.js";
|
|
28
29
|
import { loginShellLookup, npmSpawn, onPathNamed, which, whichWindows } from "./which.js";
|
|
29
30
|
import { VERSION } from "./version.js";
|
|
30
31
|
import { borrowedScheduler, realSys, serviceInstalled, serviceLogFile, servicesUnavailable } from "./service.js";
|
|
@@ -236,6 +237,49 @@ export function crashLoopRows(o = {}) {
|
|
|
236
237
|
}
|
|
237
238
|
return rows;
|
|
238
239
|
}
|
|
240
|
+
export function upgradeRows(o = {}) {
|
|
241
|
+
const m = o.m === undefined ? managedLayout() : o.m;
|
|
242
|
+
if (!m)
|
|
243
|
+
return [];
|
|
244
|
+
const rows = [];
|
|
245
|
+
const p = (() => { try {
|
|
246
|
+
return readProbation(m);
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
return null;
|
|
250
|
+
} })();
|
|
251
|
+
if (p?.stuck && p.to === (o.version ?? VERSION)) {
|
|
252
|
+
rows.push({
|
|
253
|
+
level: "warn", name: "upgrade",
|
|
254
|
+
detail: `Pantheon ${p.to} kept failing on this computer after it was installed, and could not go back to the version before it by itself: ${p.stuck_why ?? "no previous version is kept"}`,
|
|
255
|
+
fix: `run the installer again — it repairs Pantheon and keeps your teams and settings: ${installerLineHere(o.relay, o.os ?? platform())}`,
|
|
256
|
+
share: `${p.to} failing, could not go back`,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
const h = (() => { try {
|
|
260
|
+
return readRolledBack(m);
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
return null;
|
|
264
|
+
} })();
|
|
265
|
+
if (h)
|
|
266
|
+
rows.push({ level: "pass", name: "upgrade", detail: heldUpgradeSentence(h), share: `went back from ${h.version} to ${h.back_to}` });
|
|
267
|
+
return rows;
|
|
268
|
+
}
|
|
269
|
+
export function versionSkewRow(local, relayPkg, held) {
|
|
270
|
+
if (held && held.version === relayPkg) {
|
|
271
|
+
return {
|
|
272
|
+
level: "pass",
|
|
273
|
+
detail: `this machine is ${local}; the relay is ${relayPkg}, which did not work on this computer and was put back to ${held.back_to} — nothing to do, it updates by itself when a newer release is out`,
|
|
274
|
+
share: `this machine ${local}; relay ${relayPkg} was put back here`,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
level: "warn", detail: `this machine is ${local}, the relay is ${relayPkg}`,
|
|
279
|
+
fix: "run `pantheon upgrade` on the older side — features land on both halves of the wire, and the protocol version cannot tell you they are missing",
|
|
280
|
+
share: `this machine ${local}, relay ${relayPkg}`,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
239
283
|
export async function doctor(projectDir) {
|
|
240
284
|
const out = [];
|
|
241
285
|
const add = (level, name, detail, fix, share) => out.push({ level, name, detail, ...(fix ? { fix } : {}), ...(share ? { share } : {}) });
|
|
@@ -263,6 +307,8 @@ export async function doctor(projectDir) {
|
|
|
263
307
|
const fit = runtimeNodeFit(facts.layout, process.versions.node, newestRelease(), relay);
|
|
264
308
|
if (fit)
|
|
265
309
|
add(fit.level, "runtime node", fit.detail, fit.fix, fit.share);
|
|
310
|
+
for (const r of upgradeRows({ m: facts.layout, relay }))
|
|
311
|
+
add(r.level, r.name, r.detail, r.fix, r.share);
|
|
266
312
|
}
|
|
267
313
|
}
|
|
268
314
|
const host = hostEnv();
|
|
@@ -485,13 +531,24 @@ export async function doctor(projectDir) {
|
|
|
485
531
|
const line = describeChoice(choice).replace(/\bnot signed in\b/g, "signed out");
|
|
486
532
|
const bad = choice.signIn && !choice.signIn.ok && !choice.signIn.unknown;
|
|
487
533
|
const fellBack = !!prof.agent.primary_surface && choice.backend.id !== prof.agent.primary_surface && agents.length > 0;
|
|
488
|
-
const shareLine = `${choice.backend.label} — ${choice.signIn?.detail ?? "not checked"}${choice.skipped.length ? `; ${skippedSummary(choice)}` : ""}`;
|
|
534
|
+
const shareLine = `${choice.backend.label} — ${choice.cannotStart ? "cannot start here" : choice.signIn?.detail ?? "not checked"}${choice.skipped.length ? `; ${skippedSummary(choice)}` : ""}`;
|
|
489
535
|
const refused = unattendedRefusal(choice, { unsandboxedOk });
|
|
490
536
|
const surface = prof.agent.primary_surface ? agentById(prof.agent.primary_surface) : undefined;
|
|
491
|
-
|
|
537
|
+
const claudeHere = detectAvailable().some((a) => a.backend.id === "claude-code");
|
|
538
|
+
const passedOver = choice.skipped.filter((x) => x.cannotStart);
|
|
539
|
+
if (choice.cannotStart) {
|
|
540
|
+
const w = cannotStartWords(choice.backend, choice.cannotStart, { claudeHere });
|
|
541
|
+
add(workerSetUp ? "fail" : "warn", "worker agent", line, `no request can run here while you're away until it starts. ${w.fix}`, shareLine);
|
|
542
|
+
}
|
|
543
|
+
else if (refused)
|
|
492
544
|
add("warn", "worker agent", line, `teammates' requests wait for your next session here: ${refused}`, shareLine);
|
|
493
545
|
else if (bad)
|
|
494
546
|
add("warn", "worker agent", line, `your agent is signed out, so every woken run here fails until you sign in again: ${choice.skipped.map((x) => x.why.replace(/\bnot signed in\b/g, "signed out")).join("; ") || "sign in to the agent CLI"}`, shareLine);
|
|
547
|
+
else if (passedOver.length) {
|
|
548
|
+
const x = passedOver.find((p) => p.backend.id === surface?.id) ?? passedOver[0];
|
|
549
|
+
const w = cannotStartWords(x.backend, x.cannotStart ?? {}, { claudeHere: true });
|
|
550
|
+
add("warn", "worker agent", line, `${x.backend.id === surface?.id ? `you chose ${x.backend.label} at setup; it` : x.backend.label} cannot start here, so runs while you're away use ${choice.backend.label}. ${w.fix}${x.backend.id === surface?.id ? ` To make ${choice.backend.label} your choice instead: pantheon setup --agent ${choice.backend.id}` : ""}`, shareLine);
|
|
551
|
+
}
|
|
495
552
|
else if (fellBack)
|
|
496
553
|
add("warn", "worker agent", line, prof.agent.primary_surface === "kiro"
|
|
497
554
|
? `you chose Kiro at setup; Kiro answers in your live sessions, and runs while you're away use ${choice.backend.label}`
|
|
@@ -506,6 +563,15 @@ export async function doctor(projectDir) {
|
|
|
506
563
|
catch (e) {
|
|
507
564
|
add("warn", "worker agent", e.message, "pantheon setup --agent <claude-code|codex|cursor|copilot|kiro> names one that is installed", "could not be chosen");
|
|
508
565
|
}
|
|
566
|
+
try {
|
|
567
|
+
const { agentCannotStart } = await import("./readiness-alert.js");
|
|
568
|
+
const found = agentCannotStart(CONFIG_DIR);
|
|
569
|
+
const b = found ? agentById(found) : undefined;
|
|
570
|
+
if (b && !out.some((c) => c.name === "worker agent" && c.detail.includes(`${b.label} — cannot start here`))) {
|
|
571
|
+
add("warn", "worker agent", `your worker, in the background, found that ${b.label} cannot start there, although this terminal finds it`, `it looks again now${askedRecheck ? "" : " at its next check"}: pantheon status says what it finds. If it still cannot start there, the worker does not find a program this terminal does (the agent itself, or the Node it needs) — ${cannotStartWords(b, {}, { claudeHere: true }).fix}`, `${b.label} cannot start for the worker`);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
catch { }
|
|
509
575
|
try {
|
|
510
576
|
const { signedOutChecking, SIGNED_OUT_AGENTS } = await import("./signed-out.js");
|
|
511
577
|
const { SIGN_IN_FIX } = await import("./run-failure.js");
|
|
@@ -654,7 +720,13 @@ export async function doctor(projectDir) {
|
|
|
654
720
|
add("pass", "version", `${VERSION}; the relay is holding upgrades at ${held} for now, so this machine stays where it is`, undefined, `${VERSION}, upgrades held at ${held}`);
|
|
655
721
|
}
|
|
656
722
|
else if (body.pkg && body.pkg !== VERSION) {
|
|
657
|
-
|
|
723
|
+
const row = versionSkewRow(VERSION, body.pkg, (() => { try {
|
|
724
|
+
return heldBack(body.pkg);
|
|
725
|
+
}
|
|
726
|
+
catch {
|
|
727
|
+
return null;
|
|
728
|
+
} })());
|
|
729
|
+
add(row.level, "version", row.detail, row.fix, row.share);
|
|
658
730
|
}
|
|
659
731
|
else if (body.pkg) {
|
|
660
732
|
add("pass", "version", `${VERSION}, matching the relay`, undefined, `${VERSION}, matching the relay`);
|
package/dist/ledger.js
CHANGED
|
@@ -180,15 +180,21 @@ export class Ledger {
|
|
|
180
180
|
inTail = (_r, i) => tail[i] === 1;
|
|
181
181
|
}
|
|
182
182
|
let newestDropped = null;
|
|
183
|
+
const want = opts.onlyIfFrees ?? 0;
|
|
184
|
+
let frees = 0;
|
|
183
185
|
const kept = this.records.filter((r, i) => {
|
|
184
186
|
const keep = inTail(r, i) || opts.isLive(r.goal) || (opts.keep?.(r.id) ?? false);
|
|
185
187
|
if (!keep && !pres?.is(r) && (newestDropped === null || r.ts > newestDropped))
|
|
186
188
|
newestDropped = r.ts;
|
|
189
|
+
if (!keep && frees < want)
|
|
190
|
+
frees += Buffer.byteLength(JSON.stringify(r)) + 1;
|
|
187
191
|
return keep;
|
|
188
192
|
});
|
|
189
193
|
const dropped = this.records.length - kept.length;
|
|
190
194
|
if (dropped === 0)
|
|
191
195
|
return { dropped: 0, kept: kept.length, newestDropped: null };
|
|
196
|
+
if (frees < want)
|
|
197
|
+
return { dropped: 0, kept: n, newestDropped: null };
|
|
192
198
|
const text = kept.map((r) => JSON.stringify(r)).join("\n") + "\n";
|
|
193
199
|
writerFor(this.dir, this.stem).replace(this.file, text);
|
|
194
200
|
this.records = kept;
|
package/dist/leftovers.js
CHANGED
|
@@ -102,7 +102,11 @@ export function classifyLeftover(dataDir, stem, tomb, hold = DELETED_NAME_HOLD_M
|
|
|
102
102
|
const pending = pendingView(dataDir, stem, rf);
|
|
103
103
|
if (pending === null || (pending === undefined && !existsSync(rf))) {
|
|
104
104
|
const left = TEAM_FILES.filter((x) => x !== ".members.json" && existsSync(join(dataDir, `${stem}${x}`))).map((x) => `${stem}${x}`);
|
|
105
|
-
|
|
105
|
+
if (!left.length)
|
|
106
|
+
return out("live", "no member list on disk");
|
|
107
|
+
const unsure = out("unsure", `quarantine or delete incomplete: ${left.join(", ")} still here without the member list`);
|
|
108
|
+
return left.length === 1 && left[0] === `${stem}.closed-goals.json`
|
|
109
|
+
? { ...unsure, why: `${unsure.why} (only its old closed goals: a new team may take the name after the hold, and never reads them)`, nameFree: true } : unsure;
|
|
106
110
|
}
|
|
107
111
|
if (tomb.unreadable)
|
|
108
112
|
return out("unsure", `its tombstone cannot be read right now (${tomb.unreadable})`);
|
package/dist/notice.js
CHANGED
|
@@ -249,7 +249,7 @@ export function composeWaiting(items, team, ctx) {
|
|
|
249
249
|
tag: `waiting_${team.replace(/[^A-Za-z0-9_]/g, "_")}`.slice(0, 60),
|
|
250
250
|
};
|
|
251
251
|
}
|
|
252
|
-
export const DECLINE_CODES = ["wake", "wake_ask", "wake_off", "team_wake", "playbook", "capped", "failed", "commands", "not_here", "no_folder", "unavailable", "signed_out", "unsigned", "goal_cap"];
|
|
252
|
+
export const DECLINE_CODES = ["wake", "wake_ask", "wake_off", "team_wake", "playbook", "capped", "failed", "commands", "not_here", "no_folder", "unavailable", "signed_out", "unsigned", "goal_cap", "cannot_start"];
|
|
253
253
|
export function declineCodeOf(r) {
|
|
254
254
|
const m = r?.meta;
|
|
255
255
|
if (!r || r.act !== "NOTE" || !m || typeof m.declined !== "string")
|
|
@@ -270,6 +270,7 @@ export function declineWords(code, who) {
|
|
|
270
270
|
case "not_here": return `${who}'s computer doesn't have the repo it's about`;
|
|
271
271
|
case "no_folder": return `nothing on ${who}'s computer is linked to this team yet`;
|
|
272
272
|
case "signed_out": return `${who}'s agent is signed out`;
|
|
273
|
+
case "cannot_start": return `${who}'s agent can't start on ${who}'s computer`;
|
|
273
274
|
case "unsigned": return `${who}'s computer couldn't check it came from you — upgrading Pantheon (pantheon upgrade) fixes that`;
|
|
274
275
|
default: return `nothing on ${who}'s computer can take it while ${who} is away`;
|
|
275
276
|
}
|
package/dist/pickup.js
CHANGED
|
@@ -23,6 +23,7 @@ const UNAVAILABLE = {
|
|
|
23
23
|
sandbox_unavailable: "its Linux sandbox can't start",
|
|
24
24
|
pinned_kiro: "its worker is set to use Kiro, which answers only in live sessions",
|
|
25
25
|
pinned_unsandboxed: "its worker is set to use an agent without a sandbox, and it is set to leave requests for its person",
|
|
26
|
+
cannot_start: "its agent can't start there",
|
|
26
27
|
};
|
|
27
28
|
function reasonOf(w) {
|
|
28
29
|
if (w.reason && WORKER_REASONS.includes(w.reason))
|
package/dist/protocol.js
CHANGED
|
@@ -264,7 +264,7 @@ export const DeleteSpace = z.object({
|
|
|
264
264
|
});
|
|
265
265
|
export const WORKER_REASONS = ["no_agent", "kiro_only", "not_signed_in", "unsandboxed_off", "no_agent_choice",
|
|
266
266
|
"busy_turn", "recently_active", "no_signal", "capped", "outage", "awaiting_wake_approval", "busy_elsewhere", "unknown", "sandbox_unavailable",
|
|
267
|
-
"pinned_kiro", "pinned_unsandboxed"];
|
|
267
|
+
"pinned_kiro", "pinned_unsandboxed", "cannot_start"];
|
|
268
268
|
const WORK_ID = /^(cont:)?[a-z]{1,3}_[A-Za-z0-9_-]{4,64}$/;
|
|
269
269
|
export const WorkerState = z.object({
|
|
270
270
|
t: z.literal("worker_state"),
|
package/dist/readiness-alert.js
CHANGED
|
@@ -10,14 +10,14 @@ import { writeWhole } from "./pins.js";
|
|
|
10
10
|
import { signedOutRefusal } from "./signed-out.js";
|
|
11
11
|
import { refusedWords } from "./run-failure.js";
|
|
12
12
|
export { READINESS_ALERT_FILE };
|
|
13
|
-
export const PERSON_CODES = new Set(["not_signed_in", "no_agent", "sandbox_unavailable"]);
|
|
13
|
+
export const PERSON_CODES = new Set(["not_signed_in", "no_agent", "sandbox_unavailable", "cannot_start"]);
|
|
14
14
|
export const FRESH_MS = 30 * 60_000;
|
|
15
15
|
export const CONFIRM_MS = 50_000;
|
|
16
16
|
export const PENDING_MAX_MS = 15 * 60_000;
|
|
17
17
|
const REFRESH_MS = 5 * 60_000;
|
|
18
18
|
const DAY_MS = 24 * 3_600_000;
|
|
19
19
|
export const PROBLEM_LEAD = "Unattended work can't run";
|
|
20
|
-
const CODES = new Set(["no_agent", "kiro_only", "not_signed_in", "unsandboxed_off", "no_agent_choice", "sandbox_unavailable"]);
|
|
20
|
+
const CODES = new Set(["no_agent", "kiro_only", "not_signed_in", "unsandboxed_off", "no_agent_choice", "sandbox_unavailable", "cannot_start"]);
|
|
21
21
|
const AGENT_IDS = new Set(AGENTS.map((a) => a.id));
|
|
22
22
|
const keyOf = (t) => `${t.code ?? ""}|${t.agent ?? ""}`;
|
|
23
23
|
const seenKey = (s) => (s.ok ? "ok" : keyOf(s));
|
|
@@ -62,6 +62,8 @@ export function problemLine(code, agent, os = platform()) {
|
|
|
62
62
|
return `${notInstalled(agent)} — pantheon doctor shows how to install it`;
|
|
63
63
|
if (code === "sandbox_unavailable")
|
|
64
64
|
return `${label(agent ?? "claude-code")}'s sandbox can't start — pantheon doctor shows the fix`;
|
|
65
|
+
if (code === "cannot_start")
|
|
66
|
+
return `${label(agent)} can't start on this computer — pantheon doctor shows why and the fix`;
|
|
65
67
|
return null;
|
|
66
68
|
}
|
|
67
69
|
const forHowLong = (ms) => {
|
|
@@ -102,6 +104,15 @@ export function composeReadinessAlert(code, agent, o = {}) {
|
|
|
102
104
|
...button({ label: "Show me how", kind: "how", ...(agent ? { agent } : {}), dir: o.signInDir ?? homedir(), lines: [], why: head }),
|
|
103
105
|
};
|
|
104
106
|
}
|
|
107
|
+
if (code === "cannot_start") {
|
|
108
|
+
const head = "Your agent can't start";
|
|
109
|
+
return {
|
|
110
|
+
...base,
|
|
111
|
+
heading: head,
|
|
112
|
+
body: fit(`${label(agent)} can't start on this computer, so teammates' requests wait. ${os === "win32" ? "Run pantheon doctor: it says why, and the one fix." : "Click Show me how for why, and the one fix."}`, BUDGET.body),
|
|
113
|
+
...button({ label: "Show me how", kind: "how", ...(agent ? { agent } : {}), dir: o.signInDir ?? homedir(), lines: [], why: `${label(agent)} can't start on this computer` }),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
105
116
|
const missing = /^install them:/.test(o.fix ?? "");
|
|
106
117
|
return {
|
|
107
118
|
...base,
|
|
@@ -456,6 +467,10 @@ const refused = (agent, home) => {
|
|
|
456
467
|
return null;
|
|
457
468
|
}
|
|
458
469
|
};
|
|
470
|
+
export function agentCannotStart(home, now = Date.now()) {
|
|
471
|
+
const first = stuckReading(home, now);
|
|
472
|
+
return first?.code === "cannot_start" && first.agent ? first.agent : null;
|
|
473
|
+
}
|
|
459
474
|
function stuckReading(home, now) {
|
|
460
475
|
let text = null;
|
|
461
476
|
try {
|
package/dist/relay.js
CHANGED
|
@@ -441,10 +441,12 @@ function loopMs(ns) {
|
|
|
441
441
|
}
|
|
442
442
|
const CLAIM_RATE = 120;
|
|
443
443
|
const ROSTER_EVERY_MS = 500;
|
|
444
|
-
const
|
|
444
|
+
const CLOSE_COMPACT_REST = 20;
|
|
445
|
+
const CLOSE_COMPACT_REST_MAX_MS = 60_000;
|
|
445
446
|
const OUTBOX_MAX = 5_000;
|
|
446
447
|
const LINK_CLOSED = "Different words were typed here, so this link is closed. That's all: the 6-digit code in the same email still works. Give it to your coding agent.";
|
|
447
448
|
const LINK_GONE = "This link has expired (they last 10 minutes), a newer Pantheon email replaced it, or it was already used. Use the code in the newest Pantheon email, or ask your coding agent to send a new one.";
|
|
449
|
+
const STORAGE_NO_ENTRY = "the relay's disk is refusing writes, so it cannot let you in right now — reconnect in a moment";
|
|
448
450
|
const STORAGE_HELD = "the relay received this but has not saved it yet — its disk is refusing writes. It is kept, and reaches the team when the disk recovers; do not send it again.";
|
|
449
451
|
export function backupExcludes(dir, keep) {
|
|
450
452
|
const always = ["--exclude=*.tmp", "--exclude=./geoip"];
|
|
@@ -3003,7 +3005,7 @@ ${body}`;
|
|
|
3003
3005
|
}
|
|
3004
3006
|
const mine = [
|
|
3005
3007
|
...sufs.flatMap((x) => (files.includes(`${stem}${x}`) ? [`${stem}${x}`] : [])),
|
|
3006
|
-
...files.filter((f) => f.startsWith(`${stem}.usage.json.corrupt-`) || f.startsWith(`${stem}.closed-goals.json.corrupt-`)),
|
|
3008
|
+
...files.filter((f) => f.startsWith(`${stem}.usage.json.corrupt-`) || f.startsWith(`${stem}.closed-goals.json.corrupt-`) || f.startsWith(`${stem}.closed-goals.json.not-joined-`)),
|
|
3007
3009
|
];
|
|
3008
3010
|
if (!mine.length)
|
|
3009
3011
|
return { ok: false, error: `no files of "${stem}" to move`, moved: [], rolledBack: true };
|
|
@@ -3591,8 +3593,9 @@ ${body}`;
|
|
|
3591
3593
|
}
|
|
3592
3594
|
sleepingTeamState(name, safe, records, sig, index) {
|
|
3593
3595
|
const st = new StateStore(this.dataDir, safe);
|
|
3594
|
-
const loaded = st.load({ expectHistory: records.length > 0 });
|
|
3595
3596
|
const allow = new Allowlist(this.dataDir, safe);
|
|
3597
|
+
st.teamId = () => allow.peekId();
|
|
3598
|
+
const loaded = st.load({ expectHistory: records.length > 0 });
|
|
3596
3599
|
const teamName = allow.recordedName() ?? records.find((r) => r.space)?.space ?? name;
|
|
3597
3600
|
let savedAt = null;
|
|
3598
3601
|
try {
|
|
@@ -4769,7 +4772,8 @@ pantheon start</code></pre>
|
|
|
4769
4772
|
const found = this.tombstoneRecord(m.space);
|
|
4770
4773
|
const otherSpelling = !!found && !found.corrupt && !found.unreadable && safeName(found.name) !== safeName(m.space);
|
|
4771
4774
|
const tomb = otherSpelling && (this.live(m.space) || this.spaceOnDisk(m.space)) ? null : found;
|
|
4772
|
-
|
|
4775
|
+
const leftHere = !this.live(m.space) && !this.spaceOnDisk(m.space) ? this.leftoverState(safeName(m.space)) : null;
|
|
4776
|
+
if (leftHere && leftHere.state !== "live" && !leftHere.nameFree) {
|
|
4773
4777
|
this.log(`! REFUSED ${m.member}: "${m.space}" still has a deleted team's files without their member list`);
|
|
4774
4778
|
return reject("SPACE_DELETED", coveredNameWords(m.space), { gone: null });
|
|
4775
4779
|
}
|
|
@@ -4857,6 +4861,8 @@ pantheon start</code></pre>
|
|
|
4857
4861
|
this.accounts?.recordSpace(sp.name, pre?.ok ? pre.account.id : null);
|
|
4858
4862
|
}
|
|
4859
4863
|
}
|
|
4864
|
+
if ((sp.outbox?.length ?? 0) >= this.outboxMax)
|
|
4865
|
+
return reject("STORAGE", STORAGE_NO_ENTRY);
|
|
4860
4866
|
let acctSession = null;
|
|
4861
4867
|
if (this.requireAccounts && this.accounts && !this.localTrusted(ip)) {
|
|
4862
4868
|
const auth = this.accounts.authorize(m.pubkey, m.member);
|
|
@@ -6480,7 +6486,7 @@ pantheon start</code></pre>
|
|
|
6480
6486
|
writerFor(this.dataDir, safe).remove(join(this.dataDir, `${safe}${suffix}`));
|
|
6481
6487
|
try {
|
|
6482
6488
|
for (const f of readdirSync(this.dataDir))
|
|
6483
|
-
if (f.startsWith(`${safe}.usage.json.corrupt-`) || f.startsWith(`${safe}.closed-goals.json.corrupt-`))
|
|
6489
|
+
if (f.startsWith(`${safe}.usage.json.corrupt-`) || f.startsWith(`${safe}.closed-goals.json.corrupt-`) || f.startsWith(`${safe}.closed-goals.json.not-joined-`))
|
|
6484
6490
|
writerFor(this.dataDir, safe).remove(join(this.dataDir, f));
|
|
6485
6491
|
}
|
|
6486
6492
|
catch { }
|
|
@@ -6514,7 +6520,7 @@ pantheon start</code></pre>
|
|
|
6514
6520
|
const safe = name.replace(/[^a-z0-9._-]/gi, "_");
|
|
6515
6521
|
{
|
|
6516
6522
|
const ls = this.leftoverState(safe);
|
|
6517
|
-
if (ls.state === "covered" || (ls.state === "unsure" && !this.spaceOnDisk(name)))
|
|
6523
|
+
if (ls.state === "covered" || (ls.state === "unsure" && !ls.nameFree && !this.spaceOnDisk(name)))
|
|
6518
6524
|
return null;
|
|
6519
6525
|
}
|
|
6520
6526
|
const allow = new Allowlist(this.dataDir, safe);
|
|
@@ -6546,6 +6552,8 @@ pantheon start</code></pre>
|
|
|
6546
6552
|
const store = new StateStore(this.dataDir, safe);
|
|
6547
6553
|
store.headOf = () => ledger.head;
|
|
6548
6554
|
store.onError = (e) => this.noteStorageFailure(`[${name}] snapshot save`, e);
|
|
6555
|
+
store.teamId = () => allow.peekId();
|
|
6556
|
+
store.onNote = (line) => this.log(`! [${name}] ${line}`);
|
|
6549
6557
|
const restored = store.load({ quarantine: true, expectHistory: ledger.size > 0 });
|
|
6550
6558
|
if (!restored.unclean && restored.ledgerHead !== undefined && restored.ledgerHead > ledger.head) {
|
|
6551
6559
|
if (ledger.size > 0) {
|
|
@@ -6798,22 +6806,29 @@ pantheon start</code></pre>
|
|
|
6798
6806
|
sp.closeCompactTimer = undefined;
|
|
6799
6807
|
if (this.closing || sp.deleted || this.spaces.get(spaceKey(sp.name)) !== sp)
|
|
6800
6808
|
return;
|
|
6801
|
-
sp.
|
|
6809
|
+
const over = sp.ledger.bytes - this.maxLedgerBytes;
|
|
6810
|
+
if (over < 0)
|
|
6811
|
+
return;
|
|
6812
|
+
const began = performance.now();
|
|
6802
6813
|
try {
|
|
6803
|
-
this.compactSpace(sp);
|
|
6814
|
+
this.compactSpace(sp, over + 1);
|
|
6804
6815
|
}
|
|
6805
6816
|
catch (e) {
|
|
6806
6817
|
this.noteStorageFailure(`[${sp.name}] compacting after a close`, e);
|
|
6807
6818
|
}
|
|
6819
|
+
sp.closeCompactAt = performance.now();
|
|
6820
|
+
sp.closeCompactMs = sp.closeCompactAt - began;
|
|
6808
6821
|
};
|
|
6809
|
-
const
|
|
6810
|
-
|
|
6822
|
+
const rest = Math.min(CLOSE_COMPACT_REST_MAX_MS, CLOSE_COMPACT_REST * (sp.closeCompactMs ?? 0));
|
|
6823
|
+
const wait = sp.closeCompactAt === undefined ? 0 : rest - (performance.now() - sp.closeCompactAt);
|
|
6824
|
+
if (wait <= 0)
|
|
6811
6825
|
return run();
|
|
6812
|
-
sp.closeCompactTimer = setTimeout(run,
|
|
6826
|
+
sp.closeCompactTimer = setTimeout(run, wait);
|
|
6813
6827
|
sp.closeCompactTimer.unref?.();
|
|
6814
6828
|
}
|
|
6815
|
-
compactSpace(sp) {
|
|
6816
|
-
|
|
6829
|
+
compactSpace(sp, onlyIfFrees) {
|
|
6830
|
+
if (onlyIfFrees === undefined)
|
|
6831
|
+
this.compactedAt.set(sp.name, Date.now());
|
|
6817
6832
|
if (sp.unclean)
|
|
6818
6833
|
return;
|
|
6819
6834
|
const isLive = (goal) => {
|
|
@@ -6828,8 +6843,10 @@ pantheon start</code></pre>
|
|
|
6828
6843
|
const { dropped, kept, newestDropped } = sp.ledger.compact({
|
|
6829
6844
|
keepRecent: this.opts.ledgerKeepRecent ?? LIMITS.ledgerKeepRecent, isLive, keep: (id) => referenced.has(id),
|
|
6830
6845
|
presence: { is: (r) => r.act === "JOIN" || r.act === "LEAVE", keepRecent: this.opts.ledgerKeepPresence ?? LIMITS.ledgerKeepPresence },
|
|
6846
|
+
...(onlyIfFrees !== undefined ? { onlyIfFrees } : {}),
|
|
6831
6847
|
});
|
|
6832
6848
|
if (dropped) {
|
|
6849
|
+
this.compactedAt.set(sp.name, Date.now());
|
|
6833
6850
|
sp.store.noteCompacted(fromGaps);
|
|
6834
6851
|
sp.store.noteCompacted(newestDropped);
|
|
6835
6852
|
sp.store.gapsChecked = { seq: sp.ledger.head, kept: sp.ledger.size };
|
|
@@ -6960,7 +6977,7 @@ pantheon start</code></pre>
|
|
|
6960
6977
|
return Buffer.byteLength(payload);
|
|
6961
6978
|
}
|
|
6962
6979
|
const instead = msg.t === "ack" && msg.cid ? { cid: msg.cid } : msg.t === "welcome" ? {} : null;
|
|
6963
|
-
const message = msg.t === "welcome" ?
|
|
6980
|
+
const message = msg.t === "welcome" ? STORAGE_NO_ENTRY : STORAGE_HELD;
|
|
6964
6981
|
this.out(sp, run, instead ? { ws, payload: JSON.stringify({ t: "error", code: "STORAGE", message, ...instead }), hangUp: msg.t === "welcome" } : undefined);
|
|
6965
6982
|
return Buffer.byteLength(payload);
|
|
6966
6983
|
}
|
package/dist/run-failure.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { signInRefused } from "./agent-outage.js";
|
|
2
2
|
import { execFileSync } from "node:child_process";
|
|
3
3
|
import { gitCallEnv, safeGitArgs } from "./git-safe.js";
|
|
4
|
-
import { checkRepoCommand } from "./agents.js";
|
|
4
|
+
import { agentById, cannotStartWords, checkRepoCommand } from "./agents.js";
|
|
5
|
+
import { programOf, startFailureOf, startWhy } from "./agent-start.js";
|
|
5
6
|
import { bashRuleMatches, GIT_DENY_RULES } from "./claude-confine.js";
|
|
6
7
|
const AGENT_LABEL = { "claude-code": "Claude Code", codex: "Codex", cursor: "Cursor", copilot: "GitHub Copilot", kiro: "Kiro" };
|
|
7
8
|
export const SIGN_IN_FIX = {
|
|
@@ -133,6 +134,16 @@ export function diagnoseRun(f, probe = gitProbe) {
|
|
|
133
134
|
? { cause: "not_signed_in", says: `${label} refused ${w.what}, so the run couldn't start.`, fix: `${w.fix[0].toUpperCase()}${w.fix.slice(1)}.` }
|
|
134
135
|
: { cause: "not_signed_in", says: `${label} is signed out on this computer, so the run couldn't start.`, fix: `Sign in once and the next run works: ${SIGN_IN_FIX[f.agent ?? ""] ?? "sign in to the agent CLI on this machine"}.` };
|
|
135
136
|
}
|
|
137
|
+
const backend = f.exited || f.agentCmd || !f.agent ? undefined : agentById(f.agent);
|
|
138
|
+
const notStarted = backend ? startFailureOf(f.detail, { agent: backend.id, ...(f.os ? { os: f.os } : {}), ...(f.ranMs !== undefined ? { ranMs: f.ranMs } : {}), ...(f.binary ? { binary: f.binary } : {}) }) : null;
|
|
139
|
+
if (backend && notStarted) {
|
|
140
|
+
const w = cannotStartWords(backend, { ...notStarted, why: startWhy(notStarted.kind, programOf(f.binary ?? backend.binaries[0]), notStarted.needs) }, f.os ? { os: f.os } : {});
|
|
141
|
+
return {
|
|
142
|
+
cause: "agent_not_installed",
|
|
143
|
+
says: `${backend.label} could not be started on this computer, so the run never began: ${w.why}.`,
|
|
144
|
+
fix: w.fix,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
136
147
|
if (f.allowBash && (f.agent ?? "claude-code") === "claude-code" && (f.os ?? process.platform) === "linux" && SANDBOX_RE.test(f.detail)) {
|
|
137
148
|
return {
|
|
138
149
|
cause: "sandbox_unavailable",
|
package/dist/store.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { readFileSync, existsSync, mkdirSync, renameSync, openSync, writeSync, fsyncSync, closeSync, chmodSync } from "node:fs";
|
|
2
|
-
import { dirname, join } from "node:path";
|
|
1
|
+
import { readFileSync, existsSync, mkdirSync, renameSync, openSync, writeSync, fsyncSync, closeSync, chmodSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, join } from "node:path";
|
|
3
3
|
import { emptyRefusals } from "./admin-stats.js";
|
|
4
4
|
import { pendingView, writerFor } from "./disk-writer.js";
|
|
5
5
|
import { emptyUsage, parseUsage } from "./usage.js";
|
|
@@ -139,6 +139,8 @@ export class StateStore {
|
|
|
139
139
|
closedOnDisk = new Map();
|
|
140
140
|
aged = null;
|
|
141
141
|
closedUnreadable = false;
|
|
142
|
+
teamId;
|
|
143
|
+
onNote;
|
|
142
144
|
constructor(dir, stem) {
|
|
143
145
|
this.dir = dir;
|
|
144
146
|
this.stem = stem;
|
|
@@ -155,37 +157,106 @@ export class StateStore {
|
|
|
155
157
|
isAged(goals, g) {
|
|
156
158
|
return g.state === "CLOSED" && this.agedIds(goals).has(g.id);
|
|
157
159
|
}
|
|
158
|
-
loadClosed(quarantine) {
|
|
160
|
+
loadClosed(quarantine, known) {
|
|
159
161
|
this.closedOnDisk = new Map();
|
|
160
162
|
this.closedUnreadable = false;
|
|
163
|
+
let text;
|
|
161
164
|
try {
|
|
162
165
|
const pending = pendingView(this.dir, this.stem, this.closedFile);
|
|
163
166
|
if (pending === null || (pending === undefined && !existsSync(this.closedFile)))
|
|
164
167
|
return this.closedOnDisk;
|
|
165
|
-
|
|
168
|
+
text = pending ? pending.toString("utf8") : readFileSync(this.closedFile, "utf8");
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
const code = e.code ?? "EIO";
|
|
172
|
+
if (code === "ENOENT")
|
|
173
|
+
return this.closedOnDisk;
|
|
174
|
+
this.closedUnreadable = true;
|
|
175
|
+
this.onNote?.(`old closed goals' file ${basename(this.closedFile)} cannot be read right now (${code}): the team is loaded without it, and the file is left as it is`);
|
|
176
|
+
return this.closedOnDisk;
|
|
177
|
+
}
|
|
178
|
+
let team = null;
|
|
179
|
+
const read = new Map();
|
|
180
|
+
let whole = false;
|
|
181
|
+
try {
|
|
182
|
+
const raw = JSON.parse(text);
|
|
166
183
|
const all = raw && typeof raw === "object" && raw.goals && typeof raw.goals === "object" && !Array.isArray(raw.goals) ? raw.goals : null;
|
|
167
184
|
if (!all)
|
|
168
185
|
throw new Error("not a closed-goals file");
|
|
186
|
+
if (raw.team !== undefined && (typeof raw.team !== "string" || !raw.team))
|
|
187
|
+
throw new Error("not a closed-goals file");
|
|
188
|
+
team = typeof raw.team === "string" ? raw.team : null;
|
|
169
189
|
for (const [id, v] of Object.entries(all)) {
|
|
170
190
|
const g = v;
|
|
171
191
|
if (g && typeof g === "object" && g.id === id && typeof g.title === "string" && typeof g.closed_summary === "string" && Array.isArray(g.members))
|
|
172
|
-
|
|
192
|
+
read.set(id, { ...g, state: "CLOSED" });
|
|
173
193
|
}
|
|
194
|
+
whole = read.size === Object.keys(all).length;
|
|
174
195
|
}
|
|
175
196
|
catch {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
197
|
+
const aside = quarantine ? this.moveAside("corrupt") : null;
|
|
198
|
+
this.closedUnreadable = !aside;
|
|
199
|
+
this.onNote?.(`old closed goals' file ${basename(this.closedFile)} does not parse: ${aside ? `moved aside to ${basename(aside)}` : "left as it is, and never written over"}`);
|
|
200
|
+
return this.closedOnDisk;
|
|
201
|
+
}
|
|
202
|
+
const mine = this.teamId?.() ?? null;
|
|
203
|
+
if (team !== null) {
|
|
204
|
+
if (team === mine) {
|
|
205
|
+
this.closedOnDisk = read;
|
|
206
|
+
return this.closedOnDisk;
|
|
207
|
+
}
|
|
208
|
+
return this.notJoined(quarantine, read.size, `was written for another team (${team})`);
|
|
209
|
+
}
|
|
210
|
+
const own = new Map([...read].filter(([id]) => known?.has(id)));
|
|
211
|
+
if (own.size === read.size) {
|
|
212
|
+
this.closedOnDisk = own;
|
|
213
|
+
if (quarantine && mine && own.size && whole)
|
|
214
|
+
writerFor(this.dir, this.stem).replace(this.closedFile, this.closedText(own), 0o600, "first");
|
|
215
|
+
return this.closedOnDisk;
|
|
216
|
+
}
|
|
217
|
+
const why = known
|
|
218
|
+
? `names no team and holds ${read.size - own.size} goal(s) this team's snapshot does not have`
|
|
219
|
+
: "names no team, and this team has no readable snapshot to check it against";
|
|
220
|
+
if (!own.size)
|
|
221
|
+
return this.notJoined(quarantine, read.size, why);
|
|
222
|
+
this.closedOnDisk = own;
|
|
223
|
+
let aside = null;
|
|
224
|
+
if (quarantine) {
|
|
225
|
+
aside = `${this.closedFile}.not-joined-${Date.now()}`;
|
|
226
|
+
try {
|
|
227
|
+
writeFileSync(aside, text, { mode: 0o600, flag: "wx" });
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
aside = null;
|
|
183
231
|
}
|
|
184
|
-
|
|
185
|
-
|
|
232
|
+
if (aside)
|
|
233
|
+
writerFor(this.dir, this.stem).replace(this.closedFile, this.closedText(own), 0o600, "first");
|
|
186
234
|
}
|
|
235
|
+
this.closedUnreadable = !aside;
|
|
236
|
+
this.onNote?.(`old closed goals' file ${basename(this.closedFile)} ${why}: only this team's ${own.size} were read; ${aside ? `the file as it was is kept for the operator as ${basename(aside)}` : "the file is left as it is, and never written over"}`);
|
|
187
237
|
return this.closedOnDisk;
|
|
188
238
|
}
|
|
239
|
+
moveAside(as) {
|
|
240
|
+
const aside = `${this.closedFile}.${as}-${Date.now()}`;
|
|
241
|
+
try {
|
|
242
|
+
renameSync(this.closedFile, aside);
|
|
243
|
+
return aside;
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
notJoined(quarantine, goals, why) {
|
|
250
|
+
const aside = quarantine ? this.moveAside("not-joined") : null;
|
|
251
|
+
this.closedUnreadable = !aside;
|
|
252
|
+
this.closedOnDisk = new Map();
|
|
253
|
+
this.onNote?.(`old closed goals' file ${basename(this.closedFile)} ${why}: none of its ${goals} goal(s) was read into this team; ${aside ? `kept for the operator as ${basename(aside)}` : "left as it is, and never written over"}`);
|
|
254
|
+
return this.closedOnDisk;
|
|
255
|
+
}
|
|
256
|
+
closedText(goals) {
|
|
257
|
+
const team = this.teamId?.() ?? null;
|
|
258
|
+
return JSON.stringify({ v: 1, ...(team ? { team } : {}), goals: Object.fromEntries(goals) }) + "\n";
|
|
259
|
+
}
|
|
189
260
|
closedGoals() { return [...this.closedOnDisk.values()].map((g) => ({ ...g, members: [...g.members] })); }
|
|
190
261
|
loadUsage(quarantine) {
|
|
191
262
|
try {
|
|
@@ -240,7 +311,7 @@ export class StateStore {
|
|
|
240
311
|
this.loadUsage(!!opts.quarantine);
|
|
241
312
|
const pending = pendingView(this.dir, this.stem, this.file);
|
|
242
313
|
if (pending === null || (pending === undefined && !existsSync(this.file))) {
|
|
243
|
-
this.loadClosed(!!opts.quarantine);
|
|
314
|
+
this.loadClosed(!!opts.quarantine, null);
|
|
244
315
|
this.aged = null;
|
|
245
316
|
return { goals, obligations, profiles, unclean: opts.expectHistory ? "the state snapshot is missing but the ledger has history" : null };
|
|
246
317
|
}
|
|
@@ -253,7 +324,7 @@ export class StateStore {
|
|
|
253
324
|
}
|
|
254
325
|
for (const g of snap.goals ?? [])
|
|
255
326
|
goals.set(g.id, g);
|
|
256
|
-
const kept = this.loadClosed(!!opts.quarantine);
|
|
327
|
+
const kept = this.loadClosed(!!opts.quarantine, goals);
|
|
257
328
|
for (const [id, whole] of kept) {
|
|
258
329
|
const g = goals.get(id);
|
|
259
330
|
if (g && g.closed_summary === undefined && whole.closed_summary !== undefined)
|
|
@@ -300,7 +371,7 @@ export class StateStore {
|
|
|
300
371
|
}
|
|
301
372
|
catch { }
|
|
302
373
|
}
|
|
303
|
-
this.loadClosed(!!opts.quarantine);
|
|
374
|
+
this.loadClosed(!!opts.quarantine, null);
|
|
304
375
|
this.aged = null;
|
|
305
376
|
return { goals: new Map(), obligations: new Map(), profiles: new Map(), unclean: why, ...(quarantined ? { quarantined } : {}) };
|
|
306
377
|
}
|
|
@@ -345,7 +416,7 @@ export class StateStore {
|
|
|
345
416
|
});
|
|
346
417
|
}
|
|
347
418
|
if (grew) {
|
|
348
|
-
writerFor(this.dir, this.stem).replace(this.closedFile,
|
|
419
|
+
writerFor(this.dir, this.stem).replace(this.closedFile, this.closedText(next), 0o600, "first");
|
|
349
420
|
this.closedOnDisk = next;
|
|
350
421
|
}
|
|
351
422
|
}
|