@h-rig/cli 0.0.6-alpha.0
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 +30 -0
- package/dist/bin/build-rig-binaries.js +107 -0
- package/dist/bin/rig.js +9330 -0
- package/dist/src/commands/_authority-runs.js +110 -0
- package/dist/src/commands/_connection-state.js +123 -0
- package/dist/src/commands/_doctor-checks.js +501 -0
- package/dist/src/commands/_operator-view.js +322 -0
- package/dist/src/commands/_parsers.js +107 -0
- package/dist/src/commands/_paths.js +50 -0
- package/dist/src/commands/_pi-install.js +184 -0
- package/dist/src/commands/_policy.js +79 -0
- package/dist/src/commands/_preflight.js +460 -0
- package/dist/src/commands/_probes.js +13 -0
- package/dist/src/commands/_run-driver-helpers.js +289 -0
- package/dist/src/commands/_server-client.js +364 -0
- package/dist/src/commands/_snapshot-upload.js +313 -0
- package/dist/src/commands/_task-picker.js +48 -0
- package/dist/src/commands/agent.js +497 -0
- package/dist/src/commands/browser.js +890 -0
- package/dist/src/commands/connect.js +180 -0
- package/dist/src/commands/dist.js +402 -0
- package/dist/src/commands/doctor.js +511 -0
- package/dist/src/commands/github.js +276 -0
- package/dist/src/commands/inbox.js +160 -0
- package/dist/src/commands/init.js +1254 -0
- package/dist/src/commands/inspect.js +174 -0
- package/dist/src/commands/inspector.js +256 -0
- package/dist/src/commands/plugin.js +167 -0
- package/dist/src/commands/profile-and-review.js +178 -0
- package/dist/src/commands/queue.js +197 -0
- package/dist/src/commands/remote.js +507 -0
- package/dist/src/commands/repo-git-harness.js +221 -0
- package/dist/src/commands/run.js +753 -0
- package/dist/src/commands/server.js +368 -0
- package/dist/src/commands/setup.js +681 -0
- package/dist/src/commands/task-report-bug.js +1083 -0
- package/dist/src/commands/task-run-driver.js +1933 -0
- package/dist/src/commands/task.js +1325 -0
- package/dist/src/commands/test.js +39 -0
- package/dist/src/commands/workspace.js +123 -0
- package/dist/src/commands.js +9012 -0
- package/dist/src/index.js +9348 -0
- package/dist/src/launcher.js +131 -0
- package/dist/src/report-bug.js +260 -0
- package/dist/src/runner.js +272 -0
- package/dist/src/withMutedConsole.js +42 -0
- package/package.json +31 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/cli/src/commands/github.ts
|
|
3
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
4
|
+
|
|
5
|
+
// packages/cli/src/runner.ts
|
|
6
|
+
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
7
|
+
import { CliError } from "@rig/runtime/control-plane/errors";
|
|
8
|
+
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
9
|
+
import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
|
|
10
|
+
import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
|
|
11
|
+
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
12
|
+
import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
|
|
13
|
+
function takeOption(args, option) {
|
|
14
|
+
const rest = [];
|
|
15
|
+
let value;
|
|
16
|
+
for (let index = 0;index < args.length; index += 1) {
|
|
17
|
+
const current = args[index];
|
|
18
|
+
if (current === option) {
|
|
19
|
+
const next = args[index + 1];
|
|
20
|
+
if (!next || next.startsWith("-")) {
|
|
21
|
+
throw new CliError(`Missing value for ${option}`);
|
|
22
|
+
}
|
|
23
|
+
value = next;
|
|
24
|
+
index += 1;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (current !== undefined) {
|
|
28
|
+
rest.push(current);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return { value, rest };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// packages/cli/src/commands/_server-client.ts
|
|
35
|
+
import { spawnSync } from "child_process";
|
|
36
|
+
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
37
|
+
|
|
38
|
+
// packages/cli/src/commands/_connection-state.ts
|
|
39
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
40
|
+
import { homedir } from "os";
|
|
41
|
+
import { dirname, resolve } from "path";
|
|
42
|
+
function resolveGlobalConnectionsPath(env = process.env) {
|
|
43
|
+
const explicit = env.RIG_CONNECTIONS_FILE?.trim();
|
|
44
|
+
if (explicit)
|
|
45
|
+
return resolve(explicit);
|
|
46
|
+
const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
|
|
47
|
+
if (stateDir)
|
|
48
|
+
return resolve(stateDir, "connections.json");
|
|
49
|
+
return resolve(homedir(), ".rig", "connections.json");
|
|
50
|
+
}
|
|
51
|
+
function resolveRepoConnectionPath(projectRoot) {
|
|
52
|
+
return resolve(projectRoot, ".rig", "state", "connection.json");
|
|
53
|
+
}
|
|
54
|
+
function readJsonFile(path) {
|
|
55
|
+
if (!existsSync(path))
|
|
56
|
+
return null;
|
|
57
|
+
try {
|
|
58
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
59
|
+
} catch (error) {
|
|
60
|
+
throw new CliError2(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function normalizeConnection(value) {
|
|
64
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
65
|
+
return null;
|
|
66
|
+
const record = value;
|
|
67
|
+
if (record.kind === "local")
|
|
68
|
+
return { kind: "local", mode: "auto" };
|
|
69
|
+
if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
|
|
70
|
+
const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
|
|
71
|
+
return { kind: "remote", baseUrl };
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
function readGlobalConnections(options = {}) {
|
|
76
|
+
const path = resolveGlobalConnectionsPath(options.env ?? process.env);
|
|
77
|
+
const payload = readJsonFile(path);
|
|
78
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
79
|
+
return { connections: {} };
|
|
80
|
+
}
|
|
81
|
+
const rawConnections = payload.connections;
|
|
82
|
+
const connections = {};
|
|
83
|
+
if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
|
|
84
|
+
for (const [alias, raw] of Object.entries(rawConnections)) {
|
|
85
|
+
const connection = normalizeConnection(raw);
|
|
86
|
+
if (connection)
|
|
87
|
+
connections[alias] = connection;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return { connections };
|
|
91
|
+
}
|
|
92
|
+
function readRepoConnection(projectRoot) {
|
|
93
|
+
const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
|
|
94
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
95
|
+
return null;
|
|
96
|
+
const record = payload;
|
|
97
|
+
const selected = typeof record.selected === "string" ? record.selected.trim() : "";
|
|
98
|
+
if (!selected)
|
|
99
|
+
return null;
|
|
100
|
+
return {
|
|
101
|
+
selected,
|
|
102
|
+
project: typeof record.project === "string" ? record.project : undefined,
|
|
103
|
+
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function resolveSelectedConnection(projectRoot, options = {}) {
|
|
107
|
+
const repo = readRepoConnection(projectRoot);
|
|
108
|
+
if (!repo)
|
|
109
|
+
return null;
|
|
110
|
+
if (repo.selected === "local")
|
|
111
|
+
return { alias: "local", connection: { kind: "local", mode: "auto" } };
|
|
112
|
+
const global = readGlobalConnections(options);
|
|
113
|
+
const connection = global.connections[repo.selected];
|
|
114
|
+
if (!connection) {
|
|
115
|
+
throw new CliError2(`Selected Rig connection "${repo.selected}" was not found. Run \`rig connect list\` or \`rig connect use local\`.`, 1);
|
|
116
|
+
}
|
|
117
|
+
return { alias: repo.selected, connection };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// packages/cli/src/commands/_server-client.ts
|
|
121
|
+
var cachedGitHubBearerToken;
|
|
122
|
+
function cleanToken(value) {
|
|
123
|
+
const trimmed = value?.trim();
|
|
124
|
+
return trimmed ? trimmed : null;
|
|
125
|
+
}
|
|
126
|
+
function readGitHubBearerTokenForRemote() {
|
|
127
|
+
if (cachedGitHubBearerToken !== undefined)
|
|
128
|
+
return cachedGitHubBearerToken;
|
|
129
|
+
const envToken = cleanToken(process.env.RIG_GITHUB_TOKEN) ?? cleanToken(process.env.GITHUB_TOKEN) ?? cleanToken(process.env.GH_TOKEN);
|
|
130
|
+
if (envToken) {
|
|
131
|
+
cachedGitHubBearerToken = envToken;
|
|
132
|
+
return cachedGitHubBearerToken;
|
|
133
|
+
}
|
|
134
|
+
const result = spawnSync("gh", ["auth", "token"], {
|
|
135
|
+
encoding: "utf8",
|
|
136
|
+
timeout: 5000,
|
|
137
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
138
|
+
});
|
|
139
|
+
cachedGitHubBearerToken = result.status === 0 ? cleanToken(result.stdout) : null;
|
|
140
|
+
return cachedGitHubBearerToken;
|
|
141
|
+
}
|
|
142
|
+
async function ensureServerForCli(projectRoot) {
|
|
143
|
+
try {
|
|
144
|
+
const selected = resolveSelectedConnection(projectRoot);
|
|
145
|
+
if (selected?.connection.kind === "remote") {
|
|
146
|
+
return {
|
|
147
|
+
baseUrl: selected.connection.baseUrl,
|
|
148
|
+
authToken: readGitHubBearerTokenForRemote(),
|
|
149
|
+
connectionKind: "remote"
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const connection = await ensureLocalRigServerConnection(projectRoot);
|
|
153
|
+
return {
|
|
154
|
+
baseUrl: connection.baseUrl,
|
|
155
|
+
authToken: connection.authToken,
|
|
156
|
+
connectionKind: "local"
|
|
157
|
+
};
|
|
158
|
+
} catch (error) {
|
|
159
|
+
if (error instanceof Error) {
|
|
160
|
+
throw new CliError2(error.message, 1);
|
|
161
|
+
}
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function mergeHeaders(headers, authToken) {
|
|
166
|
+
const merged = new Headers(headers);
|
|
167
|
+
if (authToken) {
|
|
168
|
+
merged.set("authorization", `Bearer ${authToken}`);
|
|
169
|
+
}
|
|
170
|
+
return merged;
|
|
171
|
+
}
|
|
172
|
+
function diagnosticMessage(payload) {
|
|
173
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
174
|
+
return null;
|
|
175
|
+
const record = payload;
|
|
176
|
+
const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
|
|
177
|
+
const messages = diagnostics.flatMap((entry) => {
|
|
178
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
179
|
+
return [];
|
|
180
|
+
const diagnostic = entry;
|
|
181
|
+
const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
|
|
182
|
+
const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
|
|
183
|
+
return message ? [`${kind}: ${message}`] : [];
|
|
184
|
+
});
|
|
185
|
+
return messages.length > 0 ? messages.join("; ") : null;
|
|
186
|
+
}
|
|
187
|
+
async function requestServerJson(context, pathname, init = {}) {
|
|
188
|
+
const server = await ensureServerForCli(context.projectRoot);
|
|
189
|
+
const response = await fetch(`${server.baseUrl}${pathname}`, {
|
|
190
|
+
...init,
|
|
191
|
+
headers: mergeHeaders(init.headers, server.authToken)
|
|
192
|
+
});
|
|
193
|
+
const text = await response.text();
|
|
194
|
+
const payload = text.trim().length > 0 ? (() => {
|
|
195
|
+
try {
|
|
196
|
+
return JSON.parse(text);
|
|
197
|
+
} catch {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
})() : null;
|
|
201
|
+
if (!response.ok) {
|
|
202
|
+
const diagnostics = diagnosticMessage(payload);
|
|
203
|
+
const detail = diagnostics ?? (text || response.statusText);
|
|
204
|
+
throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
|
|
205
|
+
}
|
|
206
|
+
return payload;
|
|
207
|
+
}
|
|
208
|
+
async function getGitHubAuthStatusViaServer(context) {
|
|
209
|
+
const payload = await requestServerJson(context, "/api/github/auth/status");
|
|
210
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
211
|
+
}
|
|
212
|
+
async function postGitHubTokenViaServer(context, token, options = {}) {
|
|
213
|
+
const payload = await requestServerJson(context, "/api/github/auth/token", {
|
|
214
|
+
method: "POST",
|
|
215
|
+
headers: { "content-type": "application/json" },
|
|
216
|
+
body: JSON.stringify({ token, selectedRepo: options.selectedRepo })
|
|
217
|
+
});
|
|
218
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// packages/cli/src/commands/github.ts
|
|
222
|
+
function printPayload(context, payload, fallback) {
|
|
223
|
+
if (context.outputMode === "json")
|
|
224
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
225
|
+
else
|
|
226
|
+
console.log(fallback);
|
|
227
|
+
}
|
|
228
|
+
function readGhToken() {
|
|
229
|
+
const result = spawnSync2("gh", ["auth", "token"], { encoding: "utf8" });
|
|
230
|
+
if (result.status !== 0) {
|
|
231
|
+
const detail = result.stderr?.trim() || result.stdout?.trim() || "gh auth token failed";
|
|
232
|
+
throw new CliError2(`Could not import GitHub token from gh: ${detail}`, 1);
|
|
233
|
+
}
|
|
234
|
+
const token = result.stdout.trim();
|
|
235
|
+
if (!token)
|
|
236
|
+
throw new CliError2("gh auth token returned an empty token.", 1);
|
|
237
|
+
return token;
|
|
238
|
+
}
|
|
239
|
+
async function executeGithub(context, args) {
|
|
240
|
+
const [group, command, ...rest] = args;
|
|
241
|
+
if (group !== "auth") {
|
|
242
|
+
throw new CliError2("Usage: rig github auth <status|import-gh|token>", 1);
|
|
243
|
+
}
|
|
244
|
+
switch (command) {
|
|
245
|
+
case "status": {
|
|
246
|
+
if (rest.length > 0)
|
|
247
|
+
throw new CliError2("Usage: rig github auth status", 1);
|
|
248
|
+
const status = await getGitHubAuthStatusViaServer(context);
|
|
249
|
+
printPayload(context, status, `GitHub auth: ${status.authenticated ? "authenticated" : "unauthenticated"}`);
|
|
250
|
+
return { ok: true, group: "github", command: "auth status", details: status };
|
|
251
|
+
}
|
|
252
|
+
case "token": {
|
|
253
|
+
const parsed = takeOption(rest, "--token");
|
|
254
|
+
if (parsed.rest.length > 0)
|
|
255
|
+
throw new CliError2("Usage: rig github auth token --token <token>", 1);
|
|
256
|
+
const token = parsed.value?.trim();
|
|
257
|
+
if (!token)
|
|
258
|
+
throw new CliError2("Missing --token value.", 1);
|
|
259
|
+
const result = await postGitHubTokenViaServer(context, token);
|
|
260
|
+
printPayload(context, result, "GitHub token stored on the selected Rig server.");
|
|
261
|
+
return { ok: true, group: "github", command: "auth token", details: result };
|
|
262
|
+
}
|
|
263
|
+
case "import-gh": {
|
|
264
|
+
if (rest.length > 0)
|
|
265
|
+
throw new CliError2("Usage: rig github auth import-gh", 1);
|
|
266
|
+
const result = await postGitHubTokenViaServer(context, readGhToken());
|
|
267
|
+
printPayload(context, result, "GitHub token imported from gh and stored on the selected Rig server.");
|
|
268
|
+
return { ok: true, group: "github", command: "auth import-gh", details: result };
|
|
269
|
+
}
|
|
270
|
+
default:
|
|
271
|
+
throw new CliError2("Usage: rig github auth <status|import-gh|token>", 1);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
export {
|
|
275
|
+
executeGithub
|
|
276
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/cli/src/commands/inbox.ts
|
|
3
|
+
import { writeFileSync } from "fs";
|
|
4
|
+
import { resolve } from "path";
|
|
5
|
+
|
|
6
|
+
// packages/cli/src/runner.ts
|
|
7
|
+
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
8
|
+
import { CliError } from "@rig/runtime/control-plane/errors";
|
|
9
|
+
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
10
|
+
import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
|
|
11
|
+
import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
|
|
12
|
+
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
13
|
+
import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
|
|
14
|
+
function takeOption(args, option) {
|
|
15
|
+
const rest = [];
|
|
16
|
+
let value;
|
|
17
|
+
for (let index = 0;index < args.length; index += 1) {
|
|
18
|
+
const current = args[index];
|
|
19
|
+
if (current === option) {
|
|
20
|
+
const next = args[index + 1];
|
|
21
|
+
if (!next || next.startsWith("-")) {
|
|
22
|
+
throw new CliError(`Missing value for ${option}`);
|
|
23
|
+
}
|
|
24
|
+
value = next;
|
|
25
|
+
index += 1;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (current !== undefined) {
|
|
29
|
+
rest.push(current);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return { value, rest };
|
|
33
|
+
}
|
|
34
|
+
function requireNoExtraArgs(args, usage) {
|
|
35
|
+
if (args.length > 0) {
|
|
36
|
+
throw new CliError(`Unexpected arguments: ${args.join(" ")}
|
|
37
|
+
Usage: ${usage}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// packages/cli/src/commands/inbox.ts
|
|
42
|
+
import {
|
|
43
|
+
listAuthorityRuns,
|
|
44
|
+
readJsonlFile,
|
|
45
|
+
resolveAuthorityRunDir
|
|
46
|
+
} from "@rig/runtime/control-plane/authority-files";
|
|
47
|
+
async function executeInbox(context, args) {
|
|
48
|
+
const [command = "approvals", ...rest] = args;
|
|
49
|
+
switch (command) {
|
|
50
|
+
case "approvals": {
|
|
51
|
+
let pending = rest;
|
|
52
|
+
const run = takeOption(pending, "--run");
|
|
53
|
+
pending = run.rest;
|
|
54
|
+
const task = takeOption(pending, "--task");
|
|
55
|
+
pending = task.rest;
|
|
56
|
+
requireNoExtraArgs(pending, "bun run rig inbox approvals [--run <id>] [--task <id>]");
|
|
57
|
+
const runs = listAuthorityRuns(context.projectRoot).filter((entry) => (!run.value || entry.runId === run.value) && (!task.value || entry.taskId === task.value));
|
|
58
|
+
const approvals = runs.flatMap((entry) => readJsonlFile(resolve(resolveAuthorityRunDir(context.projectRoot, entry.runId), "approvals.jsonl")).map((record) => ({
|
|
59
|
+
runId: entry.runId,
|
|
60
|
+
record
|
|
61
|
+
})));
|
|
62
|
+
if (context.outputMode === "text") {
|
|
63
|
+
for (const approval of approvals) {
|
|
64
|
+
console.log(JSON.stringify(approval));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return { ok: true, group: "inbox", command, details: { approvals } };
|
|
68
|
+
}
|
|
69
|
+
case "approve": {
|
|
70
|
+
let pending = rest;
|
|
71
|
+
const run = takeOption(pending, "--run");
|
|
72
|
+
pending = run.rest;
|
|
73
|
+
const request = takeOption(pending, "--request");
|
|
74
|
+
pending = request.rest;
|
|
75
|
+
const decision = takeOption(pending, "--decision");
|
|
76
|
+
pending = decision.rest;
|
|
77
|
+
const note = takeOption(pending, "--note");
|
|
78
|
+
pending = note.rest;
|
|
79
|
+
requireNoExtraArgs(pending, "bun run rig inbox approve --run <id> --request <id> --decision approve|reject [--note <text>]");
|
|
80
|
+
if (!run.value || !request.value || !decision.value) {
|
|
81
|
+
throw new CliError2("approve requires --run, --request, and --decision.");
|
|
82
|
+
}
|
|
83
|
+
if (decision.value !== "approve" && decision.value !== "reject") {
|
|
84
|
+
throw new CliError2("decision must be approve or reject.");
|
|
85
|
+
}
|
|
86
|
+
const approvalsPath = resolve(resolveAuthorityRunDir(context.projectRoot, run.value), "approvals.jsonl");
|
|
87
|
+
const approvals = readJsonlFile(approvalsPath);
|
|
88
|
+
const resolvedAt = new Date().toISOString();
|
|
89
|
+
const next = approvals.map((entry) => entry.requestId === request.value || entry.id === request.value ? { ...entry, status: "resolved", decision: decision.value, note: note.value ?? null, resolvedAt } : entry);
|
|
90
|
+
writeFileSync(approvalsPath, `${next.map((entry) => JSON.stringify(entry)).join(`
|
|
91
|
+
`)}
|
|
92
|
+
`, "utf8");
|
|
93
|
+
return { ok: true, group: "inbox", command, details: { runId: run.value, requestId: request.value, decision: decision.value } };
|
|
94
|
+
}
|
|
95
|
+
case "inputs": {
|
|
96
|
+
let pending = rest;
|
|
97
|
+
const run = takeOption(pending, "--run");
|
|
98
|
+
pending = run.rest;
|
|
99
|
+
const task = takeOption(pending, "--task");
|
|
100
|
+
pending = task.rest;
|
|
101
|
+
requireNoExtraArgs(pending, "bun run rig inbox inputs [--run <id>] [--task <id>]");
|
|
102
|
+
const runs = listAuthorityRuns(context.projectRoot).filter((entry) => (!run.value || entry.runId === run.value) && (!task.value || entry.taskId === task.value));
|
|
103
|
+
const requests = runs.flatMap((entry) => readJsonlFile(resolve(resolveAuthorityRunDir(context.projectRoot, entry.runId), "user-input.jsonl")).map((record) => ({
|
|
104
|
+
runId: entry.runId,
|
|
105
|
+
record
|
|
106
|
+
})));
|
|
107
|
+
if (context.outputMode === "text") {
|
|
108
|
+
for (const request of requests) {
|
|
109
|
+
console.log(JSON.stringify(request));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { ok: true, group: "inbox", command, details: { requests } };
|
|
113
|
+
}
|
|
114
|
+
case "respond": {
|
|
115
|
+
let pending = rest;
|
|
116
|
+
const run = takeOption(pending, "--run");
|
|
117
|
+
pending = run.rest;
|
|
118
|
+
const request = takeOption(pending, "--request");
|
|
119
|
+
pending = request.rest;
|
|
120
|
+
const answers = [];
|
|
121
|
+
const remaining = [];
|
|
122
|
+
for (let index = 0;index < pending.length; index += 1) {
|
|
123
|
+
const current = pending[index];
|
|
124
|
+
if (current === "--answer") {
|
|
125
|
+
const next2 = pending[index + 1];
|
|
126
|
+
if (!next2 || next2.startsWith("-")) {
|
|
127
|
+
throw new CliError2("Missing value for --answer");
|
|
128
|
+
}
|
|
129
|
+
answers.push(next2);
|
|
130
|
+
index += 1;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (current !== undefined) {
|
|
134
|
+
remaining.push(current);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
requireNoExtraArgs(remaining, "bun run rig inbox respond --run <id> --request <id> --answer key=value [--answer key=value]");
|
|
138
|
+
if (!run.value || !request.value || answers.length === 0) {
|
|
139
|
+
throw new CliError2("respond requires --run, --request, and at least one --answer.");
|
|
140
|
+
}
|
|
141
|
+
const parsedAnswers = Object.fromEntries(answers.map((entry) => {
|
|
142
|
+
const [key, ...restValue] = entry.split("=");
|
|
143
|
+
return [key, restValue.join("=")];
|
|
144
|
+
}));
|
|
145
|
+
const requestsPath = resolve(resolveAuthorityRunDir(context.projectRoot, run.value), "user-input.jsonl");
|
|
146
|
+
const requests = readJsonlFile(requestsPath);
|
|
147
|
+
const resolvedAt = new Date().toISOString();
|
|
148
|
+
const next = requests.map((entry) => entry.requestId === request.value || entry.id === request.value ? { ...entry, status: "resolved", answers: parsedAnswers, respondedAt: resolvedAt, resolvedAt } : entry);
|
|
149
|
+
writeFileSync(requestsPath, `${next.map((entry) => JSON.stringify(entry)).join(`
|
|
150
|
+
`)}
|
|
151
|
+
`, "utf8");
|
|
152
|
+
return { ok: true, group: "inbox", command, details: { runId: run.value, requestId: request.value, answers: parsedAnswers } };
|
|
153
|
+
}
|
|
154
|
+
default:
|
|
155
|
+
throw new CliError2(`Unknown inbox command: ${command}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
export {
|
|
159
|
+
executeInbox
|
|
160
|
+
};
|