@h-rig/cli 0.0.6-alpha.63 → 0.0.6-alpha.65

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 (46) hide show
  1. package/dist/bin/rig.js +1349 -1599
  2. package/dist/src/commands/_connection-state.js +14 -5
  3. package/dist/src/commands/_doctor-checks.js +71 -11
  4. package/dist/src/commands/_help-catalog.js +99 -60
  5. package/dist/src/commands/_json-output.js +56 -0
  6. package/dist/src/commands/_operator-view.js +97 -784
  7. package/dist/src/commands/_parsers.js +18 -9
  8. package/dist/src/commands/_pi-frontend.js +96 -788
  9. package/dist/src/commands/_policy.js +12 -3
  10. package/dist/src/commands/_preflight.js +73 -13
  11. package/dist/src/commands/_run-driver-helpers.js +31 -5
  12. package/dist/src/commands/_run-replay.js +2 -2
  13. package/dist/src/commands/_server-client.js +76 -16
  14. package/dist/src/commands/_snapshot-upload.js +70 -10
  15. package/dist/src/commands/agent.js +21 -11
  16. package/dist/src/commands/browser.js +24 -15
  17. package/dist/src/commands/connect.js +22 -17
  18. package/dist/src/commands/dist.js +15 -6
  19. package/dist/src/commands/doctor.js +70 -10
  20. package/dist/src/commands/github.js +79 -19
  21. package/dist/src/commands/inbox.js +215 -131
  22. package/dist/src/commands/init.js +202 -35
  23. package/dist/src/commands/inspect.js +77 -17
  24. package/dist/src/commands/inspector.js +18 -9
  25. package/dist/src/commands/pi.js +18 -9
  26. package/dist/src/commands/plugin.js +19 -10
  27. package/dist/src/commands/profile-and-review.js +22 -13
  28. package/dist/src/commands/queue.js +19 -9
  29. package/dist/src/commands/remote.js +25 -16
  30. package/dist/src/commands/repo-git-harness.js +18 -9
  31. package/dist/src/commands/run.js +158 -805
  32. package/dist/src/commands/server.js +85 -25
  33. package/dist/src/commands/setup.js +73 -13
  34. package/dist/src/commands/stats.js +681 -0
  35. package/dist/src/commands/task-report-bug.js +24 -15
  36. package/dist/src/commands/task-run-driver.js +121 -49
  37. package/dist/src/commands/task.js +254 -893
  38. package/dist/src/commands/test.js +12 -3
  39. package/dist/src/commands/workspace.js +14 -5
  40. package/dist/src/commands.js +1339 -1650
  41. package/dist/src/index.js +1349 -1599
  42. package/dist/src/launcher.js +72 -10
  43. package/dist/src/runner.js +14 -5
  44. package/package.json +10 -7
  45. package/dist/src/commands/_pi-remote-session.js +0 -771
  46. package/dist/src/commands/_pi-worker-bridge-extension.js +0 -834
@@ -4,6 +4,57 @@ import { existsSync } from "fs";
4
4
  import { basename, resolve } from "path";
5
5
  import { loadDotEnvSecrets } from "@rig/runtime/baked-secrets";
6
6
  import { RIG_DEFINITION_DIRNAME, RIG_STATE_DIRNAME, resolveNearestRigProjectRoot } from "@rig/runtime/layout";
7
+
8
+ // packages/cli/src/commands/_json-output.ts
9
+ import { Schema } from "effect";
10
+ import {
11
+ RigDoctorCheckOutput,
12
+ RigInboxApprovalsOutput,
13
+ RigInboxInputsOutput,
14
+ RigRunListOutput,
15
+ RigRunShowOutput,
16
+ RigServerStatusOutput,
17
+ RigStatsOutput,
18
+ RigTaskListOutput,
19
+ RigTaskShowOutput
20
+ } from "@rig/contracts";
21
+ var CLI_OUTPUT_SCHEMAS = {
22
+ "task list": RigTaskListOutput,
23
+ "task show": RigTaskShowOutput,
24
+ "run list": RigRunListOutput,
25
+ "run show": RigRunShowOutput,
26
+ "server status": RigServerStatusOutput,
27
+ "inbox approvals": RigInboxApprovalsOutput,
28
+ "inbox inputs": RigInboxInputsOutput,
29
+ "doctor check": RigDoctorCheckOutput,
30
+ "stats show": RigStatsOutput
31
+ };
32
+ function isCommandOutcomeLike(value) {
33
+ if (!value || typeof value !== "object" || Array.isArray(value))
34
+ return false;
35
+ const record = value;
36
+ return typeof record.group === "string" && typeof record.command === "string";
37
+ }
38
+ function buildCliJsonEnvelope(outcome, options = {}) {
39
+ if (!isCommandOutcomeLike(outcome))
40
+ return null;
41
+ const commandKey = `${outcome.group} ${outcome.command}`;
42
+ const schema = CLI_OUTPUT_SCHEMAS[commandKey];
43
+ if (!schema)
44
+ return null;
45
+ const warn = options.warn ?? ((message) => console.error(message));
46
+ const envelope = { v: 1, command: commandKey, data: outcome.details ?? {} };
47
+ try {
48
+ Schema.decodeUnknownSync(schema)(JSON.parse(JSON.stringify(envelope)));
49
+ return envelope;
50
+ } catch (error) {
51
+ warn(`[rig] --json output for "${commandKey}" failed schema validation; printing legacy payload. ` + `(${error instanceof Error ? error.message.split(`
52
+ `)[0] : String(error)})`);
53
+ return null;
54
+ }
55
+ }
56
+
57
+ // packages/cli/src/launcher.ts
7
58
  function parsePolicyMode(value) {
8
59
  if (!value) {
9
60
  return;
@@ -47,14 +98,17 @@ function normalizeCliErrorCode(message, isCliError) {
47
98
  return isCliError ? "CLI_ERROR" : "UNEXPECTED_ERROR";
48
99
  }
49
100
  function normalizeCliErrorPayload(error, CliErrorClass, options = {}) {
50
- const isCliError = error instanceof CliErrorClass;
101
+ const isCliError = error instanceof CliErrorClass || error instanceof Error && error.name === "CliError" && typeof error.exitCode === "number";
51
102
  const message = error instanceof Error ? error.message : String(error);
52
103
  const exitCode = isCliError ? error.exitCode : 1;
104
+ const rawHint = error instanceof Error ? error.hint : undefined;
105
+ const hint = typeof rawHint === "string" && rawHint.trim() ? rawHint.trim() : undefined;
53
106
  const payload = {
54
107
  ok: false,
55
108
  code: normalizeCliErrorCode(message, isCliError),
56
109
  message,
57
- exitCode
110
+ exitCode,
111
+ ...hint ? { hint } : {}
58
112
  };
59
113
  if (options.debug && error instanceof Error && error.stack) {
60
114
  return { ...payload, stack: error.stack };
@@ -97,14 +151,19 @@ async function runRigCli(module, options = {}) {
97
151
  const context = await module.initializeRuntime(runtimeOptions);
98
152
  const outcome = await module.execute(context, runIdResult.rest);
99
153
  if (outputMode === "json") {
100
- io.log(JSON.stringify({
101
- ok: true,
102
- runId: context.runId,
103
- outcome,
104
- eventsFile: context.eventBus.getEventsFile(),
105
- policyFile: resolve(projectRoot, "rig", "policy", "policy.json"),
106
- policyMode: context.policyMode ?? policyMode ?? module.loadPolicy(projectRoot).mode
107
- }, null, 2));
154
+ const envelope = buildCliJsonEnvelope(outcome, { warn: io.error });
155
+ if (envelope) {
156
+ io.log(JSON.stringify(envelope, null, 2));
157
+ } else {
158
+ io.log(JSON.stringify({
159
+ ok: true,
160
+ runId: context.runId,
161
+ outcome,
162
+ eventsFile: context.eventBus.getEventsFile(),
163
+ policyFile: resolve(projectRoot, "rig", "policy", "policy.json"),
164
+ policyMode: context.policyMode ?? policyMode ?? module.loadPolicy(projectRoot).mode
165
+ }, null, 2));
166
+ }
108
167
  }
109
168
  } catch (error) {
110
169
  const payload = normalizeCliErrorPayload(error, module.CliError, { debug: debugErrors });
@@ -112,6 +171,9 @@ async function runRigCli(module, options = {}) {
112
171
  io.error(JSON.stringify(payload, null, 2));
113
172
  } else {
114
173
  io.error(debugErrors && payload.stack ? payload.stack : payload.message);
174
+ if (payload.hint) {
175
+ io.error(`Next: ${payload.hint}`);
176
+ }
115
177
  }
116
178
  process.exit(payload.exitCode);
117
179
  }
@@ -4,10 +4,19 @@ var {$ } = globalThis.Bun;
4
4
  import { existsSync, mkdirSync } from "fs";
5
5
  import { resolve } from "path";
6
6
  import { EventBus } from "@rig/runtime/control-plane/runtime/events";
7
- import { CliError } from "@rig/runtime/control-plane/errors";
7
+ import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
8
8
  import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
9
9
  import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
10
- import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
10
+
11
+ class CliError extends RuntimeCliError {
12
+ hint;
13
+ constructor(message, exitCode = 1, options = {}) {
14
+ super(message, exitCode);
15
+ if (options.hint?.trim()) {
16
+ this.hint = options.hint.trim();
17
+ }
18
+ }
19
+ }
11
20
  function withProjectRoot(projectRoot) {
12
21
  $.cwd(projectRoot);
13
22
  }
@@ -125,7 +134,7 @@ async function runCommand(context, parts) {
125
134
  matchedRuleIds: guardDecision.matchedRules.map((r) => r.id),
126
135
  mode: effectiveMode
127
136
  });
128
- throw new CliError(`Policy blocked command: ${formatted}`, 126);
137
+ throw new CliError(`Policy blocked command: ${formatted}`, 126, { hint: "Review rig/policy/policy.json, or re-run with `--policy-mode observe` to log instead of block." });
129
138
  }
130
139
  const startedAt = new Date;
131
140
  await context.emitEvent("command.started", {
@@ -218,7 +227,7 @@ function takeOption(args, option) {
218
227
  if (current === option) {
219
228
  const next = args[index + 1];
220
229
  if (!next || next.startsWith("-")) {
221
- throw new CliError(`Missing value for ${option}`);
230
+ throw new CliError(`Missing value for ${option}`, 1, { hint: `Provide a value after ${option}, e.g. \`${option} <value>\`.` });
222
231
  }
223
232
  value = next;
224
233
  index += 1;
@@ -254,5 +263,5 @@ export {
254
263
  initializeRuntime,
255
264
  formatCommand,
256
265
  ensureAgentShellBinary,
257
- CliError2 as CliError
266
+ CliError
258
267
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h-rig/cli",
3
- "version": "0.0.6-alpha.63",
3
+ "version": "0.0.6-alpha.65",
4
4
  "type": "module",
5
5
  "description": "Rig package",
6
6
  "license": "UNLICENSED",
@@ -23,12 +23,15 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@clack/prompts": "^1.2.0",
26
- "@earendil-works/pi-coding-agent": "npm:@h-rig/pi-coding-agent@0.0.6-alpha.63",
27
- "@rig/client": "npm:@h-rig/client@0.0.6-alpha.63",
28
- "@rig/core": "npm:@h-rig/core@0.0.6-alpha.63",
29
- "@rig/runtime": "npm:@h-rig/runtime@0.0.6-alpha.63",
30
- "@rig/server": "npm:@h-rig/server@0.0.6-alpha.63",
31
- "@rig/standard-plugin": "npm:@h-rig/standard-plugin@0.0.6-alpha.63",
26
+ "@earendil-works/pi-coding-agent": "0.79.0",
27
+ "@rig/client": "npm:@h-rig/client@0.0.6-alpha.65",
28
+ "@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.65",
29
+ "@rig/core": "npm:@h-rig/core@0.0.6-alpha.65",
30
+ "@rig/pi-rig": "npm:@h-rig/pi-rig@0.0.6-alpha.65",
31
+ "@rig/runtime": "npm:@h-rig/runtime@0.0.6-alpha.65",
32
+ "@rig/server": "npm:@h-rig/server@0.0.6-alpha.65",
33
+ "@rig/standard-plugin": "npm:@h-rig/standard-plugin@0.0.6-alpha.65",
34
+ "effect": "4.0.0-beta.78",
32
35
  "picocolors": "^1.1.1"
33
36
  }
34
37
  }