@h-rig/cli 0.0.6-alpha.28 → 0.0.6-alpha.280

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 (52) hide show
  1. package/README.md +6 -28
  2. package/package.json +11 -28
  3. package/dist/bin/build-rig-binaries.js +0 -107
  4. package/dist/bin/rig.js +0 -11739
  5. package/dist/src/commands/_authority-runs.js +0 -111
  6. package/dist/src/commands/_cli-format.js +0 -369
  7. package/dist/src/commands/_connection-state.js +0 -123
  8. package/dist/src/commands/_doctor-checks.js +0 -507
  9. package/dist/src/commands/_help-catalog.js +0 -364
  10. package/dist/src/commands/_operator-surface.js +0 -204
  11. package/dist/src/commands/_operator-view.js +0 -1147
  12. package/dist/src/commands/_parsers.js +0 -107
  13. package/dist/src/commands/_paths.js +0 -50
  14. package/dist/src/commands/_pi-frontend.js +0 -843
  15. package/dist/src/commands/_pi-install.js +0 -185
  16. package/dist/src/commands/_pi-worker-bridge-extension.js +0 -761
  17. package/dist/src/commands/_policy.js +0 -79
  18. package/dist/src/commands/_preflight.js +0 -403
  19. package/dist/src/commands/_probes.js +0 -13
  20. package/dist/src/commands/_run-driver-helpers.js +0 -289
  21. package/dist/src/commands/_server-client.js +0 -514
  22. package/dist/src/commands/_snapshot-upload.js +0 -318
  23. package/dist/src/commands/_task-picker.js +0 -76
  24. package/dist/src/commands/agent.js +0 -499
  25. package/dist/src/commands/browser.js +0 -890
  26. package/dist/src/commands/connect.js +0 -289
  27. package/dist/src/commands/dist.js +0 -402
  28. package/dist/src/commands/doctor.js +0 -517
  29. package/dist/src/commands/github.js +0 -281
  30. package/dist/src/commands/inbox.js +0 -482
  31. package/dist/src/commands/init.js +0 -1563
  32. package/dist/src/commands/inspect.js +0 -174
  33. package/dist/src/commands/inspector.js +0 -256
  34. package/dist/src/commands/plugin.js +0 -167
  35. package/dist/src/commands/profile-and-review.js +0 -178
  36. package/dist/src/commands/queue.js +0 -198
  37. package/dist/src/commands/remote.js +0 -507
  38. package/dist/src/commands/repo-git-harness.js +0 -221
  39. package/dist/src/commands/run.js +0 -1808
  40. package/dist/src/commands/server.js +0 -572
  41. package/dist/src/commands/setup.js +0 -687
  42. package/dist/src/commands/task-report-bug.js +0 -1083
  43. package/dist/src/commands/task-run-driver.js +0 -2600
  44. package/dist/src/commands/task.js +0 -2606
  45. package/dist/src/commands/test.js +0 -39
  46. package/dist/src/commands/workspace.js +0 -123
  47. package/dist/src/commands.js +0 -11418
  48. package/dist/src/index.js +0 -11757
  49. package/dist/src/launcher.js +0 -133
  50. package/dist/src/report-bug.js +0 -260
  51. package/dist/src/runner.js +0 -273
  52. package/dist/src/withMutedConsole.js +0 -42
@@ -1,514 +0,0 @@
1
- // @bun
2
- // packages/cli/src/commands/_server-client.ts
3
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
4
- import { resolve as resolve2 } 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
-
15
- // packages/cli/src/commands/_server-client.ts
16
- import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
17
-
18
- // packages/cli/src/commands/_connection-state.ts
19
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
20
- import { homedir } from "os";
21
- import { dirname, resolve } from "path";
22
- function resolveGlobalConnectionsPath(env = process.env) {
23
- const explicit = env.RIG_CONNECTIONS_FILE?.trim();
24
- if (explicit)
25
- return resolve(explicit);
26
- const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
27
- if (stateDir)
28
- return resolve(stateDir, "connections.json");
29
- return resolve(homedir(), ".rig", "connections.json");
30
- }
31
- function resolveRepoConnectionPath(projectRoot) {
32
- return resolve(projectRoot, ".rig", "state", "connection.json");
33
- }
34
- function readJsonFile(path) {
35
- if (!existsSync(path))
36
- return null;
37
- try {
38
- return JSON.parse(readFileSync(path, "utf8"));
39
- } catch (error) {
40
- throw new CliError2(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1);
41
- }
42
- }
43
- function normalizeConnection(value) {
44
- if (!value || typeof value !== "object" || Array.isArray(value))
45
- return null;
46
- const record = value;
47
- if (record.kind === "local")
48
- return { kind: "local", mode: "auto" };
49
- if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
50
- const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
51
- return { kind: "remote", baseUrl };
52
- }
53
- return null;
54
- }
55
- function readGlobalConnections(options = {}) {
56
- const path = resolveGlobalConnectionsPath(options.env ?? process.env);
57
- const payload = readJsonFile(path);
58
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
59
- return { connections: {} };
60
- }
61
- const rawConnections = payload.connections;
62
- const connections = {};
63
- if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
64
- for (const [alias, raw] of Object.entries(rawConnections)) {
65
- const connection = normalizeConnection(raw);
66
- if (connection)
67
- connections[alias] = connection;
68
- }
69
- }
70
- return { connections };
71
- }
72
- function readRepoConnection(projectRoot) {
73
- const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
74
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
75
- return null;
76
- const record = payload;
77
- const selected = typeof record.selected === "string" ? record.selected.trim() : "";
78
- if (!selected)
79
- return null;
80
- return {
81
- selected,
82
- project: typeof record.project === "string" ? record.project : undefined,
83
- linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined
84
- };
85
- }
86
- function resolveSelectedConnection(projectRoot, options = {}) {
87
- const repo = readRepoConnection(projectRoot);
88
- if (!repo)
89
- return null;
90
- if (repo.selected === "local")
91
- return { alias: "local", connection: { kind: "local", mode: "auto" } };
92
- const global = readGlobalConnections(options);
93
- const connection = global.connections[repo.selected];
94
- if (!connection) {
95
- throw new CliError2(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
96
- }
97
- return { alias: repo.selected, connection };
98
- }
99
-
100
- // packages/cli/src/commands/_server-client.ts
101
- var scopedGitHubBearerTokens = new Map;
102
- function cleanToken(value) {
103
- const trimmed = value?.trim();
104
- return trimmed ? trimmed : null;
105
- }
106
- function setGitHubBearerTokenForCurrentProcess(token, projectRoot) {
107
- const scopedKey = resolve2(projectRoot ?? process.cwd());
108
- scopedGitHubBearerTokens.set(scopedKey, cleanToken(token ?? undefined));
109
- }
110
- function readPrivateRemoteSessionToken(projectRoot) {
111
- const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
112
- if (!existsSync2(path))
113
- return null;
114
- try {
115
- const parsed = JSON.parse(readFileSync2(path, "utf8"));
116
- return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
117
- } catch {
118
- return null;
119
- }
120
- }
121
- function readGitHubBearerTokenForRemote(projectRoot) {
122
- const scopedKey = resolve2(projectRoot);
123
- if (scopedGitHubBearerTokens.has(scopedKey))
124
- return scopedGitHubBearerTokens.get(scopedKey) ?? null;
125
- const privateSession = readPrivateRemoteSessionToken(projectRoot);
126
- if (privateSession)
127
- return privateSession;
128
- return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
129
- }
130
- async function ensureServerForCli(projectRoot) {
131
- try {
132
- const selected = resolveSelectedConnection(projectRoot);
133
- if (selected?.connection.kind === "remote") {
134
- return {
135
- baseUrl: selected.connection.baseUrl,
136
- authToken: readGitHubBearerTokenForRemote(projectRoot),
137
- connectionKind: "remote"
138
- };
139
- }
140
- const connection = await ensureLocalRigServerConnection(projectRoot);
141
- return {
142
- baseUrl: connection.baseUrl,
143
- authToken: connection.authToken,
144
- connectionKind: "local"
145
- };
146
- } catch (error) {
147
- if (error instanceof Error) {
148
- throw new CliError2(error.message, 1);
149
- }
150
- throw error;
151
- }
152
- }
153
- function appendTaskFilterParams(url, filters) {
154
- if (filters.assignee)
155
- url.searchParams.set("assignee", filters.assignee);
156
- if (filters.state)
157
- url.searchParams.set("state", filters.state);
158
- if (filters.status)
159
- url.searchParams.set("status", filters.status);
160
- if (filters.limit !== undefined)
161
- url.searchParams.set("limit", String(filters.limit));
162
- }
163
- function mergeHeaders(headers, authToken) {
164
- const merged = new Headers(headers);
165
- if (authToken) {
166
- merged.set("authorization", `Bearer ${authToken}`);
167
- }
168
- return merged;
169
- }
170
- function diagnosticMessage(payload) {
171
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
172
- return null;
173
- const record = payload;
174
- const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
175
- const messages = diagnostics.flatMap((entry) => {
176
- if (!entry || typeof entry !== "object" || Array.isArray(entry))
177
- return [];
178
- const diagnostic = entry;
179
- const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
180
- const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
181
- return message ? [`${kind}: ${message}`] : [];
182
- });
183
- return messages.length > 0 ? messages.join("; ") : null;
184
- }
185
- async function requestServerJson(context, pathname, init = {}) {
186
- const server = await ensureServerForCli(context.projectRoot);
187
- const response = await fetch(`${server.baseUrl}${pathname}`, {
188
- ...init,
189
- headers: mergeHeaders(init.headers, server.authToken)
190
- });
191
- const text = await response.text();
192
- const payload = text.trim().length > 0 ? (() => {
193
- try {
194
- return JSON.parse(text);
195
- } catch {
196
- return null;
197
- }
198
- })() : null;
199
- if (!response.ok) {
200
- const diagnostics = diagnosticMessage(payload);
201
- const detail = diagnostics ?? (text || response.statusText);
202
- throw new CliError2(`Rig server request failed (${response.status}): ${detail}`, 1);
203
- }
204
- return payload;
205
- }
206
- async function listWorkspaceTasksViaServer(context, filters = {}) {
207
- const url = new URL("http://rig.local/api/workspace/tasks");
208
- appendTaskFilterParams(url, filters);
209
- const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
210
- if (!Array.isArray(payload)) {
211
- throw new CliError2("Rig server returned an invalid task list payload.", 1);
212
- }
213
- return payload.flatMap((entry) => entry && typeof entry === "object" && !Array.isArray(entry) ? [entry] : []);
214
- }
215
- async function getWorkspaceTaskViaServer(context, taskId) {
216
- const payload = await requestServerJson(context, `/api/workspace/tasks/${encodeURIComponent(taskId)}`);
217
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
218
- return null;
219
- const task = payload.task;
220
- return task && typeof task === "object" && !Array.isArray(task) ? task : null;
221
- }
222
- async function selectNextWorkspaceTaskViaServer(context, filters = {}) {
223
- const url = new URL("http://rig.local/api/workspace/tasks/next");
224
- appendTaskFilterParams(url, filters);
225
- const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
226
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
227
- throw new CliError2("Rig server returned an invalid next-task payload.", 1);
228
- }
229
- const record = payload;
230
- const rawTask = record.task;
231
- const task = rawTask && typeof rawTask === "object" && !Array.isArray(rawTask) ? rawTask : null;
232
- const count = typeof record.count === "number" && Number.isFinite(record.count) ? record.count : task ? 1 : 0;
233
- return { task, count };
234
- }
235
- async function getGitHubAuthStatusViaServer(context) {
236
- const payload = await requestServerJson(context, "/api/github/auth/status");
237
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
238
- }
239
- async function postGitHubTokenViaServer(context, token, options = {}) {
240
- const payload = await requestServerJson(context, "/api/github/auth/token", {
241
- method: "POST",
242
- headers: { "content-type": "application/json" },
243
- body: JSON.stringify({ token, selectedRepo: options.selectedRepo, projectRoot: options.projectRoot })
244
- });
245
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
246
- }
247
- async function prepareRemoteCheckoutViaServer(context, input) {
248
- const payload = await requestServerJson(context, `/api/projects/${encodeURIComponent(input.repoSlug)}/prepare-checkout`, {
249
- method: "POST",
250
- headers: { "content-type": "application/json" },
251
- body: JSON.stringify({ checkout: input.checkout, repoUrl: input.repoUrl, baseDir: input.baseDir })
252
- });
253
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
254
- }
255
- async function registerProjectViaServer(context, input) {
256
- const payload = await requestServerJson(context, "/api/projects", {
257
- method: "POST",
258
- headers: { "content-type": "application/json" },
259
- body: JSON.stringify(input)
260
- });
261
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
262
- }
263
- function sleep(ms) {
264
- return new Promise((resolve3) => setTimeout(resolve3, ms));
265
- }
266
- function isRetryableProjectRootSwitchError(error) {
267
- if (!(error instanceof Error))
268
- return false;
269
- const message = error.message.toLowerCase();
270
- return message.includes("rig server request failed (401): auth-required") || message.includes("rig server request failed (401): github-token-required") || message.includes("rig server request failed (502)") || message.includes("rig server request failed (503)") || message.includes("bad gateway") || message.includes("fetch failed") || message.includes("econnrefused") || message.includes("connection refused");
271
- }
272
- async function switchServerProjectRootViaServer(context, projectRoot, options = {}) {
273
- const timeoutMs = options.timeoutMs ?? 30000;
274
- const pollMs = options.pollMs ?? 1000;
275
- const deadline = Date.now() + timeoutMs;
276
- let lastError;
277
- let switched = null;
278
- while (Date.now() < deadline) {
279
- try {
280
- switched = await requestServerJson(context, "/api/server/project-root", {
281
- method: "POST",
282
- headers: { "content-type": "application/json" },
283
- body: JSON.stringify({ projectRoot })
284
- });
285
- break;
286
- } catch (error) {
287
- lastError = error;
288
- if (!isRetryableProjectRootSwitchError(error))
289
- throw error;
290
- await sleep(pollMs);
291
- }
292
- }
293
- if (!switched) {
294
- throw new CliError2(`Rig server did not accept project-root switch to ${projectRoot} before timeout (${lastError instanceof Error ? lastError.message : String(lastError ?? "no response")}).`, 1);
295
- }
296
- while (Date.now() < deadline) {
297
- try {
298
- const status = await requestServerJson(context, "/api/server/status");
299
- if (status && typeof status === "object" && !Array.isArray(status)) {
300
- const record = status;
301
- if (record.projectRoot === projectRoot) {
302
- return { ok: true, switched, status: record };
303
- }
304
- lastError = `server projectRoot=${String(record.projectRoot ?? "unknown")}`;
305
- }
306
- } catch (error) {
307
- lastError = error;
308
- }
309
- await sleep(pollMs);
310
- }
311
- throw new CliError2(`Rig server did not switch to ${projectRoot} before timeout (${lastError instanceof Error ? lastError.message : String(lastError ?? "no status")}).`, 1);
312
- }
313
- async function listRunsViaServer(context, options = {}) {
314
- const url = new URL("http://rig.local/api/runs");
315
- if (options.limit !== undefined)
316
- url.searchParams.set("limit", String(options.limit));
317
- const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
318
- const runs = Array.isArray(payload) ? payload : payload && typeof payload === "object" && !Array.isArray(payload) && Array.isArray(payload.runs) ? payload.runs : [];
319
- return runs.filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry)));
320
- }
321
- async function getRunDetailsViaServer(context, runId) {
322
- const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}`);
323
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
324
- }
325
- async function getRunLogsViaServer(context, runId, options = {}) {
326
- const url = new URL(`http://rig.local/api/runs/${encodeURIComponent(runId)}/logs`);
327
- if (options.limit !== undefined)
328
- url.searchParams.set("limit", String(options.limit));
329
- if (options.cursor)
330
- url.searchParams.set("cursor", options.cursor);
331
- const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
332
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { entries: [] };
333
- }
334
- async function getRunTimelineViaServer(context, runId, options = {}) {
335
- const url = new URL(`http://rig.local/api/runs/${encodeURIComponent(runId)}/timeline`);
336
- if (options.limit !== undefined)
337
- url.searchParams.set("limit", String(options.limit));
338
- if (options.cursor)
339
- url.searchParams.set("cursor", options.cursor);
340
- const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
341
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { entries: [] };
342
- }
343
- async function ensureTaskLabelsViaServer(context) {
344
- const payload = await requestServerJson(context, "/api/workspace/task-labels", { method: "POST" });
345
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
346
- }
347
- async function listGitHubProjectsViaServer(context, owner) {
348
- const url = new URL("http://rig.local/api/github/projects");
349
- url.searchParams.set("owner", owner);
350
- const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
351
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { projects: [] };
352
- }
353
- async function getGitHubProjectStatusFieldViaServer(context, projectId) {
354
- const payload = await requestServerJson(context, `/api/github/projects/${encodeURIComponent(projectId)}/status-field`);
355
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
356
- }
357
- async function updateWorkspaceTaskViaServer(context, input) {
358
- const payload = await requestServerJson(context, "/api/tasks/update", {
359
- method: "POST",
360
- headers: { "content-type": "application/json" },
361
- body: JSON.stringify(input)
362
- });
363
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { ok: true };
364
- }
365
- async function stopRunViaServer(context, runId) {
366
- const payload = await requestServerJson(context, "/api/runs/stop", {
367
- method: "POST",
368
- headers: { "content-type": "application/json" },
369
- body: JSON.stringify({ runId })
370
- });
371
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { ok: true, runId };
372
- }
373
- async function steerRunViaServer(context, runId, message) {
374
- const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/steer`, {
375
- method: "POST",
376
- headers: { "content-type": "application/json" },
377
- body: JSON.stringify({ message })
378
- });
379
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { ok: true };
380
- }
381
- async function getRunPiSessionViaServer(context, runId) {
382
- const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi`);
383
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
384
- }
385
- async function getRunPiMessagesViaServer(context, runId) {
386
- const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/messages`);
387
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { messages: [] };
388
- }
389
- async function getRunPiStatusViaServer(context, runId) {
390
- const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/status`);
391
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
392
- }
393
- async function getRunPiCommandsViaServer(context, runId) {
394
- const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/commands`);
395
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { commands: [] };
396
- }
397
- async function sendRunPiPromptViaServer(context, runId, text, streamingBehavior) {
398
- const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/prompt`, {
399
- method: "POST",
400
- headers: { "content-type": "application/json" },
401
- body: JSON.stringify({ text, streamingBehavior })
402
- });
403
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { accepted: true };
404
- }
405
- async function sendRunPiShellViaServer(context, runId, text) {
406
- const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/shell`, {
407
- method: "POST",
408
- headers: { "content-type": "application/json" },
409
- body: JSON.stringify({ text })
410
- });
411
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { accepted: true };
412
- }
413
- async function runRunPiCommandViaServer(context, runId, text) {
414
- const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/commands/run`, {
415
- method: "POST",
416
- headers: { "content-type": "application/json" },
417
- body: JSON.stringify({ text })
418
- });
419
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { type: "done" };
420
- }
421
- async function respondRunPiCommandViaServer(context, runId, requestId, value) {
422
- const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/commands/respond`, {
423
- method: "POST",
424
- headers: { "content-type": "application/json" },
425
- body: JSON.stringify({ requestId, value })
426
- });
427
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { type: "done" };
428
- }
429
- async function respondRunPiExtensionUiViaServer(context, runId, requestId, valueOrCancel) {
430
- const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/extension-ui/respond`, {
431
- method: "POST",
432
- headers: { "content-type": "application/json" },
433
- body: JSON.stringify({ requestId, ...valueOrCancel })
434
- });
435
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { accepted: true };
436
- }
437
- async function abortRunPiViaServer(context, runId) {
438
- const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/abort`, { method: "POST" });
439
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { aborted: true };
440
- }
441
- async function buildRunPiEventsWebSocketUrl(context, runId) {
442
- const server = await ensureServerForCli(context.projectRoot);
443
- const url = new URL(`${server.baseUrl.replace(/\/+$/, "")}/api/runs/${encodeURIComponent(runId)}/pi/events`);
444
- url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
445
- if (server.authToken)
446
- url.searchParams.set("token", server.authToken);
447
- return url.toString();
448
- }
449
- async function submitTaskRunViaServer(context, input) {
450
- const isTaskRun = Boolean(input.taskId);
451
- const endpoint = isTaskRun ? "/api/runs/task" : "/api/runs/adhoc";
452
- const payload = await requestServerJson(context, endpoint, {
453
- method: "POST",
454
- headers: {
455
- "content-type": "application/json"
456
- },
457
- body: JSON.stringify({
458
- runId: input.runId,
459
- taskId: input.taskId,
460
- title: input.title,
461
- runtimeAdapter: input.runtimeAdapter,
462
- model: input.model,
463
- runtimeMode: input.runtimeMode,
464
- interactionMode: input.interactionMode,
465
- initialPrompt: input.initialPrompt,
466
- baselineMode: input.baselineMode,
467
- prMode: input.prMode,
468
- executionTarget: "local"
469
- })
470
- });
471
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
472
- throw new CliError2("Rig server returned an invalid run submission payload.", 1);
473
- }
474
- const runId = payload.runId;
475
- if (typeof runId !== "string" || runId.trim().length === 0) {
476
- throw new CliError2("Rig server returned no runId for the submitted run.", 1);
477
- }
478
- return { runId };
479
- }
480
- export {
481
- updateWorkspaceTaskViaServer,
482
- switchServerProjectRootViaServer,
483
- submitTaskRunViaServer,
484
- stopRunViaServer,
485
- steerRunViaServer,
486
- setGitHubBearerTokenForCurrentProcess,
487
- sendRunPiShellViaServer,
488
- sendRunPiPromptViaServer,
489
- selectNextWorkspaceTaskViaServer,
490
- runRunPiCommandViaServer,
491
- respondRunPiExtensionUiViaServer,
492
- respondRunPiCommandViaServer,
493
- requestServerJson,
494
- registerProjectViaServer,
495
- prepareRemoteCheckoutViaServer,
496
- postGitHubTokenViaServer,
497
- listWorkspaceTasksViaServer,
498
- listRunsViaServer,
499
- listGitHubProjectsViaServer,
500
- getWorkspaceTaskViaServer,
501
- getRunTimelineViaServer,
502
- getRunPiStatusViaServer,
503
- getRunPiSessionViaServer,
504
- getRunPiMessagesViaServer,
505
- getRunPiCommandsViaServer,
506
- getRunLogsViaServer,
507
- getRunDetailsViaServer,
508
- getGitHubProjectStatusFieldViaServer,
509
- getGitHubAuthStatusViaServer,
510
- ensureTaskLabelsViaServer,
511
- ensureServerForCli,
512
- buildRunPiEventsWebSocketUrl,
513
- abortRunPiViaServer
514
- };