@h-rig/cli 0.0.6-alpha.22 → 0.0.6-alpha.221

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 (49) hide show
  1. package/README.md +6 -28
  2. package/package.json +9 -29
  3. package/dist/bin/build-rig-binaries.js +0 -107
  4. package/dist/bin/rig.js +0 -10655
  5. package/dist/src/commands/_authority-runs.js +0 -111
  6. package/dist/src/commands/_cli-format.js +0 -106
  7. package/dist/src/commands/_connection-state.js +0 -123
  8. package/dist/src/commands/_doctor-checks.js +0 -507
  9. package/dist/src/commands/_operator-surface.js +0 -204
  10. package/dist/src/commands/_operator-view.js +0 -731
  11. package/dist/src/commands/_parsers.js +0 -107
  12. package/dist/src/commands/_paths.js +0 -50
  13. package/dist/src/commands/_pi-install.js +0 -185
  14. package/dist/src/commands/_policy.js +0 -79
  15. package/dist/src/commands/_preflight.js +0 -483
  16. package/dist/src/commands/_probes.js +0 -13
  17. package/dist/src/commands/_run-driver-helpers.js +0 -289
  18. package/dist/src/commands/_server-client.js +0 -435
  19. package/dist/src/commands/_snapshot-upload.js +0 -318
  20. package/dist/src/commands/_task-picker.js +0 -76
  21. package/dist/src/commands/agent.js +0 -499
  22. package/dist/src/commands/browser.js +0 -890
  23. package/dist/src/commands/connect.js +0 -180
  24. package/dist/src/commands/dist.js +0 -402
  25. package/dist/src/commands/doctor.js +0 -517
  26. package/dist/src/commands/github.js +0 -281
  27. package/dist/src/commands/inbox.js +0 -160
  28. package/dist/src/commands/init.js +0 -1563
  29. package/dist/src/commands/inspect.js +0 -174
  30. package/dist/src/commands/inspector.js +0 -256
  31. package/dist/src/commands/plugin.js +0 -167
  32. package/dist/src/commands/profile-and-review.js +0 -178
  33. package/dist/src/commands/queue.js +0 -198
  34. package/dist/src/commands/remote.js +0 -507
  35. package/dist/src/commands/repo-git-harness.js +0 -221
  36. package/dist/src/commands/run.js +0 -1258
  37. package/dist/src/commands/server.js +0 -373
  38. package/dist/src/commands/setup.js +0 -687
  39. package/dist/src/commands/task-report-bug.js +0 -1083
  40. package/dist/src/commands/task-run-driver.js +0 -2554
  41. package/dist/src/commands/task.js +0 -1842
  42. package/dist/src/commands/test.js +0 -39
  43. package/dist/src/commands/workspace.js +0 -123
  44. package/dist/src/commands.js +0 -10334
  45. package/dist/src/index.js +0 -10673
  46. package/dist/src/launcher.js +0 -133
  47. package/dist/src/report-bug.js +0 -260
  48. package/dist/src/runner.js +0 -273
  49. package/dist/src/withMutedConsole.js +0 -42
@@ -1,107 +0,0 @@
1
- // @bun
2
- var __require = import.meta.require;
3
-
4
- // packages/cli/src/commands/_parsers.ts
5
- import { homedir } from "os";
6
- import { resolve } from "path";
7
-
8
- // packages/cli/src/runner.ts
9
- import { EventBus } from "@rig/runtime/control-plane/runtime/events";
10
- import { CliError } from "@rig/runtime/control-plane/errors";
11
- import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
12
- import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
13
- import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
14
- import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
15
- import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
16
-
17
- // packages/cli/src/commands/_parsers.ts
18
- function parsePositiveInt(value, option, fallback) {
19
- if (!value) {
20
- return fallback;
21
- }
22
- const parsed = Number.parseInt(value, 10);
23
- if (!Number.isFinite(parsed) || parsed <= 0) {
24
- throw new CliError2(`Invalid ${option} value: ${value}`);
25
- }
26
- return parsed;
27
- }
28
- function parseOptionalPositiveInt(value, option) {
29
- if (!value) {
30
- return;
31
- }
32
- const parsed = Number.parseInt(value, 10);
33
- if (!Number.isFinite(parsed) || parsed <= 0) {
34
- throw new CliError2(`Invalid ${option} value: ${value}`);
35
- }
36
- return parsed;
37
- }
38
- function parseRequiredPositiveInt(value, option) {
39
- if (!value) {
40
- throw new CliError2(`Missing value for ${option}.`);
41
- }
42
- const parsed = Number.parseInt(value, 10);
43
- if (!Number.isFinite(parsed) || parsed <= 0) {
44
- throw new CliError2(`Invalid ${option} value: ${value}`);
45
- }
46
- return parsed;
47
- }
48
- function parseAction(value) {
49
- if (!value || value === "validate") {
50
- return "validate";
51
- }
52
- if (value === "verify") {
53
- return "verify";
54
- }
55
- if (value === "pipeline") {
56
- return "pipeline";
57
- }
58
- throw new CliError2(`Invalid --action value: ${value}. Use validate, verify, or pipeline.`);
59
- }
60
- function parseIsolationMode(value, allowOff) {
61
- if (!value) {
62
- return "worktree";
63
- }
64
- if (value === "worktree") {
65
- return value;
66
- }
67
- if (allowOff && value === "off") {
68
- return value;
69
- }
70
- throw new CliError2(`Invalid isolation mode: ${value}. Use ${allowOff ? "off|" : ""}worktree.`);
71
- }
72
- function parseInstallScope(value) {
73
- if (!value || value === "user") {
74
- return "user";
75
- }
76
- if (value === "system") {
77
- return "system";
78
- }
79
- throw new CliError2(`Invalid --scope value: ${value}. Use user|system.`);
80
- }
81
- function resolveInstallDir(scope, explicitPath) {
82
- if (explicitPath) {
83
- return resolve(explicitPath);
84
- }
85
- if (scope === "system") {
86
- return "/usr/local/bin";
87
- }
88
- return resolve(homedir(), ".local/bin");
89
- }
90
- async function loadRigConfigOrNull(projectRoot) {
91
- try {
92
- const { loadConfig } = await import("@rig/core/load-config");
93
- return await loadConfig(projectRoot);
94
- } catch {
95
- return null;
96
- }
97
- }
98
- export {
99
- resolveInstallDir,
100
- parseRequiredPositiveInt,
101
- parsePositiveInt,
102
- parseOptionalPositiveInt,
103
- parseIsolationMode,
104
- parseInstallScope,
105
- parseAction,
106
- loadRigConfigOrNull
107
- };
@@ -1,50 +0,0 @@
1
- // @bun
2
- // packages/cli/src/commands/_paths.ts
3
- import { resolve } from "path";
4
- import { resolveMonorepoRoot } from "@rig/runtime/control-plane/native/utils";
5
- function resolveControlPlaneMonorepoRoot(projectRoot) {
6
- return resolveMonorepoRoot(projectRoot);
7
- }
8
- function resolveControlPlaneTaskConfigPath(projectRoot) {
9
- return resolve(resolveControlPlaneMonorepoRoot(projectRoot), ".rig", "task-config.json");
10
- }
11
- function resolveControlPlaneHostStateRoot(projectRoot) {
12
- return resolve(projectRoot, ".rig");
13
- }
14
- function resolveControlPlaneHostStateDir(projectRoot) {
15
- return resolve(resolveControlPlaneHostStateRoot(projectRoot), "state");
16
- }
17
- function resolveControlPlaneHostLogsDir(projectRoot) {
18
- return resolve(resolveControlPlaneHostStateRoot(projectRoot), "logs");
19
- }
20
- function resolveControlPlaneHostBinDir(projectRoot) {
21
- return resolve(resolveControlPlaneHostStateRoot(projectRoot), "bin");
22
- }
23
- function resolveControlPlaneHostDistDir(projectRoot) {
24
- return resolve(resolveControlPlaneHostStateRoot(projectRoot), "dist");
25
- }
26
- function resolveControlPlaneMonorepoStateRoot(projectRoot) {
27
- return resolve(resolveControlPlaneMonorepoRoot(projectRoot), ".rig");
28
- }
29
- function resolveControlPlaneMonorepoRuntimeDir(projectRoot) {
30
- return resolve(resolveControlPlaneMonorepoStateRoot(projectRoot), "runtime");
31
- }
32
- function resolveControlPlaneArtifactsDir(projectRoot) {
33
- return resolve(resolveControlPlaneMonorepoRoot(projectRoot), "artifacts");
34
- }
35
- function resolveControlPlaneDefinitionRoot(projectRoot) {
36
- return resolve(projectRoot, "rig");
37
- }
38
- export {
39
- resolveControlPlaneTaskConfigPath,
40
- resolveControlPlaneMonorepoStateRoot,
41
- resolveControlPlaneMonorepoRuntimeDir,
42
- resolveControlPlaneMonorepoRoot,
43
- resolveControlPlaneHostStateRoot,
44
- resolveControlPlaneHostStateDir,
45
- resolveControlPlaneHostLogsDir,
46
- resolveControlPlaneHostDistDir,
47
- resolveControlPlaneHostBinDir,
48
- resolveControlPlaneDefinitionRoot,
49
- resolveControlPlaneArtifactsDir
50
- };
@@ -1,185 +0,0 @@
1
- // @bun
2
- // packages/cli/src/commands/_pi-install.ts
3
- import { existsSync, readFileSync, rmSync } from "fs";
4
- import { homedir } from "os";
5
- import { resolve } from "path";
6
- var PI_RIG_PACKAGE_NAME = "@h-rig/pi-rig";
7
- var LEGACY_PI_RIG_PACKAGE_NAME = "@rig/pi-rig";
8
- var LEGACY_PI_RIG_MARKER = `// Managed by Rig. Source package: @rig/pi-rig.
9
- export { default } from '@rig/pi-rig';
10
- `;
11
- async function defaultCommandRunner(command, options = {}) {
12
- const proc = Bun.spawn(command, { cwd: options.cwd, stdout: "pipe", stderr: "pipe" });
13
- const [stdout, stderr, exitCode] = await Promise.all([
14
- new Response(proc.stdout).text(),
15
- new Response(proc.stderr).text(),
16
- proc.exited
17
- ]);
18
- return { exitCode, stdout, stderr };
19
- }
20
- function resolvePiRigExtensionPath(homeDir) {
21
- return resolve(homeDir, ".pi", "agent", "extensions", "pi-rig");
22
- }
23
- function resolvePiRigPackageSource(projectRoot, exists = existsSync) {
24
- const localPackage = resolve(projectRoot, "packages", "pi-rig");
25
- if (exists(resolve(localPackage, "package.json")))
26
- return localPackage;
27
- return `npm:${PI_RIG_PACKAGE_NAME}`;
28
- }
29
- function resolvePiHomeDir(inputHomeDir) {
30
- return inputHomeDir ?? process.env.RIG_PI_HOME_DIR?.trim() ?? homedir();
31
- }
32
- function piListContainsPiRig(output) {
33
- return output.split(/\r?\n/).some((line) => {
34
- const normalized = line.trim();
35
- return normalized.includes(PI_RIG_PACKAGE_NAME) || normalized.includes(LEGACY_PI_RIG_PACKAGE_NAME) || /(?:^|[\\/])packages[\\/]pi-rig(?:$|\s)/.test(normalized);
36
- });
37
- }
38
- async function safeRun(runner, command, options) {
39
- try {
40
- return await runner(command, options);
41
- } catch (error) {
42
- return { exitCode: 1, stdout: "", stderr: error instanceof Error ? error.message : String(error) };
43
- }
44
- }
45
- function splitInstallCommand(value) {
46
- return value.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g)?.map((part) => part.replace(/^['"]|['"]$/g, "")) ?? [];
47
- }
48
- async function ensurePiBinaryAvailable(input) {
49
- const current = await safeRun(input.runner, ["pi", "--version"]);
50
- if (current.exitCode === 0) {
51
- const updateCommand = process.env.RIG_PI_UPDATE_COMMAND?.trim();
52
- if (updateCommand) {
53
- const parts2 = splitInstallCommand(updateCommand);
54
- if (parts2.length > 0)
55
- await safeRun(input.runner, parts2, input.projectRoot ? { cwd: input.projectRoot } : undefined);
56
- }
57
- return { ok: true, detail: (current.stdout || current.stderr).trim() || undefined };
58
- }
59
- const installCommand = process.env.RIG_PI_INSTALL_COMMAND?.trim() || "bunx @earendil-works/pi@latest install";
60
- const parts = splitInstallCommand(installCommand);
61
- if (parts.length === 0) {
62
- return { ok: false, error: (current.stderr || current.stdout).trim() || "pi --version failed" };
63
- }
64
- const install = await safeRun(input.runner, parts, input.projectRoot ? { cwd: input.projectRoot } : undefined);
65
- if (install.exitCode !== 0) {
66
- return { ok: false, installedOrUpdated: true, error: (install.stderr || install.stdout).trim() || `Pi install command failed (${install.exitCode})` };
67
- }
68
- const next = await safeRun(input.runner, ["pi", "--version"]);
69
- return {
70
- ok: next.exitCode === 0,
71
- installedOrUpdated: true,
72
- detail: (next.stdout || next.stderr).trim() || undefined,
73
- ...next.exitCode === 0 ? {} : { error: (next.stderr || next.stdout).trim() || "pi --version failed after install" }
74
- };
75
- }
76
- function removeManagedLegacyPiRigBridge(homeDir, exists = existsSync) {
77
- const extensionPath = resolvePiRigExtensionPath(homeDir);
78
- const indexPath = resolve(extensionPath, "index.ts");
79
- if (!exists(indexPath))
80
- return;
81
- try {
82
- const content = readFileSync(indexPath, "utf8");
83
- if (content === LEGACY_PI_RIG_MARKER || content.includes("Managed by Rig. Source package: @rig/pi-rig")) {
84
- rmSync(extensionPath, { recursive: true, force: true });
85
- }
86
- } catch {}
87
- }
88
- async function checkPiRigInstall(input = {}) {
89
- const home = resolvePiHomeDir(input.homeDir);
90
- const extensionPath = resolvePiRigExtensionPath(home);
91
- if (process.env.RIG_TEST_FAKE_PI_INSTALL === "1") {
92
- return {
93
- extensionPath,
94
- pi: { ok: true, label: "pi", detail: "fake-pi" },
95
- piRig: { ok: true, label: "pi-rig global extension", detail: extensionPath }
96
- };
97
- }
98
- const exists = input.exists ?? existsSync;
99
- const runner = input.commandRunner ?? defaultCommandRunner;
100
- const piResult = await safeRun(runner, ["pi", "--version"]);
101
- const piListResult = piResult.exitCode === 0 ? await safeRun(runner, ["pi", "list"]) : { exitCode: 1, stdout: "", stderr: "" };
102
- const listedPiRig = piListResult.exitCode === 0 && piListContainsPiRig(`${piListResult.stdout}
103
- ${piListResult.stderr}`);
104
- const legacyBridge = exists(resolve(extensionPath, "index.ts"));
105
- const hasPiRig = listedPiRig;
106
- return {
107
- extensionPath,
108
- pi: {
109
- ok: piResult.exitCode === 0,
110
- label: "pi",
111
- detail: (piResult.stdout || piResult.stderr).trim() || undefined,
112
- hint: piResult.exitCode === 0 ? undefined : "Install Pi or run `rig init --yes` to install/update the Pi runtime."
113
- },
114
- piRig: {
115
- ok: hasPiRig,
116
- label: "pi-rig global extension",
117
- detail: hasPiRig ? piListResult.stdout.trim() || PI_RIG_PACKAGE_NAME : legacyBridge ? `${extensionPath} (legacy bridge; reinstall required)` : undefined,
118
- hint: hasPiRig ? undefined : "Run `rig init --yes` to install/enable the global pi-rig package with `pi install`."
119
- }
120
- };
121
- }
122
- async function ensurePiRigInstalled(input) {
123
- const home = resolvePiHomeDir(input.homeDir);
124
- if (process.env.RIG_TEST_FAKE_PI_INSTALL === "1") {
125
- const status2 = await checkPiRigInstall({ homeDir: home, commandRunner: input.commandRunner });
126
- return { ...status2, installedPath: status2.extensionPath };
127
- }
128
- const runner = input.commandRunner ?? defaultCommandRunner;
129
- const piAvailable = await ensurePiBinaryAvailable({ runner, projectRoot: input.projectRoot });
130
- const status = piAvailable.ok ? await checkPiRigInstall({ homeDir: home, commandRunner: runner }) : {
131
- extensionPath: resolvePiRigExtensionPath(home),
132
- pi: { ok: false, label: "pi", detail: piAvailable.error, hint: "Install/update Pi with RIG_PI_INSTALL_COMMAND or install Pi manually." },
133
- piRig: { ok: false, label: "pi-rig global extension", hint: "Pi is required before pi-rig can be installed." }
134
- };
135
- if (!piAvailable.ok) {
136
- throw new Error(`Pi install/update failed: ${piAvailable.error ?? "pi unavailable"}`);
137
- }
138
- const packageSource = resolvePiRigPackageSource(input.projectRoot);
139
- removeManagedLegacyPiRigBridge(home);
140
- const install = await runner(["pi", "install", packageSource], { cwd: input.projectRoot });
141
- if (install.exitCode !== 0) {
142
- throw new Error(`pi-rig install failed: ${(install.stderr || install.stdout).trim() || `exit ${install.exitCode}`}`);
143
- }
144
- const next = await checkPiRigInstall({ homeDir: home, commandRunner: runner });
145
- return { ...next, installedPath: packageSource };
146
- }
147
- async function ensureRemotePiRigInstalled(input) {
148
- const payload = await input.requestJson("/api/pi-rig/install", {
149
- method: "POST",
150
- headers: { "content-type": "application/json" },
151
- body: JSON.stringify({ package: PI_RIG_PACKAGE_NAME, scope: "global" })
152
- });
153
- const record = payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
154
- const piOk = record.piOk === true || record.ok === true;
155
- const piRigOk = record.piRigOk === true || record.installed === true || record.ok === true;
156
- const extensionPath = typeof record.extensionPath === "string" ? record.extensionPath : "remote:~/.pi/agent/extensions/pi-rig";
157
- return {
158
- remote: true,
159
- extensionPath,
160
- pi: {
161
- ok: piOk,
162
- label: "pi",
163
- detail: typeof record.piVersion === "string" ? record.piVersion : undefined,
164
- hint: piOk ? undefined : "Install/update Pi on the selected remote Rig server."
165
- },
166
- piRig: {
167
- ok: piRigOk,
168
- label: "pi-rig global extension",
169
- detail: extensionPath,
170
- hint: piRigOk ? undefined : "Install/enable pi-rig on the selected remote Rig server."
171
- }
172
- };
173
- }
174
- async function buildPiSetupChecks(input = {}) {
175
- const status = await checkPiRigInstall(input);
176
- return [status.pi, status.piRig];
177
- }
178
- export {
179
- resolvePiRigPackageSource,
180
- resolvePiRigExtensionPath,
181
- ensureRemotePiRigInstalled,
182
- ensurePiRigInstalled,
183
- checkPiRigInstall,
184
- buildPiSetupChecks
185
- };
@@ -1,79 +0,0 @@
1
- // @bun
2
- // packages/cli/src/commands/_policy.ts
3
- import { appendFileSync, mkdirSync } from "fs";
4
- import { resolve } from "path";
5
-
6
- // packages/cli/src/runner.ts
7
- import { EventBus } from "@rig/runtime/control-plane/runtime/events";
8
- import { CliError } from "@rig/runtime/control-plane/errors";
9
- import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
10
- import { PluginManager } from "@rig/runtime/control-plane/runtime/plugins";
11
- import { loadRuntimeContextFromEnv } from "@rig/runtime/control-plane/runtime/context";
12
- import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
13
- import { CliError as CliError2 } from "@rig/runtime/control-plane/errors";
14
- function formatCommand(parts) {
15
- return parts.map((part) => /[^a-zA-Z0-9_./:-]/.test(part) ? JSON.stringify(part) : part).join(" ");
16
- }
17
-
18
- // packages/cli/src/commands/_policy.ts
19
- import { evaluate as evaluate2, loadPolicy as loadPolicy2, resolveAction as resolveAction2 } from "@rig/runtime/control-plane/runtime/guard";
20
- import { resolveHarnessPaths } from "@rig/runtime/control-plane/native/utils";
21
- function resolveEffectivePolicyMode(context) {
22
- const envMode = process.env.RIG_BASH_MODE;
23
- if (envMode === "off" || envMode === "observe" || envMode === "enforce") {
24
- return envMode;
25
- }
26
- return context.policyMode || loadPolicy2(context.projectRoot).mode;
27
- }
28
- function appendControlledBashAudit(context, mode, command, args, matchedRuleIds, action) {
29
- if (mode === "off") {
30
- return;
31
- }
32
- const logsDir = resolveHarnessPaths(context.projectRoot).logsDir;
33
- const logFile = resolve(logsDir, "controlled-bash.jsonl");
34
- mkdirSync(logsDir, { recursive: true });
35
- const payload = {
36
- timestamp: new Date().toISOString(),
37
- mode,
38
- cwd: process.cwd(),
39
- pid: process.pid,
40
- ppid: process.ppid,
41
- argv: args,
42
- command,
43
- matchedRuleIds
44
- };
45
- if (action) {
46
- payload.action = action;
47
- }
48
- appendFileSync(logFile, `${JSON.stringify(payload)}
49
- `, "utf-8");
50
- }
51
- async function enforceNativeCommandPolicy(context, args, options) {
52
- const mode = resolveEffectivePolicyMode(context);
53
- const command = formatCommand([options.commandPrefix, ...args]);
54
- const decision = evaluate2({
55
- projectRoot: context.projectRoot,
56
- evaluation: { type: "command", command }
57
- });
58
- const action = resolveAction2(mode, decision.matchedRules);
59
- const matchedRuleIds = decision.matchedRules.map((rule) => rule.id);
60
- await context.emitEvent("policy.decision", {
61
- target: "command",
62
- command,
63
- mode,
64
- allowed: action !== "block",
65
- matchedRuleIds,
66
- reasons: decision.matchedRules.map((rule) => rule.reason)
67
- });
68
- if (options.writeAuditLog) {
69
- appendControlledBashAudit(context, mode, command, args, matchedRuleIds, action === "block" ? "blocked" : action === "warn" ? "warn" : undefined);
70
- }
71
- if (action === "block") {
72
- throw new CliError2(`Policy blocked command: ${command}`, 126);
73
- }
74
- }
75
- export {
76
- resolveEffectivePolicyMode,
77
- enforceNativeCommandPolicy,
78
- appendControlledBashAudit
79
- };