@h-rig/cli 0.0.6-alpha.1 → 0.0.6-alpha.100

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 (120) hide show
  1. package/README.md +18 -19
  2. package/dist/bin/build-rig-binaries.d.ts +2 -0
  3. package/dist/bin/build-rig-binaries.js +22 -10
  4. package/dist/bin/rig.d.ts +72 -0
  5. package/dist/bin/rig.js +15742 -7203
  6. package/dist/config/rig-default-config.yml +5 -0
  7. package/dist/src/app/drone-ui.d.ts +34 -0
  8. package/dist/src/app/drone-ui.js +278 -0
  9. package/dist/src/commands/_async-ui.d.ts +10 -0
  10. package/dist/src/commands/_async-ui.js +121 -0
  11. package/dist/src/commands/_cli-format.d.ts +56 -0
  12. package/dist/src/commands/_cli-format.js +319 -0
  13. package/dist/src/commands/_config-env.d.ts +18 -0
  14. package/dist/src/commands/_config-env.js +22 -0
  15. package/dist/src/commands/_connection-state.d.ts +54 -0
  16. package/dist/src/commands/_connection-state.js +75 -11
  17. package/dist/src/commands/_doctor-checks.d.ts +46 -0
  18. package/dist/src/commands/_doctor-checks.js +95 -244
  19. package/dist/src/commands/_help-catalog.d.ts +29 -0
  20. package/dist/src/commands/_help-catalog.js +146 -0
  21. package/dist/src/commands/_inprocess-services.d.ts +33 -0
  22. package/dist/src/commands/_inprocess-services.js +102 -0
  23. package/dist/src/commands/_json-output.d.ts +11 -0
  24. package/dist/src/commands/_json-output.js +60 -0
  25. package/dist/src/commands/_lazy-reconcile.d.ts +34 -0
  26. package/dist/src/commands/_lazy-reconcile.js +102 -0
  27. package/dist/src/commands/_parsers.d.ts +15 -0
  28. package/dist/src/commands/_parsers.js +18 -11
  29. package/dist/src/commands/_paths.d.ts +11 -0
  30. package/dist/src/commands/_paths.js +1 -1
  31. package/dist/src/commands/_pi-frontend.d.ts +35 -0
  32. package/dist/src/commands/_pi-frontend.js +64 -0
  33. package/dist/src/commands/_pi-install.d.ts +42 -0
  34. package/dist/src/commands/_pi-install.js +19 -36
  35. package/dist/src/commands/_policy.d.ts +8 -0
  36. package/dist/src/commands/_policy.js +67 -19
  37. package/dist/src/commands/_probes.d.ts +1 -0
  38. package/dist/src/commands/_run-bridge.d.ts +114 -0
  39. package/dist/src/commands/_run-bridge.js +387 -0
  40. package/dist/src/commands/_run-diagnostics.d.ts +9 -0
  41. package/dist/src/commands/_run-diagnostics.js +51 -0
  42. package/dist/src/commands/_run-driver-helpers.d.ts +26 -0
  43. package/dist/src/commands/_run-driver-helpers.js +79 -230
  44. package/dist/src/commands/_run-projection.d.ts +50 -0
  45. package/dist/src/commands/_run-projection.js +349 -0
  46. package/dist/src/commands/_run-subcommands.d.ts +3 -0
  47. package/dist/src/commands/_run-subcommands.js +31 -0
  48. package/dist/src/commands/_spinner.d.ts +25 -0
  49. package/dist/src/commands/_spinner.js +65 -0
  50. package/dist/src/commands/agent.d.ts +3 -0
  51. package/dist/src/commands/agent.js +8690 -235
  52. package/dist/src/commands/config.d.ts +3 -0
  53. package/dist/src/commands/config.js +181 -0
  54. package/dist/src/commands/dist.d.ts +28 -0
  55. package/dist/src/commands/dist.js +44 -29
  56. package/dist/src/commands/doctor.d.ts +3 -0
  57. package/dist/src/commands/doctor.js +214 -245
  58. package/dist/src/commands/github.d.ts +3 -0
  59. package/dist/src/commands/github.js +237 -171
  60. package/dist/src/commands/inbox.d.ts +28 -0
  61. package/dist/src/commands/inbox.js +530 -111
  62. package/dist/src/commands/init.d.ts +64 -0
  63. package/dist/src/commands/init.js +941 -654
  64. package/dist/src/commands/inspect.d.ts +20 -0
  65. package/dist/src/commands/inspect.js +709 -119
  66. package/dist/src/commands/pi.d.ts +3 -0
  67. package/dist/src/commands/pi.js +177 -0
  68. package/dist/src/commands/plugin.d.ts +16 -0
  69. package/dist/src/commands/plugin.js +576 -29
  70. package/dist/src/commands/profile-and-review.d.ts +4 -0
  71. package/dist/src/commands/profile-and-review.js +112 -67
  72. package/dist/src/commands/queue.d.ts +3 -0
  73. package/dist/src/commands/queue.js +20 -20
  74. package/dist/src/commands/remote.d.ts +3 -0
  75. package/dist/src/commands/remote.js +883 -50
  76. package/dist/src/commands/repo-git-harness.d.ts +5 -0
  77. package/dist/src/commands/repo-git-harness.js +78 -28
  78. package/dist/src/commands/run.d.ts +21 -0
  79. package/dist/src/commands/run.js +17732 -618
  80. package/dist/src/commands/server.d.ts +3 -0
  81. package/dist/src/commands/server.js +166 -285
  82. package/dist/src/commands/setup.d.ts +16 -0
  83. package/dist/src/commands/setup.js +230 -267
  84. package/dist/src/commands/stats.d.ts +15 -0
  85. package/dist/src/commands/stats.js +632 -0
  86. package/dist/src/commands/task-run-driver.d.ts +94 -0
  87. package/dist/src/commands/task-run-driver.js +120 -1856
  88. package/dist/src/commands/task.d.ts +35 -0
  89. package/dist/src/commands/task.js +676 -1183
  90. package/dist/src/commands/test.d.ts +3 -0
  91. package/dist/src/commands/test.js +15 -8
  92. package/dist/src/commands/triage.d.ts +11 -0
  93. package/dist/src/commands/triage.js +227 -0
  94. package/dist/src/commands/workspace.d.ts +3 -0
  95. package/dist/src/commands/workspace.js +18 -11
  96. package/dist/src/commands.d.ts +13 -0
  97. package/dist/src/commands.js +16760 -7779
  98. package/dist/src/index.d.ts +4 -0
  99. package/dist/src/index.js +16880 -8223
  100. package/dist/src/launcher.d.ts +61 -0
  101. package/dist/src/launcher.js +81 -13
  102. package/dist/src/operator-cli.d.ts +2 -0
  103. package/dist/src/operator-cli.js +17867 -0
  104. package/dist/src/operator-entry.d.ts +1 -0
  105. package/dist/src/operator-entry.js +3 -0
  106. package/dist/src/runner.d.ts +47 -0
  107. package/dist/src/runner.js +19 -24
  108. package/dist/src/withMutedConsole.d.ts +2 -0
  109. package/package.json +21 -7
  110. package/dist/src/commands/_authority-runs.js +0 -110
  111. package/dist/src/commands/_operator-view.js +0 -322
  112. package/dist/src/commands/_preflight.js +0 -460
  113. package/dist/src/commands/_server-client.js +0 -364
  114. package/dist/src/commands/_snapshot-upload.js +0 -313
  115. package/dist/src/commands/_task-picker.js +0 -48
  116. package/dist/src/commands/browser.js +0 -890
  117. package/dist/src/commands/connect.js +0 -180
  118. package/dist/src/commands/inspector.js +0 -256
  119. package/dist/src/commands/task-report-bug.js +0 -1083
  120. package/dist/src/report-bug.js +0 -260
@@ -0,0 +1,3 @@
1
+ import { type RunnerContext } from "../runner";
2
+ import type { CommandOutcome } from "@rig/runtime";
3
+ export declare function executeServer(context: RunnerContext, args: string[]): Promise<CommandOutcome>;
@@ -1,12 +1,19 @@
1
1
  // @bun
2
2
  // packages/cli/src/runner.ts
3
3
  import { EventBus } from "@rig/runtime/control-plane/runtime/events";
4
- import { CliError } from "@rig/runtime/control-plane/errors";
4
+ import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
5
5
  import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
6
- import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
7
- import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
8
6
  import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
9
- import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
7
+
8
+ class CliError extends RuntimeCliError {
9
+ hint;
10
+ constructor(message, exitCode = 1, options = {}) {
11
+ super(message, exitCode);
12
+ if (options.hint?.trim()) {
13
+ this.hint = options.hint.trim();
14
+ }
15
+ }
16
+ }
10
17
  function takeOption(args, option) {
11
18
  const rest = [];
12
19
  let value;
@@ -15,7 +22,7 @@ function takeOption(args, option) {
15
22
  if (current === option) {
16
23
  const next = args[index + 1];
17
24
  if (!next || next.startsWith("-")) {
18
- throw new CliError(`Missing value for ${option}`);
25
+ throw new CliError(`Missing value for ${option}`, 1, { hint: `Provide a value after ${option}, e.g. \`${option} <value>\`.` });
19
26
  }
20
27
  value = next;
21
28
  index += 1;
@@ -34,49 +41,17 @@ Usage: ${usage}`);
34
41
  }
35
42
  }
36
43
 
37
- // packages/cli/src/commands/_authority-runs.ts
44
+ // packages/cli/src/commands/server.ts
38
45
  import {
39
- readAuthorityRun,
40
- readJsonlFile,
41
- resolveAuthorityRunDir,
42
- writeJsonFile
43
- } from "@rig/runtime/control-plane/authority-files";
44
-
45
- // packages/cli/src/commands/_paths.ts
46
- import { resolveMonorepoRoot } from "@rig/runtime/control-plane/native/utils";
47
-
48
- // packages/cli/src/commands/_authority-runs.ts
49
- function normalizeRuntimeAdapter(value) {
50
- const normalized = value?.trim().toLowerCase();
51
- if (!normalized) {
52
- return "pi";
53
- }
54
- if (normalized === "codex" || normalized === "codex-cli" || normalized === "codex-app-server" || normalized === "gpt-codex") {
55
- return "codex";
56
- }
57
- if (normalized === "pi" || normalized === "rig-pi" || normalized === "@rig/pi") {
58
- return "pi";
59
- }
60
- return "claude-code";
61
- }
62
-
63
- // packages/cli/src/commands/_server-client.ts
64
- import { spawnSync } from "child_process";
65
- import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
46
+ listManagedRemoteEndpoints,
47
+ removeManagedRemoteEndpoint,
48
+ resolveSelectedRemote as resolveSelectedRemote2,
49
+ upsertManagedRemoteEndpoint
50
+ } from "@rig/runtime/control-plane/remote";
66
51
 
67
52
  // packages/cli/src/commands/_connection-state.ts
68
53
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
69
- import { homedir } from "os";
70
54
  import { dirname, resolve } from "path";
71
- function resolveGlobalConnectionsPath(env = process.env) {
72
- const explicit = env.RIG_CONNECTIONS_FILE?.trim();
73
- if (explicit)
74
- return resolve(explicit);
75
- const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
76
- if (stateDir)
77
- return resolve(stateDir, "connections.json");
78
- return resolve(homedir(), ".rig", "connections.json");
79
- }
80
55
  function resolveRepoConnectionPath(projectRoot) {
81
56
  return resolve(projectRoot, ".rig", "state", "connection.json");
82
57
  }
@@ -86,37 +61,13 @@ function readJsonFile(path) {
86
61
  try {
87
62
  return JSON.parse(readFileSync(path, "utf8"));
88
63
  } catch (error) {
89
- throw new CliError2(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1);
64
+ throw new CliError(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1, { hint: "Fix or delete that file, then re-select a server with `rig server use <alias|local>`." });
90
65
  }
91
66
  }
92
- function normalizeConnection(value) {
93
- if (!value || typeof value !== "object" || Array.isArray(value))
94
- return null;
95
- const record = value;
96
- if (record.kind === "local")
97
- return { kind: "local", mode: "auto" };
98
- if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
99
- const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
100
- return { kind: "remote", baseUrl };
101
- }
102
- return null;
103
- }
104
- function readGlobalConnections(options = {}) {
105
- const path = resolveGlobalConnectionsPath(options.env ?? process.env);
106
- const payload = readJsonFile(path);
107
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
108
- return { connections: {} };
109
- }
110
- const rawConnections = payload.connections;
111
- const connections = {};
112
- if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
113
- for (const [alias, raw] of Object.entries(rawConnections)) {
114
- const connection = normalizeConnection(raw);
115
- if (connection)
116
- connections[alias] = connection;
117
- }
118
- }
119
- return { connections };
67
+ function writeJsonFile(path, value) {
68
+ mkdirSync(dirname(path), { recursive: true });
69
+ writeFileSync(path, `${JSON.stringify(value, null, 2)}
70
+ `, "utf8");
120
71
  }
121
72
  function readRepoConnection(projectRoot) {
122
73
  const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
@@ -129,238 +80,168 @@ function readRepoConnection(projectRoot) {
129
80
  return {
130
81
  selected,
131
82
  project: typeof record.project === "string" ? record.project : undefined,
132
- linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined
83
+ linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
84
+ serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined,
85
+ serverProjectRootAlias: typeof record.serverProjectRootAlias === "string" && record.serverProjectRootAlias.trim() ? record.serverProjectRootAlias.trim() : undefined,
86
+ serverProjectRootBaseUrl: typeof record.serverProjectRootBaseUrl === "string" && record.serverProjectRootBaseUrl.trim() ? record.serverProjectRootBaseUrl.trim().replace(/\/+$/, "") : undefined
133
87
  };
134
88
  }
135
- function resolveSelectedConnection(projectRoot, options = {}) {
136
- const repo = readRepoConnection(projectRoot);
137
- if (!repo)
138
- return null;
139
- if (repo.selected === "local")
140
- return { alias: "local", connection: { kind: "local", mode: "auto" } };
141
- const global = readGlobalConnections(options);
142
- const connection = global.connections[repo.selected];
143
- if (!connection) {
144
- throw new CliError2(`Selected Rig connection "${repo.selected}" was not found. Run \`rig connect list\` or \`rig connect use local\`.`, 1);
145
- }
146
- return { alias: repo.selected, connection };
89
+ function writeRepoConnection(projectRoot, state) {
90
+ writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
147
91
  }
148
92
 
149
- // packages/cli/src/commands/_server-client.ts
150
- var cachedGitHubBearerToken;
151
- function cleanToken(value) {
152
- const trimmed = value?.trim();
153
- return trimmed ? trimmed : null;
154
- }
155
- function readGitHubBearerTokenForRemote() {
156
- if (cachedGitHubBearerToken !== undefined)
157
- return cachedGitHubBearerToken;
158
- const envToken = cleanToken(process.env.RIG_GITHUB_TOKEN) ?? cleanToken(process.env.GITHUB_TOKEN) ?? cleanToken(process.env.GH_TOKEN);
159
- if (envToken) {
160
- cachedGitHubBearerToken = envToken;
161
- return cachedGitHubBearerToken;
162
- }
163
- const result = spawnSync("gh", ["auth", "token"], {
164
- encoding: "utf8",
165
- timeout: 5000,
166
- stdio: ["ignore", "pipe", "ignore"]
167
- });
168
- cachedGitHubBearerToken = result.status === 0 ? cleanToken(result.stdout) : null;
169
- return cachedGitHubBearerToken;
170
- }
171
- async function ensureServerForCli(projectRoot) {
172
- try {
173
- const selected = resolveSelectedConnection(projectRoot);
174
- if (selected?.connection.kind === "remote") {
175
- return {
176
- baseUrl: selected.connection.baseUrl,
177
- authToken: readGitHubBearerTokenForRemote(),
178
- connectionKind: "remote"
179
- };
180
- }
181
- const connection = await ensureLocalRigServerConnection(projectRoot);
182
- return {
183
- baseUrl: connection.baseUrl,
184
- authToken: connection.authToken,
185
- connectionKind: "local"
186
- };
187
- } catch (error) {
188
- if (error instanceof Error) {
189
- throw new CliError2(error.message, 1);
190
- }
191
- throw error;
192
- }
193
- }
194
- function mergeHeaders(headers, authToken) {
195
- const merged = new Headers(headers);
196
- if (authToken) {
197
- merged.set("authorization", `Bearer ${authToken}`);
198
- }
199
- return merged;
200
- }
201
- function diagnosticMessage(payload) {
202
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
203
- return null;
204
- const record = payload;
205
- const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
206
- const messages = diagnostics.flatMap((entry) => {
207
- if (!entry || typeof entry !== "object" || Array.isArray(entry))
208
- return [];
209
- const diagnostic = entry;
210
- const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
211
- const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
212
- return message ? [`${kind}: ${message}`] : [];
213
- });
214
- return messages.length > 0 ? messages.join("; ") : null;
215
- }
216
- async function requestServerJson(context, pathname, init = {}) {
217
- const server = await ensureServerForCli(context.projectRoot);
218
- const response = await fetch(`${server.baseUrl}${pathname}`, {
219
- ...init,
220
- headers: mergeHeaders(init.headers, server.authToken)
221
- });
222
- const text = await response.text();
223
- const payload = text.trim().length > 0 ? (() => {
224
- try {
225
- return JSON.parse(text);
226
- } catch {
227
- return null;
228
- }
229
- })() : null;
230
- if (!response.ok) {
231
- const diagnostics = diagnosticMessage(payload);
232
- const detail = diagnostics ?? (text || response.statusText);
233
- throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
234
- }
235
- return payload;
93
+ // packages/cli/src/commands/_run-bridge.ts
94
+ import { dirname as dirname2, resolve as resolve2 } from "path";
95
+ import { CUSTOM_TYPE_FOR, sessionIdFromSessionFile } from "@rig/contracts";
96
+ import { createPluginHost } from "@rig/core";
97
+ import { loadConfig } from "@rig/core/load-config";
98
+ import { resolveOwnerNamespaceKey, resolveRegistryBaseUrl, resolveRegistrySecret, resolveSelectedRemote } from "@rig/runtime/control-plane/remote";
99
+ import { listAgentRuntimes } from "@rig/runtime/control-plane/runtime/isolation";
100
+ import { createRegistryClient } from "@rig/relay-registry";
101
+ import {
102
+ listActiveCollabSessions as ompListActiveCollabSessions
103
+ } from "@oh-my-pi/pi-coding-agent/collab/api";
104
+ async function readSelectedTarget(projectRoot, env = process.env) {
105
+ const config = await loadConfig(resolve2(projectRoot));
106
+ const selected = resolveSelectedRemote(projectRoot, env);
107
+ return {
108
+ alias: selected?.alias ?? "local",
109
+ kind: selected ? "remote" : "local",
110
+ projectRoot,
111
+ status: "ready",
112
+ taskSource: config.taskSource.kind
113
+ };
236
114
  }
237
- async function submitTaskRunViaServer(context, input) {
238
- const isTaskRun = Boolean(input.taskId);
239
- const endpoint = isTaskRun ? "/api/runs/task" : "/api/runs/adhoc";
240
- const payload = await requestServerJson(context, endpoint, {
241
- method: "POST",
242
- headers: {
243
- "content-type": "application/json"
244
- },
245
- body: JSON.stringify({
246
- runId: input.runId,
247
- taskId: input.taskId,
248
- title: input.title,
249
- runtimeAdapter: input.runtimeAdapter,
250
- model: input.model,
251
- runtimeMode: input.runtimeMode,
252
- interactionMode: input.interactionMode,
253
- initialPrompt: input.initialPrompt,
254
- baselineMode: input.baselineMode,
255
- prMode: input.prMode,
256
- executionTarget: "local"
257
- })
258
- });
259
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
260
- throw new CliError2("Rig server returned an invalid run submission payload.", 1);
261
- }
262
- const runId = payload.runId;
263
- if (typeof runId !== "string" || runId.trim().length === 0) {
264
- throw new CliError2("Rig server returned no runId for the submitted run.", 1);
265
- }
266
- return { runId };
115
+
116
+ // packages/cli/src/commands/_cli-format.ts
117
+ import pc from "picocolors";
118
+ var dim = pc.dim;
119
+ var faintBar = pc.dim("\u2502");
120
+ var accent = pc.cyan;
121
+ function printFormattedOutput(message) {
122
+ console.log(message);
267
123
  }
268
124
 
269
125
  // packages/cli/src/commands/server.ts
270
- async function executeServer(context, args, options) {
271
- const [command = "start", ...rest] = args;
126
+ var DEFAULT_REMOTE_PORT = 22;
127
+ async function executeServer(context, args) {
128
+ const [command = "status", ...rest] = args;
129
+ const text = context.outputMode === "text";
130
+ const projectRoot = context.projectRoot;
272
131
  switch (command) {
273
- case "start": {
274
- let pending = rest;
275
- const hostResult = takeOption(pending, "--host");
276
- pending = hostResult.rest;
277
- const portResult = takeOption(pending, "--port");
278
- pending = portResult.rest;
279
- const pollResult = takeOption(pending, "--poll-ms");
280
- pending = pollResult.rest;
281
- const authTokenResult = takeOption(pending, "--auth-token");
282
- pending = authTokenResult.rest;
283
- requireNoExtraArgs(pending, "bun run rig server start [--host <host>] [--port <n>] [--poll-ms <n>] [--auth-token <token>]");
284
- const commandParts = ["bun", "run", "packages/server/src/server.ts", "start"];
285
- if (hostResult.value) {
286
- commandParts.push("--host", hostResult.value);
287
- }
288
- if (portResult.value) {
289
- commandParts.push("--port", portResult.value);
290
- }
291
- if (pollResult.value) {
292
- commandParts.push("--poll-ms", pollResult.value);
293
- }
294
- if (authTokenResult.value) {
295
- commandParts.push("--auth-token", authTokenResult.value);
132
+ case "status": {
133
+ requireNoExtraArgs(rest, "rig server status");
134
+ const target = await readSelectedTarget(projectRoot);
135
+ const remote = resolveSelectedRemote2(projectRoot);
136
+ if (text) {
137
+ printFormattedOutput(target.kind === "local" ? "Placement: local (runs execute on this machine)." : `Placement: remote \u2192 ${target.alias}${remote ? ` (${remote.host}:${remote.port})` : ""}`);
138
+ printFormattedOutput(`Task source: ${target.taskSource}`);
296
139
  }
297
- await context.runCommand(commandParts);
298
- return { ok: true, group: "server", command };
299
- }
300
- case "events":
301
- throw new CliError2("server events is not supported by the CLI wrapper. Use `rig inspector stream` for bounded event streaming, or start the server with `rig server start`.", 2);
302
- case "notify-test": {
303
- let pending = rest;
304
- const eventResult = takeOption(pending, "--event");
305
- pending = eventResult.rest;
306
- requireNoExtraArgs(pending, "bun run rig server notify-test [--event <type>]");
307
- const commandParts = ["bun", "run", "packages/server/src/server.ts", "notify-test"];
308
- if (eventResult.value) {
309
- commandParts.push("--event", eventResult.value);
310
- }
311
- await context.runCommand(commandParts);
312
- return { ok: true, group: "server", command, details: { event: eventResult.value || "manual.test" } };
313
- }
314
- case "task-run": {
315
- let pending = rest;
316
- const taskResult = takeOption(pending, "--task");
317
- pending = taskResult.rest;
318
- const titleResult = takeOption(pending, "--title");
319
- pending = titleResult.rest;
320
- const runtimeAdapterResult = takeOption(pending, "--runtime-adapter");
321
- pending = runtimeAdapterResult.rest;
322
- const modelResult = takeOption(pending, "--model");
323
- pending = modelResult.rest;
324
- const runtimeModeResult = takeOption(pending, "--runtime-mode");
325
- pending = runtimeModeResult.rest;
326
- const interactionModeResult = takeOption(pending, "--interaction-mode");
327
- pending = interactionModeResult.rest;
328
- const initialPromptResult = takeOption(pending, "--initial-prompt");
329
- pending = initialPromptResult.rest;
330
- const dirtyBaselineResult = takeOption(pending, "--dirty-baseline");
331
- pending = dirtyBaselineResult.rest;
332
- const prResult = takeOption(pending, "--pr");
333
- pending = prResult.rest;
334
- requireNoExtraArgs(pending, "bun run rig --run-id <run-id> server task-run [--task <id>] [--title <text>] [--runtime-adapter claude-code|codex|pi] [--model <model>] [--runtime-mode <mode>] [--interaction-mode <mode>] [--initial-prompt <text>] [--dirty-baseline head|dirty-snapshot] [--pr auto|ask|off]");
335
- if (!taskResult.value && !initialPromptResult.value && !titleResult.value) {
336
- throw new CliError2("server task-run requires either --task <id> or --initial-prompt/--title for an ad hoc run.", 2);
337
- }
338
- const input = {
339
- runId: context.runId,
340
- taskId: taskResult.value ?? undefined,
341
- title: titleResult.value ?? undefined,
342
- runtimeAdapter: normalizeRuntimeAdapter(runtimeAdapterResult.value),
343
- model: modelResult.value ?? undefined,
344
- runtimeMode: runtimeModeResult.value || "full-access",
345
- interactionMode: interactionModeResult.value || "default",
346
- initialPrompt: initialPromptResult.value ?? undefined,
347
- baselineMode: dirtyBaselineResult.value === "dirty-snapshot" ? "dirty-snapshot" : "head",
348
- prMode: prResult.value === "auto" || prResult.value === "ask" || prResult.value === "off" ? prResult.value : undefined
140
+ return {
141
+ ok: true,
142
+ group: "server",
143
+ command,
144
+ details: {
145
+ placement: target.kind,
146
+ alias: target.alias,
147
+ taskSource: target.taskSource,
148
+ ...remote ? { host: remote.host, port: remote.port } : {}
149
+ }
349
150
  };
350
- if (process.env.RIG_SERVER_INTERNAL_EXEC === "1") {
351
- await options.executeRigOwnedTaskRun(context, input);
352
- } else {
353
- await submitTaskRunViaServer(context, input);
151
+ }
152
+ case "list": {
153
+ requireNoExtraArgs(rest, "rig server list");
154
+ const endpoints = listManagedRemoteEndpoints(undefined, projectRoot);
155
+ const selected = readRepoConnection(projectRoot)?.selected ?? "local";
156
+ if (text) {
157
+ printFormattedOutput(`${selected === "local" ? "* " : " "}local \u2014 runs execute on this machine`);
158
+ if (endpoints.length === 0) {
159
+ printFormattedOutput(" (no remote endpoints; add one with `rig server add --alias <a> --host <h>`)");
160
+ }
161
+ for (const endpoint of endpoints) {
162
+ printFormattedOutput(`${selected === endpoint.alias ? "* " : " "}${endpoint.alias} \u2014 ${endpoint.host}:${endpoint.port}`);
163
+ }
354
164
  }
355
165
  return {
356
166
  ok: true,
357
167
  group: "server",
358
168
  command,
359
- details: { runId: context.runId, taskId: taskResult.value ?? null, title: titleResult.value ?? null }
169
+ details: { selected, endpoints: endpoints.map((e) => ({ alias: e.alias, host: e.host, port: e.port })) }
360
170
  };
361
171
  }
172
+ case "use": {
173
+ const [aliasArg, ...extra] = rest;
174
+ requireNoExtraArgs(extra, "rig server use <local|alias>");
175
+ const alias = (aliasArg ?? "").trim();
176
+ if (!alias) {
177
+ throw new CliError("rig server use requires a target.", 2, { hint: "rig server use local | rig server use <alias>" });
178
+ }
179
+ if (alias !== "local") {
180
+ const known = listManagedRemoteEndpoints(undefined, projectRoot).some((endpoint) => endpoint.alias === alias);
181
+ if (!known) {
182
+ throw new CliError(`Unknown remote endpoint: ${alias}`, 2, {
183
+ hint: "Run `rig server list`, or add it with `rig server add --alias <a> --host <h>`."
184
+ });
185
+ }
186
+ }
187
+ if (context.dryRun)
188
+ return { ok: true, group: "server", command, details: { selected: alias, dryRun: true } };
189
+ const prev = readRepoConnection(projectRoot);
190
+ writeRepoConnection(projectRoot, { ...prev ?? { selected: "local" }, selected: alias });
191
+ if (text)
192
+ printFormattedOutput(alias === "local" ? "Placement set to local." : `Placement set to remote \u2192 ${alias}.`);
193
+ return { ok: true, group: "server", command, details: { selected: alias } };
194
+ }
195
+ case "add": {
196
+ const aliasOpt = takeOption(rest, "--alias");
197
+ const hostOpt = takeOption(aliasOpt.rest, "--host");
198
+ const portOpt = takeOption(hostOpt.rest, "--port");
199
+ const tokenOpt = takeOption(portOpt.rest, "--token");
200
+ const positional = tokenOpt.rest.filter((arg) => !arg.startsWith("-"));
201
+ const alias = (aliasOpt.value ?? positional[0] ?? "").trim();
202
+ const host = (hostOpt.value ?? positional[1] ?? "").trim();
203
+ const portRaw = portOpt.value ?? positional[2];
204
+ if (!alias || !host) {
205
+ throw new CliError("rig server add requires --alias <a> and --host <h>.", 2, {
206
+ hint: "rig server add --alias prod --host prod.example.com --port 22"
207
+ });
208
+ }
209
+ const port = portRaw ? Number(portRaw) : DEFAULT_REMOTE_PORT;
210
+ if (!Number.isFinite(port))
211
+ throw new CliError(`Invalid --port: ${portRaw}`, 2);
212
+ if (context.dryRun)
213
+ return { ok: true, group: "server", command, details: { alias, host, port, dryRun: true } };
214
+ const saved = upsertManagedRemoteEndpoint({ alias, host, port, ...tokenOpt.value ? { token: tokenOpt.value } : {} }, undefined, projectRoot);
215
+ if (text) {
216
+ printFormattedOutput(`Saved remote endpoint ${saved.alias} \u2192 ${saved.host}:${saved.port}. Select it with \`rig server use ${saved.alias}\`.`);
217
+ }
218
+ return { ok: true, group: "server", command, details: { alias: saved.alias, host: saved.host, port: saved.port } };
219
+ }
220
+ case "remove": {
221
+ const [aliasArg, ...extra] = rest;
222
+ requireNoExtraArgs(extra, "rig server remove <alias>");
223
+ const alias = (aliasArg ?? "").trim();
224
+ if (!alias)
225
+ throw new CliError("rig server remove requires an alias.", 2);
226
+ if (context.dryRun)
227
+ return { ok: true, group: "server", command, details: { alias, dryRun: true } };
228
+ const removed = removeManagedRemoteEndpoint(alias, undefined, projectRoot);
229
+ if (text)
230
+ printFormattedOutput(removed ? `Removed remote endpoint ${alias}.` : `No remote endpoint named ${alias}.`);
231
+ return { ok: removed, group: "server", command, details: { alias, removed } };
232
+ }
233
+ case "start":
234
+ throw new CliError("rig server start is retired: there is no standalone Rig server process after the OMP migration.", 2, {
235
+ hint: "Runs execute locally (tmux) or on a selected remote \u2014 pick one with `rig server use local|<alias>`."
236
+ });
237
+ case "repair-link":
238
+ throw new CliError("rig server repair-link is retired with the standalone server.", 2, {
239
+ hint: "Select placement with `rig server use local|<alias>`."
240
+ });
362
241
  default:
363
- throw new CliError2(`Unknown server command: ${command}`);
242
+ throw new CliError(`Unknown server command: ${command}`, 1, {
243
+ hint: "Run `rig server --help` \u2014 commands are status|list|use|add|remove."
244
+ });
364
245
  }
365
246
  }
366
247
  export {
@@ -0,0 +1,16 @@
1
+ import { type RunnerContext } from "../runner";
2
+ import { type RigPluginWithRuntime } from "@rig/core";
3
+ import type { TaskSourceConfig } from "@rig/contracts";
4
+ import type { CommandOutcome } from "@rig/runtime";
5
+ export declare function executeSetup(context: RunnerContext, args: string[]): Promise<CommandOutcome>;
6
+ type SetupCheck = {
7
+ ok: boolean;
8
+ label: string;
9
+ hint?: string;
10
+ };
11
+ type SetupRigConfig = {
12
+ plugins?: readonly RigPluginWithRuntime[];
13
+ taskSource?: TaskSourceConfig;
14
+ };
15
+ export declare function buildTaskSourceKindSetupCheck(config: SetupRigConfig): SetupCheck | null;
16
+ export {};