@principal-ai/subsystems-core 0.51.4 → 0.51.6

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 (155) hide show
  1. package/README.md +21 -6
  2. package/dist/audit/boundary.d.ts +104 -0
  3. package/dist/audit/boundary.d.ts.map +1 -0
  4. package/dist/audit/boundary.js +363 -0
  5. package/dist/audit/boundary.js.map +1 -0
  6. package/dist/audit/c4.d.ts +41 -0
  7. package/dist/audit/c4.d.ts.map +1 -0
  8. package/dist/audit/c4.js +41 -0
  9. package/dist/audit/c4.js.map +1 -0
  10. package/dist/audit/engine.d.ts +135 -0
  11. package/dist/audit/engine.d.ts.map +1 -0
  12. package/dist/audit/engine.js +828 -0
  13. package/dist/audit/engine.js.map +1 -0
  14. package/dist/audit/fixes.d.ts +80 -0
  15. package/dist/audit/fixes.d.ts.map +1 -0
  16. package/dist/audit/fixes.js +162 -0
  17. package/dist/audit/fixes.js.map +1 -0
  18. package/dist/audit/hash.d.ts +25 -0
  19. package/dist/audit/hash.d.ts.map +1 -0
  20. package/dist/audit/hash.js +53 -0
  21. package/dist/audit/hash.js.map +1 -0
  22. package/dist/audit/index.d.ts +11 -1
  23. package/dist/audit/index.d.ts.map +1 -1
  24. package/dist/audit/index.js +37 -3
  25. package/dist/audit/index.js.map +1 -1
  26. package/dist/audit/local-graphify.d.ts +75 -0
  27. package/dist/audit/local-graphify.d.ts.map +1 -0
  28. package/dist/audit/local-graphify.js +283 -0
  29. package/dist/audit/local-graphify.js.map +1 -0
  30. package/dist/audit/paths.d.ts +16 -0
  31. package/dist/audit/paths.d.ts.map +1 -0
  32. package/dist/audit/paths.js +31 -0
  33. package/dist/audit/paths.js.map +1 -0
  34. package/dist/audit/pure.d.ts +18 -0
  35. package/dist/audit/pure.d.ts.map +1 -0
  36. package/dist/audit/pure.js +50 -0
  37. package/dist/audit/pure.js.map +1 -0
  38. package/dist/audit/report-logic.d.ts +17 -0
  39. package/dist/audit/report-logic.d.ts.map +1 -0
  40. package/dist/audit/report-logic.js +206 -0
  41. package/dist/audit/report-logic.js.map +1 -0
  42. package/dist/audit/report.d.ts +136 -0
  43. package/dist/audit/report.d.ts.map +1 -0
  44. package/dist/audit/report.js +3 -0
  45. package/dist/audit/report.js.map +1 -0
  46. package/dist/audit/trail.d.ts +29 -0
  47. package/dist/audit/trail.d.ts.map +1 -0
  48. package/dist/audit/trail.js +59 -0
  49. package/dist/audit/trail.js.map +1 -0
  50. package/dist/audit/verification.d.ts +98 -0
  51. package/dist/audit/verification.d.ts.map +1 -0
  52. package/dist/audit/verification.js +11 -0
  53. package/dist/audit/verification.js.map +1 -0
  54. package/dist/audit/verify/component.d.ts +68 -0
  55. package/dist/audit/verify/component.d.ts.map +1 -0
  56. package/dist/audit/verify/component.js +500 -0
  57. package/dist/audit/verify/component.js.map +1 -0
  58. package/dist/audit/verify/declarations.d.ts +58 -0
  59. package/dist/audit/verify/declarations.d.ts.map +1 -0
  60. package/dist/audit/verify/declarations.js +227 -0
  61. package/dist/audit/verify/declarations.js.map +1 -0
  62. package/dist/audit/verify/grammar.d.ts +12 -0
  63. package/dist/audit/verify/grammar.d.ts.map +1 -0
  64. package/dist/audit/verify/grammar.js +57 -0
  65. package/dist/audit/verify/grammar.js.map +1 -0
  66. package/dist/audit/verify/index.d.ts +12 -0
  67. package/dist/audit/verify/index.d.ts.map +1 -0
  68. package/dist/audit/verify/index.js +31 -0
  69. package/dist/audit/verify/index.js.map +1 -0
  70. package/dist/audit/verify/parser.d.ts +19 -0
  71. package/dist/audit/verify/parser.d.ts.map +1 -0
  72. package/dist/audit/verify/parser.js +122 -0
  73. package/dist/audit/verify/parser.js.map +1 -0
  74. package/dist/audit/verify/span.d.ts +49 -0
  75. package/dist/audit/verify/span.d.ts.map +1 -0
  76. package/dist/audit/verify/span.js +377 -0
  77. package/dist/audit/verify/span.js.map +1 -0
  78. package/dist/graphify/anchor.d.ts +45 -0
  79. package/dist/graphify/anchor.d.ts.map +1 -0
  80. package/dist/graphify/anchor.js +179 -0
  81. package/dist/graphify/anchor.js.map +1 -0
  82. package/dist/graphify/consolidated.d.ts +259 -0
  83. package/dist/graphify/consolidated.d.ts.map +1 -0
  84. package/dist/graphify/consolidated.js +12 -0
  85. package/dist/graphify/consolidated.js.map +1 -0
  86. package/dist/graphify/construct.d.ts +41 -0
  87. package/dist/graphify/construct.d.ts.map +1 -0
  88. package/dist/graphify/construct.js +106 -0
  89. package/dist/graphify/construct.js.map +1 -0
  90. package/dist/graphify/ids.d.ts +19 -0
  91. package/dist/graphify/ids.d.ts.map +1 -0
  92. package/dist/graphify/ids.js +53 -0
  93. package/dist/graphify/ids.js.map +1 -0
  94. package/dist/graphify/index.d.ts +16 -0
  95. package/dist/graphify/index.d.ts.map +1 -0
  96. package/dist/graphify/index.js +32 -0
  97. package/dist/graphify/index.js.map +1 -0
  98. package/dist/graphify/resolve.d.ts +48 -0
  99. package/dist/graphify/resolve.d.ts.map +1 -0
  100. package/dist/graphify/resolve.js +89 -0
  101. package/dist/graphify/resolve.js.map +1 -0
  102. package/dist/graphify/signature.d.ts +87 -0
  103. package/dist/graphify/signature.d.ts.map +1 -0
  104. package/dist/graphify/signature.js +282 -0
  105. package/dist/graphify/signature.js.map +1 -0
  106. package/dist/graphify/types.d.ts +141 -0
  107. package/dist/graphify/types.d.ts.map +1 -0
  108. package/dist/graphify/types.js +9 -0
  109. package/dist/graphify/types.js.map +1 -0
  110. package/dist/index.d.ts +3 -1
  111. package/dist/index.d.ts.map +1 -1
  112. package/dist/index.js +6 -4
  113. package/dist/index.js.map +1 -1
  114. package/dist/node.d.ts +2 -0
  115. package/dist/node.d.ts.map +1 -1
  116. package/dist/node.js +3 -1
  117. package/dist/node.js.map +1 -1
  118. package/dist/storage/topic-share.d.ts +57 -0
  119. package/dist/storage/topic-share.d.ts.map +1 -0
  120. package/dist/storage/topic-share.js +55 -0
  121. package/dist/storage/topic-share.js.map +1 -0
  122. package/package.json +16 -2
  123. package/src/audit/boundary.ts +447 -0
  124. package/src/audit/c4.ts +70 -0
  125. package/src/audit/engine.ts +1058 -0
  126. package/src/audit/fixes.ts +192 -0
  127. package/src/audit/hash.ts +58 -0
  128. package/src/audit/index.ts +33 -8
  129. package/src/audit/local-graphify.test.ts +163 -0
  130. package/src/audit/local-graphify.ts +354 -0
  131. package/src/audit/paths.ts +25 -0
  132. package/src/audit/pure.ts +91 -0
  133. package/src/audit/report-logic.test.ts +145 -0
  134. package/src/audit/report-logic.ts +245 -0
  135. package/src/audit/report.ts +203 -0
  136. package/src/audit/trail.ts +77 -0
  137. package/src/audit/verification.ts +104 -0
  138. package/src/audit/verify/component.ts +760 -0
  139. package/src/audit/verify/declarations.ts +284 -0
  140. package/src/audit/verify/grammar.ts +57 -0
  141. package/src/audit/verify/index.ts +41 -0
  142. package/src/audit/verify/parser.ts +124 -0
  143. package/src/audit/verify/span.ts +478 -0
  144. package/src/graphify/anchor.ts +206 -0
  145. package/src/graphify/consolidated.ts +298 -0
  146. package/src/graphify/construct.ts +153 -0
  147. package/src/graphify/ids.ts +48 -0
  148. package/src/graphify/index.ts +16 -0
  149. package/src/graphify/resolve.ts +115 -0
  150. package/src/graphify/signature.ts +354 -0
  151. package/src/graphify/types.ts +164 -0
  152. package/src/index.ts +5 -3
  153. package/src/node.ts +2 -0
  154. package/src/storage/topic-share.test.ts +71 -0
  155. package/src/storage/topic-share.ts +91 -0
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ /**
3
+ * Source declaration parsing shared by every audit host.
4
+ *
5
+ * Graphify supplies candidates; source supplies declaration identity, kind and
6
+ * span. No subsystem-model membership, inferred graph kind, or display label
7
+ * alone is accepted as verification.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.declarationForSymbol = exports.enclosingDeclaration = exports.safeSource = exports.parseDeclarations = void 0;
11
+ const node_crypto_1 = require("node:crypto");
12
+ const node_fs_1 = require("node:fs");
13
+ const node_path_1 = require("node:path");
14
+ const hash_1 = require("../hash");
15
+ const parser_1 = require("./parser");
16
+ const kinds = {
17
+ function_declaration: 'function',
18
+ generator_function_declaration: 'function',
19
+ function_definition: 'function',
20
+ function_item: 'function',
21
+ function_signature: 'function',
22
+ class_declaration: 'class',
23
+ abstract_class_declaration: 'class',
24
+ class_definition: 'class',
25
+ class: 'class',
26
+ struct_item: 'class',
27
+ interface_declaration: 'type',
28
+ type_alias_declaration: 'type',
29
+ enum_declaration: 'type',
30
+ type_spec: 'type',
31
+ type_item: 'type',
32
+ enum_item: 'type',
33
+ trait_item: 'type',
34
+ interface: 'type',
35
+ method_definition: 'method',
36
+ method_declaration: 'method',
37
+ method_signature: 'method',
38
+ abstract_method_signature: 'method',
39
+ constructor_declaration: 'method',
40
+ method: 'method',
41
+ singleton_method: 'method',
42
+ public_field_definition: 'field',
43
+ property_signature: 'field',
44
+ const_item: 'variable',
45
+ static_item: 'variable',
46
+ internal_module: 'module',
47
+ module: 'module',
48
+ mod_item: 'module',
49
+ };
50
+ function declarationKind(node) {
51
+ if (node.type === 'function_item' && node.parent?.parent?.type === 'impl_item')
52
+ return 'method';
53
+ if (node.type === 'function_definition') {
54
+ let parent = node.parent;
55
+ if (parent?.type === 'decorated_definition')
56
+ parent = parent.parent;
57
+ if (parent?.type === 'block' && parent.parent?.type === 'class_definition')
58
+ return 'method';
59
+ }
60
+ if (node.type === 'variable_declarator') {
61
+ const value = node.childForFieldName('value');
62
+ return value &&
63
+ /^(arrow_function|function_expression|generator_function)$/.test(value.type)
64
+ ? 'function'
65
+ : 'variable';
66
+ }
67
+ return kinds[node.type];
68
+ }
69
+ function declarationName(node) {
70
+ const name = node.childForFieldName('name');
71
+ // Destructured/dynamic names cannot serve as an unambiguous identity.
72
+ if (!name ||
73
+ /pattern|computed|subscript|member_expression/.test(name.type))
74
+ return undefined;
75
+ return name.text.trim() || undefined;
76
+ }
77
+ function receiverName(node) {
78
+ const receiver = node.childForFieldName('receiver');
79
+ const findType = (part) => {
80
+ if (part.type === 'type_identifier')
81
+ return part.text;
82
+ for (const child of part.namedChildren) {
83
+ if (!child)
84
+ continue;
85
+ const name = findType(child);
86
+ if (name)
87
+ return name;
88
+ }
89
+ return undefined;
90
+ };
91
+ return receiver ? findType(receiver) : undefined;
92
+ }
93
+ const declarationCache = new Map();
94
+ const MAX_CACHED_FILES = 512;
95
+ async function parseDeclarations(file, content) {
96
+ const key = `${file.slice(file.lastIndexOf('.')).toLowerCase()}\0${(0, node_crypto_1.createHash)('sha256').update(content).digest('hex')}`;
97
+ if (declarationCache.has(key)) {
98
+ const cached = declarationCache.get(key);
99
+ declarationCache.delete(key);
100
+ declarationCache.set(key, cached);
101
+ return cached;
102
+ }
103
+ const parser = await (0, parser_1.sharedParserFor)(file);
104
+ if (!parser)
105
+ return null;
106
+ const tree = await (0, parser_1.parseWith)(parser, content);
107
+ try {
108
+ const declarations = [];
109
+ const lines = content.split(/\r?\n/).map(hash_1.normalizeDeclarationLine);
110
+ const visit = (node, scopes) => {
111
+ const construct = declarationKind(node);
112
+ const name = construct ? declarationName(node) : undefined;
113
+ let innerScopes = scopes;
114
+ if (node.type === 'impl_item') {
115
+ const type = node.childForFieldName('type')?.text;
116
+ if (type)
117
+ innerScopes = [...scopes, type];
118
+ }
119
+ if (construct && name) {
120
+ let start = node;
121
+ // A declarator needs its const/let/export wrapper to retain its
122
+ // signature and any modifiers, not just the initializer.
123
+ if (node.type === 'variable_declarator' &&
124
+ node.parent?.namedChildren.filter((c) => c?.type === 'variable_declarator').length === 1) {
125
+ start = node.parent;
126
+ }
127
+ while (start.parent &&
128
+ /^(export_statement|decorated_definition)$/.test(start.parent.type))
129
+ start = start.parent;
130
+ const receiver = node.type === 'method_declaration' ? receiverName(node) : undefined;
131
+ const qualifiedScopes = receiver ? [...scopes, receiver] : scopes;
132
+ const symbol = [...qualifiedScopes, name].join('.');
133
+ const startLine = start.startPosition.row + 1;
134
+ const endLine = start.endPosition.row + 1;
135
+ declarations.push({
136
+ name,
137
+ symbol,
138
+ construct,
139
+ startLine,
140
+ endLine,
141
+ anchorEnd: node.startPosition.row + 1,
142
+ hasError: start.hasError,
143
+ contentHash: (0, node_crypto_1.createHash)('sha256')
144
+ .update(lines.slice(startLine - 1, endLine).join('\n'))
145
+ .digest('hex')
146
+ .slice(0, 32),
147
+ });
148
+ if (['class', 'function', 'method', 'module', 'type'].includes(construct))
149
+ innerScopes = [...qualifiedScopes, name];
150
+ }
151
+ for (const child of node.namedChildren)
152
+ if (child)
153
+ visit(child, innerScopes);
154
+ };
155
+ visit(tree.rootNode, []);
156
+ const parsed = { declarations, hasError: tree.rootNode.hasError };
157
+ declarationCache.set(key, parsed);
158
+ if (declarationCache.size > MAX_CACHED_FILES)
159
+ declarationCache.delete(declarationCache.keys().next().value);
160
+ return parsed;
161
+ }
162
+ finally {
163
+ tree.delete();
164
+ }
165
+ }
166
+ exports.parseDeclarations = parseDeclarations;
167
+ function toResolvedDeclaration(declaration) {
168
+ return {
169
+ symbol: declaration.symbol,
170
+ construct: declaration.construct,
171
+ startLine: declaration.startLine,
172
+ endLine: declaration.endLine,
173
+ contentHash: declaration.contentHash,
174
+ };
175
+ }
176
+ /** Read a repo-relative source file, rejecting paths outside the checkout. */
177
+ async function safeSource(root, file) {
178
+ if ((0, node_path_1.isAbsolute)(file) || file.split('/').includes('..'))
179
+ throw new Error('Unsafe source path.');
180
+ const path = await node_fs_1.promises.realpath((0, node_path_1.resolve)(root, file));
181
+ const rel = (0, node_path_1.relative)(root, path);
182
+ if (rel === '..' || rel.startsWith(`..${node_path_1.sep}`) || (0, node_path_1.isAbsolute)(rel))
183
+ throw new Error('Source path escapes checkout.');
184
+ const stat = await node_fs_1.promises.stat(path);
185
+ if (!stat.isFile() || stat.size > 5000000)
186
+ throw new Error('Source is not a readable file below 5 MB.');
187
+ return node_fs_1.promises.readFile(path, 'utf8');
188
+ }
189
+ exports.safeSource = safeSource;
190
+ /**
191
+ * Resolve the innermost declaration containing `line` in `file`.
192
+ *
193
+ * Trail step sites are hand-authored call-site lines, while the frame the UI
194
+ * wants is the enclosing construct (a method inside a class, a helper inside a
195
+ * module). Picking the smallest containing range gives that frame; the full
196
+ * `startLine..endLine` is what the code view should show.
197
+ */
198
+ async function enclosingDeclaration(input) {
199
+ const root = await node_fs_1.promises.realpath(input.repoRoot);
200
+ const content = await safeSource(root, input.file);
201
+ const declarations = (await parseDeclarations(input.file, content))?.declarations ?? [];
202
+ const containing = declarations.filter((d) => d.startLine <= input.line && input.line <= d.endLine);
203
+ containing.sort((a, b) => a.endLine - a.startLine - (b.endLine - b.startLine) ||
204
+ b.symbol.length - a.symbol.length ||
205
+ a.symbol.localeCompare(b.symbol));
206
+ const first = containing[0];
207
+ return first ? toResolvedDeclaration(first) : null;
208
+ }
209
+ exports.enclosingDeclaration = enclosingDeclaration;
210
+ /**
211
+ * Resolve a declaration by qualified symbol in `file`. Exact qualified match
212
+ * first (`Class.method`), then a unique simple-name match — never a guess when
213
+ * the simple name is ambiguous.
214
+ */
215
+ async function declarationForSymbol(input) {
216
+ const root = await node_fs_1.promises.realpath(input.repoRoot);
217
+ const content = await safeSource(root, input.file);
218
+ const declarations = (await parseDeclarations(input.file, content))?.declarations ?? [];
219
+ const exact = declarations.find((d) => d.symbol === input.symbol);
220
+ if (exact)
221
+ return toResolvedDeclaration(exact);
222
+ const simple = input.symbol.split('.').pop();
223
+ const matches = declarations.filter((d) => d.name === simple);
224
+ return matches.length === 1 ? toResolvedDeclaration(matches[0]) : null;
225
+ }
226
+ exports.declarationForSymbol = declarationForSymbol;
227
+ //# sourceMappingURL=declarations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declarations.js","sourceRoot":"","sources":["../../../src/audit/verify/declarations.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,6CAAwC;AACxC,qCAAwC;AACxC,yCAA8D;AAE9D,kCAAkD;AAClD,qCAAqD;AAcrD,MAAM,KAAK,GAA2B;IACpC,oBAAoB,EAAE,UAAU;IAChC,8BAA8B,EAAE,UAAU;IAC1C,mB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Y,IAAI,EAAE,CAAA;IACpE,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,CAAC,CAAA;IACjE,IAAI,KAAK;QAAE,OAAO,qBAAqB,CAAC,KAAK,CAAC,CAAA;IAC9C,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAA;IAC5C,MAAM,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAA;IAC7D,OAAO,OAAO,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AACzE,CAAC;AAdD,oDAcC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Tree-sitter grammar support shared by every audit host.
3
+ *
4
+ * The audit verifies a declaration by parsing source, so both Studio and the
5
+ * CLI must agree on which extensions are parseable and which WASM grammar
6
+ * handles them.
7
+ */
8
+ /** Extension → bundled tree-sitter WASM grammar. */
9
+ export declare const CONSTRUCT_GRAMMARS: Readonly<Record<string, string>>;
10
+ export declare function grammarFile(file: string): string | null;
11
+ export declare function constructFileSupport(file: string): 'supported' | 'unsupported' | 'non-code';
12
+ //# sourceMappingURL=grammar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grammar.d.ts","sourceRoot":"","sources":["../../../src/audit/verify/grammar.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,oDAAoD;AACpD,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAa/D,CAAA;AAQD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEvD;AAgBD,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,GACX,WAAW,GAAG,aAAa,GAAG,UAAU,CAM1C"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ /**
3
+ * Tree-sitter grammar support shared by every audit host.
4
+ *
5
+ * The audit verifies a declaration by parsing source, so both Studio and the
6
+ * CLI must agree on which extensions are parseable and which WASM grammar
7
+ * handles them.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.constructFileSupport = exports.grammarFile = exports.CONSTRUCT_GRAMMARS = void 0;
11
+ /** Extension → bundled tree-sitter WASM grammar. */
12
+ exports.CONSTRUCT_GRAMMARS = {
13
+ '.ts': 'tree-sitter-typescript.wasm',
14
+ '.tsx': 'tree-sitter-tsx.wasm',
15
+ '.js': 'tree-sitter-javascript.wasm',
16
+ '.jsx': 'tree-sitter-javascript.wasm',
17
+ '.mjs': 'tree-sitter-javascript.wasm',
18
+ '.cjs': 'tree-sitter-javascript.wasm',
19
+ '.py': 'tree-sitter-python.wasm',
20
+ '.go': 'tree-sitter-go.wasm',
21
+ '.rs': 'tree-sitter-rust.wasm',
22
+ '.java': 'tree-sitter-java.wasm',
23
+ '.rb': 'tree-sitter-ruby.wasm',
24
+ '.php': 'tree-sitter-php.wasm',
25
+ };
26
+ function extension(file) {
27
+ const name = file.slice(file.lastIndexOf('/') + 1);
28
+ const dot = name.lastIndexOf('.');
29
+ return dot < 0 ? '' : name.slice(dot).toLowerCase();
30
+ }
31
+ function grammarFile(file) {
32
+ return exports.CONSTRUCT_GRAMMARS[extension(file)] ?? null;
33
+ }
34
+ exports.grammarFile = grammarFile;
35
+ // Only known non-code formats are exempt. Unknown extensions remain unsupported.
36
+ const NON_CODE_EXTENSIONS = new Set([
37
+ '.md', '.mdx', '.txt', '.rst', '.adoc',
38
+ '.json', '.jsonc', '.yaml', '.yml', '.toml', '.xml', '.ini', '.cfg',
39
+ '.lock', '.csv', '.tsv',
40
+ '.png', '.jpg', '.jpeg', '.gif', '.webp', '.svg', '.ico', '.bmp',
41
+ '.ttf', '.otf', '.woff', '.woff2', '.eot',
42
+ '.mp3', '.wav', '.ogg', '.mp4', '.webm', '.pdf',
43
+ ]);
44
+ const NON_CODE_NAMES = new Set([
45
+ 'readme', 'license', 'licence', 'copying', 'notice', 'authors', 'changelog',
46
+ '.gitignore', '.gitattributes', '.gitmodules', '.editorconfig',
47
+ ]);
48
+ function constructFileSupport(file) {
49
+ if (grammarFile(file))
50
+ return 'supported';
51
+ const name = file.slice(file.lastIndexOf('/') + 1).toLowerCase();
52
+ return NON_CODE_EXTENSIONS.has(extension(file)) || NON_CODE_NAMES.has(name)
53
+ ? 'non-code'
54
+ : 'unsupported';
55
+ }
56
+ exports.constructFileSupport = constructFileSupport;
57
+ //# sourceMappingURL=grammar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grammar.js","sourceRoot":"","sources":["../../../src/audit/verify/grammar.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,oDAAoD;AACvC,QAAA,kBAAkB,GAAqC;IAClE,KAAK,EAAE,6BAA6B;IACpC,MAAM,EAAE,sBAAsB;IAC9B,KAAK,EAAE,6BAA6B;IACpC,MAAM,EAAE,6BAA6B;IACrC,MAAM,EAAE,6BAA6B;IACrC,MAAM,EAAE,6BAA6B;IACrC,KAAK,EAAE,yBAAyB;IAChC,KAAK,EAAE,qBAAqB;IAC5B,KAAK,EAAE,uBAAuB;IAC9B,OAAO,EAAE,uBAAuB;IAChC,KAAK,EAAE,uBAAuB;IAC9B,MAAM,EAAE,sBAAsB;CAC/B,CAAA;AAED,SAAS,SAAS,CAAC,IAAY;IAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;IAClD,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IACjC,OAAO,GAAG,GAAG,C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CAAC,IAAI,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC;QACzE,CAAC,CAAC,UAAU;QACZ,CAAC,CAAC,aAAa,CAAA;AACnB,CAAC;AARD,oDAQC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Node verification layer (tree-sitter + declarations + component verify).
3
+ *
4
+ * Imported through `@principal-ai/subsystems-core/audit`; never from the
5
+ * browser-safe package entry.
6
+ */
7
+ export { CONSTRUCT_GRAMMARS, constructFileSupport, grammarFile, } from './grammar';
8
+ export { parserFor, sharedParserFor, parseWith } from './parser';
9
+ export { declarationForSymbol, enclosingDeclaration, parseDeclarations, safeSource, type ParsedDeclaration, type ParsedDeclarations, type ResolvedConstructDeclaration, } from './declarations';
10
+ export { GATE_LABELS, deriveSpan, disposeSpanTreeCache, languageKey, type DeriveInput, type SpanClass, type SpanDerivation, type SpanTreeCache, } from './span';
11
+ export { verifySubsystemComponent, verifyVerdict, type VerifyComponentAugmentation, type VerifyComponentDeps, type VerifyComponentOptions, type VerifyComponentSignatureClaim, type VerifyComponentSpanClaim, } from './component';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/audit/verify/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,GACZ,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAChE,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,UAAU,EACV,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,4BAA4B,GAClC,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,WAAW,EACX,UAAU,EACV,oBAAoB,EACpB,WAAW,EACX,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,aAAa,GACnB,MAAM,QAAQ,CAAA;AACf,OAAO,EACL,wBAAwB,EACxB,aAAa,EACb,KAAK,2BAA2B,EAChC,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,6BAA6B,EAClC,KAAK,wBAAwB,GAC9B,MAAM,aAAa,CAAA"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /**
3
+ * Node verification layer (tree-sitter + declarations + component verify).
4
+ *
5
+ * Imported through `@principal-ai/subsystems-core/audit`; never from the
6
+ * browser-safe package entry.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.verifyVerdict = exports.verifySubsystemComponent = exports.languageKey = exports.disposeSpanTreeCache = exports.deriveSpan = exports.GATE_LABELS = exports.safeSource = exports.parseDeclarations = exports.enclosingDeclaration = exports.declarationForSymbol = exports.parseWith = exports.sharedParserFor = exports.parserFor = exports.grammarFile = exports.constructFileSupport = exports.CONSTRUCT_GRAMMARS = void 0;
10
+ var grammar_1 = require("./grammar");
11
+ Object.defineProperty(exports, "CONSTRUCT_GRAMMARS", { enumerable: true, get: function () { return grammar_1.CONSTRUCT_GRAMMARS; } });
12
+ Object.defineProperty(exports, "constructFileSupport", { enumerable: true, get: function () { return grammar_1.constructFileSupport; } });
13
+ Object.defineProperty(exports, "grammarFile", { enumerable: true, get: function () { return grammar_1.grammarFile; } });
14
+ var parser_1 = require("./parser");
15
+ Object.defineProperty(exports, "parserFor", { enumerable: true, get: function () { return parser_1.parserFor; } });
16
+ Object.defineProperty(exports, "sharedParserFor", { enumerable: true, get: function () { return parser_1.sharedParserFor; } });
17
+ Object.defineProperty(exports, "parseWith", { enumerable: true, get: function () { return parser_1.parseWith; } });
18
+ var declarations_1 = require("./declarations");
19
+ Object.defineProperty(exports, "declarationForSymbol", { enumerable: true, get: function () { return declarations_1.declarationForSymbol; } });
20
+ Object.defineProperty(exports, "enclosingDeclaration", { enumerable: true, get: function () { return declarations_1.enclosingDeclaration; } });
21
+ Object.defineProperty(exports, "parseDeclarations", { enumerable: true, get: function () { return declarations_1.parseDeclarations; } });
22
+ Object.defineProperty(exports, "safeSource", { enumerable: true, get: function () { return declarations_1.safeSource; } });
23
+ var span_1 = require("./span");
24
+ Object.defineProperty(exports, "GATE_LABELS", { enumerable: true, get: function () { return span_1.GATE_LABELS; } });
25
+ Object.defineProperty(exports, "deriveSpan", { enumerable: true, get: function () { return span_1.deriveSpan; } });
26
+ Object.defineProperty(exports, "disposeSpanTreeCache", { enumerable: true, get: function () { return span_1.disposeSpanTreeCache; } });
27
+ Object.defineProperty(exports, "languageKey", { enumerable: true, get: function () { return span_1.languageKey; } });
28
+ var component_1 = require("./component");
29
+ Object.defineProperty(exports, "verifySubsystemComponent", { enumerable: true, get: function () { return component_1.verifySubsystemComponent; } });
30
+ Object.defineProperty(exports, "verifyVerdict", { enumerable: true, get: function () { return component_1.verifyVerdict; } });
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/audit/verify/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,qCAIkB;AAHhB,6GAAA,kBAAkB,OAAA;AAClB,+GAAA,oBAAoB,OAAA;AACpB,sGAAA,WAAW,OAAA;AAEb,mCAAgE;AAAvD,mGAAA,SAAS,OAAA;AAAE,yGAAA,eAAe,OAAA;AAAE,mGAAA,SAAS,OAAA;AAC9C,+CAQuB;AAPrB,oHAAA,oBAAoB,OAAA;AACpB,oHAAA,oBAAoB,OAAA;AACpB,iHAAA,iBAAiB,OAAA;AACjB,0GAAA,UAAU,OAAA;AAKZ,+BASe;AARb,mGAAA,WAAW,OAAA;AACX,kGAAA,UAAU,OAAA;AACV,4GAAA,oBAAoB,OAAA;AACpB,mGAAA,WAAW,OAAA;AAMb,yCAQoB;AAPlB,qHAAA,wBAAwB,OAAA;AACxB,0GAAA,aAAa,OAAA"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Tree-sitter parser runtime shared by every audit host.
3
+ *
4
+ * WASM assets can be bundled next to the host entry (Studio copies them to
5
+ * `bun/tree-sitter`) or resolved from installed dependencies (the CLI). This
6
+ * module checks the bundled location first, then falls back to package
7
+ * resolution, so one parser implementation serves both.
8
+ */
9
+ import { Parser, type Tree } from 'web-tree-sitter';
10
+ export declare function parserFor(file: string): Promise<Parser | null>;
11
+ export declare function sharedParserFor(file: string): Promise<Parser | null>;
12
+ /**
13
+ * Parse one file, serialized. web-tree-sitter's WASM runtime aborts if a parser
14
+ * is used concurrently, and an abort poisons the cached runtime — so calls are
15
+ * chained, and a throw drops the runtime so the next file re-initializes rather
16
+ * than failing forever.
17
+ */
18
+ export declare function parseWith(parser: Parser, content: string): Promise<Tree>;
19
+ //# sourceMappingURL=parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../../src/audit/verify/parser.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,EAAE,MAAM,EAAY,KAAK,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAgD7D,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAOpE;AAeD,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAc1E;AAID;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBxE"}
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ /**
3
+ * Tree-sitter parser runtime shared by every audit host.
4
+ *
5
+ * WASM assets can be bundled next to the host entry (Studio copies them to
6
+ * `bun/tree-sitter`) or resolved from installed dependencies (the CLI). This
7
+ * module checks the bundled location first, then falls back to package
8
+ * resolution, so one parser implementation serves both.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.parseWith = exports.sharedParserFor = exports.parserFor = void 0;
12
+ const node_fs_1 = require("node:fs");
13
+ const node_module_1 = require("node:module");
14
+ const node_path_1 = require("node:path");
15
+ const web_tree_sitter_1 = require("web-tree-sitter");
16
+ const grammar_1 = require("./grammar");
17
+ const nodeRequire = (0, node_module_1.createRequire)(__filename);
18
+ function wasmPath(wasm) {
19
+ const configured = process.env['PRINCIPAL_TREE_SITTER_DIR']?.trim();
20
+ if (configured) {
21
+ const candidate = (0, node_path_1.join)(configured, wasm);
22
+ if ((0, node_fs_1.existsSync)(candidate))
23
+ return candidate;
24
+ }
25
+ // Bundled imports share the host entry's directory. The package resolver is
26
+ // only a fallback for unbundled source/scripts in a checkout.
27
+ const bundled = (0, node_path_1.join)(__dirname, 'tree-sitter', wasm);
28
+ if ((0, node_fs_1.existsSync)(bundled))
29
+ return bundled;
30
+ try {
31
+ return nodeRequire.resolve(wasm === 'tree-sitter.wasm'
32
+ ? `web-tree-sitter/${wasm}`
33
+ : `tree-sitter-wasms/out/${wasm}`);
34
+ }
35
+ catch {
36
+ throw new Error(`Missing Tree-sitter WASM asset: ${wasm}. Install web-tree-sitter and tree-sitter-wasms, or bundle the parser assets.`);
37
+ }
38
+ }
39
+ let parserInit = null;
40
+ const grammars = new Map();
41
+ async function loadLanguage(wasm) {
42
+ let pending = grammars.get(wasm);
43
+ if (pending)
44
+ return pending;
45
+ pending = (async () => {
46
+ if (!parserInit) {
47
+ const runtimePath = wasmPath('tree-sitter.wasm');
48
+ // Emscripten's default relative lookup points at the JS bundle, not the
49
+ // installed dependency, after a host bundles its entry point.
50
+ parserInit = web_tree_sitter_1.Parser.init({ locateFile: () => runtimePath });
51
+ }
52
+ await parserInit;
53
+ return web_tree_sitter_1.Language.load(wasmPath(wasm));
54
+ })();
55
+ grammars.set(wasm, pending);
56
+ return pending;
57
+ }
58
+ async function parserFor(file) {
59
+ const wasm = (0, grammar_1.grammarFile)(file);
60
+ if (!wasm)
61
+ return null;
62
+ const language = await loadLanguage(wasm);
63
+ const parser = new web_tree_sitter_1.Parser();
64
+ parser.setLanguage(language);
65
+ return parser;
66
+ }
67
+ exports.parserFor = parserFor;
68
+ /** Drop the cached runtime so the next parse re-initializes from scratch. */
69
+ function resetParserRuntime() {
70
+ parserInit = null;
71
+ grammars.clear();
72
+ parsers.clear();
73
+ }
74
+ /**
75
+ * One long-lived Parser per grammar, reused. Creating a Parser per file churns
76
+ * the WASM heap and aborts under a large run; a shared parser is safe because
77
+ * `parseWith` serializes every call.
78
+ */
79
+ const parsers = new Map();
80
+ async function sharedParserFor(file) {
81
+ const wasm = (0, grammar_1.grammarFile)(file);
82
+ if (!wasm)
83
+ return null;
84
+ let pending = parsers.get(wasm);
85
+ if (!pending) {
86
+ pending = (async () => {
87
+ const language = await loadLanguage(wasm);
88
+ const parser = new web_tree_sitter_1.Parser();
89
+ parser.setLanguage(language);
90
+ return parser;
91
+ })();
92
+ parsers.set(wasm, pending);
93
+ }
94
+ return pending;
95
+ }
96
+ exports.sharedParserFor = sharedParserFor;
97
+ let parseQueue = Promise.resolve();
98
+ /**
99
+ * Parse one file, serialized. web-tree-sitter's WASM runtime aborts if a parser
100
+ * is used concurrently, and an abort poisons the cached runtime — so calls are
101
+ * chained, and a throw drops the runtime so the next file re-initializes rather
102
+ * than failing forever.
103
+ */
104
+ function parseWith(parser, content) {
105
+ const task = async () => {
106
+ try {
107
+ const tree = parser.parse(content);
108
+ if (!tree)
109
+ throw new Error('Tree-sitter returned no syntax tree.');
110
+ return tree;
111
+ }
112
+ catch (error) {
113
+ resetParserRuntime();
114
+ throw error;
115
+ }
116
+ };
117
+ const result = parseQueue.then(task, task);
118
+ parseQueue = result.then(() => undefined, () => undefined);
119
+ return result;
120
+ }
121
+ exports.parseWith = parseWith;
122
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../src/audit/verify/parser.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,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Q,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,CAAA;YACzC,MAAM,MAAM,GAAG,IAAI,wBAAM,EAAE,CAAA;YAC3B,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;YAC5B,OAAO,MAAM,CAAA;QACf,CAAC,CAAC,EAAE,CAAA;QACJ,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;KAC3B;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAdD,0CAcC;AAED,IAAI,UAAU,GAAqB,OAAO,CAAC,OAAO,EAAE,CAAA;AAEpD;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,MAAc,EAAE,OAAe;IACvD,MAAM,IAAI,GAAG,KAAK,IAAmB,EAAE;QACrC,IAAI;YACF,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;YAClC,IAAI,CAAC,IAAI;gBAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAA;YAClE,OAAO,IAAI,CAAA;SACZ;QAAC,OAAO,KAAK,EAAE;YACd,kBAAkB,EAAE,CAAA;YACpB,MAAM,KAAK,CAAA;SACZ;IACH,CAAC,CAAA;IACD,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IAC1C,UAAU,GAAG,MAAM,CAAC,IAAI,CACtB,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CAChB,CAAA;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAjBD,8BAiBC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Dry-run span derivability classifier — graphify anchor + tree-sitter parse.
3
+ *
4
+ * For every code component: resolve the graphify definition node, read the file
5
+ * at its `source_location` start line, parse with tree-sitter, and derive the
6
+ * declaration's end line. Then classify how *decidable* that derivation is —
7
+ * deterministic (a stored span re-hashes unchanged), trivial (all structural
8
+ * gates pass), ambiguous (candidates/gates disagree), or unknown (no anchor /
9
+ * grammar / parse).
10
+ *
11
+ * Read-only by design: this never writes a span.
12
+ */
13
+ import type { Tree } from 'web-tree-sitter';
14
+ import type { ComponentAnchorResult } from '../../graphify/anchor';
15
+ /** `ts`/`tsx`/`js`/`py` — the dialect key used below. */
16
+ export declare function languageKey(file: string): string | null;
17
+ export type SpanClass = 'deterministic' | 'trivial' | 'ambiguous' | 'unknown' | 'skipped';
18
+ export interface SpanDerivation {
19
+ class: SpanClass;
20
+ language: string | null;
21
+ graphifyStart: number | null;
22
+ derivedEnd: number | null;
23
+ declNodeType: string | null;
24
+ declName: string | null;
25
+ failedGates: string[];
26
+ evidence: string[];
27
+ }
28
+ export declare const GATE_LABELS: Record<string, string>;
29
+ /** Per-audit-pass parse-tree cache, keyed by repo file path. */
30
+ export type SpanTreeCache = Map<string, Tree>;
31
+ export interface DeriveInput {
32
+ content: string;
33
+ file: string;
34
+ symbol?: string;
35
+ construct?: string;
36
+ anchor: ComponentAnchorResult;
37
+ storedSpan?: {
38
+ startLine: number;
39
+ endLine: number;
40
+ contentHash: string;
41
+ };
42
+ /** Shared across components of the same pass (parse once per file). */
43
+ treeCache?: SpanTreeCache;
44
+ }
45
+ /** Release parser-owned trees when a caller did not provide a pass cache. */
46
+ export declare function disposeSpanTreeCache(treeCache: SpanTreeCache): void;
47
+ /** Classify one declaration and dispose its temporary WASM tree when unshared. */
48
+ export declare function deriveSpan(input: DeriveInput): Promise<SpanDerivation>;
49
+ //# sourceMappingURL=span.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"span.d.ts","sourceRoot":"","sources":["../../../src/audit/verify/span.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAA;AAKlE,yDAAyD;AACzD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,G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