@h-rig/cli 0.0.6-alpha.3 → 0.0.6-alpha.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/bin/rig.js +3606 -1172
  2. package/dist/src/commands/_authority-runs.js +1 -0
  3. package/dist/src/commands/_cli-format.js +369 -0
  4. package/dist/src/commands/_connection-state.js +1 -3
  5. package/dist/src/commands/_doctor-checks.js +13 -27
  6. package/dist/src/commands/_help-catalog.js +388 -0
  7. package/dist/src/commands/_operator-surface.js +204 -0
  8. package/dist/src/commands/_operator-view.js +861 -56
  9. package/dist/src/commands/_parsers.js +0 -2
  10. package/dist/src/commands/_pi-frontend.js +841 -0
  11. package/dist/src/commands/_pi-install.js +4 -3
  12. package/dist/src/commands/_pi-worker-bridge-extension.js +759 -0
  13. package/dist/src/commands/_policy.js +0 -2
  14. package/dist/src/commands/_preflight.js +32 -109
  15. package/dist/src/commands/_run-driver-helpers.js +0 -2
  16. package/dist/src/commands/_server-client.js +161 -31
  17. package/dist/src/commands/_snapshot-upload.js +8 -23
  18. package/dist/src/commands/_task-picker.js +44 -16
  19. package/dist/src/commands/agent.js +9 -9
  20. package/dist/src/commands/browser.js +4 -6
  21. package/dist/src/commands/connect.js +132 -25
  22. package/dist/src/commands/dist.js +4 -6
  23. package/dist/src/commands/doctor.js +13 -27
  24. package/dist/src/commands/github.js +10 -25
  25. package/dist/src/commands/inbox.js +351 -31
  26. package/dist/src/commands/init.js +298 -71
  27. package/dist/src/commands/inspect.js +10 -12
  28. package/dist/src/commands/inspector.js +2 -4
  29. package/dist/src/commands/plugin.js +76 -22
  30. package/dist/src/commands/profile-and-review.js +8 -10
  31. package/dist/src/commands/queue.js +2 -3
  32. package/dist/src/commands/remote.js +18 -20
  33. package/dist/src/commands/repo-git-harness.js +6 -8
  34. package/dist/src/commands/run.js +1157 -122
  35. package/dist/src/commands/server.js +217 -33
  36. package/dist/src/commands/setup.js +17 -37
  37. package/dist/src/commands/task-report-bug.js +5 -7
  38. package/dist/src/commands/task-run-driver.js +660 -73
  39. package/dist/src/commands/task.js +1542 -252
  40. package/dist/src/commands/test.js +3 -5
  41. package/dist/src/commands/workspace.js +4 -6
  42. package/dist/src/commands.js +3599 -1159
  43. package/dist/src/index.js +3646 -1215
  44. package/dist/src/launcher.js +5 -3
  45. package/dist/src/report-bug.js +3 -3
  46. package/dist/src/runner.js +5 -19
  47. package/package.json +6 -4
@@ -0,0 +1,388 @@
1
+ // @bun
2
+ // packages/cli/src/commands/_help-catalog.ts
3
+ import { intro, log, note, outro } from "@clack/prompts";
4
+ import pc from "picocolors";
5
+ var TOP_LEVEL_SECTIONS = [
6
+ {
7
+ title: "Server",
8
+ subtitle: "choose the local or remote Rig server that owns this repo",
9
+ commands: [
10
+ { command: "rig server status", description: "Show the selected local/remote server for this repo." },
11
+ { command: "rig server use local", description: "Switch this repo back to the local Rig server." },
12
+ { command: "rig server add <alias> <url>", description: "Save a remote Rig server alias." },
13
+ { command: "rig server use <alias>", description: "Switch this repo to a saved remote server." },
14
+ { command: "rig server list", description: "Show saved server aliases, including local." }
15
+ ]
16
+ },
17
+ {
18
+ title: "Tasks",
19
+ subtitle: "find work, inspect it, and submit Pi-backed workers",
20
+ commands: [
21
+ { command: "rig task list", description: "List tasks from the selected task source/server." },
22
+ { command: "rig task next", description: "Show the next matching task as a selected-task card." },
23
+ { command: "rig task show <id>", description: "Show a human task summary; add --raw or --json for the full payload." },
24
+ { command: "rig task run <id|--next> [--detach]", description: "Submit a task run; interactive mode follows with bundled Pi." }
25
+ ]
26
+ },
27
+ {
28
+ title: "Runs",
29
+ subtitle: "observe, attach to, and stop live or recent runs",
30
+ commands: [
31
+ { command: "rig run list", description: "List recent runs from the selected server or local state." },
32
+ { command: "rig run show <id>", description: "Show a human run summary; add --raw or --json for the full payload." },
33
+ { command: "rig run attach <id> --follow", description: "Open the native bundled Pi live view for a worker run." },
34
+ { command: "rig run stop <id>", description: "Request cancellation for a running worker." }
35
+ ]
36
+ },
37
+ {
38
+ title: "Review / inbox",
39
+ subtitle: "clear blocked runs and configure completion review",
40
+ commands: [
41
+ { command: "rig inbox approvals", description: "List pending approval requests from local/server run state." },
42
+ { command: "rig inbox inputs", description: "List pending user-input requests from local/server run state." },
43
+ { command: "rig review show|set", description: "Inspect or change the review gate policy." }
44
+ ]
45
+ },
46
+ {
47
+ title: "Health / setup",
48
+ subtitle: "bootstrap and diagnose the repo/server/GitHub/Pi path",
49
+ commands: [
50
+ { command: "rig init", description: "Interactive setup: config, GitHub auth, task source, server, checkout, Pi." },
51
+ { command: "rig doctor", description: "Diagnose project/server/GitHub/task/Pi wiring." },
52
+ { command: "rig github auth status", description: "Show GitHub auth state on the selected Rig server." }
53
+ ]
54
+ }
55
+ ];
56
+ var PRIMARY_GROUPS = [
57
+ {
58
+ name: "server",
59
+ summary: "Choose, inspect, and start the Rig server that owns tasks and runs.",
60
+ usage: ["rig server <status|list|add|use|start> [options]"],
61
+ commands: [
62
+ { command: "status", description: "Show the selected server for this repo.", primary: true },
63
+ { command: "use local", description: "Switch this repo to the local Rig server.", primary: true },
64
+ { command: "add <alias> <url>", description: "Save a remote Rig server URL.", primary: true },
65
+ { command: "use <alias>", description: "Select a saved remote server alias.", primary: true },
66
+ { command: "list", description: "List saved local/remote server aliases.", primary: true },
67
+ { command: "start [--host <host>] [--port <n>]", description: "Start a local rig-server process." }
68
+ ],
69
+ examples: [
70
+ "rig server status",
71
+ "rig server add prod https://where.rig-does.work",
72
+ "rig server use prod",
73
+ "rig server use local",
74
+ "rig server start --port 3773"
75
+ ],
76
+ next: ["Use `rig task list` to see server-owned work.", "Use `rig run list` or `rig run attach <id> --follow` to monitor runs."],
77
+ advanced: ["Compatibility alias: `rig connect ...` remains callable."]
78
+ },
79
+ {
80
+ name: "task",
81
+ summary: "Find work, start Pi-backed runs, and validate task results.",
82
+ usage: ["rig task <list|next|show|run> [options]"],
83
+ commands: [
84
+ { command: "list [--assignee <login|@me>] [--state open|closed]", description: "List tasks from the selected server/source.", primary: true },
85
+ { command: "next [filters]", description: "Render the next matching task as a selected-task card.", primary: true },
86
+ { command: "show <id>|--task <id> [--raw]", description: "Show a human task summary; --raw prints the full payload.", primary: true },
87
+ { command: "run [#<issue>|<task-id>|--next|--task <id>]", description: "Submit a task run; interactive follows with bundled Pi.", primary: true },
88
+ { command: "validate|verify [--task <id>]", description: "Run configured task checks/review gates." },
89
+ { command: "details --task <id>", description: "Show full task info from the configured source." },
90
+ { command: "reopen [--task <id> | --all] [--reason <text>]", description: "Reopen closed task(s) in the configured source." },
91
+ { command: "reset --task <id>", description: "Compatibility spelling of `reopen --task <id>`." },
92
+ { command: "artifacts|artifact-dir|artifact-write", description: "Inspect or write task artifacts." },
93
+ { command: "report-bug", description: "Create a structured bug report/task." }
94
+ ],
95
+ examples: [
96
+ "rig task list --assignee @me --limit 20",
97
+ "rig task next",
98
+ "rig task show 123 --raw",
99
+ "rig task run --next",
100
+ "rig task run #123 --runtime-adapter pi",
101
+ "rig task run --title 'Investigate deploy drift' --initial-prompt 'Check server health'"
102
+ ],
103
+ next: ["Use `--detach` to submit without attaching.", "Use `rig run attach <run-id> --follow` to rejoin a live run."]
104
+ },
105
+ {
106
+ name: "run",
107
+ summary: "Observe, attach to, and control Rig runs.",
108
+ usage: ["rig run <list|status|show|attach|stop> [options]"],
109
+ commands: [
110
+ { command: "list", description: "List recent runs from the selected server or local state.", primary: true },
111
+ { command: "status", description: "Render active and recent run groups.", primary: true },
112
+ { command: "show <id>|--run <id> [--raw]", description: "Show a human run summary; --raw prints the full payload.", primary: true },
113
+ { command: "attach <run-id>|--run <id> [--follow]", description: "Attach to the run; --follow launches native bundled Pi for live Pi runs.", primary: true },
114
+ { command: "stop [<run-id>|--run <id>]", description: "Request stop for one run or local active runs.", primary: true },
115
+ { command: "timeline --run <id> [--follow]", description: "Stream raw run timeline events." },
116
+ { command: "resume", description: "Resume the most recent interrupted local run." },
117
+ { command: "restart", description: "Restart the most recent local run from a clean runtime." },
118
+ { command: "delete|cleanup", description: "Remove completed run records/artifacts." }
119
+ ],
120
+ examples: [
121
+ "rig run list",
122
+ "rig run status",
123
+ "rig run show <run-id>",
124
+ "rig run attach <run-id> --follow",
125
+ "rig run stop <run-id>"
126
+ ],
127
+ next: ["Use `rig task run --next` to create a new run.", "Use `--json` when scripts need the full structured record."]
128
+ },
129
+ {
130
+ name: "inbox",
131
+ summary: "Review approval and user-input requests that block worker runs.",
132
+ usage: ["rig inbox <approvals|approve|inputs|respond> [options]"],
133
+ commands: [
134
+ { command: "approvals [--run <id>] [--task <id>]", description: "List pending approvals.", primary: true },
135
+ { command: "inputs [--run <id>] [--task <id>]", description: "List pending user-input requests.", primary: true },
136
+ { command: "approve --run <id> --request <id> --decision approve|reject", description: "Resolve an approval request." },
137
+ { command: "respond --run <id> --request <id> --answer key=value", description: "Answer a user-input request." }
138
+ ],
139
+ examples: [
140
+ "rig inbox approvals",
141
+ "rig inbox inputs --run <run-id>",
142
+ "rig inbox approve --run <run-id> --request <request-id> --decision approve"
143
+ ],
144
+ next: ["Rejoin the run after resolving a block: `rig run attach <run-id> --follow`."]
145
+ },
146
+ {
147
+ name: "review",
148
+ summary: "Inspect or change completion review gate policy.",
149
+ usage: ["rig review <show|set>"],
150
+ commands: [
151
+ { command: "show", description: "Show current review gate settings.", primary: true },
152
+ { command: "set <off|advisory|required> [--provider greptile]", description: "Change review strictness/provider.", primary: true }
153
+ ],
154
+ examples: ["rig review show", "rig review set required --provider greptile"],
155
+ next: ["Use `rig inbox approvals` for blocked run handoffs."]
156
+ },
157
+ {
158
+ name: "init",
159
+ summary: "Set up Rig for this repo: server, GitHub auth, checkout strategy, task source, and Pi wiring.",
160
+ usage: ["rig init [--yes] [--server local|remote] [--repo owner/repo] [--remote-url <url>]"],
161
+ commands: [
162
+ { command: "init", description: "Interactive setup wizard for a new or existing Rig repo.", primary: true },
163
+ { command: "init --yes", description: "Non-interactive setup using detected/default settings.", primary: true },
164
+ { command: "init --server remote --remote-url <url>", description: "Link this repo to a remote Rig server.", primary: true },
165
+ { command: "init --repair", description: "Repair missing private state without replacing project config." }
166
+ ],
167
+ examples: [
168
+ "rig init",
169
+ "rig init --yes --repo humanity-org/humanwork",
170
+ "rig init --server remote --remote-url https://where.rig-does.work --repo owner/repo"
171
+ ],
172
+ next: ["After init, run `rig server status`.", "Then use `rig task list` and `rig task run --next` for day-to-day work."]
173
+ },
174
+ {
175
+ name: "doctor",
176
+ summary: "Diagnostics for project/server/GitHub/Pi state.",
177
+ usage: ["rig doctor"],
178
+ commands: [
179
+ { command: "doctor", description: "Run setup and runtime diagnostics.", primary: true },
180
+ { command: "check", description: "Compatibility spelling for diagnostics." }
181
+ ],
182
+ examples: ["rig doctor", "rig doctor --json"],
183
+ next: ["Use `rig server status` and `rig github auth status` to inspect common failure points."]
184
+ },
185
+ {
186
+ name: "github",
187
+ summary: "GitHub auth helpers for the selected Rig server.",
188
+ usage: ["rig github auth <status|import-gh|token>"],
189
+ commands: [
190
+ { command: "auth status", description: "Show GitHub auth state.", primary: true },
191
+ { command: "auth import-gh", description: "Import the current `gh` token into the selected server." },
192
+ { command: "auth token --token <token>", description: "Store a token on the selected server." }
193
+ ],
194
+ examples: ["rig github auth status", "rig github auth import-gh"],
195
+ next: ["After auth is valid, use `rig task run --next`."]
196
+ }
197
+ ];
198
+ var ADVANCED_GROUPS = [
199
+ { name: "connect", summary: "Compatibility alias for `rig server` selection commands.", usage: ["rig connect <status|list|add|use>"], commands: [{ command: "status|list|add|use", description: "Use `rig server ...` for the primary UX." }] },
200
+ { name: "setup", summary: "Bootstrap/check local setup.", usage: ["rig setup <bootstrap|check|preflight>"], commands: [{ command: "bootstrap|check|preflight", description: "Setup helpers." }] },
201
+ { name: "inspect", summary: "Inspect logs, artifacts, graphs, failures.", usage: ["rig inspect <logs|artifacts|failures|graph|audit|diff>"], commands: [{ command: "logs --task <id>", description: "Inspect task logs." }] },
202
+ { name: "repo", summary: "Repository sync/baseline helpers.", usage: ["rig repo <sync|reset-baseline>"], commands: [{ command: "sync", description: "Sync project repository state." }] },
203
+ { name: "profile", summary: "Runtime profile/model defaults.", usage: ["rig profile <show|set>"], commands: [{ command: "show", description: "Show active profile." }] },
204
+ {
205
+ name: "browser",
206
+ summary: "Browser/app diagnostics for browser-required tasks.",
207
+ usage: ["rig browser <help|explain|demo|app|hp-next> [options]"],
208
+ commands: [
209
+ { command: "help", description: "Rich browser command help (canonical: `rig browser help`)." },
210
+ { command: "explain", description: "Explain the browser-required task contract." },
211
+ { command: "demo", description: "Run browser demo flows against a local page." },
212
+ { command: "app", description: "Launch the Rig Browser workstation app." },
213
+ { command: "hp-next <dev|check|e2e|reset>", description: "Drive the hp-next browser test harness." }
214
+ ]
215
+ },
216
+ {
217
+ name: "plugin",
218
+ summary: "Plugin listing, validation, and plugin-contributed commands.",
219
+ usage: ["rig plugin <list|validate|run> [options]"],
220
+ commands: [
221
+ { command: "list", description: "List plugins declared in rig.config.ts and their contributions." },
222
+ { command: "validate --task <id>", description: "Run plugin-contributed validators for a task." },
223
+ { command: "run <command-id> [args...]", description: "Execute a plugin-contributed CLI command (also callable as `rig <command-id>`)." }
224
+ ]
225
+ },
226
+ { name: "queue", summary: "Run task queues locally.", usage: ["rig queue run [options]"], commands: [{ command: "run", description: "Process queue work." }] },
227
+ { name: "agent", summary: "Runtime agent workspace helpers.", usage: ["rig agent <list|prepare|run|cleanup>"], commands: [{ command: "list", description: "List prepared agents." }] },
228
+ { name: "inspector", summary: "Event stream and drift scanners.", usage: ["rig inspector <stream|scan-upstream-drift>"], commands: [{ command: "stream", description: "Stream events." }] },
229
+ { name: "dist", summary: "Build/install packaged Rig CLI.", usage: ["rig dist <build|install|doctor>"], commands: [{ command: "build", description: "Build distribution." }] },
230
+ { name: "workspace", summary: "Workspace topology/service helpers.", usage: ["rig workspace <summary|topology|remote-hosts>"], commands: [{ command: "summary", description: "Show workspace summary." }] },
231
+ { name: "remote", summary: "Compatibility remote orchestration controls.", usage: ["rig remote <status|watch|pause|resume|...>"], commands: [{ command: "status", description: "Show remote state." }] },
232
+ { name: "git", summary: "Pass through to Rig git-flow helper.", usage: ["rig git <args...>"], commands: [{ command: "<args...>", description: "Advanced git flow operations." }] },
233
+ { name: "harness", summary: "Pass through to runtime harness CLI.", usage: ["rig harness <args...>"], commands: [{ command: "<args...>", description: "Advanced harness operations." }] },
234
+ { name: "test", summary: "Project test wrappers.", usage: ["rig test <unit|e2e|all>"], commands: [{ command: "all", description: "Run configured project tests." }] }
235
+ ];
236
+ var ADVANCED_COMMANDS = [
237
+ { command: "rig server task-run ...", description: "Internal server-owned task execution entry point." },
238
+ { command: "rig server notify-test [--event <type>]", description: "Internal event notification smoke command." },
239
+ { command: "rig run start|start-serial|start-parallel", description: "Compatibility local run starters; prefer `rig task run ...`." },
240
+ { command: "rig remote orchestrate-*", description: "Compatibility remote orchestration commands." }
241
+ ];
242
+ var ALL_GROUPS = [...PRIMARY_GROUPS, ...ADVANCED_GROUPS];
243
+ function heading(title) {
244
+ return pc.bold(pc.cyan(title));
245
+ }
246
+ function commandLine(command, description) {
247
+ const commandColumn = command.length >= 38 ? `${command} ` : command.padEnd(38);
248
+ return `${pc.dim("\u2502")} ${pc.bold(commandColumn)} ${description}`;
249
+ }
250
+ function renderCommandBlock(commands) {
251
+ return commands.map((entry) => commandLine(entry.command, entry.description)).join(`
252
+ `);
253
+ }
254
+ function renderGroup(group) {
255
+ const lines = [
256
+ `${heading(`rig ${group.name}`)} \u2014 ${group.summary}`,
257
+ "",
258
+ pc.bold("Usage"),
259
+ ...group.usage.map((line) => ` ${line}`),
260
+ "",
261
+ pc.bold("Commands"),
262
+ ...group.commands.map((entry) => commandLine(entry.command, entry.description))
263
+ ];
264
+ if (group.examples?.length) {
265
+ lines.push("", pc.bold("Examples"), ...group.examples.map((line) => ` ${pc.dim("$")} ${line}`));
266
+ }
267
+ if (group.next?.length) {
268
+ lines.push("", pc.bold("Next steps"), ...group.next.map((line) => ` ${pc.dim("\u203A")} ${line}`));
269
+ }
270
+ if (group.advanced?.length) {
271
+ lines.push("", pc.bold("Compatibility / advanced"), ...group.advanced.map((line) => ` ${pc.dim("\u203A")} ${line}`));
272
+ }
273
+ return lines.join(`
274
+ `);
275
+ }
276
+ function renderTopLevelHelp() {
277
+ return [
278
+ `${heading("rig")} ${pc.dim("\u2014 server-owned task/run control plane for Pi-backed engineering work")}`,
279
+ pc.dim("Current path: select a server, choose a task, submit a run, attach with native Pi, clear inbox/review gates."),
280
+ "",
281
+ ...TOP_LEVEL_SECTIONS.flatMap((section) => [
282
+ `${pc.bold(pc.magenta(`\u25C7 ${section.title}`))} \u2014 ${pc.dim(section.subtitle)}`,
283
+ renderCommandBlock(section.commands),
284
+ ""
285
+ ]),
286
+ pc.dim("More: `rig help --advanced` for dev/compatibility commands; `rig <group> --help` for rich per-group help; `rig --version` for the installed version."),
287
+ "",
288
+ pc.bold("Global options"),
289
+ commandLine("--project <path>", "Use a project root instead of auto-discovery."),
290
+ commandLine("--json", "Emit structured output for scripts/agents."),
291
+ commandLine("--dry-run", "Print the command plan without mutating state.")
292
+ ].join(`
293
+ `).trimEnd();
294
+ }
295
+ function renderAdvancedHelp() {
296
+ return [
297
+ `${heading("rig advanced")} \u2014 compatibility, diagnostics, and internal surfaces`,
298
+ "",
299
+ pc.bold("Primary groups"),
300
+ " server, task, run, inbox, review, init, doctor, github",
301
+ "",
302
+ pc.bold("Advanced commands"),
303
+ ...ADVANCED_COMMANDS.map((entry) => commandLine(entry.command, entry.description)),
304
+ "",
305
+ pc.bold("Advanced groups"),
306
+ ...ADVANCED_GROUPS.map((group) => commandLine(group.name, group.summary)),
307
+ "",
308
+ pc.dim("All groups remain callable. Prefer `rig server`, `rig task`, `rig run`, `rig inbox`, and `rig review` for day-to-day work.")
309
+ ].join(`
310
+ `);
311
+ }
312
+ function renderGroupHelp(groupName) {
313
+ const group = ALL_GROUPS.find((candidate) => candidate.name === groupName);
314
+ return group ? renderGroup(group) : null;
315
+ }
316
+ function listHelpGroups() {
317
+ return ALL_GROUPS.map((group) => group.name);
318
+ }
319
+ function shouldUseClackOutput() {
320
+ return Boolean(process.stdout.isTTY) && process.env.RIG_CLI_PLAIN_HELP !== "1";
321
+ }
322
+ function printTopLevelHelp() {
323
+ if (!shouldUseClackOutput()) {
324
+ console.log(renderTopLevelHelp());
325
+ return;
326
+ }
327
+ intro("rig");
328
+ for (const section of TOP_LEVEL_SECTIONS) {
329
+ note(renderCommandBlock(section.commands), `${section.title} \u2014 ${section.subtitle}`);
330
+ }
331
+ log.info("More: rig help --advanced \xB7 rig <group> --help \xB7 rig --version");
332
+ note([
333
+ commandLine("--project <path>", "Use a project root instead of auto-discovery."),
334
+ commandLine("--json", "Emit structured output for scripts/agents."),
335
+ commandLine("--dry-run", "Print the command plan without mutating state.")
336
+ ].join(`
337
+ `), "Global options");
338
+ outro("Server \u2192 task \u2192 run \u2192 inbox/review.");
339
+ }
340
+ function printAdvancedHelp() {
341
+ if (!shouldUseClackOutput()) {
342
+ console.log(renderAdvancedHelp());
343
+ return;
344
+ }
345
+ intro("rig advanced");
346
+ note(ADVANCED_COMMANDS.map((entry) => commandLine(entry.command, entry.description)).join(`
347
+ `), "Advanced commands");
348
+ note(ADVANCED_GROUPS.map((group) => commandLine(group.name, group.summary)).join(`
349
+ `), "Advanced groups");
350
+ outro("Primary daily flow: rig server \xB7 rig task \xB7 rig run \xB7 rig inbox \xB7 rig review.");
351
+ }
352
+ function printGroupHelpDocument(groupName) {
353
+ const rendered = renderGroupHelp(groupName) ?? renderTopLevelHelp();
354
+ if (!shouldUseClackOutput()) {
355
+ console.log(rendered);
356
+ return;
357
+ }
358
+ const group = ALL_GROUPS.find((candidate) => candidate.name === groupName);
359
+ if (!group) {
360
+ printTopLevelHelp();
361
+ return;
362
+ }
363
+ intro(`rig ${group.name}`);
364
+ note(group.summary, "Purpose");
365
+ note(group.usage.join(`
366
+ `), "Usage");
367
+ note(group.commands.map((entry) => commandLine(entry.command, entry.description)).join(`
368
+ `), "Commands");
369
+ if (group.examples?.length)
370
+ note(group.examples.map((line) => `$ ${line}`).join(`
371
+ `), "Examples");
372
+ if (group.next?.length)
373
+ note(group.next.map((line) => `\u203A ${line}`).join(`
374
+ `), "Next steps");
375
+ if (group.advanced?.length)
376
+ log.info(group.advanced.join(`
377
+ `));
378
+ outro("Run with --json when scripts need structured output.");
379
+ }
380
+ export {
381
+ renderTopLevelHelp,
382
+ renderGroupHelp,
383
+ renderAdvancedHelp,
384
+ printTopLevelHelp,
385
+ printGroupHelpDocument,
386
+ printAdvancedHelp,
387
+ listHelpGroups
388
+ };
@@ -0,0 +1,204 @@
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
+ }
128
+ }
129
+ },
130
+ renderLogs(entries) {
131
+ for (const [index, entry] of entries.entries()) {
132
+ const id = entryId(entry, `log:${index}:${String(entry.createdAt ?? "")}:${String(entry.title ?? "")}`);
133
+ if (seenLogs.has(id))
134
+ continue;
135
+ seenLogs.add(id);
136
+ const title = String(entry.title ?? "");
137
+ if (CANONICAL_STAGES.some((stage) => stage.toLowerCase() === title.toLowerCase()))
138
+ continue;
139
+ const detail = logDetail(entry);
140
+ if (!detail)
141
+ continue;
142
+ const protocolRecord = parseProviderProtocolLog(title, detail);
143
+ if (protocolRecord) {
144
+ const protocolLine = renderProviderProtocolLog(protocolRecord);
145
+ if (protocolLine)
146
+ writeLine(protocolLine);
147
+ continue;
148
+ }
149
+ writeLine(`[${title || "Rig log"}] ${detail}`);
150
+ }
151
+ }
152
+ };
153
+ }
154
+ function createOperatorSurface(options = {}) {
155
+ const input = options.input ?? process.stdin;
156
+ const output = options.output ?? process.stdout;
157
+ const errorOutput = options.errorOutput ?? process.stderr;
158
+ const renderer = createPiRunStreamRenderer(output);
159
+ const writeLine = (line) => output.write(`${line}
160
+ `);
161
+ return {
162
+ mode: "pi-compatible-text",
163
+ ...renderer,
164
+ info: writeLine,
165
+ error: (message) => errorOutput.write(`${message}
166
+ `),
167
+ attachCommandInput(handler) {
168
+ if (options.interactive === false || !input.isTTY)
169
+ return null;
170
+ const rl = createInterface({ input, output: process.stdout, terminal: false });
171
+ rl.on("line", (line) => {
172
+ Promise.resolve(handler(line)).catch((error) => writeLine(`Operator command failed: ${error instanceof Error ? error.message : String(error)}`));
173
+ });
174
+ return { close: () => rl.close() };
175
+ }
176
+ };
177
+ }
178
+ function taskId(task) {
179
+ return typeof task.id === "string" && task.id.trim() ? task.id : "<unknown>";
180
+ }
181
+ function taskTitle(task) {
182
+ return typeof task.title === "string" && task.title.trim() ? task.title : "Untitled task";
183
+ }
184
+ function taskStatus(task) {
185
+ return typeof task.status === "string" && task.status.trim() ? task.status : "unknown";
186
+ }
187
+ function renderTaskPickerRows(tasks) {
188
+ return tasks.map((task, index) => `${index + 1}. ${taskId(task)} \xB7 ${taskStatus(task)} \xB7 ${taskTitle(task)}`);
189
+ }
190
+ async function promptForTaskSelection(question) {
191
+ const rl = createPromptInterface({ input: process.stdin, output: process.stdout });
192
+ try {
193
+ return await rl.question(question);
194
+ } finally {
195
+ rl.close();
196
+ }
197
+ }
198
+ export {
199
+ renderTaskPickerRows,
200
+ renderOperatorSnapshot,
201
+ promptForTaskSelection,
202
+ createPiRunStreamRenderer,
203
+ createOperatorSurface
204
+ };