@join-pantheon/cli 0.35.0 → 0.35.1-rc.2
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 +165 -35
- package/dist/agent-token.js +5 -3
- package/dist/agents.js +6 -4
- package/dist/approvals-list.js +87 -0
- package/dist/board.js +491 -88
- package/dist/brief.js +17 -0
- package/dist/cli.js +687 -95
- package/dist/client.js +159 -19
- package/dist/config.js +3 -2
- package/dist/continued.js +56 -1
- package/dist/decision-ui.js +5 -3
- package/dist/doctor.js +84 -16
- package/dist/file-lock.js +40 -5
- package/dist/flow-stats.js +18 -1
- package/dist/home-guard.js +336 -54
- package/dist/home-safety.js +2 -0
- package/dist/hud-queue.js +91 -0
- package/dist/install.js +15 -1
- package/dist/mcp-instructions.js +67 -28
- package/dist/mcp.js +129 -24
- package/dist/notice-linux.js +15 -4
- package/dist/notice-windows.js +2 -2
- package/dist/notifier.js +2 -1
- package/dist/notify.js +28 -9
- package/dist/open-in.js +4 -3
- package/dist/pickup.js +17 -0
- package/dist/plain.js +139 -3
- package/dist/profile.js +12 -8
- package/dist/protocol.js +1 -1
- package/dist/question-goal.js +74 -0
- package/dist/readiness-alert.js +24 -3
- package/dist/refusal.js +2 -2
- package/dist/relay.js +143 -28
- package/dist/removed.js +4 -4
- package/dist/run-control.js +4 -3
- package/dist/run-failure.js +67 -10
- package/dist/setup-changes.js +7 -6
- package/dist/signed-out.js +144 -21
- package/dist/spend.js +5 -4
- package/dist/tray.js +24 -6
- package/dist/update-check.js +2 -1
- package/dist/uri-handler.js +10 -2
- package/dist/which.js +2 -0
- package/dist/worker-policy.js +212 -10
- package/dist/worker.js +942 -133
- package/dist/worklist.js +31 -1
- package/helper/macos/main.swift +42 -3
- package/helper/macos/menubar.swift +482 -87
- package/helper/macos/prebuilt/manifest.json +5 -5
- package/helper/macos/prebuilt/pantheon-hud +0 -0
- package/helper/macos/prebuilt/pantheon-tray +0 -0
- package/package.json +1 -1
package/dist/agent-outage.js
CHANGED
|
@@ -1,35 +1,167 @@
|
|
|
1
1
|
const MIN = 60_000, HOUR = 60 * MIN;
|
|
2
2
|
export const MAX_TEXT_WAIT_MS = 6 * HOUR;
|
|
3
|
+
export const MAX_DATED_WAIT_MS = 7 * 24 * HOUR;
|
|
3
4
|
const TAIL_LINES = 5;
|
|
5
|
+
const TRAILER_LINES = 8;
|
|
6
|
+
export const isSet = (v) => !!v && v.trim() !== "";
|
|
4
7
|
const PLAN = "its organization has disabled subscription access for it";
|
|
5
8
|
const LIMIT = "its usage limit is reached";
|
|
6
9
|
const SIGNIN = "its sign-in was refused";
|
|
7
10
|
export const SIGNIN_REFUSED = SIGNIN;
|
|
8
11
|
const OVERLOAD = "its service is overloaded";
|
|
12
|
+
const COPILOT_VAR = "(COPILOT_GITHUB_TOKEN|GH_TOKEN|GITHUB_TOKEN)";
|
|
13
|
+
const copilotVar = (env) => ["COPILOT_GITHUB_TOKEN", "GH_TOKEN", "GITHUB_TOKEN"].find((k) => isSet(env[k]) && !(k === "GITHUB_TOKEN" && env["CODESPACES"] === "true"));
|
|
14
|
+
function claudeCred(line, env, st) {
|
|
15
|
+
const from = (k) => (st.env.includes(k) ? { env: k, settings: true } : isSet(env[k]) ? { env: k } : undefined);
|
|
16
|
+
if (/^Your apiKeyHelper script is failing/.test(line))
|
|
17
|
+
return { helper: true, settings: true };
|
|
18
|
+
if (/Fix external API key$/.test(line))
|
|
19
|
+
return from("ANTHROPIC_API_KEY") ?? (st.apiKeyHelper ? { helper: true, settings: true } : { settings: true });
|
|
20
|
+
return from("ANTHROPIC_AUTH_TOKEN") ?? from("CLAUDE_CODE_OAUTH_TOKEN");
|
|
21
|
+
}
|
|
22
|
+
const CODEX_LOG = String.raw `\d{4}-\d\d-\d\dT[\d:.]+Z ERROR codex_[a-z_]+::[a-z_:]+: `;
|
|
23
|
+
const CODEX_LIMIT = [
|
|
24
|
+
String.raw `You(?:'|’)ve hit your usage limit\. Try again (?:at .+|later\.)`,
|
|
25
|
+
String.raw `You(?:'|’)ve hit your usage limit(?: for .+?\. Switch to another model now,|\. Upgrade to Plus to continue using Codex \(https:\/\/chatgpt\.com\/explore\/plus\),|\. Visit https:\/\/chatgpt\.com\/settings\/usage to purchase more credits|\. To get more access now, send a request to your admin) or try again (?:at .+|later\.)`,
|
|
26
|
+
String.raw `unexpected status 429 Too Many Requests: .*insufficient_quota.*, url: https:\/\/api\.openai\.com\/\S*.*`,
|
|
27
|
+
].join("|");
|
|
28
|
+
const CODEX_REFRESH = String.raw `Your access token could not be refreshed(?: because your refresh token (?:has expired|was already used|was revoked))?\. Please log out and sign in again\.|Your access token could not be refreshed because you have since logged out or signed in to another account\. Please sign in again\.`;
|
|
29
|
+
const COPILOT_HELP = [
|
|
30
|
+
/^Copilot can be authenticated with GitHub using an OAuth Token or a Fine-Grained Personal Access Token\.$/,
|
|
31
|
+
/^To authenticate, you can use any of the following methods:$/,
|
|
32
|
+
/^• Start 'copilot' and run the '\/login' command$/,
|
|
33
|
+
/^• Set the COPILOT_GITHUB_TOKEN, GH_TOKEN, or GITHUB_TOKEN environment variable$/,
|
|
34
|
+
/^• Run 'gh auth login' to authenticate with the GitHub CLI$/,
|
|
35
|
+
];
|
|
9
36
|
const KINDS = {
|
|
10
37
|
"claude-code": [
|
|
11
|
-
{ re:
|
|
12
|
-
{ re:
|
|
13
|
-
{ re:
|
|
14
|
-
|
|
38
|
+
{ re: /^Your organization has disabled Claude subscription access for Claude Code\b/, why: PLAN, wait: 6 * HOUR },
|
|
39
|
+
{ re: /^(?:Claude AI usage limit reached\|\d{10}|(?:5-hour|Weekly|Opus|Session) limit reached [·∙] resets \S.*|You(?:'|’)ve hit your (?:usage )?limit [·∙] resets \S.*|You(?:'|’)re out of extra usage [·∙] resets \S.*|Credit balance is too low)$/, why: LIMIT, wait: HOUR },
|
|
40
|
+
{ re: /^(?:(?:Invalid API key|Not logged in|Login expired|OAuth token (?:has expired|revoked)) [·∙] Please run \/login|Invalid API key [·∙] Fix external API key|Failed to authenticate\. API Error: 401 (?:OAuth access token is invalid\.|\{"type":"error","error":\{"type":"authentication_error".*\})(?: [·∙] Please run \/login)?|API Error: 401 \{"type":"error","error":\{"type":"authentication_error".*\} [·∙] Please run \/login)$/, why: SIGNIN, wait: HOUR,
|
|
41
|
+
claude: claudeCred },
|
|
42
|
+
{ re: /^Your apiKeyHelper script is failing [·∙] This usually means you need to re-authenticate with your provider [·∙] Run \/status to see the script's error output$/, why: SIGNIN, wait: HOUR,
|
|
43
|
+
trailer: [/^apiKeyHelper failed: .+$/], claude: claudeCred },
|
|
44
|
+
{ re: /^API Error: 529 \{"type":"error","error":\{"type":"overloaded_error"/, why: OVERLOAD, wait: 15 * MIN },
|
|
15
45
|
],
|
|
16
46
|
codex: [
|
|
17
|
-
{ re:
|
|
47
|
+
{ re: new RegExp(`^ERROR: (?:${CODEX_LIMIT})$`), why: LIMIT, wait: HOUR },
|
|
48
|
+
{ re: /^ERROR: unexpected status 401 Unauthorized: .+, url: https:\/\/(?:api\.openai\.com|chatgpt\.com)\/\S*(?:, .*)?$/, why: SIGNIN, wait: HOUR,
|
|
49
|
+
env: (line, _a, env) => (/Incorrect API key provided/.test(line) && env["CODEX_API_KEY"] ? "CODEX_API_KEY" : undefined) },
|
|
50
|
+
{ re: /^ERROR: workspace routing discovery unauthorized \(401\)$/, why: SIGNIN, wait: HOUR,
|
|
51
|
+
trailer: [new RegExp(`^${CODEX_LOG}Failed to refresh token: (?:${CODEX_REFRESH})$`)] },
|
|
52
|
+
{ re: new RegExp(`^(?:${CODEX_LOG}Failed to refresh token: |ERROR: )(?:${CODEX_REFRESH})$`), why: SIGNIN, wait: HOUR },
|
|
18
53
|
],
|
|
19
54
|
cursor: [
|
|
20
|
-
{ re:
|
|
55
|
+
{ re: /^(?:Error: Authentication required\. Please run '(?:cursor-agent|agent) login' first, or set CURSOR_API_KEY environment variable\.|Authentication required to use Cursor Agent\. Please run '(?:cursor-agent|agent) login' to authenticate\.|Error: Authentication required\. Run '(?:cursor-agent|agent) login', pass --api-key\/--auth-token, or set CURSOR_API_KEY\/CURSOR_AUTH_TOKEN\.)$/, why: SIGNIN, wait: HOUR },
|
|
21
56
|
],
|
|
22
57
|
copilot: [
|
|
23
|
-
{ re:
|
|
58
|
+
{ re: /^Error: No authentication information found\.$/, why: SIGNIN, wait: HOUR, trailer: COPILOT_HELP },
|
|
59
|
+
{ re: /^Error: Authentication token found but could not be validated\.$/, why: SIGNIN, wait: HOUR,
|
|
60
|
+
trailer: [/^Failed to fetch PAT user login \(401\): GitHub returned: Bad credentials$/, /^Failed to fetch GitHub CLI user login \(401\): GitHub returned: Bad credentials$/,
|
|
61
|
+
/^Your token may still be valid\. Check your network connection and try again\.$/, ...COPILOT_HELP],
|
|
62
|
+
needs: /^Failed to fetch (?:PAT|GitHub CLI) user login \(401\)/, env: (_l, _a, env) => copilotVar(env) },
|
|
63
|
+
{ re: /^Error: Classic Personal Access Tokens \(ghp_\) are not supported by Copilot\.$/, why: SIGNIN, wait: HOUR,
|
|
64
|
+
trailer: [new RegExp(`^The ${COPILOT_VAR} environment variable contains a classic PAT\\.$`), /^Please use a Fine-Grained Personal Access Token or another authentication method\.$/, /^To fix this, you can:$/,
|
|
65
|
+
new RegExp(`^• Replace the token in ${COPILOT_VAR} with a fine-grained PAT$`), new RegExp(`^• Unset ${COPILOT_VAR} and run 'gh auth login' to authenticate$`), new RegExp(`^• Unset ${COPILOT_VAR} and start 'copilot', then use the '/login' command$`)],
|
|
66
|
+
env: (_l, after, env) => after.map((l) => new RegExp(`^The ${COPILOT_VAR} environment variable`).exec(l)?.[1]).find(Boolean) ?? copilotVar(env) ?? "GH_TOKEN" },
|
|
24
67
|
],
|
|
25
68
|
kiro: [],
|
|
26
69
|
};
|
|
70
|
+
const ALERT_ONLY = {
|
|
71
|
+
kiro: /^error: You are not logged in, please log in with kiro-cli login$/,
|
|
72
|
+
};
|
|
73
|
+
const TEST_WORDS = /\b(?:expect(?:ed|s)?|assert(?:ion)?(?:Error)?|snapshot|fixture|toEqual|toBe|toMatch|received|mock(?:ed)?)\b/i;
|
|
74
|
+
function stoppedFromOutside(tail) {
|
|
75
|
+
const first = tail.split("\n", 1)[0] ?? "";
|
|
76
|
+
return /^exit\s+(?!-?\d+\b)\S/.test(first) || /\(stopped after \d+s\)/.test(first);
|
|
77
|
+
}
|
|
78
|
+
export function refusalOf(agent, tail, only, env, claudeSettings) {
|
|
79
|
+
if (stoppedFromOutside(tail))
|
|
80
|
+
return null;
|
|
81
|
+
const lines = tail.split("\n").map((l) => l.trim()).filter(Boolean).flatMap(ownError);
|
|
82
|
+
for (const k of KINDS[agent] ?? []) {
|
|
83
|
+
if (only && k.why !== only)
|
|
84
|
+
continue;
|
|
85
|
+
const from = Math.max(0, lines.length - TAIL_LINES - (k.trailer ? TRAILER_LINES : 0));
|
|
86
|
+
for (let i = lines.length - 1; i >= from; i--) {
|
|
87
|
+
const line = lines[i];
|
|
88
|
+
if (!k.re.test(line) || TEST_WORDS.test(line))
|
|
89
|
+
continue;
|
|
90
|
+
const after = lines.slice(i + 1);
|
|
91
|
+
if (!after.every((l) => k.trailer?.some((t) => t.test(l)) ?? false))
|
|
92
|
+
continue;
|
|
93
|
+
if (k.needs && !after.some((l) => k.needs.test(l)))
|
|
94
|
+
continue;
|
|
95
|
+
if (k.claude) {
|
|
96
|
+
const c = env !== undefined ? k.claude(line, env, claudeSettings ?? { env: [], apiKeyHelper: false }) : (/^Your apiKeyHelper/.test(line) ? { helper: true, settings: true } : undefined);
|
|
97
|
+
return { why: k.why, wait: k.wait, line, ...(c?.env ? { env: c.env } : {}), ...(c?.settings ? { settings: true } : {}), ...(c?.helper ? { helper: true } : {}) };
|
|
98
|
+
}
|
|
99
|
+
const via = k.env?.(line, after, env ?? {});
|
|
100
|
+
return { why: k.why, wait: k.wait, line, ...(via ? { env: via } : {}) };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
function ownError(line) {
|
|
106
|
+
if (!line.startsWith("{") || !line.endsWith("}"))
|
|
107
|
+
return [line];
|
|
108
|
+
try {
|
|
109
|
+
const j = JSON.parse(line);
|
|
110
|
+
if (j && j.type === "result" && j.is_error === true && typeof j.result === "string") {
|
|
111
|
+
const said = j.result.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
112
|
+
return said.length ? said : [line];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch { }
|
|
116
|
+
return [line];
|
|
117
|
+
}
|
|
118
|
+
export function signInRefused(agent, tail, env, claudeSettings) {
|
|
119
|
+
if (!agent)
|
|
120
|
+
return null;
|
|
121
|
+
const own = refusalOf(agent, tail, SIGNIN, env, claudeSettings);
|
|
122
|
+
if (own)
|
|
123
|
+
return own;
|
|
124
|
+
const re = ALERT_ONLY[agent];
|
|
125
|
+
if (!re || stoppedFromOutside(tail))
|
|
126
|
+
return null;
|
|
127
|
+
const last = tail.split("\n").map((l) => l.trim()).filter(Boolean).at(-1) ?? "";
|
|
128
|
+
return re.test(last) ? { why: SIGNIN, wait: HOUR, line: last } : null;
|
|
129
|
+
}
|
|
130
|
+
export function signInRefusal(agent, tail) {
|
|
131
|
+
return signInRefused(agent, tail)?.line ?? null;
|
|
132
|
+
}
|
|
133
|
+
const MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
|
134
|
+
function clock(h, m, ap) {
|
|
135
|
+
let hh = Number(h);
|
|
136
|
+
const mm = m ? Number(m) : 0;
|
|
137
|
+
const a = ap?.toLowerCase();
|
|
138
|
+
if (a === "pm" && hh < 12)
|
|
139
|
+
hh += 12;
|
|
140
|
+
if (a === "am" && hh === 12)
|
|
141
|
+
hh = 0;
|
|
142
|
+
return hh > 23 || mm > 59 ? null : [hh, mm];
|
|
143
|
+
}
|
|
27
144
|
function namedTime(line, now) {
|
|
28
|
-
const rel = /try again in\s+(\d{1,3})\s*(minute|min|hour|hr|day)s?\b/i.exec(line);
|
|
145
|
+
const rel = /(?:try again|resets?) in\s+(\d{1,3})\s*(minute|min|hour|hr|day)s?\b/i.exec(line);
|
|
29
146
|
if (rel) {
|
|
30
147
|
const n = Number(rel[1]);
|
|
31
148
|
const u = rel[2].toLowerCase();
|
|
32
|
-
return now + n * (u.startsWith("d") ? 24 * HOUR : u.startsWith("h") ? HOUR : MIN);
|
|
149
|
+
return { t: now + n * (u.startsWith("d") ? 24 * HOUR : u.startsWith("h") ? HOUR : MIN), dated: false };
|
|
150
|
+
}
|
|
151
|
+
const dated = /(?:resets?|reset at|try again (?:at|after))\s+(?:at\s+)?(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]*\.?\s+(\d{1,2})(?:st|nd|rd|th)?,?\s+(?:(\d{4}),?\s+)?(\d{1,2})(?::(\d{2}))?\s*(am|pm)\b/i.exec(line);
|
|
152
|
+
if (dated) {
|
|
153
|
+
const month = MONTHS.indexOf(dated[1].slice(0, 3).toLowerCase());
|
|
154
|
+
const day = Number(dated[2]);
|
|
155
|
+
const hm = clock(dated[4], dated[5], dated[6]);
|
|
156
|
+
if (month < 0 || day < 1 || day > 31 || !hm)
|
|
157
|
+
return null;
|
|
158
|
+
const year = dated[3] ? Number(dated[3]) : new Date(now).getFullYear();
|
|
159
|
+
let t = new Date(year, month, day, hm[0], hm[1], 0, 0).getTime();
|
|
160
|
+
if (new Date(t).getDate() !== day)
|
|
161
|
+
return null;
|
|
162
|
+
if (!dated[3] && t <= now)
|
|
163
|
+
t = new Date(year + 1, month, day, hm[0], hm[1], 0, 0).getTime();
|
|
164
|
+
return { t, dated: true };
|
|
33
165
|
}
|
|
34
166
|
const m = /(?:resets?|reset at|try again (?:at|after))\s+(?:at\s+)?(\d{1,2})(?::(\d{2}))?\s*(am|pm)?/i.exec(line);
|
|
35
167
|
if (!m)
|
|
@@ -48,39 +180,37 @@ function namedTime(line, now) {
|
|
|
48
180
|
let t = d.getTime();
|
|
49
181
|
if (t <= now)
|
|
50
182
|
t += 24 * HOUR;
|
|
51
|
-
return t;
|
|
52
|
-
}
|
|
53
|
-
export function ownWords(line, re, opts = {}) {
|
|
54
|
-
const m = new RegExp(re.source, re.flags.replace("g", "")).exec(line);
|
|
55
|
-
if (!m)
|
|
56
|
-
return false;
|
|
57
|
-
if (/\b(?:expect(?:ed|s)?|assert(?:ion)?(?:Error)?|snapshot|fixture|toEqual|toBe|toMatch|received|mock(?:ed)?)\b/i.test(line))
|
|
58
|
-
return false;
|
|
59
|
-
if (opts.quotes === false)
|
|
60
|
-
return true;
|
|
61
|
-
const before = line.slice(0, m.index);
|
|
62
|
-
const count = (c) => before.split(c).length - 1;
|
|
63
|
-
if (count('"') % 2 === 1 || count("`") % 2 === 1 || count("“") > count("”"))
|
|
64
|
-
return false;
|
|
65
|
-
return true;
|
|
183
|
+
return { t, dated: false };
|
|
66
184
|
}
|
|
67
185
|
export function detectOutage(agent, tail, now = Date.now()) {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
186
|
+
const r = refusalOf(agent, tail);
|
|
187
|
+
if (!r)
|
|
188
|
+
return null;
|
|
189
|
+
const epoch = agent === "claude-code" ? /Claude AI usage limit reached\|(\d{10})\b/i.exec(r.line) : null;
|
|
190
|
+
const named = epoch ? { t: Number(epoch[1]) * 1000, dated: false } : namedTime(r.line, now);
|
|
191
|
+
const until = !named || named.t <= now ? now + r.wait
|
|
192
|
+
: named.dated ? (named.t - now <= MAX_DATED_WAIT_MS ? named.t : now + r.wait)
|
|
193
|
+
: Math.min(named.t, now + MAX_TEXT_WAIT_MS);
|
|
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;
|
|
77
204
|
}
|
|
78
|
-
return null;
|
|
79
205
|
}
|
|
80
206
|
export function whenAgain(until, now = Date.now()) {
|
|
81
207
|
const d = new Date(until);
|
|
82
208
|
const hm = `${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}`;
|
|
83
|
-
|
|
209
|
+
if (new Date(now).toDateString() === d.toDateString())
|
|
210
|
+
return hm;
|
|
211
|
+
if (until - now >= 6 * 24 * HOUR)
|
|
212
|
+
return `${d.toLocaleDateString("en-GB", { day: "numeric", month: "short" })} ${hm}`;
|
|
213
|
+
return `${d.toLocaleDateString("en-GB", { weekday: "short" })} ${hm}`;
|
|
84
214
|
}
|
|
85
215
|
export function activeOutages(all, now = Date.now()) {
|
|
86
216
|
const out = {};
|
package/dist/agent-token.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import {
|
|
2
|
+
import { renameSync, rmSync, writeFileSync, mkdirSync, chmodSync, mkdtempSync } from "node:fs";
|
|
3
3
|
import { spawnSync } from "node:child_process";
|
|
4
4
|
import { agentSpawn } from "./which.js";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { CONFIG_DIR } from "./config.js";
|
|
8
|
+
import { readStateText } from "./file-lock.js";
|
|
8
9
|
export const AGENT_TOKEN_FILE = "agent-tokens.json";
|
|
9
10
|
export const CLAUDE_TOKEN_RE = /^sk-ant-oat01-[A-Za-z0-9_-]{20,400}$/;
|
|
10
11
|
export const CLAUDE_TOKEN_LIFE_MS = 365 * 86_400_000;
|
|
@@ -12,7 +13,7 @@ export const CLAUDE_TOKEN_WARN_MS = 30 * 86_400_000;
|
|
|
12
13
|
export const agentTokenFile = (home = CONFIG_DIR) => join(home, AGENT_TOKEN_FILE);
|
|
13
14
|
function read(home) {
|
|
14
15
|
try {
|
|
15
|
-
const j = JSON.parse(
|
|
16
|
+
const j = JSON.parse(readStateText(agentTokenFile(home)));
|
|
16
17
|
return j && typeof j === "object" ? j : {};
|
|
17
18
|
}
|
|
18
19
|
catch {
|
|
@@ -82,7 +83,8 @@ export function claudeTokenForRun(home = CONFIG_DIR, env = process.env, now = Da
|
|
|
82
83
|
}
|
|
83
84
|
export function envClaudeCredential(env = process.env) {
|
|
84
85
|
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
|
-
|
|
86
|
+
const v = env[k];
|
|
87
|
+
if (v && v.trim() !== "" && v !== "0")
|
|
86
88
|
return k;
|
|
87
89
|
}
|
|
88
90
|
return null;
|
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) {
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { readStateText, withFileLock } from "./file-lock.js";
|
|
4
|
+
import { writeWhole } from "./pins.js";
|
|
5
|
+
export const LIST_MAX_AGE_MS = 60 * 60_000;
|
|
6
|
+
const KEEP = 20;
|
|
7
|
+
export function parentInfo(pid, platform = process.platform) {
|
|
8
|
+
if (platform === "win32" || !Number.isInteger(pid) || pid <= 1)
|
|
9
|
+
return null;
|
|
10
|
+
try {
|
|
11
|
+
if (platform === "linux") {
|
|
12
|
+
const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
13
|
+
const start = stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19] ?? "";
|
|
14
|
+
const args = readFileSync(`/proc/${pid}/cmdline`, "utf8").split("\0").filter(Boolean).join(" ");
|
|
15
|
+
return start ? { start, args } : null;
|
|
16
|
+
}
|
|
17
|
+
const out = execFileSync("ps", ["-o", "lstart=,args=", "-p", String(pid)], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 2_000 }).replace(/\n$/, "");
|
|
18
|
+
return out.length > 25 ? { start: out.slice(0, 24).trim(), args: out.slice(24).trim() } : null;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const SHELLS = new Set(["sh", "bash", "zsh", "fish", "dash", "ksh", "mksh", "ash", "yash", "tcsh", "csh", "pwsh", "nu", "xonsh", "elvish", "oil", "osh"]);
|
|
25
|
+
export function typedShell(args) {
|
|
26
|
+
const t = args.trim().split(/\s+/);
|
|
27
|
+
const name = (t[0] ?? "").replace(/^-/, "").split("/").pop()?.toLowerCase().replace(/\.exe$/, "") ?? "";
|
|
28
|
+
if (!SHELLS.has(name) && name !== "powershell")
|
|
29
|
+
return false;
|
|
30
|
+
const rest = t.slice(1);
|
|
31
|
+
const init = rest.findIndex((x) => x === "--init-file" || x === "--rcfile" || x === "--init-command" || (x === "-C" && name === "fish"));
|
|
32
|
+
if (init >= 0 && rest.slice(0, init).every((x) => x.startsWith("-") && !/^-[a-zA-Z]*c[a-zA-Z]*$/.test(x)))
|
|
33
|
+
return true;
|
|
34
|
+
if ((name === "pwsh" || name === "powershell") && rest.some((x) => /^-noexit$/i.test(x)))
|
|
35
|
+
return true;
|
|
36
|
+
return rest.every((x) => x.startsWith("-") && x !== "-c" && !/^-[a-zA-Z]*c[a-zA-Z]*$/.test(x));
|
|
37
|
+
}
|
|
38
|
+
export function terminalKey(env = process.env, ppid = process.ppid, platform = process.platform, parent = (pid) => parentInfo(pid, platform)) {
|
|
39
|
+
const own = env["PANTHEON_TERMINAL_ID"]?.trim();
|
|
40
|
+
if (!own && platform === "win32")
|
|
41
|
+
return { key: `cmd:${ppid}`, stable: false, why: "windows" };
|
|
42
|
+
const ids = [];
|
|
43
|
+
const add = (name, v) => { if (v && v.trim())
|
|
44
|
+
ids.push(`${name}:${v.trim()}`); };
|
|
45
|
+
if (env["TMUX_PANE"])
|
|
46
|
+
add("tmux", `${env["TMUX_PANE"]}@${env["TMUX"] ?? ""}`);
|
|
47
|
+
if (env["STY"])
|
|
48
|
+
add("screen", `${env["STY"]}#${env["WINDOW"] ?? ""}`);
|
|
49
|
+
if (env["ZELLIJ_PANE_ID"])
|
|
50
|
+
add("zellij", `${env["ZELLIJ_PANE_ID"]}@${env["ZELLIJ_SESSION_NAME"] ?? ""}`);
|
|
51
|
+
for (const v of ["WEZTERM_PANE", "KITTY_WINDOW_ID", "ITERM_SESSION_ID", "TERM_SESSION_ID", "WT_SESSION"])
|
|
52
|
+
add(v, env[v]);
|
|
53
|
+
if (own)
|
|
54
|
+
return { key: [`id:${own}`, ...ids].join("|"), stable: true };
|
|
55
|
+
const info = parent(ppid);
|
|
56
|
+
if (info && !typedShell(info.args))
|
|
57
|
+
return { key: `shell:${ppid}`, stable: false, why: "wrapper" };
|
|
58
|
+
return { key: [`shell:${ppid}${info ? `@${info.start}` : ""}`, ...ids].join("|"), stable: true };
|
|
59
|
+
}
|
|
60
|
+
function read(file) {
|
|
61
|
+
try {
|
|
62
|
+
const j = JSON.parse(readStateText(file));
|
|
63
|
+
if (j && j.v === 2 && j.lists && typeof j.lists === "object")
|
|
64
|
+
return { v: 2, lists: j.lists };
|
|
65
|
+
}
|
|
66
|
+
catch { }
|
|
67
|
+
return { v: 2, lists: {} };
|
|
68
|
+
}
|
|
69
|
+
export function saveList(file, key, ids, now = Date.now()) {
|
|
70
|
+
withFileLock(file, () => {
|
|
71
|
+
const s = read(file);
|
|
72
|
+
s.lists[key] = { at: now, ids: [...ids] };
|
|
73
|
+
const fresh = Object.entries(s.lists)
|
|
74
|
+
.filter(([, l]) => l && typeof l.at === "number" && Array.isArray(l.ids) && now - l.at < 24 * 60 * 60_000)
|
|
75
|
+
.sort((a, b) => b[1].at - a[1].at).slice(0, KEEP);
|
|
76
|
+
writeWhole(file, JSON.stringify({ v: 2, lists: Object.fromEntries(fresh) }) + "\n");
|
|
77
|
+
}, 3_000);
|
|
78
|
+
}
|
|
79
|
+
export function listFor(file, key, now = Date.now()) {
|
|
80
|
+
const l = read(file).lists[key];
|
|
81
|
+
if (!l || typeof l.at !== "number" || !Array.isArray(l.ids))
|
|
82
|
+
return { none: "never" };
|
|
83
|
+
if (now - l.at >= LIST_MAX_AGE_MS || l.at > now + 60_000)
|
|
84
|
+
return { none: "old" };
|
|
85
|
+
return { ids: l.ids.filter((x) => typeof x === "string") };
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=approvals-list.js.map
|