@join-pantheon/cli 0.37.3 → 0.38.0

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
@@ -21,13 +21,13 @@ import { install, launcher, installForUser, windowsRepoOverrides, agentAsksOnce
21
21
  import { Relay } from "./relay.js";
22
22
  import { runMcp } from "./mcp.js";
23
23
  import { Worker } from "./worker.js";
24
- import { DEFAULT_REMINDER_MS, ensureNativeNotifier, HumanNotifier, hudBinaryPath, openInHere, runNotifiers, sendDesktopNotification } from "./notifier.js";
24
+ import { DEFAULT_REMINDER_MS, ensureNativeNotifier, HumanNotifier, hudBinaryPath, onlyNetworkFailures, openInHere, runNotifiers, sendDesktopNotification } from "./notifier.js";
25
25
  import { linuxDesktopReachable } from "./notice-linux.js";
26
26
  import { desktopUnavailable, hostEnv } from "./host-env.js";
27
27
  import { commandState } from "./command-state.js";
28
- import { AGENT_SURFACES, applyProfileInit, setupChosen, cleanList, dropCatchAllClaims, isAgentSurface, loadProfile, organizationProfile, profileInitialized, profilePath, saveProfile, teamProfile, wakeDefault, wakeMode } from "./profile.js";
28
+ import { AGENT_SURFACES, applyProfileInit, decisionAlertsOn, setupChosen, cleanList, dropCatchAllClaims, isAgentSurface, loadProfile, organizationProfile, profileInitialized, profilePath, saveProfile, teamProfile, wakeDefault, wakeMode } from "./profile.js";
29
29
  import { runGuide, terminalIO, questionOrNull, parseSetupFlags, questionnaire, optOutsFrom, decisionAreasProblem, ALERT_WORDS, AUTOPILOT_WAKE_OFF } from "./setup-guide.js";
30
- import { APPROVED_ENV, unsandboxedRisk, beginApproval, agentLabel, changeLabel, composeSetupAlert, dropPending, findPending, gateChanges, lastChangeLine, loadPending, logChanges, machineSetUp, markFirstSetup, askedByLabel, pendingSaid, whoIsAsking } from "./setup-changes.js";
30
+ import { APPROVED_ENV, unsandboxedRisk, beginApproval, agentLabel, changeLabel, composeSetupAlert, dropPending, findPending, gateChanges, lastChangeLine, loadPending, logChanges, machineSetUp, markFirstSetup, askedByLabel, pendingSaid, turnedOff, whoIsAsking } from "./setup-changes.js";
31
31
  import { selectActs, formatAct, resolveRef } from "./history-view.js";
32
32
  import { doctor, ownProcesses, render, shareBlock } from "./doctor.js";
33
33
  import { FEEDBACK_ADDRESS } from "./feedback.js";
@@ -93,7 +93,7 @@ if (PROMPTLESS) {
93
93
  }
94
94
  catch { }
95
95
  }
96
- const JSON_OUT = argv.includes("--json") && ["join", "start", "doctor", "status", "check"].includes(cmd);
96
+ const JSON_OUT = argv.includes("--json") && ["join", "start", "doctor", "status", "check", "setup"].includes(cmd) && !(cmd === "setup" && argv.includes("--questions"));
97
97
  let jsonSaid = false;
98
98
  function sayJson(o) {
99
99
  if (jsonSaid)
@@ -669,12 +669,17 @@ async function workerAfterBinding(how) {
669
669
  if (how === "off")
670
670
  return;
671
671
  const j = load();
672
- if (!j?.spaceId || wakeMode(loadProfile(j)) === "no")
672
+ const team = j?.spaceId;
673
+ if (!j || !team || wakeMode(loadProfile(j)) === "no")
673
674
  return;
674
675
  const { serviceInstalled, servicesUnavailable } = await import("./service.js");
675
676
  if (servicesUnavailable(process.platform) || serviceInstalled("worker"))
676
677
  return;
677
- const ws = (await import("./worker-fleet.js")).teamWorkspaces(loadAll(), j.spaceId);
678
+ if (workerOffByPerson()) {
679
+ console.error(D(` your worker stays off, as you set it — teammates' requests wait for you. To turn it on: pantheon service install worker`));
680
+ return;
681
+ }
682
+ const ws = (await import("./worker-fleet.js")).teamWorkspaces(loadAll(), team);
678
683
  if (!ws.length)
679
684
  return;
680
685
  try {
@@ -683,49 +688,163 @@ async function workerAfterBinding(how) {
683
688
  const { notLoadedWhy } = await import("./setup-guide.js");
684
689
  const why = notLoadedWhy(installService("worker", ws[0].path, commandsOn ? ["--allow-bash"] : []));
685
690
  if (why) {
686
- console.error(`\x1b[33m ! the worker is installed but not running (${why}) — teammates' requests wait for you until it runs: pantheon service restart worker\x1b[0m`);
691
+ console.error(`\x1b[33m ! the worker is installed but not running (${why}) — teammates' requests wait for you until it runs: pantheon service restart worker${process.stdin.isTTY ? "" : SANDBOX_NOTE}\x1b[0m`);
687
692
  return;
688
693
  }
689
694
  console.error(` ${C("✓")} worker on — serves ${ws.map((w) => w.name).join(", ")} while you are away${wakeMode(loadProfile(j)) === "approved" ? "; you are asked the first time each teammate needs it" : ""}${commandsOn ? "; a run may run tests, commit and push to its own branch (edits only: pantheon setup --commands no)" : ""}`);
695
+ const selfUpgrade = (await import("./worker-policy.js")).grantSelfUpgradeAtSetup();
696
+ if (selfUpgrade)
697
+ console.error(D(` ${selfUpgrade}`));
690
698
  }
691
699
  catch (e) {
692
700
  console.error(D(` the worker did not install: ${e.message} — pantheon service install worker`));
693
701
  }
694
702
  }
695
- async function bindProjectFromScratch() {
703
+ function workerOffByPerson() {
704
+ try {
705
+ return turnedOff("worker") && !(borrowedHome() ? false : serviceState("worker").running);
706
+ }
707
+ catch {
708
+ return false;
709
+ }
710
+ }
711
+ const SANDBOX_NOTE = " (coding agent: ask your person to approve running this outside your sandbox — a sandbox can't start background services)";
712
+ let folderChoicesFound = null;
713
+ async function choicesFor(m, all) {
714
+ if (folderChoicesFound?.team === m.id)
715
+ return folderChoicesFound.choices;
716
+ const { folderChoices } = await import("./folder-ask.js");
717
+ let choices = [];
718
+ try {
719
+ choices = folderChoices({ cwd: process.cwd(), all, spaceId: m.id });
720
+ }
721
+ catch { }
722
+ folderChoicesFound = { team: m.id, choices };
723
+ return choices;
724
+ }
725
+ async function folderAskFor(m, all) {
726
+ const { folderAsk, notLinkedWhy } = await import("./folder-ask.js");
696
727
  const cwd = process.cwd();
697
- if (repoInfo(cwd) || !isTemporaryRefusal(folderRefusalHere(cwd)))
728
+ const refused = folderRefusalHere(cwd);
729
+ const why = notLinkedWhy(refused) ?? (repoInfo(cwd) ? null : (await import("./repo-find.js")).holdsRepo(cwd) ? "This folder holds repos" : null);
730
+ return folderAsk({ team: m.name, choices: await choicesFor(m, all), why, command: (rest) => pantheonCommand(managedLayout()?.launcher, rest) });
731
+ }
732
+ async function askProjectFolder(cfgIn) {
733
+ const cwd = process.cwd();
734
+ if (repoInfo(cwd))
698
735
  return;
699
- const all = loadAll(), j = load();
736
+ const all = loadAll(), j = cfgIn ?? load();
700
737
  const m = all && j ? findMembership(all, j.spaceId ?? j.space) ?? findMembership(all, j.space) : null;
701
738
  if (!all || !m)
702
739
  return;
703
- if (Object.values(all.bindings ?? {}).some((b) => b.space === m.id))
740
+ const { teamLinked } = await import("./folder-ask.js");
741
+ if (teamLinked(all, m.id))
704
742
  return;
743
+ const ask = await folderAskFor(m, all);
744
+ if (!process.stdin.isTTY) {
745
+ console.error(`\n${B("Your project folder.")}`);
746
+ for (const l of ask.lines)
747
+ console.error(` ${l}`);
748
+ return;
749
+ }
750
+ const choices = await choicesFor(m, all);
705
751
  const line = pantheonCommand(managedLayout()?.launcher, `use ${m.name} --here`);
706
752
  const later = () => {
707
- console.error(` From your project folder (the repo or folder you work in), run: ${C(line)}`);
708
- console.error(D(` The worker stays off until then, and agents opened there do not speak for "${m.name}" yet.`));
753
+ console.error(` Later, from the folder you work in (a repo, or a folder of documents), run: ${C(line)}`);
754
+ console.error(D(` Until then teammates' requests can't be taken here while you're away, and agents opened there do not speak for "${m.name}" yet.`));
709
755
  };
710
- console.error(`
711
- ${B("Your project folder.")} ${D(`This is a temporary folder, so nothing in it was bound to "${m.name}".`)}`);
712
- if (!process.stdin.isTTY) {
713
- later();
714
- return;
756
+ const why = ask.lines[0] && !ask.lines[0].startsWith("This computer") ? ask.lines[0] : `Nothing on this computer is linked to "${m.name}" yet.`;
757
+ console.error(`\n${B("Your project folder.")} ${D(why)}`);
758
+ if (choices.length) {
759
+ console.error(D(` Found on this computer:`));
760
+ choices.forEach((c, i) => console.error(` ${String(i + 1).padStart(2)}. ${c.name.padEnd(18)} ${D(c.shown)}`));
715
761
  }
762
+ console.error(D(` A folder of documents works too: your worker answers teammates' questions from a copy of it, and keeps anything it writes as drafts for you.`));
716
763
  for (let tries = 0; tries < 3; tries++) {
717
- const rl = createInterface({ input: process.stdin, output: process.stderr });
718
- const a = ((await questionOrNull(rl, ` The folder you work in for "${m.name}" — a repo or a docs folder (Enter to skip): `)) ?? "").trim();
719
- rl.close();
764
+ const a = ((await askOnce(` The folder you work in for "${m.name}" — ${choices.length ? "a number above, or " : ""}a repo or a folder of documents (Enter to skip): `)) ?? "").trim();
720
765
  if (!a)
721
766
  break;
722
- const why = await bindProjectFolder(projectFolderAnswer(a, homedir(), cwd), m);
723
- if (!why)
767
+ const n = /^\d+$/.test(a) ? Number(a) : NaN;
768
+ if (Number.isInteger(n) && choices.length && (n < 1 || n > choices.length)) {
769
+ console.error(D(` pick 1 to ${choices.length}, or type a folder — or press Enter to skip`));
770
+ continue;
771
+ }
772
+ const dir = Number.isInteger(n) && choices[n - 1] ? choices[n - 1].path : projectFolderAnswer(a, homedir(), cwd);
773
+ const why2 = await bindProjectFolder(dir, m);
774
+ if (!why2)
724
775
  return;
725
- console.error(D(` ${why} — try another, or press Enter to skip`));
776
+ console.error(D(` ${why2} — try another, or press Enter to skip`));
726
777
  }
727
778
  later();
728
779
  }
780
+ async function workerWithFirstLink(all, m) {
781
+ if (argv.includes("--no-worker") || inWokenRun())
782
+ return false;
783
+ try {
784
+ const { teamLinked } = await import("./folder-ask.js");
785
+ if (teamLinked(all, m.id))
786
+ return false;
787
+ const cfg = configFor(all, m, null);
788
+ if (wakeMode(loadProfile(cfg)) === "no")
789
+ return false;
790
+ if (servicesUnavailable(process.platform) || serviceInstalled("worker"))
791
+ return false;
792
+ return !workerOffByPerson();
793
+ }
794
+ catch {
795
+ return false;
796
+ }
797
+ }
798
+ async function afterLinking(m, wantWorker) {
799
+ const all = loadAll();
800
+ if (!all)
801
+ return;
802
+ if (wantWorker) {
803
+ const { teamWorkspaces } = await import("./worker-fleet.js");
804
+ const ws = teamWorkspaces(all, m.id);
805
+ if (ws.length) {
806
+ try {
807
+ const { commandsChosen } = await import("./profile.js");
808
+ const commandsOn = ws.some((w) => w.kind === "repo") && commandsChosen() !== false;
809
+ const { notLoadedWhy } = await import("./setup-guide.js");
810
+ const why = notLoadedWhy(installService("worker", ws[0].path, commandsOn ? ["--allow-bash"] : []));
811
+ if (why)
812
+ console.error(`\x1b[33m ! Your worker is installed but not running (${why}), so this computer can't take teammates' requests yet.\n → pantheon service restart worker${process.stdin.isTTY ? "" : SANDBOX_NOTE}\x1b[0m`);
813
+ else {
814
+ console.error(` ${C("✓")} worker on — this computer takes teammates' requests for "${m.name}" while you're away${commandsOn ? "; a run may run tests, commit and push to its own branch (edits only: pantheon setup --commands no)" : ""}`);
815
+ const selfUpgrade = (await import("./worker-policy.js")).grantSelfUpgradeAtSetup();
816
+ if (selfUpgrade)
817
+ console.error(D(` ${selfUpgrade}`));
818
+ }
819
+ }
820
+ catch (e) {
821
+ console.error(`\x1b[33m ! The worker did not install (${e.message.split("\n")[0]}), so this computer can't take teammates' requests yet.\n → pantheon service install worker${process.stdin.isTTY ? "" : SANDBOX_NOTE}\x1b[0m`);
822
+ }
823
+ }
824
+ }
825
+ else if (!argv.includes("--no-worker") && !serviceInstalled("worker") && workerOffByPerson()) {
826
+ console.error(D(` your worker stays off, as you set it — teammates' requests wait for you. To turn it on: pantheon service install worker`));
827
+ }
828
+ else if (serviceInstalled("worker") && !borrowedHome()) {
829
+ try {
830
+ if (!serviceState("worker").running)
831
+ console.error(`\x1b[33m ! Your worker is installed but not running, so this computer can't take teammates' requests yet.\n → pantheon service restart worker${process.stdin.isTTY ? "" : SANDBOX_NOTE}\x1b[0m`);
832
+ }
833
+ catch { }
834
+ }
835
+ try {
836
+ if (servicesUnavailable(process.platform) || borrowedHome() || turnedOff("alerts"))
837
+ return;
838
+ const { decisionAlertsOn } = await import("./profile.js");
839
+ if (!decisionAlertsOn())
840
+ return;
841
+ if (!serviceInstalled("notifier"))
842
+ console.error(D(` Desktop alerts are off on this computer, so you won't hear when a teammate needs you. To turn them on: pantheon service install notifier`));
843
+ else if (!serviceState("notifier").running)
844
+ console.error(`\x1b[33m ! Desktop alerts are installed but not running, so you won't hear when a teammate needs you.\n → pantheon service restart notifier${process.stdin.isTTY ? "" : SANDBOX_NOTE}\x1b[0m`);
845
+ }
846
+ catch { }
847
+ }
729
848
  async function bindProjectFolder(dir, m) {
730
849
  try {
731
850
  if (!statSync(dir).isDirectory())
@@ -2140,6 +2259,7 @@ async function finishLine(tools, o) {
2140
2259
  catch {
2141
2260
  return null;
2142
2261
  } })();
2262
+ let takesWork = false;
2143
2263
  const gather = async () => {
2144
2264
  let wakeOn = false, ready = null, served = null, pending = 0;
2145
2265
  try {
@@ -2165,13 +2285,24 @@ async function finishLine(tools, o) {
2165
2285
  catch {
2166
2286
  pending = 0;
2167
2287
  }
2168
- const workerWanted = wakeOn && !argv.includes("--no-worker");
2288
+ const workerWanted = wakeOn && !argv.includes("--no-worker") && !workerOffByPerson();
2289
+ takesWork = workerWanted && (served ?? 0) > 0;
2290
+ let linkLine = null;
2291
+ if (workerWanted && served === 0 && cfg) {
2292
+ try {
2293
+ const { NAMED_FOLDER } = await import("./folder-ask.js");
2294
+ linkLine = pantheonCommand(managedLayout()?.launcher, `use ${cfg.space} --here --folder '${NAMED_FOLDER}'`);
2295
+ }
2296
+ catch {
2297
+ linkLine = null;
2298
+ }
2299
+ }
2169
2300
  const workerRowFailed = tools.some((t) => t.tool === "worker" && /^(failed|could not)/i.test(t.status));
2170
2301
  const alertsOn = tools.some((t) => t.tool === "notifications" && /^on\b/i.test(t.status));
2171
2302
  return [...(o.extra ?? []), ...finishItems({ tools, readiness: ready, team: cfg?.space ?? "<team>", workerWanted, served, windows, pending,
2172
2303
  worker: workerWanted && (served ?? 0) > 0 && !workerRowFailed ? await workerHeld() : null,
2173
2304
  alerts: alertsOn ? await alertsHeld() : null,
2174
- agentShell: !process.stdin.isTTY })];
2305
+ agentShell: !process.stdin.isTTY, linkLine })];
2175
2306
  };
2176
2307
  let items = await gather();
2177
2308
  if (guideAsks(o.preset)) {
@@ -2249,8 +2380,22 @@ async function finishLine(tools, o) {
2249
2380
  }
2250
2381
  if (JSON_OUT) {
2251
2382
  const plain = (t) => t.replace(/\x1b\[[0-9;]*m/g, "").trim();
2383
+ let ask = {};
2384
+ if (items.some((it) => it.needsFolder) && cfg) {
2385
+ try {
2386
+ const all = loadAll();
2387
+ const m = all ? findMembership(all, cfg.spaceId ?? cfg.space) ?? findMembership(all, cfg.space) : null;
2388
+ if (all && m) {
2389
+ const a = (await folderAskFor(m, all)).json;
2390
+ ask = { reason: a.reason, needs: a.needs, message: a.message, folders: a.folders, other_folder: a.other_folder, skip: a.skip };
2391
+ }
2392
+ }
2393
+ catch { }
2394
+ }
2252
2395
  sayJson({
2253
- status: items.length ? "left" : "ready",
2396
+ status: ask.needs ? "needs_person" : items.length ? "left" : "ready",
2397
+ ...ask,
2398
+ can_take_requests: takesWork && !items.some((it) => it.blocks),
2254
2399
  code: typeof process.exitCode === "number" ? process.exitCode : 0,
2255
2400
  team: cfg?.space ?? null,
2256
2401
  member: cfg?.member ?? null,
@@ -2404,6 +2549,32 @@ ${B("less common")}
2404
2549
  `;
2405
2550
  let workerAlerts = null;
2406
2551
  let workerAlertsSaid = false;
2552
+ async function trackServiceStart(kind, noNotify) {
2553
+ try {
2554
+ const { trackService, composeCrashLoop, loopLine } = await import("./crash-loop.js");
2555
+ trackService(kind, {
2556
+ onLoop: (loop) => {
2557
+ console.error(`! ${loopLine(kind, loop)}`);
2558
+ if (kind === "worker") {
2559
+ try {
2560
+ writeFileSync(join(CONFIG_DIR, "worker-state.json"), JSON.stringify({ at: Date.now(), state: "restarting", detail: `keeps stopping — restarted ${loop.starts} times in a few minutes; pantheon doctor shows why` }) + "\n");
2561
+ }
2562
+ catch { }
2563
+ }
2564
+ if (noNotify || !decisionAlertsOn())
2565
+ return;
2566
+ const n = composeCrashLoop(kind, loop);
2567
+ if (kind === "worker") {
2568
+ if (workerCanAlert())
2569
+ notifyFromWorker(n);
2570
+ }
2571
+ else
2572
+ void Promise.resolve(sendDesktopNotification(n)).catch(() => false);
2573
+ },
2574
+ });
2575
+ }
2576
+ catch { }
2577
+ }
2407
2578
  function notifyFromWorker(n) {
2408
2579
  if (process.platform === "linux") {
2409
2580
  if (!workerAlerts || Date.now() - workerAlerts.at > 60_000)
@@ -2478,13 +2649,13 @@ const COMMAND_FLAGS = {
2478
2649
  check: "--json (runs your agent once, as it runs for teammates while you're away — up to a minute)",
2479
2650
  status: "--clear-safety (once the safety warnings it shows are handled) --json",
2480
2651
  relay: "--port <n> --host <address> --data <dir> (relay leftovers --data <dir> [--json]: read-only report)",
2481
- use: "<team> --here --yes · pantheon use --unbind (this folder or repo bound to no team again)",
2652
+ use: "<team> --here [--folder <path> (that folder, not this one)] --yes --no-worker · pantheon use --unbind (this folder or repo bound to no team again)",
2482
2653
  repo: "add [--base <branch>] | list [--all] | find [<folder>] [--recents] [--yes]",
2483
2654
  login: "--email <address> --relay <url> --label <device name>",
2484
2655
  signin: "--relay <url>",
2485
2656
  signup: "--email <address> --username <name> --relay <url> --label <device name>",
2486
2657
  audit: "--space <team> --since <hours> --json",
2487
- setup: "--questions --mode <autopilot|here> --agent <claude-code|codex|cursor|copilot|kiro> (which agent answers teammates' requests here) (and every answer as a flag, with --yes)",
2658
+ setup: "--questions --mode <autopilot|here> --agent <claude-code|codex|cursor|copilot|kiro> (which agent answers teammates' requests here) --json (and every answer as a flag, with --yes)",
2488
2659
  mode: "[autopilot | here]",
2489
2660
  changes: "[list | review | approve <id> | keep <id>] --history",
2490
2661
  board: "--open --url --watch --keep --stop --focus <id> [--space <team>]",
@@ -2573,7 +2744,7 @@ const EXTRA_FLAGS = "--action-id --agent-cmd --approve-all --ask-before-sending
2573
2744
  " --keep-tray-quit --direct" +
2574
2745
  " --headless";
2575
2746
  const FLAG_COMMANDS = {
2576
- json: ["join", "start", "doctor", "status", "history", "usage", "audit", "pending", "rewire", "relay"],
2747
+ json: ["join", "start", "doctor", "status", "history", "usage", "audit", "pending", "rewire", "relay", "setup"],
2577
2748
  agent: ["join", "start", "setup", "worker", "service", "init"],
2578
2749
  };
2579
2750
  const KNOWN_FLAGS = new Set([...`${Object.values(COMMAND_FLAGS).join(" ")} ${EXTRA_FLAGS}`.matchAll(/--([a-z][a-z0-9-]*)/g)].map((m) => m[1]));
@@ -2798,8 +2969,8 @@ async function main() {
2798
2969
  console.error(D(` ${r.reach.hint}`));
2799
2970
  }
2800
2971
  if (r.claimed) {
2801
- await bindProjectFromScratch();
2802
2972
  await bindReposHere(argv.includes("--yes"));
2973
+ await askProjectFolder();
2803
2974
  await workerAfterBinding(wp.how);
2804
2975
  windowsOverridesForBoundRepos();
2805
2976
  await applyAgentChoice(load() ?? r.cfg, agentWant);
@@ -3123,7 +3294,7 @@ async function main() {
3123
3294
  await findAndBindRepos(all, m, teamRepos, { auto: !process.stdin.isTTY, recents: false, ...(inRepo ? { askFolder: false, quiet: true } : {}) }).catch(() => { });
3124
3295
  }
3125
3296
  }
3126
- await bindProjectFromScratch();
3297
+ await askProjectFolder();
3127
3298
  await workerAfterBinding(wp.how);
3128
3299
  windowsOverridesForBoundRepos();
3129
3300
  const joined = load();
@@ -3335,8 +3506,34 @@ async function main() {
3335
3506
  sayAgentReadiness(load() ?? cfg);
3336
3507
  return;
3337
3508
  }
3509
+ const wakeNow = () => { try {
3510
+ return wakeMode(loadProfile(load() ?? cfg));
3511
+ }
3512
+ catch {
3513
+ return "anyone";
3514
+ } };
3515
+ if (guideAsks(preset) && !inWokenRun() && wakeNow() !== "no")
3516
+ await askProjectFolder(cfg);
3338
3517
  await guidedSetup(cfg, repoInfo(process.cwd())?.root ?? null, { force: true, preset, command: "setup" });
3339
3518
  sayAgentReadiness(load() ?? cfg);
3519
+ if (!guideAsks(preset) && !inWokenRun() && wakeNow() !== "no" && !argv.includes("--no-worker")) {
3520
+ const all = loadAll();
3521
+ const m = all ? findMembership(all, cfg.spaceId ?? cfg.space) ?? findMembership(all, cfg.space) : null;
3522
+ const { teamLinked } = await import("./folder-ask.js");
3523
+ if (all && m && !teamLinked(all, m.id)) {
3524
+ const ask = await folderAskFor(m, all);
3525
+ console.error("");
3526
+ if (process.stdin.isTTY) {
3527
+ console.error(`\x1b[33m ${ask.lines.find((l) => l.startsWith("This computer"))}\x1b[0m`);
3528
+ console.error(` → from the folder you work in (a repo, or a folder of documents): ${C(pantheonCommand(managedLayout()?.launcher, `use ${m.name} --here`))}`);
3529
+ }
3530
+ else
3531
+ for (const l of ask.lines)
3532
+ console.error(` ${l}`);
3533
+ if (JSON_OUT)
3534
+ sayJson({ status: "needs_person", code: 0, ...ask.json });
3535
+ }
3536
+ }
3340
3537
  return;
3341
3538
  }
3342
3539
  case "version": {
@@ -3392,7 +3589,7 @@ async function main() {
3392
3589
  console.log(` ${p.online ? C("●") : D("○")} ${p.id.padEnd(14)} ${D(p.agent.padEnd(12))} ${reach}`);
3393
3590
  {
3394
3591
  const est = pickupEstimate(p, { now: client.relayNow() });
3395
- if (est.kind === "unavailable")
3592
+ if (est.kind === "unavailable" || est.kind === "not-set-up")
3396
3593
  console.log(` ${" ".repeat(16)}\x1b[33m${termSafe(est.says)}\x1b[0m`);
3397
3594
  }
3398
3595
  }
@@ -7359,6 +7556,7 @@ async function main() {
7359
7556
  }
7360
7557
  const runMinutesFlag = flag("run-minutes") === undefined ? undefined : (await import("./worker-policy.js")).parseRunMinutes(flag("run-minutes")) ?? die((await import("./worker-policy.js")).runMinutesProblem(flag("run-minutes")).replace("pantheon policy set run-minutes default", "leave --run-minutes off"));
7361
7558
  (await import("./machine.js")).recordWorkerPid();
7559
+ await trackServiceStart("worker", argv.includes("--no-notify"));
7362
7560
  const allCfg = loadAll();
7363
7561
  const bindings = Object.values(allCfg?.bindings ?? {});
7364
7562
  if (!flag("project")) {
@@ -7653,6 +7851,17 @@ async function main() {
7653
7851
  const m = await import("./machine.js");
7654
7852
  m.recordWorkerPid(m.notifierPidFile());
7655
7853
  }
7854
+ await trackServiceStart("notifier", false);
7855
+ const { VersionWatch } = await import("./version-health.js");
7856
+ const versionWatch = new VersionWatch({
7857
+ relays: () => cfgs.map((c) => c.relay),
7858
+ send: (n) => sendDesktopNotification(n),
7859
+ log: (line) => console.error(line),
7860
+ policy: () => loadPolicy(),
7861
+ workerRunning: () => serviceInstalled("worker") && workerProc().running,
7862
+ alertsOn: () => decisionAlertsOn(),
7863
+ });
7864
+ versionWatch.start();
7656
7865
  if (process.platform === "win32") {
7657
7866
  try {
7658
7867
  const { ensureUriHandler } = await import("./notice-windows.js");
@@ -7666,9 +7875,14 @@ async function main() {
7666
7875
  n.stop(); process.exit(0); };
7667
7876
  process.on("SIGINT", stopAll);
7668
7877
  process.on("SIGTERM", stopAll);
7669
- const ok = await runNotifiers(notifiers.map((n, i) => ({ label: cfgs[i].space, run: () => n.run(), stopped: () => n.isStopped })), { log: (line) => console.error(line) });
7670
- if (!ok)
7878
+ let networkOnly = false;
7879
+ const ok = await runNotifiers(notifiers.map((n, i) => ({ label: cfgs[i].space, run: () => n.run(), stopped: () => n.isStopped })), { log: (line) => console.error(line), onGiveUp: (errors) => { networkOnly = onlyNetworkFailures(errors); } });
7880
+ versionWatch.stop();
7881
+ if (!ok) {
7882
+ if (networkOnly)
7883
+ (await import("./crash-loop.js")).expectServiceExit();
7671
7884
  process.exit(1);
7885
+ }
7672
7886
  return;
7673
7887
  }
7674
7888
  case "doctor": {
@@ -7811,12 +8025,19 @@ async function main() {
7811
8025
  const next = argv.includes("--fresh") ? extra : keepServiceFlags(now, extra);
7812
8026
  extra.splice(0, extra.length, ...next);
7813
8027
  const { describeWorkerFlags } = await import("./setup-changes.js");
7814
- await protectOrStop([now === null ? { setting: "worker", from: "off", to: "on" } : { setting: "worker", from: describeWorkerFlags(now), to: describeWorkerFlags(next) }]);
8028
+ const { selfUpgradeSetupDue } = await import("./worker-policy.js");
8029
+ await protectOrStop([now === null ? { setting: "worker", from: "off", to: "on" } : { setting: "worker", from: describeWorkerFlags(now), to: describeWorkerFlags(next) },
8030
+ ...(selfUpgradeSetupDue() ? [{ setting: "self-upgrade", from: "off", to: "on" }] : [])]);
7815
8031
  }
7816
8032
  console.error(`${B("installing the pantheon worker as a background service")}`);
7817
8033
  console.error(D(flag("project") ? ` project ${project} (this checkout only)` : ` serves every repo and folder bound to a team on this machine`));
7818
8034
  for (const l of installService(kind, project, extra))
7819
8035
  console.error(l);
8036
+ {
8037
+ const selfUpgrade = (await import("./worker-policy.js")).grantSelfUpgradeAtSetup();
8038
+ if (selfUpgrade)
8039
+ console.error(`\n${D(selfUpgrade)}`);
8040
+ }
7820
8041
  {
7821
8042
  const { wakeChosen } = await import("./profile.js");
7822
8043
  const w = wakeChosen();
@@ -7854,6 +8075,22 @@ async function main() {
7854
8075
  }
7855
8076
  case "use": {
7856
8077
  await membershipGate();
8078
+ if (argv.includes("--folder")) {
8079
+ const given = flag("folder");
8080
+ if (!given || given.startsWith("--"))
8081
+ die("usage: pantheon use <team> --here --folder <the folder you work in>");
8082
+ if (!argv.includes("--here"))
8083
+ die("usage: --folder goes with --here: pantheon use <team> --here --folder <the folder you work in>");
8084
+ const dir = projectFolderAnswer(given, homedir(), process.cwd());
8085
+ try {
8086
+ if (!statSync(dir).isDirectory())
8087
+ die(`${dir} is not a folder — nothing was linked`);
8088
+ }
8089
+ catch {
8090
+ die(`there is no folder at ${dir} — nothing was linked`);
8091
+ }
8092
+ process.chdir(dir);
8093
+ }
7857
8094
  const all = loadAll() ?? die("not configured. Run `pantheon signup` first.");
7858
8095
  if (argv.includes("--unbind")) {
7859
8096
  const { folderBinding } = await import("./config.js");
@@ -7875,6 +8112,7 @@ async function main() {
7875
8112
  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"}`);
7876
8113
  if (argv.includes("--here")) {
7877
8114
  const r = repoInfo(process.cwd());
8115
+ const wantWorker = await workerWithFirstLink(all, m);
7878
8116
  const askFolder = async () => {
7879
8117
  const { folderBinding } = await import("./config.js");
7880
8118
  const cur = r ? all.bindings?.[r.fingerprint] : folderBinding(all, process.cwd());
@@ -7884,9 +8122,14 @@ async function main() {
7884
8122
  catch {
7885
8123
  return process.cwd();
7886
8124
  } })();
7887
- if (cur && here && cur.space === m.id)
8125
+ const { selfUpgradeSetupDue } = await import("./worker-policy.js");
8126
+ const worker = wantWorker ? [{ setting: "worker", from: "off", to: "on" }, ...(selfUpgradeSetupDue() ? [{ setting: "self-upgrade", from: "off", to: "on" }] : [])] : [];
8127
+ if (cur && here && cur.space === m.id) {
8128
+ if (worker.length)
8129
+ await protectOrStop(worker);
7888
8130
  return;
7889
- 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}` }]);
8131
+ }
8132
+ 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}` }, ...worker]);
7890
8133
  };
7891
8134
  if (!r) {
7892
8135
  for (let d = resolve(process.cwd());; d = dirname(d)) {
@@ -7909,11 +8152,14 @@ async function main() {
7909
8152
  console.error(D(` nothing bound — the folder itself is not bound, since it holds repos`));
7910
8153
  else
7911
8154
  console.error(D(` Agents opened in those repos now speak as you in "${m.name}". Restart any that are open.`));
8155
+ if (n)
8156
+ await afterLinking(m, wantWorker);
7912
8157
  return;
7913
8158
  }
7914
8159
  const { replaced } = bindFolder(process.cwd(), m.id);
7915
8160
  console.error(`${B("bound")} this folder → "${m.name}"${replaced ? D(` (was: ${findMembership(all, replaced.space)?.name ?? replaced.space})`) : ""}`);
7916
8161
  console.error(D(` Agents opened here, or in any folder below, now speak as you in "${m.name}". Restart any that are open.`));
8162
+ await afterLinking(m, wantWorker);
7917
8163
  return;
7918
8164
  }
7919
8165
  await askFolder();
@@ -7930,6 +8176,7 @@ async function main() {
7930
8176
  }
7931
8177
  windowsOverridesForBoundRepos();
7932
8178
  console.error(D(` Agents opened in this repo now speak as you in "${m.name}". Restart any that are open.`));
8179
+ await afterLinking(m, wantWorker);
7933
8180
  }
7934
8181
  else {
7935
8182
  setDefaultSpace(m.id);