@h-rig/cli 0.0.6-alpha.9 → 0.0.6-alpha.91
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/README.md +18 -19
- package/dist/bin/build-rig-binaries.d.ts +2 -0
- package/dist/bin/build-rig-binaries.js +22 -10
- package/dist/bin/rig.d.ts +72 -0
- package/dist/bin/rig.js +15637 -7344
- package/dist/config/rig-default-config.yml +5 -0
- package/dist/src/app/drone-ui.d.ts +34 -0
- package/dist/src/app/drone-ui.js +278 -0
- package/dist/src/commands/_async-ui.d.ts +10 -0
- package/dist/src/commands/_async-ui.js +121 -0
- package/dist/src/commands/_cli-format.d.ts +56 -0
- package/dist/src/commands/_cli-format.js +319 -0
- package/dist/src/commands/_connection-state.d.ts +54 -0
- package/dist/src/commands/_connection-state.js +75 -11
- package/dist/src/commands/_doctor-checks.d.ts +46 -0
- package/dist/src/commands/_doctor-checks.js +100 -267
- package/dist/src/commands/_help-catalog.d.ts +51 -0
- package/dist/src/commands/_help-catalog.js +502 -0
- package/dist/src/commands/_inprocess-services.d.ts +33 -0
- package/dist/src/commands/_inprocess-services.js +102 -0
- package/dist/src/commands/_json-output.d.ts +11 -0
- package/dist/src/commands/_json-output.js +60 -0
- package/dist/src/commands/_lazy-reconcile.d.ts +34 -0
- package/dist/src/commands/_lazy-reconcile.js +102 -0
- package/dist/src/commands/_parsers.d.ts +15 -0
- package/dist/src/commands/_parsers.js +18 -11
- package/dist/src/commands/_paths.d.ts +11 -0
- package/dist/src/commands/_paths.js +1 -1
- package/dist/src/commands/_pi-frontend.d.ts +35 -0
- package/dist/src/commands/_pi-frontend.js +64 -0
- package/dist/src/commands/_pi-install.d.ts +42 -0
- package/dist/src/commands/_pi-install.js +19 -36
- package/dist/src/commands/_policy.d.ts +8 -0
- package/dist/src/commands/_policy.js +67 -19
- package/dist/src/commands/_probes.d.ts +1 -0
- package/dist/src/commands/_run-bridge.d.ts +114 -0
- package/dist/src/commands/_run-bridge.js +387 -0
- package/dist/src/commands/_run-diagnostics.d.ts +9 -0
- package/dist/src/commands/_run-diagnostics.js +51 -0
- package/dist/src/commands/_run-driver-helpers.d.ts +26 -0
- package/dist/src/commands/_run-driver-helpers.js +79 -230
- package/dist/src/commands/_run-projection.d.ts +50 -0
- package/dist/src/commands/_run-projection.js +349 -0
- package/dist/src/commands/_run-subcommands.d.ts +3 -0
- package/dist/src/commands/_run-subcommands.js +31 -0
- package/dist/src/commands/_spinner.d.ts +25 -0
- package/dist/src/commands/_spinner.js +65 -0
- package/dist/src/commands/agent.d.ts +3 -0
- package/dist/src/commands/agent.js +8575 -236
- package/dist/src/commands/dist.d.ts +28 -0
- package/dist/src/commands/dist.js +44 -29
- package/dist/src/commands/doctor.d.ts +3 -0
- package/dist/src/commands/doctor.js +219 -268
- package/dist/src/commands/github.d.ts +3 -0
- package/dist/src/commands/github.js +236 -188
- package/dist/src/commands/inbox.d.ts +28 -0
- package/dist/src/commands/inbox.js +530 -111
- package/dist/src/commands/init.d.ts +64 -0
- package/dist/src/commands/init.js +912 -705
- package/dist/src/commands/inspect.d.ts +20 -0
- package/dist/src/commands/inspect.js +709 -119
- package/dist/src/commands/pi.d.ts +3 -0
- package/dist/src/commands/pi.js +177 -0
- package/dist/src/commands/plugin.d.ts +16 -0
- package/dist/src/commands/plugin.js +576 -29
- package/dist/src/commands/profile-and-review.d.ts +4 -0
- package/dist/src/commands/profile-and-review.js +112 -67
- package/dist/src/commands/queue.d.ts +3 -0
- package/dist/src/commands/queue.js +20 -20
- package/dist/src/commands/remote.d.ts +3 -0
- package/dist/src/commands/remote.js +880 -50
- package/dist/src/commands/repo-git-harness.d.ts +5 -0
- package/dist/src/commands/repo-git-harness.js +78 -28
- package/dist/src/commands/run.d.ts +21 -0
- package/dist/src/commands/run.js +17701 -661
- package/dist/src/commands/server.d.ts +3 -0
- package/dist/src/commands/server.js +166 -303
- package/dist/src/commands/setup.d.ts +16 -0
- package/dist/src/commands/setup.js +244 -299
- package/dist/src/commands/stats.d.ts +15 -0
- package/dist/src/commands/stats.js +979 -0
- package/dist/src/commands/task-run-driver.d.ts +94 -0
- package/dist/src/commands/task-run-driver.js +116 -1961
- package/dist/src/commands/task.d.ts +35 -0
- package/dist/src/commands/task.js +676 -1201
- package/dist/src/commands/test.d.ts +3 -0
- package/dist/src/commands/test.js +15 -8
- package/dist/src/commands/triage.d.ts +11 -0
- package/dist/src/commands/triage.js +227 -0
- package/dist/src/commands/workspace.d.ts +3 -0
- package/dist/src/commands/workspace.js +18 -11
- package/dist/src/commands.d.ts +13 -0
- package/dist/src/commands.js +16792 -8055
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +16862 -8450
- package/dist/src/launcher.d.ts +61 -0
- package/dist/src/launcher.js +81 -13
- package/dist/src/operator-cli.d.ts +2 -0
- package/dist/src/operator-cli.js +17837 -0
- package/dist/src/operator-entry.d.ts +1 -0
- package/dist/src/operator-entry.js +3 -0
- package/dist/src/runner.d.ts +47 -0
- package/dist/src/runner.js +16 -22
- package/dist/src/withMutedConsole.d.ts +2 -0
- package/package.json +21 -8
- package/dist/src/commands/_authority-runs.js +0 -111
- package/dist/src/commands/_operator-view.js +0 -340
- package/dist/src/commands/_preflight.js +0 -478
- package/dist/src/commands/_server-client.js +0 -382
- package/dist/src/commands/_snapshot-upload.js +0 -331
- package/dist/src/commands/_task-picker.js +0 -48
- package/dist/src/commands/browser.js +0 -890
- package/dist/src/commands/connect.js +0 -180
- package/dist/src/commands/inspector.js +0 -256
- package/dist/src/commands/task-report-bug.js +0 -1083
- 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;
|
package/dist/src/launcher.js
CHANGED
|
@@ -1,9 +1,64 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/cli/src/launcher.ts
|
|
3
3
|
import { existsSync } from "fs";
|
|
4
|
-
import { resolve } from "path";
|
|
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,
|
|
@@ -26,7 +81,9 @@ function resolveProjectRoot({
|
|
|
26
81
|
return resolve(cwd, envProjectRoot);
|
|
27
82
|
}
|
|
28
83
|
const fallbackImportDir = importDir ?? cwd;
|
|
29
|
-
const
|
|
84
|
+
const execName = basename(execPath).toLowerCase();
|
|
85
|
+
const execCandidates = execName === "rig" || execName === "rig.exe" ? [resolve(execPath, "..", "..")] : [];
|
|
86
|
+
const candidates = [cwd, ...execCandidates, resolve(fallbackImportDir, "..")];
|
|
30
87
|
for (const candidate of candidates) {
|
|
31
88
|
const nearest = resolveNearestRigProjectRoot(candidate);
|
|
32
89
|
if (hasRigProjectMarker(nearest)) {
|
|
@@ -45,14 +102,17 @@ function normalizeCliErrorCode(message, isCliError) {
|
|
|
45
102
|
return isCliError ? "CLI_ERROR" : "UNEXPECTED_ERROR";
|
|
46
103
|
}
|
|
47
104
|
function normalizeCliErrorPayload(error, CliErrorClass, options = {}) {
|
|
48
|
-
const isCliError = error instanceof CliErrorClass;
|
|
105
|
+
const isCliError = error instanceof CliErrorClass || error instanceof Error && error.name === "CliError" && typeof error.exitCode === "number";
|
|
49
106
|
const message = error instanceof Error ? error.message : String(error);
|
|
50
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;
|
|
51
110
|
const payload = {
|
|
52
111
|
ok: false,
|
|
53
112
|
code: normalizeCliErrorCode(message, isCliError),
|
|
54
113
|
message,
|
|
55
|
-
exitCode
|
|
114
|
+
exitCode,
|
|
115
|
+
...hint ? { hint } : {}
|
|
56
116
|
};
|
|
57
117
|
if (options.debug && error instanceof Error && error.stack) {
|
|
58
118
|
return { ...payload, stack: error.stack };
|
|
@@ -95,14 +155,19 @@ async function runRigCli(module, options = {}) {
|
|
|
95
155
|
const context = await module.initializeRuntime(runtimeOptions);
|
|
96
156
|
const outcome = await module.execute(context, runIdResult.rest);
|
|
97
157
|
if (outputMode === "json") {
|
|
98
|
-
io.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
+
}
|
|
106
171
|
}
|
|
107
172
|
} catch (error) {
|
|
108
173
|
const payload = normalizeCliErrorPayload(error, module.CliError, { debug: debugErrors });
|
|
@@ -110,6 +175,9 @@ async function runRigCli(module, options = {}) {
|
|
|
110
175
|
io.error(JSON.stringify(payload, null, 2));
|
|
111
176
|
} else {
|
|
112
177
|
io.error(debugErrors && payload.stack ? payload.stack : payload.message);
|
|
178
|
+
if (payload.hint) {
|
|
179
|
+
io.error(`Next: ${payload.hint}`);
|
|
180
|
+
}
|
|
113
181
|
}
|
|
114
182
|
process.exit(payload.exitCode);
|
|
115
183
|
}
|