@join-pantheon/cli 0.36.0-rc.1 → 0.37.0-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
@@ -6,6 +6,7 @@ process.emitWarning = ((warning, ...rest) => {
6
6
  return;
7
7
  return _emitWarning(warning, ...rest);
8
8
  });
9
+ import { recordInviteSent } from "./invites-sent.js";
9
10
  import { randomBytes } from "node:crypto";
10
11
  import { emailSuggestion, gitConfigValue, isGithubNoreply, pantheonCommand, signinCommand, usernameSuggestion } from "./onboard-defaults.js";
11
12
  import { closeSync, existsSync, mkdirSync, openSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
@@ -54,16 +55,18 @@ import { borrowedHome, installService, serviceInstalled, serviceLogFile, service
54
55
  import { LEGACY_TASK_NAME, hostAlive, hostFiles, readHostState, recordedTaskName } from "./win-host.js";
55
56
  import { ACTS, LIMITS } from "./protocol.js";
56
57
  import { loadPersonas, personaByName, describePersona, initPersona, personaDir, olderTeammatesNote } from "./persona.js";
57
- import { fingerprint, newKeypair, signAccount } from "./identity.js";
58
+ import { fingerprint, newKeypair, signAccount, signBytes, signStatus, teamSetupPayload } from "./identity.js";
58
59
  import { VERSION } from "./version.js";
59
60
  import { connectFailure, refusalOf, signInHint } from "./refusal.js";
60
61
  import * as mcpWindows from "./mcp-windows.js";
61
62
  import { updateBanner } from "./update-check.js";
62
63
  import { inWokenRun } from "./worker-policy.js";
63
- import { childNodeFlags, joinInstructions, managedLayout, relayServesInstaller } from "./managed.js";
64
+ import { childNodeFlags, managedLayout, relayInstallerVersion } from "./managed.js";
65
+ import { inviteBlock } from "./onboard-copy.js";
64
66
  import { spawn } from "node:child_process";
65
67
  import { EXIT, exitCodeFor, exitReason, inviteRefusalCode } from "./exit-codes.js";
66
68
  import { QUEUED_SEND_DEADLINE_MS } from "./hud-queue.js";
69
+ import { awaitLink, enterCode, inviteIndexes, requestCode, resumeArgs, resumedArgv } from "./flag-signin.js";
67
70
  const argv = process.argv.slice(2);
68
71
  for (let i = argv.length - 1; i >= 1; i--) {
69
72
  const m = /^(--[a-z][a-z0-9-]*)=(.*)$/i.exec(argv[i]);
@@ -71,7 +74,26 @@ for (let i = argv.length - 1; i >= 1; i--) {
71
74
  argv.splice(i, 1, m[1], m[2]);
72
75
  }
73
76
  const cmd = argv[0] ?? "help";
74
- const JSON_OUT = argv.includes("--json") && ["join", "start", "doctor", "status"].includes(cmd);
77
+ {
78
+ let pend;
79
+ try {
80
+ pend = identity()?.pendingAuth;
81
+ }
82
+ catch {
83
+ pend = undefined;
84
+ }
85
+ const r = resumedArgv(argv, pend, Date.now());
86
+ if (r)
87
+ argv.splice(0, argv.length, ...r);
88
+ }
89
+ const PROMPTLESS = (cmd === "join" || cmd === "start") && ["--email", "--code", "--continue"].some((f) => argv.includes(f));
90
+ if (PROMPTLESS) {
91
+ try {
92
+ Object.defineProperty(process.stdin, "isTTY", { value: false, configurable: true });
93
+ }
94
+ catch { }
95
+ }
96
+ const JSON_OUT = argv.includes("--json") && ["join", "start", "doctor", "status", "check"].includes(cmd);
75
97
  let jsonSaid = false;
76
98
  function sayJson(o) {
77
99
  if (jsonSaid)
@@ -110,6 +132,59 @@ async function signedFetch(cfg, method, path, params = {}) {
110
132
  }
111
133
  return res;
112
134
  }
135
+ function wantsFlagSignIn() {
136
+ return flag("email") !== undefined || flag("code") !== undefined || argv.includes("--continue");
137
+ }
138
+ async function flagSignIn(which, relay, joining) {
139
+ const base = relay.replace(/^ws/, "http").replace(/\/+$/, "");
140
+ let why = "";
141
+ const deps = {
142
+ post: (path, body) => fetch(`${base}${path}`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) })
143
+ .then(async (x) => ({ status: x.status, j: await relayJson(x, `${base}${path}`) }))
144
+ .catch(async (e) => { why = await describeRelayFailure(e, relay); return null; }),
145
+ unreachable: () => why,
146
+ identity: () => identity(),
147
+ saveLocked: (fn) => withConfigLock(() => { const next = fn(identity()); save({ ...next, relay: next.relay || relay }); return next; }),
148
+ newKeypair,
149
+ status: async () => {
150
+ const me = identity();
151
+ if (!me?.publicKey || !me.privateKey)
152
+ return null;
153
+ const ts = Date.now(), nonce = randomBytes(18).toString("base64url");
154
+ return fetch(`${base}/auth/status`, { headers: { "x-pantheon-key": me.publicKey, "x-pantheon-ts": String(ts), "x-pantheon-nonce": nonce, "x-pantheon-sig": signStatus(me.privateKey, me.publicKey, ts, nonce, me.pendingAuth?.aud ?? new URL(base).host) } })
155
+ .then(async (x) => ({ status: x.status, j: await relayJson(x, `${base}/auth/status`) }))
156
+ .catch(async (e) => { why = await describeRelayFailure(e, relay); return null; });
157
+ },
158
+ label: flag("label") ?? deviceLabel(),
159
+ gitEmail: gitConfigValue("user.email"),
160
+ now: () => Date.now(),
161
+ command: (rest) => pantheonCommand(managedLayout()?.launcher, JSON_OUT && / --(code|email|username|continue)\b/.test(` ${rest}`) ? `${rest} --json` : rest),
162
+ };
163
+ const code = flag("code");
164
+ const cont = argv.includes("--continue") && code === undefined && flag("email") === undefined;
165
+ if (flag("email") === undefined && code === undefined && !cont)
166
+ return;
167
+ if (code === undefined && !cont && !flag("email"))
168
+ die("usage: --email needs your address: --email you@work.com", EXIT.usage);
169
+ if (cont)
170
+ console.error(D(` Waiting for the link in the email to be confirmed (up to 90 seconds)…`));
171
+ const out = cont ? await awaitLink({ cmd: which, deps })
172
+ : code !== undefined
173
+ ? await enterCode({ cmd: which, code, deps })
174
+ : await requestCode({ cmd: which, ...(joining ? { joining } : {}), email: flag("email"), ...(flag("username") !== undefined ? { username: flag("username") } : {}), resend: argv.includes("--resend"), resume: { cmd: which, args: resumeArgs(argv), at: Date.now() }, deps });
175
+ if (out.kind === "signed_in") {
176
+ console.error(` ${C("You're in")} — ${out.already ? "already " : ""}signed in as ${B(out.account.username)} <${out.account.email}> on this machine.\n`);
177
+ return;
178
+ }
179
+ if (out.kind === "error")
180
+ die(out.message, out.exit === "usage" ? EXIT.usage : out.exit === "network" ? EXIT.network : EXIT.failed);
181
+ for (const l of out.lines)
182
+ console.error(` ${l}`);
183
+ const one = (t) => typeof t === "string" ? t.replace(/\s+\(Command Prompt: .*\)$/, "") : t;
184
+ if (JSON_OUT)
185
+ sayJson({ status: "needs_person", code: EXIT.needsPerson, reason: exitReason(EXIT.needsPerson), message: out.lines.join(" "), ...out.json, ...(out.json.next !== undefined ? { next: one(out.json.next) } : {}) });
186
+ process.exit(EXIT.needsPerson);
187
+ }
113
188
  async function requireSignInOnHostedRelay(relayFlag) {
114
189
  const cfg = identity();
115
190
  if (cfg?.account)
@@ -118,14 +193,19 @@ async function requireSignInOnHostedRelay(relayFlag) {
118
193
  const hosted = relay === DEFAULT_RELAY && !relayFlag && !process.env.PANTHEON_RELAY;
119
194
  if (!hosted)
120
195
  return;
196
+ if (wantsFlagSignIn()) {
197
+ await flagSignIn("start", relay);
198
+ if (identity()?.account)
199
+ return;
200
+ }
121
201
  if (process.stdin.isTTY) {
122
202
  if (await interactiveOnboard(relay, { starting: true }) && identity()?.account) {
123
203
  console.error("");
124
204
  return;
125
205
  }
126
- die("not signed in yet.\n When the code arrives: pantheon verify <code> (check spam if it is not in your inbox)\n Then run pantheon start again.");
206
+ die(`not signed in yet.\n When the code arrives: ${pantheonCommand(managedLayout()?.launcher, "verify <code>")} (check spam if it is not in your inbox)\n Then run pantheon start again.`);
127
207
  }
128
- die(`sign in first — this relay verifies email.\n${signInSteps().join("\n")}\n Then run pantheon start again.\n ${SIGNIN_FOR_AGENTS}`);
208
+ die(`sign in first — this relay verifies email.\n${signInSteps("start").join("\n")}\n Or sign in first, then run pantheon start again.\n ${SIGNIN_FOR_AGENTS}`);
129
209
  }
130
210
  async function requireSignInOnAccountsRelay(relayFlag) {
131
211
  if (!relayFlag || identity()?.account)
@@ -139,12 +219,17 @@ async function requireSignInOnAccountsRelay(relayFlag) {
139
219
  catch {
140
220
  return;
141
221
  }
222
+ if (hasAccounts && wantsFlagSignIn()) {
223
+ await flagSignIn("start", relayFlag);
224
+ if (identity()?.account)
225
+ return;
226
+ }
142
227
  if (hasAccounts && process.stdin.isTTY) {
143
228
  if (await interactiveOnboard(relayFlag, { starting: true }) && identity()?.account) {
144
229
  console.error("");
145
230
  return;
146
231
  }
147
- die("not signed in yet.\n When the code arrives: pantheon verify <code> (check spam if it is not in your inbox)\n Then run this same pantheon start again.");
232
+ die(`not signed in yet.\n When the code arrives: ${pantheonCommand(managedLayout()?.launcher, "verify <code>")} (check spam if it is not in your inbox)\n Then run this same pantheon start again.`);
148
233
  }
149
234
  if (hasAccounts)
150
235
  die(`sign in first — ${relayFlag} verifies email.${signInHint("NOT_SIGNED_IN", relayFlag)}\n Then run this same pantheon start again.`);
@@ -162,6 +247,8 @@ async function accountSeats(relay) {
162
247
  ]);
163
248
  }
164
249
  async function askOnce(q) {
250
+ if (PROMPTLESS)
251
+ return null;
165
252
  const rl = createInterface({ input: process.stdin, output: process.stderr });
166
253
  try {
167
254
  return await questionOrNull(rl, q);
@@ -228,7 +315,7 @@ async function interactiveOnboard(relayArg, opts = {}) {
228
315
  }
229
316
  email = e;
230
317
  }
231
- const send = (m, username) => postJson(`/auth/${m}`, m === "signup" ? { email, username, pubkey: kp.publicKey, label } : { email, pubkey: kp.publicKey, label })
318
+ const send = (m, username) => postJson(`/auth/${m}`, m === "signup" ? { email, username, pubkey: kp.publicKey, label, ...(opts.joining ? { joining: opts.joining } : {}) } : { email, pubkey: kp.publicKey, label })
232
319
  .catch(unreachable);
233
320
  const justSent = (r) => r.j.reason === "too_soon";
234
321
  let mode = "login";
@@ -350,11 +437,21 @@ async function interactiveOnboard(relayArg, opts = {}) {
350
437
  }
351
438
  const SIGNIN_FOR_AGENTS = "A coding agent that cannot sign you in hands you the signin line to run yourself, and runs this again once you say you're signed in.";
352
439
  const SPAM_HINT = "Not there in a minute? Check your spam folder.";
353
- function signInSteps() {
440
+ function signInSteps(which) {
441
+ const L = managedLayout()?.launcher;
442
+ if (which) {
443
+ const first = which === "join" ? "join '<your invite link>'" : "start";
444
+ return [
445
+ ` ${C(signinCommand(L))} ${D("in a terminal of your own: your email, then the emailed code, in one go")}`,
446
+ ` ${D("or, from any shell (a coding agent's too), two steps:")}`,
447
+ ` ${C(pantheonCommand(L, `${first} --email you@work.com --username <name teammates see, new accounts only>`))}`,
448
+ ` ${C(pantheonCommand(L, `${which} --code <the 6-digit code>`))} ${D("(the code is emailed — check spam)")}`,
449
+ ];
450
+ }
354
451
  return [
355
- ` ${C(signinCommand(managedLayout()?.launcher))} ${D("in a terminal of your own: your email, then the emailed code, in one go")}`,
356
- ` ${D("or two commands:")} ${C("pantheon signup --email you@work.com --username you")} ${D("(an account already: pantheon login --email you@work.com)")}`,
357
- ` ${C("pantheon verify <code>")} ${D("(the code is emailed — check spam)")}`,
452
+ ` ${C(signinCommand(L))} ${D("in a terminal of your own: your email, then the emailed code, in one go")}`,
453
+ ` ${D("or two commands:")} ${C(pantheonCommand(L, "signup --email you@work.com --username you"))} ${D(`(an account already: ${pantheonCommand(L, "login --email you@work.com")})`)}`,
454
+ ` ${C(pantheonCommand(L, "verify <code>"))} ${D("(the code is emailed — check spam)")}`,
358
455
  ];
359
456
  }
360
457
  function ago(t) {
@@ -400,6 +497,8 @@ function keywordFlag(raw) {
400
497
  return out;
401
498
  }
402
499
  function die(msg, code = exitCodeFor(cmd, msg)) {
500
+ if (cmd === "join" && code === EXIT.inviteUnusable)
501
+ dropCarriedOn(argv[1]);
403
502
  const said = plainError(msg);
404
503
  console.error(`pantheon: ${said}`);
405
504
  if (JSON_OUT)
@@ -925,8 +1024,7 @@ function printRelayNote(relay) {
925
1024
  host = new URL(relay.replace(/^ws/, "http")).host;
926
1025
  }
927
1026
  catch { }
928
- console.error(D(`\n Your team's messages go through ${host}. Whoever runs it can read them (they are not end-to-end encrypted), so treat the team like a shared channel;`));
929
- console.error(D(` on a relay from 0.31 on, it cannot write or change one in a teammate's name without your machine noticing: every message is signed by its sender. Your own relay: pantheon relay`));
1027
+ console.error(D(`\n Your team's messages go through ${host}: whoever runs it can read them (not end-to-end encrypted), but cannot change one in a teammate's name — every message is signed. Your own: pantheon relay`));
930
1028
  }
931
1029
  function windowsOverridesForBoundRepos() {
932
1030
  const dirs = Object.values(loadAll()?.bindings ?? {}).map((b) => b.path).filter((p) => !!p && existsSync(p));
@@ -934,19 +1032,11 @@ function windowsOverridesForBoundRepos() {
934
1032
  console.error(` ${D("claude code in")} ${r.dir} ${D(r.status)}`);
935
1033
  }
936
1034
  async function printJoinSteps(invite, relay) {
937
- const j = joinInstructions(invite, relay, await relayServesInstaller(relay));
938
- console.error(`\n${B("For a teammate who'd rather not type commands, forward this whole block:")}\n`);
939
- console.error(D(` ${j.intro}`));
940
- for (const s of j.steps) {
941
- console.error(D(` ${s.label}`));
942
- for (const l of s.lines)
943
- console.error(` ${C(l)}`);
944
- }
945
- console.error(D(` ${j.outro}`));
946
- console.error(D(` ${j.agent.label}`));
947
- for (const l of j.agent.lines)
948
- console.error(` ${C(l)}`);
949
- console.error(D(` ${j.agent.note}`));
1035
+ const installs = await relayInstallerVersion(relay);
1036
+ const b = inviteBlock(invite, { relay, installs, serves: installs !== null });
1037
+ console.error(`\n${B(b.heading)}\n`);
1038
+ for (const l of b.lines)
1039
+ console.error(l.command ? ` ${C(l.text)}` : D(` ${l.text}`));
950
1040
  }
951
1041
  const HUD_ACTION_MAX_AGE_MS = 30_000;
952
1042
  function emptyThreadStep(goal) {
@@ -1129,6 +1219,19 @@ function unattendedProject() {
1129
1219
  return { project: resolve(flag("project", ".")), how: "explicit" };
1130
1220
  return { project: resolve("."), how: "default" };
1131
1221
  }
1222
+ async function runCheck(cfg) {
1223
+ const { checkAgent, CHECK_TIMEOUT_MS } = await import("./agent-check.js");
1224
+ const ready = agentReadiness(cfg);
1225
+ const label = ready.agent ? (await import("./agents.js")).agentById(ready.agent)?.label ?? ready.agent : null;
1226
+ if (ready.ok && label)
1227
+ console.error(D(` Checking ${label} the way it runs for teammates while you're away (up to ${CHECK_TIMEOUT_MS / 1000} seconds)…`));
1228
+ const r = await checkAgent(cfg, { readiness: () => ready });
1229
+ if (r.ok)
1230
+ console.error(` ${C("✓")} ${r.agent} answered in ${r.seconds} s, run the way it runs for teammates' requests.`);
1231
+ else
1232
+ console.error(`\x1b[33m ! ${r.says}\x1b[0m\n → ${r.fix}`);
1233
+ return r;
1234
+ }
1132
1235
  function agentReadiness(cfg) {
1133
1236
  let unsandboxedOk = false;
1134
1237
  try {
@@ -1444,6 +1547,40 @@ async function rejectPendingChange(id, by) {
1444
1547
  function guideAsks(preset) {
1445
1548
  return !!process.stdin.isTTY && !!process.stderr.isTTY && !argv.includes("--yes") && !argv.includes("--no-guide") && !Object.keys(preset).length;
1446
1549
  }
1550
+ async function teamSuggestion(cfg) {
1551
+ const c = new PantheonClient(cfg, undefined, { role: "cli" });
1552
+ try {
1553
+ const ok = await Promise.race([c.connect().then(() => true, () => false), new Promise((r) => setTimeout(() => r(false), 6_000))]);
1554
+ if (!ok)
1555
+ return null;
1556
+ const founder = c.members.find((e) => e.founder);
1557
+ const prof = founder ? c.profiles.get(founder.member) : undefined;
1558
+ const ts = prof?.team_setup;
1559
+ if (!founder?.pubkey || !ts || ![cfg.spaceId, cfg.space].includes(ts.team))
1560
+ return null;
1561
+ try {
1562
+ const { loadPins, teamPinId } = await import("./pins.js");
1563
+ const pinned = loadPins().teams[teamPinId(cfg)]?.members[founder.member];
1564
+ if (pinned?.key && pinned.key !== founder.pubkey)
1565
+ return null;
1566
+ }
1567
+ catch { }
1568
+ const { teamSetupPayload, verifyBytes } = await import("./identity.js");
1569
+ const { sig, ...fields } = ts;
1570
+ if (!verifyBytes(founder.pubkey, teamSetupPayload(founder.member, fields), sig))
1571
+ return null;
1572
+ const { ALERT_OPTIONS } = await import("./setup-guide.js");
1573
+ if (!ALERT_OPTIONS.some((o) => o.id === ts.alerts))
1574
+ return null;
1575
+ return { mode: ts.mode, wake: ts.wake, commands: ts.commands, notifications: ts.alerts, by: prof.display_name || founder.member };
1576
+ }
1577
+ catch {
1578
+ return null;
1579
+ }
1580
+ finally {
1581
+ c.dispose();
1582
+ }
1583
+ }
1447
1584
  async function guidedSetup(cfg, project, opts = {}) {
1448
1585
  const preset = opts.preset ?? {};
1449
1586
  if (argv.includes("--no-guide") && !Object.keys(preset).length) {
@@ -1460,8 +1597,8 @@ async function guidedSetup(cfg, project, opts = {}) {
1460
1597
  const rl = interactive ? createInterface({ input: process.stdin, output: process.stderr }) : null;
1461
1598
  const io = rl ? terminalIO(rl, (l) => console.error(l)) : null;
1462
1599
  const summary = !!io && !!opts.summary && !opts.founder;
1463
- if (!summary)
1464
- console.error(`\n${B("A few choices, then you're done.")}${io ? "" : Object.keys(preset).length ? D(" (applying the answers you passed)") : D(" (no terminal — taking the defaults)")}`);
1600
+ if (!summary && !io)
1601
+ console.error(`\n${B("A few choices, then you're done.")}${Object.keys(preset).length ? D(" (applying the answers you passed)") : D(" (no terminal — taking the defaults)")}`);
1465
1602
  else
1466
1603
  console.error("");
1467
1604
  try {
@@ -1491,7 +1628,14 @@ async function guidedSetup(cfg, project, opts = {}) {
1491
1628
  }
1492
1629
  }
1493
1630
  }
1494
- const r = await runGuide(io, { cfg, project, optOut: optOutsFrom(argv), serves, setUp: SET_UP, ...(base !== undefined ? { base } : {}), ...(opts.founder !== undefined ? { founder: opts.founder } : {}), ...(summary ? { summary: true } : {}) }, {
1631
+ const r = await runGuide(io, { cfg, project, optOut: optOutsFrom(argv), serves, setUp: SET_UP, ...(base !== undefined ? { base } : {}), ...(opts.founder !== undefined ? { founder: opts.founder } : {}), ...(summary ? { summary: true } : {}), ...(opts.suggested ? { suggested: opts.suggested } : {}) }, {
1632
+ ...(cfg.privateKey ? { teamSetup: (a) => {
1633
+ const team = cfg.spaceId ?? cfg.space;
1634
+ if (!team)
1635
+ return null;
1636
+ const fields = { team, mode: a.mode ?? "here", wake: a.wake, commands: a.commands, alerts: a.notifications, at: Date.now() };
1637
+ return { ...fields, sig: signBytes(cfg.privateKey, teamSetupPayload(cfg.member, fields)) };
1638
+ } } : {}),
1495
1639
  gate: (changes, a) => protectSetup(changes, { replay: setupReplay(a, changes, preset), io }),
1496
1640
  unsandboxedAgents: () => { try {
1497
1641
  return agentsNeedingUnsandboxed();
@@ -1884,7 +2028,11 @@ function printReady(tools) {
1884
2028
  console.error(D(` ${l}`));
1885
2029
  }
1886
2030
  }
1887
- async function workerHeld() {
2031
+ let workerHeldOnce = null;
2032
+ function workerHeld() {
2033
+ return (workerHeldOnce ??= workerHeldNow());
2034
+ }
2035
+ async function workerHeldNow() {
1888
2036
  try {
1889
2037
  if (servicesUnavailable(process.platform))
1890
2038
  return null;
@@ -1924,7 +2072,47 @@ async function autopilotFacts(cfg) {
1924
2072
  out.worker = w ? { installed: w.installed, running: w.loaded } : null;
1925
2073
  return out;
1926
2074
  }
2075
+ function dropCarriedOn(invite) {
2076
+ try {
2077
+ withConfigLock(() => {
2078
+ const c = identity();
2079
+ const r = c?.pendingAuth?.resume;
2080
+ if (!r || r.cmd !== "join" || !invite || r.args[0] !== invite)
2081
+ return;
2082
+ const n = { ...c, pendingAuth: { ...c.pendingAuth } };
2083
+ delete n.pendingAuth.resume;
2084
+ if (c.account || typeof n.pendingAuth.at !== "number")
2085
+ delete n.pendingAuth;
2086
+ save(n);
2087
+ });
2088
+ }
2089
+ catch { }
2090
+ }
2091
+ function clearCarriedOn() {
2092
+ try {
2093
+ withConfigLock(() => {
2094
+ const c = identity();
2095
+ if (c?.account && c.pendingAuth) {
2096
+ const n = { ...c };
2097
+ delete n.pendingAuth;
2098
+ save(n);
2099
+ }
2100
+ });
2101
+ }
2102
+ catch { }
2103
+ }
2104
+ const AGENT_LABELS = { "claude code": "Claude Code", cursor: "Cursor", codex: "Codex", copilot: "Copilot", "vs code": "VS Code", kiro: "Kiro" };
2105
+ function printToolRows(tools) {
2106
+ const absent = (t) => /^skipped \([^()]*(not found|not on PATH)[^()]*\)$/i.test(t.status.trim());
2107
+ const missing = tools.filter((t) => absent(t) && AGENT_LABELS[t.tool]).map((t) => AGENT_LABELS[t.tool]);
2108
+ for (const t of tools)
2109
+ if (!absent(t))
2110
+ console.error(` ${t.tool.padEnd(14)}${t.status}`);
2111
+ if (missing.length)
2112
+ console.error(` ${"not found".padEnd(14)}${missing.join(", ")} — nothing to connect there`);
2113
+ }
1927
2114
  async function finishLine(tools, o) {
2115
+ clearCarriedOn();
1928
2116
  const { finishItems, finishLines, finishMarker, SIGN_IN_RUN } = await import("./finish-line.js");
1929
2117
  const { teamWorkspaces } = await import("./worker-fleet.js");
1930
2118
  const cfg = load();
@@ -1960,7 +2148,8 @@ async function finishLine(tools, o) {
1960
2148
  pending = 0;
1961
2149
  }
1962
2150
  const workerWanted = wakeOn && !argv.includes("--no-worker");
1963
- return [...(o.extra ?? []), ...finishItems({ tools, readiness: ready, team: cfg?.space ?? "<team>", workerWanted, served, windows, pending, worker: workerWanted && (served ?? 0) > 0 ? await workerHeld() : null })];
2151
+ const workerRowFailed = tools.some((t) => t.tool === "worker" && /^(failed|could not)/i.test(t.status));
2152
+ return [...(o.extra ?? []), ...finishItems({ tools, readiness: ready, team: cfg?.space ?? "<team>", workerWanted, served, windows, pending, worker: workerWanted && (served ?? 0) > 0 && !workerRowFailed ? await workerHeld() : null })];
1964
2153
  };
1965
2154
  let items = await gather();
1966
2155
  if (guideAsks(o.preset)) {
@@ -1998,6 +2187,34 @@ async function finishLine(tools, o) {
1998
2187
  console.error(items.length ? `\x1b[33m${B(lines[0])}\x1b[0m` : `${C("✓")} ${B(lines[0].replace(/^✓ /, ""))}`);
1999
2188
  for (const l of lines.slice(1))
2000
2189
  console.error(l);
2190
+ if (cfg && !items.length && guideAsks(o.preset) && !inWokenRun()) {
2191
+ try {
2192
+ const wake = wakeMode(loadProfile(cfg));
2193
+ const ready = wake !== "no" ? agentReadiness(cfg) : null;
2194
+ if (ready?.ok && ready.agent) {
2195
+ const label = (await import("./agents.js")).agentById(ready.agent)?.label ?? ready.agent;
2196
+ const a = ((await askOnce(`\n Check now that ${label} can answer teammates while you're away? It runs it once, up to a minute. [Y/n] `)) ?? "n").trim().toLowerCase();
2197
+ if (a === "" || a === "y" || a === "yes") {
2198
+ const r = await runCheck(cfg);
2199
+ let served = 0;
2200
+ try {
2201
+ if (cfg.spaceId)
2202
+ served = (await import("./worker-fleet.js")).teamWorkspaces(loadAll(), cfg.spaceId).length;
2203
+ }
2204
+ catch { }
2205
+ if (r.ok && wake === "anyone" && served > 0)
2206
+ console.error(` Teammates can hand you work now.`);
2207
+ else if (r.ok && wake === "approved")
2208
+ console.error(D(` A teammate's first request asks you once whether they may start work here.`));
2209
+ else if (r.ok && served === 0)
2210
+ console.error(D(` Bind a folder to work in first: pantheon use ${cfg.space} --here`));
2211
+ }
2212
+ else
2213
+ console.error(D(` Any time: pantheon check`));
2214
+ }
2215
+ }
2216
+ catch { }
2217
+ }
2001
2218
  const rd = readiness(tools);
2002
2219
  if (rd.attempted && !rd.wired)
2003
2220
  process.exitCode = 1;
@@ -2211,8 +2428,8 @@ function usageFor(command, help) {
2211
2428
  return out.length ? out.join("\n") : null;
2212
2429
  }
2213
2430
  const COMMAND_FLAGS = {
2214
- 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) --agent <claude-code|codex|cursor|copilot|kiro> --json (one object on stdout; exit codes: pantheon help exit-codes)\n and every setup answer as a flag (--name, --title, --wake, --commands, --alerts, --decides, --mode …): pantheon setup --questions",
2215
- join: "<invite link | line | code> --relay <url> --me <name> --no-worker --no-hook --no-notifications --no-menubar --reset --yes --agent <claude-code|codex|cursor|copilot|kiro> --json (one object on stdout; exit codes: pantheon help exit-codes)\n and every setup answer as a flag: pantheon setup --questions",
2431
+ start: "--space <name> --email <address> [--username <name>] then --code <6 digits>, or --continue once the email's link is confirmed (sign in from any shell; --resend for a new code) --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) --agent <claude-code|codex|cursor|copilot|kiro> --json (one object on stdout; exit codes: pantheon help exit-codes)\n and every setup answer as a flag (--name, --title, --wake, --commands, --alerts, --decides, --mode …): pantheon setup --questions",
2432
+ join: "<invite link | line | code> --email <address> [--username <name>] then --code <6 digits>, or --continue once the email's link is confirmed (sign in from any shell; --resend for a new code) --relay <url> --me <name> --no-worker --no-hook --no-notifications --no-menubar --reset --yes --agent <claude-code|codex|cursor|copilot|kiro> --json (one object on stdout; exit codes: pantheon help exit-codes)\n and every setup answer as a flag: pantheon setup --questions",
2216
2433
  invite: "--list --revoke <token|all> --may-wake | --no-wake --ttl <minutes>",
2217
2434
  admit: "<member> --may-wake | --no-wake --revoke --forget --yes",
2218
2435
  wake: "allow <member> | deny <member> | list --space <team>",
@@ -2231,6 +2448,7 @@ const COMMAND_FLAGS = {
2231
2448
  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 (token: --status --remove --no-check)",
2232
2449
  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)",
2233
2450
  doctor: "--share --project <dir> --json",
2451
+ check: "--json (runs your agent once, as it runs for teammates while you're away — up to a minute)",
2234
2452
  status: "--clear-safety (once the safety warnings it shows are handled) --json",
2235
2453
  relay: "--port <n> --host <address> --data <dir> (relay leftovers --data <dir> [--json]: read-only report)",
2236
2454
  use: "<team> --here --yes · pantheon use --unbind (this folder or repo bound to no team again)",
@@ -2517,8 +2735,7 @@ async function main() {
2517
2735
  beforeCreate: lastTeamNotice,
2518
2736
  log: (l) => console.error(l),
2519
2737
  });
2520
- for (const t of r.tools)
2521
- console.error(` ${t.tool.padEnd(14)}${t.status}`);
2738
+ printToolRows(r.tools);
2522
2739
  for (const w of r.warnings)
2523
2740
  console.error(`\x1b[33m ! ${w}\x1b[0m` + (/NOT_SIGNED_IN/.test(w) ? signInHint("NOT_SIGNED_IN", r.cfg.relay) : ""));
2524
2741
  const planWarning = r.claimed ? undefined : r.warnings.find((w) => /PLAN_LIMIT/.test(w));
@@ -2536,21 +2753,11 @@ async function main() {
2536
2753
  }
2537
2754
  if (r.invite) {
2538
2755
  const link = toJoinLink(fromInvite(r.invite));
2539
- if (link) {
2540
- console.error(`\n${B("Send your teammate this link — it unfurls in chat, and it sets up their whole machine:")}\n`);
2541
- console.error(` ${C(link)}\n`);
2542
- console.error(D(` The same invite as a command, for pasting straight into an agent:`));
2543
- console.error(` ${C(`pantheon join ${r.invite}`)}\n`);
2544
- }
2545
- else {
2546
- console.error(`\n${B("Send your teammate this one line — it sets up their whole machine:")}\n`);
2547
- console.error(` ${C(`pantheon join ${r.invite}`)}\n`);
2548
- }
2549
- console.error(D(` From the folder they work in — a clone of the team's repo, or any folder for docs and plans (no git needed). Single use, expires in ${Math.round(numFlag("ttl", 1440) / 60)}h.`));
2550
- console.error(D(` Redeeming it admits them — no separate approval step. Need another? \`pantheon invite\``));
2756
+ console.error(`\n${B("Your teammate's invite")} ${D(`(single use, expires in ${Math.round(numFlag("ttl", 1440) / 60)}h — another: pantheon invite)`)}`);
2757
+ console.error(` ${C(`pantheon join ${link ?? r.invite}`)}`);
2551
2758
  console.error(r.inviteMayWake
2552
- ? ` ${B("It also lets them wake workers:")} ${D("their requests can start an agent run on this machine while you are away (you chose wake \"anyone\"). Take it back: pantheon admit <name> --revoke")}`
2553
- : D(` It lets them join and talk to your agent. It does not let them wake this machine on its own: the first time their request needs it while you are away, you are asked (Always / Just this once / No). Approve ahead: pantheon wake allow <name>`));
2759
+ ? D(` It admits them, and their requests can start your agent here while you're away (the default — to approve each teammate first: pantheon setup --wake approved; for one person: pantheon admit <name> --revoke).`)
2760
+ : D(` It admits them. It does not let them wake this machine on its own: the first time their request needs it while you are away, you are asked (Always / Just this once / No). Approve ahead: pantheon wake allow <name>`));
2554
2761
  await printJoinSteps(link ?? r.invite, r.cfg?.relay);
2555
2762
  }
2556
2763
  if (!r.reach.shareable && r.reach.hint) {
@@ -2609,6 +2816,7 @@ async function main() {
2609
2816
  const ttl = numFlag("ttl", 1440);
2610
2817
  const mayWake = argv.includes("--may-wake") ? true : argv.includes("--no-wake") ? false : wakeDefault(loadProfile(cfg));
2611
2818
  const inv = await client.makeInvite(mayWake, ttl).catch((e) => die(e.message));
2819
+ recordInviteSent(cfg.spaceId ?? cfg.space, inv.url);
2612
2820
  const raw = toInvite({ ...cfg, token: inv.url });
2613
2821
  const link = toJoinLink({ relay: cfg.relay, space: cfg.space, token: inv.url });
2614
2822
  console.log(`pantheon join ${raw}`);
@@ -2742,7 +2950,16 @@ async function main() {
2742
2950
  }
2743
2951
  case "join": {
2744
2952
  await membershipGate();
2745
- 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]");
2953
+ if (argv[1]?.startsWith("--")) {
2954
+ const at = inviteIndexes(argv.slice(1))[0];
2955
+ if (at !== undefined && at > 0)
2956
+ argv.splice(1, 0, ...argv.splice(at + 1, 1));
2957
+ }
2958
+ if (!argv[1] || argv[1].startsWith("--")) {
2959
+ if (wantsFlagSignIn() || argv.includes("--continue"))
2960
+ die(`nothing is waiting to carry on here — start with: ${pantheonCommand(managedLayout()?.launcher, "join '<your invite link>' --email you@work.com")}`, EXIT.usage);
2961
+ }
2962
+ const invite = argv[1] && !argv[1].startsWith("--") ? 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]");
2746
2963
  const setupFlags = parseSetupFlags(argv);
2747
2964
  if (setupFlags.errors.length)
2748
2965
  die(setupFlags.errors.join("\n") + "\n pantheon setup --questions lists every answer", EXIT.usage);
@@ -2767,13 +2984,19 @@ async function main() {
2767
2984
  });
2768
2985
  console.error(D(`That was just the code — it opens "${parsed.space}" on ${new URL(parsed.relay).host}. Joining that team.\n`));
2769
2986
  }
2770
- if (!identity()?.account && sameHost(parsed.relay, DEFAULT_RELAY) && process.stdin.isTTY) {
2987
+ const hadAccount = !!identity()?.account;
2988
+ const byFlags = wantsFlagSignIn();
2989
+ if (byFlags)
2990
+ await flagSignIn("join", parsed.relay, parsed.space);
2991
+ if (!identity()?.account && sameHost(parsed.relay, DEFAULT_RELAY) && process.stdin.isTTY && !byFlags) {
2771
2992
  const ok = await interactiveOnboard(parsed.relay, { joining: parsed.space });
2772
2993
  if (!ok || !identity()?.account)
2773
- die(`not signed in yet — the invite is still good.\n When the code arrives: pantheon verify <code> (check spam if it is not in your inbox)\n Then run this same \`pantheon join\` command again.`);
2994
+ die(`not signed in yet — the invite is still good.\n When the code arrives: ${pantheonCommand(managedLayout()?.launcher, "verify <code>")} (check spam if it is not in your inbox)\n Then run this same \`pantheon join\` command again.`);
2995
+ }
2996
+ if (!hadAccount && identity()?.account) {
2774
2997
  const mineAll = await accountSeats(parsed.relay);
2775
2998
  const own = mineAll ? seatsForTeam(mineAll, parsed.space) : null;
2776
- const offer = own ? await offerSeatsHere(own) : null;
2999
+ const offer = own ? await offerSeatsHere(own, { tty: !byFlags && !!process.stdin.isTTY }) : null;
2777
3000
  if (offer?.moved.length) {
2778
3001
  console.error(`\n ${C("done")} — your seat in ${offer.moved[0]} is on this machine; the invite was not needed.`);
2779
3002
  return;
@@ -2785,7 +3008,7 @@ async function main() {
2785
3008
  console.error("");
2786
3009
  }
2787
3010
  if (!identity()?.account && sameHost(parsed.relay, DEFAULT_RELAY)) {
2788
- die(`sign in first — this relay verifies email.\n${signInSteps().join("\n")}\n Then run this same \`pantheon join\` command again — the invite is still good.\n ${SIGNIN_FOR_AGENTS}`);
3011
+ die(`sign in first — this relay verifies email.\n${signInSteps("join").join("\n")}\n Or sign in first, then run this same \`pantheon join\` command again — the invite is still good.\n ${SIGNIN_FOR_AGENTS}`);
2789
3012
  }
2790
3013
  const wp = unattendedProject();
2791
3014
  console.error(`${B("pantheon join")}\n`);
@@ -2823,8 +3046,7 @@ async function main() {
2823
3046
  die(`cannot reach the relay in that invite.\n ${m}\n Is their relay still running, and are you both on the same network/tailnet?`);
2824
3047
  die(m + (/NOT_SIGNED_IN/.test(m) ? signInHint("NOT_SIGNED_IN", parsed.relay) : ""));
2825
3048
  });
2826
- for (const t of r.tools)
2827
- console.error(` ${t.tool.padEnd(14)}${t.status}`);
3049
+ printToolRows(r.tools);
2828
3050
  for (const w of r.warnings)
2829
3051
  console.error(`\x1b[33m ! ${w}\x1b[0m` + (/NOT_SIGNED_IN/.test(w) ? signInHint("NOT_SIGNED_IN", parsed.relay) : ""));
2830
3052
  printGranted(r.granted);
@@ -2873,7 +3095,8 @@ async function main() {
2873
3095
  windowsOverridesForBoundRepos();
2874
3096
  const joined = load();
2875
3097
  await applyAgentChoice(joined, agentWant);
2876
- const guided = joined ? await guidedSetup(joined, repoInfo(process.cwd())?.root ?? null, { preset: setupFlags.preset, force: Object.keys(setupFlags.preset).length > 0 || argv.includes("--yes"), summary: true, finish: true }) : { cancelled: false };
3098
+ const suggested = joined && guideAsks(setupFlags.preset) ? await teamSuggestion(joined) : null;
3099
+ const guided = joined ? await guidedSetup(joined, repoInfo(process.cwd())?.root ?? null, { preset: setupFlags.preset, force: Object.keys(setupFlags.preset).length > 0 || argv.includes("--yes"), summary: true, finish: true, suggested }) : { cancelled: false };
2877
3100
  await finishLine(r.tools, { founder: false, preset: setupFlags.preset, ...(guided.cancelled ? { extra: [STOPPED_ITEM] } : {}) });
2878
3101
  return;
2879
3102
  }
@@ -4588,7 +4811,7 @@ async function main() {
4588
4811
  if (cfg.account) {
4589
4812
  console.log(`account ${C(cfg.account.username)} ${D(`<${cfg.account.email}>`)} ${D("verified")}`);
4590
4813
  }
4591
- else if (cfg.pendingAuth) {
4814
+ else if (cfg.pendingAuth && typeof cfg.pendingAuth.at === "number") {
4592
4815
  console.log(`account ${D(`not signed in yet — a code was sent to ${cfg.pendingAuth.email} (check spam): pantheon verify <code>`)}`);
4593
4816
  }
4594
4817
  else {
@@ -4657,6 +4880,10 @@ async function main() {
4657
4880
  }
4658
4881
  case "verify": {
4659
4882
  const cfg = identity() ?? die("run `pantheon signup` or `pantheon login` first");
4883
+ if (cfg.account) {
4884
+ console.error(`${C("already signed in")} as ${B(cfg.account.username)} <${cfg.account.email}> on this machine.`);
4885
+ return;
4886
+ }
4660
4887
  const pending = cfg.pendingAuth ?? die("nothing to verify — run `pantheon signup` or `pantheon login` first");
4661
4888
  let code = (argv[1] ?? flag("code") ?? "").trim();
4662
4889
  if (!code && process.stdin.isTTY) {
@@ -7672,6 +7899,15 @@ async function main() {
7672
7899
  client.close();
7673
7900
  return;
7674
7901
  }
7902
+ case "check": {
7903
+ const cfg = load() ?? die("not set up on this machine yet — pantheon start, or pantheon join <invite>");
7904
+ const r = await runCheck(cfg);
7905
+ if (JSON_OUT)
7906
+ sayJson(r.ok ? { status: "ok", code: 0, agent: r.agent, seconds: r.seconds } : { status: "failed", code: 1, agent: r.agent, says: r.says, fix: r.fix });
7907
+ if (!r.ok)
7908
+ process.exitCode = 1;
7909
+ return;
7910
+ }
7675
7911
  case "mcp":
7676
7912
  if (argv.includes("--child") || process.env.PANTHEON_MCP_SUPERVISED)
7677
7913
  await runMcp();