@h-rig/cli 0.0.6-alpha.93 → 0.0.6-alpha.95
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 -27
- package/bin/rig.js +16 -0
- package/package.json +14 -40
- package/dist/bin/build-rig-binaries.d.ts +0 -2
- package/dist/bin/build-rig-binaries.js +0 -119
- package/dist/bin/rig.d.ts +0 -72
- package/dist/bin/rig.js +0 -17845
- package/dist/config/rig-default-config.yml +0 -5
- package/dist/src/app/drone-ui.d.ts +0 -34
- package/dist/src/app/drone-ui.js +0 -278
- package/dist/src/commands/_async-ui.d.ts +0 -10
- package/dist/src/commands/_async-ui.js +0 -121
- package/dist/src/commands/_cli-format.d.ts +0 -56
- package/dist/src/commands/_cli-format.js +0 -319
- package/dist/src/commands/_connection-state.d.ts +0 -54
- package/dist/src/commands/_connection-state.js +0 -187
- package/dist/src/commands/_doctor-checks.d.ts +0 -46
- package/dist/src/commands/_doctor-checks.js +0 -352
- package/dist/src/commands/_help-catalog.d.ts +0 -51
- package/dist/src/commands/_help-catalog.js +0 -502
- package/dist/src/commands/_inprocess-services.d.ts +0 -33
- package/dist/src/commands/_inprocess-services.js +0 -102
- package/dist/src/commands/_json-output.d.ts +0 -11
- package/dist/src/commands/_json-output.js +0 -60
- package/dist/src/commands/_lazy-reconcile.d.ts +0 -34
- package/dist/src/commands/_lazy-reconcile.js +0 -102
- package/dist/src/commands/_parsers.d.ts +0 -15
- package/dist/src/commands/_parsers.js +0 -114
- package/dist/src/commands/_paths.d.ts +0 -11
- package/dist/src/commands/_paths.js +0 -50
- package/dist/src/commands/_pi-frontend.d.ts +0 -35
- package/dist/src/commands/_pi-frontend.js +0 -64
- package/dist/src/commands/_pi-install.d.ts +0 -42
- package/dist/src/commands/_pi-install.js +0 -167
- package/dist/src/commands/_policy.d.ts +0 -8
- package/dist/src/commands/_policy.js +0 -127
- package/dist/src/commands/_probes.d.ts +0 -1
- package/dist/src/commands/_probes.js +0 -13
- package/dist/src/commands/_run-bridge.d.ts +0 -114
- package/dist/src/commands/_run-bridge.js +0 -387
- package/dist/src/commands/_run-diagnostics.d.ts +0 -9
- package/dist/src/commands/_run-diagnostics.js +0 -51
- package/dist/src/commands/_run-driver-helpers.d.ts +0 -26
- package/dist/src/commands/_run-driver-helpers.js +0 -138
- package/dist/src/commands/_run-projection.d.ts +0 -50
- package/dist/src/commands/_run-projection.js +0 -349
- package/dist/src/commands/_run-subcommands.d.ts +0 -3
- package/dist/src/commands/_run-subcommands.js +0 -31
- package/dist/src/commands/_spinner.d.ts +0 -25
- package/dist/src/commands/_spinner.js +0 -65
- package/dist/src/commands/agent.d.ts +0 -3
- package/dist/src/commands/agent.js +0 -8837
- package/dist/src/commands/dist.d.ts +0 -28
- package/dist/src/commands/dist.js +0 -417
- package/dist/src/commands/doctor.d.ts +0 -3
- package/dist/src/commands/doctor.js +0 -480
- package/dist/src/commands/github.d.ts +0 -3
- package/dist/src/commands/github.js +0 -342
- package/dist/src/commands/inbox.d.ts +0 -28
- package/dist/src/commands/inbox.js +0 -579
- package/dist/src/commands/init.d.ts +0 -64
- package/dist/src/commands/init.js +0 -1541
- package/dist/src/commands/inspect.d.ts +0 -20
- package/dist/src/commands/inspect.js +0 -764
- package/dist/src/commands/pi.d.ts +0 -3
- package/dist/src/commands/pi.js +0 -177
- package/dist/src/commands/plugin.d.ts +0 -16
- package/dist/src/commands/plugin.js +0 -714
- package/dist/src/commands/profile-and-review.d.ts +0 -4
- package/dist/src/commands/profile-and-review.js +0 -223
- package/dist/src/commands/queue.d.ts +0 -3
- package/dist/src/commands/queue.js +0 -197
- package/dist/src/commands/remote.d.ts +0 -3
- package/dist/src/commands/remote.js +0 -1337
- package/dist/src/commands/repo-git-harness.d.ts +0 -5
- package/dist/src/commands/repo-git-harness.js +0 -271
- package/dist/src/commands/run.d.ts +0 -21
- package/dist/src/commands/run.js +0 -17837
- package/dist/src/commands/server.d.ts +0 -3
- package/dist/src/commands/server.js +0 -249
- package/dist/src/commands/setup.d.ts +0 -16
- package/dist/src/commands/setup.js +0 -644
- package/dist/src/commands/stats.d.ts +0 -15
- package/dist/src/commands/stats.js +0 -979
- package/dist/src/commands/task-run-driver.d.ts +0 -94
- package/dist/src/commands/task-run-driver.js +0 -203
- package/dist/src/commands/task.d.ts +0 -35
- package/dist/src/commands/task.js +0 -818
- package/dist/src/commands/test.d.ts +0 -3
- package/dist/src/commands/test.js +0 -46
- package/dist/src/commands/triage.d.ts +0 -11
- package/dist/src/commands/triage.js +0 -227
- package/dist/src/commands/workspace.d.ts +0 -3
- package/dist/src/commands/workspace.js +0 -130
- package/dist/src/commands.d.ts +0 -13
- package/dist/src/commands.js +0 -17969
- package/dist/src/index.d.ts +0 -4
- package/dist/src/index.js +0 -17981
- package/dist/src/launcher.d.ts +0 -61
- package/dist/src/launcher.js +0 -199
- package/dist/src/operator-cli.d.ts +0 -2
- package/dist/src/operator-cli.js +0 -17837
- package/dist/src/operator-entry.d.ts +0 -1
- package/dist/src/operator-entry.js +0 -3
- package/dist/src/runner.d.ts +0 -47
- package/dist/src/runner.js +0 -267
- package/dist/src/withMutedConsole.d.ts +0 -2
- package/dist/src/withMutedConsole.js +0 -42
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// packages/cli/src/commands/_pi-install.ts
|
|
3
|
-
import { existsSync } from "fs";
|
|
4
|
-
import { homedir } from "os";
|
|
5
|
-
import { resolve } from "path";
|
|
6
|
-
var PI_RIG_PACKAGE_NAME = "@h-rig/pi-rig";
|
|
7
|
-
async function defaultCommandRunner(command, options = {}) {
|
|
8
|
-
const proc = Bun.spawn(command, { cwd: options.cwd, stdout: "pipe", stderr: "pipe" });
|
|
9
|
-
const [stdout, stderr, exitCode] = await Promise.all([
|
|
10
|
-
new Response(proc.stdout).text(),
|
|
11
|
-
new Response(proc.stderr).text(),
|
|
12
|
-
proc.exited
|
|
13
|
-
]);
|
|
14
|
-
return { exitCode, stdout, stderr };
|
|
15
|
-
}
|
|
16
|
-
function resolvePiRigExtensionPath(homeDir) {
|
|
17
|
-
return resolve(homeDir, ".pi", "agent", "extensions", "pi-rig");
|
|
18
|
-
}
|
|
19
|
-
function resolvePiRigPackageSource(projectRoot, exists = existsSync) {
|
|
20
|
-
const localPackage = resolve(projectRoot, "packages", "pi-rig");
|
|
21
|
-
if (exists(resolve(localPackage, "package.json")))
|
|
22
|
-
return localPackage;
|
|
23
|
-
return `npm:${PI_RIG_PACKAGE_NAME}`;
|
|
24
|
-
}
|
|
25
|
-
function resolvePiHomeDir(inputHomeDir) {
|
|
26
|
-
return inputHomeDir ?? process.env.RIG_PI_HOME_DIR?.trim() ?? homedir();
|
|
27
|
-
}
|
|
28
|
-
function piListContainsPiRig(output) {
|
|
29
|
-
return output.split(/\r?\n/).some((line) => {
|
|
30
|
-
const normalized = line.trim();
|
|
31
|
-
return normalized.includes(PI_RIG_PACKAGE_NAME) || /(?:^|[\\/])packages[\\/]pi-rig(?:$|\s)/.test(normalized);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
async function safeRun(runner, command, options) {
|
|
35
|
-
try {
|
|
36
|
-
return await runner(command, options);
|
|
37
|
-
} catch (error) {
|
|
38
|
-
return { exitCode: 1, stdout: "", stderr: error instanceof Error ? error.message : String(error) };
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function splitInstallCommand(value) {
|
|
42
|
-
return value.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g)?.map((part) => part.replace(/^['"]|['"]$/g, "")) ?? [];
|
|
43
|
-
}
|
|
44
|
-
async function ensurePiBinaryAvailable(input) {
|
|
45
|
-
const current = await safeRun(input.runner, ["pi", "--version"]);
|
|
46
|
-
if (current.exitCode === 0) {
|
|
47
|
-
const updateCommand = process.env.RIG_PI_UPDATE_COMMAND?.trim();
|
|
48
|
-
if (updateCommand) {
|
|
49
|
-
const parts2 = splitInstallCommand(updateCommand);
|
|
50
|
-
if (parts2.length > 0)
|
|
51
|
-
await safeRun(input.runner, parts2, input.projectRoot ? { cwd: input.projectRoot } : undefined);
|
|
52
|
-
}
|
|
53
|
-
return { ok: true, detail: (current.stdout || current.stderr).trim() || undefined };
|
|
54
|
-
}
|
|
55
|
-
const installCommand = process.env.RIG_PI_INSTALL_COMMAND?.trim();
|
|
56
|
-
if (!installCommand) {
|
|
57
|
-
return {
|
|
58
|
-
ok: false,
|
|
59
|
-
error: `${(current.stderr || current.stdout).trim() || "pi --version failed"}. Set RIG_PI_INSTALL_COMMAND to a supported installer or install Pi manually.`
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
const parts = splitInstallCommand(installCommand);
|
|
63
|
-
if (parts.length === 0) {
|
|
64
|
-
return { ok: false, error: (current.stderr || current.stdout).trim() || "pi --version failed" };
|
|
65
|
-
}
|
|
66
|
-
const install = await safeRun(input.runner, parts, input.projectRoot ? { cwd: input.projectRoot } : undefined);
|
|
67
|
-
if (install.exitCode !== 0) {
|
|
68
|
-
return { ok: false, installedOrUpdated: true, error: (install.stderr || install.stdout).trim() || `Pi install command failed (${install.exitCode})` };
|
|
69
|
-
}
|
|
70
|
-
const next = await safeRun(input.runner, ["pi", "--version"]);
|
|
71
|
-
return {
|
|
72
|
-
ok: next.exitCode === 0,
|
|
73
|
-
installedOrUpdated: true,
|
|
74
|
-
detail: (next.stdout || next.stderr).trim() || undefined,
|
|
75
|
-
...next.exitCode === 0 ? {} : { error: (next.stderr || next.stdout).trim() || "pi --version failed after install" }
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
async function checkPiRigInstall(input = {}) {
|
|
79
|
-
const home = resolvePiHomeDir(input.homeDir);
|
|
80
|
-
const extensionPath = resolvePiRigExtensionPath(home);
|
|
81
|
-
if (process.env.RIG_TEST_FAKE_PI_INSTALL === "1") {
|
|
82
|
-
return {
|
|
83
|
-
extensionPath,
|
|
84
|
-
pi: { ok: true, label: "pi", detail: "fake-pi" },
|
|
85
|
-
piRig: { ok: true, label: "pi-rig global extension", detail: extensionPath }
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
const runner = input.commandRunner ?? defaultCommandRunner;
|
|
89
|
-
const piResult = await safeRun(runner, ["pi", "--version"]);
|
|
90
|
-
const piListResult = piResult.exitCode === 0 ? await safeRun(runner, ["pi", "list"]) : { exitCode: 1, stdout: "", stderr: "" };
|
|
91
|
-
const hasPiRig = piListResult.exitCode === 0 && piListContainsPiRig(`${piListResult.stdout}
|
|
92
|
-
${piListResult.stderr}`);
|
|
93
|
-
const hasLegacyBridgeScaffold = !hasPiRig && (input.exists ?? existsSync)(extensionPath);
|
|
94
|
-
return {
|
|
95
|
-
extensionPath,
|
|
96
|
-
pi: {
|
|
97
|
-
ok: piResult.exitCode === 0,
|
|
98
|
-
label: "pi",
|
|
99
|
-
detail: (piResult.stdout || piResult.stderr).trim() || undefined,
|
|
100
|
-
hint: piResult.exitCode === 0 ? undefined : "Install Pi/OMP manually or set RIG_PI_INSTALL_COMMAND before verifying with bare `rig` / Cockpit \u2192 Doctor."
|
|
101
|
-
},
|
|
102
|
-
piRig: {
|
|
103
|
-
ok: hasPiRig,
|
|
104
|
-
label: "pi-rig global extension",
|
|
105
|
-
detail: hasPiRig ? piListResult.stdout.trim() || PI_RIG_PACKAGE_NAME : hasLegacyBridgeScaffold ? `legacy bridge scaffold at ${extensionPath}` : undefined,
|
|
106
|
-
hint: hasPiRig ? undefined : `Install the Rig OMP extension with \`pi install ${PI_RIG_PACKAGE_NAME}\`, then verify with bare \`rig\` / Cockpit \u2192 Doctor.`
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
async function ensurePiRigInstalled(input) {
|
|
111
|
-
const home = resolvePiHomeDir(input.homeDir);
|
|
112
|
-
if (process.env.RIG_TEST_FAKE_PI_INSTALL === "1") {
|
|
113
|
-
const status = await checkPiRigInstall({ homeDir: home, commandRunner: input.commandRunner });
|
|
114
|
-
return { ...status, installedPath: status.extensionPath };
|
|
115
|
-
}
|
|
116
|
-
const runner = input.commandRunner ?? defaultCommandRunner;
|
|
117
|
-
const piAvailable = await ensurePiBinaryAvailable({ runner, projectRoot: input.projectRoot });
|
|
118
|
-
if (!piAvailable.ok) {
|
|
119
|
-
throw new Error(`Pi install/update failed: ${piAvailable.error ?? "pi unavailable"}`);
|
|
120
|
-
}
|
|
121
|
-
const packageSource = resolvePiRigPackageSource(input.projectRoot);
|
|
122
|
-
const install = await runner(["pi", "install", packageSource], { cwd: input.projectRoot });
|
|
123
|
-
if (install.exitCode !== 0) {
|
|
124
|
-
throw new Error(`pi-rig install failed: ${(install.stderr || install.stdout).trim() || `exit ${install.exitCode}`}`);
|
|
125
|
-
}
|
|
126
|
-
const next = await checkPiRigInstall({ homeDir: home, commandRunner: runner });
|
|
127
|
-
return { ...next, installedPath: packageSource };
|
|
128
|
-
}
|
|
129
|
-
async function ensureRemotePiRigInstalled(input) {
|
|
130
|
-
const payload = await input.requestJson("/api/pi-rig/install", {
|
|
131
|
-
method: "POST",
|
|
132
|
-
headers: { "content-type": "application/json" },
|
|
133
|
-
body: JSON.stringify({ package: PI_RIG_PACKAGE_NAME, scope: "global" })
|
|
134
|
-
});
|
|
135
|
-
const record = payload && typeof payload === "object" && !Array.isArray(payload) ? payload : {};
|
|
136
|
-
const piOk = record.piOk === true || record.ok === true;
|
|
137
|
-
const piRigOk = record.piRigOk === true || record.installed === true || record.ok === true;
|
|
138
|
-
const extensionPath = typeof record.extensionPath === "string" ? record.extensionPath : "remote:~/.pi/agent/extensions/pi-rig";
|
|
139
|
-
return {
|
|
140
|
-
remote: true,
|
|
141
|
-
extensionPath,
|
|
142
|
-
pi: {
|
|
143
|
-
ok: piOk,
|
|
144
|
-
label: "pi",
|
|
145
|
-
detail: typeof record.piVersion === "string" ? record.piVersion : undefined,
|
|
146
|
-
hint: piOk ? undefined : "Install/update Pi on the selected remote control host, then verify with bare `rig` / Cockpit \u2192 Doctor."
|
|
147
|
-
},
|
|
148
|
-
piRig: {
|
|
149
|
-
ok: piRigOk,
|
|
150
|
-
label: "pi-rig global extension",
|
|
151
|
-
detail: extensionPath,
|
|
152
|
-
hint: piRigOk ? undefined : `Install/enable the Rig OMP extension (${PI_RIG_PACKAGE_NAME}) on the selected remote control host, then verify with bare \`rig\` / Cockpit \u2192 Doctor.`
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
async function buildPiSetupChecks(input = {}) {
|
|
157
|
-
const status = await checkPiRigInstall(input);
|
|
158
|
-
return [status.pi, status.piRig];
|
|
159
|
-
}
|
|
160
|
-
export {
|
|
161
|
-
resolvePiRigPackageSource,
|
|
162
|
-
resolvePiRigExtensionPath,
|
|
163
|
-
ensureRemotePiRigInstalled,
|
|
164
|
-
ensurePiRigInstalled,
|
|
165
|
-
checkPiRigInstall,
|
|
166
|
-
buildPiSetupChecks
|
|
167
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type RunnerContext } from "../runner";
|
|
2
|
-
export type PolicyMode = "off" | "observe" | "enforce";
|
|
3
|
-
export declare function resolveEffectivePolicyMode(context: RunnerContext): PolicyMode;
|
|
4
|
-
export declare function appendControlledBashAudit(context: RunnerContext, mode: PolicyMode, command: string, args: string[], matchedRuleIds: string[], action?: "warn" | "blocked"): void;
|
|
5
|
-
export declare function enforceNativeCommandPolicy(context: RunnerContext, args: string[], options: {
|
|
6
|
-
commandPrefix: string;
|
|
7
|
-
writeAuditLog: boolean;
|
|
8
|
-
}): Promise<void>;
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// packages/cli/src/commands/_policy.ts
|
|
3
|
-
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "fs";
|
|
4
|
-
import { resolve as resolve2 } from "path";
|
|
5
|
-
|
|
6
|
-
// packages/cli/src/runner.ts
|
|
7
|
-
import { EventBus } from "@rig/runtime/control-plane/runtime/events";
|
|
8
|
-
import { CliError as RuntimeCliError } from "@rig/runtime/control-plane/errors";
|
|
9
|
-
import { evaluate, loadPolicy, resolveAction } from "@rig/runtime/control-plane/runtime/guard";
|
|
10
|
-
import { buildBinary } from "@rig/runtime/control-plane/runtime/isolation";
|
|
11
|
-
|
|
12
|
-
class CliError extends RuntimeCliError {
|
|
13
|
-
hint;
|
|
14
|
-
constructor(message, exitCode = 1, options = {}) {
|
|
15
|
-
super(message, exitCode);
|
|
16
|
-
if (options.hint?.trim()) {
|
|
17
|
-
this.hint = options.hint.trim();
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function formatCommand(parts) {
|
|
22
|
-
return parts.map((part) => /[^a-zA-Z0-9_./:-]/.test(part) ? JSON.stringify(part) : part).join(" ");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// packages/cli/src/commands/_paths.ts
|
|
26
|
-
import { resolve } from "path";
|
|
27
|
-
import { resolveMonorepoRoot } from "@rig/runtime/layout";
|
|
28
|
-
function resolveControlPlaneHostStateRoot(projectRoot) {
|
|
29
|
-
return resolve(projectRoot, ".rig");
|
|
30
|
-
}
|
|
31
|
-
function resolveControlPlaneHostLogsDir(projectRoot) {
|
|
32
|
-
return resolve(resolveControlPlaneHostStateRoot(projectRoot), "logs");
|
|
33
|
-
}
|
|
34
|
-
function resolveControlPlaneDefinitionRoot(projectRoot) {
|
|
35
|
-
return resolve(projectRoot, "rig");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// packages/cli/src/commands/_policy.ts
|
|
39
|
-
function loadPolicyFile(projectRoot) {
|
|
40
|
-
const policyPath = resolve2(resolveControlPlaneDefinitionRoot(projectRoot), "policy", "policy.json");
|
|
41
|
-
if (!existsSync(policyPath)) {
|
|
42
|
-
return { mode: "observe", rules: [] };
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
const parsed = JSON.parse(readFileSync(policyPath, "utf8"));
|
|
46
|
-
const mode = parsed.mode === "off" || parsed.mode === "observe" || parsed.mode === "enforce" ? parsed.mode : "observe";
|
|
47
|
-
const rules = Array.isArray(parsed.rules) ? parsed.rules.filter((value) => Boolean(value && typeof value === "object" && !Array.isArray(value))).map((value, index) => ({
|
|
48
|
-
id: typeof value.id === "string" && value.id.trim() ? value.id.trim() : `rule-${index + 1}`,
|
|
49
|
-
reason: typeof value.reason === "string" && value.reason.trim() ? value.reason.trim() : undefined,
|
|
50
|
-
match: typeof value.match === "string" && value.match.trim() ? value.match.trim() : undefined,
|
|
51
|
-
command: typeof value.command === "string" && value.command.trim() ? value.command.trim() : undefined
|
|
52
|
-
})) : [];
|
|
53
|
-
return { mode, rules };
|
|
54
|
-
} catch {
|
|
55
|
-
return { mode: "observe", rules: [] };
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function matchingRules(command, rules) {
|
|
59
|
-
return rules.filter((rule) => {
|
|
60
|
-
const rawPattern = rule.command ?? rule.match;
|
|
61
|
-
if (!rawPattern)
|
|
62
|
-
return false;
|
|
63
|
-
try {
|
|
64
|
-
return new RegExp(rawPattern, "i").test(command);
|
|
65
|
-
} catch {
|
|
66
|
-
return command.includes(rawPattern);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
function resolveEffectivePolicyMode(context) {
|
|
71
|
-
const envMode = process.env.RIG_BASH_MODE;
|
|
72
|
-
if (envMode === "off" || envMode === "observe" || envMode === "enforce") {
|
|
73
|
-
return envMode;
|
|
74
|
-
}
|
|
75
|
-
return context.policyMode ?? loadPolicyFile(context.projectRoot).mode;
|
|
76
|
-
}
|
|
77
|
-
function appendControlledBashAudit(context, mode, command, args, matchedRuleIds, action) {
|
|
78
|
-
if (mode === "off") {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const logsDir = resolveControlPlaneHostLogsDir(context.projectRoot);
|
|
82
|
-
const logFile = resolve2(logsDir, "controlled-bash.jsonl");
|
|
83
|
-
mkdirSync(logsDir, { recursive: true });
|
|
84
|
-
const payload = {
|
|
85
|
-
timestamp: new Date().toISOString(),
|
|
86
|
-
mode,
|
|
87
|
-
cwd: process.cwd(),
|
|
88
|
-
pid: process.pid,
|
|
89
|
-
ppid: process.ppid,
|
|
90
|
-
argv: args,
|
|
91
|
-
command,
|
|
92
|
-
matchedRuleIds
|
|
93
|
-
};
|
|
94
|
-
if (action) {
|
|
95
|
-
payload.action = action;
|
|
96
|
-
}
|
|
97
|
-
appendFileSync(logFile, `${JSON.stringify(payload)}
|
|
98
|
-
`, "utf-8");
|
|
99
|
-
}
|
|
100
|
-
async function enforceNativeCommandPolicy(context, args, options) {
|
|
101
|
-
const mode = resolveEffectivePolicyMode(context);
|
|
102
|
-
const command = formatCommand([options.commandPrefix, ...args]);
|
|
103
|
-
const rules = matchingRules(command, loadPolicyFile(context.projectRoot).rules);
|
|
104
|
-
const matchedRuleIds = rules.map((rule) => rule.id);
|
|
105
|
-
const action = rules.length === 0 ? "allow" : mode === "enforce" ? "block" : "warn";
|
|
106
|
-
await context.emitEvent("policy.decision", {
|
|
107
|
-
target: "command",
|
|
108
|
-
command,
|
|
109
|
-
mode,
|
|
110
|
-
allowed: action !== "block",
|
|
111
|
-
matchedRuleIds,
|
|
112
|
-
reasons: rules.map((rule) => rule.reason).filter(Boolean)
|
|
113
|
-
});
|
|
114
|
-
if (options.writeAuditLog) {
|
|
115
|
-
appendControlledBashAudit(context, mode, command, args, matchedRuleIds, action === "block" ? "blocked" : action === "warn" ? "warn" : undefined);
|
|
116
|
-
}
|
|
117
|
-
if (action === "block") {
|
|
118
|
-
throw new CliError(`Policy blocked command: ${command}`, 126, {
|
|
119
|
-
hint: "Review rig/policy/policy.json, or re-run with `--policy-mode observe` to log instead of block."
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
export {
|
|
124
|
-
resolveEffectivePolicyMode,
|
|
125
|
-
enforceNativeCommandPolicy,
|
|
126
|
-
appendControlledBashAudit
|
|
127
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function runQuietBinaryProbe(binaryPath: string, args: string[], cwd: string): Promise<boolean>;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
// packages/cli/src/commands/_probes.ts
|
|
3
|
-
async function runQuietBinaryProbe(binaryPath, args, cwd) {
|
|
4
|
-
try {
|
|
5
|
-
const run = await Bun.$`${binaryPath} ${args}`.cwd(cwd).quiet().nothrow();
|
|
6
|
-
return run.exitCode === 0;
|
|
7
|
-
} catch {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export {
|
|
12
|
-
runQuietBinaryProbe
|
|
13
|
-
};
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import type { ChildProcess, SpawnOptions } from "node:child_process";
|
|
2
|
-
import { type RegisteredTaskSource } from "@rig/contracts";
|
|
3
|
-
import { type CollabRegistryFilter, type LiveCollabProjection } from "@oh-my-pi/pi-coding-agent/collab/api";
|
|
4
|
-
export type RigExtensionTask = {
|
|
5
|
-
readonly id: string;
|
|
6
|
-
readonly title?: string | null;
|
|
7
|
-
readonly status?: string | null;
|
|
8
|
-
readonly source?: string | null;
|
|
9
|
-
readonly url?: string | null;
|
|
10
|
-
readonly body?: string | null;
|
|
11
|
-
};
|
|
12
|
-
export type RigExtensionServerState = {
|
|
13
|
-
readonly alias: string;
|
|
14
|
-
readonly kind: "local" | "remote";
|
|
15
|
-
readonly baseUrl?: string | null;
|
|
16
|
-
readonly projectRoot?: string | null;
|
|
17
|
-
readonly status?: string | null;
|
|
18
|
-
readonly taskSource?: string | null;
|
|
19
|
-
};
|
|
20
|
-
export type RigExtensionAttachResult = {
|
|
21
|
-
readonly sessionPath?: string | null;
|
|
22
|
-
readonly joinLink?: string | null;
|
|
23
|
-
readonly collabSessionId?: string | null;
|
|
24
|
-
};
|
|
25
|
-
export type RunRunProcessInput = {
|
|
26
|
-
readonly projectRoot?: string;
|
|
27
|
-
readonly taskId: string;
|
|
28
|
-
readonly runId?: string;
|
|
29
|
-
readonly title?: string | null;
|
|
30
|
-
readonly model?: string | null;
|
|
31
|
-
readonly prompt?: string | null;
|
|
32
|
-
readonly rigRunBin?: string;
|
|
33
|
-
readonly writeStdout?: (text: string) => void;
|
|
34
|
-
};
|
|
35
|
-
export type RunRunProcessResult = {
|
|
36
|
-
readonly runId: string;
|
|
37
|
-
readonly pid: number;
|
|
38
|
-
readonly sessionName: string;
|
|
39
|
-
readonly runtime: unknown;
|
|
40
|
-
};
|
|
41
|
-
export type RunRunProcess = (input: RunRunProcessInput) => Promise<RunRunProcessResult>;
|
|
42
|
-
type SpawnFunction = (command: string, args: readonly string[], options: SpawnOptions) => ChildProcess;
|
|
43
|
-
type ListTasksDeps = {
|
|
44
|
-
readonly loadTaskSource?: (projectRoot: string) => Promise<{
|
|
45
|
-
readonly kind: string;
|
|
46
|
-
readonly source: RegisteredTaskSource;
|
|
47
|
-
}>;
|
|
48
|
-
};
|
|
49
|
-
type SpawnRunProcessDeps = {
|
|
50
|
-
readonly runRunProcess?: RunRunProcess;
|
|
51
|
-
readonly spawn?: SpawnFunction;
|
|
52
|
-
readonly uuid?: () => string;
|
|
53
|
-
readonly resolveRigRunBin?: () => string;
|
|
54
|
-
readonly env?: NodeJS.ProcessEnv;
|
|
55
|
-
};
|
|
56
|
-
type AttachViaRelayDeps = {
|
|
57
|
-
readonly listActiveCollabSessions?: (filter: CollabRegistryFilter) => Promise<readonly LiveCollabProjection[]>;
|
|
58
|
-
readonly sleep?: (ms: number) => Promise<void>;
|
|
59
|
-
readonly now?: () => number;
|
|
60
|
-
};
|
|
61
|
-
export type SpawnRunProcessInput = {
|
|
62
|
-
readonly projectRoot: string;
|
|
63
|
-
readonly taskId: string;
|
|
64
|
-
readonly title?: string | null;
|
|
65
|
-
};
|
|
66
|
-
export type AttachViaRelayInput = {
|
|
67
|
-
readonly runId: string;
|
|
68
|
-
readonly taskId?: string | null;
|
|
69
|
-
readonly identityFilter: CollabRegistryFilter;
|
|
70
|
-
readonly timeoutMs?: number;
|
|
71
|
-
readonly pollIntervalMs?: number;
|
|
72
|
-
};
|
|
73
|
-
export declare function listTasksFromSource(projectRoot: string, deps?: ListTasksDeps): Promise<readonly RigExtensionTask[]>;
|
|
74
|
-
export declare function getTaskFromSource(projectRoot: string, taskId: string, deps?: ListTasksDeps): Promise<RigExtensionTask | null>;
|
|
75
|
-
export declare function readSelectedTarget(projectRoot: string, env?: NodeJS.ProcessEnv): Promise<RigExtensionServerState>;
|
|
76
|
-
export declare function resolveRigRunBin(): string;
|
|
77
|
-
export declare function spawnRunProcess(input: SpawnRunProcessInput, deps?: SpawnRunProcessDeps): Promise<{
|
|
78
|
-
readonly runId: string;
|
|
79
|
-
}>;
|
|
80
|
-
export type RunControl = {
|
|
81
|
-
readonly kind: "steer";
|
|
82
|
-
readonly message: string;
|
|
83
|
-
} | {
|
|
84
|
-
readonly kind: "stop";
|
|
85
|
-
readonly reason: string;
|
|
86
|
-
};
|
|
87
|
-
export interface DeliverRemoteControlDeps {
|
|
88
|
-
readonly env?: NodeJS.ProcessEnv;
|
|
89
|
-
readonly spawn?: SpawnFunction;
|
|
90
|
-
}
|
|
91
|
-
interface RemoteControlContext {
|
|
92
|
-
readonly checkout?: string | null;
|
|
93
|
-
readonly registryBaseUrl?: string | null;
|
|
94
|
-
readonly namespaceKey?: string | null;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Build the remote shell command that re-runs the operator's control VERB on the
|
|
98
|
-
* remote host. The run is LOCAL there (its session journal lives on the remote
|
|
99
|
-
* disk), so `rig run steer/stop <runId>` resolves it locally and the remote
|
|
100
|
-
* worker's own localRunChanges consumer applies it — fully symmetric with local
|
|
101
|
-
* placement. We SSH the verb (not a pre-built sentinel) so the remote rebuilds via
|
|
102
|
-
* its canonical stop path. Identity is passed inline (SSH does not forward local
|
|
103
|
-
* env); the registry HMAC secret is read from the remote env, never sent over argv.
|
|
104
|
-
*/
|
|
105
|
-
export declare function buildRemoteControlCommand(runId: string, control: RunControl, ctx: RemoteControlContext): string;
|
|
106
|
-
/**
|
|
107
|
-
* Deliver a steer/stop control to a REMOTE run by running the verb on the remote
|
|
108
|
-
* host over SSH (login shell, identical to spawnRunProcess). Awaits the remote
|
|
109
|
-
* exit code so the operator gets an honest success/failure — not fire-and-forget.
|
|
110
|
-
*/
|
|
111
|
-
export declare function deliverRemoteRunControl(projectRoot: string, runId: string, control: RunControl, deps?: DeliverRemoteControlDeps): Promise<void>;
|
|
112
|
-
export declare function listActiveRunCollab(filter: CollabRegistryFilter): Promise<readonly LiveCollabProjection[]>;
|
|
113
|
-
export declare function attachViaRelay(input: AttachViaRelayInput, deps?: AttachViaRelayDeps): Promise<RigExtensionAttachResult | null>;
|
|
114
|
-
export {};
|