@h-rig/cli 0.0.6-alpha.9 → 0.0.6-alpha.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -19
- package/dist/bin/build-rig-binaries.d.ts +2 -0
- package/dist/bin/build-rig-binaries.js +22 -10
- package/dist/bin/rig.d.ts +72 -0
- package/dist/bin/rig.js +15637 -7344
- package/dist/config/rig-default-config.yml +5 -0
- package/dist/src/app/drone-ui.d.ts +34 -0
- package/dist/src/app/drone-ui.js +278 -0
- package/dist/src/commands/_async-ui.d.ts +10 -0
- package/dist/src/commands/_async-ui.js +121 -0
- package/dist/src/commands/_cli-format.d.ts +56 -0
- package/dist/src/commands/_cli-format.js +319 -0
- package/dist/src/commands/_connection-state.d.ts +54 -0
- package/dist/src/commands/_connection-state.js +75 -11
- package/dist/src/commands/_doctor-checks.d.ts +46 -0
- package/dist/src/commands/_doctor-checks.js +100 -267
- package/dist/src/commands/_help-catalog.d.ts +51 -0
- package/dist/src/commands/_help-catalog.js +502 -0
- package/dist/src/commands/_inprocess-services.d.ts +33 -0
- package/dist/src/commands/_inprocess-services.js +102 -0
- package/dist/src/commands/_json-output.d.ts +11 -0
- package/dist/src/commands/_json-output.js +60 -0
- package/dist/src/commands/_lazy-reconcile.d.ts +34 -0
- package/dist/src/commands/_lazy-reconcile.js +102 -0
- package/dist/src/commands/_parsers.d.ts +15 -0
- package/dist/src/commands/_parsers.js +18 -11
- package/dist/src/commands/_paths.d.ts +11 -0
- package/dist/src/commands/_paths.js +1 -1
- package/dist/src/commands/_pi-frontend.d.ts +35 -0
- package/dist/src/commands/_pi-frontend.js +64 -0
- package/dist/src/commands/_pi-install.d.ts +42 -0
- package/dist/src/commands/_pi-install.js +19 -36
- package/dist/src/commands/_policy.d.ts +8 -0
- package/dist/src/commands/_policy.js +67 -19
- package/dist/src/commands/_probes.d.ts +1 -0
- package/dist/src/commands/_run-bridge.d.ts +114 -0
- package/dist/src/commands/_run-bridge.js +387 -0
- package/dist/src/commands/_run-diagnostics.d.ts +9 -0
- package/dist/src/commands/_run-diagnostics.js +51 -0
- package/dist/src/commands/_run-driver-helpers.d.ts +26 -0
- package/dist/src/commands/_run-driver-helpers.js +79 -230
- package/dist/src/commands/_run-projection.d.ts +50 -0
- package/dist/src/commands/_run-projection.js +349 -0
- package/dist/src/commands/_run-subcommands.d.ts +3 -0
- package/dist/src/commands/_run-subcommands.js +31 -0
- package/dist/src/commands/_spinner.d.ts +25 -0
- package/dist/src/commands/_spinner.js +65 -0
- package/dist/src/commands/agent.d.ts +3 -0
- package/dist/src/commands/agent.js +8575 -236
- package/dist/src/commands/dist.d.ts +28 -0
- package/dist/src/commands/dist.js +44 -29
- package/dist/src/commands/doctor.d.ts +3 -0
- package/dist/src/commands/doctor.js +219 -268
- package/dist/src/commands/github.d.ts +3 -0
- package/dist/src/commands/github.js +236 -188
- package/dist/src/commands/inbox.d.ts +28 -0
- package/dist/src/commands/inbox.js +530 -111
- package/dist/src/commands/init.d.ts +64 -0
- package/dist/src/commands/init.js +912 -705
- package/dist/src/commands/inspect.d.ts +20 -0
- package/dist/src/commands/inspect.js +709 -119
- package/dist/src/commands/pi.d.ts +3 -0
- package/dist/src/commands/pi.js +177 -0
- package/dist/src/commands/plugin.d.ts +16 -0
- package/dist/src/commands/plugin.js +576 -29
- package/dist/src/commands/profile-and-review.d.ts +4 -0
- package/dist/src/commands/profile-and-review.js +112 -67
- package/dist/src/commands/queue.d.ts +3 -0
- package/dist/src/commands/queue.js +20 -20
- package/dist/src/commands/remote.d.ts +3 -0
- package/dist/src/commands/remote.js +880 -50
- package/dist/src/commands/repo-git-harness.d.ts +5 -0
- package/dist/src/commands/repo-git-harness.js +78 -28
- package/dist/src/commands/run.d.ts +21 -0
- package/dist/src/commands/run.js +17701 -661
- package/dist/src/commands/server.d.ts +3 -0
- package/dist/src/commands/server.js +166 -303
- package/dist/src/commands/setup.d.ts +16 -0
- package/dist/src/commands/setup.js +244 -299
- package/dist/src/commands/stats.d.ts +15 -0
- package/dist/src/commands/stats.js +979 -0
- package/dist/src/commands/task-run-driver.d.ts +94 -0
- package/dist/src/commands/task-run-driver.js +116 -1961
- package/dist/src/commands/task.d.ts +35 -0
- package/dist/src/commands/task.js +676 -1201
- package/dist/src/commands/test.d.ts +3 -0
- package/dist/src/commands/test.js +15 -8
- package/dist/src/commands/triage.d.ts +11 -0
- package/dist/src/commands/triage.js +227 -0
- package/dist/src/commands/workspace.d.ts +3 -0
- package/dist/src/commands/workspace.js +18 -11
- package/dist/src/commands.d.ts +13 -0
- package/dist/src/commands.js +16792 -8055
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +16862 -8450
- package/dist/src/launcher.d.ts +61 -0
- package/dist/src/launcher.js +81 -13
- package/dist/src/operator-cli.d.ts +2 -0
- package/dist/src/operator-cli.js +17837 -0
- package/dist/src/operator-entry.d.ts +1 -0
- package/dist/src/operator-entry.js +3 -0
- package/dist/src/runner.d.ts +47 -0
- package/dist/src/runner.js +16 -22
- package/dist/src/withMutedConsole.d.ts +2 -0
- package/package.json +21 -8
- package/dist/src/commands/_authority-runs.js +0 -111
- package/dist/src/commands/_operator-view.js +0 -340
- package/dist/src/commands/_preflight.js +0 -478
- package/dist/src/commands/_server-client.js +0 -382
- package/dist/src/commands/_snapshot-upload.js +0 -331
- package/dist/src/commands/_task-picker.js +0 -48
- package/dist/src/commands/browser.js +0 -890
- package/dist/src/commands/connect.js +0 -180
- package/dist/src/commands/inspector.js +0 -256
- package/dist/src/commands/task-report-bug.js +0 -1083
- package/dist/src/report-bug.js +0 -260
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// packages/cli/src/runner.ts
|
|
3
|
-
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
4
|
-
import { CliError } from "@rig/runtime/control-plane/errors";
|
|
5
|
-
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
6
|
-
import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
|
|
7
|
-
import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
|
|
8
|
-
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
9
|
-
import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
|
|
10
|
-
function requireNoExtraArgs(args, usage) {
|
|
11
|
-
if (args.length > 0) {
|
|
12
|
-
throw new CliError(`Unexpected arguments: ${args.join(" ")}
|
|
13
|
-
Usage: ${usage}`);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// packages/cli/src/commands/_connection-state.ts
|
|
18
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
19
|
-
import { homedir } from "os";
|
|
20
|
-
import { dirname, resolve } from "path";
|
|
21
|
-
function resolveGlobalConnectionsPath(env = process.env) {
|
|
22
|
-
const explicit = env.RIG_CONNECTIONS_FILE?.trim();
|
|
23
|
-
if (explicit)
|
|
24
|
-
return resolve(explicit);
|
|
25
|
-
const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
|
|
26
|
-
if (stateDir)
|
|
27
|
-
return resolve(stateDir, "connections.json");
|
|
28
|
-
return resolve(homedir(), ".rig", "connections.json");
|
|
29
|
-
}
|
|
30
|
-
function resolveRepoConnectionPath(projectRoot) {
|
|
31
|
-
return resolve(projectRoot, ".rig", "state", "connection.json");
|
|
32
|
-
}
|
|
33
|
-
function readJsonFile(path) {
|
|
34
|
-
if (!existsSync(path))
|
|
35
|
-
return null;
|
|
36
|
-
try {
|
|
37
|
-
return JSON.parse(readFileSync(path, "utf8"));
|
|
38
|
-
} catch (error) {
|
|
39
|
-
throw new CliError2(`Invalid Rig connection state at ${path}: ${error instanceof Error ? error.message : String(error)}`, 1);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function writeJsonFile(path, value) {
|
|
43
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
44
|
-
writeFileSync(path, `${JSON.stringify(value, null, 2)}
|
|
45
|
-
`, "utf8");
|
|
46
|
-
}
|
|
47
|
-
function normalizeConnection(value) {
|
|
48
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
49
|
-
return null;
|
|
50
|
-
const record = value;
|
|
51
|
-
if (record.kind === "local")
|
|
52
|
-
return { kind: "local", mode: "auto" };
|
|
53
|
-
if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
|
|
54
|
-
const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
|
|
55
|
-
return { kind: "remote", baseUrl };
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
function readGlobalConnections(options = {}) {
|
|
60
|
-
const path = resolveGlobalConnectionsPath(options.env ?? process.env);
|
|
61
|
-
const payload = readJsonFile(path);
|
|
62
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
63
|
-
return { connections: {} };
|
|
64
|
-
}
|
|
65
|
-
const rawConnections = payload.connections;
|
|
66
|
-
const connections = {};
|
|
67
|
-
if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
|
|
68
|
-
for (const [alias, raw] of Object.entries(rawConnections)) {
|
|
69
|
-
const connection = normalizeConnection(raw);
|
|
70
|
-
if (connection)
|
|
71
|
-
connections[alias] = connection;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return { connections };
|
|
75
|
-
}
|
|
76
|
-
function writeGlobalConnections(state, options = {}) {
|
|
77
|
-
writeJsonFile(resolveGlobalConnectionsPath(options.env ?? process.env), state);
|
|
78
|
-
}
|
|
79
|
-
function upsertGlobalConnection(alias, connection, options = {}) {
|
|
80
|
-
const cleanAlias = alias.trim();
|
|
81
|
-
if (!cleanAlias)
|
|
82
|
-
throw new CliError2("Connection alias is required.", 1);
|
|
83
|
-
const state = readGlobalConnections(options);
|
|
84
|
-
state.connections[cleanAlias] = connection;
|
|
85
|
-
writeGlobalConnections(state, options);
|
|
86
|
-
return state;
|
|
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
|
-
};
|
|
101
|
-
}
|
|
102
|
-
function writeRepoConnection(projectRoot, state) {
|
|
103
|
-
writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// packages/cli/src/commands/connect.ts
|
|
107
|
-
function parseConnection(alias, value) {
|
|
108
|
-
if (alias === "local" && !value)
|
|
109
|
-
return { kind: "local", mode: "auto" };
|
|
110
|
-
if (!value)
|
|
111
|
-
throw new CliError2("Missing remote server URL. Usage: rig connect add <alias> <url>", 1);
|
|
112
|
-
let parsed;
|
|
113
|
-
try {
|
|
114
|
-
parsed = new URL(value);
|
|
115
|
-
} catch {
|
|
116
|
-
throw new CliError2(`Invalid Rig server URL: ${value}`, 1);
|
|
117
|
-
}
|
|
118
|
-
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
|
|
119
|
-
throw new CliError2("Rig remote server URL must be http(s).", 1);
|
|
120
|
-
}
|
|
121
|
-
return { kind: "remote", baseUrl: parsed.toString().replace(/\/+$/, "") };
|
|
122
|
-
}
|
|
123
|
-
function printJsonOrText(context, payload, text) {
|
|
124
|
-
if (context.outputMode === "json") {
|
|
125
|
-
console.log(JSON.stringify(payload, null, 2));
|
|
126
|
-
} else {
|
|
127
|
-
console.log(text);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
async function executeConnect(context, args) {
|
|
131
|
-
const [command, ...rest] = args;
|
|
132
|
-
switch (command ?? "status") {
|
|
133
|
-
case "list": {
|
|
134
|
-
requireNoExtraArgs(rest, "rig connect list");
|
|
135
|
-
const state = readGlobalConnections();
|
|
136
|
-
printJsonOrText(context, state, Object.entries(state.connections).map(([alias, connection]) => `${alias} ${connection.kind === "remote" ? connection.baseUrl : "local"}`).join(`
|
|
137
|
-
`) || "No Rig connections configured.");
|
|
138
|
-
return { ok: true, group: "connect", command: "list", details: state };
|
|
139
|
-
}
|
|
140
|
-
case "add": {
|
|
141
|
-
const [alias, url, ...extra] = rest;
|
|
142
|
-
if (!alias)
|
|
143
|
-
throw new CliError2("Missing alias. Usage: rig connect add <alias> <url>", 1);
|
|
144
|
-
requireNoExtraArgs(extra, "rig connect add <alias> <url>");
|
|
145
|
-
const connection = parseConnection(alias, url);
|
|
146
|
-
const state = upsertGlobalConnection(alias, connection);
|
|
147
|
-
printJsonOrText(context, { alias, connection }, `Added Rig connection ${alias}.`);
|
|
148
|
-
return { ok: true, group: "connect", command: "add", details: { alias, connection, count: Object.keys(state.connections).length } };
|
|
149
|
-
}
|
|
150
|
-
case "use": {
|
|
151
|
-
const [alias, ...extra] = rest;
|
|
152
|
-
if (!alias)
|
|
153
|
-
throw new CliError2("Missing alias. Usage: rig connect use <alias|local>", 1);
|
|
154
|
-
requireNoExtraArgs(extra, "rig connect use <alias|local>");
|
|
155
|
-
if (alias !== "local") {
|
|
156
|
-
const state = readGlobalConnections();
|
|
157
|
-
if (!state.connections[alias])
|
|
158
|
-
throw new CliError2(`Unknown Rig connection: ${alias}`, 1);
|
|
159
|
-
}
|
|
160
|
-
const repoState = { selected: alias, linkedAt: new Date().toISOString() };
|
|
161
|
-
writeRepoConnection(context.projectRoot, repoState);
|
|
162
|
-
printJsonOrText(context, repoState, `Selected Rig connection ${alias} for this repo.`);
|
|
163
|
-
return { ok: true, group: "connect", command: "use", details: repoState };
|
|
164
|
-
}
|
|
165
|
-
case "status": {
|
|
166
|
-
requireNoExtraArgs(rest, "rig connect status");
|
|
167
|
-
const repo = readRepoConnection(context.projectRoot);
|
|
168
|
-
const global = readGlobalConnections();
|
|
169
|
-
const details = { selected: repo?.selected ?? "local", repo, connections: global.connections };
|
|
170
|
-
printJsonOrText(context, details, `Selected Rig connection: ${details.selected}`);
|
|
171
|
-
return { ok: true, group: "connect", command: "status", details };
|
|
172
|
-
}
|
|
173
|
-
default:
|
|
174
|
-
throw new CliError2(`Unknown connect command: ${String(command)}
|
|
175
|
-
Usage: rig connect <list|add|use|status>`, 1);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
export {
|
|
179
|
-
executeConnect
|
|
180
|
-
};
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// packages/cli/src/commands/inspector.ts
|
|
3
|
-
import { iterateServerSentEvents } from "@rig/client";
|
|
4
|
-
|
|
5
|
-
// packages/cli/src/runner.ts
|
|
6
|
-
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
7
|
-
import { CliError } from "@rig/runtime/control-plane/errors";
|
|
8
|
-
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
9
|
-
import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
|
|
10
|
-
import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
|
|
11
|
-
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
12
|
-
import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
|
|
13
|
-
function takeFlag(args, flag) {
|
|
14
|
-
const rest = [];
|
|
15
|
-
let value = false;
|
|
16
|
-
for (const arg of args) {
|
|
17
|
-
if (arg === flag) {
|
|
18
|
-
value = true;
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
rest.push(arg);
|
|
22
|
-
}
|
|
23
|
-
return { value, rest };
|
|
24
|
-
}
|
|
25
|
-
function takeOption(args, option) {
|
|
26
|
-
const rest = [];
|
|
27
|
-
let value;
|
|
28
|
-
for (let index = 0;index < args.length; index += 1) {
|
|
29
|
-
const current = args[index];
|
|
30
|
-
if (current === option) {
|
|
31
|
-
const next = args[index + 1];
|
|
32
|
-
if (!next || next.startsWith("-")) {
|
|
33
|
-
throw new CliError(`Missing value for ${option}`);
|
|
34
|
-
}
|
|
35
|
-
value = next;
|
|
36
|
-
index += 1;
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
if (current !== undefined) {
|
|
40
|
-
rest.push(current);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return { value, rest };
|
|
44
|
-
}
|
|
45
|
-
function requireNoExtraArgs(args, usage) {
|
|
46
|
-
if (args.length > 0) {
|
|
47
|
-
throw new CliError(`Unexpected arguments: ${args.join(" ")}
|
|
48
|
-
Usage: ${usage}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// packages/cli/src/commands/inspector.ts
|
|
53
|
-
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
54
|
-
|
|
55
|
-
// packages/cli/src/commands/_parsers.ts
|
|
56
|
-
function parseRequiredPositiveInt(value, option) {
|
|
57
|
-
if (!value) {
|
|
58
|
-
throw new CliError2(`Missing value for ${option}.`);
|
|
59
|
-
}
|
|
60
|
-
const parsed = Number.parseInt(value, 10);
|
|
61
|
-
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
62
|
-
throw new CliError2(`Invalid ${option} value: ${value}`);
|
|
63
|
-
}
|
|
64
|
-
return parsed;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// packages/cli/src/commands/inspector.ts
|
|
68
|
-
function formatInspectorStreamLine(payload) {
|
|
69
|
-
const emittedAt = payload.emittedAt ?? new Date().toISOString();
|
|
70
|
-
const agentStatus = String(payload.agent?.status ?? "unknown");
|
|
71
|
-
const queueDepth = Number(payload.agent?.queueDepth ?? 0);
|
|
72
|
-
const activeRuns = Array.isArray(payload.snapshot?.activeRuns) ? payload.snapshot?.activeRuns.length : 0;
|
|
73
|
-
const lines = [
|
|
74
|
-
`[${emittedAt}] seq=${String(payload.sequence ?? "?")} agent=${agentStatus} queue=${queueDepth} activeRuns=${activeRuns}`
|
|
75
|
-
];
|
|
76
|
-
const lastAssistantMessage = payload.agent?.lastAssistantMessage?.trim();
|
|
77
|
-
if (lastAssistantMessage) {
|
|
78
|
-
lines.push(` assistant: ${lastAssistantMessage.split(`
|
|
79
|
-
`)[0].slice(0, 240)}`);
|
|
80
|
-
}
|
|
81
|
-
const recentProtocol = payload.agent?.recentProtocolEvents;
|
|
82
|
-
const latestProtocol = Array.isArray(recentProtocol) && recentProtocol.length > 0 ? recentProtocol[recentProtocol.length - 1] : null;
|
|
83
|
-
if (latestProtocol?.method) {
|
|
84
|
-
lines.push(` protocol: ${String(latestProtocol.direction ?? "recv")} ${String(latestProtocol.kind ?? "notification")} ${latestProtocol.method}`);
|
|
85
|
-
}
|
|
86
|
-
const finding = Array.isArray(payload.journal?.recentFindings) && payload.journal?.recentFindings.length > 0 ? payload.journal?.recentFindings[0] : null;
|
|
87
|
-
if (finding?.summary) {
|
|
88
|
-
lines.push(` finding: ${String(finding.source ?? "journal")} \xB7 ${finding.summary}`);
|
|
89
|
-
}
|
|
90
|
-
const action = Array.isArray(payload.journal?.recentActions) && payload.journal?.recentActions.length > 0 ? payload.journal?.recentActions[0] : null;
|
|
91
|
-
if (action?.actionType) {
|
|
92
|
-
lines.push(` action: ${action.actionType} (${String(action.status ?? "unknown")})${action.target ? ` -> ${action.target}` : ""}`);
|
|
93
|
-
}
|
|
94
|
-
return lines;
|
|
95
|
-
}
|
|
96
|
-
async function executeInspector(context, args) {
|
|
97
|
-
const [command = "stream", ...rest] = args;
|
|
98
|
-
switch (command) {
|
|
99
|
-
case "stream": {
|
|
100
|
-
let pending = rest;
|
|
101
|
-
const onceResult = takeFlag(pending, "--once");
|
|
102
|
-
pending = onceResult.rest;
|
|
103
|
-
const secondsResult = takeOption(pending, "--seconds");
|
|
104
|
-
pending = secondsResult.rest;
|
|
105
|
-
const pollMsResult = takeOption(pending, "--poll-ms");
|
|
106
|
-
pending = pollMsResult.rest;
|
|
107
|
-
requireNoExtraArgs(pending, "bun run rig inspector stream [--once] [--seconds <n>] [--poll-ms <n>]");
|
|
108
|
-
const seconds = secondsResult.value ? parseRequiredPositiveInt(secondsResult.value, "--seconds") : null;
|
|
109
|
-
const pollMs = pollMsResult.value ? parseRequiredPositiveInt(pollMsResult.value, "--poll-ms") : null;
|
|
110
|
-
if (context.outputMode === "json" && !onceResult.value && !seconds) {
|
|
111
|
-
throw new CliError2("--json inspector stream requires --once or --seconds <n>.", 2);
|
|
112
|
-
}
|
|
113
|
-
const connection = await ensureLocalRigServerConnection(context.projectRoot);
|
|
114
|
-
const streamUrl = new URL("/api/inspector/stream", connection.baseUrl);
|
|
115
|
-
if (onceResult.value) {
|
|
116
|
-
streamUrl.searchParams.set("once", "1");
|
|
117
|
-
}
|
|
118
|
-
if (pollMs) {
|
|
119
|
-
streamUrl.searchParams.set("pollMs", String(pollMs));
|
|
120
|
-
}
|
|
121
|
-
const controller = new AbortController;
|
|
122
|
-
const deadline = seconds ? setTimeout(() => controller.abort(), seconds * 1000) : null;
|
|
123
|
-
let interrupted = false;
|
|
124
|
-
const onSignal = () => {
|
|
125
|
-
interrupted = true;
|
|
126
|
-
controller.abort();
|
|
127
|
-
};
|
|
128
|
-
if (!onceResult.value) {
|
|
129
|
-
process.once("SIGINT", onSignal);
|
|
130
|
-
process.once("SIGTERM", onSignal);
|
|
131
|
-
}
|
|
132
|
-
try {
|
|
133
|
-
const response = await fetch(streamUrl, {
|
|
134
|
-
headers: connection.authToken ? { authorization: `Bearer ${connection.authToken}` } : undefined,
|
|
135
|
-
signal: controller.signal
|
|
136
|
-
});
|
|
137
|
-
if (!response.ok) {
|
|
138
|
-
throw new CliError2(`Inspector stream request failed (${response.status}).`, response.status);
|
|
139
|
-
}
|
|
140
|
-
let received = 0;
|
|
141
|
-
let lastEvent = null;
|
|
142
|
-
for await (const event of iterateServerSentEvents(response)) {
|
|
143
|
-
const payload = JSON.parse(event.data);
|
|
144
|
-
lastEvent = { event: event.event, payload };
|
|
145
|
-
received += 1;
|
|
146
|
-
if (context.outputMode === "text" && event.event === "snapshot") {
|
|
147
|
-
for (const line of formatInspectorStreamLine(payload)) {
|
|
148
|
-
console.log(line);
|
|
149
|
-
}
|
|
150
|
-
} else if (context.outputMode === "text") {
|
|
151
|
-
console.log(`[inspector:${event.event}] ${event.data}`);
|
|
152
|
-
}
|
|
153
|
-
if (onceResult.value) {
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return {
|
|
158
|
-
ok: true,
|
|
159
|
-
group: "inspector",
|
|
160
|
-
command,
|
|
161
|
-
details: {
|
|
162
|
-
streamUrl: streamUrl.toString(),
|
|
163
|
-
received,
|
|
164
|
-
interrupted,
|
|
165
|
-
once: onceResult.value,
|
|
166
|
-
seconds,
|
|
167
|
-
lastEvent
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
} catch (error) {
|
|
171
|
-
if (controller.signal.aborted && !onceResult.value) {
|
|
172
|
-
return {
|
|
173
|
-
ok: true,
|
|
174
|
-
group: "inspector",
|
|
175
|
-
command,
|
|
176
|
-
details: {
|
|
177
|
-
streamUrl: streamUrl.toString(),
|
|
178
|
-
received: 0,
|
|
179
|
-
interrupted: true,
|
|
180
|
-
once: onceResult.value,
|
|
181
|
-
seconds,
|
|
182
|
-
lastEvent: null
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
throw error;
|
|
187
|
-
} finally {
|
|
188
|
-
if (deadline) {
|
|
189
|
-
clearTimeout(deadline);
|
|
190
|
-
}
|
|
191
|
-
if (!onceResult.value) {
|
|
192
|
-
process.off("SIGINT", onSignal);
|
|
193
|
-
process.off("SIGTERM", onSignal);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
case "scan-upstream-drift": {
|
|
198
|
-
let pending = rest;
|
|
199
|
-
const scanIdResult = takeOption(pending, "--scan-id");
|
|
200
|
-
pending = scanIdResult.rest;
|
|
201
|
-
requireNoExtraArgs(pending, "bun run rig inspector scan-upstream-drift [--scan-id <id>]");
|
|
202
|
-
const connection = await ensureLocalRigServerConnection(context.projectRoot);
|
|
203
|
-
const response = await fetch(new URL("/api/inspector/tools/invoke", connection.baseUrl), {
|
|
204
|
-
method: "POST",
|
|
205
|
-
headers: {
|
|
206
|
-
"content-type": "application/json",
|
|
207
|
-
...connection.authToken ? { authorization: `Bearer ${connection.authToken}` } : {}
|
|
208
|
-
},
|
|
209
|
-
body: JSON.stringify({
|
|
210
|
-
name: "scan_upstream_drift",
|
|
211
|
-
input: scanIdResult.value ? { scanId: scanIdResult.value } : {}
|
|
212
|
-
})
|
|
213
|
-
});
|
|
214
|
-
if (!response.ok) {
|
|
215
|
-
throw new CliError2(`Upstream drift scan request failed (${response.status}).`, response.status);
|
|
216
|
-
}
|
|
217
|
-
const result = await response.json();
|
|
218
|
-
if (context.outputMode === "text") {
|
|
219
|
-
console.log(String(result.summary ?? "Upstream drift scan completed"));
|
|
220
|
-
const details = result.details;
|
|
221
|
-
if (details && typeof details === "object" && !Array.isArray(details)) {
|
|
222
|
-
const record = details;
|
|
223
|
-
if (typeof record.scannedCommitCount === "number") {
|
|
224
|
-
console.log(` scanned commits: ${record.scannedCommitCount}`);
|
|
225
|
-
}
|
|
226
|
-
if (typeof record.ignoredCommitCount === "number") {
|
|
227
|
-
console.log(` ignored commits: ${record.ignoredCommitCount}`);
|
|
228
|
-
}
|
|
229
|
-
if (typeof record.followupCount === "number") {
|
|
230
|
-
console.log(` follow-up tasks: ${record.followupCount}`);
|
|
231
|
-
}
|
|
232
|
-
if (Array.isArray(record.createdTaskIds) && record.createdTaskIds.length > 0) {
|
|
233
|
-
console.log(` created tasks: ${record.createdTaskIds.join(", ")}`);
|
|
234
|
-
}
|
|
235
|
-
if (typeof record.latestHeadSha === "string" && record.latestHeadSha.length > 0) {
|
|
236
|
-
console.log(` latest upstream head: ${record.latestHeadSha}`);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return {
|
|
241
|
-
ok: true,
|
|
242
|
-
group: "inspector",
|
|
243
|
-
command,
|
|
244
|
-
details: {
|
|
245
|
-
scanId: scanIdResult.value ?? null,
|
|
246
|
-
result
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
default:
|
|
251
|
-
throw new CliError2(`Unknown inspector command: ${command}`);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
export {
|
|
255
|
-
executeInspector
|
|
256
|
-
};
|