@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.
- package/README.md +18 -19
- package/dist/bin/build-rig-binaries.d.ts +2 -0
- package/dist/bin/build-rig-binaries.js +22 -10
- package/dist/bin/rig.d.ts +72 -0
- package/dist/bin/rig.js +15637 -7344
- package/dist/config/rig-default-config.yml +5 -0
- package/dist/src/app/drone-ui.d.ts +34 -0
- package/dist/src/app/drone-ui.js +278 -0
- package/dist/src/commands/_async-ui.d.ts +10 -0
- package/dist/src/commands/_async-ui.js +121 -0
- package/dist/src/commands/_cli-format.d.ts +56 -0
- package/dist/src/commands/_cli-format.js +319 -0
- package/dist/src/commands/_connection-state.d.ts +54 -0
- package/dist/src/commands/_connection-state.js +75 -11
- package/dist/src/commands/_doctor-checks.d.ts +46 -0
- package/dist/src/commands/_doctor-checks.js +100 -267
- package/dist/src/commands/_help-catalog.d.ts +51 -0
- package/dist/src/commands/_help-catalog.js +502 -0
- package/dist/src/commands/_inprocess-services.d.ts +33 -0
- package/dist/src/commands/_inprocess-services.js +102 -0
- package/dist/src/commands/_json-output.d.ts +11 -0
- package/dist/src/commands/_json-output.js +60 -0
- package/dist/src/commands/_lazy-reconcile.d.ts +34 -0
- package/dist/src/commands/_lazy-reconcile.js +102 -0
- package/dist/src/commands/_parsers.d.ts +15 -0
- package/dist/src/commands/_parsers.js +18 -11
- package/dist/src/commands/_paths.d.ts +11 -0
- package/dist/src/commands/_paths.js +1 -1
- package/dist/src/commands/_pi-frontend.d.ts +35 -0
- package/dist/src/commands/_pi-frontend.js +64 -0
- package/dist/src/commands/_pi-install.d.ts +42 -0
- package/dist/src/commands/_pi-install.js +19 -36
- package/dist/src/commands/_policy.d.ts +8 -0
- package/dist/src/commands/_policy.js +67 -19
- package/dist/src/commands/_probes.d.ts +1 -0
- package/dist/src/commands/_run-bridge.d.ts +114 -0
- package/dist/src/commands/_run-bridge.js +387 -0
- package/dist/src/commands/_run-diagnostics.d.ts +9 -0
- package/dist/src/commands/_run-diagnostics.js +51 -0
- package/dist/src/commands/_run-driver-helpers.d.ts +26 -0
- package/dist/src/commands/_run-driver-helpers.js +79 -230
- package/dist/src/commands/_run-projection.d.ts +50 -0
- package/dist/src/commands/_run-projection.js +349 -0
- package/dist/src/commands/_run-subcommands.d.ts +3 -0
- package/dist/src/commands/_run-subcommands.js +31 -0
- package/dist/src/commands/_spinner.d.ts +25 -0
- package/dist/src/commands/_spinner.js +65 -0
- package/dist/src/commands/agent.d.ts +3 -0
- package/dist/src/commands/agent.js +8575 -236
- package/dist/src/commands/dist.d.ts +28 -0
- package/dist/src/commands/dist.js +44 -29
- package/dist/src/commands/doctor.d.ts +3 -0
- package/dist/src/commands/doctor.js +219 -268
- package/dist/src/commands/github.d.ts +3 -0
- package/dist/src/commands/github.js +236 -188
- package/dist/src/commands/inbox.d.ts +28 -0
- package/dist/src/commands/inbox.js +530 -111
- package/dist/src/commands/init.d.ts +64 -0
- package/dist/src/commands/init.js +912 -705
- package/dist/src/commands/inspect.d.ts +20 -0
- package/dist/src/commands/inspect.js +709 -119
- package/dist/src/commands/pi.d.ts +3 -0
- package/dist/src/commands/pi.js +177 -0
- package/dist/src/commands/plugin.d.ts +16 -0
- package/dist/src/commands/plugin.js +576 -29
- package/dist/src/commands/profile-and-review.d.ts +4 -0
- package/dist/src/commands/profile-and-review.js +112 -67
- package/dist/src/commands/queue.d.ts +3 -0
- package/dist/src/commands/queue.js +20 -20
- package/dist/src/commands/remote.d.ts +3 -0
- package/dist/src/commands/remote.js +880 -50
- package/dist/src/commands/repo-git-harness.d.ts +5 -0
- package/dist/src/commands/repo-git-harness.js +78 -28
- package/dist/src/commands/run.d.ts +21 -0
- package/dist/src/commands/run.js +17701 -661
- package/dist/src/commands/server.d.ts +3 -0
- package/dist/src/commands/server.js +166 -303
- package/dist/src/commands/setup.d.ts +16 -0
- package/dist/src/commands/setup.js +244 -299
- package/dist/src/commands/stats.d.ts +15 -0
- package/dist/src/commands/stats.js +979 -0
- package/dist/src/commands/task-run-driver.d.ts +94 -0
- package/dist/src/commands/task-run-driver.js +116 -1961
- package/dist/src/commands/task.d.ts +35 -0
- package/dist/src/commands/task.js +676 -1201
- package/dist/src/commands/test.d.ts +3 -0
- package/dist/src/commands/test.js +15 -8
- package/dist/src/commands/triage.d.ts +11 -0
- package/dist/src/commands/triage.js +227 -0
- package/dist/src/commands/workspace.d.ts +3 -0
- package/dist/src/commands/workspace.js +18 -11
- package/dist/src/commands.d.ts +13 -0
- package/dist/src/commands.js +16792 -8055
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +16862 -8450
- package/dist/src/launcher.d.ts +61 -0
- package/dist/src/launcher.js +81 -13
- package/dist/src/operator-cli.d.ts +2 -0
- package/dist/src/operator-cli.js +17837 -0
- package/dist/src/operator-entry.d.ts +1 -0
- package/dist/src/operator-entry.js +3 -0
- package/dist/src/runner.d.ts +47 -0
- package/dist/src/runner.js +16 -22
- package/dist/src/withMutedConsole.d.ts +2 -0
- package/package.json +21 -8
- package/dist/src/commands/_authority-runs.js +0 -111
- package/dist/src/commands/_operator-view.js +0 -340
- package/dist/src/commands/_preflight.js +0 -478
- package/dist/src/commands/_server-client.js +0 -382
- package/dist/src/commands/_snapshot-upload.js +0 -331
- package/dist/src/commands/_task-picker.js +0 -48
- package/dist/src/commands/browser.js +0 -890
- package/dist/src/commands/connect.js +0 -180
- package/dist/src/commands/inspector.js +0 -256
- package/dist/src/commands/task-report-bug.js +0 -1083
- package/dist/src/report-bug.js +0 -260
|
@@ -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
|
-
|
|
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/
|
|
44
|
+
// packages/cli/src/commands/server.ts
|
|
38
45
|
import {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
} from "@rig/runtime/control-plane/
|
|
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
|
|
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
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
|
138
|
-
|
|
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/
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
-
|
|
289
|
-
|
|
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 "
|
|
292
|
-
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
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: {
|
|
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
|
|
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 {};
|