@join-pantheon/cli 0.33.10 → 0.33.11-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.
package/dist/cli.js CHANGED
@@ -23,8 +23,9 @@ import { DEFAULT_REMINDER_MS, ensureNativeNotifier, HumanNotifier, hudBinaryPath
23
23
  import { linuxDesktopReachable } from "./notice-linux.js";
24
24
  import { desktopUnavailable, hostEnv } from "./host-env.js";
25
25
  import { commandState } from "./command-state.js";
26
- import { AGENT_SURFACES, applyProfileInit, cleanList, dropCatchAllClaims, isAgentSurface, loadProfile, organizationProfile, profileInitialized, saveProfile, teamProfile, wakeDefault, wakeMode } from "./profile.js";
27
- import { runGuide, terminalIO, questionOrNull, parseSetupFlags, questionnaire, optOutsFrom, decisionAreasProblem } from "./setup-guide.js";
26
+ import { AGENT_SURFACES, applyProfileInit, cleanList, dropCatchAllClaims, isAgentSurface, loadProfile, organizationProfile, profileInitialized, profilePath, saveProfile, teamProfile, wakeDefault, wakeMode } from "./profile.js";
27
+ import { runGuide, terminalIO, questionOrNull, parseSetupFlags, questionnaire, optOutsFrom, decisionAreasProblem, ALERT_WORDS, AUTOPILOT_WAKE_OFF } from "./setup-guide.js";
28
+ import { APPROVED_ENV, unsandboxedRisk, beginApproval, changeLabel, composeSetupAlert, dropPending, findPending, gateChanges, lastChangeLine, loadPending, logChanges, machineSetUp, markFirstSetup, askedByLabel, pendingSaid, whoIsAsking } from "./setup-changes.js";
28
29
  import { selectActs, formatAct, resolveRef } from "./history-view.js";
29
30
  import { doctor, render, shareBlock } from "./doctor.js";
30
31
  import { FEEDBACK_ADDRESS } from "./feedback.js";
@@ -40,11 +41,11 @@ import { removeHook, decideStop, writeIntent, clearIntent, readIntent, repairNot
40
41
  import { pending, render as renderPending } from "./pending.js";
41
42
  import { signedRead } from "./reads.js";
42
43
  import { start as qsStart, join as qsJoin, wireUp, teamNameFor, deviceLabel, bindableFolder, startReconnects } from "./quickstart.js";
43
- import { recordedAgent, unattendedReadiness } from "./agents.js";
44
+ import { agentsNeedingUnsandboxed as agentsNeedingUnsandboxedSync, recordedAgent, unattendedReadiness } from "./agents.js";
44
45
  import { agentProblem, PROBLEM_LEAD } from "./readiness-alert.js";
45
46
  import { stripControls } from "./notice.js";
46
47
  import { pickupEstimate } from "./pickup.js";
47
- import { loadPolicy, requestReadinessRecheck, unsandboxedAllowed } from "./worker-policy.js";
48
+ import { loadPolicy, requestReadinessRecheck, unsandboxedAllowed, savePolicy, MODE_LABELS, AUTOPILOT_PLAN_NOTE, effectiveMode, parseMode, describeMode } from "./worker-policy.js";
48
49
  import { alreadyMemberLine, askedLine, configureLines, fetchSeats, inUseLine, offerSeats, seatsForTeam, seatsToMove, startGate, RECOVER_WAITING_EXIT } from "./recover-offer.js";
49
50
  import { hyphenateSpaces, shellArg, teamNameProblem } from "./team-name.js";
50
51
  import { folderRefusalHere, isTemporaryRefusal, projectFolderAnswer } from "./folder-guard.js";
@@ -872,6 +873,270 @@ function sayAgentReadiness(cfg) {
872
873
  }
873
874
  catch { }
874
875
  }
876
+ const SET_UP = (() => { try {
877
+ return machineSetUp({ profileFile: profilePath() });
878
+ }
879
+ catch {
880
+ return false;
881
+ } })();
882
+ function personName() {
883
+ try {
884
+ const c = load();
885
+ if (c) {
886
+ const p = loadProfile(c);
887
+ return p.human.display_name || c.display || c.member;
888
+ }
889
+ }
890
+ catch { }
891
+ try {
892
+ const p = JSON.parse(readFileSync(profilePath(), "utf8"));
893
+ if (typeof p.human?.display_name === "string" && p.human.display_name.trim())
894
+ return p.human.display_name.trim();
895
+ }
896
+ catch { }
897
+ return "you";
898
+ }
899
+ async function alertPendingChanges() {
900
+ try {
901
+ const list = loadPending();
902
+ const { TOAST_CAPS } = await import("./notice-windows.js");
903
+ const plat = process.platform;
904
+ const n = composeSetupAlert(list, { buttons: plat === "darwin" || plat === "win32", ...(plat === "win32" ? { room: TOAST_CAPS.body } : {}) });
905
+ if (!n)
906
+ return false;
907
+ return !!(await Promise.resolve(sendDesktopNotification(n)).catch(() => false));
908
+ }
909
+ catch {
910
+ return false;
911
+ }
912
+ }
913
+ async function protectSetup(changes, o = {}) {
914
+ if (!changes.length)
915
+ return true;
916
+ if (whoIsAsking().kind !== "worker" && changes.some((c) => c.from !== c.to)) {
917
+ const busy = await setupBusy();
918
+ if (busy) {
919
+ console.log(`${busy} Nothing changed.`);
920
+ return false;
921
+ }
922
+ }
923
+ const r = await gateChanges({
924
+ changes, argv: o.replay ?? argv.slice(), processArgv: argv.slice(), cwd: process.cwd(), setUp: SET_UP, yes: argv.includes("--yes"),
925
+ confirm: async (lines) => {
926
+ console.error(`\n${B(lines.length === 1 ? "This changes your setup." : "These change your setup.")}`);
927
+ for (const l of lines)
928
+ console.error(` • ${l}`);
929
+ const a = o.io ? await o.io.ask(`\n Make ${lines.length === 1 ? "this change" : "these changes"}? (y/N)`, "n") : await askOnce(`\n Make ${lines.length === 1 ? "this change" : "these changes"}? [y/N] `);
930
+ return /^y(es)?$/i.test((a ?? "").trim());
931
+ },
932
+ });
933
+ if (r.go)
934
+ return true;
935
+ if (r.why === "pending") {
936
+ const alerted = r.fresh ? await alertPendingChanges() : false;
937
+ if (whoIsAsking().kind === "agent" && whoIsAsking().agent === "no terminal") {
938
+ console.log(`No terminal here, so this was held for ${personName()} to confirm: run it in a terminal window, or approve it with pantheon changes approve ${r.entry.id} from one.`);
939
+ for (const c of r.entry.changes)
940
+ console.log(` ${changeLabel(c)}`);
941
+ return false;
942
+ }
943
+ for (const l of pendingSaid(personName(), r.entry, alerted))
944
+ console.log(l);
945
+ return false;
946
+ }
947
+ if (r.why === "not replayable") {
948
+ console.log(`This change can't wait for ${personName() === "you" ? "your" : `${personName()}'s`} approval from here — run it in a terminal window. Nothing changed.`);
949
+ return false;
950
+ }
951
+ if (r.why === "full") {
952
+ console.log(`Too many changes are waiting for ${personName()} already — nothing changed. They review them with: pantheon changes`);
953
+ return false;
954
+ }
955
+ if (r.why === "declined") {
956
+ console.log("Kept as it is — nothing changed.");
957
+ return false;
958
+ }
959
+ if (r.why === "refused")
960
+ die("a woken run cannot change this machine's setup — a person has to do it here");
961
+ console.log("This change was approved, but the setup changed since it was asked, so nothing was changed. Run it again to be asked afresh.");
962
+ return false;
963
+ }
964
+ async function protectOrStop(changes, replay) {
965
+ if (!(await protectSetup(changes, replay ? { replay } : {})))
966
+ process.exit(0);
967
+ }
968
+ function alertWords() {
969
+ try {
970
+ const c = load();
971
+ const n = c ? loadProfile(c).notifications : undefined;
972
+ const id = !n ? "decisions" : !n.decisions ? "none" : n.worker_done ? "worker" : n.deliveries ? "deliveries" : "decisions";
973
+ return ALERT_WORDS[id];
974
+ }
975
+ catch {
976
+ return ALERT_WORDS.decisions;
977
+ }
978
+ }
979
+ async function stillOwed(ref, space) {
980
+ try {
981
+ const f = loadAll();
982
+ const m = f && space ? findMembership(f, space) : undefined;
983
+ const cfg = f && m ? configFor(f, m, null) : load();
984
+ if (!cfg)
985
+ return null;
986
+ const res = await signedRead(cfg, "/obligations", { member: cfg.member }, { timeoutMs: 6000 });
987
+ if (!res.ok)
988
+ return null;
989
+ const list = (await res.json()).obligations ?? [];
990
+ return list.some((o) => o.ref === ref && o.owner === cfg.member);
991
+ }
992
+ catch {
993
+ return null;
994
+ }
995
+ }
996
+ function agentsNeedingUnsandboxedNames() {
997
+ const xs = agentsNeedingUnsandboxedSync();
998
+ return xs.length < 2 ? xs.join("") : `${xs.slice(0, -1).join(", ")} and ${xs[xs.length - 1]}`;
999
+ }
1000
+ function changesLogLabel() { return join(CONFIG_DIR, "setup-changes.log"); }
1001
+ function setupReplay(a, changes, preset) {
1002
+ const out = ["setup", "--yes"];
1003
+ const has = (k) => changes.some((c) => c.setting === k);
1004
+ if (has("mode") && a.mode)
1005
+ out.push("--mode", a.mode);
1006
+ if (has("wake"))
1007
+ out.push("--wake", a.wake);
1008
+ if (has("commands"))
1009
+ out.push("--commands", a.commands ? "yes" : "no");
1010
+ if (has("unsandboxed") && a.unsandboxed !== undefined)
1011
+ out.push("--unsandboxed", a.unsandboxed ? "yes" : "no");
1012
+ if (has("decides"))
1013
+ out.push("--decides", a.decides.join(",") || "none");
1014
+ if (has("alerts"))
1015
+ out.push("--alerts", a.notifications);
1016
+ if (has("persona"))
1017
+ out.push("--playbook", "yes");
1018
+ if (has("base") && a.base)
1019
+ out.push("--base", a.base);
1020
+ void preset;
1021
+ return out;
1022
+ }
1023
+ async function runBusySaid() {
1024
+ let min = null;
1025
+ try {
1026
+ const { runMinutesLeft, guardMinutesLeft } = await import("./worker.js");
1027
+ min = runMinutesLeft(CONFIG_DIR) ?? guardMinutesLeft(CONFIG_DIR);
1028
+ }
1029
+ catch { }
1030
+ return `Your agent is in the middle of a request${min ? ` (about ${min} min left)` : ""}. Try again when it finishes — or Stop it first from the menu bar, or stop it now with: pantheon stop worker.`;
1031
+ }
1032
+ async function membershipGate() {
1033
+ if (inWokenRun())
1034
+ return;
1035
+ const busy = await setupBusy();
1036
+ if (busy)
1037
+ die(`${busy} Nothing changed.`);
1038
+ }
1039
+ async function setupBusy() {
1040
+ try {
1041
+ const { runInFlight, guardHeld, recoverInterruptedGuard, putBackSaid } = await import("./worker.js");
1042
+ if (runInFlight(CONFIG_DIR) || guardHeld(CONFIG_DIR))
1043
+ return await runBusySaid();
1044
+ const r = recoverInterruptedGuard(CONFIG_DIR);
1045
+ if (r.outcome === "restored" && r.said.length)
1046
+ console.log(`Your worker stopped in the middle of a teammate's request. ${putBackSaid(r.said)}`);
1047
+ if (r.outcome === "failed" && !r.dropped)
1048
+ return `Pantheon could not yet put back what a teammate's request changed while your worker stopped mid-run (${r.why}). Try again in a moment.`;
1049
+ if (r.outcome === "failed")
1050
+ console.log(`Pantheon could not put back what a teammate's request changed while your worker stopped mid-run (${r.why}) — check your setup: pantheon status, pantheon policy.`);
1051
+ return null;
1052
+ }
1053
+ catch {
1054
+ return null;
1055
+ }
1056
+ }
1057
+ async function approvePendingChange(id, by, quiet = false) {
1058
+ const { replayAllowed, approvalApplied, outOfDateLine } = await import("./setup-changes.js");
1059
+ const entry = findPending(id);
1060
+ if (!entry)
1061
+ return { ok: false, said: "that change is no longer waiting — it was answered already, or it is more than a week old" };
1062
+ if (!replayAllowed(entry.argv)) {
1063
+ dropPending(id);
1064
+ return { ok: false, said: `that change's command is not one Pantheon runs on an approval (pantheon ${entry.argv.slice(0, 2).join(" ")}) — nothing changed, and it no longer waits` };
1065
+ }
1066
+ {
1067
+ const busy = await setupBusy();
1068
+ if (busy)
1069
+ return { ok: false, said: busy };
1070
+ }
1071
+ const since = Date.now();
1072
+ const token = beginApproval(id, by);
1073
+ if (!token)
1074
+ return { ok: false, said: "that change is no longer waiting" };
1075
+ const cwd = existsSync(entry.cwd) ? entry.cwd : homedir();
1076
+ const { spawnSync } = await import("node:child_process");
1077
+ const r = spawnSync(process.execPath, [...childNodeFlags(), process.argv[1], ...entry.argv], {
1078
+ cwd, env: { ...process.env, [APPROVED_ENV]: token }, stdio: ["ignore", "pipe", "pipe"], encoding: "utf8", timeout: 5 * 60_000,
1079
+ });
1080
+ dropPending(id);
1081
+ if (approvalApplied(id, since)) {
1082
+ if (r.status !== 0 && !quiet) {
1083
+ const tail = String(r.stderr ?? "").trim().split("\n").filter(Boolean).slice(-3).join("\n");
1084
+ if (tail)
1085
+ console.error(D(tail));
1086
+ }
1087
+ return { ok: true, said: `approved — ${entry.changes.map((c) => changeLabel(c)).join("; ")}` };
1088
+ }
1089
+ const failed = String(r.stderr ?? "").trim().split("\n").filter(Boolean).pop() ?? "";
1090
+ if (r.status !== 0 && failed && !/out of date|setup changed since/.test(failed))
1091
+ return { ok: false, said: `the change did not apply: ${failed.replace(/^pantheon: /, "")}` };
1092
+ return { ok: false, said: outOfDateLine(entry, since) };
1093
+ }
1094
+ async function reviewPendingChanges() {
1095
+ const { loadPending, consequence, askedByWords } = await import("./setup-changes.js");
1096
+ const list = loadPending();
1097
+ if (!list.length) {
1098
+ console.log("Nothing is waiting — no change to your setup needs you.");
1099
+ return 0;
1100
+ }
1101
+ console.log(B(`${list.length === 1 ? "A change" : `${list.length} changes`} to your setup ${list.length === 1 ? "is" : "are"} waiting for you. Nothing changes until you say so.`));
1102
+ for (const p of list) {
1103
+ {
1104
+ const busy = await setupBusy();
1105
+ if (busy) {
1106
+ console.log(`\n${busy} Nothing more was answered — the rest still waits (pantheon changes review).`);
1107
+ return 1;
1108
+ }
1109
+ }
1110
+ console.log(`\n${B(p.changes.map((c) => changeLabel(c)).join("; "))} ${D(`asked ${askedByWords(p.asked_by)}`)}`);
1111
+ for (const c of p.changes)
1112
+ console.log(` ${consequence(c)}`);
1113
+ const a = ((await askOnce(" Approve, Keep as is, or Skip for now? [a/k/S] ")) ?? "").trim().toLowerCase();
1114
+ if (a === "a" || a === "approve") {
1115
+ const r = await approvePendingChange(p.id, "terminal");
1116
+ console.log(r.ok ? ` ${C("approved")}` : ` not done: ${r.said}`);
1117
+ }
1118
+ else if (a === "k" || a === "keep") {
1119
+ const r = await rejectPendingChange(p.id, "terminal");
1120
+ console.log(r.ok ? ` ${C("kept as it is")}` : ` not done: ${r.said}`);
1121
+ }
1122
+ else
1123
+ console.log(D(" skipped — it still waits (pantheon changes)"));
1124
+ }
1125
+ return 0;
1126
+ }
1127
+ async function rejectPendingChange(id, by) {
1128
+ const entry = findPending(id);
1129
+ if (!entry)
1130
+ return { ok: false, said: "that change is no longer waiting" };
1131
+ {
1132
+ const busy = await setupBusy();
1133
+ if (busy)
1134
+ return { ok: false, said: busy };
1135
+ }
1136
+ dropPending(id);
1137
+ logChanges(entry.changes.map((c) => ({ at: Date.now(), setting: c.setting, from: c.from, to: c.to, ...(c.about ? { about: c.about } : {}), asked_by: entry.asked_by, outcome: "kept", approved_by: by, id })));
1138
+ return { ok: true, said: `kept as it is — ${entry.changes.map((c) => changeLabel(c)).join("; ")} was not made` };
1139
+ }
875
1140
  async function guidedSetup(cfg, project, opts = {}) {
876
1141
  if (argv.includes("--no-guide"))
877
1142
  return;
@@ -893,7 +1158,24 @@ async function guidedSetup(cfg, project, opts = {}) {
893
1158
  catch { }
894
1159
  }
895
1160
  const { agentsNeedingUnsandboxed } = await import("./agents.js");
896
- const r = await runGuide(io, { cfg, project, optOut: optOutsFrom(argv), serves, ...(opts.founder !== undefined ? { founder: opts.founder } : {}) }, {
1161
+ let base;
1162
+ if (project && SET_UP) {
1163
+ const info = repoInfo(project);
1164
+ if (info) {
1165
+ const { repo: _r, repoOrigin: _o, ...plain } = cfg;
1166
+ const c = new PantheonClient(plain, undefined, { role: "cli" });
1167
+ try {
1168
+ if (await Promise.race([c.connect().then(() => true, () => false), new Promise((res) => setTimeout(() => res(false), 5_000))]))
1169
+ base = c.repos.find((x) => x.fingerprint === info.fingerprint)?.base ?? null;
1170
+ }
1171
+ catch { }
1172
+ finally {
1173
+ c.dispose();
1174
+ }
1175
+ }
1176
+ }
1177
+ const r = await runGuide(io, { cfg, project, optOut: optOutsFrom(argv), serves, setUp: SET_UP, ...(base !== undefined ? { base } : {}), ...(opts.founder !== undefined ? { founder: opts.founder } : {}) }, {
1178
+ gate: (changes, a) => protectSetup(changes, { replay: setupReplay(a, changes, preset), io }),
897
1179
  unsandboxedAgents: () => { try {
898
1180
  return agentsNeedingUnsandboxed();
899
1181
  }
@@ -933,17 +1215,78 @@ async function guidedSetup(cfg, project, opts = {}) {
933
1215
  },
934
1216
  } : {}),
935
1217
  }, preset);
1218
+ if (r.held)
1219
+ return;
1220
+ if (!SET_UP) {
1221
+ try {
1222
+ markFirstSetup(askedByLabel(whoIsAsking()));
1223
+ }
1224
+ catch { }
1225
+ }
936
1226
  console.error("");
937
1227
  for (const l of r.applied)
938
1228
  console.error(` ${C("✓")} ${l}`);
939
1229
  for (const w of r.warnings)
940
1230
  console.error(`\x1b[33m ! ${w}\x1b[0m`);
1231
+ {
1232
+ const told = modeNoticeOnce();
1233
+ if (told.length) {
1234
+ console.error("");
1235
+ for (const l of told)
1236
+ if (l)
1237
+ console.error(` ${l}`);
1238
+ }
1239
+ }
941
1240
  console.error(D(`\n Change any of this later: pantheon setup`));
942
1241
  }
943
1242
  finally {
944
1243
  rl?.close();
945
1244
  }
946
1245
  }
1246
+ function setupStatusLines() {
1247
+ try {
1248
+ const out = [];
1249
+ const waiting = loadPending();
1250
+ if (waiting.length)
1251
+ out.push(`\x1b[33m${B(`${waiting.length} change${waiting.length === 1 ? "" : "s"} to your setup ${waiting.length === 1 ? "is" : "are"} waiting for you:`)}\x1b[0m ${waiting.map((p) => p.changes.map((c) => changeLabel(c)).join(", ")).join("; ")} ${D("— pantheon changes")}`);
1252
+ const last = lastChangeLine();
1253
+ if (last)
1254
+ out.push(D(` ${last} (pantheon changes --history)`));
1255
+ return out.length ? [...out, ""] : [];
1256
+ }
1257
+ catch {
1258
+ return [];
1259
+ }
1260
+ }
1261
+ function modeStatusLines() {
1262
+ try {
1263
+ const p = loadPolicy();
1264
+ if (p.mode)
1265
+ return [D(` mode: ${p.mode === "autopilot" ? `autopilot ("${MODE_LABELS.autopilot}") (change: pantheon setup --mode here)` : `here ("${MODE_LABELS.here}") (change: pantheon setup --mode autopilot)`}`), ""];
1266
+ return modeNoticeOnce();
1267
+ }
1268
+ catch {
1269
+ return [];
1270
+ }
1271
+ }
1272
+ function modeNoticeOnce() {
1273
+ try {
1274
+ const p = loadPolicy();
1275
+ if (p.mode || p.modeToldAt)
1276
+ return [];
1277
+ p.modeToldAt = Date.now();
1278
+ savePolicy(p);
1279
+ return [
1280
+ `${B("Autopilot:")} your agent can take every teammate's request at once and finish it on its own, even while you work.`,
1281
+ D(` Right now your worker waits while you're at your computer, and that stays as it is unless you choose. ${AUTOPILOT_PLAN_NOTE}`),
1282
+ D(` Choose: pantheon setup --mode autopilot (or keep it as it is: pantheon setup --mode here)`),
1283
+ "",
1284
+ ];
1285
+ }
1286
+ catch {
1287
+ return [];
1288
+ }
1289
+ }
947
1290
  async function workdirFor(cfg, hud) {
948
1291
  const { loadAll, findMembership } = await import("./config.js");
949
1292
  const { pickWorkdir } = await import("./workdir.js");
@@ -1187,6 +1530,13 @@ ${B("control")}
1187
1530
  or it waits a day); recover confirm|cancel <who> is the teammate's side
1188
1531
  pantheon worker stay answerable while you are away
1189
1532
  (--agent claude-code|codex|cursor|copilot|kiro|auto, --persona <name>)
1533
+ pantheon changes changes to your setup an agent asked for, waiting for your yes (review; approve|keep <id>; --history)
1534
+ a setup command run with no terminal (a script, a scheduler) is held the same way: it prints
1535
+ "No terminal here, so this was held …", exits 0, and waits for: pantheon changes approve <id>
1536
+ from a terminal window. Inside an agent's window (Claude Code's !) approving is refused — use
1537
+ a separate Terminal window or the alert's Approve.
1538
+ pantheon mode autopilot (your agent handles everything) or here (you answer when you're here)
1539
+ — choose: pantheon setup --mode autopilot|here
1190
1540
  pantheon policy what this machine's worker may do, in one screen (grant/revoke self-upgrade)
1191
1541
  pantheon policy set run-minutes <5-180> how long one woken run may take here (default 60)
1192
1542
  pantheon policy set idle-seconds <0-900> how long your session must be quiet before your worker takes a request (default 120)
@@ -1215,7 +1565,7 @@ ${B("control")}
1215
1565
  pantheon panic emergency stop: ends the run in flight and the worker, and switches off wake rights in every team you are in
1216
1566
  pantheon doctor [--share] check this machine end to end; --share prints it without names or paths, to paste to us
1217
1567
  pantheon network [--proxy <url> | --direct | --clear] how this machine reaches the relay; save a proxy for every Pantheon process here
1218
- pantheon setup three questions — your name, your role, may a woken run execute commands —
1568
+ pantheon setup a few questions — your name, your role, who finishes teammates' requests (--mode), commands —
1219
1569
  then one screen of defaults to keep or change: who may wake this machine,
1220
1570
  alerts, what you personally decide, playbook, base branch. Re-run any time.
1221
1571
  (--questions prints them for an agent to ask you; answers go back as flags,
@@ -1296,7 +1646,7 @@ function usageFor(command, help) {
1296
1646
  return out.length ? out.join("\n") : null;
1297
1647
  }
1298
1648
  const COMMAND_FLAGS = {
1299
- start: "--space <name> --relay <url> --me <name> --port <n> --ttl <minutes> --no-worker --no-hook --no-notifications --no-menubar --reset --yes --new-team (a team even though you have a seat to bring here)\n and every setup answer as a flag (--name, --title, --wake, --commands, --alerts, --decides …): pantheon setup --questions",
1649
+ start: "--space <name> --relay <url> --me <name> --port <n> --ttl <minutes> --no-worker --no-hook --no-notifications --no-menubar --reset --yes --new-team (a team even though you have a seat to bring here)\n and every setup answer as a flag (--name, --title, --wake, --commands, --alerts, --decides, --mode …): pantheon setup --questions",
1300
1650
  join: "<invite link | line | code> --relay <url> --me <name> --no-worker --no-hook --no-notifications --no-menubar --reset --yes\n and every setup answer as a flag: pantheon setup --questions",
1301
1651
  invite: "--list --revoke <token|all> --may-wake | --no-wake --ttl <minutes>",
1302
1652
  admit: "<member> --may-wake | --no-wake --revoke --forget --yes",
@@ -1313,7 +1663,7 @@ const COMMAND_FLAGS = {
1313
1663
  stop: "[relay|worker|notifier|menubar|all] --port <n>",
1314
1664
  logs: "[relay|worker|notifier|menubar] --follow --n <lines>",
1315
1665
  worker: "--agent <claude-code|codex|cursor|copilot|kiro|auto> --persona <name> --project <dir> --allow-bash --max-runs <n> --max-runs-day <n> --run-minutes <5-180> --grace <s> --once",
1316
- service: "install [relay|worker|notifier|menubar] | restart <kind> | uninstall <kind> --project <dir> --allow-bash --run-minutes <5-180>",
1666
+ service: "install [relay|worker|notifier|menubar] | restart <kind> | uninstall <kind> --project <dir> --allow-bash --run-minutes <5-180> --fresh (a worker's flags from these alone, not kept)",
1317
1667
  doctor: "--share --project <dir>",
1318
1668
  relay: "--port <n> --host <address> --data <dir>",
1319
1669
  use: "<team> --here --yes · pantheon use --unbind (this folder or repo bound to no team again)",
@@ -1322,7 +1672,9 @@ const COMMAND_FLAGS = {
1322
1672
  signin: "--relay <url>",
1323
1673
  signup: "--email <address> --username <name> --relay <url> --label <device name>",
1324
1674
  audit: "--space <team> --since <hours> --json",
1325
- setup: "--questions (and every answer as a flag, with --yes)",
1675
+ setup: "--questions --mode <autopilot|here> (and every answer as a flag, with --yes)",
1676
+ mode: "[autopilot | here]",
1677
+ changes: "[list | review | approve <id> | keep <id>] --history",
1326
1678
  board: "--open --url --watch --keep --stop --focus <id>",
1327
1679
  };
1328
1680
  const HELP_OPAQUE = new Set(["mcp", "hook", "pending", "tray-status", "help", "version", "-v", "--help", "-h"]);
@@ -1447,6 +1799,11 @@ async function main() {
1447
1799
  return;
1448
1800
  }
1449
1801
  }
1802
+ if (process.env[APPROVED_ENV]) {
1803
+ const { approvedRun } = await import("./setup-changes.js");
1804
+ if (!approvedRun())
1805
+ die("this approval is not for this command (or it has expired) — nothing changed. Approve it again: pantheon changes");
1806
+ }
1450
1807
  switch (cmd) {
1451
1808
  case "network": {
1452
1809
  const all = loadAll() ?? die("not configured — sign up or join a team first");
@@ -1781,6 +2138,7 @@ async function main() {
1781
2138
  return;
1782
2139
  }
1783
2140
  case "join": {
2141
+ await membershipGate();
1784
2142
  const invite = argv[1] ?? die("usage: pantheon join <invite> (pantheons://host/space#token, https://www.joinpantheon.network/join/<team>#<token>, or just the code) [setup answers as flags — pantheon setup --questions]");
1785
2143
  const setupFlags = parseSetupFlags(argv);
1786
2144
  if (setupFlags.errors.length)
@@ -2106,7 +2464,7 @@ async function main() {
2106
2464
  if (inWokenRun() && !argv.includes("--questions"))
2107
2465
  die("a woken run cannot change this machine's setup — a person has to run this here");
2108
2466
  if (argv.includes("--questions")) {
2109
- console.log(questionnaire());
2467
+ console.log(questionnaire({ setUp: SET_UP, name: personName() }));
2110
2468
  return;
2111
2469
  }
2112
2470
  const { preset, errors } = parseSetupFlags(argv);
@@ -2230,6 +2588,12 @@ async function main() {
2230
2588
  if (problem)
2231
2589
  console.log(`\x1b[33m${B(`${PROBLEM_LEAD}:`)} ${problem}\x1b[0m\n`);
2232
2590
  }
2591
+ for (const l of setupStatusLines())
2592
+ console.log(l);
2593
+ const allGone = ts.length > 0 && ts.every((c) => !!RM.goneOf(teamOf(c)));
2594
+ if (!allGone)
2595
+ for (const l of modeStatusLines())
2596
+ console.log(l);
2233
2597
  for (const [i, c] of ts.entries()) {
2234
2598
  if (ts.length > 1)
2235
2599
  console.log(`${i ? "\n" : ""}${D("━━━ team")} ${B(c.space)} ${D(`(${i + 1} of ${ts.length}) ━━━`)}`);
@@ -2648,11 +3012,14 @@ async function main() {
2648
3012
  console.log(` ${sn.id} ${sn.agent} ${sn.role}${sn.id === client.session ? D(" <- this command") : ""}`);
2649
3013
  const w = me?.work;
2650
3014
  const ago = (t) => { const m = Math.round((Date.now() - t) / 60_000); return m < 1 ? "under a minute" : `${m}m`; };
2651
- const activity = !w
2652
- ? D("no signal — no turn reported since the relay came up; your next prompt reports one")
2653
- : w.busy
2654
- ? `a turn is in flight${w.busy_since ? ` (for ${ago(w.busy_since)})` : ""} ${D(`the worker waits; a turn past ${LIMITS.activityBusyTtlMs / 60_000}m with no Stop is read as ended`)}`
2655
- : `idle for ${ago(w.idle_since)} ${D(await (async () => { const W = await import("./worker-policy.js"); const n = W.effectiveIdleSeconds({ policy: loadPolicy() }).seconds; return n ? `the worker takes work after ${W.describeIdleSeconds(n)} idle` : "the worker takes work as soon as no turn is in flight"; })())}`;
3015
+ const autopilot = effectiveMode(loadPolicy()) === "autopilot";
3016
+ const activity = autopilot
3017
+ ? `${w?.busy ? "a turn is in flight" : "not reported as busy"} ${D("autopilot — the worker takes teammates' requests at once, whatever you are doing")}`
3018
+ : !w
3019
+ ? D("no signal — no turn reported since the relay came up; your next prompt reports one")
3020
+ : w.busy
3021
+ ? `a turn is in flight${w.busy_since ? ` (for ${ago(w.busy_since)})` : ""} ${D(`the worker waits; a turn past ${LIMITS.activityBusyTtlMs / 60_000}m with no Stop is read as ended`)}`
3022
+ : `idle for ${ago(w.idle_since)} ${D(await (async () => { const W = await import("./worker-policy.js"); const n = W.effectiveIdleSeconds({ policy: loadPolicy() }).seconds; return n ? `the worker takes work after ${W.describeIdleSeconds(n)} idle` : "the worker takes work as soon as no turn is in flight"; })())}`;
2656
3023
  console.log(` your activity: ${activity}`);
2657
3024
  for (const p of client.roster.filter((m) => m.id !== cfg.member)) {
2658
3025
  console.log(` ${p.id.padEnd(16)}${p.online ? C("online") : D("offline")} ${p.sessions.length} window(s)`);
@@ -2673,6 +3040,11 @@ async function main() {
2673
3040
  console.log(` ${l}`);
2674
3041
  if (res.note)
2675
3042
  console.log(D(`\n ${res.note}`));
3043
+ if (what === "all" || what === "worker" || what === "notifier") {
3044
+ const by = askedByLabel(whoIsAsking());
3045
+ logChanges([...(what !== "notifier" ? [{ at: Date.now(), setting: "worker", from: "running", to: "stopped (pantheon stop)", asked_by: by, outcome: "stopped" }] : []),
3046
+ ...(what !== "worker" ? [{ at: Date.now(), setting: "alerts", from: "running", to: "stopped (pantheon stop)", asked_by: by, outcome: "stopped" }] : [])]);
3047
+ }
2676
3048
  return;
2677
3049
  }
2678
3050
  case "logs": {
@@ -2923,6 +3295,16 @@ async function main() {
2923
3295
  need();
2924
3296
  const scope = argv.includes("--user") ? "user" : "project";
2925
3297
  const projectDir = scope === "project" ? process.cwd() : undefined;
3298
+ {
3299
+ const on = (() => { try {
3300
+ return agentHookStates(projectDir).some((x) => x.installed);
3301
+ }
3302
+ catch {
3303
+ return false;
3304
+ } })();
3305
+ if (!on)
3306
+ await protectOrStop([{ setting: "hooks", from: "off", to: "on" }]);
3307
+ }
2926
3308
  console.error(`${B("wake-up hook")}`);
2927
3309
  try {
2928
3310
  const { lines, agents } = installHooks(scope, projectDir ?? process.cwd());
@@ -2948,6 +3330,16 @@ async function main() {
2948
3330
  return;
2949
3331
  }
2950
3332
  if (sub === "uninstall" || sub === "remove") {
3333
+ {
3334
+ const on = (() => { try {
3335
+ return agentHookStates().some((x) => x.installed);
3336
+ }
3337
+ catch {
3338
+ return false;
3339
+ } })();
3340
+ if (on)
3341
+ await protectOrStop([{ setting: "hooks", from: "on", to: "off" }]);
3342
+ }
2951
3343
  console.error(`${B("removing the wake-up hook")}`);
2952
3344
  clearIntent();
2953
3345
  for (const l of removeHook())
@@ -2992,6 +3384,7 @@ async function main() {
2992
3384
  case "leave": {
2993
3385
  const uninstalling = cmd === "uninstall";
2994
3386
  const self = uninstalling ? "uninstall" : "leave";
3387
+ await membershipGate();
2995
3388
  if (uninstalling) {
2996
3389
  if (inWokenRun())
2997
3390
  die("a woken run cannot uninstall Pantheon — a person has to run this here");
@@ -3276,6 +3669,7 @@ async function main() {
3276
3669
  }
3277
3670
  case "panic": {
3278
3671
  console.error(`${B("PANIC — locking down this machine")}\n`);
3672
+ logChanges([{ at: Date.now(), setting: "worker", from: "running", to: "stopped, wake grants revoked (pantheon panic)", asked_by: askedByLabel(whoIsAsking()), outcome: "stopped" }]);
3279
3673
  {
3280
3674
  const { killRecordedRun } = await import("./worker.js");
3281
3675
  const killed = killRecordedRun(dirname(CONFIG_PATH));
@@ -3679,6 +4073,18 @@ async function main() {
3679
4073
  if (sub === "init") {
3680
4074
  const name = argv[2] ?? die("usage: pantheon persona init <name> [--user]");
3681
4075
  const scope = argv.includes("--user") ? "user" : "project";
4076
+ {
4077
+ const there = personaByName(loadPersonas(project), name);
4078
+ if (there && there.scope === scope) {
4079
+ console.error(`${B("persona already there")} ${there.file} — kept as it is (edit it to change it)`);
4080
+ return;
4081
+ }
4082
+ }
4083
+ {
4084
+ const had = loadPersonas(project);
4085
+ if (!personaByName(had, name))
4086
+ await protectOrStop([{ setting: "persona", about: name, from: had.length ? `your personas (${had.map((p) => p.name).join(", ")})` : "any request", to: name }]);
4087
+ }
3682
4088
  let file;
3683
4089
  try {
3684
4090
  file = initPersona(name, scope, project);
@@ -3819,6 +4225,17 @@ async function main() {
3819
4225
  if (!surface && !publicChange && !vague.dropped.length) {
3820
4226
  die("usage: pantheon profile set [--surface codex|claude-code|cursor|copilot|kiro] [--name name] [--title title] [--responsibilities a,b] [--human-required a,b] [--agent-can-decide a,b] [--keywords 'domain=word|word;domain=word']");
3821
4227
  }
4228
+ {
4229
+ const held = (d) => profile.authority[d] === "human_required";
4230
+ const changes = [
4231
+ ...(humanRequired ?? []).filter((d) => !held(d)).map((d) => ({ setting: "decides", about: d, from: "agents", to: "yours" })),
4232
+ ...(agentCanDecide ?? []).filter((d) => held(d)).map((d) => ({ setting: "decides", about: d, from: "yours", to: "agents" })),
4233
+ ...(selectedSurface && selectedSurface !== profile.agent.primary_surface ? [{ setting: "agent", from: profile.agent.primary_surface, to: selectedSurface }] : []),
4234
+ ];
4235
+ const replay = ["profile", "set", ...["human-required", "agent-can-decide", "surface", "space"].flatMap((f) => flag(f) !== undefined ? [`--${f}`, flag(f)] : [])];
4236
+ if (changes.length && !inWokenRun())
4237
+ await protectOrStop(changes, replay);
4238
+ }
3822
4239
  if (flag("space")) {
3823
4240
  const pf = loadAll() ?? die("not configured");
3824
4241
  const m = findMembership(pf, flag("space")) ?? die(`you are not in a team called "${flag("space")}"`);
@@ -4253,6 +4670,12 @@ async function main() {
4253
4670
  unchecked = true;
4254
4671
  }
4255
4672
  }
4673
+ {
4674
+ const { isApprovedWaker } = await import("./worker-policy.js");
4675
+ const was = isApprovedWaker(loadPolicy(), [cfg.spaceId, cfg.space], who);
4676
+ if (!inWokenRun())
4677
+ await protectOrStop([{ setting: "waker", about: who, from: was ? "allowed" : "not allowed", to: sub === "allow" ? "allowed" : "not allowed" }]);
4678
+ }
4256
4679
  const r = setLocalWaker([cfg.spaceId, cfg.space], who, sub === "allow");
4257
4680
  if (!r.ok)
4258
4681
  die(r.why);
@@ -4305,6 +4728,95 @@ async function main() {
4305
4728
  die(`${near.d <= 2 ? `"${sub}" — did you mean: pantheon wake ${near.k}?\n` : ""}usage: pantheon wake allow <name> [--space <team>] · pantheon wake deny <name> [--space <team>] · pantheon wake list`);
4306
4729
  }
4307
4730
  }
4731
+ case "mode": {
4732
+ const want = argv[1];
4733
+ if (want !== undefined && want !== "show") {
4734
+ const m = parseMode(want) ?? die(`pantheon mode takes autopilot or here, not "${want}" — or nothing, to show it`);
4735
+ if (inWokenRun())
4736
+ die("a woken run cannot change how teammates' requests are handled here — a person has to choose it");
4737
+ const now = effectiveMode(loadPolicy());
4738
+ await protectOrStop([{ setting: "mode", from: now, to: m }]);
4739
+ const p = loadPolicy();
4740
+ if (p.mode !== m) {
4741
+ p.mode = m;
4742
+ savePolicy(p);
4743
+ }
4744
+ console.log(`${C("set")} ${describeMode(m)}`);
4745
+ if (m === "autopilot") {
4746
+ try {
4747
+ const c = load();
4748
+ if (c && wakeMode(loadProfile(c)) === "no")
4749
+ console.log(`\x1b[33m ! ${AUTOPILOT_WAKE_OFF}\x1b[0m`);
4750
+ }
4751
+ catch { }
4752
+ }
4753
+ if (m === "autopilot")
4754
+ console.log(D(` ${AUTOPILOT_PLAN_NOTE}`));
4755
+ console.log(D(` from your worker's next look, no restart${m === "autopilot" ? "; back to waiting for you: pantheon mode here" : "; everything to your agent: pantheon mode autopilot"}`));
4756
+ return;
4757
+ }
4758
+ const p = loadPolicy();
4759
+ const m = effectiveMode(p);
4760
+ console.log(`${B("mode")} ${m === "autopilot" ? C(describeMode(m)) : describeMode(m)}${p.mode ? "" : D(" (never chosen on this machine — today's behaviour)")}`);
4761
+ console.log(D(m === "autopilot"
4762
+ ? `\n Back to waiting for you: pantheon setup --mode here`
4763
+ : `\n Everything to your agent: pantheon setup --mode autopilot\n ${AUTOPILOT_PLAN_NOTE}`));
4764
+ return;
4765
+ }
4766
+ case "changes": {
4767
+ const { loadPending, readChangeLog, consequence, askedByWords, whoIsAsking, ago } = await import("./setup-changes.js");
4768
+ const sub = argv[1];
4769
+ if (sub === "review" || sub === "approve" || sub === "reject" || sub === "keep") {
4770
+ const busy = await setupBusy();
4771
+ if (busy)
4772
+ die(`${busy} Nothing changed.`);
4773
+ }
4774
+ if (sub === "review") {
4775
+ if (whoIsAsking().kind !== "terminal")
4776
+ die(`only ${personName()} can review changes to their setup — in their own terminal: pantheon changes review. Nothing changed.`);
4777
+ process.exit(await reviewPendingChanges());
4778
+ }
4779
+ if (sub === "approve" || sub === "reject" || sub === "keep") {
4780
+ const id = argv[2] ?? die(`usage: pantheon changes ${sub} <id> (pantheon changes lists them)`);
4781
+ if (whoIsAsking().kind !== "terminal")
4782
+ die(`${sub === "approve" ? "Approve" : "Answer it"} from a separate Terminal window, or click ${sub === "approve" ? "Approve" : "Keep as is"} on the alert. A command run inside an agent's window (or with no terminal) can't answer a change to ${personName() === "you" ? "your" : `${personName()}'s`} setup: pantheon changes ${sub} ${id}. Nothing changed.`);
4783
+ const r = sub === "approve" ? await approvePendingChange(id, "terminal") : await rejectPendingChange(id, "terminal");
4784
+ console.log(r.ok ? `${C(sub === "approve" ? "approved" : "kept")} ${r.said.replace(/^(approved|kept as it is) — /, "")}` : `not done: ${r.said}`);
4785
+ if (!r.ok)
4786
+ process.exit(1);
4787
+ return;
4788
+ }
4789
+ if (sub === "history" || argv.includes("--history")) {
4790
+ const log = readChangeLog().slice(-40);
4791
+ if (!log.length) {
4792
+ console.log(D("no setup changes recorded on this machine yet"));
4793
+ return;
4794
+ }
4795
+ console.log(B("setup changes on this machine") + D(` (${changesLogLabel()})`));
4796
+ for (const e of log) {
4797
+ const what = e.setting === "first-setup" ? "First setup" : changeLabel({ setting: e.setting, from: e.from, to: e.to, ...(e.about ? { about: e.about } : {}) });
4798
+ console.log(` ${new Date(e.at).toLocaleString()} ${what} ${D(`${e.outcome}, ${askedByWords(e.asked_by)}${e.approved_by ? `, answered ${askedByWords(e.approved_by)}` : ""}`)}`);
4799
+ }
4800
+ return;
4801
+ }
4802
+ if (sub && sub !== "list")
4803
+ die("usage: pantheon changes [list | review | approve <id> | keep <id> | --history]");
4804
+ const list = loadPending();
4805
+ if (!list.length) {
4806
+ console.log(`${D("nothing waiting")} — no change to your setup is waiting for you. ${D("History: pantheon changes --history")}`);
4807
+ return;
4808
+ }
4809
+ console.log(B(`${list.length} change${list.length === 1 ? "" : "s"} to your setup waiting for you`));
4810
+ for (const p of list) {
4811
+ console.log(`\n ${C(p.id)} ${D(`asked ${askedByWords(p.asked_by)}, ${ago(Date.now() - p.at)}`)}`);
4812
+ for (const c of p.changes) {
4813
+ console.log(` ${changeLabel(c)}`);
4814
+ console.log(` ${D(consequence(c))}`);
4815
+ }
4816
+ console.log(` approve: ${C(`pantheon changes approve ${p.id}`)} keep as it is: ${C(`pantheon changes keep ${p.id}`)}`);
4817
+ }
4818
+ return;
4819
+ }
4308
4820
  case "policy": {
4309
4821
  const { loadPolicy, savePolicy, grant, revoke, inWokenRun, CAPABILITY_ARGS, parseRunMinutes, runMinutesProblem, effectiveRunMinutes, describeRunMinutes, RUN_MINUTES, parseIdleSeconds, idleSecondsProblem, effectiveIdleSeconds, describeIdleSeconds, IDLE_SECONDS } = await import("./worker-policy.js");
4310
4822
  const { COMMAND_GRANT_SCOPE } = await import("./agents.js");
@@ -4317,18 +4829,19 @@ async function main() {
4317
4829
  if (inWokenRun())
4318
4830
  die("a woken run cannot change how long the worker waits for you — a person has to run this here");
4319
4831
  const raw = argv[3];
4832
+ const next = raw === "default" ? IDLE_SECONDS.default : parseIdleSeconds(raw) ?? die(idleSecondsProblem(raw));
4833
+ const was = effectiveIdleSeconds({ policy: loadPolicy() }).seconds;
4834
+ await protectOrStop([{ setting: "idle-seconds", from: String(was), to: String(next) }]);
4320
4835
  const p = loadPolicy();
4321
4836
  if (raw === "default")
4322
4837
  delete p.idleSeconds;
4323
- else {
4324
- const n = parseIdleSeconds(raw);
4325
- if (n === null)
4326
- die(idleSecondsProblem(raw));
4327
- p.idleSeconds = n;
4328
- }
4838
+ else
4839
+ p.idleSeconds = next;
4329
4840
  savePolicy(p);
4330
4841
  const now = effectiveIdleSeconds({ policy: p });
4331
4842
  console.log(`${C("set")} idle wait — your worker takes a teammate's request ${now.seconds ? `after your session has been quiet ${describeIdleSeconds(now.seconds)}` : "with no extra wait once your session is quiet (a turn in flight still holds it)"}${now.from === "default" ? " (the default)" : ""} ${D("— from its next look, no restart; teammates are told the wait")}`);
4843
+ if (effectiveMode(p) === "autopilot")
4844
+ console.log(D(` you are on autopilot, which takes requests at once and does not wait — this applies if you switch to: pantheon setup --mode here`));
4332
4845
  if (workerProc().running)
4333
4846
  console.log(D(` a worker started with --idle keeps its own value`));
4334
4847
  return;
@@ -4336,15 +4849,14 @@ async function main() {
4336
4849
  if (inWokenRun())
4337
4850
  die("a woken run cannot change how long runs may take — a person has to run this here");
4338
4851
  const raw = argv[3];
4852
+ const next = raw === "default" ? RUN_MINUTES.default : parseRunMinutes(raw) ?? die(runMinutesProblem(raw));
4853
+ const was = effectiveRunMinutes({ policy: loadPolicy() }).minutes;
4854
+ await protectOrStop([{ setting: "run-minutes", from: String(was), to: String(next) }]);
4339
4855
  const p = loadPolicy();
4340
4856
  if (raw === "default")
4341
4857
  delete p.runMinutes;
4342
- else {
4343
- const n = parseRunMinutes(raw);
4344
- if (n === null)
4345
- die(runMinutesProblem(raw));
4346
- p.runMinutes = n;
4347
- }
4858
+ else
4859
+ p.runMinutes = next;
4348
4860
  savePolicy(p);
4349
4861
  const now = effectiveRunMinutes({ policy: p });
4350
4862
  console.log(`${C("set")} run limit — ${describeRunMinutes(now)} ${D("— from the next run; a run already going keeps the limit it started with")}`);
@@ -4358,6 +4870,19 @@ async function main() {
4358
4870
  const cap = caps.find((c) => c === capArg) ?? die(`unknown capability "${argv[2] ?? ""}" — capabilities: ${caps.map((c) => CAPABILITY_ARGS[c]).join(", ")}`);
4359
4871
  if (sub === "grant" && inWokenRun())
4360
4872
  die("a woken run cannot grant this machine anything — a person has to run this here");
4873
+ {
4874
+ const { unsandboxedAllowed } = await import("./worker-policy.js");
4875
+ const before = loadPolicy();
4876
+ const on = cap === "unsandboxed_runs" ? unsandboxedAllowed(before) : !!before.grants[cap];
4877
+ const setting = cap === "run_commands" ? "commands" : cap === "unsandboxed_runs" ? "unsandboxed" : "self-upgrade";
4878
+ const names = cap === "unsandboxed_runs" ? (() => { try {
4879
+ return agentsNeedingUnsandboxedNames();
4880
+ }
4881
+ catch {
4882
+ return "";
4883
+ } })() : "";
4884
+ await protectOrStop([{ setting, ...(names ? { about: names } : {}), from: on ? "on" : "off", to: sub === "grant" ? "on" : "off" }]);
4885
+ }
4361
4886
  const p = loadPolicy();
4362
4887
  if (sub === "grant")
4363
4888
  grant(p, cap, "always", "policy-command");
@@ -4368,7 +4893,12 @@ async function main() {
4368
4893
  ? (sub === "grant" ? "— the worker keeps pantheon current with the relay" : "— the worker will ask in your approvals inbox when it falls behind")
4369
4894
  : cap === "unsandboxed_runs"
4370
4895
  ? (sub === "grant"
4371
- ? "— Codex, Cursor and Copilot answer teammates' requests while you're away, so nobody waits on you. To have them wait for you instead: pantheon policy revoke unsandboxed-runs"
4896
+ ? `— ${(() => { const who = (() => { try {
4897
+ return agentsNeedingUnsandboxedNames() || undefined;
4898
+ }
4899
+ catch {
4900
+ return undefined;
4901
+ } })(); return `${who ?? "Codex, Cursor and Copilot"} answer${who && !/,| and /.test(who) ? "s" : ""} teammates' requests while you're away, so nobody waits on you.${argv.includes("--yes") || !SET_UP ? ` ${unsandboxedRisk(who)}` : ""}`; })()} To have them wait for you instead: pantheon policy revoke unsandboxed-runs`
4372
4902
  : "— Codex, Cursor and Copilot leave teammates' requests for you to pick up when you're back; Claude Code still answers them. On again: pantheon policy grant unsandboxed-runs")
4373
4903
  : (sub === "grant" ? `— ${COMMAND_GRANT_SCOPE}` : "— woken runs are back to edits only");
4374
4904
  console.log(`${C(sub === "grant" ? "granted" : "revoked")} ${CAPABILITY_ARGS[cap]} ${D(said)}`);
@@ -4420,8 +4950,13 @@ async function main() {
4420
4950
  const wf = workerFlagRunMinutes();
4421
4951
  if (wf !== null)
4422
4952
  console.log(` \x1b[33mthe running worker was started with --run-minutes ${wf}, which it uses instead\x1b[0m`);
4423
- const idle = effectiveIdleSeconds({ policy: p });
4424
- console.log(` idle wait ${idle.seconds ? `${describeIdleSeconds(idle.seconds)} of quiet in your session before your worker takes a request` : "none — your worker takes a request as soon as no turn is in flight in your session"}${D(` (${idle.from === "default" ? "the default" : "set on this machine"}; change: pantheon policy set idle-seconds <${IDLE_SECONDS.min}-${IDLE_SECONDS.max}>)`)}`);
4953
+ if (effectiveMode(p) === "autopilot")
4954
+ console.log(` mode ${C("autopilot")}${D(` ("${MODE_LABELS.autopilot}"): your worker takes teammates' requests at once, even while you work (change: pantheon setup --mode here)`)}`);
4955
+ else {
4956
+ console.log(` mode here${D(` ("${MODE_LABELS.here}"): requests wait while you're at your computer (change: pantheon setup --mode autopilot)`)}`);
4957
+ const idle = effectiveIdleSeconds({ policy: p });
4958
+ console.log(` idle wait ${idle.seconds ? `${describeIdleSeconds(idle.seconds)} of quiet in your session before your worker takes a request` : "none — your worker takes a request as soon as no turn is in flight in your session"}${D(` (${idle.from === "default" ? "the default" : "set on this machine"}; change: pantheon policy set idle-seconds <${IDLE_SECONDS.min}-${IDLE_SECONDS.max}>)`)}`);
4959
+ }
4425
4960
  }
4426
4961
  console.log(`\n${D("Change it: pantheon policy grant|revoke self-upgrade|run-commands|unsandboxed-runs · pantheon policy set run-minutes <n> | idle-seconds <n> · personas: pantheon persona init · who may wake this machine: pantheon wake allow|deny <who>")}`);
4427
4962
  return;
@@ -4469,6 +5004,7 @@ async function main() {
4469
5004
  c.on("exit", (status) => { clearTimeout(t); done(status === 0); });
4470
5005
  }) : null,
4471
5006
  runBrief: () => spawnSync(process.execPath, self(["brief"]), { stdio: "inherit", env: childEnv }).status ?? 1,
5007
+ runReview: () => spawnSync(process.execPath, self(["changes", "review"]), { stdio: "inherit", env: childEnv }).status ?? 1,
4472
5008
  print: (l) => console.log(l),
4473
5009
  pause: async () => {
4474
5010
  if (!process.stdin.isTTY)
@@ -4560,12 +5096,68 @@ async function main() {
4560
5096
  const run = runInFlight(CONFIG_DIR);
4561
5097
  if (age > HUD_ACTION_MAX_AGE_MS)
4562
5098
  refuse(`that menu-bar action was written ${Math.round(age / 1000)}s ago — click it again`);
4563
- if (run && st.mtimeMs >= run.at - 1_000)
4564
- refuse("that menu-bar action was written while a woken run was working on this machine, so it is not trusted — click it again once the run is done");
5099
+ if (run && st.mtimeMs >= run.at - 1_000 && !(parsed?.action === "run" && typeof parsed.ref === "string" && parsed.ref === run.ref)) {
5100
+ refuse(parsed?.action === "change" || parsed?.action === "changes" ? await runBusySaid()
5101
+ : parsed?.action === "run" ? `Your agent is in the middle of another request. Take over or Stop this one when it finishes — or Stop that one first.`
5102
+ : "that menu-bar action was written while a woken run was working on this machine, so it is not trusted — click it again once the run is done");
5103
+ }
4565
5104
  hud = parsed;
4566
5105
  }
4567
5106
  if (argv.includes("--only-action") && !hud)
4568
5107
  refuse("that action was already taken or is no longer there — click it again");
5108
+ if (hud?.action === "change") {
5109
+ const { whoIsAsking } = await import("./setup-changes.js");
5110
+ if (whoIsAsking(process.env, true).kind !== "terminal")
5111
+ refuse(`only ${personName()} can answer a change to their setup`);
5112
+ const id = typeof hud.change === "string" && /^c_[0-9a-f]{8}$/.test(hud.change) ? hud.change : refuse("that is not a setup change");
5113
+ const by = hud.by === "board" || hud.by === "tray" ? hud.by : "alert";
5114
+ const r = hud.answer === "approve" ? await approvePendingChange(id, by, true) : await rejectPendingChange(id, by);
5115
+ console.log(r.ok ? r.said : `not sent: ${r.said}`);
5116
+ if (by === "alert" && hud.answer === "approve" && !r.ok) {
5117
+ const { SETUP_ALERT_TAG } = await import("./setup-changes.js");
5118
+ const left = loadPending().length;
5119
+ await Promise.resolve(sendDesktopNotification({ kind: "setup", who: "Pantheon", heading: "Nothing changed",
5120
+ context: "", body: `${r.said.replace(/^./, (c) => c.toUpperCase())}${left ? `\n${left} more change${left === 1 ? "" : "s"} still wait${left === 1 ? "s" : ""}: pantheon changes` : ""}`,
5121
+ ttl: 15, sound: false, tag: SETUP_ALERT_TAG })).catch(() => false);
5122
+ }
5123
+ process.exit(r.ok ? 0 : 1);
5124
+ }
5125
+ if (hud?.action === "changes") {
5126
+ const { whoIsAsking } = await import("./setup-changes.js");
5127
+ if (whoIsAsking().kind !== "terminal")
5128
+ refuse(`only ${personName()} can review changes to their setup — in their own terminal: pantheon changes review`);
5129
+ process.exit(await reviewPendingChanges());
5130
+ }
5131
+ if (hud?.action === "run") {
5132
+ const { whoIsAsking } = await import("./setup-changes.js");
5133
+ if (whoIsAsking(process.env, true).kind !== "terminal")
5134
+ refuse(`only ${personName()} can stop their agent's work from here`);
5135
+ const { RUN_REF, requestRunStop, stopSaid } = await import("./run-control.js");
5136
+ const ref = typeof hud.ref === "string" && RUN_REF.test(hud.ref) ? hud.ref : refuse("that is not a request this machine can stop");
5137
+ const how = hud.run === "takeover" || hud.run === "stop" ? hud.run : refuse("that is not Take over or Stop");
5138
+ const { runInFlight } = await import("./worker.js");
5139
+ const run = runInFlight(CONFIG_DIR);
5140
+ const running = run?.ref === ref;
5141
+ if (!running && !ref.startsWith("cont:")) {
5142
+ const owed = await stillOwed(ref, typeof hud.space === "string" ? hud.space : undefined);
5143
+ if (owed === false)
5144
+ refuse("That's already finished — nothing to stop.");
5145
+ }
5146
+ if (!running && ref.startsWith("cont:")) {
5147
+ const { continuationDone } = await import("./continued.js");
5148
+ if (continuationDone(ref.slice(5), CONFIG_DIR))
5149
+ refuse("That's already finished — nothing to stop.");
5150
+ }
5151
+ const team = typeof hud.space === "string" && hud.space ? hud.space : (() => { try {
5152
+ return load()?.space;
5153
+ }
5154
+ catch {
5155
+ return undefined;
5156
+ } })();
5157
+ requestRunStop({ ref, how, ...(team ? { space: team } : {}) });
5158
+ console.log(stopSaid(how, running));
5159
+ process.exit(0);
5160
+ }
4569
5161
  }
4570
5162
  let cfg = (() => {
4571
5163
  if (!hud?.space) {
@@ -5462,6 +6054,9 @@ async function main() {
5462
6054
  const sub = argv[1] ?? "install";
5463
6055
  const kind = argv.includes("relay") ? "relay" : argv.includes("notifier") ? "notifier" : argv.includes("menubar") ? "menubar" : "worker";
5464
6056
  if (sub === "uninstall" || sub === "stop") {
6057
+ if ((kind === "worker" || kind === "notifier") && serviceInstalled(kind)) {
6058
+ await protectOrStop([kind === "worker" ? { setting: "worker", from: "on", to: "off" } : { setting: "alerts", from: alertWords(), to: "none" }]);
6059
+ }
5465
6060
  console.error(`${B(`removing the pantheon ${kind} service`)}`);
5466
6061
  for (const l of uninstallService(kind))
5467
6062
  console.error(l);
@@ -5516,6 +6111,8 @@ async function main() {
5516
6111
  }
5517
6112
  if (kind === "notifier") {
5518
6113
  need();
6114
+ if (!serviceInstalled("notifier"))
6115
+ await protectOrStop([{ setting: "alerts", from: "none", to: alertWords() === "none" ? "decisions that need you" : alertWords() }]);
5519
6116
  const extraN = [];
5520
6117
  if (flag("remind"))
5521
6118
  extraN.push("--remind", flag("remind"));
@@ -5566,11 +6163,25 @@ async function main() {
5566
6163
  if (flag(f))
5567
6164
  extra.push(`--${f}`, flag(f));
5568
6165
  }
6166
+ {
6167
+ const { installedServiceArgs, keepServiceFlags } = await import("./service.js");
6168
+ const now = installedServiceArgs("worker");
6169
+ const next = argv.includes("--fresh") ? extra : keepServiceFlags(now, extra);
6170
+ extra.splice(0, extra.length, ...next);
6171
+ const { describeWorkerFlags } = await import("./setup-changes.js");
6172
+ await protectOrStop([now === null ? { setting: "worker", from: "off", to: "on" } : { setting: "worker", from: describeWorkerFlags(now), to: describeWorkerFlags(next) }]);
6173
+ }
5569
6174
  console.error(`${B("installing the pantheon worker as a background service")}`);
5570
6175
  console.error(D(flag("project") ? ` project ${project} (this checkout only)` : ` serves every repo and folder bound to a team on this machine`));
5571
6176
  for (const l of installService(kind, project, extra))
5572
6177
  console.error(l);
5573
- console.error(`\n${D("It only acts on requests from teammates approved on this machine — you are asked the first time each one needs it — one run at a time.")}`);
6178
+ {
6179
+ const { wakeChosen } = await import("./profile.js");
6180
+ const w = wakeChosen();
6181
+ console.error(`\n${D(w === "anyone" ? "It acts on requests from any teammate (your wake setting: anyone), one run at a time."
6182
+ : w === "no" ? "Your wake setting is no, so it starts no work on teammates' requests until you change it (pantheon setup --wake anyone or approved)."
6183
+ : "It only acts on requests from teammates approved on this machine — you are asked the first time each one needs it — one run at a time.")}`);
6184
+ }
5574
6185
  return;
5575
6186
  }
5576
6187
  case "spaces": {
@@ -5600,6 +6211,7 @@ async function main() {
5600
6211
  return;
5601
6212
  }
5602
6213
  case "use": {
6214
+ await membershipGate();
5603
6215
  const all = loadAll() ?? die("not configured. Run `pantheon signup` first.");
5604
6216
  if (argv.includes("--unbind")) {
5605
6217
  const { folderBinding } = await import("./config.js");
@@ -5609,7 +6221,10 @@ async function main() {
5609
6221
  if (fb && !key)
5610
6222
  die(`this folder is not bound itself — ${fb.path} is, and this folder is inside it. Run pantheon use --unbind there.`);
5611
6223
  const was = key ? all.bindings?.[key] : undefined;
5612
- if (!key || !was || !unbindRepo(key))
6224
+ if (!key || !was)
6225
+ die(`${r ? "this repo" : "this folder"} is not bound to a team — nothing to undo`);
6226
+ await protectOrStop([{ setting: "folder", about: r ? (r.origin ?? r.root) : was.path, from: "bound", to: "unbound" }]);
6227
+ if (!unbindRepo(key))
5613
6228
  die(`${r ? "this repo" : "this folder"} is not bound to a team — nothing to undo`);
5614
6229
  console.error(`${B("unbound")} ${r ? (r.origin ?? r.root) : was.path} — it was "${findMembership(all, was.space)?.name ?? was.space}"; it now resolves as a folder bound to no team`);
5615
6230
  return;
@@ -5618,6 +6233,19 @@ async function main() {
5618
6233
  const m = findMembership(all, ref) ?? die(`you are not in a team called "${ref}". Yours: ${Object.values(all.spaces ?? {}).map((x) => x.name).join(", ") || "none"}`);
5619
6234
  if (argv.includes("--here")) {
5620
6235
  const r = repoInfo(process.cwd());
6236
+ const askFolder = async () => {
6237
+ const { folderBinding } = await import("./config.js");
6238
+ const cur = r ? all.bindings?.[r.fingerprint] : folderBinding(all, process.cwd());
6239
+ const here = r ? true : !!cur && cur.path === (() => { try {
6240
+ return realpathSync.native(process.cwd());
6241
+ }
6242
+ catch {
6243
+ return process.cwd();
6244
+ } })();
6245
+ if (cur && here && cur.space === m.id)
6246
+ return;
6247
+ await protectOrStop([{ setting: "folder", about: r ? (r.origin ?? r.root) : process.cwd(), from: cur && here ? `bound to ${findMembership(all, cur.space)?.name ?? cur.space}` : "not bound", to: `bound to ${m.name}` }]);
6248
+ };
5621
6249
  if (!r) {
5622
6250
  for (let d = resolve(process.cwd());; d = dirname(d)) {
5623
6251
  if (existsSync(join(d, ".git")))
@@ -5632,6 +6260,7 @@ async function main() {
5632
6260
  const what = refused.kind === "root" ? "the root of the disk" : refused.kind === "home" ? "your home folder" : "a folder that holds your home folder";
5633
6261
  die(`this is ${what}: binding it puts every folder under it in "${m.name}", and an agent opened anywhere there would speak for that team.\n Bind a project folder instead, or if you mean it: pantheon use ${m.name} --here --yes`);
5634
6262
  }
6263
+ await askFolder();
5635
6264
  if ((await import("./repo-find.js")).holdsRepo(process.cwd())) {
5636
6265
  const n = await bindReposIn(process.cwd(), all, m, argv.includes("--yes"), `pantheon use ${m.name} --here --yes`);
5637
6266
  if (!n)
@@ -5645,6 +6274,7 @@ async function main() {
5645
6274
  console.error(D(` Agents opened here, or in any folder below, now speak as you in "${m.name}". Restart any that are open.`));
5646
6275
  return;
5647
6276
  }
6277
+ await askFolder();
5648
6278
  const { replaced } = bindRepo(r, m.id);
5649
6279
  console.error(`${B("bound")} ${r.origin ?? r.root} → "${m.name}"${replaced ? D(` (was: ${findMembership(all, replaced.space)?.name ?? replaced.space})`) : ""}`);
5650
6280
  if (!r.shared)
@@ -5684,6 +6314,16 @@ async function main() {
5684
6314
  if (sub === "add") {
5685
6315
  const r = repoInfo(flag("path") ?? process.cwd()) ?? die("not inside a git repo");
5686
6316
  const base = flag("base") ?? null;
6317
+ if (base) {
6318
+ const now = client.repos.find((x) => x.fingerprint === r.fingerprint)?.base ?? null;
6319
+ if (now !== base) {
6320
+ const go = await protectSetup([{ setting: "base", about: r.origin ?? r.root, from: now ?? "origin's default branch", to: base }]);
6321
+ if (!go) {
6322
+ client.close();
6323
+ return;
6324
+ }
6325
+ }
6326
+ }
5687
6327
  await client.bindRepo(r.fingerprint, r.origin, base).catch((e) => die(e.message));
5688
6328
  if (cfg.spaceId)
5689
6329
  bindRepo(r, cfg.spaceId);