@join-pantheon/cli 0.35.1-rc.1 → 0.35.1-rc.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/dist/agent-outage.js +11 -1
- package/dist/agents.js +6 -4
- package/dist/board.js +20 -2
- package/dist/continued.js +1 -1
- package/dist/doctor.js +5 -3
- package/dist/file-lock.js +1 -1
- package/dist/home-guard.js +31 -12
- package/dist/mcp-instructions.js +17 -13
- package/dist/mcp.js +19 -8
- package/dist/notify.js +34 -8
- package/dist/relay.js +2 -1
- package/dist/spend.js +3 -2
- package/dist/worker.js +119 -33
- package/helper/macos/prebuilt/manifest.json +1 -1
- package/package.json +1 -1
package/dist/agent-outage.js
CHANGED
|
@@ -191,7 +191,17 @@ export function detectOutage(agent, tail, now = Date.now()) {
|
|
|
191
191
|
const until = !named || named.t <= now ? now + r.wait
|
|
192
192
|
: named.dated ? (named.t - now <= MAX_DATED_WAIT_MS ? named.t : now + r.wait)
|
|
193
193
|
: Math.min(named.t, now + MAX_TEXT_WAIT_MS);
|
|
194
|
-
return { why: r.why, until: Math.max(until, now + 5 * MIN) };
|
|
194
|
+
return { why: r.why, until: Math.max(until, now + 5 * MIN), ...(r.why === SIGNIN ? { signIn: true } : {}) };
|
|
195
|
+
}
|
|
196
|
+
export const isSignOut = (out) => out.signIn === true || out.why === SIGNIN;
|
|
197
|
+
export function outagePredicate(why) {
|
|
198
|
+
switch (why) {
|
|
199
|
+
case PLAN: return "has subscription access turned off by its organization";
|
|
200
|
+
case LIMIT: return "has reached its usage limit";
|
|
201
|
+
case SIGNIN: return "refused its sign-in";
|
|
202
|
+
case OVERLOAD: return "is overloaded";
|
|
203
|
+
default: return why;
|
|
204
|
+
}
|
|
195
205
|
}
|
|
196
206
|
export function whenAgain(until, now = Date.now()) {
|
|
197
207
|
const d = new Date(until);
|
package/dist/agents.js
CHANGED
|
@@ -9,7 +9,7 @@ import { gitCallEnv, safeGitArgs } from "./git-safe.js";
|
|
|
9
9
|
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
|
-
import { earliest, whenAgain } from "./agent-outage.js";
|
|
12
|
+
import { earliest, isSignOut, whenAgain } from "./agent-outage.js";
|
|
13
13
|
import { PANTHEON_TOOL_NAMES, PANTHEON_TOOLS } from "./tools.js";
|
|
14
14
|
import { claudeRunSettings, NO_CLAUDE_FEATURES, runTmpDir, sandboxCacheEnv, versionAtLeast } from "./claude-confine.js";
|
|
15
15
|
export function launchArgs(agent, prompt, name) {
|
|
@@ -320,7 +320,7 @@ export function chooseAgent(preferred, opts = {}) {
|
|
|
320
320
|
for (const c of order) {
|
|
321
321
|
const out = opts.outages?.[c.backend.id];
|
|
322
322
|
if (out) {
|
|
323
|
-
skipped.push({ backend: c.backend, why: `unavailable until ${whenAgain(out.until)} — ${out.why}` });
|
|
323
|
+
skipped.push({ backend: c.backend, why: isSignOut(out) ? "signed out — until it is signed in again" : `unavailable until ${whenAgain(out.until)} — ${out.why}` });
|
|
324
324
|
continue;
|
|
325
325
|
}
|
|
326
326
|
const s = state(c.backend, c.binary);
|
|
@@ -628,6 +628,7 @@ export const COMMAND_GRANT_SCOPE = "a run with commands works in its own worktre
|
|
|
628
628
|
"After every run Pantheon checks its own settings and puts back any change a run made to them; " +
|
|
629
629
|
"pantheon setup --unsandboxed no leaves those requests for you instead. Kiro answers in your live sessions. " +
|
|
630
630
|
"Turn commands off any time: pantheon policy revoke run-commands.";
|
|
631
|
+
export const WOKEN_INSTRUCTIONS_ROOM = 8192;
|
|
631
632
|
export function headlessSpawn(opts) {
|
|
632
633
|
const l = launcher();
|
|
633
634
|
const identity = {
|
|
@@ -667,7 +668,8 @@ export function headlessSpawn(opts) {
|
|
|
667
668
|
const f = opts.claude?.features ?? NO_CLAUDE_FEATURES;
|
|
668
669
|
const notes = [];
|
|
669
670
|
const extra = [];
|
|
670
|
-
|
|
671
|
+
const claudeEnv = { ...procEnv, CLAUDE_CODE_MAX_MCP_DESCRIPTION_LENGTH: String(WOKEN_INSTRUCTIONS_ROOM) };
|
|
672
|
+
let env = claudeEnv;
|
|
671
673
|
let rulesOnArgv = bashRules;
|
|
672
674
|
let osSandbox = false;
|
|
673
675
|
if (opts.claude && opts.runHome) {
|
|
@@ -693,7 +695,7 @@ export function headlessSpawn(opts) {
|
|
|
693
695
|
rulesOnArgv = [];
|
|
694
696
|
notes.push(...c.notes);
|
|
695
697
|
if (c.sandboxed)
|
|
696
|
-
env = { ...
|
|
698
|
+
env = { ...claudeEnv, ...sandboxCacheEnv(runTmp) };
|
|
697
699
|
osSandbox = "sandbox" in c.settings;
|
|
698
700
|
}
|
|
699
701
|
else if (f.disallowedTools) {
|
package/dist/board.js
CHANGED
|
@@ -1418,6 +1418,18 @@ function banner(msg, isError) {
|
|
|
1418
1418
|
b.hidden = false;
|
|
1419
1419
|
}
|
|
1420
1420
|
|
|
1421
|
+
// This page is being unloaded (a reload, closing the tab, a navigation): a send cut off by it is not
|
|
1422
|
+
// known to have failed, and its in-flight record is left exactly as it is, for the page that loads next
|
|
1423
|
+
// to ask the board about (/api/outcome) — never put back as unsent, never released (0.35.1-rc.1 re-check:
|
|
1424
|
+
// the old page's error handler turned Send back on, and the same words went out twice).
|
|
1425
|
+
let leaving = false;
|
|
1426
|
+
if (typeof addEventListener === "function") {
|
|
1427
|
+
addEventListener("pagehide", () => { leaving = true; });
|
|
1428
|
+
addEventListener("beforeunload", () => { leaving = true; });
|
|
1429
|
+
// Back from the browser's page cache after all: here again, and a send cut off meanwhile is asked
|
|
1430
|
+
// about like one found after a reload.
|
|
1431
|
+
addEventListener("pageshow", () => { leaving = false; for (const f of inFlight.values()) if (f.unknown) f.restored = true; });
|
|
1432
|
+
}
|
|
1421
1433
|
async function api(path, body, bearer) {
|
|
1422
1434
|
const headers = { "Accept": "application/json" };
|
|
1423
1435
|
const cred = bearer || session;
|
|
@@ -1426,7 +1438,11 @@ async function api(path, body, bearer) {
|
|
|
1426
1438
|
if (body !== undefined) { headers["Content-Type"] = "application/json"; init.body = JSON.stringify(body); }
|
|
1427
1439
|
let res;
|
|
1428
1440
|
try { res = await fetch(path, init); }
|
|
1429
|
-
catch
|
|
1441
|
+
catch (err) {
|
|
1442
|
+
// Cut off because this page is going away (a reload, a navigation): not "the board has stopped" —
|
|
1443
|
+
// nothing is known about what was sent (0.35.1-rc.1 re-check).
|
|
1444
|
+
const e = new Error("gone"); e.gone = true; e.aborted = leaving || !!(err && err.name === "AbortError"); throw e;
|
|
1445
|
+
}
|
|
1430
1446
|
let j = null;
|
|
1431
1447
|
try { j = await res.json(); } catch { j = null; }
|
|
1432
1448
|
if (res.status === 401) { const e = new Error("auth"); e.auth = true; throw e; }
|
|
@@ -1830,13 +1846,15 @@ async function send() {
|
|
|
1830
1846
|
if (inFlight.get(k) === f) landed(k, f, r);
|
|
1831
1847
|
if (r.ok) refresh();
|
|
1832
1848
|
} catch (e) {
|
|
1849
|
+
// Cut off by this page going away: unknown, not failed — the record stays for the next page.
|
|
1850
|
+
if (leaving || e.aborted) { f.unknown = true; return; }
|
|
1833
1851
|
if (inFlight.get(k) === f) {
|
|
1834
1852
|
putBack(k, text, kind);
|
|
1835
1853
|
const why = e.auth ? "This board link has expired. Run pantheon board to open a fresh one." : "Not sent — " + (e.gone ? "the board has stopped." : e.message);
|
|
1836
1854
|
sayOn(k, f.name, why + (e.auth ? "" : keyOf(current) === k ? " Your words are still in the box." : " Your words are kept on it."));
|
|
1837
1855
|
}
|
|
1838
1856
|
} finally {
|
|
1839
|
-
if (inFlight.get(k) === f) { inFlight.delete(k); saveLocal(); }
|
|
1857
|
+
if (!f.unknown && !leaving && inFlight.get(k) === f) { inFlight.delete(k); saveLocal(); }
|
|
1840
1858
|
if (keyOf(current) === k) syncControls();
|
|
1841
1859
|
}
|
|
1842
1860
|
}
|
package/dist/continued.js
CHANGED
|
@@ -4,7 +4,7 @@ import { CONFIG_DIR } from "./config.js";
|
|
|
4
4
|
import { readStateFile, withFileLock } from "./file-lock.js";
|
|
5
5
|
import { writeWhole } from "./pins.js";
|
|
6
6
|
const KEEP = 500;
|
|
7
|
-
export const WORKER_MARK = /^(parked|parked-nc|parked2|parked-ns|parked2-ns|unparked|failed1|stuck|stuck-safety|stuck-safety-due|refused)(@[^:]+)?:/;
|
|
7
|
+
export const WORKER_MARK = /^(parked|parked-nc|parked2|parked-ns|parked2-ns|unparked|failed1|stuck|stuck-safety|stuck-safety-due|refused|esc-for|decided-for)(@[^:]+)?:/;
|
|
8
8
|
const KEEP_WORKER = 2_000;
|
|
9
9
|
export const markedHere = new Set();
|
|
10
10
|
function capped(list) {
|
package/dist/doctor.js
CHANGED
|
@@ -520,9 +520,11 @@ export async function doctor(projectDir) {
|
|
|
520
520
|
const budget = instructionBudget(cfg);
|
|
521
521
|
const fromProfile = budget.profileChars;
|
|
522
522
|
const budgetLine = `${budget.chars} chars (~${budget.tokens} tokens) of session instructions per turn — ${budget.fixedChars} Pantheon's own${fromProfile > 0 ? `, ${fromProfile} from your profile (who you are, what you reserved)` : ""}; the ${budget.protocolChars}-char protocol arrives with the first tool call instead`;
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
523
|
+
const liveOver = budget.chars > 2_048;
|
|
524
|
+
add(budget.fixedChars > 1_000 || liveOver ? "warn" : "pass", "mcp context", budgetLine, liveOver ? `over 2,048 chars, which some Claude Code versions cut: a shorter title, fewer responsibilities or fewer reserved areas in your profile keeps it whole (pantheon profile show)`
|
|
525
|
+
: budget.fixedChars > 1_000 ? "Pantheon's own part used to be ~3,800 chars on every turn, and it competed with the work people asked for" : undefined, budgetLine);
|
|
526
|
+
const wokenLine = `${budget.wokenChars} chars in a woken run's instructions; the rules it must keep end at ${budget.wokenMustEnd} of 2,048; what you decide personally comes with each run's brief`;
|
|
527
|
+
add(budget.wokenMustEnd > 2_048 ? "warn" : "pass", "woken context", wokenLine, budget.wokenMustEnd > 2_048 ? "your member or team name is long enough that a host keeping 2,048 chars would cut the rules a woken run must keep" : undefined, wokenLine);
|
|
526
528
|
const approval = chosenApproval();
|
|
527
529
|
add("pass", "approval", approvalSummary(approval), `change with pantheon setup --ask-before-sending (or --approve-all); pantheon leave removes the Codex line`, approval);
|
|
528
530
|
const measured = await measureMcp({ cwd: projectDir });
|
package/dist/file-lock.js
CHANGED
|
@@ -121,7 +121,7 @@ export function readStateFile(p) {
|
|
|
121
121
|
}
|
|
122
122
|
if (!st.isFile())
|
|
123
123
|
throw new Error(`${p} is not a plain file`);
|
|
124
|
-
return readFileSync(p, "utf8");
|
|
124
|
+
return readFileSync(p, "utf8").replace(/^\uFEFF/, "");
|
|
125
125
|
}
|
|
126
126
|
export function brokenStateFiles(dir, guarded = []) {
|
|
127
127
|
const out = [];
|
package/dist/home-guard.js
CHANGED
|
@@ -811,10 +811,10 @@ export function restoreHome(s) {
|
|
|
811
811
|
return new Set();
|
|
812
812
|
}
|
|
813
813
|
})();
|
|
814
|
-
if (s.at !== undefined) {
|
|
814
|
+
if (s.at !== undefined && !s.queueDone) {
|
|
815
815
|
const gone = sweepActionQueue(s.home, { maxAgeMs: 30_000, since: s.at - 1_000 });
|
|
816
816
|
if (gone)
|
|
817
|
-
out.push({ rel: HUD_QUEUE_DIR, what: "removed", keys: [`${gone} queued menu-bar action${gone === 1 ? "" : "s"}`] });
|
|
817
|
+
out.push({ rel: HUD_QUEUE_DIR, what: "removed", keys: [`${gone} queued menu-bar action${gone === 1 ? "" : "s"} — one you clicked while it ran: click it again`] });
|
|
818
818
|
}
|
|
819
819
|
for (const f of s.files) {
|
|
820
820
|
const file = join(s.home, f.rel);
|
|
@@ -824,19 +824,43 @@ export function restoreHome(s) {
|
|
|
824
824
|
if (linkNow !== f.link) {
|
|
825
825
|
try {
|
|
826
826
|
const through = read(file);
|
|
827
|
+
const ownWrite = f.link !== undefined && linkNow === undefined && !!through && !!trusted.get(resolve(file))?.has(sha(through));
|
|
827
828
|
makeWritable(file);
|
|
828
829
|
rmSync(file, { force: true });
|
|
829
|
-
if (f.link !== undefined)
|
|
830
|
+
if (f.link !== undefined) {
|
|
830
831
|
symlinkSync(f.link, file);
|
|
832
|
+
if (ownWrite) {
|
|
833
|
+
try {
|
|
834
|
+
writeFileSync(file, through);
|
|
835
|
+
}
|
|
836
|
+
catch { }
|
|
837
|
+
}
|
|
838
|
+
}
|
|
831
839
|
else if (through)
|
|
832
840
|
putWhole(file, through);
|
|
833
|
-
|
|
841
|
+
if (!ownWrite)
|
|
842
|
+
out.push({ rel: f.rel, what: "reverted", keys: [linkNow !== undefined ? "a link in place of the file" : "its link replaced by a file"] });
|
|
834
843
|
}
|
|
835
844
|
catch {
|
|
836
845
|
out.push({ rel: f.rel, what: "reported", keys: ["(could not be put back — unattended runs are held until it is writable again)"], failed: true });
|
|
837
846
|
continue;
|
|
838
847
|
}
|
|
839
848
|
}
|
|
849
|
+
const putKept = (text) => {
|
|
850
|
+
if (f.link !== undefined && linkOf(file) === f.link) {
|
|
851
|
+
try {
|
|
852
|
+
writeFileSync(file, text);
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
catch { }
|
|
856
|
+
}
|
|
857
|
+
try {
|
|
858
|
+
if (lstatSync(file).isSymbolicLink())
|
|
859
|
+
rmSync(file, { force: true });
|
|
860
|
+
}
|
|
861
|
+
catch { }
|
|
862
|
+
putWhole(file, text);
|
|
863
|
+
};
|
|
840
864
|
const now = read(file);
|
|
841
865
|
const hashNow = now ? sha(now) : null;
|
|
842
866
|
if (hashNow === f.hash)
|
|
@@ -973,12 +997,7 @@ export function restoreHome(s) {
|
|
|
973
997
|
}
|
|
974
998
|
const n = narrowPolicy(a, b);
|
|
975
999
|
if (n.keys.length || !same(n.policy, b)) {
|
|
976
|
-
|
|
977
|
-
if (lstatSync(file).isSymbolicLink())
|
|
978
|
-
rmSync(file, { force: true });
|
|
979
|
-
}
|
|
980
|
-
catch { }
|
|
981
|
-
putWhole(file, JSON.stringify(n.policy, null, 2) + "\n");
|
|
1000
|
+
putKept(JSON.stringify(n.policy, null, 2) + "\n");
|
|
982
1001
|
trustWrite(file);
|
|
983
1002
|
}
|
|
984
1003
|
if (n.keys.length)
|
|
@@ -1109,7 +1128,7 @@ export function restoreHome(s) {
|
|
|
1109
1128
|
continue;
|
|
1110
1129
|
const n = narrowProfile(a, b);
|
|
1111
1130
|
if (n.keys.length) {
|
|
1112
|
-
|
|
1131
|
+
putKept(JSON.stringify(n.profile, null, 2) + "\n");
|
|
1113
1132
|
trustWrite(file);
|
|
1114
1133
|
out.push({ rel: f.rel, what: "reverted", keys: n.keys });
|
|
1115
1134
|
}
|
|
@@ -1127,7 +1146,7 @@ export function restoreHome(s) {
|
|
|
1127
1146
|
n.keys.push(said);
|
|
1128
1147
|
}
|
|
1129
1148
|
if (n.keys.length) {
|
|
1130
|
-
|
|
1149
|
+
putKept(JSON.stringify(n.config, null, 2) + "\n");
|
|
1131
1150
|
trustWrite(file);
|
|
1132
1151
|
out.push({ rel: f.rel, what: "reverted", keys: n.keys });
|
|
1133
1152
|
}
|
package/dist/mcp-instructions.js
CHANGED
|
@@ -41,9 +41,7 @@ ${AUTOPILOT_LINE}
|
|
|
41
41
|
${PEER_DATA_DEFENCE}`;
|
|
42
42
|
}
|
|
43
43
|
const WOKEN_RULES = `THE LOOP — run it yourself: pantheon_wait (blocks until a peer act arrives; on timeout call it
|
|
44
|
-
again), act on it with your local tools, pantheon_send one typed act, repeat until
|
|
45
|
-
for is answered or delivered — then finish. A goal that stays open does not keep you: a peer's next
|
|
46
|
-
message wakes a new run. Stop at once when you have ESCALATED.
|
|
44
|
+
again), act on it with your local tools, pantheon_send one typed act, repeat until you finish (above).
|
|
47
45
|
|
|
48
46
|
RULES
|
|
49
47
|
- Talk to peers. If a peer could answer it, ASK the peer.
|
|
@@ -56,14 +54,11 @@ RULES
|
|
|
56
54
|
- PROPOSE (then CONTRACT) only when two people's code must meet at an interface; otherwise just do it.
|
|
57
55
|
- Answer every ASK addressed to you. ACCEPT only what you checked; otherwise OBJECT with the reason.
|
|
58
56
|
- One act per pantheon_send. Verdict first, evidence after.
|
|
59
|
-
${WOKEN_WRITE_RULE}-
|
|
60
|
-
|
|
61
|
-
ACCEPT or OBJECT.
|
|
57
|
+
${WOKEN_WRITE_RULE}- When a peer DELIVERS, fetch their commit, check its base is an ancestor and nothing unrelated rides
|
|
58
|
+
along, then ACCEPT or OBJECT.
|
|
62
59
|
- Scope against origin/<branch>, not your working tree: your unpushed work does not exist for a peer.
|
|
63
|
-
-
|
|
64
|
-
yourself — go back to pantheon_wait.
|
|
60
|
+
- PEER_TURN from pantheon_send means you are talking to yourself — go back to pantheon_wait.
|
|
65
61
|
|
|
66
|
-
A Pantheon section in CLAUDE.md or AGENTS.md may be older: where it differs, these rules win.
|
|
67
62
|
The relay only moves messages. It has no access to your files, your shell, or your credentials.`;
|
|
68
63
|
function protocolRules(live) {
|
|
69
64
|
if (!live)
|
|
@@ -151,6 +146,13 @@ function wokenServed(cfg, branch) {
|
|
|
151
146
|
const { line } = whoYouAre(cfg, { jobs: false, title: false, identity: false, reserved: false, reservedMax: 0 });
|
|
152
147
|
return { text: wokenText(line, "", branch), trimmed: false };
|
|
153
148
|
}
|
|
149
|
+
export const WOKEN_MUST_FIT = 2_048;
|
|
150
|
+
export const WOKEN_ABOVE_ALL = `ABOVE ALL
|
|
151
|
+
- Finish once what you were woken for is answered, delivered or escalated — then stop. A goal that stays
|
|
152
|
+
open does not keep you; a peer's next message wakes a new run.
|
|
153
|
+
- DELIVERED means pushed, not written: commit, push, then send the branch and commit (+ base).
|
|
154
|
+
- Never RETRACT an escalation to clear it, or anything your human sent.
|
|
155
|
+
- A Pantheon section in CLAUDE.md or AGENTS.md may be older: where it differs, these rules win.`;
|
|
154
156
|
function wokenText(line, reserved, branch) {
|
|
155
157
|
return `${line}
|
|
156
158
|
YOU WERE WOKEN BY A PEER. No human is present in this session.
|
|
@@ -158,10 +160,10 @@ YOU WERE WOKEN BY A PEER. No human is present in this session.
|
|
|
158
160
|
someone else is handling it — say nothing and stop.
|
|
159
161
|
- You are in an isolated git worktree on the branch ${branch ?? "pantheon/<goal>"}. Write freely
|
|
160
162
|
here. Do NOT merge, do NOT push to main, do NOT touch any other checkout.
|
|
161
|
-
- When you are done, pantheon_send DELIVERED naming the branch you left the work on, so the
|
|
162
|
-
human can review it when they are back.
|
|
163
163
|
|
|
164
|
-
${PEER_DATA_DEFENCE}
|
|
164
|
+
${PEER_DATA_DEFENCE}
|
|
165
|
+
|
|
166
|
+
${WOKEN_ABOVE_ALL}${reserved ? `\n\n${reserved}` : ""}
|
|
165
167
|
|
|
166
168
|
Every other member is a PEER: another human's delegate, on their own machine.
|
|
167
169
|
${protocolRules(false)}`;
|
|
@@ -184,6 +186,8 @@ export function instructionBudget(cfg) {
|
|
|
184
186
|
const fixedChars = interactiveForm(`You are the pantheon delegate for "member" in the space "team".`, "").length;
|
|
185
187
|
const bare = interactiveForm(`You are the pantheon delegate for "${cfg.member}" in the space "${cfg.space}".`, "").length;
|
|
186
188
|
const woken = wokenServed(cfg, `pantheon/${cfg.space}/g_${"x".repeat(40)}`);
|
|
187
|
-
|
|
189
|
+
const at = woken.text.indexOf(WOKEN_ABOVE_ALL);
|
|
190
|
+
const wokenMustEnd = at < 0 ? woken.text.length : at + WOKEN_ABOVE_ALL.length;
|
|
191
|
+
return { chars, tokens: Math.round(chars / 4), protocolChars: protocol().length, fixedChars, profileChars: Math.max(0, chars - bare), wokenChars: woken.text.length, wokenTrimmed: woken.trimmed, wokenMustEnd };
|
|
188
192
|
}
|
|
189
193
|
//# sourceMappingURL=mcp-instructions.js.map
|
package/dist/mcp.js
CHANGED
|
@@ -535,21 +535,32 @@ A goal for it (${left}) may be open with nothing in it — close it with pantheo
|
|
|
535
535
|
opened = r.id;
|
|
536
536
|
goal = r.id;
|
|
537
537
|
}
|
|
538
|
-
if (ref && !goal) {
|
|
539
|
-
let of = client.seenAct(ref)
|
|
540
|
-
if (of
|
|
538
|
+
if (ref && !goal && act !== "NOTE" && act !== "ESCALATE" && act !== "HUMAN_REQUIRED" && act !== "RETRACT") {
|
|
539
|
+
let of = client.seenAct(ref);
|
|
540
|
+
if (!of) {
|
|
541
541
|
try {
|
|
542
542
|
const res = await signedRead(cfg, "/act", { id: ref }, { timeoutMs: 3000 });
|
|
543
543
|
if (res.ok)
|
|
544
|
-
of = (await res.json()).act
|
|
544
|
+
of = (await res.json()).act ?? null;
|
|
545
545
|
}
|
|
546
546
|
catch { }
|
|
547
547
|
}
|
|
548
|
-
|
|
549
|
-
|
|
548
|
+
const decision = act === "ANSWER" && (of?.act === "ESCALATE" || of?.act === "HUMAN_REQUIRED");
|
|
549
|
+
const g = of && typeof of.goal === "string" && of.goal && !decision ? of.goal : null;
|
|
550
|
+
const known = g ? client.goals.get(g) : undefined;
|
|
551
|
+
if (known?.state === "CLOSED") {
|
|
552
|
+
return fail(`pantheon: not sent — the act you named is in "${known.title}", which is closed: no ${act} can go there now. ` +
|
|
553
|
+
`Say what is left in a NOTE or, if your human must decide, an ESCALATE — neither needs a goal.\n (GOAL_CLOSED)`);
|
|
554
|
+
}
|
|
555
|
+
if (known && known.budget > 0 && known.acts >= known.budget) {
|
|
556
|
+
return fail(`pantheon: not sent — the act you named is in "${known.title}", which has used all the messages it may have ` +
|
|
557
|
+
`(${known.budget}), so it waits for a person now. Tell your human with an ESCALATE (it needs no goal).\n (BUDGET_SPENT)`);
|
|
558
|
+
}
|
|
559
|
+
if (g)
|
|
560
|
+
goal = g;
|
|
550
561
|
}
|
|
551
|
-
if (act === "ESCALATE" && role === "worker" && !ref
|
|
552
|
-
const mine = client.myWork().filter((o) => o.kind !== "HUMAN" && o.goal === goal && o.claimed_by?.session === client.session);
|
|
562
|
+
if (act === "ESCALATE" && role === "worker" && !ref) {
|
|
563
|
+
const mine = client.myWork().filter((o) => o.kind !== "HUMAN" && (!goal || o.goal === goal) && o.claimed_by?.session === client.session);
|
|
553
564
|
if (mine.length === 1)
|
|
554
565
|
ref = mine[0].ref;
|
|
555
566
|
}
|
package/dist/notify.js
CHANGED
|
@@ -2,9 +2,9 @@ import { fenceBlock } from "./untrusted.js";
|
|
|
2
2
|
import { chosenApproval, isVersionManagedPath } from "./install.js";
|
|
3
3
|
import { parseJsonText } from "./text-file.js";
|
|
4
4
|
import { toolsAllowed } from "./tools.js";
|
|
5
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync, rmSync } from "node:fs";
|
|
5
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync, rmSync, statSync } from "node:fs";
|
|
6
6
|
import { homedir, platform } from "node:os";
|
|
7
|
-
import { dirname, join, resolve } from "node:path";
|
|
7
|
+
import { dirname, isAbsolute, join, resolve, win32 } from "node:path";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
import { whichPantheon } from "./service.js";
|
|
10
10
|
import { managedLayout } from "./managed.js";
|
|
@@ -13,10 +13,28 @@ import { detectForHooks, agentById } from "./agents.js";
|
|
|
13
13
|
import { codexHookState, cursorHookState, copilotHookState, kiroHookState, installCodexHooks, installCursorHooks, installCopilotHooks, installKiroHooks, removeCodexHooks, removeCursorHooks, removeCopilotHooks, removeKiroHooks, } from "./hooks-install.js";
|
|
14
14
|
export const HOOK_MARKER = "pantheon hook";
|
|
15
15
|
export const HOOK_RE = /(?:pantheon(?:\.cmd|\.exe|\.bat)?["']?\s+hook\s|cli\.js["']?\s+hook\s+(?:stop|prompt|end|codex-stop|copilot-stop|cursor-stop|kiro-stop|kiro-prompt)\b)/i;
|
|
16
|
-
|
|
16
|
+
const LAUNCH_BIN = /^(?:"(?:[^"]*[\\/])?pantheon(?:\.cmd|\.exe|\.bat)?"|'(?:[^']|'\\'')*?(?:[\\/])?pantheon(?:\.cmd|\.exe|\.bat)?'|(?:[^\s"'`;&|<>$()]*[\\/])?pantheon(?:\.cmd|\.exe|\.bat)?)$/i;
|
|
17
|
+
const BARE_ODD_BIN = /^\S*[\\/]pantheon(?:\.cmd|\.exe|\.bat)?$/i;
|
|
18
|
+
const isOldBarePantheon = (word) => {
|
|
19
|
+
if (!BARE_ODD_BIN.test(word) || !(isAbsolute(word) || win32.isAbsolute(word)))
|
|
20
|
+
return false;
|
|
21
|
+
try {
|
|
22
|
+
return statSync(word).isFile();
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const LAUNCH_NODE = /^(?:"[^"]*node(?:\.exe)?"|'(?:[^']|'\\'')*?node(?:\.exe)?'|[^\s"'`;&|<>$()]*node(?:\.exe)?)(?:\s+--use-system-ca)?\s+(?:"[^"]*cli\.js"|'(?:[^']|'\\'')*cli\.js'|[^\s"'`;&|<>$()]*cli\.js)$/i;
|
|
29
|
+
const HOOK_VERBS = /^(?:stop|prompt|end|codex-stop|copilot-stop|cursor-stop|cursor-prompt|kiro-stop|kiro-prompt)$/i;
|
|
30
|
+
const HOOK_SHAPE = /^\s*([\s\S]+?)\s+hook\s+([a-z][a-z-]*)(?:\s*>\s*\/dev\/null(?:\s+2>&1)?)?\s*$/i;
|
|
31
|
+
export const isOurHookCommand = (cmd) => {
|
|
32
|
+
const m = cmd ? HOOK_SHAPE.exec(cmd) : null;
|
|
33
|
+
return !!m && (LAUNCH_BIN.test(m[1]) || (isOldBarePantheon(m[1]) && HOOK_VERBS.test(m[2])) || (LAUNCH_NODE.test(m[1]) && HOOK_VERBS.test(m[2])));
|
|
34
|
+
};
|
|
17
35
|
export const hookBin = (bin, os = platform()) => {
|
|
18
36
|
if (os === "win32")
|
|
19
|
-
return /[\s$`']/.test(bin) ? windowsHookArg(bin) : bin;
|
|
37
|
+
return /[\s$`'&|<>()^!%;,=]/.test(bin) ? windowsHookArg(bin) : bin;
|
|
20
38
|
return /^[A-Za-z0-9_./:~+-]+$/.test(bin) ? bin : `'${bin.replace(/'/g, `'\\''`)}'`;
|
|
21
39
|
};
|
|
22
40
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
@@ -64,6 +82,14 @@ function write(file, doc) {
|
|
|
64
82
|
function ours(g) {
|
|
65
83
|
return g.hooks?.some((h) => isOurHookCommand(h.command)) ?? false;
|
|
66
84
|
}
|
|
85
|
+
function withoutOurs(groups) {
|
|
86
|
+
return groups.flatMap((g) => {
|
|
87
|
+
if (!ours(g))
|
|
88
|
+
return [g];
|
|
89
|
+
const rest = (g.hooks ?? []).filter((h) => !isOurHookCommand(h.command));
|
|
90
|
+
return rest.length ? [{ ...g, hooks: rest }] : [];
|
|
91
|
+
});
|
|
92
|
+
}
|
|
67
93
|
export function hookState(projectDir = process.cwd(), only) {
|
|
68
94
|
for (const scope of (only ? [only] : ["project", "user"])) {
|
|
69
95
|
const file = settingsPath(scope, projectDir);
|
|
@@ -233,8 +259,8 @@ function installClaudeHook(scope, projectDir = process.cwd()) {
|
|
|
233
259
|
let changed = false;
|
|
234
260
|
for (const [event, cmd] of Object.entries(events)) {
|
|
235
261
|
const existing = doc.hooks[event] ?? [];
|
|
236
|
-
const cleaned = existing
|
|
237
|
-
if (cleaned
|
|
262
|
+
const cleaned = withoutOurs(existing);
|
|
263
|
+
if (JSON.stringify(cleaned) !== JSON.stringify(existing))
|
|
238
264
|
changed = true;
|
|
239
265
|
cleaned.push({ hooks: [{ type: "command", command: cmd, timeout: 10 }] });
|
|
240
266
|
doc.hooks[event] = cleaned;
|
|
@@ -314,8 +340,8 @@ function removeClaudeHook(projectDir = process.cwd()) {
|
|
|
314
340
|
}
|
|
315
341
|
let touched = false;
|
|
316
342
|
for (const [event, groups] of Object.entries(doc.hooks ?? {})) {
|
|
317
|
-
const kept = (groups ?? [])
|
|
318
|
-
if (kept
|
|
343
|
+
const kept = withoutOurs(groups ?? []);
|
|
344
|
+
if (JSON.stringify(kept) !== JSON.stringify(groups ?? [])) {
|
|
319
345
|
touched = true;
|
|
320
346
|
if (kept.length)
|
|
321
347
|
doc.hooks[event] = kept;
|
package/dist/relay.js
CHANGED
|
@@ -6451,7 +6451,8 @@ function decisionBody(rec, sp) {
|
|
|
6451
6451
|
}
|
|
6452
6452
|
export function first(s, n = 200, summary) {
|
|
6453
6453
|
const said = (t) => t.replace(/^\s*(?:#{1,6}\s+|>\s*|[-*+]\s+|\d+[.)]\s+|\[[ xX]\]\s+)*/, "").replace(/\*\*|__|`/g, "").trim();
|
|
6454
|
-
const
|
|
6454
|
+
const head = s.length > 4096 ? s.slice(0, 4096) : s;
|
|
6455
|
+
const text = head.replace(/<!--[\s\S]*?(?:-->|$)/g, "").replace(/^[ \t]*(```|~~~)[\s\S]*?(?:^[ \t]*\1[^\n]*$|(?![\s\S]))/gm, "");
|
|
6455
6456
|
const notProse = (l) => /^\s*([-*_])(?:\s*\1){2,}\s*$/.test(l) || /^\s*\|/.test(l) || /^\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)+\|?\s*$/.test(l);
|
|
6456
6457
|
const lines = text.split("\n").filter((l) => !notProse(l) && said(l).length > 0);
|
|
6457
6458
|
const heading = (l) => /^\s*#{1,6}\s/.test(l);
|
package/dist/spend.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { renameSync, rmSync, writeFileSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { readStateText } from "./file-lock.js";
|
|
2
3
|
import { randomBytes } from "node:crypto";
|
|
3
4
|
import { dirname, join } from "node:path";
|
|
4
5
|
import { CONFIG_DIR } from "./config.js";
|
|
@@ -8,7 +9,7 @@ function bookPath(home) {
|
|
|
8
9
|
function read(home) {
|
|
9
10
|
let text;
|
|
10
11
|
try {
|
|
11
|
-
text =
|
|
12
|
+
text = readStateText(bookPath(home));
|
|
12
13
|
}
|
|
13
14
|
catch (e) {
|
|
14
15
|
if (e.code === "ENOENT")
|
package/dist/worker.js
CHANGED
|
@@ -6,18 +6,18 @@ import { homedir } from "node:os";
|
|
|
6
6
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
7
7
|
import { absentDeniedPaths, describeKept, ownWorktreeConfig, detectClaudeFeatures, describeFeatures, ensureRunTmp, leavesSandboxMounts, NO_CLAUDE_FEATURES, removeSandboxLeftovers, runTmpDir } from "./claude-confine.js";
|
|
8
8
|
import { snapshotHome, restoreHome, describeChange, trustWrite, askedHere, canon, withdrawnHere, noesHere, adoptOwn, persistOwn, persistPending, resetOwn, persistSnapshot, persistRestored, persistAttempt, loadPersistedGuard, clearPersistedGuard, CHANGES_LOG_FILE, GUARDED_FILES } from "./home-guard.js";
|
|
9
|
-
import { PantheonClient } from "./client.js";
|
|
9
|
+
import { PantheonClient, failedActId } from "./client.js";
|
|
10
10
|
import { createHash, randomBytes } from "node:crypto";
|
|
11
11
|
import { newKeypair, signDelegate } from "./identity.js";
|
|
12
12
|
import { loadPins, pinScope, savePins, teamPinId, writeWhole } from "./pins.js";
|
|
13
13
|
import { answeredIn, markAnswered, noteNonce, unmarkAnswered } from "./nonces.js";
|
|
14
|
-
import { brokenStateFiles, brokenStateFix, pidAlive, readStateFile, withFileLock } from "./file-lock.js";
|
|
14
|
+
import { brokenStateFiles, brokenStateFix, pidAlive, readStateFile, readStateText, withFileLock } from "./file-lock.js";
|
|
15
15
|
import { mkdirInside, writeInside } from "./safe-write.js";
|
|
16
16
|
import { corruptHeldFiles, MAX_HELD_PER_RUN, remoteTipIs, takeHeldFrames, updateHeldState, verifyHeldFrame, writeHoldConfig } from "./held-delivery.js";
|
|
17
17
|
import { adoptedCommon, adoptWorktree, gitCallEnv, lfsInUse, repoHooksArgs, safeGitArgs, WorktreeTampered } from "./git-safe.js";
|
|
18
18
|
import { trusted } from "./verify-act.js";
|
|
19
19
|
import { AGENTS, headlessSpawn, materializeSpawnFiles, chooseAgent, agentById, describeChoice, unattendedRefusal, unattendedRefusalOf, SIGN_IN_CHECK, SANDBOXED_FOR_UNATTENDED, NOT_FOR_UNATTENDED_RUNS, claudeSandboxable, unattendedReadiness, anyUnattendedAgentOnPath, forgetMissingBinaries, gitMissing, quarantineRepoAgentConfig, AGENT_EDIT_SUFFIX, REPO_AGENT_CONFIG, COMMAND_GRANT_SCOPE, repoCommands, REPO_COMMANDS_FILE, claudeCommandRules, } from "./agents.js";
|
|
20
|
-
import { activeOutages, detectOutage, earliest, whenAgain, SIGNIN_REFUSED } from "./agent-outage.js";
|
|
20
|
+
import { activeOutages, detectOutage, earliest, isSignOut, outagePredicate, whenAgain, SIGNIN_REFUSED } from "./agent-outage.js";
|
|
21
21
|
import { agentSpawn, CmdLineUnsafe } from "./which.js";
|
|
22
22
|
import { VERSION } from "./version.js";
|
|
23
23
|
import { applyAnswer, ASK_EXPIRY_MS, policyUnreadable, CAPABILITY_ARGS, CARRY_REASON, carryOverWakers, dropLedgerGrants, hasWakeOnce, isApprovedWaker, mayAskWake, takeWakeOnce, OLD_RELAY_WAKE, relayKnowsAdmitters, loadPolicy, mayAsk, needsSelfUpgrade, parseGrantAnswer, recordAsk, savePolicy, useGrant, WOKEN_RUN_ENV, takeTeamFlagOnYes, unsandboxedAllowed, policyPath, isNewer, RUN_MINUTES, effectiveRunMinutes, effectiveIdleSeconds, readinessRecheckPath, policyHome, describeRunMinutes, parseRunMinutes, currentMode, wakeSettled, } from "./worker-policy.js";
|
|
@@ -797,6 +797,8 @@ That is their decision. Reply to your teammate with it now (step 4: an ANSWER wi
|
|
|
797
797
|
in your own plain words, and act on it if the request asks for work. Do not escalate the same question again.
|
|
798
798
|
`;
|
|
799
799
|
}
|
|
800
|
+
const ESCALATED_FOR = "esc-for:";
|
|
801
|
+
const DECIDED_FOR = "decided-for:";
|
|
800
802
|
export const MOOT_GRACE_MS = 2 * 60_000;
|
|
801
803
|
export function buildBrief(o, trigger, branch, persona, canPush = false, decided) {
|
|
802
804
|
const placed = branch
|
|
@@ -1007,7 +1009,7 @@ export const PERSON_HOLD_TTL_MS = 60_000;
|
|
|
1007
1009
|
export const PERSON_ANSWERING = "your person is answering a question on this computer";
|
|
1008
1010
|
export function personHold(dir, now = Date.now()) {
|
|
1009
1011
|
try {
|
|
1010
|
-
const v = JSON.parse(
|
|
1012
|
+
const v = JSON.parse(readStateText(join(dir, PERSON_HOLD)));
|
|
1011
1013
|
const pid = Number(v?.pid), at = Number(v?.at);
|
|
1012
1014
|
if (!Number.isInteger(pid) || pid <= 1 || !Number.isFinite(at) || at > now + 5_000 || now - at > PERSON_HOLD_TTL_MS || !pidAlive(pid))
|
|
1013
1015
|
return null;
|
|
@@ -1178,7 +1180,7 @@ export async function recoverGuardHere(home) {
|
|
|
1178
1180
|
} })();
|
|
1179
1181
|
if (!anyCfg)
|
|
1180
1182
|
return { outcome: "unreachable" };
|
|
1181
|
-
const v = await verifyOwnWrites(g.own, anyCfg.member, (t) => configForTeam(t, anyCfg));
|
|
1183
|
+
const v = await verifyOwnWrites(g.own, anyCfg.member, (t) => configForTeam(t, anyCfg), refusedSaid((l) => console.error(l)));
|
|
1182
1184
|
if (v === "unreachable")
|
|
1183
1185
|
return { outcome: "unreachable" };
|
|
1184
1186
|
own = v;
|
|
@@ -1192,7 +1194,7 @@ export function recoverInterruptedGuard(home, now = Date.now(), restore = restor
|
|
|
1192
1194
|
if (sameProcess(g.worker, g.workerId))
|
|
1193
1195
|
return { outcome: "live" };
|
|
1194
1196
|
try {
|
|
1195
|
-
const r = JSON.parse(
|
|
1197
|
+
const r = JSON.parse(readStateText(join(home, RUN_RECORD)));
|
|
1196
1198
|
if (r && r.worker === g.worker && Number.isInteger(r.pid) && r.pid > 1 && typeof r.at === "number" && now - r.at <= recordLimitMs(r) && recordedRunAlive(r.pid))
|
|
1197
1199
|
killRunTree(r.pid);
|
|
1198
1200
|
}
|
|
@@ -1211,7 +1213,7 @@ export function recoverInterruptedGuard(home, now = Date.now(), restore = restor
|
|
|
1211
1213
|
const wentAt = lease && lease.pid === g.worker && typeof lease.at === "number" && Number.isFinite(lease.at) ? lease.at + RUN_LEASE_RENEW_MS : null;
|
|
1212
1214
|
if (wentAt !== null && !pending)
|
|
1213
1215
|
try {
|
|
1214
|
-
const mine =
|
|
1216
|
+
const mine = readStateText(join(home, CHANGES_LOG_FILE)).split("\n").some((l) => {
|
|
1215
1217
|
try {
|
|
1216
1218
|
const e = JSON.parse(l);
|
|
1217
1219
|
return typeof e.at === "number" && e.at > Math.max(g.at, wentAt) && e.setting !== "first-setup" && e.asked_by === "terminal" && (e.outcome === "applied" || e.outcome === "approved" || e.outcome === "kept");
|
|
@@ -1227,7 +1229,7 @@ export function recoverInterruptedGuard(home, now = Date.now(), restore = restor
|
|
|
1227
1229
|
}
|
|
1228
1230
|
catch { }
|
|
1229
1231
|
try {
|
|
1230
|
-
const snapshot = pending ? { ...g.snapshot, files: g.snapshot.files.filter((f) => g.pending.includes(f.rel)) } : g.snapshot;
|
|
1232
|
+
const snapshot = pending ? { ...g.snapshot, files: g.snapshot.files.filter((f) => g.pending.includes(f.rel)), queueDone: true } : g.snapshot;
|
|
1231
1233
|
const changes = restore(snapshot);
|
|
1232
1234
|
const said = putBackList(changes);
|
|
1233
1235
|
const rels = changes.filter((c) => c.failed).map((c) => c.rel);
|
|
@@ -1273,7 +1275,7 @@ function writeRunRecord(dir, r) {
|
|
|
1273
1275
|
function clearRunRecord(dir, pid) {
|
|
1274
1276
|
try {
|
|
1275
1277
|
const f = join(dir, RUN_RECORD);
|
|
1276
|
-
const r = JSON.parse(
|
|
1278
|
+
const r = JSON.parse(readStateText(f));
|
|
1277
1279
|
if (r.pid === pid)
|
|
1278
1280
|
rmSync(f, { force: true });
|
|
1279
1281
|
}
|
|
@@ -1283,7 +1285,7 @@ export function killRecordedRun(dir, now = Date.now()) {
|
|
|
1283
1285
|
const f = join(dir, RUN_RECORD);
|
|
1284
1286
|
let r;
|
|
1285
1287
|
try {
|
|
1286
|
-
r = JSON.parse(
|
|
1288
|
+
r = JSON.parse(readStateText(f));
|
|
1287
1289
|
}
|
|
1288
1290
|
catch {
|
|
1289
1291
|
return null;
|
|
@@ -1323,7 +1325,7 @@ export function parentOf(pid) {
|
|
|
1323
1325
|
export function runInFlight(dir, now = Date.now(), o = {}) {
|
|
1324
1326
|
let r;
|
|
1325
1327
|
try {
|
|
1326
|
-
r = JSON.parse(
|
|
1328
|
+
r = JSON.parse(readStateText(join(dir, RUN_RECORD)));
|
|
1327
1329
|
}
|
|
1328
1330
|
catch {
|
|
1329
1331
|
return null;
|
|
@@ -1350,7 +1352,7 @@ export function runMinutesLeft(dir, now = Date.now()) {
|
|
|
1350
1352
|
if (!runInFlight(dir, now))
|
|
1351
1353
|
return null;
|
|
1352
1354
|
try {
|
|
1353
|
-
const r = JSON.parse(
|
|
1355
|
+
const r = JSON.parse(readStateText(join(dir, RUN_RECORD)));
|
|
1354
1356
|
if (typeof r.exited_at === "number")
|
|
1355
1357
|
return 1;
|
|
1356
1358
|
if (typeof r.limit !== "number" || !Number.isFinite(r.limit))
|
|
@@ -1374,6 +1376,15 @@ export function answerWindow(askSeq, hint, fullScanDue) {
|
|
|
1374
1376
|
return Math.max(0, hint);
|
|
1375
1377
|
}
|
|
1376
1378
|
const teamConfigs = new Map();
|
|
1379
|
+
const refusedSaid = (log) => {
|
|
1380
|
+
const said = new Set();
|
|
1381
|
+
return (team, status) => {
|
|
1382
|
+
if (said.has(team))
|
|
1383
|
+
return;
|
|
1384
|
+
said.add(team);
|
|
1385
|
+
log(` guard the relay of "${team}" refused this machine (${status === 410 ? "the team was deleted" : status === 401 ? "it needs a newer pantheon" : "removed from the team, or signed out"}) — what the interrupted run's worker had asked there is not kept; nothing waits on it`);
|
|
1386
|
+
};
|
|
1387
|
+
};
|
|
1377
1388
|
function configForTeam(team, mine) {
|
|
1378
1389
|
if (team === mine.spaceId || team === mine.space)
|
|
1379
1390
|
return mine;
|
|
@@ -1389,7 +1400,7 @@ function configForTeam(team, mine) {
|
|
|
1389
1400
|
return null;
|
|
1390
1401
|
}
|
|
1391
1402
|
}
|
|
1392
|
-
export async function verifyOwnWrites(o, member, cfgFor) {
|
|
1403
|
+
export async function verifyOwnWrites(o, member, cfgFor, refused) {
|
|
1393
1404
|
const out = { wake: [], cap: [], stuck: [], safety: [], withdrawn: [], noes: [], marks: [] };
|
|
1394
1405
|
let unreachable = false;
|
|
1395
1406
|
const seen = new Map();
|
|
@@ -1407,6 +1418,8 @@ export async function verifyOwnWrites(o, member, cfgFor) {
|
|
|
1407
1418
|
if (found)
|
|
1408
1419
|
break;
|
|
1409
1420
|
}
|
|
1421
|
+
else if (res.status === 401 || res.status === 403 || res.status === 410)
|
|
1422
|
+
refused?.(cfg.space, res.status);
|
|
1410
1423
|
else if (res.status !== 404)
|
|
1411
1424
|
unreachable = true;
|
|
1412
1425
|
}
|
|
@@ -1802,7 +1815,7 @@ export class Worker {
|
|
|
1802
1815
|
}
|
|
1803
1816
|
outageDiagnosis(label, out, others, meanwhile) {
|
|
1804
1817
|
const id = AGENTS.find((a) => a.label === label)?.id;
|
|
1805
|
-
if (out
|
|
1818
|
+
if (isSignOut(out) || (id && this.signedOutHere.has(id))) {
|
|
1806
1819
|
let why = (id && this.signedOutHere.has(id) && this.outages.get(id)?.why) || undefined;
|
|
1807
1820
|
if (why === SIGNIN_REFUSED)
|
|
1808
1821
|
why = undefined;
|
|
@@ -1828,11 +1841,11 @@ export class Worker {
|
|
|
1828
1841
|
: others.length ? `; ${others.join("; ")}` : "; no other agent is installed for runs while you are away";
|
|
1829
1842
|
return {
|
|
1830
1843
|
cause: "agent_unavailable",
|
|
1831
|
-
says: `${label} is unavailable here until about ${at}
|
|
1844
|
+
says: `${label} ${outagePredicate(out.why)}, so it is unavailable here until about ${at}${rest}.`,
|
|
1832
1845
|
fix: `It runs by itself after ${at}. Sooner: sign in to another agent (cursor-agent, codex or copilot) — and for an agent without a sandbox, pantheon policy grant unsandboxed-runs — or answer it in a live session.`,
|
|
1833
1846
|
peer: {
|
|
1834
1847
|
summary: `${this.cfg.member}'s agent is unavailable for ${forAbout(out.until)} — this waits`,
|
|
1835
|
-
body: `${this.cfg.member}'s worker could not start a run: ${label} ${out.why}, and no other agent on that machine could take it. It is still owed; the worker tries again in ${forAbout(out.until)}.`,
|
|
1848
|
+
body: `${this.cfg.member}'s worker could not start a run: ${label} ${outagePredicate(out.why)}, and no other agent on that machine could take it. It is still owed; the worker tries again in ${forAbout(out.until)}.`,
|
|
1836
1849
|
},
|
|
1837
1850
|
};
|
|
1838
1851
|
}
|
|
@@ -1850,7 +1863,7 @@ export class Worker {
|
|
|
1850
1863
|
const until = mark.at + retryAfter(mark);
|
|
1851
1864
|
const cur = this.outages.get(id);
|
|
1852
1865
|
if (!cur || cur.until < until)
|
|
1853
|
-
this.outages.set(id, { why: this.signedOutWhy(id, mark), until });
|
|
1866
|
+
this.outages.set(id, { why: this.signedOutWhy(id, mark), until, signIn: true });
|
|
1854
1867
|
this.signedOutHere.add(id);
|
|
1855
1868
|
}
|
|
1856
1869
|
else if (this.signedOutHere.has(id)) {
|
|
@@ -1899,7 +1912,7 @@ export class Worker {
|
|
|
1899
1912
|
try {
|
|
1900
1913
|
this.opts.notify({
|
|
1901
1914
|
kind: "worker", who: "Your worker", heading: `${c.backend.label} is answering for Claude Code`, context: this.cfg.space,
|
|
1902
|
-
body: `Claude Code is
|
|
1915
|
+
body: `${isSignOut(first.out) ? `Claude Code ${outagePredicate(first.out.why === SIGNIN_REFUSED ? "is signed out on this machine" : first.out.why)}. Until it is signed in again` : `Claude Code ${outagePredicate(first.out.why)}, so it is unavailable until about ${whenAgain(first.out.until)}. Until then`} ${c.backend.label} takes teammates' requests on this machine, without Claude Code's sandbox, as your settings allow. To have them wait instead: pantheon policy revoke unsandboxed-runs`,
|
|
1903
1916
|
ttl: 0, sound: false,
|
|
1904
1917
|
});
|
|
1905
1918
|
}
|
|
@@ -2197,7 +2210,7 @@ export class Worker {
|
|
|
2197
2210
|
const e = byId.get(r.ref) ?? client.seenAct(r.ref);
|
|
2198
2211
|
if (!e || e.act !== "ESCALATE" || e.from !== this.cfg.member)
|
|
2199
2212
|
continue;
|
|
2200
|
-
if (e.ref ? e.ref !== o.ref : !
|
|
2213
|
+
if (e.ref ? e.ref !== o.ref : !this.hasMark(`${ESCALATED_FOR}${e.id}:${o.ref}`))
|
|
2201
2214
|
continue;
|
|
2202
2215
|
if (!as(e, "verified-run") || !as(r, "verified"))
|
|
2203
2216
|
continue;
|
|
@@ -2221,6 +2234,7 @@ export class Worker {
|
|
|
2221
2234
|
if (this.contDone.has(mark) || this.continuedHas(mark))
|
|
2222
2235
|
return;
|
|
2223
2236
|
this.markDone(mark);
|
|
2237
|
+
this.markDone(`${DECIDED_FOR}${o.ref}:${d.answer.id}`);
|
|
2224
2238
|
this.decided.set(o.ref, d.answer.body);
|
|
2225
2239
|
if (this.decided.size > 200)
|
|
2226
2240
|
this.decided.delete(this.decided.keys().next().value);
|
|
@@ -2239,6 +2253,26 @@ export class Worker {
|
|
|
2239
2253
|
this.opts.log(`> ${owedLabel(o.kind)} ${o.id}: its person answered the escalation (${d.answer.id}) — a run takes it again to pass that on`);
|
|
2240
2254
|
}
|
|
2241
2255
|
decided = new Map();
|
|
2256
|
+
hasMark(id) { return this.contDone.has(id) || this.continuedHas(id); }
|
|
2257
|
+
async decisionFor(client, o) {
|
|
2258
|
+
const kept = this.decided.get(o.ref);
|
|
2259
|
+
if (kept !== undefined)
|
|
2260
|
+
return kept;
|
|
2261
|
+
const seen = this.escalationAnswer(client, o)?.answer.body;
|
|
2262
|
+
if (seen !== undefined)
|
|
2263
|
+
return seen;
|
|
2264
|
+
this.loadContinued();
|
|
2265
|
+
const prefix = `${DECIDED_FOR}${o.ref}:`;
|
|
2266
|
+
const ids = [...this.contDone].filter((k) => k.startsWith(prefix)).map((k) => k.slice(prefix.length));
|
|
2267
|
+
const id = ids.at(-1);
|
|
2268
|
+
if (!id)
|
|
2269
|
+
return undefined;
|
|
2270
|
+
const answer = (await this.fetchActById(id));
|
|
2271
|
+
const escalation = answer?.ref ? (await this.fetchActById(answer.ref)) : null;
|
|
2272
|
+
if (!answer || !escalation)
|
|
2273
|
+
return undefined;
|
|
2274
|
+
return this.escalationAnswer(client, o, [escalation, answer])?.answer.body;
|
|
2275
|
+
}
|
|
2242
2276
|
async recentActs() {
|
|
2243
2277
|
try {
|
|
2244
2278
|
const res = await signedRead(this.cfg, "/history", {}, { timeoutMs: 5000 });
|
|
@@ -2257,7 +2291,7 @@ export class Worker {
|
|
|
2257
2291
|
this.keepOwn();
|
|
2258
2292
|
}
|
|
2259
2293
|
async verifyOwn(o) {
|
|
2260
|
-
return verifyOwnWrites(o, this.cfg.member, (t) => configForTeam(t, this.cfg));
|
|
2294
|
+
return verifyOwnWrites(o, this.cfg.member, (t) => configForTeam(t, this.cfg), refusedSaid(this.opts.log));
|
|
2261
2295
|
}
|
|
2262
2296
|
keepOwn() { try {
|
|
2263
2297
|
persistOwn(this.stateDir());
|
|
@@ -2270,7 +2304,7 @@ export class Worker {
|
|
|
2270
2304
|
if (!p)
|
|
2271
2305
|
return false;
|
|
2272
2306
|
let changes = [];
|
|
2273
|
-
const only = { ...p.snap, files: p.snap.files.filter((f) => p.rels.includes(f.rel)) };
|
|
2307
|
+
const only = { ...p.snap, files: p.snap.files.filter((f) => p.rels.includes(f.rel)), queueDone: true };
|
|
2274
2308
|
try {
|
|
2275
2309
|
changes = (this.opts.restore ?? restoreHome)(only);
|
|
2276
2310
|
}
|
|
@@ -3240,6 +3274,9 @@ export class Worker {
|
|
|
3240
3274
|
this.report("idle");
|
|
3241
3275
|
if (candidate && job.ok)
|
|
3242
3276
|
this.markDone(`handled:${candidate.ref}`);
|
|
3277
|
+
if (candidate)
|
|
3278
|
+
for (const id of job.escalated ?? [])
|
|
3279
|
+
this.markDone(`${ESCALATED_FOR}${id}:${candidate.ref}`);
|
|
3243
3280
|
const ran = candidate ? candidateAct : continuation;
|
|
3244
3281
|
if (job.ok && ran?.sig) {
|
|
3245
3282
|
try {
|
|
@@ -3411,7 +3448,7 @@ export class Worker {
|
|
|
3411
3448
|
runRecord = null;
|
|
3412
3449
|
recordChanged = false;
|
|
3413
3450
|
recordOnDisk() { try {
|
|
3414
|
-
return
|
|
3451
|
+
return readStateText(join(this.stateDir(), RUN_RECORD));
|
|
3415
3452
|
}
|
|
3416
3453
|
catch {
|
|
3417
3454
|
return null;
|
|
@@ -3496,7 +3533,7 @@ export class Worker {
|
|
|
3496
3533
|
const dir = this.stateDir(), f = join(dir, RUN_RECORD);
|
|
3497
3534
|
let r;
|
|
3498
3535
|
try {
|
|
3499
|
-
r = JSON.parse(
|
|
3536
|
+
r = JSON.parse(readStateText(f));
|
|
3500
3537
|
}
|
|
3501
3538
|
catch {
|
|
3502
3539
|
return;
|
|
@@ -3645,7 +3682,7 @@ export class Worker {
|
|
|
3645
3682
|
: `(the triggering act ${printable(o.ref)} is not in this session's buffer; the relay's one-line summary of it follows)\n${o.body}`;
|
|
3646
3683
|
const act = (base ?? undefined);
|
|
3647
3684
|
const needs = workNeedsCommands(o.kind, trigger, o.kind === "REVISE" && act?.ref ? client.seenAct(act.ref)?.act : act?.act);
|
|
3648
|
-
const decided =
|
|
3685
|
+
const decided = await this.decisionFor(client, o);
|
|
3649
3686
|
return this.runJob(client, o, persona, policy, (branch, canPush) => buildBrief(o, trigger, branch, persona, canPush, decided), true, needs, trigger, act);
|
|
3650
3687
|
}
|
|
3651
3688
|
async handleContinuation(client, act, persona, policy) {
|
|
@@ -3664,7 +3701,7 @@ export class Worker {
|
|
|
3664
3701
|
}
|
|
3665
3702
|
spentOnce = {};
|
|
3666
3703
|
policyBytes() { try {
|
|
3667
|
-
return
|
|
3704
|
+
return readStateText(policyPath(this.opts.home));
|
|
3668
3705
|
}
|
|
3669
3706
|
catch {
|
|
3670
3707
|
return null;
|
|
@@ -4220,7 +4257,20 @@ export class Worker {
|
|
|
4220
4257
|
const held = await this.settleHeld(client, heldRun ? { run: heldRun, canPush: canPush && !massDelete, massDelete } : null);
|
|
4221
4258
|
const settled = [...held.sent, ...held.waiting];
|
|
4222
4259
|
const settledIds = new Set(settled.map((a) => a.id));
|
|
4223
|
-
const
|
|
4260
|
+
const runId = this.runKey?.runId;
|
|
4261
|
+
const goalOf = new Map();
|
|
4262
|
+
if (o.goal != null && runId)
|
|
4263
|
+
for (const a of client.mineSince(startedAt)) {
|
|
4264
|
+
if (goalOf.size >= 8)
|
|
4265
|
+
break;
|
|
4266
|
+
if (a.goal == null && a.ref && a.ref !== o.ref && a.sig?.role === "run" && a.sig.cert?.run === runId && !goalOf.has(a.ref)) {
|
|
4267
|
+
const t = (client.seenAct(a.ref) ?? await this.fetchActById(a.ref).catch(() => null));
|
|
4268
|
+
goalOf.set(a.ref, t ? (t.goal ?? null) : undefined);
|
|
4269
|
+
}
|
|
4270
|
+
}
|
|
4271
|
+
const elsewhere = o.goal == null ? [] : client.mineSince(startedAt).filter((a) => a.goal !== o.goal && !settledIds.has(a.id)
|
|
4272
|
+
&& ((!!o.ref && a.ref === o.ref) || (!!runId && a.goal == null && (a.ref == null || a.ref === o.ref || goalOf.get(a.ref) === o.goal) && a.sig?.role === "run" && a.sig.cert?.run === runId)));
|
|
4273
|
+
const sent = [...client.mineSince(startedAt, o.goal).filter((a) => !settledIds.has(a.id)), ...elsewhere, ...settled.filter((a) => o.goal == null || a.goal === o.goal)];
|
|
4224
4274
|
const repliedWith = sent.find((a) => ["DELIVERED", "ANSWER", "ESCALATE", "ACCEPT", "OBJECT", "PROPOSE", "CONTRACT", "CLOSE", "WITHDRAW"].includes(a.act) || (a.act === "NOTE" && !!a.ref));
|
|
4225
4275
|
const replied = requireReply ? client.repliedTo(o) || !!repliedWith : true;
|
|
4226
4276
|
if (requireReply && replied && !client.repliedTo(o) && repliedWith) {
|
|
@@ -4312,7 +4362,8 @@ export class Worker {
|
|
|
4312
4362
|
this.opts.log(quiet ? `< read ${o.id} on ${branch} — the thread was already settled, nothing sent`
|
|
4313
4363
|
: ok ? `< handled ${o.id} on ${branch}`
|
|
4314
4364
|
: `! ${o.id} stopped [${diagnosis.cause}]: ${diagnosis.says} (transcript: ${runLog})`);
|
|
4315
|
-
|
|
4365
|
+
const escalated = sent.filter((a) => a.act === "ESCALATE" && !a.ref && a.from === this.cfg.member && (a.sig?.role === "run" || a.role === "worker")).map((a) => a.id);
|
|
4366
|
+
return { obligation: o, branch, worktree, ok, detail, ...(diagnosis ? { diagnosis } : {}), ...(escalated.length ? { escalated } : {}) };
|
|
4316
4367
|
}
|
|
4317
4368
|
catch (e) {
|
|
4318
4369
|
if (!recorded) {
|
|
@@ -4652,7 +4703,7 @@ export class Worker {
|
|
|
4652
4703
|
if (this.running || !client.connected)
|
|
4653
4704
|
return;
|
|
4654
4705
|
try {
|
|
4655
|
-
const r = JSON.parse(
|
|
4706
|
+
const r = JSON.parse(readStateText(join(this.stateDir(), RUN_RECORD)));
|
|
4656
4707
|
if (r && r.space === this.cfg.space && Number.isInteger(r.worker) && r.worker !== process.pid && pidAlive(r.worker))
|
|
4657
4708
|
return;
|
|
4658
4709
|
}
|
|
@@ -4839,8 +4890,13 @@ export class Worker {
|
|
|
4839
4890
|
savePolicy(fresh, this.opts.home);
|
|
4840
4891
|
}
|
|
4841
4892
|
safetyDue = new Map();
|
|
4893
|
+
stuckDue = new Map();
|
|
4894
|
+
async ownOnRecord(client, id, waitMs) {
|
|
4895
|
+
const r = (await client.seenOwn(id, waitMs).catch(() => null)) ?? (await client.storedAct(id).catch(() => null));
|
|
4896
|
+
return r ? { id: r.id, seq: r.seq } : null;
|
|
4897
|
+
}
|
|
4842
4898
|
safetyRaised = new Map();
|
|
4843
|
-
async reportStuck(client, o, d, attempts, again = 0) {
|
|
4899
|
+
async reportStuck(client, o, d, attempts, again = 0, known) {
|
|
4844
4900
|
this.learnRequests([o]);
|
|
4845
4901
|
const safety = SAFETY_CAUSES.has(d.cause);
|
|
4846
4902
|
const key = safety ? `stuck-safety:${this.oKey(o.id)}:${d.cause}` : `stuck:${this.oKey(o.id)}`;
|
|
@@ -4883,12 +4939,14 @@ export class Worker {
|
|
|
4883
4939
|
...(safety ? { meta: { safety_stop: d.cause } } : {}),
|
|
4884
4940
|
});
|
|
4885
4941
|
const passing = (m) => !/^[A-Z_]+:/.test(m) || /^(RATE_LIMIT|STORAGE|STALE_VIEW|TOO_MANY_REFUSALS):/.test(m);
|
|
4886
|
-
const
|
|
4942
|
+
const before = known ? await this.ownOnRecord(client, known, 500) : null;
|
|
4943
|
+
const sent = before ?? await client.send(frame(o.goal)).catch((e) => {
|
|
4887
4944
|
if (!safety || passing(e.message))
|
|
4888
4945
|
return Promise.reject(e);
|
|
4889
4946
|
return client.send(frame(null, false, null)).catch((e2) => passing(e2.message) ? Promise.reject(e2) : client.send(frame(null, true, null)));
|
|
4890
4947
|
});
|
|
4891
4948
|
markContinued(space, key, this.opts.home);
|
|
4949
|
+
this.stuckDue.delete(key);
|
|
4892
4950
|
if (safety) {
|
|
4893
4951
|
this.safetyDue.delete(key);
|
|
4894
4952
|
this.safetyRaised.set(sent.id, { o, d, seq: sent.seq, again });
|
|
@@ -4928,12 +4986,40 @@ export class Worker {
|
|
|
4928
4986
|
}
|
|
4929
4987
|
catch { }
|
|
4930
4988
|
}
|
|
4931
|
-
|
|
4989
|
+
const unanswered = !safety && /^NO_REPLY\b/.test(msg) ? failedActId(e) : null;
|
|
4990
|
+
if (unanswered) {
|
|
4991
|
+
const on = await this.ownOnRecord(client, unanswered, 2_500);
|
|
4992
|
+
if (on) {
|
|
4993
|
+
await this.reportStuck(client, o, d, attempts, again, on.id);
|
|
4994
|
+
return;
|
|
4995
|
+
}
|
|
4996
|
+
}
|
|
4997
|
+
const retry = !safety && (!!unanswered || !/^[A-Z_]+:/.test(msg) || /^(RATE_LIMIT|STORAGE|STALE_VIEW|TOO_MANY_REFUSALS):/.test(msg));
|
|
4998
|
+
if (retry)
|
|
4999
|
+
this.stuckDue.set(key, { o, d, attempts, again, next: Date.now() + 60_000, ...(unanswered ? { known: unanswered } : known ? { known } : {}) });
|
|
5000
|
+
else if (!safety)
|
|
5001
|
+
this.stuckDue.delete(key);
|
|
5002
|
+
this.opts.log(`! could not report the stuck obligation on the ledger: ${msg}${safety ? lasting ? " — a safety warning: shown on this computer instead" : " — a safety warning: tried again until it is said" : retry ? " — tried again in a minute" : ""}`);
|
|
4932
5003
|
}
|
|
4933
5004
|
}
|
|
4934
5005
|
async settleSafety(client) {
|
|
4935
5006
|
if (!client.connected)
|
|
4936
5007
|
return;
|
|
5008
|
+
for (const [key, s] of [...this.stuckDue]) {
|
|
5009
|
+
if (loadContinued(this.spaceKey(), this.opts.home).has(key)) {
|
|
5010
|
+
this.stuckDue.delete(key);
|
|
5011
|
+
continue;
|
|
5012
|
+
}
|
|
5013
|
+
const now = client.myWork().find((x) => this.oKey(x.id) === this.oKey(s.o.id));
|
|
5014
|
+
if (!now) {
|
|
5015
|
+
this.stuckDue.delete(key);
|
|
5016
|
+
continue;
|
|
5017
|
+
}
|
|
5018
|
+
if (s.next > Date.now())
|
|
5019
|
+
continue;
|
|
5020
|
+
s.next = Date.now() + 60_000;
|
|
5021
|
+
await this.reportStuck(client, now, s.d, s.attempts, s.again, s.known);
|
|
5022
|
+
}
|
|
4937
5023
|
for (const [key, { o, d }] of [...this.safetyDue]) {
|
|
4938
5024
|
if (loadContinued(this.spaceKey(), this.opts.home).has(key)) {
|
|
4939
5025
|
this.safetyDue.delete(key);
|
|
@@ -5612,7 +5698,7 @@ export class Worker {
|
|
|
5612
5698
|
cursorSaid = 0;
|
|
5613
5699
|
readCursor() {
|
|
5614
5700
|
try {
|
|
5615
|
-
const j = JSON.parse(
|
|
5701
|
+
const j = JSON.parse(readStateText(this.cursorFile()));
|
|
5616
5702
|
const v = j[this.spaceKey()] ?? j[this.cfg.space];
|
|
5617
5703
|
return typeof v === "number" && v > 0 ? v : 0;
|
|
5618
5704
|
}
|
|
@@ -5627,7 +5713,7 @@ export class Worker {
|
|
|
5627
5713
|
try {
|
|
5628
5714
|
let j = {};
|
|
5629
5715
|
try {
|
|
5630
|
-
j = JSON.parse(
|
|
5716
|
+
j = JSON.parse(readStateText(this.cursorFile()));
|
|
5631
5717
|
}
|
|
5632
5718
|
catch { }
|
|
5633
5719
|
j[this.spaceKey()] = seq;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@join-pantheon/cli",
|
|
3
|
-
"version": "0.35.1-rc.
|
|
3
|
+
"version": "0.35.1-rc.3",
|
|
4
4
|
"description": "Let your coding agent collaborate directly with your teammates' agents — ask, agree an interface, and deliver, without a human relaying messages.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|