@join-pantheon/cli 0.36.0 → 0.37.0-rc.2

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,63 @@ async function signedFetch(cfg, method, path, params = {}) {
110
132
  }
111
133
  return res;
112
134
  }
135
+ const FLAG_SIGNIN_POST_MS = 30_000;
136
+ function wantsFlagSignIn() {
137
+ return flag("email") !== undefined || flag("code") !== undefined || argv.includes("--continue");
138
+ }
139
+ async function flagSignIn(which, relay, joining) {
140
+ const base = relay.replace(/^ws/, "http").replace(/\/+$/, "");
141
+ let why = "";
142
+ const deps = {
143
+ post: (path, body) => fetch(`${base}${path}`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body), signal: AbortSignal.timeout(FLAG_SIGNIN_POST_MS) })
144
+ .then(async (x) => ({ status: x.status, j: await relayJson(x, `${base}${path}`) }))
145
+ .catch(async (e) => { why = await describeRelayFailure(e, relay); return null; }),
146
+ unreachable: () => why,
147
+ identity: () => identity(),
148
+ saveLocked: (fn) => withConfigLock(() => { const next = fn(identity()); save({ ...next, relay: next.relay || relay }); return next; }),
149
+ newKeypair,
150
+ status: async (timeoutMs) => {
151
+ const me = identity();
152
+ if (!me?.publicKey || !me.privateKey)
153
+ return null;
154
+ const ts = Date.now(), nonce = randomBytes(18).toString("base64url");
155
+ 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) }, signal: AbortSignal.timeout(timeoutMs) })
156
+ .then(async (x) => {
157
+ const after = Number(x.headers.get("retry-after"));
158
+ return { status: x.status, j: await relayJson(x, `${base}/auth/status`), ...(x.status === 429 && Number.isFinite(after) && after > 0 ? { retryAfter: Math.min(after, 60) } : {}) };
159
+ })
160
+ .catch(async (e) => { why = await describeRelayFailure(e, relay); return null; });
161
+ },
162
+ label: flag("label") ?? deviceLabel(),
163
+ gitEmail: gitConfigValue("user.email"),
164
+ now: () => Date.now(),
165
+ command: (rest) => pantheonCommand(managedLayout()?.launcher, JSON_OUT && / --(code|email|username|continue)\b/.test(` ${rest}`) ? `${rest} --json` : rest),
166
+ };
167
+ const code = flag("code");
168
+ const cont = argv.includes("--continue") && code === undefined && flag("email") === undefined;
169
+ if (flag("email") === undefined && code === undefined && !cont)
170
+ return;
171
+ if (code === undefined && !cont && !flag("email"))
172
+ die("usage: --email needs your address: --email you@work.com", EXIT.usage);
173
+ if (cont)
174
+ console.error(D(` Waiting for the link in the email to be confirmed (up to 90 seconds)…`));
175
+ const out = cont ? await awaitLink({ cmd: which, deps })
176
+ : code !== undefined
177
+ ? await enterCode({ cmd: which, code, deps })
178
+ : 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 });
179
+ if (out.kind === "signed_in") {
180
+ console.error(` ${C("You're in")} — ${out.already ? "already " : ""}signed in as ${B(out.account.username)} <${out.account.email}> on this machine.\n`);
181
+ return;
182
+ }
183
+ if (out.kind === "error")
184
+ die(out.message, out.exit === "usage" ? EXIT.usage : out.exit === "network" ? EXIT.network : EXIT.failed);
185
+ for (const l of out.lines)
186
+ console.error(` ${l}`);
187
+ const one = (t) => typeof t === "string" ? t.replace(/\s+\(Command Prompt: .*\)$/, "") : t;
188
+ if (JSON_OUT)
189
+ 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) } : {}) });
190
+ process.exit(EXIT.needsPerson);
191
+ }
113
192
  async function requireSignInOnHostedRelay(relayFlag) {
114
193
  const cfg = identity();
115
194
  if (cfg?.account)
@@ -118,14 +197,19 @@ async function requireSignInOnHostedRelay(relayFlag) {
118
197
  const hosted = relay === DEFAULT_RELAY && !relayFlag && !process.env.PANTHEON_RELAY;
119
198
  if (!hosted)
120
199
  return;
200
+ if (wantsFlagSignIn()) {
201
+ await flagSignIn("start", relay);
202
+ if (identity()?.account)
203
+ return;
204
+ }
121
205
  if (process.stdin.isTTY) {
122
206
  if (await interactiveOnboard(relay, { starting: true }) && identity()?.account) {
123
207
  console.error("");
124
208
  return;
125
209
  }
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.");
210
+ 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
211
  }
128
- die(`sign in first — this relay verifies email.\n${signInSteps().join("\n")}\n Then run pantheon start again.\n ${SIGNIN_FOR_AGENTS}`);
212
+ 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
213
  }
130
214
  async function requireSignInOnAccountsRelay(relayFlag) {
131
215
  if (!relayFlag || identity()?.account)
@@ -139,12 +223,17 @@ async function requireSignInOnAccountsRelay(relayFlag) {
139
223
  catch {
140
224
  return;
141
225
  }
226
+ if (hasAccounts && wantsFlagSignIn()) {
227
+ await flagSignIn("start", relayFlag);
228
+ if (identity()?.account)
229
+ return;
230
+ }
142
231
  if (hasAccounts && process.stdin.isTTY) {
143
232
  if (await interactiveOnboard(relayFlag, { starting: true }) && identity()?.account) {
144
233
  console.error("");
145
234
  return;
146
235
  }
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.");
236
+ 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
237
  }
149
238
  if (hasAccounts)
150
239
  die(`sign in first — ${relayFlag} verifies email.${signInHint("NOT_SIGNED_IN", relayFlag)}\n Then run this same pantheon start again.`);
@@ -162,6 +251,8 @@ async function accountSeats(relay) {
162
251
  ]);
163
252
  }
164
253
  async function askOnce(q) {
254
+ if (PROMPTLESS)
255
+ return null;
165
256
  const rl = createInterface({ input: process.stdin, output: process.stderr });
166
257
  try {
167
258
  return await questionOrNull(rl, q);
@@ -228,7 +319,7 @@ async function interactiveOnboard(relayArg, opts = {}) {
228
319
  }
229
320
  email = e;
230
321
  }
231
- const send = (m, username) => postJson(`/auth/${m}`, m === "signup" ? { email, username, pubkey: kp.publicKey, label } : { email, pubkey: kp.publicKey, label })
322
+ 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
323
  .catch(unreachable);
233
324
  const justSent = (r) => r.j.reason === "too_soon";
234
325
  let mode = "login";
@@ -350,11 +441,21 @@ async function interactiveOnboard(relayArg, opts = {}) {
350
441
  }
351
442
  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
443
  const SPAM_HINT = "Not there in a minute? Check your spam folder.";
353
- function signInSteps() {
444
+ function signInSteps(which) {
445
+ const L = managedLayout()?.launcher;
446
+ if (which) {
447
+ const first = which === "join" ? "join '<your invite link>'" : "start";
448
+ return [
449
+ ` ${C(signinCommand(L))} ${D("in a terminal of your own: your email, then the emailed code, in one go")}`,
450
+ ` ${D("or, from any shell (a coding agent's too), two steps:")}`,
451
+ ` ${C(pantheonCommand(L, `${first} --email you@work.com --username <name teammates see, new accounts only>`))}`,
452
+ ` ${C(pantheonCommand(L, `${which} --code <the 6-digit code>`))} ${D("(the code is emailed — check spam)")}`,
453
+ ];
454
+ }
354
455
  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)")}`,
456
+ ` ${C(signinCommand(L))} ${D("in a terminal of your own: your email, then the emailed code, in one go")}`,
457
+ ` ${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")})`)}`,
458
+ ` ${C(pantheonCommand(L, "verify <code>"))} ${D("(the code is emailed — check spam)")}`,
358
459
  ];
359
460
  }
360
461
  function ago(t) {
@@ -400,6 +501,8 @@ function keywordFlag(raw) {
400
501
  return out;
401
502
  }
402
503
  function die(msg, code = exitCodeFor(cmd, msg)) {
504
+ if (cmd === "join" && code === EXIT.inviteUnusable)
505
+ dropCarriedOn(argv[1]);
403
506
  const said = plainError(msg);
404
507
  console.error(`pantheon: ${said}`);
405
508
  if (JSON_OUT)
@@ -925,8 +1028,7 @@ function printRelayNote(relay) {
925
1028
  host = new URL(relay.replace(/^ws/, "http")).host;
926
1029
  }
927
1030
  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`));
1031
+ 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
1032
  }
931
1033
  function windowsOverridesForBoundRepos() {
932
1034
  const dirs = Object.values(loadAll()?.bindings ?? {}).map((b) => b.path).filter((p) => !!p && existsSync(p));
@@ -934,19 +1036,11 @@ function windowsOverridesForBoundRepos() {
934
1036
  console.error(` ${D("claude code in")} ${r.dir} ${D(r.status)}`);
935
1037
  }
936
1038
  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}`));
1039
+ const installs = await relayInstallerVersion(relay);
1040
+ const b = inviteBlock(invite, { relay, installs, serves: installs !== null });
1041
+ console.error(`\n${B(b.heading)}\n`);
1042
+ for (const l of b.lines)
1043
+ console.error(l.command ? ` ${C(l.text)}` : D(` ${l.text}`));
950
1044
  }
951
1045
  const HUD_ACTION_MAX_AGE_MS = 30_000;
952
1046
  function emptyThreadStep(goal) {
@@ -1129,6 +1223,19 @@ function unattendedProject() {
1129
1223
  return { project: resolve(flag("project", ".")), how: "explicit" };
1130
1224
  return { project: resolve("."), how: "default" };
1131
1225
  }
1226
+ async function runCheck(cfg) {
1227
+ const { checkAgent, CHECK_TIMEOUT_MS } = await import("./agent-check.js");
1228
+ const ready = agentReadiness(cfg);
1229
+ const label = ready.agent ? (await import("./agents.js")).agentById(ready.agent)?.label ?? ready.agent : null;
1230
+ if (ready.ok && label)
1231
+ console.error(D(` Checking ${label} the way it runs for teammates while you're away (up to ${CHECK_TIMEOUT_MS / 1000} seconds)…`));
1232
+ const r = await checkAgent(cfg, { readiness: () => ready });
1233
+ if (r.ok)
1234
+ console.error(` ${C("✓")} ${r.agent} answered in ${r.seconds} s, run the way it runs for teammates' requests.`);
1235
+ else
1236
+ console.error(`\x1b[33m ! ${r.says}\x1b[0m\n → ${r.fix}`);
1237
+ return r;
1238
+ }
1132
1239
  function agentReadiness(cfg) {
1133
1240
  let unsandboxedOk = false;
1134
1241
  try {
@@ -1444,6 +1551,40 @@ async function rejectPendingChange(id, by) {
1444
1551
  function guideAsks(preset) {
1445
1552
  return !!process.stdin.isTTY && !!process.stderr.isTTY && !argv.includes("--yes") && !argv.includes("--no-guide") && !Object.keys(preset).length;
1446
1553
  }
1554
+ async function teamSuggestion(cfg) {
1555
+ const c = new PantheonClient(cfg, undefined, { role: "cli" });
1556
+ try {
1557
+ const ok = await Promise.race([c.connect().then(() => true, () => false), new Promise((r) => setTimeout(() => r(false), 6_000))]);
1558
+ if (!ok)
1559
+ return null;
1560
+ const founder = c.members.find((e) => e.founder);
1561
+ const prof = founder ? c.profiles.get(founder.member) : undefined;
1562
+ const ts = prof?.team_setup;
1563
+ if (!founder?.pubkey || !ts || ![cfg.spaceId, cfg.space].includes(ts.team))
1564
+ return null;
1565
+ try {
1566
+ const { loadPins, teamPinId } = await import("./pins.js");
1567
+ const pinned = loadPins().teams[teamPinId(cfg)]?.members[founder.member];
1568
+ if (pinned?.key && pinned.key !== founder.pubkey)
1569
+ return null;
1570
+ }
1571
+ catch { }
1572
+ const { teamSetupPayload, verifyBytes } = await import("./identity.js");
1573
+ const { sig, ...fields } = ts;
1574
+ if (!verifyBytes(founder.pubkey, teamSetupPayload(founder.member, fields), sig))
1575
+ return null;
1576
+ const { ALERT_OPTIONS } = await import("./setup-guide.js");
1577
+ if (!ALERT_OPTIONS.some((o) => o.id === ts.alerts))
1578
+ return null;
1579
+ return { mode: ts.mode, wake: ts.wake, commands: ts.commands, notifications: ts.alerts, by: prof.display_name || founder.member };
1580
+ }
1581
+ catch {
1582
+ return null;
1583
+ }
1584
+ finally {
1585
+ c.dispose();
1586
+ }
1587
+ }
1447
1588
  async function guidedSetup(cfg, project, opts = {}) {
1448
1589
  const preset = opts.preset ?? {};
1449
1590
  if (argv.includes("--no-guide") && !Object.keys(preset).length) {
@@ -1460,8 +1601,8 @@ async function guidedSetup(cfg, project, opts = {}) {
1460
1601
  const rl = interactive ? createInterface({ input: process.stdin, output: process.stderr }) : null;
1461
1602
  const io = rl ? terminalIO(rl, (l) => console.error(l)) : null;
1462
1603
  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)")}`);
1604
+ if (!summary && !io)
1605
+ 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
1606
  else
1466
1607
  console.error("");
1467
1608
  try {
@@ -1491,7 +1632,14 @@ async function guidedSetup(cfg, project, opts = {}) {
1491
1632
  }
1492
1633
  }
1493
1634
  }
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 } : {}) }, {
1635
+ 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 } : {}) }, {
1636
+ ...(cfg.privateKey ? { teamSetup: (a) => {
1637
+ const team = cfg.spaceId ?? cfg.space;
1638
+ if (!team)
1639
+ return null;
1640
+ const fields = { team, mode: a.mode ?? "here", wake: a.wake, commands: a.commands, alerts: a.notifications, at: Date.now() };
1641
+ return { ...fields, sig: signBytes(cfg.privateKey, teamSetupPayload(cfg.member, fields)) };
1642
+ } } : {}),
1495
1643
  gate: (changes, a) => protectSetup(changes, { replay: setupReplay(a, changes, preset), io }),
1496
1644
  unsandboxedAgents: () => { try {
1497
1645
  return agentsNeedingUnsandboxed();
@@ -1884,7 +2032,11 @@ function printReady(tools) {
1884
2032
  console.error(D(` ${l}`));
1885
2033
  }
1886
2034
  }
1887
- async function workerHeld() {
2035
+ let workerHeldOnce = null;
2036
+ function workerHeld() {
2037
+ return (workerHeldOnce ??= workerHeldNow());
2038
+ }
2039
+ async function workerHeldNow() {
1888
2040
  try {
1889
2041
  if (servicesUnavailable(process.platform))
1890
2042
  return null;
@@ -1924,7 +2076,47 @@ async function autopilotFacts(cfg) {
1924
2076
  out.worker = w ? { installed: w.installed, running: w.loaded } : null;
1925
2077
  return out;
1926
2078
  }
2079
+ function dropCarriedOn(invite) {
2080
+ try {
2081
+ withConfigLock(() => {
2082
+ const c = identity();
2083
+ const r = c?.pendingAuth?.resume;
2084
+ if (!r || r.cmd !== "join" || !invite || r.args[0] !== invite)
2085
+ return;
2086
+ const n = { ...c, pendingAuth: { ...c.pendingAuth } };
2087
+ delete n.pendingAuth.resume;
2088
+ if (c.account || typeof n.pendingAuth.at !== "number")
2089
+ delete n.pendingAuth;
2090
+ save(n);
2091
+ });
2092
+ }
2093
+ catch { }
2094
+ }
2095
+ function clearCarriedOn() {
2096
+ try {
2097
+ withConfigLock(() => {
2098
+ const c = identity();
2099
+ if (c?.account && c.pendingAuth) {
2100
+ const n = { ...c };
2101
+ delete n.pendingAuth;
2102
+ save(n);
2103
+ }
2104
+ });
2105
+ }
2106
+ catch { }
2107
+ }
2108
+ const AGENT_LABELS = { "claude code": "Claude Code", cursor: "Cursor", codex: "Codex", copilot: "Copilot", "vs code": "VS Code", kiro: "Kiro" };
2109
+ function printToolRows(tools) {
2110
+ const absent = (t) => /^skipped \([^()]*(not found|not on PATH)[^()]*\)$/i.test(t.status.trim());
2111
+ const missing = tools.filter((t) => absent(t) && AGENT_LABELS[t.tool]).map((t) => AGENT_LABELS[t.tool]);
2112
+ for (const t of tools)
2113
+ if (!absent(t))
2114
+ console.error(` ${t.tool.padEnd(14)}${t.status}`);
2115
+ if (missing.length)
2116
+ console.error(` ${"not found".padEnd(14)}${missing.join(", ")} — nothing to connect there`);
2117
+ }
1927
2118
  async function finishLine(tools, o) {
2119
+ clearCarriedOn();
1928
2120
  const { finishItems, finishLines, finishMarker, SIGN_IN_RUN } = await import("./finish-line.js");
1929
2121
  const { teamWorkspaces } = await import("./worker-fleet.js");
1930
2122
  const cfg = load();
@@ -1960,7 +2152,8 @@ async function finishLine(tools, o) {
1960
2152
  pending = 0;
1961
2153
  }
1962
2154
  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 })];
2155
+ const workerRowFailed = tools.some((t) => t.tool === "worker" && /^(failed|could not)/i.test(t.status));
2156
+ 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
2157
  };
1965
2158
  let items = await gather();
1966
2159
  if (guideAsks(o.preset)) {
@@ -1998,6 +2191,34 @@ async function finishLine(tools, o) {
1998
2191
  console.error(items.length ? `\x1b[33m${B(lines[0])}\x1b[0m` : `${C("✓")} ${B(lines[0].replace(/^✓ /, ""))}`);
1999
2192
  for (const l of lines.slice(1))
2000
2193
  console.error(l);
2194
+ if (cfg && !items.length && guideAsks(o.preset) && !inWokenRun()) {
2195
+ try {
2196
+ const wake = wakeMode(loadProfile(cfg));
2197
+ const ready = wake !== "no" ? agentReadiness(cfg) : null;
2198
+ if (ready?.ok && ready.agent) {
2199
+ const label = (await import("./agents.js")).agentById(ready.agent)?.label ?? ready.agent;
2200
+ 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();
2201
+ if (a === "" || a === "y" || a === "yes") {
2202
+ const r = await runCheck(cfg);
2203
+ let served = 0;
2204
+ try {
2205
+ if (cfg.spaceId)
2206
+ served = (await import("./worker-fleet.js")).teamWorkspaces(loadAll(), cfg.spaceId).length;
2207
+ }
2208
+ catch { }
2209
+ if (r.ok && wake === "anyone" && served > 0)
2210
+ console.error(` Teammates can hand you work now.`);
2211
+ else if (r.ok && wake === "approved")
2212
+ console.error(D(` A teammate's first request asks you once whether they may start work here.`));
2213
+ else if (r.ok && served === 0)
2214
+ console.error(D(` Bind a folder to work in first: pantheon use ${cfg.space} --here`));
2215
+ }
2216
+ else
2217
+ console.error(D(` Any time: pantheon check`));
2218
+ }
2219
+ }
2220
+ catch { }
2221
+ }
2001
2222
  const rd = readiness(tools);
2002
2223
  if (rd.attempted && !rd.wired)
2003
2224
  process.exitCode = 1;
@@ -2211,8 +2432,8 @@ function usageFor(command, help) {
2211
2432
  return out.length ? out.join("\n") : null;
2212
2433
  }
2213
2434
  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",
2435
+ 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",
2436
+ 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
2437
  invite: "--list --revoke <token|all> --may-wake | --no-wake --ttl <minutes>",
2217
2438
  admit: "<member> --may-wake | --no-wake --revoke --forget --yes",
2218
2439
  wake: "allow <member> | deny <member> | list --space <team>",
@@ -2231,6 +2452,7 @@ const COMMAND_FLAGS = {
2231
2452
  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
2453
  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
2454
  doctor: "--share --project <dir> --json",
2455
+ check: "--json (runs your agent once, as it runs for teammates while you're away — up to a minute)",
2234
2456
  status: "--clear-safety (once the safety warnings it shows are handled) --json",
2235
2457
  relay: "--port <n> --host <address> --data <dir> (relay leftovers --data <dir> [--json]: read-only report)",
2236
2458
  use: "<team> --here --yes · pantheon use --unbind (this folder or repo bound to no team again)",
@@ -2517,8 +2739,7 @@ async function main() {
2517
2739
  beforeCreate: lastTeamNotice,
2518
2740
  log: (l) => console.error(l),
2519
2741
  });
2520
- for (const t of r.tools)
2521
- console.error(` ${t.tool.padEnd(14)}${t.status}`);
2742
+ printToolRows(r.tools);
2522
2743
  for (const w of r.warnings)
2523
2744
  console.error(`\x1b[33m ! ${w}\x1b[0m` + (/NOT_SIGNED_IN/.test(w) ? signInHint("NOT_SIGNED_IN", r.cfg.relay) : ""));
2524
2745
  const planWarning = r.claimed ? undefined : r.warnings.find((w) => /PLAN_LIMIT/.test(w));
@@ -2536,21 +2757,11 @@ async function main() {
2536
2757
  }
2537
2758
  if (r.invite) {
2538
2759
  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\``));
2760
+ console.error(`\n${B("Your teammate's invite")} ${D(`(single use, expires in ${Math.round(numFlag("ttl", 1440) / 60)}h — another: pantheon invite)`)}`);
2761
+ console.error(` ${C(`pantheon join ${link ?? r.invite}`)}`);
2551
2762
  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>`));
2763
+ ? 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).`)
2764
+ : 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
2765
  await printJoinSteps(link ?? r.invite, r.cfg?.relay);
2555
2766
  }
2556
2767
  if (!r.reach.shareable && r.reach.hint) {
@@ -2609,6 +2820,7 @@ async function main() {
2609
2820
  const ttl = numFlag("ttl", 1440);
2610
2821
  const mayWake = argv.includes("--may-wake") ? true : argv.includes("--no-wake") ? false : wakeDefault(loadProfile(cfg));
2611
2822
  const inv = await client.makeInvite(mayWake, ttl).catch((e) => die(e.message));
2823
+ recordInviteSent(cfg.spaceId ?? cfg.space, inv.url);
2612
2824
  const raw = toInvite({ ...cfg, token: inv.url });
2613
2825
  const link = toJoinLink({ relay: cfg.relay, space: cfg.space, token: inv.url });
2614
2826
  console.log(`pantheon join ${raw}`);
@@ -2742,7 +2954,16 @@ async function main() {
2742
2954
  }
2743
2955
  case "join": {
2744
2956
  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]");
2957
+ if (argv[1]?.startsWith("--")) {
2958
+ const at = inviteIndexes(argv.slice(1))[0];
2959
+ if (at !== undefined && at > 0)
2960
+ argv.splice(1, 0, ...argv.splice(at + 1, 1));
2961
+ }
2962
+ if (!argv[1] || argv[1].startsWith("--")) {
2963
+ if (wantsFlagSignIn() || argv.includes("--continue"))
2964
+ die(`nothing is waiting to carry on here — start with: ${pantheonCommand(managedLayout()?.launcher, "join '<your invite link>' --email you@work.com")}`, EXIT.usage);
2965
+ }
2966
+ 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
2967
  const setupFlags = parseSetupFlags(argv);
2747
2968
  if (setupFlags.errors.length)
2748
2969
  die(setupFlags.errors.join("\n") + "\n pantheon setup --questions lists every answer", EXIT.usage);
@@ -2767,13 +2988,19 @@ async function main() {
2767
2988
  });
2768
2989
  console.error(D(`That was just the code — it opens "${parsed.space}" on ${new URL(parsed.relay).host}. Joining that team.\n`));
2769
2990
  }
2770
- if (!identity()?.account && sameHost(parsed.relay, DEFAULT_RELAY) && process.stdin.isTTY) {
2991
+ const hadAccount = !!identity()?.account;
2992
+ const byFlags = wantsFlagSignIn();
2993
+ if (byFlags)
2994
+ await flagSignIn("join", parsed.relay, parsed.space);
2995
+ if (!identity()?.account && sameHost(parsed.relay, DEFAULT_RELAY) && process.stdin.isTTY && !byFlags) {
2771
2996
  const ok = await interactiveOnboard(parsed.relay, { joining: parsed.space });
2772
2997
  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.`);
2998
+ 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.`);
2999
+ }
3000
+ if (!hadAccount && identity()?.account) {
2774
3001
  const mineAll = await accountSeats(parsed.relay);
2775
3002
  const own = mineAll ? seatsForTeam(mineAll, parsed.space) : null;
2776
- const offer = own ? await offerSeatsHere(own) : null;
3003
+ const offer = own ? await offerSeatsHere(own, { tty: !byFlags && !!process.stdin.isTTY }) : null;
2777
3004
  if (offer?.moved.length) {
2778
3005
  console.error(`\n ${C("done")} — your seat in ${offer.moved[0]} is on this machine; the invite was not needed.`);
2779
3006
  return;
@@ -2785,7 +3012,7 @@ async function main() {
2785
3012
  console.error("");
2786
3013
  }
2787
3014
  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}`);
3015
+ 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
3016
  }
2790
3017
  const wp = unattendedProject();
2791
3018
  console.error(`${B("pantheon join")}\n`);
@@ -2823,8 +3050,7 @@ async function main() {
2823
3050
  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
3051
  die(m + (/NOT_SIGNED_IN/.test(m) ? signInHint("NOT_SIGNED_IN", parsed.relay) : ""));
2825
3052
  });
2826
- for (const t of r.tools)
2827
- console.error(` ${t.tool.padEnd(14)}${t.status}`);
3053
+ printToolRows(r.tools);
2828
3054
  for (const w of r.warnings)
2829
3055
  console.error(`\x1b[33m ! ${w}\x1b[0m` + (/NOT_SIGNED_IN/.test(w) ? signInHint("NOT_SIGNED_IN", parsed.relay) : ""));
2830
3056
  printGranted(r.granted);
@@ -2873,7 +3099,8 @@ async function main() {
2873
3099
  windowsOverridesForBoundRepos();
2874
3100
  const joined = load();
2875
3101
  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 };
3102
+ const suggested = joined && guideAsks(setupFlags.preset) ? await teamSuggestion(joined) : null;
3103
+ 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
3104
  await finishLine(r.tools, { founder: false, preset: setupFlags.preset, ...(guided.cancelled ? { extra: [STOPPED_ITEM] } : {}) });
2878
3105
  return;
2879
3106
  }
@@ -4588,7 +4815,7 @@ async function main() {
4588
4815
  if (cfg.account) {
4589
4816
  console.log(`account ${C(cfg.account.username)} ${D(`<${cfg.account.email}>`)} ${D("verified")}`);
4590
4817
  }
4591
- else if (cfg.pendingAuth) {
4818
+ else if (cfg.pendingAuth && typeof cfg.pendingAuth.at === "number") {
4592
4819
  console.log(`account ${D(`not signed in yet — a code was sent to ${cfg.pendingAuth.email} (check spam): pantheon verify <code>`)}`);
4593
4820
  }
4594
4821
  else {
@@ -4657,6 +4884,10 @@ async function main() {
4657
4884
  }
4658
4885
  case "verify": {
4659
4886
  const cfg = identity() ?? die("run `pantheon signup` or `pantheon login` first");
4887
+ if (cfg.account) {
4888
+ console.error(`${C("already signed in")} as ${B(cfg.account.username)} <${cfg.account.email}> on this machine.`);
4889
+ return;
4890
+ }
4660
4891
  const pending = cfg.pendingAuth ?? die("nothing to verify — run `pantheon signup` or `pantheon login` first");
4661
4892
  let code = (argv[1] ?? flag("code") ?? "").trim();
4662
4893
  if (!code && process.stdin.isTTY) {
@@ -7672,6 +7903,15 @@ async function main() {
7672
7903
  client.close();
7673
7904
  return;
7674
7905
  }
7906
+ case "check": {
7907
+ const cfg = load() ?? die("not set up on this machine yet — pantheon start, or pantheon join <invite>");
7908
+ const r = await runCheck(cfg);
7909
+ if (JSON_OUT)
7910
+ 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 });
7911
+ if (!r.ok)
7912
+ process.exitCode = 1;
7913
+ return;
7914
+ }
7675
7915
  case "mcp":
7676
7916
  if (argv.includes("--child") || process.env.PANTHEON_MCP_SUPERVISED)
7677
7917
  await runMcp();