@securecode-ai/mcp 0.1.0

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 (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +71 -0
  3. package/dist/api/client.d.ts +22 -0
  4. package/dist/api/client.js +141 -0
  5. package/dist/api/client.js.map +1 -0
  6. package/dist/api/types.d.ts +129 -0
  7. package/dist/api/types.js +3 -0
  8. package/dist/api/types.js.map +1 -0
  9. package/dist/approval/auditLog.d.ts +3 -0
  10. package/dist/approval/auditLog.js +67 -0
  11. package/dist/approval/auditLog.js.map +1 -0
  12. package/dist/approval/broker.d.ts +11 -0
  13. package/dist/approval/broker.js +252 -0
  14. package/dist/approval/broker.js.map +1 -0
  15. package/dist/approval/types.d.ts +26 -0
  16. package/dist/approval/types.js +58 -0
  17. package/dist/approval/types.js.map +1 -0
  18. package/dist/attack/agentLoop.d.ts +21 -0
  19. package/dist/attack/agentLoop.js +148 -0
  20. package/dist/attack/agentLoop.js.map +1 -0
  21. package/dist/attack/executor.d.ts +17 -0
  22. package/dist/attack/executor.js +162 -0
  23. package/dist/attack/executor.js.map +1 -0
  24. package/dist/attack/policy.d.ts +26 -0
  25. package/dist/attack/policy.js +73 -0
  26. package/dist/attack/policy.js.map +1 -0
  27. package/dist/attack/protocol.d.ts +64 -0
  28. package/dist/attack/protocol.js +3 -0
  29. package/dist/attack/protocol.js.map +1 -0
  30. package/dist/attack/report.d.ts +16 -0
  31. package/dist/attack/report.js +54 -0
  32. package/dist/attack/report.js.map +1 -0
  33. package/dist/auth/credentialStore.d.ts +20 -0
  34. package/dist/auth/credentialStore.js +148 -0
  35. package/dist/auth/credentialStore.js.map +1 -0
  36. package/dist/auth/keychain.d.ts +14 -0
  37. package/dist/auth/keychain.js +267 -0
  38. package/dist/auth/keychain.js.map +1 -0
  39. package/dist/index.d.ts +2 -0
  40. package/dist/index.js +170 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/mcp/server.d.ts +2 -0
  43. package/dist/mcp/server.js +183 -0
  44. package/dist/mcp/server.js.map +1 -0
  45. package/dist/mcp/tools.d.ts +2 -0
  46. package/dist/mcp/tools.js +120 -0
  47. package/dist/mcp/tools.js.map +1 -0
  48. package/dist/mcp/types.d.ts +26 -0
  49. package/dist/mcp/types.js +3 -0
  50. package/dist/mcp/types.js.map +1 -0
  51. package/dist/project-map/astHelpers.d.ts +89 -0
  52. package/dist/project-map/astHelpers.js +468 -0
  53. package/dist/project-map/astHelpers.js.map +1 -0
  54. package/dist/project-map/cache.d.ts +11 -0
  55. package/dist/project-map/cache.js +86 -0
  56. package/dist/project-map/cache.js.map +1 -0
  57. package/dist/project-map/confidence.d.ts +50 -0
  58. package/dist/project-map/confidence.js +87 -0
  59. package/dist/project-map/confidence.js.map +1 -0
  60. package/dist/project-map/crossFile.d.ts +73 -0
  61. package/dist/project-map/crossFile.js +33 -0
  62. package/dist/project-map/crossFile.js.map +1 -0
  63. package/dist/project-map/detectors.d.ts +83 -0
  64. package/dist/project-map/detectors.js +376 -0
  65. package/dist/project-map/detectors.js.map +1 -0
  66. package/dist/project-map/layer1.d.ts +74 -0
  67. package/dist/project-map/layer1.js +928 -0
  68. package/dist/project-map/layer1.js.map +1 -0
  69. package/dist/project-map/layer2.d.ts +30 -0
  70. package/dist/project-map/layer2.js +249 -0
  71. package/dist/project-map/layer2.js.map +1 -0
  72. package/dist/project-map/mapBuilder.d.ts +17 -0
  73. package/dist/project-map/mapBuilder.js +164 -0
  74. package/dist/project-map/mapBuilder.js.map +1 -0
  75. package/dist/project-map/parserLoader.d.ts +61 -0
  76. package/dist/project-map/parserLoader.js +175 -0
  77. package/dist/project-map/parserLoader.js.map +1 -0
  78. package/dist/project-map/schemas.d.ts +28 -0
  79. package/dist/project-map/schemas.js +131 -0
  80. package/dist/project-map/schemas.js.map +1 -0
  81. package/dist/project-map/types.d.ts +232 -0
  82. package/dist/project-map/types.js +61 -0
  83. package/dist/project-map/types.js.map +1 -0
  84. package/dist/tools/attack.d.ts +2 -0
  85. package/dist/tools/attack.js +80 -0
  86. package/dist/tools/attack.js.map +1 -0
  87. package/dist/tools/fix.d.ts +2 -0
  88. package/dist/tools/fix.js +60 -0
  89. package/dist/tools/fix.js.map +1 -0
  90. package/dist/tools/map.d.ts +2 -0
  91. package/dist/tools/map.js +46 -0
  92. package/dist/tools/map.js.map +1 -0
  93. package/dist/tools/scan.d.ts +2 -0
  94. package/dist/tools/scan.js +55 -0
  95. package/dist/tools/scan.js.map +1 -0
  96. package/dist/utils/files.d.ts +8 -0
  97. package/dist/utils/files.js +79 -0
  98. package/dist/utils/files.js.map +1 -0
  99. package/package.json +53 -0
  100. package/resources/tree-sitter/tree-sitter-javascript.wasm +0 -0
  101. package/resources/tree-sitter/tree-sitter-python.wasm +0 -0
  102. package/resources/tree-sitter/tree-sitter-tsx.wasm +0 -0
  103. package/resources/tree-sitter/tree-sitter-typescript.wasm +0 -0
@@ -0,0 +1,468 @@
1
+ "use strict";
2
+ /**
3
+ * Phase 4 — generic Tree-sitter AST helpers shared by Layer 1 (static
4
+ * extraction) and Layer 2 (dynamic detection). Keeping them in one place
5
+ * means the two layers share the same notion of "a call to X" and "a
6
+ * string literal at this position".
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.walk = walk;
43
+ exports.walkNamed = walkNamed;
44
+ exports.isStringLiteral = isStringLiteral;
45
+ exports.isIdentifier = isIdentifier;
46
+ exports.stringLiteralValue = stringLiteralValue;
47
+ exports.firstAncestor = firstAncestor;
48
+ exports.baseIdentifier = baseIdentifier;
49
+ exports.callParts = callParts;
50
+ exports.resolveIdentifier = resolveIdentifier;
51
+ exports.collectStringAssignments = collectStringAssignments;
52
+ exports.pythonModuleSpec = pythonModuleSpec;
53
+ exports.collectImports = collectImports;
54
+ exports.resolveModulePath = resolveModulePath;
55
+ const fs = __importStar(require("fs"));
56
+ const path = __importStar(require("path"));
57
+ /** Walk the tree depth-first, yielding every named + unnamed node. */
58
+ function* walk(node) {
59
+ yield node;
60
+ for (const child of node.children) {
61
+ yield* walk(child);
62
+ }
63
+ }
64
+ /** Walk named nodes only (skips punctuation/brackets). */
65
+ function* walkNamed(node) {
66
+ for (const n of walk(node)) {
67
+ if (n.type !== '' && !n.type.startsWith('.')) {
68
+ yield n;
69
+ }
70
+ }
71
+ }
72
+ /** True iff node is a string-literal node (JS/TS/Python all share 'string'). */
73
+ function isStringLiteral(node) {
74
+ return node.type === 'string';
75
+ }
76
+ /** True iff node is an identifier (variable reference). */
77
+ function isIdentifier(node) {
78
+ return node.type === 'identifier';
79
+ }
80
+ /** Get the text of a string literal without the surrounding quotes. */
81
+ function stringLiteralValue(node, source) {
82
+ if (!isStringLiteral(node))
83
+ return '';
84
+ const raw = node.startIndex < node.endIndex
85
+ ? source.slice(node.startIndex, node.endIndex)
86
+ : '';
87
+ // Strip surrounding quotes/backticks. Template literals keep ${...} as-is
88
+ // (callers can detect template_argument_substitution if they need exactness).
89
+ if (raw.length >= 2) {
90
+ const f = raw[0];
91
+ const l = raw[raw.length - 1];
92
+ if ((f === '"' && l === '"') || (f === "'" && l === "'") || (f === '`' && l === '`')) {
93
+ return raw.slice(1, -1);
94
+ }
95
+ }
96
+ return raw;
97
+ }
98
+ /**
99
+ * Find the first ancestor matching a predicate.
100
+ */
101
+ function firstAncestor(node, pred) {
102
+ let cur = node.parent;
103
+ while (cur) {
104
+ if (pred(cur))
105
+ return cur;
106
+ cur = cur.parent;
107
+ }
108
+ return null;
109
+ }
110
+ /**
111
+ * Walk an access chain down to the identifier it is rooted at.
112
+ *
113
+ * `res.status(201)` -> `res`, `prisma.user` -> `prisma`,
114
+ * `supabase.from('x').select('*')` -> `supabase`. Returns null when the chain
115
+ * bottoms out in something that is not an identifier (a literal, `this`, an
116
+ * immediately-invoked function), in which case callers fall back to the text.
117
+ */
118
+ function baseIdentifier(node, source) {
119
+ let cur = node;
120
+ // Bounded to keep a pathological/incorrectly-parsed tree from spinning.
121
+ for (let hops = 0; cur && hops < 64; hops++) {
122
+ if (isIdentifier(cur))
123
+ return source.slice(cur.startIndex, cur.endIndex);
124
+ switch (cur.type) {
125
+ case 'member_expression':
126
+ case 'attribute':
127
+ case 'call_expression':
128
+ case 'call':
129
+ case 'subscript_expression':
130
+ case 'subscript':
131
+ cur = cur.child(0);
132
+ break;
133
+ case 'await_expression':
134
+ case 'await':
135
+ case 'parenthesized_expression':
136
+ case 'non_null_expression':
137
+ case 'as_expression':
138
+ cur = cur.namedChildren[0] ?? null;
139
+ break;
140
+ default:
141
+ return null;
142
+ }
143
+ }
144
+ return null;
145
+ }
146
+ /** Parse a call node into CallParts. Returns null if not a recognizable call. */
147
+ function callParts(callNode, source) {
148
+ // JS/TS: 'call_expression' with function = 'member_expression'.
149
+ // Python: 'call' with func = 'attribute' (e.g. app.get).
150
+ const func = callNode.child(0);
151
+ if (!func)
152
+ return null;
153
+ let receiver = null;
154
+ let receiverText = null;
155
+ let method = '';
156
+ if (func.type === 'member_expression' || func.type === 'attribute') {
157
+ const obj = func.child(0);
158
+ const prop = func.child(func.childCount - 1);
159
+ if (obj && prop) {
160
+ receiverText = source.slice(obj.startIndex, obj.endIndex);
161
+ receiver = baseIdentifier(obj, source) ?? receiverText;
162
+ method = source.slice(prop.startIndex, prop.endIndex);
163
+ }
164
+ }
165
+ else if (func.type === 'identifier') {
166
+ method = source.slice(func.startIndex, func.endIndex);
167
+ }
168
+ else {
169
+ return null;
170
+ }
171
+ // Collect args. JS: arguments node; Python: arguments node. Both have
172
+ // named children for the positional args.
173
+ const argsNode = callNode.child(callNode.childCount - 1);
174
+ const args = [];
175
+ if (argsNode) {
176
+ for (const c of argsNode.namedChildren) {
177
+ args.push(c);
178
+ }
179
+ }
180
+ return {
181
+ receiver,
182
+ receiverText,
183
+ method,
184
+ args,
185
+ line: callNode.startPosition.row,
186
+ };
187
+ }
188
+ /**
189
+ * Resolve an identifier to a string value when it's defined as a
190
+ * simple const/variable assignment to a string literal IN THE SAME FILE.
191
+ * Used for intra-file dataflow confidence (0.6).
192
+ *
193
+ * `assignments` is a map of variableName -> stringLiteralValue, built by
194
+ * a pre-pass over the file.
195
+ */
196
+ function resolveIdentifier(name, assignments) {
197
+ return assignments.get(name) ?? null;
198
+ }
199
+ /**
200
+ * Build a map of `name -> string literal value` for every
201
+ * const X = 'literal' / let X = 'literal' / X = 'literal'
202
+ * in the file. Also handles Python `X = 'literal'` at module level.
203
+ */
204
+ function collectStringAssignments(root, source) {
205
+ const out = new Map();
206
+ for (const n of walk(root)) {
207
+ // JS/TS lexical_declaration / variable_declaration
208
+ if (n.type === 'lexical_declaration' || n.type === 'variable_declaration') {
209
+ for (const decl of n.namedChildren) {
210
+ if (decl.type !== 'variable_declarator')
211
+ continue;
212
+ const name = decl.child(0);
213
+ const value = decl.child(decl.childCount - 1);
214
+ if (name && value && isIdentifier(name) && isStringLiteral(value)) {
215
+ out.set(source.slice(name.startIndex, name.endIndex), stringLiteralValue(value, source));
216
+ }
217
+ }
218
+ continue;
219
+ }
220
+ // Python: simple assignment statement `name = "str"`
221
+ if (n.type === 'assignment' || n.type === 'assign') {
222
+ const left = n.child(0);
223
+ const right = n.child(n.childCount - 1);
224
+ if (left && right && isIdentifier(left) && isStringLiteral(right)) {
225
+ out.set(source.slice(left.startIndex, left.endIndex), stringLiteralValue(right, source));
226
+ }
227
+ continue;
228
+ }
229
+ // JS expression statement that's an assignment (X = "y" without var)
230
+ if (n.type === 'assignment_expression') {
231
+ const left = n.child(0);
232
+ const right = n.child(n.childCount - 1);
233
+ if (left && right && isIdentifier(left) && isStringLiteral(right)) {
234
+ out.set(source.slice(left.startIndex, left.endIndex), stringLiteralValue(right, source));
235
+ }
236
+ }
237
+ }
238
+ return out;
239
+ }
240
+ /**
241
+ * Collect the local names bound by a destructuring pattern.
242
+ *
243
+ * Handles object and array patterns, renames (`{ a: b }` binds `b`), defaults
244
+ * (`{ a = 1 }` binds `a`), and rest elements (`{ ...rest }`). Nested patterns
245
+ * recurse. Used to map destructured `require()` bindings back to their module.
246
+ */
247
+ function boundPatternNames(pattern, source) {
248
+ const names = [];
249
+ const visit = (node) => {
250
+ switch (node.type) {
251
+ case 'object_pattern':
252
+ case 'array_pattern':
253
+ for (const child of node.namedChildren)
254
+ visit(child);
255
+ return;
256
+ case 'pair_pattern': {
257
+ // { key: local } — only the value side introduces a binding.
258
+ const value = node.namedChildren[node.namedChildren.length - 1];
259
+ if (value)
260
+ visit(value);
261
+ return;
262
+ }
263
+ case 'object_assignment_pattern':
264
+ case 'assignment_pattern': {
265
+ // { a = default } — the left side is the binding.
266
+ const target = node.namedChildren[0];
267
+ if (target)
268
+ visit(target);
269
+ return;
270
+ }
271
+ case 'rest_pattern':
272
+ case 'shorthand_property_identifier_pattern':
273
+ case 'shorthand_property_identifier':
274
+ for (const child of node.namedChildren)
275
+ visit(child);
276
+ if (node.namedChildren.length === 0) {
277
+ names.push(source.slice(node.startIndex, node.endIndex));
278
+ }
279
+ return;
280
+ default:
281
+ if (isIdentifier(node)) {
282
+ names.push(source.slice(node.startIndex, node.endIndex));
283
+ return;
284
+ }
285
+ for (const child of node.namedChildren)
286
+ visit(child);
287
+ }
288
+ };
289
+ visit(pattern);
290
+ return names;
291
+ }
292
+ /**
293
+ * Normalise a Python module reference into the same relative-path shape the
294
+ * JS/TS import specs use, so one resolver handles both.
295
+ *
296
+ * `.deps` -> `./deps`
297
+ * `..models` -> `../models`
298
+ * `.` -> `./`
299
+ * `sqlalchemy.orm` -> unchanged (absolute; matched by name, not resolved)
300
+ */
301
+ function pythonModuleSpec(mod) {
302
+ const trimmed = mod.trim();
303
+ const leading = /^\.+/.exec(trimmed);
304
+ if (!leading)
305
+ return trimmed;
306
+ const depth = leading[0].length;
307
+ const rest = trimmed.slice(depth).replace(/\./g, '/');
308
+ const prefix = depth === 1 ? './' : '../'.repeat(depth - 1);
309
+ return prefix + rest;
310
+ }
311
+ /** Collect every import in the file as { localName -> sourceSpec }. */
312
+ function collectImports(root, source) {
313
+ const out = new Map();
314
+ for (const n of walk(root)) {
315
+ // JS/TS import statements. Python also uses the node type
316
+ // `import_statement`, so the JS shape is only claimed when the
317
+ // statement actually carries a string module specifier — otherwise it
318
+ // falls through to the Python handling below.
319
+ if (n.type === 'import_statement' || n.type === 'import_declaration') {
320
+ const sourceNode = n.namedChildren.find(c => isStringLiteral(c));
321
+ if (sourceNode) {
322
+ const from = stringLiteralValue(sourceNode, source);
323
+ // `import { a, b as c } from 'mod'` nests the specifiers two
324
+ // levels down (import_clause > named_imports > import_specifier),
325
+ // so the bindings are gathered by walking the statement rather
326
+ // than by reading direct children — named imports are the
327
+ // dominant ESM idiom and missing them makes the file look like
328
+ // it imports nothing.
329
+ for (const spec of walk(n)) {
330
+ if (spec === sourceNode)
331
+ continue;
332
+ if (spec.type === 'import_specifier' || spec.type === 'namespace_import') {
333
+ const local = spec.namedChildren[spec.namedChildren.length - 1];
334
+ if (local && isIdentifier(local)) {
335
+ out.set(source.slice(local.startIndex, local.endIndex), from);
336
+ }
337
+ continue;
338
+ }
339
+ // Default import: an identifier directly under the clause.
340
+ if (isIdentifier(spec) && spec.parent?.type === 'import_clause') {
341
+ out.set(source.slice(spec.startIndex, spec.endIndex), from);
342
+ }
343
+ }
344
+ continue;
345
+ }
346
+ }
347
+ // Python `import a.b`, `import a.b as c`, `from x.y import A, B as C`.
348
+ //
349
+ // The imported NAMES are `dotted_name` nodes just like the module is,
350
+ // so they cannot be told apart by node type — only by position. The
351
+ // module is the first named child; everything after it is a binding.
352
+ if (n.type === 'import_statement' || n.type === 'import_from_statement') {
353
+ const children = n.namedChildren;
354
+ if (children.length === 0)
355
+ continue;
356
+ const bindLast = (node, mod) => {
357
+ // `import os.path` binds `os`; `from x import a` binds `a`.
358
+ const text = source.slice(node.startIndex, node.endIndex);
359
+ const segments = text.split('.');
360
+ const local = n.type === 'import_from_statement'
361
+ ? segments[segments.length - 1]
362
+ : segments[0];
363
+ if (local)
364
+ out.set(local.trim(), mod);
365
+ };
366
+ if (n.type === 'import_from_statement') {
367
+ const moduleNode = children[0];
368
+ const rawMod = source.slice(moduleNode.startIndex, moduleNode.endIndex);
369
+ const mod = pythonModuleSpec(rawMod);
370
+ const packageOnly = /^\.+$/.test(rawMod.trim());
371
+ for (const c of children.slice(1)) {
372
+ if (c.type === 'wildcard_import')
373
+ continue;
374
+ if (c.type === 'aliased_import') {
375
+ const alias = c.child(c.childCount - 1);
376
+ if (alias && isIdentifier(alias)) {
377
+ out.set(source.slice(alias.startIndex, alias.endIndex), mod);
378
+ }
379
+ continue;
380
+ }
381
+ // `from . import views` names a sibling MODULE, not a symbol
382
+ // of the current package, so the spec has to grow the name
383
+ // for it to resolve to a file.
384
+ if (packageOnly) {
385
+ const name = source.slice(c.startIndex, c.endIndex).trim();
386
+ out.set(name.split('.').pop(), mod + name);
387
+ continue;
388
+ }
389
+ bindLast(c, mod);
390
+ }
391
+ continue;
392
+ }
393
+ // Plain `import a.b [as c]` — every child is its own module.
394
+ for (const c of children) {
395
+ if (c.type === 'aliased_import') {
396
+ const target = c.namedChildren[0];
397
+ const alias = c.child(c.childCount - 1);
398
+ const mod = target ? source.slice(target.startIndex, target.endIndex) : '';
399
+ if (alias && isIdentifier(alias)) {
400
+ out.set(source.slice(alias.startIndex, alias.endIndex), mod);
401
+ }
402
+ continue;
403
+ }
404
+ if (c.type === 'dotted_name' || isIdentifier(c)) {
405
+ bindLast(c, source.slice(c.startIndex, c.endIndex));
406
+ }
407
+ }
408
+ continue;
409
+ }
410
+ // CommonJS: const X = require('mod') and const { A, B: C } = require('mod').
411
+ // Destructured requires are the dominant idiom for several libraries we
412
+ // must detect (`const { PrismaClient } = require('@prisma/client')`), so
413
+ // binding patterns are walked for identifiers rather than skipped.
414
+ if (n.type === 'lexical_declaration' || n.type === 'variable_declaration') {
415
+ for (const decl of n.namedChildren) {
416
+ if (decl.type !== 'variable_declarator')
417
+ continue;
418
+ const name = decl.child(0);
419
+ const value = decl.child(decl.childCount - 1);
420
+ if (!name || !value || value.type !== 'call_expression')
421
+ continue;
422
+ const parts = callParts(value, source);
423
+ if (!parts || parts.method !== 'require' || parts.receiver !== null || parts.args.length !== 1) {
424
+ continue;
425
+ }
426
+ const a = parts.args[0];
427
+ if (!isStringLiteral(a))
428
+ continue;
429
+ const from = stringLiteralValue(a, source);
430
+ if (isIdentifier(name)) {
431
+ out.set(source.slice(name.startIndex, name.endIndex), from);
432
+ continue;
433
+ }
434
+ // Binding pattern: map every bound local name to the module.
435
+ for (const local of boundPatternNames(name, source)) {
436
+ out.set(local, from);
437
+ }
438
+ }
439
+ }
440
+ }
441
+ return out;
442
+ }
443
+ /** Resolve a module spec like './middleware/auth' to an absolute file path. */
444
+ function resolveModulePath(spec, fromFile, workspaceRoot) {
445
+ if (!spec.startsWith('.') && !spec.startsWith('/'))
446
+ return null; // bare specifier = node_modules
447
+ const base = path.resolve(path.dirname(fromFile), spec);
448
+ const candidates = [
449
+ base,
450
+ base + '.ts',
451
+ base + '.tsx',
452
+ base + '.js',
453
+ base + '.jsx',
454
+ base + '.mjs',
455
+ base + '.cjs',
456
+ base + '.py',
457
+ path.join(base, 'index.ts'),
458
+ path.join(base, 'index.js'),
459
+ path.join(base, 'index.tsx'),
460
+ path.join(base, '__init__.py'),
461
+ ];
462
+ for (const c of candidates) {
463
+ if (fs.existsSync(c))
464
+ return path.relative(workspaceRoot, c).replace(/\\/g, '/');
465
+ }
466
+ return null;
467
+ }
468
+ //# sourceMappingURL=astHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astHelpers.js","sourceRoot":"","sources":["../../src/project-map/astHelpers.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOH,oBAKC;AAGD,8BAMC;AAGD,0CAEC;AAGD,oCAEC;AAGD,gDAeC;AAKD,sCAUC;AAuCD,wCA0BC;AAGD,8BAyCC;AAUD,8CAKC;AAOD,4DAkCC;AA2DD,4CAQC;AAGD,wCA8HC;AAGD,8CAyBC;AAncD,uCAAyB;AACzB,2CAA6B;AAG7B,sEAAsE;AACtE,QAAe,CAAC,CAAC,IAAI,CAAC,IAAoB;IACtC,MAAM,IAAI,CAAC;IACX,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;AACL,CAAC;AAED,0DAA0D;AAC1D,QAAe,CAAC,CAAC,SAAS,CAAC,IAAoB;IAC3C,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACzB,IAAI,CAAC,CAAC,IAAI,KAAK,EAA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AC;QAC3B,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC;QAC3B,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC;KACjC,CAAC;IACF,KAAK,MAAM,CAAC,IAAI,UAAU,EAAE,CAAC;QACzB,IAAI,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;YAAE,OAAO,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { ProjectMap } from './types';
2
+ export declare function cachePath(workspaceRoot: string): string;
3
+ export declare function readCache(workspaceRoot: string): ProjectMap | null;
4
+ export declare function writeCache(workspaceRoot: string, map: ProjectMap): void;
5
+ export declare function cacheStatus(workspaceRoot: string): {
6
+ exists: boolean;
7
+ builtAt?: number;
8
+ version?: number;
9
+ endpointCount?: number;
10
+ fileCount?: number;
11
+ };
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.cachePath = cachePath;
37
+ exports.readCache = readCache;
38
+ exports.writeCache = writeCache;
39
+ exports.cacheStatus = cacheStatus;
40
+ const fs = __importStar(require("fs"));
41
+ const path = __importStar(require("path"));
42
+ const types_1 = require("./types");
43
+ const CACHE_DIR = '.securecode';
44
+ const CACHE_FILE = 'project-map.json';
45
+ function cachePath(workspaceRoot) {
46
+ return path.join(workspaceRoot, CACHE_DIR, CACHE_FILE);
47
+ }
48
+ function readCache(workspaceRoot) {
49
+ const p = cachePath(workspaceRoot);
50
+ try {
51
+ if (!fs.existsSync(p))
52
+ return null;
53
+ const raw = fs.readFileSync(p, 'utf8');
54
+ const map = JSON.parse(raw);
55
+ if (!map.version || map.version > types_1.PROJECT_MAP_SCHEMA_VERSION) {
56
+ return null;
57
+ }
58
+ return map;
59
+ }
60
+ catch {
61
+ return null;
62
+ }
63
+ }
64
+ function writeCache(workspaceRoot, map) {
65
+ const dir = path.join(workspaceRoot, CACHE_DIR);
66
+ if (!fs.existsSync(dir)) {
67
+ fs.mkdirSync(dir, { recursive: true });
68
+ }
69
+ const p = cachePath(workspaceRoot);
70
+ const tmp = p + '.tmp';
71
+ fs.writeFileSync(tmp, JSON.stringify(map, null, 2), 'utf8');
72
+ fs.renameSync(tmp, p);
73
+ }
74
+ function cacheStatus(workspaceRoot) {
75
+ const map = readCache(workspaceRoot);
76
+ if (!map)
77
+ return { exists: false };
78
+ return {
79
+ exists: true,
80
+ builtAt: map.builtAt,
81
+ version: map.version,
82
+ endpointCount: (map.endpoints || []).length,
83
+ fileCount: map.files ? Object.keys(map.files).length : 0,
84
+ };
85
+ }
86
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/project-map/cache.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,8BAEC;AAED,8BAaC;AAED,gCASC;AAED,kCAgBC;AAtDD,uCAAyB;AACzB,2CAA6B;AAE7B,mCAAqD;AAErD,MAAM,SAAS,GAAG,aAAa,CAAC;AAChC,MAAM,UAAU,GAAG,kBAAkB,CAAC;AAEtC,SAAgB,SAAS,CAAC,aAAqB;IAC3C,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AAC3D,CAAC;AAED,SAAgB,SAAS,CAAC,aAAqB;IAC3C,MAAM,CAAC,GAAG,SAAS,CAAC,aAAa,CAAC,CAAC;IACnC,IAAI,CAAC;QACD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;YAAE,OAAO,IAAI,CAAC;QACnC,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACvC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAe,CAAC;QAC1C,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,GAAG,kCAA0B,EAAE,CAAC;YAC3D,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,IAAI,CAAC;IAChB,CAAC;AACL,CAAC;AAED,SAAgB,UAAU,CAAC,aAAqB,EAAE,GAAe;IAC7D,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IAChD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACtB,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3C,CAAC;IACD,MAAM,CAAC,GAAG,SAAS,CAAC,aAAa,CAAC,CAAC;IACnC,MAAM,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC;IACvB,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAC5D,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;AAC1B,CAAC;AAED,SAAgB,WAAW,CAAC,aAAqB;IAO7C,MAAM,GAAG,GAAG,SAAS,CAAC,aAAa,CAAC,CAAC;IACrC,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IACnC,OAAO;QACH,MAAM,EAAE,IAAI;QACZ,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,aAAa,EAAE,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,MAAM;QAC3C,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;KAC3D,CAAC;AACN,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Phase 4 — confidence scoring + runtime-confirmed upgrade.
3
+ *
4
+ * Centralizes the README's confidence model so Layer 1, Layer 2, the
5
+ * runtime trace merger, and the cache all share one definition.
6
+ *
7
+ * 1.0 — STATIC_LITERAL (string-literal path, directly-registered middleware)
8
+ * 0.8 — RUNTIME_CONFIRMED (trace hook observed the relationship)
9
+ * 0.6 — INTRA_FILE_DATAFLOW (resolved from a same-file const/variable)
10
+ * 0.2 — UNRESOLVED (could not statically resolve; not yet traced)
11
+ * 0.15 — META_PROGRAMMING (new Function / vm.runIn* / dynamic require)
12
+ * 0.1 — FULLY_UNRESOLVED (no usable evidence)
13
+ * 0.0 — DYNAMIC_PATTERN (D1-D10 flagged but un-confirmed)
14
+ */
15
+ import { EndpointRecord, MiddlewareEntry } from './types';
16
+ /**
17
+ * Pick the lowest confidence among the evidence gathered for the record.
18
+ *
19
+ * `pathConfidence` counts as evidence: a route registered at a string-literal
20
+ * path is well-understood even if it has no middleware, params or calls.
21
+ *
22
+ * A record with NO evidence at all — nothing resolved about the path and no
23
+ * relationships — scores FULLY_UNRESOLVED. Scoring it STATIC_LITERAL would
24
+ * report maximum certainty about an endpoint we know nothing about, and this
25
+ * value travels into EndpointContext and on to the AI scan stages.
26
+ */
27
+ export declare function aggregateConfidence(record: EndpointRecord): number;
28
+ /**
29
+ * Map a Layer 2 pattern type to the META_PROGRAMMING confidence the
30
+ * record gets if that pattern is the only evidence for a relationship.
31
+ * (D1-D10 all start at 0.0; once a runtime trace confirms them, they
32
+ * jump to 0.8.)
33
+ */
34
+ export declare function patternMetaConfidence(_patternType: string): number;
35
+ /**
36
+ * Upgrade a record's confidence after a runtime trace confirms it.
37
+ * Per the README: confirmed-but-previously-unresolved entries go 0.2 -> 0.8.
38
+ * Records that were META_PROGRAMMING (0.15) also upgrade to 0.8 on confirmation.
39
+ *
40
+ * Absence of evidence (trace ran, endpoint not hit) does NOT downgrade —
41
+ * the spec is explicit: we leave confidence low, we don't mark "absent".
42
+ */
43
+ export declare function applyRuntimeConfirmation(record: EndpointRecord): EndpointRecord;
44
+ /**
45
+ * Cross-file middleware resolution: given a middleware entry whose
46
+ * sourceFile is unknown (because the import was dynamic or unresolvable),
47
+ * set it to UNRESOLVED confidence. Used by the builder when an import
48
+ * could not be resolved to a file.
49
+ */
50
+ export declare function markUnresolved(entry: MiddlewareEntry): MiddlewareEntry;