@join-pantheon/cli 0.38.0 → 0.38.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/README.md +10 -2
- package/bin/pantheon.js +16 -1
- package/bin/upgrade-guard.js +273 -0
- package/dist/agent-check.js +9 -0
- package/dist/agents.js +8 -1
- package/dist/claude-confine.js +1 -0
- package/dist/cli.js +103 -6
- package/dist/crash-loop.js +22 -5
- package/dist/file-lock.js +19 -4
- package/dist/flow-stats.js +1 -0
- package/dist/home-safety.js +5 -0
- package/dist/leftovers.js +1 -1
- package/dist/mcp.js +23 -6
- package/dist/notice.js +2 -1
- package/dist/notify.js +14 -2
- package/dist/pending.js +11 -3
- package/dist/plain.js +1 -0
- package/dist/relay.js +103 -22
- package/dist/setup-changes.js +8 -0
- package/dist/spend.js +12 -0
- package/dist/store.js +100 -2
- package/dist/upgrade-probation.js +130 -0
- package/dist/upgrade.js +13 -0
- package/dist/version-health.js +8 -1
- package/dist/win-host.js +2 -1
- package/dist/worker-policy.js +61 -1
- package/dist/worker.js +241 -13
- package/helper/macos/prebuilt/manifest.json +2 -2
- package/helper/macos/prebuilt/pantheon-hud +0 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/store.js
CHANGED
|
@@ -4,6 +4,23 @@ import { emptyRefusals } from "./admin-stats.js";
|
|
|
4
4
|
import { pendingView, writerFor } from "./disk-writer.js";
|
|
5
5
|
import { emptyUsage, parseUsage } from "./usage.js";
|
|
6
6
|
export const USAGE_SAVE_MS = 5_000;
|
|
7
|
+
export const CLOSED_AGE_MS = 30 * 24 * 60 * 60_000;
|
|
8
|
+
export const CLOSED_KEEP = 200;
|
|
9
|
+
const AGED_RECHECK_MS = 10 * 60_000;
|
|
10
|
+
export function closedAt(g) {
|
|
11
|
+
return typeof g.closed_at === "number" && Number.isFinite(g.closed_at) ? g.closed_at : g.opened_at;
|
|
12
|
+
}
|
|
13
|
+
export function agedClosed(goals, now = Date.now(), age = CLOSED_AGE_MS, keep = CLOSED_KEEP) {
|
|
14
|
+
const closed = [...goals].filter((g) => g.state === "CLOSED");
|
|
15
|
+
if (closed.length <= keep)
|
|
16
|
+
return new Set();
|
|
17
|
+
closed.sort((a, b) => closedAt(b) - closedAt(a));
|
|
18
|
+
const out = new Set();
|
|
19
|
+
for (const g of closed.slice(keep))
|
|
20
|
+
if (now - closedAt(g) > age)
|
|
21
|
+
out.add(g.id);
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
7
24
|
export const FIRST_CLAIMS_KEEP_MS = 31 * 86_400_000;
|
|
8
25
|
export const FIRST_CLAIMS_MAX = 5_000;
|
|
9
26
|
export function ensurePrivateDir(dir) {
|
|
@@ -118,12 +135,58 @@ export class StateStore {
|
|
|
118
135
|
usageFile;
|
|
119
136
|
usageTimer = null;
|
|
120
137
|
usageDirty = false;
|
|
138
|
+
closedFile;
|
|
139
|
+
closedOnDisk = new Map();
|
|
140
|
+
aged = null;
|
|
141
|
+
closedUnreadable = false;
|
|
121
142
|
constructor(dir, stem) {
|
|
122
143
|
this.dir = dir;
|
|
123
144
|
this.stem = stem;
|
|
124
145
|
this.file = join(dir, `${stem}.state.json`);
|
|
125
146
|
this.usageFile = join(dir, `${stem}.usage.json`);
|
|
147
|
+
this.closedFile = join(dir, `${stem}.closed-goals.json`);
|
|
148
|
+
}
|
|
149
|
+
agedIds(goals, now = Date.now()) {
|
|
150
|
+
if (!this.aged || this.aged.size !== goals.size || now - this.aged.at > AGED_RECHECK_MS) {
|
|
151
|
+
this.aged = { ids: agedClosed(goals.values(), now), at: now, size: goals.size };
|
|
152
|
+
}
|
|
153
|
+
return this.aged.ids;
|
|
154
|
+
}
|
|
155
|
+
isAged(goals, g) {
|
|
156
|
+
return g.state === "CLOSED" && this.agedIds(goals).has(g.id);
|
|
157
|
+
}
|
|
158
|
+
loadClosed(quarantine) {
|
|
159
|
+
this.closedOnDisk = new Map();
|
|
160
|
+
this.closedUnreadable = false;
|
|
161
|
+
try {
|
|
162
|
+
const pending = pendingView(this.dir, this.stem, this.closedFile);
|
|
163
|
+
if (pending === null || (pending === undefined && !existsSync(this.closedFile)))
|
|
164
|
+
return this.closedOnDisk;
|
|
165
|
+
const raw = JSON.parse(pending ? pending.toString("utf8") : readFileSync(this.closedFile, "utf8"));
|
|
166
|
+
const all = raw && typeof raw === "object" && raw.goals && typeof raw.goals === "object" && !Array.isArray(raw.goals) ? raw.goals : null;
|
|
167
|
+
if (!all)
|
|
168
|
+
throw new Error("not a closed-goals file");
|
|
169
|
+
for (const [id, v] of Object.entries(all)) {
|
|
170
|
+
const g = v;
|
|
171
|
+
if (g && typeof g === "object" && g.id === id && typeof g.title === "string" && typeof g.closed_summary === "string" && Array.isArray(g.members))
|
|
172
|
+
this.closedOnDisk.set(id, { ...g, state: "CLOSED" });
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
let moved = false;
|
|
177
|
+
if (quarantine) {
|
|
178
|
+
try {
|
|
179
|
+
renameSync(this.closedFile, `${this.closedFile}.corrupt-${Date.now()}`);
|
|
180
|
+
moved = true;
|
|
181
|
+
}
|
|
182
|
+
catch { }
|
|
183
|
+
}
|
|
184
|
+
this.closedUnreadable = !moved;
|
|
185
|
+
this.closedOnDisk = new Map();
|
|
186
|
+
}
|
|
187
|
+
return this.closedOnDisk;
|
|
126
188
|
}
|
|
189
|
+
closedGoals() { return [...this.closedOnDisk.values()].map((g) => ({ ...g, members: [...g.members] })); }
|
|
127
190
|
loadUsage(quarantine) {
|
|
128
191
|
try {
|
|
129
192
|
const pending = pendingView(this.dir, this.stem, this.usageFile);
|
|
@@ -177,6 +240,8 @@ export class StateStore {
|
|
|
177
240
|
this.loadUsage(!!opts.quarantine);
|
|
178
241
|
const pending = pendingView(this.dir, this.stem, this.file);
|
|
179
242
|
if (pending === null || (pending === undefined && !existsSync(this.file))) {
|
|
243
|
+
this.loadClosed(!!opts.quarantine);
|
|
244
|
+
this.aged = null;
|
|
180
245
|
return { goals, obligations, profiles, unclean: opts.expectHistory ? "the state snapshot is missing but the ledger has history" : null };
|
|
181
246
|
}
|
|
182
247
|
try {
|
|
@@ -188,6 +253,13 @@ export class StateStore {
|
|
|
188
253
|
}
|
|
189
254
|
for (const g of snap.goals ?? [])
|
|
190
255
|
goals.set(g.id, g);
|
|
256
|
+
const kept = this.loadClosed(!!opts.quarantine);
|
|
257
|
+
for (const [id, whole] of kept) {
|
|
258
|
+
const g = goals.get(id);
|
|
259
|
+
if (g && g.closed_summary === undefined && whole.closed_summary !== undefined)
|
|
260
|
+
goals.set(id, { ...g, closed_summary: whole.closed_summary });
|
|
261
|
+
}
|
|
262
|
+
this.aged = null;
|
|
191
263
|
for (const o of snap.obligations ?? []) {
|
|
192
264
|
obligations.set(o.id, o.claimed_by ? { ...o, claimed_by: { ...o.claimed_by, at: Date.now() } } : o);
|
|
193
265
|
}
|
|
@@ -228,6 +300,8 @@ export class StateStore {
|
|
|
228
300
|
}
|
|
229
301
|
catch { }
|
|
230
302
|
}
|
|
303
|
+
this.loadClosed(!!opts.quarantine);
|
|
304
|
+
this.aged = null;
|
|
231
305
|
return { goals: new Map(), obligations: new Map(), profiles: new Map(), unclean: why, ...(quarantined ? { quarantined } : {}) };
|
|
232
306
|
}
|
|
233
307
|
}
|
|
@@ -251,10 +325,34 @@ export class StateStore {
|
|
|
251
325
|
}
|
|
252
326
|
onError;
|
|
253
327
|
flush(goals, obligations, profiles) {
|
|
328
|
+
let list = [...goals.values()];
|
|
329
|
+
if (!this.closedUnreadable) {
|
|
330
|
+
const aged = this.agedIds(goals);
|
|
331
|
+
const next = new Map(this.closedOnDisk);
|
|
332
|
+
let grew = false;
|
|
333
|
+
if (aged.size) {
|
|
334
|
+
list = list.map((g) => {
|
|
335
|
+
if (g.state !== "CLOSED" || !aged.has(g.id) || g.closed_summary === undefined)
|
|
336
|
+
return g;
|
|
337
|
+
const had = next.get(g.id);
|
|
338
|
+
if (!had || had.closed_summary !== g.closed_summary) {
|
|
339
|
+
next.set(g.id, { ...g, members: [...g.members] });
|
|
340
|
+
grew = true;
|
|
341
|
+
}
|
|
342
|
+
const rest = { ...g };
|
|
343
|
+
delete rest.closed_summary;
|
|
344
|
+
return rest;
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
if (grew) {
|
|
348
|
+
writerFor(this.dir, this.stem).replace(this.closedFile, JSON.stringify({ v: 1, goals: Object.fromEntries(next) }) + "\n", 0o600, "first");
|
|
349
|
+
this.closedOnDisk = next;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
254
352
|
const snap = {
|
|
255
353
|
...this.extra,
|
|
256
354
|
v: 2,
|
|
257
|
-
goals:
|
|
355
|
+
goals: list,
|
|
258
356
|
obligations: [...obligations.values()],
|
|
259
357
|
profiles: [...profiles.values()],
|
|
260
358
|
...(this.refusals.total ? { refusals: this.refusals } : {}),
|
|
@@ -265,7 +363,7 @@ export class StateStore {
|
|
|
265
363
|
...(this.gapsChecked ? { gaps_checked: this.gapsChecked } : {}),
|
|
266
364
|
saved_at: Date.now(),
|
|
267
365
|
};
|
|
268
|
-
writerFor(this.dir, this.stem).replace(this.file, JSON.stringify(snap
|
|
366
|
+
writerFor(this.dir, this.stem).replace(this.file, JSON.stringify(snap) + "\n");
|
|
269
367
|
}
|
|
270
368
|
keptFirstClaims(now = Date.now()) {
|
|
271
369
|
for (const [k, c] of this.firstClaims)
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { readFileSync, rmSync } from "node:fs";
|
|
2
|
+
import { posix, win32 } from "node:path";
|
|
3
|
+
import { managedLayout } from "./managed.js";
|
|
4
|
+
import { atomicWrite } from "./worker-policy.js";
|
|
5
|
+
export const PROBATION_FILE = "upgrade-probation.json";
|
|
6
|
+
export const HELD_FILE = "upgrade-held.json";
|
|
7
|
+
export const PROBATION_MS = 2 * 3600_000;
|
|
8
|
+
export const FAILS_TO_ROLL_BACK = 3;
|
|
9
|
+
export const NEVER_ONLINE_MS = 15 * 60_000;
|
|
10
|
+
const isTime = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
11
|
+
export function runtimeDir(m) {
|
|
12
|
+
return (/\.exe$/i.test(m.node) ? win32 : posix).dirname(m.prevDir);
|
|
13
|
+
}
|
|
14
|
+
const fileIn = (m, name) => (/\.exe$/i.test(m.node) ? win32 : posix).join(runtimeDir(m), name);
|
|
15
|
+
const readJson = (f) => {
|
|
16
|
+
try {
|
|
17
|
+
const v = JSON.parse(readFileSync(f, "utf8"));
|
|
18
|
+
return v && typeof v === "object" ? v : null;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export function readProbation(m = managedLayout()) {
|
|
25
|
+
if (!m)
|
|
26
|
+
return null;
|
|
27
|
+
const p = readJson(fileIn(m, PROBATION_FILE));
|
|
28
|
+
if (!p || typeof p.to !== "string" || !isTime(p.at))
|
|
29
|
+
return null;
|
|
30
|
+
return p;
|
|
31
|
+
}
|
|
32
|
+
export function probationText(from, to, now) {
|
|
33
|
+
return JSON.stringify({ v: 1, ...(from ? { from } : {}), to, at: now, runs: [], fails: [] }, null, 2) + "\n";
|
|
34
|
+
}
|
|
35
|
+
export function onProbation(version, o = {}) {
|
|
36
|
+
const p = readProbation(o.m === undefined ? managedLayout() : o.m);
|
|
37
|
+
return !!p && p.to === version && !p.stuck && (o.now ?? Date.now()) - p.at <= PROBATION_MS;
|
|
38
|
+
}
|
|
39
|
+
export function probationPassed(version, o = {}) {
|
|
40
|
+
const m = o.m === undefined ? managedLayout() : o.m;
|
|
41
|
+
const p = readProbation(m);
|
|
42
|
+
if (!m || !p || p.to !== version)
|
|
43
|
+
return false;
|
|
44
|
+
try {
|
|
45
|
+
rmSync(fileIn(m, PROBATION_FILE), { force: true });
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function changeProbation(m, fn) {
|
|
53
|
+
const p = readProbation(m);
|
|
54
|
+
if (!p)
|
|
55
|
+
return false;
|
|
56
|
+
fn(p);
|
|
57
|
+
try {
|
|
58
|
+
atomicWrite(fileIn(m, PROBATION_FILE), JSON.stringify(p, null, 2) + "\n");
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export function markNeverOnline(version, o = {}) {
|
|
66
|
+
const m = o.m === undefined ? managedLayout() : o.m;
|
|
67
|
+
if (!m || readProbation(m)?.to !== version)
|
|
68
|
+
return false;
|
|
69
|
+
return changeProbation(m, (p) => { p.never_online = o.now ?? Date.now(); });
|
|
70
|
+
}
|
|
71
|
+
export function probationStopExpected(o = {}) {
|
|
72
|
+
const m = o.m === undefined ? managedLayout() : o.m;
|
|
73
|
+
if (!m || !readProbation(m))
|
|
74
|
+
return;
|
|
75
|
+
changeProbation(m, (p) => { p.stop_expected_at = o.now ?? Date.now(); });
|
|
76
|
+
}
|
|
77
|
+
export function readRolledBack(m = managedLayout()) {
|
|
78
|
+
if (!m)
|
|
79
|
+
return null;
|
|
80
|
+
const h = readJson(fileIn(m, HELD_FILE));
|
|
81
|
+
if (!h || typeof h.version !== "string" || typeof h.back_to !== "string")
|
|
82
|
+
return null;
|
|
83
|
+
return { version: h.version, back_to: h.back_to, at: isTime(h.at) ? h.at : 0, why: typeof h.why === "string" ? h.why : "", ...(isTime(h.told_at) ? { told_at: h.told_at } : {}) };
|
|
84
|
+
}
|
|
85
|
+
export function markRolledBackTold(o = {}) {
|
|
86
|
+
const m = o.m === undefined ? managedLayout() : o.m;
|
|
87
|
+
const h = m ? readRolledBack(m) : null;
|
|
88
|
+
if (!m || !h)
|
|
89
|
+
return;
|
|
90
|
+
try {
|
|
91
|
+
atomicWrite(fileIn(m, HELD_FILE), JSON.stringify({ v: 1, ...h, told_at: o.now ?? Date.now() }, null, 2) + "\n");
|
|
92
|
+
}
|
|
93
|
+
catch { }
|
|
94
|
+
}
|
|
95
|
+
export function heldBack(pkg, o = {}) {
|
|
96
|
+
if (!pkg)
|
|
97
|
+
return null;
|
|
98
|
+
const h = readRolledBack(o.m === undefined ? managedLayout() : o.m);
|
|
99
|
+
return h && h.version === pkg ? h : null;
|
|
100
|
+
}
|
|
101
|
+
export function rolledBackSentence(h) {
|
|
102
|
+
const what = h.why === "never_online" ? "could not reach your team" : "kept stopping";
|
|
103
|
+
return `Pantheon ${h.version} ${what} on this computer, so it went back to ${h.back_to} by itself. Nothing to do: it updates again when a newer release is out.`;
|
|
104
|
+
}
|
|
105
|
+
export function watchNeverOnline(o) {
|
|
106
|
+
if (!onProbation(o.version, o.m === undefined ? {} : { m: o.m }))
|
|
107
|
+
return null;
|
|
108
|
+
const t = setTimeout(() => {
|
|
109
|
+
void (async () => {
|
|
110
|
+
if (o.connected() || !onProbation(o.version, o.m === undefined ? {} : { m: o.m }))
|
|
111
|
+
return;
|
|
112
|
+
let up = false;
|
|
113
|
+
try {
|
|
114
|
+
up = await o.relayAnswers();
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
up = false;
|
|
118
|
+
}
|
|
119
|
+
if (!up || o.connected())
|
|
120
|
+
return;
|
|
121
|
+
if (!markNeverOnline(o.version, o.m === undefined ? {} : { m: o.m }))
|
|
122
|
+
return;
|
|
123
|
+
o.log?.(`! pantheon ${o.version} has not reached the team's relay in ${Math.round((o.afterMs ?? NEVER_ONLINE_MS) / 60_000)} minutes though the relay answers — going back to the previous version`);
|
|
124
|
+
o.exit();
|
|
125
|
+
})();
|
|
126
|
+
}, o.afterMs ?? NEVER_ONLINE_MS);
|
|
127
|
+
t.unref?.();
|
|
128
|
+
return t;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=upgrade-probation.js.map
|
package/dist/upgrade.js
CHANGED
|
@@ -8,6 +8,7 @@ import { proxyEnvFor } from "./network.js";
|
|
|
8
8
|
import { relayProc, workerProc, notifierProc, menubarProc } from "./machine.js";
|
|
9
9
|
import { load } from "./config.js";
|
|
10
10
|
import { compareVersions, INSTALLER_MIN_CLI, isVersion } from "./installer.js";
|
|
11
|
+
import { HELD_FILE, PROBATION_FILE, probationText } from "./upgrade-probation.js";
|
|
11
12
|
export const WINDOWS_PROFILE_ROOT_MIN = "0.33.1-0";
|
|
12
13
|
import { childNodeFlags, installerLineHere, launcherWithRepair, managedLayout, nodeSatisfies, nodeTooOldSentence, runtimeNodeVersion } from "./managed.js";
|
|
13
14
|
export function repoRoot() {
|
|
@@ -400,6 +401,11 @@ export function stagedManagedUpgrade(m, spec, io = realSwapIo(m)) {
|
|
|
400
401
|
const staged = startsAs(P.join(stagedPkg, "bin", "pantheon.js"));
|
|
401
402
|
if (staged !== version)
|
|
402
403
|
throw new Error(`the new pantheon ${version} did not start (it answered ${staged ?? "nothing"}); the working version was kept`);
|
|
404
|
+
let from = null;
|
|
405
|
+
try {
|
|
406
|
+
from = JSON.parse(io.read(P.join(m.pkgDir, "package.json"))).version ?? null;
|
|
407
|
+
}
|
|
408
|
+
catch { }
|
|
403
409
|
if (!rename(stagedPkg, ready))
|
|
404
410
|
throw new Error("the new pantheon's files are still held by another program (a virus scan); nothing was changed, and the next check tries again");
|
|
405
411
|
if (!inPlace())
|
|
@@ -431,6 +437,13 @@ export function stagedManagedUpgrade(m, spec, io = realSwapIo(m)) {
|
|
|
431
437
|
? `pantheon ${version} did not start once in place (it answered ${placed ?? "nothing"}); the previous version was put back`
|
|
432
438
|
: `pantheon ${version} did not start once in place, and the previous version could not be put back yet. ${inPlace() ? `It is kept at ${prev}; the next upgrade puts it back, or run the installer again` : repairHint()}`);
|
|
433
439
|
}
|
|
440
|
+
if (from && from !== version && whole(prev)) {
|
|
441
|
+
try {
|
|
442
|
+
io.write(P.join(runtime, PROBATION_FILE), probationText(from, version, Date.now()));
|
|
443
|
+
}
|
|
444
|
+
catch { }
|
|
445
|
+
}
|
|
446
|
+
tidy(P.join(runtime, HELD_FILE));
|
|
434
447
|
return { version };
|
|
435
448
|
}
|
|
436
449
|
finally {
|
package/dist/version-health.js
CHANGED
|
@@ -5,6 +5,7 @@ import { atomicWrite, isNewer, ASK_EXPIRY_MS } from "./worker-policy.js";
|
|
|
5
5
|
import { installedVersion } from "./mcp-supervisor.js";
|
|
6
6
|
import { VERSION } from "./version.js";
|
|
7
7
|
import { BUDGET } from "./notice.js";
|
|
8
|
+
import { readRolledBack } from "./upgrade-probation.js";
|
|
8
9
|
export const BEHIND_ALERT_AFTER_MS = 24 * 3_600_000;
|
|
9
10
|
export const GRANTED_STUCK_AFTER_MS = 72 * 3_600_000;
|
|
10
11
|
export const RELAY_PKG_REFRESH_MS = 60 * 60_000;
|
|
@@ -155,6 +156,8 @@ export function behindVerdict(seen, o) {
|
|
|
155
156
|
return { due: false, why: "current" };
|
|
156
157
|
if (o.state.behind_alerted?.[seen.pkg])
|
|
157
158
|
return { due: false, why: "said" };
|
|
159
|
+
if (o.rolledBack && o.rolledBack === seen.pkg)
|
|
160
|
+
return { due: false, why: "worker_said" };
|
|
158
161
|
if (o.state.upgrade_failed?.[seen.pkg]?.alerted_at)
|
|
159
162
|
return { due: false, why: "worker_said" };
|
|
160
163
|
if (o.policy?.upgradeHeld?.version === seen.pkg)
|
|
@@ -209,11 +212,12 @@ export class VersionWatch {
|
|
|
209
212
|
const quiet = [];
|
|
210
213
|
let running;
|
|
211
214
|
const workerRunning = () => (running ??= safe(() => false, () => this.o.workerRunning()));
|
|
215
|
+
const rolledBack = safe(() => null, () => (this.o.rolledBack ?? (() => readRolledBack()?.version ?? null))());
|
|
212
216
|
for (const r of relays) {
|
|
213
217
|
const seen = state.relays[r];
|
|
214
218
|
if (!seen)
|
|
215
219
|
continue;
|
|
216
|
-
const v = behindVerdict(seen, { local, now: now(), state, policy, workerRunning });
|
|
220
|
+
const v = behindVerdict(seen, { local, now: now(), state, policy, workerRunning, rolledBack });
|
|
217
221
|
if (v.due)
|
|
218
222
|
due.push(seen.pkg);
|
|
219
223
|
else if (v.why === "worker_said")
|
|
@@ -267,6 +271,9 @@ export function behindStatusLine(o) {
|
|
|
267
271
|
if (!seen || !isNewer(seen.pkg, o.local))
|
|
268
272
|
return null;
|
|
269
273
|
const pkg = seen.pkg;
|
|
274
|
+
if (o.rolledBack && o.rolledBack === pkg) {
|
|
275
|
+
return `pantheon ${o.local} here, the team's relay ${pkg}: ${pkg} did not work on this computer, so Pantheon went back to ${o.local} by itself and updates again when a newer release is out — nothing to do unless your human asks.`;
|
|
276
|
+
}
|
|
270
277
|
const held = o.policy?.upgradeHeld?.version === pkg ? o.policy.upgradeHeld : null;
|
|
271
278
|
if (held) {
|
|
272
279
|
return `PANTHEON IS OUT OF DATE HERE: this computer runs ${o.local}, the team's relay ${pkg}, and the update needs something only your human can do: ${held.why} ` +
|
package/dist/win-host.js
CHANGED
|
@@ -530,6 +530,7 @@ export function realHostIo(o = {}) {
|
|
|
530
530
|
const node = o.node ?? process.execPath;
|
|
531
531
|
const flags = o.flags ?? [];
|
|
532
532
|
const cli = o.cli ?? resolve(HERE, "cli.js");
|
|
533
|
+
const childEntry = o.cli ? cli : (() => { const b = resolve(HERE, "..", "bin", "pantheon.js"); return existsSync(b) ? b : cli; })();
|
|
533
534
|
const pantheon = o.pantheonCommand ?? `"${node}" ${flags.join(" ")} "${cli}"`.replace(/\s+/g, " ");
|
|
534
535
|
const session = o.session ?? hostSession();
|
|
535
536
|
const parent = process.ppid;
|
|
@@ -617,7 +618,7 @@ export function realHostIo(o = {}) {
|
|
|
617
618
|
const d = readDefinition(child, home);
|
|
618
619
|
if (!d)
|
|
619
620
|
throw new Error(`no ${child} definition`);
|
|
620
|
-
argv = childArgv(child, d.args, node, flags,
|
|
621
|
+
argv = childArgv(child, d.args, node, flags, childEntry);
|
|
621
622
|
if (existsSync(d.cwd))
|
|
622
623
|
cwd = d.cwd;
|
|
623
624
|
}
|
package/dist/worker-policy.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, renameSync, rmSync, writeFileSync, writeSync } from "node:fs";
|
|
1
|
+
import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeFileSync, writeSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
2
3
|
import { dirname, join } from "node:path";
|
|
3
4
|
import { CONFIG_PATH } from "./config.js";
|
|
4
5
|
import { trustWrite } from "./home-guard.js";
|
|
@@ -78,6 +79,63 @@ export function describeRunMinutes(r, persona) {
|
|
|
78
79
|
: r.from === "flag" ? "this worker's --run-minutes" : `lowered by persona ${persona ?? ""}`.trim();
|
|
79
80
|
return `${r.minutes} minutes per run (${why})`;
|
|
80
81
|
}
|
|
82
|
+
export const DEFAULT_RUN_MODEL = { "claude-code": "sonnet" };
|
|
83
|
+
export const OWN_MODEL = "own";
|
|
84
|
+
export const RUN_MODEL_AGENTS = ["claude-code", "codex", "cursor", "copilot", "kiro"];
|
|
85
|
+
export function parseModelName(raw) {
|
|
86
|
+
if (raw === undefined || raw === null)
|
|
87
|
+
return null;
|
|
88
|
+
const s = String(raw).trim();
|
|
89
|
+
return /^[A-Za-z0-9][A-Za-z0-9._:/\[\]-]{0,79}$/.test(s) ? s : null;
|
|
90
|
+
}
|
|
91
|
+
export function effectiveRunModel(agent, policy, routing = null) {
|
|
92
|
+
const set = agent ? policy?.models?.[agent] : undefined;
|
|
93
|
+
if (set === OWN_MODEL)
|
|
94
|
+
return { model: null, from: "own" };
|
|
95
|
+
if (set)
|
|
96
|
+
return { model: set, from: "policy" };
|
|
97
|
+
const d = agent ? DEFAULT_RUN_MODEL[agent] : undefined;
|
|
98
|
+
if (d && agent === "claude-code" && routing)
|
|
99
|
+
return { model: null, from: "provider" };
|
|
100
|
+
return d ? { model: d, from: "default" } : { model: null, from: "own" };
|
|
101
|
+
}
|
|
102
|
+
export const CLAUDE_ROUTING_VARS = ["CLAUDE_CODE_USE_BEDROCK", "CLAUDE_CODE_USE_VERTEX", "CLAUDE_CODE_USE_FOUNDRY", "ANTHROPIC_BASE_URL", "ANTHROPIC_MODEL"];
|
|
103
|
+
export function claudeRouting(env = process.env, home = homedir()) {
|
|
104
|
+
let fromSettings = {};
|
|
105
|
+
try {
|
|
106
|
+
const j = JSON.parse(readFileSync(join(home, ".claude", "settings.json"), "utf8"));
|
|
107
|
+
if (j && typeof j.env === "object" && j.env !== null)
|
|
108
|
+
fromSettings = j.env;
|
|
109
|
+
}
|
|
110
|
+
catch { }
|
|
111
|
+
for (const v of CLAUDE_ROUTING_VARS) {
|
|
112
|
+
const x = env[v] ?? fromSettings[v];
|
|
113
|
+
if (typeof x !== "string" || !x.trim())
|
|
114
|
+
continue;
|
|
115
|
+
if (v.startsWith("CLAUDE_CODE_USE_") && /^(0|false|no|off)$/i.test(x.trim()))
|
|
116
|
+
continue;
|
|
117
|
+
return v;
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
export function describeRunModel(r) {
|
|
122
|
+
if (!r.model)
|
|
123
|
+
return "the agent's own default model";
|
|
124
|
+
return `${r.model} (${r.from === "default" ? "the default" : "set on this machine"})`;
|
|
125
|
+
}
|
|
126
|
+
export const GOAL_RUNS = { default: 12, min: 1, max: 100 };
|
|
127
|
+
export function parseGoalRuns(raw) {
|
|
128
|
+
if (raw === undefined || raw === null)
|
|
129
|
+
return null;
|
|
130
|
+
const s = String(raw).trim();
|
|
131
|
+
if (!/^\d+$/.test(s))
|
|
132
|
+
return null;
|
|
133
|
+
const n = Number(s);
|
|
134
|
+
return n >= GOAL_RUNS.min && n <= GOAL_RUNS.max ? n : null;
|
|
135
|
+
}
|
|
136
|
+
export function effectiveGoalRuns(policy) {
|
|
137
|
+
return policy?.goalRuns !== undefined ? { runs: policy.goalRuns, from: "policy" } : { runs: GOAL_RUNS.default, from: "default" };
|
|
138
|
+
}
|
|
81
139
|
export const finalKey = {
|
|
82
140
|
cap: (cap) => `cap:${cap}`,
|
|
83
141
|
wake: (team, member) => `wake:${wakeKey(team, member)}`,
|
|
@@ -226,6 +284,8 @@ function parsePolicy(text) {
|
|
|
226
284
|
? { upgradeHeld: { version: raw.upgradeHeld.version, node: raw.upgradeHeld.node, at: Number(raw.upgradeHeld.at) || 0, why: String(raw.upgradeHeld.why ?? "") } } : {}),
|
|
227
285
|
...(typeof raw.runMinutes === "number" && parseRunMinutes(raw.runMinutes) !== null ? { runMinutes: raw.runMinutes } : {}),
|
|
228
286
|
...(typeof raw.idleSeconds === "number" && parseIdleSeconds(raw.idleSeconds) !== null ? { idleSeconds: raw.idleSeconds } : {}),
|
|
287
|
+
...(isRecord(raw.models) ? (() => { const m = Object.fromEntries(Object.entries(raw.models).filter(([k, v]) => RUN_MODEL_AGENTS.includes(k) && typeof v === "string" && parseModelName(v) !== null)); return Object.keys(m).length ? { models: m } : {}; })() : {}),
|
|
288
|
+
...(typeof raw.goalRuns === "number" && parseGoalRuns(raw.goalRuns) !== null ? { goalRuns: raw.goalRuns } : {}),
|
|
229
289
|
...(typeof raw.mode === "string" && parseMode(raw.mode) ? { mode: raw.mode } : {}),
|
|
230
290
|
...(typeof raw.modeToldAt === "number" ? { modeToldAt: raw.modeToldAt } : {}),
|
|
231
291
|
...(isRecord(raw.stuckReports) ? { stuckReports: Object.fromEntries(Object.entries(raw.stuckReports).filter(([, v]) => isRecord(v) && typeof v.ref === "string" && typeof v.team === "string" && typeof v.at === "number")) } : {}),
|