@h-rig/cli 0.0.6-alpha.80 → 0.0.6-alpha.81
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/dist/bin/rig.js +17034 -11249
- package/dist/src/app/board.js +32 -3
- package/dist/src/app/drone-ui.js +1 -1
- package/dist/src/app/theme.js +1 -0
- package/dist/src/app-opentui/adapters/common.d.ts +53 -0
- package/dist/src/app-opentui/adapters/common.js +149 -0
- package/dist/src/app-opentui/adapters/doctor.d.ts +11 -0
- package/dist/src/app-opentui/adapters/doctor.js +780 -0
- package/dist/src/app-opentui/adapters/fleet.d.ts +16 -0
- package/dist/src/app-opentui/adapters/fleet.js +874 -0
- package/dist/src/app-opentui/adapters/inbox.d.ts +33 -0
- package/dist/src/app-opentui/adapters/inbox.js +1454 -0
- package/dist/src/app-opentui/adapters/init.d.ts +13 -0
- package/dist/src/app-opentui/adapters/init.js +2357 -0
- package/dist/src/app-opentui/adapters/pi-attach.d.ts +16 -0
- package/dist/src/app-opentui/adapters/pi-attach.js +1295 -0
- package/dist/src/app-opentui/adapters/run-detail.d.ts +20 -0
- package/dist/src/app-opentui/adapters/run-detail.js +893 -0
- package/dist/src/app-opentui/adapters/server.d.ts +14 -0
- package/dist/src/app-opentui/adapters/server.js +798 -0
- package/dist/src/app-opentui/adapters/tasks.d.ts +55 -0
- package/dist/src/app-opentui/adapters/tasks.js +3472 -0
- package/dist/src/app-opentui/bootstrap.d.ts +16 -0
- package/dist/src/app-opentui/bootstrap.js +19509 -0
- package/dist/src/app-opentui/drone.d.ts +12 -0
- package/dist/src/app-opentui/drone.js +227 -0
- package/dist/src/app-opentui/events.d.ts +7 -0
- package/dist/src/app-opentui/events.js +28 -0
- package/dist/src/app-opentui/index.d.ts +8 -0
- package/dist/src/app-opentui/index.js +3477 -0
- package/dist/src/app-opentui/intent.d.ts +3 -0
- package/dist/src/app-opentui/intent.js +211 -0
- package/dist/src/app-opentui/layout.d.ts +15 -0
- package/dist/src/app-opentui/layout.js +44 -0
- package/dist/src/app-opentui/list-search.d.ts +8 -0
- package/dist/src/app-opentui/list-search.js +43 -0
- package/dist/src/app-opentui/pi-host-child.d.ts +2 -0
- package/dist/src/app-opentui/pi-host-child.js +778 -0
- package/dist/src/app-opentui/pi-pty-host.d.ts +64 -0
- package/dist/src/app-opentui/pi-pty-host.js +384 -0
- package/dist/src/app-opentui/registry.d.ts +4 -0
- package/dist/src/app-opentui/registry.js +6835 -0
- package/dist/src/app-opentui/render/graphics.d.ts +39 -0
- package/dist/src/app-opentui/render/graphics.js +537 -0
- package/dist/src/app-opentui/render/image-visual-layer-native-canvas.d.ts +2 -0
- package/dist/src/app-opentui/render/image-visual-layer-native-canvas.js +1480 -0
- package/dist/src/app-opentui/render/image-visual-layer-worker.d.ts +1 -0
- package/dist/src/app-opentui/render/image-visual-layer-worker.js +1541 -0
- package/dist/src/app-opentui/render/image-visual-layer.d.ts +93 -0
- package/dist/src/app-opentui/render/image-visual-layer.js +945 -0
- package/dist/src/app-opentui/render/panels.d.ts +10 -0
- package/dist/src/app-opentui/render/panels.js +201 -0
- package/dist/src/app-opentui/render/scene.d.ts +16 -0
- package/dist/src/app-opentui/render/scene.js +110 -0
- package/dist/src/app-opentui/render/text.d.ts +10 -0
- package/dist/src/app-opentui/render/text.js +121 -0
- package/dist/src/app-opentui/render/type-bar.d.ts +14 -0
- package/dist/src/app-opentui/render/type-bar.js +137 -0
- package/dist/src/app-opentui/runtime.d.ts +2 -0
- package/dist/src/app-opentui/runtime.js +3406 -0
- package/dist/src/app-opentui/scenes/doctor.d.ts +2 -0
- package/dist/src/app-opentui/scenes/doctor.js +91 -0
- package/dist/src/app-opentui/scenes/error.d.ts +2 -0
- package/dist/src/app-opentui/scenes/error.js +190 -0
- package/dist/src/app-opentui/scenes/fleet.d.ts +3 -0
- package/dist/src/app-opentui/scenes/fleet.js +207 -0
- package/dist/src/app-opentui/scenes/handoff.d.ts +2 -0
- package/dist/src/app-opentui/scenes/handoff.js +147 -0
- package/dist/src/app-opentui/scenes/help.d.ts +3 -0
- package/dist/src/app-opentui/scenes/help.js +138 -0
- package/dist/src/app-opentui/scenes/inbox.d.ts +2 -0
- package/dist/src/app-opentui/scenes/inbox.js +118 -0
- package/dist/src/app-opentui/scenes/init.d.ts +2 -0
- package/dist/src/app-opentui/scenes/init.js +94 -0
- package/dist/src/app-opentui/scenes/main.d.ts +2 -0
- package/dist/src/app-opentui/scenes/main.js +96 -0
- package/dist/src/app-opentui/scenes/run-detail.d.ts +2 -0
- package/dist/src/app-opentui/scenes/run-detail.js +139 -0
- package/dist/src/app-opentui/scenes/server.d.ts +2 -0
- package/dist/src/app-opentui/scenes/server.js +88 -0
- package/dist/src/app-opentui/scenes/tasks.d.ts +3 -0
- package/dist/src/app-opentui/scenes/tasks.js +230 -0
- package/dist/src/app-opentui/state.d.ts +4 -0
- package/dist/src/app-opentui/state.js +286 -0
- package/dist/src/app-opentui/theme.d.ts +36 -0
- package/dist/src/app-opentui/theme.js +88 -0
- package/dist/src/app-opentui/types.d.ts +188 -0
- package/dist/src/app-opentui/types.js +1 -0
- package/dist/src/commands/_async-ui.js +1 -1
- package/dist/src/commands/_operator-view.js +1 -1
- package/dist/src/commands/_pi-frontend.js +1 -1
- package/dist/src/commands/_spinner.js +1 -1
- package/dist/src/commands/browser.js +1 -1
- package/dist/src/commands/doctor.js +1 -1
- package/dist/src/commands/github.js +1 -1
- package/dist/src/commands/inbox.js +1 -1
- package/dist/src/commands/init.js +1 -1
- package/dist/src/commands/inspect.js +1 -1
- package/dist/src/commands/run.js +1 -1
- package/dist/src/commands/setup.js +1 -1
- package/dist/src/commands/stats.js +1 -1
- package/dist/src/commands/task.js +1 -1
- package/dist/src/commands.js +33 -4
- package/dist/src/index.js +33 -4
- package/package.json +11 -8
|
@@ -0,0 +1,1454 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __returnValue = (v) => v;
|
|
4
|
+
function __exportSetter(name, newValue) {
|
|
5
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
+
}
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
set: __exportSetter.bind(all, name)
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
17
|
+
|
|
18
|
+
// packages/cli/src/runner.ts
|
|
19
|
+
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
20
|
+
import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
|
|
21
|
+
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
22
|
+
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
23
|
+
function takeOption(args, option) {
|
|
24
|
+
const rest = [];
|
|
25
|
+
let value;
|
|
26
|
+
for (let index = 0;index < args.length; index += 1) {
|
|
27
|
+
const current = args[index];
|
|
28
|
+
if (current === option) {
|
|
29
|
+
const next = args[index + 1];
|
|
30
|
+
if (!next || next.startsWith("-")) {
|
|
31
|
+
throw new CliError(`Missing value for ${option}`, 1, { hint: `Provide a value after ${option}, e.g. \`${option} <value>\`.` });
|
|
32
|
+
}
|
|
33
|
+
value = next;
|
|
34
|
+
index += 1;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (current !== undefined) {
|
|
38
|
+
rest.push(current);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return { value, rest };
|
|
42
|
+
}
|
|
43
|
+
function requireNoExtraArgs(args, usage) {
|
|
44
|
+
if (args.length > 0) {
|
|
45
|
+
throw new CliError(`Unexpected arguments: ${args.join(" ")}
|
|
46
|
+
Usage: ${usage}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
var CliError;
|
|
50
|
+
var init_runner = __esm(() => {
|
|
51
|
+
CliError = class CliError extends RuntimeCliError {
|
|
52
|
+
hint;
|
|
53
|
+
constructor(message, exitCode = 1, options = {}) {
|
|
54
|
+
super(message, exitCode);
|
|
55
|
+
if (options.hint?.trim()) {
|
|
56
|
+
this.hint = options.hint.trim();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// packages/cli/src/app/theme.ts
|
|
63
|
+
function hexToRgb(hex) {
|
|
64
|
+
const value = hex.replace("#", "");
|
|
65
|
+
return [
|
|
66
|
+
Number.parseInt(value.slice(0, 2), 16),
|
|
67
|
+
Number.parseInt(value.slice(2, 4), 16),
|
|
68
|
+
Number.parseInt(value.slice(4, 6), 16)
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
function fg(hex) {
|
|
72
|
+
const [r, g, b] = hexToRgb(hex);
|
|
73
|
+
return (text) => `\x1B[38;2;${r};${g};${b}m${text}\x1B[39m`;
|
|
74
|
+
}
|
|
75
|
+
function bold(text) {
|
|
76
|
+
return `\x1B[1m${text}\x1B[22m`;
|
|
77
|
+
}
|
|
78
|
+
function microDroneFrame(tick) {
|
|
79
|
+
const blade = MICRO_BLADES[tick % MICRO_BLADES.length];
|
|
80
|
+
const eye = EYE_FRAMES[Math.floor(tick / 2) % EYE_FRAMES.length];
|
|
81
|
+
return `(${blade})${eye}(${blade})`;
|
|
82
|
+
}
|
|
83
|
+
function renderMicroDroneFrame(tick) {
|
|
84
|
+
const blade = MICRO_BLADES[tick % MICRO_BLADES.length];
|
|
85
|
+
const eye = EYE_FRAMES[Math.floor(tick / 2) % EYE_FRAMES.length];
|
|
86
|
+
return `${ink4("(")}${cyan(blade)}${ink4(")")}${bold(accent(eye))}${ink4("(")}${cyan(blade)}${ink4(")")}`;
|
|
87
|
+
}
|
|
88
|
+
var RIG_PALETTE, ink, ink2, ink3, ink4, accent, accentDim, cyan, red, yellow, DRONE_ART, EYE_FRAMES, DRONE_WIDTH, DRONE_HEIGHT, MICRO_BLADES, MICRO_DRONE_FRAMES;
|
|
89
|
+
var init_theme = __esm(() => {
|
|
90
|
+
RIG_PALETTE = {
|
|
91
|
+
ink: "#f2f3f6",
|
|
92
|
+
ink2: "#aeb0ba",
|
|
93
|
+
ink3: "#6c6e79",
|
|
94
|
+
ink4: "#44464f",
|
|
95
|
+
accent: "#ccff4d",
|
|
96
|
+
accentDim: "#a9d63f",
|
|
97
|
+
cyan: "#56d8ff",
|
|
98
|
+
red: "#ff5d5d",
|
|
99
|
+
yellow: "#ffd24d"
|
|
100
|
+
};
|
|
101
|
+
ink = fg(RIG_PALETTE.ink);
|
|
102
|
+
ink2 = fg(RIG_PALETTE.ink2);
|
|
103
|
+
ink3 = fg(RIG_PALETTE.ink3);
|
|
104
|
+
ink4 = fg(RIG_PALETTE.ink4);
|
|
105
|
+
accent = fg(RIG_PALETTE.accent);
|
|
106
|
+
accentDim = fg(RIG_PALETTE.accentDim);
|
|
107
|
+
cyan = fg(RIG_PALETTE.cyan);
|
|
108
|
+
red = fg(RIG_PALETTE.red);
|
|
109
|
+
yellow = fg(RIG_PALETTE.yellow);
|
|
110
|
+
DRONE_ART = [
|
|
111
|
+
" .-=-. .-=-. ",
|
|
112
|
+
" ( !!! ) ( !!! ) ",
|
|
113
|
+
" '-=-'._ _.'-=-' ",
|
|
114
|
+
" '._ _.' ",
|
|
115
|
+
" '=$$$$$$$=.' ",
|
|
116
|
+
" =$$$$$$$$$$$= ",
|
|
117
|
+
" $$$@@@@@@@@@@$$$ ",
|
|
118
|
+
" $$$@@ @@$$$ ",
|
|
119
|
+
" $$@ ? @$$$ ",
|
|
120
|
+
" $$$@ '-' @$$$ ",
|
|
121
|
+
" $$$@@ @@$$$ ",
|
|
122
|
+
" $$$@@@@@@@@@@$$$ ",
|
|
123
|
+
" =$$$$$$$$$$$= ",
|
|
124
|
+
" '=$$$$$$$=.' ",
|
|
125
|
+
" _.' '._ ",
|
|
126
|
+
" .-=-.' '.-=-. ",
|
|
127
|
+
" ( !!! ) ( !!! ) ",
|
|
128
|
+
" '-=-' '-=-' "
|
|
129
|
+
];
|
|
130
|
+
EYE_FRAMES = ["@", "o", "."];
|
|
131
|
+
DRONE_WIDTH = DRONE_ART[0].length;
|
|
132
|
+
DRONE_HEIGHT = DRONE_ART.length;
|
|
133
|
+
MICRO_BLADES = ["---", "\\\\\\", "|||", "///"];
|
|
134
|
+
MICRO_DRONE_FRAMES = Array.from({ length: 12 }, (_, index) => microDroneFrame(index));
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// packages/cli/src/commands/_spinner.ts
|
|
138
|
+
function createTtySpinner(input) {
|
|
139
|
+
const output = input.output ?? process.stdout;
|
|
140
|
+
const isTty = output.isTTY === true;
|
|
141
|
+
const frames = input.frames && input.frames.length > 0 ? input.frames : SPINNER_FRAMES;
|
|
142
|
+
let label = input.label;
|
|
143
|
+
let frame = 0;
|
|
144
|
+
let paused = false;
|
|
145
|
+
let stopped = false;
|
|
146
|
+
let lastPrintedLabel = "";
|
|
147
|
+
const render = () => {
|
|
148
|
+
if (stopped || paused)
|
|
149
|
+
return;
|
|
150
|
+
if (!isTty) {
|
|
151
|
+
if (label !== lastPrintedLabel) {
|
|
152
|
+
output.write(`${label}
|
|
153
|
+
`);
|
|
154
|
+
lastPrintedLabel = label;
|
|
155
|
+
}
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
frame = (frame + 1) % frames.length;
|
|
159
|
+
const glyph = frames[frame] ?? frames[0] ?? "";
|
|
160
|
+
output.write(`\r\x1B[2K${input.styleFrame ? input.styleFrame(glyph) : glyph} ${label}`);
|
|
161
|
+
};
|
|
162
|
+
const clearLine = () => {
|
|
163
|
+
if (isTty)
|
|
164
|
+
output.write("\r\x1B[2K");
|
|
165
|
+
};
|
|
166
|
+
render();
|
|
167
|
+
const timer = isTty ? setInterval(render, input.intervalMs ?? 16) : null;
|
|
168
|
+
return {
|
|
169
|
+
setLabel(next) {
|
|
170
|
+
label = next;
|
|
171
|
+
render();
|
|
172
|
+
},
|
|
173
|
+
pause() {
|
|
174
|
+
paused = true;
|
|
175
|
+
clearLine();
|
|
176
|
+
},
|
|
177
|
+
resume() {
|
|
178
|
+
if (stopped)
|
|
179
|
+
return;
|
|
180
|
+
paused = false;
|
|
181
|
+
render();
|
|
182
|
+
},
|
|
183
|
+
stop(finalLine) {
|
|
184
|
+
if (stopped)
|
|
185
|
+
return;
|
|
186
|
+
stopped = true;
|
|
187
|
+
if (timer)
|
|
188
|
+
clearInterval(timer);
|
|
189
|
+
clearLine();
|
|
190
|
+
if (finalLine)
|
|
191
|
+
output.write(`${finalLine}
|
|
192
|
+
`);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
var SPINNER_FRAMES;
|
|
197
|
+
var init__spinner = __esm(() => {
|
|
198
|
+
SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// packages/cli/src/app/drone-ui.ts
|
|
202
|
+
import { ProcessTerminal, TUI, Text, Input, SelectList, matchesKey } from "@earendil-works/pi-tui";
|
|
203
|
+
function droneNote(message, title) {
|
|
204
|
+
if (title)
|
|
205
|
+
console.log(` ${accentDim("\u25C7")} ${bold(ink2(title))}`);
|
|
206
|
+
for (const line of message.split(`
|
|
207
|
+
`)) {
|
|
208
|
+
console.log(` ${ink4("\u2502")} ${line}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
var init_drone_ui = __esm(() => {
|
|
212
|
+
init_theme();
|
|
213
|
+
init__spinner();
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// packages/cli/src/commands/_cli-format.ts
|
|
217
|
+
import pc from "picocolors";
|
|
218
|
+
function stringField2(record, key, fallback = "") {
|
|
219
|
+
const value = record[key];
|
|
220
|
+
return typeof value === "string" && value.trim() ? value.trim() : fallback;
|
|
221
|
+
}
|
|
222
|
+
function statusColor(status) {
|
|
223
|
+
const normalized = status.toLowerCase();
|
|
224
|
+
if (["completed", "merged", "closed", "done", "accepted", "pass", "selected", "approved", "running"].includes(normalized))
|
|
225
|
+
return accent;
|
|
226
|
+
if (["failed", "needs_attention", "needs-attention", "blocked", "error", "rejected"].includes(normalized))
|
|
227
|
+
return red;
|
|
228
|
+
if (["reviewing", "validating", "in_progress", "in-progress", "remote", "preparing", "closing-out"].includes(normalized))
|
|
229
|
+
return cyan;
|
|
230
|
+
if (["ready", "open", "queued", "created", "local", "pending"].includes(normalized))
|
|
231
|
+
return yellow;
|
|
232
|
+
return themeDim;
|
|
233
|
+
}
|
|
234
|
+
function firstString(record, keys, fallback = "") {
|
|
235
|
+
for (const key of keys) {
|
|
236
|
+
const value = stringField2(record, key);
|
|
237
|
+
if (value)
|
|
238
|
+
return value;
|
|
239
|
+
}
|
|
240
|
+
return fallback;
|
|
241
|
+
}
|
|
242
|
+
function requestIdOf(entry) {
|
|
243
|
+
return firstString(entry, ["requestId", "id", "approvalId", "inputId"], "(unknown-request)");
|
|
244
|
+
}
|
|
245
|
+
function shouldUseClackOutput() {
|
|
246
|
+
return Boolean(process.stdout.isTTY) && process.env.RIG_CLI_PLAIN_HELP !== "1";
|
|
247
|
+
}
|
|
248
|
+
function printFormattedOutput(message, options = {}) {
|
|
249
|
+
if (!shouldUseClackOutput()) {
|
|
250
|
+
console.log(message);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
droneNote(message, options.title);
|
|
254
|
+
}
|
|
255
|
+
function formatStatusPill(status) {
|
|
256
|
+
const label = status || "unknown";
|
|
257
|
+
return statusColor(label)(`\u25CF ${label}`);
|
|
258
|
+
}
|
|
259
|
+
function formatSection(title, subtitle) {
|
|
260
|
+
return `${pc.bold(accent("\u25C6"))} ${pc.bold(title)}${subtitle ? themeDim(` \u2014 ${subtitle}`) : ""}`;
|
|
261
|
+
}
|
|
262
|
+
function formatNextSteps(steps) {
|
|
263
|
+
if (steps.length === 0)
|
|
264
|
+
return [];
|
|
265
|
+
return [pc.bold("Next"), ...steps.map((step) => `${accent("\u203A")} ${step}`)];
|
|
266
|
+
}
|
|
267
|
+
function formatInboxList(kind, entries) {
|
|
268
|
+
const title = kind === "approvals" ? "Approval inbox" : "Input inbox";
|
|
269
|
+
if (entries.length === 0) {
|
|
270
|
+
return [
|
|
271
|
+
formatSection(title, "empty"),
|
|
272
|
+
themeDim(kind === "approvals" ? "No pending approvals." : "No pending user-input requests."),
|
|
273
|
+
"",
|
|
274
|
+
...formatNextSteps(["Check runs: `rig run status`", "Start work: `rig task run --next`"])
|
|
275
|
+
].join(`
|
|
276
|
+
`);
|
|
277
|
+
}
|
|
278
|
+
const lines = [formatSection(title, `${entries.length} pending`)];
|
|
279
|
+
for (const entry of entries) {
|
|
280
|
+
const record = entry.record && typeof entry.record === "object" && !Array.isArray(entry.record) ? entry.record : entry;
|
|
281
|
+
const runId = firstString(entry, ["runId"], firstString(record, ["runId"]));
|
|
282
|
+
const taskId = firstString(entry, ["taskId"], firstString(record, ["taskId", "task"]));
|
|
283
|
+
const requestId = requestIdOf(record);
|
|
284
|
+
const status = firstString(record, ["status", "state"], "pending");
|
|
285
|
+
const prompt = firstString(record, ["prompt", "message", "reason", "title", "summary"], kind === "approvals" ? "Approval requested" : "Input requested");
|
|
286
|
+
lines.push(`${themeFaint("\u2502")} ${pc.bold(requestId)} ${formatStatusPill(status)} ${prompt}`);
|
|
287
|
+
lines.push(`${themeFaint("\u2502")} ${themeDim("run ")} ${runId || "(unknown-run)"}${taskId ? themeDim(` task ${taskId}`) : ""}`);
|
|
288
|
+
}
|
|
289
|
+
lines.push("", ...formatNextSteps(kind === "approvals" ? ["Resolve: `rig inbox approve --run <run-id> --request <request-id> --decision approve|reject`", "Rejoin: `rig run attach <run-id> --follow`"] : ["Respond: `rig inbox respond --run <run-id> --request <request-id> --answer key=value`", "Rejoin: `rig run attach <run-id> --follow`"]));
|
|
290
|
+
return lines.join(`
|
|
291
|
+
`);
|
|
292
|
+
}
|
|
293
|
+
var themeDim = (value) => ink3(value), themeFaint = (value) => ink4(value);
|
|
294
|
+
var init__cli_format = __esm(() => {
|
|
295
|
+
init_drone_ui();
|
|
296
|
+
init_theme();
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
// packages/cli/src/commands/_connection-state.ts
|
|
300
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
301
|
+
import { homedir } from "os";
|
|
302
|
+
import { dirname, resolve } from "path";
|
|
303
|
+
function resolveGlobalConnectionsPath(env = process.env) {
|
|
304
|
+
const explicit = env.RIG_CONNECTIONS_FILE?.trim();
|
|
305
|
+
if (explicit)
|
|
306
|
+
return resolve(explicit);
|
|
307
|
+
const stateDir = env.RIG_GLOBAL_STATE_DIR?.trim();
|
|
308
|
+
if (stateDir)
|
|
309
|
+
return resolve(stateDir, "connections.json");
|
|
310
|
+
return resolve(homedir(), ".rig", "connections.json");
|
|
311
|
+
}
|
|
312
|
+
function resolveRepoConnectionPath(projectRoot) {
|
|
313
|
+
return resolve(projectRoot, ".rig", "state", "connection.json");
|
|
314
|
+
}
|
|
315
|
+
function readJsonFile(path) {
|
|
316
|
+
if (!existsSync(path))
|
|
317
|
+
return null;
|
|
318
|
+
try {
|
|
319
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
320
|
+
} catch (error) {
|
|
321
|
+
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>`." });
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function writeJsonFile(path, value) {
|
|
325
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
326
|
+
writeFileSync(path, `${JSON.stringify(value, null, 2)}
|
|
327
|
+
`, "utf8");
|
|
328
|
+
}
|
|
329
|
+
function normalizeConnection(value) {
|
|
330
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
331
|
+
return null;
|
|
332
|
+
const record = value;
|
|
333
|
+
if (record.kind === "local")
|
|
334
|
+
return { kind: "local", mode: "auto" };
|
|
335
|
+
if (record.kind === "remote" && typeof record.baseUrl === "string" && record.baseUrl.trim()) {
|
|
336
|
+
const baseUrl = record.baseUrl.trim().replace(/\/+$/, "");
|
|
337
|
+
return { kind: "remote", baseUrl };
|
|
338
|
+
}
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
function readGlobalConnections(options = {}) {
|
|
342
|
+
const path = resolveGlobalConnectionsPath(options.env ?? process.env);
|
|
343
|
+
const payload = readJsonFile(path);
|
|
344
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
345
|
+
return { connections: {} };
|
|
346
|
+
}
|
|
347
|
+
const rawConnections = payload.connections;
|
|
348
|
+
const connections = {};
|
|
349
|
+
if (rawConnections && typeof rawConnections === "object" && !Array.isArray(rawConnections)) {
|
|
350
|
+
for (const [alias, raw] of Object.entries(rawConnections)) {
|
|
351
|
+
const connection = normalizeConnection(raw);
|
|
352
|
+
if (connection)
|
|
353
|
+
connections[alias] = connection;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return { connections };
|
|
357
|
+
}
|
|
358
|
+
function readRepoConnection(projectRoot) {
|
|
359
|
+
const payload = readJsonFile(resolveRepoConnectionPath(projectRoot));
|
|
360
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
361
|
+
return null;
|
|
362
|
+
const record = payload;
|
|
363
|
+
const selected = typeof record.selected === "string" ? record.selected.trim() : "";
|
|
364
|
+
if (!selected)
|
|
365
|
+
return null;
|
|
366
|
+
return {
|
|
367
|
+
selected,
|
|
368
|
+
project: typeof record.project === "string" ? record.project : undefined,
|
|
369
|
+
linkedAt: typeof record.linkedAt === "string" ? record.linkedAt : undefined,
|
|
370
|
+
serverProjectRoot: typeof record.serverProjectRoot === "string" && record.serverProjectRoot.trim() ? record.serverProjectRoot.trim() : undefined
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
function writeRepoConnection(projectRoot, state) {
|
|
374
|
+
writeJsonFile(resolveRepoConnectionPath(projectRoot), state);
|
|
375
|
+
}
|
|
376
|
+
function resolveSelectedConnection(projectRoot, options = {}) {
|
|
377
|
+
const repo = readRepoConnection(projectRoot);
|
|
378
|
+
if (!repo)
|
|
379
|
+
return null;
|
|
380
|
+
if (repo.selected === "local")
|
|
381
|
+
return { alias: "local", connection: { kind: "local", mode: "auto" }, serverProjectRoot: repo.serverProjectRoot };
|
|
382
|
+
const global = readGlobalConnections(options);
|
|
383
|
+
const connection = global.connections[repo.selected];
|
|
384
|
+
if (!connection) {
|
|
385
|
+
throw new CliError(`Selected Rig server "${repo.selected}" was not found. Run \`rig server list\` or \`rig server use local\`.`, 1);
|
|
386
|
+
}
|
|
387
|
+
return { alias: repo.selected, connection, serverProjectRoot: repo.serverProjectRoot };
|
|
388
|
+
}
|
|
389
|
+
function writeRepoServerProjectRoot(projectRoot, serverProjectRoot) {
|
|
390
|
+
const repo = readRepoConnection(projectRoot);
|
|
391
|
+
if (!repo)
|
|
392
|
+
return;
|
|
393
|
+
writeRepoConnection(projectRoot, { ...repo, serverProjectRoot });
|
|
394
|
+
}
|
|
395
|
+
var init__connection_state = __esm(() => {
|
|
396
|
+
init_runner();
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
// packages/cli/src/commands/_server-client.ts
|
|
400
|
+
var exports__server_client = {};
|
|
401
|
+
__export(exports__server_client, {
|
|
402
|
+
updateWorkspaceTaskViaServer: () => updateWorkspaceTaskViaServer,
|
|
403
|
+
switchServerProjectRootViaServer: () => switchServerProjectRootViaServer,
|
|
404
|
+
submitTaskRunViaServer: () => submitTaskRunViaServer,
|
|
405
|
+
stopRunViaServer: () => stopRunViaServer,
|
|
406
|
+
steerRunViaServer: () => steerRunViaServer,
|
|
407
|
+
setServerPhaseListener: () => setServerPhaseListener,
|
|
408
|
+
setGitHubBearerTokenForCurrentProcess: () => setGitHubBearerTokenForCurrentProcess,
|
|
409
|
+
sendRunPiShellViaServer: () => sendRunPiShellViaServer,
|
|
410
|
+
sendRunPiPromptViaServer: () => sendRunPiPromptViaServer,
|
|
411
|
+
selectNextWorkspaceTaskViaServer: () => selectNextWorkspaceTaskViaServer,
|
|
412
|
+
runRunPiCommandViaServer: () => runRunPiCommandViaServer,
|
|
413
|
+
resumeRunViaServer: () => resumeRunViaServer,
|
|
414
|
+
respondRunPiExtensionUiViaServer: () => respondRunPiExtensionUiViaServer,
|
|
415
|
+
resolveServerConnectionLabel: () => resolveServerConnectionLabel,
|
|
416
|
+
requestServerJson: () => requestServerJson,
|
|
417
|
+
registerProjectViaServer: () => registerProjectViaServer,
|
|
418
|
+
prepareRemoteCheckoutViaServer: () => prepareRemoteCheckoutViaServer,
|
|
419
|
+
postGitHubTokenViaServer: () => postGitHubTokenViaServer,
|
|
420
|
+
listWorkspaceTasksViaServer: () => listWorkspaceTasksViaServer,
|
|
421
|
+
listRunsViaServer: () => listRunsViaServer,
|
|
422
|
+
listGitHubProjectsViaServer: () => listGitHubProjectsViaServer,
|
|
423
|
+
getWorkspaceTaskViaServer: () => getWorkspaceTaskViaServer,
|
|
424
|
+
getRunTimelineViaServer: () => getRunTimelineViaServer,
|
|
425
|
+
getRunPiStatusViaServer: () => getRunPiStatusViaServer,
|
|
426
|
+
getRunPiSessionViaServer: () => getRunPiSessionViaServer,
|
|
427
|
+
getRunPiMessagesViaServer: () => getRunPiMessagesViaServer,
|
|
428
|
+
getRunPiCommandsViaServer: () => getRunPiCommandsViaServer,
|
|
429
|
+
getRunPiCapabilitiesViaServer: () => getRunPiCapabilitiesViaServer,
|
|
430
|
+
getRunLogsViaServer: () => getRunLogsViaServer,
|
|
431
|
+
getRunDetailsViaServer: () => getRunDetailsViaServer,
|
|
432
|
+
getGitHubProjectStatusFieldViaServer: () => getGitHubProjectStatusFieldViaServer,
|
|
433
|
+
getGitHubAuthStatusViaServer: () => getGitHubAuthStatusViaServer,
|
|
434
|
+
ensureTaskLabelsViaServer: () => ensureTaskLabelsViaServer,
|
|
435
|
+
ensureServerForCli: () => ensureServerForCli,
|
|
436
|
+
buildRunPiEventsWebSocketUrl: () => buildRunPiEventsWebSocketUrl,
|
|
437
|
+
abortRunPiViaServer: () => abortRunPiViaServer
|
|
438
|
+
});
|
|
439
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
440
|
+
import { resolve as resolve2 } from "path";
|
|
441
|
+
import { ensureLocalRigServerConnection } from "@rig/runtime/local-server";
|
|
442
|
+
function setServerPhaseListener(listener) {
|
|
443
|
+
const previous = serverPhaseListener;
|
|
444
|
+
serverPhaseListener = listener;
|
|
445
|
+
return previous;
|
|
446
|
+
}
|
|
447
|
+
function reportServerPhase(label) {
|
|
448
|
+
serverPhaseListener?.(label);
|
|
449
|
+
}
|
|
450
|
+
function cleanToken(value) {
|
|
451
|
+
const trimmed = value?.trim();
|
|
452
|
+
return trimmed ? trimmed : null;
|
|
453
|
+
}
|
|
454
|
+
function setGitHubBearerTokenForCurrentProcess(token, projectRoot) {
|
|
455
|
+
const scopedKey = resolve2(projectRoot ?? process.cwd());
|
|
456
|
+
scopedGitHubBearerTokens.set(scopedKey, cleanToken(token ?? undefined));
|
|
457
|
+
}
|
|
458
|
+
function readPrivateRemoteSessionToken(projectRoot) {
|
|
459
|
+
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
460
|
+
if (!existsSync2(path))
|
|
461
|
+
return null;
|
|
462
|
+
try {
|
|
463
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
464
|
+
return cleanToken(typeof parsed.apiSessionToken === "string" ? parsed.apiSessionToken : typeof parsed.sessionToken === "string" ? parsed.sessionToken : undefined);
|
|
465
|
+
} catch {
|
|
466
|
+
return null;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
function readGitHubBearerTokenForRemote(projectRoot) {
|
|
470
|
+
const scopedKey = resolve2(projectRoot);
|
|
471
|
+
if (scopedGitHubBearerTokens.has(scopedKey))
|
|
472
|
+
return scopedGitHubBearerTokens.get(scopedKey) ?? null;
|
|
473
|
+
const privateSession = readPrivateRemoteSessionToken(projectRoot);
|
|
474
|
+
if (privateSession)
|
|
475
|
+
return privateSession;
|
|
476
|
+
return cleanToken(process.env.RIG_SERVER_AUTH_TOKEN) ?? cleanToken(process.env.RIG_REMOTE_AUTH_TOKEN);
|
|
477
|
+
}
|
|
478
|
+
function readStoredGitHubAuthToken(projectRoot) {
|
|
479
|
+
const path = resolve2(projectRoot, ".rig", "state", "github-auth.json");
|
|
480
|
+
if (!existsSync2(path))
|
|
481
|
+
return null;
|
|
482
|
+
try {
|
|
483
|
+
const parsed = JSON.parse(readFileSync2(path, "utf8"));
|
|
484
|
+
return cleanToken(typeof parsed.token === "string" ? parsed.token : undefined);
|
|
485
|
+
} catch {
|
|
486
|
+
return null;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
function readLocalConnectionFallbackToken(projectRoot) {
|
|
490
|
+
return readGitHubBearerTokenForRemote(projectRoot) ?? cleanToken(process.env.RIG_GITHUB_TOKEN) ?? readStoredGitHubAuthToken(projectRoot);
|
|
491
|
+
}
|
|
492
|
+
async function ensureServerForCli(projectRoot) {
|
|
493
|
+
try {
|
|
494
|
+
const selected = resolveSelectedConnection(projectRoot);
|
|
495
|
+
if (selected?.connection.kind === "remote") {
|
|
496
|
+
reportServerPhase(`Connecting to ${selected.alias}\u2026`);
|
|
497
|
+
const authToken = readGitHubBearerTokenForRemote(projectRoot);
|
|
498
|
+
const serverProjectRoot = selected.serverProjectRoot ?? await backfillRemoteServerProjectRoot(projectRoot, selected.connection.baseUrl, authToken);
|
|
499
|
+
return {
|
|
500
|
+
baseUrl: selected.connection.baseUrl,
|
|
501
|
+
authToken,
|
|
502
|
+
connectionKind: "remote",
|
|
503
|
+
serverProjectRoot
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
reportServerPhase("Starting local Rig server\u2026");
|
|
507
|
+
const connection = await ensureLocalRigServerConnection(projectRoot);
|
|
508
|
+
return {
|
|
509
|
+
baseUrl: connection.baseUrl,
|
|
510
|
+
authToken: connection.authToken ?? readLocalConnectionFallbackToken(projectRoot),
|
|
511
|
+
connectionKind: "local",
|
|
512
|
+
serverProjectRoot: resolve2(projectRoot)
|
|
513
|
+
};
|
|
514
|
+
} catch (error) {
|
|
515
|
+
if (error instanceof Error) {
|
|
516
|
+
throw new CliError(error.message, 1);
|
|
517
|
+
}
|
|
518
|
+
throw error;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
async function backfillRemoteServerProjectRoot(projectRoot, baseUrl, authToken) {
|
|
522
|
+
const repo = readRepoConnection(projectRoot);
|
|
523
|
+
const slug = repo?.project?.trim();
|
|
524
|
+
if (!slug)
|
|
525
|
+
return null;
|
|
526
|
+
try {
|
|
527
|
+
const response = await fetch(`${baseUrl}/api/projects/${encodeURIComponent(slug)}`, {
|
|
528
|
+
headers: mergeHeaders(undefined, authToken)
|
|
529
|
+
});
|
|
530
|
+
if (!response.ok)
|
|
531
|
+
return null;
|
|
532
|
+
const payload = await response.json();
|
|
533
|
+
const project = payload.project && typeof payload.project === "object" && !Array.isArray(payload.project) ? payload.project : null;
|
|
534
|
+
const checkouts = Array.isArray(project?.checkouts) ? project.checkouts : [];
|
|
535
|
+
const latestCheckout = [...checkouts].reverse().find((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry) && typeof entry.path === "string"));
|
|
536
|
+
const path = typeof latestCheckout?.path === "string" && latestCheckout.path.trim() ? latestCheckout.path.trim() : null;
|
|
537
|
+
if (path)
|
|
538
|
+
writeRepoServerProjectRoot(projectRoot, path);
|
|
539
|
+
return path;
|
|
540
|
+
} catch {
|
|
541
|
+
return null;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
function appendTaskFilterParams(url, filters) {
|
|
545
|
+
if (filters.assignee)
|
|
546
|
+
url.searchParams.set("assignee", filters.assignee);
|
|
547
|
+
if (filters.state)
|
|
548
|
+
url.searchParams.set("state", filters.state);
|
|
549
|
+
if (filters.status)
|
|
550
|
+
url.searchParams.set("status", filters.status);
|
|
551
|
+
if (filters.limit !== undefined)
|
|
552
|
+
url.searchParams.set("limit", String(filters.limit));
|
|
553
|
+
}
|
|
554
|
+
function mergeHeaders(headers, authToken) {
|
|
555
|
+
const merged = new Headers(headers);
|
|
556
|
+
if (authToken) {
|
|
557
|
+
merged.set("authorization", `Bearer ${authToken}`);
|
|
558
|
+
}
|
|
559
|
+
return merged;
|
|
560
|
+
}
|
|
561
|
+
function diagnosticMessage(payload) {
|
|
562
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
563
|
+
return null;
|
|
564
|
+
const record = payload;
|
|
565
|
+
const diagnostics = Array.isArray(record.diagnostics) ? record.diagnostics : [];
|
|
566
|
+
const messages = diagnostics.flatMap((entry) => {
|
|
567
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
568
|
+
return [];
|
|
569
|
+
const diagnostic = entry;
|
|
570
|
+
const kind = typeof diagnostic.kind === "string" ? diagnostic.kind : "task-source";
|
|
571
|
+
const message = typeof diagnostic.message === "string" ? diagnostic.message : null;
|
|
572
|
+
return message ? [`${kind}: ${message}`] : [];
|
|
573
|
+
});
|
|
574
|
+
return messages.length > 0 ? messages.join("; ") : null;
|
|
575
|
+
}
|
|
576
|
+
async function probeServerReachability(baseUrl, authToken) {
|
|
577
|
+
try {
|
|
578
|
+
const response = await fetch(`${baseUrl.replace(/\/+$/, "")}/api/server/status`, {
|
|
579
|
+
headers: mergeHeaders(undefined, authToken),
|
|
580
|
+
signal: AbortSignal.timeout(1500)
|
|
581
|
+
});
|
|
582
|
+
return response.ok;
|
|
583
|
+
} catch {
|
|
584
|
+
return false;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
function cachedServerReachability(projectRoot, baseUrl, authToken) {
|
|
588
|
+
const key = resolve2(projectRoot);
|
|
589
|
+
const cached = serverReachabilityCache.get(key);
|
|
590
|
+
if (cached)
|
|
591
|
+
return cached;
|
|
592
|
+
const probe = probeServerReachability(baseUrl, authToken);
|
|
593
|
+
serverReachabilityCache.set(key, probe);
|
|
594
|
+
return probe;
|
|
595
|
+
}
|
|
596
|
+
function describeSelectedServer(projectRoot, server) {
|
|
597
|
+
try {
|
|
598
|
+
const selected = resolveSelectedConnection(projectRoot);
|
|
599
|
+
if (selected) {
|
|
600
|
+
return {
|
|
601
|
+
alias: selected.alias,
|
|
602
|
+
target: selected.connection.kind === "remote" ? selected.connection.baseUrl : server.baseUrl
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
} catch {}
|
|
606
|
+
return { alias: server.connectionKind === "remote" ? "remote" : "local", target: server.baseUrl };
|
|
607
|
+
}
|
|
608
|
+
async function buildServerFailureContext(projectRoot, server) {
|
|
609
|
+
const { alias, target } = describeSelectedServer(projectRoot, server);
|
|
610
|
+
const reachable = await cachedServerReachability(projectRoot, server.baseUrl, server.authToken);
|
|
611
|
+
const reachability = reachable ? "server is reachable" : "server is unreachable";
|
|
612
|
+
return {
|
|
613
|
+
contextLine: `Currently connected to: ${alias} at ${target} (${reachability}).`,
|
|
614
|
+
hint: "Check the selected server with `rig server status`, or switch with `rig server use <alias|local>`."
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
async function requestServerJson(context, pathname, init = {}) {
|
|
618
|
+
const server = await ensureServerForCli(context.projectRoot);
|
|
619
|
+
const headers = mergeHeaders(init.headers, server.authToken);
|
|
620
|
+
if (server.serverProjectRoot)
|
|
621
|
+
headers.set("x-rig-project-root", server.serverProjectRoot);
|
|
622
|
+
reportServerPhase(`${(init.method ?? "GET").toUpperCase()} ${pathname.split("?")[0]}\u2026`);
|
|
623
|
+
let response;
|
|
624
|
+
try {
|
|
625
|
+
response = await fetch(`${server.baseUrl}${pathname}`, {
|
|
626
|
+
...init,
|
|
627
|
+
headers
|
|
628
|
+
});
|
|
629
|
+
} catch (error) {
|
|
630
|
+
const failure = await buildServerFailureContext(context.projectRoot, server);
|
|
631
|
+
throw new CliError(`Rig server request failed: ${error instanceof Error ? error.message : String(error)}
|
|
632
|
+
${failure.contextLine}`, 1, { hint: failure.hint });
|
|
633
|
+
}
|
|
634
|
+
const text = await response.text();
|
|
635
|
+
const payload = text.trim().length > 0 ? (() => {
|
|
636
|
+
try {
|
|
637
|
+
return JSON.parse(text);
|
|
638
|
+
} catch {
|
|
639
|
+
return null;
|
|
640
|
+
}
|
|
641
|
+
})() : null;
|
|
642
|
+
if (!response.ok) {
|
|
643
|
+
const diagnostics = diagnosticMessage(payload);
|
|
644
|
+
const rawDetail = diagnostics ?? (text || response.statusText);
|
|
645
|
+
const detail = diagnostics ? rawDetail : rawDetail.split(`
|
|
646
|
+
`).map((line) => line.trim()).find((line) => line.length > 0)?.slice(0, 200) ?? response.statusText;
|
|
647
|
+
const failure = await buildServerFailureContext(context.projectRoot, server);
|
|
648
|
+
throw new CliError(`Rig server request failed (${response.status}): ${detail}
|
|
649
|
+
${failure.contextLine}`, 1, { hint: failure.hint });
|
|
650
|
+
}
|
|
651
|
+
return payload;
|
|
652
|
+
}
|
|
653
|
+
async function listWorkspaceTasksViaServer(context, filters = {}) {
|
|
654
|
+
const url = new URL("http://rig.local/api/workspace/tasks");
|
|
655
|
+
appendTaskFilterParams(url, filters);
|
|
656
|
+
const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
|
|
657
|
+
if (!Array.isArray(payload)) {
|
|
658
|
+
throw new CliError("Rig server returned an invalid task list payload.", 1, { hint: "Check the selected server with `rig server status`; mixed CLI/server versions can mismatch \u2014 try `rig doctor`." });
|
|
659
|
+
}
|
|
660
|
+
return payload.flatMap((entry) => entry && typeof entry === "object" && !Array.isArray(entry) ? [entry] : []);
|
|
661
|
+
}
|
|
662
|
+
async function getWorkspaceTaskViaServer(context, taskId) {
|
|
663
|
+
const payload = await requestServerJson(context, `/api/workspace/tasks/${encodeURIComponent(taskId)}`);
|
|
664
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
665
|
+
return null;
|
|
666
|
+
const task = payload.task;
|
|
667
|
+
return task && typeof task === "object" && !Array.isArray(task) ? task : null;
|
|
668
|
+
}
|
|
669
|
+
async function selectNextWorkspaceTaskViaServer(context, filters = {}) {
|
|
670
|
+
const url = new URL("http://rig.local/api/workspace/tasks/next");
|
|
671
|
+
appendTaskFilterParams(url, filters);
|
|
672
|
+
const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
|
|
673
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
674
|
+
throw new CliError("Rig server returned an invalid next-task payload.", 1, { hint: "Check the selected server with `rig server status`; try `rig task list` to see the raw task set." });
|
|
675
|
+
}
|
|
676
|
+
const record = payload;
|
|
677
|
+
const rawTask = record.task;
|
|
678
|
+
const task = rawTask && typeof rawTask === "object" && !Array.isArray(rawTask) ? rawTask : null;
|
|
679
|
+
const count = typeof record.count === "number" && Number.isFinite(record.count) ? record.count : task ? 1 : 0;
|
|
680
|
+
return { task, count };
|
|
681
|
+
}
|
|
682
|
+
async function getGitHubAuthStatusViaServer(context) {
|
|
683
|
+
const payload = await requestServerJson(context, "/api/github/auth/status");
|
|
684
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
685
|
+
}
|
|
686
|
+
async function postGitHubTokenViaServer(context, token, options = {}) {
|
|
687
|
+
const payload = await requestServerJson(context, "/api/github/auth/token", {
|
|
688
|
+
method: "POST",
|
|
689
|
+
headers: { "content-type": "application/json" },
|
|
690
|
+
body: JSON.stringify({ token, selectedRepo: options.selectedRepo, projectRoot: options.projectRoot })
|
|
691
|
+
});
|
|
692
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
693
|
+
}
|
|
694
|
+
async function prepareRemoteCheckoutViaServer(context, input) {
|
|
695
|
+
const payload = await requestServerJson(context, `/api/projects/${encodeURIComponent(input.repoSlug)}/prepare-checkout`, {
|
|
696
|
+
method: "POST",
|
|
697
|
+
headers: { "content-type": "application/json" },
|
|
698
|
+
body: JSON.stringify({ checkout: input.checkout, repoUrl: input.repoUrl, baseDir: input.baseDir })
|
|
699
|
+
});
|
|
700
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
701
|
+
}
|
|
702
|
+
async function registerProjectViaServer(context, input) {
|
|
703
|
+
const payload = await requestServerJson(context, "/api/projects", {
|
|
704
|
+
method: "POST",
|
|
705
|
+
headers: { "content-type": "application/json" },
|
|
706
|
+
body: JSON.stringify(input)
|
|
707
|
+
});
|
|
708
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
709
|
+
}
|
|
710
|
+
function sleep(ms) {
|
|
711
|
+
return new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
712
|
+
}
|
|
713
|
+
function isRetryableProjectRootSwitchError(error) {
|
|
714
|
+
if (!(error instanceof Error))
|
|
715
|
+
return false;
|
|
716
|
+
const message = error.message.toLowerCase();
|
|
717
|
+
return message.includes("rig server request failed (401): auth-required") || message.includes("rig server request failed (401): github-token-required") || message.includes("rig server request failed (502)") || message.includes("rig server request failed (503)") || message.includes("bad gateway") || message.includes("fetch failed") || message.includes("econnrefused") || message.includes("connection refused");
|
|
718
|
+
}
|
|
719
|
+
async function switchServerProjectRootViaServer(context, projectRoot, options = {}) {
|
|
720
|
+
const timeoutMs = options.timeoutMs ?? 30000;
|
|
721
|
+
const pollMs = options.pollMs ?? 1000;
|
|
722
|
+
const deadline = Date.now() + timeoutMs;
|
|
723
|
+
let lastError;
|
|
724
|
+
let switched = null;
|
|
725
|
+
while (Date.now() < deadline) {
|
|
726
|
+
try {
|
|
727
|
+
switched = await requestServerJson(context, "/api/server/project-root", {
|
|
728
|
+
method: "POST",
|
|
729
|
+
headers: { "content-type": "application/json" },
|
|
730
|
+
body: JSON.stringify({ projectRoot })
|
|
731
|
+
});
|
|
732
|
+
break;
|
|
733
|
+
} catch (error) {
|
|
734
|
+
lastError = error;
|
|
735
|
+
if (!isRetryableProjectRootSwitchError(error))
|
|
736
|
+
throw error;
|
|
737
|
+
await sleep(pollMs);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
if (!switched) {
|
|
741
|
+
throw new CliError(`Rig server did not accept project-root switch to ${projectRoot} before timeout (${lastError instanceof Error ? lastError.message : String(lastError ?? "no response")}).`, 1);
|
|
742
|
+
}
|
|
743
|
+
const record = switched && typeof switched === "object" && !Array.isArray(switched) ? switched : {};
|
|
744
|
+
if (record.ok === true) {
|
|
745
|
+
writeRepoServerProjectRoot(context.projectRoot, projectRoot);
|
|
746
|
+
return { ok: true, switched: record };
|
|
747
|
+
}
|
|
748
|
+
throw new CliError(`Rig server rejected project-root scope ${projectRoot}: ${String(record.message ?? record.error ?? "unknown error")}`, 1);
|
|
749
|
+
}
|
|
750
|
+
async function listRunsViaServer(context, options = {}) {
|
|
751
|
+
const url = new URL("http://rig.local/api/runs");
|
|
752
|
+
if (options.limit !== undefined)
|
|
753
|
+
url.searchParams.set("limit", String(options.limit));
|
|
754
|
+
const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
|
|
755
|
+
const runs = Array.isArray(payload) ? payload : payload && typeof payload === "object" && !Array.isArray(payload) && Array.isArray(payload.runs) ? payload.runs : [];
|
|
756
|
+
return runs.filter((entry) => Boolean(entry && typeof entry === "object" && !Array.isArray(entry)));
|
|
757
|
+
}
|
|
758
|
+
async function getRunDetailsViaServer(context, runId) {
|
|
759
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}`);
|
|
760
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
761
|
+
}
|
|
762
|
+
async function getRunLogsViaServer(context, runId, options = {}) {
|
|
763
|
+
const url = new URL(`http://rig.local/api/runs/${encodeURIComponent(runId)}/logs`);
|
|
764
|
+
if (options.limit !== undefined)
|
|
765
|
+
url.searchParams.set("limit", String(options.limit));
|
|
766
|
+
if (options.cursor)
|
|
767
|
+
url.searchParams.set("cursor", options.cursor);
|
|
768
|
+
const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
|
|
769
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { entries: [] };
|
|
770
|
+
}
|
|
771
|
+
async function getRunTimelineViaServer(context, runId, options = {}) {
|
|
772
|
+
const url = new URL(`http://rig.local/api/runs/${encodeURIComponent(runId)}/timeline`);
|
|
773
|
+
if (options.limit !== undefined)
|
|
774
|
+
url.searchParams.set("limit", String(options.limit));
|
|
775
|
+
if (options.cursor)
|
|
776
|
+
url.searchParams.set("cursor", options.cursor);
|
|
777
|
+
const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
|
|
778
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { entries: [] };
|
|
779
|
+
}
|
|
780
|
+
async function ensureTaskLabelsViaServer(context) {
|
|
781
|
+
const payload = await requestServerJson(context, "/api/workspace/task-labels", { method: "POST" });
|
|
782
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
783
|
+
}
|
|
784
|
+
async function listGitHubProjectsViaServer(context, owner) {
|
|
785
|
+
const url = new URL("http://rig.local/api/github/projects");
|
|
786
|
+
url.searchParams.set("owner", owner);
|
|
787
|
+
const payload = await requestServerJson(context, `${url.pathname}${url.search}`);
|
|
788
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { projects: [] };
|
|
789
|
+
}
|
|
790
|
+
async function getGitHubProjectStatusFieldViaServer(context, projectId) {
|
|
791
|
+
const payload = await requestServerJson(context, `/api/github/projects/${encodeURIComponent(projectId)}/status-field`);
|
|
792
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
793
|
+
}
|
|
794
|
+
async function updateWorkspaceTaskViaServer(context, input) {
|
|
795
|
+
const payload = await requestServerJson(context, "/api/tasks/update", {
|
|
796
|
+
method: "POST",
|
|
797
|
+
headers: { "content-type": "application/json" },
|
|
798
|
+
body: JSON.stringify(input)
|
|
799
|
+
});
|
|
800
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { ok: true };
|
|
801
|
+
}
|
|
802
|
+
async function resumeRunViaServer(context, runId, options) {
|
|
803
|
+
let targetRunId = runId?.trim() || null;
|
|
804
|
+
if (!targetRunId) {
|
|
805
|
+
const candidates = (await listRunsViaServer(context)).filter((run) => RESUMABLE_RUN_STATUSES.has(String(run.status ?? ""))).sort((left, right) => String(right.updatedAt ?? "").localeCompare(String(left.updatedAt ?? "")));
|
|
806
|
+
targetRunId = typeof candidates[0]?.runId === "string" ? candidates[0].runId : null;
|
|
807
|
+
}
|
|
808
|
+
if (!targetRunId) {
|
|
809
|
+
throw new CliError(options.restart ? "No run is available to restart." : "No resumable run is available.", 2, { hint: "List runs with `rig run list`, then pass an explicit id: `rig run resume <run-id>`." });
|
|
810
|
+
}
|
|
811
|
+
const payload = await requestServerJson(context, "/api/runs/resume", {
|
|
812
|
+
method: "POST",
|
|
813
|
+
headers: { "content-type": "application/json" },
|
|
814
|
+
body: JSON.stringify({ runId: targetRunId, createdAt: new Date().toISOString(), restart: options.restart })
|
|
815
|
+
});
|
|
816
|
+
const record = payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
817
|
+
if (record.ok === false) {
|
|
818
|
+
const message = typeof record.error === "string" && record.error.trim() ? record.error : "run resume failed";
|
|
819
|
+
throw new CliError(`${options.restart ? "restart" : "resume"} failed for ${targetRunId}: ${message}`, 1);
|
|
820
|
+
}
|
|
821
|
+
return { ok: true, runId: targetRunId, ...record };
|
|
822
|
+
}
|
|
823
|
+
async function resolveServerConnectionLabel(projectRoot) {
|
|
824
|
+
try {
|
|
825
|
+
const selected = resolveSelectedConnection(projectRoot);
|
|
826
|
+
if (!selected)
|
|
827
|
+
return "no server selected";
|
|
828
|
+
if (selected.connection.kind === "remote") {
|
|
829
|
+
return selected.connection.baseUrl.replace(/^https?:\/\//, "");
|
|
830
|
+
}
|
|
831
|
+
return `local (${selected.alias})`;
|
|
832
|
+
} catch {
|
|
833
|
+
return "no server selected";
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
async function stopRunViaServer(context, runId) {
|
|
837
|
+
const payload = await requestServerJson(context, "/api/runs/stop", {
|
|
838
|
+
method: "POST",
|
|
839
|
+
headers: { "content-type": "application/json" },
|
|
840
|
+
body: JSON.stringify({ runId })
|
|
841
|
+
});
|
|
842
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { ok: true, runId };
|
|
843
|
+
}
|
|
844
|
+
async function steerRunViaServer(context, runId, message) {
|
|
845
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/steer`, {
|
|
846
|
+
method: "POST",
|
|
847
|
+
headers: { "content-type": "application/json" },
|
|
848
|
+
body: JSON.stringify({ message })
|
|
849
|
+
});
|
|
850
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { ok: true };
|
|
851
|
+
}
|
|
852
|
+
async function getRunPiSessionViaServer(context, runId) {
|
|
853
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi`);
|
|
854
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
855
|
+
}
|
|
856
|
+
async function getRunPiMessagesViaServer(context, runId) {
|
|
857
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/messages`);
|
|
858
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { messages: [] };
|
|
859
|
+
}
|
|
860
|
+
async function getRunPiStatusViaServer(context, runId) {
|
|
861
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/status`);
|
|
862
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
863
|
+
}
|
|
864
|
+
async function getRunPiCommandsViaServer(context, runId) {
|
|
865
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/commands`);
|
|
866
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { commands: [] };
|
|
867
|
+
}
|
|
868
|
+
async function getRunPiCapabilitiesViaServer(context, runId) {
|
|
869
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/capabilities`);
|
|
870
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { capabilities: null };
|
|
871
|
+
}
|
|
872
|
+
async function sendRunPiPromptViaServer(context, runId, text, streamingBehavior) {
|
|
873
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/prompt`, {
|
|
874
|
+
method: "POST",
|
|
875
|
+
headers: { "content-type": "application/json" },
|
|
876
|
+
body: JSON.stringify({ text, streamingBehavior })
|
|
877
|
+
});
|
|
878
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { accepted: true };
|
|
879
|
+
}
|
|
880
|
+
async function sendRunPiShellViaServer(context, runId, text) {
|
|
881
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/shell`, {
|
|
882
|
+
method: "POST",
|
|
883
|
+
headers: { "content-type": "application/json" },
|
|
884
|
+
body: JSON.stringify({ text })
|
|
885
|
+
});
|
|
886
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { accepted: true };
|
|
887
|
+
}
|
|
888
|
+
async function runRunPiCommandViaServer(context, runId, text) {
|
|
889
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/commands/run`, {
|
|
890
|
+
method: "POST",
|
|
891
|
+
headers: { "content-type": "application/json" },
|
|
892
|
+
body: JSON.stringify({ text })
|
|
893
|
+
});
|
|
894
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { type: "done" };
|
|
895
|
+
}
|
|
896
|
+
async function respondRunPiExtensionUiViaServer(context, runId, requestId, valueOrCancel) {
|
|
897
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/extension-ui/respond`, {
|
|
898
|
+
method: "POST",
|
|
899
|
+
headers: { "content-type": "application/json" },
|
|
900
|
+
body: JSON.stringify({ requestId, ...valueOrCancel })
|
|
901
|
+
});
|
|
902
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { accepted: true };
|
|
903
|
+
}
|
|
904
|
+
async function abortRunPiViaServer(context, runId) {
|
|
905
|
+
const payload = await requestServerJson(context, `/api/runs/${encodeURIComponent(runId)}/pi/abort`, { method: "POST" });
|
|
906
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? payload : { aborted: true };
|
|
907
|
+
}
|
|
908
|
+
async function buildRunPiEventsWebSocketUrl(context, runId) {
|
|
909
|
+
const server = await ensureServerForCli(context.projectRoot);
|
|
910
|
+
const url = new URL(`${server.baseUrl.replace(/\/+$/, "")}/api/runs/${encodeURIComponent(runId)}/pi/events`);
|
|
911
|
+
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
912
|
+
if (server.authToken)
|
|
913
|
+
url.searchParams.set("token", server.authToken);
|
|
914
|
+
if (server.serverProjectRoot)
|
|
915
|
+
url.searchParams.set("rigProjectRoot", server.serverProjectRoot);
|
|
916
|
+
return url.toString();
|
|
917
|
+
}
|
|
918
|
+
async function submitTaskRunViaServer(context, input) {
|
|
919
|
+
const isTaskRun = Boolean(input.taskId);
|
|
920
|
+
const endpoint = isTaskRun ? "/api/runs/task" : "/api/runs/adhoc";
|
|
921
|
+
const payload = await requestServerJson(context, endpoint, {
|
|
922
|
+
method: "POST",
|
|
923
|
+
headers: {
|
|
924
|
+
"content-type": "application/json"
|
|
925
|
+
},
|
|
926
|
+
body: JSON.stringify({
|
|
927
|
+
runId: input.runId,
|
|
928
|
+
taskId: input.taskId,
|
|
929
|
+
title: input.title,
|
|
930
|
+
runtimeAdapter: input.runtimeAdapter,
|
|
931
|
+
model: input.model,
|
|
932
|
+
runtimeMode: input.runtimeMode,
|
|
933
|
+
interactionMode: input.interactionMode,
|
|
934
|
+
initialPrompt: input.initialPrompt,
|
|
935
|
+
baselineMode: input.baselineMode,
|
|
936
|
+
prMode: input.prMode,
|
|
937
|
+
executionTarget: "local"
|
|
938
|
+
})
|
|
939
|
+
});
|
|
940
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
941
|
+
throw new CliError("Rig server returned an invalid run submission payload.", 1, { hint: "Check `rig server status` and retry; `rig run list` shows whether the run was created anyway." });
|
|
942
|
+
}
|
|
943
|
+
const runId = payload.runId;
|
|
944
|
+
if (typeof runId !== "string" || runId.trim().length === 0) {
|
|
945
|
+
throw new CliError("Rig server returned no runId for the submitted run.", 1, { hint: "Check `rig run list` \u2014 the run may still have been created; otherwise retry the submission." });
|
|
946
|
+
}
|
|
947
|
+
return { runId };
|
|
948
|
+
}
|
|
949
|
+
var scopedGitHubBearerTokens, serverPhaseListener = null, serverReachabilityCache, RESUMABLE_RUN_STATUSES;
|
|
950
|
+
var init__server_client = __esm(() => {
|
|
951
|
+
init_runner();
|
|
952
|
+
init__connection_state();
|
|
953
|
+
scopedGitHubBearerTokens = new Map;
|
|
954
|
+
serverReachabilityCache = new Map;
|
|
955
|
+
RESUMABLE_RUN_STATUSES = new Set([
|
|
956
|
+
"created",
|
|
957
|
+
"preparing",
|
|
958
|
+
"running",
|
|
959
|
+
"validating",
|
|
960
|
+
"reviewing",
|
|
961
|
+
"stopped",
|
|
962
|
+
"failed",
|
|
963
|
+
"needs-attention",
|
|
964
|
+
"needs_attention"
|
|
965
|
+
]);
|
|
966
|
+
});
|
|
967
|
+
|
|
968
|
+
// packages/cli/src/commands/_async-ui.ts
|
|
969
|
+
import pc2 from "picocolors";
|
|
970
|
+
async function withSpinner(label, work, options = {}) {
|
|
971
|
+
if (options.outputMode === "json") {
|
|
972
|
+
return work(() => {});
|
|
973
|
+
}
|
|
974
|
+
if (activeUpdate) {
|
|
975
|
+
const outer = activeUpdate;
|
|
976
|
+
outer(label);
|
|
977
|
+
return work(outer);
|
|
978
|
+
}
|
|
979
|
+
const output = options.output ?? process.stderr;
|
|
980
|
+
const isTty = output.isTTY === true;
|
|
981
|
+
let lastLabel = label;
|
|
982
|
+
if (!isTty) {
|
|
983
|
+
output.write(`${label}
|
|
984
|
+
`);
|
|
985
|
+
const update2 = (next) => {
|
|
986
|
+
lastLabel = next;
|
|
987
|
+
};
|
|
988
|
+
activeUpdate = update2;
|
|
989
|
+
const previousListener2 = setServerPhaseListener(update2);
|
|
990
|
+
try {
|
|
991
|
+
return await work(update2);
|
|
992
|
+
} finally {
|
|
993
|
+
activeUpdate = null;
|
|
994
|
+
setServerPhaseListener(previousListener2);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
const spinner = createTtySpinner({
|
|
998
|
+
label,
|
|
999
|
+
output,
|
|
1000
|
+
frames: MICRO_DRONE_FRAMES,
|
|
1001
|
+
styleFrame: (frame) => renderMicroDroneFrame(Math.max(0, MICRO_DRONE_FRAMES.indexOf(frame)))
|
|
1002
|
+
});
|
|
1003
|
+
const update = (next) => {
|
|
1004
|
+
lastLabel = next;
|
|
1005
|
+
spinner.setLabel(next);
|
|
1006
|
+
};
|
|
1007
|
+
activeUpdate = update;
|
|
1008
|
+
const previousListener = setServerPhaseListener(update);
|
|
1009
|
+
try {
|
|
1010
|
+
const result = await work(update);
|
|
1011
|
+
spinner.stop(options.doneLabel ? `${DONE_SYMBOL} ${options.doneLabel}` : undefined);
|
|
1012
|
+
return result;
|
|
1013
|
+
} catch (error) {
|
|
1014
|
+
spinner.stop(`${FAIL_SYMBOL} ${lastLabel}`);
|
|
1015
|
+
throw error;
|
|
1016
|
+
} finally {
|
|
1017
|
+
activeUpdate = null;
|
|
1018
|
+
setServerPhaseListener(previousListener);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
var DONE_SYMBOL, FAIL_SYMBOL, activeUpdate = null;
|
|
1022
|
+
var init__async_ui = __esm(() => {
|
|
1023
|
+
init__spinner();
|
|
1024
|
+
init__server_client();
|
|
1025
|
+
init_theme();
|
|
1026
|
+
DONE_SYMBOL = pc2.green("\u25C7");
|
|
1027
|
+
FAIL_SYMBOL = pc2.red("\u25A0");
|
|
1028
|
+
});
|
|
1029
|
+
|
|
1030
|
+
// packages/cli/src/commands/inbox.ts
|
|
1031
|
+
var exports_inbox = {};
|
|
1032
|
+
__export(exports_inbox, {
|
|
1033
|
+
readPendingInboxCounts: () => readPendingInboxCounts,
|
|
1034
|
+
printPendingInboxFooter: () => printPendingInboxFooter,
|
|
1035
|
+
listInboxRecords: () => listInboxRecords,
|
|
1036
|
+
executeInbox: () => executeInbox
|
|
1037
|
+
});
|
|
1038
|
+
async function listInboxRecords(context, kind, filters) {
|
|
1039
|
+
const params = new URLSearchParams;
|
|
1040
|
+
if (filters.run)
|
|
1041
|
+
params.set("runId", filters.run);
|
|
1042
|
+
if (filters.task)
|
|
1043
|
+
params.set("taskId", filters.task);
|
|
1044
|
+
const query = params.size > 0 ? `?${params.toString()}` : "";
|
|
1045
|
+
const payload = await requestServerJson(context, `/api/inbox/${kind}${query}`);
|
|
1046
|
+
const records = Array.isArray(payload) ? payload : [];
|
|
1047
|
+
return filters.pendingOnly ? records.filter((entry) => (entry.status ?? "pending") !== "resolved") : records;
|
|
1048
|
+
}
|
|
1049
|
+
async function readPendingInboxCounts(context) {
|
|
1050
|
+
try {
|
|
1051
|
+
const [approvals, inputs] = await Promise.all([
|
|
1052
|
+
listInboxRecords(context, "approvals", { pendingOnly: true }),
|
|
1053
|
+
listInboxRecords(context, "inputs", { pendingOnly: true })
|
|
1054
|
+
]);
|
|
1055
|
+
return { approvals: approvals.length, inputs: inputs.length };
|
|
1056
|
+
} catch {
|
|
1057
|
+
return null;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
async function printPendingInboxFooter(context) {
|
|
1061
|
+
if (context.outputMode !== "text")
|
|
1062
|
+
return;
|
|
1063
|
+
const counts = await readPendingInboxCounts(context);
|
|
1064
|
+
if (!counts || counts.approvals === 0 && counts.inputs === 0)
|
|
1065
|
+
return;
|
|
1066
|
+
const parts = [];
|
|
1067
|
+
if (counts.approvals > 0)
|
|
1068
|
+
parts.push(`${counts.approvals} approval${counts.approvals === 1 ? "" : "s"}`);
|
|
1069
|
+
if (counts.inputs > 0)
|
|
1070
|
+
parts.push(`${counts.inputs} input request${counts.inputs === 1 ? "" : "s"}`);
|
|
1071
|
+
console.log(`
|
|
1072
|
+
\u26A0 ${parts.join(" and ")} pending \u2014 run \`rig inbox\` to review.`);
|
|
1073
|
+
}
|
|
1074
|
+
function renderList(context, kind, records) {
|
|
1075
|
+
if (context.outputMode === "text") {
|
|
1076
|
+
printFormattedOutput(formatInboxList(kind, records));
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
async function watchInbox(context, filters) {
|
|
1080
|
+
const render = async () => {
|
|
1081
|
+
const [approvals, inputs] = await Promise.all([
|
|
1082
|
+
listInboxRecords(context, "approvals", { ...filters, pendingOnly: true }),
|
|
1083
|
+
listInboxRecords(context, "inputs", { ...filters, pendingOnly: true })
|
|
1084
|
+
]);
|
|
1085
|
+
console.clear();
|
|
1086
|
+
console.log(`rig inbox \u2014 watching (Ctrl-C to stop) \u2014 ${new Date().toLocaleTimeString()}`);
|
|
1087
|
+
renderList(context, "approvals", approvals);
|
|
1088
|
+
renderList(context, "inputs", inputs);
|
|
1089
|
+
if (approvals.length === 0 && inputs.length === 0) {
|
|
1090
|
+
console.log("Nothing pending.");
|
|
1091
|
+
} else {
|
|
1092
|
+
console.log(`
|
|
1093
|
+
Resolve with: rig inbox approve --run <id> --request <id> --decision approve|reject`);
|
|
1094
|
+
}
|
|
1095
|
+
};
|
|
1096
|
+
await render();
|
|
1097
|
+
const server = await ensureServerForCli(context.projectRoot);
|
|
1098
|
+
const relevant = /"type":"rig\.(approval|user-input)\./;
|
|
1099
|
+
const fallbackTimer = setInterval(() => {
|
|
1100
|
+
render();
|
|
1101
|
+
}, 30000);
|
|
1102
|
+
fallbackTimer.unref?.();
|
|
1103
|
+
for (;; ) {
|
|
1104
|
+
try {
|
|
1105
|
+
const response = await fetch(`${server.baseUrl}/api/server/events`, {
|
|
1106
|
+
headers: {
|
|
1107
|
+
...server.authToken ? { authorization: `Bearer ${server.authToken}` } : {},
|
|
1108
|
+
...server.serverProjectRoot ? { "x-rig-project-root": server.serverProjectRoot } : {},
|
|
1109
|
+
accept: "text/event-stream"
|
|
1110
|
+
}
|
|
1111
|
+
});
|
|
1112
|
+
if (!response.ok || !response.body)
|
|
1113
|
+
throw new Error(`SSE ${response.status}`);
|
|
1114
|
+
const reader = response.body.getReader();
|
|
1115
|
+
const decoder = new TextDecoder;
|
|
1116
|
+
for (;; ) {
|
|
1117
|
+
const { done, value } = await reader.read();
|
|
1118
|
+
if (done)
|
|
1119
|
+
break;
|
|
1120
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
1121
|
+
if (relevant.test(chunk)) {
|
|
1122
|
+
await render();
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
} catch {
|
|
1126
|
+
await render();
|
|
1127
|
+
await new Promise((resolveSleep) => setTimeout(resolveSleep, 2000));
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
async function executeInbox(context, args) {
|
|
1132
|
+
const [command = "approvals", ...rest] = args;
|
|
1133
|
+
switch (command) {
|
|
1134
|
+
case "approvals": {
|
|
1135
|
+
let pending = rest;
|
|
1136
|
+
const run = takeOption(pending, "--run");
|
|
1137
|
+
pending = run.rest;
|
|
1138
|
+
const task = takeOption(pending, "--task");
|
|
1139
|
+
pending = task.rest;
|
|
1140
|
+
requireNoExtraArgs(pending, "rig inbox approvals [--run <id>] [--task <id>]");
|
|
1141
|
+
const approvals = await withSpinner("Reading approvals from server\u2026", () => listInboxRecords(context, "approvals", { run: run.value, task: task.value }), { outputMode: context.outputMode });
|
|
1142
|
+
renderList(context, "approvals", approvals);
|
|
1143
|
+
return { ok: true, group: "inbox", command, details: { approvals } };
|
|
1144
|
+
}
|
|
1145
|
+
case "inputs": {
|
|
1146
|
+
let pending = rest;
|
|
1147
|
+
const run = takeOption(pending, "--run");
|
|
1148
|
+
pending = run.rest;
|
|
1149
|
+
const task = takeOption(pending, "--task");
|
|
1150
|
+
pending = task.rest;
|
|
1151
|
+
requireNoExtraArgs(pending, "rig inbox inputs [--run <id>] [--task <id>]");
|
|
1152
|
+
const requests = await withSpinner("Reading input requests from server\u2026", () => listInboxRecords(context, "inputs", { run: run.value, task: task.value }), { outputMode: context.outputMode });
|
|
1153
|
+
renderList(context, "inputs", requests);
|
|
1154
|
+
return { ok: true, group: "inbox", command, details: { requests } };
|
|
1155
|
+
}
|
|
1156
|
+
case "approve": {
|
|
1157
|
+
let pending = rest;
|
|
1158
|
+
const run = takeOption(pending, "--run");
|
|
1159
|
+
pending = run.rest;
|
|
1160
|
+
const request = takeOption(pending, "--request");
|
|
1161
|
+
pending = request.rest;
|
|
1162
|
+
const decision = takeOption(pending, "--decision");
|
|
1163
|
+
pending = decision.rest;
|
|
1164
|
+
const note = takeOption(pending, "--note");
|
|
1165
|
+
pending = note.rest;
|
|
1166
|
+
requireNoExtraArgs(pending, "rig inbox approve --run <id> --request <id> --decision approve|reject [--note <text>]");
|
|
1167
|
+
if (!run.value || !request.value || !decision.value) {
|
|
1168
|
+
throw new CliError("approve requires --run, --request, and --decision. List pending requests with `rig inbox approvals`.");
|
|
1169
|
+
}
|
|
1170
|
+
if (decision.value !== "approve" && decision.value !== "reject") {
|
|
1171
|
+
throw new CliError("decision must be approve or reject.", 1, { hint: "Re-run as `rig inbox approve --run <id> --request <id> --decision approve|reject`." });
|
|
1172
|
+
}
|
|
1173
|
+
const result = await withSpinner(`Resolving approval ${request.value}\u2026`, () => requestServerJson(context, "/api/inbox/approvals/resolve", {
|
|
1174
|
+
method: "POST",
|
|
1175
|
+
headers: { "content-type": "application/json" },
|
|
1176
|
+
body: JSON.stringify({
|
|
1177
|
+
runId: run.value,
|
|
1178
|
+
requestId: request.value,
|
|
1179
|
+
decision: decision.value,
|
|
1180
|
+
note: note.value ?? null
|
|
1181
|
+
})
|
|
1182
|
+
}), { outputMode: context.outputMode });
|
|
1183
|
+
return { ok: true, group: "inbox", command, details: { result } };
|
|
1184
|
+
}
|
|
1185
|
+
case "respond": {
|
|
1186
|
+
let pending = rest;
|
|
1187
|
+
const run = takeOption(pending, "--run");
|
|
1188
|
+
pending = run.rest;
|
|
1189
|
+
const request = takeOption(pending, "--request");
|
|
1190
|
+
pending = request.rest;
|
|
1191
|
+
const answers = [];
|
|
1192
|
+
const remaining = [];
|
|
1193
|
+
for (let index = 0;index < pending.length; index += 1) {
|
|
1194
|
+
const current = pending[index];
|
|
1195
|
+
if (current === "--answer") {
|
|
1196
|
+
const next = pending[index + 1];
|
|
1197
|
+
if (!next || next.startsWith("-")) {
|
|
1198
|
+
throw new CliError("Missing value for --answer", 1, { hint: "Pass key=value pairs, e.g. `rig inbox respond --run <id> --request <id> --answer key=value`." });
|
|
1199
|
+
}
|
|
1200
|
+
answers.push(next);
|
|
1201
|
+
index += 1;
|
|
1202
|
+
continue;
|
|
1203
|
+
}
|
|
1204
|
+
if (current !== undefined) {
|
|
1205
|
+
remaining.push(current);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
requireNoExtraArgs(remaining, "rig inbox respond --run <id> --request <id> --answer key=value [--answer key=value]");
|
|
1209
|
+
if (!run.value || !request.value || answers.length === 0) {
|
|
1210
|
+
throw new CliError("respond requires --run, --request, and at least one --answer. List pending requests with `rig inbox inputs`.");
|
|
1211
|
+
}
|
|
1212
|
+
const parsedAnswers = Object.fromEntries(answers.map((entry) => {
|
|
1213
|
+
const [key, ...restValue] = entry.split("=");
|
|
1214
|
+
return [key, restValue.join("=")];
|
|
1215
|
+
}));
|
|
1216
|
+
const result = await withSpinner(`Sending response for ${request.value}\u2026`, () => requestServerJson(context, "/api/inbox/inputs/respond", {
|
|
1217
|
+
method: "POST",
|
|
1218
|
+
headers: { "content-type": "application/json" },
|
|
1219
|
+
body: JSON.stringify({
|
|
1220
|
+
runId: run.value,
|
|
1221
|
+
requestId: request.value,
|
|
1222
|
+
answers: parsedAnswers
|
|
1223
|
+
})
|
|
1224
|
+
}), { outputMode: context.outputMode });
|
|
1225
|
+
return { ok: true, group: "inbox", command, details: { result } };
|
|
1226
|
+
}
|
|
1227
|
+
case "watch": {
|
|
1228
|
+
let pending = rest;
|
|
1229
|
+
const run = takeOption(pending, "--run");
|
|
1230
|
+
pending = run.rest;
|
|
1231
|
+
const task = takeOption(pending, "--task");
|
|
1232
|
+
pending = task.rest;
|
|
1233
|
+
requireNoExtraArgs(pending, "rig inbox watch [--run <id>] [--task <id>]");
|
|
1234
|
+
return await watchInbox(context, { run: run.value, task: task.value });
|
|
1235
|
+
}
|
|
1236
|
+
default:
|
|
1237
|
+
throw new CliError(`Unknown inbox command: ${command}. Use approvals|inputs|approve|respond|watch.`);
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
var init_inbox = __esm(() => {
|
|
1241
|
+
init_runner();
|
|
1242
|
+
init__cli_format();
|
|
1243
|
+
init__server_client();
|
|
1244
|
+
init__async_ui();
|
|
1245
|
+
});
|
|
1246
|
+
|
|
1247
|
+
// packages/cli/src/app-opentui/adapters/common.ts
|
|
1248
|
+
function adapterContextFromRuntime(runtime, renderer) {
|
|
1249
|
+
return {
|
|
1250
|
+
projectRoot: runtime.getState().projectRoot,
|
|
1251
|
+
renderer,
|
|
1252
|
+
ensureRuntime: () => runtime.getRunnerContext(),
|
|
1253
|
+
emit: (event) => runtime.emit(event),
|
|
1254
|
+
getState: () => runtime.getState()
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
function projectRootOf(ctx) {
|
|
1258
|
+
const root = ctx.rig?.projectRoot ?? ctx.projectRoot ?? ctx.getState().projectRoot;
|
|
1259
|
+
if (typeof root === "string" && root.trim())
|
|
1260
|
+
return root;
|
|
1261
|
+
throw new Error("Rig app adapter requires a projectRoot.");
|
|
1262
|
+
}
|
|
1263
|
+
function normalizeAppError(error) {
|
|
1264
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1265
|
+
const rawHint = error instanceof Error ? error.hint : undefined;
|
|
1266
|
+
return {
|
|
1267
|
+
message,
|
|
1268
|
+
...typeof rawHint === "string" && rawHint.trim() ? { hint: rawHint.trim() } : {}
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
function emitStarted(ctx, label, optimistic) {
|
|
1272
|
+
ctx.emit({ type: "action.started", label, ...optimistic ? { optimistic } : {} });
|
|
1273
|
+
}
|
|
1274
|
+
function emitProgress(ctx, label, detail, data) {
|
|
1275
|
+
ctx.emit({ type: "action.progress", label, ...detail ? { detail } : {}, ...data ? { data } : {} });
|
|
1276
|
+
}
|
|
1277
|
+
function emitCompleted(ctx, label, data) {
|
|
1278
|
+
ctx.emit({ type: "action.completed", label, ...data ? { data } : {} });
|
|
1279
|
+
}
|
|
1280
|
+
function emitFailed(ctx, label, error, data) {
|
|
1281
|
+
if (data)
|
|
1282
|
+
patchData(ctx, data);
|
|
1283
|
+
const normalized = normalizeAppError(error);
|
|
1284
|
+
ctx.emit({
|
|
1285
|
+
type: "action.failed",
|
|
1286
|
+
label,
|
|
1287
|
+
message: normalized.message,
|
|
1288
|
+
...normalized.hint ? { hint: normalized.hint } : {},
|
|
1289
|
+
cause: error
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
function patchData(ctx, data) {
|
|
1293
|
+
ctx.emit({ type: "data.patch", data });
|
|
1294
|
+
}
|
|
1295
|
+
function patchFooter(ctx, footer) {
|
|
1296
|
+
ctx.emit({ type: "footer.patch", footer });
|
|
1297
|
+
}
|
|
1298
|
+
function stringField(record, keys, fallback = "") {
|
|
1299
|
+
for (const key of keys) {
|
|
1300
|
+
const value = record[key];
|
|
1301
|
+
if (typeof value === "string" && value.trim())
|
|
1302
|
+
return value.trim();
|
|
1303
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
1304
|
+
return String(value);
|
|
1305
|
+
}
|
|
1306
|
+
return fallback;
|
|
1307
|
+
}
|
|
1308
|
+
function payloadString(intent, key) {
|
|
1309
|
+
const value = intent.action.payload?.[key];
|
|
1310
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
// packages/cli/src/app-opentui/adapters/inbox.ts
|
|
1314
|
+
function createInboxAdapter() {
|
|
1315
|
+
return {
|
|
1316
|
+
id: "inbox",
|
|
1317
|
+
async handleIntent(runtime, intent) {
|
|
1318
|
+
if (intent.scene !== "inbox" && !intent.action.kind.startsWith("inbox-"))
|
|
1319
|
+
return false;
|
|
1320
|
+
const ctx = adapterContextFromRuntime(runtime);
|
|
1321
|
+
if (intent.action.kind === "inbox-approve" || intent.action.kind === "inbox-reject") {
|
|
1322
|
+
const requestId = payloadString(intent, "requestId");
|
|
1323
|
+
let match = requestId ? findInboxRecord(ctx, "approvals", requestId) : null;
|
|
1324
|
+
if (requestId && !match)
|
|
1325
|
+
match = findInRecords((await refreshInbox(ctx)).approvals, requestId);
|
|
1326
|
+
if (requestId && match) {
|
|
1327
|
+
await resolveApproval(ctx, { runId: match.runId, requestId: match.requestId, decision: intent.action.kind === "inbox-approve" ? "approve" : "reject" });
|
|
1328
|
+
return true;
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
if (intent.action.kind === "inbox-answer") {
|
|
1332
|
+
const requestId = payloadString(intent, "requestId");
|
|
1333
|
+
let match = requestId ? findInboxRecord(ctx, "inputs", requestId) : null;
|
|
1334
|
+
if (requestId && !match)
|
|
1335
|
+
match = findInRecords((await refreshInbox(ctx)).inputs, requestId);
|
|
1336
|
+
const answer = payloadString(intent, "answer");
|
|
1337
|
+
if (requestId && match && answer) {
|
|
1338
|
+
await answerInputRequest(ctx, { runId: match.runId, requestId: match.requestId, answers: { answer } });
|
|
1339
|
+
return true;
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
await refreshInbox(ctx);
|
|
1343
|
+
return true;
|
|
1344
|
+
}
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
function findInRecords(records, requestId) {
|
|
1348
|
+
return records.find((record) => record.requestId === requestId || record.requestId.startsWith(requestId)) ?? null;
|
|
1349
|
+
}
|
|
1350
|
+
function findInboxRecord(ctx, kind, requestId) {
|
|
1351
|
+
const inbox = ctx.getState().data?.inbox;
|
|
1352
|
+
if (!inbox || typeof inbox !== "object" || Array.isArray(inbox))
|
|
1353
|
+
return null;
|
|
1354
|
+
const records = inbox[kind];
|
|
1355
|
+
if (!Array.isArray(records))
|
|
1356
|
+
return null;
|
|
1357
|
+
return findInRecords(records, requestId);
|
|
1358
|
+
}
|
|
1359
|
+
function normalizeInboxRecord(kind, record) {
|
|
1360
|
+
const runId = stringField(record, ["runId"]);
|
|
1361
|
+
const requestId = stringField(record, ["requestId", "id"]);
|
|
1362
|
+
if (!runId || !requestId)
|
|
1363
|
+
return null;
|
|
1364
|
+
const taskId = stringField(record, ["taskId"]);
|
|
1365
|
+
const nested = record.record && typeof record.record === "object" && !Array.isArray(record.record) ? record.record : {};
|
|
1366
|
+
return {
|
|
1367
|
+
kind,
|
|
1368
|
+
runId,
|
|
1369
|
+
requestId,
|
|
1370
|
+
status: stringField(record, ["status"], "pending"),
|
|
1371
|
+
title: stringField(nested, ["title", "prompt", "message", "toolName"], kind === "approvals" ? "approval request" : "input request"),
|
|
1372
|
+
raw: record,
|
|
1373
|
+
...taskId ? { taskId } : {}
|
|
1374
|
+
};
|
|
1375
|
+
}
|
|
1376
|
+
async function refreshInbox(ctx, filters = {}) {
|
|
1377
|
+
const label = "Loading inbox";
|
|
1378
|
+
emitStarted(ctx, label);
|
|
1379
|
+
try {
|
|
1380
|
+
const { listInboxRecords: listInboxRecords2 } = await Promise.resolve().then(() => (init_inbox(), exports_inbox));
|
|
1381
|
+
const context = { projectRoot: projectRootOf(ctx) };
|
|
1382
|
+
emitProgress(ctx, label, "reading approvals and input requests");
|
|
1383
|
+
const [approvalsRaw, inputsRaw] = await Promise.all([
|
|
1384
|
+
listInboxRecords2(context, "approvals", { run: filters.run, task: filters.task, pendingOnly: filters.pendingOnly ?? true }),
|
|
1385
|
+
listInboxRecords2(context, "inputs", { run: filters.run, task: filters.task, pendingOnly: filters.pendingOnly ?? true })
|
|
1386
|
+
]);
|
|
1387
|
+
const approvals = approvalsRaw.flatMap((entry) => {
|
|
1388
|
+
const normalized = normalizeInboxRecord("approvals", entry);
|
|
1389
|
+
return normalized ? [normalized] : [];
|
|
1390
|
+
});
|
|
1391
|
+
const inputs = inputsRaw.flatMap((entry) => {
|
|
1392
|
+
const normalized = normalizeInboxRecord("inputs", entry);
|
|
1393
|
+
return normalized ? [normalized] : [];
|
|
1394
|
+
});
|
|
1395
|
+
patchData(ctx, { inbox: { approvals, inputs, refreshedAt: new Date().toISOString() } });
|
|
1396
|
+
patchFooter(ctx, { inbox: `${approvals.length + inputs.length} pending` });
|
|
1397
|
+
emitCompleted(ctx, label, { approvals: approvals.length, inputs: inputs.length });
|
|
1398
|
+
return { approvals, inputs };
|
|
1399
|
+
} catch (error) {
|
|
1400
|
+
emitFailed(ctx, label, error);
|
|
1401
|
+
throw error;
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
async function resolveApproval(ctx, input) {
|
|
1405
|
+
const label = `${input.decision === "approve" ? "Approving" : "Rejecting"} ${input.requestId}`;
|
|
1406
|
+
emitStarted(ctx, label, {
|
|
1407
|
+
inboxPatch: { kind: "approvals", runId: input.runId, requestId: input.requestId, status: input.decision === "approve" ? "approving" : "rejecting" }
|
|
1408
|
+
});
|
|
1409
|
+
patchData(ctx, { inboxOptimistic: { kind: "approvals", ...input, status: input.decision === "approve" ? "approving" : "rejecting" } });
|
|
1410
|
+
try {
|
|
1411
|
+
const { requestServerJson: requestServerJson2 } = await Promise.resolve().then(() => (init__server_client(), exports__server_client));
|
|
1412
|
+
const result = await requestServerJson2({ projectRoot: projectRootOf(ctx) }, "/api/inbox/approvals/resolve", {
|
|
1413
|
+
method: "POST",
|
|
1414
|
+
headers: { "content-type": "application/json" },
|
|
1415
|
+
body: JSON.stringify({ runId: input.runId, requestId: input.requestId, decision: input.decision, note: input.note ?? null })
|
|
1416
|
+
});
|
|
1417
|
+
const record = result && typeof result === "object" && !Array.isArray(result) ? result : { ok: true };
|
|
1418
|
+
emitCompleted(ctx, label, { runId: input.runId, requestId: input.requestId, decision: input.decision, result: record });
|
|
1419
|
+
await refreshInbox(ctx).catch(() => ({ approvals: [], inputs: [] }));
|
|
1420
|
+
return record;
|
|
1421
|
+
} catch (error) {
|
|
1422
|
+
emitFailed(ctx, label, error, { runId: input.runId, requestId: input.requestId, revert: { status: "pending" } });
|
|
1423
|
+
throw error;
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
async function answerInputRequest(ctx, input) {
|
|
1427
|
+
const label = `Answering ${input.requestId}`;
|
|
1428
|
+
emitStarted(ctx, label, {
|
|
1429
|
+
inboxPatch: { kind: "inputs", runId: input.runId, requestId: input.requestId, status: "answering" }
|
|
1430
|
+
});
|
|
1431
|
+
patchData(ctx, { inboxOptimistic: { kind: "inputs", ...input, status: "answering" } });
|
|
1432
|
+
try {
|
|
1433
|
+
const { requestServerJson: requestServerJson2 } = await Promise.resolve().then(() => (init__server_client(), exports__server_client));
|
|
1434
|
+
const result = await requestServerJson2({ projectRoot: projectRootOf(ctx) }, "/api/inbox/inputs/respond", {
|
|
1435
|
+
method: "POST",
|
|
1436
|
+
headers: { "content-type": "application/json" },
|
|
1437
|
+
body: JSON.stringify({ runId: input.runId, requestId: input.requestId, answers: input.answers })
|
|
1438
|
+
});
|
|
1439
|
+
const record = result && typeof result === "object" && !Array.isArray(result) ? result : { ok: true };
|
|
1440
|
+
emitCompleted(ctx, label, { runId: input.runId, requestId: input.requestId, result: record });
|
|
1441
|
+
await refreshInbox(ctx).catch(() => ({ approvals: [], inputs: [] }));
|
|
1442
|
+
return record;
|
|
1443
|
+
} catch (error) {
|
|
1444
|
+
emitFailed(ctx, label, error, { runId: input.runId, requestId: input.requestId, revert: { status: "pending" } });
|
|
1445
|
+
throw error;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
export {
|
|
1449
|
+
resolveApproval,
|
|
1450
|
+
refreshInbox,
|
|
1451
|
+
normalizeInboxRecord,
|
|
1452
|
+
createInboxAdapter,
|
|
1453
|
+
answerInputRequest
|
|
1454
|
+
};
|