@h-rig/cli 0.0.6-alpha.9 → 0.0.6-alpha.91

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 (116) 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 +15637 -7344
  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/_connection-state.d.ts +54 -0
  14. package/dist/src/commands/_connection-state.js +75 -11
  15. package/dist/src/commands/_doctor-checks.d.ts +46 -0
  16. package/dist/src/commands/_doctor-checks.js +100 -267
  17. package/dist/src/commands/_help-catalog.d.ts +51 -0
  18. package/dist/src/commands/_help-catalog.js +502 -0
  19. package/dist/src/commands/_inprocess-services.d.ts +33 -0
  20. package/dist/src/commands/_inprocess-services.js +102 -0
  21. package/dist/src/commands/_json-output.d.ts +11 -0
  22. package/dist/src/commands/_json-output.js +60 -0
  23. package/dist/src/commands/_lazy-reconcile.d.ts +34 -0
  24. package/dist/src/commands/_lazy-reconcile.js +102 -0
  25. package/dist/src/commands/_parsers.d.ts +15 -0
  26. package/dist/src/commands/_parsers.js +18 -11
  27. package/dist/src/commands/_paths.d.ts +11 -0
  28. package/dist/src/commands/_paths.js +1 -1
  29. package/dist/src/commands/_pi-frontend.d.ts +35 -0
  30. package/dist/src/commands/_pi-frontend.js +64 -0
  31. package/dist/src/commands/_pi-install.d.ts +42 -0
  32. package/dist/src/commands/_pi-install.js +19 -36
  33. package/dist/src/commands/_policy.d.ts +8 -0
  34. package/dist/src/commands/_policy.js +67 -19
  35. package/dist/src/commands/_probes.d.ts +1 -0
  36. package/dist/src/commands/_run-bridge.d.ts +114 -0
  37. package/dist/src/commands/_run-bridge.js +387 -0
  38. package/dist/src/commands/_run-diagnostics.d.ts +9 -0
  39. package/dist/src/commands/_run-diagnostics.js +51 -0
  40. package/dist/src/commands/_run-driver-helpers.d.ts +26 -0
  41. package/dist/src/commands/_run-driver-helpers.js +79 -230
  42. package/dist/src/commands/_run-projection.d.ts +50 -0
  43. package/dist/src/commands/_run-projection.js +349 -0
  44. package/dist/src/commands/_run-subcommands.d.ts +3 -0
  45. package/dist/src/commands/_run-subcommands.js +31 -0
  46. package/dist/src/commands/_spinner.d.ts +25 -0
  47. package/dist/src/commands/_spinner.js +65 -0
  48. package/dist/src/commands/agent.d.ts +3 -0
  49. package/dist/src/commands/agent.js +8575 -236
  50. package/dist/src/commands/dist.d.ts +28 -0
  51. package/dist/src/commands/dist.js +44 -29
  52. package/dist/src/commands/doctor.d.ts +3 -0
  53. package/dist/src/commands/doctor.js +219 -268
  54. package/dist/src/commands/github.d.ts +3 -0
  55. package/dist/src/commands/github.js +236 -188
  56. package/dist/src/commands/inbox.d.ts +28 -0
  57. package/dist/src/commands/inbox.js +530 -111
  58. package/dist/src/commands/init.d.ts +64 -0
  59. package/dist/src/commands/init.js +912 -705
  60. package/dist/src/commands/inspect.d.ts +20 -0
  61. package/dist/src/commands/inspect.js +709 -119
  62. package/dist/src/commands/pi.d.ts +3 -0
  63. package/dist/src/commands/pi.js +177 -0
  64. package/dist/src/commands/plugin.d.ts +16 -0
  65. package/dist/src/commands/plugin.js +576 -29
  66. package/dist/src/commands/profile-and-review.d.ts +4 -0
  67. package/dist/src/commands/profile-and-review.js +112 -67
  68. package/dist/src/commands/queue.d.ts +3 -0
  69. package/dist/src/commands/queue.js +20 -20
  70. package/dist/src/commands/remote.d.ts +3 -0
  71. package/dist/src/commands/remote.js +880 -50
  72. package/dist/src/commands/repo-git-harness.d.ts +5 -0
  73. package/dist/src/commands/repo-git-harness.js +78 -28
  74. package/dist/src/commands/run.d.ts +21 -0
  75. package/dist/src/commands/run.js +17701 -661
  76. package/dist/src/commands/server.d.ts +3 -0
  77. package/dist/src/commands/server.js +166 -303
  78. package/dist/src/commands/setup.d.ts +16 -0
  79. package/dist/src/commands/setup.js +244 -299
  80. package/dist/src/commands/stats.d.ts +15 -0
  81. package/dist/src/commands/stats.js +979 -0
  82. package/dist/src/commands/task-run-driver.d.ts +94 -0
  83. package/dist/src/commands/task-run-driver.js +116 -1961
  84. package/dist/src/commands/task.d.ts +35 -0
  85. package/dist/src/commands/task.js +676 -1201
  86. package/dist/src/commands/test.d.ts +3 -0
  87. package/dist/src/commands/test.js +15 -8
  88. package/dist/src/commands/triage.d.ts +11 -0
  89. package/dist/src/commands/triage.js +227 -0
  90. package/dist/src/commands/workspace.d.ts +3 -0
  91. package/dist/src/commands/workspace.js +18 -11
  92. package/dist/src/commands.d.ts +13 -0
  93. package/dist/src/commands.js +16792 -8055
  94. package/dist/src/index.d.ts +4 -0
  95. package/dist/src/index.js +16862 -8450
  96. package/dist/src/launcher.d.ts +61 -0
  97. package/dist/src/launcher.js +81 -13
  98. package/dist/src/operator-cli.d.ts +2 -0
  99. package/dist/src/operator-cli.js +17837 -0
  100. package/dist/src/operator-entry.d.ts +1 -0
  101. package/dist/src/operator-entry.js +3 -0
  102. package/dist/src/runner.d.ts +47 -0
  103. package/dist/src/runner.js +16 -22
  104. package/dist/src/withMutedConsole.d.ts +2 -0
  105. package/package.json +21 -8
  106. package/dist/src/commands/_authority-runs.js +0 -111
  107. package/dist/src/commands/_operator-view.js +0 -340
  108. package/dist/src/commands/_preflight.js +0 -478
  109. package/dist/src/commands/_server-client.js +0 -382
  110. package/dist/src/commands/_snapshot-upload.js +0 -331
  111. package/dist/src/commands/_task-picker.js +0 -48
  112. package/dist/src/commands/browser.js +0 -890
  113. package/dist/src/commands/connect.js +0 -180
  114. package/dist/src/commands/inspector.js +0 -256
  115. package/dist/src/commands/task-report-bug.js +0 -1083
  116. 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,51 +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 { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
66
- import { resolve as resolve2 } from "path";
67
- import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
46
+ listManagedRemoteEndpoints,
47
+ removeManagedRemoteEndpoint,
48
+ resolveSelectedRemote as resolveSelectedRemote2,
49
+ upsertManagedRemoteEndpoint
50
+ } from "@rig/runtime/control-plane/remote";
68
51
 
69
52
  // packages/cli/src/commands/_connection-state.ts
70
53
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
71
- import { homedir } from "os";
72
54
  import { dirname, resolve } from "path";
73
- function resolveGlobalConnectionsPath(env = process.env) {
74
- const explicit = env.RIG_CONNECTIONS_FILE?.trim();
75
- if (explicit)
76
- return resolve(explicit);
77
- const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
78
- if (stateDir)
79
- return resolve(stateDir, "connections.json");
80
- return resolve(homedir(), ".rig", "connections.json");
81
- }
82
55
  function resolveRepoConnectionPath(projectRoot) {
83
56
  return resolve(projectRoot, ".rig", "state", "connection.json");
84
57
  }
@@ -88,37 +61,13 @@ function readJsonFile(path) {
88
61
  try {
89
62
  return JSON.parse(readFileSync(path, "utf8"));
90
63
  } catch (error) {
91
- 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>`." });
92
65
  }
93
66
  }
94
- function normalizeConnection(value) {
95
- if (!value || typeof value !== "object" || Array.isArray(value))
96
- return null;
97
- const record = value;
98
- if (record.kind === "local")
99
- return { kind: "local", mode: "auto" };
100
- if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
101
- const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
102
- return { kind: "remote", baseUrl };
103
- }
104
- return null;
105
- }
106
- function readGlobalConnections(options = {}) {
107
- const path = resolveGlobalConnectionsPath(options.env ?? process.env);
108
- const payload = readJsonFile(path);
109
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
110
- return { connections: {} };
111
- }
112
- const rawConnections = payload.connections;
113
- const connections = {};
114
- if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
115
- for (const [alias, raw] of Object.entries(rawConnections)) {
116
- const connection = normalizeConnection(raw);
117
- if (connection)
118
- connections[alias] = connection;
119
- }
120
- }
121
- return { connections };
67
+ function writeJsonFile(path, value) {
68
+ mkdirSync(dirname(path), { recursive: true });
69
+ writeFileSync(path, `${JSON.stringify(value, null, 2)}
70
+ `, "utf8");
122
71
  }
123
72
  function readRepoConnection(projectRoot) {
124
73
  const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
@@ -131,254 +80,168 @@ function readRepoConnection(projectRoot) {
131
80
  return {
132
81
  selected,
133
82
  project: typeof record.project === "string" ? record.project : undefined,
134
- 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
135
87
  };
136
88
  }
137
- function resolveSelectedConnection(projectRoot, options = {}) {
138
- const repo = readRepoConnection(projectRoot);
139
- if (!repo)
140
- return null;
141
- if (repo.selected === "local")
142
- return { alias: "local", connection: { kind: "local", mode: "auto" } };
143
- const global = readGlobalConnections(options);
144
- const connection = global.connections[repo.selected];
145
- if (!connection) {
146
- throw new CliError2(`Selected Rig connection "${repo.selected}" was not found. Run \`rig connect list\` or \`rig connect use local\`.`, 1);
147
- }
148
- return { alias: repo.selected, connection };
89
+ function writeRepoConnection(projectRoot, state) {
90
+ writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
149
91
  }
150
92
 
151
- // packages/cli/src/commands/_server-client.ts
152
- var cachedGitHubBearerToken;
153
- function cleanToken(value) {
154
- const trimmed = value?.trim();
155
- return trimmed ? trimmed : null;
156
- }
157
- function readPrivateRemoteSessionToken(projectRoot) {
158
- const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
159
- if (!existsSync2(path))
160
- return null;
161
- try {
162
- const parsed = JSON.parse(readFileSync2(path, "utf8"));
163
- return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
164
- } catch {
165
- return null;
166
- }
167
- }
168
- function readGitHubBearerTokenForRemote(projectRoot) {
169
- if (cachedGitHubBearerToken !== undefined)
170
- return cachedGitHubBearerToken;
171
- const privateSession = readPrivateRemoteSessionToken(projectRoot);
172
- if (privateSession) {
173
- cachedGitHubBearerToken = privateSession;
174
- return cachedGitHubBearerToken;
175
- }
176
- const envToken = cleanToken(process.env.RIG_GITHUB_TOKEN) ?? cleanToken(process.env.GITHUB_TOKEN) ?? cleanToken(process.env.GH_TOKEN);
177
- if (envToken) {
178
- cachedGitHubBearerToken = envToken;
179
- return cachedGitHubBearerToken;
180
- }
181
- const result = spawnSync("gh", ["auth", "token"], {
182
- encoding: "utf8",
183
- timeout: 5000,
184
- stdio: ["ignore", "pipe", "ignore"]
185
- });
186
- cachedGitHubBearerToken = result.status === 0 ? cleanToken(result.stdout) : null;
187
- return cachedGitHubBearerToken;
188
- }
189
- async function ensureServerForCli(projectRoot) {
190
- try {
191
- const selected = resolveSelectedConnection(projectRoot);
192
- if (selected?.connection.kind === "remote") {
193
- return {
194
- baseUrl: selected.connection.baseUrl,
195
- authToken: readGitHubBearerTokenForRemote(projectRoot),
196
- connectionKind: "remote"
197
- };
198
- }
199
- const connection = await ensureLocalRigServerConnection(projectRoot);
200
- return {
201
- baseUrl: connection.baseUrl,
202
- authToken: connection.authToken,
203
- connectionKind: "local"
204
- };
205
- } catch (error) {
206
- if (error instanceof Error) {
207
- throw new CliError2(error.message, 1);
208
- }
209
- throw error;
210
- }
211
- }
212
- function mergeHeaders(headers, authToken) {
213
- const merged = new Headers(headers);
214
- if (authToken) {
215
- merged.set("authorization", `Bearer ${authToken}`);
216
- }
217
- return merged;
218
- }
219
- function diagnosticMessage(payload) {
220
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
221
- return null;
222
- const record = payload;
223
- const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
224
- const messages = diagnostics.flatMap((entry) => {
225
- if (!entry || typeof entry !== "object" || Array.isArray(entry))
226
- return [];
227
- const diagnostic = entry;
228
- const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
229
- const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
230
- return message ? [`${kind}: ${message}`] : [];
231
- });
232
- return messages.length > 0 ? messages.join("; ") : null;
233
- }
234
- async function requestServerJson(context, pathname, init = {}) {
235
- const server = await ensureServerForCli(context.projectRoot);
236
- const response = await fetch(`${server.baseUrl}${pathname}`, {
237
- ...init,
238
- headers: mergeHeaders(init.headers, server.authToken)
239
- });
240
- const text = await response.text();
241
- const payload = text.trim().length > 0 ? (() => {
242
- try {
243
- return JSON.parse(text);
244
- } catch {
245
- return null;
246
- }
247
- })() : null;
248
- if (!response.ok) {
249
- const diagnostics = diagnosticMessage(payload);
250
- const detail = diagnostics ?? (text || response.statusText);
251
- throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
252
- }
253
- 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
+ };
254
114
  }
255
- async function submitTaskRunViaServer(context, input) {
256
- const isTaskRun = Boolean(input.taskId);
257
- const endpoint = isTaskRun ? "/api/runs/task" : "/api/runs/adhoc";
258
- const payload = await requestServerJson(context, endpoint, {
259
- method: "POST",
260
- headers: {
261
- "content-type": "application/json"
262
- },
263
- body: JSON.stringify({
264
- runId: input.runId,
265
- taskId: input.taskId,
266
- title: input.title,
267
- runtimeAdapter: input.runtimeAdapter,
268
- model: input.model,
269
- runtimeMode: input.runtimeMode,
270
- interactionMode: input.interactionMode,
271
- initialPrompt: input.initialPrompt,
272
- baselineMode: input.baselineMode,
273
- prMode: input.prMode,
274
- executionTarget: "local"
275
- })
276
- });
277
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
278
- throw new CliError2("Rig server returned an invalid run submission payload.", 1);
279
- }
280
- const runId = payload.runId;
281
- if (typeof runId !== "string" || runId.trim().length === 0) {
282
- throw new CliError2("Rig server returned no runId for the submitted run.", 1);
283
- }
284
- 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);
285
123
  }
286
124
 
287
125
  // packages/cli/src/commands/server.ts
288
- async function executeServer(context, args, options) {
289
- 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;
290
131
  switch (command) {
291
- case "start": {
292
- let pending = rest;
293
- const hostResult = takeOption(pending, "--host");
294
- pending = hostResult.rest;
295
- const portResult = takeOption(pending, "--port");
296
- pending = portResult.rest;
297
- const pollResult = takeOption(pending, "--poll-ms");
298
- pending = pollResult.rest;
299
- const authTokenResult = takeOption(pending, "--auth-token");
300
- pending = authTokenResult.rest;
301
- requireNoExtraArgs(pending, "bun run rig server start [--host <host>] [--port <n>] [--poll-ms <n>] [--auth-token <token>]");
302
- const commandParts = ["rig-server", "start"];
303
- if (hostResult.value) {
304
- commandParts.push("--host", hostResult.value);
305
- }
306
- if (portResult.value) {
307
- commandParts.push("--port", portResult.value);
308
- }
309
- if (pollResult.value) {
310
- commandParts.push("--poll-ms", pollResult.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}`);
311
139
  }
312
- if (authTokenResult.value) {
313
- commandParts.push("--auth-token", authTokenResult.value);
314
- }
315
- await context.runCommand(commandParts);
316
- return { ok: true, group: "server", command };
317
- }
318
- case "events":
319
- 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);
320
- case "notify-test": {
321
- let pending = rest;
322
- const eventResult = takeOption(pending, "--event");
323
- pending = eventResult.rest;
324
- requireNoExtraArgs(pending, "bun run rig server notify-test [--event <type>]");
325
- const commandParts = ["rig-server", "notify-test"];
326
- if (eventResult.value) {
327
- commandParts.push("--event", eventResult.value);
328
- }
329
- await context.runCommand(commandParts);
330
- return { ok: true, group: "server", command, details: { event: eventResult.value || "manual.test" } };
331
- }
332
- case "task-run": {
333
- let pending = rest;
334
- const taskResult = takeOption(pending, "--task");
335
- pending = taskResult.rest;
336
- const titleResult = takeOption(pending, "--title");
337
- pending = titleResult.rest;
338
- const runtimeAdapterResult = takeOption(pending, "--runtime-adapter");
339
- pending = runtimeAdapterResult.rest;
340
- const modelResult = takeOption(pending, "--model");
341
- pending = modelResult.rest;
342
- const runtimeModeResult = takeOption(pending, "--runtime-mode");
343
- pending = runtimeModeResult.rest;
344
- const interactionModeResult = takeOption(pending, "--interaction-mode");
345
- pending = interactionModeResult.rest;
346
- const initialPromptResult = takeOption(pending, "--initial-prompt");
347
- pending = initialPromptResult.rest;
348
- const dirtyBaselineResult = takeOption(pending, "--dirty-baseline");
349
- pending = dirtyBaselineResult.rest;
350
- const prResult = takeOption(pending, "--pr");
351
- pending = prResult.rest;
352
- 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]");
353
- if (!taskResult.value && !initialPromptResult.value && !titleResult.value) {
354
- throw new CliError2("server task-run requires either --task <id> or --initial-prompt/--title for an ad hoc run.", 2);
355
- }
356
- const input = {
357
- runId: context.runId,
358
- taskId: taskResult.value ?? undefined,
359
- title: titleResult.value ?? undefined,
360
- runtimeAdapter: normalizeRuntimeAdapter(runtimeAdapterResult.value),
361
- model: modelResult.value ?? undefined,
362
- runtimeMode: runtimeModeResult.value || "full-access",
363
- interactionMode: interactionModeResult.value || "default",
364
- initialPrompt: initialPromptResult.value ?? undefined,
365
- baselineMode: dirtyBaselineResult.value === "dirty-snapshot" ? "dirty-snapshot" : "head",
366
- 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
+ }
367
150
  };
368
- if (process.env.RIG_SERVER_INTERNAL_EXEC === "1") {
369
- await options.executeRigOwnedTaskRun(context, input);
370
- } else {
371
- 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
+ }
372
164
  }
373
165
  return {
374
166
  ok: true,
375
167
  group: "server",
376
168
  command,
377
- 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 })) }
378
170
  };
379
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
+ });
380
241
  default:
381
- 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
+ });
382
245
  }
383
246
  }
384
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 {};