@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/home-guard.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { chmodSync, lstatSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
-
import {
|
|
2
|
+
import { chmodSync, lstatSync, readFileSync, readlinkSync, renameSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
5
|
import { parseJsonText } from "./text-file.js";
|
|
5
6
|
import { withFileLock } from "./file-lock.js";
|
|
6
7
|
import { writeWhole } from "./pins.js";
|
|
8
|
+
import { WORKER_MARK, markedHere, ownReleases } from "./continued.js";
|
|
9
|
+
import { HUD_QUEUE_DIR, sweepActionQueue } from "./hud-queue.js";
|
|
7
10
|
export const POLICY_FILE = "worker-policy.json";
|
|
8
11
|
export const PROFILE_FILE = "profile.json";
|
|
9
12
|
export const HUD_FILE = join("bin", ".hud-action.json");
|
|
@@ -21,7 +24,9 @@ export const RUN_CONTROL_FILE = "run-control.json";
|
|
|
21
24
|
export const HUD_PREF_FILE = join("bin", ".hud-pref.json");
|
|
22
25
|
export const AGENT_TOKENS_FILE = "agent-tokens.json";
|
|
23
26
|
export const SIGNED_OUT_FILE = "signed-out.json";
|
|
24
|
-
export const
|
|
27
|
+
export const SIGNED_OUT_SALT_FILE = "signed-out.salt";
|
|
28
|
+
export const APPROVALS_LIST_FILE = "approvals-last.json";
|
|
29
|
+
export const GUARDED_FILES = [AGENT_TOKENS_FILE, SIGNED_OUT_FILE, SIGNED_OUT_SALT_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, APPROVALS_LIST_FILE];
|
|
25
30
|
export function narrowRunControl(before, now) {
|
|
26
31
|
const list = (x) => (Array.isArray(obj(x).stops) ? obj(x).stops.filter((e) => !!e && typeof e === "object") : []);
|
|
27
32
|
const b = list(before), n = list(now);
|
|
@@ -98,14 +103,64 @@ export function trustWrite(file, prev) {
|
|
|
98
103
|
set.delete(set.values().next().value);
|
|
99
104
|
trusted.set(k, set);
|
|
100
105
|
}
|
|
106
|
+
const linkOf = (f) => { try {
|
|
107
|
+
return lstatSync(f).isSymbolicLink() ? readlinkSync(f) : undefined;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return undefined;
|
|
111
|
+
} };
|
|
101
112
|
export function snapshotHome(home, files = GUARDED_FILES) {
|
|
102
|
-
const s = { home, at: Date.now(), files: files.map((rel) => { const b = read(join(home, rel)); return { rel, bytes: b, hash: b ? sha(b) : null }; }) };
|
|
113
|
+
const s = { home, at: Date.now(), files: files.map((rel) => { const b = read(join(home, rel)); const l = linkOf(join(home, rel)); return { rel, bytes: b, hash: b ? sha(b) : null, ...(l !== undefined ? { link: l } : {}) }; }) };
|
|
103
114
|
for (const f of s.files)
|
|
104
115
|
runBaseline.set(resolve(join(home, f.rel)), f.hash);
|
|
105
116
|
return s;
|
|
106
117
|
}
|
|
107
118
|
export const RUN_GUARD_FILE = "worker-run-guard.json";
|
|
108
119
|
export const RUN_GUARD_TMP = `${RUN_GUARD_FILE}.tmp`;
|
|
120
|
+
export function ownWrites() {
|
|
121
|
+
return { wake: [...askedHere.wake], cap: [...askedHere.cap], stuck: [...askedHere.stuck], safety: [...askedHere.safety], withdrawn: [...withdrawnHere], noes: [...noesHere], marks: [...markedHere] };
|
|
122
|
+
}
|
|
123
|
+
export function resetOwn() {
|
|
124
|
+
for (const m of Object.values(askedHere))
|
|
125
|
+
m.clear();
|
|
126
|
+
withdrawnHere.clear();
|
|
127
|
+
noesHere.clear();
|
|
128
|
+
markedHere.clear();
|
|
129
|
+
}
|
|
130
|
+
export function adoptOwn(o) {
|
|
131
|
+
if (!o)
|
|
132
|
+
return;
|
|
133
|
+
for (const [k, v] of o.wake)
|
|
134
|
+
askedHere.wake.set(k, v);
|
|
135
|
+
for (const [k, v] of o.cap)
|
|
136
|
+
askedHere.cap.set(k, v);
|
|
137
|
+
for (const [k, v] of o.stuck)
|
|
138
|
+
askedHere.stuck.set(k, v);
|
|
139
|
+
for (const [k, v] of o.safety ?? [])
|
|
140
|
+
askedHere.safety.set(k, v);
|
|
141
|
+
for (const k of o.withdrawn)
|
|
142
|
+
withdrawnHere.add(k);
|
|
143
|
+
for (const k of o.noes)
|
|
144
|
+
noesHere.add(k);
|
|
145
|
+
for (const k of o.marks)
|
|
146
|
+
markedHere.add(k);
|
|
147
|
+
}
|
|
148
|
+
const pairs = (v) => Array.isArray(v) ? v.filter((x) => Array.isArray(x) && typeof x[0] === "string" && typeof x[1] === "string") : [];
|
|
149
|
+
const strs = (v) => Array.isArray(v) ? v.filter((x) => typeof x === "string") : [];
|
|
150
|
+
function amendGuard(home, patch) {
|
|
151
|
+
try {
|
|
152
|
+
const f = join(home, RUN_GUARD_FILE);
|
|
153
|
+
const o = obj(JSON.parse(readFileSync(f, "utf8")));
|
|
154
|
+
if (!Array.isArray(o.files))
|
|
155
|
+
return;
|
|
156
|
+
const tmp = join(home, RUN_GUARD_TMP);
|
|
157
|
+
writeFileSync(tmp, JSON.stringify({ ...o, ...patch }), { mode: 0o600 });
|
|
158
|
+
renameSync(tmp, f);
|
|
159
|
+
}
|
|
160
|
+
catch { }
|
|
161
|
+
}
|
|
162
|
+
export function persistOwn(home) { amendGuard(home, { own: ownWrites() }); }
|
|
163
|
+
export function persistPending(home, rels) { amendGuard(home, { pending: rels, own: ownWrites() }); }
|
|
109
164
|
export function configSecretPaths(cfg) {
|
|
110
165
|
const c = obj(cfg);
|
|
111
166
|
const out = [];
|
|
@@ -173,7 +228,8 @@ function unredactConfig(before, now) {
|
|
|
173
228
|
const HOLDS_SECRETS = new Set([CONFIG_FILE, AGENT_TOKENS_FILE]);
|
|
174
229
|
export function persistSnapshot(s, o = {}) {
|
|
175
230
|
const file = join(s.home, RUN_GUARD_FILE);
|
|
176
|
-
const files = s.files.map((f) => {
|
|
231
|
+
const files = s.files.map((f) => ({ ...persisted(f), ...(f.link !== undefined ? { link: f.link } : {}) }));
|
|
232
|
+
function persisted(f) {
|
|
177
233
|
if (!HOLDS_SECRETS.has(f.rel) || !f.bytes)
|
|
178
234
|
return { rel: f.rel, bytes: f.bytes ? f.bytes.toString("base64") : null, hash: f.hash };
|
|
179
235
|
if (f.rel === AGENT_TOKENS_FILE)
|
|
@@ -186,7 +242,7 @@ export function persistSnapshot(s, o = {}) {
|
|
|
186
242
|
safe = null;
|
|
187
243
|
}
|
|
188
244
|
return { rel: f.rel, bytes: safe === null ? null : Buffer.from(safe).toString("base64"), hash: f.hash, redacted: true };
|
|
189
|
-
}
|
|
245
|
+
}
|
|
190
246
|
const body = { v: 2, worker: o.worker ?? process.pid, ...(o.workerId ? { worker_id: o.workerId } : {}), at: s.at ?? Date.now(), ...(o.limit !== undefined ? { limit: o.limit } : {}), attempts: o.attempts ?? 0, files };
|
|
191
247
|
const tmp = join(s.home, RUN_GUARD_TMP);
|
|
192
248
|
writeFileSync(tmp, JSON.stringify(body), { mode: 0o600 });
|
|
@@ -216,6 +272,11 @@ export function loadPersistedGuard(home) {
|
|
|
216
272
|
out.limit = o.limit;
|
|
217
273
|
if (Array.isArray(o.restored))
|
|
218
274
|
out.restored = o.restored.filter((x) => typeof x === "string");
|
|
275
|
+
if (Array.isArray(o.pending))
|
|
276
|
+
out.pending = strs(o.pending).filter((r) => GUARDED_FILES.includes(r));
|
|
277
|
+
const ow = obj(o.own);
|
|
278
|
+
if (Object.keys(ow).length)
|
|
279
|
+
out.own = { wake: pairs(ow.wake), cap: pairs(ow.cap), stuck: pairs(ow.stuck), safety: pairs(ow.safety), withdrawn: strs(ow.withdrawn), noes: strs(ow.noes), marks: strs(ow.marks) };
|
|
219
280
|
if (Array.isArray(o.files)) {
|
|
220
281
|
const files = [];
|
|
221
282
|
for (const f of o.files) {
|
|
@@ -223,12 +284,13 @@ export function loadPersistedGuard(home) {
|
|
|
223
284
|
if (typeof x.rel !== "string" || !GUARDED_FILES.includes(x.rel))
|
|
224
285
|
continue;
|
|
225
286
|
const bytes = typeof x.bytes === "string" ? Buffer.from(x.bytes, "base64") : null;
|
|
287
|
+
const link = typeof x.link === "string" ? { link: x.link } : {};
|
|
226
288
|
if (HOLDS_SECRETS.has(x.rel)) {
|
|
227
289
|
const hash = typeof x.hash === "string" && /^[0-9a-f]{64}$/.test(x.hash) ? x.hash : null;
|
|
228
|
-
files.push({ rel: x.rel, bytes, hash, redacted: true });
|
|
290
|
+
files.push({ rel: x.rel, bytes, hash, redacted: true, ...link });
|
|
229
291
|
continue;
|
|
230
292
|
}
|
|
231
|
-
files.push({ rel: x.rel, bytes, hash: bytes ? sha(bytes) : null });
|
|
293
|
+
files.push({ rel: x.rel, bytes, hash: bytes ? sha(bytes) : null, ...link });
|
|
232
294
|
}
|
|
233
295
|
out.snapshot = { home, at: o.at, files };
|
|
234
296
|
}
|
|
@@ -266,8 +328,16 @@ export function changedKeys(a, b, prefix = "", depth = 0) {
|
|
|
266
328
|
}
|
|
267
329
|
const obj = (x) => (x && typeof x === "object" && !Array.isArray(x) ? x : {});
|
|
268
330
|
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
269
|
-
export const askedHere = new
|
|
331
|
+
export const askedHere = { wake: new Map(), cap: new Map(), stuck: new Map(), safety: new Map() };
|
|
332
|
+
export function canon(v) {
|
|
333
|
+
return JSON.stringify(v, (_k, x) => x && typeof x === "object" && !Array.isArray(x)
|
|
334
|
+
? Object.fromEntries(Object.keys(x).sort().map((k) => [k, x[k]])) : x);
|
|
335
|
+
}
|
|
336
|
+
export const withdrawnHere = new Set();
|
|
337
|
+
export const noesHere = new Set();
|
|
338
|
+
const isTime = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
270
339
|
export function narrowPolicy(before, now, keepAsks = askedHere) {
|
|
340
|
+
const mine = (kind, key, v) => keepAsks[kind].get(key) === canon(v);
|
|
271
341
|
const b = obj(before);
|
|
272
342
|
const keys = [];
|
|
273
343
|
const out = { ...now };
|
|
@@ -299,31 +369,62 @@ export function narrowPolicy(before, now, keepAsks = askedHere) {
|
|
|
299
369
|
}
|
|
300
370
|
if (Object.keys(wakers).length || "wakers" in now)
|
|
301
371
|
out.wakers = wakers;
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
372
|
+
const dated = (field, lifted, keepAdded = () => false) => {
|
|
373
|
+
const bv = obj(b[field]), nv = obj(now[field]);
|
|
374
|
+
const res = {};
|
|
375
|
+
for (const [k, at] of Object.entries(bv))
|
|
376
|
+
if (isTime(at))
|
|
377
|
+
res[k] = at;
|
|
378
|
+
for (const [k, at] of Object.entries(nv)) {
|
|
379
|
+
if (k in res) {
|
|
380
|
+
if (same(at, res[k]))
|
|
381
|
+
continue;
|
|
382
|
+
keys.push(`${field}.${k} ${!isTime(at) ? lifted : at < res[k] ? (field === "denied" ? "backdated" : lifted) : "moved later"}`);
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
if ((keepAdded(k) || noesHere.has(`${field}:${k}`)) && isTime(at)) {
|
|
386
|
+
res[k] = Math.min(at, Date.now());
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
if (k in bv && same(bv[k], at))
|
|
390
|
+
continue;
|
|
391
|
+
keys.push(`${field}.${k} added (taken back)`);
|
|
392
|
+
}
|
|
393
|
+
for (const k of Object.keys(res))
|
|
394
|
+
if (!(k in nv))
|
|
395
|
+
keys.push(`${field}.${k} ${field === "denied" ? "removed" : lifted}`);
|
|
396
|
+
return res;
|
|
397
|
+
};
|
|
398
|
+
out.denied = dated("denied", "backdated", (cap) => cap === "unsandboxed_runs");
|
|
313
399
|
const bk = obj(b.asks), nk = obj(now.asks);
|
|
314
400
|
const pending = {};
|
|
401
|
+
const askAct = (q) => (q && typeof q === "object" && typeof q.act === "string" ? q.act : "");
|
|
315
402
|
for (const [cap, q] of Object.entries(nk)) {
|
|
316
403
|
if (!(cap in bk)) {
|
|
404
|
+
if (mine("cap", cap, q)) {
|
|
405
|
+
pending[cap] = q;
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
317
408
|
keys.push(`asks.${cap} added`);
|
|
318
409
|
continue;
|
|
319
410
|
}
|
|
320
411
|
if (!same(bk[cap], q)) {
|
|
412
|
+
if (mine("cap", cap, q)) {
|
|
413
|
+
pending[cap] = q;
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
321
416
|
keys.push(`asks.${cap} changed`);
|
|
322
417
|
pending[cap] = bk[cap];
|
|
323
418
|
continue;
|
|
324
419
|
}
|
|
325
420
|
pending[cap] = q;
|
|
326
421
|
}
|
|
422
|
+
for (const [cap, q] of Object.entries(bk)) {
|
|
423
|
+
if (cap in nk || withdrawnHere.has(askAct(q)))
|
|
424
|
+
continue;
|
|
425
|
+
pending[cap] = q;
|
|
426
|
+
keys.push(`asks.${cap} removed`);
|
|
427
|
+
}
|
|
327
428
|
if ("asks" in now || Object.keys(pending).length)
|
|
328
429
|
out.asks = pending;
|
|
329
430
|
const bo = obj(b.wakeOnce), no = obj(now.wakeOnce);
|
|
@@ -340,21 +441,12 @@ export function narrowPolicy(before, now, keepAsks = askedHere) {
|
|
|
340
441
|
}
|
|
341
442
|
if ("wakeOnce" in now || Object.keys(once).length)
|
|
342
443
|
out.wakeOnce = once;
|
|
343
|
-
const
|
|
344
|
-
const wakeNo = { ...nn };
|
|
345
|
-
for (const [k, at] of Object.entries(nn))
|
|
346
|
-
wakeNo[k] = capAt(at, bn[k]);
|
|
347
|
-
for (const [k, at] of Object.entries(bn)) {
|
|
348
|
-
if (!(k in nn) || (typeof at === "number" && typeof nn[k] === "number" && nn[k] < at)) {
|
|
349
|
-
wakeNo[k] = at;
|
|
350
|
-
keys.push(`wakeNo.${k} lifted`);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
444
|
+
const wakeNo = dated("wakeNo", "lifted");
|
|
353
445
|
const ba = obj(b.wakeAsks), na = obj(now.wakeAsks);
|
|
354
446
|
const asks = {};
|
|
355
447
|
for (const [id, q] of Object.entries(na)) {
|
|
356
448
|
if (!(id in ba)) {
|
|
357
|
-
if (
|
|
449
|
+
if (mine("wake", id, q)) {
|
|
358
450
|
asks[id] = q;
|
|
359
451
|
continue;
|
|
360
452
|
}
|
|
@@ -362,12 +454,22 @@ export function narrowPolicy(before, now, keepAsks = askedHere) {
|
|
|
362
454
|
continue;
|
|
363
455
|
}
|
|
364
456
|
if (!same(ba[id], q)) {
|
|
457
|
+
if (mine("wake", id, q)) {
|
|
458
|
+
asks[id] = q;
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
365
461
|
keys.push(`wakeAsks.${id} changed`);
|
|
366
462
|
asks[id] = ba[id];
|
|
367
463
|
continue;
|
|
368
464
|
}
|
|
369
465
|
asks[id] = q;
|
|
370
466
|
}
|
|
467
|
+
for (const [id, q] of Object.entries(ba)) {
|
|
468
|
+
if (id in na || withdrawnHere.has(id))
|
|
469
|
+
continue;
|
|
470
|
+
asks[id] = q;
|
|
471
|
+
keys.push(`wakeAsks.${id} removed`);
|
|
472
|
+
}
|
|
371
473
|
if ("wakeAsks" in now || Object.keys(asks).length)
|
|
372
474
|
out.wakeAsks = asks;
|
|
373
475
|
for (const f of ["wakersCarried", "wakersDeferred"]) {
|
|
@@ -398,15 +500,24 @@ export function narrowPolicy(before, now, keepAsks = askedHere) {
|
|
|
398
500
|
if ("wakeNo" in now || Object.keys(wakeNo).length)
|
|
399
501
|
out.wakeNo = wakeNo;
|
|
400
502
|
const bfn = new Set(Array.isArray(b.finalNo) ? b.finalNo.filter((k) => typeof k === "string") : []);
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
503
|
+
const fn = Array.isArray(now.finalNo) ? now.finalNo.filter((k) => typeof k === "string") : [];
|
|
504
|
+
const keptFinal = fn.filter((k) => bfn.has(k));
|
|
505
|
+
for (const k of new Set(fn.filter((k) => !bfn.has(k))))
|
|
506
|
+
keys.push(`finalNo.${k} added (taken back)`);
|
|
507
|
+
const lostFinal = [...bfn].filter((k) => !fn.includes(k));
|
|
508
|
+
for (const k of lostFinal)
|
|
509
|
+
keys.push(`finalNo.${k} removed`);
|
|
510
|
+
if (Array.isArray(now.finalNo) || bfn.size)
|
|
511
|
+
out.finalNo = [...keptFinal, ...lostFinal];
|
|
405
512
|
const bs = obj(b.stuckReports), ns = obj(now.stuckReports);
|
|
406
513
|
if ("stuckReports" in now) {
|
|
407
514
|
const kept = {};
|
|
408
515
|
for (const [id, r] of Object.entries(ns)) {
|
|
409
516
|
if (!(id in bs)) {
|
|
517
|
+
if (mine("stuck", id, r)) {
|
|
518
|
+
kept[id] = r;
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
410
521
|
keys.push(`stuckReports.${id} added`);
|
|
411
522
|
continue;
|
|
412
523
|
}
|
|
@@ -419,6 +530,26 @@ export function narrowPolicy(before, now, keepAsks = askedHere) {
|
|
|
419
530
|
}
|
|
420
531
|
out.stuckReports = kept;
|
|
421
532
|
}
|
|
533
|
+
{
|
|
534
|
+
const bsn = obj(b.safetyNotes), nsn = obj(now.safetyNotes);
|
|
535
|
+
const notes = {};
|
|
536
|
+
for (const [k, v] of Object.entries(nsn)) {
|
|
537
|
+
if (k in bsn ? same(bsn[k], v) : mine("safety", k, v)) {
|
|
538
|
+
notes[k] = v;
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
keys.push(`safetyNotes.${k} ${k in bsn ? "changed" : "added"}`);
|
|
542
|
+
if (k in bsn)
|
|
543
|
+
notes[k] = bsn[k];
|
|
544
|
+
}
|
|
545
|
+
for (const [k, v] of Object.entries(bsn))
|
|
546
|
+
if (!(k in nsn)) {
|
|
547
|
+
notes[k] = v;
|
|
548
|
+
keys.push(`safetyNotes.${k} removed`);
|
|
549
|
+
}
|
|
550
|
+
if ("safetyNotes" in now || Object.keys(notes).length)
|
|
551
|
+
out.safetyNotes = notes;
|
|
552
|
+
}
|
|
422
553
|
const minutes = (x) => (typeof x === "number" && Number.isInteger(x) && x >= RUN_MINUTES_MIN && x <= RUN_MINUTES_MAX ? x : RUN_MINUTES_DEFAULT);
|
|
423
554
|
if (!same(b.runMinutes, now.runMinutes) && minutes(now.runMinutes) > minutes(b.runMinutes)) {
|
|
424
555
|
if ("runMinutes" in b)
|
|
@@ -594,7 +725,7 @@ export function narrowPins(before, now) {
|
|
|
594
725
|
}
|
|
595
726
|
return { value: { ...n, v: 1, teams }, keys };
|
|
596
727
|
}
|
|
597
|
-
export function narrowNonces(before, now) {
|
|
728
|
+
export function narrowNonces(before, now, released = new Set()) {
|
|
598
729
|
const b = obj(before), n = obj(now);
|
|
599
730
|
const out = { ...n };
|
|
600
731
|
let lost = 0;
|
|
@@ -602,8 +733,10 @@ export function narrowNonces(before, now) {
|
|
|
602
733
|
const cur = { ...obj(n[team]) };
|
|
603
734
|
const forward = (c, w) => same(c, w) || (Array.isArray(c) && Array.isArray(w) && c[0] === w[0] && c[1] === w[1]
|
|
604
735
|
&& (c[2] ?? null) === (w[2] ?? null) && typeof c[3] === "number" && (w[3] === undefined || w[3] === c[3]));
|
|
736
|
+
const ownTakeBack = (c, w) => Array.isArray(c) && Array.isArray(w) && typeof w[0] === "string" && released.has(`${team}|${w[0]}`)
|
|
737
|
+
&& c[0] === w[0] && c[1] === w[1] && (c[2] ?? null) === (w[2] ?? null) && c[3] === undefined;
|
|
605
738
|
for (const [k, v] of Object.entries(obj(entries)))
|
|
606
|
-
if (!(k in cur) || !forward(cur[k], v)) {
|
|
739
|
+
if (!(k in cur) || (!forward(cur[k], v) && !ownTakeBack(cur[k], v))) {
|
|
607
740
|
cur[k] = v;
|
|
608
741
|
lost++;
|
|
609
742
|
}
|
|
@@ -669,8 +802,65 @@ export function restoreHome(s) {
|
|
|
669
802
|
}
|
|
670
803
|
for (const f of s.files)
|
|
671
804
|
runBaseline.delete(resolve(join(s.home, f.rel)));
|
|
805
|
+
const releasedOwn = (() => {
|
|
806
|
+
const snap = s.files.find((f) => f.rel === CONTINUED_FILE);
|
|
807
|
+
try {
|
|
808
|
+
return ownReleases(parse(snap?.bytes ?? null), parse(read(join(s.home, CONTINUED_FILE))), s.at ?? Date.now());
|
|
809
|
+
}
|
|
810
|
+
catch {
|
|
811
|
+
return new Set();
|
|
812
|
+
}
|
|
813
|
+
})();
|
|
814
|
+
if (s.at !== undefined && !s.queueDone) {
|
|
815
|
+
const gone = sweepActionQueue(s.home, { maxAgeMs: 30_000, since: s.at - 1_000 });
|
|
816
|
+
if (gone)
|
|
817
|
+
out.push({ rel: HUD_QUEUE_DIR, what: "removed", keys: [`${gone} queued menu-bar action${gone === 1 ? "" : "s"} — one you clicked while it ran: click it again`] });
|
|
818
|
+
}
|
|
672
819
|
for (const f of s.files) {
|
|
673
820
|
const file = join(s.home, f.rel);
|
|
821
|
+
if (f.rel.includes("/"))
|
|
822
|
+
makeWritable(dirname(file), false);
|
|
823
|
+
const linkNow = linkOf(file);
|
|
824
|
+
if (linkNow !== f.link) {
|
|
825
|
+
try {
|
|
826
|
+
const through = read(file);
|
|
827
|
+
const ownWrite = f.link !== undefined && linkNow === undefined && !!through && !!trusted.get(resolve(file))?.has(sha(through));
|
|
828
|
+
makeWritable(file);
|
|
829
|
+
rmSync(file, { force: true });
|
|
830
|
+
if (f.link !== undefined) {
|
|
831
|
+
symlinkSync(f.link, file);
|
|
832
|
+
if (ownWrite) {
|
|
833
|
+
try {
|
|
834
|
+
writeFileSync(file, through);
|
|
835
|
+
}
|
|
836
|
+
catch { }
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
else if (through)
|
|
840
|
+
putWhole(file, through);
|
|
841
|
+
if (!ownWrite)
|
|
842
|
+
out.push({ rel: f.rel, what: "reverted", keys: [linkNow !== undefined ? "a link in place of the file" : "its link replaced by a file"] });
|
|
843
|
+
}
|
|
844
|
+
catch {
|
|
845
|
+
out.push({ rel: f.rel, what: "reported", keys: ["(could not be put back — unattended runs are held until it is writable again)"], failed: true });
|
|
846
|
+
continue;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
const putKept = (text) => {
|
|
850
|
+
if (f.link !== undefined && linkOf(file) === f.link) {
|
|
851
|
+
try {
|
|
852
|
+
writeFileSync(file, text);
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
catch { }
|
|
856
|
+
}
|
|
857
|
+
try {
|
|
858
|
+
if (lstatSync(file).isSymbolicLink())
|
|
859
|
+
rmSync(file, { force: true });
|
|
860
|
+
}
|
|
861
|
+
catch { }
|
|
862
|
+
putWhole(file, text);
|
|
863
|
+
};
|
|
674
864
|
const now = read(file);
|
|
675
865
|
const hashNow = now ? sha(now) : null;
|
|
676
866
|
if (hashNow === f.hash)
|
|
@@ -678,6 +868,7 @@ export function restoreHome(s) {
|
|
|
678
868
|
const alwaysNarrow = f.rel === POLICY_FILE || f.rel === PROFILE_FILE || f.rel === CONFIG_FILE || f.rel === CONTINUED_FILE || f.rel === CURSOR_FILE || f.rel === PINS_FILE || f.rel === NONCES_FILE || f.rel === PENDING_CHANGES_FILE || f.rel === CHANGES_LOG_FILE || f.rel === RUN_CONTROL_FILE || f.rel === HUD_PREF_FILE;
|
|
679
869
|
if (!alwaysNarrow && trusted.get(resolve(file))?.has(hashNow ?? "absent"))
|
|
680
870
|
continue;
|
|
871
|
+
makeWritable(file);
|
|
681
872
|
try {
|
|
682
873
|
if (f.rel === HUD_FILE) {
|
|
683
874
|
if (now) {
|
|
@@ -691,7 +882,7 @@ export function restoreHome(s) {
|
|
|
691
882
|
rmSync(file, { recursive: true, force: true });
|
|
692
883
|
}
|
|
693
884
|
catch { }
|
|
694
|
-
if (f.rel === AGENT_TOKENS_FILE || f.rel === SIGNED_OUT_FILE) {
|
|
885
|
+
if (f.rel === AGENT_TOKENS_FILE || f.rel === SIGNED_OUT_FILE || f.rel === SIGNED_OUT_SALT_FILE) {
|
|
695
886
|
try {
|
|
696
887
|
if (lstatSync(file).isSymbolicLink())
|
|
697
888
|
rmSync(file, { force: true });
|
|
@@ -706,7 +897,7 @@ export function restoreHome(s) {
|
|
|
706
897
|
writeWhole(file, f.bytes.toString("utf8"));
|
|
707
898
|
else
|
|
708
899
|
rmSync(file, { force: true });
|
|
709
|
-
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 } : {}) });
|
|
900
|
+
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 || f.rel === SIGNED_OUT_SALT_FILE ? { quiet: true } : {}) });
|
|
710
901
|
continue;
|
|
711
902
|
}
|
|
712
903
|
if (f.rel === CHANGES_LOG_FILE) {
|
|
@@ -723,7 +914,7 @@ export function restoreHome(s) {
|
|
|
723
914
|
const added = (is.startsWith(was) ? is.slice(was.length).split("\n") : is.split("\n").filter((l) => !old.has(l))).filter((l) => l.trim());
|
|
724
915
|
const planted = added.filter(firstSetup).length;
|
|
725
916
|
if (f.bytes)
|
|
726
|
-
|
|
917
|
+
putWhole(file, f.bytes);
|
|
727
918
|
else
|
|
728
919
|
rmSync(file, { force: true });
|
|
729
920
|
trustWrite(file);
|
|
@@ -753,16 +944,35 @@ export function restoreHome(s) {
|
|
|
753
944
|
writeWhole(file, JSON.stringify(next));
|
|
754
945
|
}
|
|
755
946
|
catch {
|
|
756
|
-
|
|
947
|
+
putWhole(file, JSON.stringify(next));
|
|
757
948
|
}
|
|
758
949
|
trustWrite(file);
|
|
759
950
|
out.push({ rel: f.rel, what: "reverted", keys: ["where questions open"] });
|
|
760
951
|
continue;
|
|
761
952
|
}
|
|
953
|
+
if (f.rel === APPROVALS_LIST_FILE) {
|
|
954
|
+
try {
|
|
955
|
+
if (lstatSync(file).isSymbolicLink() || !statSync(file).isFile())
|
|
956
|
+
rmSync(file, { recursive: true, force: true });
|
|
957
|
+
}
|
|
958
|
+
catch { }
|
|
959
|
+
const bl = obj(obj(a).lists), nl = obj(obj(parse(read(file))).lists);
|
|
960
|
+
const kept = Object.fromEntries(Object.entries(nl).filter(([k, l]) => k in bl && same(bl[k], l)));
|
|
961
|
+
const dropped = Object.keys(nl).length - Object.keys(kept).length;
|
|
962
|
+
try {
|
|
963
|
+
writeWhole(file, JSON.stringify({ v: 2, lists: kept }) + "\n");
|
|
964
|
+
}
|
|
965
|
+
catch {
|
|
966
|
+
putWhole(file, JSON.stringify({ v: 2, lists: kept }) + "\n");
|
|
967
|
+
}
|
|
968
|
+
trustWrite(file);
|
|
969
|
+
out.push({ rel: f.rel, what: "reverted", keys: dropped ? [`${dropped} numbered approvals list${dropped === 1 ? "" : "s"} — list again`] : [], quiet: true });
|
|
970
|
+
continue;
|
|
971
|
+
}
|
|
762
972
|
if (f.rel === RUN_CONTROL_FILE) {
|
|
763
973
|
const n = narrowRunControl(a, b);
|
|
764
974
|
if (n.keys.length) {
|
|
765
|
-
|
|
975
|
+
putWhole(file, JSON.stringify(n.value, null, 2) + "\n");
|
|
766
976
|
trustWrite(file);
|
|
767
977
|
out.push({ rel: f.rel, what: "reverted", keys: n.keys });
|
|
768
978
|
}
|
|
@@ -771,7 +981,7 @@ export function restoreHome(s) {
|
|
|
771
981
|
if (f.rel === PENDING_CHANGES_FILE) {
|
|
772
982
|
const n = narrowPending(a, b);
|
|
773
983
|
if (n.keys.length) {
|
|
774
|
-
|
|
984
|
+
putWhole(file, JSON.stringify(n.value, null, 2) + "\n");
|
|
775
985
|
trustWrite(file);
|
|
776
986
|
out.push({ rel: f.rel, what: "reverted", keys: n.keys });
|
|
777
987
|
}
|
|
@@ -780,17 +990,18 @@ export function restoreHome(s) {
|
|
|
780
990
|
if (f.rel === POLICY_FILE) {
|
|
781
991
|
if (!b) {
|
|
782
992
|
if (f.bytes) {
|
|
783
|
-
|
|
993
|
+
putWhole(file, f.bytes);
|
|
784
994
|
out.push({ rel: f.rel, what: "reverted", keys: ["(the whole file)"] });
|
|
785
995
|
}
|
|
786
996
|
continue;
|
|
787
997
|
}
|
|
788
998
|
const n = narrowPolicy(a, b);
|
|
789
|
-
if (n.keys.length) {
|
|
790
|
-
|
|
999
|
+
if (n.keys.length || !same(n.policy, b)) {
|
|
1000
|
+
putKept(JSON.stringify(n.policy, null, 2) + "\n");
|
|
791
1001
|
trustWrite(file);
|
|
792
|
-
out.push({ rel: f.rel, what: "reverted", keys: n.keys });
|
|
793
1002
|
}
|
|
1003
|
+
if (n.keys.length)
|
|
1004
|
+
out.push({ rel: f.rel, what: "reverted", keys: n.keys });
|
|
794
1005
|
continue;
|
|
795
1006
|
}
|
|
796
1007
|
const locked = (fn) => {
|
|
@@ -810,7 +1021,7 @@ export function restoreHome(s) {
|
|
|
810
1021
|
writeWhole(file, text);
|
|
811
1022
|
}
|
|
812
1023
|
catch {
|
|
813
|
-
|
|
1024
|
+
putWhole(file, text);
|
|
814
1025
|
} };
|
|
815
1026
|
if (f.rel === RECHECK_FILE || f.rel === READINESS_ALERT_FILE) {
|
|
816
1027
|
try {
|
|
@@ -839,7 +1050,7 @@ export function restoreHome(s) {
|
|
|
839
1050
|
if (f.rel === PINS_FILE || f.rel === NONCES_FILE) {
|
|
840
1051
|
locked(() => {
|
|
841
1052
|
const cur = parse(read(file));
|
|
842
|
-
const n = f.rel === PINS_FILE ? narrowPins(a, cur) : narrowNonces(a, cur);
|
|
1053
|
+
const n = f.rel === PINS_FILE ? narrowPins(a, cur) : narrowNonces(a, cur, releasedOwn);
|
|
843
1054
|
if (n.keys.length) {
|
|
844
1055
|
put(JSON.stringify(n.value, null, 2) + "\n");
|
|
845
1056
|
trustWrite(file);
|
|
@@ -861,14 +1072,33 @@ export function restoreHome(s) {
|
|
|
861
1072
|
}
|
|
862
1073
|
}
|
|
863
1074
|
else if (Array.isArray(v)) {
|
|
1075
|
+
if (k.endsWith(" inflight"))
|
|
1076
|
+
continue;
|
|
864
1077
|
const cur = Array.isArray(now[k]) ? now[k] : [];
|
|
865
|
-
const back = v.filter((x) => !cur.includes(x));
|
|
1078
|
+
const back = v.filter((x) => !cur.includes(x) && !(typeof x === "string" && x.startsWith("handled:") && releasedOwn.has(`${k}|${x.slice("handled:".length)}`)));
|
|
866
1079
|
if (back.length) {
|
|
867
1080
|
merged[k] = [...back, ...cur];
|
|
868
1081
|
lost += back.length;
|
|
869
1082
|
}
|
|
870
1083
|
}
|
|
871
1084
|
}
|
|
1085
|
+
let planted = 0;
|
|
1086
|
+
if (f.rel === CONTINUED_FILE)
|
|
1087
|
+
for (const [k, v] of Object.entries(merged)) {
|
|
1088
|
+
if (!Array.isArray(v))
|
|
1089
|
+
continue;
|
|
1090
|
+
const was = new Set(Array.isArray(before[k]) ? before[k] : []);
|
|
1091
|
+
const kept = v.filter((x) => !(typeof x === "string" && WORKER_MARK.test(x) && !was.has(x) && !markedHere.has(x)));
|
|
1092
|
+
if (kept.length !== v.length) {
|
|
1093
|
+
merged[k] = kept;
|
|
1094
|
+
planted += v.length - kept.length;
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
if (planted) {
|
|
1098
|
+
put(JSON.stringify(merged) + "\n");
|
|
1099
|
+
trustWrite(file);
|
|
1100
|
+
out.push({ rel: f.rel, what: "reverted", keys: [`${planted} worker mark${planted === 1 ? "" : "s"} added during the run`] });
|
|
1101
|
+
}
|
|
872
1102
|
let sentDropped = 0;
|
|
873
1103
|
if (f.rel === CONTINUED_FILE)
|
|
874
1104
|
for (const [k, v] of Object.entries(merged)) {
|
|
@@ -898,7 +1128,7 @@ export function restoreHome(s) {
|
|
|
898
1128
|
continue;
|
|
899
1129
|
const n = narrowProfile(a, b);
|
|
900
1130
|
if (n.keys.length) {
|
|
901
|
-
|
|
1131
|
+
putKept(JSON.stringify(n.profile, null, 2) + "\n");
|
|
902
1132
|
trustWrite(file);
|
|
903
1133
|
out.push({ rel: f.rel, what: "reverted", keys: n.keys });
|
|
904
1134
|
}
|
|
@@ -916,7 +1146,7 @@ export function restoreHome(s) {
|
|
|
916
1146
|
n.keys.push(said);
|
|
917
1147
|
}
|
|
918
1148
|
if (n.keys.length) {
|
|
919
|
-
|
|
1149
|
+
putKept(JSON.stringify(n.config, null, 2) + "\n");
|
|
920
1150
|
trustWrite(file);
|
|
921
1151
|
out.push({ rel: f.rel, what: "reverted", keys: n.keys });
|
|
922
1152
|
}
|
|
@@ -928,7 +1158,7 @@ export function restoreHome(s) {
|
|
|
928
1158
|
out.push({ rel: f.rel, what: "reported", keys: ["unreadable since the run — Pantheon could not put it back; check it (pantheon status)"] });
|
|
929
1159
|
}
|
|
930
1160
|
else if (a && !b && now) {
|
|
931
|
-
|
|
1161
|
+
putWhole(file, f.bytes);
|
|
932
1162
|
trustWrite(file);
|
|
933
1163
|
out.push({ rel: f.rel, what: "reverted", keys: ["(the whole file)"] });
|
|
934
1164
|
}
|
|
@@ -936,11 +1166,63 @@ export function restoreHome(s) {
|
|
|
936
1166
|
out.push({ rel: f.rel, what: "reported", keys: [] });
|
|
937
1167
|
}
|
|
938
1168
|
catch {
|
|
939
|
-
out.push({ rel: f.rel, what: "reported", keys: ["(could not be
|
|
1169
|
+
out.push({ rel: f.rel, what: "reported", keys: ["(could not be put back — unattended runs are held until it is writable again)"], failed: true });
|
|
940
1170
|
}
|
|
941
1171
|
}
|
|
942
1172
|
return out;
|
|
943
1173
|
}
|
|
1174
|
+
function putWhole(file, data) {
|
|
1175
|
+
const tmp = `${file}.${process.pid}.${Date.now().toString(36)}.guard.tmp`;
|
|
1176
|
+
try {
|
|
1177
|
+
writeFileSync(tmp, data, { mode: 0o600, flag: "wx" });
|
|
1178
|
+
renameSync(tmp, file);
|
|
1179
|
+
}
|
|
1180
|
+
catch {
|
|
1181
|
+
try {
|
|
1182
|
+
rmSync(tmp, { force: true });
|
|
1183
|
+
}
|
|
1184
|
+
catch { }
|
|
1185
|
+
writeFileSync(file, data, { mode: 0o600 });
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
function makeWritable(file, deep = true) {
|
|
1189
|
+
let st;
|
|
1190
|
+
try {
|
|
1191
|
+
st = lstatSync(file);
|
|
1192
|
+
}
|
|
1193
|
+
catch {
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
if (st.isSymbolicLink())
|
|
1197
|
+
return;
|
|
1198
|
+
const dir = st.isDirectory() && deep;
|
|
1199
|
+
const quiet = { stdio: "ignore", timeout: 5_000 };
|
|
1200
|
+
if (process.platform === "darwin") {
|
|
1201
|
+
try {
|
|
1202
|
+
execFileSync("chflags", [...(dir ? ["-R"] : []), "nouchg,nouappnd", file], quiet);
|
|
1203
|
+
}
|
|
1204
|
+
catch { }
|
|
1205
|
+
try {
|
|
1206
|
+
execFileSync("chmod", [...(dir ? ["-R"] : []), "-N", file], quiet);
|
|
1207
|
+
}
|
|
1208
|
+
catch { }
|
|
1209
|
+
}
|
|
1210
|
+
else if (process.platform === "linux") {
|
|
1211
|
+
try {
|
|
1212
|
+
execFileSync("setfacl", [...(dir ? ["-R"] : []), "-b", file], quiet);
|
|
1213
|
+
}
|
|
1214
|
+
catch { }
|
|
1215
|
+
}
|
|
1216
|
+
try {
|
|
1217
|
+
execFileSync("chmod", [...(dir ? ["-R"] : []), "u+rwX", file], quiet);
|
|
1218
|
+
}
|
|
1219
|
+
catch {
|
|
1220
|
+
try {
|
|
1221
|
+
chmodSync(file, st.isDirectory() ? 0o700 : 0o600);
|
|
1222
|
+
}
|
|
1223
|
+
catch { }
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
944
1226
|
export function describeChange(c) {
|
|
945
1227
|
if (c.what === "removed")
|
|
946
1228
|
return `${c.rel} was written while the run could write it — removed, not acted on`;
|