@tipolink/mcp 1.0.1 → 1.0.2

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/dist/cli.js CHANGED
@@ -2,15 +2,19 @@
2
2
 
3
3
  // src/cli.ts
4
4
  import { execFileSync } from "node:child_process";
5
- import { existsSync as existsSync5, realpathSync as realpathSync3 } from "node:fs";
5
+ import { existsSync as existsSync6, realpathSync as realpathSync3 } from "node:fs";
6
6
  import path9 from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
8
 
9
9
  // ../engine/src/ast-extractor.ts
10
10
  import { createHash } from "node:crypto";
11
- import path2 from "node:path";
11
+ import path3 from "node:path";
12
12
  import ts from "typescript";
13
13
 
14
+ // ../engine/src/cache.ts
15
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
16
+ import path2 from "node:path";
17
+
14
18
  // ../engine/src/paths.ts
15
19
  import path from "node:path";
16
20
  function compareText(a, b) {
@@ -49,9 +53,143 @@ function computeRelativeImportSpec(fromRelPath, toRelPath) {
49
53
  return rel;
50
54
  }
51
55
 
56
+ // ../engine/src/cache.ts
57
+ var CACHE_SCHEMA_VERSION = "1.0.2";
58
+ function cacheEntryMatches(entry, contentSha256, mtimeMs, size) {
59
+ if (contentSha256 !== void 0) {
60
+ return entry.contentSha256 === contentSha256;
61
+ }
62
+ if (mtimeMs !== void 0 || size !== void 0) {
63
+ if (mtimeMs !== void 0 && entry.mtimeMs !== mtimeMs) return false;
64
+ if (size !== void 0 && entry.size !== size) return false;
65
+ return true;
66
+ }
67
+ return true;
68
+ }
69
+ var JsonFileAstCache = class {
70
+ filePath;
71
+ schemaInvalidated = false;
72
+ autoSave;
73
+ workspaces = /* @__PURE__ */ new Map();
74
+ dirty = false;
75
+ constructor(filePathOrOptions) {
76
+ if (typeof filePathOrOptions === "string") {
77
+ this.filePath = filePathOrOptions;
78
+ this.autoSave = true;
79
+ } else {
80
+ this.filePath = filePathOrOptions.filePath;
81
+ this.autoSave = filePathOrOptions.autoSave ?? true;
82
+ }
83
+ this.loadFromDisk();
84
+ }
85
+ loadFromDisk() {
86
+ if (!existsSync(this.filePath)) return;
87
+ try {
88
+ const raw = readFileSync(this.filePath, "utf8");
89
+ if (!raw.trim()) return;
90
+ const parsed = JSON.parse(raw);
91
+ if (!parsed || typeof parsed !== "object" || !parsed.workspaces || typeof parsed.workspaces !== "object") {
92
+ this.schemaInvalidated = true;
93
+ this.dirty = true;
94
+ return;
95
+ }
96
+ if (parsed.manifestSchemaVersion !== CACHE_SCHEMA_VERSION) {
97
+ this.workspaces.clear();
98
+ this.schemaInvalidated = true;
99
+ this.dirty = true;
100
+ return;
101
+ }
102
+ for (const [workspaceId, files] of Object.entries(parsed.workspaces)) {
103
+ if (!files || typeof files !== "object") continue;
104
+ const map = /* @__PURE__ */ new Map();
105
+ for (const [relPath, manifest] of Object.entries(files)) {
106
+ if (manifest && typeof manifest === "object" && typeof manifest.contentSha256 === "string") {
107
+ const norm = toPosix(relPath);
108
+ map.set(norm, { ...manifest, relativePath: norm });
109
+ }
110
+ }
111
+ this.workspaces.set(workspaceId, map);
112
+ }
113
+ } catch {
114
+ this.workspaces.clear();
115
+ this.schemaInvalidated = true;
116
+ this.dirty = true;
117
+ }
118
+ }
119
+ get(workspaceId, relativePath, contentSha256, mtimeMs, size) {
120
+ const wsMap = this.workspaces.get(workspaceId);
121
+ if (!wsMap) return void 0;
122
+ const hit = wsMap.get(toPosix(relativePath));
123
+ if (!hit) return void 0;
124
+ return cacheEntryMatches(hit, contentSha256, mtimeMs, size) ? hit : void 0;
125
+ }
126
+ set(workspaceId, manifest) {
127
+ const norm = toPosix(manifest.relativePath);
128
+ const normalized = {
129
+ ...manifest,
130
+ relativePath: norm
131
+ };
132
+ let wsMap = this.workspaces.get(workspaceId);
133
+ if (!wsMap) {
134
+ wsMap = /* @__PURE__ */ new Map();
135
+ this.workspaces.set(workspaceId, wsMap);
136
+ }
137
+ wsMap.set(norm, normalized);
138
+ this.dirty = true;
139
+ if (this.autoSave) {
140
+ this.save();
141
+ }
142
+ }
143
+ getAllWorkspaceManifests(workspaceId) {
144
+ const wsMap = this.workspaces.get(workspaceId);
145
+ if (!wsMap) return [];
146
+ return [...wsMap.values()];
147
+ }
148
+ clear(workspaceId) {
149
+ if (workspaceId === void 0) {
150
+ this.workspaces.clear();
151
+ } else {
152
+ this.workspaces.delete(workspaceId);
153
+ }
154
+ this.dirty = true;
155
+ if (this.autoSave) {
156
+ this.save();
157
+ }
158
+ }
159
+ save() {
160
+ if (!this.dirty && existsSync(this.filePath)) return;
161
+ const payload = {
162
+ version: 1,
163
+ manifestSchemaVersion: CACHE_SCHEMA_VERSION,
164
+ workspaces: {}
165
+ };
166
+ for (const [workspaceId, wsMap] of this.workspaces.entries()) {
167
+ const obj = {};
168
+ for (const [relPath, manifest] of wsMap.entries()) {
169
+ obj[relPath] = manifest;
170
+ }
171
+ payload.workspaces[workspaceId] = obj;
172
+ }
173
+ const dir = path2.dirname(this.filePath);
174
+ mkdirSync(dir, { recursive: true });
175
+ const serialized = JSON.stringify(payload, null, 2);
176
+ const tmpPath = `${this.filePath}.${process.pid}.${Date.now()}.tmp`;
177
+ try {
178
+ writeFileSync(tmpPath, serialized, "utf8");
179
+ renameSync(tmpPath, this.filePath);
180
+ } catch {
181
+ writeFileSync(this.filePath, serialized, "utf8");
182
+ }
183
+ this.dirty = false;
184
+ }
185
+ flush() {
186
+ this.save();
187
+ }
188
+ };
189
+
52
190
  // ../engine/src/ast-extractor.ts
53
191
  function scriptKindFor(filePath) {
54
- switch (path2.extname(filePath).toLowerCase()) {
192
+ switch (path3.extname(filePath).toLowerCase()) {
55
193
  case ".tsx":
56
194
  return ts.ScriptKind.TSX;
57
195
  case ".jsx":
@@ -65,7 +203,7 @@ function scriptKindFor(filePath) {
65
203
  }
66
204
  }
67
205
  function jsTsLanguageFor(filePath) {
68
- switch (path2.extname(filePath).toLowerCase()) {
206
+ switch (path3.extname(filePath).toLowerCase()) {
69
207
  case ".js":
70
208
  case ".jsx":
71
209
  case ".mjs":
@@ -90,19 +228,123 @@ function hasModifier(node, kind) {
90
228
  function isFunctionLikeNode(node) {
91
229
  return ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node) || ts.isMethodDeclaration(node);
92
230
  }
93
- function computeStructuralHashWithCount(node, sourceFile) {
231
+ function collectBindingNames(binding, out) {
232
+ if (ts.isIdentifier(binding)) {
233
+ out.add(binding.text);
234
+ } else if (ts.isObjectBindingPattern(binding) || ts.isArrayBindingPattern(binding)) {
235
+ for (const elem of binding.elements) {
236
+ if (ts.isBindingElement(elem)) {
237
+ collectBindingNames(elem.name, out);
238
+ }
239
+ }
240
+ }
241
+ }
242
+ function collectFunctionScopeBindings(fn, out) {
243
+ if (fn.name && ts.isIdentifier(fn.name)) {
244
+ out.add(fn.name.text);
245
+ }
246
+ if (fn.typeParameters) {
247
+ for (const tp of fn.typeParameters) {
248
+ out.add(tp.name.text);
249
+ }
250
+ }
251
+ for (const param of fn.parameters) {
252
+ collectBindingNames(param.name, out);
253
+ }
254
+ }
255
+ function collectHoistedVarDeclarations(node, out) {
256
+ const walk = (curr) => {
257
+ if (isFunctionLikeNode(curr)) return;
258
+ if (ts.isVariableDeclarationList(curr)) {
259
+ const isBlockScoped = (curr.flags & (ts.NodeFlags.Const | ts.NodeFlags.Let)) !== 0;
260
+ if (!isBlockScoped) {
261
+ for (const decl of curr.declarations) {
262
+ collectBindingNames(decl.name, out);
263
+ }
264
+ }
265
+ }
266
+ ts.forEachChild(curr, walk);
267
+ };
268
+ ts.forEachChild(node, walk);
269
+ }
270
+ function collectDirectStatementLocals(statements, out) {
271
+ for (const stmt of statements) {
272
+ if (ts.isVariableStatement(stmt)) {
273
+ for (const decl of stmt.declarationList.declarations) {
274
+ collectBindingNames(decl.name, out);
275
+ }
276
+ } else if (ts.isFunctionDeclaration(stmt) && stmt.name) {
277
+ out.add(stmt.name.text);
278
+ } else if (ts.isClassDeclaration(stmt) && stmt.name) {
279
+ out.add(stmt.name.text);
280
+ }
281
+ }
282
+ }
283
+ function classifyIdentifierRole(curr, parent) {
284
+ if (!parent) return "variable";
285
+ if (ts.isPropertyAccessExpression(parent) && parent.name === curr) return "property";
286
+ if (ts.isQualifiedName(parent) && parent.right === curr) return "property";
287
+ if (ts.isBindingElement(parent) && parent.propertyName === curr) return "object_key";
288
+ if (ts.isPropertyAssignment(parent) && parent.name === curr) return "object_key";
289
+ if (ts.isPropertySignature(parent) && parent.name === curr) return "object_key";
290
+ if (ts.isMethodDeclaration(parent) && parent.name === curr) return "object_key";
291
+ if (ts.isMethodSignature(parent) && parent.name === curr) return "object_key";
292
+ if (ts.isGetAccessorDeclaration(parent) && parent.name === curr) return "object_key";
293
+ if (ts.isSetAccessorDeclaration(parent) && parent.name === curr) return "object_key";
294
+ if (ts.isPropertyDeclaration(parent) && parent.name === curr) return "object_key";
295
+ if (ts.isJsxAttribute(parent) && parent.name === curr) return "object_key";
296
+ if ((ts.isLabeledStatement(parent) || ts.isBreakStatement(parent) || ts.isContinueStatement(parent)) && parent.label === curr) {
297
+ return "property";
298
+ }
299
+ if (ts.isParameter(parent) && parent.name === curr || ts.isVariableDeclaration(parent) && parent.name === curr || ts.isBindingElement(parent) && parent.name === curr || ts.isFunctionDeclaration(parent) && parent.name === curr || ts.isFunctionExpression(parent) && parent.name === curr || ts.isClassDeclaration(parent) && parent.name === curr || ts.isClassExpression(parent) && parent.name === curr || ts.isTypeParameterDeclaration(parent) && parent.name === curr) {
300
+ return "declaration";
301
+ }
302
+ return "variable";
303
+ }
304
+ function collectModuleLocalDeclarations(sourceFile) {
305
+ const decls = /* @__PURE__ */ new Set();
306
+ for (const stmt of sourceFile.statements) {
307
+ if (ts.isVariableStatement(stmt)) {
308
+ for (const decl of stmt.declarationList.declarations) {
309
+ collectBindingNames(decl.name, decls);
310
+ }
311
+ } else if (ts.isFunctionDeclaration(stmt) && stmt.name) {
312
+ decls.add(stmt.name.text);
313
+ } else if (ts.isClassDeclaration(stmt) && stmt.name) {
314
+ decls.add(stmt.name.text);
315
+ } else if (ts.isEnumDeclaration(stmt)) {
316
+ decls.add(stmt.name.text);
317
+ }
318
+ }
319
+ return decls;
320
+ }
321
+ function computeStructuralHashWithCount(node, sourceFile, options) {
94
322
  const target = ts.isVariableDeclaration(node) && node.initializer && (ts.isArrowFunction(node.initializer) || ts.isFunctionExpression(node.initializer)) ? node.initializer : node;
323
+ const normalizedFilePath = normalizeRelPath(options?.filePath ?? sourceFile.fileName);
324
+ const moduleLocalDecls = options?.moduleLocalDecls ?? collectModuleLocalDeclarations(sourceFile);
95
325
  const tokens = [];
96
326
  let nodeCount = 0;
97
327
  let astNodeCount = 0;
98
- const visit = (curr, countAsBody) => {
328
+ const visit = (curr, countAsBody, scope, parent) => {
99
329
  nodeCount += 1;
100
330
  if (countAsBody) {
101
331
  astNodeCount += 1;
102
332
  }
103
333
  tokens.push(`K:${curr.kind}`);
334
+ let childScope = scope;
104
335
  if (ts.isPropertyAccessExpression(curr)) {
105
- tokens.push(`PROP:.${curr.name.text}`);
336
+ tokens.push(`PROP:${curr.name.text}`);
337
+ } else if (ts.isStringLiteral(curr) || ts.isNoSubstitutionTemplateLiteral(curr)) {
338
+ tokens.push(`STR:${curr.text}`);
339
+ } else if (ts.isTemplateExpression(curr)) {
340
+ tokens.push(`TPL_H:${curr.head.text}`);
341
+ for (const span of curr.templateSpans) {
342
+ tokens.push(`TPL_M:${span.literal.text}`);
343
+ }
344
+ } else if (ts.isNumericLiteral(curr)) {
345
+ tokens.push(`NUM:${curr.text}`);
346
+ } else if (ts.isRegularExpressionLiteral(curr)) {
347
+ tokens.push(`REGEX:${curr.text}`);
106
348
  } else if (ts.isBinaryExpression(curr)) {
107
349
  tokens.push(`OP:${curr.operatorToken.kind}`);
108
350
  } else if (ts.isPrefixUnaryExpression(curr)) {
@@ -112,10 +354,61 @@ function computeStructuralHashWithCount(node, sourceFile) {
112
354
  } else if (ts.isVariableDeclarationList(curr)) {
113
355
  const declFlag = curr.flags & (ts.NodeFlags.Const | ts.NodeFlags.Let);
114
356
  tokens.push(`VF:${declFlag}`);
357
+ } else if (ts.isIdentifier(curr)) {
358
+ const role = classifyIdentifierRole(curr, parent);
359
+ if (role === "declaration") {
360
+ tokens.push("ID:$L");
361
+ } else if (role === "object_key") {
362
+ tokens.push(`KEY:${curr.text}`);
363
+ } else if (role === "variable") {
364
+ if (scope.has(curr.text)) {
365
+ tokens.push("ID:$L");
366
+ } else if (moduleLocalDecls.has(curr.text)) {
367
+ tokens.push(`STATE:${normalizedFilePath}:${curr.text}`);
368
+ } else {
369
+ tokens.push(`EXT:${curr.text}`);
370
+ }
371
+ }
115
372
  }
116
- ts.forEachChild(curr, (child) => visit(child, countAsBody));
373
+ if (curr !== target && isFunctionLikeNode(curr)) {
374
+ const next = new Set(scope);
375
+ collectFunctionScopeBindings(curr, next);
376
+ if (curr.body) {
377
+ collectHoistedVarDeclarations(curr.body, next);
378
+ }
379
+ childScope = next;
380
+ } else if (ts.isBlock(curr)) {
381
+ const next = new Set(scope);
382
+ collectDirectStatementLocals(curr.statements, next);
383
+ childScope = next;
384
+ } else if (ts.isCaseClause(curr) || ts.isDefaultClause(curr)) {
385
+ const next = new Set(scope);
386
+ collectDirectStatementLocals(curr.statements, next);
387
+ childScope = next;
388
+ } else if (ts.isForStatement(curr) || ts.isForInStatement(curr) || ts.isForOfStatement(curr)) {
389
+ if (curr.initializer && ts.isVariableDeclarationList(curr.initializer)) {
390
+ const next = new Set(scope);
391
+ for (const decl of curr.initializer.declarations) {
392
+ collectBindingNames(decl.name, next);
393
+ }
394
+ childScope = next;
395
+ }
396
+ } else if (ts.isCatchClause(curr) && curr.variableDeclaration) {
397
+ const next = new Set(scope);
398
+ collectBindingNames(curr.variableDeclaration.name, next);
399
+ childScope = next;
400
+ }
401
+ ts.forEachChild(curr, (child) => visit(child, countAsBody, childScope, curr));
117
402
  };
118
403
  if (isFunctionLikeNode(target)) {
404
+ const rootScope = /* @__PURE__ */ new Set();
405
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {
406
+ rootScope.add(node.name.text);
407
+ }
408
+ collectFunctionScopeBindings(target, rootScope);
409
+ if (target.body) {
410
+ collectHoistedVarDeclarations(target.body, rootScope);
411
+ }
119
412
  tokens.push("FN");
120
413
  if (hasModifier(target, ts.SyntaxKind.AsyncKeyword)) {
121
414
  tokens.push("MOD:ASYNC");
@@ -124,14 +417,13 @@ function computeStructuralHashWithCount(node, sourceFile) {
124
417
  tokens.push("MOD:GEN");
125
418
  }
126
419
  for (const param of target.parameters) {
127
- visit(param, false);
420
+ visit(param, false, rootScope, target);
128
421
  }
129
422
  if (target.body) {
130
- visit(target.body, true);
423
+ visit(target.body, true, rootScope, target);
131
424
  }
132
425
  } else {
133
- void sourceFile;
134
- visit(target, true);
426
+ visit(target, true, /* @__PURE__ */ new Set(), void 0);
135
427
  }
136
428
  const structuralHash = createHash("sha256").update(tokens.join("|"), "utf8").digest("hex").slice(0, 16);
137
429
  return { structuralHash, nodeCount, astNodeCount };
@@ -165,7 +457,7 @@ function formatConstSummary(decl, sourceFile) {
165
457
  }
166
458
  if (ts.isObjectLiteralExpression(init)) {
167
459
  const keys = init.properties.slice(0, 5).map((prop) => {
168
- if (ts.isPropertyAssignment(prop) || ts.isShorthandPropertyAssignment(prop)) {
460
+ if (ts.isPropertyAssignment(prop) || ts.isShorthandPropertyAssignment(prop) || ts.isMethodDeclaration(prop)) {
169
461
  return prop.name.getText(sourceFile);
170
462
  }
171
463
  return "...";
@@ -206,10 +498,10 @@ function formatEnumSignature(node, sourceFile) {
206
498
  function lineNumberOf(node, sourceFile) {
207
499
  return sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;
208
500
  }
209
- function pushImportRef(refs, keyMap, rawSpecifier, importedNames, isReExport, isTypeOnly) {
501
+ function pushImportRef(refs, keyMap, rawSpecifier, importedNames, isReExport, isTypeOnly, isDynamic = false) {
210
502
  const trimmed = rawSpecifier.trim();
211
503
  if (!trimmed) return;
212
- const dedupKey = `${trimmed}\0${isReExport ? "1" : "0"}\0${isTypeOnly ? "1" : "0"}`;
504
+ const dedupKey = `${trimmed}\0${isReExport ? "1" : "0"}\0${isTypeOnly ? "1" : "0"}\0${isDynamic ? "1" : "0"}`;
213
505
  const existing = keyMap.get(dedupKey);
214
506
  if (existing) {
215
507
  for (const name of importedNames) {
@@ -223,7 +515,8 @@ function pushImportRef(refs, keyMap, rawSpecifier, importedNames, isReExport, is
223
515
  rawSpecifier: trimmed,
224
516
  importedNames: [...new Set(importedNames)],
225
517
  isReExport,
226
- isTypeOnly
518
+ isTypeOnly,
519
+ ...isDynamic ? { isDynamic: true } : {}
227
520
  };
228
521
  keyMap.set(dedupKey, entry);
229
522
  refs.push(entry);
@@ -236,7 +529,10 @@ function extractImports(sourceFile) {
236
529
  if (ts.isStringLiteral(node.moduleSpecifier)) {
237
530
  const names = [];
238
531
  const clause = node.importClause;
239
- const isTypeOnly = Boolean(clause?.isTypeOnly);
532
+ const allNamedTypeOnly = Boolean(
533
+ clause && !clause.name && clause.namedBindings && ts.isNamedImports(clause.namedBindings) && clause.namedBindings.elements.length > 0 && clause.namedBindings.elements.every((elem) => elem.isTypeOnly)
534
+ );
535
+ const isTypeOnly = Boolean(clause?.isTypeOnly) || allNamedTypeOnly;
240
536
  if (clause) {
241
537
  if (clause.name) names.push("default");
242
538
  if (clause.namedBindings) {
@@ -249,13 +545,19 @@ function extractImports(sourceFile) {
249
545
  }
250
546
  }
251
547
  }
252
- pushImportRef(refs, keyMap, node.moduleSpecifier.text, names, false, isTypeOnly);
548
+ pushImportRef(refs, keyMap, node.moduleSpecifier.text, names, false, isTypeOnly, false);
253
549
  }
254
550
  } else if (ts.isExportDeclaration(node)) {
255
551
  if (node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
256
552
  const names = [];
553
+ const allNamedTypeOnly = Boolean(
554
+ node.exportClause && ts.isNamedExports(node.exportClause) && node.exportClause.elements.length > 0 && node.exportClause.elements.every((elem) => elem.isTypeOnly)
555
+ );
556
+ const isTypeOnly = Boolean(node.isTypeOnly) || allNamedTypeOnly;
257
557
  if (!node.exportClause) {
258
- names.push("*");
558
+ if (!isTypeOnly) {
559
+ names.push("*");
560
+ }
259
561
  } else if (ts.isNamespaceExport(node.exportClause)) {
260
562
  names.push("*");
261
563
  } else if (ts.isNamedExports(node.exportClause)) {
@@ -263,27 +565,27 @@ function extractImports(sourceFile) {
263
565
  names.push((elem.propertyName ?? elem.name).text);
264
566
  }
265
567
  }
266
- pushImportRef(refs, keyMap, node.moduleSpecifier.text, names, true, Boolean(node.isTypeOnly));
568
+ pushImportRef(refs, keyMap, node.moduleSpecifier.text, names, true, isTypeOnly, false);
267
569
  }
268
570
  } else if (ts.isImportEqualsDeclaration(node)) {
269
571
  if (ts.isExternalModuleReference(node.moduleReference) && ts.isStringLiteral(node.moduleReference.expression)) {
270
- pushImportRef(refs, keyMap, node.moduleReference.expression.text, [node.name.text], false, false);
572
+ pushImportRef(refs, keyMap, node.moduleReference.expression.text, [node.name.text], false, false, false);
271
573
  }
272
574
  } else if (ts.isCallExpression(node)) {
273
575
  const first = node.arguments[0];
274
576
  if (first && ts.isStringLiteralLike(first)) {
275
577
  const callee = node.expression;
276
578
  if (callee.kind === ts.SyntaxKind.ImportKeyword) {
277
- pushImportRef(refs, keyMap, first.text, [], false, false);
579
+ pushImportRef(refs, keyMap, first.text, [], false, false, true);
278
580
  } else if (ts.isIdentifier(callee) && callee.text === "require") {
279
- pushImportRef(refs, keyMap, first.text, [], false, false);
581
+ pushImportRef(refs, keyMap, first.text, [], false, false, false);
280
582
  }
281
583
  }
282
584
  } else if (ts.isImportTypeNode(node)) {
283
585
  const argument = node.argument;
284
586
  if (ts.isLiteralTypeNode(argument) && ts.isStringLiteral(argument.literal)) {
285
587
  const names = node.qualifier ? [collapseWhitespace(node.qualifier.getText(sourceFile))] : [];
286
- pushImportRef(refs, keyMap, argument.literal.text, names, false, true);
588
+ pushImportRef(refs, keyMap, argument.literal.text, names, false, true, false);
287
589
  }
288
590
  }
289
591
  ts.forEachChild(node, visit);
@@ -302,6 +604,8 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
302
604
  scriptKindFor(absolutePath)
303
605
  );
304
606
  const imports = extractImports(sourceFile);
607
+ const moduleLocalDecls = collectModuleLocalDeclarations(sourceFile);
608
+ const hashOptions = { filePath: rel, moduleLocalDecls };
305
609
  const localDecls = /* @__PURE__ */ new Map();
306
610
  const exportedSymbols = [];
307
611
  const internalFunctions = [];
@@ -319,7 +623,11 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
319
623
  if (ts.isFunctionDeclaration(stmt)) {
320
624
  if (!stmt.body) continue;
321
625
  const declName = stmt.name?.text;
322
- const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(stmt, sourceFile);
626
+ const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
627
+ stmt,
628
+ sourceFile,
629
+ hashOptions
630
+ );
323
631
  const signature = formatFunctionSignature(stmt, sourceFile);
324
632
  const line = lineNumberOf(stmt, sourceFile);
325
633
  if (declName) {
@@ -361,7 +669,11 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
361
669
  const line = lineNumberOf(decl, sourceFile);
362
670
  const init = decl.initializer;
363
671
  if (init && (ts.isArrowFunction(init) || ts.isFunctionExpression(init))) {
364
- const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(init, sourceFile);
672
+ const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
673
+ decl,
674
+ sourceFile,
675
+ hashOptions
676
+ );
365
677
  const signature = formatFunctionSignature(init, sourceFile);
366
678
  localDecls.set(declName, {
367
679
  name: declName,
@@ -599,7 +911,11 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
599
911
  });
600
912
  }
601
913
  } else if (ts.isArrowFunction(stmt.expression) || ts.isFunctionExpression(stmt.expression)) {
602
- const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(stmt.expression, sourceFile);
914
+ const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
915
+ stmt.expression,
916
+ sourceFile,
917
+ hashOptions
918
+ );
603
919
  addExported({
604
920
  name: "default",
605
921
  kind: "function",
@@ -642,6 +958,7 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
642
958
  return {
643
959
  relativePath: rel,
644
960
  contentSha256,
961
+ schemaVersion: CACHE_SCHEMA_VERSION,
645
962
  language: jsTsLanguageFor(absolutePath),
646
963
  ...mtimeMs !== void 0 ? { mtimeMs } : {},
647
964
  ...size !== void 0 ? { size } : {},
@@ -651,129 +968,6 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
651
968
  };
652
969
  }
653
970
 
654
- // ../engine/src/cache.ts
655
- import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
656
- import path3 from "node:path";
657
- function cacheEntryMatches(entry, contentSha256, mtimeMs, size) {
658
- if (contentSha256 !== void 0) {
659
- return entry.contentSha256 === contentSha256;
660
- }
661
- if (mtimeMs !== void 0 || size !== void 0) {
662
- if (mtimeMs !== void 0 && entry.mtimeMs !== mtimeMs) return false;
663
- if (size !== void 0 && entry.size !== size) return false;
664
- return true;
665
- }
666
- return true;
667
- }
668
- var JsonFileAstCache = class {
669
- filePath;
670
- autoSave;
671
- workspaces = /* @__PURE__ */ new Map();
672
- dirty = false;
673
- constructor(filePathOrOptions) {
674
- if (typeof filePathOrOptions === "string") {
675
- this.filePath = filePathOrOptions;
676
- this.autoSave = true;
677
- } else {
678
- this.filePath = filePathOrOptions.filePath;
679
- this.autoSave = filePathOrOptions.autoSave ?? true;
680
- }
681
- this.loadFromDisk();
682
- }
683
- loadFromDisk() {
684
- if (!existsSync(this.filePath)) return;
685
- try {
686
- const raw = readFileSync(this.filePath, "utf8");
687
- if (!raw.trim()) return;
688
- const parsed = JSON.parse(raw);
689
- if (!parsed || typeof parsed !== "object" || !parsed.workspaces || typeof parsed.workspaces !== "object") {
690
- return;
691
- }
692
- for (const [workspaceId, files] of Object.entries(parsed.workspaces)) {
693
- if (!files || typeof files !== "object") continue;
694
- const map = /* @__PURE__ */ new Map();
695
- for (const [relPath, manifest] of Object.entries(files)) {
696
- if (manifest && typeof manifest === "object" && typeof manifest.contentSha256 === "string") {
697
- const norm = toPosix(relPath);
698
- map.set(norm, { ...manifest, relativePath: norm });
699
- }
700
- }
701
- this.workspaces.set(workspaceId, map);
702
- }
703
- } catch {
704
- this.workspaces.clear();
705
- }
706
- }
707
- get(workspaceId, relativePath, contentSha256, mtimeMs, size) {
708
- const wsMap = this.workspaces.get(workspaceId);
709
- if (!wsMap) return void 0;
710
- const hit = wsMap.get(toPosix(relativePath));
711
- if (!hit) return void 0;
712
- return cacheEntryMatches(hit, contentSha256, mtimeMs, size) ? hit : void 0;
713
- }
714
- set(workspaceId, manifest) {
715
- const norm = toPosix(manifest.relativePath);
716
- const normalized = {
717
- ...manifest,
718
- relativePath: norm
719
- };
720
- let wsMap = this.workspaces.get(workspaceId);
721
- if (!wsMap) {
722
- wsMap = /* @__PURE__ */ new Map();
723
- this.workspaces.set(workspaceId, wsMap);
724
- }
725
- wsMap.set(norm, normalized);
726
- this.dirty = true;
727
- if (this.autoSave) {
728
- this.save();
729
- }
730
- }
731
- getAllWorkspaceManifests(workspaceId) {
732
- const wsMap = this.workspaces.get(workspaceId);
733
- if (!wsMap) return [];
734
- return [...wsMap.values()];
735
- }
736
- clear(workspaceId) {
737
- if (workspaceId === void 0) {
738
- this.workspaces.clear();
739
- } else {
740
- this.workspaces.delete(workspaceId);
741
- }
742
- this.dirty = true;
743
- if (this.autoSave) {
744
- this.save();
745
- }
746
- }
747
- save() {
748
- if (!this.dirty && existsSync(this.filePath)) return;
749
- const payload = {
750
- version: 1,
751
- workspaces: {}
752
- };
753
- for (const [workspaceId, wsMap] of this.workspaces.entries()) {
754
- const obj = {};
755
- for (const [relPath, manifest] of wsMap.entries()) {
756
- obj[relPath] = manifest;
757
- }
758
- payload.workspaces[workspaceId] = obj;
759
- }
760
- const dir = path3.dirname(this.filePath);
761
- mkdirSync(dir, { recursive: true });
762
- const serialized = JSON.stringify(payload, null, 2);
763
- const tmpPath = `${this.filePath}.${process.pid}.${Date.now()}.tmp`;
764
- try {
765
- writeFileSync(tmpPath, serialized, "utf8");
766
- renameSync(tmpPath, this.filePath);
767
- } catch {
768
- writeFileSync(this.filePath, serialized, "utf8");
769
- }
770
- this.dirty = false;
771
- }
772
- flush() {
773
- this.save();
774
- }
775
- };
776
-
777
971
  // ../engine/src/env.ts
778
972
  function readEnv(name) {
779
973
  return process.env[`TIPOLINK_${name}`] ?? process.env[`INTERLINK_${name}`];
@@ -2918,6 +3112,45 @@ function buildWorkspaceResolutionContext(root, rootReal, allRelativePaths, confi
2918
3112
 
2919
3113
  // ../engine/src/indexer.ts
2920
3114
  var SOURCE_EXTENSIONS = new Set(defaultPolyglotRegistry.supportedExtensions);
3115
+ var NON_CODE_ASSET_EXTENSIONS = /* @__PURE__ */ new Set([
3116
+ ".css",
3117
+ ".scss",
3118
+ ".less",
3119
+ ".svg",
3120
+ ".png",
3121
+ ".jpg",
3122
+ ".jpeg",
3123
+ ".webp",
3124
+ ".gif",
3125
+ ".ico",
3126
+ ".woff",
3127
+ ".woff2",
3128
+ ".ttf",
3129
+ ".wasm",
3130
+ ".json",
3131
+ ".glsl",
3132
+ ".sql",
3133
+ ".txt",
3134
+ ".md"
3135
+ ]);
3136
+ function stripImportQueryAndHash(specifier) {
3137
+ const trimmed = specifier.trim();
3138
+ const qIdx = trimmed.indexOf("?");
3139
+ const hIdx = trimmed.indexOf("#");
3140
+ let cut = trimmed.length;
3141
+ if (qIdx !== -1 && qIdx < cut) cut = qIdx;
3142
+ if (hIdx !== -1 && hIdx < cut) cut = hIdx;
3143
+ return trimmed.slice(0, cut);
3144
+ }
3145
+ function isRelativeImportSpecifier(specifier) {
3146
+ const clean = stripImportQueryAndHash(specifier);
3147
+ return clean === "." || clean === ".." || clean.startsWith("./") || clean.startsWith("../");
3148
+ }
3149
+ function isNonCodeAssetSpecifier(specifier) {
3150
+ const clean = stripImportQueryAndHash(specifier);
3151
+ const ext = path5.posix.extname(clean).toLowerCase();
3152
+ return ext.length > 0 && NON_CODE_ASSET_EXTENSIONS.has(ext) && !SOURCE_EXTENSIONS.has(ext);
3153
+ }
2921
3154
  var SKIP_DIRS = /* @__PURE__ */ new Set([
2922
3155
  "node_modules",
2923
3156
  ".git",
@@ -3127,7 +3360,18 @@ function resolveAlias(spec, fromFile, index) {
3127
3360
  }
3128
3361
  return null;
3129
3362
  }
3130
- function localRef(found, index, importedNames, isReExport) {
3363
+ function buildEdgeFlags(importedNames, meta) {
3364
+ const isTypeOnly = meta?.isTypeOnly === true;
3365
+ const isDynamic = meta?.isDynamic === true;
3366
+ const hasStaticValueImport = !isTypeOnly && !isDynamic && meta?.verifiedAssetOnDisk !== true && importedNames.length > 0;
3367
+ return {
3368
+ ...isTypeOnly ? { isTypeOnly: true } : {},
3369
+ ...isDynamic ? { isDynamic: true } : {},
3370
+ hasStaticValueImport,
3371
+ ...meta?.verifiedAssetOnDisk !== void 0 ? { verifiedAssetOnDisk: meta.verifiedAssetOnDisk } : {}
3372
+ };
3373
+ }
3374
+ function localRef(found, index, importedNames, isReExport, meta) {
3131
3375
  let real;
3132
3376
  try {
3133
3377
  real = realpathSync.native(found);
@@ -3140,55 +3384,72 @@ function localRef(found, index, importedNames, isReExport) {
3140
3384
  kind: "local",
3141
3385
  label,
3142
3386
  importedNames: [...importedNames],
3143
- isReExport
3387
+ isReExport,
3388
+ ...buildEdgeFlags(importedNames, meta)
3144
3389
  };
3145
3390
  }
3146
- function unresolvedRef(base, index, importedNames, isReExport) {
3391
+ function unresolvedRef(base, index, importedNames, isReExport, meta) {
3147
3392
  const label = displayPath(index.root, path5.resolve(base));
3148
3393
  return {
3149
3394
  key: `unresolved:${label}`,
3150
3395
  kind: "unresolved",
3151
3396
  label: `${label} (unresolved)`,
3152
3397
  importedNames: [...importedNames],
3153
- isReExport
3398
+ isReExport,
3399
+ ...buildEdgeFlags(importedNames, meta)
3154
3400
  };
3155
3401
  }
3156
- function externalRef(spec, importedNames, isReExport) {
3402
+ function externalRef(spec, importedNames, isReExport, meta) {
3157
3403
  return {
3158
3404
  key: `pkg:${spec}`,
3159
3405
  kind: "external",
3160
3406
  label: spec,
3161
3407
  importedNames: [...importedNames],
3162
- isReExport
3408
+ isReExport,
3409
+ ...buildEdgeFlags(importedNames, meta)
3163
3410
  };
3164
3411
  }
3165
- function resolveModule(rawSpec, fromFile, index, importedNames = [], isReExport = false) {
3166
- const spec = rawSpec.trim();
3412
+ function resolveModule(rawSpec, fromFile, index, importedNames = [], isReExport = false, meta) {
3413
+ const spec = stripImportQueryAndHash(rawSpec);
3167
3414
  if (spec === "." || spec === ".." || spec.startsWith("./") || spec.startsWith("../")) {
3168
3415
  const base = path5.resolve(path5.dirname(fromFile), spec);
3169
3416
  const found = resolveCandidate(base);
3170
- return found ? localRef(found, index, importedNames, isReExport) : unresolvedRef(base, index, importedNames, isReExport);
3417
+ const isAsset = isNonCodeAssetSpecifier(spec);
3418
+ const verifiedAssetOnDisk = isAsset ? Boolean(found) : meta?.verifiedAssetOnDisk;
3419
+ const effectiveMeta = {
3420
+ ...meta,
3421
+ ...verifiedAssetOnDisk !== void 0 ? { verifiedAssetOnDisk } : {}
3422
+ };
3423
+ return found ? localRef(found, index, importedNames, isReExport, effectiveMeta) : unresolvedRef(base, index, importedNames, isReExport, effectiveMeta);
3171
3424
  }
3172
3425
  if (spec.startsWith("node:")) {
3173
- return externalRef(spec, importedNames, isReExport);
3426
+ return externalRef(spec, importedNames, isReExport, meta);
3174
3427
  }
3175
3428
  if (NODE_BUILTINS.has(spec)) {
3176
- return externalRef(`node:${spec}`, importedNames, isReExport);
3429
+ return externalRef(`node:${spec}`, importedNames, isReExport, meta);
3177
3430
  }
3178
3431
  if (path5.isAbsolute(spec)) {
3179
3432
  const found = resolveCandidate(spec);
3180
- if (found) return localRef(found, index, importedNames, isReExport);
3433
+ if (found) return localRef(found, index, importedNames, isReExport, meta);
3181
3434
  }
3182
3435
  const aliased = resolveAlias(spec, fromFile, index);
3183
- if (aliased) return localRef(aliased, index, importedNames, isReExport);
3184
- return externalRef(spec, importedNames, isReExport);
3436
+ if (aliased) {
3437
+ const isAsset = isNonCodeAssetSpecifier(aliased);
3438
+ return localRef(aliased, index, importedNames, isReExport, {
3439
+ ...meta,
3440
+ ...isAsset ? { verifiedAssetOnDisk: true } : {}
3441
+ });
3442
+ }
3443
+ return externalRef(spec, importedNames, isReExport, meta);
3185
3444
  }
3186
3445
  function mergeModuleRef(modules, ref) {
3446
+ const incomingHasStatic = ref.hasStaticValueImport ?? (ref.isTypeOnly !== true && ref.isDynamic !== true && ref.verifiedAssetOnDisk !== true && ref.importedNames.length > 0);
3187
3447
  const existing = modules.get(ref.key);
3188
3448
  if (!existing) {
3189
3449
  modules.set(ref.key, {
3190
3450
  ...ref,
3191
- importedNames: [...ref.importedNames]
3451
+ importedNames: [...ref.importedNames],
3452
+ hasStaticValueImport: incomingHasStatic
3192
3453
  });
3193
3454
  return;
3194
3455
  }
@@ -3200,6 +3461,15 @@ function mergeModuleRef(modules, ref) {
3200
3461
  if (ref.isReExport) {
3201
3462
  existing.isReExport = true;
3202
3463
  }
3464
+ const existingHasStatic = existing.hasStaticValueImport ?? (existing.isTypeOnly !== true && existing.isDynamic !== true && existing.verifiedAssetOnDisk !== true && existing.importedNames.length > 0);
3465
+ existing.hasStaticValueImport = existingHasStatic || incomingHasStatic;
3466
+ existing.isTypeOnly = Boolean(existing.isTypeOnly) && Boolean(ref.isTypeOnly);
3467
+ existing.isDynamic = Boolean(existing.isDynamic) && Boolean(ref.isDynamic);
3468
+ if (ref.verifiedAssetOnDisk === true) {
3469
+ existing.verifiedAssetOnDisk = true;
3470
+ } else if (ref.verifiedAssetOnDisk === false && existing.verifiedAssetOnDisk === void 0) {
3471
+ existing.verifiedAssetOnDisk = false;
3472
+ }
3203
3473
  }
3204
3474
  function addInboundEdge(index, callerRel, targetRel) {
3205
3475
  let inboundSet = index.inbound.get(targetRel);
@@ -3232,8 +3502,13 @@ function registerIndexedFile(index, file, extraId) {
3232
3502
  function resolveNonJsTsImport(imp, relative, language, index, modules) {
3233
3503
  const adapter = defaultPolyglotRegistry.getAdapterById(language);
3234
3504
  const ctx = index.resolutionContext;
3505
+ const edgeMeta = {
3506
+ isTypeOnly: imp.isTypeOnly,
3507
+ isDynamic: imp.isDynamic,
3508
+ verifiedAssetOnDisk: imp.verifiedAssetOnDisk
3509
+ };
3235
3510
  if (!adapter || !ctx) {
3236
- const ext = externalRef(imp.rawSpecifier, imp.importedNames, imp.isReExport);
3511
+ const ext = externalRef(imp.rawSpecifier, imp.importedNames, imp.isReExport, edgeMeta);
3237
3512
  mergeModuleRef(modules, { ...ext, rawSpecifier: imp.rawSpecifier });
3238
3513
  return { ...imp, resolvedKind: "external", resolvedPaths: [] };
3239
3514
  }
@@ -3246,6 +3521,7 @@ function resolveNonJsTsImport(imp, relative, language, index, modules) {
3246
3521
  label: targetRel,
3247
3522
  importedNames: [...imp.importedNames],
3248
3523
  isReExport: imp.isReExport,
3524
+ ...buildEdgeFlags(imp.importedNames, edgeMeta),
3249
3525
  rawSpecifier: imp.rawSpecifier
3250
3526
  });
3251
3527
  }
@@ -3263,6 +3539,7 @@ function resolveNonJsTsImport(imp, relative, language, index, modules) {
3263
3539
  label: `${attempt} (unresolved)`,
3264
3540
  importedNames: [...imp.importedNames],
3265
3541
  isReExport: imp.isReExport,
3542
+ ...buildEdgeFlags(imp.importedNames, edgeMeta),
3266
3543
  rawSpecifier: imp.rawSpecifier
3267
3544
  });
3268
3545
  return {
@@ -3273,7 +3550,7 @@ function resolveNonJsTsImport(imp, relative, language, index, modules) {
3273
3550
  }
3274
3551
  const extLabel = res.externalLabel ?? imp.rawSpecifier;
3275
3552
  mergeModuleRef(modules, {
3276
- ...externalRef(extLabel, imp.importedNames, imp.isReExport),
3553
+ ...externalRef(extLabel, imp.importedNames, imp.isReExport, edgeMeta),
3277
3554
  rawSpecifier: imp.rawSpecifier
3278
3555
  });
3279
3556
  return {
@@ -3334,11 +3611,29 @@ function indexFileOnDisk(absolute, index, options) {
3334
3611
  const resolvedImports = [];
3335
3612
  for (const imp of manifest.imports) {
3336
3613
  if (isJsTs) {
3337
- const ref = resolveModule(imp.rawSpecifier, realAbs, index, imp.importedNames, imp.isReExport);
3614
+ const cleanSpec = stripImportQueryAndHash(imp.rawSpecifier);
3615
+ let verifiedAssetOnDisk = imp.verifiedAssetOnDisk;
3616
+ if (isRelativeImportSpecifier(cleanSpec) && isNonCodeAssetSpecifier(cleanSpec)) {
3617
+ verifiedAssetOnDisk = isFile(path5.resolve(path5.dirname(realAbs), cleanSpec));
3618
+ }
3619
+ const ref = resolveModule(
3620
+ imp.rawSpecifier,
3621
+ realAbs,
3622
+ index,
3623
+ imp.importedNames,
3624
+ imp.isReExport,
3625
+ {
3626
+ isTypeOnly: imp.isTypeOnly,
3627
+ isDynamic: imp.isDynamic,
3628
+ verifiedAssetOnDisk
3629
+ }
3630
+ );
3338
3631
  mergeModuleRef(modules, { ...ref, rawSpecifier: imp.rawSpecifier });
3339
3632
  const resolvedPaths = ref.kind === "local" ? [ref.label] : ref.kind === "unresolved" ? [ref.label.replace(/ \(unresolved\)$/, "")] : [];
3633
+ const effectiveVerifiedAsset = ref.verifiedAssetOnDisk !== void 0 ? ref.verifiedAssetOnDisk : verifiedAssetOnDisk;
3340
3634
  resolvedImports.push({
3341
3635
  ...imp,
3636
+ ...effectiveVerifiedAsset !== void 0 ? { verifiedAssetOnDisk: effectiveVerifiedAsset } : {},
3342
3637
  resolvedKind: ref.kind,
3343
3638
  resolvedPaths
3344
3639
  });
@@ -3748,16 +4043,94 @@ function initWorkspaceConfigs(rootDir, options = {}) {
3748
4043
  }
3749
4044
 
3750
4045
  // src/mcp-stdio.ts
3751
- import { existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync3 } from "node:fs";
4046
+ import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync4 } from "node:fs";
3752
4047
  import path8 from "node:path";
3753
4048
 
3754
4049
  // src/extractor.ts
3755
4050
  import { createHash as createHash4 } from "node:crypto";
3756
- import { readdirSync as readdirSync2, readFileSync as readFileSync5, realpathSync as realpathSync2, statSync as statSync2 } from "node:fs";
4051
+ import { existsSync as existsSync4, readdirSync as readdirSync2, readFileSync as readFileSync5, realpathSync as realpathSync2, statSync as statSync2, writeFileSync as writeFileSync3 } from "node:fs";
3757
4052
  import path7 from "node:path";
3758
4053
  function sha256Text(text) {
3759
4054
  return createHash4("sha256").update(text, "utf8").digest("hex");
3760
4055
  }
4056
+ function computeManifestSyncHash(manifest) {
4057
+ const assetSig = manifest.imports.map((imp) => {
4058
+ const assetFlag = imp.verifiedAssetOnDisk === true ? "1" : imp.verifiedAssetOnDisk === false ? "0" : "-";
4059
+ const dynFlag = imp.isDynamic === true ? "D" : "S";
4060
+ const typeFlag = imp.isTypeOnly ? "T" : "V";
4061
+ return `${imp.rawSpecifier}:${typeFlag}${dynFlag}${assetFlag}:${imp.importedNames.length}`;
4062
+ }).join("|");
4063
+ const symSig = manifest.exportedSymbols.map((s) => `${s.name}:${s.structuralHash ?? ""}`).join(",");
4064
+ const internalSig = manifest.internalFunctions.map((f) => `${f.name}:${f.structuralHash}`).join(",");
4065
+ const schema = manifest.schemaVersion ?? CACHE_SCHEMA_VERSION;
4066
+ return sha256Text(`${schema}\0${manifest.contentSha256}\0${assetSig}\0${symSig}\0${internalSig}`);
4067
+ }
4068
+ function verifyRelativeAssetsOnDisk(manifest, sourceAbsPath) {
4069
+ const sourceDir = path7.dirname(sourceAbsPath);
4070
+ let changed = false;
4071
+ const updatedImports = manifest.imports.map((imp) => {
4072
+ const cleanSpec = stripImportQueryAndHash(imp.rawSpecifier);
4073
+ if (!isRelativeImportSpecifier(cleanSpec) || !isNonCodeAssetSpecifier(cleanSpec)) {
4074
+ return imp;
4075
+ }
4076
+ const resolvedDiskPath = path7.resolve(sourceDir, cleanSpec);
4077
+ const verified = existsSync4(resolvedDiskPath);
4078
+ if (imp.verifiedAssetOnDisk !== verified) {
4079
+ changed = true;
4080
+ }
4081
+ return {
4082
+ ...imp,
4083
+ verifiedAssetOnDisk: verified
4084
+ };
4085
+ });
4086
+ if (!changed) {
4087
+ return { manifest, changed: false };
4088
+ }
4089
+ return {
4090
+ manifest: {
4091
+ ...manifest,
4092
+ imports: updatedImports
4093
+ },
4094
+ changed: true
4095
+ };
4096
+ }
4097
+ function invalidateStaleCloudSyncFile(cachePath, workspaceId) {
4098
+ const syncPath = path7.join(path7.dirname(cachePath), "cloud-sync.json");
4099
+ if (!existsSync4(syncPath)) return;
4100
+ try {
4101
+ const parsed = JSON.parse(readFileSync5(syncPath, "utf8"));
4102
+ if (!parsed || typeof parsed !== "object") return;
4103
+ if (parsed.manifestSchemaVersion !== CACHE_SCHEMA_VERSION) {
4104
+ writeFileSync3(
4105
+ syncPath,
4106
+ JSON.stringify(
4107
+ {
4108
+ version: 1,
4109
+ manifestSchemaVersion: CACHE_SCHEMA_VERSION,
4110
+ workspaces: {}
4111
+ },
4112
+ null,
4113
+ 2
4114
+ ),
4115
+ "utf8"
4116
+ );
4117
+ return;
4118
+ }
4119
+ if (parsed.workspaces && typeof parsed.workspaces === "object") {
4120
+ let modified = false;
4121
+ for (const key of Object.keys(parsed.workspaces)) {
4122
+ if (key === workspaceId || key.endsWith(`::${workspaceId}`)) {
4123
+ delete parsed.workspaces[key];
4124
+ modified = true;
4125
+ }
4126
+ }
4127
+ if (modified) {
4128
+ writeFileSync3(syncPath, JSON.stringify(parsed, null, 2), "utf8");
4129
+ }
4130
+ }
4131
+ } catch {
4132
+ }
4133
+ }
3761
4134
  function hasSkippedPathSegment(relPath) {
3762
4135
  const segments = toPosix(relPath).replace(/^\.\//, "").split("/");
3763
4136
  return segments.some((seg) => seg.length > 0 && SKIP_DIRS.has(seg));
@@ -3770,6 +4143,7 @@ function sanitizeManifest(manifest) {
3770
4143
  return {
3771
4144
  relativePath: toPosix(manifest.relativePath),
3772
4145
  contentSha256: manifest.contentSha256,
4146
+ schemaVersion: manifest.schemaVersion ?? CACHE_SCHEMA_VERSION,
3773
4147
  ...manifest.language !== void 0 ? { language: manifest.language } : {},
3774
4148
  ...manifest.mtimeMs !== void 0 ? { mtimeMs: manifest.mtimeMs } : {},
3775
4149
  ...manifest.size !== void 0 ? { size: manifest.size } : {},
@@ -3778,6 +4152,8 @@ function sanitizeManifest(manifest) {
3778
4152
  importedNames: [...imp.importedNames],
3779
4153
  isReExport: imp.isReExport,
3780
4154
  isTypeOnly: imp.isTypeOnly,
4155
+ ...imp.isDynamic === true ? { isDynamic: true } : {},
4156
+ ...typeof imp.verifiedAssetOnDisk === "boolean" ? { verifiedAssetOnDisk: imp.verifiedAssetOnDisk } : {},
3781
4157
  ...Array.isArray(imp.resolvedPaths) ? { resolvedPaths: imp.resolvedPaths.map((p) => toPosix(p)) } : {},
3782
4158
  ...imp.resolvedKind !== void 0 ? { resolvedKind: imp.resolvedKind } : {}
3783
4159
  })),
@@ -3850,6 +4226,7 @@ function scanWorkspaceManifests(rootDir, options = {}) {
3850
4226
  const cachePath = options.cachePath ?? path7.join(resolvedRoot, ".tipolink", "cache.json");
3851
4227
  const writeCache = options.writeCache ?? true;
3852
4228
  const cache = new JsonFileAstCache({ filePath: cachePath, autoSave: false });
4229
+ const schemaInvalidated = cache.schemaInvalidated;
3853
4230
  const priorManifests = cache.getAllWorkspaceManifests(workspaceId);
3854
4231
  const priorPaths = /* @__PURE__ */ new Set();
3855
4232
  let prunedSkippedEntries = false;
@@ -3866,7 +4243,7 @@ function scanWorkspaceManifests(rootDir, options = {}) {
3866
4243
  const deltaRelPaths = /* @__PURE__ */ new Set();
3867
4244
  let cacheHits = 0;
3868
4245
  let parsedCount = 0;
3869
- let cacheMutated = false;
4246
+ let cacheMutated = schemaInvalidated;
3870
4247
  for (const absPath of sourceFiles) {
3871
4248
  let realAbs;
3872
4249
  try {
@@ -3885,29 +4262,44 @@ function scanWorkspaceManifests(rootDir, options = {}) {
3885
4262
  }
3886
4263
  if (!stats.isFile()) continue;
3887
4264
  const statHit = cache.get(workspaceId, relPath, void 0, stats.mtimeMs, stats.size);
3888
- if (statHit) {
4265
+ if (statHit && statHit.schemaVersion === CACHE_SCHEMA_VERSION) {
3889
4266
  cacheHits += 1;
3890
- rawAllManifests.push(sanitizeManifest(statHit));
4267
+ const verified = verifyRelativeAssetsOnDisk(sanitizeManifest(statHit), realAbs);
4268
+ if (verified.changed) {
4269
+ cache.set(workspaceId, verified.manifest);
4270
+ cacheMutated = true;
4271
+ deltaRelPaths.add(relPath);
4272
+ }
4273
+ rawAllManifests.push(verified.manifest);
3891
4274
  continue;
3892
4275
  }
3893
4276
  const source = readFileSync5(realAbs, "utf8");
3894
4277
  const contentSha256 = sha256Text(source);
3895
4278
  const hashHit = cache.get(workspaceId, relPath, contentSha256);
3896
- if (hashHit) {
4279
+ if (hashHit && hashHit.schemaVersion === CACHE_SCHEMA_VERSION) {
3897
4280
  cacheHits += 1;
3898
- const refreshed = sanitizeManifest({
3899
- ...hashHit,
3900
- mtimeMs: stats.mtimeMs,
3901
- size: stats.size
3902
- });
3903
- cache.set(workspaceId, refreshed);
4281
+ const verified = verifyRelativeAssetsOnDisk(
4282
+ sanitizeManifest({
4283
+ ...hashHit,
4284
+ mtimeMs: stats.mtimeMs,
4285
+ size: stats.size
4286
+ }),
4287
+ realAbs
4288
+ );
4289
+ cache.set(workspaceId, verified.manifest);
3904
4290
  cacheMutated = true;
3905
- rawAllManifests.push(refreshed);
4291
+ if (verified.changed) {
4292
+ deltaRelPaths.add(relPath);
4293
+ }
4294
+ rawAllManifests.push(verified.manifest);
3906
4295
  continue;
3907
4296
  }
3908
- const extracted = sanitizeManifest(
3909
- defaultPolyglotRegistry.extractManifest(source, realAbs, relPath, stats.mtimeMs, stats.size)
3910
- );
4297
+ const extracted = verifyRelativeAssetsOnDisk(
4298
+ sanitizeManifest(
4299
+ defaultPolyglotRegistry.extractManifest(source, realAbs, relPath, stats.mtimeMs, stats.size)
4300
+ ),
4301
+ realAbs
4302
+ ).manifest;
3911
4303
  parsedCount += 1;
3912
4304
  cache.set(workspaceId, extracted);
3913
4305
  cacheMutated = true;
@@ -3929,22 +4321,27 @@ function scanWorkspaceManifests(rootDir, options = {}) {
3929
4321
  }
3930
4322
  if (writeCache && cacheMutated) {
3931
4323
  cache.flush();
4324
+ if (schemaInvalidated) {
4325
+ invalidateStaleCloudSyncFile(cachePath, workspaceId);
4326
+ }
3932
4327
  }
3933
4328
  const index = buildIndex(resolvedRoot, { workspaceId, cache });
3934
4329
  const allManifests = [];
3935
4330
  const manifestDelta = [];
3936
4331
  for (const file of index.files) {
3937
4332
  if (hasSkippedPathSegment(file.relative)) continue;
3938
- const sanitized = sanitizeManifest(file.manifest);
3939
- allManifests.push(sanitized);
4333
+ const verified = verifyRelativeAssetsOnDisk(sanitizeManifest(file.manifest), file.absolute).manifest;
4334
+ allManifests.push(verified);
3940
4335
  if (deltaRelPaths.has(file.relative)) {
3941
- manifestDelta.push(sanitized);
4336
+ manifestDelta.push(verified);
3942
4337
  }
3943
4338
  }
3944
4339
  return {
3945
4340
  workspaceId,
3946
4341
  rootDir: resolvedRoot,
3947
4342
  cachePath,
4343
+ schemaVersion: CACHE_SCHEMA_VERSION,
4344
+ schemaInvalidated,
3948
4345
  allManifests,
3949
4346
  manifestDelta,
3950
4347
  removedPaths,
@@ -3957,7 +4354,7 @@ function scanWorkspaceManifests(rootDir, options = {}) {
3957
4354
  // src/mcp-stdio.ts
3958
4355
  var DEFAULT_CLOUD_API_URL2 = "https://tipolink.co";
3959
4356
  var DEFAULT_PORTAL_URL = "https://tipolink.co";
3960
- var TIPOLINK_MCP_VERSION = "1.0.1";
4357
+ var TIPOLINK_MCP_VERSION = "1.0.2";
3961
4358
  var VALID_SYMBOL_KINDS = /* @__PURE__ */ new Set([
3962
4359
  "function",
3963
4360
  "const",
@@ -4094,11 +4491,13 @@ function cloudSyncStatePath(workspaceRoot) {
4094
4491
  }
4095
4492
  function loadCloudSyncHashes(workspaceRoot, stateKey) {
4096
4493
  const filePath = cloudSyncStatePath(workspaceRoot);
4097
- if (!existsSync4(filePath)) return null;
4494
+ if (!existsSync5(filePath)) return null;
4098
4495
  try {
4099
4496
  const raw = readFileSync6(filePath, "utf8");
4100
4497
  const parsed = JSON.parse(raw);
4101
- if (!parsed || typeof parsed !== "object" || !parsed.workspaces) return null;
4498
+ if (!parsed || typeof parsed !== "object" || parsed.manifestSchemaVersion !== CACHE_SCHEMA_VERSION || !parsed.workspaces) {
4499
+ return null;
4500
+ }
4102
4501
  const entry = parsed.workspaces[stateKey];
4103
4502
  return isRecord(entry) ? entry : null;
4104
4503
  } catch {
@@ -4107,32 +4506,41 @@ function loadCloudSyncHashes(workspaceRoot, stateKey) {
4107
4506
  }
4108
4507
  function saveCloudSyncHashes(workspaceRoot, stateKey, manifests) {
4109
4508
  const filePath = cloudSyncStatePath(workspaceRoot);
4110
- let store = { version: 1, workspaces: {} };
4111
- if (existsSync4(filePath)) {
4509
+ let store = {
4510
+ version: 1,
4511
+ manifestSchemaVersion: CACHE_SCHEMA_VERSION,
4512
+ workspaces: {}
4513
+ };
4514
+ if (existsSync5(filePath)) {
4112
4515
  try {
4113
4516
  const parsed = JSON.parse(readFileSync6(filePath, "utf8"));
4114
- if (parsed && typeof parsed === "object" && isRecord(parsed.workspaces)) {
4517
+ if (parsed && typeof parsed === "object" && parsed.manifestSchemaVersion === CACHE_SCHEMA_VERSION && isRecord(parsed.workspaces)) {
4115
4518
  store = {
4116
4519
  version: 1,
4520
+ manifestSchemaVersion: CACHE_SCHEMA_VERSION,
4117
4521
  workspaces: parsed.workspaces
4118
4522
  };
4119
4523
  }
4120
4524
  } catch {
4121
- store = { version: 1, workspaces: {} };
4525
+ store = {
4526
+ version: 1,
4527
+ manifestSchemaVersion: CACHE_SCHEMA_VERSION,
4528
+ workspaces: {}
4529
+ };
4122
4530
  }
4123
4531
  }
4124
4532
  const nextMap = {};
4125
4533
  for (const manifest of manifests) {
4126
- nextMap[manifest.relativePath] = manifest.contentSha256;
4534
+ nextMap[manifest.relativePath] = computeManifestSyncHash(manifest);
4127
4535
  }
4128
4536
  store.workspaces[stateKey] = nextMap;
4129
4537
  mkdirSync3(path8.dirname(filePath), { recursive: true });
4130
- writeFileSync3(filePath, JSON.stringify(store, null, 2), "utf8");
4538
+ writeFileSync4(filePath, JSON.stringify(store, null, 2), "utf8");
4131
4539
  }
4132
4540
  function computeCloudSyncDelta(scan, apiUrl) {
4133
4541
  const baseUrl = apiUrl.replace(/\/+$/, "");
4134
4542
  const stateKey = `${baseUrl}::${scan.workspaceId}`;
4135
- const priorHashes = loadCloudSyncHashes(scan.rootDir, stateKey);
4543
+ const priorHashes = scan.schemaInvalidated ? null : loadCloudSyncHashes(scan.rootDir, stateKey);
4136
4544
  if (!priorHashes) {
4137
4545
  return {
4138
4546
  delta: scan.allManifests,
@@ -4145,7 +4553,7 @@ function computeCloudSyncDelta(scan, apiUrl) {
4145
4553
  const delta = [];
4146
4554
  for (const manifest of scan.allManifests) {
4147
4555
  activePaths.add(manifest.relativePath);
4148
- if (priorHashes[manifest.relativePath] !== manifest.contentSha256) {
4556
+ if (priorHashes[manifest.relativePath] !== computeManifestSyncHash(manifest)) {
4149
4557
  delta.push(manifest);
4150
4558
  }
4151
4559
  }
@@ -4876,7 +5284,7 @@ function collectStagedOrModifiedSources(rootDir, hookTargetFile) {
4876
5284
  let hasAnyNonSourceHookTarget = false;
4877
5285
  const addIfSource = (rawFile) => {
4878
5286
  const abs = path9.isAbsolute(rawFile) ? path9.resolve(rawFile) : path9.resolve(rootDir, rawFile);
4879
- if (!existsSync5(abs)) return;
5287
+ if (!existsSync6(abs)) return;
4880
5288
  const ext = path9.extname(abs).toLowerCase();
4881
5289
  if (!SOURCE_EXTENSIONS.has(ext)) {
4882
5290
  if (hookTargetFile && rawFile === hookTargetFile) {