@h-rig/cli 0.0.6-alpha.10 → 0.0.6-alpha.100

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 (120) hide show
  1. package/README.md +18 -19
  2. package/dist/bin/build-rig-binaries.d.ts +2 -0
  3. package/dist/bin/build-rig-binaries.js +22 -10
  4. package/dist/bin/rig.d.ts +72 -0
  5. package/dist/bin/rig.js +15683 -7361
  6. package/dist/config/rig-default-config.yml +5 -0
  7. package/dist/src/app/drone-ui.d.ts +34 -0
  8. package/dist/src/app/drone-ui.js +278 -0
  9. package/dist/src/commands/_async-ui.d.ts +10 -0
  10. package/dist/src/commands/_async-ui.js +121 -0
  11. package/dist/src/commands/_cli-format.d.ts +56 -0
  12. package/dist/src/commands/_cli-format.js +319 -0
  13. package/dist/src/commands/_config-env.d.ts +18 -0
  14. package/dist/src/commands/_config-env.js +22 -0
  15. package/dist/src/commands/_connection-state.d.ts +54 -0
  16. package/dist/src/commands/_connection-state.js +75 -11
  17. package/dist/src/commands/_doctor-checks.d.ts +46 -0
  18. package/dist/src/commands/_doctor-checks.js +100 -267
  19. package/dist/src/commands/_help-catalog.d.ts +29 -0
  20. package/dist/src/commands/_help-catalog.js +146 -0
  21. package/dist/src/commands/_inprocess-services.d.ts +33 -0
  22. package/dist/src/commands/_inprocess-services.js +102 -0
  23. package/dist/src/commands/_json-output.d.ts +11 -0
  24. package/dist/src/commands/_json-output.js +60 -0
  25. package/dist/src/commands/_lazy-reconcile.d.ts +34 -0
  26. package/dist/src/commands/_lazy-reconcile.js +102 -0
  27. package/dist/src/commands/_parsers.d.ts +15 -0
  28. package/dist/src/commands/_parsers.js +18 -11
  29. package/dist/src/commands/_paths.d.ts +11 -0
  30. package/dist/src/commands/_paths.js +1 -1
  31. package/dist/src/commands/_pi-frontend.d.ts +35 -0
  32. package/dist/src/commands/_pi-frontend.js +64 -0
  33. package/dist/src/commands/_pi-install.d.ts +42 -0
  34. package/dist/src/commands/_pi-install.js +19 -36
  35. package/dist/src/commands/_policy.d.ts +8 -0
  36. package/dist/src/commands/_policy.js +67 -19
  37. package/dist/src/commands/_probes.d.ts +1 -0
  38. package/dist/src/commands/_run-bridge.d.ts +114 -0
  39. package/dist/src/commands/_run-bridge.js +387 -0
  40. package/dist/src/commands/_run-diagnostics.d.ts +9 -0
  41. package/dist/src/commands/_run-diagnostics.js +51 -0
  42. package/dist/src/commands/_run-driver-helpers.d.ts +26 -0
  43. package/dist/src/commands/_run-driver-helpers.js +79 -230
  44. package/dist/src/commands/_run-projection.d.ts +50 -0
  45. package/dist/src/commands/_run-projection.js +349 -0
  46. package/dist/src/commands/_run-subcommands.d.ts +3 -0
  47. package/dist/src/commands/_run-subcommands.js +31 -0
  48. package/dist/src/commands/_spinner.d.ts +25 -0
  49. package/dist/src/commands/_spinner.js +65 -0
  50. package/dist/src/commands/agent.d.ts +3 -0
  51. package/dist/src/commands/agent.js +8690 -236
  52. package/dist/src/commands/config.d.ts +3 -0
  53. package/dist/src/commands/config.js +181 -0
  54. package/dist/src/commands/dist.d.ts +28 -0
  55. package/dist/src/commands/dist.js +44 -29
  56. package/dist/src/commands/doctor.d.ts +3 -0
  57. package/dist/src/commands/doctor.js +219 -268
  58. package/dist/src/commands/github.d.ts +3 -0
  59. package/dist/src/commands/github.js +236 -188
  60. package/dist/src/commands/inbox.d.ts +28 -0
  61. package/dist/src/commands/inbox.js +530 -111
  62. package/dist/src/commands/init.d.ts +64 -0
  63. package/dist/src/commands/init.js +912 -705
  64. package/dist/src/commands/inspect.d.ts +20 -0
  65. package/dist/src/commands/inspect.js +709 -119
  66. package/dist/src/commands/pi.d.ts +3 -0
  67. package/dist/src/commands/pi.js +177 -0
  68. package/dist/src/commands/plugin.d.ts +16 -0
  69. package/dist/src/commands/plugin.js +576 -29
  70. package/dist/src/commands/profile-and-review.d.ts +4 -0
  71. package/dist/src/commands/profile-and-review.js +112 -67
  72. package/dist/src/commands/queue.d.ts +3 -0
  73. package/dist/src/commands/queue.js +20 -20
  74. package/dist/src/commands/remote.d.ts +3 -0
  75. package/dist/src/commands/remote.js +883 -50
  76. package/dist/src/commands/repo-git-harness.d.ts +5 -0
  77. package/dist/src/commands/repo-git-harness.js +78 -28
  78. package/dist/src/commands/run.d.ts +21 -0
  79. package/dist/src/commands/run.js +17731 -661
  80. package/dist/src/commands/server.d.ts +3 -0
  81. package/dist/src/commands/server.js +166 -303
  82. package/dist/src/commands/setup.d.ts +16 -0
  83. package/dist/src/commands/setup.js +244 -299
  84. package/dist/src/commands/stats.d.ts +15 -0
  85. package/dist/src/commands/stats.js +632 -0
  86. package/dist/src/commands/task-run-driver.d.ts +94 -0
  87. package/dist/src/commands/task-run-driver.js +116 -1961
  88. package/dist/src/commands/task.d.ts +35 -0
  89. package/dist/src/commands/task.js +676 -1201
  90. package/dist/src/commands/test.d.ts +3 -0
  91. package/dist/src/commands/test.js +15 -8
  92. package/dist/src/commands/triage.d.ts +11 -0
  93. package/dist/src/commands/triage.js +227 -0
  94. package/dist/src/commands/workspace.d.ts +3 -0
  95. package/dist/src/commands/workspace.js +18 -11
  96. package/dist/src/commands.d.ts +13 -0
  97. package/dist/src/commands.js +16812 -8045
  98. package/dist/src/index.d.ts +4 -0
  99. package/dist/src/index.js +16817 -8377
  100. package/dist/src/launcher.d.ts +61 -0
  101. package/dist/src/launcher.js +77 -11
  102. package/dist/src/operator-cli.d.ts +2 -0
  103. package/dist/src/operator-cli.js +17867 -0
  104. package/dist/src/operator-entry.d.ts +1 -0
  105. package/dist/src/operator-entry.js +3 -0
  106. package/dist/src/runner.d.ts +47 -0
  107. package/dist/src/runner.js +16 -22
  108. package/dist/src/withMutedConsole.d.ts +2 -0
  109. package/package.json +21 -8
  110. package/dist/src/commands/_authority-runs.js +0 -111
  111. package/dist/src/commands/_operator-view.js +0 -340
  112. package/dist/src/commands/_preflight.js +0 -478
  113. package/dist/src/commands/_server-client.js +0 -382
  114. package/dist/src/commands/_snapshot-upload.js +0 -331
  115. package/dist/src/commands/_task-picker.js +0 -48
  116. package/dist/src/commands/browser.js +0 -890
  117. package/dist/src/commands/connect.js +0 -180
  118. package/dist/src/commands/inspector.js +0 -256
  119. package/dist/src/commands/task-report-bug.js +0 -1083
  120. package/dist/src/report-bug.js +0 -260
@@ -0,0 +1,61 @@
1
+ import type { RunnerContext } from "./runner";
2
+ export type PolicyModeValue = "off" | "observe" | "enforce";
3
+ export interface ResolveProjectRootOptions {
4
+ readonly envProjectRoot?: string;
5
+ readonly execPath?: string;
6
+ readonly importDir?: string;
7
+ readonly cwd?: string;
8
+ }
9
+ export interface CliIo {
10
+ readonly log: (message: string) => void;
11
+ readonly error: (message: string) => void;
12
+ }
13
+ export interface RigCliRunOptions {
14
+ readonly argv?: readonly string[];
15
+ readonly io?: CliIo;
16
+ readonly envProjectRoot?: string;
17
+ readonly execPath?: string;
18
+ readonly importDir?: string;
19
+ readonly cwd?: string;
20
+ }
21
+ export interface RigCliModule {
22
+ readonly CliError: new (message: string, exitCode?: number) => Error & {
23
+ exitCode: number;
24
+ };
25
+ execute: (context: RunnerContext, args: string[]) => Promise<unknown>;
26
+ initializeRuntime: (options: {
27
+ projectRoot: string;
28
+ dryRun: boolean;
29
+ outputMode: "json" | "text";
30
+ runId?: string | undefined;
31
+ policyMode?: PolicyModeValue | undefined;
32
+ }) => Promise<RunnerContext>;
33
+ loadPolicy(projectRoot: string): {
34
+ mode: PolicyModeValue;
35
+ };
36
+ takeFlag(args: string[], flag: string): {
37
+ value: boolean;
38
+ rest: string[];
39
+ };
40
+ takeOption(args: string[], option: string): {
41
+ value?: string;
42
+ rest: string[];
43
+ };
44
+ withProjectRoot(projectRoot: string): void;
45
+ }
46
+ export declare function parsePolicyMode(value: string | undefined): PolicyModeValue | undefined;
47
+ export declare function resolveProjectRoot({ envProjectRoot, execPath, importDir, cwd, }: ResolveProjectRootOptions): string;
48
+ export interface CliErrorPayload {
49
+ readonly ok: false;
50
+ readonly code: string;
51
+ readonly message: string;
52
+ readonly exitCode: number;
53
+ /** Remediation hint (next command to run); rendered as `Next: <hint>`. */
54
+ readonly hint?: string;
55
+ readonly stack?: string;
56
+ }
57
+ export declare function normalizeCliErrorPayload(error: unknown, CliErrorClass: RigCliModule["CliError"], options?: {
58
+ readonly debug?: boolean;
59
+ }): CliErrorPayload;
60
+ export declare function runRigCli(module: RigCliModule, options?: RigCliRunOptions): Promise<void>;
61
+ export declare function hydrateProcessEnvFromDotEnv(projectRoot: string): void;
@@ -4,6 +4,61 @@ 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
+ RigServerRepairLinkOutput,
17
+ RigServerStatusOutput,
18
+ RigServerUseOutput,
19
+ RigStatsOutput,
20
+ RigTaskListOutput,
21
+ RigTaskShowOutput
22
+ } from "@rig/contracts";
23
+ var CLI_OUTPUT_SCHEMAS = {
24
+ "task list": RigTaskListOutput,
25
+ "task show": RigTaskShowOutput,
26
+ "run list": RigRunListOutput,
27
+ "run show": RigRunShowOutput,
28
+ "server use": RigServerUseOutput,
29
+ "server status": RigServerStatusOutput,
30
+ "server repair-link": RigServerRepairLinkOutput,
31
+ "inbox approvals": RigInboxApprovalsOutput,
32
+ "inbox inputs": RigInboxInputsOutput,
33
+ "doctor check": RigDoctorCheckOutput,
34
+ "stats show": RigStatsOutput
35
+ };
36
+ function isCommandOutcomeLike(value) {
37
+ if (!value || typeof value !== "object" || Array.isArray(value))
38
+ return false;
39
+ const record = value;
40
+ return typeof record.group === "string" && typeof record.command === "string";
41
+ }
42
+ function buildCliJsonEnvelope(outcome, options = {}) {
43
+ if (!isCommandOutcomeLike(outcome))
44
+ return null;
45
+ const commandKey = `${outcome.group} ${outcome.command}`;
46
+ const schema = CLI_OUTPUT_SCHEMAS[commandKey];
47
+ if (!schema)
48
+ return null;
49
+ const warn = options.warn ?? ((message) => console.error(message));
50
+ const envelope = { v: 1, command: commandKey, data: outcome.details ?? {} };
51
+ try {
52
+ Schema.decodeUnknownSync(schema)(JSON.parse(JSON.stringify(envelope)));
53
+ return envelope;
54
+ } catch (error) {
55
+ warn(`[rig] --json output for "${commandKey}" failed schema validation; printing legacy payload. ` + `(${error instanceof Error ? error.message.split(`
56
+ `)[0] : String(error)})`);
57
+ return null;
58
+ }
59
+ }
60
+
61
+ // packages/cli/src/launcher.ts
7
62
  function parsePolicyMode(value) {
8
63
  if (!value) {
9
64
  return;
@@ -14,7 +69,7 @@ function parsePolicyMode(value) {
14
69
  throw new Error(`Invalid --policy-mode value: ${value}. Use off|observe|enforce.`);
15
70
  }
16
71
  function hasRigProjectMarker(candidate) {
17
- return existsSync(resolve(candidate, RIG_DEFINITION_DIRNAME)) || existsSync(resolve(candidate, RIG_STATE_DIRNAME)) || existsSync(resolve(candidate, "rig.config.ts")) || existsSync(resolve(candidate, "rig.config.json"));
72
+ return existsSync(resolve(candidate, RIG_DEFINITION_DIRNAME)) || existsSync(resolve(candidate, RIG_STATE_DIRNAME)) || existsSync(resolve(candidate, "rig.config.ts")) || existsSync(resolve(candidate, "rig.config.json")) || existsSync(resolve(candidate, ".git"));
18
73
  }
19
74
  function resolveProjectRoot({
20
75
  envProjectRoot,
@@ -47,14 +102,17 @@ function normalizeCliErrorCode(message, isCliError) {
47
102
  return isCliError ? "CLI_ERROR" : "UNEXPECTED_ERROR";
48
103
  }
49
104
  function normalizeCliErrorPayload(error, CliErrorClass, options = {}) {
50
- const isCliError = error instanceof CliErrorClass;
105
+ const isCliError = error instanceof CliErrorClass || error instanceof Error && error.name === "CliError" && typeof error.exitCode === "number";
51
106
  const message = error instanceof Error ? error.message : String(error);
52
107
  const exitCode = isCliError ? error.exitCode : 1;
108
+ const rawHint = error instanceof Error ? error.hint : undefined;
109
+ const hint = typeof rawHint === "string" && rawHint.trim() ? rawHint.trim() : undefined;
53
110
  const payload = {
54
111
  ok: false,
55
112
  code: normalizeCliErrorCode(message, isCliError),
56
113
  message,
57
- exitCode
114
+ exitCode,
115
+ ...hint ? { hint } : {}
58
116
  };
59
117
  if (options.debug && error instanceof Error && error.stack) {
60
118
  return { ...payload, stack: error.stack };
@@ -97,14 +155,19 @@ async function runRigCli(module, options = {}) {
97
155
  const context = await module.initializeRuntime(runtimeOptions);
98
156
  const outcome = await module.execute(context, runIdResult.rest);
99
157
  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));
158
+ const envelope = buildCliJsonEnvelope(outcome, { warn: io.error });
159
+ if (envelope) {
160
+ io.log(JSON.stringify(envelope, null, 2));
161
+ } else {
162
+ io.log(JSON.stringify({
163
+ ok: true,
164
+ runId: context.runId,
165
+ outcome,
166
+ eventsFile: context.eventBus.getEventsFile(),
167
+ policyFile: resolve(projectRoot, "rig", "policy", "policy.json"),
168
+ policyMode: context.policyMode ?? policyMode ?? module.loadPolicy(projectRoot).mode
169
+ }, null, 2));
170
+ }
108
171
  }
109
172
  } catch (error) {
110
173
  const payload = normalizeCliErrorPayload(error, module.CliError, { debug: debugErrors });
@@ -112,6 +175,9 @@ async function runRigCli(module, options = {}) {
112
175
  io.error(JSON.stringify(payload, null, 2));
113
176
  } else {
114
177
  io.error(debugErrors && payload.stack ? payload.stack : payload.message);
178
+ if (payload.hint) {
179
+ io.error(`Next: ${payload.hint}`);
180
+ }
115
181
  }
116
182
  process.exit(payload.exitCode);
117
183
  }
@@ -0,0 +1,2 @@
1
+ /** Run an operator command (`rig task|run|inbox|stats|inspect|doctor|...`). */
2
+ export declare function runRigOperatorCli(argv: readonly string[]): Promise<void>;