@join-pantheon/cli 0.33.11-rc.2 → 0.34.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -19,7 +19,7 @@ import { install, launcher, installForUser, windowsRepoOverrides, agentAsksOnce
19
19
  import { Relay } from "./relay.js";
20
20
  import { runMcp } from "./mcp.js";
21
21
  import { Worker } from "./worker.js";
22
- import { DEFAULT_REMINDER_MS, ensureNativeNotifier, HumanNotifier, hudBinaryPath, runNotifiers, sendDesktopNotification } from "./notifier.js";
22
+ import { DEFAULT_REMINDER_MS, ensureNativeNotifier, HumanNotifier, hudBinaryPath, openInHere, runNotifiers, sendDesktopNotification } from "./notifier.js";
23
23
  import { linuxDesktopReachable } from "./notice-linux.js";
24
24
  import { desktopUnavailable, hostEnv } from "./host-env.js";
25
25
  import { commandState } from "./command-state.js";
@@ -742,18 +742,26 @@ async function launchAgent(binary, args, prompt, cwd) {
742
742
  catch (e) {
743
743
  if (!(e instanceof CmdLineUnsafe))
744
744
  throw e;
745
- const where = cwd ?? process.cwd();
746
- const rel = join(".pantheon", "handoff", `${Date.now()}-${randomBytes(3).toString("hex")}.md`);
747
- handoff = join(where, rel);
748
- mkdirSync(dirname(handoff), { recursive: true });
749
- writeFileSync(handoff, prompt + "\n");
745
+ const { writeHandoff } = await import("./open-in.js");
750
746
  try {
751
- const { excludeRunFiles } = await import("./worker.js");
752
- excludeRunFiles(where);
747
+ const h = writeHandoff(prompt, null, CONFIG_DIR);
748
+ handoff = h.file;
749
+ console.error(D(` the question is in ${h.file} — the agent is asked to read it (it may ask your permission to read outside this folder)`));
750
+ sp = agentSpawn(binary, args(h.ask));
751
+ }
752
+ catch (e2) {
753
+ const { copyToClipboard } = await import("./desktop-app.js");
754
+ const copied = (() => { try {
755
+ return copyToClipboard(prompt);
756
+ }
757
+ catch {
758
+ return false;
759
+ } })();
760
+ console.error(`${B("the question could not be handed over in a file")} ${D(`(${e2.message.slice(0, 120)})`)} — ${copied ? "it is on your clipboard: paste it into the agent (Ctrl+V)" : "here it is to copy:"}`);
761
+ if (!copied)
762
+ console.log(`\n${prompt}\n`);
763
+ sp = agentSpawn(binary, args("Pantheon: a teammate's question is on my clipboard — I will paste it next."));
753
764
  }
754
- catch { }
755
- console.error(D(` the question is in ${rel} — the agent is asked to read it`));
756
- sp = agentSpawn(binary, args(`Read the file ${rel.split(/[\\/]/).join("/")} in this folder and do what it asks.`));
757
765
  }
758
766
  try {
759
767
  const r = spawnSync(sp.command, sp.args, { stdio: "inherit", ...(cwd ? { cwd } : {}), ...sp.options });
@@ -776,11 +784,10 @@ async function claudeAppInstead(surface, prompt) {
776
784
  const { detectAvailable } = await import("./agents.js");
777
785
  if (detectAvailable().some((a) => a.backend.id === "claude-code"))
778
786
  return false;
779
- const { findClaudeApp, explainInClaudeApp } = await import("./desktop-app.js");
780
- const app = findClaudeApp();
781
- if (!app)
787
+ const { legacyClaudeApp } = await import("./open-in.js");
788
+ const r = legacyClaudeApp(prompt);
789
+ if (!r)
782
790
  return false;
783
- const r = explainInClaudeApp(prompt, app);
784
791
  if (!r.ok) {
785
792
  console.error(D(` ${r.says} — opening an agent CLI instead`));
786
793
  return false;
@@ -790,6 +797,68 @@ async function claudeAppInstead(surface, prompt) {
790
797
  console.log(`\n${prompt}\n`);
791
798
  return true;
792
799
  }
800
+ async function openInAppIfChosen(hud, surface, prompt, cwd, queuedId) {
801
+ if (hud?.terminal)
802
+ return false;
803
+ const oi = await import("./open-in.js");
804
+ const silent = argv.includes("--silent");
805
+ const chosenApp = oi.effectiveOpenIn({ home: CONFIG_DIR, appPresent: () => oi.claudeAppPresent() }) === "app";
806
+ const question = async () => (typeof prompt === "string" ? prompt : await prompt());
807
+ if (hud?.tool === oi.CLAUDE_APP_TOOL && !chosenApp) {
808
+ const q = await question();
809
+ const r = oi.legacyClaudeApp(q);
810
+ if (r?.ok) {
811
+ console.error(r.says);
812
+ if (/could not be copied/.test(r.says))
813
+ console.log(`\n${q}\n`);
814
+ return true;
815
+ }
816
+ if (r)
817
+ console.error(D(` ${r.says}`));
818
+ return silent ? toVisibleTerminal(hud, queuedId, r?.says ?? "the Claude app is not here") : false;
819
+ }
820
+ const otherTool = !!hud?.tool && hud.tool !== oi.CLAUDE_APP_TOOL && hud.tool !== surface;
821
+ if (chosenApp && !otherTool) {
822
+ let r;
823
+ try {
824
+ r = await oi.openInClaudeApp(await question(), cwd, { home: CONFIG_DIR });
825
+ }
826
+ catch (e) {
827
+ r = { ok: false, says: `the Claude app could not be given the question (${e.message.slice(0, 80)})` };
828
+ }
829
+ if (r.ok) {
830
+ console.error(r.says);
831
+ return true;
832
+ }
833
+ if (!silent) {
834
+ console.error(D(` ${r.says} — opening an agent CLI instead`));
835
+ return false;
836
+ }
837
+ return toVisibleTerminal(hud, queuedId, r.says);
838
+ }
839
+ return silent ? toVisibleTerminal(hud, queuedId, "questions open in a terminal on this computer") : false;
840
+ }
841
+ async function toVisibleTerminal(hud, queuedId, why) {
842
+ const oi = await import("./open-in.js");
843
+ if (process.platform === "darwin") {
844
+ try {
845
+ if (hud) {
846
+ const { writeHudAction } = await import("./uri-handler.js");
847
+ writeHudAction(CONFIG_DIR, { ...hud, terminal: true, nonce: undefined });
848
+ }
849
+ else
850
+ writeFileSync(join(CONFIG_DIR, "bin", ".explain-id"), queuedId ?? "all");
851
+ const file = hud?.action === "details" ? "pantheon-details.command" : "pantheon-explain.command";
852
+ if (oi.startDetached("open", [join(CONFIG_DIR, "bin", file)])) {
853
+ console.error(D(` ${why} — opening a terminal`));
854
+ return true;
855
+ }
856
+ }
857
+ catch { }
858
+ }
859
+ console.log(`not sent: ${why}`);
860
+ process.exit(1);
861
+ }
793
862
  async function workerServesLines() {
794
863
  try {
795
864
  const { workerServesReport } = await import("./worker-fleet.js");
@@ -1551,6 +1620,8 @@ ${B("control")}
1551
1620
  pantheon profile show, create (init), or set your agent and attention profile
1552
1621
  pantheon directory organization roles and decision authority
1553
1622
  pantheon approvals decisions waiting on you; show or answer one
1623
+ pantheon open-in [app|terminal] where Explain and Show details open: the Claude app (a session with the
1624
+ question typed in, no terminal) or your agent in a terminal
1554
1625
  pantheon board your board in the browser, on any OS: what needs you, what your agents are on, and act on it
1555
1626
  (--open start or reuse it and open it · --url print its address
1556
1627
  · --watch the same lanes in this terminal, for SSH · --keep never stop when idle · --stop)
@@ -1651,6 +1722,7 @@ const COMMAND_FLAGS = {
1651
1722
  invite: "--list --revoke <token|all> --may-wake | --no-wake --ttl <minutes>",
1652
1723
  admit: "<member> --may-wake | --no-wake --revoke --forget --yes",
1653
1724
  wake: "allow <member> | deny <member> | list --space <team>",
1725
+ "open-in": "[app | terminal] (no argument: where they open now)",
1654
1726
  trust: "[<member>] --yes --space <team>",
1655
1727
  recover: "[<team>] | withdraw <team> | confirm <member> | cancel <member> [--yes] --space <team> --no-worker --no-hook --no-notifications --no-menubar\n exits 3 when the move was asked for and waits for a teammate (or a day); 0 when it moved",
1656
1728
  say: "<ACT> <text> --to <member>[,<member>] --goal <id> --ref <id | seq | last> --summary '<one line>' --domains <a,b> --branch --commit --remote (DELIVERED) --space <team>",
@@ -1665,7 +1737,7 @@ const COMMAND_FLAGS = {
1665
1737
  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",
1666
1738
  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)",
1667
1739
  doctor: "--share --project <dir>",
1668
- relay: "--port <n> --host <address> --data <dir>",
1740
+ relay: "--port <n> --host <address> --data <dir> (relay leftovers --data <dir> [--json]: read-only report)",
1669
1741
  use: "<team> --here --yes · pantheon use --unbind (this folder or repo bound to no team again)",
1670
1742
  repo: "add [--base <branch>] | list [--all] | find [<folder>] [--recents] [--yes]",
1671
1743
  login: "--email <address> --relay <url> --label <device name>",
@@ -1745,7 +1817,7 @@ function slipDistance(a, b) {
1745
1817
  return d[a.length][b.length];
1746
1818
  }
1747
1819
  const EXTRA_FLAGS = "--action-id --agent-cmd --approve-all --ask-before-sending --child --code --data --device --display --force --help --host --idle --keywords --local " +
1748
- "--no-browser --no-continue --no-guide --no-notify --only-action --path --peek --poll --portable --publish --queued --quiet --remind --scratch --serve --session --surface --token --unattended " +
1820
+ "--no-browser --no-continue --no-guide --no-notify --only-action --path --peek --poll --portable --publish --queued --quiet --remind --scratch --serve --session --silent --surface --token --unattended " +
1749
1821
  "--until --user --version --all --json " +
1750
1822
  "--name --title --wake --commands --unsandboxed --alerts --decides --playbook --base --responsibilities --human-required --agent-can-decide --capabilities" +
1751
1823
  " --keep-tray-quit --direct";
@@ -2033,6 +2105,20 @@ async function main() {
2033
2105
  return;
2034
2106
  }
2035
2107
  case "relay": {
2108
+ if (argv[1] === "leftovers") {
2109
+ const { leftoverReport } = await import("./leftovers.js");
2110
+ const dir = resolveDataDir(flag("data")).dir;
2111
+ const rows = leftoverReport(dir);
2112
+ if (flag("json") !== undefined || process.argv.includes("--json")) {
2113
+ console.log(JSON.stringify({ data: dir, leftovers: rows }, null, 2));
2114
+ return;
2115
+ }
2116
+ const w = Math.max(4, ...rows.map((r) => r.stem.length));
2117
+ console.log(`member lists in ${dir}: ${rows.length} (${rows.filter((r) => r.state === "covered").length} covered, ${rows.filter((r) => r.state === "unsure").length} unsure)`);
2118
+ for (const r of rows)
2119
+ console.log(`${r.state.padEnd(8)} ${r.stem.padEnd(w)} ${r.why}`);
2120
+ return;
2121
+ }
2036
2122
  for (const s of [process.stdout, process.stderr])
2037
2123
  s.on("error", () => { });
2038
2124
  process.on("unhandledRejection", (e) => { console.error(`! unhandled rejection: ${e?.stack ?? String(e)}`); });
@@ -5004,6 +5090,7 @@ async function main() {
5004
5090
  c.on("exit", (status) => { clearTimeout(t); done(status === 0); });
5005
5091
  }) : null,
5006
5092
  runBrief: () => spawnSync(process.execPath, self(["brief"]), { stdio: "inherit", env: childEnv }).status ?? 1,
5093
+ opensInApp: () => openInHere(uriHome) === "app",
5007
5094
  runReview: () => spawnSync(process.execPath, self(["changes", "review"]), { stdio: "inherit", env: childEnv }).status ?? 1,
5008
5095
  print: (l) => console.log(l),
5009
5096
  pause: async () => {
@@ -5478,6 +5565,31 @@ async function main() {
5478
5565
  const ls = t.trim().split("\n");
5479
5566
  return ls.slice(0, max).map((l) => ` ${l}`).join("\n") + (ls.length > max ? `\n ${D(`… ${ls.length - max} more lines — 3 shows the whole thread`)}` : "");
5480
5567
  };
5568
+ const detailsPrompt = async () => {
5569
+ let prompt = o ? dp(o.id, dt(o.body)) : "";
5570
+ if (o) {
5571
+ const c3 = new PantheonClient(tcfg, undefined, { role: "cli" });
5572
+ try {
5573
+ await c3.connect();
5574
+ prompt = await decisionBriefFor(tcfg, c3, o);
5575
+ }
5576
+ catch { }
5577
+ finally {
5578
+ c3.close();
5579
+ }
5580
+ }
5581
+ else if (a) {
5582
+ const { runBrief } = await import("./decision-ui.js");
5583
+ prompt = runBrief({ team: tcfg.space, peer, goal: goalTitle ? { title: goalTitle } : null, request: req?.body ?? "(the request is no longer held by the relay)",
5584
+ reply: mine ? { act: a.act, text: a.body } : null, ...(meta.branch ? { branch: meta.branch } : {}), ...(meta.commit ? { commit: meta.commit } : {}),
5585
+ owedByMe: owed.map((x) => x.body), ok: true });
5586
+ if (!mine)
5587
+ prompt = prompt.replace(/^Pantheon: my worker handled .*$/m, `Pantheon: ${a.from}'s ${a.act.toLowerCase()} in "${tcfg.space}"`);
5588
+ }
5589
+ return prompt;
5590
+ };
5591
+ if ((a || o) && await openInAppIfChosen(hud, loadProfile(tcfg).agent.primary_surface, detailsPrompt, wd?.path ?? undefined))
5592
+ return;
5481
5593
  if (a) {
5482
5594
  console.log(`${B(mine ? `Your worker answered ${peer}` : `${a.from} sent ${a.act === "ASK" ? "a question" : a.act === "DELIVERED" ? "a delivery" : "a message"}`)}${D(` · team ${tcfg.space}${goalTitle ? ` · "${goalTitle}"` : ""} · ${ago(a.ts)}`)}`);
5483
5595
  if (req)
@@ -5508,26 +5620,7 @@ async function main() {
5508
5620
  break;
5509
5621
  if (choice === "1" && agent) {
5510
5622
  rl.close();
5511
- let prompt = o ? dp(o.id, dt(o.body)) : "";
5512
- if (o) {
5513
- const c3 = new PantheonClient(tcfg, undefined, { role: "cli" });
5514
- try {
5515
- await c3.connect();
5516
- prompt = await decisionBriefFor(tcfg, c3, o);
5517
- }
5518
- catch { }
5519
- finally {
5520
- c3.close();
5521
- }
5522
- }
5523
- else {
5524
- const { runBrief } = await import("./decision-ui.js");
5525
- prompt = runBrief({ team: tcfg.space, peer, goal: goalTitle ? { title: goalTitle } : null, request: req?.body ?? "(the request is no longer held by the relay)",
5526
- reply: mine ? { act: a.act, text: a.body } : null, ...(meta.branch ? { branch: meta.branch } : {}), ...(meta.commit ? { commit: meta.commit } : {}),
5527
- owedByMe: owed.map((x) => x.body), ok: true });
5528
- if (!mine)
5529
- prompt = prompt.replace(/^Pantheon: my worker handled .*$/m, `Pantheon: ${a.from}'s ${a.act.toLowerCase()} in "${tcfg.space}"`);
5530
- }
5623
+ const prompt = await detailsPrompt();
5531
5624
  console.error(D(`opening ${agent.id}…`));
5532
5625
  await launchAgent(agent.binary, (p) => launchArgs(agent.id, p, sessionName(prompt)), prompt);
5533
5626
  return;
@@ -5621,6 +5714,8 @@ async function main() {
5621
5714
  }
5622
5715
  }
5623
5716
  if (hud.prompt) {
5717
+ if (await openInAppIfChosen(hud, p.agent.primary_surface, hud.prompt, cwd))
5718
+ return;
5624
5719
  if (await claudeAppInstead(hud.tool ?? p.agent.primary_surface, hud.prompt))
5625
5720
  return;
5626
5721
  const agent = pickExplainAgent(hud.tool ?? p.agent.primary_surface, detectAvailable());
@@ -5677,6 +5772,8 @@ async function main() {
5677
5772
  console.log(D("no decisions waiting on you — nothing to explain"));
5678
5773
  return;
5679
5774
  }
5775
+ if (await openInAppIfChosen(null, loadProfile(one?.cfg ?? cfg).agent.primary_surface, prompt, cwd, id ?? "all"))
5776
+ return;
5680
5777
  if (await claudeAppInstead(loadProfile(one?.cfg ?? cfg).agent.primary_surface, prompt))
5681
5778
  return;
5682
5779
  const agent = pickExplainAgent(loadProfile(one?.cfg ?? cfg).agent.primary_surface, detectAvailable());
@@ -5688,6 +5785,52 @@ async function main() {
5688
5785
  await launchAgent(agent.binary, (p) => launchArgs(agent.id, p, sessionName(finalPrompt)), finalPrompt, cwd);
5689
5786
  return;
5690
5787
  }
5788
+ case "open-in": {
5789
+ const oi = await import("./open-in.js");
5790
+ let surface = "claude-code";
5791
+ try {
5792
+ const c = resolveFor(process.cwd()).cfg;
5793
+ if (c)
5794
+ surface = loadProfile(c).agent.primary_surface;
5795
+ }
5796
+ catch { }
5797
+ const cliTool = isAgentSurface(surface) ? surface : "claude-code";
5798
+ const want = argv[1];
5799
+ if (want !== undefined && want !== "app" && want !== "terminal")
5800
+ die("usage: pantheon open-in [app|terminal]");
5801
+ if (want !== undefined && inWokenRun())
5802
+ die("a woken run cannot change where this machine opens questions — a person has to run this here");
5803
+ if (want !== undefined) {
5804
+ const busy = await setupBusy();
5805
+ if (busy) {
5806
+ console.log(`${busy} Nothing changed.`);
5807
+ process.exit(2);
5808
+ }
5809
+ }
5810
+ const present = oi.claudeAppPresent();
5811
+ const who = (() => { const w = whoIsAsking(); return w.kind === "terminal" ? "terminal" : w.kind === "agent" && w.agent === "no terminal" ? "menu bar or tray" : askedByLabel(w); })();
5812
+ if (want === "app") {
5813
+ if (!present)
5814
+ die("the Claude app is not installed here — install it from https://claude.ai/download, then run this again");
5815
+ oi.setOpenIn(CONFIG_DIR, "app", cliTool, who);
5816
+ }
5817
+ else if (want === "terminal")
5818
+ oi.setOpenIn(CONFIG_DIR, "terminal", cliTool, who);
5819
+ const now = oi.effectiveOpenIn({ home: CONFIG_DIR, appPresent: () => present });
5820
+ const chosen = oi.chosenOpenIn(CONFIG_DIR);
5821
+ const typed = process.platform !== "win32" || oi.windowsLinkHandler();
5822
+ console.log(now === "app"
5823
+ ? typed
5824
+ ? `Explain and Show details open in ${B("the Claude app")}: a new Claude Code session in the team's folder, with the question typed in — you press Enter to send it. No terminal.`
5825
+ : `Explain and Show details open ${B("the Claude app")} with the question on your clipboard — paste it (Ctrl+V) to start. No terminal.`
5826
+ : `Explain and Show details open ${B("in a terminal")}, with your agent (${cliTool}) and the question${!chosen ? " — as before" : ""}.`);
5827
+ if (!chosen)
5828
+ console.log(D(" (nothing chosen on this machine: everything works as it always has)"));
5829
+ if (chosen === "app" && !present)
5830
+ console.log(D(" you chose the Claude app, but it is not here — so a terminal for now"));
5831
+ console.log(D(now === "app" ? " change it: pantheon open-in terminal" : ` change it: pantheon open-in app${present ? "" : " (once the Claude app is installed)"}`));
5832
+ return;
5833
+ }
5691
5834
  case "approvals": {
5692
5835
  const sub = argv[1] ?? "list";
5693
5836
  const id = argv[2];
@@ -65,7 +65,7 @@ export function clipboardCommand(os = process.platform, find = () => true) {
65
65
  return { cmd: "xclip", args: ["-selection", "clipboard"] };
66
66
  return null;
67
67
  }
68
- function copyReal(text) {
68
+ export function copyToClipboard(text) {
69
69
  const c = clipboardCommand();
70
70
  if (!c)
71
71
  return false;
@@ -88,7 +88,7 @@ function startReal(cmd, args) {
88
88
  }
89
89
  }
90
90
  export function explainInClaudeApp(prompt, app, d = {}) {
91
- const copied = (d.copy ?? copyReal)(prompt);
91
+ const copied = (d.copy ?? copyToClipboard)(prompt);
92
92
  const o = openAppCommand(app);
93
93
  if (!(d.start ?? startReal)(o.cmd, o.args))
94
94
  return { ok: false, says: "the Claude app could not be opened" };