@join-pantheon/cli 0.34.2 → 0.34.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 +2 -1
- package/dist/agent-token.js +133 -0
- package/dist/agents.js +15 -1
- package/dist/cli.js +134 -5
- package/dist/doctor.js +36 -0
- package/dist/home-guard.js +24 -2
- package/dist/home-safety.js +2 -0
- package/dist/mcp.js +5 -3
- package/dist/relay.js +12 -3
- package/dist/signed-out.js +90 -0
- package/dist/worker.js +66 -3
- package/helper/macos/prebuilt/manifest.json +1 -1
- package/package.json +1 -1
package/dist/agent-outage.js
CHANGED
|
@@ -4,12 +4,13 @@ const TAIL_LINES = 5;
|
|
|
4
4
|
const PLAN = "its organization has disabled subscription access for it";
|
|
5
5
|
const LIMIT = "its usage limit is reached";
|
|
6
6
|
const SIGNIN = "its sign-in was refused";
|
|
7
|
+
export const SIGNIN_REFUSED = SIGNIN;
|
|
7
8
|
const OVERLOAD = "its service is overloaded";
|
|
8
9
|
const KINDS = {
|
|
9
10
|
"claude-code": [
|
|
10
11
|
{ re: /disabled Claude subscription access/i, why: PLAN, wait: 6 * HOUR },
|
|
11
12
|
{ re: /Claude AI usage limit reached|(?:5-hour|weekly|Opus|session) limit reached|you(?:'|’)ve hit your (?:usage )?limit|out of extra usage|credit balance is too low/i, why: LIMIT, wait: HOUR },
|
|
12
|
-
{ re: /OAuth token has expired|Invalid API key · Please run \/login|Please run \/login/i, why: SIGNIN, wait: HOUR },
|
|
13
|
+
{ re: /OAuth token has expired|Invalid API key · Please run \/login|Please run \/login|Failed to authenticate|API Error: 401\b|OAuth access token is invalid/i, why: SIGNIN, wait: HOUR },
|
|
13
14
|
{ re: /overloaded_error/i, why: OVERLOAD, wait: 15 * MIN },
|
|
14
15
|
],
|
|
15
16
|
codex: [
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFileSync, renameSync, rmSync, writeFileSync, mkdirSync, chmodSync, mkdtempSync } from "node:fs";
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { agentSpawn } from "./which.js";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { CONFIG_DIR } from "./config.js";
|
|
8
|
+
export const AGENT_TOKEN_FILE = "agent-tokens.json";
|
|
9
|
+
export const CLAUDE_TOKEN_RE = /^sk-ant-oat01-[A-Za-z0-9_-]{20,400}$/;
|
|
10
|
+
export const CLAUDE_TOKEN_LIFE_MS = 365 * 86_400_000;
|
|
11
|
+
export const CLAUDE_TOKEN_WARN_MS = 30 * 86_400_000;
|
|
12
|
+
export const agentTokenFile = (home = CONFIG_DIR) => join(home, AGENT_TOKEN_FILE);
|
|
13
|
+
function read(home) {
|
|
14
|
+
try {
|
|
15
|
+
const j = JSON.parse(readFileSync(agentTokenFile(home), "utf8"));
|
|
16
|
+
return j && typeof j === "object" ? j : {};
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function loadClaudeToken(home = CONFIG_DIR) {
|
|
23
|
+
const c = read(home).claude;
|
|
24
|
+
if (!c || typeof c.token !== "string" || !CLAUDE_TOKEN_RE.test(c.token) || typeof c.saved_at !== "number")
|
|
25
|
+
return null;
|
|
26
|
+
return c;
|
|
27
|
+
}
|
|
28
|
+
export const normalizeClaudeToken = (raw) => raw.replace(/\s+/g, "");
|
|
29
|
+
export function claudeTokenProblem(raw) {
|
|
30
|
+
const t = normalizeClaudeToken(raw);
|
|
31
|
+
if (!t)
|
|
32
|
+
return "nothing was pasted";
|
|
33
|
+
if (/^sk-ant-api\d\d-/.test(t))
|
|
34
|
+
return "that is an API key, not the token `claude setup-token` prints (it starts with sk-ant-oat01-)";
|
|
35
|
+
if (!t.startsWith("sk-ant-oat01-") && t.includes("sk-ant-oat01-"))
|
|
36
|
+
return "there is other text around the token — copy the token alone";
|
|
37
|
+
if (!CLAUDE_TOKEN_RE.test(t))
|
|
38
|
+
return "it does not look like the token `claude setup-token` prints (it starts with sk-ant-oat01-)";
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
export function saveClaudeToken(raw, home = CONFIG_DIR, now = Date.now()) {
|
|
42
|
+
const why = claudeTokenProblem(raw);
|
|
43
|
+
if (why)
|
|
44
|
+
throw new Error(why);
|
|
45
|
+
const f = read(home);
|
|
46
|
+
const stored = { token: normalizeClaudeToken(raw), saved_at: now };
|
|
47
|
+
f.claude = stored;
|
|
48
|
+
mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
49
|
+
const file = agentTokenFile(home);
|
|
50
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
51
|
+
writeFileSync(tmp, JSON.stringify(f, null, 2) + "\n", { mode: 0o600 });
|
|
52
|
+
try {
|
|
53
|
+
chmodSync(tmp, 0o600);
|
|
54
|
+
}
|
|
55
|
+
catch { }
|
|
56
|
+
renameSync(tmp, file);
|
|
57
|
+
return stored;
|
|
58
|
+
}
|
|
59
|
+
export function removeClaudeToken(home = CONFIG_DIR) {
|
|
60
|
+
const f = read(home);
|
|
61
|
+
if (!f.claude)
|
|
62
|
+
return false;
|
|
63
|
+
delete f.claude;
|
|
64
|
+
const file = agentTokenFile(home);
|
|
65
|
+
if (!Object.keys(f).length) {
|
|
66
|
+
rmSync(file, { force: true });
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
70
|
+
writeFileSync(tmp, JSON.stringify(f, null, 2) + "\n", { mode: 0o600 });
|
|
71
|
+
renameSync(tmp, file);
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
export const claudeTokenEnds = (t) => t.saved_at + CLAUDE_TOKEN_LIFE_MS;
|
|
75
|
+
export function claudeTokenForRun(home = CONFIG_DIR, env = process.env, now = Date.now()) {
|
|
76
|
+
if (envClaudeCredential(env))
|
|
77
|
+
return null;
|
|
78
|
+
const t = loadClaudeToken(home);
|
|
79
|
+
if (!t || now >= claudeTokenEnds(t))
|
|
80
|
+
return null;
|
|
81
|
+
return t.token;
|
|
82
|
+
}
|
|
83
|
+
export function envClaudeCredential(env = process.env) {
|
|
84
|
+
for (const k of ["CLAUDE_CODE_USE_BEDROCK", "CLAUDE_CODE_USE_VERTEX", "CLAUDE_CODE_USE_FOUNDRY", "ANTHROPIC_AUTH_TOKEN", "ANTHROPIC_API_KEY", "CLAUDE_CODE_OAUTH_TOKEN"]) {
|
|
85
|
+
if (env[k] && env[k] !== "0")
|
|
86
|
+
return k;
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
export function claudeTokenStamp(home = CONFIG_DIR) {
|
|
91
|
+
const t = loadClaudeToken(home);
|
|
92
|
+
return t ? createHash("sha256").update(t.token).digest("hex").slice(0, 12) : "";
|
|
93
|
+
}
|
|
94
|
+
export function checkClaudeToken(token, binary, o = {}) {
|
|
95
|
+
if (!binary)
|
|
96
|
+
return { ok: false, bad: false, why: "Claude Code is not installed here" };
|
|
97
|
+
const cwd = mkdtempSync(join(tmpdir(), "pantheon-token-check-"));
|
|
98
|
+
const configDir = join(cwd, ".claude-config");
|
|
99
|
+
mkdirSync(configDir, { recursive: true, mode: 0o700 });
|
|
100
|
+
const env = { ...(o.env ?? process.env), CLAUDE_CODE_OAUTH_TOKEN: token, CLAUDE_CONFIG_DIR: configDir };
|
|
101
|
+
for (const k of ["ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN", "CLAUDE_CODE_USE_BEDROCK", "CLAUDE_CODE_USE_VERTEX", "CLAUDE_CODE_USE_FOUNDRY", "PANTHEON_HOME"])
|
|
102
|
+
delete env[k];
|
|
103
|
+
try {
|
|
104
|
+
const args = ["-p", "Reply with the single word OK.", "--max-turns", "1", "--strict-mcp-config", "--mcp-config", '{"mcpServers":{}}', "--setting-sources", "user"];
|
|
105
|
+
const r = (o.run ?? runCheck)(binary, args, env, cwd);
|
|
106
|
+
const said = r.out.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
107
|
+
if (r.status === 0)
|
|
108
|
+
return { ok: true };
|
|
109
|
+
const refusal = said.slice(-5).find((l) => /please run \/login|invalid api key|oauth (?:access )?token|failed to authenticate|unauthori[sz]ed|api error: 401\b/i.test(l));
|
|
110
|
+
if (refusal)
|
|
111
|
+
return { ok: false, bad: true, says: refusal.slice(0, 160) };
|
|
112
|
+
return { ok: false, bad: false, why: r.timedOut ? "Claude Code did not answer within a minute" : `Claude Code could not be asked (${(said.at(-1) ?? "no answer").slice(0, 120)})` };
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
try {
|
|
116
|
+
rmSync(cwd, { recursive: true, force: true });
|
|
117
|
+
}
|
|
118
|
+
catch { }
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function runCheck(bin, args, env, cwd) {
|
|
122
|
+
let plan;
|
|
123
|
+
try {
|
|
124
|
+
plan = agentSpawn(bin, args);
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
return { status: null, out: e.message };
|
|
128
|
+
}
|
|
129
|
+
const r = spawnSync(plan.command, plan.args, { env, cwd, encoding: "utf8", timeout: 60_000, stdio: ["ignore", "pipe", "pipe"], windowsHide: true, ...plan.options });
|
|
130
|
+
return { status: r.status, out: `${r.stdout ?? ""}\n${r.stderr ?? ""}`, timedOut: r.error?.code === "ETIMEDOUT" };
|
|
131
|
+
}
|
|
132
|
+
export const CLAUDE_TOKEN_WHOLE_MIN = 100;
|
|
133
|
+
//# sourceMappingURL=agent-token.js.map
|
package/dist/agents.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { claudeTokenEnds, envClaudeCredential, loadClaudeToken } from "./agent-token.js";
|
|
1
2
|
import { execFileSync } from "node:child_process";
|
|
2
3
|
import { createHash, randomBytes } from "node:crypto";
|
|
3
4
|
import { accessSync, constants as fsConstants, cpSync, existsSync, statSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, renameSync, rmSync } from "node:fs";
|
|
@@ -248,6 +249,19 @@ export function signedIn(backend, binary, run = runStatus, home = homedir()) {
|
|
|
248
249
|
return copilotSignedIn(run);
|
|
249
250
|
if (backend.id === "kiro")
|
|
250
251
|
return kiroSignedIn(binary, run, process.env, home);
|
|
252
|
+
if (backend.id === "claude-code") {
|
|
253
|
+
const named = envClaudeCredential(process.env);
|
|
254
|
+
if (named)
|
|
255
|
+
return { ok: true, detail: `signed in (${named} in the environment)` };
|
|
256
|
+
const t = loadClaudeToken();
|
|
257
|
+
if (t) {
|
|
258
|
+
const ends = claudeTokenEnds(t);
|
|
259
|
+
if (Date.now() < ends)
|
|
260
|
+
return { ok: true, detail: `signed in with a long-lived token (until ${new Date(ends).toISOString().slice(0, 10)})` };
|
|
261
|
+
if (!existsSync(join(home, AGENT_HOME_DIR[backend.id])))
|
|
262
|
+
return { ok: false, detail: `the long-lived token ended ${new Date(ends).toISOString().slice(0, 10)} — make a new one: claude setup-token, then pantheon worker token` };
|
|
263
|
+
}
|
|
264
|
+
}
|
|
251
265
|
if (!existsSync(join(home, AGENT_HOME_DIR[backend.id])))
|
|
252
266
|
return { ok: false, detail: "never signed in on this machine" };
|
|
253
267
|
const check = SIGN_IN_CHECK[backend.id];
|
|
@@ -708,7 +722,7 @@ export function headlessSpawn(opts) {
|
|
|
708
722
|
...extra,
|
|
709
723
|
"--allowedTools", ...PANTHEON_TOOLS, ...rulesOnArgv,
|
|
710
724
|
],
|
|
711
|
-
env,
|
|
725
|
+
env: opts.claudeToken ? { ...env, CLAUDE_CODE_OAUTH_TOKEN: opts.claudeToken } : env,
|
|
712
726
|
writeFiles,
|
|
713
727
|
...(notes.length ? { notes } : {}),
|
|
714
728
|
...(extra.includes("--setting-sources") ? { repoSettingsIgnored: true } : {}),
|
package/dist/cli.js
CHANGED
|
@@ -1599,6 +1599,8 @@ ${B("control")}
|
|
|
1599
1599
|
or it waits a day); recover confirm|cancel <who> is the teammate's side
|
|
1600
1600
|
pantheon worker stay answerable while you are away
|
|
1601
1601
|
(--agent claude-code|codex|cursor|copilot|kiro|auto, --persona <name>)
|
|
1602
|
+
pantheon worker token keep the worker's Claude Code signed in for a year: paste what \`claude setup-token\` prints
|
|
1603
|
+
(--status, --remove)
|
|
1602
1604
|
pantheon changes changes to your setup an agent asked for, waiting for your yes (review; approve|keep <id>; --history)
|
|
1603
1605
|
a setup command run with no terminal (a script, a scheduler) is held the same way: it prints
|
|
1604
1606
|
"No terminal here, so this was held …", exits 0, and waits for: pantheon changes approve <id>
|
|
@@ -1734,7 +1736,7 @@ const COMMAND_FLAGS = {
|
|
|
1734
1736
|
uninstall: "--yes --forget-identity --stop-relay --project <dir>",
|
|
1735
1737
|
stop: "[relay|worker|notifier|menubar|all] --port <n>",
|
|
1736
1738
|
logs: "[relay|worker|notifier|menubar] --follow --n <lines>",
|
|
1737
|
-
worker: "--agent <claude-code|codex|cursor|copilot|kiro|auto> --persona <name> --project <dir> --allow-bash --max-runs <n> --max-runs-day <n> --run-minutes <5-180> --grace <s> --once",
|
|
1739
|
+
worker: "--agent <claude-code|codex|cursor|copilot|kiro|auto> --persona <name> --project <dir> --allow-bash --max-runs <n> --max-runs-day <n> --run-minutes <5-180> --grace <s> --once (token: --status --remove --no-check)",
|
|
1738
1740
|
service: "install [relay|worker|notifier|menubar] | restart <kind> | uninstall <kind> --project <dir> --allow-bash --run-minutes <5-180> --fresh (a worker's flags from these alone, not kept)",
|
|
1739
1741
|
doctor: "--share --project <dir>",
|
|
1740
1742
|
relay: "--port <n> --host <address> --data <dir> (relay leftovers --data <dir> [--json]: read-only report)",
|
|
@@ -5755,7 +5757,7 @@ async function main() {
|
|
|
5755
5757
|
}
|
|
5756
5758
|
const closeAll = () => { for (const c of clients)
|
|
5757
5759
|
c.close(); };
|
|
5758
|
-
const one = id ? open.find((x) => x.o.id === id) : open.length === 1 ? open[0] : undefined;
|
|
5760
|
+
const one = id ? open.find((x) => x.o.id === id) ?? open.find((x) => x.o.ref === id) : open.length === 1 ? open[0] : undefined;
|
|
5759
5761
|
if (id && !one) {
|
|
5760
5762
|
closeAll();
|
|
5761
5763
|
die(`no decision ${id} is waiting on you in ${every.length > 1 ? `any of your ${every.length} teams` : `"${cfg.space}"`}`);
|
|
@@ -5844,7 +5846,7 @@ async function main() {
|
|
|
5844
5846
|
const closeAll = () => { for (const c of conns)
|
|
5845
5847
|
c.client.close(); };
|
|
5846
5848
|
const all = conns.flatMap(({ cfg, client }) => client.obligations.filter((o) => o.kind === "HUMAN" && o.owner === `human:${cfg.member}`).map((o) => ({ o, cfg, client })));
|
|
5847
|
-
const find = (want) => all.find((x) => x.o.id === want);
|
|
5849
|
+
const find = (want) => all.find((x) => x.o.id === want) ?? all.find((x) => x.o.ref === want);
|
|
5848
5850
|
if (sub === "answer") {
|
|
5849
5851
|
if (!id)
|
|
5850
5852
|
die("usage: pantheon approvals answer <obligation-id> <decision> [--summary 'one line']");
|
|
@@ -5907,7 +5909,7 @@ async function main() {
|
|
|
5907
5909
|
if (sub === "answer") {
|
|
5908
5910
|
if (!id)
|
|
5909
5911
|
die("usage: pantheon approvals answer <obligation-id> <decision>");
|
|
5910
|
-
const o = waiting.find((x) => x.id === id) ?? die(`no decision ${id} is waiting on you`);
|
|
5912
|
+
const o = waiting.find((x) => x.id === id) ?? waiting.find((x) => x.ref === id) ?? die(`no decision ${id} is waiting on you`);
|
|
5911
5913
|
const answer = argv.slice(3).join(" ").trim() || die("state the decision; it will be written to the audit ledger");
|
|
5912
5914
|
const sent = await client.send({ act: "ANSWER", body: answer, goal: null, ref: o.ref, after_seq: client.readSeq });
|
|
5913
5915
|
console.log(`${C("answered")} ${id} — ledger act ${sent.id}`);
|
|
@@ -5917,7 +5919,7 @@ async function main() {
|
|
|
5917
5919
|
if (sub === "show") {
|
|
5918
5920
|
if (!id)
|
|
5919
5921
|
die("usage: pantheon approvals show <obligation-id>");
|
|
5920
|
-
const o = waiting.find((x) => x.id === id) ?? die(`no decision ${id} is waiting on you`);
|
|
5922
|
+
const o = waiting.find((x) => x.id === id) ?? waiting.find((x) => x.ref === id) ?? die(`no decision ${id} is waiting on you`);
|
|
5921
5923
|
console.log(`${B("Decision required")} ${o.id}`);
|
|
5922
5924
|
console.log(` ${o.body}`);
|
|
5923
5925
|
if (o.goal)
|
|
@@ -5936,6 +5938,10 @@ async function main() {
|
|
|
5936
5938
|
return;
|
|
5937
5939
|
}
|
|
5938
5940
|
case "worker": {
|
|
5941
|
+
if (argv[1] === "token") {
|
|
5942
|
+
await workerToken(argv.slice(2));
|
|
5943
|
+
return;
|
|
5944
|
+
}
|
|
5939
5945
|
const runMinutesFlag = flag("run-minutes") === undefined ? undefined : (await import("./worker-policy.js")).parseRunMinutes(flag("run-minutes")) ?? die((await import("./worker-policy.js")).runMinutesProblem(flag("run-minutes")).replace("pantheon policy set run-minutes default", "leave --run-minutes off"));
|
|
5940
5946
|
(await import("./machine.js")).recordWorkerPid();
|
|
5941
5947
|
const allCfg = loadAll();
|
|
@@ -6598,4 +6604,127 @@ main().catch(async (e) => die(await describeRelayFailure(e, (() => { try {
|
|
|
6598
6604
|
catch {
|
|
6599
6605
|
return undefined;
|
|
6600
6606
|
} })())));
|
|
6607
|
+
async function workerToken(args) {
|
|
6608
|
+
const { saveClaudeToken, removeClaudeToken, loadClaudeToken, claudeTokenEnds, envClaudeCredential, claudeTokenProblem } = await import("./agent-token.js");
|
|
6609
|
+
const day = (ms) => new Date(ms).toISOString().slice(0, 10);
|
|
6610
|
+
const leaked = args.some((a) => /sk-ant-/.test(a));
|
|
6611
|
+
const stray = args.find((a) => !a.startsWith("--"));
|
|
6612
|
+
if (leaked || stray) {
|
|
6613
|
+
die(`don't put the token on the command line — your shell keeps it in its history. Run ${B("pantheon worker token")} and paste it when asked.${leaked ? " If you just did, clear that line from your shell history." : ""}`);
|
|
6614
|
+
}
|
|
6615
|
+
if (args.includes("--remove")) {
|
|
6616
|
+
await workerTokenGate("remove");
|
|
6617
|
+
console.log(removeClaudeToken() ? "Removed: your worker's Claude Code runs use your normal Claude sign-in again." : "No token was saved here.");
|
|
6618
|
+
return;
|
|
6619
|
+
}
|
|
6620
|
+
if (args.includes("--status")) {
|
|
6621
|
+
const t = loadClaudeToken();
|
|
6622
|
+
const env = envClaudeCredential();
|
|
6623
|
+
if (env)
|
|
6624
|
+
console.log(`${env} is set in this environment: Claude Code uses it before any saved token.`);
|
|
6625
|
+
console.log(t ? `A long-lived token is saved (${day(t.saved_at)}); it works until ${day(claudeTokenEnds(t))}.` : "No token is saved: woken runs use your normal Claude sign-in (it lapses about every 30 days).");
|
|
6626
|
+
return;
|
|
6627
|
+
}
|
|
6628
|
+
await workerTokenGate(args.includes("--remove") ? "remove" : "save");
|
|
6629
|
+
let raw;
|
|
6630
|
+
if (process.stdin.isTTY) {
|
|
6631
|
+
console.log("Get the token first: run `claude setup-token` in another terminal and copy what it prints (it starts with sk-ant-oat01-).");
|
|
6632
|
+
raw = await readHidden("Paste the token here (it will not show), then press Enter: ");
|
|
6633
|
+
}
|
|
6634
|
+
else {
|
|
6635
|
+
if (process.stdout.isTTY)
|
|
6636
|
+
process.stdout.write("Paste the token, then press Enter: ");
|
|
6637
|
+
raw = await new Promise((ok) => {
|
|
6638
|
+
let d = "";
|
|
6639
|
+
process.stdin.setEncoding("utf8");
|
|
6640
|
+
const done = () => { process.stdin.pause(); ok(d); };
|
|
6641
|
+
process.stdin.on("data", (c) => { d += c; if (d.length > 4096)
|
|
6642
|
+
d = d.slice(0, 4096); if (process.stdout.isTTY && /\n\s*$/.test(d) && /sk-ant-/.test(d))
|
|
6643
|
+
done(); });
|
|
6644
|
+
process.stdin.on("end", done);
|
|
6645
|
+
});
|
|
6646
|
+
}
|
|
6647
|
+
const why = claudeTokenProblem(raw);
|
|
6648
|
+
if (why)
|
|
6649
|
+
die(`not saved: ${why}.`);
|
|
6650
|
+
let unchecked = null;
|
|
6651
|
+
if (!args.includes("--no-check")) {
|
|
6652
|
+
const { checkClaudeToken, normalizeClaudeToken } = await import("./agent-token.js");
|
|
6653
|
+
const { resolveBinary, agentById } = await import("./agents.js");
|
|
6654
|
+
console.log("Checking it with Claude Code…");
|
|
6655
|
+
const bin = (() => { try {
|
|
6656
|
+
return resolveBinary(agentById("claude-code")) ?? null;
|
|
6657
|
+
}
|
|
6658
|
+
catch {
|
|
6659
|
+
return null;
|
|
6660
|
+
} })();
|
|
6661
|
+
const c = checkClaudeToken(normalizeClaudeToken(raw), bin);
|
|
6662
|
+
if (!c.ok && c.bad)
|
|
6663
|
+
die(`not saved: Claude refused this token ("${c.says}"). Copy the whole token \`claude setup-token\` printed — it may run over two lines — and run this again. (To save it without this check: pantheon worker token --no-check)`);
|
|
6664
|
+
if (!c.ok) {
|
|
6665
|
+
unchecked = c.why;
|
|
6666
|
+
const { CLAUDE_TOKEN_WHOLE_MIN } = await import("./agent-token.js");
|
|
6667
|
+
const n = normalizeClaudeToken(raw).length;
|
|
6668
|
+
if (n < CLAUDE_TOKEN_WHOLE_MIN)
|
|
6669
|
+
die(`not saved: it could not be checked (${c.why}), and at ${n} characters it is shorter than a whole token — copy it again in full (it may run over two lines). To save it as it is: pantheon worker token --no-check`);
|
|
6670
|
+
}
|
|
6671
|
+
}
|
|
6672
|
+
const t = saveClaudeToken(raw);
|
|
6673
|
+
if (unchecked)
|
|
6674
|
+
console.log(`Could not check it now: ${unchecked}. It is saved; pantheon doctor says if a run is refused.`);
|
|
6675
|
+
console.log(`${C("saved")}: this machine's worker gives it to the Claude Code runs it starts, from the next run on (no restart needed). It works until ${day(claudeTokenEnds(t))}.`);
|
|
6676
|
+
console.log("Keep it private like a password: anyone holding it uses your Claude plan. A run's own commands can see it in Claude Code's environment; only teammates you let wake your worker start runs.");
|
|
6677
|
+
console.log(`Check it: ${B("pantheon doctor")} — the worker agent line says "signed in with a long-lived token". Remove it: ${B("pantheon worker token --remove")}`);
|
|
6678
|
+
const env = envClaudeCredential();
|
|
6679
|
+
if (env)
|
|
6680
|
+
console.log(`Note: ${env} is set in this environment, and Claude Code uses it before this token.`);
|
|
6681
|
+
}
|
|
6682
|
+
async function workerTokenGate(what) {
|
|
6683
|
+
const who = whoIsAsking(process.env, !!process.stdout.isTTY);
|
|
6684
|
+
if (who.kind !== "terminal")
|
|
6685
|
+
die(`${what === "save" ? "saving" : "removing"} the worker's Claude token is for ${personName()} to do, in a terminal of their own (on Windows: PowerShell or Windows Terminal) — ${who.kind === "worker" ? "a woken run" : who.agent === "no terminal" ? "a script with no terminal" : "an agent"} cannot do it for them. Ask them to run: pantheon worker token${what === "remove" ? " --remove" : ""}`);
|
|
6686
|
+
const busy = await setupBusy();
|
|
6687
|
+
if (busy)
|
|
6688
|
+
die(`${busy} Nothing changed — run it again once the request is done.`);
|
|
6689
|
+
}
|
|
6690
|
+
function readHidden(prompt) {
|
|
6691
|
+
return new Promise((ok) => {
|
|
6692
|
+
process.stdout.write(prompt);
|
|
6693
|
+
const stdin = process.stdin;
|
|
6694
|
+
let value = "";
|
|
6695
|
+
const done = (v) => {
|
|
6696
|
+
stdin.setRawMode?.(false);
|
|
6697
|
+
stdin.pause();
|
|
6698
|
+
stdin.removeListener("data", onData);
|
|
6699
|
+
process.stdout.write("\n");
|
|
6700
|
+
if (v === null)
|
|
6701
|
+
process.exit(130);
|
|
6702
|
+
ok(v);
|
|
6703
|
+
};
|
|
6704
|
+
const onData = (chunk) => {
|
|
6705
|
+
const text = String(chunk);
|
|
6706
|
+
for (let i = 0; i < text.length; i++) {
|
|
6707
|
+
const ch = text[i];
|
|
6708
|
+
if (ch === "\u0003")
|
|
6709
|
+
return done(null);
|
|
6710
|
+
if (ch === "\r" || ch === "\n") {
|
|
6711
|
+
if (text.slice(i).trim() === "")
|
|
6712
|
+
return done(value);
|
|
6713
|
+
value += "\n";
|
|
6714
|
+
continue;
|
|
6715
|
+
}
|
|
6716
|
+
if (ch === "\u007f" || ch === "\b") {
|
|
6717
|
+
value = value.slice(0, -1);
|
|
6718
|
+
continue;
|
|
6719
|
+
}
|
|
6720
|
+
if (value.length < 4096)
|
|
6721
|
+
value += ch;
|
|
6722
|
+
}
|
|
6723
|
+
};
|
|
6724
|
+
stdin.setRawMode?.(true);
|
|
6725
|
+
stdin.resume();
|
|
6726
|
+
stdin.setEncoding("utf8");
|
|
6727
|
+
stdin.on("data", onData);
|
|
6728
|
+
});
|
|
6729
|
+
}
|
|
6601
6730
|
//# sourceMappingURL=cli.js.map
|
package/dist/doctor.js
CHANGED
|
@@ -407,6 +407,42 @@ export async function doctor(projectDir) {
|
|
|
407
407
|
catch (e) {
|
|
408
408
|
add("warn", "worker agent", e.message, "pantheon setup --agent <claude-code|codex|cursor|copilot|kiro> names one that is installed", "could not be chosen");
|
|
409
409
|
}
|
|
410
|
+
try {
|
|
411
|
+
const { signedOutNow, SIGNED_OUT_AGENTS } = await import("./signed-out.js");
|
|
412
|
+
const { SIGN_IN_FIX } = await import("./run-failure.js");
|
|
413
|
+
const { claudeTokenForRun } = await import("./agent-token.js");
|
|
414
|
+
for (const id of SIGNED_OUT_AGENTS) {
|
|
415
|
+
const m = signedOutNow(id);
|
|
416
|
+
if (!m)
|
|
417
|
+
continue;
|
|
418
|
+
const label = agentById(id)?.label ?? id;
|
|
419
|
+
const token = id === "claude-code" && !!claudeTokenForRun(undefined, {});
|
|
420
|
+
add("warn", "worker agent", `a run here at ${new Date(m.at).toISOString().slice(0, 16).replace("T", " ")} UTC found ${label} ${token ? "refusing the saved worker token" : "signed out"} ("${m.says}"), so teammates' requests wait`, token ? "make a new token (claude setup-token, then pantheon worker token), or remove it to use your own sign-in: pantheon worker token --remove"
|
|
421
|
+
: `${SIGN_IN_FIX[id] ?? "sign in to it again"}${id === "claude-code" ? " — or keep it signed in for a year: claude setup-token, then pantheon worker token" : ""}`, `${label} found signed out by a run`);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
catch { }
|
|
425
|
+
try {
|
|
426
|
+
const { envClaudeCredential } = await import("./agent-token.js");
|
|
427
|
+
const named = envClaudeCredential();
|
|
428
|
+
if (named && workerSetUp && !inWokenRun())
|
|
429
|
+
add("warn", "worker agent", `${named} is set in this shell, which your worker's service does not see — its runs use the token saved for it, or your own Claude sign-in`, "to keep the worker signed in for a year: claude setup-token, then pantheon worker token", `${named} set in the shell only`);
|
|
430
|
+
}
|
|
431
|
+
catch { }
|
|
432
|
+
try {
|
|
433
|
+
const { loadClaudeToken, claudeTokenEnds, CLAUDE_TOKEN_WARN_MS } = await import("./agent-token.js");
|
|
434
|
+
const t = loadClaudeToken();
|
|
435
|
+
if (t) {
|
|
436
|
+
const ends = claudeTokenEnds(t), left = ends - Date.now(), day = new Date(ends).toISOString().slice(0, 10);
|
|
437
|
+
if (left <= 0)
|
|
438
|
+
add("warn", "worker token", `Claude Code's long-lived token ended ${day}`, "make a new one: claude setup-token, then pantheon worker token", "ended");
|
|
439
|
+
else if (left <= CLAUDE_TOKEN_WARN_MS)
|
|
440
|
+
add("warn", "worker token", `Claude Code's long-lived token ends ${day}`, "make a new one before then: claude setup-token, then pantheon worker token", "ends within a month");
|
|
441
|
+
else
|
|
442
|
+
add("pass", "worker token", `Claude Code runs use a long-lived token until ${day}`, undefined, "saved");
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
catch { }
|
|
410
446
|
}
|
|
411
447
|
{
|
|
412
448
|
const here = readKiroAgent(kiroAgentFile(join(projectDir, ".kiro")));
|
package/dist/home-guard.js
CHANGED
|
@@ -19,7 +19,9 @@ export const CHANGES_LOG_FILE = "setup-changes.log";
|
|
|
19
19
|
export const PENDING_CHANGES_FILE = "setup-pending.json";
|
|
20
20
|
export const RUN_CONTROL_FILE = "run-control.json";
|
|
21
21
|
export const HUD_PREF_FILE = join("bin", ".hud-pref.json");
|
|
22
|
-
export const
|
|
22
|
+
export const AGENT_TOKENS_FILE = "agent-tokens.json";
|
|
23
|
+
export const SIGNED_OUT_FILE = "signed-out.json";
|
|
24
|
+
export const GUARDED_FILES = [AGENT_TOKENS_FILE, SIGNED_OUT_FILE, POLICY_FILE, CONFIG_FILE, PROFILE_FILE, HUD_FILE, CONTINUED_FILE, CURSOR_FILE, PINS_FILE, NONCES_FILE, REMOVED_FILE, RECHECK_FILE, READINESS_ALERT_FILE, CHANGES_LOG_FILE, PENDING_CHANGES_FILE, RUN_CONTROL_FILE, HUD_PREF_FILE];
|
|
23
25
|
export function narrowRunControl(before, now) {
|
|
24
26
|
const list = (x) => (Array.isArray(obj(x).stops) ? obj(x).stops.filter((e) => !!e && typeof e === "object") : []);
|
|
25
27
|
const b = list(before), n = list(now);
|
|
@@ -168,12 +170,14 @@ function unredactConfig(before, now) {
|
|
|
168
170
|
walk(before, []);
|
|
169
171
|
return { config: out, proxyLost };
|
|
170
172
|
}
|
|
171
|
-
const HOLDS_SECRETS = new Set([CONFIG_FILE]);
|
|
173
|
+
const HOLDS_SECRETS = new Set([CONFIG_FILE, AGENT_TOKENS_FILE]);
|
|
172
174
|
export function persistSnapshot(s, o = {}) {
|
|
173
175
|
const file = join(s.home, RUN_GUARD_FILE);
|
|
174
176
|
const files = s.files.map((f) => {
|
|
175
177
|
if (!HOLDS_SECRETS.has(f.rel) || !f.bytes)
|
|
176
178
|
return { rel: f.rel, bytes: f.bytes ? f.bytes.toString("base64") : null, hash: f.hash };
|
|
179
|
+
if (f.rel === AGENT_TOKENS_FILE)
|
|
180
|
+
return { rel: f.rel, bytes: null, hash: f.hash, redacted: true };
|
|
177
181
|
let safe = null;
|
|
178
182
|
try {
|
|
179
183
|
safe = JSON.stringify(redactConfig(parseJsonText(f.bytes.toString("utf8"))));
|
|
@@ -660,6 +664,24 @@ export function restoreHome(s) {
|
|
|
660
664
|
rmSync(file, { recursive: true, force: true });
|
|
661
665
|
}
|
|
662
666
|
catch { }
|
|
667
|
+
if (f.rel === AGENT_TOKENS_FILE || f.rel === SIGNED_OUT_FILE) {
|
|
668
|
+
try {
|
|
669
|
+
if (lstatSync(file).isSymbolicLink())
|
|
670
|
+
rmSync(file, { force: true });
|
|
671
|
+
}
|
|
672
|
+
catch { }
|
|
673
|
+
if (f.rel === AGENT_TOKENS_FILE && f.redacted) {
|
|
674
|
+
rmSync(file, { force: true });
|
|
675
|
+
out.push({ rel: f.rel, what: "removed", keys: ["the worker's Claude token changed while a run went — save it again: pantheon worker token"] });
|
|
676
|
+
continue;
|
|
677
|
+
}
|
|
678
|
+
if (f.bytes)
|
|
679
|
+
writeWhole(file, f.bytes.toString("utf8"));
|
|
680
|
+
else
|
|
681
|
+
rmSync(file, { force: true });
|
|
682
|
+
out.push({ rel: f.rel, what: f.bytes ? "reverted" : "removed", keys: f.rel === AGENT_TOKENS_FILE ? ["the worker's Claude token"] : [], ...(f.rel === SIGNED_OUT_FILE ? { quiet: true } : {}) });
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
663
685
|
if (f.rel === CHANGES_LOG_FILE) {
|
|
664
686
|
const was = f.bytes?.toString("utf8") ?? "";
|
|
665
687
|
const is = now?.toString("utf8") ?? "";
|
package/dist/home-safety.js
CHANGED
|
@@ -23,6 +23,8 @@ export const PANTHEON_HOME_ENTRIES = [
|
|
|
23
23
|
{ name: "removed.json", what: "the teams this machine was removed from", identity: true },
|
|
24
24
|
{ name: "readiness-recheck.stamp", what: "the mark that has the worker look again for an agent it can run" },
|
|
25
25
|
{ name: "worker-state.json", what: "the worker's last state" },
|
|
26
|
+
{ name: "agent-tokens.json", what: "the long-lived Claude Code token your worker's runs use (pantheon worker token)" },
|
|
27
|
+
{ name: "signed-out.json", what: "the agents a run here found signed out" },
|
|
26
28
|
{ name: "readiness-alert.json", what: "what you were told about this machine taking requests (signed out, no agent)" },
|
|
27
29
|
{ name: "worker-run.json", what: "the worker's record of a run in flight" },
|
|
28
30
|
{ name: "worker-run-guard.json", what: "Pantheon's own files as they were before the run in flight, put back if its worker goes mid-run" },
|
package/dist/mcp.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { loadClaudeToken } from "./agent-token.js";
|
|
1
2
|
import { agentLabelFor, clientState, ConnectionReport } from "./conn-report.js";
|
|
2
3
|
import { randomBytes } from "node:crypto";
|
|
3
4
|
import { existsSync, rmSync } from "node:fs";
|
|
@@ -124,7 +125,8 @@ export async function runMcp() {
|
|
|
124
125
|
}
|
|
125
126
|
catch {
|
|
126
127
|
return [];
|
|
127
|
-
} })()
|
|
128
|
+
} })(),
|
|
129
|
+
process.env.CLAUDE_CODE_OAUTH_TOKEN, process.env.ANTHROPIC_API_KEY, process.env.ANTHROPIC_AUTH_TOKEN, loadClaudeToken()?.token],
|
|
128
130
|
});
|
|
129
131
|
const branch = process.env.PANTHEON_BRANCH;
|
|
130
132
|
const client = new PantheonClient(cfg, undefined, { role });
|
|
@@ -327,7 +329,7 @@ export async function runMcp() {
|
|
|
327
329
|
? `open goals:\n${open.map((g) => ` ${g.id} ${g.state} ${g.acts}/${g.budget} acts "${g.title}"${goalTrustNote(g)} members: ${g.members.join(",")}${deadlineLabel(g.deadline)}${goalKindLabel(g)}`).join("\n")}`
|
|
328
330
|
: `open goals: none`,
|
|
329
331
|
mine.length
|
|
330
|
-
? `YOURS TO HANDLE (claim before working):\n${mine.map((o) => ` ${o.id} ${o.kind}${o.claimed_by ? " [yours]" : ""} (ref ${o.ref}) — ${o.body}`).join("\n")}`
|
|
332
|
+
? `YOURS TO HANDLE (claim before working):\n${mine.map((o) => ` ${o.id} ${o.kind}${o.claimed_by ? " [yours]" : ""} (ref ${o.ref}${o.goal ? `, goal ${o.goal}` : ""}) — ${o.body}`).join("\n")}\n (a line here is a summary: pantheon_history on its goal has the whole act, a closed goal's too)`
|
|
331
333
|
: `yours to handle: nothing`,
|
|
332
334
|
taken.length
|
|
333
335
|
? `taken by another of your sessions (leave these alone):\n${taken.map((o) => ` ${o.id} ${o.kind} — ${o.body}`).join("\n")}`
|
|
@@ -454,7 +456,7 @@ export async function runMcp() {
|
|
|
454
456
|
}
|
|
455
457
|
const work = client.myWork();
|
|
456
458
|
return text(fmtAll(acts) +
|
|
457
|
-
(work.length ? `\n\nYOURS TO HANDLE — pantheon_claim first:\n${work.map((o) => ` ${o.id} ${o.kind} — ${o.body}`).join("\n")}` : ""));
|
|
459
|
+
(work.length ? `\n\nYOURS TO HANDLE — pantheon_claim first:\n${work.map((o) => ` ${o.id} ${o.kind}${o.goal ? ` (goal ${o.goal})` : ""} — ${o.body}`).join("\n")}` : ""));
|
|
458
460
|
}));
|
|
459
461
|
const pickupLines = (to, ref) => {
|
|
460
462
|
const mayWake = client.members.find((m) => m.member === cfg.member)?.may_wake;
|
package/dist/relay.js
CHANGED
|
@@ -5291,6 +5291,14 @@ pantheon start</code></pre>
|
|
|
5291
5291
|
this.noteStorageFailure("evicting idle spaces", e);
|
|
5292
5292
|
}
|
|
5293
5293
|
}
|
|
5294
|
+
settlesOpenDecision(sp, act, ref) {
|
|
5295
|
+
if (act !== "ANSWER" || !ref)
|
|
5296
|
+
return false;
|
|
5297
|
+
const target = sp.ledger.find(ref);
|
|
5298
|
+
if (target?.act !== "ESCALATE" && target?.act !== "HUMAN_REQUIRED")
|
|
5299
|
+
return false;
|
|
5300
|
+
return [...sp.obligations.values()].some((o) => o.kind === "HUMAN" && o.ref === ref);
|
|
5301
|
+
}
|
|
5294
5302
|
claimHolds(sp, holder, now = Date.now()) {
|
|
5295
5303
|
const live = [...sp.members.values()].some((m) => m.sessions.has(holder.session));
|
|
5296
5304
|
return now - holder.at < (live ? LIMITS.claimLiveTtlMs : LIMITS.claimTtlMs);
|
|
@@ -5529,13 +5537,14 @@ pantheon start</code></pre>
|
|
|
5529
5537
|
return { code: "NOT_IN_GOAL", message: `${id} is not in "${goal.title}", so they could never answer it here — open a goal with them, or send it without a goal` };
|
|
5530
5538
|
}
|
|
5531
5539
|
}
|
|
5532
|
-
if (goal.state === "CLOSED")
|
|
5540
|
+
if (goal.state === "CLOSED" && !this.settlesOpenDecision(sp, act, ref))
|
|
5533
5541
|
return { code: "GOAL_CLOSED", message: `goal "${goal.title}" is closed` };
|
|
5534
5542
|
if (!goal.members.includes(me.id))
|
|
5535
5543
|
return { code: "NOT_IN_GOAL", message: `you are not a member of "${goal.title}"` };
|
|
5536
5544
|
const decision = act === "ANSWER" && ref ? sp.ledger.find(ref) : undefined;
|
|
5537
|
-
const
|
|
5545
|
+
const ownLive = !!decision && decision.goal === goalId
|
|
5538
5546
|
&& [...sp.obligations.values()].some((o) => o.kind === "HUMAN" && o.ref === ref && o.goal === goalId && o.owner === `human:${me.id}`);
|
|
5547
|
+
const settlesOwnHuman = ownLive && (role === "cli" || goal.state === "CLOSED");
|
|
5539
5548
|
if (goal.acts >= goal.budget && !settlesOwnHuman) {
|
|
5540
5549
|
return { code: "BUDGET_SPENT", message: `goal "${goal.title}" spent its ${goal.budget}-act budget and needs a human` };
|
|
5541
5550
|
}
|
|
@@ -6006,7 +6015,7 @@ pantheon start</code></pre>
|
|
|
6006
6015
|
}
|
|
6007
6016
|
for (const e of allow.all()) {
|
|
6008
6017
|
if (e.admitted && !sp.members.has(e.member)) {
|
|
6009
|
-
sp.members.set(e.member, { id: e.member, display: e.member, agent: e.last_agent ?? "unknown", last_seen: e.first_seen, sessions: new Map(), activity: new Map(), delivered_seq: 0, stamps: [] });
|
|
6018
|
+
sp.members.set(e.member, { id: e.member, display: e.member, agent: e.last_agent ?? "unknown", last_seen: e.last_seen ?? e.first_seen, sessions: new Map(), activity: new Map(), delivered_seq: 0, stamps: [] });
|
|
6010
6019
|
}
|
|
6011
6020
|
}
|
|
6012
6021
|
this.rebuildRecent(sp);
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { readFileSync, renameSync, statSync, writeFileSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { CONFIG_DIR } from "./config.js";
|
|
5
|
+
import { claudeTokenStamp } from "./agent-token.js";
|
|
6
|
+
import { trustWrite } from "./home-guard.js";
|
|
7
|
+
export const SIGNED_OUT_RE = /please run \/login|login expired|not logged in\b|invalid api key|oauth token (?:has )?expired|oauth token refresh failed|failed to authenticate|api error: 401\b|oauth access token is invalid|run `?(?:codex|cursor-agent) login`?/i;
|
|
8
|
+
export const SIGNED_OUT_RETRY_MS = 3_600_000;
|
|
9
|
+
export const SIGNED_OUT_MAX_RETRY_MS = 8 * 3_600_000;
|
|
10
|
+
const TAIL_LINES = 5;
|
|
11
|
+
export const SIGNED_OUT_AGENTS = ["claude-code", "codex", "cursor", "copilot"];
|
|
12
|
+
const FILE = "signed-out.json";
|
|
13
|
+
const mtime = (p) => { try {
|
|
14
|
+
return String(statSync(p).mtimeMs);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return "-";
|
|
18
|
+
} };
|
|
19
|
+
export function signInSignature(agent, o = {}) {
|
|
20
|
+
const h = o.userHome ?? homedir();
|
|
21
|
+
if (agent === "claude-code")
|
|
22
|
+
return [mtime(join(h, ".claude", ".credentials.json")), mtime(join(h, ".claude.json")), claudeTokenStamp(o.pantheonHome ?? CONFIG_DIR)].join("|");
|
|
23
|
+
if (agent === "codex")
|
|
24
|
+
return mtime(join(h, ".codex", "auth.json"));
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
const file = (home) => join(home, FILE);
|
|
28
|
+
function read(home) {
|
|
29
|
+
try {
|
|
30
|
+
const j = JSON.parse(readFileSync(file(home), "utf8"));
|
|
31
|
+
return j && typeof j === "object" ? j : {};
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function write(home, m) {
|
|
38
|
+
try {
|
|
39
|
+
mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
40
|
+
const tmp = `${file(home)}.${process.pid}.tmp`;
|
|
41
|
+
writeFileSync(tmp, JSON.stringify(m, null, 2) + "\n", { mode: 0o600 });
|
|
42
|
+
renameSync(tmp, file(home));
|
|
43
|
+
trustWrite(file(home));
|
|
44
|
+
}
|
|
45
|
+
catch { }
|
|
46
|
+
}
|
|
47
|
+
export const retryAfter = (m) => Math.min(SIGNED_OUT_RETRY_MS * 2 ** Math.max(0, m.tries ?? 0), SIGNED_OUT_MAX_RETRY_MS);
|
|
48
|
+
export function markSignedOut(agent, output, o = {}) {
|
|
49
|
+
const tail = output.split("\n").map((l) => l.trim()).filter(Boolean).slice(-TAIL_LINES);
|
|
50
|
+
const line = tail.find((l) => SIGNED_OUT_RE.test(l));
|
|
51
|
+
if (!line)
|
|
52
|
+
return false;
|
|
53
|
+
const home = o.pantheonHome ?? CONFIG_DIR;
|
|
54
|
+
const m = read(home);
|
|
55
|
+
const sig = signInSignature(agent, o);
|
|
56
|
+
const prev = m[agent];
|
|
57
|
+
const tries = prev && prev.sig === sig ? (prev.tries ?? 0) + 1 : 0;
|
|
58
|
+
m[agent] = { at: o.now ?? Date.now(), sig, says: line.slice(0, 160), ...(tries ? { tries } : {}) };
|
|
59
|
+
write(home, m);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
export function signedOutNow(agent, o = {}) {
|
|
63
|
+
const home = o.pantheonHome ?? CONFIG_DIR;
|
|
64
|
+
const m = read(home);
|
|
65
|
+
const mark = m[agent];
|
|
66
|
+
if (!mark || typeof mark.at !== "number" || mark.at === 0)
|
|
67
|
+
return null;
|
|
68
|
+
const now = o.now ?? Date.now();
|
|
69
|
+
const changed = signInSignature(agent, o) !== mark.sig;
|
|
70
|
+
const due = now - mark.at >= retryAfter(mark) || now < mark.at;
|
|
71
|
+
if (!changed && !due)
|
|
72
|
+
return mark;
|
|
73
|
+
if (o.lift) {
|
|
74
|
+
if (changed)
|
|
75
|
+
delete m[agent];
|
|
76
|
+
else
|
|
77
|
+
m[agent] = { ...mark, at: 0 };
|
|
78
|
+
write(home, m);
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
export function clearSignedOut(agent, o = {}) {
|
|
83
|
+
const home = o.pantheonHome ?? CONFIG_DIR;
|
|
84
|
+
const m = read(home);
|
|
85
|
+
if (!(agent in m))
|
|
86
|
+
return;
|
|
87
|
+
delete m[agent];
|
|
88
|
+
write(home, m);
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=signed-out.js.map
|
package/dist/worker.js
CHANGED
|
@@ -16,7 +16,7 @@ import { corruptHeldFiles, MAX_HELD_PER_RUN, remoteTipIs, takeHeldFrames, update
|
|
|
16
16
|
import { adoptedCommon, adoptWorktree, gitCallEnv, lfsInUse, repoHooksArgs, safeGitArgs, WorktreeTampered } from "./git-safe.js";
|
|
17
17
|
import { trusted } from "./verify-act.js";
|
|
18
18
|
import { 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";
|
|
19
|
-
import { activeOutages, detectOutage, earliest, whenAgain } from "./agent-outage.js";
|
|
19
|
+
import { activeOutages, detectOutage, earliest, whenAgain, SIGNIN_REFUSED } from "./agent-outage.js";
|
|
20
20
|
import { agentSpawn, CmdLineUnsafe } from "./which.js";
|
|
21
21
|
import { VERSION } from "./version.js";
|
|
22
22
|
import { applyAnswer, 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, } from "./worker-policy.js";
|
|
@@ -32,7 +32,9 @@ import { handledIn, loadContinued, markContinued, unmarkContinued, wakeAlertedKe
|
|
|
32
32
|
import { decisionAlertsOn, loadProfile, profileForTeam, reservedDecisionsNote, saveProfile, wakeMode } from "./profile.js";
|
|
33
33
|
import { clip } from "./brief.js";
|
|
34
34
|
import { composeWakeAsk, composeWorker } from "./notice.js";
|
|
35
|
-
import { diagnoseRun, gitProbe, workNeedsCommands } from "./run-failure.js";
|
|
35
|
+
import { diagnoseRun, gitProbe, workNeedsCommands, SIGN_IN_FIX } from "./run-failure.js";
|
|
36
|
+
import { clearSignedOut, markSignedOut, retryAfter, signedOutNow, SIGNED_OUT_AGENTS } from "./signed-out.js";
|
|
37
|
+
import { claudeTokenForRun } from "./agent-token.js";
|
|
36
38
|
import { installedTools, preferredTool } from "./notifier.js";
|
|
37
39
|
import { obligationSignature, StatusNudger } from "./status-nudge.js";
|
|
38
40
|
import { clientState, ConnectionReport } from "./conn-report.js";
|
|
@@ -1401,6 +1403,7 @@ export class Worker {
|
|
|
1401
1403
|
return hit.d;
|
|
1402
1404
|
let d = null;
|
|
1403
1405
|
try {
|
|
1406
|
+
this.syncSignedOut();
|
|
1404
1407
|
const c = (this.opts.choose ?? chooseAgent)(agent, { prefer: loadProfile(this.cfg).agent.primary_surface, unsandboxedOk: ok, outages: activeOutages(this.outages) });
|
|
1405
1408
|
if (c.outage)
|
|
1406
1409
|
d = this.outageDiagnosis(c.backend.label, c.outage, []);
|
|
@@ -1441,7 +1444,7 @@ export class Worker {
|
|
|
1441
1444
|
readinessAt = 0;
|
|
1442
1445
|
checkReadiness(force) {
|
|
1443
1446
|
const now = Date.now();
|
|
1444
|
-
const every = (this.readiness && !this.readiness.ok) || this.alertPending ? WORKER_READINESS_RETRY_MS : WORKER_READINESS_MS;
|
|
1447
|
+
const every = (this.readiness && !this.readiness.ok && !this.readiness.signedOut) || this.alertPending ? WORKER_READINESS_RETRY_MS : WORKER_READINESS_MS;
|
|
1445
1448
|
let marked = false;
|
|
1446
1449
|
try {
|
|
1447
1450
|
const t = statSync(readinessRecheckPath(this.opts.home)).mtimeMs;
|
|
@@ -1479,6 +1482,14 @@ export class Worker {
|
|
|
1479
1482
|
if (r.ok && this.readiness && !this.readiness.ok)
|
|
1480
1483
|
this.opts.log(` agent ready again — teammates are told this machine takes requests`);
|
|
1481
1484
|
this.readiness = { ok: r.ok, short: r.short, ...(r.code ? { code: r.code } : {}), ...(r.pinned ? { pinned: true } : {}), ...(r.agent ? { agent: r.agent } : {}), ...(r.fix ? { fix: r.fix } : {}), ...(r.unknown ? { unknown: true } : {}) };
|
|
1485
|
+
this.syncSignedOut();
|
|
1486
|
+
if (r.ok && this.signedOutHere.size && !this.opts.readinessCheck) {
|
|
1487
|
+
const held = this.heldForSandbox();
|
|
1488
|
+
if (held?.cause === "agent_unavailable") {
|
|
1489
|
+
this.readiness = { ok: false, short: "its agent CLI was signed out (a run here was refused)", code: "not_signed_in", fix: held.fix ?? "", signedOut: true };
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1482
1493
|
this.tellPerson(now);
|
|
1483
1494
|
}
|
|
1484
1495
|
catch {
|
|
@@ -1576,6 +1587,42 @@ export class Worker {
|
|
|
1576
1587
|
},
|
|
1577
1588
|
};
|
|
1578
1589
|
}
|
|
1590
|
+
signedOutHere = new Set();
|
|
1591
|
+
syncSignedOut() {
|
|
1592
|
+
if (this.opts.agentCmd)
|
|
1593
|
+
return;
|
|
1594
|
+
for (const id of SIGNED_OUT_AGENTS) {
|
|
1595
|
+
const mark = signedOutNow(id, { pantheonHome: this.stateDir(), lift: true });
|
|
1596
|
+
if (mark) {
|
|
1597
|
+
const until = mark.at + retryAfter(mark);
|
|
1598
|
+
const cur = this.outages.get(id);
|
|
1599
|
+
if (!cur || cur.until < until)
|
|
1600
|
+
this.outages.set(id, { why: this.signedOutWhy(id, mark.says), until });
|
|
1601
|
+
this.signedOutHere.add(id);
|
|
1602
|
+
}
|
|
1603
|
+
else if (this.signedOutHere.has(id)) {
|
|
1604
|
+
this.signedOutHere.delete(id);
|
|
1605
|
+
const was = this.outages.get(id)?.until;
|
|
1606
|
+
this.outages.delete(id);
|
|
1607
|
+
if (was !== undefined) {
|
|
1608
|
+
for (const [k, t] of this.outageHold)
|
|
1609
|
+
if (t <= was + 120_000)
|
|
1610
|
+
this.outageHold.delete(k);
|
|
1611
|
+
for (const [k, t] of this.outageHeldUntil)
|
|
1612
|
+
if (t <= was + 120_000)
|
|
1613
|
+
this.outageHeldUntil.delete(k);
|
|
1614
|
+
}
|
|
1615
|
+
this.opts.log(` agent ${agentById(id)?.label ?? id} is signed in again — teammates' requests are taken again`);
|
|
1616
|
+
this.readinessAt = 0;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
signedOutWhy(id, says) {
|
|
1621
|
+
if (id === "claude-code" && claudeTokenForRun(this.stateDir()))
|
|
1622
|
+
return `refused the token saved for this worker ("${says}") — make a new one (claude setup-token, then pantheon worker token), or remove it to use your own sign-in: pantheon worker token --remove`;
|
|
1623
|
+
const how = SIGN_IN_FIX[id] ?? "sign in to it again on this machine";
|
|
1624
|
+
return `is signed out on this machine ("${says}") — ${how}${id === "claude-code" ? ", or keep it signed in for a year: claude setup-token, then pantheon worker token" : ""}`;
|
|
1625
|
+
}
|
|
1579
1626
|
outagesPassed(c) {
|
|
1580
1627
|
const now = activeOutages(this.outages);
|
|
1581
1628
|
return c.skipped.flatMap((x) => { const out = now[x.backend.id]; return out ? [{ label: x.backend.label, out }] : []; });
|
|
@@ -2460,6 +2507,7 @@ export class Worker {
|
|
|
2460
2507
|
await this.tellWakeNo(client);
|
|
2461
2508
|
await this.tellStops(client);
|
|
2462
2509
|
this.sayKeyChanges(client);
|
|
2510
|
+
this.syncSignedOut();
|
|
2463
2511
|
const aged = client
|
|
2464
2512
|
.myWork()
|
|
2465
2513
|
.filter((o) => o.kind !== "HUMAN" && o.kind !== "DELIVER" && !o.claimed_by)
|
|
@@ -3179,6 +3227,7 @@ export class Worker {
|
|
|
3179
3227
|
let choice;
|
|
3180
3228
|
if (!this.opts.agentCmd) {
|
|
3181
3229
|
try {
|
|
3230
|
+
this.syncSignedOut();
|
|
3182
3231
|
choice = (this.opts.choose ?? chooseAgent)(policy.agent ?? this.opts.agent, { prefer: loadProfile(this.cfg).agent.primary_surface, unsandboxedOk: this.unsandboxedOk(), outages: activeOutages(this.outages) });
|
|
3183
3232
|
}
|
|
3184
3233
|
catch (e) {
|
|
@@ -3410,8 +3459,10 @@ export class Worker {
|
|
|
3410
3459
|
if (features && allowBash && !ensureRunTmp(runTmpDir(runHome))) {
|
|
3411
3460
|
throw new Error(`the run's temp dir ${runTmpDir(runHome)} is not this user's own folder (another user's, or a link) — a command run is not started with it`);
|
|
3412
3461
|
}
|
|
3462
|
+
const claudeToken = backend.id === "claude-code" && !this.opts.agentCmd ? claudeTokenForRun(this.stateDir()) : null;
|
|
3413
3463
|
const plan = headlessSpawn({
|
|
3414
3464
|
backend, binary, prompt: brief, worktree, cfg: runCfg, branch, allowBash, runHome,
|
|
3465
|
+
...(claudeToken ? { claudeToken } : {}),
|
|
3415
3466
|
...(attached.length ? { readOnlyDirs: attached.map((a) => a.path) } : {}),
|
|
3416
3467
|
...(baseSha ? { base: baseSha } : {}), ...(tipSha ? { commandsRev: tipSha } : {}), goal,
|
|
3417
3468
|
...(features ? { claude: { features, pantheonHome: this.stateDir(), home: personHome, userSettings: join(personHome, ".claude", "settings.json"), ...(() => { const c = adoptedCommon(worktree); return c ? { gitCommon: c } : {}; })() } } : {}),
|
|
@@ -3687,6 +3738,10 @@ export class Worker {
|
|
|
3687
3738
|
const refusedLog = snap ? join(scratch, `${basename(worktree)}.${choice?.backend.id}-refused.run.log`) : join(worktree, `.pantheon-run.${choice?.backend.id}-refused.log`);
|
|
3688
3739
|
if (outage) {
|
|
3689
3740
|
this.outages.set(choice.backend.id, outage);
|
|
3741
|
+
if (outage.why === SIGNIN_REFUSED && !this.opts.agentCmd && markSignedOut(choice.backend.id, detail, { pantheonHome: this.stateDir() })) {
|
|
3742
|
+
this.syncSignedOut();
|
|
3743
|
+
this.readinessAt = 0;
|
|
3744
|
+
}
|
|
3690
3745
|
this.writeRunLog(logRoot, refusedLog, `obligation ${o.id}\nbranch ${branch}\nagent ${choice.backend.label}\n\n${detail}\n`);
|
|
3691
3746
|
if (Date.now() - startedAt < ONCE_GIVE_BACK_MS)
|
|
3692
3747
|
this.restoreOnces();
|
|
@@ -3703,6 +3758,14 @@ export class Worker {
|
|
|
3703
3758
|
...(/\(stopped after \d+s\)/.test(detail.split("\n")[0] ?? "") ? { timedOut: { minutes: runLimit.minutes, from: runLimit.from } } : {}),
|
|
3704
3759
|
...(bashDroppedForSandbox ? { commandsNeedSandbox: byCli ? "agent-cmd" : "claude" } : {}), ...(agentId ? { agent: agentId } : {}), ...(place.kind === "folder" ? { folder: true } : {}),
|
|
3705
3760
|
...(agentId === "claude-code" && allowBash ? { allowedRules: bashRules } : {}), ...(baseRef ? { baseRef } : {}) }, this.opts.probe ?? gitProbe);
|
|
3761
|
+
if (ok && agentId && !this.opts.agentCmd)
|
|
3762
|
+
clearSignedOut(agentId, { pantheonHome: this.stateDir() });
|
|
3763
|
+
if (!ok && diagnosis?.cause === "not_signed_in" && agentId && !this.opts.agentCmd
|
|
3764
|
+
&& markSignedOut(agentId, detail, { pantheonHome: this.stateDir() })) {
|
|
3765
|
+
this.opts.log(`! ${choice?.backend.label ?? agentId} is signed out on this machine: requests wait until it is signed in again${agentId === "claude-code" ? " (pantheon worker token keeps Claude Code signed in for a year)" : ""}`);
|
|
3766
|
+
this.syncSignedOut();
|
|
3767
|
+
this.readinessAt = 0;
|
|
3768
|
+
}
|
|
3706
3769
|
if (this.opts.notify && !quiet && (!ok || loadProfile(this.cfg).notifications?.worker_done)) {
|
|
3707
3770
|
try {
|
|
3708
3771
|
const reply = sent[sent.length - 1] ?? null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@join-pantheon/cli",
|
|
3
|
-
"version": "0.34.
|
|
3
|
+
"version": "0.34.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": {
|