@join-pantheon/cli 0.35.0 → 0.35.1-rc.1

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.
Files changed (51) hide show
  1. package/dist/agent-outage.js +156 -36
  2. package/dist/agent-token.js +5 -3
  3. package/dist/approvals-list.js +87 -0
  4. package/dist/board.js +472 -87
  5. package/dist/brief.js +17 -0
  6. package/dist/cli.js +687 -95
  7. package/dist/client.js +159 -19
  8. package/dist/config.js +3 -2
  9. package/dist/continued.js +56 -1
  10. package/dist/decision-ui.js +5 -3
  11. package/dist/doctor.js +81 -15
  12. package/dist/file-lock.js +39 -4
  13. package/dist/flow-stats.js +18 -1
  14. package/dist/home-guard.js +317 -54
  15. package/dist/home-safety.js +2 -0
  16. package/dist/hud-queue.js +91 -0
  17. package/dist/install.js +15 -1
  18. package/dist/mcp-instructions.js +55 -20
  19. package/dist/mcp.js +114 -24
  20. package/dist/notice-linux.js +15 -4
  21. package/dist/notice-windows.js +2 -2
  22. package/dist/notifier.js +2 -1
  23. package/dist/notify.js +8 -4
  24. package/dist/open-in.js +4 -3
  25. package/dist/pickup.js +17 -0
  26. package/dist/plain.js +139 -3
  27. package/dist/profile.js +12 -8
  28. package/dist/protocol.js +1 -1
  29. package/dist/question-goal.js +74 -0
  30. package/dist/readiness-alert.js +24 -3
  31. package/dist/refusal.js +2 -2
  32. package/dist/relay.js +142 -28
  33. package/dist/removed.js +4 -4
  34. package/dist/run-control.js +4 -3
  35. package/dist/run-failure.js +67 -10
  36. package/dist/setup-changes.js +7 -6
  37. package/dist/signed-out.js +144 -21
  38. package/dist/spend.js +2 -2
  39. package/dist/tray.js +24 -6
  40. package/dist/update-check.js +2 -1
  41. package/dist/uri-handler.js +10 -2
  42. package/dist/which.js +2 -0
  43. package/dist/worker-policy.js +212 -10
  44. package/dist/worker.js +847 -114
  45. package/dist/worklist.js +31 -1
  46. package/helper/macos/main.swift +42 -3
  47. package/helper/macos/menubar.swift +482 -87
  48. package/helper/macos/prebuilt/manifest.json +5 -5
  49. package/helper/macos/prebuilt/pantheon-hud +0 -0
  50. package/helper/macos/prebuilt/pantheon-tray +0 -0
  51. package/package.json +1 -1
package/dist/relay.js CHANGED
@@ -434,6 +434,13 @@ function actSigProblem(m, member, memberPub, teams, delegated) {
434
434
  }), sig.s));
435
435
  return ok ? null : "the signature does not match this act";
436
436
  }
437
+ function kindFromOpening(sig, said) {
438
+ if (sig && typeof sig === "object" && "kind" in sig) {
439
+ const k = sig.kind;
440
+ return k === "worklist" || k === "question" ? k : null;
441
+ }
442
+ return said === "worklist" ? "worklist" : null;
443
+ }
437
444
  function goalSigProblem(m, member, memberPub, teams, delegated) {
438
445
  const sig = m.sig;
439
446
  if (!sig)
@@ -524,7 +531,10 @@ export function deletedWords(t) {
524
531
  const coveredNameWords = (name) => `the name "${name}" belongs to a deleted team whose files are still here; the relay operator can move them to quarantine, or use a different name.`;
525
532
  const invitesHeldWords = (name) => `invites to "${name}" cannot be used right now: a team of this name was deleted on this relay, and the relay cannot tell this one apart from it. Ask the team's founder or the relay operator.`;
526
533
  const deletedNameWords = (name) => `the space "${name}" was deleted. Start a new one with a different name, or contact the relay operator.`;
527
- const removedWords = (member, name, by) => `"${member}" was removed from "${name}"${by ? ` by ${by}` : ""}. Only a member of the team can let you back in.`;
534
+ const backInWords = (founder) => founder ? `Only a member who founded the team can let you back in — that is ${founder}` : "Only a member of the team can let you back in";
535
+ const removedWords = (member, name, by) => `"${member}" was removed from "${name}"${by ? ` by ${by}` : ""}. Only a member who founded the team can let you back in.`;
536
+ export const revokedWords = (member, name, by, founder) => `"${member}" was removed from "${name}"${by ? ` by ${by}` : ""}. ${backInWords(founder)} (pantheon admit ${member}); until then this machine cannot read or send in it.`;
537
+ export const RUN_OPEN_DECISIONS = 3;
528
538
  export class Relay {
529
539
  opts;
530
540
  advertisedPkg() { return advertisedPkg(this.upgradeHold, VERSION); }
@@ -2309,7 +2319,7 @@ Sign in with a code sent to this address at /view on the relay.`).catch(() => fa
2309
2319
  return { status: 409, body: { reason: "unbound", error: `"${name}" has no team token yet (it was made by an old relay): a member has to connect to it once from a machine that already has it, then the seat can be moved` } };
2310
2320
  const known = seat.publicKey === device.pubkey || roster.recoveryOf(u)?.pubkey === device.pubkey;
2311
2321
  if (!known) {
2312
- const refused = this.recoveryProofRefusal(A, acct, device, name, seat, roster.founder() === u);
2322
+ const refused = this.recoveryProofRefusal(A, acct, device, name, seat, roster.founder() === u, roster.founder());
2313
2323
  if (refused)
2314
2324
  return refused;
2315
2325
  }
@@ -2334,7 +2344,7 @@ Sign in with a code sent to this address at /view on the relay.`).catch(() => fa
2334
2344
  }
2335
2345
  return { status: 202, body: { state: "waiting", space: sp.name, due_at: pend.due_at, fp: pend.fp, others: this.othersIn(sp, u) } };
2336
2346
  }
2337
- const again = this.recoveryProofRefusal(A, acct, device, sp.name, e, sp.allow.founder() === u);
2347
+ const again = this.recoveryProofRefusal(A, acct, device, sp.name, e, sp.allow.founder() === u, sp.allow.founder());
2338
2348
  if (again)
2339
2349
  return again;
2340
2350
  const oldFp = fingerprint(e.publicKey);
@@ -2367,7 +2377,7 @@ Sign in with a code sent to this address at /view on the relay.`).catch(() => fa
2367
2377
  this.broadcast(sp, { t: "members", members: this.members(sp) });
2368
2378
  return { status: 202, body: { state: "waiting", space: sp.name, due_at: r.due_at, fp: r.fp, others } };
2369
2379
  }
2370
- recoveryProofRefusal(A, acct, device, name, seat, founder) {
2380
+ recoveryProofRefusal(A, acct, device, name, seat, founder, teamFounder = null) {
2371
2381
  const proof = A.lastEmailProof(acct.id, device.fingerprint);
2372
2382
  if (!proof || Date.now() - proof > RECOVERY_PROOF_MS) {
2373
2383
  return { status: 403, body: { reason: "sign_in_again", error: `first prove it is you: run pantheon recover ${quoteTeam(name)} in a terminal (it emails a code to ${acct.email} and asks for it), or sign in with pantheon signin and within ${RECOVERY_PROOF_MS / 60_000} minutes run pantheon recover ${quoteTeam(name)} again` } };
@@ -2376,7 +2386,8 @@ Sign in with a code sent to this address at /view on the relay.`).catch(() => fa
2376
2386
  if (!A.wasDeviceOf(acct.id, oldFp, seat.moved?.at ?? seat.first_seen)) {
2377
2387
  this.log(`[${name}] ! recovery refused for ${acct.username}: the seat's key ${oldFp} was not a device of their account when the seat was taken`);
2378
2388
  return { status: 403, body: { reason: "unproven", error: `the key holding your seat in "${name}" (${oldFp}) was not signed in to this account when the seat was taken (an account deleted and made again is a new account, and records over a year old are gone), so the relay cannot tell it was yours. ` +
2379
- (founder ? `A founder's seat cannot be handed over any other way: start a new team (pantheon start) and invite your teammates to it.` : `A teammate who has checked it is you can retire it instead (pantheon admit ${acct.username} --forget) and invite you again.`) } };
2389
+ (founder ? `A founder's seat cannot be handed over any other way: start a new team (pantheon start) and invite your teammates to it.` :
2390
+ `${teamFounder ? `${teamFounder}, who founded "${name}",` : "A teammate"} can retire it instead, once they have checked it is you (pantheon admit ${acct.username} --forget), and invite you again.`) } };
2380
2391
  }
2381
2392
  return null;
2382
2393
  }
@@ -2520,7 +2531,7 @@ Sign in with a code sent to this address at /view on the relay.`).catch(() => fa
2520
2531
  if (!pub && reader && Number.isFinite(ts) && Math.abs(Date.now() - ts) < LIMITS.activityFreshMs && !signed.dpub) {
2521
2532
  const e = target.allow.get(reader);
2522
2533
  if (e && !e.admitted && e.revoked_at && e.publicKey && verifyRead(e.publicKey, req.method ?? "GET", url.pathname, signed, sig)) {
2523
- return { ok: false, status: 403, code: "REVOKED", error: `"${reader}" was removed from "${name}"${e.revoked_by ? ` by ${e.revoked_by}` : ""}. Only a member of the team can let you back in.` };
2534
+ return { ok: false, status: 403, code: "REVOKED", error: revokedWords(reader, name, e.revoked_by, target.allow.founder()) };
2524
2535
  }
2525
2536
  }
2526
2537
  if (!pub || !Number.isFinite(ts) || Math.abs(Date.now() - ts) >= LIMITS.activityFreshMs)
@@ -4471,7 +4482,7 @@ pantheon start</code></pre>
4471
4482
  const e = sp.allow.get(m.member);
4472
4483
  if (e && e.publicKey === m.pubkey && !e.admitted && e.revoked_at) {
4473
4484
  this.log(`[${sp.name}] ! REFUSED ${m.member}: removed (earlier token)`);
4474
- return reject("REVOKED", `"${m.member}" was removed from "${sp.name}"${e.revoked_by ? ` by ${e.revoked_by}` : ""}. Only a member of the team can let you back in (pantheon admit ${m.member}); until then this machine cannot read or send in it.`);
4485
+ return reject("REVOKED", revokedWords(m.member, sp.name, e.revoked_by, sp.allow.founder()));
4475
4486
  }
4476
4487
  if (!e || e.publicKey !== m.pubkey || !e.admitted) {
4477
4488
  this.log(`[${sp.name}] ! REFUSED ${m.member}: an earlier token, and not an admitted member with this key`);
@@ -4506,12 +4517,12 @@ pantheon start</code></pre>
4506
4517
  ` A founder's key cannot be replaced: if this is really you on another machine, restore your original ~/.pantheon/config.json (the key is in it). Without it, join under another name (--me <new-name>) or start a new team (pantheon start).`));
4507
4518
  }
4508
4519
  return reject("KEY_MISMATCH", `"${m.member}" is already registered here with a different key. If you are someone else, join under your own name (--me <your-name>).` + (recover ||
4509
- ` If this is really you on another machine, an admitted member who has checked it is you runs pantheon admit ${m.member} --forget (it removes whoever holds the name now) and sends you a new invite.`));
4520
+ ` If this is really you on another machine, ${sp.allow.founder() ? `${sp.allow.founder()}, who founded "${sp.name}", checks it is you, then runs` : "an admitted member who has checked it is you runs"} pantheon admit ${m.member} --forget (it removes whoever holds the name now) and sends you a new invite.`));
4510
4521
  }
4511
4522
  if (verdict === "revoked") {
4512
4523
  const e = sp.allow.get(m.member);
4513
4524
  this.log(`[${sp.name}] ! REFUSED ${m.member}: removed${e?.revoked_by ? ` by ${e.revoked_by}` : ""}`);
4514
- return reject("REVOKED", `"${m.member}" was removed from "${sp.name}"${e?.revoked_by ? ` by ${e.revoked_by}` : ""}. Only a member of the team can let you back in (pantheon admit ${m.member}); until then this machine cannot read or send in it.`);
4525
+ return reject("REVOKED", revokedWords(m.member, sp.name, e?.revoked_by, sp.allow.founder()));
4515
4526
  }
4516
4527
  if (verdict === "new" || verdict === "pending") {
4517
4528
  this.log(`[${sp.name}] ? PENDING ${m.member} ${fingerprint(m.pubkey)}`);
@@ -5022,7 +5033,8 @@ pantheon start</code></pre>
5022
5033
  from: me.id, act: "NOTE", to: null, goal: goal.id, ref: null,
5023
5034
  body: `goal opened: ${goal.title}\nacceptance: ${goal.acceptance || "(none stated)"}` +
5024
5035
  (goal.deadline ? `\ndeadline: ${new Date(goal.deadline).toISOString()}` : "") +
5025
- (goal.kind === "worklist" ? `\nkind: worklist — ${me.id}'s own list; peers may read it, nobody owes anything in it` : ""),
5036
+ (goal.kind === "worklist" ? `\nkind: worklist — ${me.id}'s own list; peers may read it, nobody owes anything in it`
5037
+ : goal.kind === "question" ? `\nkind: question — one question and its answer` : ""),
5026
5038
  meta: { goal_members: goal.members, goal_budget: goal.budget, ...(m.sig ? { goal_sig: m.sig, goal_text: { title: goal.title, acceptance: goal.acceptance } } : {}) },
5027
5039
  });
5028
5040
  this.send(ws, { t: "ack", ...(m.cid ? { cid: m.cid } : {}), id: goal.id, seq: rec.seq });
@@ -5088,14 +5100,14 @@ pantheon start</code></pre>
5088
5100
  || (!!m.ref && r.ref === m.ref));
5089
5101
  if (missed.length) {
5090
5102
  return fail("STALE_VIEW", `${missed.length} act(s) arrived while you were composing — read them before you answer:\n` +
5091
- missed.slice(0, 8).map((r) => ` [${r.seq}] ${r.act} from ${r.from}: ${first(r.body)}`).join("\n") +
5103
+ missed.slice(0, 8).map((r) => ` [${r.seq}] ${r.act} from ${r.from}: ${first(r.body, 200, r.summary)}`).join("\n") +
5092
5104
  (missed.length > 8 ? `\n ...and ${missed.length - 8} more` : "") +
5093
5105
  `\nCall pantheon_wait, then send again.`, m.cid);
5094
5106
  }
5095
5107
  }
5096
- const err = this.validateAct(space, me, m.act, m.goal ?? null, m.ref ?? null, m.to ?? null, m.meta, m.defers_to, m.body.length, m.summary, m.repo, role);
5108
+ const err = this.validateAct(space, me, m.act, m.goal ?? null, m.ref ?? null, m.to ?? null, m.meta, m.defers_to, m.body.length, m.summary, m.repo, role, delegated?.run ?? null);
5097
5109
  if (err)
5098
- return fail(err.code, err.message, m.cid);
5110
+ return fail(err.code, err.message, m.cid, err.answer ? { answer: err.answer } : {});
5099
5111
  if (m.act === "PROPOSE" && m.affects?.length) {
5100
5112
  const g = m.goal ? space.goals.get(m.goal) : undefined;
5101
5113
  const outside = m.affects.filter((x) => !g?.members.includes(x));
@@ -5104,7 +5116,15 @@ pantheon start</code></pre>
5104
5116
  }
5105
5117
  }
5106
5118
  const wasFull = this.spaceFull(space);
5107
- if (wasFull && !recoveryStep && !this.freesRoom(space, me.id, m.act, m.ref ?? null))
5119
+ const cause = m.act === "ESCALATE" && !delegated && m.meta ? m.meta.safety_stop : undefined;
5120
+ const openStops = (who) => [...space.obligations.values()].filter((o) => {
5121
+ if (o.kind !== "HUMAN" || (who && o.owner !== `human:${who}`))
5122
+ return false;
5123
+ const a = space.ledger.find(o.ref);
5124
+ return !!a && a.act === "ESCALATE" && typeof a.meta?.safety_stop === "string";
5125
+ }).length;
5126
+ const safetyStop = (cause === "outside_links" || cause === "worktree_tampered") && openStops(me.id) < 1 && openStops() < 5;
5127
+ if (wasFull && !recoveryStep && !safetyStop && !this.freesRoom(space, me.id, m.act, m.ref ?? null))
5108
5128
  return fail("SPACE_FULL", this.spaceFullMessage(space), m.cid);
5109
5129
  space.ledger.checkBacklog();
5110
5130
  const rec = this.commit(space, {
@@ -5151,7 +5171,7 @@ pantheon start</code></pre>
5151
5171
  continue;
5152
5172
  this.commit(space, {
5153
5173
  from: me.id, session: sessionId, role, act: "NOTE", to: [p.member], goal: null, ref: rec.id,
5154
- body: `${me.id} named ${rec.to[0]} to decide ${p.domains.join(", ")} on '${goalTitle ?? first(rec.body, 80)}' — you were passed over`,
5174
+ body: `${me.id} named ${rec.to[0]} to decide ${p.domains.join(", ")} on '${goalTitle ?? first(rec.body, 80, rec.summary)}' — you were passed over`,
5155
5175
  meta: { notice: "passed_over", decider: rec.to[0], domains: p.domains, ...(rec.goal ? { goal: rec.goal } : {}) },
5156
5176
  });
5157
5177
  }
@@ -5322,9 +5342,58 @@ pantheon start</code></pre>
5322
5342
  if (lapsed)
5323
5343
  this.pushObligations(sp);
5324
5344
  }
5325
- validateAct(sp, me, act, goalId, ref, to, meta, deferTo, bodyLen = 0, summary, repo, role) {
5345
+ validateAct(sp, me, act, goalId, ref, to, meta, deferTo, bodyLen = 0, summary, repo, role, byRun = null) {
5326
5346
  if (!SENDABLE.includes(act))
5327
5347
  return { code: "RESERVED_ACT", message: `${act} is emitted by the relay, not by a delegate` };
5348
+ if (byRun && (act === "ESCALATE" || act === "HUMAN_REQUIRED")) {
5349
+ let open = 0;
5350
+ for (const o of sp.obligations.values()) {
5351
+ if (o.kind !== "HUMAN")
5352
+ continue;
5353
+ const a = sp.ledger.find(o.ref);
5354
+ if (a && a.from === me.id && a.sig?.role === "run" && a.sig.cert?.run === byRun)
5355
+ open++;
5356
+ }
5357
+ if (open >= RUN_OPEN_DECISIONS) {
5358
+ return { code: "NOT_FOR_A_RUN", message: `this run already has ${open} decisions waiting on its person — add to one of them with a NOTE instead of raising another` };
5359
+ }
5360
+ }
5361
+ if (byRun && ref && (act === "ANSWER" || act === "RETRACT" || act === "ACCEPT" || act === "OBJECT" || act === "DELIVERED")) {
5362
+ const target = sp.ledger.find(ref);
5363
+ const decision = !!target && (target.act === "ESCALATE" || target.act === "HUMAN_REQUIRED");
5364
+ const waitsOnPerson = [...sp.obligations.values()].some((o) => o.kind === "HUMAN" && o.ref === ref && o.owner === `human:${me.id}`);
5365
+ if ((act === "ANSWER" || act === "ACCEPT" || act === "OBJECT") && (decision || waitsOnPerson)) {
5366
+ return { code: "NOT_FOR_A_RUN", message: "that decision waits on a person — an unattended run cannot answer it; leave it for them (add to it with a NOTE if that helps)" };
5367
+ }
5368
+ if (act === "ACCEPT" && target && target.act !== "PROPOSE" && target.act !== "CONTRACT" && target.act !== "DELIVERED") {
5369
+ return { code: "NOT_FOR_A_RUN", message: `an unattended run accepts a proposal, a contract or a delivery — not ${target.act === "ASK" ? "a question (answer it)" : `a ${target.act.toLowerCase()}`}` };
5370
+ }
5371
+ if ((act === "ANSWER" || act === "ACCEPT" || act === "OBJECT") && target && !decision) {
5372
+ const all = sp.ledger.all();
5373
+ const retracted = new Set();
5374
+ for (let i = all.length - 1; i >= 0 && all[i].seq > target.seq; i--) {
5375
+ const r = all[i];
5376
+ if (r.from !== me.id)
5377
+ continue;
5378
+ if (r.act === "RETRACT" && r.ref) {
5379
+ retracted.add(r.ref);
5380
+ continue;
5381
+ }
5382
+ if (r.ref === target.id && r.sig?.role !== "run" && (r.act === "ANSWER" || r.act === "ACCEPT" || r.act === "OBJECT") && !retracted.has(r.id)) {
5383
+ return { code: "NOT_FOR_A_RUN", message: "its person already answered this — an unattended run does not answer it again; add a NOTE if there is more to say" };
5384
+ }
5385
+ }
5386
+ }
5387
+ const ownRun = !!target && target.sig?.role === "run" && target.sig.cert?.run === byRun;
5388
+ if (act === "RETRACT" && !ownRun) {
5389
+ return { code: "NOT_FOR_A_RUN", message: decision
5390
+ ? "an unattended run cannot withdraw a decision it did not raise itself — it stays for the person"
5391
+ : "an unattended run withdraws only what it said itself — this was said by its person (or another session), and stays" };
5392
+ }
5393
+ if (act === "RETRACT" && !decision && [...sp.obligations.values()].some((o) => o.kind === "HUMAN" && o.ref === ref)) {
5394
+ return { code: "NOT_FOR_A_RUN", message: "a decision waiting on a person points at this — an unattended run cannot withdraw it; it stays for the person" };
5395
+ }
5396
+ }
5328
5397
  const now = Date.now();
5329
5398
  me.stamps = me.stamps.filter((t) => now - t < LIMITS.rateWindowMs);
5330
5399
  if (me.stamps.length >= LIMITS.rateActs) {
@@ -5414,6 +5483,10 @@ pantheon start</code></pre>
5414
5483
  if (o.kind !== "HUMAN" || o.owner !== `human:${to[0]}` || (o.goal ?? null) !== (goalId ?? null))
5415
5484
  return false;
5416
5485
  const prev = sp.ledger.find(o.ref);
5486
+ if (!prev || prev.act !== "HUMAN_REQUIRED" || prev.from !== me.id)
5487
+ return false;
5488
+ if (goalId == null && (!ref || prev.ref !== ref))
5489
+ return false;
5417
5490
  const prevDomains = Array.isArray(prev?.meta?.decision_domains)
5418
5491
  ? prev.meta.decision_domains.filter((x) => typeof x === "string")
5419
5492
  : [];
@@ -5421,7 +5494,7 @@ pantheon start</code></pre>
5421
5494
  });
5422
5495
  if (openDup) {
5423
5496
  return { code: "DECISION_ALREADY_WAITING",
5424
- message: `${to[0]}'s human already has this decision open as ${openDup.id} (${domains.join(", ")}). Their answer will unblock you — wait for it instead of re-asking.` };
5497
+ message: `you already asked ${to[0]}'s human this — your earlier question is open as ${openDup.id} (${domains.join(", ")}). Their answer will unblock you — wait for it instead of re-asking.` };
5425
5498
  }
5426
5499
  }
5427
5500
  if (bodyLen > LIMITS.summaryRequiredOver && !summary) {
@@ -5514,6 +5587,35 @@ pantheon start</code></pre>
5514
5587
  if (asked?.act === "HUMAN_REQUIRED" && asked.to?.[0] && asked.to[0] !== me.id) {
5515
5588
  return { code: "NOT_YOUR_DECISION", message: `that decision is ${asked.to[0]}'s to make — add to it with a NOTE instead` };
5516
5589
  }
5590
+ if (asked && (asked.act === "ESCALATE" || asked.act === "HUMAN_REQUIRED")) {
5591
+ const all = sp.ledger.all();
5592
+ for (let i = all.length - 1; i >= 0 && all[i].seq > asked.seq; i--) {
5593
+ const r = all[i];
5594
+ if (r.act === "RETRACT" && r.ref === asked.id && r.from === asked.from) {
5595
+ return { code: "WITHDRAWN", message: `that decision was withdrawn by ${asked.from === me.id ? "your own agent" : asked.from} — nothing to answer, and nothing changed` };
5596
+ }
5597
+ }
5598
+ const decider = asked.act === "ESCALATE" ? asked.from : asked.to?.[0];
5599
+ if (decider === me.id && ![...sp.obligations.values()].some((o) => o.kind === "HUMAN" && o.ref === asked.id && o.owner === `human:${me.id}`)) {
5600
+ const all = sp.ledger.all();
5601
+ const retracted = new Set();
5602
+ let standing;
5603
+ for (let i = all.length - 1; i >= 0 && all[i].seq > asked.seq; i--) {
5604
+ const r = all[i];
5605
+ if (r.act === "RETRACT" && r.ref && r.from === me.id)
5606
+ retracted.add(r.ref);
5607
+ else if (r.act === "ANSWER" && r.ref === asked.id && r.from === me.id && !retracted.has(r.id)) {
5608
+ standing = r;
5609
+ break;
5610
+ }
5611
+ }
5612
+ if (standing) {
5613
+ const byAgent = standing.role === "interactive" || standing.role === "worker" || standing.sig?.role === "run";
5614
+ return { code: "ALREADY_ANSWERED", answer: standing.id,
5615
+ message: `${byAgent ? "your agent already answered" : "you already answered"} this decision: "${first(standing.body, 80, standing.summary)}" — nothing was sent. An answer given can't be changed from here; add a note if there is more to say` };
5616
+ }
5617
+ }
5618
+ }
5517
5619
  }
5518
5620
  if (!goalId) {
5519
5621
  const target = ref ? sp.ledger.find(ref) : undefined;
@@ -5613,7 +5715,7 @@ pantheon start</code></pre>
5613
5715
  case "ASK":
5614
5716
  for (const owner of rec.to ?? []) {
5615
5717
  this.oblige(sp, { kind: "ANSWER", owner, ref: rec.id, goal: rec.goal,
5616
- body: `${rec.from} asked: ${first(rec.body)}` });
5718
+ body: `${rec.from} asked: ${first(rec.body, 200, rec.summary)}` });
5617
5719
  }
5618
5720
  break;
5619
5721
  case "ANSWER":
@@ -5641,7 +5743,7 @@ pantheon start</code></pre>
5641
5743
  .filter((x) => x !== rec.from);
5642
5744
  for (const owner of targets) {
5643
5745
  this.oblige(sp, { kind: "ACCEPT", owner, ref: rec.id, goal: rec.goal,
5644
- body: `${rec.from} proposed: ${first(rec.body)} — ACCEPT or OBJECT` });
5746
+ body: `${rec.from} proposed: ${first(rec.body, 200, rec.summary)} — ACCEPT or OBJECT` });
5645
5747
  }
5646
5748
  break;
5647
5749
  }
@@ -5664,7 +5766,7 @@ pantheon start</code></pre>
5664
5766
  const target = sp.ledger.find(rec.ref);
5665
5767
  if (target) {
5666
5768
  this.oblige(sp, { kind: "REVISE", owner: target.from, ref: rec.id, goal: rec.goal,
5667
- body: `${rec.from} objected: ${first(rec.body)}` });
5769
+ body: `${rec.from} objected: ${first(rec.body, 200, rec.summary)}` });
5668
5770
  }
5669
5771
  }
5670
5772
  break;
@@ -5684,7 +5786,7 @@ pantheon start</code></pre>
5684
5786
  case "ESCALATE":
5685
5787
  this.oblige(sp, { kind: "HUMAN", owner: `human:${rec.from}`, ref: rec.id, goal: rec.goal,
5686
5788
  ...(rec.ref ? { about: rec.ref } : {}),
5687
- body: `${rec.from} escalated: ${first(rec.body)}` });
5789
+ body: `${rec.from} escalated: ${first(rec.body, 200, rec.summary)}` });
5688
5790
  if (goal && goal.state === "OPEN") {
5689
5791
  goal.state = "BLOCKED";
5690
5792
  this.broadcast(sp, { t: "goal", goal });
@@ -5701,10 +5803,13 @@ pantheon start</code></pre>
5701
5803
  case "WITHDRAW":
5702
5804
  break;
5703
5805
  case "RETRACT":
5704
- if (rec.ref)
5806
+ if (rec.ref) {
5807
+ const withdrawn = sp.ledger.find(rec.ref);
5808
+ const isDecision = withdrawn?.act === "ESCALATE" || withdrawn?.act === "HUMAN_REQUIRED";
5705
5809
  for (const [id, o] of sp.obligations)
5706
- if (o.ref === rec.ref)
5810
+ if (o.ref === rec.ref && (o.kind !== "HUMAN" || isDecision))
5707
5811
  sp.obligations.delete(id);
5812
+ }
5708
5813
  if (rec.ref)
5709
5814
  for (const [k, v] of sp.recent)
5710
5815
  if (v.id === rec.ref)
@@ -5720,7 +5825,7 @@ pantheon start</code></pre>
5720
5825
  if (asked && decider === rec.from && !stillAnswered && !alreadyLive && !retracted.has(asked.id)) {
5721
5826
  this.oblige(sp, { kind: "HUMAN", owner: `human:${decider}`, ref: asked.id, goal: asked.goal,
5722
5827
  ...(asked.act === "ESCALATE" && asked.ref ? { about: asked.ref } : {}),
5723
- body: asked.act === "ESCALATE" ? `${asked.from} escalated: ${first(asked.body)}` : decisionBody(asked, sp) });
5828
+ body: asked.act === "ESCALATE" ? `${asked.from} escalated: ${first(asked.body, 200, asked.summary)}` : decisionBody(asked, sp) });
5724
5829
  const g = asked.goal ? sp.goals.get(asked.goal) : undefined;
5725
5830
  if (g && g.state === "OPEN") {
5726
5831
  g.state = "BLOCKED";
@@ -6168,7 +6273,7 @@ pantheon start</code></pre>
6168
6273
  opened_by: r.from,
6169
6274
  opened_at: r.ts,
6170
6275
  ...(Number.isFinite(deadline) ? { deadline } : {}),
6171
- ...(mm[4] === "worklist" ? { kind: "worklist" } : {}),
6276
+ ...(kindFromOpening(meta?.goal_sig, mm[4]) ? { kind: kindFromOpening(meta?.goal_sig, mm[4]) } : {}),
6172
6277
  };
6173
6278
  }
6174
6279
  compactSpace(sp) {
@@ -6342,10 +6447,19 @@ function passedOverBy(sp, decider, domains) {
6342
6447
  }
6343
6448
  function decisionBody(rec, sp) {
6344
6449
  const marker = rec.meta?.["authority"] === "named" ? namedMarker(rec.from, rec.meta, passedOverBy(sp, rec.to?.[0] ?? "", decisionDomains(rec))) : null;
6345
- return `${rec.from} needs a decision: ${marker ? `[${marker}] ` : ""}${first(rec.body)}`;
6450
+ return `${rec.from} needs a decision: ${marker ? `[${marker}] ` : ""}${first(rec.body, 200, rec.summary)}`;
6346
6451
  }
6347
- function first(s, n = 200) {
6348
- const line = s.split("\n")[0] ?? "";
6452
+ export function first(s, n = 200, summary) {
6453
+ const said = (t) => t.replace(/^\s*(?:#{1,6}\s+|>\s*|[-*+]\s+|\d+[.)]\s+|\[[ xX]\]\s+)*/, "").replace(/\*\*|__|`/g, "").trim();
6454
+ const text = s.replace(/<!--[\s\S]*?(?:-->|$)/g, "").replace(/^\s*(```|~~~)[\s\S]*?(?:^\s*\1[^\n]*$|(?![\s\S]))/gm, "");
6455
+ const notProse = (l) => /^\s*([-*_])(?:\s*\1){2,}\s*$/.test(l) || /^\s*\|/.test(l) || /^\s*:?-{3,}:?\s*(?:\|\s*:?-{3,}:?\s*)+\|?\s*$/.test(l);
6456
+ const lines = text.split("\n").filter((l) => !notProse(l) && said(l).length > 0);
6457
+ const heading = (l) => /^\s*#{1,6}\s/.test(l);
6458
+ const prose = lines.find((l) => !heading(l));
6459
+ const opening = lines.length && heading(lines[0]) && prose
6460
+ ? `${said(lines[0]).replace(/[:.]$/, "")}${/[?!]$/.test(said(lines[0])) ? "" : ":"} ${said(prose)}`
6461
+ : said(lines[0] ?? "");
6462
+ const line = (summary && said(summary)) || opening || said(s.split("\n").find((l) => said(l).length > 0) ?? "");
6349
6463
  if (line.length <= n)
6350
6464
  return line;
6351
6465
  const cut = line.slice(0, n - 1);
package/dist/removed.js CHANGED
@@ -1,8 +1,8 @@
1
- import { mkdirSync, readFileSync } from "node:fs";
1
+ import { mkdirSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
3
  import { CONFIG_DIR, legacySpaceId } from "./config.js";
4
4
  import { shellArg } from "./team-name.js";
5
- import { withFileLock } from "./file-lock.js";
5
+ import { withFileLock, readStateText, readStateBytes } from "./file-lock.js";
6
6
  import { writeWhole } from "./pins.js";
7
7
  import { trustWrite } from "./home-guard.js";
8
8
  export const REMOVED_FIRST_MS = 5 * 60_000;
@@ -21,7 +21,7 @@ export function removalRefusal(lastError) {
21
21
  export const safeMemberName = (x) => typeof x === "string" && x.length <= 48 && /^[a-z0-9][a-z0-9._-]*$/i.test(x) ? x : undefined;
22
22
  function readAll(home) {
23
23
  try {
24
- const raw = JSON.parse(readFileSync(removedPath(home), "utf8"));
24
+ const raw = JSON.parse(readStateText(removedPath(home)));
25
25
  if (!raw || typeof raw !== "object" || Array.isArray(raw))
26
26
  return {};
27
27
  const out = {};
@@ -49,7 +49,7 @@ function update(home, fn) {
49
49
  return withFileLock(f, () => {
50
50
  let prev = null;
51
51
  try {
52
- prev = readFileSync(f);
52
+ prev = readStateBytes(f);
53
53
  }
54
54
  catch { }
55
55
  const all = readAll(home);
@@ -1,15 +1,16 @@
1
- import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
1
+ import { mkdirSync, renameSync, writeFileSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
3
  import { CONFIG_PATH } from "./config.js";
4
4
  import { parseJsonText } from "./text-file.js";
5
5
  import { trustWrite } from "./home-guard.js";
6
+ import { readStateText, readStateBytes } from "./file-lock.js";
6
7
  export const CONT_STOP_KEEP_MS = 30 * 24 * 3600_000;
7
8
  const homeOf = (home) => home ?? process.env.PANTHEON_HOME ?? dirname(CONFIG_PATH);
8
9
  export const runControlPath = (home) => join(homeOf(home), "run-control.json");
9
10
  export const RUN_REF = /^(cont:)?a_[A-Za-z0-9_-]{4,64}$/;
10
11
  export function loadRunStops(home, now = Date.now()) {
11
12
  try {
12
- const raw = parseJsonText(readFileSync(runControlPath(home), "utf8"));
13
+ const raw = parseJsonText(readStateText(runControlPath(home)));
13
14
  const list = Array.isArray(raw?.stops) ? raw.stops : [];
14
15
  return list.filter((s) => !!s && typeof s === "object" && typeof s.ref === "string" && RUN_REF.test(s.ref)
15
16
  && (s.how === "stop" || s.how === "takeover") && typeof s.at === "number"
@@ -24,7 +25,7 @@ function saveRunStops(list, home) {
24
25
  mkdirSync(dirname(f), { recursive: true });
25
26
  let prev = null;
26
27
  try {
27
- prev = readFileSync(f);
28
+ prev = readStateBytes(f);
28
29
  }
29
30
  catch { }
30
31
  const tmp = `${f}.${process.pid}.tmp`;
@@ -1,17 +1,74 @@
1
- import { ownWords } from "./agent-outage.js";
1
+ import { signInRefused } from "./agent-outage.js";
2
2
  import { execFileSync } from "node:child_process";
3
3
  import { gitCallEnv, safeGitArgs } from "./git-safe.js";
4
4
  import { checkRepoCommand } from "./agents.js";
5
5
  import { bashRuleMatches, GIT_DENY_RULES } from "./claude-confine.js";
6
- export const AUTH_RE = /not (?:logged|signed) in|not authenticated|no (?:github )?(?:authentication|credentials?|token) (?:found|available)|login required|please (?:log|sign) in|run .*login|invalid api key|unauthori[sz]ed|authentication (?:failed|required)|\b401\b|expired (?:token|session)/i;
7
6
  const AGENT_LABEL = { "claude-code": "Claude Code", codex: "Codex", cursor: "Cursor", copilot: "GitHub Copilot", kiro: "Kiro" };
8
7
  export const SIGN_IN_FIX = {
9
8
  "claude-code": "run `claude`, then /login",
10
- codex: "run `codex login`",
9
+ codex: "run `codex login` (if your Codex keeps its sign-in in the keyring, run `codex -c 'cli_auth_credentials_store=\"file\"' login` — the worker's runs read only the one saved to a file)",
11
10
  cursor: "run `cursor-agent login`",
12
11
  copilot: "run `copilot login` (or `gh auth login` — copilot uses gh's sign-in too)",
13
12
  kiro: "run `kiro-cli login` (or set KIRO_API_KEY)",
14
13
  };
14
+ export function signInFixFor(agent, env) {
15
+ return refusedWords(agent, { line: "", ...(env ? { env } : {}) })?.fix ?? SIGN_IN_FIX[agent ?? ""] ?? "sign in to the agent CLI on this machine";
16
+ }
17
+ export function refusedWords(agent, r) {
18
+ const restart = "then run `pantheon service restart worker`";
19
+ const soon = "the worker tries again within the hour, or at once after `pantheon doctor`";
20
+ const SETTINGS = "~/.claude/settings.json";
21
+ if (agent === "claude-code" && r.settings) {
22
+ if (r.helper && /^Your apiKeyHelper script is failing/.test(r.line)) {
23
+ return {
24
+ what: `the apiKeyHelper in Claude's settings — its script is failing, which usually means a sign-in to your provider ran out`,
25
+ fix: `sign in to your provider again (or fix the apiKeyHelper script in ${SETTINGS}) — ${soon}`,
26
+ short: "sign in to your provider again — or pantheon doctor to try now",
27
+ };
28
+ }
29
+ if (r.env) {
30
+ return {
31
+ what: `the ${r.env} in Claude's settings (${SETTINGS})`,
32
+ fix: `replace or remove ${r.env} in the env block of ${SETTINGS} — ${soon}; a sign-in does not override it`,
33
+ short: `replace or remove it in ${SETTINGS} — or pantheon doctor to try now`,
34
+ };
35
+ }
36
+ return {
37
+ what: r.helper ? `the key the apiKeyHelper in Claude's settings (${SETTINGS}) gave it` : `a key from Claude's settings (an env entry or apiKeyHelper in ${SETTINGS})`,
38
+ fix: `${r.helper ? "renew the key the apiKeyHelper returns (rotate it, or sign in to your provider again)" : `replace or remove that key in ${SETTINGS} (its env block, or what apiKeyHelper returns)`} — ${soon}; a sign-in does not override it`,
39
+ short: `${r.helper ? "renew the key it returns" : `replace or remove it in ${SETTINGS}`} — or pantheon doctor to try now`,
40
+ };
41
+ }
42
+ if (r.env) {
43
+ return {
44
+ what: `the ${r.env} set in the worker's environment`,
45
+ fix: `replace or unset ${r.env} where the worker gets its environment, ${restart} — a sign-in does not override it`,
46
+ short: "replace or unset it there, then pantheon service restart worker",
47
+ };
48
+ }
49
+ if (agent === "claude-code" && /Fix external API key$/.test(r.line)) {
50
+ return {
51
+ what: "a key it was given (in the worker's environment or Claude's settings)",
52
+ fix: `replace or remove that key — ANTHROPIC_API_KEY where the worker gets its environment, or the key or apiKeyHelper in Claude's settings (${SETTINGS}) — ${restart}; a sign-in does not override it`,
53
+ short: "replace or remove it (ANTHROPIC_API_KEY, or Claude's settings), then pantheon service restart worker",
54
+ };
55
+ }
56
+ if (agent === "claude-code" && r.savedToken) {
57
+ return {
58
+ what: "the token saved for this worker",
59
+ fix: "make a new one — claude setup-token, then pantheon worker token — or remove it to use your own sign-in: pantheon worker token --remove",
60
+ short: "make a new one: claude setup-token, then pantheon worker token",
61
+ };
62
+ }
63
+ if (agent === "codex" && /Incorrect API key provided/.test(r.line)) {
64
+ return {
65
+ what: "the API key saved with codex login",
66
+ fix: "save a new key — `printenv OPENAI_API_KEY | codex login --with-api-key`, with the new key in OPENAI_API_KEY — or run `codex login` to sign in with ChatGPT",
67
+ short: "save a new one: printenv OPENAI_API_KEY | codex login --with-api-key",
68
+ };
69
+ }
70
+ return null;
71
+ }
15
72
  const sh = (dir, ...args) => execFileSync("git", safeGitArgs(dir, ["-C", dir, ...args]), { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], env: gitCallEnv(args, process.env), timeout: 5_000 }).trim();
16
73
  export const gitProbe = {
17
74
  isRepo: (dir) => { try {
@@ -68,13 +125,13 @@ export function diagnoseRun(f, probe = gitProbe) {
68
125
  fix: `To give it longer: ${raise}. What it did so far is kept (transcript: ${f.runLog}).`,
69
126
  };
70
127
  }
71
- if (!f.exited && f.detail.split("\n").some((l) => ownWords(l, AUTH_RE))) {
72
- const fix = SIGN_IN_FIX[f.agent ?? ""] ?? "sign in to the agent CLI on this machine";
73
- return {
74
- cause: "not_signed_in",
75
- says: `${AGENT_LABEL[f.agent ?? ""] ?? "The agent"} is signed out on this computer, so the run couldn't start.`,
76
- fix: `Sign in once and the next run works: ${fix}.`,
77
- };
128
+ const refused = f.exited ? null : signInRefused(f.agent, f.detail, f.env, f.claudeSettings);
129
+ if (refused) {
130
+ const label = AGENT_LABEL[f.agent ?? ""] ?? "The agent";
131
+ const w = refusedWords(f.agent, { ...refused, ...(f.savedToken ? { savedToken: true } : {}) });
132
+ return w
133
+ ? { cause: "not_signed_in", says: `${label} refused ${w.what}, so the run couldn't start.`, fix: `${w.fix[0].toUpperCase()}${w.fix.slice(1)}.` }
134
+ : { cause: "not_signed_in", says: `${label} is signed out on this computer, so the run couldn't start.`, fix: `Sign in once and the next run works: ${SIGN_IN_FIX[f.agent ?? ""] ?? "sign in to the agent CLI on this machine"}.` };
78
135
  }
79
136
  if (f.allowBash && (f.agent ?? "claude-code") === "claude-code" && (f.os ?? process.platform) === "linux" && SANDBOX_RE.test(f.detail)) {
80
137
  return {
@@ -1,10 +1,11 @@
1
1
  import { randomBytes } from "node:crypto";
2
- import { appendFileSync, closeSync, mkdirSync, openSync, readFileSync, readSync, renameSync, statSync, writeFileSync } from "node:fs";
2
+ import { appendFileSync, closeSync, mkdirSync, openSync, readSync, renameSync, statSync, writeFileSync } from "node:fs";
3
3
  import { dirname, join } from "node:path";
4
4
  import { CONFIG_PATH } from "./config.js";
5
5
  import { argvHash, trustWrite } from "./home-guard.js";
6
6
  import { AUTOPILOT_PLAN_NOTE, describeIdleSeconds, inWokenRun } from "./worker-policy.js";
7
7
  import { parseJsonText } from "./text-file.js";
8
+ import { readStateText, readStateBytes } from "./file-lock.js";
8
9
  export function unsandboxedRisk(who = "Codex, Cursor and Copilot") {
9
10
  const either = who.replace(/ and ([^,]+)$/, " or $1");
10
11
  const one = !/,| or /.test(either);
@@ -202,7 +203,7 @@ export function logChanges(entries, home) {
202
203
  mkdirSync(dirname(f), { recursive: true });
203
204
  appendFileSync(f, entries.map((e) => JSON.stringify(e)).join("\n") + "\n", { mode: 0o600 });
204
205
  if (statSync(f).size > CHANGE_LOG_TRIM_BYTES) {
205
- const lines = readFileSync(f, "utf8").split("\n").filter((l) => l.trim());
206
+ const lines = readStateText(f).split("\n").filter((l) => l.trim());
206
207
  const first = lines.find((l) => l.includes(`"setting":"${FIRST_SETUP}"`));
207
208
  const rest = lines.filter((l) => l !== first).slice(-CHANGE_LOG_MAX);
208
209
  const tmp = `${f}.${process.pid}.tmp`;
@@ -216,7 +217,7 @@ export function readChangeLog(home, head) {
216
217
  let text = "";
217
218
  try {
218
219
  if (head === undefined)
219
- text = readFileSync(changesLogPath(home), "utf8");
220
+ text = readStateText(changesLogPath(home));
220
221
  else {
221
222
  const fd = openSync(changesLogPath(home), "r");
222
223
  try {
@@ -284,7 +285,7 @@ export function replayAllowed(argv) {
284
285
  export { argvHash };
285
286
  export function loadPending(home, now = Date.now()) {
286
287
  try {
287
- const raw = parseJsonText(readFileSync(pendingChangesPath(home), "utf8"));
288
+ const raw = parseJsonText(readStateText(pendingChangesPath(home)));
288
289
  const list = Array.isArray(raw?.pending) ? raw.pending : [];
289
290
  return list.filter((p) => !!p && typeof p === "object" && typeof p.id === "string"
290
291
  && Array.isArray(p.changes) && Array.isArray(p.argv) && typeof p.cwd === "string"
@@ -299,7 +300,7 @@ export function savePending(list, home) {
299
300
  mkdirSync(dirname(f), { recursive: true });
300
301
  let prev = null;
301
302
  try {
302
- prev = readFileSync(f);
303
+ prev = readStateBytes(f);
303
304
  }
304
305
  catch { }
305
306
  const tmp = `${f}.${process.pid}.tmp`;
@@ -478,7 +479,7 @@ export function markFirstSetup(askedBy, home, now = Date.now()) {
478
479
  }
479
480
  export function machineSetUp(o) {
480
481
  try {
481
- const p = JSON.parse(readFileSync(o.profileFile, "utf8"));
482
+ const p = JSON.parse(readStateText(o.profileFile));
482
483
  if (typeof p?.agent?.wake_default !== "string")
483
484
  return false;
484
485
  const first = firstSetupAt(o.home);