@h-rig/cli 0.0.6-alpha.24 → 0.0.6-alpha.240
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 +6 -28
- package/package.json +13 -28
- package/dist/bin/build-rig-binaries.js +0 -107
- package/dist/bin/rig.js +0 -11112
- package/dist/src/commands/_authority-runs.js +0 -111
- package/dist/src/commands/_cli-format.js +0 -106
- package/dist/src/commands/_connection-state.js +0 -123
- package/dist/src/commands/_doctor-checks.js +0 -507
- package/dist/src/commands/_operator-surface.js +0 -204
- package/dist/src/commands/_operator-view.js +0 -1147
- package/dist/src/commands/_parsers.js +0 -107
- package/dist/src/commands/_paths.js +0 -50
- package/dist/src/commands/_pi-frontend.js +0 -843
- package/dist/src/commands/_pi-install.js +0 -185
- package/dist/src/commands/_pi-worker-bridge-extension.js +0 -761
- package/dist/src/commands/_policy.js +0 -79
- package/dist/src/commands/_preflight.js +0 -403
- package/dist/src/commands/_probes.js +0 -13
- package/dist/src/commands/_run-driver-helpers.js +0 -289
- package/dist/src/commands/_server-client.js +0 -514
- package/dist/src/commands/_snapshot-upload.js +0 -318
- package/dist/src/commands/_task-picker.js +0 -76
- package/dist/src/commands/agent.js +0 -499
- package/dist/src/commands/browser.js +0 -890
- package/dist/src/commands/connect.js +0 -180
- package/dist/src/commands/dist.js +0 -402
- package/dist/src/commands/doctor.js +0 -517
- package/dist/src/commands/github.js +0 -281
- package/dist/src/commands/inbox.js +0 -160
- package/dist/src/commands/init.js +0 -1563
- package/dist/src/commands/inspect.js +0 -174
- package/dist/src/commands/inspector.js +0 -256
- package/dist/src/commands/plugin.js +0 -167
- package/dist/src/commands/profile-and-review.js +0 -178
- package/dist/src/commands/queue.js +0 -198
- package/dist/src/commands/remote.js +0 -507
- package/dist/src/commands/repo-git-harness.js +0 -221
- package/dist/src/commands/run.js +0 -1674
- package/dist/src/commands/server.js +0 -373
- package/dist/src/commands/setup.js +0 -687
- package/dist/src/commands/task-report-bug.js +0 -1083
- package/dist/src/commands/task-run-driver.js +0 -2600
- package/dist/src/commands/task.js +0 -2178
- package/dist/src/commands/test.js +0 -39
- package/dist/src/commands/workspace.js +0 -123
- package/dist/src/commands.js +0 -10791
- package/dist/src/index.js +0 -11130
- package/dist/src/launcher.js +0 -133
- package/dist/src/report-bug.js +0 -260
- package/dist/src/runner.js +0 -273
- package/dist/src/withMutedConsole.js +0 -42
|
@@ -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
|
-
};
|