@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/index.js CHANGED
@@ -1,13 +1,17 @@
1
1
  // src/extractor.ts
2
2
  import { createHash as createHash4 } from "node:crypto";
3
- import { readdirSync as readdirSync2, readFileSync as readFileSync4, realpathSync as realpathSync2, statSync as statSync2 } from "node:fs";
3
+ import { existsSync as existsSync3, readdirSync as readdirSync2, readFileSync as readFileSync4, realpathSync as realpathSync2, statSync as statSync2, writeFileSync as writeFileSync2 } from "node:fs";
4
4
  import path6 from "node:path";
5
5
 
6
6
  // ../engine/src/ast-extractor.ts
7
7
  import { createHash } from "node:crypto";
8
- import path2 from "node:path";
8
+ import path3 from "node:path";
9
9
  import ts from "typescript";
10
10
 
11
+ // ../engine/src/cache.ts
12
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
13
+ import path2 from "node:path";
14
+
11
15
  // ../engine/src/paths.ts
12
16
  import path from "node:path";
13
17
  function compareText(a, b) {
@@ -46,9 +50,143 @@ function computeRelativeImportSpec(fromRelPath, toRelPath) {
46
50
  return rel;
47
51
  }
48
52
 
53
+ // ../engine/src/cache.ts
54
+ var CACHE_SCHEMA_VERSION = "1.0.2";
55
+ function cacheEntryMatches(entry, contentSha256, mtimeMs, size) {
56
+ if (contentSha256 !== void 0) {
57
+ return entry.contentSha256 === contentSha256;
58
+ }
59
+ if (mtimeMs !== void 0 || size !== void 0) {
60
+ if (mtimeMs !== void 0 && entry.mtimeMs !== mtimeMs) return false;
61
+ if (size !== void 0 && entry.size !== size) return false;
62
+ return true;
63
+ }
64
+ return true;
65
+ }
66
+ var JsonFileAstCache = class {
67
+ filePath;
68
+ schemaInvalidated = false;
69
+ autoSave;
70
+ workspaces = /* @__PURE__ */ new Map();
71
+ dirty = false;
72
+ constructor(filePathOrOptions) {
73
+ if (typeof filePathOrOptions === "string") {
74
+ this.filePath = filePathOrOptions;
75
+ this.autoSave = true;
76
+ } else {
77
+ this.filePath = filePathOrOptions.filePath;
78
+ this.autoSave = filePathOrOptions.autoSave ?? true;
79
+ }
80
+ this.loadFromDisk();
81
+ }
82
+ loadFromDisk() {
83
+ if (!existsSync(this.filePath)) return;
84
+ try {
85
+ const raw = readFileSync(this.filePath, "utf8");
86
+ if (!raw.trim()) return;
87
+ const parsed = JSON.parse(raw);
88
+ if (!parsed || typeof parsed !== "object" || !parsed.workspaces || typeof parsed.workspaces !== "object") {
89
+ this.schemaInvalidated = true;
90
+ this.dirty = true;
91
+ return;
92
+ }
93
+ if (parsed.manifestSchemaVersion !== CACHE_SCHEMA_VERSION) {
94
+ this.workspaces.clear();
95
+ this.schemaInvalidated = true;
96
+ this.dirty = true;
97
+ return;
98
+ }
99
+ for (const [workspaceId, files] of Object.entries(parsed.workspaces)) {
100
+ if (!files || typeof files !== "object") continue;
101
+ const map = /* @__PURE__ */ new Map();
102
+ for (const [relPath, manifest] of Object.entries(files)) {
103
+ if (manifest && typeof manifest === "object" && typeof manifest.contentSha256 === "string") {
104
+ const norm = toPosix(relPath);
105
+ map.set(norm, { ...manifest, relativePath: norm });
106
+ }
107
+ }
108
+ this.workspaces.set(workspaceId, map);
109
+ }
110
+ } catch {
111
+ this.workspaces.clear();
112
+ this.schemaInvalidated = true;
113
+ this.dirty = true;
114
+ }
115
+ }
116
+ get(workspaceId, relativePath, contentSha256, mtimeMs, size) {
117
+ const wsMap = this.workspaces.get(workspaceId);
118
+ if (!wsMap) return void 0;
119
+ const hit = wsMap.get(toPosix(relativePath));
120
+ if (!hit) return void 0;
121
+ return cacheEntryMatches(hit, contentSha256, mtimeMs, size) ? hit : void 0;
122
+ }
123
+ set(workspaceId, manifest) {
124
+ const norm = toPosix(manifest.relativePath);
125
+ const normalized = {
126
+ ...manifest,
127
+ relativePath: norm
128
+ };
129
+ let wsMap = this.workspaces.get(workspaceId);
130
+ if (!wsMap) {
131
+ wsMap = /* @__PURE__ */ new Map();
132
+ this.workspaces.set(workspaceId, wsMap);
133
+ }
134
+ wsMap.set(norm, normalized);
135
+ this.dirty = true;
136
+ if (this.autoSave) {
137
+ this.save();
138
+ }
139
+ }
140
+ getAllWorkspaceManifests(workspaceId) {
141
+ const wsMap = this.workspaces.get(workspaceId);
142
+ if (!wsMap) return [];
143
+ return [...wsMap.values()];
144
+ }
145
+ clear(workspaceId) {
146
+ if (workspaceId === void 0) {
147
+ this.workspaces.clear();
148
+ } else {
149
+ this.workspaces.delete(workspaceId);
150
+ }
151
+ this.dirty = true;
152
+ if (this.autoSave) {
153
+ this.save();
154
+ }
155
+ }
156
+ save() {
157
+ if (!this.dirty && existsSync(this.filePath)) return;
158
+ const payload = {
159
+ version: 1,
160
+ manifestSchemaVersion: CACHE_SCHEMA_VERSION,
161
+ workspaces: {}
162
+ };
163
+ for (const [workspaceId, wsMap] of this.workspaces.entries()) {
164
+ const obj = {};
165
+ for (const [relPath, manifest] of wsMap.entries()) {
166
+ obj[relPath] = manifest;
167
+ }
168
+ payload.workspaces[workspaceId] = obj;
169
+ }
170
+ const dir = path2.dirname(this.filePath);
171
+ mkdirSync(dir, { recursive: true });
172
+ const serialized = JSON.stringify(payload, null, 2);
173
+ const tmpPath = `${this.filePath}.${process.pid}.${Date.now()}.tmp`;
174
+ try {
175
+ writeFileSync(tmpPath, serialized, "utf8");
176
+ renameSync(tmpPath, this.filePath);
177
+ } catch {
178
+ writeFileSync(this.filePath, serialized, "utf8");
179
+ }
180
+ this.dirty = false;
181
+ }
182
+ flush() {
183
+ this.save();
184
+ }
185
+ };
186
+
49
187
  // ../engine/src/ast-extractor.ts
50
188
  function scriptKindFor(filePath) {
51
- switch (path2.extname(filePath).toLowerCase()) {
189
+ switch (path3.extname(filePath).toLowerCase()) {
52
190
  case ".tsx":
53
191
  return ts.ScriptKind.TSX;
54
192
  case ".jsx":
@@ -62,7 +200,7 @@ function scriptKindFor(filePath) {
62
200
  }
63
201
  }
64
202
  function jsTsLanguageFor(filePath) {
65
- switch (path2.extname(filePath).toLowerCase()) {
203
+ switch (path3.extname(filePath).toLowerCase()) {
66
204
  case ".js":
67
205
  case ".jsx":
68
206
  case ".mjs":
@@ -87,19 +225,123 @@ function hasModifier(node, kind) {
87
225
  function isFunctionLikeNode(node) {
88
226
  return ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node) || ts.isMethodDeclaration(node);
89
227
  }
90
- function computeStructuralHashWithCount(node, sourceFile) {
228
+ function collectBindingNames(binding, out) {
229
+ if (ts.isIdentifier(binding)) {
230
+ out.add(binding.text);
231
+ } else if (ts.isObjectBindingPattern(binding) || ts.isArrayBindingPattern(binding)) {
232
+ for (const elem of binding.elements) {
233
+ if (ts.isBindingElement(elem)) {
234
+ collectBindingNames(elem.name, out);
235
+ }
236
+ }
237
+ }
238
+ }
239
+ function collectFunctionScopeBindings(fn, out) {
240
+ if (fn.name && ts.isIdentifier(fn.name)) {
241
+ out.add(fn.name.text);
242
+ }
243
+ if (fn.typeParameters) {
244
+ for (const tp of fn.typeParameters) {
245
+ out.add(tp.name.text);
246
+ }
247
+ }
248
+ for (const param of fn.parameters) {
249
+ collectBindingNames(param.name, out);
250
+ }
251
+ }
252
+ function collectHoistedVarDeclarations(node, out) {
253
+ const walk = (curr) => {
254
+ if (isFunctionLikeNode(curr)) return;
255
+ if (ts.isVariableDeclarationList(curr)) {
256
+ const isBlockScoped = (curr.flags & (ts.NodeFlags.Const | ts.NodeFlags.Let)) !== 0;
257
+ if (!isBlockScoped) {
258
+ for (const decl of curr.declarations) {
259
+ collectBindingNames(decl.name, out);
260
+ }
261
+ }
262
+ }
263
+ ts.forEachChild(curr, walk);
264
+ };
265
+ ts.forEachChild(node, walk);
266
+ }
267
+ function collectDirectStatementLocals(statements, out) {
268
+ for (const stmt of statements) {
269
+ if (ts.isVariableStatement(stmt)) {
270
+ for (const decl of stmt.declarationList.declarations) {
271
+ collectBindingNames(decl.name, out);
272
+ }
273
+ } else if (ts.isFunctionDeclaration(stmt) && stmt.name) {
274
+ out.add(stmt.name.text);
275
+ } else if (ts.isClassDeclaration(stmt) && stmt.name) {
276
+ out.add(stmt.name.text);
277
+ }
278
+ }
279
+ }
280
+ function classifyIdentifierRole(curr, parent) {
281
+ if (!parent) return "variable";
282
+ if (ts.isPropertyAccessExpression(parent) && parent.name === curr) return "property";
283
+ if (ts.isQualifiedName(parent) && parent.right === curr) return "property";
284
+ if (ts.isBindingElement(parent) && parent.propertyName === curr) return "object_key";
285
+ if (ts.isPropertyAssignment(parent) && parent.name === curr) return "object_key";
286
+ if (ts.isPropertySignature(parent) && parent.name === curr) return "object_key";
287
+ if (ts.isMethodDeclaration(parent) && parent.name === curr) return "object_key";
288
+ if (ts.isMethodSignature(parent) && parent.name === curr) return "object_key";
289
+ if (ts.isGetAccessorDeclaration(parent) && parent.name === curr) return "object_key";
290
+ if (ts.isSetAccessorDeclaration(parent) && parent.name === curr) return "object_key";
291
+ if (ts.isPropertyDeclaration(parent) && parent.name === curr) return "object_key";
292
+ if (ts.isJsxAttribute(parent) && parent.name === curr) return "object_key";
293
+ if ((ts.isLabeledStatement(parent) || ts.isBreakStatement(parent) || ts.isContinueStatement(parent)) && parent.label === curr) {
294
+ return "property";
295
+ }
296
+ 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) {
297
+ return "declaration";
298
+ }
299
+ return "variable";
300
+ }
301
+ function collectModuleLocalDeclarations(sourceFile) {
302
+ const decls = /* @__PURE__ */ new Set();
303
+ for (const stmt of sourceFile.statements) {
304
+ if (ts.isVariableStatement(stmt)) {
305
+ for (const decl of stmt.declarationList.declarations) {
306
+ collectBindingNames(decl.name, decls);
307
+ }
308
+ } else if (ts.isFunctionDeclaration(stmt) && stmt.name) {
309
+ decls.add(stmt.name.text);
310
+ } else if (ts.isClassDeclaration(stmt) && stmt.name) {
311
+ decls.add(stmt.name.text);
312
+ } else if (ts.isEnumDeclaration(stmt)) {
313
+ decls.add(stmt.name.text);
314
+ }
315
+ }
316
+ return decls;
317
+ }
318
+ function computeStructuralHashWithCount(node, sourceFile, options) {
91
319
  const target = ts.isVariableDeclaration(node) && node.initializer && (ts.isArrowFunction(node.initializer) || ts.isFunctionExpression(node.initializer)) ? node.initializer : node;
320
+ const normalizedFilePath = normalizeRelPath(options?.filePath ?? sourceFile.fileName);
321
+ const moduleLocalDecls = options?.moduleLocalDecls ?? collectModuleLocalDeclarations(sourceFile);
92
322
  const tokens = [];
93
323
  let nodeCount = 0;
94
324
  let astNodeCount = 0;
95
- const visit = (curr, countAsBody) => {
325
+ const visit = (curr, countAsBody, scope, parent) => {
96
326
  nodeCount += 1;
97
327
  if (countAsBody) {
98
328
  astNodeCount += 1;
99
329
  }
100
330
  tokens.push(`K:${curr.kind}`);
331
+ let childScope = scope;
101
332
  if (ts.isPropertyAccessExpression(curr)) {
102
- tokens.push(`PROP:.${curr.name.text}`);
333
+ tokens.push(`PROP:${curr.name.text}`);
334
+ } else if (ts.isStringLiteral(curr) || ts.isNoSubstitutionTemplateLiteral(curr)) {
335
+ tokens.push(`STR:${curr.text}`);
336
+ } else if (ts.isTemplateExpression(curr)) {
337
+ tokens.push(`TPL_H:${curr.head.text}`);
338
+ for (const span of curr.templateSpans) {
339
+ tokens.push(`TPL_M:${span.literal.text}`);
340
+ }
341
+ } else if (ts.isNumericLiteral(curr)) {
342
+ tokens.push(`NUM:${curr.text}`);
343
+ } else if (ts.isRegularExpressionLiteral(curr)) {
344
+ tokens.push(`REGEX:${curr.text}`);
103
345
  } else if (ts.isBinaryExpression(curr)) {
104
346
  tokens.push(`OP:${curr.operatorToken.kind}`);
105
347
  } else if (ts.isPrefixUnaryExpression(curr)) {
@@ -109,10 +351,61 @@ function computeStructuralHashWithCount(node, sourceFile) {
109
351
  } else if (ts.isVariableDeclarationList(curr)) {
110
352
  const declFlag = curr.flags & (ts.NodeFlags.Const | ts.NodeFlags.Let);
111
353
  tokens.push(`VF:${declFlag}`);
354
+ } else if (ts.isIdentifier(curr)) {
355
+ const role = classifyIdentifierRole(curr, parent);
356
+ if (role === "declaration") {
357
+ tokens.push("ID:$L");
358
+ } else if (role === "object_key") {
359
+ tokens.push(`KEY:${curr.text}`);
360
+ } else if (role === "variable") {
361
+ if (scope.has(curr.text)) {
362
+ tokens.push("ID:$L");
363
+ } else if (moduleLocalDecls.has(curr.text)) {
364
+ tokens.push(`STATE:${normalizedFilePath}:${curr.text}`);
365
+ } else {
366
+ tokens.push(`EXT:${curr.text}`);
367
+ }
368
+ }
112
369
  }
113
- ts.forEachChild(curr, (child) => visit(child, countAsBody));
370
+ if (curr !== target && isFunctionLikeNode(curr)) {
371
+ const next = new Set(scope);
372
+ collectFunctionScopeBindings(curr, next);
373
+ if (curr.body) {
374
+ collectHoistedVarDeclarations(curr.body, next);
375
+ }
376
+ childScope = next;
377
+ } else if (ts.isBlock(curr)) {
378
+ const next = new Set(scope);
379
+ collectDirectStatementLocals(curr.statements, next);
380
+ childScope = next;
381
+ } else if (ts.isCaseClause(curr) || ts.isDefaultClause(curr)) {
382
+ const next = new Set(scope);
383
+ collectDirectStatementLocals(curr.statements, next);
384
+ childScope = next;
385
+ } else if (ts.isForStatement(curr) || ts.isForInStatement(curr) || ts.isForOfStatement(curr)) {
386
+ if (curr.initializer && ts.isVariableDeclarationList(curr.initializer)) {
387
+ const next = new Set(scope);
388
+ for (const decl of curr.initializer.declarations) {
389
+ collectBindingNames(decl.name, next);
390
+ }
391
+ childScope = next;
392
+ }
393
+ } else if (ts.isCatchClause(curr) && curr.variableDeclaration) {
394
+ const next = new Set(scope);
395
+ collectBindingNames(curr.variableDeclaration.name, next);
396
+ childScope = next;
397
+ }
398
+ ts.forEachChild(curr, (child) => visit(child, countAsBody, childScope, curr));
114
399
  };
115
400
  if (isFunctionLikeNode(target)) {
401
+ const rootScope = /* @__PURE__ */ new Set();
402
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {
403
+ rootScope.add(node.name.text);
404
+ }
405
+ collectFunctionScopeBindings(target, rootScope);
406
+ if (target.body) {
407
+ collectHoistedVarDeclarations(target.body, rootScope);
408
+ }
116
409
  tokens.push("FN");
117
410
  if (hasModifier(target, ts.SyntaxKind.AsyncKeyword)) {
118
411
  tokens.push("MOD:ASYNC");
@@ -121,14 +414,13 @@ function computeStructuralHashWithCount(node, sourceFile) {
121
414
  tokens.push("MOD:GEN");
122
415
  }
123
416
  for (const param of target.parameters) {
124
- visit(param, false);
417
+ visit(param, false, rootScope, target);
125
418
  }
126
419
  if (target.body) {
127
- visit(target.body, true);
420
+ visit(target.body, true, rootScope, target);
128
421
  }
129
422
  } else {
130
- void sourceFile;
131
- visit(target, true);
423
+ visit(target, true, /* @__PURE__ */ new Set(), void 0);
132
424
  }
133
425
  const structuralHash = createHash("sha256").update(tokens.join("|"), "utf8").digest("hex").slice(0, 16);
134
426
  return { structuralHash, nodeCount, astNodeCount };
@@ -162,7 +454,7 @@ function formatConstSummary(decl, sourceFile) {
162
454
  }
163
455
  if (ts.isObjectLiteralExpression(init)) {
164
456
  const keys = init.properties.slice(0, 5).map((prop) => {
165
- if (ts.isPropertyAssignment(prop) || ts.isShorthandPropertyAssignment(prop)) {
457
+ if (ts.isPropertyAssignment(prop) || ts.isShorthandPropertyAssignment(prop) || ts.isMethodDeclaration(prop)) {
166
458
  return prop.name.getText(sourceFile);
167
459
  }
168
460
  return "...";
@@ -203,10 +495,10 @@ function formatEnumSignature(node, sourceFile) {
203
495
  function lineNumberOf(node, sourceFile) {
204
496
  return sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;
205
497
  }
206
- function pushImportRef(refs, keyMap, rawSpecifier, importedNames, isReExport, isTypeOnly) {
498
+ function pushImportRef(refs, keyMap, rawSpecifier, importedNames, isReExport, isTypeOnly, isDynamic = false) {
207
499
  const trimmed = rawSpecifier.trim();
208
500
  if (!trimmed) return;
209
- const dedupKey = `${trimmed}\0${isReExport ? "1" : "0"}\0${isTypeOnly ? "1" : "0"}`;
501
+ const dedupKey = `${trimmed}\0${isReExport ? "1" : "0"}\0${isTypeOnly ? "1" : "0"}\0${isDynamic ? "1" : "0"}`;
210
502
  const existing = keyMap.get(dedupKey);
211
503
  if (existing) {
212
504
  for (const name of importedNames) {
@@ -220,7 +512,8 @@ function pushImportRef(refs, keyMap, rawSpecifier, importedNames, isReExport, is
220
512
  rawSpecifier: trimmed,
221
513
  importedNames: [...new Set(importedNames)],
222
514
  isReExport,
223
- isTypeOnly
515
+ isTypeOnly,
516
+ ...isDynamic ? { isDynamic: true } : {}
224
517
  };
225
518
  keyMap.set(dedupKey, entry);
226
519
  refs.push(entry);
@@ -233,7 +526,10 @@ function extractImports(sourceFile) {
233
526
  if (ts.isStringLiteral(node.moduleSpecifier)) {
234
527
  const names = [];
235
528
  const clause = node.importClause;
236
- const isTypeOnly = Boolean(clause?.isTypeOnly);
529
+ const allNamedTypeOnly = Boolean(
530
+ clause && !clause.name && clause.namedBindings && ts.isNamedImports(clause.namedBindings) && clause.namedBindings.elements.length > 0 && clause.namedBindings.elements.every((elem) => elem.isTypeOnly)
531
+ );
532
+ const isTypeOnly = Boolean(clause?.isTypeOnly) || allNamedTypeOnly;
237
533
  if (clause) {
238
534
  if (clause.name) names.push("default");
239
535
  if (clause.namedBindings) {
@@ -246,13 +542,19 @@ function extractImports(sourceFile) {
246
542
  }
247
543
  }
248
544
  }
249
- pushImportRef(refs, keyMap, node.moduleSpecifier.text, names, false, isTypeOnly);
545
+ pushImportRef(refs, keyMap, node.moduleSpecifier.text, names, false, isTypeOnly, false);
250
546
  }
251
547
  } else if (ts.isExportDeclaration(node)) {
252
548
  if (node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
253
549
  const names = [];
550
+ const allNamedTypeOnly = Boolean(
551
+ node.exportClause && ts.isNamedExports(node.exportClause) && node.exportClause.elements.length > 0 && node.exportClause.elements.every((elem) => elem.isTypeOnly)
552
+ );
553
+ const isTypeOnly = Boolean(node.isTypeOnly) || allNamedTypeOnly;
254
554
  if (!node.exportClause) {
255
- names.push("*");
555
+ if (!isTypeOnly) {
556
+ names.push("*");
557
+ }
256
558
  } else if (ts.isNamespaceExport(node.exportClause)) {
257
559
  names.push("*");
258
560
  } else if (ts.isNamedExports(node.exportClause)) {
@@ -260,27 +562,27 @@ function extractImports(sourceFile) {
260
562
  names.push((elem.propertyName ?? elem.name).text);
261
563
  }
262
564
  }
263
- pushImportRef(refs, keyMap, node.moduleSpecifier.text, names, true, Boolean(node.isTypeOnly));
565
+ pushImportRef(refs, keyMap, node.moduleSpecifier.text, names, true, isTypeOnly, false);
264
566
  }
265
567
  } else if (ts.isImportEqualsDeclaration(node)) {
266
568
  if (ts.isExternalModuleReference(node.moduleReference) && ts.isStringLiteral(node.moduleReference.expression)) {
267
- pushImportRef(refs, keyMap, node.moduleReference.expression.text, [node.name.text], false, false);
569
+ pushImportRef(refs, keyMap, node.moduleReference.expression.text, [node.name.text], false, false, false);
268
570
  }
269
571
  } else if (ts.isCallExpression(node)) {
270
572
  const first = node.arguments[0];
271
573
  if (first && ts.isStringLiteralLike(first)) {
272
574
  const callee = node.expression;
273
575
  if (callee.kind === ts.SyntaxKind.ImportKeyword) {
274
- pushImportRef(refs, keyMap, first.text, [], false, false);
576
+ pushImportRef(refs, keyMap, first.text, [], false, false, true);
275
577
  } else if (ts.isIdentifier(callee) && callee.text === "require") {
276
- pushImportRef(refs, keyMap, first.text, [], false, false);
578
+ pushImportRef(refs, keyMap, first.text, [], false, false, false);
277
579
  }
278
580
  }
279
581
  } else if (ts.isImportTypeNode(node)) {
280
582
  const argument = node.argument;
281
583
  if (ts.isLiteralTypeNode(argument) && ts.isStringLiteral(argument.literal)) {
282
584
  const names = node.qualifier ? [collapseWhitespace(node.qualifier.getText(sourceFile))] : [];
283
- pushImportRef(refs, keyMap, argument.literal.text, names, false, true);
585
+ pushImportRef(refs, keyMap, argument.literal.text, names, false, true, false);
284
586
  }
285
587
  }
286
588
  ts.forEachChild(node, visit);
@@ -299,6 +601,8 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
299
601
  scriptKindFor(absolutePath)
300
602
  );
301
603
  const imports = extractImports(sourceFile);
604
+ const moduleLocalDecls = collectModuleLocalDeclarations(sourceFile);
605
+ const hashOptions = { filePath: rel, moduleLocalDecls };
302
606
  const localDecls = /* @__PURE__ */ new Map();
303
607
  const exportedSymbols = [];
304
608
  const internalFunctions = [];
@@ -316,7 +620,11 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
316
620
  if (ts.isFunctionDeclaration(stmt)) {
317
621
  if (!stmt.body) continue;
318
622
  const declName = stmt.name?.text;
319
- const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(stmt, sourceFile);
623
+ const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
624
+ stmt,
625
+ sourceFile,
626
+ hashOptions
627
+ );
320
628
  const signature = formatFunctionSignature(stmt, sourceFile);
321
629
  const line = lineNumberOf(stmt, sourceFile);
322
630
  if (declName) {
@@ -358,7 +666,11 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
358
666
  const line = lineNumberOf(decl, sourceFile);
359
667
  const init = decl.initializer;
360
668
  if (init && (ts.isArrowFunction(init) || ts.isFunctionExpression(init))) {
361
- const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(init, sourceFile);
669
+ const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
670
+ decl,
671
+ sourceFile,
672
+ hashOptions
673
+ );
362
674
  const signature = formatFunctionSignature(init, sourceFile);
363
675
  localDecls.set(declName, {
364
676
  name: declName,
@@ -596,7 +908,11 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
596
908
  });
597
909
  }
598
910
  } else if (ts.isArrowFunction(stmt.expression) || ts.isFunctionExpression(stmt.expression)) {
599
- const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(stmt.expression, sourceFile);
911
+ const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
912
+ stmt.expression,
913
+ sourceFile,
914
+ hashOptions
915
+ );
600
916
  addExported({
601
917
  name: "default",
602
918
  kind: "function",
@@ -639,6 +955,7 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
639
955
  return {
640
956
  relativePath: rel,
641
957
  contentSha256,
958
+ schemaVersion: CACHE_SCHEMA_VERSION,
642
959
  language: jsTsLanguageFor(absolutePath),
643
960
  ...mtimeMs !== void 0 ? { mtimeMs } : {},
644
961
  ...size !== void 0 ? { size } : {},
@@ -648,129 +965,6 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
648
965
  };
649
966
  }
650
967
 
651
- // ../engine/src/cache.ts
652
- import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
653
- import path3 from "node:path";
654
- function cacheEntryMatches(entry, contentSha256, mtimeMs, size) {
655
- if (contentSha256 !== void 0) {
656
- return entry.contentSha256 === contentSha256;
657
- }
658
- if (mtimeMs !== void 0 || size !== void 0) {
659
- if (mtimeMs !== void 0 && entry.mtimeMs !== mtimeMs) return false;
660
- if (size !== void 0 && entry.size !== size) return false;
661
- return true;
662
- }
663
- return true;
664
- }
665
- var JsonFileAstCache = class {
666
- filePath;
667
- autoSave;
668
- workspaces = /* @__PURE__ */ new Map();
669
- dirty = false;
670
- constructor(filePathOrOptions) {
671
- if (typeof filePathOrOptions === "string") {
672
- this.filePath = filePathOrOptions;
673
- this.autoSave = true;
674
- } else {
675
- this.filePath = filePathOrOptions.filePath;
676
- this.autoSave = filePathOrOptions.autoSave ?? true;
677
- }
678
- this.loadFromDisk();
679
- }
680
- loadFromDisk() {
681
- if (!existsSync(this.filePath)) return;
682
- try {
683
- const raw = readFileSync(this.filePath, "utf8");
684
- if (!raw.trim()) return;
685
- const parsed = JSON.parse(raw);
686
- if (!parsed || typeof parsed !== "object" || !parsed.workspaces || typeof parsed.workspaces !== "object") {
687
- return;
688
- }
689
- for (const [workspaceId, files] of Object.entries(parsed.workspaces)) {
690
- if (!files || typeof files !== "object") continue;
691
- const map = /* @__PURE__ */ new Map();
692
- for (const [relPath, manifest] of Object.entries(files)) {
693
- if (manifest && typeof manifest === "object" && typeof manifest.contentSha256 === "string") {
694
- const norm = toPosix(relPath);
695
- map.set(norm, { ...manifest, relativePath: norm });
696
- }
697
- }
698
- this.workspaces.set(workspaceId, map);
699
- }
700
- } catch {
701
- this.workspaces.clear();
702
- }
703
- }
704
- get(workspaceId, relativePath, contentSha256, mtimeMs, size) {
705
- const wsMap = this.workspaces.get(workspaceId);
706
- if (!wsMap) return void 0;
707
- const hit = wsMap.get(toPosix(relativePath));
708
- if (!hit) return void 0;
709
- return cacheEntryMatches(hit, contentSha256, mtimeMs, size) ? hit : void 0;
710
- }
711
- set(workspaceId, manifest) {
712
- const norm = toPosix(manifest.relativePath);
713
- const normalized = {
714
- ...manifest,
715
- relativePath: norm
716
- };
717
- let wsMap = this.workspaces.get(workspaceId);
718
- if (!wsMap) {
719
- wsMap = /* @__PURE__ */ new Map();
720
- this.workspaces.set(workspaceId, wsMap);
721
- }
722
- wsMap.set(norm, normalized);
723
- this.dirty = true;
724
- if (this.autoSave) {
725
- this.save();
726
- }
727
- }
728
- getAllWorkspaceManifests(workspaceId) {
729
- const wsMap = this.workspaces.get(workspaceId);
730
- if (!wsMap) return [];
731
- return [...wsMap.values()];
732
- }
733
- clear(workspaceId) {
734
- if (workspaceId === void 0) {
735
- this.workspaces.clear();
736
- } else {
737
- this.workspaces.delete(workspaceId);
738
- }
739
- this.dirty = true;
740
- if (this.autoSave) {
741
- this.save();
742
- }
743
- }
744
- save() {
745
- if (!this.dirty && existsSync(this.filePath)) return;
746
- const payload = {
747
- version: 1,
748
- workspaces: {}
749
- };
750
- for (const [workspaceId, wsMap] of this.workspaces.entries()) {
751
- const obj = {};
752
- for (const [relPath, manifest] of wsMap.entries()) {
753
- obj[relPath] = manifest;
754
- }
755
- payload.workspaces[workspaceId] = obj;
756
- }
757
- const dir = path3.dirname(this.filePath);
758
- mkdirSync(dir, { recursive: true });
759
- const serialized = JSON.stringify(payload, null, 2);
760
- const tmpPath = `${this.filePath}.${process.pid}.${Date.now()}.tmp`;
761
- try {
762
- writeFileSync(tmpPath, serialized, "utf8");
763
- renameSync(tmpPath, this.filePath);
764
- } catch {
765
- writeFileSync(this.filePath, serialized, "utf8");
766
- }
767
- this.dirty = false;
768
- }
769
- flush() {
770
- this.save();
771
- }
772
- };
773
-
774
968
  // ../engine/src/env.ts
775
969
  function readEnv(name) {
776
970
  return process.env[`TIPOLINK_${name}`] ?? process.env[`INTERLINK_${name}`];
@@ -2915,6 +3109,45 @@ function buildWorkspaceResolutionContext(root, rootReal, allRelativePaths, confi
2915
3109
 
2916
3110
  // ../engine/src/indexer.ts
2917
3111
  var SOURCE_EXTENSIONS = new Set(defaultPolyglotRegistry.supportedExtensions);
3112
+ var NON_CODE_ASSET_EXTENSIONS = /* @__PURE__ */ new Set([
3113
+ ".css",
3114
+ ".scss",
3115
+ ".less",
3116
+ ".svg",
3117
+ ".png",
3118
+ ".jpg",
3119
+ ".jpeg",
3120
+ ".webp",
3121
+ ".gif",
3122
+ ".ico",
3123
+ ".woff",
3124
+ ".woff2",
3125
+ ".ttf",
3126
+ ".wasm",
3127
+ ".json",
3128
+ ".glsl",
3129
+ ".sql",
3130
+ ".txt",
3131
+ ".md"
3132
+ ]);
3133
+ function stripImportQueryAndHash(specifier) {
3134
+ const trimmed = specifier.trim();
3135
+ const qIdx = trimmed.indexOf("?");
3136
+ const hIdx = trimmed.indexOf("#");
3137
+ let cut = trimmed.length;
3138
+ if (qIdx !== -1 && qIdx < cut) cut = qIdx;
3139
+ if (hIdx !== -1 && hIdx < cut) cut = hIdx;
3140
+ return trimmed.slice(0, cut);
3141
+ }
3142
+ function isRelativeImportSpecifier(specifier) {
3143
+ const clean = stripImportQueryAndHash(specifier);
3144
+ return clean === "." || clean === ".." || clean.startsWith("./") || clean.startsWith("../");
3145
+ }
3146
+ function isNonCodeAssetSpecifier(specifier) {
3147
+ const clean = stripImportQueryAndHash(specifier);
3148
+ const ext = path5.posix.extname(clean).toLowerCase();
3149
+ return ext.length > 0 && NON_CODE_ASSET_EXTENSIONS.has(ext) && !SOURCE_EXTENSIONS.has(ext);
3150
+ }
2918
3151
  var SKIP_DIRS = /* @__PURE__ */ new Set([
2919
3152
  "node_modules",
2920
3153
  ".git",
@@ -3124,7 +3357,18 @@ function resolveAlias(spec, fromFile, index) {
3124
3357
  }
3125
3358
  return null;
3126
3359
  }
3127
- function localRef(found, index, importedNames, isReExport) {
3360
+ function buildEdgeFlags(importedNames, meta) {
3361
+ const isTypeOnly = meta?.isTypeOnly === true;
3362
+ const isDynamic = meta?.isDynamic === true;
3363
+ const hasStaticValueImport = !isTypeOnly && !isDynamic && meta?.verifiedAssetOnDisk !== true && importedNames.length > 0;
3364
+ return {
3365
+ ...isTypeOnly ? { isTypeOnly: true } : {},
3366
+ ...isDynamic ? { isDynamic: true } : {},
3367
+ hasStaticValueImport,
3368
+ ...meta?.verifiedAssetOnDisk !== void 0 ? { verifiedAssetOnDisk: meta.verifiedAssetOnDisk } : {}
3369
+ };
3370
+ }
3371
+ function localRef(found, index, importedNames, isReExport, meta) {
3128
3372
  let real;
3129
3373
  try {
3130
3374
  real = realpathSync.native(found);
@@ -3137,55 +3381,72 @@ function localRef(found, index, importedNames, isReExport) {
3137
3381
  kind: "local",
3138
3382
  label,
3139
3383
  importedNames: [...importedNames],
3140
- isReExport
3384
+ isReExport,
3385
+ ...buildEdgeFlags(importedNames, meta)
3141
3386
  };
3142
3387
  }
3143
- function unresolvedRef(base, index, importedNames, isReExport) {
3388
+ function unresolvedRef(base, index, importedNames, isReExport, meta) {
3144
3389
  const label = displayPath(index.root, path5.resolve(base));
3145
3390
  return {
3146
3391
  key: `unresolved:${label}`,
3147
3392
  kind: "unresolved",
3148
3393
  label: `${label} (unresolved)`,
3149
3394
  importedNames: [...importedNames],
3150
- isReExport
3395
+ isReExport,
3396
+ ...buildEdgeFlags(importedNames, meta)
3151
3397
  };
3152
3398
  }
3153
- function externalRef(spec, importedNames, isReExport) {
3399
+ function externalRef(spec, importedNames, isReExport, meta) {
3154
3400
  return {
3155
3401
  key: `pkg:${spec}`,
3156
3402
  kind: "external",
3157
3403
  label: spec,
3158
3404
  importedNames: [...importedNames],
3159
- isReExport
3405
+ isReExport,
3406
+ ...buildEdgeFlags(importedNames, meta)
3160
3407
  };
3161
3408
  }
3162
- function resolveModule(rawSpec, fromFile, index, importedNames = [], isReExport = false) {
3163
- const spec = rawSpec.trim();
3409
+ function resolveModule(rawSpec, fromFile, index, importedNames = [], isReExport = false, meta) {
3410
+ const spec = stripImportQueryAndHash(rawSpec);
3164
3411
  if (spec === "." || spec === ".." || spec.startsWith("./") || spec.startsWith("../")) {
3165
3412
  const base = path5.resolve(path5.dirname(fromFile), spec);
3166
3413
  const found = resolveCandidate(base);
3167
- return found ? localRef(found, index, importedNames, isReExport) : unresolvedRef(base, index, importedNames, isReExport);
3414
+ const isAsset = isNonCodeAssetSpecifier(spec);
3415
+ const verifiedAssetOnDisk = isAsset ? Boolean(found) : meta?.verifiedAssetOnDisk;
3416
+ const effectiveMeta = {
3417
+ ...meta,
3418
+ ...verifiedAssetOnDisk !== void 0 ? { verifiedAssetOnDisk } : {}
3419
+ };
3420
+ return found ? localRef(found, index, importedNames, isReExport, effectiveMeta) : unresolvedRef(base, index, importedNames, isReExport, effectiveMeta);
3168
3421
  }
3169
3422
  if (spec.startsWith("node:")) {
3170
- return externalRef(spec, importedNames, isReExport);
3423
+ return externalRef(spec, importedNames, isReExport, meta);
3171
3424
  }
3172
3425
  if (NODE_BUILTINS.has(spec)) {
3173
- return externalRef(`node:${spec}`, importedNames, isReExport);
3426
+ return externalRef(`node:${spec}`, importedNames, isReExport, meta);
3174
3427
  }
3175
3428
  if (path5.isAbsolute(spec)) {
3176
3429
  const found = resolveCandidate(spec);
3177
- if (found) return localRef(found, index, importedNames, isReExport);
3430
+ if (found) return localRef(found, index, importedNames, isReExport, meta);
3178
3431
  }
3179
3432
  const aliased = resolveAlias(spec, fromFile, index);
3180
- if (aliased) return localRef(aliased, index, importedNames, isReExport);
3181
- return externalRef(spec, importedNames, isReExport);
3433
+ if (aliased) {
3434
+ const isAsset = isNonCodeAssetSpecifier(aliased);
3435
+ return localRef(aliased, index, importedNames, isReExport, {
3436
+ ...meta,
3437
+ ...isAsset ? { verifiedAssetOnDisk: true } : {}
3438
+ });
3439
+ }
3440
+ return externalRef(spec, importedNames, isReExport, meta);
3182
3441
  }
3183
3442
  function mergeModuleRef(modules, ref) {
3443
+ const incomingHasStatic = ref.hasStaticValueImport ?? (ref.isTypeOnly !== true && ref.isDynamic !== true && ref.verifiedAssetOnDisk !== true && ref.importedNames.length > 0);
3184
3444
  const existing = modules.get(ref.key);
3185
3445
  if (!existing) {
3186
3446
  modules.set(ref.key, {
3187
3447
  ...ref,
3188
- importedNames: [...ref.importedNames]
3448
+ importedNames: [...ref.importedNames],
3449
+ hasStaticValueImport: incomingHasStatic
3189
3450
  });
3190
3451
  return;
3191
3452
  }
@@ -3197,6 +3458,15 @@ function mergeModuleRef(modules, ref) {
3197
3458
  if (ref.isReExport) {
3198
3459
  existing.isReExport = true;
3199
3460
  }
3461
+ const existingHasStatic = existing.hasStaticValueImport ?? (existing.isTypeOnly !== true && existing.isDynamic !== true && existing.verifiedAssetOnDisk !== true && existing.importedNames.length > 0);
3462
+ existing.hasStaticValueImport = existingHasStatic || incomingHasStatic;
3463
+ existing.isTypeOnly = Boolean(existing.isTypeOnly) && Boolean(ref.isTypeOnly);
3464
+ existing.isDynamic = Boolean(existing.isDynamic) && Boolean(ref.isDynamic);
3465
+ if (ref.verifiedAssetOnDisk === true) {
3466
+ existing.verifiedAssetOnDisk = true;
3467
+ } else if (ref.verifiedAssetOnDisk === false && existing.verifiedAssetOnDisk === void 0) {
3468
+ existing.verifiedAssetOnDisk = false;
3469
+ }
3200
3470
  }
3201
3471
  function addInboundEdge(index, callerRel, targetRel) {
3202
3472
  let inboundSet = index.inbound.get(targetRel);
@@ -3229,8 +3499,13 @@ function registerIndexedFile(index, file, extraId) {
3229
3499
  function resolveNonJsTsImport(imp, relative, language, index, modules) {
3230
3500
  const adapter = defaultPolyglotRegistry.getAdapterById(language);
3231
3501
  const ctx = index.resolutionContext;
3502
+ const edgeMeta = {
3503
+ isTypeOnly: imp.isTypeOnly,
3504
+ isDynamic: imp.isDynamic,
3505
+ verifiedAssetOnDisk: imp.verifiedAssetOnDisk
3506
+ };
3232
3507
  if (!adapter || !ctx) {
3233
- const ext = externalRef(imp.rawSpecifier, imp.importedNames, imp.isReExport);
3508
+ const ext = externalRef(imp.rawSpecifier, imp.importedNames, imp.isReExport, edgeMeta);
3234
3509
  mergeModuleRef(modules, { ...ext, rawSpecifier: imp.rawSpecifier });
3235
3510
  return { ...imp, resolvedKind: "external", resolvedPaths: [] };
3236
3511
  }
@@ -3243,6 +3518,7 @@ function resolveNonJsTsImport(imp, relative, language, index, modules) {
3243
3518
  label: targetRel,
3244
3519
  importedNames: [...imp.importedNames],
3245
3520
  isReExport: imp.isReExport,
3521
+ ...buildEdgeFlags(imp.importedNames, edgeMeta),
3246
3522
  rawSpecifier: imp.rawSpecifier
3247
3523
  });
3248
3524
  }
@@ -3260,6 +3536,7 @@ function resolveNonJsTsImport(imp, relative, language, index, modules) {
3260
3536
  label: `${attempt} (unresolved)`,
3261
3537
  importedNames: [...imp.importedNames],
3262
3538
  isReExport: imp.isReExport,
3539
+ ...buildEdgeFlags(imp.importedNames, edgeMeta),
3263
3540
  rawSpecifier: imp.rawSpecifier
3264
3541
  });
3265
3542
  return {
@@ -3270,7 +3547,7 @@ function resolveNonJsTsImport(imp, relative, language, index, modules) {
3270
3547
  }
3271
3548
  const extLabel = res.externalLabel ?? imp.rawSpecifier;
3272
3549
  mergeModuleRef(modules, {
3273
- ...externalRef(extLabel, imp.importedNames, imp.isReExport),
3550
+ ...externalRef(extLabel, imp.importedNames, imp.isReExport, edgeMeta),
3274
3551
  rawSpecifier: imp.rawSpecifier
3275
3552
  });
3276
3553
  return {
@@ -3331,11 +3608,29 @@ function indexFileOnDisk(absolute, index, options) {
3331
3608
  const resolvedImports = [];
3332
3609
  for (const imp of manifest.imports) {
3333
3610
  if (isJsTs) {
3334
- const ref = resolveModule(imp.rawSpecifier, realAbs, index, imp.importedNames, imp.isReExport);
3611
+ const cleanSpec = stripImportQueryAndHash(imp.rawSpecifier);
3612
+ let verifiedAssetOnDisk = imp.verifiedAssetOnDisk;
3613
+ if (isRelativeImportSpecifier(cleanSpec) && isNonCodeAssetSpecifier(cleanSpec)) {
3614
+ verifiedAssetOnDisk = isFile(path5.resolve(path5.dirname(realAbs), cleanSpec));
3615
+ }
3616
+ const ref = resolveModule(
3617
+ imp.rawSpecifier,
3618
+ realAbs,
3619
+ index,
3620
+ imp.importedNames,
3621
+ imp.isReExport,
3622
+ {
3623
+ isTypeOnly: imp.isTypeOnly,
3624
+ isDynamic: imp.isDynamic,
3625
+ verifiedAssetOnDisk
3626
+ }
3627
+ );
3335
3628
  mergeModuleRef(modules, { ...ref, rawSpecifier: imp.rawSpecifier });
3336
3629
  const resolvedPaths = ref.kind === "local" ? [ref.label] : ref.kind === "unresolved" ? [ref.label.replace(/ \(unresolved\)$/, "")] : [];
3630
+ const effectiveVerifiedAsset = ref.verifiedAssetOnDisk !== void 0 ? ref.verifiedAssetOnDisk : verifiedAssetOnDisk;
3337
3631
  resolvedImports.push({
3338
3632
  ...imp,
3633
+ ...effectiveVerifiedAsset !== void 0 ? { verifiedAssetOnDisk: effectiveVerifiedAsset } : {},
3339
3634
  resolvedKind: ref.kind,
3340
3635
  resolvedPaths
3341
3636
  });
@@ -3426,6 +3721,84 @@ function buildIndex(root, options) {
3426
3721
  function sha256Text(text) {
3427
3722
  return createHash4("sha256").update(text, "utf8").digest("hex");
3428
3723
  }
3724
+ function computeManifestSyncHash(manifest) {
3725
+ const assetSig = manifest.imports.map((imp) => {
3726
+ const assetFlag = imp.verifiedAssetOnDisk === true ? "1" : imp.verifiedAssetOnDisk === false ? "0" : "-";
3727
+ const dynFlag = imp.isDynamic === true ? "D" : "S";
3728
+ const typeFlag = imp.isTypeOnly ? "T" : "V";
3729
+ return `${imp.rawSpecifier}:${typeFlag}${dynFlag}${assetFlag}:${imp.importedNames.length}`;
3730
+ }).join("|");
3731
+ const symSig = manifest.exportedSymbols.map((s) => `${s.name}:${s.structuralHash ?? ""}`).join(",");
3732
+ const internalSig = manifest.internalFunctions.map((f) => `${f.name}:${f.structuralHash}`).join(",");
3733
+ const schema = manifest.schemaVersion ?? CACHE_SCHEMA_VERSION;
3734
+ return sha256Text(`${schema}\0${manifest.contentSha256}\0${assetSig}\0${symSig}\0${internalSig}`);
3735
+ }
3736
+ function verifyRelativeAssetsOnDisk(manifest, sourceAbsPath) {
3737
+ const sourceDir = path6.dirname(sourceAbsPath);
3738
+ let changed = false;
3739
+ const updatedImports = manifest.imports.map((imp) => {
3740
+ const cleanSpec = stripImportQueryAndHash(imp.rawSpecifier);
3741
+ if (!isRelativeImportSpecifier(cleanSpec) || !isNonCodeAssetSpecifier(cleanSpec)) {
3742
+ return imp;
3743
+ }
3744
+ const resolvedDiskPath = path6.resolve(sourceDir, cleanSpec);
3745
+ const verified = existsSync3(resolvedDiskPath);
3746
+ if (imp.verifiedAssetOnDisk !== verified) {
3747
+ changed = true;
3748
+ }
3749
+ return {
3750
+ ...imp,
3751
+ verifiedAssetOnDisk: verified
3752
+ };
3753
+ });
3754
+ if (!changed) {
3755
+ return { manifest, changed: false };
3756
+ }
3757
+ return {
3758
+ manifest: {
3759
+ ...manifest,
3760
+ imports: updatedImports
3761
+ },
3762
+ changed: true
3763
+ };
3764
+ }
3765
+ function invalidateStaleCloudSyncFile(cachePath, workspaceId) {
3766
+ const syncPath = path6.join(path6.dirname(cachePath), "cloud-sync.json");
3767
+ if (!existsSync3(syncPath)) return;
3768
+ try {
3769
+ const parsed = JSON.parse(readFileSync4(syncPath, "utf8"));
3770
+ if (!parsed || typeof parsed !== "object") return;
3771
+ if (parsed.manifestSchemaVersion !== CACHE_SCHEMA_VERSION) {
3772
+ writeFileSync2(
3773
+ syncPath,
3774
+ JSON.stringify(
3775
+ {
3776
+ version: 1,
3777
+ manifestSchemaVersion: CACHE_SCHEMA_VERSION,
3778
+ workspaces: {}
3779
+ },
3780
+ null,
3781
+ 2
3782
+ ),
3783
+ "utf8"
3784
+ );
3785
+ return;
3786
+ }
3787
+ if (parsed.workspaces && typeof parsed.workspaces === "object") {
3788
+ let modified = false;
3789
+ for (const key of Object.keys(parsed.workspaces)) {
3790
+ if (key === workspaceId || key.endsWith(`::${workspaceId}`)) {
3791
+ delete parsed.workspaces[key];
3792
+ modified = true;
3793
+ }
3794
+ }
3795
+ if (modified) {
3796
+ writeFileSync2(syncPath, JSON.stringify(parsed, null, 2), "utf8");
3797
+ }
3798
+ }
3799
+ } catch {
3800
+ }
3801
+ }
3429
3802
  function hasSkippedPathSegment(relPath) {
3430
3803
  const segments = toPosix(relPath).replace(/^\.\//, "").split("/");
3431
3804
  return segments.some((seg) => seg.length > 0 && SKIP_DIRS.has(seg));
@@ -3438,6 +3811,7 @@ function sanitizeManifest(manifest) {
3438
3811
  return {
3439
3812
  relativePath: toPosix(manifest.relativePath),
3440
3813
  contentSha256: manifest.contentSha256,
3814
+ schemaVersion: manifest.schemaVersion ?? CACHE_SCHEMA_VERSION,
3441
3815
  ...manifest.language !== void 0 ? { language: manifest.language } : {},
3442
3816
  ...manifest.mtimeMs !== void 0 ? { mtimeMs: manifest.mtimeMs } : {},
3443
3817
  ...manifest.size !== void 0 ? { size: manifest.size } : {},
@@ -3446,6 +3820,8 @@ function sanitizeManifest(manifest) {
3446
3820
  importedNames: [...imp.importedNames],
3447
3821
  isReExport: imp.isReExport,
3448
3822
  isTypeOnly: imp.isTypeOnly,
3823
+ ...imp.isDynamic === true ? { isDynamic: true } : {},
3824
+ ...typeof imp.verifiedAssetOnDisk === "boolean" ? { verifiedAssetOnDisk: imp.verifiedAssetOnDisk } : {},
3449
3825
  ...Array.isArray(imp.resolvedPaths) ? { resolvedPaths: imp.resolvedPaths.map((p) => toPosix(p)) } : {},
3450
3826
  ...imp.resolvedKind !== void 0 ? { resolvedKind: imp.resolvedKind } : {}
3451
3827
  })),
@@ -3518,6 +3894,7 @@ function scanWorkspaceManifests(rootDir, options = {}) {
3518
3894
  const cachePath = options.cachePath ?? path6.join(resolvedRoot, ".tipolink", "cache.json");
3519
3895
  const writeCache = options.writeCache ?? true;
3520
3896
  const cache = new JsonFileAstCache({ filePath: cachePath, autoSave: false });
3897
+ const schemaInvalidated = cache.schemaInvalidated;
3521
3898
  const priorManifests = cache.getAllWorkspaceManifests(workspaceId);
3522
3899
  const priorPaths = /* @__PURE__ */ new Set();
3523
3900
  let prunedSkippedEntries = false;
@@ -3534,7 +3911,7 @@ function scanWorkspaceManifests(rootDir, options = {}) {
3534
3911
  const deltaRelPaths = /* @__PURE__ */ new Set();
3535
3912
  let cacheHits = 0;
3536
3913
  let parsedCount = 0;
3537
- let cacheMutated = false;
3914
+ let cacheMutated = schemaInvalidated;
3538
3915
  for (const absPath of sourceFiles) {
3539
3916
  let realAbs;
3540
3917
  try {
@@ -3553,29 +3930,44 @@ function scanWorkspaceManifests(rootDir, options = {}) {
3553
3930
  }
3554
3931
  if (!stats.isFile()) continue;
3555
3932
  const statHit = cache.get(workspaceId, relPath, void 0, stats.mtimeMs, stats.size);
3556
- if (statHit) {
3933
+ if (statHit && statHit.schemaVersion === CACHE_SCHEMA_VERSION) {
3557
3934
  cacheHits += 1;
3558
- rawAllManifests.push(sanitizeManifest(statHit));
3935
+ const verified = verifyRelativeAssetsOnDisk(sanitizeManifest(statHit), realAbs);
3936
+ if (verified.changed) {
3937
+ cache.set(workspaceId, verified.manifest);
3938
+ cacheMutated = true;
3939
+ deltaRelPaths.add(relPath);
3940
+ }
3941
+ rawAllManifests.push(verified.manifest);
3559
3942
  continue;
3560
3943
  }
3561
3944
  const source = readFileSync4(realAbs, "utf8");
3562
3945
  const contentSha256 = sha256Text(source);
3563
3946
  const hashHit = cache.get(workspaceId, relPath, contentSha256);
3564
- if (hashHit) {
3947
+ if (hashHit && hashHit.schemaVersion === CACHE_SCHEMA_VERSION) {
3565
3948
  cacheHits += 1;
3566
- const refreshed = sanitizeManifest({
3567
- ...hashHit,
3568
- mtimeMs: stats.mtimeMs,
3569
- size: stats.size
3570
- });
3571
- cache.set(workspaceId, refreshed);
3949
+ const verified = verifyRelativeAssetsOnDisk(
3950
+ sanitizeManifest({
3951
+ ...hashHit,
3952
+ mtimeMs: stats.mtimeMs,
3953
+ size: stats.size
3954
+ }),
3955
+ realAbs
3956
+ );
3957
+ cache.set(workspaceId, verified.manifest);
3572
3958
  cacheMutated = true;
3573
- rawAllManifests.push(refreshed);
3959
+ if (verified.changed) {
3960
+ deltaRelPaths.add(relPath);
3961
+ }
3962
+ rawAllManifests.push(verified.manifest);
3574
3963
  continue;
3575
3964
  }
3576
- const extracted = sanitizeManifest(
3577
- defaultPolyglotRegistry.extractManifest(source, realAbs, relPath, stats.mtimeMs, stats.size)
3578
- );
3965
+ const extracted = verifyRelativeAssetsOnDisk(
3966
+ sanitizeManifest(
3967
+ defaultPolyglotRegistry.extractManifest(source, realAbs, relPath, stats.mtimeMs, stats.size)
3968
+ ),
3969
+ realAbs
3970
+ ).manifest;
3579
3971
  parsedCount += 1;
3580
3972
  cache.set(workspaceId, extracted);
3581
3973
  cacheMutated = true;
@@ -3597,22 +3989,27 @@ function scanWorkspaceManifests(rootDir, options = {}) {
3597
3989
  }
3598
3990
  if (writeCache && cacheMutated) {
3599
3991
  cache.flush();
3992
+ if (schemaInvalidated) {
3993
+ invalidateStaleCloudSyncFile(cachePath, workspaceId);
3994
+ }
3600
3995
  }
3601
3996
  const index = buildIndex(resolvedRoot, { workspaceId, cache });
3602
3997
  const allManifests = [];
3603
3998
  const manifestDelta = [];
3604
3999
  for (const file of index.files) {
3605
4000
  if (hasSkippedPathSegment(file.relative)) continue;
3606
- const sanitized = sanitizeManifest(file.manifest);
3607
- allManifests.push(sanitized);
4001
+ const verified = verifyRelativeAssetsOnDisk(sanitizeManifest(file.manifest), file.absolute).manifest;
4002
+ allManifests.push(verified);
3608
4003
  if (deltaRelPaths.has(file.relative)) {
3609
- manifestDelta.push(sanitized);
4004
+ manifestDelta.push(verified);
3610
4005
  }
3611
4006
  }
3612
4007
  return {
3613
4008
  workspaceId,
3614
4009
  rootDir: resolvedRoot,
3615
4010
  cachePath,
4011
+ schemaVersion: CACHE_SCHEMA_VERSION,
4012
+ schemaInvalidated,
3616
4013
  allManifests,
3617
4014
  manifestDelta,
3618
4015
  removedPaths,
@@ -3623,7 +4020,7 @@ function scanWorkspaceManifests(rootDir, options = {}) {
3623
4020
  }
3624
4021
 
3625
4022
  // src/init-installer.ts
3626
- import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync as writeFileSync2 } from "node:fs";
4023
+ import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "node:fs";
3627
4024
  import path7 from "node:path";
3628
4025
  var TIPOLINK_START_MARKER = "<!-- tipolink:start -->";
3629
4026
  var TIPOLINK_END_MARKER = "<!-- tipolink:end -->";
@@ -3634,7 +4031,7 @@ var DEFAULT_CLOUD_API_URL = "https://tipolink.co";
3634
4031
  var GITIGNORE_TIPOLINK_RE = /^\s*\/?\.tipolink\/?\s*$/;
3635
4032
  function ensureGitignoreIgnoresTipolink(rootDir, result) {
3636
4033
  const gitignorePath = path7.join(rootDir, ".gitignore");
3637
- if (!existsSync3(gitignorePath)) {
4034
+ if (!existsSync4(gitignorePath)) {
3638
4035
  return;
3639
4036
  }
3640
4037
  const existing = readFileSync5(gitignorePath, "utf8");
@@ -3653,7 +4050,7 @@ function ensureGitignoreIgnoresTipolink(rootDir, result) {
3653
4050
  } else {
3654
4051
  nextContent = `${existing}${eol}.tipolink/${eol}`;
3655
4052
  }
3656
- writeFileSync2(gitignorePath, nextContent, "utf8");
4053
+ writeFileSync3(gitignorePath, nextContent, "utf8");
3657
4054
  result.updated.push(".gitignore");
3658
4055
  }
3659
4056
  function normalizeRemoteMcpUrl(apiUrl) {
@@ -3668,7 +4065,7 @@ function isPlainRecord(value) {
3668
4065
  return typeof value === "object" && value !== null && !Array.isArray(value);
3669
4066
  }
3670
4067
  function readJsonRecord(filePath) {
3671
- if (!existsSync3(filePath)) {
4068
+ if (!existsSync4(filePath)) {
3672
4069
  return {};
3673
4070
  }
3674
4071
  const raw = readFileSync5(filePath, "utf8").trim();
@@ -3691,19 +4088,19 @@ function writeManagedFile(rootDir, relPath, content, result) {
3691
4088
  const absPath = path7.join(rootDir, relPath);
3692
4089
  const normalizedRel = relPath.split(path7.sep).join("/");
3693
4090
  result.files.push(normalizedRel);
3694
- if (existsSync3(absPath)) {
4091
+ if (existsSync4(absPath)) {
3695
4092
  const existing = readFileSync5(absPath, "utf8");
3696
4093
  if (existing === content) {
3697
4094
  result.unchanged.push(normalizedRel);
3698
4095
  return;
3699
4096
  }
3700
4097
  mkdirSync2(path7.dirname(absPath), { recursive: true });
3701
- writeFileSync2(absPath, content, "utf8");
4098
+ writeFileSync3(absPath, content, "utf8");
3702
4099
  result.updated.push(normalizedRel);
3703
4100
  return;
3704
4101
  }
3705
4102
  mkdirSync2(path7.dirname(absPath), { recursive: true });
3706
- writeFileSync2(absPath, content, "utf8");
4103
+ writeFileSync3(absPath, content, "utf8");
3707
4104
  result.created.push(normalizedRel);
3708
4105
  }
3709
4106
  function mergeMcpServersFile(filePath, entries) {
@@ -3777,7 +4174,7 @@ function upsertMarkdownSection(filePath, defaultHeading, sectionBody) {
3777
4174
  const wrappedBlock = `${TIPOLINK_START_MARKER}
3778
4175
  ${sectionBody.trim()}
3779
4176
  ${TIPOLINK_END_MARKER}`;
3780
- if (!existsSync3(filePath)) {
4177
+ if (!existsSync4(filePath)) {
3781
4178
  return `${defaultHeading}
3782
4179
 
3783
4180
  ${wrappedBlock}
@@ -3945,11 +4342,11 @@ function initWorkspaceConfigs(rootDir, options = {}) {
3945
4342
  }
3946
4343
 
3947
4344
  // src/mcp-stdio.ts
3948
- import { existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync3 } from "node:fs";
4345
+ import { existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync4 } from "node:fs";
3949
4346
  import path8 from "node:path";
3950
4347
  var DEFAULT_CLOUD_API_URL2 = "https://tipolink.co";
3951
4348
  var DEFAULT_PORTAL_URL = "https://tipolink.co";
3952
- var TIPOLINK_MCP_VERSION = "1.0.1";
4349
+ var TIPOLINK_MCP_VERSION = "1.0.2";
3953
4350
  var VALID_SYMBOL_KINDS = /* @__PURE__ */ new Set([
3954
4351
  "function",
3955
4352
  "const",
@@ -4086,11 +4483,13 @@ function cloudSyncStatePath(workspaceRoot) {
4086
4483
  }
4087
4484
  function loadCloudSyncHashes(workspaceRoot, stateKey) {
4088
4485
  const filePath = cloudSyncStatePath(workspaceRoot);
4089
- if (!existsSync4(filePath)) return null;
4486
+ if (!existsSync5(filePath)) return null;
4090
4487
  try {
4091
4488
  const raw = readFileSync6(filePath, "utf8");
4092
4489
  const parsed = JSON.parse(raw);
4093
- if (!parsed || typeof parsed !== "object" || !parsed.workspaces) return null;
4490
+ if (!parsed || typeof parsed !== "object" || parsed.manifestSchemaVersion !== CACHE_SCHEMA_VERSION || !parsed.workspaces) {
4491
+ return null;
4492
+ }
4094
4493
  const entry = parsed.workspaces[stateKey];
4095
4494
  return isRecord(entry) ? entry : null;
4096
4495
  } catch {
@@ -4099,32 +4498,41 @@ function loadCloudSyncHashes(workspaceRoot, stateKey) {
4099
4498
  }
4100
4499
  function saveCloudSyncHashes(workspaceRoot, stateKey, manifests) {
4101
4500
  const filePath = cloudSyncStatePath(workspaceRoot);
4102
- let store = { version: 1, workspaces: {} };
4103
- if (existsSync4(filePath)) {
4501
+ let store = {
4502
+ version: 1,
4503
+ manifestSchemaVersion: CACHE_SCHEMA_VERSION,
4504
+ workspaces: {}
4505
+ };
4506
+ if (existsSync5(filePath)) {
4104
4507
  try {
4105
4508
  const parsed = JSON.parse(readFileSync6(filePath, "utf8"));
4106
- if (parsed && typeof parsed === "object" && isRecord(parsed.workspaces)) {
4509
+ if (parsed && typeof parsed === "object" && parsed.manifestSchemaVersion === CACHE_SCHEMA_VERSION && isRecord(parsed.workspaces)) {
4107
4510
  store = {
4108
4511
  version: 1,
4512
+ manifestSchemaVersion: CACHE_SCHEMA_VERSION,
4109
4513
  workspaces: parsed.workspaces
4110
4514
  };
4111
4515
  }
4112
4516
  } catch {
4113
- store = { version: 1, workspaces: {} };
4517
+ store = {
4518
+ version: 1,
4519
+ manifestSchemaVersion: CACHE_SCHEMA_VERSION,
4520
+ workspaces: {}
4521
+ };
4114
4522
  }
4115
4523
  }
4116
4524
  const nextMap = {};
4117
4525
  for (const manifest of manifests) {
4118
- nextMap[manifest.relativePath] = manifest.contentSha256;
4526
+ nextMap[manifest.relativePath] = computeManifestSyncHash(manifest);
4119
4527
  }
4120
4528
  store.workspaces[stateKey] = nextMap;
4121
4529
  mkdirSync3(path8.dirname(filePath), { recursive: true });
4122
- writeFileSync3(filePath, JSON.stringify(store, null, 2), "utf8");
4530
+ writeFileSync4(filePath, JSON.stringify(store, null, 2), "utf8");
4123
4531
  }
4124
4532
  function computeCloudSyncDelta(scan, apiUrl) {
4125
4533
  const baseUrl = apiUrl.replace(/\/+$/, "");
4126
4534
  const stateKey = `${baseUrl}::${scan.workspaceId}`;
4127
- const priorHashes = loadCloudSyncHashes(scan.rootDir, stateKey);
4535
+ const priorHashes = scan.schemaInvalidated ? null : loadCloudSyncHashes(scan.rootDir, stateKey);
4128
4536
  if (!priorHashes) {
4129
4537
  return {
4130
4538
  delta: scan.allManifests,
@@ -4137,7 +4545,7 @@ function computeCloudSyncDelta(scan, apiUrl) {
4137
4545
  const delta = [];
4138
4546
  for (const manifest of scan.allManifests) {
4139
4547
  activePaths.add(manifest.relativePath);
4140
- if (priorHashes[manifest.relativePath] !== manifest.contentSha256) {
4548
+ if (priorHashes[manifest.relativePath] !== computeManifestSyncHash(manifest)) {
4141
4549
  delta.push(manifest);
4142
4550
  }
4143
4551
  }
@@ -4699,7 +5107,7 @@ async function startStdioMcpServer(options = {}) {
4699
5107
 
4700
5108
  // src/cli.ts
4701
5109
  import { execFileSync } from "node:child_process";
4702
- import { existsSync as existsSync5, realpathSync as realpathSync3 } from "node:fs";
5110
+ import { existsSync as existsSync6, realpathSync as realpathSync3 } from "node:fs";
4703
5111
  import path9 from "node:path";
4704
5112
  import { fileURLToPath } from "node:url";
4705
5113
  var VALUE_FLAGS = /* @__PURE__ */ new Set(["dir", "api-url", "api-key", "kind", "from", "depth"]);
@@ -4872,7 +5280,7 @@ function collectStagedOrModifiedSources(rootDir, hookTargetFile) {
4872
5280
  let hasAnyNonSourceHookTarget = false;
4873
5281
  const addIfSource = (rawFile) => {
4874
5282
  const abs = path9.isAbsolute(rawFile) ? path9.resolve(rawFile) : path9.resolve(rootDir, rawFile);
4875
- if (!existsSync5(abs)) return;
5283
+ if (!existsSync6(abs)) return;
4876
5284
  const ext = path9.extname(abs).toLowerCase();
4877
5285
  if (!SOURCE_EXTENSIONS.has(ext)) {
4878
5286
  if (hookTargetFile && rawFile === hookTargetFile) {
@@ -5121,11 +5529,13 @@ if (isDirectEntrypoint()) {
5121
5529
  );
5122
5530
  }
5123
5531
  export {
5532
+ CACHE_SCHEMA_VERSION,
5124
5533
  DEFAULT_CLOUD_API_URL2 as DEFAULT_CLOUD_API_URL,
5125
5534
  DEFAULT_PORTAL_URL,
5126
5535
  JsonRpcStreamParser,
5127
5536
  TIPOLINK_MCP_TOOLS,
5128
5537
  TIPOLINK_MCP_VERSION,
5538
+ computeManifestSyncHash,
5129
5539
  createMcpDispatcher,
5130
5540
  deriveWorkspaceId,
5131
5541
  encodeJsonRpcFrame,