@h-rig/cli-surface-plugin 0.0.6-alpha.157 → 0.0.6-alpha.159

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