@cuzfrog/pi-module-gates 0.13.0 → 0.13.1

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 CHANGED
@@ -25,7 +25,7 @@ The extension intercepts agent `write`/`edit` operations and enforces these cont
25
25
  - **Readonly gate** — is the target file locked?
26
26
  **Fronzen gate** — is there any surface change to the target file?
27
27
  - **Export gate** — would the change introduce an export not in the `visible` list?
28
- - **Module interface import gate** — external files can only import from the module not internal files, i.e. re-exports from `index.ts` or `mod.rs`. (Only Typescript/JavaScript and Rust are supported)
28
+ - **Module interface import gate** — external files can only import from the module not internal files, i.e. re-exports from `index.ts` or `mod.rs`. A child module may import from a parent module's internal files (not recommended but allowed). (Only Typescript/JavaScript and Rust are supported)
29
29
  - **Import gate** (not implemented yet) — would the change introduce an import violating visibility scope?
30
30
 
31
31
  - System prompt: [system-prompt.md](src/context/system-prompt.ts)
@@ -126,7 +126,7 @@ Add a `module-gates` entry to `.pi/settings.json`:
126
126
  | `moduleDescriptorFileName` | `MODULE.md` | File name used for module descriptors (case-insensitive) |
127
127
  | `moduleDescriptorReadonly` | `true` | When `true`, descriptor files are readonly.|
128
128
  | `sourceRoot` | `"src/"` | Directory to scan for descriptor files and enforce gates. Set to `""` to scan from project root. |
129
- | `disableModuleInterfaceImportGate` | `false` | By default, external files can only import from the module not internal files, i.e. re-exports from `index.ts` or `mod.rs` |
129
+ | `disableModuleInterfaceImportGate` | `false` | When `true`, imports will not be forced to be from module interface. |
130
130
 
131
131
  When no settings file exists or no `module-gates` key is present, defaults apply.
132
132
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuzfrog/pi-module-gates",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "pi extension that controls the entropy of the codebase by enforcing code module boundaries.",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -19,7 +19,9 @@ function extractExports(src: string): Signature[] {
19
19
  ),
20
20
  ].map((m) => ({ name: m[1] }));
21
21
 
22
- for (const m of src.matchAll(/^export\s*\{\s*([^}]+)\s*\}\s*from/gm)) {
22
+ for (const m of src.matchAll(
23
+ /^export\s*(?:type\s+)?\{\s*([^}]+)\s*\}\s*from/gm,
24
+ )) {
23
25
  const inner = m[1];
24
26
  for (const entry of inner.split(",")) {
25
27
  const trimmed = entry.trim();
@@ -37,5 +39,15 @@ function extractExports(src: string): Signature[] {
37
39
  results.push({ name: m[1] });
38
40
  }
39
41
 
42
+ for (const m of src.matchAll(/^export\s*\*\s+from/gm)) {
43
+ results.push({ name: "*" });
44
+ }
45
+
46
+ for (const m of src.matchAll(
47
+ /^export\s+default\s+(?!function|class|const|let|var|type|interface|enum|abstract|async|declare)([a-zA-Z_]\w*)/gm,
48
+ )) {
49
+ results.push({ name: m[1] });
50
+ }
51
+
40
52
  return results;
41
53
  }
@@ -63,7 +63,7 @@ function checkViolation(
63
63
  if (isInterfaceFile(resolved)) return undefined;
64
64
 
65
65
  const sourceModule = findOwningModule(path.join(fileDir, "dummy.ts"), index);
66
- if (sourceModule && sourceModule === targetModule) return undefined;
66
+ if (sourceModule && isDescendantOrSelf(sourceModule, targetModule)) return undefined;
67
67
 
68
68
  const relTarget = path.relative(cwd, resolved);
69
69
  const relModule = path.relative(cwd, targetModule);
@@ -146,3 +146,8 @@ function isInterfaceFile(absPath: string): boolean {
146
146
 
147
147
  return false;
148
148
  }
149
+
150
+ function isDescendantOrSelf(child: string, ancestor: string): boolean {
151
+ if (child === ancestor) return true;
152
+ return child.startsWith(ancestor + path.sep);
153
+ }