@h-rig/cli-surface-plugin 0.0.6-alpha.157 → 0.0.6-alpha.158
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/dist/src/app/drone-ui.d.ts +0 -11
- package/dist/src/app/drone-ui.js +0 -114
- package/dist/src/commands/_async-ui.d.ts +1 -1
- package/dist/src/commands/_cli-format.d.ts +0 -29
- package/dist/src/commands/_cli-format.js +59 -113
- package/dist/src/commands/_connection-state.d.ts +6 -33
- package/dist/src/commands/_connection-state.js +654 -138
- package/dist/src/commands/_doctor-checks.d.ts +2 -5
- package/dist/src/commands/_doctor-checks.js +10 -9
- package/dist/src/commands/_help-catalog.d.ts +2 -1
- package/dist/src/commands/_help-catalog.js +654 -7
- package/dist/src/commands/_inprocess-services.d.ts +5 -5
- package/dist/src/commands/_inprocess-services.js +1 -1
- package/dist/src/commands/_parsers.js +651 -12
- package/dist/src/commands/_paths.d.ts +0 -2
- package/dist/src/commands/_paths.js +2 -10
- package/dist/src/commands/_pi-install.d.ts +2 -12
- package/dist/src/commands/_pi-install.js +3 -36
- package/dist/src/commands/_policy.js +659 -20
- package/dist/src/commands/agent.d.ts +1 -1
- package/dist/src/commands/agent.js +675 -24
- package/dist/src/commands/config.d.ts +1 -1
- package/dist/src/commands/config.js +656 -21
- package/dist/src/commands/dist.d.ts +1 -1
- package/dist/src/commands/dist.js +828 -102
- package/dist/src/commands/doctor.d.ts +1 -1
- package/dist/src/commands/doctor.js +658 -12
- package/dist/src/commands/github.d.ts +1 -1
- package/dist/src/commands/github.js +658 -19
- package/dist/src/commands/inbox.d.ts +12 -8
- package/dist/src/commands/inbox.js +741 -22
- package/dist/src/commands/init.d.ts +17 -19
- package/dist/src/commands/init.js +836 -306
- package/dist/src/commands/inspect.d.ts +5 -6
- package/dist/src/commands/inspect.js +754 -42
- package/dist/src/commands/pi.d.ts +1 -1
- package/dist/src/commands/pi.js +655 -16
- package/dist/src/commands/plugin.d.ts +9 -9
- package/dist/src/commands/plugin.js +652 -13
- package/dist/src/commands/profile-and-review.d.ts +1 -1
- package/dist/src/commands/profile-and-review.js +655 -16
- package/dist/src/commands/queue.d.ts +1 -1
- package/dist/src/commands/queue.js +871 -12
- package/dist/src/commands/remote-client.d.ts +152 -0
- package/dist/src/commands/remote-client.js +475 -0
- package/dist/src/commands/remote.d.ts +1 -1
- package/dist/src/commands/remote.js +1100 -29
- package/dist/src/commands/repo-git-harness.d.ts +1 -1
- package/dist/src/commands/repo-git-harness.js +2321 -47
- package/dist/src/commands/run.d.ts +10 -6
- package/dist/src/commands/run.js +830 -50
- package/dist/src/commands/server.d.ts +1 -1
- package/dist/src/commands/server.js +649 -11
- package/dist/src/commands/setup.d.ts +2 -2
- package/dist/src/commands/setup.js +829 -18
- package/dist/src/commands/stats.d.ts +2 -4
- package/dist/src/commands/stats.js +1299 -20
- package/dist/src/commands/test.d.ts +1 -1
- package/dist/src/commands/test.js +648 -9
- package/dist/src/commands/triage.d.ts +2 -3
- package/dist/src/commands/triage.js +657 -11
- package/dist/src/commands/workspace.d.ts +1 -1
- package/dist/src/commands/workspace.js +1280 -15
- package/dist/src/control-plane/agent-binary-build.d.ts +9 -0
- package/dist/src/control-plane/agent-binary-build.js +88 -0
- package/dist/src/control-plane/embedded-native-assets.d.ts +7 -0
- package/dist/src/control-plane/embedded-native-assets.js +6 -0
- package/dist/src/control-plane/guard.d.ts +17 -0
- package/dist/src/control-plane/guard.js +684 -0
- package/dist/src/control-plane/harness-cli.d.ts +12 -0
- package/dist/src/control-plane/harness-cli.js +1623 -0
- package/dist/src/control-plane/native/git-ops.d.ts +67 -0
- package/dist/src/control-plane/native/git-ops.js +1381 -0
- package/dist/src/control-plane/native/github-auth-env.d.ts +1 -0
- package/dist/src/control-plane/native/github-auth-env.js +21 -0
- package/dist/src/control-plane/native/host-git.d.ts +4 -0
- package/dist/src/control-plane/native/host-git.js +51 -0
- package/dist/src/control-plane/priority-queue.d.ts +22 -0
- package/dist/src/control-plane/priority-queue.js +212 -0
- package/dist/src/control-plane/rigfig.d.ts +9 -0
- package/dist/src/control-plane/rigfig.js +70 -0
- package/dist/src/control-plane/scope.d.ts +3 -0
- package/dist/src/control-plane/scope.js +58 -0
- package/dist/src/control-plane/setup-status.d.ts +44 -0
- package/dist/src/control-plane/setup-status.js +164 -0
- package/dist/src/control-plane/task-data.d.ts +2 -0
- package/dist/src/control-plane/task-data.js +12 -0
- package/dist/src/control-plane/workspace-ops.d.ts +79 -0
- package/dist/src/control-plane/workspace-ops.js +639 -0
- package/dist/src/help-catalog-data.d.ts +7 -0
- package/dist/src/help-catalog-data.js +660 -0
- package/dist/src/kernel-dispatch.js +1 -3
- package/dist/src/plugin.js +10072 -30
- package/dist/src/runner.d.ts +7 -9
- package/dist/src/runner.js +750 -30
- package/package.json +12 -13
- package/dist/src/commands/_json-output.d.ts +0 -11
- package/dist/src/commands/_json-output.js +0 -54
- package/dist/src/commands/_pi-frontend.d.ts +0 -35
- package/dist/src/commands/_pi-frontend.js +0 -64
- package/dist/src/commands/_run-driver-helpers.d.ts +0 -26
- package/dist/src/commands/_run-driver-helpers.js +0 -132
- package/dist/src/commands/task-run-driver.d.ts +0 -93
- package/dist/src/commands/task-run-driver.js +0 -136
- package/dist/src/commands/task.d.ts +0 -46
- package/dist/src/commands/task.js +0 -555
- package/dist/src/provider-model.d.ts +0 -34
- package/dist/src/provider-model.js +0 -56
- package/dist/src/rig-config-package-deps.d.ts +0 -10
- package/dist/src/rig-config-package-deps.js +0 -272
- package/dist/src/version.d.ts +0 -8
- package/dist/src/version.js +0 -47
|
@@ -2,22 +2,661 @@
|
|
|
2
2
|
var __require = import.meta.require;
|
|
3
3
|
|
|
4
4
|
// packages/cli-surface-plugin/src/commands/plugin.ts
|
|
5
|
-
import { existsSync } from "fs";
|
|
6
|
-
import { resolve } from "path";
|
|
5
|
+
import { existsSync as existsSync2 } from "fs";
|
|
6
|
+
import { resolve as resolve2 } from "path";
|
|
7
7
|
|
|
8
8
|
// packages/cli-surface-plugin/src/runner.ts
|
|
9
|
-
import { EventBus } from "@rig/runtime
|
|
10
|
-
import { CliError as RuntimeCliError } from "@rig/
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
import { EventBus } from "@rig/core/runtime-events";
|
|
10
|
+
import { CliError as RuntimeCliError } from "@rig/contracts";
|
|
11
|
+
|
|
12
|
+
// packages/cli-surface-plugin/src/control-plane/guard.ts
|
|
13
|
+
import { optimizeNextInvocation } from "bun:jsc";
|
|
14
|
+
import { existsSync, readFileSync, statSync } from "fs";
|
|
15
|
+
import { resolve } from "path";
|
|
16
|
+
|
|
17
|
+
// packages/cli-surface-plugin/src/control-plane/scope.ts
|
|
18
|
+
import { getScopeRules } from "@rig/core/scope-rules";
|
|
19
|
+
var scopeRegexCache = new Map;
|
|
20
|
+
function unique(values) {
|
|
21
|
+
return [...new Set(values)];
|
|
22
|
+
}
|
|
23
|
+
function normalizeRelativeScopePath(inputPath) {
|
|
24
|
+
let normalized = inputPath.replace(/^\.\//, "");
|
|
25
|
+
const rules = getScopeRules();
|
|
26
|
+
if (rules?.stripPrefixes) {
|
|
27
|
+
for (const prefix of rules.stripPrefixes) {
|
|
28
|
+
if (normalized.startsWith(prefix)) {
|
|
29
|
+
normalized = normalized.slice(prefix.length);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return normalized;
|
|
34
|
+
}
|
|
35
|
+
function normalizePathToScope(projectRoot, monorepoRoot, inputPath) {
|
|
36
|
+
let normalized = inputPath.replace(/^\.\//, "");
|
|
37
|
+
if (normalized.startsWith(projectRoot + "/")) {
|
|
38
|
+
normalized = normalized.slice(projectRoot.length + 1);
|
|
39
|
+
}
|
|
40
|
+
if (normalized.startsWith(monorepoRoot + "/")) {
|
|
41
|
+
normalized = normalized.slice(monorepoRoot.length + 1);
|
|
42
|
+
}
|
|
43
|
+
return normalizeRelativeScopePath(normalized);
|
|
44
|
+
}
|
|
45
|
+
function scopeGlobToRegex(glob) {
|
|
46
|
+
const cached = scopeRegexCache.get(glob);
|
|
47
|
+
if (cached) {
|
|
48
|
+
return cached;
|
|
49
|
+
}
|
|
50
|
+
const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "__GLOBSTAR__").replace(/\*/g, "[^/]*").replace(/__GLOBSTAR__/g, ".*");
|
|
51
|
+
const compiled = new RegExp(`^${escaped}$`);
|
|
52
|
+
scopeRegexCache.set(glob, compiled);
|
|
53
|
+
return compiled;
|
|
54
|
+
}
|
|
55
|
+
function scopeMatches(path, scopes) {
|
|
56
|
+
const pathVariants = unique([path, normalizeRelativeScopePath(path)]);
|
|
57
|
+
for (const scope of scopes) {
|
|
58
|
+
const scopeVariants = unique([scope, normalizeRelativeScopePath(scope)]);
|
|
59
|
+
for (const candidatePath of pathVariants) {
|
|
60
|
+
for (const candidateScope of scopeVariants) {
|
|
61
|
+
if (candidatePath === candidateScope || scopeGlobToRegex(candidateScope).test(candidatePath)) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// packages/cli-surface-plugin/src/control-plane/guard.ts
|
|
71
|
+
import {
|
|
72
|
+
POLICY_VERSION
|
|
73
|
+
} from "@rig/contracts";
|
|
74
|
+
var DEFAULT_SCOPE = {
|
|
75
|
+
fail_closed: true,
|
|
76
|
+
harness_paths_exempt: true,
|
|
77
|
+
runtime_paths_exempt: true
|
|
78
|
+
};
|
|
79
|
+
var DEFAULT_SANDBOX = {
|
|
80
|
+
mode: "enforce",
|
|
81
|
+
network: true,
|
|
82
|
+
read_deny: [],
|
|
83
|
+
write_allow_from_runtime: true
|
|
84
|
+
};
|
|
85
|
+
var DEFAULT_ISOLATION = {
|
|
86
|
+
default_mode: "worktree",
|
|
87
|
+
repo_symlink_fallback: false,
|
|
88
|
+
strict_provisioning: true,
|
|
89
|
+
fail_closed_on_provision_error: true
|
|
90
|
+
};
|
|
91
|
+
var DEFAULT_COMPLETION = {
|
|
92
|
+
derive_checks_from_scope: true,
|
|
93
|
+
checks: [],
|
|
94
|
+
typescript_config_probe: ["tsconfig.json"],
|
|
95
|
+
eslint_config_probe: [".eslintrc.js", ".eslintrc.json", "eslint.config.js"]
|
|
96
|
+
};
|
|
97
|
+
var DEFAULT_RUNTIME_IMAGE = {
|
|
98
|
+
deps: {
|
|
99
|
+
monorepo_install: false,
|
|
100
|
+
hp_next_install: false
|
|
101
|
+
},
|
|
102
|
+
plugins_require_binaries: true
|
|
103
|
+
};
|
|
104
|
+
var DEFAULT_RUNTIME_SNAPSHOT = {
|
|
105
|
+
enabled: true
|
|
106
|
+
};
|
|
107
|
+
function defaultPolicy() {
|
|
108
|
+
return {
|
|
109
|
+
version: POLICY_VERSION,
|
|
110
|
+
mode: "enforce",
|
|
111
|
+
scope: { ...DEFAULT_SCOPE },
|
|
112
|
+
rules: [],
|
|
113
|
+
sandbox: { ...DEFAULT_SANDBOX },
|
|
114
|
+
isolation: { ...DEFAULT_ISOLATION },
|
|
115
|
+
completion: { ...DEFAULT_COMPLETION },
|
|
116
|
+
runtime_image: {
|
|
117
|
+
deps: { ...DEFAULT_RUNTIME_IMAGE.deps },
|
|
118
|
+
plugins_require_binaries: DEFAULT_RUNTIME_IMAGE.plugins_require_binaries
|
|
119
|
+
},
|
|
120
|
+
runtime_snapshot: { ...DEFAULT_RUNTIME_SNAPSHOT }
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
var policyCache = null;
|
|
124
|
+
var policyCachePath = null;
|
|
125
|
+
var seededPolicyConfig = null;
|
|
126
|
+
var compiledRegexCache = new Map;
|
|
127
|
+
function loadPolicy(projectRoot) {
|
|
128
|
+
if (seededPolicyConfig) {
|
|
129
|
+
return seededPolicyConfig;
|
|
130
|
+
}
|
|
131
|
+
const configPath = resolve(projectRoot, "rig/policy/policy.json");
|
|
132
|
+
if (!existsSync(configPath)) {
|
|
133
|
+
return defaultPolicy();
|
|
134
|
+
}
|
|
135
|
+
let mtimeMs;
|
|
136
|
+
try {
|
|
137
|
+
mtimeMs = statSync(configPath).mtimeMs;
|
|
138
|
+
} catch {
|
|
139
|
+
return defaultPolicy();
|
|
140
|
+
}
|
|
141
|
+
if (policyCache && policyCachePath === configPath && policyCache.mtimeMs === mtimeMs) {
|
|
142
|
+
return policyCache.config;
|
|
143
|
+
}
|
|
144
|
+
let parsed;
|
|
145
|
+
try {
|
|
146
|
+
parsed = JSON.parse(readFileSync(configPath, "utf-8"));
|
|
147
|
+
} catch {
|
|
148
|
+
return defaultPolicy();
|
|
149
|
+
}
|
|
150
|
+
const config = mergeWithDefaults(parsed);
|
|
151
|
+
policyCache = { mtimeMs, config };
|
|
152
|
+
policyCachePath = configPath;
|
|
153
|
+
return config;
|
|
154
|
+
}
|
|
155
|
+
function mergeWithDefaults(parsed) {
|
|
156
|
+
const base = defaultPolicy();
|
|
157
|
+
if (typeof parsed.mode === "string" && isValidMode(parsed.mode)) {
|
|
158
|
+
base.mode = parsed.mode;
|
|
159
|
+
}
|
|
160
|
+
if (parsed.scope && typeof parsed.scope === "object" && !Array.isArray(parsed.scope)) {
|
|
161
|
+
const s = parsed.scope;
|
|
162
|
+
if (typeof s.fail_closed === "boolean")
|
|
163
|
+
base.scope.fail_closed = s.fail_closed;
|
|
164
|
+
if (typeof s.harness_paths_exempt === "boolean")
|
|
165
|
+
base.scope.harness_paths_exempt = s.harness_paths_exempt;
|
|
166
|
+
if (typeof s.runtime_paths_exempt === "boolean")
|
|
167
|
+
base.scope.runtime_paths_exempt = s.runtime_paths_exempt;
|
|
168
|
+
}
|
|
169
|
+
if (Array.isArray(parsed.rules)) {
|
|
170
|
+
base.rules = precompilePolicyRuleRegexes(parsed.rules.filter(isValidRule));
|
|
171
|
+
}
|
|
172
|
+
if (Array.isArray(parsed.deny) && base.rules.length === 0) {
|
|
173
|
+
base.rules = precompilePolicyRuleRegexes(migrateLegacyDeny(parsed.deny));
|
|
174
|
+
}
|
|
175
|
+
if (parsed.sandbox && typeof parsed.sandbox === "object" && !Array.isArray(parsed.sandbox)) {
|
|
176
|
+
const sb = parsed.sandbox;
|
|
177
|
+
if (typeof sb.mode === "string" && isValidMode(sb.mode))
|
|
178
|
+
base.sandbox.mode = sb.mode;
|
|
179
|
+
if (typeof sb.network === "boolean")
|
|
180
|
+
base.sandbox.network = sb.network;
|
|
181
|
+
if (Array.isArray(sb.read_deny))
|
|
182
|
+
base.sandbox.read_deny = sb.read_deny.filter((v) => typeof v === "string");
|
|
183
|
+
if (typeof sb.write_allow_from_runtime === "boolean")
|
|
184
|
+
base.sandbox.write_allow_from_runtime = sb.write_allow_from_runtime;
|
|
185
|
+
}
|
|
186
|
+
if (parsed.isolation && typeof parsed.isolation === "object" && !Array.isArray(parsed.isolation)) {
|
|
187
|
+
const iso = parsed.isolation;
|
|
188
|
+
if (iso.default_mode === "worktree")
|
|
189
|
+
base.isolation.default_mode = iso.default_mode;
|
|
190
|
+
if (typeof iso.repo_symlink_fallback === "boolean")
|
|
191
|
+
base.isolation.repo_symlink_fallback = iso.repo_symlink_fallback;
|
|
192
|
+
if (typeof iso.strict_provisioning === "boolean")
|
|
193
|
+
base.isolation.strict_provisioning = iso.strict_provisioning;
|
|
194
|
+
if (typeof iso.fail_closed_on_provision_error === "boolean")
|
|
195
|
+
base.isolation.fail_closed_on_provision_error = iso.fail_closed_on_provision_error;
|
|
196
|
+
}
|
|
197
|
+
if (parsed.completion && typeof parsed.completion === "object" && !Array.isArray(parsed.completion)) {
|
|
198
|
+
const comp = parsed.completion;
|
|
199
|
+
if (typeof comp.derive_checks_from_scope === "boolean")
|
|
200
|
+
base.completion.derive_checks_from_scope = comp.derive_checks_from_scope;
|
|
201
|
+
if (Array.isArray(comp.checks))
|
|
202
|
+
base.completion.checks = comp.checks.filter((v) => typeof v === "string");
|
|
203
|
+
if (Array.isArray(comp.typescript_config_probe))
|
|
204
|
+
base.completion.typescript_config_probe = comp.typescript_config_probe.filter((v) => typeof v === "string");
|
|
205
|
+
if (Array.isArray(comp.eslint_config_probe))
|
|
206
|
+
base.completion.eslint_config_probe = comp.eslint_config_probe.filter((v) => typeof v === "string");
|
|
207
|
+
}
|
|
208
|
+
if (parsed.runtime_image && typeof parsed.runtime_image === "object" && !Array.isArray(parsed.runtime_image)) {
|
|
209
|
+
const runtimeImage = parsed.runtime_image;
|
|
210
|
+
if (runtimeImage.deps && typeof runtimeImage.deps === "object" && !Array.isArray(runtimeImage.deps)) {
|
|
211
|
+
const deps = runtimeImage.deps;
|
|
212
|
+
if (typeof deps.monorepo_install === "boolean") {
|
|
213
|
+
base.runtime_image.deps.monorepo_install = deps.monorepo_install;
|
|
214
|
+
}
|
|
215
|
+
if (typeof deps.hp_next_install === "boolean") {
|
|
216
|
+
base.runtime_image.deps.hp_next_install = deps.hp_next_install;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (typeof runtimeImage.plugins_require_binaries === "boolean") {
|
|
220
|
+
base.runtime_image.plugins_require_binaries = runtimeImage.plugins_require_binaries;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (parsed.runtime_snapshot && typeof parsed.runtime_snapshot === "object" && !Array.isArray(parsed.runtime_snapshot)) {
|
|
224
|
+
const runtimeSnapshot = parsed.runtime_snapshot;
|
|
225
|
+
if (typeof runtimeSnapshot.enabled === "boolean") {
|
|
226
|
+
base.runtime_snapshot.enabled = runtimeSnapshot.enabled;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return base;
|
|
230
|
+
}
|
|
231
|
+
function isValidMode(value) {
|
|
232
|
+
return value === "off" || value === "observe" || value === "enforce";
|
|
233
|
+
}
|
|
234
|
+
function isValidRule(value) {
|
|
235
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
236
|
+
return false;
|
|
237
|
+
const r = value;
|
|
238
|
+
return typeof r.id === "string" && typeof r.category === "string" && r.match != null && typeof r.match === "object";
|
|
239
|
+
}
|
|
240
|
+
function migrateLegacyDeny(deny) {
|
|
241
|
+
const rules = [];
|
|
242
|
+
for (const entry of deny) {
|
|
243
|
+
if (typeof entry.id !== "string")
|
|
244
|
+
continue;
|
|
245
|
+
const match = {};
|
|
246
|
+
if (typeof entry.pattern === "string")
|
|
247
|
+
match.pattern = entry.pattern;
|
|
248
|
+
if (typeof entry.regex === "string")
|
|
249
|
+
match.regex = entry.regex;
|
|
250
|
+
if (!match.pattern && !match.regex)
|
|
251
|
+
continue;
|
|
252
|
+
rules.push({
|
|
253
|
+
id: entry.id,
|
|
254
|
+
category: "command",
|
|
255
|
+
match,
|
|
256
|
+
action: "block",
|
|
257
|
+
...typeof entry.description === "string" ? { description: entry.description } : {}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
return rules;
|
|
261
|
+
}
|
|
262
|
+
function precompilePolicyRuleRegexes(rules) {
|
|
263
|
+
return rules.map((rule) => {
|
|
264
|
+
const compiledRegex = rule.match.regex ? compileSafeRegex(rule.match.regex, `rules.${rule.id}.match.regex`, true) : undefined;
|
|
265
|
+
const compiledUnlessRegex = rule.unless?.regex ? compileSafeRegex(rule.unless.regex, `rules.${rule.id}.unless.regex`, true) : undefined;
|
|
266
|
+
return {
|
|
267
|
+
...rule,
|
|
268
|
+
...compiledRegex ? { compiledRegex } : {},
|
|
269
|
+
...compiledUnlessRegex ? { compiledUnlessRegex } : {}
|
|
270
|
+
};
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
function getRegexUnsafeReason(pattern) {
|
|
274
|
+
if (pattern.length > 512) {
|
|
275
|
+
return "pattern exceeds max safe length (512 chars)";
|
|
276
|
+
}
|
|
277
|
+
if (/\\[1-9]/.test(pattern)) {
|
|
278
|
+
return "pattern uses backreferences";
|
|
279
|
+
}
|
|
280
|
+
if (/\((?:[^()\\]|\\.)*[+*](?:[^()\\]|\\.)*\)\s*[*+{]/.test(pattern)) {
|
|
281
|
+
return "pattern contains nested quantifiers";
|
|
282
|
+
}
|
|
283
|
+
if (/\((?:[^()\\]|\\.)*\.\\?[+*](?:[^()\\]|\\.)*\)\s*[*+{]/.test(pattern)) {
|
|
284
|
+
return "pattern contains nested broad quantifiers";
|
|
285
|
+
}
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
function compileSafeRegex(pattern, sourceLabel, logOnFailure) {
|
|
289
|
+
const cached = compiledRegexCache.get(pattern);
|
|
290
|
+
if (cached !== undefined) {
|
|
291
|
+
return cached ?? undefined;
|
|
292
|
+
}
|
|
293
|
+
const unsafeReason = getRegexUnsafeReason(pattern);
|
|
294
|
+
if (unsafeReason) {
|
|
295
|
+
if (logOnFailure) {
|
|
296
|
+
console.warn(`[policy] Skipping unsafe regex in ${sourceLabel}: ${unsafeReason}`);
|
|
297
|
+
}
|
|
298
|
+
compiledRegexCache.set(pattern, null);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
try {
|
|
302
|
+
const compiled = new RegExp(pattern);
|
|
303
|
+
compiledRegexCache.set(pattern, compiled);
|
|
304
|
+
return compiled;
|
|
305
|
+
} catch (error) {
|
|
306
|
+
if (logOnFailure) {
|
|
307
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
308
|
+
console.warn(`[policy] Skipping invalid regex in ${sourceLabel}: ${message}`);
|
|
309
|
+
}
|
|
310
|
+
compiledRegexCache.set(pattern, null);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function matchRule(rule, input) {
|
|
315
|
+
const { match } = rule;
|
|
316
|
+
if (match.pattern && input.includes(match.pattern)) {
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
if (match.regex) {
|
|
320
|
+
const compiled = rule.compiledRegex || compileSafeRegex(match.regex, `rules.${rule.id}.match.regex`, false);
|
|
321
|
+
if (!compiled) {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
try {
|
|
325
|
+
return compiled.test(input);
|
|
326
|
+
} catch {
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
function matchRuleUnless(rule, command, taskId) {
|
|
333
|
+
if (!rule.unless)
|
|
334
|
+
return false;
|
|
335
|
+
if (rule.unless.regex) {
|
|
336
|
+
const compiled = rule.compiledUnlessRegex || compileSafeRegex(rule.unless.regex, `rules.${rule.id}.unless.regex`, false);
|
|
337
|
+
if (!compiled) {
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
try {
|
|
341
|
+
if (compiled.test(command))
|
|
342
|
+
return true;
|
|
343
|
+
} catch {}
|
|
344
|
+
}
|
|
345
|
+
if (rule.unless.task_in && taskId) {
|
|
346
|
+
if (rule.unless.task_in.includes(taskId))
|
|
347
|
+
return true;
|
|
348
|
+
}
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
function resolveAction(mode, matched) {
|
|
352
|
+
if (matched.length === 0)
|
|
353
|
+
return "allow";
|
|
354
|
+
if (mode === "off")
|
|
355
|
+
return "allow";
|
|
356
|
+
if (mode === "observe")
|
|
357
|
+
return "warn";
|
|
358
|
+
return "block";
|
|
359
|
+
}
|
|
360
|
+
function resolveAbsolutePath(projectRoot, rawPath) {
|
|
361
|
+
if (rawPath.startsWith("/"))
|
|
362
|
+
return resolve(rawPath);
|
|
363
|
+
return resolve(projectRoot, rawPath);
|
|
364
|
+
}
|
|
365
|
+
function isHarnessPath(projectRoot, rawPath) {
|
|
366
|
+
const absPath = resolveAbsolutePath(projectRoot, rawPath);
|
|
367
|
+
const managedRoots = [
|
|
368
|
+
resolve(projectRoot, "rig"),
|
|
369
|
+
resolve(projectRoot, ".rig"),
|
|
370
|
+
resolve(projectRoot, "artifacts")
|
|
371
|
+
];
|
|
372
|
+
return managedRoots.some((root) => absPath === root || absPath.startsWith(root + "/"));
|
|
373
|
+
}
|
|
374
|
+
function isRuntimePath(projectRoot, rawPath, taskWorkspace) {
|
|
375
|
+
const absPath = resolveAbsolutePath(projectRoot, rawPath);
|
|
376
|
+
if (taskWorkspace) {
|
|
377
|
+
const workspaceRigRoot = resolve(taskWorkspace, ".rig");
|
|
378
|
+
const workspaceArtifactsRoot = resolve(taskWorkspace, "artifacts");
|
|
379
|
+
if (absPath === workspaceRigRoot || absPath.startsWith(workspaceRigRoot + "/") || absPath === workspaceArtifactsRoot || absPath.startsWith(workspaceArtifactsRoot + "/")) {
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
const runtimeRoot = resolve(projectRoot, ".rig/runtime/agents");
|
|
384
|
+
return absPath === runtimeRoot || absPath.startsWith(runtimeRoot + "/");
|
|
385
|
+
}
|
|
386
|
+
function isTestFile(path) {
|
|
387
|
+
return /\.(test|spec)\.(ts|tsx|js|jsx)$/.test(path) || /\/(__tests__|tests|test)\//.test(path);
|
|
388
|
+
}
|
|
389
|
+
function evaluate(context) {
|
|
390
|
+
const policy = loadPolicy(context.projectRoot);
|
|
391
|
+
switch (context.evaluation.type) {
|
|
392
|
+
case "tool-call":
|
|
393
|
+
return evaluateToolCall(policy, context);
|
|
394
|
+
case "command":
|
|
395
|
+
return evaluateCommand(policy, context);
|
|
396
|
+
case "content-write":
|
|
397
|
+
return evaluateContent(policy, context);
|
|
398
|
+
case "file-access":
|
|
399
|
+
return evaluateScope(policy, context, context.evaluation.file_path, context.evaluation.access);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
function evaluateScope(policy, context, filePath, access) {
|
|
403
|
+
const allowed = () => ({
|
|
404
|
+
allowed: true,
|
|
405
|
+
matchedRules: [],
|
|
406
|
+
action: "allow",
|
|
407
|
+
failClosed: false
|
|
408
|
+
});
|
|
409
|
+
if (policy.scope.harness_paths_exempt && isHarnessPath(context.projectRoot, filePath)) {
|
|
410
|
+
return allowed();
|
|
411
|
+
}
|
|
412
|
+
if (policy.scope.runtime_paths_exempt && isRuntimePath(context.projectRoot, filePath, context.taskWorkspace)) {
|
|
413
|
+
return allowed();
|
|
414
|
+
}
|
|
415
|
+
if (!context.taskId) {
|
|
416
|
+
if (access === "write" && policy.scope.fail_closed) {
|
|
417
|
+
return {
|
|
418
|
+
allowed: false,
|
|
419
|
+
matchedRules: [],
|
|
420
|
+
action: resolveAction(policy.mode, [{ id: "scope:no-task", category: "command", reason: "No active task; fail-closed for write operations" }]),
|
|
421
|
+
failClosed: true
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
return allowed();
|
|
425
|
+
}
|
|
426
|
+
const scopes = context.taskScopes || [];
|
|
427
|
+
if (scopes.length === 0) {
|
|
428
|
+
return allowed();
|
|
429
|
+
}
|
|
430
|
+
if (context.taskWorkspace && context.taskWorkspace !== context.projectRoot && filePath.startsWith("/")) {
|
|
431
|
+
const absPath = resolve(filePath);
|
|
432
|
+
if (!absPath.startsWith(context.taskWorkspace + "/") && !isHarnessPath(context.projectRoot, filePath)) {
|
|
433
|
+
const reason2 = `Absolute path '${filePath}' is outside task runtime boundary. Allowed root: ${context.taskWorkspace}`;
|
|
434
|
+
const matched2 = [{ id: "scope:workspace-boundary", category: "command", reason: reason2 }];
|
|
435
|
+
return {
|
|
436
|
+
allowed: policy.mode !== "enforce",
|
|
437
|
+
matchedRules: matched2,
|
|
438
|
+
action: resolveAction(policy.mode, matched2),
|
|
439
|
+
failClosed: false
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
const monorepoRoot = context.monorepoRoot || process.env.MONOREPO_ROOT?.trim() || context.taskWorkspace || context.projectRoot;
|
|
444
|
+
let normalizedPath = filePath;
|
|
445
|
+
if (context.taskWorkspace && context.taskWorkspace !== context.projectRoot && filePath.startsWith(context.taskWorkspace + "/")) {
|
|
446
|
+
normalizedPath = filePath.slice(context.taskWorkspace.length + 1);
|
|
447
|
+
}
|
|
448
|
+
normalizedPath = normalizePathToScope(context.projectRoot, monorepoRoot, normalizedPath);
|
|
449
|
+
if (scopeMatches(filePath, scopes) || scopeMatches(normalizedPath, scopes)) {
|
|
450
|
+
return allowed();
|
|
451
|
+
}
|
|
452
|
+
const reason = `File '${filePath}' (normalized: '${normalizedPath}') is outside scope of task ${context.taskId}`;
|
|
453
|
+
const matched = [{ id: "scope:out-of-scope", category: "command", reason }];
|
|
454
|
+
return {
|
|
455
|
+
allowed: policy.mode !== "enforce",
|
|
456
|
+
matchedRules: matched,
|
|
457
|
+
action: resolveAction(policy.mode, matched),
|
|
458
|
+
failClosed: false
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
function evaluateCommand(policy, context) {
|
|
462
|
+
const evaluation = context.evaluation;
|
|
463
|
+
if (evaluation.type !== "command") {
|
|
464
|
+
return { allowed: true, matchedRules: [], action: "allow", failClosed: false };
|
|
465
|
+
}
|
|
466
|
+
const command = evaluation.command;
|
|
467
|
+
const matchedRules = [];
|
|
468
|
+
for (const rule of policy.rules) {
|
|
469
|
+
if (rule.category !== "command")
|
|
470
|
+
continue;
|
|
471
|
+
if (!matchRule(rule, command))
|
|
472
|
+
continue;
|
|
473
|
+
if (matchRuleUnless(rule, command, context.taskId))
|
|
474
|
+
continue;
|
|
475
|
+
matchedRules.push({
|
|
476
|
+
id: rule.id,
|
|
477
|
+
category: rule.category,
|
|
478
|
+
...rule.description !== undefined ? { description: rule.description } : {},
|
|
479
|
+
reason: rule.description || `Matched rule ${rule.id}`
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
const writeTarget = extractWriteTarget(command);
|
|
483
|
+
if (writeTarget && !/^\/dev\//.test(writeTarget) && !/^\/proc\//.test(writeTarget)) {
|
|
484
|
+
const scopeResult = evaluateScope(policy, context, writeTarget, "write");
|
|
485
|
+
if (!scopeResult.allowed || scopeResult.matchedRules.length > 0) {
|
|
486
|
+
matchedRules.push(...scopeResult.matchedRules);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
const action = resolveAction(policy.mode, matchedRules);
|
|
490
|
+
return {
|
|
491
|
+
allowed: action !== "block",
|
|
492
|
+
matchedRules,
|
|
493
|
+
action,
|
|
494
|
+
failClosed: false
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
function extractWriteTarget(command) {
|
|
498
|
+
const redirect = command.match(/>>?\s+([^\s;|&]+)/);
|
|
499
|
+
if (redirect?.[1])
|
|
500
|
+
return redirect[1];
|
|
501
|
+
const tee = command.match(/tee\s+(-a\s+)?([^\s;|&]+)/);
|
|
502
|
+
if (tee?.[2])
|
|
503
|
+
return tee[2];
|
|
504
|
+
return "";
|
|
505
|
+
}
|
|
506
|
+
function evaluateContent(policy, context) {
|
|
507
|
+
const evaluation = context.evaluation;
|
|
508
|
+
if (evaluation.type !== "content-write") {
|
|
509
|
+
return { allowed: true, matchedRules: [], action: "allow", failClosed: false };
|
|
510
|
+
}
|
|
511
|
+
const { content, file_path } = evaluation;
|
|
512
|
+
const matchedRules = [];
|
|
513
|
+
const scopeResult = evaluateScope(policy, context, file_path, "write");
|
|
514
|
+
if (scopeResult.matchedRules.length > 0) {
|
|
515
|
+
matchedRules.push(...scopeResult.matchedRules);
|
|
516
|
+
}
|
|
517
|
+
for (const rule of policy.rules) {
|
|
518
|
+
if (rule.category !== "content" && rule.category !== "import" && rule.category !== "test-integrity")
|
|
519
|
+
continue;
|
|
520
|
+
if (rule.applies_to === "test-files" && !isTestFile(file_path))
|
|
521
|
+
continue;
|
|
522
|
+
if (!matchRule(rule, content))
|
|
523
|
+
continue;
|
|
524
|
+
if (matchRuleUnless(rule, content, context.taskId))
|
|
525
|
+
continue;
|
|
526
|
+
matchedRules.push({
|
|
527
|
+
id: rule.id,
|
|
528
|
+
category: rule.category,
|
|
529
|
+
...rule.description !== undefined ? { description: rule.description } : {},
|
|
530
|
+
reason: rule.description || `Matched rule ${rule.id}`
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
const action = resolveAction(policy.mode, matchedRules);
|
|
534
|
+
return {
|
|
535
|
+
allowed: action !== "block",
|
|
536
|
+
matchedRules,
|
|
537
|
+
action,
|
|
538
|
+
failClosed: false
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
function evaluateToolCall(policy, context) {
|
|
542
|
+
const evaluation = context.evaluation;
|
|
543
|
+
if (evaluation.type !== "tool-call") {
|
|
544
|
+
return { allowed: true, matchedRules: [], action: "allow", failClosed: false };
|
|
545
|
+
}
|
|
546
|
+
const { tool_name, tool_input } = evaluation;
|
|
547
|
+
const allMatched = [];
|
|
548
|
+
const filePaths = extractFilePathsFromToolInput(tool_name, tool_input);
|
|
549
|
+
for (const fp of filePaths) {
|
|
550
|
+
const access = isWriteTool(tool_name) ? "write" : "read";
|
|
551
|
+
const scopeResult = evaluateScope(policy, context, fp, access);
|
|
552
|
+
if (scopeResult.matchedRules.length > 0) {
|
|
553
|
+
allMatched.push(...scopeResult.matchedRules);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
const content = extractContentFromToolInput(tool_input);
|
|
557
|
+
if (content) {
|
|
558
|
+
const filePath = filePaths[0] || "";
|
|
559
|
+
const contentContext = {
|
|
560
|
+
...context,
|
|
561
|
+
evaluation: { type: "content-write", file_path: filePath, content }
|
|
562
|
+
};
|
|
563
|
+
const contentPolicy = loadPolicy(context.projectRoot);
|
|
564
|
+
for (const rule of contentPolicy.rules) {
|
|
565
|
+
if (rule.category !== "content" && rule.category !== "import" && rule.category !== "test-integrity")
|
|
566
|
+
continue;
|
|
567
|
+
if (rule.applies_to === "test-files" && !isTestFile(filePath))
|
|
568
|
+
continue;
|
|
569
|
+
if (!matchRule(rule, content))
|
|
570
|
+
continue;
|
|
571
|
+
if (matchRuleUnless(rule, content, context.taskId))
|
|
572
|
+
continue;
|
|
573
|
+
allMatched.push({
|
|
574
|
+
id: rule.id,
|
|
575
|
+
category: rule.category,
|
|
576
|
+
...rule.description !== undefined ? { description: rule.description } : {},
|
|
577
|
+
reason: rule.description || `Matched rule ${rule.id}`
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
if (tool_name === "Bash") {
|
|
582
|
+
const command = String(tool_input.command || tool_input.cmd || "");
|
|
583
|
+
if (command) {
|
|
584
|
+
const cmdContext = {
|
|
585
|
+
...context,
|
|
586
|
+
evaluation: { type: "command", command }
|
|
587
|
+
};
|
|
588
|
+
const cmdResult = evaluateCommand(policy, cmdContext);
|
|
589
|
+
if (cmdResult.matchedRules.length > 0) {
|
|
590
|
+
allMatched.push(...cmdResult.matchedRules);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
const seen = new Set;
|
|
595
|
+
const deduplicated = [];
|
|
596
|
+
for (const rule of allMatched) {
|
|
597
|
+
if (!seen.has(rule.id)) {
|
|
598
|
+
seen.add(rule.id);
|
|
599
|
+
deduplicated.push(rule);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
const action = resolveAction(policy.mode, deduplicated);
|
|
603
|
+
return {
|
|
604
|
+
allowed: action !== "block",
|
|
605
|
+
matchedRules: deduplicated,
|
|
606
|
+
action,
|
|
607
|
+
failClosed: false
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
function isWriteTool(toolName) {
|
|
611
|
+
return toolName === "Write" || toolName === "Edit" || toolName === "MultiEdit";
|
|
612
|
+
}
|
|
613
|
+
function extractFilePathsFromToolInput(toolName, input) {
|
|
614
|
+
const paths = [];
|
|
615
|
+
const add = (value) => {
|
|
616
|
+
if (typeof value === "string" && value.trim()) {
|
|
617
|
+
paths.push(value.trim());
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
if (toolName === "Read" || toolName === "Write" || toolName === "Edit" || toolName === "MultiEdit") {
|
|
621
|
+
add(input.file_path);
|
|
622
|
+
add(input.path);
|
|
623
|
+
} else if (toolName === "Glob") {
|
|
624
|
+
add(input.path);
|
|
625
|
+
} else if (toolName === "Grep") {
|
|
626
|
+
add(input.path);
|
|
627
|
+
} else {
|
|
628
|
+
add(input.file_path);
|
|
629
|
+
add(input.path);
|
|
630
|
+
}
|
|
631
|
+
return paths;
|
|
632
|
+
}
|
|
633
|
+
function extractContentFromToolInput(input) {
|
|
634
|
+
if (typeof input.content === "string")
|
|
635
|
+
return input.content;
|
|
636
|
+
if (typeof input.new_string === "string")
|
|
637
|
+
return input.new_string;
|
|
638
|
+
return "";
|
|
639
|
+
}
|
|
640
|
+
var guardHotPathPrimed = false;
|
|
641
|
+
function primeGuardHotPaths() {
|
|
642
|
+
if (guardHotPathPrimed) {
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
guardHotPathPrimed = true;
|
|
646
|
+
try {
|
|
647
|
+
optimizeNextInvocation(matchRule);
|
|
648
|
+
optimizeNextInvocation(evaluate);
|
|
649
|
+
} catch {}
|
|
650
|
+
}
|
|
651
|
+
primeGuardHotPaths();
|
|
652
|
+
|
|
653
|
+
// packages/cli-surface-plugin/src/control-plane/agent-binary-build.ts
|
|
654
|
+
import { runtimeProvisioningEnv } from "@rig/core/runtime-provisioning-env";
|
|
13
655
|
|
|
656
|
+
// packages/cli-surface-plugin/src/runner.ts
|
|
14
657
|
class CliError extends RuntimeCliError {
|
|
15
|
-
hint;
|
|
16
658
|
constructor(message, exitCode = 1, options = {}) {
|
|
17
|
-
super(message, exitCode);
|
|
18
|
-
if (options.hint?.trim()) {
|
|
19
|
-
this.hint = options.hint.trim();
|
|
20
|
-
}
|
|
659
|
+
super(message, exitCode, options);
|
|
21
660
|
}
|
|
22
661
|
}
|
|
23
662
|
function takeOption(args, option) {
|
|
@@ -55,7 +694,7 @@ Usage: ${usage}`);
|
|
|
55
694
|
}
|
|
56
695
|
|
|
57
696
|
// packages/cli-surface-plugin/src/commands/plugin.ts
|
|
58
|
-
import { buildPluginHostContext } from "@rig/
|
|
697
|
+
import { buildPluginHostContext } from "@rig/core/plugin-host-context";
|
|
59
698
|
|
|
60
699
|
// packages/cli-surface-plugin/src/commands/_parsers.ts
|
|
61
700
|
async function loadRigConfigOrNull(projectRoot) {
|
|
@@ -94,7 +733,7 @@ async function executePlugin(context, args) {
|
|
|
94
733
|
}
|
|
95
734
|
if (context.outputMode === "text") {
|
|
96
735
|
if (declarative.length === 0) {
|
|
97
|
-
const configExists = ["rig.config.ts", "rig.config.mts", "rig.config.json"].some((name) =>
|
|
736
|
+
const configExists = ["rig.config.ts", "rig.config.mts", "rig.config.json"].some((name) => existsSync2(resolve2(context.projectRoot, name)));
|
|
98
737
|
console.log(configExists ? "rig.config found but no plugins could be loaded. If the config imports @rig/* packages, run `bun install` in this project first." : "No plugins loaded. Declare plugins in rig.config.ts.");
|
|
99
738
|
} else {
|
|
100
739
|
console.log("Plugins (rig.config.ts):");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type RunnerContext } from "../runner";
|
|
2
|
-
import type { CommandOutcome } from "@rig/
|
|
2
|
+
import type { CommandOutcome } from "@rig/contracts";
|
|
3
3
|
export declare function executeProfile(context: RunnerContext, args: string[]): Promise<CommandOutcome>;
|
|
4
4
|
export declare function executeReview(context: RunnerContext, args: string[]): Promise<CommandOutcome>;
|