@h-rig/cli 0.0.6-alpha.90 → 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 (118) hide show
  1. package/README.md +18 -19
  2. package/dist/bin/build-rig-binaries.js +22 -10
  3. package/dist/bin/rig.d.ts +71 -1
  4. package/dist/bin/rig.js +15078 -11169
  5. package/dist/config/rig-default-config.yml +5 -0
  6. package/dist/src/app/drone-ui.d.ts +11 -14
  7. package/dist/src/app/drone-ui.js +70 -86
  8. package/dist/src/commands/_async-ui.d.ts +1 -4
  9. package/dist/src/commands/_async-ui.js +9 -111
  10. package/dist/src/commands/_cli-format.d.ts +16 -9
  11. package/dist/src/commands/_cli-format.js +167 -295
  12. package/dist/src/commands/_connection-state.d.ts +11 -1
  13. package/dist/src/commands/_connection-state.js +50 -5
  14. package/dist/src/commands/_doctor-checks.d.ts +0 -6
  15. package/dist/src/commands/_doctor-checks.js +79 -382
  16. package/dist/src/commands/_help-catalog.d.ts +1 -1
  17. package/dist/src/commands/_help-catalog.js +217 -157
  18. package/dist/src/commands/_inprocess-services.d.ts +33 -0
  19. package/dist/src/commands/_inprocess-services.js +102 -0
  20. package/dist/src/commands/_json-output.js +4 -0
  21. package/dist/src/commands/_lazy-reconcile.d.ts +34 -0
  22. package/dist/src/commands/_lazy-reconcile.js +102 -0
  23. package/dist/src/commands/_paths.js +1 -1
  24. package/dist/src/commands/_pi-frontend.d.ts +18 -10
  25. package/dist/src/commands/_pi-frontend.js +37 -715
  26. package/dist/src/commands/_pi-install.js +18 -36
  27. package/dist/src/commands/_policy.d.ts +1 -1
  28. package/dist/src/commands/_policy.js +56 -15
  29. package/dist/src/commands/_run-bridge.d.ts +114 -0
  30. package/dist/src/commands/_run-bridge.js +387 -0
  31. package/dist/src/commands/_run-diagnostics.d.ts +9 -0
  32. package/dist/src/commands/_run-diagnostics.js +51 -0
  33. package/dist/src/commands/_run-driver-helpers.d.ts +8 -81
  34. package/dist/src/commands/_run-driver-helpers.js +79 -283
  35. package/dist/src/commands/_run-projection.d.ts +50 -0
  36. package/dist/src/commands/_run-projection.js +349 -0
  37. package/dist/src/commands/_run-subcommands.d.ts +3 -0
  38. package/dist/src/commands/_run-subcommands.js +31 -0
  39. package/dist/src/commands/_spinner.js +1 -1
  40. package/dist/src/commands/agent.d.ts +1 -1
  41. package/dist/src/commands/agent.js +8559 -239
  42. package/dist/src/commands/dist.d.ts +1 -1
  43. package/dist/src/commands/dist.js +27 -19
  44. package/dist/src/commands/doctor.d.ts +1 -1
  45. package/dist/src/commands/doctor.js +93 -475
  46. package/dist/src/commands/github.d.ts +1 -1
  47. package/dist/src/commands/github.js +113 -387
  48. package/dist/src/commands/inbox.d.ts +22 -24
  49. package/dist/src/commands/inbox.js +420 -691
  50. package/dist/src/commands/init.d.ts +6 -16
  51. package/dist/src/commands/init.js +334 -971
  52. package/dist/src/commands/inspect.d.ts +19 -2
  53. package/dist/src/commands/inspect.js +644 -610
  54. package/dist/src/commands/pi.d.ts +1 -1
  55. package/dist/src/commands/plugin.d.ts +1 -1
  56. package/dist/src/commands/plugin.js +486 -7
  57. package/dist/src/commands/profile-and-review.d.ts +1 -1
  58. package/dist/src/commands/profile-and-review.js +94 -56
  59. package/dist/src/commands/queue.js +1 -21
  60. package/dist/src/commands/remote.d.ts +1 -1
  61. package/dist/src/commands/remote.js +837 -14
  62. package/dist/src/commands/repo-git-harness.d.ts +1 -1
  63. package/dist/src/commands/repo-git-harness.js +57 -14
  64. package/dist/src/commands/run.d.ts +20 -2
  65. package/dist/src/commands/run.js +17579 -1759
  66. package/dist/src/commands/server.d.ts +2 -6
  67. package/dist/src/commands/server.js +141 -723
  68. package/dist/src/commands/setup.d.ts +1 -1
  69. package/dist/src/commands/setup.js +102 -484
  70. package/dist/src/commands/stats.d.ts +13 -10
  71. package/dist/src/commands/stats.js +689 -761
  72. package/dist/src/commands/task-run-driver.d.ts +50 -88
  73. package/dist/src/commands/task-run-driver.js +116 -2717
  74. package/dist/src/commands/task.d.ts +34 -13
  75. package/dist/src/commands/task.js +668 -2523
  76. package/dist/src/commands/test.d.ts +1 -1
  77. package/dist/src/commands/triage.d.ts +11 -0
  78. package/dist/src/commands/triage.js +227 -0
  79. package/dist/src/commands/workspace.d.ts +1 -1
  80. package/dist/src/commands.d.ts +0 -16
  81. package/dist/src/commands.js +16657 -12250
  82. package/dist/src/index.js +16528 -12497
  83. package/dist/src/launcher.js +4 -0
  84. package/dist/src/operator-cli.d.ts +2 -0
  85. package/dist/src/operator-cli.js +17837 -0
  86. package/dist/src/operator-entry.d.ts +1 -0
  87. package/dist/src/operator-entry.js +3 -0
  88. package/package.json +18 -12
  89. package/dist/src/app/board.d.ts +0 -23
  90. package/dist/src/app/board.js +0 -1786
  91. package/dist/src/app/theme.d.ts +0 -47
  92. package/dist/src/app/theme.js +0 -150
  93. package/dist/src/commands/_authority-runs.d.ts +0 -22
  94. package/dist/src/commands/_authority-runs.js +0 -110
  95. package/dist/src/commands/_operator-surface.d.ts +0 -34
  96. package/dist/src/commands/_operator-surface.js +0 -220
  97. package/dist/src/commands/_operator-view.d.ts +0 -30
  98. package/dist/src/commands/_operator-view.js +0 -1070
  99. package/dist/src/commands/_preflight.d.ts +0 -22
  100. package/dist/src/commands/_preflight.js +0 -540
  101. package/dist/src/commands/_run-replay.d.ts +0 -24
  102. package/dist/src/commands/_run-replay.js +0 -142
  103. package/dist/src/commands/_server-client.d.ts +0 -186
  104. package/dist/src/commands/_server-client.js +0 -681
  105. package/dist/src/commands/_snapshot-upload.d.ts +0 -39
  106. package/dist/src/commands/_snapshot-upload.js +0 -455
  107. package/dist/src/commands/_task-picker.d.ts +0 -9
  108. package/dist/src/commands/_task-picker.js +0 -201
  109. package/dist/src/commands/browser.d.ts +0 -65
  110. package/dist/src/commands/browser.js +0 -1173
  111. package/dist/src/commands/connect.d.ts +0 -7
  112. package/dist/src/commands/connect.js +0 -419
  113. package/dist/src/commands/inspector.d.ts +0 -3
  114. package/dist/src/commands/inspector.js +0 -263
  115. package/dist/src/commands/task-report-bug.d.ts +0 -19
  116. package/dist/src/commands/task-report-bug.js +0 -1281
  117. package/dist/src/report-bug.d.ts +0 -44
  118. package/dist/src/report-bug.js +0 -260
@@ -1,39 +0,0 @@
1
- export declare const UPLOADED_SNAPSHOT_PR_MARKER = "<!-- rig:uploaded-snapshot -->";
2
- export declare const SNAPSHOT_ARCHIVE_VERSION = 1;
3
- export declare const SNAPSHOT_ARCHIVE_CONTENT_TYPE = "application/vnd.rig.snapshot+json";
4
- export type SnapshotUploadManifest = {
5
- readonly root: string;
6
- readonly files: readonly string[];
7
- readonly excludedDirectories: readonly string[];
8
- };
9
- export type SnapshotUploadArchiveFile = {
10
- readonly path: string;
11
- readonly contentBase64: string;
12
- };
13
- export type SnapshotUploadArchive = {
14
- readonly version: typeof SNAPSHOT_ARCHIVE_VERSION;
15
- readonly root: string;
16
- readonly files: readonly SnapshotUploadArchiveFile[];
17
- readonly excludedDirectories: readonly string[];
18
- readonly createdAt: string;
19
- };
20
- export declare function buildSnapshotUploadManifest(projectRoot: string, options?: {
21
- readonly excludedDirectories?: readonly string[];
22
- }): Promise<SnapshotUploadManifest>;
23
- export declare function createSnapshotUploadArchive(projectRoot: string, options?: {
24
- readonly excludedDirectories?: readonly string[];
25
- readonly now?: () => Date;
26
- }): Promise<SnapshotUploadArchive>;
27
- export declare function encodeSnapshotUploadArchive(archive: SnapshotUploadArchive): string;
28
- export declare function writeSnapshotUploadArchive(projectRoot: string, outputPath: string, options?: {
29
- readonly excludedDirectories?: readonly string[];
30
- readonly now?: () => Date;
31
- }): Promise<SnapshotUploadArchive>;
32
- export declare function uploadSnapshotArchiveViaServer(context: {
33
- readonly projectRoot: string;
34
- }, input: {
35
- readonly repoSlug: string;
36
- readonly archive: SnapshotUploadArchive;
37
- readonly baseDir?: string;
38
- }): Promise<Record<string, unknown>>;
39
- export declare function appendUploadedSnapshotPrNotice(body: string): string;
@@ -1,455 +0,0 @@
1
- // @bun
2
- // packages/cli/src/commands/_snapshot-upload.ts
3
- import { mkdir, readdir, readFile, writeFile } from "fs/promises";
4
- import { dirname as dirname2, resolve as resolve3, relative, sep } from "path";
5
-
6
- // packages/cli/src/commands/_server-client.ts
7
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
8
- import { resolve as resolve2 } from "path";
9
-
10
- // packages/cli/src/runner.ts
11
- import { EventBus } from "@rig/runtime/control-plane/runtime/events";
12
- import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
13
- import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
14
- import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
15
-
16
- class CliError extends RuntimeCliError {
17
- hint;
18
- constructor(message, exitCode = 1, options = {}) {
19
- super(message, exitCode);
20
- if (options.hint?.trim()) {
21
- this.hint = options.hint.trim();
22
- }
23
- }
24
- }
25
-
26
- // packages/cli/src/commands/_server-client.ts
27
- import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
28
-
29
- // packages/cli/src/commands/_connection-state.ts
30
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
31
- import { homedir } from "os";
32
- import { dirname, resolve } from "path";
33
- function resolveGlobalConnectionsPath(env = process.env) {
34
- const explicit = env.RIG_CONNECTIONS_FILE?.trim();
35
- if (explicit)
36
- return resolve(explicit);
37
- const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
38
- if (stateDir)
39
- return resolve(stateDir, "connections.json");
40
- return resolve(homedir(), ".rig", "connections.json");
41
- }
42
- function resolveRepoConnectionPath(projectRoot) {
43
- return resolve(projectRoot, ".rig", "state", "connection.json");
44
- }
45
- function readJsonFile(path) {
46
- if (!existsSync(path))
47
- return null;
48
- try {
49
- return JSON.parse(readFileSync(path, "utf8"));
50
- } catch (error) {
51
- 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>`." });
52
- }
53
- }
54
- function writeJsonFile(path, value) {
55
- mkdirSync(dirname(path), { recursive: true });
56
- writeFileSync(path, `${JSON.stringify(value, null, 2)}
57
- `, "utf8");
58
- }
59
- function normalizeConnection(value) {
60
- if (!value || typeof value !== "object" || Array.isArray(value))
61
- return null;
62
- const record = value;
63
- if (record.kind === "local")
64
- return { kind: "local", mode: "auto" };
65
- if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
66
- const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
67
- return { kind: "remote", baseUrl };
68
- }
69
- return null;
70
- }
71
- function readGlobalConnections(options = {}) {
72
- const path = resolveGlobalConnectionsPath(options.env ?? process.env);
73
- const payload = readJsonFile(path);
74
- if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
75
- return { connections: {} };
76
- }
77
- const rawConnections = payload.connections;
78
- const connections = {};
79
- if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
80
- for (const [alias, raw] of Object.entries(rawConnections)) {
81
- const connection = normalizeConnection(raw);
82
- if (connection)
83
- connections[alias] = connection;
84
- }
85
- }
86
- return { connections };
87
- }
88
- function readRepoConnection(projectRoot) {
89
- const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
90
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
91
- return null;
92
- const record = payload;
93
- const selected = typeof record.selected === "string" ? record.selected.trim() : "";
94
- if (!selected)
95
- return null;
96
- return {
97
- selected,
98
- project: typeof record.project === "string" ? record.project : undefined,
99
- linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
100
- serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
101
- };
102
- }
103
- function writeRepoConnection(projectRoot, state) {
104
- writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
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" }, serverProjectRoot: repo.serverProjectRoot };
112
- const global = readGlobalConnections(options);
113
- const connection = global.connections[repo.selected];
114
- if (!connection) {
115
- throw new CliError(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
116
- }
117
- return { alias: repo.selected, connection, serverProjectRoot: repo.serverProjectRoot };
118
- }
119
- function writeRepoServerProjectRoot(projectRoot, serverProjectRoot) {
120
- const repo = readRepoConnection(projectRoot);
121
- if (!repo)
122
- return;
123
- writeRepoConnection(projectRoot, { ...repo, serverProjectRoot });
124
- }
125
-
126
- // packages/cli/src/commands/_server-client.ts
127
- var scopedGitHubBearerTokens = new Map;
128
- var serverPhaseListener = null;
129
- function reportServerPhase(label) {
130
- serverPhaseListener?.(label);
131
- }
132
- function cleanToken(value) {
133
- const trimmed = value?.trim();
134
- return trimmed ? trimmed : null;
135
- }
136
- function readPrivateRemoteSessionToken(projectRoot) {
137
- const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
138
- if (!existsSync2(path))
139
- return null;
140
- try {
141
- const parsed = JSON.parse(readFileSync2(path, "utf8"));
142
- return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
143
- } catch {
144
- return null;
145
- }
146
- }
147
- function readGitHubBearerTokenForRemote(projectRoot) {
148
- const scopedKey = resolve2(projectRoot);
149
- if (scopedGitHubBearerTokens.has(scopedKey))
150
- return scopedGitHubBearerTokens.get(scopedKey) ?? null;
151
- const privateSession = readPrivateRemoteSessionToken(projectRoot);
152
- if (privateSession)
153
- return privateSession;
154
- return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
155
- }
156
- function readStoredGitHubAuthToken(projectRoot) {
157
- const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
158
- if (!existsSync2(path))
159
- return null;
160
- try {
161
- const parsed = JSON.parse(readFileSync2(path, "utf8"));
162
- return cleanToken(typeof parsed.token === "string" ? parsed.token : undefined);
163
- } catch {
164
- return null;
165
- }
166
- }
167
- function readLocalConnectionFallbackToken(projectRoot) {
168
- return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
169
- }
170
- async function ensureServerForCli(projectRoot) {
171
- try {
172
- const selected = resolveSelectedConnection(projectRoot);
173
- if (selected?.connection.kind === "remote") {
174
- reportServerPhase(`Connecting to ${selected.alias}\u2026`);
175
- const authToken = readGitHubBearerTokenForRemote(projectRoot);
176
- const serverProjectRoot = selected.serverProjectRoot ?? await backfillRemoteServerProjectRoot(projectRoot, selected.connection.baseUrl, authToken);
177
- return {
178
- baseUrl: selected.connection.baseUrl,
179
- authToken,
180
- connectionKind: "remote",
181
- serverProjectRoot
182
- };
183
- }
184
- reportServerPhase("Starting local Rig server\u2026");
185
- const connection = await ensureLocalRigServerConnection(projectRoot);
186
- return {
187
- baseUrl: connection.baseUrl,
188
- authToken: connection.authToken ?? readLocalConnectionFallbackToken(projectRoot),
189
- connectionKind: "local",
190
- serverProjectRoot: resolve2(projectRoot)
191
- };
192
- } catch (error) {
193
- if (error instanceof Error) {
194
- throw new CliError(error.message, 1);
195
- }
196
- throw error;
197
- }
198
- }
199
- async function backfillRemoteServerProjectRoot(projectRoot, baseUrl, authToken) {
200
- const repo = readRepoConnection(projectRoot);
201
- const slug = repo?.project?.trim();
202
- if (!slug)
203
- return null;
204
- try {
205
- const response = await fetch(`${baseUrl}/api/projects/${encodeURIComponent(slug)}`, {
206
- headers: mergeHeaders(undefined, authToken)
207
- });
208
- if (!response.ok)
209
- return null;
210
- const payload = await response.json();
211
- const project = payload.project && typeof payload.project === "object" && !Array.isArray(payload.project) ? payload.project : null;
212
- const checkouts = Array.isArray(project?.checkouts) ? project.checkouts : [];
213
- const latestCheckout = [...checkouts].reverse().find((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry) && typeof entry.path === "string"));
214
- const path = typeof latestCheckout?.path === "string" && latestCheckout.path.trim() ? latestCheckout.path.trim() : null;
215
- if (path)
216
- writeRepoServerProjectRoot(projectRoot, path);
217
- return path;
218
- } catch {
219
- return null;
220
- }
221
- }
222
- function mergeHeaders(headers, authToken) {
223
- const merged = new Headers(headers);
224
- if (authToken) {
225
- merged.set("authorization", `Bearer ${authToken}`);
226
- }
227
- return merged;
228
- }
229
- function diagnosticMessage(payload) {
230
- if (!payload || typeof payload !== "object" || Array.isArray(payload))
231
- return null;
232
- const record = payload;
233
- const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
234
- const messages = diagnostics.flatMap((entry) => {
235
- if (!entry || typeof entry !== "object" || Array.isArray(entry))
236
- return [];
237
- const diagnostic = entry;
238
- const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
239
- const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
240
- return message ? [`${kind}: ${message}`] : [];
241
- });
242
- return messages.length > 0 ? messages.join("; ") : null;
243
- }
244
- var serverReachabilityCache = new Map;
245
- async function probeServerReachability(baseUrl, authToken) {
246
- try {
247
- const response = await fetch(`${baseUrl.replace(/\/+$/, "")}/api/server/status`, {
248
- headers: mergeHeaders(undefined, authToken),
249
- signal: AbortSignal.timeout(1500)
250
- });
251
- return response.ok;
252
- } catch {
253
- return false;
254
- }
255
- }
256
- function cachedServerReachability(projectRoot, baseUrl, authToken) {
257
- const key = resolve2(projectRoot);
258
- const cached = serverReachabilityCache.get(key);
259
- if (cached)
260
- return cached;
261
- const probe = probeServerReachability(baseUrl, authToken);
262
- serverReachabilityCache.set(key, probe);
263
- return probe;
264
- }
265
- function describeSelectedServer(projectRoot, server) {
266
- try {
267
- const selected = resolveSelectedConnection(projectRoot);
268
- if (selected) {
269
- return {
270
- alias: selected.alias,
271
- target: selected.connection.kind === "remote" ? selected.connection.baseUrl : server.baseUrl
272
- };
273
- }
274
- } catch {}
275
- return { alias: server.connectionKind === "remote" ? "remote" : "local", target: server.baseUrl };
276
- }
277
- async function buildServerFailureContext(projectRoot, server) {
278
- const { alias, target } = describeSelectedServer(projectRoot, server);
279
- const reachable = await cachedServerReachability(projectRoot, server.baseUrl, server.authToken);
280
- const reachability = reachable ? "server is reachable" : "server is unreachable";
281
- return {
282
- contextLine: `Currently connected to: ${alias} at ${target} (${reachability}).`,
283
- hint: "Check the selected server with `rig server status`, or switch with `rig server use <alias|local>`."
284
- };
285
- }
286
- async function requestServerJson(context, pathname, init = {}) {
287
- const server = await ensureServerForCli(context.projectRoot);
288
- const headers = mergeHeaders(init.headers, server.authToken);
289
- if (server.serverProjectRoot)
290
- headers.set("x-rig-project-root", server.serverProjectRoot);
291
- reportServerPhase(`${(init.method ?? "GET").toUpperCase()} ${pathname.split("?")[0]}\u2026`);
292
- let response;
293
- try {
294
- response = await fetch(`${server.baseUrl}${pathname}`, {
295
- ...init,
296
- headers
297
- });
298
- } catch (error) {
299
- const failure = await buildServerFailureContext(context.projectRoot, server);
300
- throw new CliError(`Rig server request failed: ${error instanceof Error ? error.message : String(error)}
301
- ${failure.contextLine}`, 1, { hint: failure.hint });
302
- }
303
- const text = await response.text();
304
- const payload = text.trim().length > 0 ? (() => {
305
- try {
306
- return JSON.parse(text);
307
- } catch {
308
- return null;
309
- }
310
- })() : null;
311
- if (!response.ok) {
312
- const diagnostics = diagnosticMessage(payload);
313
- const rawDetail = diagnostics ?? (text || response.statusText);
314
- const detail = diagnostics ? rawDetail : rawDetail.split(`
315
- `).map((line) => line.trim()).find((line) => line.length > 0)?.slice(0, 200) ?? response.statusText;
316
- const failure = await buildServerFailureContext(context.projectRoot, server);
317
- throw new CliError(`Rig server request failed (${response.status}): ${detail}
318
- ${failure.contextLine}`, 1, { hint: failure.hint });
319
- }
320
- return payload;
321
- }
322
- var RESUMABLE_RUN_STATUSES = new Set([
323
- "created",
324
- "preparing",
325
- "running",
326
- "validating",
327
- "reviewing",
328
- "stopped",
329
- "failed",
330
- "needs-attention",
331
- "needs_attention"
332
- ]);
333
-
334
- // packages/cli/src/commands/_snapshot-upload.ts
335
- var UPLOADED_SNAPSHOT_PR_MARKER = "<!-- rig:uploaded-snapshot -->";
336
- var SNAPSHOT_ARCHIVE_VERSION = 1;
337
- var SNAPSHOT_ARCHIVE_CONTENT_TYPE = "application/vnd.rig.snapshot+json";
338
- var DEFAULT_EXCLUDED_DIRECTORIES = new Set([
339
- ".git",
340
- ".rig",
341
- "node_modules",
342
- ".turbo",
343
- ".next",
344
- ".cache",
345
- "coverage",
346
- "dist",
347
- "build",
348
- "out"
349
- ]);
350
- function toPosixPath(path) {
351
- return path.split(sep).join("/");
352
- }
353
- function assertManifestPath(root, relativePath) {
354
- if (!relativePath || relativePath.startsWith("/") || relativePath.includes("\x00")) {
355
- throw new Error(`Invalid snapshot path: ${relativePath}`);
356
- }
357
- const resolved = resolve3(root, relativePath);
358
- const relativeToRoot = relative(root, resolved);
359
- if (relativeToRoot.startsWith("..") || relativeToRoot === ".." || resolve3(relativeToRoot) === resolved) {
360
- throw new Error(`Snapshot path escapes project root: ${relativePath}`);
361
- }
362
- return resolved;
363
- }
364
- async function buildSnapshotUploadManifest(projectRoot, options = {}) {
365
- const root = resolve3(projectRoot);
366
- const excludedDirectories = [...new Set([
367
- ...DEFAULT_EXCLUDED_DIRECTORIES,
368
- ...options.excludedDirectories ?? []
369
- ])];
370
- const excludedSet = new Set(excludedDirectories);
371
- const files = [];
372
- async function visit(dir) {
373
- const entries = await readdir(dir, { withFileTypes: true });
374
- for (const entry of entries) {
375
- if (entry.isDirectory() && excludedSet.has(entry.name))
376
- continue;
377
- const fullPath = resolve3(dir, entry.name);
378
- if (entry.isDirectory()) {
379
- await visit(fullPath);
380
- continue;
381
- }
382
- if (!entry.isFile())
383
- continue;
384
- files.push(toPosixPath(relative(root, fullPath)));
385
- }
386
- }
387
- await visit(root);
388
- files.sort();
389
- return { root, files, excludedDirectories };
390
- }
391
- async function createSnapshotUploadArchive(projectRoot, options = {}) {
392
- const manifest = await buildSnapshotUploadManifest(projectRoot, options);
393
- const files = await Promise.all(manifest.files.map(async (path) => {
394
- const fullPath = assertManifestPath(manifest.root, path);
395
- return {
396
- path,
397
- contentBase64: (await readFile(fullPath)).toString("base64")
398
- };
399
- }));
400
- return {
401
- version: SNAPSHOT_ARCHIVE_VERSION,
402
- root: manifest.root,
403
- files,
404
- excludedDirectories: manifest.excludedDirectories,
405
- createdAt: (options.now?.() ?? new Date).toISOString()
406
- };
407
- }
408
- function encodeSnapshotUploadArchive(archive) {
409
- return Buffer.from(JSON.stringify(archive), "utf8").toString("base64");
410
- }
411
- async function writeSnapshotUploadArchive(projectRoot, outputPath, options = {}) {
412
- const archive = await createSnapshotUploadArchive(projectRoot, options);
413
- const target = resolve3(outputPath);
414
- await mkdir(dirname2(target), { recursive: true });
415
- await writeFile(target, JSON.stringify(archive, null, 2), "utf8");
416
- return archive;
417
- }
418
- async function uploadSnapshotArchiveViaServer(context, input) {
419
- const payload = await requestServerJson(context, `/api/projects/${encodeURIComponent(input.repoSlug)}/upload-snapshot`, {
420
- method: "POST",
421
- headers: { "content-type": "application/json" },
422
- body: JSON.stringify({
423
- archiveContentBase64: encodeSnapshotUploadArchive(input.archive),
424
- contentType: SNAPSHOT_ARCHIVE_CONTENT_TYPE,
425
- baseDir: input.baseDir
426
- })
427
- });
428
- return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
429
- }
430
- function appendUploadedSnapshotPrNotice(body) {
431
- if (body.includes(UPLOADED_SNAPSHOT_PR_MARKER))
432
- return body;
433
- const prefix = body.trimEnd();
434
- const notice = [
435
- UPLOADED_SNAPSHOT_PR_MARKER,
436
- "This PR was seeded from an uploaded local working-tree snapshot. Review local snapshot provenance before merging if repository policy requires it."
437
- ].join(`
438
- `);
439
- return prefix.length > 0 ? `${prefix}
440
-
441
- ${notice}
442
- ` : `${notice}
443
- `;
444
- }
445
- export {
446
- writeSnapshotUploadArchive,
447
- uploadSnapshotArchiveViaServer,
448
- encodeSnapshotUploadArchive,
449
- createSnapshotUploadArchive,
450
- buildSnapshotUploadManifest,
451
- appendUploadedSnapshotPrNotice,
452
- UPLOADED_SNAPSHOT_PR_MARKER,
453
- SNAPSHOT_ARCHIVE_VERSION,
454
- SNAPSHOT_ARCHIVE_CONTENT_TYPE
455
- };
@@ -1,9 +0,0 @@
1
- import type { WorkspaceTaskRecord } from "./_server-client";
2
- import { renderTaskPickerRows, type TaskPickerRenderer } from "./_operator-surface";
3
- export { renderTaskPickerRows, type TaskPickerRenderer };
4
- export type TaskPickerIO = {
5
- readonly isTty?: boolean;
6
- readonly prompt?: (question: string) => Promise<string>;
7
- readonly renderer?: TaskPickerRenderer;
8
- };
9
- export declare function selectTaskWithTextPicker(tasks: readonly WorkspaceTaskRecord[], io?: TaskPickerIO): Promise<WorkspaceTaskRecord | null>;