@h-rig/guard-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.
@@ -0,0 +1,3 @@
1
+ export declare function normalizePathToScope(projectRoot: string, monorepoRoot: string, inputPath: string): string;
2
+ export declare function scopeGlobToRegex(glob: string): RegExp;
3
+ export declare function scopeMatches(path: string, scopes: string[]): boolean;
@@ -0,0 +1,58 @@
1
+ // @bun
2
+ // packages/guard-plugin/src/scope.ts
3
+ import { getScopeRules } from "@rig/core/scope-rules";
4
+ var scopeRegexCache = new Map;
5
+ function unique(values) {
6
+ return [...new Set(values)];
7
+ }
8
+ function normalizeRelativeScopePath(inputPath) {
9
+ let normalized = inputPath.replace(/^\.\//, "");
10
+ const rules = getScopeRules();
11
+ if (rules?.stripPrefixes) {
12
+ for (const prefix of rules.stripPrefixes) {
13
+ if (normalized.startsWith(prefix)) {
14
+ normalized = normalized.slice(prefix.length);
15
+ }
16
+ }
17
+ }
18
+ return normalized;
19
+ }
20
+ function normalizePathToScope(projectRoot, monorepoRoot, inputPath) {
21
+ let normalized = inputPath.replace(/^\.\//, "");
22
+ if (normalized.startsWith(projectRoot + "/")) {
23
+ normalized = normalized.slice(projectRoot.length + 1);
24
+ }
25
+ if (normalized.startsWith(monorepoRoot + "/")) {
26
+ normalized = normalized.slice(monorepoRoot.length + 1);
27
+ }
28
+ return normalizeRelativeScopePath(normalized);
29
+ }
30
+ function scopeGlobToRegex(glob) {
31
+ const cached = scopeRegexCache.get(glob);
32
+ if (cached) {
33
+ return cached;
34
+ }
35
+ const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "__GLOBSTAR__").replace(/\*/g, "[^/]*").replace(/__GLOBSTAR__/g, ".*");
36
+ const compiled = new RegExp(`^${escaped}$`);
37
+ scopeRegexCache.set(glob, compiled);
38
+ return compiled;
39
+ }
40
+ function scopeMatches(path, scopes) {
41
+ const pathVariants = unique([path, normalizeRelativeScopePath(path)]);
42
+ for (const scope of scopes) {
43
+ const scopeVariants = unique([scope, normalizeRelativeScopePath(scope)]);
44
+ for (const candidatePath of pathVariants) {
45
+ for (const candidateScope of scopeVariants) {
46
+ if (candidatePath === candidateScope || scopeGlobToRegex(candidateScope).test(candidatePath)) {
47
+ return true;
48
+ }
49
+ }
50
+ }
51
+ }
52
+ return false;
53
+ }
54
+ export {
55
+ scopeMatches,
56
+ scopeGlobToRegex,
57
+ normalizePathToScope
58
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h-rig/guard-plugin",
3
- "version": "0.0.6-alpha.157",
3
+ "version": "0.0.6-alpha.158",
4
4
  "type": "module",
5
5
  "description": "First-party runtime policy-guard hooks contributed as a single-channel Rig plugin.",
6
6
  "license": "UNLICENSED",
@@ -17,6 +17,22 @@
17
17
  "types": "./dist/src/plugin.d.ts",
18
18
  "import": "./dist/src/plugin.js"
19
19
  },
20
+ "./guard": {
21
+ "types": "./dist/src/guard.d.ts",
22
+ "import": "./dist/src/guard.js"
23
+ },
24
+ "./controlled-bash": {
25
+ "types": "./dist/src/controlled-bash.d.ts",
26
+ "import": "./dist/src/controlled-bash.js"
27
+ },
28
+ "./agent-shell": {
29
+ "types": "./dist/src/agent-shell.d.ts",
30
+ "import": "./dist/src/agent-shell.js"
31
+ },
32
+ "./agent-binary-build": {
33
+ "types": "./dist/src/agent-binary-build.d.ts",
34
+ "import": "./dist/src/agent-binary-build.js"
35
+ },
20
36
  "./hooks/safety-guard": {
21
37
  "types": "./dist/src/hooks/safety-guard.d.ts",
22
38
  "import": "./dist/src/hooks/safety-guard.js"
@@ -49,9 +65,8 @@
49
65
  "module": "./dist/src/index.js",
50
66
  "types": "./dist/src/index.d.ts",
51
67
  "dependencies": {
52
- "@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.157",
53
- "@rig/core": "npm:@h-rig/core@0.0.6-alpha.157",
54
- "@rig/hook-kit": "npm:@h-rig/hook-kit@0.0.6-alpha.157",
55
- "@rig/runtime": "npm:@h-rig/runtime@0.0.6-alpha.157"
68
+ "@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.158",
69
+ "@rig/core": "npm:@h-rig/core@0.0.6-alpha.158",
70
+ "@rig/hook-kit": "npm:@h-rig/hook-kit@0.0.6-alpha.158"
56
71
  }
57
72
  }