@h-rig/cli 0.0.6-alpha.90 → 0.0.6-alpha.92
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.js +22 -10
- package/dist/bin/rig.d.ts +71 -1
- package/dist/bin/rig.js +15078 -11169
- package/dist/config/rig-default-config.yml +5 -0
- package/dist/src/app/drone-ui.d.ts +11 -14
- package/dist/src/app/drone-ui.js +70 -86
- package/dist/src/commands/_async-ui.d.ts +1 -4
- package/dist/src/commands/_async-ui.js +9 -111
- package/dist/src/commands/_cli-format.d.ts +16 -9
- package/dist/src/commands/_cli-format.js +167 -295
- package/dist/src/commands/_connection-state.d.ts +11 -1
- package/dist/src/commands/_connection-state.js +50 -5
- package/dist/src/commands/_doctor-checks.d.ts +0 -6
- package/dist/src/commands/_doctor-checks.js +79 -382
- package/dist/src/commands/_help-catalog.d.ts +1 -1
- package/dist/src/commands/_help-catalog.js +217 -157
- 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.js +4 -0
- package/dist/src/commands/_lazy-reconcile.d.ts +34 -0
- package/dist/src/commands/_lazy-reconcile.js +102 -0
- package/dist/src/commands/_paths.js +1 -1
- package/dist/src/commands/_pi-frontend.d.ts +18 -10
- package/dist/src/commands/_pi-frontend.js +37 -715
- package/dist/src/commands/_pi-install.js +18 -36
- package/dist/src/commands/_policy.d.ts +1 -1
- package/dist/src/commands/_policy.js +56 -15
- 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 +8 -81
- package/dist/src/commands/_run-driver-helpers.js +79 -283
- 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.js +1 -1
- package/dist/src/commands/agent.d.ts +1 -1
- package/dist/src/commands/agent.js +8559 -239
- package/dist/src/commands/dist.d.ts +1 -1
- package/dist/src/commands/dist.js +27 -19
- package/dist/src/commands/doctor.d.ts +1 -1
- package/dist/src/commands/doctor.js +93 -475
- package/dist/src/commands/github.d.ts +1 -1
- package/dist/src/commands/github.js +113 -387
- package/dist/src/commands/inbox.d.ts +22 -24
- package/dist/src/commands/inbox.js +420 -691
- package/dist/src/commands/init.d.ts +6 -16
- package/dist/src/commands/init.js +334 -971
- package/dist/src/commands/inspect.d.ts +19 -2
- package/dist/src/commands/inspect.js +644 -610
- package/dist/src/commands/pi.d.ts +1 -1
- package/dist/src/commands/plugin.d.ts +1 -1
- package/dist/src/commands/plugin.js +486 -7
- package/dist/src/commands/profile-and-review.d.ts +1 -1
- package/dist/src/commands/profile-and-review.js +94 -56
- package/dist/src/commands/queue.js +1 -21
- package/dist/src/commands/remote.d.ts +1 -1
- package/dist/src/commands/remote.js +837 -14
- package/dist/src/commands/repo-git-harness.d.ts +1 -1
- package/dist/src/commands/repo-git-harness.js +57 -14
- package/dist/src/commands/run.d.ts +20 -2
- package/dist/src/commands/run.js +17579 -1759
- package/dist/src/commands/server.d.ts +2 -6
- package/dist/src/commands/server.js +141 -723
- package/dist/src/commands/setup.d.ts +1 -1
- package/dist/src/commands/setup.js +102 -484
- package/dist/src/commands/stats.d.ts +13 -10
- package/dist/src/commands/stats.js +689 -761
- package/dist/src/commands/task-run-driver.d.ts +50 -88
- package/dist/src/commands/task-run-driver.js +116 -2717
- package/dist/src/commands/task.d.ts +34 -13
- package/dist/src/commands/task.js +668 -2523
- package/dist/src/commands/test.d.ts +1 -1
- package/dist/src/commands/triage.d.ts +11 -0
- package/dist/src/commands/triage.js +227 -0
- package/dist/src/commands/workspace.d.ts +1 -1
- package/dist/src/commands.d.ts +0 -16
- package/dist/src/commands.js +16657 -12250
- package/dist/src/index.js +16528 -12497
- package/dist/src/launcher.js +4 -0
- 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/package.json +18 -12
- package/dist/src/app/board.d.ts +0 -23
- package/dist/src/app/board.js +0 -1786
- package/dist/src/app/theme.d.ts +0 -47
- package/dist/src/app/theme.js +0 -150
- package/dist/src/commands/_authority-runs.d.ts +0 -22
- package/dist/src/commands/_authority-runs.js +0 -110
- package/dist/src/commands/_operator-surface.d.ts +0 -34
- package/dist/src/commands/_operator-surface.js +0 -220
- package/dist/src/commands/_operator-view.d.ts +0 -30
- package/dist/src/commands/_operator-view.js +0 -1070
- package/dist/src/commands/_preflight.d.ts +0 -22
- package/dist/src/commands/_preflight.js +0 -540
- package/dist/src/commands/_run-replay.d.ts +0 -24
- package/dist/src/commands/_run-replay.js +0 -142
- package/dist/src/commands/_server-client.d.ts +0 -186
- package/dist/src/commands/_server-client.js +0 -681
- package/dist/src/commands/_snapshot-upload.d.ts +0 -39
- package/dist/src/commands/_snapshot-upload.js +0 -455
- package/dist/src/commands/_task-picker.d.ts +0 -9
- package/dist/src/commands/_task-picker.js +0 -201
- package/dist/src/commands/browser.d.ts +0 -65
- package/dist/src/commands/browser.js +0 -1173
- package/dist/src/commands/connect.d.ts +0 -7
- package/dist/src/commands/connect.js +0 -419
- package/dist/src/commands/inspector.d.ts +0 -3
- package/dist/src/commands/inspector.js +0 -263
- package/dist/src/commands/task-report-bug.d.ts +0 -19
- package/dist/src/commands/task-report-bug.js +0 -1281
- package/dist/src/report-bug.d.ts +0 -44
- package/dist/src/report-bug.js +0 -260
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { type RunnerContext } from "../runner";
|
|
2
|
-
export type TaskRunPreflightStatus = "pass" | "warn" | "fail";
|
|
3
|
-
export type TaskRunPreflightCheck = {
|
|
4
|
-
readonly id: string;
|
|
5
|
-
readonly label: string;
|
|
6
|
-
readonly status: TaskRunPreflightStatus;
|
|
7
|
-
readonly detail?: string;
|
|
8
|
-
readonly remediation?: string;
|
|
9
|
-
};
|
|
10
|
-
export type TaskRunPreflightResult = {
|
|
11
|
-
readonly ok: boolean;
|
|
12
|
-
readonly checks: readonly TaskRunPreflightCheck[];
|
|
13
|
-
};
|
|
14
|
-
export type TaskRunPreflightOptions = {
|
|
15
|
-
readonly taskId?: string | null;
|
|
16
|
-
readonly runtimeAdapter?: "claude-code" | "codex" | "pi";
|
|
17
|
-
readonly requestJson?: (pathname: string, init?: RequestInit) => Promise<unknown>;
|
|
18
|
-
};
|
|
19
|
-
export declare function runFastTaskRunPreflight(context: RunnerContext, options?: TaskRunPreflightOptions): Promise<TaskRunPreflightResult>;
|
|
20
|
-
export declare function runProjectMainSyncPreflight(context: RunnerContext, options: {
|
|
21
|
-
disabled: boolean;
|
|
22
|
-
}): Promise<void>;
|
|
@@ -1,540 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// packages/cli/src/runner.ts
|
|
3
|
-
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
4
|
-
import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
|
|
5
|
-
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
6
|
-
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
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
|
-
}
|
|
17
|
-
|
|
18
|
-
// packages/cli/src/commands/_preflight.ts
|
|
19
|
-
import { ensureProjectMainFreshBeforeRun } from "@rig/runtime/control-plane/project-main-pre-run-sync";
|
|
20
|
-
|
|
21
|
-
// packages/cli/src/commands/_connection-state.ts
|
|
22
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
23
|
-
import { homedir } from "os";
|
|
24
|
-
import { dirname, resolve } from "path";
|
|
25
|
-
function resolveGlobalConnectionsPath(env = process.env) {
|
|
26
|
-
const explicit = env.RIG_CONNECTIONS_FILE?.trim();
|
|
27
|
-
if (explicit)
|
|
28
|
-
return resolve(explicit);
|
|
29
|
-
const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
|
|
30
|
-
if (stateDir)
|
|
31
|
-
return resolve(stateDir, "connections.json");
|
|
32
|
-
return resolve(homedir(), ".rig", "connections.json");
|
|
33
|
-
}
|
|
34
|
-
function resolveRepoConnectionPath(projectRoot) {
|
|
35
|
-
return resolve(projectRoot, ".rig", "state", "connection.json");
|
|
36
|
-
}
|
|
37
|
-
function readJsonFile(path) {
|
|
38
|
-
if (!existsSync(path))
|
|
39
|
-
return null;
|
|
40
|
-
try {
|
|
41
|
-
return JSON.parse(readFileSync(path, "utf8"));
|
|
42
|
-
} catch (error) {
|
|
43
|
-
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>`." });
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function writeJsonFile(path, value) {
|
|
47
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
48
|
-
writeFileSync(path, `${JSON.stringify(value, null, 2)}
|
|
49
|
-
`, "utf8");
|
|
50
|
-
}
|
|
51
|
-
function normalizeConnection(value) {
|
|
52
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
53
|
-
return null;
|
|
54
|
-
const record = value;
|
|
55
|
-
if (record.kind === "local")
|
|
56
|
-
return { kind: "local", mode: "auto" };
|
|
57
|
-
if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
|
|
58
|
-
const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
|
|
59
|
-
return { kind: "remote", baseUrl };
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
function readGlobalConnections(options = {}) {
|
|
64
|
-
const path = resolveGlobalConnectionsPath(options.env ?? process.env);
|
|
65
|
-
const payload = readJsonFile(path);
|
|
66
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
67
|
-
return { connections: {} };
|
|
68
|
-
}
|
|
69
|
-
const rawConnections = payload.connections;
|
|
70
|
-
const connections = {};
|
|
71
|
-
if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
|
|
72
|
-
for (const [alias, raw] of Object.entries(rawConnections)) {
|
|
73
|
-
const connection = normalizeConnection(raw);
|
|
74
|
-
if (connection)
|
|
75
|
-
connections[alias] = connection;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return { connections };
|
|
79
|
-
}
|
|
80
|
-
function readRepoConnection(projectRoot) {
|
|
81
|
-
const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
|
|
82
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
83
|
-
return null;
|
|
84
|
-
const record = payload;
|
|
85
|
-
const selected = typeof record.selected === "string" ? record.selected.trim() : "";
|
|
86
|
-
if (!selected)
|
|
87
|
-
return null;
|
|
88
|
-
return {
|
|
89
|
-
selected,
|
|
90
|
-
project: typeof record.project === "string" ? record.project : undefined,
|
|
91
|
-
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
|
|
92
|
-
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function writeRepoConnection(projectRoot, state) {
|
|
96
|
-
writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
|
|
97
|
-
}
|
|
98
|
-
function resolveSelectedConnection(projectRoot, options = {}) {
|
|
99
|
-
const repo = readRepoConnection(projectRoot);
|
|
100
|
-
if (!repo)
|
|
101
|
-
return null;
|
|
102
|
-
if (repo.selected === "local")
|
|
103
|
-
return { alias: "local", connection: { kind: "local", mode: "auto" }, serverProjectRoot: repo.serverProjectRoot };
|
|
104
|
-
const global = readGlobalConnections(options);
|
|
105
|
-
const connection = global.connections[repo.selected];
|
|
106
|
-
if (!connection) {
|
|
107
|
-
throw new CliError(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
108
|
-
}
|
|
109
|
-
return { alias: repo.selected, connection, serverProjectRoot: repo.serverProjectRoot };
|
|
110
|
-
}
|
|
111
|
-
function writeRepoServerProjectRoot(projectRoot, serverProjectRoot) {
|
|
112
|
-
const repo = readRepoConnection(projectRoot);
|
|
113
|
-
if (!repo)
|
|
114
|
-
return;
|
|
115
|
-
writeRepoConnection(projectRoot, { ...repo, serverProjectRoot });
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// packages/cli/src/commands/_server-client.ts
|
|
119
|
-
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
120
|
-
import { resolve as resolve2 } from "path";
|
|
121
|
-
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
122
|
-
var scopedGitHubBearerTokens = new Map;
|
|
123
|
-
var serverPhaseListener = null;
|
|
124
|
-
function reportServerPhase(label) {
|
|
125
|
-
serverPhaseListener?.(label);
|
|
126
|
-
}
|
|
127
|
-
function cleanToken(value) {
|
|
128
|
-
const trimmed = value?.trim();
|
|
129
|
-
return trimmed ? trimmed : null;
|
|
130
|
-
}
|
|
131
|
-
function readPrivateRemoteSessionToken(projectRoot) {
|
|
132
|
-
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
133
|
-
if (!existsSync2(path))
|
|
134
|
-
return null;
|
|
135
|
-
try {
|
|
136
|
-
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
137
|
-
return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
|
|
138
|
-
} catch {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
function readGitHubBearerTokenForRemote(projectRoot) {
|
|
143
|
-
const scopedKey = resolve2(projectRoot);
|
|
144
|
-
if (scopedGitHubBearerTokens.has(scopedKey))
|
|
145
|
-
return scopedGitHubBearerTokens.get(scopedKey) ?? null;
|
|
146
|
-
const privateSession = readPrivateRemoteSessionToken(projectRoot);
|
|
147
|
-
if (privateSession)
|
|
148
|
-
return privateSession;
|
|
149
|
-
return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
|
|
150
|
-
}
|
|
151
|
-
function readStoredGitHubAuthToken(projectRoot) {
|
|
152
|
-
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
153
|
-
if (!existsSync2(path))
|
|
154
|
-
return null;
|
|
155
|
-
try {
|
|
156
|
-
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
157
|
-
return cleanToken(typeof parsed.token === "string" ? parsed.token : undefined);
|
|
158
|
-
} catch {
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
function readLocalConnectionFallbackToken(projectRoot) {
|
|
163
|
-
return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
|
|
164
|
-
}
|
|
165
|
-
async function ensureServerForCli(projectRoot) {
|
|
166
|
-
try {
|
|
167
|
-
const selected = resolveSelectedConnection(projectRoot);
|
|
168
|
-
if (selected?.connection.kind === "remote") {
|
|
169
|
-
reportServerPhase(`Connecting to ${selected.alias}\u2026`);
|
|
170
|
-
const authToken = readGitHubBearerTokenForRemote(projectRoot);
|
|
171
|
-
const serverProjectRoot = selected.serverProjectRoot ?? await backfillRemoteServerProjectRoot(projectRoot, selected.connection.baseUrl, authToken);
|
|
172
|
-
return {
|
|
173
|
-
baseUrl: selected.connection.baseUrl,
|
|
174
|
-
authToken,
|
|
175
|
-
connectionKind: "remote",
|
|
176
|
-
serverProjectRoot
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
reportServerPhase("Starting local Rig server\u2026");
|
|
180
|
-
const connection = await ensureLocalRigServerConnection(projectRoot);
|
|
181
|
-
return {
|
|
182
|
-
baseUrl: connection.baseUrl,
|
|
183
|
-
authToken: connection.authToken ?? readLocalConnectionFallbackToken(projectRoot),
|
|
184
|
-
connectionKind: "local",
|
|
185
|
-
serverProjectRoot: resolve2(projectRoot)
|
|
186
|
-
};
|
|
187
|
-
} catch (error) {
|
|
188
|
-
if (error instanceof Error) {
|
|
189
|
-
throw new CliError(error.message, 1);
|
|
190
|
-
}
|
|
191
|
-
throw error;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
async function backfillRemoteServerProjectRoot(projectRoot, baseUrl, authToken) {
|
|
195
|
-
const repo = readRepoConnection(projectRoot);
|
|
196
|
-
const slug = repo?.project?.trim();
|
|
197
|
-
if (!slug)
|
|
198
|
-
return null;
|
|
199
|
-
try {
|
|
200
|
-
const response = await fetch(`${baseUrl}/api/projects/${encodeURIComponent(slug)}`, {
|
|
201
|
-
headers: mergeHeaders(undefined, authToken)
|
|
202
|
-
});
|
|
203
|
-
if (!response.ok)
|
|
204
|
-
return null;
|
|
205
|
-
const payload = await response.json();
|
|
206
|
-
const project = payload.project && typeof payload.project === "object" && !Array.isArray(payload.project) ? payload.project : null;
|
|
207
|
-
const checkouts = Array.isArray(project?.checkouts) ? project.checkouts : [];
|
|
208
|
-
const latestCheckout = [...checkouts].reverse().find((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry) && typeof entry.path === "string"));
|
|
209
|
-
const path = typeof latestCheckout?.path === "string" && latestCheckout.path.trim() ? latestCheckout.path.trim() : null;
|
|
210
|
-
if (path)
|
|
211
|
-
writeRepoServerProjectRoot(projectRoot, path);
|
|
212
|
-
return path;
|
|
213
|
-
} catch {
|
|
214
|
-
return null;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
function mergeHeaders(headers, authToken) {
|
|
218
|
-
const merged = new Headers(headers);
|
|
219
|
-
if (authToken) {
|
|
220
|
-
merged.set("authorization", `Bearer ${authToken}`);
|
|
221
|
-
}
|
|
222
|
-
return merged;
|
|
223
|
-
}
|
|
224
|
-
function diagnosticMessage(payload) {
|
|
225
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
226
|
-
return null;
|
|
227
|
-
const record = payload;
|
|
228
|
-
const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
|
|
229
|
-
const messages = diagnostics.flatMap((entry) => {
|
|
230
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
231
|
-
return [];
|
|
232
|
-
const diagnostic = entry;
|
|
233
|
-
const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
|
|
234
|
-
const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
|
|
235
|
-
return message ? [`${kind}: ${message}`] : [];
|
|
236
|
-
});
|
|
237
|
-
return messages.length > 0 ? messages.join("; ") : null;
|
|
238
|
-
}
|
|
239
|
-
var serverReachabilityCache = new Map;
|
|
240
|
-
async function probeServerReachability(baseUrl, authToken) {
|
|
241
|
-
try {
|
|
242
|
-
const response = await fetch(`${baseUrl.replace(/\/+$/, "")}/api/server/status`, {
|
|
243
|
-
headers: mergeHeaders(undefined, authToken),
|
|
244
|
-
signal: AbortSignal.timeout(1500)
|
|
245
|
-
});
|
|
246
|
-
return response.ok;
|
|
247
|
-
} catch {
|
|
248
|
-
return false;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
function cachedServerReachability(projectRoot, baseUrl, authToken) {
|
|
252
|
-
const key = resolve2(projectRoot);
|
|
253
|
-
const cached = serverReachabilityCache.get(key);
|
|
254
|
-
if (cached)
|
|
255
|
-
return cached;
|
|
256
|
-
const probe = probeServerReachability(baseUrl, authToken);
|
|
257
|
-
serverReachabilityCache.set(key, probe);
|
|
258
|
-
return probe;
|
|
259
|
-
}
|
|
260
|
-
function describeSelectedServer(projectRoot, server) {
|
|
261
|
-
try {
|
|
262
|
-
const selected = resolveSelectedConnection(projectRoot);
|
|
263
|
-
if (selected) {
|
|
264
|
-
return {
|
|
265
|
-
alias: selected.alias,
|
|
266
|
-
target: selected.connection.kind === "remote" ? selected.connection.baseUrl : server.baseUrl
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
} catch {}
|
|
270
|
-
return { alias: server.connectionKind === "remote" ? "remote" : "local", target: server.baseUrl };
|
|
271
|
-
}
|
|
272
|
-
async function buildServerFailureContext(projectRoot, server) {
|
|
273
|
-
const { alias, target } = describeSelectedServer(projectRoot, server);
|
|
274
|
-
const reachable = await cachedServerReachability(projectRoot, server.baseUrl, server.authToken);
|
|
275
|
-
const reachability = reachable ? "server is reachable" : "server is unreachable";
|
|
276
|
-
return {
|
|
277
|
-
contextLine: `Currently connected to: ${alias} at ${target} (${reachability}).`,
|
|
278
|
-
hint: "Check the selected server with `rig server status`, or switch with `rig server use <alias|local>`."
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
async function requestServerJson(context, pathname, init = {}) {
|
|
282
|
-
const server = await ensureServerForCli(context.projectRoot);
|
|
283
|
-
const headers = mergeHeaders(init.headers, server.authToken);
|
|
284
|
-
if (server.serverProjectRoot)
|
|
285
|
-
headers.set("x-rig-project-root", server.serverProjectRoot);
|
|
286
|
-
reportServerPhase(`${(init.method ?? "GET").toUpperCase()} ${pathname.split("?")[0]}\u2026`);
|
|
287
|
-
let response;
|
|
288
|
-
try {
|
|
289
|
-
response = await fetch(`${server.baseUrl}${pathname}`, {
|
|
290
|
-
...init,
|
|
291
|
-
headers
|
|
292
|
-
});
|
|
293
|
-
} catch (error) {
|
|
294
|
-
const failure = await buildServerFailureContext(context.projectRoot, server);
|
|
295
|
-
throw new CliError(`Rig server request failed: ${error instanceof Error ? error.message : String(error)}
|
|
296
|
-
${failure.contextLine}`, 1, { hint: failure.hint });
|
|
297
|
-
}
|
|
298
|
-
const text = await response.text();
|
|
299
|
-
const payload = text.trim().length > 0 ? (() => {
|
|
300
|
-
try {
|
|
301
|
-
return JSON.parse(text);
|
|
302
|
-
} catch {
|
|
303
|
-
return null;
|
|
304
|
-
}
|
|
305
|
-
})() : null;
|
|
306
|
-
if (!response.ok) {
|
|
307
|
-
const diagnostics = diagnosticMessage(payload);
|
|
308
|
-
const rawDetail = diagnostics ?? (text || response.statusText);
|
|
309
|
-
const detail = diagnostics ? rawDetail : rawDetail.split(`
|
|
310
|
-
`).map((line) => line.trim()).find((line) => line.length > 0)?.slice(0, 200) ?? response.statusText;
|
|
311
|
-
const failure = await buildServerFailureContext(context.projectRoot, server);
|
|
312
|
-
throw new CliError(`Rig server request failed (${response.status}): ${detail}
|
|
313
|
-
${failure.contextLine}`, 1, { hint: failure.hint });
|
|
314
|
-
}
|
|
315
|
-
return payload;
|
|
316
|
-
}
|
|
317
|
-
var RESUMABLE_RUN_STATUSES = new Set([
|
|
318
|
-
"created",
|
|
319
|
-
"preparing",
|
|
320
|
-
"running",
|
|
321
|
-
"validating",
|
|
322
|
-
"reviewing",
|
|
323
|
-
"stopped",
|
|
324
|
-
"failed",
|
|
325
|
-
"needs-attention",
|
|
326
|
-
"needs_attention"
|
|
327
|
-
]);
|
|
328
|
-
|
|
329
|
-
// packages/cli/src/commands/_preflight.ts
|
|
330
|
-
function preflightCheck(id, label, status, detail, remediation) {
|
|
331
|
-
return {
|
|
332
|
-
id,
|
|
333
|
-
label,
|
|
334
|
-
status,
|
|
335
|
-
...detail ? { detail } : {},
|
|
336
|
-
...remediation ? { remediation } : {}
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
function message(error) {
|
|
340
|
-
return error instanceof Error ? error.message : String(error);
|
|
341
|
-
}
|
|
342
|
-
function isAuthenticated(payload) {
|
|
343
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
344
|
-
return false;
|
|
345
|
-
const record = payload;
|
|
346
|
-
return record.signedIn === true || record.authenticated === true || record.status === "authenticated" || record.ok === true && typeof record.login === "string" && record.login.trim().length > 0;
|
|
347
|
-
}
|
|
348
|
-
function taskMatchesId(entry, taskId) {
|
|
349
|
-
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
350
|
-
return false;
|
|
351
|
-
const record = entry;
|
|
352
|
-
if (record.id === taskId || record.taskId === taskId)
|
|
353
|
-
return true;
|
|
354
|
-
const raw = record.raw;
|
|
355
|
-
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
356
|
-
const rawRecord = raw;
|
|
357
|
-
if (String(rawRecord.number ?? "") === taskId.replace(/^#/, ""))
|
|
358
|
-
return true;
|
|
359
|
-
}
|
|
360
|
-
return false;
|
|
361
|
-
}
|
|
362
|
-
function isActiveRunStatus(status) {
|
|
363
|
-
const normalized = String(status ?? "running").toLowerCase();
|
|
364
|
-
return !["completed", "complete", "done", "merged", "closed", "failed", "cancelled", "canceled", "needs_attention", "needs-attention", "stopped"].includes(normalized);
|
|
365
|
-
}
|
|
366
|
-
function permissionAllowsPr(payload) {
|
|
367
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
368
|
-
return null;
|
|
369
|
-
const record = payload;
|
|
370
|
-
if (record.canOpenPullRequest === true || record.pullRequests === true || record.push === true || record.maintain === true || record.admin === true)
|
|
371
|
-
return true;
|
|
372
|
-
if (record.canOpenPullRequest === false || record.pullRequests === false || record.push === false)
|
|
373
|
-
return false;
|
|
374
|
-
const permissions = record.permissions;
|
|
375
|
-
if (permissions && typeof permissions === "object" && !Array.isArray(permissions)) {
|
|
376
|
-
const p = permissions;
|
|
377
|
-
if (p.push === true || p.maintain === true || p.admin === true)
|
|
378
|
-
return true;
|
|
379
|
-
if (p.push === false && p.maintain !== true && p.admin !== true)
|
|
380
|
-
return false;
|
|
381
|
-
}
|
|
382
|
-
return null;
|
|
383
|
-
}
|
|
384
|
-
function isNotFoundError(error) {
|
|
385
|
-
return /\b(404|not found)\b/i.test(message(error));
|
|
386
|
-
}
|
|
387
|
-
function projectCheckoutReady(payload) {
|
|
388
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
389
|
-
return null;
|
|
390
|
-
const record = payload;
|
|
391
|
-
if (record.checkoutReady === true || record.ready === true)
|
|
392
|
-
return true;
|
|
393
|
-
if (record.checkoutReady === false || record.ready === false)
|
|
394
|
-
return false;
|
|
395
|
-
const project = record.project;
|
|
396
|
-
if (project && typeof project === "object" && !Array.isArray(project)) {
|
|
397
|
-
const checkouts = project.checkouts;
|
|
398
|
-
if (Array.isArray(checkouts))
|
|
399
|
-
return checkouts.length > 0;
|
|
400
|
-
}
|
|
401
|
-
return null;
|
|
402
|
-
}
|
|
403
|
-
function activeDuplicateRun(runs, taskId) {
|
|
404
|
-
if (!Array.isArray(runs))
|
|
405
|
-
return null;
|
|
406
|
-
for (const run of runs) {
|
|
407
|
-
if (!run || typeof run !== "object" || Array.isArray(run))
|
|
408
|
-
continue;
|
|
409
|
-
const record = run;
|
|
410
|
-
if ((record.taskId === taskId || record.task === taskId) && isActiveRunStatus(record.status))
|
|
411
|
-
return record;
|
|
412
|
-
}
|
|
413
|
-
return null;
|
|
414
|
-
}
|
|
415
|
-
async function runFastTaskRunPreflight(context, options = {}) {
|
|
416
|
-
const checks = [];
|
|
417
|
-
const request = options.requestJson ?? ((pathname, init) => requestServerJson(context, pathname, init));
|
|
418
|
-
const taskId = options.taskId?.trim() || null;
|
|
419
|
-
const requiresCurrentRunApi = Boolean(taskId);
|
|
420
|
-
const selectedServer = options.requestJson ? null : await ensureServerForCli(context.projectRoot).catch(() => null);
|
|
421
|
-
const allowLocalLegacyTaskRunCompatibility = selectedServer?.connectionKind === "local";
|
|
422
|
-
let legacyServerCompatibility = false;
|
|
423
|
-
try {
|
|
424
|
-
await request("/api/server/status");
|
|
425
|
-
checks.push(preflightCheck("server", "Rig server reachable", "pass"));
|
|
426
|
-
} catch (error) {
|
|
427
|
-
if (isNotFoundError(error)) {
|
|
428
|
-
try {
|
|
429
|
-
await request("/health");
|
|
430
|
-
legacyServerCompatibility = !requiresCurrentRunApi || allowLocalLegacyTaskRunCompatibility;
|
|
431
|
-
checks.push(requiresCurrentRunApi && !allowLocalLegacyTaskRunCompatibility ? preflightCheck("server", "Rig server reachable", "fail", "legacy /health endpoint only; current task-run APIs are required", "Upgrade/select the Rig server before launching a task run.") : preflightCheck("server", "Rig server reachable", "pass", allowLocalLegacyTaskRunCompatibility ? "local legacy /health endpoint; submit endpoint will be authoritative" : "legacy /health endpoint"));
|
|
432
|
-
} catch (healthError) {
|
|
433
|
-
checks.push(preflightCheck("server", "Rig server reachable", "fail", message(healthError), "Start or select a reachable Rig server."));
|
|
434
|
-
}
|
|
435
|
-
} else {
|
|
436
|
-
checks.push(preflightCheck("server", "Rig server reachable", "fail", message(error), "Start or select a reachable Rig server."));
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
const repo = readRepoConnection(context.projectRoot);
|
|
440
|
-
checks.push(repo ? preflightCheck("project-link", "project linked to Rig server", repo.project ? "pass" : "warn", `${repo.selected}${repo.project ? ` -> ${repo.project}` : ""}`, "Run `rig init --yes --repo owner/repo` to record the GitHub repo slug.") : preflightCheck("project-link", "project linked to Rig server", legacyServerCompatibility ? "warn" : "fail", "missing .rig/state/connection.json", "Run `rig init` or `rig server use <alias|local>`."));
|
|
441
|
-
try {
|
|
442
|
-
const auth = await request("/api/github/auth/status");
|
|
443
|
-
checks.push(isAuthenticated(auth) ? preflightCheck("github-auth", "GitHub auth valid", "pass") : preflightCheck("github-auth", "GitHub auth valid", legacyServerCompatibility ? "warn" : "fail", "not authenticated", "Run `rig github auth import-gh` or `rig github auth token --token <token>`."));
|
|
444
|
-
} catch (error) {
|
|
445
|
-
checks.push(preflightCheck("github-auth", "GitHub auth valid", legacyServerCompatibility ? "warn" : "fail", message(error), "Fix GitHub auth on the selected Rig server."));
|
|
446
|
-
}
|
|
447
|
-
try {
|
|
448
|
-
const projection = await request("/api/workspace/task-projection");
|
|
449
|
-
checks.push(preflightCheck("task-projection", "task projection ready", "pass", JSON.stringify(projection).slice(0, 120)));
|
|
450
|
-
} catch (error) {
|
|
451
|
-
checks.push(preflightCheck("task-projection", "task projection ready", "warn", message(error), "Refresh task projection with `rig task list` before launching."));
|
|
452
|
-
}
|
|
453
|
-
try {
|
|
454
|
-
const permissions = await request("/api/github/repo/permissions");
|
|
455
|
-
const allowed = permissionAllowsPr(permissions);
|
|
456
|
-
checks.push(allowed === false ? preflightCheck("github-repo-permissions", "GitHub PR permissions", "fail", JSON.stringify(permissions).slice(0, 120), "Grant the selected GitHub token permission to push branches and open PRs.") : preflightCheck("github-repo-permissions", "GitHub PR permissions", allowed === true ? "pass" : "warn", JSON.stringify(permissions).slice(0, 120), "Confirm the selected token can push branches and open PRs."));
|
|
457
|
-
} catch (error) {
|
|
458
|
-
checks.push(preflightCheck("github-repo-permissions", "GitHub PR permissions", "warn", message(error), "Ensure the selected token can push branches and open PRs."));
|
|
459
|
-
}
|
|
460
|
-
if (repo?.project) {
|
|
461
|
-
try {
|
|
462
|
-
const project = await request(`/api/projects/${encodeURIComponent(repo.project)}`);
|
|
463
|
-
const ready = projectCheckoutReady(project);
|
|
464
|
-
checks.push(ready === false ? preflightCheck("remote-checkout", "execution checkout ready", "fail", JSON.stringify(project).slice(0, 120), "Repair the server checkout or rerun `rig init` with a valid checkout strategy.") : preflightCheck("remote-checkout", "execution checkout ready", ready === true ? "pass" : "warn", JSON.stringify(project).slice(0, 120), "Confirm the selected server has a prepared execution checkout."));
|
|
465
|
-
} catch (error) {
|
|
466
|
-
checks.push(preflightCheck("remote-checkout", "execution checkout ready", "warn", message(error), "Run `rig init` or repair the server checkout before launch."));
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
if (taskId) {
|
|
470
|
-
try {
|
|
471
|
-
const tasks = await request(`/api/workspace/tasks?limit=200&refresh=1`);
|
|
472
|
-
const found = Array.isArray(tasks) && tasks.some((task) => taskMatchesId(task, taskId));
|
|
473
|
-
checks.push(found ? preflightCheck("issue", "task/issue accessible", "pass", taskId) : preflightCheck("issue", "task/issue accessible", legacyServerCompatibility ? "warn" : "fail", taskId, "Confirm the issue exists and matches the configured task filters."));
|
|
474
|
-
} catch (error) {
|
|
475
|
-
checks.push(preflightCheck("issue", "task/issue accessible", legacyServerCompatibility ? "warn" : "fail", message(error), "Fix the task source before launching a run."));
|
|
476
|
-
}
|
|
477
|
-
try {
|
|
478
|
-
const runs = await request("/api/runs?limit=200");
|
|
479
|
-
const duplicate = activeDuplicateRun(runs, taskId);
|
|
480
|
-
checks.push(duplicate ? preflightCheck("duplicate-active-run", "one active run per task", "fail", String(duplicate.runId ?? taskId), "Attach to or stop the existing run before starting another one for this task.") : preflightCheck("duplicate-active-run", "one active run per task", "pass", taskId));
|
|
481
|
-
} catch (error) {
|
|
482
|
-
checks.push(preflightCheck("duplicate-active-run", "one active run per task", "warn", message(error), "Could not list active runs; the server will still reject conflicting runs if configured."));
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
if ((options.runtimeAdapter ?? "pi") === "pi") {
|
|
486
|
-
checks.push(preflightCheck("runtime", "worker Pi SDK session daemon", "pass", selectedServer?.connectionKind === "remote" ? "remote worker-owned runtime" : "bundled server-owned runtime"));
|
|
487
|
-
} else {
|
|
488
|
-
checks.push(preflightCheck("runtime", "runtime adapter", "pass", options.runtimeAdapter));
|
|
489
|
-
}
|
|
490
|
-
const failures = checks.filter((check) => check.status === "fail");
|
|
491
|
-
if (failures.length > 0) {
|
|
492
|
-
const summary = failures.map((check) => `${check.label}${check.detail ? `: ${check.detail}` : ""}`).join("; ");
|
|
493
|
-
if (failures.some((check) => check.id === "duplicate-active-run") && taskId) {
|
|
494
|
-
throw new CliError(`Task ${taskId} already has an active Rig run. ${summary}`, 1, { hint: `Attach to it with \`rig run attach <run-id> --follow\`, or stop it first with \`rig run stop <run-id>\`.` });
|
|
495
|
-
}
|
|
496
|
-
throw new CliError(`Task run preflight failed: ${summary}`, 1, { hint: "Run `rig doctor` to diagnose, then retry `rig task run`." });
|
|
497
|
-
}
|
|
498
|
-
return { ok: true, checks };
|
|
499
|
-
}
|
|
500
|
-
async function runProjectMainSyncPreflight(context, options) {
|
|
501
|
-
if (context.dryRun) {
|
|
502
|
-
if (context.outputMode === "text" && !options.disabled) {
|
|
503
|
-
console.log("[dry-run] project-rig pre-run sync check");
|
|
504
|
-
}
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
const result = await ensureProjectMainFreshBeforeRun({
|
|
508
|
-
projectRoot: context.projectRoot,
|
|
509
|
-
disabled: options.disabled,
|
|
510
|
-
runBootstrap: async () => {
|
|
511
|
-
const bootstrap = await context.runCommand(["bun", "run", "bootstrap"]);
|
|
512
|
-
if (bootstrap.exitCode !== 0) {
|
|
513
|
-
throw new CliError(bootstrap.stderr || bootstrap.stdout || "bun run bootstrap failed during project pre-run sync", bootstrap.exitCode || 1);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
});
|
|
517
|
-
if (context.outputMode !== "text") {
|
|
518
|
-
return;
|
|
519
|
-
}
|
|
520
|
-
switch (result.status) {
|
|
521
|
-
case "disabled":
|
|
522
|
-
console.log("Project pre-run sync skipped (--skip-project-sync).");
|
|
523
|
-
break;
|
|
524
|
-
case "skipped_not_main":
|
|
525
|
-
console.log(`Project pre-run sync skipped (current branch: ${result.branch}).`);
|
|
526
|
-
break;
|
|
527
|
-
case "up_to_date":
|
|
528
|
-
break;
|
|
529
|
-
case "local_ahead":
|
|
530
|
-
console.log(`Project pre-run sync skipped (local main ahead by ${result.localAhead} commit(s)).`);
|
|
531
|
-
break;
|
|
532
|
-
case "updated":
|
|
533
|
-
console.log(`Project pre-run sync updated local main from origin/main (+${result.remoteAhead}) and bootstrapped.`);
|
|
534
|
-
break;
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
export {
|
|
538
|
-
runProjectMainSyncPreflight,
|
|
539
|
-
runFastTaskRunPreflight
|
|
540
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { type AuthorityRunRecord } from "@rig/runtime/control-plane/authority-files";
|
|
2
|
-
export type RunReplayLine = {
|
|
3
|
-
at: string | null;
|
|
4
|
-
source: "run" | "session";
|
|
5
|
-
summary: string;
|
|
6
|
-
};
|
|
7
|
-
export type RunReplayResult = {
|
|
8
|
-
runId: string;
|
|
9
|
-
logPath: string;
|
|
10
|
-
sessionFile: string | null;
|
|
11
|
-
entryCount: number;
|
|
12
|
-
sessionEntryCount: number;
|
|
13
|
-
lines: string[];
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Locate the worker Pi session.jsonl for a run, without ever reading the file
|
|
17
|
-
* during the run lifecycle — replay-time only. Prefers the exact
|
|
18
|
-
* piSession.sessionFile recorded on the run record; falls back to scanning
|
|
19
|
-
* `<piSession.cwd>/.rig/session/` for `*_<sessionId>.jsonl`.
|
|
20
|
-
*/
|
|
21
|
-
export declare function resolveRunSessionFile(record: AuthorityRunRecord | null): string | null;
|
|
22
|
-
export declare function buildRunReplay(projectRoot: string, runId: string, options?: {
|
|
23
|
-
withSession?: boolean;
|
|
24
|
-
}): RunReplayResult;
|