@h-rig/cli 0.0.6-alpha.15 → 0.0.6-alpha.150

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/bin/rig.js +16 -0
  3. package/package.json +14 -27
  4. package/dist/bin/build-rig-binaries.js +0 -107
  5. package/dist/bin/rig.js +0 -10076
  6. package/dist/src/commands/_authority-runs.js +0 -111
  7. package/dist/src/commands/_connection-state.js +0 -123
  8. package/dist/src/commands/_doctor-checks.js +0 -506
  9. package/dist/src/commands/_operator-surface.js +0 -157
  10. package/dist/src/commands/_operator-view.js +0 -449
  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 -184
  14. package/dist/src/commands/_policy.js +0 -79
  15. package/dist/src/commands/_preflight.js +0 -482
  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 -426
  19. package/dist/src/commands/_snapshot-upload.js +0 -318
  20. package/dist/src/commands/_task-picker.js +0 -56
  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 -516
  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 -1511
  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 -893
  37. package/dist/src/commands/server.js +0 -373
  38. package/dist/src/commands/setup.js +0 -686
  39. package/dist/src/commands/task-report-bug.js +0 -1083
  40. package/dist/src/commands/task-run-driver.js +0 -2442
  41. package/dist/src/commands/task.js +0 -1476
  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 -9755
  45. package/dist/src/index.js +0 -10094
  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,184 +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 = "@rig/pi-rig";
7
- var LEGACY_PI_RIG_MARKER = `// Managed by Rig. Source package: @rig/pi-rig.
8
- export { default } from '@rig/pi-rig';
9
- `;
10
- async function defaultCommandRunner(command, options = {}) {
11
- const proc = Bun.spawn(command, { cwd: options.cwd, stdout: "pipe", stderr: "pipe" });
12
- const [stdout, stderr, exitCode] = await Promise.all([
13
- new Response(proc.stdout).text(),
14
- new Response(proc.stderr).text(),
15
- proc.exited
16
- ]);
17
- return { exitCode, stdout, stderr };
18
- }
19
- function resolvePiRigExtensionPath(homeDir) {
20
- return resolve(homeDir, ".pi", "agent", "extensions", "pi-rig");
21
- }
22
- function resolvePiRigPackageSource(projectRoot, exists = existsSync) {
23
- const localPackage = resolve(projectRoot, "packages", "pi-rig");
24
- if (exists(resolve(localPackage, "package.json")))
25
- return localPackage;
26
- return `npm:${PI_RIG_PACKAGE_NAME}`;
27
- }
28
- function resolvePiHomeDir(inputHomeDir) {
29
- return inputHomeDir ?? process.env.RIG_PI_HOME_DIR?.trim() ?? homedir();
30
- }
31
- function piListContainsPiRig(output) {
32
- return output.split(/\r?\n/).some((line) => {
33
- const normalized = line.trim();
34
- return normalized.includes(PI_RIG_PACKAGE_NAME) || /(?:^|[\\/])packages[\\/]pi-rig(?:$|\s)/.test(normalized);
35
- });
36
- }
37
- async function safeRun(runner, command, options) {
38
- try {
39
- return await runner(command, options);
40
- } catch (error) {
41
- return { exitCode: 1, stdout: "", stderr: error instanceof Error ? error.message : String(error) };
42
- }
43
- }
44
- function splitInstallCommand(value) {
45
- return value.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g)?.map((part) => part.replace(/^['"]|['"]$/g, "")) ?? [];
46
- }
47
- async function ensurePiBinaryAvailable(input) {
48
- const current = await safeRun(input.runner, ["pi", "--version"]);
49
- if (current.exitCode === 0) {
50
- const updateCommand = process.env.RIG_PI_UPDATE_COMMAND?.trim();
51
- if (updateCommand) {
52
- const parts2 = splitInstallCommand(updateCommand);
53
- if (parts2.length > 0)
54
- await safeRun(input.runner, parts2, input.projectRoot ? { cwd: input.projectRoot } : undefined);
55
- }
56
- return { ok: true, detail: (current.stdout || current.stderr).trim() || undefined };
57
- }
58
- const installCommand = process.env.RIG_PI_INSTALL_COMMAND?.trim() || "bunx @earendil-works/pi@latest install";
59
- const parts = splitInstallCommand(installCommand);
60
- if (parts.length === 0) {
61
- return { ok: false, error: (current.stderr || current.stdout).trim() || "pi --version failed" };
62
- }
63
- const install = await safeRun(input.runner, parts, input.projectRoot ? { cwd: input.projectRoot } : undefined);
64
- if (install.exitCode !== 0) {
65
- return { ok: false, installedOrUpdated: true, error: (install.stderr || install.stdout).trim() || `Pi install command failed (${install.exitCode})` };
66
- }
67
- const next = await safeRun(input.runner, ["pi", "--version"]);
68
- return {
69
- ok: next.exitCode === 0,
70
- installedOrUpdated: true,
71
- detail: (next.stdout || next.stderr).trim() || undefined,
72
- ...next.exitCode === 0 ? {} : { error: (next.stderr || next.stdout).trim() || "pi --version failed after install" }
73
- };
74
- }
75
- function removeManagedLegacyPiRigBridge(homeDir, exists = existsSync) {
76
- const extensionPath = resolvePiRigExtensionPath(homeDir);
77
- const indexPath = resolve(extensionPath, "index.ts");
78
- if (!exists(indexPath))
79
- return;
80
- try {
81
- const content = readFileSync(indexPath, "utf8");
82
- if (content === LEGACY_PI_RIG_MARKER || content.includes("Managed by Rig. Source package: @rig/pi-rig")) {
83
- rmSync(extensionPath, { recursive: true, force: true });
84
- }
85
- } catch {}
86
- }
87
- async function checkPiRigInstall(input = {}) {
88
- const home = resolvePiHomeDir(input.homeDir);
89
- const extensionPath = resolvePiRigExtensionPath(home);
90
- if (process.env.RIG_TEST_FAKE_PI_INSTALL === "1") {
91
- return {
92
- extensionPath,
93
- pi: { ok: true, label: "pi", detail: "fake-pi" },
94
- piRig: { ok: true, label: "pi-rig global extension", detail: extensionPath }
95
- };
96
- }
97
- const exists = input.exists ?? existsSync;
98
- const runner = input.commandRunner ?? defaultCommandRunner;
99
- const piResult = await safeRun(runner, ["pi", "--version"]);
100
- const piListResult = piResult.exitCode === 0 ? await safeRun(runner, ["pi", "list"]) : { exitCode: 1, stdout: "", stderr: "" };
101
- const listedPiRig = piListResult.exitCode === 0 && piListContainsPiRig(`${piListResult.stdout}
102
- ${piListResult.stderr}`);
103
- const legacyBridge = exists(resolve(extensionPath, "index.ts"));
104
- const hasPiRig = listedPiRig;
105
- return {
106
- extensionPath,
107
- pi: {
108
- ok: piResult.exitCode === 0,
109
- label: "pi",
110
- detail: (piResult.stdout || piResult.stderr).trim() || undefined,
111
- hint: piResult.exitCode === 0 ? undefined : "Install Pi or run `rig init --yes` to install/update the Pi runtime."
112
- },
113
- piRig: {
114
- ok: hasPiRig,
115
- label: "pi-rig global extension",
116
- detail: hasPiRig ? piListResult.stdout.trim() || PI_RIG_PACKAGE_NAME : legacyBridge ? `${extensionPath} (legacy bridge; reinstall required)` : undefined,
117
- hint: hasPiRig ? undefined : "Run `rig init --yes` to install/enable the global pi-rig package with `pi install`."
118
- }
119
- };
120
- }
121
- async function ensurePiRigInstalled(input) {
122
- const home = resolvePiHomeDir(input.homeDir);
123
- if (process.env.RIG_TEST_FAKE_PI_INSTALL === "1") {
124
- const status2 = await checkPiRigInstall({ homeDir: home, commandRunner: input.commandRunner });
125
- return { ...status2, installedPath: status2.extensionPath };
126
- }
127
- const runner = input.commandRunner ?? defaultCommandRunner;
128
- const piAvailable = await ensurePiBinaryAvailable({ runner, projectRoot: input.projectRoot });
129
- const status = piAvailable.ok ? await checkPiRigInstall({ homeDir: home, commandRunner: runner }) : {
130
- extensionPath: resolvePiRigExtensionPath(home),
131
- pi: { ok: false, label: "pi", detail: piAvailable.error, hint: "Install/update Pi with RIG_PI_INSTALL_COMMAND or install Pi manually." },
132
- piRig: { ok: false, label: "pi-rig global extension", hint: "Pi is required before pi-rig can be installed." }
133
- };
134
- if (!piAvailable.ok) {
135
- throw new Error(`Pi install/update failed: ${piAvailable.error ?? "pi unavailable"}`);
136
- }
137
- const packageSource = resolvePiRigPackageSource(input.projectRoot);
138
- removeManagedLegacyPiRigBridge(home);
139
- const install = await runner(["pi", "install", packageSource], { cwd: input.projectRoot });
140
- if (install.exitCode !== 0) {
141
- throw new Error(`pi-rig install failed: ${(install.stderr || install.stdout).trim() || `exit ${install.exitCode}`}`);
142
- }
143
- const next = await checkPiRigInstall({ homeDir: home, commandRunner: runner });
144
- return { ...next, installedPath: packageSource };
145
- }
146
- async function ensureRemotePiRigInstalled(input) {
147
- const payload = await input.requestJson("/api/pi-rig/install", {
148
- method: "POST",
149
- headers: { "content-type": "application/json" },
150
- body: JSON.stringify({ package: "@rig/pi-rig", scope: "global" })
151
- });
152
- const record = payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
153
- const piOk = record.piOk === true || record.ok === true;
154
- const piRigOk = record.piRigOk === true || record.installed === true || record.ok === true;
155
- const extensionPath = typeof record.extensionPath === "string" ? record.extensionPath : "remote:~/.pi/agent/extensions/pi-rig";
156
- return {
157
- remote: true,
158
- extensionPath,
159
- pi: {
160
- ok: piOk,
161
- label: "pi",
162
- detail: typeof record.piVersion === "string" ? record.piVersion : undefined,
163
- hint: piOk ? undefined : "Install/update Pi on the selected remote Rig server."
164
- },
165
- piRig: {
166
- ok: piRigOk,
167
- label: "pi-rig global extension",
168
- detail: extensionPath,
169
- hint: piRigOk ? undefined : "Install/enable pi-rig on the selected remote Rig server."
170
- }
171
- };
172
- }
173
- async function buildPiSetupChecks(input = {}) {
174
- const status = await checkPiRigInstall(input);
175
- return [status.pi, status.piRig];
176
- }
177
- export {
178
- resolvePiRigPackageSource,
179
- resolvePiRigExtensionPath,
180
- ensureRemotePiRigInstalled,
181
- ensurePiRigInstalled,
182
- checkPiRigInstall,
183
- buildPiSetupChecks
184
- };
@@ -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
- };