@join-pantheon/cli 0.37.3 → 0.38.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.
package/dist/notifier.js CHANGED
@@ -9,18 +9,22 @@ import { dirname, join, resolve } from "node:path";
9
9
  import { fileURLToPath } from "node:url";
10
10
  import { PantheonClient } from "./client.js";
11
11
  import { CONFIG_DIR } from "./config.js";
12
- import { awaitingDecision } from "./pickup.js";
12
+ import { awaitingDecision, pickupEstimate } from "./pickup.js";
13
13
  import { loadProfile } from "./profile.js";
14
- import { APP_TOOLS, CLAUDE_APP_CHOSEN, composeDecision, composeDelivery, composeJoined, composePassedOver, composeWaiting, composeWakeAsk, neverAlerts, passedOverNotice, TOOL_LABELS } from "./notice.js";
14
+ import { APP_TOOLS, CLAUDE_APP_CHOSEN, composeDecision, composeJoined, composePassedOver, composeReplies, composeUnpicked, composeWaiting, composeWakeAsk, declineCodeOf, neverAlerts, passedOverNotice, TOOL_LABELS } from "./notice.js";
15
15
  import { loadPolicy } from "./worker-policy.js";
16
16
  import { withoutAgentMarkers } from "./setup-changes.js";
17
- import { wakeAlerted } from "./continued.js";
17
+ import { liveReadAt, wakeAlerted } from "./continued.js";
18
+ import { teamPinId } from "./pins.js";
19
+ import { signedRead } from "./reads.js";
18
20
  import { cliOnPath, detectAvailable } from "./agents.js";
19
21
  import { CLAUDE_APP_TOOL, chosenOpenIn, claudeAppPresent, effectiveOpenIn } from "./open-in.js";
20
22
  import { whichPantheon } from "./service.js";
21
23
  import { powerNow } from "./power.js";
22
24
  import { obligationSignature, StatusNudger } from "./status-nudge.js";
23
25
  import { clientState, ConnectionReport } from "./conn-report.js";
26
+ import { noteServiceConnected } from "./crash-loop.js";
27
+ import { refusalOf } from "./refusal.js";
24
28
  import { removalFor, removalHolds, removalRefusal, removalWords, removedLine, removedNotice, takeTold } from "./removed.js";
25
29
  export const DEFAULT_REMINDER_MS = 4 * 60 * 60 * 1_000;
26
30
  export const JOIN_BATCH_MS = 20_000;
@@ -49,6 +53,46 @@ export function waitingRequests(obligations, member, state, now, fromOf) {
49
53
  && !awaitingDecision(obligations, o)
50
54
  && (() => { const f = fromOf(o); return !!f && f !== member; })());
51
55
  }
56
+ export const ASKED_FOLLOWUP_MS = 60 * 60_000;
57
+ export const ASKED_EVERY_MS = 10 * 60_000;
58
+ export const REPLY_BATCH_MS = 2_500;
59
+ let machineAskedAt = 0;
60
+ export function resetAskedClock() { machineAskedAt = 0; }
61
+ export function unpickedRequests(obligations, member, state, now, fromOf, o = {}) {
62
+ const byRef = new Map();
63
+ for (const x of obligations) {
64
+ if (x.owner === member || x.owner.startsWith("human:") || x.kind === "HUMAN" || x.kind === "CONTINUE" || x.kind === "DELIVER")
65
+ continue;
66
+ byRef.set(x.ref, [...(byRef.get(x.ref) ?? []), x]);
67
+ }
68
+ const out = [];
69
+ for (const [ref, owed] of byRef) {
70
+ if (state.notified_at[`act:asked:${ref}`] !== undefined)
71
+ continue;
72
+ if (owed.some((x) => x.claimed_by))
73
+ continue;
74
+ if (fromOf(owed[0]) !== member)
75
+ continue;
76
+ const at = Math.min(...owed.map((x) => x.created_at));
77
+ if (now - at < ASKED_FOLLOWUP_MS || now - at >= WAITING_MAX_AGE_MS)
78
+ continue;
79
+ if (owed.some((x) => awaitingDecision(obligations, x)))
80
+ continue;
81
+ const goal = owed[0].goal;
82
+ if (goal && o.closed?.(goal))
83
+ continue;
84
+ const to = o.sentTo?.(ref)?.filter((t) => t !== member);
85
+ if (to?.length && owed.length < to.length)
86
+ continue;
87
+ if (o.replied?.(ref, to?.length ? to : owed.map((x) => x.owner)))
88
+ continue;
89
+ out.push({ ref, owed });
90
+ }
91
+ return out;
92
+ }
93
+ export function repliedIn(acts, ref, askedOf) {
94
+ return acts.some((a) => a.ref === ref && askedOf.includes(a.from) && !(a.act === "NOTE" && a.role === "worker" && !a.meta?.declined));
95
+ }
52
96
  export function humanObligations(obligations, member) {
53
97
  return obligations.filter((o) => o.kind === "HUMAN" && o.owner === `human:${member}`);
54
98
  }
@@ -276,6 +320,7 @@ export class HumanNotifier {
276
320
  report.close();
277
321
  throw e;
278
322
  }
323
+ noteServiceConnected();
279
324
  try {
280
325
  await this.serve(client);
281
326
  }
@@ -298,6 +343,23 @@ export class HumanNotifier {
298
343
  const joined = new Set();
299
344
  const settled = new Set();
300
345
  let joinedSince = 0;
346
+ let replies = [];
347
+ let repliesSince = 0;
348
+ const batched = new Set();
349
+ const own = new Map();
350
+ const ownAct = async (id) => {
351
+ const seen = client.seenAct(id);
352
+ if (seen)
353
+ return seen;
354
+ if (own.has(id))
355
+ return own.get(id);
356
+ const r = await client.storedAct(id, 3_000).catch(() => null);
357
+ own.set(id, r);
358
+ if (own.size > 500)
359
+ own.delete(own.keys().next().value);
360
+ return r;
361
+ };
362
+ const byRun = (a) => a.sig?.role === "run" || a.role === "worker";
301
363
  try {
302
364
  let removedSaid = false;
303
365
  while (!this.stopped) {
@@ -381,7 +443,11 @@ export class HumanNotifier {
381
443
  const last = Math.max(state.notified_at["act:wait:last"] ?? 0, machineWaitingAt);
382
444
  if (waiting.length && (last === 0 || now() - last >= WAITING_EVERY_MS)) {
383
445
  const items = waiting.map((o) => ({ from: fromOf(o), what: client.seenAct(o.ref)?.summary ?? o.body }));
446
+ const before = machineWaitingAt;
447
+ machineWaitingAt = now();
384
448
  const ok = await send(withLabel(composeWaiting(items, this.cfg.space, { tools, preferred: preferredTool(profile, tools), now: now() })));
449
+ if (!ok)
450
+ machineWaitingAt = before;
385
451
  if (ok) {
386
452
  for (const o of waiting)
387
453
  state.notified_at[`act:wait:${o.ref}`] = now();
@@ -392,6 +458,70 @@ export class HumanNotifier {
392
458
  }
393
459
  }
394
460
  }
461
+ if (prefs.decisions) {
462
+ const relayNow = now() + (client.relayNow() - Date.now());
463
+ const fromOf = (o) => client.seenAct(o.ref)?.from ?? own.get(o.ref)?.from ?? requestFrom(o.body);
464
+ let due = unpickedRequests(client.obligations, this.cfg.member, state, relayNow, fromOf, {
465
+ closed: (g) => client.goals.get(g)?.state === "CLOSED",
466
+ sentTo: (ref) => (client.seenAct(ref) ?? own.get(ref))?.to,
467
+ replied: (ref, askedOf) => repliedIn(client.seenSince(0), ref, askedOf),
468
+ });
469
+ const last = Math.max(state.notified_at["act:asked:last"] ?? 0, machineAskedAt);
470
+ if (due.length && (last === 0 || now() - last >= ASKED_EVERY_MS)) {
471
+ const before = machineAskedAt;
472
+ machineAskedAt = now();
473
+ const runs = [];
474
+ for (const d of due) {
475
+ const a = await ownAct(d.ref);
476
+ if (a && byRun(a))
477
+ runs.push(d.ref);
478
+ }
479
+ for (const ref of runs) {
480
+ state.notified_at[`act:asked:${ref}`] = now();
481
+ dirty = true;
482
+ }
483
+ due = due.filter((d) => !runs.includes(d.ref) && !((a) => a?.to?.length && d.owed.length < a.to.filter((t) => t !== this.cfg.member).length)(own.get(d.ref) ?? client.seenAct(d.ref)));
484
+ const replied = [];
485
+ for (const d of due) {
486
+ const mine = client.seenAct(d.ref) ?? own.get(d.ref);
487
+ const to = mine?.to?.filter((t) => t !== this.cfg.member);
488
+ const askedOf = to?.length ? to : d.owed.map((x) => x.owner);
489
+ try {
490
+ const goal = d.owed[0].goal;
491
+ const res = await signedRead(this.cfg, "/history", goal ? { goal } : { since: String(Math.max(0, (mine?.seq ?? 1) - 1)) }, { timeoutMs: 3_000 });
492
+ const acts = res.ok ? (await res.json()).acts ?? [] : [];
493
+ if (repliedIn(acts, d.ref, askedOf))
494
+ replied.push(d.ref);
495
+ }
496
+ catch { }
497
+ }
498
+ for (const ref of replied) {
499
+ state.notified_at[`act:asked:${ref}`] = now();
500
+ dirty = true;
501
+ }
502
+ due = due.filter((d) => !replied.includes(d.ref));
503
+ if (due.length) {
504
+ const mayWake = client.members.find((m) => m.member === this.cfg.member)?.may_wake;
505
+ const items = due.map((d) => {
506
+ const owners = [...new Set(d.owed.map((o) => o.owner))];
507
+ const peer = client.roster.find((m) => m.id === owners[0]) ?? { id: owners[0], sessions: [] };
508
+ const est = owners.length === 1 ? pickupEstimate(peer, { now: relayNow, about: { ref: d.ref, goal: d.owed[0].goal }, claimedBy: null, ...(mayWake !== undefined ? { mayWake } : {}) }) : null;
509
+ const why = est && est.kind !== "soon" ? est.says : undefined;
510
+ const mine = client.seenAct(d.ref) ?? own.get(d.ref);
511
+ return { owners, what: mine?.summary ?? mine?.body ?? d.owed[0].body, ...(why ? { why } : {}) };
512
+ });
513
+ const ok = await send(withLabel(composeUnpicked(items, this.cfg.space, { tools, preferred: preferredTool(profile, tools), now: now() })));
514
+ for (const d of due)
515
+ state.notified_at[`act:asked:${d.ref}`] = now();
516
+ state.notified_at["act:asked:last"] = now();
517
+ machineAskedAt = now();
518
+ dirty = true;
519
+ this.opts.log(ok ? `> follow-up alert: ${due.length} request${due.length === 1 ? "" : "s"} of yours nobody picked up` : `! could not show the follow-up alert for ${due.length} request${due.length === 1 ? "" : "s"}`);
520
+ }
521
+ else
522
+ machineAskedAt = before;
523
+ }
524
+ }
395
525
  if (dirty || !existsSync(stateFile))
396
526
  writeState(stateFile, state);
397
527
  const arrived = await client.next(pollMs);
@@ -455,21 +585,66 @@ export class HumanNotifier {
455
585
  writeState(stateFile, state);
456
586
  }
457
587
  }
458
- if (prefs.deliveries) {
459
- for (const r of arrived) {
460
- if (r.act !== "DELIVERED" || neverAlerts(r) || r.from === this.cfg.member || state.notified_at[`act:${r.id}`])
461
- continue;
462
- const goal = r.goal ? client.goals.get(r.goal) : undefined;
588
+ for (const r of arrived) {
589
+ if (!prefs.decisions && !prefs.deliveries)
590
+ break;
591
+ if (r.from === this.cfg.member || neverAlerts(r) || batched.has(r.id) || state.notified_at[`act:${r.id}`])
592
+ continue;
593
+ if (r.act !== "ANSWER" && r.act !== "DELIVERED" && !declineCodeOf(r))
594
+ continue;
595
+ if (client.relayNow() - r.ts > WAITING_MAX_AGE_MS)
596
+ continue;
597
+ const goal = r.goal ? client.goals.get(r.goal) : undefined;
598
+ const code = declineCodeOf(r);
599
+ const asked = r.ref && prefs.decisions ? await ownAct(r.ref) : null;
600
+ let item = null;
601
+ if (!prefs.decisions) { }
602
+ else if (asked && asked.from === this.cfg.member && !byRun(asked)) {
603
+ item = code ? (r.to?.includes(this.cfg.member) ? { kind: "declined", act: r, code, asked: asked.summary ?? asked.body } : null)
604
+ : { kind: r.act === "ANSWER" ? "answer" : "delivery", act: r };
605
+ }
606
+ else if (!r.ref && !code) {
607
+ if (r.act === "ANSWER" && r.to?.includes(this.cfg.member))
608
+ item = { kind: "answer", act: r };
609
+ else if (r.act === "DELIVERED" && goal?.opened_by === this.cfg.member && goal.sig?.role !== "run"
610
+ && (r.to?.length ? r.to.includes(this.cfg.member) : goal.members.length === 2))
611
+ item = { kind: "delivery", act: r };
612
+ }
613
+ if (!item && prefs.deliveries && r.act === "DELIVERED") {
463
614
  const forMe = r.to?.length ? r.to.includes(this.cfg.member) : (goal?.members.includes(this.cfg.member) ?? false);
464
- if (!forMe)
465
- continue;
466
- const ok = await send(withLabel(composeDelivery(r, goal, peerOf(r.from), { tools, preferred: preferredTool(profile, tools), now: now() })));
467
- if (ok) {
468
- state.notified_at[`act:${r.id}`] = now();
469
- writeState(stateFile, state);
470
- this.opts.log(`> delivery alert for ${r.id} from ${r.from}`);
471
- }
615
+ if (forMe)
616
+ item = { kind: "delivery", act: r };
472
617
  }
618
+ if (!item)
619
+ continue;
620
+ if (!replies.length)
621
+ repliesSince = now();
622
+ replies.push(item);
623
+ batched.add(r.id);
624
+ }
625
+ if (replies.length && now() - repliesSince >= (this.opts.replyBatchMs ?? REPLY_BATCH_MS)) {
626
+ const batch = replies;
627
+ replies = [];
628
+ const pin = [teamPinId(this.cfg)];
629
+ const shown = (x) => x.kind !== "declined" && (() => { try {
630
+ return liveReadAt(pin, x.act.id).length > 0;
631
+ }
632
+ catch {
633
+ return false;
634
+ } })();
635
+ const say = batch.filter((x) => !shown(x));
636
+ for (const x of batch) {
637
+ state.notified_at[`act:${x.act.id}`] = now();
638
+ batched.delete(x.act.id);
639
+ }
640
+ for (const x of batch)
641
+ if (x.kind === "declined" && x.act.ref)
642
+ state.notified_at[`act:asked:${x.act.ref}`] = now();
643
+ if (say.length) {
644
+ const ok = await send(withLabel(composeReplies(say, this.cfg.space, (g) => (g ? client.goals.get(g) : undefined), (m) => peerOf(m), { tools, preferred: preferredTool(profile, tools), now: now() })));
645
+ this.opts.log(ok ? `> reply alert: ${say.map((x) => `${x.kind} ${x.act.id} from ${x.act.from}`).join(", ")}` : `! could not show the reply alert for ${say.length}`);
646
+ }
647
+ writeState(stateFile, state);
473
648
  }
474
649
  }
475
650
  }
@@ -478,9 +653,19 @@ export class HumanNotifier {
478
653
  }
479
654
  }
480
655
  }
656
+ export function onlyNetworkFailures(errors) {
657
+ return errors.length > 0 && errors.every((e) => {
658
+ const r = refusalOf(e);
659
+ if (r && PASSING_OR_SAID.has(r.code))
660
+ return true;
661
+ return !r && !/^SPACE_MISMATCH\b/.test(e.trim());
662
+ });
663
+ }
664
+ const PASSING_OR_SAID = new Set(["SPACE_UNREADABLE", "BAD_NONCE", "STORAGE", "SHUTTING_DOWN", "SPACE_DELETED"]);
481
665
  export async function runNotifiers(teams, o) {
482
666
  const sleep = o.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
483
667
  const failing = new Set();
668
+ const lastError = new Map();
484
669
  let gaveUp = false;
485
670
  let giveUp;
486
671
  const allFailing = new Promise((r) => { giveUp = () => r(false); });
@@ -497,9 +682,14 @@ export async function runNotifiers(teams, o) {
497
682
  removed = !!removalRefusal(e.message);
498
683
  if (!removed) {
499
684
  failing.add(i);
685
+ lastError.set(i, e.message);
500
686
  o.log(`[${t.label}] ! not connecting: ${e.message.split("\n")[0]}`);
501
687
  if (failing.size === teams.length) {
502
688
  gaveUp = true;
689
+ try {
690
+ o.onGiveUp?.([...failing].map((n) => lastError.get(n) ?? ""));
691
+ }
692
+ catch { }
503
693
  giveUp();
504
694
  return;
505
695
  }
package/dist/notify.js CHANGED
@@ -428,11 +428,22 @@ export async function decideStop(raw, deps) {
428
428
  const owed = report.obligations ?? [];
429
429
  const closed = new Set(report.closed_goals ?? []);
430
430
  const DEMANDS_RESPONSE = new Set(["ASK", "PROPOSE", "OBJECT", "DELIVERED", "CONTRACT"]);
431
+ const NEWS_WHEN_NAMED = new Set(["HUMAN_REQUIRED", "ESCALATE", "CLOSE", "ACCEPT", "RETRACT", "COMMIT", "JOIN", "LEAVE"]);
432
+ const withHuman = new Set(report.with_human ?? []);
433
+ const worklists = new Set(report.worklist_goals ?? []);
431
434
  const work = acts.filter((a) => {
432
435
  if (a.goal && closed.has(a.goal))
433
436
  return false;
437
+ if (NEWS_WHEN_NAMED.has(a.act))
438
+ return false;
439
+ if (a.id && withHuman.has(a.id))
440
+ return false;
441
+ if (a.goal && worklists.has(a.goal))
442
+ return false;
434
443
  if (a.act === "NOTE" && a.meta && typeof a.meta === "object" && "notice" in a.meta)
435
444
  return false;
445
+ if (a.act === "NOTE" && a.meta && typeof a.meta === "object" && "declined" in a.meta)
446
+ return false;
436
447
  const to = Array.isArray(a.to) ? a.to : [];
437
448
  if (to.length && deps.me && !to.includes(deps.me))
438
449
  return false;
@@ -440,7 +451,8 @@ export async function decideStop(raw, deps) {
440
451
  return true;
441
452
  return DEMANDS_RESPONSE.has(a.act);
442
453
  });
443
- const mustAct = owed.length > 0 || work.length > 0;
454
+ const owedNow = owed.filter((o) => o.kind !== "HUMAN" && o.kind !== "DELIVER");
455
+ const mustAct = owedNow.length > 0 || work.length > 0;
444
456
  if (!mustAct) {
445
457
  clearBlocks(session, deps.home);
446
458
  return acts.length
@@ -463,7 +475,7 @@ export async function decideStop(raw, deps) {
463
475
  }
464
476
  if (acts.length > 6)
465
477
  previews.push(`...and ${acts.length - 6} more`);
466
- for (const o of owed.slice(0, 4))
478
+ for (const o of owedNow.slice(0, 4))
467
479
  previews.push(`you owe: ${o.kind} — ${o.body.slice(0, 120)}`);
468
480
  if (previews.length) {
469
481
  lines.push(fenceBlock("your teammates (first lines only)", previews.join("\n")).block);
@@ -48,6 +48,7 @@ function stepsFor(invite, o) {
48
48
  const npm = ["npm install -g @join-pantheon/cli", `pantheon ${cmd.map(q).join(" ")}`];
49
49
  return { person, npm, agent: agentRequest(invite, o) };
50
50
  }
51
+ export const FOLDER_ASK = "If it ends by asking which folder I work in for the team, show me the folders it lists and ask me which one — a project, or a folder of documents. Run the line it gives for the one I pick, or for a folder I name. Never pick one for me.";
51
52
  export function agentRequest(invite, o) {
52
53
  const base = invite === null || quotableInvite(invite) === invite ? baseOf(o) : null;
53
54
  const what = invite ? "join my teammate's Pantheon team" : "set up Pantheon and start a team";
@@ -63,6 +64,7 @@ export function agentRequest(invite, o) {
63
64
  `On Windows: curl.exe -fsSL ${base}/install.ps1 -o pantheon-install.ps1, read it, then run: powershell -NoProfile -Command "Set-Item Env:PANTHEON_ARGS '${psVerb} ${flags}'; Get-Content -Raw pantheon-install.ps1 | iex"`,
64
65
  `It emails me a 6-digit code and a link (it may land in spam), and prints two words in capitals. When you ask me for the code, show me those two words too: I can give you the code, or open the email's link and type the words there. Then, for the way I used, run the exact command it prints next (it names Pantheon by its full path, since this shell may not find \`pantheon\` yet), with the code in place of <the 6-digit code>.`,
65
66
  ...(invite ? [] : [`If it says I'm already in some teams, show me their names and ask which this computer should join, then run the line it gives for each one I pick. Don't ask me to name a new team unless I say I want one.`]),
67
+ FOLDER_ASK,
66
68
  `The download, the sign-in and the setup need network access, and the setup starts Pantheon's background helpers, which a sandbox blocks. If your shell runs in a sandbox (Codex's does), ask me to approve running each of them outside it. In Codex, ask me to approve running them with network access. If the request is turned down without asking me, or this shell still can't go online, don't look for a way around it: tell me to choose "Ask for approval" in Codex's permissions menu (under the message box), then try again when I say so.`,
67
69
  "What it changes, to tell me before running it:",
68
70
  ...INSTALL_CHANGES.slice(0, 3).map((c) => `- ${c}`),
@@ -72,6 +74,7 @@ export function agentRequest(invite, o) {
72
74
  intro,
73
75
  `It needs Node.js 22.13 or newer. Run: npm install -g @join-pantheon/cli — then: pantheon ${verb} --json`,
74
76
  `If it exits with code 10, I need to sign in once: give me the line it prints to run in a terminal of my own, and run it again after.${invite ? " Don't open the invite link: it holds a one-time secret." : ""}`,
77
+ FOLDER_ASK,
75
78
  ].join("\n");
76
79
  }
77
80
  export function inviteBlock(invite, o) {
package/dist/pending.js CHANGED
@@ -97,9 +97,14 @@ export async function pending(opts) {
97
97
  ]);
98
98
  if (obligationsBody === null && (first || historyBody === null))
99
99
  return null;
100
+ const listOf = (k) => { const v = obligationsBody?.[k]; return Array.isArray(v) ? v.filter((x) => typeof x === "string") : []; };
101
+ const withHuman = new Set(listOf("with_human"));
102
+ const worklists = new Set(listOf("worklist_goals"));
100
103
  const outstanding = (obligationsBody?.obligations ?? [])
101
104
  .filter((o) => !o.claimed)
102
- .filter((o) => o.owner === cfg.member);
105
+ .filter((o) => o.owner === cfg.member)
106
+ .filter((o) => o.kind !== "HUMAN" && o.kind !== "DELIVER" && o.kind !== "CONTINUE")
107
+ .filter((o) => !withHuman.has(o.ref));
103
108
  const workerOnline = !!obligationsBody?.worker_online;
104
109
  const heldNow = Date.now();
105
110
  let autopilot = false;
@@ -276,7 +281,9 @@ export async function pending(opts) {
276
281
  .filter((r) => !r.to || r.to.length === 0 || r.to.includes(cfg.member))
277
282
  .filter((r) => !mine.some((m) => m.seq > r.seq && (m.ref === r.id || (!!r.goal && m.goal === r.goal))))
278
283
  .filter((r) => !checkSigs || verified(r))
279
- .filter((r) => !isRequestFor(r) || !autopilotHolds(r.id));
284
+ .filter((r) => !isRequestFor(r) || !autopilotHolds(r.id))
285
+ .filter((r) => !withHuman.has(r.id))
286
+ .filter((r) => !r.goal || !worklists.has(r.goal) || !!owedRefs?.has(r.id));
280
287
  let copies = new Set();
281
288
  try {
282
289
  copies = copiesAmong(teamPinId(cfg), acts.filter((r) => !!r.sig && trusted(trustIn(r))).map((r) => ({ member: r.from, nonce: r.sig.nonce, id: r.id, sig: r.sig.s })));
@@ -309,7 +316,8 @@ export async function pending(opts) {
309
316
  }
310
317
  const closed_goals = (obligationsBody?.closed_goals ?? []);
311
318
  const report = { seq: seq ?? 0, acts: first ? [] : acts, obligations, closed_goals, left_for_worker,
312
- ...(autopilot ? { autopilot: true, worker_online: workerOnline } : {}) };
319
+ ...(autopilot ? { autopilot: true, worker_online: workerOnline } : {}),
320
+ ...(withHuman.size ? { with_human: [...withHuman] } : {}), ...(worklists.size ? { worklist_goals: [...worklists] } : {}) };
313
321
  return report.acts.length || report.obligations.length || report.left_for_worker ? report : null;
314
322
  }
315
323
  export function render(report) {
package/dist/pickup.js CHANGED
@@ -8,6 +8,12 @@ export function inWords(ms) {
8
8
  const h = Math.round(m / 60);
9
9
  return `about ${h} hour${h === 1 ? "" : "s"}`;
10
10
  }
11
+ export function machineOn(peer) {
12
+ return (peer.sessions ?? []).length > 0;
13
+ }
14
+ export function notSetUpWords(who) {
15
+ return `${who}'s computer is on, but nothing there is set up to take requests while ${who} is away`;
16
+ }
11
17
  const UNAVAILABLE = {
12
18
  no_agent: "Claude Code (or another agent CLI) isn't installed there",
13
19
  kiro_only: "only Kiro is installed there, and Kiro answers in live sessions only",
@@ -38,9 +44,11 @@ export function pickupEstimate(peer, o = {}) {
38
44
  return { kind: "no-wake", says: `${who}'s worker does not take your requests (the team does not let you wake it), so this waits for ${who}${live ? ", who has a live session open" : ""}` };
39
45
  }
40
46
  if (!workerOn) {
41
- return { kind: "offline", says: live
42
- ? `${who}'s worker is offline; ${who} has a live session open, which sees this when their agent next looks`
43
- : `${who}'s worker is offline, so this waits until ${who} is back` };
47
+ if (live)
48
+ return { kind: "not-set-up", says: `${who} has a session open, which sees this when their agent next looks; nothing on ${who}'s computer is set up to take requests while ${who} is away` };
49
+ if (machineOn(peer))
50
+ return { kind: "not-set-up", says: notSetUpWords(who) };
51
+ return { kind: "offline", says: `${who}'s worker is offline, so this waits until ${who} is back` };
44
52
  }
45
53
  const cb = o.claimedBy;
46
54
  if (cb && cb.role === "worker" && !(peer.sessions ?? []).some((s) => s.id === cb.session)) {
@@ -8,22 +8,23 @@ import { lookup } from "node:dns/promises";
8
8
  import { describeRelayFailure, interceptedText, RelayReplyError } from "./network.js";
9
9
  import { PantheonClient } from "./client.js";
10
10
  import { holdsRepo } from "./repo-find.js";
11
- import { folderFacts, folderRefusal, folderRefusalHere, isInside, isTemporaryRefusal } from "./folder-guard.js";
11
+ import { folderFacts, folderRefusal, isInside } from "./folder-guard.js";
12
12
  import { load, loadAll, identity, save, toInvite, resolveFor, repoInfo, bindRepo, bindFolder, folderBinding, DEFAULT_RELAY } from "./config.js";
13
13
  import { looksLikePlaceholder, teamSlug } from "./team-name.js";
14
- import { commandsChosen, loadProfile, wakeChosen, wakeDefault } from "./profile.js";
14
+ import { commandsChosen, decisionAlertsOn, loadProfile, wakeChosen, wakeDefault } from "./profile.js";
15
+ import { turnedOff } from "./setup-changes.js";
15
16
  import { newKeypair } from "./identity.js";
16
17
  import { installForUser } from "./install.js";
17
18
  import { writeIntent, installHooks } from "./notify.js";
18
19
  import { detectAvailable, agentById, agentsNeedingUnsandboxed, folderReaderLine, recordedAgent } from "./agents.js";
19
- import { installService, installedServiceArgs, keepServiceFlags, servicesUnavailable } from "./service.js";
20
+ import { borrowedHome, installService, installedServiceArgs, keepServiceFlags, serviceState, servicesUnavailable } from "./service.js";
20
21
  import { clearTrayQuit } from "./win-host.js";
21
22
  import { ensureNativeNotifier } from "./notifier.js";
22
23
  import { ensureTrayBinary, writeTrayCommands } from "./tray.js";
23
24
  import { desktopUnavailable, ephemeralWarning, hostEnv } from "./host-env.js";
24
- import { existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
25
+ import { mkdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
25
26
  import { localAddresses } from "./machine.js";
26
- import { grant as grantCap, loadPolicy, policyPath, savePolicy, unsandboxedAllowed } from "./worker-policy.js";
27
+ import { grantSelfUpgradeAtSetup, loadPolicy, unsandboxedAllowed } from "./worker-policy.js";
27
28
  import { Relay } from "./relay.js";
28
29
  import { loginShellEnv, which } from "./which.js";
29
30
  const sh = (cmd) => {
@@ -39,6 +40,24 @@ const notLoaded = (r) => r && typeof r === "object" && r.loaded === false
39
40
  : null;
40
41
  export function wireUp(opts, deps = {}) {
41
42
  const installSvc = deps.installService ?? installService;
43
+ const running = (kind) => { try {
44
+ return (deps.running ?? ((k) => !borrowedHome() && serviceState(k).running))(kind);
45
+ }
46
+ catch {
47
+ return false;
48
+ } };
49
+ const offByPerson = (s) => { try {
50
+ return (deps.turnedOff ?? turnedOff)(s) && !running(s === "worker" ? "worker" : "notifier");
51
+ }
52
+ catch {
53
+ return false;
54
+ } };
55
+ const alertsOff = () => { try {
56
+ return offByPerson("alerts") || !(deps.alertsOn ?? decisionAlertsOn)();
57
+ }
58
+ catch {
59
+ return false;
60
+ } };
42
61
  const workerFlags = (wanted, decided) => keepServiceFlags(deps.installService ? null : installedServiceArgs("worker"), wanted, decided);
43
62
  const ensureNotifier = deps.ensureNotifier ?? ensureNativeNotifier;
44
63
  const ensureTray = deps.ensureTray ?? ensureTrayBinary;
@@ -69,6 +88,9 @@ export function wireUp(opts, deps = {}) {
69
88
  if (opts.notifications && !host.desktop) {
70
89
  tools.push({ tool: "notifications", status: desktopUnavailable(host, "desktop alerts") });
71
90
  }
91
+ else if (opts.notifications && alertsOff()) {
92
+ tools.push({ tool: "notifications", status: "off — you turned alerts off on this computer, and they stay so. To turn them on: pantheon setup --alerts decisions" });
93
+ }
72
94
  else if (opts.notifications) {
73
95
  try {
74
96
  const mac = host.platform === "darwin";
@@ -124,6 +146,9 @@ export function wireUp(opts, deps = {}) {
124
146
  if (how === "off") {
125
147
  tools.push({ tool: "worker", status: "off (--no-worker) — this machine cannot answer the team while you are away" });
126
148
  }
149
+ else if (how === "default" && opts.unattended && offByPerson("worker")) {
150
+ tools.push({ tool: "worker", status: "off — you turned it off on this computer, and it stays so: teammates' requests wait for you. To turn it on: pantheon service install worker" });
151
+ }
127
152
  else if (opts.unattended && noServices) {
128
153
  tools.push({ tool: "worker", status: noServices });
129
154
  }
@@ -160,6 +185,9 @@ export function wireUp(opts, deps = {}) {
160
185
  } })();
161
186
  if (reader && !reader.ok)
162
187
  warnings.push(`${reader.line} — until then, teammates' requests for this folder wait for your live session`);
188
+ const selfUpgrade = grantSelfUpgradeAtSetup();
189
+ if (selfUpgrade)
190
+ granted.push(selfUpgrade);
163
191
  }
164
192
  }
165
193
  catch (e) {
@@ -197,12 +225,9 @@ export function wireUp(opts, deps = {}) {
197
225
  } })();
198
226
  if (away.length && unsandboxedAllowed(loadPolicy()))
199
227
  granted.push(`${away.join(", ")} ${away.length === 1 ? "answers" : "answer"} those requests, so teammates get answers even when you're offline. To have them wait for you instead: pantheon setup --unsandboxed no`);
200
- if (!existsSync(policyPath())) {
201
- const pol = loadPolicy();
202
- grantCap(pol, "self_upgrade", "always", "setup-default");
203
- savePolicy(pol);
204
- granted.push(`The worker keeps pantheon itself current with your team's relay (fast-forward pull + rebuild, reported on the ledger). Revoke: pantheon policy revoke self-upgrade`);
205
- }
228
+ const selfUpgrade = grantSelfUpgradeAtSetup();
229
+ if (selfUpgrade)
230
+ granted.push(selfUpgrade);
206
231
  }
207
232
  catch (e) {
208
233
  tools.push({ tool: "worker", status: `could not install: ${e.message}` });
@@ -513,12 +538,14 @@ export async function start(opts) {
513
538
  if (repo && !client.repos.some((r) => r.fingerprint === repo.fingerprint)) {
514
539
  await client.bindRepo(repo.fingerprint, repo.origin).catch((e) => warnings.push(`could not register this repo with the team: ${e.message}`));
515
540
  }
516
- if (!repo && c.spaceId && bindableFolder(process.cwd())) {
541
+ const linkedAlready = reuse && Object.values(loadAll()?.bindings ?? {}).some((b) => b.space === c.spaceId);
542
+ if (!repo && c.spaceId && bindableFolder(process.cwd()) && !linkedAlready) {
517
543
  bindFolder(process.cwd(), c.spaceId);
518
544
  folderBound = process.cwd();
519
545
  }
520
- else if (!repo && c.spaceId)
521
- temporaryFolderNote(process.cwd(), opts.log, c.space);
546
+ else if (!repo && c.spaceId && linkedAlready && !folderBinding(loadAll(), process.cwd()) && bindableFolder(process.cwd())) {
547
+ opts.log(` folder this folder was not added — "${c.space}" already has its folders on this computer (to add this one too: pantheon use ${c.space} --here)`);
548
+ }
522
549
  if (repo && c.spaceId) {
523
550
  const { replaced } = bindRepo(repo, c.spaceId);
524
551
  const was = replaced ?? (here.binding && here.binding.space !== c.spaceId ? here.binding : null);
@@ -613,8 +640,6 @@ export async function join(opts) {
613
640
  bindFolder(process.cwd(), cfg.spaceId);
614
641
  opts.log(` folder ${process.cwd()} → bound to "${cfg.space}" (agents opened here speak in it; no git needed)`);
615
642
  }
616
- else if (!repo && cfg.spaceId)
617
- temporaryFolderNote(process.cwd(), opts.log, cfg.space);
618
643
  if (repo && cfg.spaceId) {
619
644
  const { replaced } = bindRepo(repo, cfg.spaceId);
620
645
  if (replaced)
@@ -660,11 +685,6 @@ export function bindableFolder(dir) {
660
685
  catch { }
661
686
  return true;
662
687
  }
663
- function temporaryFolderNote(dir, log, team) {
664
- const r = folderRefusalHere(dir);
665
- if (isTemporaryRefusal(r))
666
- log(` folder not bound — ${r.why.replace("<team>", team)}`);
667
- }
668
688
  function detectAgent(prior) {
669
689
  return recordedAgent(prior, { fresh: true });
670
690
  }