@h-rig/cli 0.0.6-alpha.88 → 0.0.6-alpha.89

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.
Files changed (70) hide show
  1. package/dist/bin/rig.js +1159 -292
  2. package/dist/src/app/board.js +462 -48
  3. package/dist/src/app-opentui/adapters/doctor.js +458 -46
  4. package/dist/src/app-opentui/adapters/family.js +670 -147
  5. package/dist/src/app-opentui/adapters/fleet.js +477 -46
  6. package/dist/src/app-opentui/adapters/inbox.js +477 -46
  7. package/dist/src/app-opentui/adapters/init.js +497 -74
  8. package/dist/src/app-opentui/adapters/inspect.js +477 -46
  9. package/dist/src/app-opentui/adapters/pi-attach.js +484 -53
  10. package/dist/src/app-opentui/adapters/run-detail.js +477 -46
  11. package/dist/src/app-opentui/adapters/server.d.ts +26 -0
  12. package/dist/src/app-opentui/adapters/server.js +676 -59
  13. package/dist/src/app-opentui/adapters/tasks.js +539 -81
  14. package/dist/src/app-opentui/autocomplete.js +4 -2
  15. package/dist/src/app-opentui/bootstrap.js +1155 -288
  16. package/dist/src/app-opentui/command-palette.js +37 -10
  17. package/dist/src/app-opentui/index.js +566 -89
  18. package/dist/src/app-opentui/intent.js +33 -8
  19. package/dist/src/app-opentui/keymap.js +43 -29
  20. package/dist/src/app-opentui/pi-host-child.js +465 -53
  21. package/dist/src/app-opentui/react/App.js +104 -44
  22. package/dist/src/app-opentui/react/ChromeHost.js +16 -4
  23. package/dist/src/app-opentui/react/launch.js +555 -88
  24. package/dist/src/app-opentui/react/nav.js +1 -1
  25. package/dist/src/app-opentui/registry.js +1062 -237
  26. package/dist/src/app-opentui/remote-link.d.ts +10 -0
  27. package/dist/src/app-opentui/remote-link.js +47 -0
  28. package/dist/src/app-opentui/runtime.js +566 -89
  29. package/dist/src/app-opentui/scenes/doctor.js +1 -1
  30. package/dist/src/app-opentui/scenes/error.js +50 -4
  31. package/dist/src/app-opentui/scenes/family.js +60 -6
  32. package/dist/src/app-opentui/scenes/fleet.js +65 -13
  33. package/dist/src/app-opentui/scenes/help.js +4 -2
  34. package/dist/src/app-opentui/scenes/init.js +12 -12
  35. package/dist/src/app-opentui/scenes/main.js +7 -7
  36. package/dist/src/app-opentui/scenes/server.js +83 -11
  37. package/dist/src/app-opentui/scenes/tasks.js +79 -16
  38. package/dist/src/app-opentui/state.js +25 -5
  39. package/dist/src/app-opentui/surface-catalog.js +4 -2
  40. package/dist/src/app-opentui/types.d.ts +1 -1
  41. package/dist/src/commands/_cli-format.d.ts +10 -1
  42. package/dist/src/commands/_cli-format.js +5 -2
  43. package/dist/src/commands/_connection-state.d.ts +11 -1
  44. package/dist/src/commands/_connection-state.js +50 -5
  45. package/dist/src/commands/_doctor-checks.js +458 -46
  46. package/dist/src/commands/_help-catalog.js +4 -2
  47. package/dist/src/commands/_json-output.js +4 -0
  48. package/dist/src/commands/_operator-view.js +465 -53
  49. package/dist/src/commands/_pi-frontend.js +465 -53
  50. package/dist/src/commands/_preflight.js +509 -72
  51. package/dist/src/commands/_server-client.d.ts +33 -0
  52. package/dist/src/commands/_server-client.js +477 -46
  53. package/dist/src/commands/_server-events.js +446 -41
  54. package/dist/src/commands/_snapshot-upload.js +460 -48
  55. package/dist/src/commands/connect.js +620 -15
  56. package/dist/src/commands/doctor.js +458 -46
  57. package/dist/src/commands/github.js +462 -50
  58. package/dist/src/commands/inbox.js +458 -46
  59. package/dist/src/commands/init.js +497 -74
  60. package/dist/src/commands/inspect.js +458 -46
  61. package/dist/src/commands/run.js +465 -53
  62. package/dist/src/commands/server.js +647 -163
  63. package/dist/src/commands/setup.js +463 -51
  64. package/dist/src/commands/stats.js +462 -48
  65. package/dist/src/commands/task-run-driver.js +464 -52
  66. package/dist/src/commands/task.js +520 -81
  67. package/dist/src/commands.js +670 -147
  68. package/dist/src/index.js +674 -147
  69. package/dist/src/launcher.js +4 -0
  70. package/package.json +8 -8
@@ -351,12 +351,13 @@ var PRIMARY_GROUPS = [
351
351
  {
352
352
  name: "server",
353
353
  summary: "Choose, inspect, and start the Rig server that owns tasks and runs.",
354
- usage: ["rig server <status|list|add|use|start> [options]"],
354
+ usage: ["rig server <status|list|add|use|repair-link|start> [options]"],
355
355
  commands: [
356
- { command: "status", description: "Show the selected server for this repo.", primary: true },
356
+ { command: "status", description: "Show the selected server and remote project-root link for this repo.", primary: true },
357
357
  { command: "use local", description: "Switch this repo to the local Rig server.", primary: true },
358
358
  { command: "add <alias> <url>", description: "Save a remote Rig server URL.", primary: true },
359
359
  { command: "use <alias>", description: "Select a saved remote server alias.", primary: true },
360
+ { command: "repair-link [--prepare|--backfill-only] [--repo owner/repo]", description: "Backfill or prepare the selected remote's server-host checkout link.", primary: true },
360
361
  { command: "list", description: "List saved local/remote server aliases.", primary: true },
361
362
  { command: "start [--host <host>] [--port <n>]", description: "Start a local rig-server process." }
362
363
  ],
@@ -364,6 +365,7 @@ var PRIMARY_GROUPS = [
364
365
  "rig server status",
365
366
  "rig server add prod https://where.rig-does.work",
366
367
  "rig server use prod",
368
+ "rig server repair-link --repo owner/repo",
367
369
  "rig server use local",
368
370
  "rig server start --port 3773"
369
371
  ],
@@ -1056,16 +1058,31 @@ function taskViewIntent(argv, command = "", rest = [], raw) {
1056
1058
  const { payload, label } = taskViewPayload(command, rest);
1057
1059
  return intent("tasks", argv, "refresh", payload, label, raw);
1058
1060
  }
1059
- function routeServer(argv, command, raw, checkingLabel) {
1060
- if (!command || command === "status") {
1061
+ function routeServer(argv, command, rest, raw, checkingLabel) {
1062
+ if (!command || command === "status" || command === "list") {
1061
1063
  return intent("server", argv, "refresh", undefined, command ? checkingLabel : "Loading server", raw);
1062
1064
  }
1065
+ if (command === "use") {
1066
+ const alias = firstNonOption(rest);
1067
+ if (alias === "local")
1068
+ return intent("server", argv, "server-use-local", undefined, "Use local server", raw);
1069
+ if (alias)
1070
+ return intent("server", argv, "server-use-remote", { alias }, `Use ${alias}`, raw);
1071
+ return intent("server", argv, "refresh", undefined, "Select a remote alias in Server", raw);
1072
+ }
1073
+ if (command === "add")
1074
+ return intent("server", argv, "server-add-remote", { argv: [...argv] }, "Add remote server", raw);
1075
+ if (command === "repair-link")
1076
+ return intent("server", argv, "remote-link-repair", undefined, "Repair remote link", raw);
1063
1077
  return commandRunIntent(argv, raw);
1064
1078
  }
1065
1079
  function routeGithub(argv, command, rest, raw) {
1066
1080
  if (command === "auth" && (rest[0]?.toLowerCase() ?? "status") === "status" && rest.length <= 1) {
1067
1081
  return intent("server", argv, "refresh", undefined, "Checking GitHub auth", raw);
1068
1082
  }
1083
+ if (command === "auth" && rest[0]?.toLowerCase() === "import-gh" && rest.length <= 1) {
1084
+ return intent("server", argv, "github-auth-import", undefined, "Import GitHub auth", raw);
1085
+ }
1069
1086
  return commandRunIntent(argv, raw);
1070
1087
  }
1071
1088
  function routeDoctor(argv, command, raw) {
@@ -1114,11 +1131,16 @@ function intentFromArgv(argv) {
1114
1131
  return commandRunIntent(argv);
1115
1132
  }
1116
1133
  if (normalizedGroup === "server")
1117
- return routeServer(argv, normalizedCommand, undefined, "Checking server");
1134
+ return routeServer(argv, normalizedCommand, rest, undefined, "Checking server");
1118
1135
  if (normalizedGroup === "github")
1119
1136
  return routeGithub(argv, normalizedCommand, rest);
1120
- if (normalizedGroup === "init")
1121
- return commandRunIntent(argv);
1137
+ if (normalizedGroup === "init") {
1138
+ if (!normalizedCommand)
1139
+ return intent("init", argv, "refresh", undefined, "Open init");
1140
+ if (rest.includes("--yes") || normalizedCommand === "--yes")
1141
+ return intent("init", argv, "init-start", undefined, "Run init");
1142
+ return intent("init", argv, "refresh", undefined, "Open init");
1143
+ }
1122
1144
  if (normalizedGroup === "doctor")
1123
1145
  return routeDoctor(argv, normalizedCommand);
1124
1146
  if (normalizedGroup === "inbox")
@@ -1181,12 +1203,17 @@ function intentFromTypeBar(value) {
1181
1203
  return commandRunIntent(parts, value);
1182
1204
  return intent("tasks", parts, "refresh", undefined, "Select a task, then press Enter; or use run next", value);
1183
1205
  }
1184
- if (first === "init")
1185
- return commandRunIntent(parts, value);
1206
+ if (first === "init") {
1207
+ if (!second)
1208
+ return intent("init", parts, "refresh", undefined, "Open init", value);
1209
+ if (parts.includes("--yes"))
1210
+ return intent("init", parts, "init-start", undefined, "Run init", value);
1211
+ return intent("init", parts, "refresh", undefined, "Open init", value);
1212
+ }
1186
1213
  if (first === "doctor")
1187
1214
  return routeDoctor(parts, second, value);
1188
1215
  if (first === "server")
1189
- return routeServer(parts, second, value, "Loading server");
1216
+ return routeServer(parts, second, rest, value, "Loading server");
1190
1217
  if (first === "github")
1191
1218
  return routeGithub(parts, second, rest, value);
1192
1219
  if (first === "inbox")
@@ -1204,12 +1231,6 @@ function intentFromTypeBar(value) {
1204
1231
  return intentFromArgv(parts);
1205
1232
  }
1206
1233
 
1207
- // packages/cli/src/app-opentui/pi-pty-host.ts
1208
- function getActivePiHost() {
1209
- return null;
1210
- }
1211
- function stopActivePiHost(_reason) {}
1212
-
1213
1234
  // packages/cli/src/app-opentui/keymap.ts
1214
1235
  var autocompleteState;
1215
1236
  function clearTypeBar(context, message) {
@@ -1219,22 +1240,15 @@ function clearTypeBar(context, message) {
1219
1240
  context.emitTypeBarPatch({ value: "", mode: "nav", prompt: undefined, message });
1220
1241
  }
1221
1242
  function handleEmbeddedTerminalKey(context, key) {
1222
- const state = context.getState();
1223
- const piHost = getActivePiHost();
1224
- const commandHost = getActiveCommandHost();
1225
- const host = state.scene === "handoff" ? piHost : state.scene === "command" ? commandHost : null;
1243
+ if (context.getState().scene !== "command")
1244
+ return false;
1245
+ const host = getActiveCommandHost();
1226
1246
  if (!host)
1227
1247
  return false;
1228
1248
  if (key.ctrl && key.name === "]") {
1229
- if (state.scene === "handoff") {
1230
- stopActivePiHost("operator detach");
1231
- clearTypeBar(context, "detached from Pi");
1232
- context.runAppAction("Opening runs", () => context.runtime.runIntent({ scene: "fleet", argv: ["runs"], action: { kind: "refresh", label: "Opening runs" } }));
1233
- } else {
1234
- stopActiveCommandHost("operator detach");
1235
- clearTypeBar(context, "closed command");
1236
- context.runAppAction("Project menu", () => context.runtime.runIntent({ scene: "main", argv: ["main"], action: { kind: "none", label: "Project menu" } }));
1237
- }
1249
+ stopActiveCommandHost("operator detach");
1250
+ clearTypeBar(context, "closed command");
1251
+ context.runAppAction("Project menu", () => context.runtime.runIntent({ scene: "main", argv: ["main"], action: { kind: "none", label: "Project menu" } }));
1238
1252
  return true;
1239
1253
  }
1240
1254
  const sequence = key.raw || key.sequence;
@@ -1546,8 +1560,8 @@ import { WsTransport } from "@rig/client";
1546
1560
  import { RIG_WS_CHANNELS } from "@rig/contracts";
1547
1561
 
1548
1562
  // packages/cli/src/commands/_server-client.ts
1549
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
1550
- import { resolve as resolve2 } from "path";
1563
+ import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
1564
+ import { dirname as dirname2, isAbsolute, resolve as resolve2 } from "path";
1551
1565
 
1552
1566
  // packages/cli/src/runner.ts
1553
1567
  import { EventBus } from "@rig/runtime/control-plane/runtime/events";
@@ -1639,12 +1653,28 @@ function readRepoConnection(projectRoot) {
1639
1653
  selected,
1640
1654
  project: typeof record.project === "string" ? record.project : undefined,
1641
1655
  linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
1642
- serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
1656
+ serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined,
1657
+ serverProjectRootAlias: typeof record.serverProjectRootAlias === "string" && record.serverProjectRootAlias.trim() ? record.serverProjectRootAlias.trim() : undefined,
1658
+ serverProjectRootBaseUrl: typeof record.serverProjectRootBaseUrl === "string" && record.serverProjectRootBaseUrl.trim() ? record.serverProjectRootBaseUrl.trim().replace(/\/+$/, "") : undefined
1643
1659
  };
1644
1660
  }
1645
1661
  function writeRepoConnection(projectRoot, state) {
1646
1662
  writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
1647
1663
  }
1664
+ function rootAllowedForSelection(repo, connection) {
1665
+ const root = repo.serverProjectRoot?.trim();
1666
+ if (!root)
1667
+ return;
1668
+ if (connection.kind === "remote") {
1669
+ if (repo.serverProjectRootAlias !== repo.selected)
1670
+ return;
1671
+ if (repo.serverProjectRootBaseUrl !== connection.baseUrl)
1672
+ return;
1673
+ } else if (repo.serverProjectRootAlias && repo.serverProjectRootAlias !== repo.selected) {
1674
+ return;
1675
+ }
1676
+ return root;
1677
+ }
1648
1678
  function resolveSelectedConnection(projectRoot, options = {}) {
1649
1679
  const repo = readRepoConnection(projectRoot);
1650
1680
  if (!repo)
@@ -1656,13 +1686,41 @@ function resolveSelectedConnection(projectRoot, options = {}) {
1656
1686
  if (!connection) {
1657
1687
  throw new CliError(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
1658
1688
  }
1659
- return { alias: repo.selected, connection, serverProjectRoot: repo.serverProjectRoot };
1689
+ return { alias: repo.selected, connection, serverProjectRoot: rootAllowedForSelection(repo, connection) };
1660
1690
  }
1661
- function writeRepoServerProjectRoot(projectRoot, serverProjectRoot) {
1691
+ function writeRepoServerProjectRoot(projectRoot, serverProjectRoot, metadata = {}) {
1662
1692
  const repo = readRepoConnection(projectRoot);
1663
1693
  if (!repo)
1664
1694
  return;
1665
- writeRepoConnection(projectRoot, { ...repo, serverProjectRoot });
1695
+ let inferred = metadata;
1696
+ if (!inferred.alias || !inferred.baseUrl) {
1697
+ try {
1698
+ const selected = resolveSelectedConnection(projectRoot);
1699
+ if (selected?.connection.kind === "remote") {
1700
+ inferred = {
1701
+ alias: inferred.alias ?? selected.alias,
1702
+ baseUrl: inferred.baseUrl ?? selected.connection.baseUrl
1703
+ };
1704
+ }
1705
+ } catch {}
1706
+ }
1707
+ writeRepoConnection(projectRoot, {
1708
+ ...repo,
1709
+ ...metadata.project ? { project: metadata.project } : {},
1710
+ serverProjectRoot,
1711
+ ...inferred.alias ? { serverProjectRootAlias: inferred.alias } : {},
1712
+ ...inferred.baseUrl ? { serverProjectRootBaseUrl: inferred.baseUrl.replace(/\/+$/, "") } : {}
1713
+ });
1714
+ }
1715
+ function clearRepoServerProjectRoot(projectRoot) {
1716
+ const repo = readRepoConnection(projectRoot);
1717
+ if (!repo)
1718
+ return;
1719
+ writeRepoConnection(projectRoot, {
1720
+ selected: repo.selected,
1721
+ ...repo.project ? { project: repo.project } : {},
1722
+ ...repo.linkedAt ? { linkedAt: repo.linkedAt } : {}
1723
+ });
1666
1724
  }
1667
1725
 
1668
1726
  // packages/cli/src/commands/_server-client.ts
@@ -1703,11 +1761,10 @@ function readStoredGitHubAuthToken(projectRoot) {
1703
1761
  const parsed = readRemoteAuthState(projectRoot);
1704
1762
  return parsed ? cleanToken(typeof parsed.token === "string" ? parsed.token : undefined) : null;
1705
1763
  }
1706
- function inferRemoteServerProjectRootFromAuthState(projectRoot) {
1707
- const repo = readRepoConnection(projectRoot);
1708
- const slug = repo?.project?.trim();
1709
- if (!slug || !/^[^/]+\/[^/]+$/.test(slug))
1764
+ function inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug) {
1765
+ if (!/^[^/]+\/[^/]+$/.test(repoSlug))
1710
1766
  return null;
1767
+ const repo = readRepoConnection(projectRoot);
1711
1768
  const auth = readRemoteAuthState(projectRoot);
1712
1769
  const authUpdatedAt = typeof auth?.updatedAt === "string" ? Date.parse(auth.updatedAt) : Number.NaN;
1713
1770
  const repoLinkedAt = typeof repo?.linkedAt === "string" ? Date.parse(repo.linkedAt) : Number.NaN;
@@ -1716,25 +1773,413 @@ function inferRemoteServerProjectRootFromAuthState(projectRoot) {
1716
1773
  const checkoutBaseDir = typeof auth?.checkoutBaseDir === "string" && auth.checkoutBaseDir.trim() ? auth.checkoutBaseDir.trim() : null;
1717
1774
  if (!checkoutBaseDir)
1718
1775
  return null;
1719
- const inferred = `${checkoutBaseDir.replace(/\/+$/, "")}/${slug}`;
1720
- writeRepoServerProjectRoot(projectRoot, inferred);
1721
- return inferred;
1776
+ return `${checkoutBaseDir.replace(/\/+$/, "")}/${repoSlug}`;
1722
1777
  }
1723
1778
  function readLocalConnectionFallbackToken(projectRoot) {
1724
1779
  return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
1725
1780
  }
1781
+ function normalizeRepoSlug(value) {
1782
+ const slug = value?.trim();
1783
+ return slug && /^[^/\s]+\/[^/\s]+$/.test(slug) ? slug : null;
1784
+ }
1785
+ function readProjectLinkSlug(projectRoot) {
1786
+ const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
1787
+ if (!existsSync2(path))
1788
+ return null;
1789
+ try {
1790
+ const parsed = JSON.parse(readFileSync2(path, "utf8"));
1791
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
1792
+ return null;
1793
+ return normalizeRepoSlug(typeof parsed.repoSlug === "string" ? String(parsed.repoSlug) : null);
1794
+ } catch {
1795
+ return null;
1796
+ }
1797
+ }
1798
+ function writeProjectLinkConnection(projectRoot, repoSlug, alias) {
1799
+ const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
1800
+ mkdirSync2(dirname2(path), { recursive: true });
1801
+ writeFileSync2(path, `${JSON.stringify({ repoSlug, connection: alias, linkedAt: new Date().toISOString() }, null, 2)}
1802
+ `, "utf8");
1803
+ }
1804
+ function remoteLinkRepairCommand(repoSlug) {
1805
+ return repoSlug ? `rig server repair-link --repo ${repoSlug}` : "rig server repair-link --repo owner/repo";
1806
+ }
1807
+ function formatRemoteProjectLinkHint(resolution) {
1808
+ const repair = remoteLinkRepairCommand(resolution.repoSlug);
1809
+ if (resolution.status === "auth_required") {
1810
+ return `Authenticate the selected remote${resolution.alias ? ` (${resolution.alias})` : ""}, then run \`${repair}\`. Use \`rig github auth import-gh\` or \`rig init --repair --server remote --github-auth device${resolution.repoSlug ? ` --repo ${resolution.repoSlug}` : ""}\`.`;
1811
+ }
1812
+ if (resolution.status === "missing_project") {
1813
+ return `Record the repo slug, then run \`${repair}\` (or \`rig init --repo owner/repo --server remote --github-auth device\`).`;
1814
+ }
1815
+ if (resolution.status === "not_remote")
1816
+ return "Select a remote server with `rig server use <alias>` before repairing a remote project link.";
1817
+ return `Run \`${repair}\` to backfill or prepare a server-host checkout for the selected remote${resolution.alias ? ` (${resolution.alias})` : ""}.`;
1818
+ }
1819
+ function remoteProjectLinkFailure(input) {
1820
+ const partial = {
1821
+ status: input.status,
1822
+ alias: input.alias,
1823
+ baseUrl: input.baseUrl,
1824
+ repoSlug: input.repoSlug
1825
+ };
1826
+ return {
1827
+ ok: false,
1828
+ ...input,
1829
+ hint: formatRemoteProjectLinkHint(partial),
1830
+ next: remoteLinkRepairCommand(input.repoSlug)
1831
+ };
1832
+ }
1833
+ function remoteProjectLinkSuccess(input) {
1834
+ return {
1835
+ ok: true,
1836
+ status: input.status,
1837
+ alias: input.alias,
1838
+ baseUrl: input.baseUrl,
1839
+ repoSlug: input.repoSlug,
1840
+ serverProjectRoot: input.serverProjectRoot,
1841
+ source: input.source,
1842
+ prepared: input.prepared ?? input.status === "prepared",
1843
+ validated: input.validated ?? false,
1844
+ message: input.message ?? `Remote project link ready for ${input.repoSlug}.`,
1845
+ hint: "Remote-scoped task/run/status requests will send x-rig-project-root for this server-host checkout.",
1846
+ next: "rig task list"
1847
+ };
1848
+ }
1849
+ function localCheckoutPathCandidate(projectRoot, candidate) {
1850
+ try {
1851
+ const local = resolve2(projectRoot);
1852
+ const resolved = resolve2(candidate);
1853
+ return resolved === local || resolved.startsWith(`${local}/`);
1854
+ } catch {
1855
+ return false;
1856
+ }
1857
+ }
1858
+ async function requestRemoteProjectLinkJson(baseUrl, pathname, authToken, init = {}) {
1859
+ const requestUrl = new URL(`${baseUrl}${pathname}`);
1860
+ if (authToken && queryAuthFallbackEnabled())
1861
+ requestUrl.searchParams.set("rt", authToken);
1862
+ const response = await fetch(requestUrl, {
1863
+ ...init,
1864
+ headers: mergeHeaders(init.headers, authToken)
1865
+ });
1866
+ const text = await response.text();
1867
+ const payload = text.trim().length > 0 ? (() => {
1868
+ try {
1869
+ return JSON.parse(text);
1870
+ } catch {
1871
+ return null;
1872
+ }
1873
+ })() : null;
1874
+ return { ok: response.ok, status: response.status, payload, text };
1875
+ }
1876
+ function payloadError(payload, fallback) {
1877
+ if (payload && typeof payload === "object" && !Array.isArray(payload)) {
1878
+ const record = payload;
1879
+ const value = record.error ?? record.message ?? record.reason;
1880
+ if (typeof value === "string" && value.trim())
1881
+ return value.trim();
1882
+ }
1883
+ return fallback;
1884
+ }
1885
+ function checkoutPathsFromProjectPayload(payload) {
1886
+ if (!payload || typeof payload !== "object" || Array.isArray(payload))
1887
+ return [];
1888
+ const project = payload.project;
1889
+ if (!project || typeof project !== "object" || Array.isArray(project))
1890
+ return [];
1891
+ const checkouts = project.checkouts;
1892
+ if (!Array.isArray(checkouts))
1893
+ return [];
1894
+ return [...checkouts].reverse().flatMap((entry) => {
1895
+ if (!entry || typeof entry !== "object" || Array.isArray(entry))
1896
+ return [];
1897
+ const path = entry.path;
1898
+ return typeof path === "string" && path.trim() ? [path.trim()] : [];
1899
+ });
1900
+ }
1901
+ function checkoutPathFromPreparePayload(payload) {
1902
+ if (!payload || typeof payload !== "object" || Array.isArray(payload))
1903
+ return null;
1904
+ const checkout = payload.checkout;
1905
+ if (!checkout || typeof checkout !== "object" || Array.isArray(checkout))
1906
+ return null;
1907
+ const path = checkout.path;
1908
+ return typeof path === "string" && path.trim() ? path.trim() : null;
1909
+ }
1910
+ async function validateAndPersistRemoteRoot(input) {
1911
+ const candidate = input.candidate.trim();
1912
+ if (!candidate || !isAbsolute(candidate)) {
1913
+ return remoteProjectLinkFailure({
1914
+ status: "invalid_root",
1915
+ alias: input.alias,
1916
+ baseUrl: input.baseUrl,
1917
+ repoSlug: input.repoSlug,
1918
+ message: `Remote project root candidate is not an absolute server-host path: ${candidate || "(empty)"}.`
1919
+ });
1920
+ }
1921
+ if (localCheckoutPathCandidate(input.projectRoot, candidate)) {
1922
+ return remoteProjectLinkFailure({
1923
+ status: "invalid_root",
1924
+ alias: input.alias,
1925
+ baseUrl: input.baseUrl,
1926
+ repoSlug: input.repoSlug,
1927
+ message: `Refusing to use local checkout path ${candidate} as a remote server project root.`
1928
+ });
1929
+ }
1930
+ let response;
1931
+ try {
1932
+ response = await requestRemoteProjectLinkJson(input.baseUrl, "/api/server/project-root", input.authToken, {
1933
+ method: "POST",
1934
+ headers: { "content-type": "application/json" },
1935
+ body: JSON.stringify({ projectRoot: candidate })
1936
+ });
1937
+ } catch (error) {
1938
+ return remoteProjectLinkFailure({
1939
+ status: "error",
1940
+ alias: input.alias,
1941
+ baseUrl: input.baseUrl,
1942
+ repoSlug: input.repoSlug,
1943
+ message: `Could not validate remote project root ${candidate}: ${error instanceof Error ? error.message : String(error)}`
1944
+ });
1945
+ }
1946
+ if (response.status === 401 || response.status === 403) {
1947
+ return remoteProjectLinkFailure({
1948
+ status: "auth_required",
1949
+ alias: input.alias,
1950
+ baseUrl: input.baseUrl,
1951
+ repoSlug: input.repoSlug,
1952
+ statusCode: response.status,
1953
+ message: `Remote server ${input.alias} requires authentication before validating project root ${candidate}.`
1954
+ });
1955
+ }
1956
+ if (!response.ok) {
1957
+ return remoteProjectLinkFailure({
1958
+ status: "invalid_root",
1959
+ alias: input.alias,
1960
+ baseUrl: input.baseUrl,
1961
+ repoSlug: input.repoSlug,
1962
+ statusCode: response.status,
1963
+ message: `Remote server rejected project root ${candidate} (${response.status}): ${payloadError(response.payload, response.text || "project-root validation failed")}`
1964
+ });
1965
+ }
1966
+ const record = response.payload && typeof response.payload === "object" && !Array.isArray(response.payload) ? response.payload : {};
1967
+ if (record.ok !== true) {
1968
+ return remoteProjectLinkFailure({
1969
+ status: "invalid_root",
1970
+ alias: input.alias,
1971
+ baseUrl: input.baseUrl,
1972
+ repoSlug: input.repoSlug,
1973
+ message: `Remote server did not accept project root ${candidate}: ${payloadError(response.payload, "project-root validation failed")}`
1974
+ });
1975
+ }
1976
+ const accepted = typeof record.projectRoot === "string" && record.projectRoot.trim() ? record.projectRoot.trim() : typeof record.requestedProjectRoot === "string" && record.requestedProjectRoot.trim() ? record.requestedProjectRoot.trim() : candidate;
1977
+ writeRepoServerProjectRoot(input.projectRoot, accepted, { alias: input.alias, baseUrl: input.baseUrl, project: input.repoSlug });
1978
+ writeProjectLinkConnection(input.projectRoot, input.repoSlug, input.alias);
1979
+ const status = input.status ?? (input.prepared ? "prepared" : "backfilled");
1980
+ return remoteProjectLinkSuccess({
1981
+ status,
1982
+ alias: input.alias,
1983
+ baseUrl: input.baseUrl,
1984
+ repoSlug: input.repoSlug,
1985
+ serverProjectRoot: accepted,
1986
+ source: input.source,
1987
+ prepared: input.prepared,
1988
+ validated: true,
1989
+ message: status === "ready" ? `Remote project link already points to ${accepted} and was validated on ${input.alias}.` : input.prepared ? `Prepared and linked remote checkout ${accepted} for ${input.repoSlug}.` : `Backfilled remote checkout ${accepted} for ${input.repoSlug}.`
1990
+ });
1991
+ }
1992
+ async function ensureRemoteProjectRootLink(projectRoot, options = {}) {
1993
+ let selected;
1994
+ try {
1995
+ selected = resolveSelectedConnection(projectRoot);
1996
+ } catch (error) {
1997
+ return remoteProjectLinkFailure({ status: "error", message: error instanceof Error ? error.message : String(error) });
1998
+ }
1999
+ if (!selected || selected.connection.kind !== "remote") {
2000
+ return remoteProjectLinkFailure({ status: "not_remote", message: "No remote Rig server is selected for this repo." });
2001
+ }
2002
+ const repo = readRepoConnection(projectRoot);
2003
+ const explicitRepoRequested = options.repoSlug !== undefined;
2004
+ const explicitRepoSlug = explicitRepoRequested ? normalizeRepoSlug(options.repoSlug) : null;
2005
+ const repoProjectSlug = normalizeRepoSlug(repo?.project);
2006
+ const repoSlug = explicitRepoSlug ?? repoProjectSlug ?? readProjectLinkSlug(projectRoot);
2007
+ const alias = selected.alias;
2008
+ const baseUrl = selected.connection.baseUrl;
2009
+ const authToken = options.authToken === undefined ? readGitHubBearerTokenForRemote(projectRoot) : options.authToken;
2010
+ const mode = options.mode ?? "backfill-only";
2011
+ if (explicitRepoRequested && !explicitRepoSlug) {
2012
+ return remoteProjectLinkFailure({
2013
+ status: "missing_project",
2014
+ alias,
2015
+ baseUrl,
2016
+ message: `Invalid --repo value ${JSON.stringify(options.repoSlug)}. Expected owner/repo.`
2017
+ });
2018
+ }
2019
+ if (!repoSlug) {
2020
+ return remoteProjectLinkFailure({
2021
+ status: "missing_project",
2022
+ alias,
2023
+ baseUrl,
2024
+ message: `Remote server ${alias} is selected, but this checkout has no GitHub repo slug recorded.`
2025
+ });
2026
+ }
2027
+ const skippedCandidates = [];
2028
+ const storedRoot = selected.serverProjectRoot?.trim() || null;
2029
+ const storedRootMatchesResolvedRepo = repoProjectSlug === repoSlug;
2030
+ if (storedRoot && storedRootMatchesResolvedRepo) {
2031
+ if (localCheckoutPathCandidate(projectRoot, storedRoot)) {
2032
+ clearRepoServerProjectRoot(projectRoot);
2033
+ skippedCandidates.push(storedRoot);
2034
+ } else {
2035
+ const storedResult = await validateAndPersistRemoteRoot({
2036
+ projectRoot,
2037
+ alias,
2038
+ baseUrl,
2039
+ authToken,
2040
+ repoSlug,
2041
+ candidate: storedRoot,
2042
+ source: "stored",
2043
+ status: "ready"
2044
+ });
2045
+ if (storedResult.ok || storedResult.status === "auth_required" || storedResult.status === "error")
2046
+ return storedResult;
2047
+ clearRepoServerProjectRoot(projectRoot);
2048
+ skippedCandidates.push(storedRoot);
2049
+ }
2050
+ } else if (storedRoot) {
2051
+ skippedCandidates.push(storedRoot);
2052
+ }
2053
+ const authCandidate = inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug);
2054
+ if (authCandidate) {
2055
+ const authResult = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: authCandidate, source: "auth-state" });
2056
+ if (authResult.ok || authResult.status === "auth_required")
2057
+ return authResult;
2058
+ }
2059
+ let registryResponse;
2060
+ try {
2061
+ registryResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}`, authToken);
2062
+ } catch (error) {
2063
+ return remoteProjectLinkFailure({
2064
+ status: "error",
2065
+ alias,
2066
+ baseUrl,
2067
+ repoSlug,
2068
+ message: `Could not read remote project registry for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
2069
+ });
2070
+ }
2071
+ if (registryResponse.status === 401 || registryResponse.status === 403) {
2072
+ return remoteProjectLinkFailure({
2073
+ status: "auth_required",
2074
+ alias,
2075
+ baseUrl,
2076
+ repoSlug,
2077
+ statusCode: registryResponse.status,
2078
+ message: `Remote server ${alias} requires authentication before reading the ${repoSlug} project registry.`
2079
+ });
2080
+ }
2081
+ if (registryResponse.ok) {
2082
+ const candidates = checkoutPathsFromProjectPayload(registryResponse.payload);
2083
+ for (const candidate of candidates) {
2084
+ const result = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate, source: "registry" });
2085
+ if (result.ok || result.status === "auth_required")
2086
+ return result;
2087
+ skippedCandidates.push(candidate);
2088
+ }
2089
+ if (mode === "backfill-only") {
2090
+ return remoteProjectLinkFailure({
2091
+ status: candidates.length > 0 ? "invalid_root" : "no_server_checkout",
2092
+ alias,
2093
+ baseUrl,
2094
+ repoSlug,
2095
+ message: candidates.length > 0 ? `Remote registry has checkout candidates for ${repoSlug}, but none validated for ${alias}.` : `Remote registry has ${repoSlug}, but no server checkout path is linked yet.`,
2096
+ skippedCandidates
2097
+ });
2098
+ }
2099
+ } else if (registryResponse.status === 404) {
2100
+ if (mode === "backfill-only") {
2101
+ return remoteProjectLinkFailure({
2102
+ status: "project_not_registered",
2103
+ alias,
2104
+ baseUrl,
2105
+ repoSlug,
2106
+ statusCode: registryResponse.status,
2107
+ message: `Remote server ${alias} has no registered project record for ${repoSlug}.`
2108
+ });
2109
+ }
2110
+ } else {
2111
+ return remoteProjectLinkFailure({
2112
+ status: "error",
2113
+ alias,
2114
+ baseUrl,
2115
+ repoSlug,
2116
+ statusCode: registryResponse.status,
2117
+ message: `Could not backfill ${repoSlug} from remote registry (${registryResponse.status}): ${payloadError(registryResponse.payload, registryResponse.text || "registry lookup failed")}`,
2118
+ skippedCandidates
2119
+ });
2120
+ }
2121
+ let prepareResponse;
2122
+ try {
2123
+ prepareResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}/prepare-checkout`, authToken, {
2124
+ method: "POST",
2125
+ headers: { "content-type": "application/json" },
2126
+ body: JSON.stringify({ checkout: { kind: "managed-clone" }, repoUrl: `https://github.com/${repoSlug}.git` })
2127
+ });
2128
+ } catch (error) {
2129
+ return remoteProjectLinkFailure({
2130
+ status: "error",
2131
+ alias,
2132
+ baseUrl,
2133
+ repoSlug,
2134
+ message: `Could not prepare remote checkout for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
2135
+ });
2136
+ }
2137
+ if (prepareResponse.status === 401 || prepareResponse.status === 403) {
2138
+ return remoteProjectLinkFailure({
2139
+ status: "auth_required",
2140
+ alias,
2141
+ baseUrl,
2142
+ repoSlug,
2143
+ statusCode: prepareResponse.status,
2144
+ message: `Remote server ${alias} requires authentication before preparing ${repoSlug}.`
2145
+ });
2146
+ }
2147
+ if (!prepareResponse.ok) {
2148
+ return remoteProjectLinkFailure({
2149
+ status: "error",
2150
+ alias,
2151
+ baseUrl,
2152
+ repoSlug,
2153
+ statusCode: prepareResponse.status,
2154
+ message: `Remote checkout prepare failed for ${repoSlug} (${prepareResponse.status}): ${payloadError(prepareResponse.payload, prepareResponse.text || "prepare-checkout failed")}`,
2155
+ skippedCandidates
2156
+ });
2157
+ }
2158
+ const preparedPath = checkoutPathFromPreparePayload(prepareResponse.payload);
2159
+ if (!preparedPath) {
2160
+ return remoteProjectLinkFailure({
2161
+ status: "invalid_root",
2162
+ alias,
2163
+ baseUrl,
2164
+ repoSlug,
2165
+ message: `Remote checkout prepare for ${repoSlug} did not return a checkout.path.`,
2166
+ skippedCandidates
2167
+ });
2168
+ }
2169
+ return validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: preparedPath, source: "prepare", prepared: true });
2170
+ }
1726
2171
  async function ensureServerForCli(projectRoot) {
1727
2172
  try {
1728
2173
  const selected = resolveSelectedConnection(projectRoot);
1729
2174
  if (selected?.connection.kind === "remote") {
1730
2175
  reportServerPhase(`Connecting to ${selected.alias}\u2026`);
1731
2176
  const authToken = readGitHubBearerTokenForRemote(projectRoot);
1732
- const serverProjectRoot = selected.serverProjectRoot ?? inferRemoteServerProjectRootFromAuthState(projectRoot) ?? await backfillRemoteServerProjectRoot(projectRoot, selected.connection.baseUrl, authToken);
2177
+ const link = await ensureRemoteProjectRootLink(projectRoot, { mode: "backfill-only", authToken });
1733
2178
  return {
1734
2179
  baseUrl: selected.connection.baseUrl,
1735
2180
  authToken,
1736
2181
  connectionKind: "remote",
1737
- serverProjectRoot
2182
+ serverProjectRoot: link.ok ? link.serverProjectRoot ?? null : null
1738
2183
  };
1739
2184
  }
1740
2185
  reportServerPhase("Starting local Rig server\u2026");
@@ -1752,32 +2197,6 @@ async function ensureServerForCli(projectRoot) {
1752
2197
  throw error;
1753
2198
  }
1754
2199
  }
1755
- async function backfillRemoteServerProjectRoot(projectRoot, baseUrl, authToken) {
1756
- const repo = readRepoConnection(projectRoot);
1757
- const slug = repo?.project?.trim();
1758
- if (!slug)
1759
- return null;
1760
- try {
1761
- const url = new URL(`${baseUrl}/api/projects/${encodeURIComponent(slug)}`);
1762
- if (authToken && queryAuthFallbackEnabled())
1763
- url.searchParams.set("rt", authToken);
1764
- const response = await fetch(url, {
1765
- headers: mergeHeaders(undefined, authToken)
1766
- });
1767
- if (!response.ok)
1768
- return null;
1769
- const payload = await response.json();
1770
- const project = payload.project && typeof payload.project === "object" && !Array.isArray(payload.project) ? payload.project : null;
1771
- const checkouts = Array.isArray(project?.checkouts) ? project.checkouts : [];
1772
- const latestCheckout = [...checkouts].reverse().find((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry) && typeof entry.path === "string"));
1773
- const path = typeof latestCheckout?.path === "string" && latestCheckout.path.trim() ? latestCheckout.path.trim() : null;
1774
- if (path)
1775
- writeRepoServerProjectRoot(projectRoot, path);
1776
- return path;
1777
- } catch {
1778
- return null;
1779
- }
1780
- }
1781
2200
  function mergeCookie(existing, name, value) {
1782
2201
  const encoded = `${name}=${encodeURIComponent(value)}`;
1783
2202
  if (!existing?.trim())
@@ -3549,6 +3968,48 @@ function renderAsciiPreloaderFrame(scene, layout, tick) {
3549
3968
  };
3550
3969
  }
3551
3970
 
3971
+ // packages/cli/src/app-opentui/remote-link.ts
3972
+ var REPAIRABLE_REMOTE_LINK_STATUSES = new Set([
3973
+ "auth_required",
3974
+ "project_not_registered",
3975
+ "no_server_checkout",
3976
+ "invalid_root",
3977
+ "needs_prepare",
3978
+ "error"
3979
+ ]);
3980
+ function remoteProjectLinkError(message) {
3981
+ return /no server-host project root link|remote project(?:-root)? link|x-rig-project-root|serverProjectRoot/i.test(message ?? "");
3982
+ }
3983
+ function serverRecordForRemoteLink(state) {
3984
+ const server = state.data.server;
3985
+ return server && typeof server === "object" && !Array.isArray(server) ? server : null;
3986
+ }
3987
+ function remoteProjectLinkState(state) {
3988
+ const serverRecord = serverRecordForRemoteLink(state);
3989
+ if (!serverRecord || serverRecord.kind !== "remote")
3990
+ return null;
3991
+ const link = serverRecord.remoteProjectLink;
3992
+ if (link && typeof link === "object" && !Array.isArray(link))
3993
+ return link;
3994
+ const direct = state.data.remoteProjectLink;
3995
+ if (direct && typeof direct === "object" && !Array.isArray(direct))
3996
+ return direct;
3997
+ return null;
3998
+ }
3999
+ function shouldOfferRemoteLinkRepair(state, message) {
4000
+ const link = remoteProjectLinkState(state);
4001
+ if (link) {
4002
+ if (link.ok === true)
4003
+ return false;
4004
+ const status = link.status ?? "";
4005
+ return REPAIRABLE_REMOTE_LINK_STATUSES.has(status);
4006
+ }
4007
+ const serverRecord = serverRecordForRemoteLink(state);
4008
+ if (serverRecord && serverRecord.kind !== "remote")
4009
+ return false;
4010
+ return remoteProjectLinkError(message ?? state.error?.message);
4011
+ }
4012
+
3552
4013
  // packages/cli/src/app-opentui/selectable.ts
3553
4014
  function selectableDeckRow(deck, item) {
3554
4015
  return { ...deckRow({ ...deck, activateOnClick: true }), selectable: item };
@@ -3558,13 +4019,17 @@ function selectableDeckRow(deck, item) {
3558
4019
  var ERROR_ACTIONS = [
3559
4020
  { detail: "return to dashboard", item: { id: "main", label: "main", intent: { scene: "main", argv: [], action: { kind: "refresh", label: "Back to dashboard" } }, message: "back to dashboard" } },
3560
4021
  { detail: "run diagnostics", item: { id: "doctor", label: "doctor", intent: { scene: "doctor", argv: ["doctor"], action: { kind: "doctor-run", label: "Run doctor" } }, message: "run diagnostics" } },
3561
- { detail: "open server controls", item: { id: "server", label: "server", intent: { scene: "server", argv: ["server", "status"], action: { kind: "refresh", label: "Open server controls" } }, message: "open server controls" } },
3562
- { detail: "repair project/server/auth link", item: { id: "repair", label: "repair", intent: { scene: "command", argv: ["init", "--repair"], action: { kind: "command-run", label: "Repair project link" } }, message: "repair project link" } }
4022
+ { detail: "open server controls", item: { id: "server", label: "server", intent: { scene: "server", argv: ["server", "status"], action: { kind: "refresh", label: "Open server controls" } }, message: "open server controls" } }
3563
4023
  ];
4024
+ var ERROR_REPAIR_LINK_ACTION = { detail: "backfill or prepare selected remote project-root link", item: { id: "repair-link", label: "repair link", intent: { scene: "server", argv: ["server", "repair-link"], action: { kind: "remote-link-repair", label: "Repair remote link", payload: { returnScene: "server" } } }, message: "repair remote project link" } };
4025
+ function errorActions(state) {
4026
+ return shouldOfferRemoteLinkRepair(state, state.error?.message) ? [...ERROR_ACTIONS, ERROR_REPAIR_LINK_ACTION] : ERROR_ACTIONS;
4027
+ }
3564
4028
  function renderErrorScene(state) {
3565
4029
  const message = state.error?.message ?? "Unknown app error";
3566
4030
  const hint = state.error?.hint ?? "Use the actions below to recover.";
3567
- const selected = Math.max(0, Math.min(3, state.selection.index));
4031
+ const actions = errorActions(state);
4032
+ const selected = Math.max(0, Math.min(actions.length - 1, state.selection.index));
3568
4033
  return makeSceneFrame({
3569
4034
  scene: "error",
3570
4035
  title: "Error",
@@ -3582,7 +4047,7 @@ function renderErrorScene(state) {
3582
4047
  ...hint ? [line(hint, { fg: RIG_UI.yellow })] : [],
3583
4048
  line("", { fg: RIG_UI.ink3 }),
3584
4049
  line("ACTIONS", { fg: RIG_UI.ink3, bold: true }),
3585
- ...ERROR_ACTIONS.map(({ detail, item }, index) => selectableDeckRow({ label: item.label, detail, index, active: selected === index }, item))
4050
+ ...actions.map(({ detail, item }, index) => selectableDeckRow({ label: item.label, detail, index, active: selected === index }, item))
3586
4051
  ],
3587
4052
  backgroundColor: RIG_UI.panel,
3588
4053
  backgroundAlpha: 184,
@@ -3710,7 +4175,7 @@ function renderHelpScene(state, layout) {
3710
4175
 
3711
4176
  // packages/cli/src/app-opentui/scenes/main.ts
3712
4177
  var CONFIGURED_MENU = [
3713
- ["init", "setup, reconfigure, repair project state", { id: "init", label: "init", intent: { scene: "command", argv: ["init"], action: { kind: "command-run", label: "Run init" } }, message: "run setup/reconfigure flow" }],
4178
+ ["init", "guided setup, reconfigure, repair project state", { id: "init", label: "init", intent: { scene: "init", argv: ["init"], action: { kind: "refresh", label: "Open init" } }, message: "open native init flow" }],
3714
4179
  ["server", "local/remote target, auth, linkage", { id: "server", label: "server", intent: { scene: "server", argv: ["server", "status"], action: { kind: "refresh", label: "Checking server" } }, message: "check selected server" }],
3715
4180
  ["github", "auth, selected repo, stored token", { id: "github", label: "github", intent: { scene: "server", argv: ["github", "auth", "status"], action: { kind: "refresh", label: "Checking GitHub auth" } }, message: "check GitHub auth" }],
3716
4181
  ["tasks", "browse, filter, dispatch, attach active work", { id: "tasks", label: "tasks", intent: { scene: "tasks", argv: ["tasks"], action: { kind: "refresh", label: "Opening tasks" } }, message: "selected tasks" }],
@@ -3729,10 +4194,10 @@ var CONFIGURED_MENU = [
3729
4194
  ["help", "all actions, shortcuts, mouse controls", { id: "help", label: "help", intent: { scene: "help", argv: ["help"], action: { kind: "none", label: "Opening help" } }, message: "selected help" }]
3730
4195
  ];
3731
4196
  var ONBOARD_PRIMARY = {
3732
- id: "onboard-setup",
3733
- label: "Start guided setup",
3734
- intent: { scene: "init", argv: ["init"], action: { kind: "refresh", label: "Setup" } },
3735
- message: "open the guided setup checklist"
4197
+ id: "onboard-init",
4198
+ label: "Start guided init",
4199
+ intent: { scene: "init", argv: ["init"], action: { kind: "refresh", label: "Init" } },
4200
+ message: "open the native init checklist"
3736
4201
  };
3737
4202
  var ONBOARD_SECONDARY = [
3738
4203
  ["server", "select a local or remote target", { id: "server", label: "server", intent: { scene: "server", argv: ["server", "status"], action: { kind: "refresh", label: "Checking server" } }, message: "check selected server" }],
@@ -3795,7 +4260,7 @@ function configuredMenuRows(selectedIndex) {
3795
4260
  }));
3796
4261
  }
3797
4262
  function onboardingRows(selectedIndex) {
3798
- const primary = selectableDeckRow({ label: "setup", detail: "Start guided setup \u2014 recommended", active: selectedIndex === 0 }, ONBOARD_PRIMARY);
4263
+ const primary = selectableDeckRow({ label: "init", detail: "Start guided init \u2014 recommended", active: selectedIndex === 0 }, ONBOARD_PRIMARY);
3799
4264
  const secondary = ONBOARD_SECONDARY.map(([label, detail, item], index) => ({
3800
4265
  ...deckRow({ label, detail, index: index + 1, active: selectedIndex === index + 1, activateOnClick: true }),
3801
4266
  selectable: item
@@ -3859,7 +4324,7 @@ function renderMainScene(state, layout) {
3859
4324
  statusLine(state)
3860
4325
  ] : [
3861
4326
  line("WELCOME", { fg: RIG_UI.ink, bold: true }),
3862
- line("This project isn't set up yet. One guided flow gets you running.", { fg: RIG_UI.ink2 }),
4327
+ line("This project isn't initialized yet. One native init flow gets you running.", { fg: RIG_UI.ink2 }),
3863
4328
  blank(),
3864
4329
  line("GET STARTED", { fg: RIG_UI.ink, bold: true }),
3865
4330
  ...onboardingRows(actionSelected),
@@ -3894,6 +4359,12 @@ function renderMainScene(state, layout) {
3894
4359
  });
3895
4360
  }
3896
4361
 
4362
+ // packages/cli/src/app-opentui/pi-pty-host.ts
4363
+ function getActivePiHost() {
4364
+ return null;
4365
+ }
4366
+ function stopActivePiHost(_reason) {}
4367
+
3897
4368
  // packages/cli/src/app-opentui/runtime.ts
3898
4369
  var MAX_SCENE_LINES = 200;
3899
4370
  var MAX_SCENE_PANELS = 5;
@@ -3914,7 +4385,7 @@ var PRIMARY_NAV = [
3914
4385
  { id: "tasks", label: "Tasks", scene: "tasks", argv: ["tasks"], enterLabel: "Tasks", member: ["tasks"] },
3915
4386
  { id: "inbox", label: "Inbox", scene: "inbox", argv: ["inbox"], enterLabel: "Inbox", member: ["inbox"], badge: inboxPendingCount },
3916
4387
  { id: "stats", label: "Stats", scene: "family", argv: ["stats"], enterLabel: "Stats", member: ["family"] },
3917
- { id: "setup", label: "Setup", scene: "init", argv: ["init"], enterLabel: "Setup", member: ["init", "doctor", "server", "pi", "plugin", "repo", "workspace"] },
4388
+ { id: "init", label: "Init", scene: "init", argv: ["init"], enterLabel: "Init", member: ["init", "doctor", "server", "pi", "plugin", "repo", "workspace"] },
3918
4389
  { id: "help", label: "Help", scene: "help", argv: ["help"], enterLabel: "Help", member: ["help"] }
3919
4390
  ];
3920
4391
  function navSectionIntent(section) {
@@ -3954,7 +4425,7 @@ function entryIntentForScene(scene) {
3954
4425
  case "doctor":
3955
4426
  return { scene, argv: ["doctor"], action: { kind: "doctor-run", label: "Doctor" } };
3956
4427
  case "init":
3957
- return { scene, argv: ["init"], action: { kind: "refresh", label: "Setup" } };
4428
+ return { scene, argv: ["init"], action: { kind: "refresh", label: "Init" } };
3958
4429
  case "run-detail":
3959
4430
  return { scene, argv: ["run", "status"], action: { kind: "refresh", label: "Run" } };
3960
4431
  case "pi":
@@ -4070,7 +4541,7 @@ function sceneSectionLabel(scene) {
4070
4541
  handoff: "pi console",
4071
4542
  server: "server",
4072
4543
  doctor: "doctor",
4073
- init: "setup",
4544
+ init: "init",
4074
4545
  pi: "pi",
4075
4546
  plugin: "plugins",
4076
4547
  repo: "repo",
@@ -4561,7 +5032,7 @@ async function launchRigOpenTuiApp(options) {
4561
5032
  }
4562
5033
  for (const adapter of options.adapters ?? [])
4563
5034
  await adapter.start?.(runtime);
4564
- liveEvents = await connectRigServerEvents(options.projectRoot, {
5035
+ connectRigServerEvents(options.projectRoot, {
4565
5036
  onSnapshotInvalidated: () => refreshCurrentDataScene(),
4566
5037
  onRunLogAppended: () => {
4567
5038
  const scene = store.getState().scene;
@@ -4569,11 +5040,17 @@ async function launchRigOpenTuiApp(options) {
4569
5040
  refreshCurrentDataScene();
4570
5041
  },
4571
5042
  onStatus: (status) => store.patch({ footer: { live: liveLinkLabel(status) } })
4572
- }).catch(() => null);
4573
- if (!liveEvents)
4574
- store.patch({ footer: { live: liveLinkLabel("disconnected") } });
4575
- if (liveEvents)
5043
+ }).then((subscription) => {
5044
+ if (destroyed) {
5045
+ subscription.close();
5046
+ return;
5047
+ }
5048
+ liveEvents = subscription;
4576
5049
  resources.add(() => liveEvents?.close());
5050
+ }).catch(() => {
5051
+ if (!destroyed)
5052
+ store.patch({ footer: { live: liveLinkLabel("disconnected") } });
5053
+ });
4577
5054
  await runtime.runIntent(store.getState().intent);
4578
5055
  } catch (error) {
4579
5056
  const normalized = normalizeError(error);