@join-pantheon/cli 0.28.0 → 0.29.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/accounts.js +13 -2
- package/dist/agents.js +377 -9
- package/dist/cli.js +377 -192
- package/dist/client.js +73 -12
- package/dist/config.js +15 -0
- package/dist/doctor.js +13 -10
- package/dist/grants.js +16 -1
- package/dist/hooks-install.js +4 -2
- package/dist/host-env.js +51 -6
- package/dist/install.js +216 -16
- package/dist/kiro-files.js +23 -6
- package/dist/ledger.js +8 -2
- package/dist/machine.js +273 -54
- package/dist/mcp-supervisor.js +5 -0
- package/dist/mcp.js +33 -6
- package/dist/network.js +258 -57
- package/dist/pending.js +14 -7
- package/dist/quickstart.js +180 -21
- package/dist/refusal.js +29 -0
- package/dist/relay.js +686 -440
- package/dist/roster-file.js +19 -3
- package/dist/run-failure.js +18 -7
- package/dist/service.js +173 -40
- package/dist/setup-guide.js +21 -4
- package/dist/store.js +9 -3
- package/dist/which.js +66 -4
- package/dist/workdir.js +7 -1
- package/dist/worker.js +522 -101
- package/helper/macos/menubar.swift +11 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -7,21 +7,21 @@ process.emitWarning = ((warning, ...rest) => {
|
|
|
7
7
|
return _emitWarning(warning, ...rest);
|
|
8
8
|
});
|
|
9
9
|
import { randomBytes } from "node:crypto";
|
|
10
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
11
|
-
import {
|
|
10
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { dirname, join, resolve } from "node:path";
|
|
12
12
|
import { PantheonClient } from "./client.js";
|
|
13
|
-
import { agentSpawn } from "./which.js";
|
|
14
|
-
import { fromInvite, looksLikeInviteCode, resolveInviteCode, load, save, toInvite, toJoinLink, resolveFor, loadAll, repoInfo, bindRepo, findMembership, setDefaultSpace, removeMembership, configFor, CONFIG_DIR, CONFIG_PATH, DEFAULT_RELAY, resolveForHook } from "./config.js";
|
|
13
|
+
import { agentSpawn, CmdLineUnsafe } from "./which.js";
|
|
14
|
+
import { fromInvite, looksLikeInviteCode, resolveInviteCode, load, save, toInvite, toJoinLink, resolveFor, loadAll, identity, repoInfo, bindRepo, findMembership, setDefaultSpace, removeMembership, configFor, CONFIG_DIR, CONFIG_PATH, DEFAULT_RELAY, resolveForHook } from "./config.js";
|
|
15
15
|
import { fmtLimit } from "./plans.js";
|
|
16
16
|
import { validEmail, validUsername } from "./accounts.js";
|
|
17
|
-
import { install, launcher, installForUser
|
|
17
|
+
import { install, launcher, installForUser } from "./install.js";
|
|
18
18
|
import { Relay } from "./relay.js";
|
|
19
19
|
import { runMcp } from "./mcp.js";
|
|
20
20
|
import { Worker } from "./worker.js";
|
|
21
21
|
import { DEFAULT_REMINDER_MS, ensureNativeNotifier, HumanNotifier, sendDesktopNotification } from "./notifier.js";
|
|
22
22
|
import { desktopUnavailable, hostEnv } from "./host-env.js";
|
|
23
23
|
import { AGENT_SURFACES, applyProfileInit, cleanList, isAgentSurface, loadProfile, organizationProfile, profileInitialized, saveProfile, wakeDefault } from "./profile.js";
|
|
24
|
-
import { runGuide, terminalIO, parseSetupFlags, questionnaire } from "./setup-guide.js";
|
|
24
|
+
import { runGuide, terminalIO, parseSetupFlags, questionnaire, optOutsFrom } from "./setup-guide.js";
|
|
25
25
|
import { selectActs, formatAct, resolveRef } from "./history-view.js";
|
|
26
26
|
import { doctor, render, shareBlock } from "./doctor.js";
|
|
27
27
|
import { FEEDBACK_ADDRESS } from "./feedback.js";
|
|
@@ -30,17 +30,18 @@ import { assess } from "./untrusted.js";
|
|
|
30
30
|
import { report as spendReport, recentRuns } from "./spend.js";
|
|
31
31
|
import { renderBrief, renderTeam } from "./brief.js";
|
|
32
32
|
import { resolveDataDir, saveAll } from "./config.js";
|
|
33
|
-
import { currentPlan, installNetwork, redactProxy, normalizeProxy,
|
|
33
|
+
import { currentPlan, installNetwork, redactProxy, redactText, normalizeProxy, proxyToRemember, describeNetError } from "./network.js";
|
|
34
34
|
import { createInterface } from "node:readline";
|
|
35
35
|
import { homedir } from "node:os";
|
|
36
36
|
import { removeHook, decideStop, writeIntent, clearIntent, readIntent, installHooks, agentHookStates } from "./notify.js";
|
|
37
37
|
import { pending, render as renderPending } from "./pending.js";
|
|
38
|
-
import { start as qsStart, join as qsJoin, wireUp } from "./quickstart.js";
|
|
38
|
+
import { start as qsStart, join as qsJoin, wireUp, teamNameFor } from "./quickstart.js";
|
|
39
39
|
import { installService, uninstallService } from "./service.js";
|
|
40
40
|
import { LIMITS } from "./protocol.js";
|
|
41
41
|
import { loadPersonas, personaByName, describePersona, initPersona, personaDir } from "./persona.js";
|
|
42
42
|
import { fingerprint, newKeypair, signAccount } from "./identity.js";
|
|
43
43
|
import { VERSION } from "./version.js";
|
|
44
|
+
import { connectFailure } from "./refusal.js";
|
|
44
45
|
import * as mcpWindows from "./mcp-windows.js";
|
|
45
46
|
import { updateBanner } from "./update-check.js";
|
|
46
47
|
const argv = process.argv.slice(2);
|
|
@@ -62,7 +63,7 @@ async function signedFetch(cfg, method, path, params = {}) {
|
|
|
62
63
|
return res;
|
|
63
64
|
}
|
|
64
65
|
function requireSignInOnHostedRelay(relayFlag) {
|
|
65
|
-
const cfg =
|
|
66
|
+
const cfg = identity();
|
|
66
67
|
if (cfg?.account)
|
|
67
68
|
return;
|
|
68
69
|
const relay = relayFlag ?? cfg?.relay ?? process.env.PANTHEON_RELAY ?? DEFAULT_RELAY;
|
|
@@ -72,7 +73,7 @@ function requireSignInOnHostedRelay(relayFlag) {
|
|
|
72
73
|
die(`sign in first — this relay verifies email.\n New here: pantheon signup --email you@work.com --username you\n Have an account: pantheon login --email you@work.com\n Then run pantheon start again.`);
|
|
73
74
|
}
|
|
74
75
|
async function interactiveOnboard(relayArg) {
|
|
75
|
-
const prior =
|
|
76
|
+
const prior = identity();
|
|
76
77
|
const relay = relayArg ?? prior?.relay ?? process.env.PANTHEON_RELAY ?? DEFAULT_RELAY;
|
|
77
78
|
const base = relay.replace(/^ws/, "http").replace(/\/+$/, "");
|
|
78
79
|
if (!process.stdin.isTTY) {
|
|
@@ -152,7 +153,7 @@ async function interactiveOnboard(relayArg) {
|
|
|
152
153
|
console.error(D(` could not resend: ${rs?.j.error ?? "the relay did not send an email"} — try again in a minute.`));
|
|
153
154
|
continue;
|
|
154
155
|
}
|
|
155
|
-
const v = await postJson("/auth/verify", { email, code });
|
|
156
|
+
const v = await postJson("/auth/verify", { email, code, pubkey: kp.publicKey });
|
|
156
157
|
if (v.status === 200) {
|
|
157
158
|
const acct = v.j.account;
|
|
158
159
|
const cfg = { ...(prior ?? {}), relay, member: acct.username, space: prior?.space ?? "", token: prior?.token ?? "",
|
|
@@ -252,10 +253,44 @@ function targets() {
|
|
|
252
253
|
const r = resolveFor(process.cwd());
|
|
253
254
|
if (r.cfg && r.cfg.space && r.reason !== "default")
|
|
254
255
|
return [r.cfg];
|
|
255
|
-
if (r.reason === "default" && f)
|
|
256
|
+
if ((r.reason === "default" || r.reason === "unbound") && f && Object.keys(f.spaces ?? {}).length)
|
|
256
257
|
return Object.values(f.spaces ?? {}).map((m) => configFor(f, m, null));
|
|
257
258
|
return [need()];
|
|
258
259
|
}
|
|
260
|
+
async function launchAgent(binary, args, prompt, cwd) {
|
|
261
|
+
const { spawnSync } = await import("node:child_process");
|
|
262
|
+
let sp;
|
|
263
|
+
let handoff = null;
|
|
264
|
+
try {
|
|
265
|
+
sp = agentSpawn(binary, args(prompt));
|
|
266
|
+
}
|
|
267
|
+
catch (e) {
|
|
268
|
+
if (!(e instanceof CmdLineUnsafe))
|
|
269
|
+
throw e;
|
|
270
|
+
const where = cwd ?? process.cwd();
|
|
271
|
+
const rel = join(".pantheon", "handoff", `${Date.now()}-${randomBytes(3).toString("hex")}.md`);
|
|
272
|
+
handoff = join(where, rel);
|
|
273
|
+
mkdirSync(dirname(handoff), { recursive: true });
|
|
274
|
+
writeFileSync(handoff, prompt + "\n");
|
|
275
|
+
try {
|
|
276
|
+
const { excludeRunFiles } = await import("./worker.js");
|
|
277
|
+
excludeRunFiles(where);
|
|
278
|
+
}
|
|
279
|
+
catch { }
|
|
280
|
+
console.error(D(` the question is in ${rel} — the agent is asked to read it`));
|
|
281
|
+
sp = agentSpawn(binary, args(`Read the file ${rel.split(/[\\/]/).join("/")} in this folder and do what it asks.`));
|
|
282
|
+
}
|
|
283
|
+
try {
|
|
284
|
+
spawnSync(sp.command, sp.args, { stdio: "inherit", ...(cwd ? { cwd } : {}), ...sp.options });
|
|
285
|
+
}
|
|
286
|
+
finally {
|
|
287
|
+
if (handoff)
|
|
288
|
+
try {
|
|
289
|
+
rmSync(handoff, { force: true });
|
|
290
|
+
}
|
|
291
|
+
catch { }
|
|
292
|
+
}
|
|
293
|
+
}
|
|
259
294
|
function needStrict() {
|
|
260
295
|
const r = resolveFor(process.cwd(), { strict: true });
|
|
261
296
|
return r.cfg && r.cfg.space ? r.cfg : null;
|
|
@@ -286,7 +321,7 @@ async function guidedSetup(cfg, project, opts = {}) {
|
|
|
286
321
|
const io = rl ? terminalIO(rl, (l) => console.error(l)) : null;
|
|
287
322
|
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)")}`);
|
|
288
323
|
try {
|
|
289
|
-
const r = await runGuide(io, { cfg, project }, {
|
|
324
|
+
const r = await runGuide(io, { cfg, project, optOut: optOutsFrom(argv) }, {
|
|
290
325
|
publish: async (p) => {
|
|
291
326
|
const c = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
292
327
|
try {
|
|
@@ -336,23 +371,27 @@ async function workdirFor(cfg, hud) {
|
|
|
336
371
|
const bindings = all && m ? Object.values(all.bindings ?? {}).filter((b) => b.space === m.id) : [];
|
|
337
372
|
let hints = [];
|
|
338
373
|
if (bindings.length > 1 && hud.goal) {
|
|
339
|
-
const acts = await fetchHistory(cfg).catch(() => []);
|
|
374
|
+
const acts = await fetchHistory(cfg, { goal: hud.goal }).catch(() => []);
|
|
340
375
|
hints = acts.filter((x) => x.goal === hud.goal).flatMap((x) => [x.body, JSON.stringify(x.meta ?? {})]);
|
|
341
376
|
}
|
|
342
377
|
return pickWorkdir(bindings, hints, team);
|
|
343
378
|
}
|
|
344
|
-
async function fetchHistory(cfg,
|
|
379
|
+
async function fetchHistory(cfg, opts = {}) {
|
|
345
380
|
const base = cfg.relay.replace(/^ws/, "http").replace(/\/+$/, "");
|
|
346
|
-
const
|
|
381
|
+
const q = `space=${encodeURIComponent(cfg.space)}&token=${encodeURIComponent(cfg.token)}`
|
|
382
|
+
+ (opts.goal ? `&goal=${encodeURIComponent(opts.goal)}` : opts.since !== undefined ? `&since=${opts.since}` : "");
|
|
383
|
+
const res = await fetch(`${base}/history?${q}`, { signal: AbortSignal.timeout(8000) });
|
|
347
384
|
if (!res.ok)
|
|
348
385
|
throw new Error(`relay answered ${res.status} for the ledger`);
|
|
349
386
|
return (await res.json()).acts ?? [];
|
|
350
387
|
}
|
|
351
|
-
async function fetchAct(cfg, id) {
|
|
388
|
+
async function fetchAct(cfg, id, budgetMs = Number.POSITIVE_INFINITY) {
|
|
352
389
|
const base = cfg.relay.replace(/^ws/, "http").replace(/\/+$/, "");
|
|
353
390
|
const q = `space=${encodeURIComponent(cfg.space)}&token=${encodeURIComponent(cfg.token)}`;
|
|
391
|
+
const deadline = Date.now() + budgetMs;
|
|
392
|
+
const left = () => Math.max(1, Math.min(8000, deadline - Date.now()));
|
|
354
393
|
try {
|
|
355
|
-
const res = await fetch(`${base}/act?${q}&id=${encodeURIComponent(id)}`, { signal: AbortSignal.timeout(
|
|
394
|
+
const res = await fetch(`${base}/act?${q}&id=${encodeURIComponent(id)}`, { signal: AbortSignal.timeout(left()) });
|
|
356
395
|
if (res.ok) {
|
|
357
396
|
const body = await res.json();
|
|
358
397
|
if (body.act)
|
|
@@ -364,7 +403,9 @@ async function fetchAct(cfg, id) {
|
|
|
364
403
|
catch { }
|
|
365
404
|
let head = 0;
|
|
366
405
|
try {
|
|
367
|
-
|
|
406
|
+
if (Date.now() >= deadline)
|
|
407
|
+
return null;
|
|
408
|
+
const h = await (await fetch(`${base}/health?space=${encodeURIComponent(cfg.space)}`, { signal: AbortSignal.timeout(left()) })).json();
|
|
368
409
|
head = h.spaces?.[0]?.seq ?? 0;
|
|
369
410
|
}
|
|
370
411
|
catch { }
|
|
@@ -372,8 +413,10 @@ async function fetchAct(cfg, id) {
|
|
|
372
413
|
if (windows[windows.length - 1] !== 0)
|
|
373
414
|
windows.push(0);
|
|
374
415
|
for (const since of windows) {
|
|
416
|
+
if (Date.now() >= deadline)
|
|
417
|
+
return null;
|
|
375
418
|
try {
|
|
376
|
-
const acts = await fetchHistory(cfg, since);
|
|
419
|
+
const acts = await fetchHistory(cfg, { since });
|
|
377
420
|
const act = acts.find((a) => a.id === id || String(a.seq) === id);
|
|
378
421
|
if (act)
|
|
379
422
|
return { act };
|
|
@@ -551,18 +594,31 @@ ${B("less common")}
|
|
|
551
594
|
pantheon version the pantheon version this machine is running
|
|
552
595
|
`;
|
|
553
596
|
const QUIET = new Set(["mcp", "hook", "pending", "version", "tray-status"]);
|
|
597
|
+
function usageFor(command, help) {
|
|
598
|
+
const plain = help.replace(/\x1b\[[0-9;]*m/g, "").split("\n");
|
|
599
|
+
const out = [];
|
|
600
|
+
const names = new RegExp(`(^\\s+|·\\s+)pantheon ${command.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(\\s|$)`);
|
|
601
|
+
for (let i = 0; i < plain.length; i++) {
|
|
602
|
+
if (!names.test(plain[i]))
|
|
603
|
+
continue;
|
|
604
|
+
out.push(plain[i]);
|
|
605
|
+
while (i + 1 < plain.length && /^\s{20,}\S/.test(plain[i + 1]) && !/^\s+pantheon /.test(plain[i + 1]))
|
|
606
|
+
out.push(plain[++i]);
|
|
607
|
+
}
|
|
608
|
+
return out.length ? out.join("\n") : null;
|
|
609
|
+
}
|
|
610
|
+
const HELP_OPAQUE = new Set(["mcp", "hook", "pending", "tray-status", "help", "version", "-v", "--help", "-h"]);
|
|
554
611
|
function rememberWorkingProxy() {
|
|
555
612
|
try {
|
|
556
|
-
const plan = currentPlan();
|
|
557
|
-
const via = plan.https ?? plan.http;
|
|
558
|
-
if (!via || (plan.source !== "env" && !(plan.fallbackOnly && usedSystemFallback())))
|
|
559
|
-
return;
|
|
560
613
|
const all = loadAll();
|
|
561
|
-
if (!all
|
|
614
|
+
if (!all)
|
|
562
615
|
return;
|
|
563
|
-
const
|
|
564
|
-
|
|
565
|
-
|
|
616
|
+
const latest = Object.values(all.spaces ?? {}).sort((a, b) => (b.joined_at ?? 0) - (a.joined_at ?? 0))[0];
|
|
617
|
+
const keep = proxyToRemember(latest?.relay ?? all.relay, currentPlan(), all.network);
|
|
618
|
+
if (!keep)
|
|
619
|
+
return;
|
|
620
|
+
saveAll({ ...all, network: { ...keep, saved_at: Date.now() } });
|
|
621
|
+
console.error(D(` saved the proxy ${redactProxy(keep.proxy)} for this machine's other Pantheon processes (worker, editors) — change it with pantheon network`));
|
|
566
622
|
}
|
|
567
623
|
catch { }
|
|
568
624
|
}
|
|
@@ -578,19 +634,27 @@ async function main() {
|
|
|
578
634
|
catch { }
|
|
579
635
|
}
|
|
580
636
|
if (argv.length === 0) {
|
|
581
|
-
const cfg =
|
|
637
|
+
const cfg = identity();
|
|
582
638
|
if (cfg?.account) {
|
|
583
639
|
console.error(`${B("pantheon")} — signed in as ${C(cfg.account.username)}. ${D(`Your plate: pantheon brief · all commands: pantheon help`)}`);
|
|
584
640
|
return;
|
|
585
641
|
}
|
|
586
642
|
return interactiveOnboard();
|
|
587
643
|
}
|
|
644
|
+
if (!HELP_OPAQUE.has(cmd)) {
|
|
645
|
+
const helpAt = cmd === "say" ? [argv[1]] : argv.slice(1);
|
|
646
|
+
if (helpAt.some((a) => a === "--help" || a === "-h")) {
|
|
647
|
+
const u = usageFor(cmd, HELP_ALL);
|
|
648
|
+
console.error(u ? `${u}\n\n${D("nothing was run · all commands: pantheon help --all")}` : HELP);
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
588
652
|
switch (cmd) {
|
|
589
653
|
case "network": {
|
|
590
654
|
const all = loadAll() ?? die("not configured — sign up or join a team first");
|
|
591
655
|
const set = flag("proxy");
|
|
592
656
|
if (set !== undefined) {
|
|
593
|
-
const p = normalizeProxy(set) ?? die(`"${set}" is not a proxy address — use http://host:port (add user:password@ if it needs a login)`);
|
|
657
|
+
const p = normalizeProxy(set) ?? die(`"${redactText(set)}" is not a proxy address — use http://host:port (add user:password@ if it needs a login)`);
|
|
594
658
|
saveAll({ ...all, network: { proxy: p, ...(flag("no-proxy") ? { no_proxy: flag("no-proxy") } : {}), source: "pantheon network", saved_at: Date.now() } });
|
|
595
659
|
console.error(`${B("saved")} every Pantheon process on this machine now reaches the relay through ${redactProxy(p)}`);
|
|
596
660
|
return;
|
|
@@ -608,7 +672,7 @@ async function main() {
|
|
|
608
672
|
}
|
|
609
673
|
const plan = currentPlan();
|
|
610
674
|
const via = plan.https ?? plan.http;
|
|
611
|
-
console.log(`${B("network")} ${via ? `through ${redactProxy(via)}` : "direct"}${plan.source !== "none" ? D(` from ${plan.source}${plan.fallbackOnly ? ", used only if a direct connection fails" : ""}`) : ""}`);
|
|
675
|
+
console.log(`${B("network")} ${via ? `through ${redactProxy(via)}` : "direct"}${plan.source !== "none" ? D(` from ${plan.source}${plan.fallbackOnly ? ", used only if a direct connection fails" : plan.retryDirect ? " (saved by start/join; direct is tried if it cannot be reached)" : ""}`) : all.network?.proxy === "" ? D(" saved by pantheon network --direct") : ""}`);
|
|
612
676
|
if (via)
|
|
613
677
|
console.log(D(` not for: ${plan.noProxy.join(", ")}`));
|
|
614
678
|
if (plan.pac)
|
|
@@ -624,7 +688,7 @@ async function main() {
|
|
|
624
688
|
requireSignInOnHostedRelay(flag("relay"));
|
|
625
689
|
console.error(`${B("pantheon start")}\n`);
|
|
626
690
|
if (!flag("space") && !repoInfo(process.cwd()))
|
|
627
|
-
console.error(D(` No git repo here, so the team will be named after this folder: "${
|
|
691
|
+
console.error(D(` No git repo here, so the team will be named after this folder: "${teamNameFor(process.cwd())}". Pass --space <name> to choose.\n`));
|
|
628
692
|
const r = await qsStart({
|
|
629
693
|
port,
|
|
630
694
|
dataDir: resolveDataDir(flag("data")).dir,
|
|
@@ -633,6 +697,7 @@ async function main() {
|
|
|
633
697
|
...(flag("space") ? { space: flag("space") } : {}),
|
|
634
698
|
...(flag("me") ? { me: flag("me") } : {}),
|
|
635
699
|
...(flag("relay") ? { relay: flag("relay") } : {}),
|
|
700
|
+
...(setupFlags.preset.wake ? { wake: setupFlags.preset.wake } : {}),
|
|
636
701
|
hook: !argv.includes("--no-hook"),
|
|
637
702
|
notifications: !argv.includes("--no-notifications"),
|
|
638
703
|
menubar: !argv.includes("--no-menubar"),
|
|
@@ -685,7 +750,7 @@ async function main() {
|
|
|
685
750
|
case "invite": {
|
|
686
751
|
const cfg = need();
|
|
687
752
|
const client = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
688
|
-
await client.connect().catch((e) => die(client.pending ?? e.
|
|
753
|
+
await client.connect().catch((e) => die(client.pending ?? connectFailure(e, cfg.relay)));
|
|
689
754
|
await new Promise((r) => setTimeout(r, 250));
|
|
690
755
|
const revokeAt = argv.indexOf("--revoke");
|
|
691
756
|
const revokeArg = revokeAt >= 0 ? (argv[revokeAt + 1] && !argv[revokeAt + 1].startsWith("--") ? argv[revokeAt + 1] : "all") : undefined;
|
|
@@ -728,6 +793,7 @@ async function main() {
|
|
|
728
793
|
return;
|
|
729
794
|
}
|
|
730
795
|
case "relay": {
|
|
796
|
+
process.on("unhandledRejection", (e) => { console.error(`! unhandled rejection: ${e?.stack ?? String(e)}`); });
|
|
731
797
|
const relay = new Relay({
|
|
732
798
|
port: Number(flag("port", process.env.PORT ?? "8787")),
|
|
733
799
|
host: flag("host", "0.0.0.0"),
|
|
@@ -757,16 +823,18 @@ async function main() {
|
|
|
757
823
|
return;
|
|
758
824
|
}
|
|
759
825
|
case "init": {
|
|
760
|
-
const
|
|
826
|
+
const had = argv.includes("--reset") ? null : identity();
|
|
827
|
+
const kp = had?.publicKey && had.privateKey ? { publicKey: had.publicKey, privateKey: had.privateKey } : newKeypair();
|
|
761
828
|
const cfg = {
|
|
762
829
|
relay: flag("relay", "ws://localhost:8787"),
|
|
763
830
|
space: flag("space", "team"),
|
|
764
831
|
token: flag("token", randomBytes(16).toString("hex")),
|
|
765
|
-
member: flag("me"
|
|
832
|
+
member: flag("me") ?? had?.member ?? process.env.USER ?? "me",
|
|
766
833
|
publicKey: kp.publicKey,
|
|
767
834
|
privateKey: kp.privateKey,
|
|
768
835
|
display: flag("display"),
|
|
769
836
|
agent: flag("agent", "unknown"),
|
|
837
|
+
...(had?.account ? { account: had.account } : {}),
|
|
770
838
|
};
|
|
771
839
|
save(cfg);
|
|
772
840
|
console.error(`${B("space claimed.")} config: ${D(CONFIG_PATH)}\n`);
|
|
@@ -813,7 +881,7 @@ async function main() {
|
|
|
813
881
|
parsed = await resolveInviteCode(invite, candidates).catch((err) => die(err.message.replace(/^INVITE_CODE_[A-Z]+:\s*/, "")));
|
|
814
882
|
console.error(D(`That was just the code — it opens "${parsed.space}" on ${new URL(parsed.relay).host}. Joining that team.\n`));
|
|
815
883
|
}
|
|
816
|
-
if (!
|
|
884
|
+
if (!identity()?.account && sameHost(parsed.relay, DEFAULT_RELAY)) {
|
|
817
885
|
die(`sign in first — this relay verifies email.\n New here: pantheon signup --email you@work.com --username you\n Have an account: pantheon login --email you@work.com\n Then run this same \`pantheon join\` command again — the invite is still good.`);
|
|
818
886
|
}
|
|
819
887
|
const wp = unattendedProject();
|
|
@@ -888,6 +956,22 @@ async function main() {
|
|
|
888
956
|
}
|
|
889
957
|
case "rewire": {
|
|
890
958
|
const rows = installForUser().map((t) => ({ tool: t.tool, status: t.status }));
|
|
959
|
+
try {
|
|
960
|
+
const { refreshServiceDefinition, serviceInstalled: installed, restartService: restart } = await import("./service.js");
|
|
961
|
+
for (const kind of ["worker", "notifier", "menubar"]) {
|
|
962
|
+
if (!installed(kind))
|
|
963
|
+
continue;
|
|
964
|
+
const fresh = refreshServiceDefinition(kind);
|
|
965
|
+
if (fresh.line)
|
|
966
|
+
console.error(fresh.line);
|
|
967
|
+
if (fresh.changed && kind !== "worker")
|
|
968
|
+
for (const l of restart(kind, undefined, { reload: true }))
|
|
969
|
+
console.error(l);
|
|
970
|
+
else if (fresh.changed)
|
|
971
|
+
console.error(D(" worker: the new definition applies at its next restart"));
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
catch { }
|
|
891
975
|
if (argv.includes("--json")) {
|
|
892
976
|
console.log(JSON.stringify(rows));
|
|
893
977
|
return;
|
|
@@ -958,6 +1042,7 @@ async function main() {
|
|
|
958
1042
|
}
|
|
959
1043
|
}
|
|
960
1044
|
}
|
|
1045
|
+
const { refreshServiceDefinition } = await import("./service.js");
|
|
961
1046
|
for (const kind of ["worker", "notifier", "menubar"]) {
|
|
962
1047
|
if (!serviceInstalled(kind))
|
|
963
1048
|
continue;
|
|
@@ -965,7 +1050,10 @@ async function main() {
|
|
|
965
1050
|
console.error(` ${D("worker: a run is in progress — left alone. When it is done:")} pantheon service restart worker`);
|
|
966
1051
|
continue;
|
|
967
1052
|
}
|
|
968
|
-
|
|
1053
|
+
const fresh = refreshServiceDefinition(kind);
|
|
1054
|
+
if (fresh.line)
|
|
1055
|
+
console.error(fresh.line);
|
|
1056
|
+
for (const l of restartService(kind, undefined, { reload: fresh.changed }))
|
|
969
1057
|
console.error(l);
|
|
970
1058
|
}
|
|
971
1059
|
if (r.restart.includes("relay"))
|
|
@@ -1005,7 +1093,7 @@ async function main() {
|
|
|
1005
1093
|
console.error(client.pending);
|
|
1006
1094
|
process.exit(2);
|
|
1007
1095
|
}
|
|
1008
|
-
die(
|
|
1096
|
+
die(connectFailure(e, cfg.relay));
|
|
1009
1097
|
});
|
|
1010
1098
|
await new Promise((r) => setTimeout(r, 350));
|
|
1011
1099
|
const peers = client.roster.filter((m) => m.id !== cfg.member);
|
|
@@ -1073,7 +1161,7 @@ async function main() {
|
|
|
1073
1161
|
for (const cfg of targets()) {
|
|
1074
1162
|
const profile = loadProfile(cfg);
|
|
1075
1163
|
const client = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
1076
|
-
await client.connect().catch((e) => die(client.pending ?? e.
|
|
1164
|
+
await client.connect().catch((e) => die(client.pending ?? connectFailure(e, cfg.relay)));
|
|
1077
1165
|
await new Promise((r) => setTimeout(r, 350));
|
|
1078
1166
|
process.stdout.write(renderBrief({
|
|
1079
1167
|
space: cfg.space,
|
|
@@ -1103,7 +1191,7 @@ async function main() {
|
|
|
1103
1191
|
}
|
|
1104
1192
|
const cfg = need();
|
|
1105
1193
|
const client = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
1106
|
-
await client.connect().catch((e) => die(client.pending ?? e.
|
|
1194
|
+
await client.connect().catch((e) => die(client.pending ?? connectFailure(e, cfg.relay)));
|
|
1107
1195
|
await new Promise((r) => setTimeout(r, 350));
|
|
1108
1196
|
process.stdout.write(renderTeam({
|
|
1109
1197
|
space: cfg.space,
|
|
@@ -1131,7 +1219,7 @@ async function main() {
|
|
|
1131
1219
|
};
|
|
1132
1220
|
const base = cfg.relay.replace(/^ws/, "http").replace(/\/+$/, "");
|
|
1133
1221
|
const q = `space=${encodeURIComponent(cfg.space)}&token=${encodeURIComponent(cfg.token)}`;
|
|
1134
|
-
const first = await fetch(`${base}/history?${q}`).catch((e) => die(
|
|
1222
|
+
const first = await fetch(`${base}/history?${q}`).catch((e) => die(describeNetError(e, cfg.relay)));
|
|
1135
1223
|
if (!first.ok)
|
|
1136
1224
|
die(`relay answered ${first.status} — check the space name and token`);
|
|
1137
1225
|
let since = ((await first.json()).acts ?? []).at(-1)?.seq ?? 0;
|
|
@@ -1160,7 +1248,8 @@ async function main() {
|
|
|
1160
1248
|
}
|
|
1161
1249
|
case "history": {
|
|
1162
1250
|
const cfg = need();
|
|
1163
|
-
const acts = await fetchHistory(cfg,
|
|
1251
|
+
const acts = await fetchHistory(cfg, flag("goal") ? { goal: flag("goal") } : flag("since") ? { since: numFlag("since", 0) } : {})
|
|
1252
|
+
.catch((e) => die(`cannot read the ledger — ${e.message}`));
|
|
1164
1253
|
const picked = selectActs(acts, {
|
|
1165
1254
|
...(flag("goal") ? { goal: flag("goal") } : {}), ...(flag("from") ? { from: flag("from") } : {}),
|
|
1166
1255
|
last: numFlag("last", 20), presence: argv.includes("--presence"),
|
|
@@ -1192,11 +1281,11 @@ async function main() {
|
|
|
1192
1281
|
case "show": {
|
|
1193
1282
|
const cfg = need();
|
|
1194
1283
|
const key = argv[1] ?? die("usage: pantheon show <act id | sequence number>");
|
|
1195
|
-
const
|
|
1196
|
-
const a =
|
|
1197
|
-
console.log(formatAct(a));
|
|
1284
|
+
const found = await fetchAct(cfg, key);
|
|
1285
|
+
const a = found?.act ?? die(`no act ${key} in what the relay still holds (pantheon history lists them)`);
|
|
1286
|
+
console.log(formatAct(a, found?.goalTitle ? { goalTitle: found.goalTitle } : {}));
|
|
1198
1287
|
if (a.ref) {
|
|
1199
|
-
const r =
|
|
1288
|
+
const r = (await fetchAct(cfg, a.ref))?.act;
|
|
1200
1289
|
if (r)
|
|
1201
1290
|
console.log(D(`\nin reply to:\n`) + formatAct(r, { short: true }));
|
|
1202
1291
|
}
|
|
@@ -1211,7 +1300,7 @@ async function main() {
|
|
|
1211
1300
|
die("nothing to say — pantheon say NOTE 'your message here'");
|
|
1212
1301
|
const summary = flag("summary");
|
|
1213
1302
|
const client = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
1214
|
-
await client.connect().catch((e) => die(
|
|
1303
|
+
await client.connect().catch((e) => die(connectFailure(e, cfg.relay)));
|
|
1215
1304
|
const to = flag("to");
|
|
1216
1305
|
const meta = {};
|
|
1217
1306
|
for (const k of ["branch", "commit", "remote"]) {
|
|
@@ -1225,7 +1314,15 @@ async function main() {
|
|
|
1225
1314
|
let goalArg = flag("goal") ?? null;
|
|
1226
1315
|
let ref = flag("ref") ?? null;
|
|
1227
1316
|
if (ref !== null || ["ANSWER", "ACCEPT", "OBJECT"].includes(act)) {
|
|
1228
|
-
|
|
1317
|
+
let acts;
|
|
1318
|
+
if (ref && ref !== "last") {
|
|
1319
|
+
const hit = (await fetchAct(cfg, ref))?.act;
|
|
1320
|
+
acts = hit ? [hit] : [];
|
|
1321
|
+
if (!hit && /^a_/.test(ref))
|
|
1322
|
+
console.error(D(` ${ref} is not in what this relay holds — sending it as given`));
|
|
1323
|
+
}
|
|
1324
|
+
else
|
|
1325
|
+
acts = await fetchHistory(cfg, goalArg ? { goal: goalArg } : {}).catch(() => []);
|
|
1229
1326
|
const rr = resolveRef(acts, ref, act, goalArg, cfg.member);
|
|
1230
1327
|
if (rr.error) {
|
|
1231
1328
|
client.close();
|
|
@@ -1351,23 +1448,17 @@ async function main() {
|
|
|
1351
1448
|
return;
|
|
1352
1449
|
}
|
|
1353
1450
|
case "stop": {
|
|
1354
|
-
const what = (argv[1]
|
|
1451
|
+
const what = (argv[1] && !argv[1].startsWith("--") ? argv[1] : "all").toLowerCase();
|
|
1452
|
+
if (!["all", "relay", "worker", "notifier", "menubar"].includes(what))
|
|
1453
|
+
die(`usage: pantheon stop [relay|worker|notifier|menubar|all]`);
|
|
1454
|
+
const { stopMachine } = await import("./machine.js");
|
|
1355
1455
|
console.log(B("stopping"));
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
if (what === "notifier" || what === "all")
|
|
1363
|
-
for (const l of stopProc("notifier"))
|
|
1364
|
-
console.log(` ${l}`);
|
|
1365
|
-
if (what === "menubar" || what === "all")
|
|
1366
|
-
for (const l of stopProc("menubar"))
|
|
1367
|
-
console.log(` ${l}`);
|
|
1368
|
-
if (what === "relay" || what === "all") {
|
|
1369
|
-
console.log(D(`\n Your teammates are offline until a relay is running again.`));
|
|
1370
|
-
}
|
|
1456
|
+
const everyTeam = Object.values(loadAll()?.spaces ?? {}).map((m) => ({ name: m.name, relay: m.relay }));
|
|
1457
|
+
const res = stopMachine(what, { port: Number(flag("port", "8787")), teams: everyTeam.length ? everyTeam : (load()?.relay ? [{ name: load().space, relay: load().relay }] : []) });
|
|
1458
|
+
for (const l of res.lines)
|
|
1459
|
+
console.log(` ${l}`);
|
|
1460
|
+
if (res.note)
|
|
1461
|
+
console.log(D(`\n ${res.note}`));
|
|
1371
1462
|
return;
|
|
1372
1463
|
}
|
|
1373
1464
|
case "logs": {
|
|
@@ -1375,7 +1466,7 @@ async function main() {
|
|
|
1375
1466
|
const proc = kind === "relay" ? relayProc(Number(flag("port", "8787"))) : kind === "worker" ? workerProc() : notifierProc();
|
|
1376
1467
|
const f = logFileFor(kind, proc);
|
|
1377
1468
|
if (!f)
|
|
1378
|
-
die(`no ${kind} log found. If it runs as a service, the plist names the path; if you started it by hand, its output went to that terminal.`);
|
|
1469
|
+
die(`no ${kind} log found. ${process.platform === "linux" ? `If it runs as a service: journalctl --user -u pantheon-${kind}` : process.platform === "darwin" ? "If it runs as a service, the plist names the path" : "Services are not used on Windows"}; if you started it by hand, its output went to that terminal.`);
|
|
1379
1470
|
console.error(D(`${f} (${statFile(f)})\n`));
|
|
1380
1471
|
const follow = argv.includes("-f") || argv.includes("--follow");
|
|
1381
1472
|
const { spawn } = await import("node:child_process");
|
|
@@ -1664,7 +1755,7 @@ async function main() {
|
|
|
1664
1755
|
if (!argv.includes("--yes"))
|
|
1665
1756
|
die(`this deletes "${m.name}" for everyone in it — its history, goals and invites — and cannot be undone.\n If you mean it: pantheon space delete ${m.name} --yes`);
|
|
1666
1757
|
const client = new PantheonClient(configFor(all, m, null), undefined, { role: "cli" });
|
|
1667
|
-
await client.connect().catch((e) => die(client.pending ?? e.
|
|
1758
|
+
await client.connect().catch((e) => die(client.pending ?? connectFailure(e, m.relay)));
|
|
1668
1759
|
await client.deleteSpace(m.name).catch((e) => { client.close(); die(e.message); });
|
|
1669
1760
|
client.close();
|
|
1670
1761
|
const bound = Object.values(all.bindings ?? {}).filter((b) => b.space === m.id).length;
|
|
@@ -1682,53 +1773,103 @@ async function main() {
|
|
|
1682
1773
|
console.error(D(`Your teammates still list you in "${m.name}". Ask one of them to run: pantheon admit ${m.name === all.member ? "you" : all.member} --revoke if you are not coming back.`));
|
|
1683
1774
|
return;
|
|
1684
1775
|
}
|
|
1685
|
-
const
|
|
1776
|
+
const all = loadAll();
|
|
1777
|
+
const me = identity(all);
|
|
1778
|
+
const { leavePlan } = await import("./machine.js");
|
|
1779
|
+
const plan = leavePlan(all);
|
|
1686
1780
|
const project = resolve(flag("project", "."));
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1781
|
+
const keepIdentity = argv.includes("--keep-identity");
|
|
1782
|
+
if (plan.teams.length > 1 && !keepIdentity && !argv.includes("--yes")) {
|
|
1783
|
+
const list = plan.teams.map((t) => `"${t.name}"`).join(", ");
|
|
1784
|
+
if (!process.stdin.isTTY)
|
|
1785
|
+
die(`this machine is in ${plan.teams.length} teams — ${list}. Leaving removes its key, so it leaves ALL of them.\n If you mean it: pantheon leave --yes\n Just one team: pantheon leave <team>`);
|
|
1786
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
1787
|
+
const answer = await new Promise((res) => rl.question(`This machine is in ${plan.teams.length} teams: ${list}. Leaving removes its key, so it leaves ALL of them. Type "yes" to continue: `, (x) => res(x.trim())));
|
|
1788
|
+
rl.close();
|
|
1789
|
+
if (answer.toLowerCase() !== "yes")
|
|
1790
|
+
die(`nothing was changed. Leave one team with: pantheon leave <team>`);
|
|
1791
|
+
}
|
|
1792
|
+
console.error(`${B("leaving pantheon")}${plan.teams.length ? D(` — ${plan.teams.map((t) => t.name).join(", ")}`) : ""}\n`);
|
|
1793
|
+
const { uninstallMachine, realUninstallIo } = await import("./machine.js");
|
|
1794
|
+
const { removeUserMcpEntries } = await import("./install.js");
|
|
1795
|
+
const done = uninstallMachine({ project, stopRelay: argv.includes("--stop-relay") }, realUninstallIo({
|
|
1796
|
+
port: Number(flag("port", "8787")),
|
|
1797
|
+
removeMcpEntries: () => removeUserMcpEntries({ project }),
|
|
1798
|
+
hasIntent: () => readIntent() !== null,
|
|
1799
|
+
clearIntent: () => clearIntent(),
|
|
1800
|
+
}));
|
|
1801
|
+
for (const l of done.lines)
|
|
1693
1802
|
console.error(` ${l}`);
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
console.error(` ${l}`);
|
|
1697
|
-
else if (relayProc(Number(flag("port", "8787"))).running) {
|
|
1698
|
-
console.error(` relay: left running — others may be using it. Stop it with: pantheon stop relay`);
|
|
1699
|
-
}
|
|
1803
|
+
const removed = [...done.removed];
|
|
1804
|
+
const left = [...done.left];
|
|
1700
1805
|
for (const l of removeHook(project))
|
|
1701
1806
|
console.error(` hook: ${l.trim()}`);
|
|
1702
1807
|
const { revokeToolPermissions } = await import("./grants.js");
|
|
1703
|
-
for (const l of revokeToolPermissions())
|
|
1808
|
+
for (const l of revokeToolPermissions()) {
|
|
1704
1809
|
console.error(` perms:${l}`);
|
|
1705
|
-
|
|
1706
|
-
const l = removeCodexUserScope();
|
|
1707
|
-
if (l)
|
|
1708
|
-
console.error(` perms:${l}`);
|
|
1810
|
+
removed.push(l.trim().replace(/^removed /, ""));
|
|
1709
1811
|
}
|
|
1710
|
-
const { unlinkSync, existsSync: exists, rmSync } = await import("node:fs");
|
|
1711
|
-
if (
|
|
1712
|
-
if (
|
|
1713
|
-
|
|
1812
|
+
const { unlinkSync, existsSync: exists, rmSync, readdirSync } = await import("node:fs");
|
|
1813
|
+
if (all && exists(CONFIG_PATH)) {
|
|
1814
|
+
if (keepIdentity) {
|
|
1815
|
+
left.push(`your identity and ${plan.teams.length} team membership${plan.teams.length === 1 ? "" : "s"}, ${CONFIG_PATH} (--keep-identity)`);
|
|
1714
1816
|
}
|
|
1715
1817
|
else {
|
|
1716
1818
|
unlinkSync(CONFIG_PATH);
|
|
1819
|
+
removed.push(`${CONFIG_PATH} — your key and ${plan.teams.length ? `the token${plan.teams.length === 1 ? "" : "s"} for ${plan.teams.map((t) => `"${t.name}"`).join(", ")}` : "account"}; rejoining means a new invite`);
|
|
1820
|
+
const runHomes = join(CONFIG_PATH, "..", "run-homes");
|
|
1821
|
+
const { restorePendingQuarantines, pendingQuarantines } = await import("./agents.js");
|
|
1822
|
+
const put = restorePendingQuarantines(runHomes);
|
|
1823
|
+
if (put.length)
|
|
1824
|
+
removed.push(`nothing of your repos' — what interrupted runs had held aside: ${put.join("; ")}`);
|
|
1825
|
+
const still = pendingQuarantines(runHomes);
|
|
1826
|
+
const keptAside = (dir) => { try {
|
|
1827
|
+
return readdirSync(join(dir, "quarantine-kept")).length > 0;
|
|
1828
|
+
}
|
|
1829
|
+
catch {
|
|
1830
|
+
return false;
|
|
1831
|
+
} };
|
|
1832
|
+
let homes = [];
|
|
1717
1833
|
try {
|
|
1718
|
-
|
|
1834
|
+
homes = readdirSync(runHomes);
|
|
1719
1835
|
}
|
|
1720
1836
|
catch { }
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1837
|
+
const keep = new Set([...still.map((x) => x.runHome), ...homes.map((h) => join(runHomes, h)).filter(keptAside)]);
|
|
1838
|
+
for (const h of homes) {
|
|
1839
|
+
const dir = join(runHomes, h);
|
|
1840
|
+
if (keep.has(dir))
|
|
1841
|
+
continue;
|
|
1842
|
+
try {
|
|
1843
|
+
rmSync(dir, { recursive: true, force: true });
|
|
1844
|
+
}
|
|
1845
|
+
catch { }
|
|
1846
|
+
}
|
|
1847
|
+
if (!keep.size) {
|
|
1848
|
+
try {
|
|
1849
|
+
rmSync(runHomes, { recursive: true, force: true });
|
|
1850
|
+
}
|
|
1851
|
+
catch { }
|
|
1852
|
+
}
|
|
1853
|
+
for (const x of still)
|
|
1854
|
+
left.push(`${x.runHome} — it still holds ${x.paths.join(", ")} from ${x.worktree}, which could not be put back safely; compare and move them back by hand, then delete the folder`);
|
|
1855
|
+
for (const dir of keep)
|
|
1856
|
+
if (keptAside(dir) && !still.some((x) => x.runHome === dir))
|
|
1857
|
+
left.push(`${join(dir, "quarantine-kept")} — agent config an interrupted run held, set aside because the repo had moved on; check it, then delete the folder`);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
console.error(`\n${B("Removed")}`);
|
|
1861
|
+
for (const r of removed)
|
|
1862
|
+
console.error(` ${C("✓")} ${r}`);
|
|
1863
|
+
if (!removed.length)
|
|
1864
|
+
console.error(` ${D("nothing — Pantheon had nothing installed here")}`);
|
|
1865
|
+
console.error(`\n${B("Left")}`);
|
|
1866
|
+
for (const l of left)
|
|
1867
|
+
console.error(` • ${l}`);
|
|
1868
|
+
console.error(` • ${D("files committed in your repos (.mcp.json, .cursor/mcp.json, .vscode/mcp.json, the brief in AGENTS.md / CLAUDE.md) — your team's; delete them in a commit if the whole team is leaving")}`);
|
|
1869
|
+
console.error(` • ${D("the relay's ledger on disk, and anything you pushed to git")}`);
|
|
1870
|
+
if (plan.teams.length) {
|
|
1871
|
+
console.error(`\n ${D(`Your teammates still list you in ${plan.teams.map((t) => `"${t.name}"`).join(", ")}. Ask someone in each to run:`)}`);
|
|
1872
|
+
console.error(` ${D(`pantheon admit ${me?.member ?? plan.member ?? "<your name>"} --revoke`)}`);
|
|
1732
1873
|
}
|
|
1733
1874
|
console.error(`\n ${D(`If Pantheon let you down, one line on why to ${FEEDBACK_ADDRESS} would help more than you might think.`)}`);
|
|
1734
1875
|
return;
|
|
@@ -1741,35 +1882,42 @@ async function main() {
|
|
|
1741
1882
|
return;
|
|
1742
1883
|
}
|
|
1743
1884
|
case "panic": {
|
|
1744
|
-
const cfg = need();
|
|
1745
1885
|
console.error(`${B("PANIC — locking down this machine")}\n`);
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
const
|
|
1749
|
-
const
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1886
|
+
const { panicMachine, waitStopped } = await import("./machine.js");
|
|
1887
|
+
const all = loadAll();
|
|
1888
|
+
const teams = Object.values(all?.spaces ?? {});
|
|
1889
|
+
const r = await panicMachine({
|
|
1890
|
+
stopWorker: () => stopProc("worker"),
|
|
1891
|
+
workerDown: () => waitStopped("worker", 5000),
|
|
1892
|
+
teams,
|
|
1893
|
+
revoke: async (m) => {
|
|
1894
|
+
const cfg = configFor(all, m, null);
|
|
1895
|
+
const client = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
1896
|
+
try {
|
|
1897
|
+
await client.connect();
|
|
1898
|
+
await new Promise((res) => setTimeout(res, 300));
|
|
1899
|
+
const wakers = client.members.filter((x) => x.admitted && x.may_wake && x.member !== cfg.member);
|
|
1900
|
+
for (const w of wakers)
|
|
1901
|
+
await client.admit(w.member, false, false).catch(() => { });
|
|
1902
|
+
return wakers.map((w) => w.member);
|
|
1903
|
+
}
|
|
1904
|
+
finally {
|
|
1905
|
+
client.close();
|
|
1906
|
+
}
|
|
1907
|
+
},
|
|
1908
|
+
});
|
|
1909
|
+
for (const l of r.lines)
|
|
1910
|
+
console.error(l);
|
|
1765
1911
|
console.error(D(` Your peers can still message you; only unattended runs are off.`));
|
|
1766
1912
|
console.error(D(` To undo: pantheon service install worker and pantheon admit <who> --may-wake`));
|
|
1913
|
+
if (!r.ok)
|
|
1914
|
+
process.exitCode = 1;
|
|
1767
1915
|
return;
|
|
1768
1916
|
}
|
|
1769
1917
|
case "members": {
|
|
1770
1918
|
const cfg = need();
|
|
1771
1919
|
const client = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
1772
|
-
await client.connect().catch((e) => die(client.pending ?? e.
|
|
1920
|
+
await client.connect().catch((e) => die(client.pending ?? connectFailure(e, cfg.relay)));
|
|
1773
1921
|
await new Promise((r) => setTimeout(r, 300));
|
|
1774
1922
|
console.log(`${B(`who is in ${cfg.space}`)}\n`);
|
|
1775
1923
|
for (const e of client.members) {
|
|
@@ -1790,7 +1938,7 @@ async function main() {
|
|
|
1790
1938
|
const cfg = need();
|
|
1791
1939
|
const who = argv[1] ?? die("usage: pantheon admit <member> [--may-wake] [--revoke] [--forget]");
|
|
1792
1940
|
const client = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
1793
|
-
await client.connect().catch((e) => die(client.pending ?? e.
|
|
1941
|
+
await client.connect().catch((e) => die(client.pending ?? connectFailure(e, cfg.relay)));
|
|
1794
1942
|
await new Promise((r) => setTimeout(r, 250));
|
|
1795
1943
|
const forget = argv.includes("--forget");
|
|
1796
1944
|
const revoke = argv.includes("--revoke");
|
|
@@ -1837,16 +1985,21 @@ async function main() {
|
|
|
1837
1985
|
return;
|
|
1838
1986
|
}
|
|
1839
1987
|
case "whoami": {
|
|
1840
|
-
const cfg =
|
|
1988
|
+
const cfg = identity() ?? die("not set up on this machine — pantheon signup, or pantheon join <invite>");
|
|
1989
|
+
const team = resolveFor(process.cwd()).cfg;
|
|
1841
1990
|
if (cfg.account) {
|
|
1842
1991
|
console.log(`account ${C(cfg.account.username)} ${D(`<${cfg.account.email}>`)} ${D("verified")}`);
|
|
1843
1992
|
}
|
|
1993
|
+
else if (cfg.pendingAuth) {
|
|
1994
|
+
console.log(`account ${D(`not signed in yet — a code was sent to ${cfg.pendingAuth.email}: pantheon verify <code>`)}`);
|
|
1995
|
+
}
|
|
1844
1996
|
else {
|
|
1845
1997
|
console.log(`account ${D("not signed in")} ${D("— pantheon signup / pantheon login")}`);
|
|
1846
1998
|
}
|
|
1847
1999
|
console.log(`member ${C(cfg.member)}`);
|
|
1848
|
-
|
|
1849
|
-
console.log(`
|
|
2000
|
+
const teams = Object.values(loadAll()?.spaces ?? {}).map((m) => m.name);
|
|
2001
|
+
console.log(`space ${team?.space || (teams.length ? D(`none picked here — you are in ${teams.join(", ")}`) : D("none yet — pantheon start, or pantheon join <invite>"))}`);
|
|
2002
|
+
console.log(`relay ${team?.space ? team.relay : cfg.relay}`);
|
|
1850
2003
|
console.log(`this device ${C(fingerprint(cfg.publicKey))}`);
|
|
1851
2004
|
console.log(D(`\nManage your devices and sessions: pantheon sessions`));
|
|
1852
2005
|
return;
|
|
@@ -1858,7 +2011,7 @@ async function main() {
|
|
|
1858
2011
|
return interactiveOnboard(flag("relay"));
|
|
1859
2012
|
const email = flag("email") ?? die(`usage: pantheon ${purpose} --email you@work.com${purpose === "signup" ? " --username <name>" : ""} [--relay wss://...]`);
|
|
1860
2013
|
const username = purpose === "signup" ? (flag("username") ?? die("usage: pantheon signup --email you@work.com --username <name>")) : undefined;
|
|
1861
|
-
const prior =
|
|
2014
|
+
const prior = identity();
|
|
1862
2015
|
const relay = flag("relay") ?? prior?.relay ?? process.env.PANTHEON_RELAY ?? DEFAULT_RELAY;
|
|
1863
2016
|
const kp = prior?.publicKey && prior.privateKey ? { publicKey: prior.publicKey, privateKey: prior.privateKey } : newKeypair();
|
|
1864
2017
|
const label = flag("label") ?? `${process.env.USER ?? "a"}'s ${process.platform === "darwin" ? "mac" : process.platform}`;
|
|
@@ -1866,7 +2019,7 @@ async function main() {
|
|
|
1866
2019
|
const body = purpose === "signup" ? { email, username, pubkey: kp.publicKey, label } : { email, pubkey: kp.publicKey, label };
|
|
1867
2020
|
const r = await fetch(`${base}/auth/${purpose}`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) })
|
|
1868
2021
|
.then(async (x) => ({ status: x.status, j: await x.json() }))
|
|
1869
|
-
.catch((e) => die(
|
|
2022
|
+
.catch((e) => die(describeNetError(e, relay)));
|
|
1870
2023
|
if (r.status !== 200)
|
|
1871
2024
|
die(String(r.j.error ?? `signup failed (${r.status})`));
|
|
1872
2025
|
save({ ...(prior ?? {}), relay, member: username ?? prior?.member ?? "me", space: prior?.space ?? "", token: prior?.token ?? "",
|
|
@@ -1883,7 +2036,7 @@ async function main() {
|
|
|
1883
2036
|
return;
|
|
1884
2037
|
}
|
|
1885
2038
|
case "verify": {
|
|
1886
|
-
const cfg =
|
|
2039
|
+
const cfg = identity() ?? die("run `pantheon signup` or `pantheon login` first");
|
|
1887
2040
|
const pending = cfg.pendingAuth ?? die("nothing to verify — run `pantheon signup` or `pantheon login` first");
|
|
1888
2041
|
let code = (argv[1] ?? flag("code") ?? "").trim();
|
|
1889
2042
|
if (!code && process.stdin.isTTY) {
|
|
@@ -1894,9 +2047,9 @@ async function main() {
|
|
|
1894
2047
|
if (!code)
|
|
1895
2048
|
die("usage: pantheon verify <6-digit-code>");
|
|
1896
2049
|
const base = cfg.relay.replace(/^ws/, "http").replace(/\/+$/, "");
|
|
1897
|
-
const r = await fetch(`${base}/auth/verify`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ email: pending.email, code }) })
|
|
2050
|
+
const r = await fetch(`${base}/auth/verify`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ email: pending.email, code, pubkey: cfg.publicKey }) })
|
|
1898
2051
|
.then(async (x) => ({ status: x.status, j: await x.json() }))
|
|
1899
|
-
.catch((e) => die(
|
|
2052
|
+
.catch((e) => die(describeNetError(e, cfg.relay)));
|
|
1900
2053
|
if (r.status !== 200)
|
|
1901
2054
|
die(String(r.j.error ?? "verification failed"));
|
|
1902
2055
|
const acct = r.j.account;
|
|
@@ -1910,7 +2063,7 @@ async function main() {
|
|
|
1910
2063
|
return;
|
|
1911
2064
|
}
|
|
1912
2065
|
case "sessions": {
|
|
1913
|
-
const cfg =
|
|
2066
|
+
const cfg = identity() ?? die("not set up on this machine — pantheon signup first");
|
|
1914
2067
|
if (!cfg.account)
|
|
1915
2068
|
die("not signed in — run `pantheon signup` or `pantheon login` first");
|
|
1916
2069
|
const sub = argv[1];
|
|
@@ -1922,7 +2075,7 @@ async function main() {
|
|
|
1922
2075
|
const me = await signedFetch(cfg, "GET", "/account/sessions").then((x) => x.json()).catch(() => ({}));
|
|
1923
2076
|
thisDevice = me.this_device ?? "";
|
|
1924
2077
|
}
|
|
1925
|
-
const r = await signedFetch(cfg, "POST", "/account/revoke", { kind, id }).then((x) => x.json()).catch((e) => die(e.
|
|
2078
|
+
const r = await signedFetch(cfg, "POST", "/account/revoke", { kind, id }).then((x) => x.json()).catch((e) => die(describeNetError(e, cfg.relay)));
|
|
1926
2079
|
if (kind === "device" && id === thisDevice) {
|
|
1927
2080
|
const cl = { ...cfg };
|
|
1928
2081
|
delete cl.account;
|
|
@@ -1931,7 +2084,7 @@ async function main() {
|
|
|
1931
2084
|
console.error(`${C("revoked")} — ${r.revoked ?? 0} session(s)${r.device_removed ? ", device removed" : ""}${kind === "device" && id === thisDevice ? " (this device — you are now signed out)" : ""}`);
|
|
1932
2085
|
return;
|
|
1933
2086
|
}
|
|
1934
|
-
const r = await signedFetch(cfg, "GET", "/account/sessions").then((x) => x.json()).catch((e) => die(e.
|
|
2087
|
+
const r = await signedFetch(cfg, "GET", "/account/sessions").then((x) => x.json()).catch((e) => die(describeNetError(e, cfg.relay)));
|
|
1935
2088
|
console.log(`${B(r.account.username)} ${D(`<${r.account.email}>`)}\n`);
|
|
1936
2089
|
console.log(B("devices"));
|
|
1937
2090
|
for (const d of r.devices)
|
|
@@ -1946,12 +2099,12 @@ async function main() {
|
|
|
1946
2099
|
return;
|
|
1947
2100
|
}
|
|
1948
2101
|
case "audit": {
|
|
1949
|
-
const cfg =
|
|
2102
|
+
const cfg = identity() ?? die("not set up on this machine — pantheon signup first");
|
|
1950
2103
|
if (!cfg.account)
|
|
1951
2104
|
die("not signed in — run `pantheon signup` first");
|
|
1952
2105
|
const space = flag("space");
|
|
1953
2106
|
const since = flag("since") ? String(Date.now() - Number(flag("since")) * 3_600_000) : undefined;
|
|
1954
|
-
const r = await signedFetch(cfg, "GET", "/audit", { ...(space ? { space } : {}), ...(since ? { since } : {}) }).then((x) => x.json()).catch((e) => die(e.
|
|
2107
|
+
const r = await signedFetch(cfg, "GET", "/audit", { ...(space ? { space } : {}), ...(since ? { since } : {}) }).then((x) => x.json()).catch((e) => die(describeNetError(e, cfg.relay)));
|
|
1955
2108
|
if (r.error)
|
|
1956
2109
|
die(r.error);
|
|
1957
2110
|
if (argv.includes("--json")) {
|
|
@@ -1966,22 +2119,34 @@ async function main() {
|
|
|
1966
2119
|
return;
|
|
1967
2120
|
}
|
|
1968
2121
|
case "logout": {
|
|
1969
|
-
const cfg =
|
|
2122
|
+
const cfg = identity() ?? die("not set up on this machine — pantheon signup first");
|
|
1970
2123
|
if (!cfg.account) {
|
|
1971
2124
|
console.error(D("not signed in — nothing to log out"));
|
|
1972
2125
|
return;
|
|
1973
2126
|
}
|
|
1974
|
-
const list = await signedFetch(cfg, "GET", "/account/sessions").then((x) => x.json()
|
|
1975
|
-
|
|
1976
|
-
|
|
2127
|
+
const list = await signedFetch(cfg, "GET", "/account/sessions").then(async (x) => ({ ok: x.ok, status: x.status, j: await x.json().catch(() => ({})) }))
|
|
2128
|
+
.catch((e) => die(describeNetError(e, cfg.relay)));
|
|
2129
|
+
if (!list.ok && list.status !== 403)
|
|
2130
|
+
die(`the relay did not sign this device out (${list.j.error ?? list.status}) — nothing changed. Try again, or remove it from another device: pantheon sessions`);
|
|
2131
|
+
let revoked = list.status === 403;
|
|
2132
|
+
if (list.ok && list.j.this_device) {
|
|
2133
|
+
const r = await signedFetch(cfg, "POST", "/account/revoke", { kind: "device", id: list.j.this_device })
|
|
2134
|
+
.then(async (x) => ({ ok: x.ok, j: await x.json().catch(() => ({})) }))
|
|
2135
|
+
.catch((e) => die(describeNetError(e, cfg.relay)));
|
|
2136
|
+
if (!r.ok)
|
|
2137
|
+
die(`the relay did not sign this device out (${r.j.error ?? "refused"}) — nothing changed. Try again, or remove it from another device: pantheon sessions`);
|
|
2138
|
+
revoked = true;
|
|
2139
|
+
}
|
|
2140
|
+
else if (list.ok)
|
|
2141
|
+
revoked = true;
|
|
1977
2142
|
const cleared = { ...cfg };
|
|
1978
2143
|
delete cleared.account;
|
|
1979
2144
|
save(cleared);
|
|
1980
|
-
console.error(`${C("logged out")} — this device is signed out. Sign back in with ${C("pantheon login --email " + cfg.account.email)}.`);
|
|
2145
|
+
console.error(`${C("logged out")} — ${revoked ? "this device is signed out" : "signed out here"}. Sign back in with ${C("pantheon login --email " + cfg.account.email)}.`);
|
|
1981
2146
|
return;
|
|
1982
2147
|
}
|
|
1983
2148
|
case "account": {
|
|
1984
|
-
const cfg =
|
|
2149
|
+
const cfg = identity() ?? die("not set up on this machine — pantheon signup first");
|
|
1985
2150
|
if (!cfg.account)
|
|
1986
2151
|
die("not signed in");
|
|
1987
2152
|
const sub = argv[1];
|
|
@@ -1989,7 +2154,7 @@ async function main() {
|
|
|
1989
2154
|
die("usage: pantheon account delete");
|
|
1990
2155
|
if (!argv.includes("--yes"))
|
|
1991
2156
|
die(`This permanently deletes your account (${cfg.account.username} <${cfg.account.email}>), all your devices, and all your sessions. Re-run with --yes to confirm.`);
|
|
1992
|
-
const r = await signedFetch(cfg, "POST", "/account/delete").then((x) => x.json()).catch((e) => die(e.
|
|
2157
|
+
const r = await signedFetch(cfg, "POST", "/account/delete").then((x) => x.json()).catch((e) => die(describeNetError(e, cfg.relay)));
|
|
1993
2158
|
if (!r.ok)
|
|
1994
2159
|
die(String(r.error ?? "delete failed"));
|
|
1995
2160
|
const cleared = { ...cfg };
|
|
@@ -2179,7 +2344,7 @@ async function main() {
|
|
|
2179
2344
|
if (overlap)
|
|
2180
2345
|
die("an overlapping delegation already exists for one of these domains; remove it first");
|
|
2181
2346
|
const client = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
2182
|
-
await client.connect().catch((e) => die(e.
|
|
2347
|
+
await client.connect().catch((e) => die(connectFailure(e, cfg.relay)));
|
|
2183
2348
|
if (!client.profiles.has(to)) {
|
|
2184
2349
|
client.close();
|
|
2185
2350
|
die(`${to} has no published profile; delegation would have nowhere verifiable to land`);
|
|
@@ -2221,7 +2386,7 @@ async function main() {
|
|
|
2221
2386
|
case "directory": {
|
|
2222
2387
|
const cfg = need();
|
|
2223
2388
|
const client = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
2224
|
-
await client.connect().catch((e) => die(e.
|
|
2389
|
+
await client.connect().catch((e) => die(connectFailure(e, cfg.relay)));
|
|
2225
2390
|
if (!client.profiles.size)
|
|
2226
2391
|
console.log(`${D("no organization profiles published yet")}`);
|
|
2227
2392
|
for (const p of client.profiles.values()) {
|
|
@@ -2278,12 +2443,41 @@ async function main() {
|
|
|
2278
2443
|
return;
|
|
2279
2444
|
}
|
|
2280
2445
|
case "explain": {
|
|
2281
|
-
const cfg = need();
|
|
2282
2446
|
const { readFileSync, rmSync } = await import("node:fs");
|
|
2447
|
+
const CONFIG_DIR = dirname(CONFIG_PATH);
|
|
2448
|
+
let hud = null;
|
|
2449
|
+
if (argv.includes("--queued")) {
|
|
2450
|
+
const f = join(CONFIG_DIR, "bin", ".hud-action.json");
|
|
2451
|
+
try {
|
|
2452
|
+
hud = JSON.parse(readFileSync(f, "utf8"));
|
|
2453
|
+
rmSync(f, { force: true });
|
|
2454
|
+
}
|
|
2455
|
+
catch {
|
|
2456
|
+
hud = null;
|
|
2457
|
+
}
|
|
2458
|
+
}
|
|
2459
|
+
const cfg = (() => {
|
|
2460
|
+
if (!hud?.space)
|
|
2461
|
+
return need();
|
|
2462
|
+
const f = loadAll();
|
|
2463
|
+
const m = f ? findMembership(f, hud.space) : undefined;
|
|
2464
|
+
if (f && m)
|
|
2465
|
+
return configFor(f, m, null);
|
|
2466
|
+
const here = resolveFor(process.cwd()).cfg;
|
|
2467
|
+
if (here?.space === hud.space)
|
|
2468
|
+
return here;
|
|
2469
|
+
const why = `this machine is no longer in the team "${hud.space}"`;
|
|
2470
|
+
if (hud.action === "reply" || hud.action === "retract") {
|
|
2471
|
+
console.log(`not sent: ${why}`);
|
|
2472
|
+
process.exit(1);
|
|
2473
|
+
}
|
|
2474
|
+
return die(why);
|
|
2475
|
+
})();
|
|
2476
|
+
if (hud && hud.goal === "")
|
|
2477
|
+
delete hud.goal;
|
|
2283
2478
|
const { pickExplainAgent, decisionPrompt: dp, allDecisionsPrompt: adp, decisionTitle: dt, sessionName } = await import("./decision-ui.js");
|
|
2284
2479
|
const { loadProfile } = await import("./profile.js");
|
|
2285
2480
|
const { detectAvailable, launchArgs } = await import("./agents.js");
|
|
2286
|
-
const CONFIG_DIR = dirname(CONFIG_PATH);
|
|
2287
2481
|
let id = argv.find((a, i) => i > 0 && !a.startsWith("--"));
|
|
2288
2482
|
if (argv.includes("--queued")) {
|
|
2289
2483
|
const queued = join(CONFIG_DIR, "bin", ".explain-id");
|
|
@@ -2295,17 +2489,6 @@ async function main() {
|
|
|
2295
2489
|
if (id === "all")
|
|
2296
2490
|
id = undefined;
|
|
2297
2491
|
}
|
|
2298
|
-
let hud = null;
|
|
2299
|
-
if (argv.includes("--queued")) {
|
|
2300
|
-
const f = join(CONFIG_DIR, "bin", ".hud-action.json");
|
|
2301
|
-
try {
|
|
2302
|
-
hud = JSON.parse(readFileSync(f, "utf8"));
|
|
2303
|
-
rmSync(f, { force: true });
|
|
2304
|
-
}
|
|
2305
|
-
catch {
|
|
2306
|
-
hud = null;
|
|
2307
|
-
}
|
|
2308
|
-
}
|
|
2309
2492
|
if (hud?.action === "fix") {
|
|
2310
2493
|
const dir = hud.dir && existsSync(hud.dir) ? hud.dir : process.cwd();
|
|
2311
2494
|
const steps = hud.lines ?? [];
|
|
@@ -2353,22 +2536,31 @@ async function main() {
|
|
|
2353
2536
|
if (!body)
|
|
2354
2537
|
notSent("nothing to send");
|
|
2355
2538
|
const c2 = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
2356
|
-
await c2.connect().catch((e) => notSent(e.
|
|
2539
|
+
await c2.connect().catch((e) => notSent(connectFailure(e, cfg.relay)));
|
|
2357
2540
|
const o = hud.decision ? c2.obligations.find((x) => x.id === hud.decision) : undefined;
|
|
2358
|
-
const
|
|
2359
|
-
const target =
|
|
2360
|
-
|
|
2541
|
+
const targetId = o?.ref ?? hud.act;
|
|
2542
|
+
const target = targetId ? (await fetchAct(cfg, targetId, 8_000))?.act : undefined;
|
|
2543
|
+
let goal = o?.goal ?? target?.goal ?? hud.goal ?? null;
|
|
2361
2544
|
if (kind === "ANSWER" && !o && !target) {
|
|
2362
2545
|
c2.close();
|
|
2363
2546
|
notSent("that decision is no longer waiting — nothing to answer");
|
|
2364
2547
|
}
|
|
2548
|
+
if (goal && c2.goals.get(goal)?.state === "CLOSED") {
|
|
2549
|
+
if (kind === "ASK") {
|
|
2550
|
+
c2.close();
|
|
2551
|
+
notSent("that goal is closed — open a new one to ask more");
|
|
2552
|
+
}
|
|
2553
|
+
goal = null;
|
|
2554
|
+
}
|
|
2365
2555
|
const ref = kind === "ANSWER" ? (o?.ref ?? target?.id ?? null) : kind === "ASK" ? (target?.id ?? null) : null;
|
|
2366
2556
|
const to = kind === "ASK" ? (target && target.from !== cfg.member ? [target.from] : null) : null;
|
|
2367
2557
|
if (kind === "ASK" && !to) {
|
|
2368
2558
|
c2.close();
|
|
2369
2559
|
notSent("cannot tell who raised this — use Show the thread and reply from there");
|
|
2370
2560
|
}
|
|
2371
|
-
const
|
|
2561
|
+
const summary = body.length > LIMITS.summaryRequiredOver
|
|
2562
|
+
? (body.split(/\n|(?<=[.!?])\s/)[0] ?? body).trim().slice(0, LIMITS.summaryChars) : undefined;
|
|
2563
|
+
const sent = await c2.send({ act: kind, body, goal, ref, to, after_seq: c2.readSeq, meta: { surface: "menubar" }, ...(summary ? { summary } : {}) })
|
|
2372
2564
|
.catch((e) => notSent(e.message));
|
|
2373
2565
|
c2.close();
|
|
2374
2566
|
console.log(`sent ${kind} id=${sent.id} seq=${sent.seq}`);
|
|
@@ -2379,7 +2571,7 @@ async function main() {
|
|
|
2379
2571
|
if (!hud.act)
|
|
2380
2572
|
notSent("nothing to retract");
|
|
2381
2573
|
const c2 = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
2382
|
-
await c2.connect().catch((e) => notSent(e.
|
|
2574
|
+
await c2.connect().catch((e) => notSent(connectFailure(e, cfg.relay)));
|
|
2383
2575
|
const sent = await c2.send({ act: "RETRACT", body: "Retracted from the menu bar.", goal: null, ref: hud.act, to: null, meta: { surface: "menubar" } })
|
|
2384
2576
|
.catch((e) => notSent(e.message));
|
|
2385
2577
|
c2.close();
|
|
@@ -2388,14 +2580,15 @@ async function main() {
|
|
|
2388
2580
|
}
|
|
2389
2581
|
if (hud?.action === "done") {
|
|
2390
2582
|
const c2 = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
2391
|
-
await c2.connect().catch((e) => die(e.
|
|
2583
|
+
await c2.connect().catch((e) => die(connectFailure(e, cfg.relay)));
|
|
2392
2584
|
const o = hud.decision ? c2.obligations.find((x) => x.id === hud.decision) : undefined;
|
|
2393
2585
|
if (!o) {
|
|
2394
2586
|
c2.close();
|
|
2395
2587
|
console.error(D("that decision is no longer waiting on you"));
|
|
2396
2588
|
return;
|
|
2397
2589
|
}
|
|
2398
|
-
|
|
2590
|
+
const open = o.goal && c2.goals.get(o.goal)?.state !== "CLOSED" ? o.goal : null;
|
|
2591
|
+
await c2.send({ act: "ANSWER", ref: o.ref, goal: open, after_seq: c2.readSeq,
|
|
2399
2592
|
body: "Marked done from the alert — handled outside this thread." }).catch((e) => die(e.message));
|
|
2400
2593
|
c2.close();
|
|
2401
2594
|
console.error(D(`done — ${o.id} is no longer waiting on you`));
|
|
@@ -2411,19 +2604,18 @@ async function main() {
|
|
|
2411
2604
|
}
|
|
2412
2605
|
if (wd)
|
|
2413
2606
|
console.error(D(` ${wd.note}`));
|
|
2414
|
-
const
|
|
2415
|
-
const a = hud.act ? acts.find((x) => x.id === hud.act) : undefined;
|
|
2607
|
+
const a = hud.act ? (await fetchAct(cfg, hud.act))?.act : undefined;
|
|
2416
2608
|
let o;
|
|
2417
2609
|
if (hud.decision) {
|
|
2418
2610
|
const c2 = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
2419
|
-
await c2.connect().catch((e) => die(e.
|
|
2611
|
+
await c2.connect().catch((e) => die(connectFailure(e, cfg.relay)));
|
|
2420
2612
|
o = c2.obligations.find((x) => x.id === hud.decision);
|
|
2421
2613
|
c2.close();
|
|
2422
2614
|
}
|
|
2423
2615
|
if (a) {
|
|
2424
2616
|
console.log(formatAct(a));
|
|
2425
2617
|
if (a.ref) {
|
|
2426
|
-
const r =
|
|
2618
|
+
const r = (await fetchAct(cfg, a.ref))?.act;
|
|
2427
2619
|
if (r)
|
|
2428
2620
|
console.log(D("\nin reply to:\n") + formatAct(r, { short: true }));
|
|
2429
2621
|
}
|
|
@@ -2451,11 +2643,7 @@ async function main() {
|
|
|
2451
2643
|
rl.close();
|
|
2452
2644
|
const prompt = o ? dp(o.id, dt(o.body)) : `Read Pantheon act ${a.id}${goalId ? ` and the thread of goal ${goalId}` : ""}. Explain in plain words what happened and whether anything is owed by me, then give me numbered next steps. Do not act until I choose.`;
|
|
2453
2645
|
console.error(D(`opening ${agent.id}…`));
|
|
2454
|
-
|
|
2455
|
-
{
|
|
2456
|
-
const sp = agentSpawn(agent.binary, launchArgs(agent.id, prompt, sessionName(prompt)));
|
|
2457
|
-
spawnSync(sp.command, sp.args, { stdio: "inherit", ...sp.options });
|
|
2458
|
-
}
|
|
2646
|
+
await launchAgent(agent.binary, (p) => launchArgs(agent.id, p, sessionName(prompt)), prompt);
|
|
2459
2647
|
return;
|
|
2460
2648
|
}
|
|
2461
2649
|
if (choice === "2") {
|
|
@@ -2496,7 +2684,8 @@ async function main() {
|
|
|
2496
2684
|
continue;
|
|
2497
2685
|
}
|
|
2498
2686
|
if (choice === "3" && goalId) {
|
|
2499
|
-
|
|
2687
|
+
const thread = await fetchHistory(cfg, { goal: goalId }).catch(() => []);
|
|
2688
|
+
for (const t of selectActs(thread, { goal: goalId, last: 40 }))
|
|
2500
2689
|
console.log(formatAct(t, { short: true }));
|
|
2501
2690
|
continue;
|
|
2502
2691
|
}
|
|
@@ -2523,10 +2712,7 @@ async function main() {
|
|
|
2523
2712
|
const bin = cliOnPath("grok") ?? die("grok is not on PATH here");
|
|
2524
2713
|
console.error(D("opening grok…"));
|
|
2525
2714
|
const { spawnSync } = await import("node:child_process");
|
|
2526
|
-
|
|
2527
|
-
const sp = agentSpawn(bin, [hud.prompt]);
|
|
2528
|
-
spawnSync(sp.command, sp.args, { stdio: "inherit", ...(cwd ? { cwd } : {}), ...sp.options });
|
|
2529
|
-
}
|
|
2715
|
+
await launchAgent(bin, (p) => [p], hud.prompt, cwd ?? undefined);
|
|
2530
2716
|
return;
|
|
2531
2717
|
}
|
|
2532
2718
|
if (hud.prompt) {
|
|
@@ -2535,10 +2721,7 @@ async function main() {
|
|
|
2535
2721
|
die("no agent CLI found on this machine (claude, cursor-agent, codex, copilot, or kiro-cli)");
|
|
2536
2722
|
console.error(D(`opening ${agent.id}…`));
|
|
2537
2723
|
const { spawnSync } = await import("node:child_process");
|
|
2538
|
-
|
|
2539
|
-
const sp = agentSpawn(agent.binary, launchArgs(agent.id, hud.prompt, sessionName(hud.prompt)));
|
|
2540
|
-
spawnSync(sp.command, sp.args, { stdio: "inherit", ...(cwd ? { cwd } : {}), ...sp.options });
|
|
2541
|
-
}
|
|
2724
|
+
await launchAgent(agent.binary, (p) => launchArgs(agent.id, p, sessionName(hud.prompt)), hud.prompt, cwd ?? undefined);
|
|
2542
2725
|
return;
|
|
2543
2726
|
}
|
|
2544
2727
|
if (hud.decision)
|
|
@@ -2551,7 +2734,7 @@ async function main() {
|
|
|
2551
2734
|
}
|
|
2552
2735
|
}
|
|
2553
2736
|
const client = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
2554
|
-
await client.connect().catch((e) => die(e.
|
|
2737
|
+
await client.connect().catch((e) => die(connectFailure(e, cfg.relay)));
|
|
2555
2738
|
const waiting = client.obligations.filter((o) => o.kind === "HUMAN" && o.owner === `human:${cfg.member}`);
|
|
2556
2739
|
client.close();
|
|
2557
2740
|
const one = id ? waiting.find((o) => o.id === id) : waiting.length === 1 ? waiting[0] : undefined;
|
|
@@ -2567,10 +2750,7 @@ async function main() {
|
|
|
2567
2750
|
die("no agent CLI found on this machine (claude, cursor-agent, codex, copilot, or kiro-cli)");
|
|
2568
2751
|
console.error(D(`opening ${agent.id} with the question…`));
|
|
2569
2752
|
const { spawnSync } = await import("node:child_process");
|
|
2570
|
-
|
|
2571
|
-
const sp = agentSpawn(agent.binary, launchArgs(agent.id, prompt, sessionName(prompt)));
|
|
2572
|
-
spawnSync(sp.command, sp.args, { stdio: "inherit", ...sp.options });
|
|
2573
|
-
}
|
|
2753
|
+
await launchAgent(agent.binary, (p) => launchArgs(agent.id, p, sessionName(prompt)), prompt);
|
|
2574
2754
|
return;
|
|
2575
2755
|
}
|
|
2576
2756
|
case "approvals": {
|
|
@@ -2579,7 +2759,7 @@ async function main() {
|
|
|
2579
2759
|
const conns = [];
|
|
2580
2760
|
for (const c of targets()) {
|
|
2581
2761
|
const cl = new PantheonClient(c, undefined, { role: "cli" });
|
|
2582
|
-
await cl.connect().catch((e) => die(`${c.space}: ${e.
|
|
2762
|
+
await cl.connect().catch((e) => die(`${c.space}: ${connectFailure(e, c.relay)}`));
|
|
2583
2763
|
conns.push({ cfg: c, client: cl });
|
|
2584
2764
|
}
|
|
2585
2765
|
const closeAll = () => { for (const c of conns)
|
|
@@ -2624,7 +2804,7 @@ async function main() {
|
|
|
2624
2804
|
const cfg = need();
|
|
2625
2805
|
const sub = argv[1] ?? "list";
|
|
2626
2806
|
const client = new PantheonClient(cfg, undefined, { role: "cli" });
|
|
2627
|
-
await client.connect().catch((e) => die(e.
|
|
2807
|
+
await client.connect().catch((e) => die(connectFailure(e, cfg.relay)));
|
|
2628
2808
|
const waiting = client.obligations.filter((o) => o.kind === "HUMAN" && o.owner === `human:${cfg.member}`);
|
|
2629
2809
|
const id = argv[2];
|
|
2630
2810
|
if (sub === "answer") {
|
|
@@ -2937,7 +3117,7 @@ async function main() {
|
|
|
2937
3117
|
const sub = argv[1] ?? "list";
|
|
2938
3118
|
const { repo: _r, repoOrigin: _o, ...plain } = cfg;
|
|
2939
3119
|
const client = new PantheonClient(plain, undefined, { role: "cli" });
|
|
2940
|
-
await client.connect().catch((e) => die(client.pending ?? e.
|
|
3120
|
+
await client.connect().catch((e) => die(client.pending ?? connectFailure(e, plain.relay)));
|
|
2941
3121
|
if (sub === "add") {
|
|
2942
3122
|
const r = repoInfo(flag("path") ?? process.cwd()) ?? die("not inside a git repo");
|
|
2943
3123
|
const base = flag("base") ?? null;
|
|
@@ -2981,5 +3161,10 @@ async function main() {
|
|
|
2981
3161
|
process.exit(cmd === "help" || cmd === "--help" ? 0 : 1);
|
|
2982
3162
|
}
|
|
2983
3163
|
}
|
|
2984
|
-
main().catch((e) => die(e
|
|
3164
|
+
main().catch((e) => die(describeNetError(e, (() => { try {
|
|
3165
|
+
return load()?.relay;
|
|
3166
|
+
}
|
|
3167
|
+
catch {
|
|
3168
|
+
return undefined;
|
|
3169
|
+
} })())));
|
|
2985
3170
|
//# sourceMappingURL=cli.js.map
|