@h-rig/cli 0.0.6-alpha.7 → 0.0.6-alpha.71

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 (53) hide show
  1. package/README.md +1 -1
  2. package/dist/bin/rig.js +4507 -1506
  3. package/dist/src/commands/_async-ui.js +152 -0
  4. package/dist/src/commands/_authority-runs.js +2 -3
  5. package/dist/src/commands/_cli-format.js +369 -0
  6. package/dist/src/commands/_connection-state.js +30 -11
  7. package/dist/src/commands/_doctor-checks.js +177 -43
  8. package/dist/src/commands/_help-catalog.js +485 -0
  9. package/dist/src/commands/_json-output.js +56 -0
  10. package/dist/src/commands/_operator-surface.js +220 -0
  11. package/dist/src/commands/_operator-view.js +595 -72
  12. package/dist/src/commands/_parsers.js +18 -11
  13. package/dist/src/commands/_pi-frontend.js +411 -0
  14. package/dist/src/commands/_pi-install.js +4 -3
  15. package/dist/src/commands/_policy.js +12 -5
  16. package/dist/src/commands/_preflight.js +187 -127
  17. package/dist/src/commands/_run-driver-helpers.js +75 -22
  18. package/dist/src/commands/_run-replay.js +142 -0
  19. package/dist/src/commands/_server-client.js +343 -60
  20. package/dist/src/commands/_snapshot-upload.js +160 -38
  21. package/dist/src/commands/_spinner.js +65 -0
  22. package/dist/src/commands/_task-picker.js +44 -16
  23. package/dist/src/commands/agent.js +39 -20
  24. package/dist/src/commands/browser.js +28 -21
  25. package/dist/src/commands/connect.js +146 -33
  26. package/dist/src/commands/dist.js +19 -12
  27. package/dist/src/commands/doctor.js +304 -44
  28. package/dist/src/commands/github.js +301 -52
  29. package/dist/src/commands/inbox.js +679 -72
  30. package/dist/src/commands/init.js +622 -118
  31. package/dist/src/commands/inspect.js +515 -32
  32. package/dist/src/commands/inspector.js +20 -13
  33. package/dist/src/commands/pi.js +177 -0
  34. package/dist/src/commands/plugin.js +95 -27
  35. package/dist/src/commands/profile-and-review.js +26 -19
  36. package/dist/src/commands/queue.js +32 -12
  37. package/dist/src/commands/remote.js +43 -36
  38. package/dist/src/commands/repo-git-harness.js +22 -15
  39. package/dist/src/commands/run.js +1162 -158
  40. package/dist/src/commands/server.js +373 -56
  41. package/dist/src/commands/setup.js +316 -62
  42. package/dist/src/commands/stats.js +1030 -0
  43. package/dist/src/commands/task-report-bug.js +29 -22
  44. package/dist/src/commands/task-run-driver.js +862 -129
  45. package/dist/src/commands/task.js +1423 -311
  46. package/dist/src/commands/test.js +15 -8
  47. package/dist/src/commands/workspace.js +18 -11
  48. package/dist/src/commands.js +4446 -1499
  49. package/dist/src/index.js +4502 -1504
  50. package/dist/src/launcher.js +77 -13
  51. package/dist/src/report-bug.js +3 -3
  52. package/dist/src/runner.js +16 -22
  53. package/package.json +10 -5
@@ -0,0 +1,485 @@
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: "Start here",
8
+ subtitle: "one-time setup, pick a server",
9
+ commands: [
10
+ { command: "rig init", description: "Wizard: config, GitHub auth, task source, server, Pi wiring." },
11
+ { command: "rig server use <alias|local>", description: "Pick which Rig server owns this repo (`rig server list` to see them)." },
12
+ { command: "rig server status", description: "Show the selected server for this repo." }
13
+ ]
14
+ },
15
+ {
16
+ title: "Work",
17
+ subtitle: "find a task, put an agent on it, answer what it asks",
18
+ commands: [
19
+ { command: "rig task list", description: "What's on the board (from the selected source/server)." },
20
+ { command: "rig task run --next", description: "Dispatch an agent; interactive mode opens the native Pi session." },
21
+ { command: "rig run status", description: "Active and recent runs at a glance." },
22
+ { command: "rig run attach <id> --follow", description: "Join the live Pi session (worker keeps running if you /detach)." },
23
+ { command: "rig inbox approvals", description: "Approvals workers are waiting on (then `rig inbox approve \u2026`)." }
24
+ ]
25
+ },
26
+ {
27
+ title: "Watch",
28
+ subtitle: "fleet metrics and per-task forensics",
29
+ commands: [
30
+ { command: "rig stats [--since 7d]", description: "Fleet metrics: completion/failure rates, median run time, steering, stalls." },
31
+ { command: "rig inspect logs --task <id>", description: "Latest run log for a task." },
32
+ { command: "rig inspect diff --task <id>", description: "Changed files for a task." }
33
+ ]
34
+ },
35
+ {
36
+ title: "Unblock",
37
+ subtitle: "diagnose wiring, fix auth",
38
+ commands: [
39
+ { command: "rig doctor", description: "Check every part of the wiring \u2014 run this when anything feels off." },
40
+ { command: "rig github auth status", description: "GitHub auth state on the selected server." }
41
+ ]
42
+ },
43
+ {
44
+ title: "Extend",
45
+ subtitle: "plugins contribute validators, hooks, task sources, commands",
46
+ commands: [
47
+ { command: "rig plugin list", description: "What the rig.config.ts plugins contribute." },
48
+ { command: "rig plugin run <command-id>", description: "Execute a plugin-contributed CLI command." }
49
+ ]
50
+ }
51
+ ];
52
+ var PRIMARY_GROUPS = [
53
+ {
54
+ name: "server",
55
+ summary: "Choose, inspect, and start the Rig server that owns tasks and runs.",
56
+ usage: ["rig server <status|list|add|use|start> [options]"],
57
+ commands: [
58
+ { command: "status", description: "Show the selected server for this repo.", primary: true },
59
+ { command: "use local", description: "Switch this repo to the local Rig server.", primary: true },
60
+ { command: "add <alias> <url>", description: "Save a remote Rig server URL.", primary: true },
61
+ { command: "use <alias>", description: "Select a saved remote server alias.", primary: true },
62
+ { command: "list", description: "List saved local/remote server aliases.", primary: true },
63
+ { command: "start [--host <host>] [--port <n>]", description: "Start a local rig-server process." }
64
+ ],
65
+ examples: [
66
+ "rig server status",
67
+ "rig server add prod https://where.rig-does.work",
68
+ "rig server use prod",
69
+ "rig server use local",
70
+ "rig server start --port 3773"
71
+ ],
72
+ next: ["Use `rig task list` to see server-owned work.", "Use `rig run list` or `rig run attach <id> --follow` to monitor runs."]
73
+ },
74
+ {
75
+ name: "task",
76
+ summary: "Find work, start Pi-backed runs, and validate task results.",
77
+ usage: ["rig task <list|next|show|run> [options]"],
78
+ commands: [
79
+ { command: "list [--assignee <login|me|@me>] [--state open|closed]", description: "List tasks from the selected server/source.", primary: true },
80
+ { command: "next [filters]", description: "Render the next matching task as a selected-task card.", primary: true },
81
+ { command: "show <id>|--task <id> [--raw]", description: "Show a human task summary; --raw prints the full payload.", primary: true },
82
+ { command: "run [#<issue>|<task-id>|--next|--task <id>]", description: "Submit a task run; interactive follows with bundled Pi.", primary: true },
83
+ { command: "validate|verify [--task <id>]", description: "Run configured task checks/review gates." },
84
+ { command: "details --task <id>", description: "Show full task info from the configured source." },
85
+ { command: "reopen [--task <id> | --all] [--reason <text>]", description: "Reopen closed task(s) in the configured source." },
86
+ { command: "artifacts|artifact-dir|artifact-write", description: "Inspect or write task artifacts." },
87
+ { command: "report-bug", description: "Create a structured bug report/task." }
88
+ ],
89
+ examples: [
90
+ "rig task list --assignee @me --limit 20",
91
+ "rig task next",
92
+ "rig task show 123 --raw",
93
+ "rig task run --next",
94
+ "rig task run #123 --runtime-adapter pi",
95
+ "rig task run --title 'Investigate deploy drift' --initial-prompt 'Check server health'"
96
+ ],
97
+ next: ["Use `--detach` to submit without attaching.", "Use `rig run attach <run-id> --follow` to rejoin a live run."]
98
+ },
99
+ {
100
+ name: "run",
101
+ summary: "Observe, attach to, and control Rig runs.",
102
+ usage: ["rig run <list|status|show|attach|stop> [options]"],
103
+ commands: [
104
+ { command: "list", description: "List recent runs from the selected server or local state.", primary: true },
105
+ { command: "status", description: "Render active and recent run groups.", primary: true },
106
+ { command: "show <id>|--run <id> [--raw]", description: "Show a human run summary; --raw prints the full payload.", primary: true },
107
+ { command: "attach <run-id>|--run <id> [--follow]", description: "Attach to the run; --follow opens the enriched bundled Pi (worker brain).", primary: true },
108
+ { command: "stop [<run-id>|--run <id>]", description: "Request stop for one run or local active runs.", primary: true },
109
+ { command: "steer <run-id> --message <text>", description: "Queue a steering message into a live worker without attaching." },
110
+ { command: "timeline --run <id> [--follow]", description: "Stream raw run timeline events." },
111
+ { command: "replay <run-id>|--run <id> [--with-session]", description: "Print the run's consolidated run.jsonl as a merged timeline; --with-session interleaves the Pi session log." },
112
+ { command: "resume", description: "Resume the most recent interrupted local run." },
113
+ { command: "restart", description: "Restart the most recent local run from a clean runtime." },
114
+ { command: "delete|cleanup", description: "Remove completed run records/artifacts." }
115
+ ],
116
+ examples: [
117
+ "rig run list",
118
+ "rig run status",
119
+ "rig run show <run-id>",
120
+ "rig run attach <run-id> --follow",
121
+ "rig run stop <run-id>"
122
+ ],
123
+ next: ["Use `rig task run --next` to create a new run.", "Use `--json` when scripts need the full structured record."]
124
+ },
125
+ {
126
+ name: "inbox",
127
+ summary: "Review approval and user-input requests that block worker runs.",
128
+ usage: ["rig inbox <approvals|approve|inputs|respond> [options]"],
129
+ commands: [
130
+ { command: "approvals [--run <id>] [--task <id>]", description: "List pending approvals.", primary: true },
131
+ { command: "inputs [--run <id>] [--task <id>]", description: "List pending user-input requests.", primary: true },
132
+ { command: "approve --run <id> --request <id> --decision approve|reject", description: "Resolve an approval request." },
133
+ { command: "respond --run <id> --request <id> --answer key=value", description: "Answer a user-input request." }
134
+ ],
135
+ examples: [
136
+ "rig inbox approvals",
137
+ "rig inbox inputs --run <run-id>",
138
+ "rig inbox approve --run <run-id> --request <request-id> --decision approve"
139
+ ],
140
+ next: ["Rejoin the run after resolving a block: `rig run attach <run-id> --follow`."]
141
+ },
142
+ {
143
+ name: "stats",
144
+ summary: "Fleet metrics computed from on-disk run journals (no server required).",
145
+ usage: ["rig stats [show] [--since <7d|30d|ISO date>]"],
146
+ commands: [
147
+ { command: "show [--since <window>]", description: "Total runs, completion/failure/needs-attention rates, median run time, steering, stalls, approvals.", primary: true }
148
+ ],
149
+ examples: [
150
+ "rig stats",
151
+ "rig stats --since 7d",
152
+ "rig stats --since 2026-06-01 --json"
153
+ ],
154
+ next: ["Inspect outliers with `rig run list` and `rig run show <run-id>`.", "Use `--json` for the schema'd envelope (see docs/cli-json.md)."]
155
+ },
156
+ {
157
+ name: "inspect",
158
+ summary: "Inspect logs, artifacts, graphs, failures for a task.",
159
+ usage: ["rig inspect <logs|artifacts|failures|graph|audit|diff> --task <id>"],
160
+ commands: [
161
+ { command: "logs --task <id>", description: "Latest run log for a task (local or selected server).", primary: true },
162
+ { command: "artifacts --task <id>", description: "List the task's completion artifacts.", primary: true },
163
+ { command: "failures --task <id>", description: "Recorded failures for a task.", primary: true },
164
+ { command: "diff --task <id>", description: "Changed files for a task.", primary: true },
165
+ { command: "graph", description: "Task dependency graph." },
166
+ { command: "audit", description: "Controlled-command audit trail." }
167
+ ],
168
+ examples: ["rig inspect logs --task <id>", "rig inspect diff --task <id>"],
169
+ next: ["Use `rig stats` for fleet-level metrics across runs."]
170
+ },
171
+ {
172
+ name: "repo",
173
+ summary: "Repository sync/baseline helpers for the Rig-managed checkout.",
174
+ usage: ["rig repo <sync|reset-baseline>"],
175
+ commands: [
176
+ { command: "sync", description: "Sync project repository state.", primary: true },
177
+ { command: "reset-baseline", description: "Reset the managed baseline for the repo." }
178
+ ],
179
+ examples: ["rig repo sync"]
180
+ },
181
+ {
182
+ name: "plugin",
183
+ summary: "Plugin listing, validation, and plugin-contributed commands.",
184
+ usage: ["rig plugin <list|validate|run> [options]"],
185
+ commands: [
186
+ { command: "list", description: "List plugins declared in rig.config.ts and their contributions.", primary: true },
187
+ { command: "validate --task <id>", description: "Run plugin-contributed validators for a task.", primary: true },
188
+ { command: "run <command-id> [args...]", description: "Execute a plugin-contributed CLI command (also callable as `rig <command-id>`)." }
189
+ ],
190
+ examples: ["rig plugin list", "rig plugin run <command-id>"]
191
+ },
192
+ {
193
+ name: "init",
194
+ summary: "Set up Rig for this repo: server, GitHub auth, checkout strategy, task source, and Pi wiring.",
195
+ usage: ["rig init [--yes] [--server local|remote] [--repo owner/repo] [--remote-url <url>]"],
196
+ commands: [
197
+ { command: "init", description: "Interactive setup wizard for a new or existing Rig repo.", primary: true },
198
+ { command: "init --demo", description: "Offline demo project: files task source + 3 sample tasks, zero GitHub.", primary: true },
199
+ { command: "init --yes", description: "Non-interactive setup using detected/default settings.", primary: true },
200
+ { command: "init --server remote --remote-url <url>", description: "Link this repo to a remote Rig server.", primary: true },
201
+ { command: "init --repair", description: "Repair missing private state without replacing project config." }
202
+ ],
203
+ examples: [
204
+ "rig init",
205
+ "rig init --demo",
206
+ "rig init --yes --repo humanity-org/humanwork",
207
+ "rig init --server remote --remote-url https://where.rig-does.work --repo owner/repo"
208
+ ],
209
+ next: ["After init, run `rig server status`.", "Then use `rig task list` and `rig task run --next` for day-to-day work."]
210
+ },
211
+ {
212
+ name: "doctor",
213
+ summary: "Diagnostics for project/server/GitHub/Pi state.",
214
+ usage: ["rig doctor"],
215
+ commands: [
216
+ { command: "doctor", description: "Run setup and runtime diagnostics.", primary: true },
217
+ { command: "check", description: "Compatibility spelling for diagnostics." }
218
+ ],
219
+ examples: ["rig doctor", "rig doctor --json"],
220
+ next: ["Use `rig server status` and `rig github auth status` to inspect common failure points."]
221
+ },
222
+ {
223
+ name: "github",
224
+ summary: "GitHub auth helpers for the selected Rig server.",
225
+ usage: ["rig github auth <status|import-gh|token>"],
226
+ commands: [
227
+ { command: "auth status", description: "Show GitHub auth state.", primary: true },
228
+ { command: "auth import-gh", description: "Import the current `gh` token into the selected server." },
229
+ { command: "auth token --token <token>", description: "Store a token on the selected server." }
230
+ ],
231
+ examples: ["rig github auth status", "rig github auth import-gh"],
232
+ next: ["After auth is valid, use `rig task run --next`."]
233
+ }
234
+ ];
235
+ var ADVANCED_GROUPS = [
236
+ { name: "setup", summary: "Bootstrap/check local setup.", usage: ["rig setup <bootstrap|check|preflight>"], commands: [{ command: "bootstrap|check|preflight", description: "Setup helpers." }] },
237
+ { name: "profile", summary: "Runtime profile/model defaults.", usage: ["rig profile <show|set>"], commands: [{ command: "show", description: "Show active profile." }] },
238
+ {
239
+ name: "review",
240
+ summary: "Inspect or change completion review gate policy.",
241
+ usage: ["rig review <show|set>"],
242
+ commands: [
243
+ { command: "show", description: "Show current review gate settings." },
244
+ { command: "set <off|advisory|required> [--provider greptile]", description: "Change review strictness/provider." }
245
+ ],
246
+ examples: ["rig review show", "rig review set required --provider greptile"],
247
+ next: ["Use `rig inbox approvals` for blocked run handoffs."]
248
+ },
249
+ {
250
+ name: "browser",
251
+ summary: "Browser/app diagnostics for browser-required tasks.",
252
+ usage: ["rig browser <help|explain|demo|app|hp-next> [options]"],
253
+ commands: [
254
+ { command: "help", description: "Rich browser command help (canonical: `rig browser help`)." },
255
+ { command: "explain", description: "Explain the browser-required task contract." },
256
+ { command: "demo", description: "Run browser demo flows against a local page." },
257
+ { command: "app", description: "Launch the Rig Browser workstation app." },
258
+ { command: "hp-next <dev|check|e2e|reset>", description: "Drive the hp-next browser test harness." }
259
+ ]
260
+ },
261
+ {
262
+ name: "pi",
263
+ summary: "Manage Pi extension packages for this project (community extensions from npm/git).",
264
+ usage: ["rig pi <list|add|remove|search> [args]"],
265
+ commands: [
266
+ { command: "list", description: "Show project and user Pi extension packages." },
267
+ { command: "add <source>", description: "Add an npm/git Pi extension to .pi/settings.json (auto-installs at next session)." },
268
+ { command: "remove <source>", description: "Remove an operator-added Pi extension." },
269
+ { command: "search [term]", description: "Discover Pi extension packages on the npm registry." }
270
+ ],
271
+ examples: ["rig pi search subagents", "rig pi add pi-subagents", "rig pi list"],
272
+ next: ["Config-managed extensions: declare `runtime: { pi: { packages: [...] } }` in rig.config.ts \u2014 workers pick them up automatically."]
273
+ },
274
+ { name: "queue", summary: "Run task queues locally.", usage: ["rig queue run [options]"], commands: [{ command: "run", description: "Process queue work." }] },
275
+ { name: "agent", summary: "Runtime agent workspace helpers.", usage: ["rig agent <list|prepare|run|cleanup>"], commands: [{ command: "list", description: "List prepared agents." }] },
276
+ { name: "inspector", summary: "Event stream and drift scanners.", usage: ["rig inspector <stream|scan-upstream-drift>"], commands: [{ command: "stream", description: "Stream events." }] },
277
+ { name: "dist", summary: "Build/install packaged Rig CLI.", usage: ["rig dist <build|install|doctor>"], commands: [{ command: "build", description: "Build distribution." }] },
278
+ { name: "workspace", summary: "Workspace topology/service helpers.", usage: ["rig workspace <summary|topology|remote-hosts>"], commands: [{ command: "summary", description: "Show workspace summary." }] },
279
+ { name: "remote", summary: "Compatibility remote orchestration controls.", usage: ["rig remote <status|watch|pause|resume|...>"], commands: [{ command: "status", description: "Show remote state." }] },
280
+ { name: "git", summary: "Pass through to Rig git-flow helper.", usage: ["rig git <args...>"], commands: [{ command: "<args...>", description: "Advanced git flow operations." }] },
281
+ { name: "harness", summary: "Pass through to runtime harness CLI.", usage: ["rig harness <args...>"], commands: [{ command: "<args...>", description: "Advanced harness operations." }] },
282
+ { name: "test", summary: "Project test wrappers.", usage: ["rig test <unit|e2e|all>"], commands: [{ command: "all", description: "Run configured project tests." }] }
283
+ ];
284
+ var ADVANCED_COMMANDS = [
285
+ { command: "rig server task-run ...", description: "Internal server-owned task execution entry point." },
286
+ { command: "rig server notify-test [--event <type>]", description: "Internal event notification smoke command." },
287
+ { command: "rig run start|start-serial|start-parallel", description: "Local epic queue starters (server-owned tasks use `rig task run ...`)." },
288
+ { command: "rig remote orchestrate-*", description: "Compatibility remote orchestration commands." }
289
+ ];
290
+ var ALL_GROUPS = [...PRIMARY_GROUPS, ...ADVANCED_GROUPS];
291
+ function heading(title) {
292
+ return pc.bold(pc.cyan(title));
293
+ }
294
+ function renderRigBanner(version) {
295
+ const m = (s) => pc.bold(pc.magenta(s));
296
+ const c = (s) => pc.bold(pc.cyan(s));
297
+ const y = (s) => pc.yellow(s);
298
+ const d = (s) => pc.dim(s);
299
+ const lines = [
300
+ m(" \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 ") + d(" \u2591\u2592\u2593\u2588 "),
301
+ m(" \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D ") + d("\u2593\u2592\u2591"),
302
+ c(" \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2557") + d(" \u2591\u2592"),
303
+ c(" \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551") + d(" \u2588\u2593\u2591"),
304
+ y(" \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D") + d(" \u2592\u2591"),
305
+ y(" \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D "),
306
+ "",
307
+ ` ${c("\u25E2\u25E4")} ${pc.bold("the control rig for autonomous coding agents")} ${m("//")} ${d("you are the operator")}`,
308
+ version ? ` ${d(`v${version} \xB7 jack in: rig task run --next`)}` : ` ${d("jack in: rig task run --next")}`
309
+ ];
310
+ return lines.join(`
311
+ `);
312
+ }
313
+ function commandLine(command, description) {
314
+ const commandColumn = command.length >= 38 ? `${command} ` : command.padEnd(38);
315
+ return `${pc.dim("\u2502")} ${pc.bold(commandColumn)} ${description}`;
316
+ }
317
+ function renderCommandBlock(commands) {
318
+ return commands.map((entry) => commandLine(entry.command, entry.description)).join(`
319
+ `);
320
+ }
321
+ function renderGroup(group) {
322
+ const lines = [
323
+ `${heading(`rig ${group.name}`)} \u2014 ${group.summary}`,
324
+ "",
325
+ pc.bold("Usage"),
326
+ ...group.usage.map((line) => ` ${line}`),
327
+ "",
328
+ pc.bold("Commands"),
329
+ ...group.commands.map((entry) => commandLine(entry.command, entry.description))
330
+ ];
331
+ if (group.examples?.length) {
332
+ lines.push("", pc.bold("Examples"), ...group.examples.map((line) => ` ${pc.dim("$")} ${line}`));
333
+ }
334
+ if (group.next?.length) {
335
+ lines.push("", pc.bold("Next steps"), ...group.next.map((line) => ` ${pc.dim("\u203A")} ${line}`));
336
+ }
337
+ if (group.advanced?.length) {
338
+ lines.push("", pc.bold("Compatibility / advanced"), ...group.advanced.map((line) => ` ${pc.dim("\u203A")} ${line}`));
339
+ }
340
+ return lines.join(`
341
+ `);
342
+ }
343
+ function renderTopLevelHelp() {
344
+ return [
345
+ `${heading("rig")} ${pc.dim("\u2014 server-owned task/run control plane for Pi-backed engineering work")}`,
346
+ pc.dim("Current path: select a server, choose a task, submit a run, attach with native Pi, clear inbox gates."),
347
+ "",
348
+ ...TOP_LEVEL_SECTIONS.flatMap((section) => [
349
+ `${pc.bold(pc.magenta(`\u25C7 ${section.title}`))} \u2014 ${pc.dim(section.subtitle)}`,
350
+ renderCommandBlock(section.commands),
351
+ ""
352
+ ]),
353
+ pc.dim("More: `rig help --advanced` for dev/compatibility commands; `rig <group> --help` for rich per-group help; `rig --version` for the installed version."),
354
+ "",
355
+ pc.bold("Global options"),
356
+ commandLine("--project <path>", "Use a project root instead of auto-discovery."),
357
+ commandLine("--json", "Emit structured output for scripts/agents."),
358
+ commandLine("--dry-run", "Print the command plan without mutating state.")
359
+ ].join(`
360
+ `).trimEnd();
361
+ }
362
+ function renderAdvancedHelp() {
363
+ return [
364
+ `${heading("rig advanced")} \u2014 compatibility, diagnostics, and internal surfaces`,
365
+ "",
366
+ pc.bold("Primary groups"),
367
+ " init, server, task, run, inbox, repo, plugin, inspect, stats, doctor, github",
368
+ "",
369
+ pc.bold("Advanced commands"),
370
+ ...ADVANCED_COMMANDS.map((entry) => commandLine(entry.command, entry.description)),
371
+ "",
372
+ pc.bold("Advanced groups"),
373
+ ...ADVANCED_GROUPS.map((group) => commandLine(group.name, group.summary)),
374
+ "",
375
+ pc.dim("All groups remain callable. Prefer `rig server`, `rig task`, `rig run`, and `rig inbox` for day-to-day work.")
376
+ ].join(`
377
+ `);
378
+ }
379
+ function renderGroupHelp(groupName) {
380
+ const group = ALL_GROUPS.find((candidate) => candidate.name === groupName);
381
+ return group ? renderGroup(group) : null;
382
+ }
383
+ function listHelpGroups() {
384
+ return ALL_GROUPS.map((group) => group.name);
385
+ }
386
+ function suggestGroupCommandForWord(word) {
387
+ const normalized = word.trim().toLowerCase();
388
+ if (!normalized)
389
+ return null;
390
+ for (const group of ALL_GROUPS) {
391
+ for (const entry of group.commands) {
392
+ const firstToken = entry.command.split(/\s+/)[0] ?? "";
393
+ const names = firstToken.split("|").map((name) => name.trim().toLowerCase());
394
+ if (names.includes(normalized)) {
395
+ return `rig ${group.name} ${normalized}`;
396
+ }
397
+ }
398
+ }
399
+ return null;
400
+ }
401
+ function shouldUseClackOutput() {
402
+ return Boolean(process.stdout.isTTY) && process.env.RIG_CLI_PLAIN_HELP !== "1";
403
+ }
404
+ function printTopLevelHelp(state = {}) {
405
+ if (!shouldUseClackOutput()) {
406
+ console.log(renderTopLevelHelp());
407
+ return;
408
+ }
409
+ console.log(renderRigBanner(state.version));
410
+ console.log("");
411
+ if (state.projectInitialized === false) {
412
+ intro("no rig project in this directory");
413
+ note([
414
+ commandLine("rig init", "Set this repo up: config, GitHub auth, task source, server, Pi."),
415
+ commandLine("rig init --yes", "Same, non-interactive, sensible defaults."),
416
+ commandLine("rig doctor", "Already initialized somewhere else? Check the wiring.")
417
+ ].join(`
418
+ `), "Get started");
419
+ outro("After init: rig task run --next puts an agent on your next task.");
420
+ return;
421
+ }
422
+ intro(state.selectedServer ? `server: ${state.selectedServer}` : "rig");
423
+ for (const section of TOP_LEVEL_SECTIONS) {
424
+ note(renderCommandBlock(section.commands), `${section.title} \u2014 ${section.subtitle}`);
425
+ }
426
+ log.info("More: rig help --advanced \xB7 rig <group> --help \xB7 rig --version");
427
+ note([
428
+ commandLine("--project <path>", "Use a project root instead of auto-discovery."),
429
+ commandLine("--json", "Emit structured output for scripts/agents."),
430
+ commandLine("--dry-run", "Print the command plan without mutating state.")
431
+ ].join(`
432
+ `), "Global options");
433
+ outro("init \u2192 task run \u2192 watch \u2192 inbox \u2192 merged.");
434
+ }
435
+ function printAdvancedHelp() {
436
+ if (!shouldUseClackOutput()) {
437
+ console.log(renderAdvancedHelp());
438
+ return;
439
+ }
440
+ intro("rig advanced");
441
+ note(ADVANCED_COMMANDS.map((entry) => commandLine(entry.command, entry.description)).join(`
442
+ `), "Advanced commands");
443
+ note(ADVANCED_GROUPS.map((group) => commandLine(group.name, group.summary)).join(`
444
+ `), "Advanced groups");
445
+ outro("Primary daily flow: rig server \xB7 rig task \xB7 rig run \xB7 rig inbox.");
446
+ }
447
+ function printGroupHelpDocument(groupName) {
448
+ const rendered = renderGroupHelp(groupName) ?? renderTopLevelHelp();
449
+ if (!shouldUseClackOutput()) {
450
+ console.log(rendered);
451
+ return;
452
+ }
453
+ const group = ALL_GROUPS.find((candidate) => candidate.name === groupName);
454
+ if (!group) {
455
+ printTopLevelHelp();
456
+ return;
457
+ }
458
+ intro(`rig ${group.name}`);
459
+ note(group.summary, "Purpose");
460
+ note(group.usage.join(`
461
+ `), "Usage");
462
+ note(group.commands.map((entry) => commandLine(entry.command, entry.description)).join(`
463
+ `), "Commands");
464
+ if (group.examples?.length)
465
+ note(group.examples.map((line) => `$ ${line}`).join(`
466
+ `), "Examples");
467
+ if (group.next?.length)
468
+ note(group.next.map((line) => `\u203A ${line}`).join(`
469
+ `), "Next steps");
470
+ if (group.advanced?.length)
471
+ log.info(group.advanced.join(`
472
+ `));
473
+ outro("Run with --json when scripts need structured output.");
474
+ }
475
+ export {
476
+ suggestGroupCommandForWord,
477
+ renderTopLevelHelp,
478
+ renderRigBanner,
479
+ renderGroupHelp,
480
+ renderAdvancedHelp,
481
+ printTopLevelHelp,
482
+ printGroupHelpDocument,
483
+ printAdvancedHelp,
484
+ listHelpGroups
485
+ };
@@ -0,0 +1,56 @@
1
+ // @bun
2
+ // packages/cli/src/commands/_json-output.ts
3
+ import { Schema } from "effect";
4
+ import {
5
+ RigDoctorCheckOutput,
6
+ RigInboxApprovalsOutput,
7
+ RigInboxInputsOutput,
8
+ RigRunListOutput,
9
+ RigRunShowOutput,
10
+ RigServerStatusOutput,
11
+ RigStatsOutput,
12
+ RigTaskListOutput,
13
+ RigTaskShowOutput
14
+ } from "@rig/contracts";
15
+ var CLI_OUTPUT_SCHEMAS = {
16
+ "task list": RigTaskListOutput,
17
+ "task show": RigTaskShowOutput,
18
+ "run list": RigRunListOutput,
19
+ "run show": RigRunShowOutput,
20
+ "server status": RigServerStatusOutput,
21
+ "inbox approvals": RigInboxApprovalsOutput,
22
+ "inbox inputs": RigInboxInputsOutput,
23
+ "doctor check": RigDoctorCheckOutput,
24
+ "stats show": RigStatsOutput
25
+ };
26
+ function isCommandOutcomeLike(value) {
27
+ if (!value || typeof value !== "object" || Array.isArray(value))
28
+ return false;
29
+ const record = value;
30
+ return typeof record.group === "string" && typeof record.command === "string";
31
+ }
32
+ function buildCliJsonEnvelope(outcome, options = {}) {
33
+ if (!isCommandOutcomeLike(outcome))
34
+ return null;
35
+ const commandKey = `${outcome.group} ${outcome.command}`;
36
+ const schema = CLI_OUTPUT_SCHEMAS[commandKey];
37
+ if (!schema)
38
+ return null;
39
+ const warn = options.warn ?? ((message) => console.error(message));
40
+ const envelope = { v: 1, command: commandKey, data: outcome.details ?? {} };
41
+ try {
42
+ Schema.decodeUnknownSync(schema)(JSON.parse(JSON.stringify(envelope)));
43
+ return envelope;
44
+ } catch (error) {
45
+ warn(`[rig] --json output for "${commandKey}" failed schema validation; printing legacy payload. ` + `(${error instanceof Error ? error.message.split(`
46
+ `)[0] : String(error)})`);
47
+ return null;
48
+ }
49
+ }
50
+ function listSchematizedCliCommands() {
51
+ return Object.keys(CLI_OUTPUT_SCHEMAS).sort();
52
+ }
53
+ export {
54
+ listSchematizedCliCommands,
55
+ buildCliJsonEnvelope
56
+ };