@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
@@ -215,16 +215,31 @@ function taskViewIntent(argv, command = "", rest = [], raw) {
215
215
  const { payload, label } = taskViewPayload(command, rest);
216
216
  return intent("tasks", argv, "refresh", payload, label, raw);
217
217
  }
218
- function routeServer(argv, command, raw, checkingLabel) {
219
- if (!command || command === "status") {
218
+ function routeServer(argv, command, rest, raw, checkingLabel) {
219
+ if (!command || command === "status" || command === "list") {
220
220
  return intent("server", argv, "refresh", undefined, command ? checkingLabel : "Loading server", raw);
221
221
  }
222
+ if (command === "use") {
223
+ const alias = firstNonOption(rest);
224
+ if (alias === "local")
225
+ return intent("server", argv, "server-use-local", undefined, "Use local server", raw);
226
+ if (alias)
227
+ return intent("server", argv, "server-use-remote", { alias }, `Use ${alias}`, raw);
228
+ return intent("server", argv, "refresh", undefined, "Select a remote alias in Server", raw);
229
+ }
230
+ if (command === "add")
231
+ return intent("server", argv, "server-add-remote", { argv: [...argv] }, "Add remote server", raw);
232
+ if (command === "repair-link")
233
+ return intent("server", argv, "remote-link-repair", undefined, "Repair remote link", raw);
222
234
  return commandRunIntent(argv, raw);
223
235
  }
224
236
  function routeGithub(argv, command, rest, raw) {
225
237
  if (command === "auth" && (rest[0]?.toLowerCase() ?? "status") === "status" && rest.length <= 1) {
226
238
  return intent("server", argv, "refresh", undefined, "Checking GitHub auth", raw);
227
239
  }
240
+ if (command === "auth" && rest[0]?.toLowerCase() === "import-gh" && rest.length <= 1) {
241
+ return intent("server", argv, "github-auth-import", undefined, "Import GitHub auth", raw);
242
+ }
228
243
  return commandRunIntent(argv, raw);
229
244
  }
230
245
  function routeDoctor(argv, command, raw) {
@@ -273,11 +288,16 @@ function intentFromArgv(argv) {
273
288
  return commandRunIntent(argv);
274
289
  }
275
290
  if (normalizedGroup === "server")
276
- return routeServer(argv, normalizedCommand, undefined, "Checking server");
291
+ return routeServer(argv, normalizedCommand, rest, undefined, "Checking server");
277
292
  if (normalizedGroup === "github")
278
293
  return routeGithub(argv, normalizedCommand, rest);
279
- if (normalizedGroup === "init")
280
- return commandRunIntent(argv);
294
+ if (normalizedGroup === "init") {
295
+ if (!normalizedCommand)
296
+ return intent("init", argv, "refresh", undefined, "Open init");
297
+ if (rest.includes("--yes") || normalizedCommand === "--yes")
298
+ return intent("init", argv, "init-start", undefined, "Run init");
299
+ return intent("init", argv, "refresh", undefined, "Open init");
300
+ }
281
301
  if (normalizedGroup === "doctor")
282
302
  return routeDoctor(argv, normalizedCommand);
283
303
  if (normalizedGroup === "inbox")
@@ -340,12 +360,17 @@ function intentFromTypeBar(value) {
340
360
  return commandRunIntent(parts, value);
341
361
  return intent("tasks", parts, "refresh", undefined, "Select a task, then press Enter; or use run next", value);
342
362
  }
343
- if (first === "init")
344
- return commandRunIntent(parts, value);
363
+ if (first === "init") {
364
+ if (!second)
365
+ return intent("init", parts, "refresh", undefined, "Open init", value);
366
+ if (parts.includes("--yes"))
367
+ return intent("init", parts, "init-start", undefined, "Run init", value);
368
+ return intent("init", parts, "refresh", undefined, "Open init", value);
369
+ }
345
370
  if (first === "doctor")
346
371
  return routeDoctor(parts, second, value);
347
372
  if (first === "server")
348
- return routeServer(parts, second, value, "Loading server");
373
+ return routeServer(parts, second, rest, value, "Loading server");
349
374
  if (first === "github")
350
375
  return routeGithub(parts, second, rest, value);
351
376
  if (first === "inbox")
@@ -806,12 +831,13 @@ var PRIMARY_GROUPS = [
806
831
  {
807
832
  name: "server",
808
833
  summary: "Choose, inspect, and start the Rig server that owns tasks and runs.",
809
- usage: ["rig server <status|list|add|use|start> [options]"],
834
+ usage: ["rig server <status|list|add|use|repair-link|start> [options]"],
810
835
  commands: [
811
- { command: "status", description: "Show the selected server for this repo.", primary: true },
836
+ { command: "status", description: "Show the selected server and remote project-root link for this repo.", primary: true },
812
837
  { command: "use local", description: "Switch this repo to the local Rig server.", primary: true },
813
838
  { command: "add <alias> <url>", description: "Save a remote Rig server URL.", primary: true },
814
839
  { command: "use <alias>", description: "Select a saved remote server alias.", primary: true },
840
+ { command: "repair-link [--prepare|--backfill-only] [--repo owner/repo]", description: "Backfill or prepare the selected remote's server-host checkout link.", primary: true },
815
841
  { command: "list", description: "List saved local/remote server aliases.", primary: true },
816
842
  { command: "start [--host <host>] [--port <n>]", description: "Start a local rig-server process." }
817
843
  ],
@@ -819,6 +845,7 @@ var PRIMARY_GROUPS = [
819
845
  "rig server status",
820
846
  "rig server add prod https://where.rig-does.work",
821
847
  "rig server use prod",
848
+ "rig server repair-link --repo owner/repo",
822
849
  "rig server use local",
823
850
  "rig server start --port 3773"
824
851
  ],
@@ -1308,12 +1335,6 @@ function cycleCompletion(value, state, candidates = commandCandidates()) {
1308
1335
  return { value: matches[nextIndex], state: { base, index: nextIndex } };
1309
1336
  }
1310
1337
 
1311
- // packages/cli/src/app-opentui/pi-pty-host.ts
1312
- function getActivePiHost() {
1313
- return null;
1314
- }
1315
- function stopActivePiHost(_reason) {}
1316
-
1317
1338
  // packages/cli/src/app-opentui/keymap.ts
1318
1339
  var autocompleteState;
1319
1340
  function clearTypeBar(context, message) {
@@ -1323,22 +1344,15 @@ function clearTypeBar(context, message) {
1323
1344
  context.emitTypeBarPatch({ value: "", mode: "nav", prompt: undefined, message });
1324
1345
  }
1325
1346
  function handleEmbeddedTerminalKey(context, key) {
1326
- const state = context.getState();
1327
- const piHost = getActivePiHost();
1328
- const commandHost = getActiveCommandHost();
1329
- const host = state.scene === "handoff" ? piHost : state.scene === "command" ? commandHost : null;
1347
+ if (context.getState().scene !== "command")
1348
+ return false;
1349
+ const host = getActiveCommandHost();
1330
1350
  if (!host)
1331
1351
  return false;
1332
1352
  if (key.ctrl && key.name === "]") {
1333
- if (state.scene === "handoff") {
1334
- stopActivePiHost("operator detach");
1335
- clearTypeBar(context, "detached from Pi");
1336
- context.runAppAction("Opening runs", () => context.runtime.runIntent({ scene: "fleet", argv: ["runs"], action: { kind: "refresh", label: "Opening runs" } }));
1337
- } else {
1338
- stopActiveCommandHost("operator detach");
1339
- clearTypeBar(context, "closed command");
1340
- context.runAppAction("Project menu", () => context.runtime.runIntent({ scene: "main", argv: ["main"], action: { kind: "none", label: "Project menu" } }));
1341
- }
1353
+ stopActiveCommandHost("operator detach");
1354
+ clearTypeBar(context, "closed command");
1355
+ context.runAppAction("Project menu", () => context.runtime.runIntent({ scene: "main", argv: ["main"], action: { kind: "none", label: "Project menu" } }));
1342
1356
  return true;
1343
1357
  }
1344
1358
  const sequence = key.raw || key.sequence;
@@ -1591,8 +1605,8 @@ import { WsTransport } from "@rig/client";
1591
1605
  import { RIG_WS_CHANNELS } from "@rig/contracts";
1592
1606
 
1593
1607
  // packages/cli/src/commands/_server-client.ts
1594
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
1595
- import { resolve as resolve2 } from "path";
1608
+ import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
1609
+ import { dirname as dirname2, isAbsolute, resolve as resolve2 } from "path";
1596
1610
 
1597
1611
  // packages/cli/src/runner.ts
1598
1612
  import { EventBus } from "@rig/runtime/control-plane/runtime/events";
@@ -1684,12 +1698,28 @@ function readRepoConnection(projectRoot) {
1684
1698
  selected,
1685
1699
  project: typeof record.project === "string" ? record.project : undefined,
1686
1700
  linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
1687
- serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
1701
+ serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined,
1702
+ serverProjectRootAlias: typeof record.serverProjectRootAlias === "string" && record.serverProjectRootAlias.trim() ? record.serverProjectRootAlias.trim() : undefined,
1703
+ serverProjectRootBaseUrl: typeof record.serverProjectRootBaseUrl === "string" && record.serverProjectRootBaseUrl.trim() ? record.serverProjectRootBaseUrl.trim().replace(/\/+$/, "") : undefined
1688
1704
  };
1689
1705
  }
1690
1706
  function writeRepoConnection(projectRoot, state) {
1691
1707
  writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
1692
1708
  }
1709
+ function rootAllowedForSelection(repo, connection) {
1710
+ const root = repo.serverProjectRoot?.trim();
1711
+ if (!root)
1712
+ return;
1713
+ if (connection.kind === "remote") {
1714
+ if (repo.serverProjectRootAlias !== repo.selected)
1715
+ return;
1716
+ if (repo.serverProjectRootBaseUrl !== connection.baseUrl)
1717
+ return;
1718
+ } else if (repo.serverProjectRootAlias && repo.serverProjectRootAlias !== repo.selected) {
1719
+ return;
1720
+ }
1721
+ return root;
1722
+ }
1693
1723
  function resolveSelectedConnection(projectRoot, options = {}) {
1694
1724
  const repo = readRepoConnection(projectRoot);
1695
1725
  if (!repo)
@@ -1701,13 +1731,41 @@ function resolveSelectedConnection(projectRoot, options = {}) {
1701
1731
  if (!connection) {
1702
1732
  throw new CliError(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
1703
1733
  }
1704
- return { alias: repo.selected, connection, serverProjectRoot: repo.serverProjectRoot };
1734
+ return { alias: repo.selected, connection, serverProjectRoot: rootAllowedForSelection(repo, connection) };
1705
1735
  }
1706
- function writeRepoServerProjectRoot(projectRoot, serverProjectRoot) {
1736
+ function writeRepoServerProjectRoot(projectRoot, serverProjectRoot, metadata = {}) {
1707
1737
  const repo = readRepoConnection(projectRoot);
1708
1738
  if (!repo)
1709
1739
  return;
1710
- writeRepoConnection(projectRoot, { ...repo, serverProjectRoot });
1740
+ let inferred = metadata;
1741
+ if (!inferred.alias || !inferred.baseUrl) {
1742
+ try {
1743
+ const selected = resolveSelectedConnection(projectRoot);
1744
+ if (selected?.connection.kind === "remote") {
1745
+ inferred = {
1746
+ alias: inferred.alias ?? selected.alias,
1747
+ baseUrl: inferred.baseUrl ?? selected.connection.baseUrl
1748
+ };
1749
+ }
1750
+ } catch {}
1751
+ }
1752
+ writeRepoConnection(projectRoot, {
1753
+ ...repo,
1754
+ ...metadata.project ? { project: metadata.project } : {},
1755
+ serverProjectRoot,
1756
+ ...inferred.alias ? { serverProjectRootAlias: inferred.alias } : {},
1757
+ ...inferred.baseUrl ? { serverProjectRootBaseUrl: inferred.baseUrl.replace(/\/+$/, "") } : {}
1758
+ });
1759
+ }
1760
+ function clearRepoServerProjectRoot(projectRoot) {
1761
+ const repo = readRepoConnection(projectRoot);
1762
+ if (!repo)
1763
+ return;
1764
+ writeRepoConnection(projectRoot, {
1765
+ selected: repo.selected,
1766
+ ...repo.project ? { project: repo.project } : {},
1767
+ ...repo.linkedAt ? { linkedAt: repo.linkedAt } : {}
1768
+ });
1711
1769
  }
1712
1770
 
1713
1771
  // packages/cli/src/commands/_server-client.ts
@@ -1748,11 +1806,10 @@ function readStoredGitHubAuthToken(projectRoot) {
1748
1806
  const parsed = readRemoteAuthState(projectRoot);
1749
1807
  return parsed ? cleanToken(typeof parsed.token === "string" ? parsed.token : undefined) : null;
1750
1808
  }
1751
- function inferRemoteServerProjectRootFromAuthState(projectRoot) {
1752
- const repo = readRepoConnection(projectRoot);
1753
- const slug = repo?.project?.trim();
1754
- if (!slug || !/^[^/]+\/[^/]+$/.test(slug))
1809
+ function inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug) {
1810
+ if (!/^[^/]+\/[^/]+$/.test(repoSlug))
1755
1811
  return null;
1812
+ const repo = readRepoConnection(projectRoot);
1756
1813
  const auth = readRemoteAuthState(projectRoot);
1757
1814
  const authUpdatedAt = typeof auth?.updatedAt === "string" ? Date.parse(auth.updatedAt) : Number.NaN;
1758
1815
  const repoLinkedAt = typeof repo?.linkedAt === "string" ? Date.parse(repo.linkedAt) : Number.NaN;
@@ -1761,25 +1818,413 @@ function inferRemoteServerProjectRootFromAuthState(projectRoot) {
1761
1818
  const checkoutBaseDir = typeof auth?.checkoutBaseDir === "string" && auth.checkoutBaseDir.trim() ? auth.checkoutBaseDir.trim() : null;
1762
1819
  if (!checkoutBaseDir)
1763
1820
  return null;
1764
- const inferred = `${checkoutBaseDir.replace(/\/+$/, "")}/${slug}`;
1765
- writeRepoServerProjectRoot(projectRoot, inferred);
1766
- return inferred;
1821
+ return `${checkoutBaseDir.replace(/\/+$/, "")}/${repoSlug}`;
1767
1822
  }
1768
1823
  function readLocalConnectionFallbackToken(projectRoot) {
1769
1824
  return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
1770
1825
  }
1826
+ function normalizeRepoSlug(value) {
1827
+ const slug = value?.trim();
1828
+ return slug && /^[^/\s]+\/[^/\s]+$/.test(slug) ? slug : null;
1829
+ }
1830
+ function readProjectLinkSlug(projectRoot) {
1831
+ const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
1832
+ if (!existsSync2(path))
1833
+ return null;
1834
+ try {
1835
+ const parsed = JSON.parse(readFileSync2(path, "utf8"));
1836
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
1837
+ return null;
1838
+ return normalizeRepoSlug(typeof parsed.repoSlug === "string" ? String(parsed.repoSlug) : null);
1839
+ } catch {
1840
+ return null;
1841
+ }
1842
+ }
1843
+ function writeProjectLinkConnection(projectRoot, repoSlug, alias) {
1844
+ const path = resolve2(projectRoot, ".rig", "state", "project-link.json");
1845
+ mkdirSync2(dirname2(path), { recursive: true });
1846
+ writeFileSync2(path, `${JSON.stringify({ repoSlug, connection: alias, linkedAt: new Date().toISOString() }, null, 2)}
1847
+ `, "utf8");
1848
+ }
1849
+ function remoteLinkRepairCommand(repoSlug) {
1850
+ return repoSlug ? `rig server repair-link --repo ${repoSlug}` : "rig server repair-link --repo owner/repo";
1851
+ }
1852
+ function formatRemoteProjectLinkHint(resolution) {
1853
+ const repair = remoteLinkRepairCommand(resolution.repoSlug);
1854
+ if (resolution.status === "auth_required") {
1855
+ 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}` : ""}\`.`;
1856
+ }
1857
+ if (resolution.status === "missing_project") {
1858
+ return `Record the repo slug, then run \`${repair}\` (or \`rig init --repo owner/repo --server remote --github-auth device\`).`;
1859
+ }
1860
+ if (resolution.status === "not_remote")
1861
+ return "Select a remote server with `rig server use <alias>` before repairing a remote project link.";
1862
+ return `Run \`${repair}\` to backfill or prepare a server-host checkout for the selected remote${resolution.alias ? ` (${resolution.alias})` : ""}.`;
1863
+ }
1864
+ function remoteProjectLinkFailure(input) {
1865
+ const partial = {
1866
+ status: input.status,
1867
+ alias: input.alias,
1868
+ baseUrl: input.baseUrl,
1869
+ repoSlug: input.repoSlug
1870
+ };
1871
+ return {
1872
+ ok: false,
1873
+ ...input,
1874
+ hint: formatRemoteProjectLinkHint(partial),
1875
+ next: remoteLinkRepairCommand(input.repoSlug)
1876
+ };
1877
+ }
1878
+ function remoteProjectLinkSuccess(input) {
1879
+ return {
1880
+ ok: true,
1881
+ status: input.status,
1882
+ alias: input.alias,
1883
+ baseUrl: input.baseUrl,
1884
+ repoSlug: input.repoSlug,
1885
+ serverProjectRoot: input.serverProjectRoot,
1886
+ source: input.source,
1887
+ prepared: input.prepared ?? input.status === "prepared",
1888
+ validated: input.validated ?? false,
1889
+ message: input.message ?? `Remote project link ready for ${input.repoSlug}.`,
1890
+ hint: "Remote-scoped task/run/status requests will send x-rig-project-root for this server-host checkout.",
1891
+ next: "rig task list"
1892
+ };
1893
+ }
1894
+ function localCheckoutPathCandidate(projectRoot, candidate) {
1895
+ try {
1896
+ const local = resolve2(projectRoot);
1897
+ const resolved = resolve2(candidate);
1898
+ return resolved === local || resolved.startsWith(`${local}/`);
1899
+ } catch {
1900
+ return false;
1901
+ }
1902
+ }
1903
+ async function requestRemoteProjectLinkJson(baseUrl, pathname, authToken, init = {}) {
1904
+ const requestUrl = new URL(`${baseUrl}${pathname}`);
1905
+ if (authToken && queryAuthFallbackEnabled())
1906
+ requestUrl.searchParams.set("rt", authToken);
1907
+ const response = await fetch(requestUrl, {
1908
+ ...init,
1909
+ headers: mergeHeaders(init.headers, authToken)
1910
+ });
1911
+ const text = await response.text();
1912
+ const payload = text.trim().length > 0 ? (() => {
1913
+ try {
1914
+ return JSON.parse(text);
1915
+ } catch {
1916
+ return null;
1917
+ }
1918
+ })() : null;
1919
+ return { ok: response.ok, status: response.status, payload, text };
1920
+ }
1921
+ function payloadError(payload, fallback) {
1922
+ if (payload && typeof payload === "object" && !Array.isArray(payload)) {
1923
+ const record = payload;
1924
+ const value = record.error ?? record.message ?? record.reason;
1925
+ if (typeof value === "string" && value.trim())
1926
+ return value.trim();
1927
+ }
1928
+ return fallback;
1929
+ }
1930
+ function checkoutPathsFromProjectPayload(payload) {
1931
+ if (!payload || typeof payload !== "object" || Array.isArray(payload))
1932
+ return [];
1933
+ const project = payload.project;
1934
+ if (!project || typeof project !== "object" || Array.isArray(project))
1935
+ return [];
1936
+ const checkouts = project.checkouts;
1937
+ if (!Array.isArray(checkouts))
1938
+ return [];
1939
+ return [...checkouts].reverse().flatMap((entry) => {
1940
+ if (!entry || typeof entry !== "object" || Array.isArray(entry))
1941
+ return [];
1942
+ const path = entry.path;
1943
+ return typeof path === "string" && path.trim() ? [path.trim()] : [];
1944
+ });
1945
+ }
1946
+ function checkoutPathFromPreparePayload(payload) {
1947
+ if (!payload || typeof payload !== "object" || Array.isArray(payload))
1948
+ return null;
1949
+ const checkout = payload.checkout;
1950
+ if (!checkout || typeof checkout !== "object" || Array.isArray(checkout))
1951
+ return null;
1952
+ const path = checkout.path;
1953
+ return typeof path === "string" && path.trim() ? path.trim() : null;
1954
+ }
1955
+ async function validateAndPersistRemoteRoot(input) {
1956
+ const candidate = input.candidate.trim();
1957
+ if (!candidate || !isAbsolute(candidate)) {
1958
+ return remoteProjectLinkFailure({
1959
+ status: "invalid_root",
1960
+ alias: input.alias,
1961
+ baseUrl: input.baseUrl,
1962
+ repoSlug: input.repoSlug,
1963
+ message: `Remote project root candidate is not an absolute server-host path: ${candidate || "(empty)"}.`
1964
+ });
1965
+ }
1966
+ if (localCheckoutPathCandidate(input.projectRoot, candidate)) {
1967
+ return remoteProjectLinkFailure({
1968
+ status: "invalid_root",
1969
+ alias: input.alias,
1970
+ baseUrl: input.baseUrl,
1971
+ repoSlug: input.repoSlug,
1972
+ message: `Refusing to use local checkout path ${candidate} as a remote server project root.`
1973
+ });
1974
+ }
1975
+ let response;
1976
+ try {
1977
+ response = await requestRemoteProjectLinkJson(input.baseUrl, "/api/server/project-root", input.authToken, {
1978
+ method: "POST",
1979
+ headers: { "content-type": "application/json" },
1980
+ body: JSON.stringify({ projectRoot: candidate })
1981
+ });
1982
+ } catch (error) {
1983
+ return remoteProjectLinkFailure({
1984
+ status: "error",
1985
+ alias: input.alias,
1986
+ baseUrl: input.baseUrl,
1987
+ repoSlug: input.repoSlug,
1988
+ message: `Could not validate remote project root ${candidate}: ${error instanceof Error ? error.message : String(error)}`
1989
+ });
1990
+ }
1991
+ if (response.status === 401 || response.status === 403) {
1992
+ return remoteProjectLinkFailure({
1993
+ status: "auth_required",
1994
+ alias: input.alias,
1995
+ baseUrl: input.baseUrl,
1996
+ repoSlug: input.repoSlug,
1997
+ statusCode: response.status,
1998
+ message: `Remote server ${input.alias} requires authentication before validating project root ${candidate}.`
1999
+ });
2000
+ }
2001
+ if (!response.ok) {
2002
+ return remoteProjectLinkFailure({
2003
+ status: "invalid_root",
2004
+ alias: input.alias,
2005
+ baseUrl: input.baseUrl,
2006
+ repoSlug: input.repoSlug,
2007
+ statusCode: response.status,
2008
+ message: `Remote server rejected project root ${candidate} (${response.status}): ${payloadError(response.payload, response.text || "project-root validation failed")}`
2009
+ });
2010
+ }
2011
+ const record = response.payload && typeof response.payload === "object" && !Array.isArray(response.payload) ? response.payload : {};
2012
+ if (record.ok !== true) {
2013
+ return remoteProjectLinkFailure({
2014
+ status: "invalid_root",
2015
+ alias: input.alias,
2016
+ baseUrl: input.baseUrl,
2017
+ repoSlug: input.repoSlug,
2018
+ message: `Remote server did not accept project root ${candidate}: ${payloadError(response.payload, "project-root validation failed")}`
2019
+ });
2020
+ }
2021
+ const accepted = typeof record.projectRoot === "string" && record.projectRoot.trim() ? record.projectRoot.trim() : typeof record.requestedProjectRoot === "string" && record.requestedProjectRoot.trim() ? record.requestedProjectRoot.trim() : candidate;
2022
+ writeRepoServerProjectRoot(input.projectRoot, accepted, { alias: input.alias, baseUrl: input.baseUrl, project: input.repoSlug });
2023
+ writeProjectLinkConnection(input.projectRoot, input.repoSlug, input.alias);
2024
+ const status = input.status ?? (input.prepared ? "prepared" : "backfilled");
2025
+ return remoteProjectLinkSuccess({
2026
+ status,
2027
+ alias: input.alias,
2028
+ baseUrl: input.baseUrl,
2029
+ repoSlug: input.repoSlug,
2030
+ serverProjectRoot: accepted,
2031
+ source: input.source,
2032
+ prepared: input.prepared,
2033
+ validated: true,
2034
+ 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}.`
2035
+ });
2036
+ }
2037
+ async function ensureRemoteProjectRootLink(projectRoot, options = {}) {
2038
+ let selected;
2039
+ try {
2040
+ selected = resolveSelectedConnection(projectRoot);
2041
+ } catch (error) {
2042
+ return remoteProjectLinkFailure({ status: "error", message: error instanceof Error ? error.message : String(error) });
2043
+ }
2044
+ if (!selected || selected.connection.kind !== "remote") {
2045
+ return remoteProjectLinkFailure({ status: "not_remote", message: "No remote Rig server is selected for this repo." });
2046
+ }
2047
+ const repo = readRepoConnection(projectRoot);
2048
+ const explicitRepoRequested = options.repoSlug !== undefined;
2049
+ const explicitRepoSlug = explicitRepoRequested ? normalizeRepoSlug(options.repoSlug) : null;
2050
+ const repoProjectSlug = normalizeRepoSlug(repo?.project);
2051
+ const repoSlug = explicitRepoSlug ?? repoProjectSlug ?? readProjectLinkSlug(projectRoot);
2052
+ const alias = selected.alias;
2053
+ const baseUrl = selected.connection.baseUrl;
2054
+ const authToken = options.authToken === undefined ? readGitHubBearerTokenForRemote(projectRoot) : options.authToken;
2055
+ const mode = options.mode ?? "backfill-only";
2056
+ if (explicitRepoRequested && !explicitRepoSlug) {
2057
+ return remoteProjectLinkFailure({
2058
+ status: "missing_project",
2059
+ alias,
2060
+ baseUrl,
2061
+ message: `Invalid --repo value ${JSON.stringify(options.repoSlug)}. Expected owner/repo.`
2062
+ });
2063
+ }
2064
+ if (!repoSlug) {
2065
+ return remoteProjectLinkFailure({
2066
+ status: "missing_project",
2067
+ alias,
2068
+ baseUrl,
2069
+ message: `Remote server ${alias} is selected, but this checkout has no GitHub repo slug recorded.`
2070
+ });
2071
+ }
2072
+ const skippedCandidates = [];
2073
+ const storedRoot = selected.serverProjectRoot?.trim() || null;
2074
+ const storedRootMatchesResolvedRepo = repoProjectSlug === repoSlug;
2075
+ if (storedRoot && storedRootMatchesResolvedRepo) {
2076
+ if (localCheckoutPathCandidate(projectRoot, storedRoot)) {
2077
+ clearRepoServerProjectRoot(projectRoot);
2078
+ skippedCandidates.push(storedRoot);
2079
+ } else {
2080
+ const storedResult = await validateAndPersistRemoteRoot({
2081
+ projectRoot,
2082
+ alias,
2083
+ baseUrl,
2084
+ authToken,
2085
+ repoSlug,
2086
+ candidate: storedRoot,
2087
+ source: "stored",
2088
+ status: "ready"
2089
+ });
2090
+ if (storedResult.ok || storedResult.status === "auth_required" || storedResult.status === "error")
2091
+ return storedResult;
2092
+ clearRepoServerProjectRoot(projectRoot);
2093
+ skippedCandidates.push(storedRoot);
2094
+ }
2095
+ } else if (storedRoot) {
2096
+ skippedCandidates.push(storedRoot);
2097
+ }
2098
+ const authCandidate = inferRemoteServerProjectRootCandidateFromAuthState(projectRoot, repoSlug);
2099
+ if (authCandidate) {
2100
+ const authResult = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: authCandidate, source: "auth-state" });
2101
+ if (authResult.ok || authResult.status === "auth_required")
2102
+ return authResult;
2103
+ }
2104
+ let registryResponse;
2105
+ try {
2106
+ registryResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}`, authToken);
2107
+ } catch (error) {
2108
+ return remoteProjectLinkFailure({
2109
+ status: "error",
2110
+ alias,
2111
+ baseUrl,
2112
+ repoSlug,
2113
+ message: `Could not read remote project registry for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
2114
+ });
2115
+ }
2116
+ if (registryResponse.status === 401 || registryResponse.status === 403) {
2117
+ return remoteProjectLinkFailure({
2118
+ status: "auth_required",
2119
+ alias,
2120
+ baseUrl,
2121
+ repoSlug,
2122
+ statusCode: registryResponse.status,
2123
+ message: `Remote server ${alias} requires authentication before reading the ${repoSlug} project registry.`
2124
+ });
2125
+ }
2126
+ if (registryResponse.ok) {
2127
+ const candidates = checkoutPathsFromProjectPayload(registryResponse.payload);
2128
+ for (const candidate of candidates) {
2129
+ const result = await validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate, source: "registry" });
2130
+ if (result.ok || result.status === "auth_required")
2131
+ return result;
2132
+ skippedCandidates.push(candidate);
2133
+ }
2134
+ if (mode === "backfill-only") {
2135
+ return remoteProjectLinkFailure({
2136
+ status: candidates.length > 0 ? "invalid_root" : "no_server_checkout",
2137
+ alias,
2138
+ baseUrl,
2139
+ repoSlug,
2140
+ 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.`,
2141
+ skippedCandidates
2142
+ });
2143
+ }
2144
+ } else if (registryResponse.status === 404) {
2145
+ if (mode === "backfill-only") {
2146
+ return remoteProjectLinkFailure({
2147
+ status: "project_not_registered",
2148
+ alias,
2149
+ baseUrl,
2150
+ repoSlug,
2151
+ statusCode: registryResponse.status,
2152
+ message: `Remote server ${alias} has no registered project record for ${repoSlug}.`
2153
+ });
2154
+ }
2155
+ } else {
2156
+ return remoteProjectLinkFailure({
2157
+ status: "error",
2158
+ alias,
2159
+ baseUrl,
2160
+ repoSlug,
2161
+ statusCode: registryResponse.status,
2162
+ message: `Could not backfill ${repoSlug} from remote registry (${registryResponse.status}): ${payloadError(registryResponse.payload, registryResponse.text || "registry lookup failed")}`,
2163
+ skippedCandidates
2164
+ });
2165
+ }
2166
+ let prepareResponse;
2167
+ try {
2168
+ prepareResponse = await requestRemoteProjectLinkJson(baseUrl, `/api/projects/${encodeURIComponent(repoSlug)}/prepare-checkout`, authToken, {
2169
+ method: "POST",
2170
+ headers: { "content-type": "application/json" },
2171
+ body: JSON.stringify({ checkout: { kind: "managed-clone" }, repoUrl: `https://github.com/${repoSlug}.git` })
2172
+ });
2173
+ } catch (error) {
2174
+ return remoteProjectLinkFailure({
2175
+ status: "error",
2176
+ alias,
2177
+ baseUrl,
2178
+ repoSlug,
2179
+ message: `Could not prepare remote checkout for ${repoSlug} on ${alias}: ${error instanceof Error ? error.message : String(error)}`
2180
+ });
2181
+ }
2182
+ if (prepareResponse.status === 401 || prepareResponse.status === 403) {
2183
+ return remoteProjectLinkFailure({
2184
+ status: "auth_required",
2185
+ alias,
2186
+ baseUrl,
2187
+ repoSlug,
2188
+ statusCode: prepareResponse.status,
2189
+ message: `Remote server ${alias} requires authentication before preparing ${repoSlug}.`
2190
+ });
2191
+ }
2192
+ if (!prepareResponse.ok) {
2193
+ return remoteProjectLinkFailure({
2194
+ status: "error",
2195
+ alias,
2196
+ baseUrl,
2197
+ repoSlug,
2198
+ statusCode: prepareResponse.status,
2199
+ message: `Remote checkout prepare failed for ${repoSlug} (${prepareResponse.status}): ${payloadError(prepareResponse.payload, prepareResponse.text || "prepare-checkout failed")}`,
2200
+ skippedCandidates
2201
+ });
2202
+ }
2203
+ const preparedPath = checkoutPathFromPreparePayload(prepareResponse.payload);
2204
+ if (!preparedPath) {
2205
+ return remoteProjectLinkFailure({
2206
+ status: "invalid_root",
2207
+ alias,
2208
+ baseUrl,
2209
+ repoSlug,
2210
+ message: `Remote checkout prepare for ${repoSlug} did not return a checkout.path.`,
2211
+ skippedCandidates
2212
+ });
2213
+ }
2214
+ return validateAndPersistRemoteRoot({ projectRoot, alias, baseUrl, authToken, repoSlug, candidate: preparedPath, source: "prepare", prepared: true });
2215
+ }
1771
2216
  async function ensureServerForCli(projectRoot) {
1772
2217
  try {
1773
2218
  const selected = resolveSelectedConnection(projectRoot);
1774
2219
  if (selected?.connection.kind === "remote") {
1775
2220
  reportServerPhase(`Connecting to ${selected.alias}\u2026`);
1776
2221
  const authToken = readGitHubBearerTokenForRemote(projectRoot);
1777
- const serverProjectRoot = selected.serverProjectRoot ?? inferRemoteServerProjectRootFromAuthState(projectRoot) ?? await backfillRemoteServerProjectRoot(projectRoot, selected.connection.baseUrl, authToken);
2222
+ const link = await ensureRemoteProjectRootLink(projectRoot, { mode: "backfill-only", authToken });
1778
2223
  return {
1779
2224
  baseUrl: selected.connection.baseUrl,
1780
2225
  authToken,
1781
2226
  connectionKind: "remote",
1782
- serverProjectRoot
2227
+ serverProjectRoot: link.ok ? link.serverProjectRoot ?? null : null
1783
2228
  };
1784
2229
  }
1785
2230
  reportServerPhase("Starting local Rig server\u2026");
@@ -1797,32 +2242,6 @@ async function ensureServerForCli(projectRoot) {
1797
2242
  throw error;
1798
2243
  }
1799
2244
  }
1800
- async function backfillRemoteServerProjectRoot(projectRoot, baseUrl, authToken) {
1801
- const repo = readRepoConnection(projectRoot);
1802
- const slug = repo?.project?.trim();
1803
- if (!slug)
1804
- return null;
1805
- try {
1806
- const url = new URL(`${baseUrl}/api/projects/${encodeURIComponent(slug)}`);
1807
- if (authToken && queryAuthFallbackEnabled())
1808
- url.searchParams.set("rt", authToken);
1809
- const response = await fetch(url, {
1810
- headers: mergeHeaders(undefined, authToken)
1811
- });
1812
- if (!response.ok)
1813
- return null;
1814
- const payload = await response.json();
1815
- const project = payload.project && typeof payload.project === "object" && !Array.isArray(payload.project) ? payload.project : null;
1816
- const checkouts = Array.isArray(project?.checkouts) ? project.checkouts : [];
1817
- const latestCheckout = [...checkouts].reverse().find((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry) && typeof entry.path === "string"));
1818
- const path = typeof latestCheckout?.path === "string" && latestCheckout.path.trim() ? latestCheckout.path.trim() : null;
1819
- if (path)
1820
- writeRepoServerProjectRoot(projectRoot, path);
1821
- return path;
1822
- } catch {
1823
- return null;
1824
- }
1825
- }
1826
2245
  function mergeCookie(existing, name, value) {
1827
2246
  const encoded = `${name}=${encodeURIComponent(value)}`;
1828
2247
  if (!existing?.trim())
@@ -3315,6 +3734,48 @@ function destroyNativeHost(host) {
3315
3734
  } catch {}
3316
3735
  }
3317
3736
 
3737
+ // packages/cli/src/app-opentui/remote-link.ts
3738
+ var REPAIRABLE_REMOTE_LINK_STATUSES = new Set([
3739
+ "auth_required",
3740
+ "project_not_registered",
3741
+ "no_server_checkout",
3742
+ "invalid_root",
3743
+ "needs_prepare",
3744
+ "error"
3745
+ ]);
3746
+ function remoteProjectLinkError(message) {
3747
+ return /no server-host project root link|remote project(?:-root)? link|x-rig-project-root|serverProjectRoot/i.test(message ?? "");
3748
+ }
3749
+ function serverRecordForRemoteLink(state) {
3750
+ const server = state.data.server;
3751
+ return server && typeof server === "object" && !Array.isArray(server) ? server : null;
3752
+ }
3753
+ function remoteProjectLinkState(state) {
3754
+ const serverRecord = serverRecordForRemoteLink(state);
3755
+ if (!serverRecord || serverRecord.kind !== "remote")
3756
+ return null;
3757
+ const link = serverRecord.remoteProjectLink;
3758
+ if (link && typeof link === "object" && !Array.isArray(link))
3759
+ return link;
3760
+ const direct = state.data.remoteProjectLink;
3761
+ if (direct && typeof direct === "object" && !Array.isArray(direct))
3762
+ return direct;
3763
+ return null;
3764
+ }
3765
+ function shouldOfferRemoteLinkRepair(state, message) {
3766
+ const link = remoteProjectLinkState(state);
3767
+ if (link) {
3768
+ if (link.ok === true)
3769
+ return false;
3770
+ const status = link.status ?? "";
3771
+ return REPAIRABLE_REMOTE_LINK_STATUSES.has(status);
3772
+ }
3773
+ const serverRecord = serverRecordForRemoteLink(state);
3774
+ if (serverRecord && serverRecord.kind !== "remote")
3775
+ return false;
3776
+ return remoteProjectLinkError(message ?? state.error?.message);
3777
+ }
3778
+
3318
3779
  // packages/cli/src/app-opentui/selectable.ts
3319
3780
  function selectableDeckRow(deck, item) {
3320
3781
  return { ...deckRow({ ...deck, activateOnClick: true }), selectable: item };
@@ -3324,13 +3785,17 @@ function selectableDeckRow(deck, item) {
3324
3785
  var ERROR_ACTIONS = [
3325
3786
  { detail: "return to dashboard", item: { id: "main", label: "main", intent: { scene: "main", argv: [], action: { kind: "refresh", label: "Back to dashboard" } }, message: "back to dashboard" } },
3326
3787
  { detail: "run diagnostics", item: { id: "doctor", label: "doctor", intent: { scene: "doctor", argv: ["doctor"], action: { kind: "doctor-run", label: "Run doctor" } }, message: "run diagnostics" } },
3327
- { 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" } },
3328
- { 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" } }
3788
+ { 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" } }
3329
3789
  ];
3790
+ 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" } };
3791
+ function errorActions(state) {
3792
+ return shouldOfferRemoteLinkRepair(state, state.error?.message) ? [...ERROR_ACTIONS, ERROR_REPAIR_LINK_ACTION] : ERROR_ACTIONS;
3793
+ }
3330
3794
  function renderErrorScene(state) {
3331
3795
  const message = state.error?.message ?? "Unknown app error";
3332
3796
  const hint = state.error?.hint ?? "Use the actions below to recover.";
3333
- const selected = Math.max(0, Math.min(3, state.selection.index));
3797
+ const actions = errorActions(state);
3798
+ const selected = Math.max(0, Math.min(actions.length - 1, state.selection.index));
3334
3799
  return makeSceneFrame({
3335
3800
  scene: "error",
3336
3801
  title: "Error",
@@ -3348,7 +3813,7 @@ function renderErrorScene(state) {
3348
3813
  ...hint ? [line(hint, { fg: RIG_UI.yellow })] : [],
3349
3814
  line("", { fg: RIG_UI.ink3 }),
3350
3815
  line("ACTIONS", { fg: RIG_UI.ink3, bold: true }),
3351
- ...ERROR_ACTIONS.map(({ detail, item }, index) => selectableDeckRow({ label: item.label, detail, index, active: selected === index }, item))
3816
+ ...actions.map(({ detail, item }, index) => selectableDeckRow({ label: item.label, detail, index, active: selected === index }, item))
3352
3817
  ],
3353
3818
  backgroundColor: RIG_UI.panel,
3354
3819
  backgroundAlpha: 184,
@@ -3476,7 +3941,7 @@ function renderHelpScene(state, layout) {
3476
3941
 
3477
3942
  // packages/cli/src/app-opentui/scenes/main.ts
3478
3943
  var CONFIGURED_MENU = [
3479
- ["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" }],
3944
+ ["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" }],
3480
3945
  ["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" }],
3481
3946
  ["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" }],
3482
3947
  ["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" }],
@@ -3495,10 +3960,10 @@ var CONFIGURED_MENU = [
3495
3960
  ["help", "all actions, shortcuts, mouse controls", { id: "help", label: "help", intent: { scene: "help", argv: ["help"], action: { kind: "none", label: "Opening help" } }, message: "selected help" }]
3496
3961
  ];
3497
3962
  var ONBOARD_PRIMARY = {
3498
- id: "onboard-setup",
3499
- label: "Start guided setup",
3500
- intent: { scene: "init", argv: ["init"], action: { kind: "refresh", label: "Setup" } },
3501
- message: "open the guided setup checklist"
3963
+ id: "onboard-init",
3964
+ label: "Start guided init",
3965
+ intent: { scene: "init", argv: ["init"], action: { kind: "refresh", label: "Init" } },
3966
+ message: "open the native init checklist"
3502
3967
  };
3503
3968
  var ONBOARD_SECONDARY = [
3504
3969
  ["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" }],
@@ -3561,7 +4026,7 @@ function configuredMenuRows(selectedIndex) {
3561
4026
  }));
3562
4027
  }
3563
4028
  function onboardingRows(selectedIndex) {
3564
- const primary = selectableDeckRow({ label: "setup", detail: "Start guided setup \u2014 recommended", active: selectedIndex === 0 }, ONBOARD_PRIMARY);
4029
+ const primary = selectableDeckRow({ label: "init", detail: "Start guided init \u2014 recommended", active: selectedIndex === 0 }, ONBOARD_PRIMARY);
3565
4030
  const secondary = ONBOARD_SECONDARY.map(([label, detail, item], index) => ({
3566
4031
  ...deckRow({ label, detail, index: index + 1, active: selectedIndex === index + 1, activateOnClick: true }),
3567
4032
  selectable: item
@@ -3625,7 +4090,7 @@ function renderMainScene(state, layout) {
3625
4090
  statusLine(state)
3626
4091
  ] : [
3627
4092
  line("WELCOME", { fg: RIG_UI.ink, bold: true }),
3628
- line("This project isn't set up yet. One guided flow gets you running.", { fg: RIG_UI.ink2 }),
4093
+ line("This project isn't initialized yet. One native init flow gets you running.", { fg: RIG_UI.ink2 }),
3629
4094
  blank(),
3630
4095
  line("GET STARTED", { fg: RIG_UI.ink, bold: true }),
3631
4096
  ...onboardingRows(actionSelected),
@@ -3677,7 +4142,7 @@ var PRIMARY_NAV = [
3677
4142
  { id: "tasks", label: "Tasks", scene: "tasks", argv: ["tasks"], enterLabel: "Tasks", member: ["tasks"] },
3678
4143
  { id: "inbox", label: "Inbox", scene: "inbox", argv: ["inbox"], enterLabel: "Inbox", member: ["inbox"], badge: inboxPendingCount },
3679
4144
  { id: "stats", label: "Stats", scene: "family", argv: ["stats"], enterLabel: "Stats", member: ["family"] },
3680
- { id: "setup", label: "Setup", scene: "init", argv: ["init"], enterLabel: "Setup", member: ["init", "doctor", "server", "pi", "plugin", "repo", "workspace"] },
4145
+ { id: "init", label: "Init", scene: "init", argv: ["init"], enterLabel: "Init", member: ["init", "doctor", "server", "pi", "plugin", "repo", "workspace"] },
3681
4146
  { id: "help", label: "Help", scene: "help", argv: ["help"], enterLabel: "Help", member: ["help"] }
3682
4147
  ];
3683
4148
  function activeNavSection(scene) {
@@ -3698,7 +4163,7 @@ function entryIntentForScene(scene) {
3698
4163
  case "doctor":
3699
4164
  return { scene, argv: ["doctor"], action: { kind: "doctor-run", label: "Doctor" } };
3700
4165
  case "init":
3701
- return { scene, argv: ["init"], action: { kind: "refresh", label: "Setup" } };
4166
+ return { scene, argv: ["init"], action: { kind: "refresh", label: "Init" } };
3702
4167
  case "run-detail":
3703
4168
  return { scene, argv: ["run", "status"], action: { kind: "refresh", label: "Run" } };
3704
4169
  case "pi":
@@ -3732,7 +4197,7 @@ function sceneSectionLabel(scene) {
3732
4197
  handoff: "pi console",
3733
4198
  server: "server",
3734
4199
  doctor: "doctor",
3735
- init: "setup",
4200
+ init: "init",
3736
4201
  pi: "pi",
3737
4202
  plugin: "plugins",
3738
4203
  repo: "repo",
@@ -4137,7 +4602,7 @@ var PRIMARY_NAV2 = [
4137
4602
  { id: "tasks", label: "Tasks", scene: "tasks", argv: ["tasks"], enterLabel: "Tasks", member: ["tasks"] },
4138
4603
  { id: "inbox", label: "Inbox", scene: "inbox", argv: ["inbox"], enterLabel: "Inbox", member: ["inbox"], badge: inboxPendingCount2 },
4139
4604
  { id: "stats", label: "Stats", scene: "family", argv: ["stats"], enterLabel: "Stats", member: ["family"] },
4140
- { id: "setup", label: "Setup", scene: "init", argv: ["init"], enterLabel: "Setup", member: ["init", "doctor", "server", "pi", "plugin", "repo", "workspace"] },
4605
+ { id: "init", label: "Init", scene: "init", argv: ["init"], enterLabel: "Init", member: ["init", "doctor", "server", "pi", "plugin", "repo", "workspace"] },
4141
4606
  { id: "help", label: "Help", scene: "help", argv: ["help"], enterLabel: "Help", member: ["help"] }
4142
4607
  ];
4143
4608
  function navSectionIntent(section) {
@@ -4401,7 +4866,7 @@ async function launchRigReactApp(options) {
4401
4866
  }
4402
4867
  for (const adapter of options.adapters ?? [])
4403
4868
  await adapter.start?.(runtime);
4404
- liveEvents = await connectRigServerEvents(options.projectRoot, {
4869
+ connectRigServerEvents(options.projectRoot, {
4405
4870
  onSnapshotInvalidated: () => refreshCurrentDataScene(),
4406
4871
  onRunLogAppended: () => {
4407
4872
  const scene = store.getState().scene;
@@ -4409,9 +4874,11 @@ async function launchRigReactApp(options) {
4409
4874
  refreshCurrentDataScene();
4410
4875
  },
4411
4876
  onStatus: (status) => store.patch({ footer: { live: liveLinkLabel(status) } })
4412
- }).catch(() => null);
4413
- if (!liveEvents)
4877
+ }).then((subscription) => {
4878
+ liveEvents = subscription;
4879
+ }).catch(() => {
4414
4880
  store.patch({ footer: { live: liveLinkLabel("disconnected") } });
4881
+ });
4415
4882
  await runtime.runIntent(store.getState().intent);
4416
4883
  } catch (error) {
4417
4884
  const n = normalizeError(error);