@h-rig/cli 0.0.6-alpha.9 → 0.0.6-alpha.90
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 +1 -1
- package/dist/bin/build-rig-binaries.d.ts +2 -0
- package/dist/bin/rig.d.ts +2 -0
- package/dist/bin/rig.js +11052 -6668
- package/dist/src/app/board.d.ts +23 -0
- package/dist/src/app/board.js +1786 -0
- package/dist/src/app/drone-ui.d.ts +37 -0
- package/dist/src/app/drone-ui.js +294 -0
- package/dist/src/app/theme.d.ts +47 -0
- package/dist/src/app/theme.js +150 -0
- package/dist/src/commands/_async-ui.d.ts +13 -0
- package/dist/src/commands/_async-ui.js +223 -0
- package/dist/src/commands/_authority-runs.d.ts +22 -0
- package/dist/src/commands/_authority-runs.js +2 -3
- package/dist/src/commands/_cli-format.d.ts +49 -0
- package/dist/src/commands/_cli-format.js +447 -0
- package/dist/src/commands/_connection-state.d.ts +44 -0
- package/dist/src/commands/_connection-state.js +30 -11
- package/dist/src/commands/_doctor-checks.d.ts +52 -0
- package/dist/src/commands/_doctor-checks.js +180 -44
- package/dist/src/commands/_help-catalog.d.ts +51 -0
- package/dist/src/commands/_help-catalog.js +442 -0
- package/dist/src/commands/_json-output.d.ts +11 -0
- package/dist/src/commands/_json-output.js +56 -0
- package/dist/src/commands/_operator-surface.d.ts +34 -0
- package/dist/src/commands/_operator-surface.js +220 -0
- package/dist/src/commands/_operator-view.d.ts +30 -0
- package/dist/src/commands/_operator-view.js +803 -73
- 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/_pi-frontend.d.ts +27 -0
- package/dist/src/commands/_pi-frontend.js +742 -0
- package/dist/src/commands/_pi-install.d.ts +42 -0
- package/dist/src/commands/_pi-install.js +5 -4
- package/dist/src/commands/_policy.d.ts +8 -0
- package/dist/src/commands/_policy.js +12 -5
- package/dist/src/commands/_preflight.d.ts +22 -0
- package/dist/src/commands/_preflight.js +190 -128
- package/dist/src/commands/_probes.d.ts +1 -0
- package/dist/src/commands/_run-driver-helpers.d.ts +99 -0
- package/dist/src/commands/_run-driver-helpers.js +75 -22
- package/dist/src/commands/_run-replay.d.ts +24 -0
- package/dist/src/commands/_run-replay.js +142 -0
- package/dist/src/commands/_server-client.d.ts +186 -0
- package/dist/src/commands/_server-client.js +360 -61
- package/dist/src/commands/_snapshot-upload.d.ts +39 -0
- package/dist/src/commands/_snapshot-upload.js +163 -39
- package/dist/src/commands/_spinner.d.ts +25 -0
- package/dist/src/commands/_spinner.js +65 -0
- package/dist/src/commands/_task-picker.d.ts +9 -0
- package/dist/src/commands/_task-picker.js +172 -19
- package/dist/src/commands/agent.d.ts +3 -0
- package/dist/src/commands/agent.js +39 -20
- package/dist/src/commands/browser.d.ts +65 -0
- package/dist/src/commands/browser.js +334 -51
- package/dist/src/commands/connect.d.ts +7 -0
- package/dist/src/commands/connect.js +272 -33
- package/dist/src/commands/dist.d.ts +28 -0
- package/dist/src/commands/dist.js +19 -12
- package/dist/src/commands/doctor.d.ts +3 -0
- package/dist/src/commands/doctor.js +378 -45
- package/dist/src/commands/github.d.ts +3 -0
- package/dist/src/commands/github.js +375 -53
- package/dist/src/commands/inbox.d.ts +30 -0
- package/dist/src/commands/inbox.js +760 -70
- package/dist/src/commands/init.d.ts +74 -0
- package/dist/src/commands/init.js +963 -119
- package/dist/src/commands/inspect.d.ts +3 -0
- package/dist/src/commands/inspect.js +588 -32
- package/dist/src/commands/inspector.d.ts +3 -0
- package/dist/src/commands/inspector.js +20 -13
- 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 +95 -27
- package/dist/src/commands/profile-and-review.d.ts +4 -0
- package/dist/src/commands/profile-and-review.js +26 -19
- package/dist/src/commands/queue.d.ts +3 -0
- package/dist/src/commands/queue.js +32 -12
- package/dist/src/commands/remote.d.ts +3 -0
- package/dist/src/commands/remote.js +43 -36
- package/dist/src/commands/repo-git-harness.d.ts +5 -0
- package/dist/src/commands/repo-git-harness.js +22 -15
- package/dist/src/commands/run.d.ts +3 -0
- package/dist/src/commands/run.js +1379 -159
- package/dist/src/commands/server.d.ts +7 -0
- package/dist/src/commands/server.js +502 -57
- package/dist/src/commands/setup.d.ts +16 -0
- package/dist/src/commands/setup.js +390 -63
- package/dist/src/commands/stats.d.ts +12 -0
- package/dist/src/commands/stats.js +1051 -0
- package/dist/src/commands/task-report-bug.d.ts +19 -0
- package/dist/src/commands/task-report-bug.js +260 -62
- package/dist/src/commands/task-run-driver.d.ts +132 -0
- package/dist/src/commands/task-run-driver.js +886 -130
- package/dist/src/commands/task.d.ts +14 -0
- package/dist/src/commands/task.js +1644 -314
- package/dist/src/commands/test.d.ts +3 -0
- package/dist/src/commands/test.js +15 -8
- package/dist/src/commands/workspace.d.ts +3 -0
- package/dist/src/commands/workspace.js +18 -11
- package/dist/src/commands.d.ts +29 -0
- package/dist/src/commands.js +10967 -6637
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +10168 -5787
- package/dist/src/launcher.d.ts +61 -0
- package/dist/src/launcher.js +77 -13
- package/dist/src/report-bug.d.ts +44 -0
- package/dist/src/report-bug.js +3 -3
- 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 +13 -6
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// packages/cli/src/commands/_operator-surface.ts
|
|
3
|
+
import { createInterface } from "readline";
|
|
4
|
+
import { createInterface as createPromptInterface } from "readline/promises";
|
|
5
|
+
var CANONICAL_STAGES = [
|
|
6
|
+
"Connect",
|
|
7
|
+
"GitHub/task sync",
|
|
8
|
+
"Prepare workspace",
|
|
9
|
+
"Launch Pi",
|
|
10
|
+
"Plan",
|
|
11
|
+
"Implement",
|
|
12
|
+
"Validate",
|
|
13
|
+
"Commit",
|
|
14
|
+
"Open PR",
|
|
15
|
+
"Review/CI",
|
|
16
|
+
"Merge",
|
|
17
|
+
"Complete"
|
|
18
|
+
];
|
|
19
|
+
function logDetail(log) {
|
|
20
|
+
return typeof log.detail === "string" ? log.detail.trim() : "";
|
|
21
|
+
}
|
|
22
|
+
function parseProviderProtocolLog(title, detail) {
|
|
23
|
+
if (title.trim().toLowerCase() !== "agent output")
|
|
24
|
+
return null;
|
|
25
|
+
if (!detail.startsWith("{") || !detail.endsWith("}"))
|
|
26
|
+
return null;
|
|
27
|
+
try {
|
|
28
|
+
const record = JSON.parse(detail);
|
|
29
|
+
if (!record || typeof record !== "object" || Array.isArray(record))
|
|
30
|
+
return null;
|
|
31
|
+
const type = record.type;
|
|
32
|
+
return typeof type === "string" && [
|
|
33
|
+
"assistant",
|
|
34
|
+
"message_start",
|
|
35
|
+
"message_update",
|
|
36
|
+
"message_end",
|
|
37
|
+
"stream_event",
|
|
38
|
+
"tool_result",
|
|
39
|
+
"tool_execution_start",
|
|
40
|
+
"tool_execution_update",
|
|
41
|
+
"tool_execution_end",
|
|
42
|
+
"turn_start",
|
|
43
|
+
"turn_end"
|
|
44
|
+
].includes(type) ? record : null;
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function renderProviderProtocolLog(record) {
|
|
50
|
+
const type = typeof record.type === "string" ? record.type : "";
|
|
51
|
+
if (type === "tool_execution_start" || type === "tool_execution_update" || type === "tool_execution_end") {
|
|
52
|
+
const toolName = String(record.toolName ?? record.name ?? "tool");
|
|
53
|
+
const status = type === "tool_execution_start" ? "started" : type === "tool_execution_end" ? record.isError === true || record.result && typeof record.result === "object" && !Array.isArray(record.result) && record.result.isError === true ? "failed" : "completed" : "running";
|
|
54
|
+
return `[Pi tool] ${toolName} ${status}`;
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
function entryId(entry, fallback) {
|
|
59
|
+
return typeof entry.id === "string" && entry.id.trim() ? entry.id : fallback;
|
|
60
|
+
}
|
|
61
|
+
function renderOperatorSnapshot(snapshot) {
|
|
62
|
+
const run = snapshot.run.run && typeof snapshot.run.run === "object" ? snapshot.run.run : snapshot.run;
|
|
63
|
+
const runId = String(run.runId ?? run.id ?? "run");
|
|
64
|
+
const status = String(run.status ?? "unknown");
|
|
65
|
+
const logs = snapshot.logs ?? [];
|
|
66
|
+
const latestByStage = new Map;
|
|
67
|
+
for (const log of logs) {
|
|
68
|
+
const title = String(log.title ?? "").toLowerCase();
|
|
69
|
+
const stageName = String(log.stage ?? "").toLowerCase();
|
|
70
|
+
const stage = CANONICAL_STAGES.find((candidate) => candidate.toLowerCase() === title || candidate.toLowerCase() === stageName);
|
|
71
|
+
if (stage)
|
|
72
|
+
latestByStage.set(stage, log);
|
|
73
|
+
}
|
|
74
|
+
const stageLines = CANONICAL_STAGES.flatMap((stage) => {
|
|
75
|
+
const match = latestByStage.get(stage);
|
|
76
|
+
return match ? [`${stage}: ${String(match.status ?? status)}${logDetail(match) ? ` \u2014 ${logDetail(match)}` : ""}`] : [];
|
|
77
|
+
});
|
|
78
|
+
return [`Rig run ${runId}: ${status}`, ...stageLines].join(`
|
|
79
|
+
`);
|
|
80
|
+
}
|
|
81
|
+
function createPiRunStreamRenderer(output = process.stdout) {
|
|
82
|
+
let lastSnapshot = "";
|
|
83
|
+
const assistantTextById = new Map;
|
|
84
|
+
const seenTimeline = new Set;
|
|
85
|
+
const seenLogs = new Set;
|
|
86
|
+
const writeLine = (line) => output.write(`${line}
|
|
87
|
+
`);
|
|
88
|
+
return {
|
|
89
|
+
renderSnapshot(snapshot) {
|
|
90
|
+
const rendered = renderOperatorSnapshot(snapshot);
|
|
91
|
+
if (rendered && rendered !== lastSnapshot) {
|
|
92
|
+
writeLine(rendered);
|
|
93
|
+
lastSnapshot = rendered;
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
renderTimeline(entries) {
|
|
97
|
+
for (const [index, entry] of entries.entries()) {
|
|
98
|
+
const id = entryId(entry, `timeline:${index}:${String(entry.cursor ?? "")}`);
|
|
99
|
+
if (entry.type === "assistant_message" && typeof entry.text === "string") {
|
|
100
|
+
const text = entry.text;
|
|
101
|
+
const previousText = assistantTextById.get(id) ?? "";
|
|
102
|
+
if (!previousText && text.trim()) {
|
|
103
|
+
writeLine("[Pi assistant]");
|
|
104
|
+
}
|
|
105
|
+
if (text.startsWith(previousText)) {
|
|
106
|
+
const delta = text.slice(previousText.length);
|
|
107
|
+
if (delta)
|
|
108
|
+
output.write(delta);
|
|
109
|
+
} else if (text.trim() && text !== previousText) {
|
|
110
|
+
if (previousText)
|
|
111
|
+
writeLine(`
|
|
112
|
+
[Pi assistant]`);
|
|
113
|
+
output.write(text);
|
|
114
|
+
}
|
|
115
|
+
assistantTextById.set(id, text);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (seenTimeline.has(id))
|
|
119
|
+
continue;
|
|
120
|
+
seenTimeline.add(id);
|
|
121
|
+
if (entry.type === "tool_execution_start" || entry.type === "tool_execution_update" || entry.type === "tool_execution_end" || entry.type === "mcp_tool_call") {
|
|
122
|
+
writeLine(`[Pi tool] ${String(entry.toolName ?? entry.name ?? entry.title ?? entry.type)} ${String(entry.status ?? entry.state ?? "")}`.trim());
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (entry.type === "timeline_warning") {
|
|
126
|
+
writeLine(`[Rig timeline] ${String(entry.detail ?? entry.message ?? "timeline unavailable")}`);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (entry.type === "action") {
|
|
130
|
+
const text = String(entry.detail ?? entry.message ?? entry.title ?? "").trim();
|
|
131
|
+
if (text)
|
|
132
|
+
writeLine(`[Rig action] ${text}`);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (entry.type === "user_message") {
|
|
136
|
+
const text = String(entry.text ?? entry.message ?? entry.detail ?? "").trim();
|
|
137
|
+
if (text)
|
|
138
|
+
writeLine(`[Operator] ${text}`);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const fallback = String(entry.detail ?? entry.message ?? entry.text ?? entry.title ?? "").trim();
|
|
142
|
+
if (fallback)
|
|
143
|
+
writeLine(`[${String(entry.type ?? "timeline")}] ${fallback}`);
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
renderLogs(entries) {
|
|
147
|
+
for (const [index, entry] of entries.entries()) {
|
|
148
|
+
const id = entryId(entry, `log:${index}:${String(entry.createdAt ?? "")}:${String(entry.title ?? "")}`);
|
|
149
|
+
if (seenLogs.has(id))
|
|
150
|
+
continue;
|
|
151
|
+
seenLogs.add(id);
|
|
152
|
+
const title = String(entry.title ?? "");
|
|
153
|
+
if (CANONICAL_STAGES.some((stage) => stage.toLowerCase() === title.toLowerCase()))
|
|
154
|
+
continue;
|
|
155
|
+
const detail = logDetail(entry);
|
|
156
|
+
if (!detail)
|
|
157
|
+
continue;
|
|
158
|
+
const protocolRecord = parseProviderProtocolLog(title, detail);
|
|
159
|
+
if (protocolRecord) {
|
|
160
|
+
const protocolLine = renderProviderProtocolLog(protocolRecord);
|
|
161
|
+
if (protocolLine)
|
|
162
|
+
writeLine(protocolLine);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
writeLine(`[${title || "Rig log"}] ${detail}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function createOperatorSurface(options = {}) {
|
|
171
|
+
const input = options.input ?? process.stdin;
|
|
172
|
+
const output = options.output ?? process.stdout;
|
|
173
|
+
const errorOutput = options.errorOutput ?? process.stderr;
|
|
174
|
+
const renderer = createPiRunStreamRenderer(output);
|
|
175
|
+
const writeLine = (line) => output.write(`${line}
|
|
176
|
+
`);
|
|
177
|
+
return {
|
|
178
|
+
mode: "pi-compatible-text",
|
|
179
|
+
...renderer,
|
|
180
|
+
info: writeLine,
|
|
181
|
+
error: (message) => errorOutput.write(`${message}
|
|
182
|
+
`),
|
|
183
|
+
attachCommandInput(handler) {
|
|
184
|
+
if (options.interactive === false || !input.isTTY)
|
|
185
|
+
return null;
|
|
186
|
+
const rl = createInterface({ input, output: process.stdout, terminal: false });
|
|
187
|
+
rl.on("line", (line) => {
|
|
188
|
+
Promise.resolve(handler(line)).catch((error) => writeLine(`Operator command failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
189
|
+
});
|
|
190
|
+
return { close: () => rl.close() };
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function taskId(task) {
|
|
195
|
+
return typeof task.id === "string" && task.id.trim() ? task.id : "<unknown>";
|
|
196
|
+
}
|
|
197
|
+
function taskTitle(task) {
|
|
198
|
+
return typeof task.title === "string" && task.title.trim() ? task.title : "Untitled task";
|
|
199
|
+
}
|
|
200
|
+
function taskStatus(task) {
|
|
201
|
+
return typeof task.status === "string" && task.status.trim() ? task.status : "unknown";
|
|
202
|
+
}
|
|
203
|
+
function renderTaskPickerRows(tasks) {
|
|
204
|
+
return tasks.map((task, index) => `${index + 1}. ${taskId(task)} \xB7 ${taskStatus(task)} \xB7 ${taskTitle(task)}`);
|
|
205
|
+
}
|
|
206
|
+
async function promptForTaskSelection(question) {
|
|
207
|
+
const rl = createPromptInterface({ input: process.stdin, output: process.stdout });
|
|
208
|
+
try {
|
|
209
|
+
return await rl.question(question);
|
|
210
|
+
} finally {
|
|
211
|
+
rl.close();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
export {
|
|
215
|
+
renderTaskPickerRows,
|
|
216
|
+
renderOperatorSnapshot,
|
|
217
|
+
promptForTaskSelection,
|
|
218
|
+
createPiRunStreamRenderer,
|
|
219
|
+
createOperatorSurface
|
|
220
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { steerRunViaServer, stopRunViaServer } from "./_server-client";
|
|
2
|
+
import { createPiRunStreamRenderer, renderOperatorSnapshot } from "./_operator-surface";
|
|
3
|
+
import type { RunnerContext } from "../runner";
|
|
4
|
+
export { createPiRunStreamRenderer, renderOperatorSnapshot };
|
|
5
|
+
export declare function applyOperatorCommand(context: Pick<RunnerContext, "projectRoot">, input: {
|
|
6
|
+
readonly runId: string;
|
|
7
|
+
readonly line: string;
|
|
8
|
+
}, deps?: {
|
|
9
|
+
readonly steer?: typeof steerRunViaServer;
|
|
10
|
+
readonly stop?: typeof stopRunViaServer;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
action: "continue" | "detach" | "stopped" | "ignored";
|
|
13
|
+
message?: string;
|
|
14
|
+
}>;
|
|
15
|
+
export declare function attachRunOperatorView(context: Pick<RunnerContext, "projectRoot" | "outputMode">, input: {
|
|
16
|
+
readonly runId: string;
|
|
17
|
+
readonly message?: string | null;
|
|
18
|
+
readonly once?: boolean;
|
|
19
|
+
readonly follow?: boolean;
|
|
20
|
+
readonly pollMs?: number;
|
|
21
|
+
readonly interactive?: boolean;
|
|
22
|
+
}): Promise<{
|
|
23
|
+
run: Record<string, unknown>;
|
|
24
|
+
logs: Record<string, unknown>[];
|
|
25
|
+
timeline: Record<string, unknown>[];
|
|
26
|
+
timelineCursor: string | null;
|
|
27
|
+
steered: boolean;
|
|
28
|
+
rendered: string;
|
|
29
|
+
detached?: boolean;
|
|
30
|
+
}>;
|