@tipolink/mcp 1.0.0 → 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 +644 -200
- package/dist/extractor.d.ts +10 -1
- package/dist/extractor.js +584 -185
- package/dist/index.d.ts +2 -2
- package/dist/index.js +653 -206
- package/dist/init-installer.js +26 -0
- package/dist/mcp-stdio.d.ts +1 -0
- package/dist/mcp-stdio.js +607 -197
- package/package.json +1 -1
package/dist/mcp-stdio.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
// src/mcp-stdio.ts
|
|
2
|
-
import { existsSync as
|
|
2
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "node:fs";
|
|
3
3
|
import path7 from "node:path";
|
|
4
4
|
|
|
5
5
|
// ../engine/src/ast-extractor.ts
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
|
-
import
|
|
7
|
+
import path3 from "node:path";
|
|
8
8
|
import ts from "typescript";
|
|
9
9
|
|
|
10
|
+
// ../engine/src/cache.ts
|
|
11
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
12
|
+
import path2 from "node:path";
|
|
13
|
+
|
|
10
14
|
// ../engine/src/paths.ts
|
|
11
15
|
import path from "node:path";
|
|
12
16
|
function compareText(a, b) {
|
|
@@ -45,9 +49,143 @@ function computeRelativeImportSpec(fromRelPath, toRelPath) {
|
|
|
45
49
|
return rel;
|
|
46
50
|
}
|
|
47
51
|
|
|
52
|
+
// ../engine/src/cache.ts
|
|
53
|
+
var CACHE_SCHEMA_VERSION = "1.0.2";
|
|
54
|
+
function cacheEntryMatches(entry, contentSha256, mtimeMs, size) {
|
|
55
|
+
if (contentSha256 !== void 0) {
|
|
56
|
+
return entry.contentSha256 === contentSha256;
|
|
57
|
+
}
|
|
58
|
+
if (mtimeMs !== void 0 || size !== void 0) {
|
|
59
|
+
if (mtimeMs !== void 0 && entry.mtimeMs !== mtimeMs) return false;
|
|
60
|
+
if (size !== void 0 && entry.size !== size) return false;
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
var JsonFileAstCache = class {
|
|
66
|
+
filePath;
|
|
67
|
+
schemaInvalidated = false;
|
|
68
|
+
autoSave;
|
|
69
|
+
workspaces = /* @__PURE__ */ new Map();
|
|
70
|
+
dirty = false;
|
|
71
|
+
constructor(filePathOrOptions) {
|
|
72
|
+
if (typeof filePathOrOptions === "string") {
|
|
73
|
+
this.filePath = filePathOrOptions;
|
|
74
|
+
this.autoSave = true;
|
|
75
|
+
} else {
|
|
76
|
+
this.filePath = filePathOrOptions.filePath;
|
|
77
|
+
this.autoSave = filePathOrOptions.autoSave ?? true;
|
|
78
|
+
}
|
|
79
|
+
this.loadFromDisk();
|
|
80
|
+
}
|
|
81
|
+
loadFromDisk() {
|
|
82
|
+
if (!existsSync(this.filePath)) return;
|
|
83
|
+
try {
|
|
84
|
+
const raw = readFileSync(this.filePath, "utf8");
|
|
85
|
+
if (!raw.trim()) return;
|
|
86
|
+
const parsed = JSON.parse(raw);
|
|
87
|
+
if (!parsed || typeof parsed !== "object" || !parsed.workspaces || typeof parsed.workspaces !== "object") {
|
|
88
|
+
this.schemaInvalidated = true;
|
|
89
|
+
this.dirty = true;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (parsed.manifestSchemaVersion !== CACHE_SCHEMA_VERSION) {
|
|
93
|
+
this.workspaces.clear();
|
|
94
|
+
this.schemaInvalidated = true;
|
|
95
|
+
this.dirty = true;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
for (const [workspaceId, files] of Object.entries(parsed.workspaces)) {
|
|
99
|
+
if (!files || typeof files !== "object") continue;
|
|
100
|
+
const map = /* @__PURE__ */ new Map();
|
|
101
|
+
for (const [relPath, manifest] of Object.entries(files)) {
|
|
102
|
+
if (manifest && typeof manifest === "object" && typeof manifest.contentSha256 === "string") {
|
|
103
|
+
const norm = toPosix(relPath);
|
|
104
|
+
map.set(norm, { ...manifest, relativePath: norm });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
this.workspaces.set(workspaceId, map);
|
|
108
|
+
}
|
|
109
|
+
} catch {
|
|
110
|
+
this.workspaces.clear();
|
|
111
|
+
this.schemaInvalidated = true;
|
|
112
|
+
this.dirty = true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
get(workspaceId, relativePath, contentSha256, mtimeMs, size) {
|
|
116
|
+
const wsMap = this.workspaces.get(workspaceId);
|
|
117
|
+
if (!wsMap) return void 0;
|
|
118
|
+
const hit = wsMap.get(toPosix(relativePath));
|
|
119
|
+
if (!hit) return void 0;
|
|
120
|
+
return cacheEntryMatches(hit, contentSha256, mtimeMs, size) ? hit : void 0;
|
|
121
|
+
}
|
|
122
|
+
set(workspaceId, manifest) {
|
|
123
|
+
const norm = toPosix(manifest.relativePath);
|
|
124
|
+
const normalized = {
|
|
125
|
+
...manifest,
|
|
126
|
+
relativePath: norm
|
|
127
|
+
};
|
|
128
|
+
let wsMap = this.workspaces.get(workspaceId);
|
|
129
|
+
if (!wsMap) {
|
|
130
|
+
wsMap = /* @__PURE__ */ new Map();
|
|
131
|
+
this.workspaces.set(workspaceId, wsMap);
|
|
132
|
+
}
|
|
133
|
+
wsMap.set(norm, normalized);
|
|
134
|
+
this.dirty = true;
|
|
135
|
+
if (this.autoSave) {
|
|
136
|
+
this.save();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
getAllWorkspaceManifests(workspaceId) {
|
|
140
|
+
const wsMap = this.workspaces.get(workspaceId);
|
|
141
|
+
if (!wsMap) return [];
|
|
142
|
+
return [...wsMap.values()];
|
|
143
|
+
}
|
|
144
|
+
clear(workspaceId) {
|
|
145
|
+
if (workspaceId === void 0) {
|
|
146
|
+
this.workspaces.clear();
|
|
147
|
+
} else {
|
|
148
|
+
this.workspaces.delete(workspaceId);
|
|
149
|
+
}
|
|
150
|
+
this.dirty = true;
|
|
151
|
+
if (this.autoSave) {
|
|
152
|
+
this.save();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
save() {
|
|
156
|
+
if (!this.dirty && existsSync(this.filePath)) return;
|
|
157
|
+
const payload = {
|
|
158
|
+
version: 1,
|
|
159
|
+
manifestSchemaVersion: CACHE_SCHEMA_VERSION,
|
|
160
|
+
workspaces: {}
|
|
161
|
+
};
|
|
162
|
+
for (const [workspaceId, wsMap] of this.workspaces.entries()) {
|
|
163
|
+
const obj = {};
|
|
164
|
+
for (const [relPath, manifest] of wsMap.entries()) {
|
|
165
|
+
obj[relPath] = manifest;
|
|
166
|
+
}
|
|
167
|
+
payload.workspaces[workspaceId] = obj;
|
|
168
|
+
}
|
|
169
|
+
const dir = path2.dirname(this.filePath);
|
|
170
|
+
mkdirSync(dir, { recursive: true });
|
|
171
|
+
const serialized = JSON.stringify(payload, null, 2);
|
|
172
|
+
const tmpPath = `${this.filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
173
|
+
try {
|
|
174
|
+
writeFileSync(tmpPath, serialized, "utf8");
|
|
175
|
+
renameSync(tmpPath, this.filePath);
|
|
176
|
+
} catch {
|
|
177
|
+
writeFileSync(this.filePath, serialized, "utf8");
|
|
178
|
+
}
|
|
179
|
+
this.dirty = false;
|
|
180
|
+
}
|
|
181
|
+
flush() {
|
|
182
|
+
this.save();
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
48
186
|
// ../engine/src/ast-extractor.ts
|
|
49
187
|
function scriptKindFor(filePath) {
|
|
50
|
-
switch (
|
|
188
|
+
switch (path3.extname(filePath).toLowerCase()) {
|
|
51
189
|
case ".tsx":
|
|
52
190
|
return ts.ScriptKind.TSX;
|
|
53
191
|
case ".jsx":
|
|
@@ -61,7 +199,7 @@ function scriptKindFor(filePath) {
|
|
|
61
199
|
}
|
|
62
200
|
}
|
|
63
201
|
function jsTsLanguageFor(filePath) {
|
|
64
|
-
switch (
|
|
202
|
+
switch (path3.extname(filePath).toLowerCase()) {
|
|
65
203
|
case ".js":
|
|
66
204
|
case ".jsx":
|
|
67
205
|
case ".mjs":
|
|
@@ -86,19 +224,123 @@ function hasModifier(node, kind) {
|
|
|
86
224
|
function isFunctionLikeNode(node) {
|
|
87
225
|
return ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node) || ts.isMethodDeclaration(node);
|
|
88
226
|
}
|
|
89
|
-
function
|
|
227
|
+
function collectBindingNames(binding, out) {
|
|
228
|
+
if (ts.isIdentifier(binding)) {
|
|
229
|
+
out.add(binding.text);
|
|
230
|
+
} else if (ts.isObjectBindingPattern(binding) || ts.isArrayBindingPattern(binding)) {
|
|
231
|
+
for (const elem of binding.elements) {
|
|
232
|
+
if (ts.isBindingElement(elem)) {
|
|
233
|
+
collectBindingNames(elem.name, out);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function collectFunctionScopeBindings(fn, out) {
|
|
239
|
+
if (fn.name && ts.isIdentifier(fn.name)) {
|
|
240
|
+
out.add(fn.name.text);
|
|
241
|
+
}
|
|
242
|
+
if (fn.typeParameters) {
|
|
243
|
+
for (const tp of fn.typeParameters) {
|
|
244
|
+
out.add(tp.name.text);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
for (const param of fn.parameters) {
|
|
248
|
+
collectBindingNames(param.name, out);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function collectHoistedVarDeclarations(node, out) {
|
|
252
|
+
const walk = (curr) => {
|
|
253
|
+
if (isFunctionLikeNode(curr)) return;
|
|
254
|
+
if (ts.isVariableDeclarationList(curr)) {
|
|
255
|
+
const isBlockScoped = (curr.flags & (ts.NodeFlags.Const | ts.NodeFlags.Let)) !== 0;
|
|
256
|
+
if (!isBlockScoped) {
|
|
257
|
+
for (const decl of curr.declarations) {
|
|
258
|
+
collectBindingNames(decl.name, out);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
ts.forEachChild(curr, walk);
|
|
263
|
+
};
|
|
264
|
+
ts.forEachChild(node, walk);
|
|
265
|
+
}
|
|
266
|
+
function collectDirectStatementLocals(statements, out) {
|
|
267
|
+
for (const stmt of statements) {
|
|
268
|
+
if (ts.isVariableStatement(stmt)) {
|
|
269
|
+
for (const decl of stmt.declarationList.declarations) {
|
|
270
|
+
collectBindingNames(decl.name, out);
|
|
271
|
+
}
|
|
272
|
+
} else if (ts.isFunctionDeclaration(stmt) && stmt.name) {
|
|
273
|
+
out.add(stmt.name.text);
|
|
274
|
+
} else if (ts.isClassDeclaration(stmt) && stmt.name) {
|
|
275
|
+
out.add(stmt.name.text);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function classifyIdentifierRole(curr, parent) {
|
|
280
|
+
if (!parent) return "variable";
|
|
281
|
+
if (ts.isPropertyAccessExpression(parent) && parent.name === curr) return "property";
|
|
282
|
+
if (ts.isQualifiedName(parent) && parent.right === curr) return "property";
|
|
283
|
+
if (ts.isBindingElement(parent) && parent.propertyName === curr) return "object_key";
|
|
284
|
+
if (ts.isPropertyAssignment(parent) && parent.name === curr) return "object_key";
|
|
285
|
+
if (ts.isPropertySignature(parent) && parent.name === curr) return "object_key";
|
|
286
|
+
if (ts.isMethodDeclaration(parent) && parent.name === curr) return "object_key";
|
|
287
|
+
if (ts.isMethodSignature(parent) && parent.name === curr) return "object_key";
|
|
288
|
+
if (ts.isGetAccessorDeclaration(parent) && parent.name === curr) return "object_key";
|
|
289
|
+
if (ts.isSetAccessorDeclaration(parent) && parent.name === curr) return "object_key";
|
|
290
|
+
if (ts.isPropertyDeclaration(parent) && parent.name === curr) return "object_key";
|
|
291
|
+
if (ts.isJsxAttribute(parent) && parent.name === curr) return "object_key";
|
|
292
|
+
if ((ts.isLabeledStatement(parent) || ts.isBreakStatement(parent) || ts.isContinueStatement(parent)) && parent.label === curr) {
|
|
293
|
+
return "property";
|
|
294
|
+
}
|
|
295
|
+
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) {
|
|
296
|
+
return "declaration";
|
|
297
|
+
}
|
|
298
|
+
return "variable";
|
|
299
|
+
}
|
|
300
|
+
function collectModuleLocalDeclarations(sourceFile) {
|
|
301
|
+
const decls = /* @__PURE__ */ new Set();
|
|
302
|
+
for (const stmt of sourceFile.statements) {
|
|
303
|
+
if (ts.isVariableStatement(stmt)) {
|
|
304
|
+
for (const decl of stmt.declarationList.declarations) {
|
|
305
|
+
collectBindingNames(decl.name, decls);
|
|
306
|
+
}
|
|
307
|
+
} else if (ts.isFunctionDeclaration(stmt) && stmt.name) {
|
|
308
|
+
decls.add(stmt.name.text);
|
|
309
|
+
} else if (ts.isClassDeclaration(stmt) && stmt.name) {
|
|
310
|
+
decls.add(stmt.name.text);
|
|
311
|
+
} else if (ts.isEnumDeclaration(stmt)) {
|
|
312
|
+
decls.add(stmt.name.text);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return decls;
|
|
316
|
+
}
|
|
317
|
+
function computeStructuralHashWithCount(node, sourceFile, options) {
|
|
90
318
|
const target = ts.isVariableDeclaration(node) && node.initializer && (ts.isArrowFunction(node.initializer) || ts.isFunctionExpression(node.initializer)) ? node.initializer : node;
|
|
319
|
+
const normalizedFilePath = normalizeRelPath(options?.filePath ?? sourceFile.fileName);
|
|
320
|
+
const moduleLocalDecls = options?.moduleLocalDecls ?? collectModuleLocalDeclarations(sourceFile);
|
|
91
321
|
const tokens = [];
|
|
92
322
|
let nodeCount = 0;
|
|
93
323
|
let astNodeCount = 0;
|
|
94
|
-
const visit = (curr, countAsBody) => {
|
|
324
|
+
const visit = (curr, countAsBody, scope, parent) => {
|
|
95
325
|
nodeCount += 1;
|
|
96
326
|
if (countAsBody) {
|
|
97
327
|
astNodeCount += 1;
|
|
98
328
|
}
|
|
99
329
|
tokens.push(`K:${curr.kind}`);
|
|
330
|
+
let childScope = scope;
|
|
100
331
|
if (ts.isPropertyAccessExpression(curr)) {
|
|
101
|
-
tokens.push(`PROP
|
|
332
|
+
tokens.push(`PROP:${curr.name.text}`);
|
|
333
|
+
} else if (ts.isStringLiteral(curr) || ts.isNoSubstitutionTemplateLiteral(curr)) {
|
|
334
|
+
tokens.push(`STR:${curr.text}`);
|
|
335
|
+
} else if (ts.isTemplateExpression(curr)) {
|
|
336
|
+
tokens.push(`TPL_H:${curr.head.text}`);
|
|
337
|
+
for (const span of curr.templateSpans) {
|
|
338
|
+
tokens.push(`TPL_M:${span.literal.text}`);
|
|
339
|
+
}
|
|
340
|
+
} else if (ts.isNumericLiteral(curr)) {
|
|
341
|
+
tokens.push(`NUM:${curr.text}`);
|
|
342
|
+
} else if (ts.isRegularExpressionLiteral(curr)) {
|
|
343
|
+
tokens.push(`REGEX:${curr.text}`);
|
|
102
344
|
} else if (ts.isBinaryExpression(curr)) {
|
|
103
345
|
tokens.push(`OP:${curr.operatorToken.kind}`);
|
|
104
346
|
} else if (ts.isPrefixUnaryExpression(curr)) {
|
|
@@ -108,10 +350,61 @@ function computeStructuralHashWithCount(node, sourceFile) {
|
|
|
108
350
|
} else if (ts.isVariableDeclarationList(curr)) {
|
|
109
351
|
const declFlag = curr.flags & (ts.NodeFlags.Const | ts.NodeFlags.Let);
|
|
110
352
|
tokens.push(`VF:${declFlag}`);
|
|
353
|
+
} else if (ts.isIdentifier(curr)) {
|
|
354
|
+
const role = classifyIdentifierRole(curr, parent);
|
|
355
|
+
if (role === "declaration") {
|
|
356
|
+
tokens.push("ID:$L");
|
|
357
|
+
} else if (role === "object_key") {
|
|
358
|
+
tokens.push(`KEY:${curr.text}`);
|
|
359
|
+
} else if (role === "variable") {
|
|
360
|
+
if (scope.has(curr.text)) {
|
|
361
|
+
tokens.push("ID:$L");
|
|
362
|
+
} else if (moduleLocalDecls.has(curr.text)) {
|
|
363
|
+
tokens.push(`STATE:${normalizedFilePath}:${curr.text}`);
|
|
364
|
+
} else {
|
|
365
|
+
tokens.push(`EXT:${curr.text}`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
if (curr !== target && isFunctionLikeNode(curr)) {
|
|
370
|
+
const next = new Set(scope);
|
|
371
|
+
collectFunctionScopeBindings(curr, next);
|
|
372
|
+
if (curr.body) {
|
|
373
|
+
collectHoistedVarDeclarations(curr.body, next);
|
|
374
|
+
}
|
|
375
|
+
childScope = next;
|
|
376
|
+
} else if (ts.isBlock(curr)) {
|
|
377
|
+
const next = new Set(scope);
|
|
378
|
+
collectDirectStatementLocals(curr.statements, next);
|
|
379
|
+
childScope = next;
|
|
380
|
+
} else if (ts.isCaseClause(curr) || ts.isDefaultClause(curr)) {
|
|
381
|
+
const next = new Set(scope);
|
|
382
|
+
collectDirectStatementLocals(curr.statements, next);
|
|
383
|
+
childScope = next;
|
|
384
|
+
} else if (ts.isForStatement(curr) || ts.isForInStatement(curr) || ts.isForOfStatement(curr)) {
|
|
385
|
+
if (curr.initializer && ts.isVariableDeclarationList(curr.initializer)) {
|
|
386
|
+
const next = new Set(scope);
|
|
387
|
+
for (const decl of curr.initializer.declarations) {
|
|
388
|
+
collectBindingNames(decl.name, next);
|
|
389
|
+
}
|
|
390
|
+
childScope = next;
|
|
391
|
+
}
|
|
392
|
+
} else if (ts.isCatchClause(curr) && curr.variableDeclaration) {
|
|
393
|
+
const next = new Set(scope);
|
|
394
|
+
collectBindingNames(curr.variableDeclaration.name, next);
|
|
395
|
+
childScope = next;
|
|
111
396
|
}
|
|
112
|
-
ts.forEachChild(curr, (child) => visit(child, countAsBody));
|
|
397
|
+
ts.forEachChild(curr, (child) => visit(child, countAsBody, childScope, curr));
|
|
113
398
|
};
|
|
114
399
|
if (isFunctionLikeNode(target)) {
|
|
400
|
+
const rootScope = /* @__PURE__ */ new Set();
|
|
401
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name)) {
|
|
402
|
+
rootScope.add(node.name.text);
|
|
403
|
+
}
|
|
404
|
+
collectFunctionScopeBindings(target, rootScope);
|
|
405
|
+
if (target.body) {
|
|
406
|
+
collectHoistedVarDeclarations(target.body, rootScope);
|
|
407
|
+
}
|
|
115
408
|
tokens.push("FN");
|
|
116
409
|
if (hasModifier(target, ts.SyntaxKind.AsyncKeyword)) {
|
|
117
410
|
tokens.push("MOD:ASYNC");
|
|
@@ -120,14 +413,13 @@ function computeStructuralHashWithCount(node, sourceFile) {
|
|
|
120
413
|
tokens.push("MOD:GEN");
|
|
121
414
|
}
|
|
122
415
|
for (const param of target.parameters) {
|
|
123
|
-
visit(param, false);
|
|
416
|
+
visit(param, false, rootScope, target);
|
|
124
417
|
}
|
|
125
418
|
if (target.body) {
|
|
126
|
-
visit(target.body, true);
|
|
419
|
+
visit(target.body, true, rootScope, target);
|
|
127
420
|
}
|
|
128
421
|
} else {
|
|
129
|
-
void
|
|
130
|
-
visit(target, true);
|
|
422
|
+
visit(target, true, /* @__PURE__ */ new Set(), void 0);
|
|
131
423
|
}
|
|
132
424
|
const structuralHash = createHash("sha256").update(tokens.join("|"), "utf8").digest("hex").slice(0, 16);
|
|
133
425
|
return { structuralHash, nodeCount, astNodeCount };
|
|
@@ -161,7 +453,7 @@ function formatConstSummary(decl, sourceFile) {
|
|
|
161
453
|
}
|
|
162
454
|
if (ts.isObjectLiteralExpression(init)) {
|
|
163
455
|
const keys = init.properties.slice(0, 5).map((prop) => {
|
|
164
|
-
if (ts.isPropertyAssignment(prop) || ts.isShorthandPropertyAssignment(prop)) {
|
|
456
|
+
if (ts.isPropertyAssignment(prop) || ts.isShorthandPropertyAssignment(prop) || ts.isMethodDeclaration(prop)) {
|
|
165
457
|
return prop.name.getText(sourceFile);
|
|
166
458
|
}
|
|
167
459
|
return "...";
|
|
@@ -202,10 +494,10 @@ function formatEnumSignature(node, sourceFile) {
|
|
|
202
494
|
function lineNumberOf(node, sourceFile) {
|
|
203
495
|
return sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;
|
|
204
496
|
}
|
|
205
|
-
function pushImportRef(refs, keyMap, rawSpecifier, importedNames, isReExport, isTypeOnly) {
|
|
497
|
+
function pushImportRef(refs, keyMap, rawSpecifier, importedNames, isReExport, isTypeOnly, isDynamic = false) {
|
|
206
498
|
const trimmed = rawSpecifier.trim();
|
|
207
499
|
if (!trimmed) return;
|
|
208
|
-
const dedupKey = `${trimmed}\0${isReExport ? "1" : "0"}\0${isTypeOnly ? "1" : "0"}`;
|
|
500
|
+
const dedupKey = `${trimmed}\0${isReExport ? "1" : "0"}\0${isTypeOnly ? "1" : "0"}\0${isDynamic ? "1" : "0"}`;
|
|
209
501
|
const existing = keyMap.get(dedupKey);
|
|
210
502
|
if (existing) {
|
|
211
503
|
for (const name of importedNames) {
|
|
@@ -219,7 +511,8 @@ function pushImportRef(refs, keyMap, rawSpecifier, importedNames, isReExport, is
|
|
|
219
511
|
rawSpecifier: trimmed,
|
|
220
512
|
importedNames: [...new Set(importedNames)],
|
|
221
513
|
isReExport,
|
|
222
|
-
isTypeOnly
|
|
514
|
+
isTypeOnly,
|
|
515
|
+
...isDynamic ? { isDynamic: true } : {}
|
|
223
516
|
};
|
|
224
517
|
keyMap.set(dedupKey, entry);
|
|
225
518
|
refs.push(entry);
|
|
@@ -232,7 +525,10 @@ function extractImports(sourceFile) {
|
|
|
232
525
|
if (ts.isStringLiteral(node.moduleSpecifier)) {
|
|
233
526
|
const names = [];
|
|
234
527
|
const clause = node.importClause;
|
|
235
|
-
const
|
|
528
|
+
const allNamedTypeOnly = Boolean(
|
|
529
|
+
clause && !clause.name && clause.namedBindings && ts.isNamedImports(clause.namedBindings) && clause.namedBindings.elements.length > 0 && clause.namedBindings.elements.every((elem) => elem.isTypeOnly)
|
|
530
|
+
);
|
|
531
|
+
const isTypeOnly = Boolean(clause?.isTypeOnly) || allNamedTypeOnly;
|
|
236
532
|
if (clause) {
|
|
237
533
|
if (clause.name) names.push("default");
|
|
238
534
|
if (clause.namedBindings) {
|
|
@@ -245,13 +541,19 @@ function extractImports(sourceFile) {
|
|
|
245
541
|
}
|
|
246
542
|
}
|
|
247
543
|
}
|
|
248
|
-
pushImportRef(refs, keyMap, node.moduleSpecifier.text, names, false, isTypeOnly);
|
|
544
|
+
pushImportRef(refs, keyMap, node.moduleSpecifier.text, names, false, isTypeOnly, false);
|
|
249
545
|
}
|
|
250
546
|
} else if (ts.isExportDeclaration(node)) {
|
|
251
547
|
if (node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
252
548
|
const names = [];
|
|
549
|
+
const allNamedTypeOnly = Boolean(
|
|
550
|
+
node.exportClause && ts.isNamedExports(node.exportClause) && node.exportClause.elements.length > 0 && node.exportClause.elements.every((elem) => elem.isTypeOnly)
|
|
551
|
+
);
|
|
552
|
+
const isTypeOnly = Boolean(node.isTypeOnly) || allNamedTypeOnly;
|
|
253
553
|
if (!node.exportClause) {
|
|
254
|
-
|
|
554
|
+
if (!isTypeOnly) {
|
|
555
|
+
names.push("*");
|
|
556
|
+
}
|
|
255
557
|
} else if (ts.isNamespaceExport(node.exportClause)) {
|
|
256
558
|
names.push("*");
|
|
257
559
|
} else if (ts.isNamedExports(node.exportClause)) {
|
|
@@ -259,27 +561,27 @@ function extractImports(sourceFile) {
|
|
|
259
561
|
names.push((elem.propertyName ?? elem.name).text);
|
|
260
562
|
}
|
|
261
563
|
}
|
|
262
|
-
pushImportRef(refs, keyMap, node.moduleSpecifier.text, names, true,
|
|
564
|
+
pushImportRef(refs, keyMap, node.moduleSpecifier.text, names, true, isTypeOnly, false);
|
|
263
565
|
}
|
|
264
566
|
} else if (ts.isImportEqualsDeclaration(node)) {
|
|
265
567
|
if (ts.isExternalModuleReference(node.moduleReference) && ts.isStringLiteral(node.moduleReference.expression)) {
|
|
266
|
-
pushImportRef(refs, keyMap, node.moduleReference.expression.text, [node.name.text], false, false);
|
|
568
|
+
pushImportRef(refs, keyMap, node.moduleReference.expression.text, [node.name.text], false, false, false);
|
|
267
569
|
}
|
|
268
570
|
} else if (ts.isCallExpression(node)) {
|
|
269
571
|
const first = node.arguments[0];
|
|
270
572
|
if (first && ts.isStringLiteralLike(first)) {
|
|
271
573
|
const callee = node.expression;
|
|
272
574
|
if (callee.kind === ts.SyntaxKind.ImportKeyword) {
|
|
273
|
-
pushImportRef(refs, keyMap, first.text, [], false, false);
|
|
575
|
+
pushImportRef(refs, keyMap, first.text, [], false, false, true);
|
|
274
576
|
} else if (ts.isIdentifier(callee) && callee.text === "require") {
|
|
275
|
-
pushImportRef(refs, keyMap, first.text, [], false, false);
|
|
577
|
+
pushImportRef(refs, keyMap, first.text, [], false, false, false);
|
|
276
578
|
}
|
|
277
579
|
}
|
|
278
580
|
} else if (ts.isImportTypeNode(node)) {
|
|
279
581
|
const argument = node.argument;
|
|
280
582
|
if (ts.isLiteralTypeNode(argument) && ts.isStringLiteral(argument.literal)) {
|
|
281
583
|
const names = node.qualifier ? [collapseWhitespace(node.qualifier.getText(sourceFile))] : [];
|
|
282
|
-
pushImportRef(refs, keyMap, argument.literal.text, names, false, true);
|
|
584
|
+
pushImportRef(refs, keyMap, argument.literal.text, names, false, true, false);
|
|
283
585
|
}
|
|
284
586
|
}
|
|
285
587
|
ts.forEachChild(node, visit);
|
|
@@ -298,6 +600,8 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
|
|
|
298
600
|
scriptKindFor(absolutePath)
|
|
299
601
|
);
|
|
300
602
|
const imports = extractImports(sourceFile);
|
|
603
|
+
const moduleLocalDecls = collectModuleLocalDeclarations(sourceFile);
|
|
604
|
+
const hashOptions = { filePath: rel, moduleLocalDecls };
|
|
301
605
|
const localDecls = /* @__PURE__ */ new Map();
|
|
302
606
|
const exportedSymbols = [];
|
|
303
607
|
const internalFunctions = [];
|
|
@@ -315,7 +619,11 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
|
|
|
315
619
|
if (ts.isFunctionDeclaration(stmt)) {
|
|
316
620
|
if (!stmt.body) continue;
|
|
317
621
|
const declName = stmt.name?.text;
|
|
318
|
-
const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
|
|
622
|
+
const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
|
|
623
|
+
stmt,
|
|
624
|
+
sourceFile,
|
|
625
|
+
hashOptions
|
|
626
|
+
);
|
|
319
627
|
const signature = formatFunctionSignature(stmt, sourceFile);
|
|
320
628
|
const line = lineNumberOf(stmt, sourceFile);
|
|
321
629
|
if (declName) {
|
|
@@ -357,7 +665,11 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
|
|
|
357
665
|
const line = lineNumberOf(decl, sourceFile);
|
|
358
666
|
const init = decl.initializer;
|
|
359
667
|
if (init && (ts.isArrowFunction(init) || ts.isFunctionExpression(init))) {
|
|
360
|
-
const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
|
|
668
|
+
const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
|
|
669
|
+
decl,
|
|
670
|
+
sourceFile,
|
|
671
|
+
hashOptions
|
|
672
|
+
);
|
|
361
673
|
const signature = formatFunctionSignature(init, sourceFile);
|
|
362
674
|
localDecls.set(declName, {
|
|
363
675
|
name: declName,
|
|
@@ -595,7 +907,11 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
|
|
|
595
907
|
});
|
|
596
908
|
}
|
|
597
909
|
} else if (ts.isArrowFunction(stmt.expression) || ts.isFunctionExpression(stmt.expression)) {
|
|
598
|
-
const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
|
|
910
|
+
const { structuralHash, nodeCount, astNodeCount } = computeStructuralHashWithCount(
|
|
911
|
+
stmt.expression,
|
|
912
|
+
sourceFile,
|
|
913
|
+
hashOptions
|
|
914
|
+
);
|
|
599
915
|
addExported({
|
|
600
916
|
name: "default",
|
|
601
917
|
kind: "function",
|
|
@@ -638,6 +954,7 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
|
|
|
638
954
|
return {
|
|
639
955
|
relativePath: rel,
|
|
640
956
|
contentSha256,
|
|
957
|
+
schemaVersion: CACHE_SCHEMA_VERSION,
|
|
641
958
|
language: jsTsLanguageFor(absolutePath),
|
|
642
959
|
...mtimeMs !== void 0 ? { mtimeMs } : {},
|
|
643
960
|
...size !== void 0 ? { size } : {},
|
|
@@ -647,129 +964,6 @@ function extractFileAstManifest(source, absolutePath, relativePath, mtimeMs, siz
|
|
|
647
964
|
};
|
|
648
965
|
}
|
|
649
966
|
|
|
650
|
-
// ../engine/src/cache.ts
|
|
651
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
652
|
-
import path3 from "node:path";
|
|
653
|
-
function cacheEntryMatches(entry, contentSha256, mtimeMs, size) {
|
|
654
|
-
if (contentSha256 !== void 0) {
|
|
655
|
-
return entry.contentSha256 === contentSha256;
|
|
656
|
-
}
|
|
657
|
-
if (mtimeMs !== void 0 || size !== void 0) {
|
|
658
|
-
if (mtimeMs !== void 0 && entry.mtimeMs !== mtimeMs) return false;
|
|
659
|
-
if (size !== void 0 && entry.size !== size) return false;
|
|
660
|
-
return true;
|
|
661
|
-
}
|
|
662
|
-
return true;
|
|
663
|
-
}
|
|
664
|
-
var JsonFileAstCache = class {
|
|
665
|
-
filePath;
|
|
666
|
-
autoSave;
|
|
667
|
-
workspaces = /* @__PURE__ */ new Map();
|
|
668
|
-
dirty = false;
|
|
669
|
-
constructor(filePathOrOptions) {
|
|
670
|
-
if (typeof filePathOrOptions === "string") {
|
|
671
|
-
this.filePath = filePathOrOptions;
|
|
672
|
-
this.autoSave = true;
|
|
673
|
-
} else {
|
|
674
|
-
this.filePath = filePathOrOptions.filePath;
|
|
675
|
-
this.autoSave = filePathOrOptions.autoSave ?? true;
|
|
676
|
-
}
|
|
677
|
-
this.loadFromDisk();
|
|
678
|
-
}
|
|
679
|
-
loadFromDisk() {
|
|
680
|
-
if (!existsSync(this.filePath)) return;
|
|
681
|
-
try {
|
|
682
|
-
const raw = readFileSync(this.filePath, "utf8");
|
|
683
|
-
if (!raw.trim()) return;
|
|
684
|
-
const parsed = JSON.parse(raw);
|
|
685
|
-
if (!parsed || typeof parsed !== "object" || !parsed.workspaces || typeof parsed.workspaces !== "object") {
|
|
686
|
-
return;
|
|
687
|
-
}
|
|
688
|
-
for (const [workspaceId, files] of Object.entries(parsed.workspaces)) {
|
|
689
|
-
if (!files || typeof files !== "object") continue;
|
|
690
|
-
const map = /* @__PURE__ */ new Map();
|
|
691
|
-
for (const [relPath, manifest] of Object.entries(files)) {
|
|
692
|
-
if (manifest && typeof manifest === "object" && typeof manifest.contentSha256 === "string") {
|
|
693
|
-
const norm = toPosix(relPath);
|
|
694
|
-
map.set(norm, { ...manifest, relativePath: norm });
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
this.workspaces.set(workspaceId, map);
|
|
698
|
-
}
|
|
699
|
-
} catch {
|
|
700
|
-
this.workspaces.clear();
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
get(workspaceId, relativePath, contentSha256, mtimeMs, size) {
|
|
704
|
-
const wsMap = this.workspaces.get(workspaceId);
|
|
705
|
-
if (!wsMap) return void 0;
|
|
706
|
-
const hit = wsMap.get(toPosix(relativePath));
|
|
707
|
-
if (!hit) return void 0;
|
|
708
|
-
return cacheEntryMatches(hit, contentSha256, mtimeMs, size) ? hit : void 0;
|
|
709
|
-
}
|
|
710
|
-
set(workspaceId, manifest) {
|
|
711
|
-
const norm = toPosix(manifest.relativePath);
|
|
712
|
-
const normalized = {
|
|
713
|
-
...manifest,
|
|
714
|
-
relativePath: norm
|
|
715
|
-
};
|
|
716
|
-
let wsMap = this.workspaces.get(workspaceId);
|
|
717
|
-
if (!wsMap) {
|
|
718
|
-
wsMap = /* @__PURE__ */ new Map();
|
|
719
|
-
this.workspaces.set(workspaceId, wsMap);
|
|
720
|
-
}
|
|
721
|
-
wsMap.set(norm, normalized);
|
|
722
|
-
this.dirty = true;
|
|
723
|
-
if (this.autoSave) {
|
|
724
|
-
this.save();
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
getAllWorkspaceManifests(workspaceId) {
|
|
728
|
-
const wsMap = this.workspaces.get(workspaceId);
|
|
729
|
-
if (!wsMap) return [];
|
|
730
|
-
return [...wsMap.values()];
|
|
731
|
-
}
|
|
732
|
-
clear(workspaceId) {
|
|
733
|
-
if (workspaceId === void 0) {
|
|
734
|
-
this.workspaces.clear();
|
|
735
|
-
} else {
|
|
736
|
-
this.workspaces.delete(workspaceId);
|
|
737
|
-
}
|
|
738
|
-
this.dirty = true;
|
|
739
|
-
if (this.autoSave) {
|
|
740
|
-
this.save();
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
save() {
|
|
744
|
-
if (!this.dirty && existsSync(this.filePath)) return;
|
|
745
|
-
const payload = {
|
|
746
|
-
version: 1,
|
|
747
|
-
workspaces: {}
|
|
748
|
-
};
|
|
749
|
-
for (const [workspaceId, wsMap] of this.workspaces.entries()) {
|
|
750
|
-
const obj = {};
|
|
751
|
-
for (const [relPath, manifest] of wsMap.entries()) {
|
|
752
|
-
obj[relPath] = manifest;
|
|
753
|
-
}
|
|
754
|
-
payload.workspaces[workspaceId] = obj;
|
|
755
|
-
}
|
|
756
|
-
const dir = path3.dirname(this.filePath);
|
|
757
|
-
mkdirSync(dir, { recursive: true });
|
|
758
|
-
const serialized = JSON.stringify(payload, null, 2);
|
|
759
|
-
const tmpPath = `${this.filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
760
|
-
try {
|
|
761
|
-
writeFileSync(tmpPath, serialized, "utf8");
|
|
762
|
-
renameSync(tmpPath, this.filePath);
|
|
763
|
-
} catch {
|
|
764
|
-
writeFileSync(this.filePath, serialized, "utf8");
|
|
765
|
-
}
|
|
766
|
-
this.dirty = false;
|
|
767
|
-
}
|
|
768
|
-
flush() {
|
|
769
|
-
this.save();
|
|
770
|
-
}
|
|
771
|
-
};
|
|
772
|
-
|
|
773
967
|
// ../engine/src/env.ts
|
|
774
968
|
function readEnv(name) {
|
|
775
969
|
return process.env[`TIPOLINK_${name}`] ?? process.env[`INTERLINK_${name}`];
|
|
@@ -2914,6 +3108,45 @@ function buildWorkspaceResolutionContext(root, rootReal, allRelativePaths, confi
|
|
|
2914
3108
|
|
|
2915
3109
|
// ../engine/src/indexer.ts
|
|
2916
3110
|
var SOURCE_EXTENSIONS = new Set(defaultPolyglotRegistry.supportedExtensions);
|
|
3111
|
+
var NON_CODE_ASSET_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
3112
|
+
".css",
|
|
3113
|
+
".scss",
|
|
3114
|
+
".less",
|
|
3115
|
+
".svg",
|
|
3116
|
+
".png",
|
|
3117
|
+
".jpg",
|
|
3118
|
+
".jpeg",
|
|
3119
|
+
".webp",
|
|
3120
|
+
".gif",
|
|
3121
|
+
".ico",
|
|
3122
|
+
".woff",
|
|
3123
|
+
".woff2",
|
|
3124
|
+
".ttf",
|
|
3125
|
+
".wasm",
|
|
3126
|
+
".json",
|
|
3127
|
+
".glsl",
|
|
3128
|
+
".sql",
|
|
3129
|
+
".txt",
|
|
3130
|
+
".md"
|
|
3131
|
+
]);
|
|
3132
|
+
function stripImportQueryAndHash(specifier) {
|
|
3133
|
+
const trimmed = specifier.trim();
|
|
3134
|
+
const qIdx = trimmed.indexOf("?");
|
|
3135
|
+
const hIdx = trimmed.indexOf("#");
|
|
3136
|
+
let cut = trimmed.length;
|
|
3137
|
+
if (qIdx !== -1 && qIdx < cut) cut = qIdx;
|
|
3138
|
+
if (hIdx !== -1 && hIdx < cut) cut = hIdx;
|
|
3139
|
+
return trimmed.slice(0, cut);
|
|
3140
|
+
}
|
|
3141
|
+
function isRelativeImportSpecifier(specifier) {
|
|
3142
|
+
const clean = stripImportQueryAndHash(specifier);
|
|
3143
|
+
return clean === "." || clean === ".." || clean.startsWith("./") || clean.startsWith("../");
|
|
3144
|
+
}
|
|
3145
|
+
function isNonCodeAssetSpecifier(specifier) {
|
|
3146
|
+
const clean = stripImportQueryAndHash(specifier);
|
|
3147
|
+
const ext = path5.posix.extname(clean).toLowerCase();
|
|
3148
|
+
return ext.length > 0 && NON_CODE_ASSET_EXTENSIONS.has(ext) && !SOURCE_EXTENSIONS.has(ext);
|
|
3149
|
+
}
|
|
2917
3150
|
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
2918
3151
|
"node_modules",
|
|
2919
3152
|
".git",
|
|
@@ -3123,7 +3356,18 @@ function resolveAlias(spec, fromFile, index) {
|
|
|
3123
3356
|
}
|
|
3124
3357
|
return null;
|
|
3125
3358
|
}
|
|
3126
|
-
function
|
|
3359
|
+
function buildEdgeFlags(importedNames, meta) {
|
|
3360
|
+
const isTypeOnly = meta?.isTypeOnly === true;
|
|
3361
|
+
const isDynamic = meta?.isDynamic === true;
|
|
3362
|
+
const hasStaticValueImport = !isTypeOnly && !isDynamic && meta?.verifiedAssetOnDisk !== true && importedNames.length > 0;
|
|
3363
|
+
return {
|
|
3364
|
+
...isTypeOnly ? { isTypeOnly: true } : {},
|
|
3365
|
+
...isDynamic ? { isDynamic: true } : {},
|
|
3366
|
+
hasStaticValueImport,
|
|
3367
|
+
...meta?.verifiedAssetOnDisk !== void 0 ? { verifiedAssetOnDisk: meta.verifiedAssetOnDisk } : {}
|
|
3368
|
+
};
|
|
3369
|
+
}
|
|
3370
|
+
function localRef(found, index, importedNames, isReExport, meta) {
|
|
3127
3371
|
let real;
|
|
3128
3372
|
try {
|
|
3129
3373
|
real = realpathSync.native(found);
|
|
@@ -3136,55 +3380,72 @@ function localRef(found, index, importedNames, isReExport) {
|
|
|
3136
3380
|
kind: "local",
|
|
3137
3381
|
label,
|
|
3138
3382
|
importedNames: [...importedNames],
|
|
3139
|
-
isReExport
|
|
3383
|
+
isReExport,
|
|
3384
|
+
...buildEdgeFlags(importedNames, meta)
|
|
3140
3385
|
};
|
|
3141
3386
|
}
|
|
3142
|
-
function unresolvedRef(base, index, importedNames, isReExport) {
|
|
3387
|
+
function unresolvedRef(base, index, importedNames, isReExport, meta) {
|
|
3143
3388
|
const label = displayPath(index.root, path5.resolve(base));
|
|
3144
3389
|
return {
|
|
3145
3390
|
key: `unresolved:${label}`,
|
|
3146
3391
|
kind: "unresolved",
|
|
3147
3392
|
label: `${label} (unresolved)`,
|
|
3148
3393
|
importedNames: [...importedNames],
|
|
3149
|
-
isReExport
|
|
3394
|
+
isReExport,
|
|
3395
|
+
...buildEdgeFlags(importedNames, meta)
|
|
3150
3396
|
};
|
|
3151
3397
|
}
|
|
3152
|
-
function externalRef(spec, importedNames, isReExport) {
|
|
3398
|
+
function externalRef(spec, importedNames, isReExport, meta) {
|
|
3153
3399
|
return {
|
|
3154
3400
|
key: `pkg:${spec}`,
|
|
3155
3401
|
kind: "external",
|
|
3156
3402
|
label: spec,
|
|
3157
3403
|
importedNames: [...importedNames],
|
|
3158
|
-
isReExport
|
|
3404
|
+
isReExport,
|
|
3405
|
+
...buildEdgeFlags(importedNames, meta)
|
|
3159
3406
|
};
|
|
3160
3407
|
}
|
|
3161
|
-
function resolveModule(rawSpec, fromFile, index, importedNames = [], isReExport = false) {
|
|
3162
|
-
const spec = rawSpec
|
|
3408
|
+
function resolveModule(rawSpec, fromFile, index, importedNames = [], isReExport = false, meta) {
|
|
3409
|
+
const spec = stripImportQueryAndHash(rawSpec);
|
|
3163
3410
|
if (spec === "." || spec === ".." || spec.startsWith("./") || spec.startsWith("../")) {
|
|
3164
3411
|
const base = path5.resolve(path5.dirname(fromFile), spec);
|
|
3165
3412
|
const found = resolveCandidate(base);
|
|
3166
|
-
|
|
3413
|
+
const isAsset = isNonCodeAssetSpecifier(spec);
|
|
3414
|
+
const verifiedAssetOnDisk = isAsset ? Boolean(found) : meta?.verifiedAssetOnDisk;
|
|
3415
|
+
const effectiveMeta = {
|
|
3416
|
+
...meta,
|
|
3417
|
+
...verifiedAssetOnDisk !== void 0 ? { verifiedAssetOnDisk } : {}
|
|
3418
|
+
};
|
|
3419
|
+
return found ? localRef(found, index, importedNames, isReExport, effectiveMeta) : unresolvedRef(base, index, importedNames, isReExport, effectiveMeta);
|
|
3167
3420
|
}
|
|
3168
3421
|
if (spec.startsWith("node:")) {
|
|
3169
|
-
return externalRef(spec, importedNames, isReExport);
|
|
3422
|
+
return externalRef(spec, importedNames, isReExport, meta);
|
|
3170
3423
|
}
|
|
3171
3424
|
if (NODE_BUILTINS.has(spec)) {
|
|
3172
|
-
return externalRef(`node:${spec}`, importedNames, isReExport);
|
|
3425
|
+
return externalRef(`node:${spec}`, importedNames, isReExport, meta);
|
|
3173
3426
|
}
|
|
3174
3427
|
if (path5.isAbsolute(spec)) {
|
|
3175
3428
|
const found = resolveCandidate(spec);
|
|
3176
|
-
if (found) return localRef(found, index, importedNames, isReExport);
|
|
3429
|
+
if (found) return localRef(found, index, importedNames, isReExport, meta);
|
|
3177
3430
|
}
|
|
3178
3431
|
const aliased = resolveAlias(spec, fromFile, index);
|
|
3179
|
-
if (aliased)
|
|
3180
|
-
|
|
3432
|
+
if (aliased) {
|
|
3433
|
+
const isAsset = isNonCodeAssetSpecifier(aliased);
|
|
3434
|
+
return localRef(aliased, index, importedNames, isReExport, {
|
|
3435
|
+
...meta,
|
|
3436
|
+
...isAsset ? { verifiedAssetOnDisk: true } : {}
|
|
3437
|
+
});
|
|
3438
|
+
}
|
|
3439
|
+
return externalRef(spec, importedNames, isReExport, meta);
|
|
3181
3440
|
}
|
|
3182
3441
|
function mergeModuleRef(modules, ref) {
|
|
3442
|
+
const incomingHasStatic = ref.hasStaticValueImport ?? (ref.isTypeOnly !== true && ref.isDynamic !== true && ref.verifiedAssetOnDisk !== true && ref.importedNames.length > 0);
|
|
3183
3443
|
const existing = modules.get(ref.key);
|
|
3184
3444
|
if (!existing) {
|
|
3185
3445
|
modules.set(ref.key, {
|
|
3186
3446
|
...ref,
|
|
3187
|
-
importedNames: [...ref.importedNames]
|
|
3447
|
+
importedNames: [...ref.importedNames],
|
|
3448
|
+
hasStaticValueImport: incomingHasStatic
|
|
3188
3449
|
});
|
|
3189
3450
|
return;
|
|
3190
3451
|
}
|
|
@@ -3196,6 +3457,15 @@ function mergeModuleRef(modules, ref) {
|
|
|
3196
3457
|
if (ref.isReExport) {
|
|
3197
3458
|
existing.isReExport = true;
|
|
3198
3459
|
}
|
|
3460
|
+
const existingHasStatic = existing.hasStaticValueImport ?? (existing.isTypeOnly !== true && existing.isDynamic !== true && existing.verifiedAssetOnDisk !== true && existing.importedNames.length > 0);
|
|
3461
|
+
existing.hasStaticValueImport = existingHasStatic || incomingHasStatic;
|
|
3462
|
+
existing.isTypeOnly = Boolean(existing.isTypeOnly) && Boolean(ref.isTypeOnly);
|
|
3463
|
+
existing.isDynamic = Boolean(existing.isDynamic) && Boolean(ref.isDynamic);
|
|
3464
|
+
if (ref.verifiedAssetOnDisk === true) {
|
|
3465
|
+
existing.verifiedAssetOnDisk = true;
|
|
3466
|
+
} else if (ref.verifiedAssetOnDisk === false && existing.verifiedAssetOnDisk === void 0) {
|
|
3467
|
+
existing.verifiedAssetOnDisk = false;
|
|
3468
|
+
}
|
|
3199
3469
|
}
|
|
3200
3470
|
function addInboundEdge(index, callerRel, targetRel) {
|
|
3201
3471
|
let inboundSet = index.inbound.get(targetRel);
|
|
@@ -3228,8 +3498,13 @@ function registerIndexedFile(index, file, extraId) {
|
|
|
3228
3498
|
function resolveNonJsTsImport(imp, relative, language, index, modules) {
|
|
3229
3499
|
const adapter = defaultPolyglotRegistry.getAdapterById(language);
|
|
3230
3500
|
const ctx = index.resolutionContext;
|
|
3501
|
+
const edgeMeta = {
|
|
3502
|
+
isTypeOnly: imp.isTypeOnly,
|
|
3503
|
+
isDynamic: imp.isDynamic,
|
|
3504
|
+
verifiedAssetOnDisk: imp.verifiedAssetOnDisk
|
|
3505
|
+
};
|
|
3231
3506
|
if (!adapter || !ctx) {
|
|
3232
|
-
const ext = externalRef(imp.rawSpecifier, imp.importedNames, imp.isReExport);
|
|
3507
|
+
const ext = externalRef(imp.rawSpecifier, imp.importedNames, imp.isReExport, edgeMeta);
|
|
3233
3508
|
mergeModuleRef(modules, { ...ext, rawSpecifier: imp.rawSpecifier });
|
|
3234
3509
|
return { ...imp, resolvedKind: "external", resolvedPaths: [] };
|
|
3235
3510
|
}
|
|
@@ -3242,6 +3517,7 @@ function resolveNonJsTsImport(imp, relative, language, index, modules) {
|
|
|
3242
3517
|
label: targetRel,
|
|
3243
3518
|
importedNames: [...imp.importedNames],
|
|
3244
3519
|
isReExport: imp.isReExport,
|
|
3520
|
+
...buildEdgeFlags(imp.importedNames, edgeMeta),
|
|
3245
3521
|
rawSpecifier: imp.rawSpecifier
|
|
3246
3522
|
});
|
|
3247
3523
|
}
|
|
@@ -3259,6 +3535,7 @@ function resolveNonJsTsImport(imp, relative, language, index, modules) {
|
|
|
3259
3535
|
label: `${attempt} (unresolved)`,
|
|
3260
3536
|
importedNames: [...imp.importedNames],
|
|
3261
3537
|
isReExport: imp.isReExport,
|
|
3538
|
+
...buildEdgeFlags(imp.importedNames, edgeMeta),
|
|
3262
3539
|
rawSpecifier: imp.rawSpecifier
|
|
3263
3540
|
});
|
|
3264
3541
|
return {
|
|
@@ -3269,7 +3546,7 @@ function resolveNonJsTsImport(imp, relative, language, index, modules) {
|
|
|
3269
3546
|
}
|
|
3270
3547
|
const extLabel = res.externalLabel ?? imp.rawSpecifier;
|
|
3271
3548
|
mergeModuleRef(modules, {
|
|
3272
|
-
...externalRef(extLabel, imp.importedNames, imp.isReExport),
|
|
3549
|
+
...externalRef(extLabel, imp.importedNames, imp.isReExport, edgeMeta),
|
|
3273
3550
|
rawSpecifier: imp.rawSpecifier
|
|
3274
3551
|
});
|
|
3275
3552
|
return {
|
|
@@ -3330,11 +3607,29 @@ function indexFileOnDisk(absolute, index, options) {
|
|
|
3330
3607
|
const resolvedImports = [];
|
|
3331
3608
|
for (const imp of manifest.imports) {
|
|
3332
3609
|
if (isJsTs) {
|
|
3333
|
-
const
|
|
3610
|
+
const cleanSpec = stripImportQueryAndHash(imp.rawSpecifier);
|
|
3611
|
+
let verifiedAssetOnDisk = imp.verifiedAssetOnDisk;
|
|
3612
|
+
if (isRelativeImportSpecifier(cleanSpec) && isNonCodeAssetSpecifier(cleanSpec)) {
|
|
3613
|
+
verifiedAssetOnDisk = isFile(path5.resolve(path5.dirname(realAbs), cleanSpec));
|
|
3614
|
+
}
|
|
3615
|
+
const ref = resolveModule(
|
|
3616
|
+
imp.rawSpecifier,
|
|
3617
|
+
realAbs,
|
|
3618
|
+
index,
|
|
3619
|
+
imp.importedNames,
|
|
3620
|
+
imp.isReExport,
|
|
3621
|
+
{
|
|
3622
|
+
isTypeOnly: imp.isTypeOnly,
|
|
3623
|
+
isDynamic: imp.isDynamic,
|
|
3624
|
+
verifiedAssetOnDisk
|
|
3625
|
+
}
|
|
3626
|
+
);
|
|
3334
3627
|
mergeModuleRef(modules, { ...ref, rawSpecifier: imp.rawSpecifier });
|
|
3335
3628
|
const resolvedPaths = ref.kind === "local" ? [ref.label] : ref.kind === "unresolved" ? [ref.label.replace(/ \(unresolved\)$/, "")] : [];
|
|
3629
|
+
const effectiveVerifiedAsset = ref.verifiedAssetOnDisk !== void 0 ? ref.verifiedAssetOnDisk : verifiedAssetOnDisk;
|
|
3336
3630
|
resolvedImports.push({
|
|
3337
3631
|
...imp,
|
|
3632
|
+
...effectiveVerifiedAsset !== void 0 ? { verifiedAssetOnDisk: effectiveVerifiedAsset } : {},
|
|
3338
3633
|
resolvedKind: ref.kind,
|
|
3339
3634
|
resolvedPaths
|
|
3340
3635
|
});
|
|
@@ -3423,11 +3718,89 @@ function buildIndex(root, options) {
|
|
|
3423
3718
|
|
|
3424
3719
|
// src/extractor.ts
|
|
3425
3720
|
import { createHash as createHash4 } from "node:crypto";
|
|
3426
|
-
import { readdirSync as readdirSync2, readFileSync as readFileSync4, realpathSync as realpathSync2, statSync as statSync2 } from "node:fs";
|
|
3721
|
+
import { existsSync as existsSync3, readdirSync as readdirSync2, readFileSync as readFileSync4, realpathSync as realpathSync2, statSync as statSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
3427
3722
|
import path6 from "node:path";
|
|
3428
3723
|
function sha256Text(text) {
|
|
3429
3724
|
return createHash4("sha256").update(text, "utf8").digest("hex");
|
|
3430
3725
|
}
|
|
3726
|
+
function computeManifestSyncHash(manifest) {
|
|
3727
|
+
const assetSig = manifest.imports.map((imp) => {
|
|
3728
|
+
const assetFlag = imp.verifiedAssetOnDisk === true ? "1" : imp.verifiedAssetOnDisk === false ? "0" : "-";
|
|
3729
|
+
const dynFlag = imp.isDynamic === true ? "D" : "S";
|
|
3730
|
+
const typeFlag = imp.isTypeOnly ? "T" : "V";
|
|
3731
|
+
return `${imp.rawSpecifier}:${typeFlag}${dynFlag}${assetFlag}:${imp.importedNames.length}`;
|
|
3732
|
+
}).join("|");
|
|
3733
|
+
const symSig = manifest.exportedSymbols.map((s) => `${s.name}:${s.structuralHash ?? ""}`).join(",");
|
|
3734
|
+
const internalSig = manifest.internalFunctions.map((f) => `${f.name}:${f.structuralHash}`).join(",");
|
|
3735
|
+
const schema = manifest.schemaVersion ?? CACHE_SCHEMA_VERSION;
|
|
3736
|
+
return sha256Text(`${schema}\0${manifest.contentSha256}\0${assetSig}\0${symSig}\0${internalSig}`);
|
|
3737
|
+
}
|
|
3738
|
+
function verifyRelativeAssetsOnDisk(manifest, sourceAbsPath) {
|
|
3739
|
+
const sourceDir = path6.dirname(sourceAbsPath);
|
|
3740
|
+
let changed = false;
|
|
3741
|
+
const updatedImports = manifest.imports.map((imp) => {
|
|
3742
|
+
const cleanSpec = stripImportQueryAndHash(imp.rawSpecifier);
|
|
3743
|
+
if (!isRelativeImportSpecifier(cleanSpec) || !isNonCodeAssetSpecifier(cleanSpec)) {
|
|
3744
|
+
return imp;
|
|
3745
|
+
}
|
|
3746
|
+
const resolvedDiskPath = path6.resolve(sourceDir, cleanSpec);
|
|
3747
|
+
const verified = existsSync3(resolvedDiskPath);
|
|
3748
|
+
if (imp.verifiedAssetOnDisk !== verified) {
|
|
3749
|
+
changed = true;
|
|
3750
|
+
}
|
|
3751
|
+
return {
|
|
3752
|
+
...imp,
|
|
3753
|
+
verifiedAssetOnDisk: verified
|
|
3754
|
+
};
|
|
3755
|
+
});
|
|
3756
|
+
if (!changed) {
|
|
3757
|
+
return { manifest, changed: false };
|
|
3758
|
+
}
|
|
3759
|
+
return {
|
|
3760
|
+
manifest: {
|
|
3761
|
+
...manifest,
|
|
3762
|
+
imports: updatedImports
|
|
3763
|
+
},
|
|
3764
|
+
changed: true
|
|
3765
|
+
};
|
|
3766
|
+
}
|
|
3767
|
+
function invalidateStaleCloudSyncFile(cachePath, workspaceId) {
|
|
3768
|
+
const syncPath = path6.join(path6.dirname(cachePath), "cloud-sync.json");
|
|
3769
|
+
if (!existsSync3(syncPath)) return;
|
|
3770
|
+
try {
|
|
3771
|
+
const parsed = JSON.parse(readFileSync4(syncPath, "utf8"));
|
|
3772
|
+
if (!parsed || typeof parsed !== "object") return;
|
|
3773
|
+
if (parsed.manifestSchemaVersion !== CACHE_SCHEMA_VERSION) {
|
|
3774
|
+
writeFileSync2(
|
|
3775
|
+
syncPath,
|
|
3776
|
+
JSON.stringify(
|
|
3777
|
+
{
|
|
3778
|
+
version: 1,
|
|
3779
|
+
manifestSchemaVersion: CACHE_SCHEMA_VERSION,
|
|
3780
|
+
workspaces: {}
|
|
3781
|
+
},
|
|
3782
|
+
null,
|
|
3783
|
+
2
|
|
3784
|
+
),
|
|
3785
|
+
"utf8"
|
|
3786
|
+
);
|
|
3787
|
+
return;
|
|
3788
|
+
}
|
|
3789
|
+
if (parsed.workspaces && typeof parsed.workspaces === "object") {
|
|
3790
|
+
let modified = false;
|
|
3791
|
+
for (const key of Object.keys(parsed.workspaces)) {
|
|
3792
|
+
if (key === workspaceId || key.endsWith(`::${workspaceId}`)) {
|
|
3793
|
+
delete parsed.workspaces[key];
|
|
3794
|
+
modified = true;
|
|
3795
|
+
}
|
|
3796
|
+
}
|
|
3797
|
+
if (modified) {
|
|
3798
|
+
writeFileSync2(syncPath, JSON.stringify(parsed, null, 2), "utf8");
|
|
3799
|
+
}
|
|
3800
|
+
}
|
|
3801
|
+
} catch {
|
|
3802
|
+
}
|
|
3803
|
+
}
|
|
3431
3804
|
function hasSkippedPathSegment(relPath) {
|
|
3432
3805
|
const segments = toPosix(relPath).replace(/^\.\//, "").split("/");
|
|
3433
3806
|
return segments.some((seg) => seg.length > 0 && SKIP_DIRS.has(seg));
|
|
@@ -3440,6 +3813,7 @@ function sanitizeManifest(manifest) {
|
|
|
3440
3813
|
return {
|
|
3441
3814
|
relativePath: toPosix(manifest.relativePath),
|
|
3442
3815
|
contentSha256: manifest.contentSha256,
|
|
3816
|
+
schemaVersion: manifest.schemaVersion ?? CACHE_SCHEMA_VERSION,
|
|
3443
3817
|
...manifest.language !== void 0 ? { language: manifest.language } : {},
|
|
3444
3818
|
...manifest.mtimeMs !== void 0 ? { mtimeMs: manifest.mtimeMs } : {},
|
|
3445
3819
|
...manifest.size !== void 0 ? { size: manifest.size } : {},
|
|
@@ -3448,6 +3822,8 @@ function sanitizeManifest(manifest) {
|
|
|
3448
3822
|
importedNames: [...imp.importedNames],
|
|
3449
3823
|
isReExport: imp.isReExport,
|
|
3450
3824
|
isTypeOnly: imp.isTypeOnly,
|
|
3825
|
+
...imp.isDynamic === true ? { isDynamic: true } : {},
|
|
3826
|
+
...typeof imp.verifiedAssetOnDisk === "boolean" ? { verifiedAssetOnDisk: imp.verifiedAssetOnDisk } : {},
|
|
3451
3827
|
...Array.isArray(imp.resolvedPaths) ? { resolvedPaths: imp.resolvedPaths.map((p) => toPosix(p)) } : {},
|
|
3452
3828
|
...imp.resolvedKind !== void 0 ? { resolvedKind: imp.resolvedKind } : {}
|
|
3453
3829
|
})),
|
|
@@ -3520,6 +3896,7 @@ function scanWorkspaceManifests(rootDir, options = {}) {
|
|
|
3520
3896
|
const cachePath = options.cachePath ?? path6.join(resolvedRoot, ".tipolink", "cache.json");
|
|
3521
3897
|
const writeCache = options.writeCache ?? true;
|
|
3522
3898
|
const cache = new JsonFileAstCache({ filePath: cachePath, autoSave: false });
|
|
3899
|
+
const schemaInvalidated = cache.schemaInvalidated;
|
|
3523
3900
|
const priorManifests = cache.getAllWorkspaceManifests(workspaceId);
|
|
3524
3901
|
const priorPaths = /* @__PURE__ */ new Set();
|
|
3525
3902
|
let prunedSkippedEntries = false;
|
|
@@ -3536,7 +3913,7 @@ function scanWorkspaceManifests(rootDir, options = {}) {
|
|
|
3536
3913
|
const deltaRelPaths = /* @__PURE__ */ new Set();
|
|
3537
3914
|
let cacheHits = 0;
|
|
3538
3915
|
let parsedCount = 0;
|
|
3539
|
-
let cacheMutated =
|
|
3916
|
+
let cacheMutated = schemaInvalidated;
|
|
3540
3917
|
for (const absPath of sourceFiles) {
|
|
3541
3918
|
let realAbs;
|
|
3542
3919
|
try {
|
|
@@ -3555,29 +3932,44 @@ function scanWorkspaceManifests(rootDir, options = {}) {
|
|
|
3555
3932
|
}
|
|
3556
3933
|
if (!stats.isFile()) continue;
|
|
3557
3934
|
const statHit = cache.get(workspaceId, relPath, void 0, stats.mtimeMs, stats.size);
|
|
3558
|
-
if (statHit) {
|
|
3935
|
+
if (statHit && statHit.schemaVersion === CACHE_SCHEMA_VERSION) {
|
|
3559
3936
|
cacheHits += 1;
|
|
3560
|
-
|
|
3937
|
+
const verified = verifyRelativeAssetsOnDisk(sanitizeManifest(statHit), realAbs);
|
|
3938
|
+
if (verified.changed) {
|
|
3939
|
+
cache.set(workspaceId, verified.manifest);
|
|
3940
|
+
cacheMutated = true;
|
|
3941
|
+
deltaRelPaths.add(relPath);
|
|
3942
|
+
}
|
|
3943
|
+
rawAllManifests.push(verified.manifest);
|
|
3561
3944
|
continue;
|
|
3562
3945
|
}
|
|
3563
3946
|
const source = readFileSync4(realAbs, "utf8");
|
|
3564
3947
|
const contentSha256 = sha256Text(source);
|
|
3565
3948
|
const hashHit = cache.get(workspaceId, relPath, contentSha256);
|
|
3566
|
-
if (hashHit) {
|
|
3949
|
+
if (hashHit && hashHit.schemaVersion === CACHE_SCHEMA_VERSION) {
|
|
3567
3950
|
cacheHits += 1;
|
|
3568
|
-
const
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3951
|
+
const verified = verifyRelativeAssetsOnDisk(
|
|
3952
|
+
sanitizeManifest({
|
|
3953
|
+
...hashHit,
|
|
3954
|
+
mtimeMs: stats.mtimeMs,
|
|
3955
|
+
size: stats.size
|
|
3956
|
+
}),
|
|
3957
|
+
realAbs
|
|
3958
|
+
);
|
|
3959
|
+
cache.set(workspaceId, verified.manifest);
|
|
3574
3960
|
cacheMutated = true;
|
|
3575
|
-
|
|
3961
|
+
if (verified.changed) {
|
|
3962
|
+
deltaRelPaths.add(relPath);
|
|
3963
|
+
}
|
|
3964
|
+
rawAllManifests.push(verified.manifest);
|
|
3576
3965
|
continue;
|
|
3577
3966
|
}
|
|
3578
|
-
const extracted =
|
|
3579
|
-
|
|
3580
|
-
|
|
3967
|
+
const extracted = verifyRelativeAssetsOnDisk(
|
|
3968
|
+
sanitizeManifest(
|
|
3969
|
+
defaultPolyglotRegistry.extractManifest(source, realAbs, relPath, stats.mtimeMs, stats.size)
|
|
3970
|
+
),
|
|
3971
|
+
realAbs
|
|
3972
|
+
).manifest;
|
|
3581
3973
|
parsedCount += 1;
|
|
3582
3974
|
cache.set(workspaceId, extracted);
|
|
3583
3975
|
cacheMutated = true;
|
|
@@ -3599,22 +3991,27 @@ function scanWorkspaceManifests(rootDir, options = {}) {
|
|
|
3599
3991
|
}
|
|
3600
3992
|
if (writeCache && cacheMutated) {
|
|
3601
3993
|
cache.flush();
|
|
3994
|
+
if (schemaInvalidated) {
|
|
3995
|
+
invalidateStaleCloudSyncFile(cachePath, workspaceId);
|
|
3996
|
+
}
|
|
3602
3997
|
}
|
|
3603
3998
|
const index = buildIndex(resolvedRoot, { workspaceId, cache });
|
|
3604
3999
|
const allManifests = [];
|
|
3605
4000
|
const manifestDelta = [];
|
|
3606
4001
|
for (const file of index.files) {
|
|
3607
4002
|
if (hasSkippedPathSegment(file.relative)) continue;
|
|
3608
|
-
const
|
|
3609
|
-
allManifests.push(
|
|
4003
|
+
const verified = verifyRelativeAssetsOnDisk(sanitizeManifest(file.manifest), file.absolute).manifest;
|
|
4004
|
+
allManifests.push(verified);
|
|
3610
4005
|
if (deltaRelPaths.has(file.relative)) {
|
|
3611
|
-
manifestDelta.push(
|
|
4006
|
+
manifestDelta.push(verified);
|
|
3612
4007
|
}
|
|
3613
4008
|
}
|
|
3614
4009
|
return {
|
|
3615
4010
|
workspaceId,
|
|
3616
4011
|
rootDir: resolvedRoot,
|
|
3617
4012
|
cachePath,
|
|
4013
|
+
schemaVersion: CACHE_SCHEMA_VERSION,
|
|
4014
|
+
schemaInvalidated,
|
|
3618
4015
|
allManifests,
|
|
3619
4016
|
manifestDelta,
|
|
3620
4017
|
removedPaths,
|
|
@@ -3627,6 +4024,7 @@ function scanWorkspaceManifests(rootDir, options = {}) {
|
|
|
3627
4024
|
// src/mcp-stdio.ts
|
|
3628
4025
|
var DEFAULT_CLOUD_API_URL = "https://tipolink.co";
|
|
3629
4026
|
var DEFAULT_PORTAL_URL = "https://tipolink.co";
|
|
4027
|
+
var TIPOLINK_MCP_VERSION = "1.0.2";
|
|
3630
4028
|
var VALID_SYMBOL_KINDS = /* @__PURE__ */ new Set([
|
|
3631
4029
|
"function",
|
|
3632
4030
|
"const",
|
|
@@ -3763,11 +4161,13 @@ function cloudSyncStatePath(workspaceRoot) {
|
|
|
3763
4161
|
}
|
|
3764
4162
|
function loadCloudSyncHashes(workspaceRoot, stateKey) {
|
|
3765
4163
|
const filePath = cloudSyncStatePath(workspaceRoot);
|
|
3766
|
-
if (!
|
|
4164
|
+
if (!existsSync4(filePath)) return null;
|
|
3767
4165
|
try {
|
|
3768
4166
|
const raw = readFileSync5(filePath, "utf8");
|
|
3769
4167
|
const parsed = JSON.parse(raw);
|
|
3770
|
-
if (!parsed || typeof parsed !== "object" || !parsed.workspaces)
|
|
4168
|
+
if (!parsed || typeof parsed !== "object" || parsed.manifestSchemaVersion !== CACHE_SCHEMA_VERSION || !parsed.workspaces) {
|
|
4169
|
+
return null;
|
|
4170
|
+
}
|
|
3771
4171
|
const entry = parsed.workspaces[stateKey];
|
|
3772
4172
|
return isRecord(entry) ? entry : null;
|
|
3773
4173
|
} catch {
|
|
@@ -3776,32 +4176,41 @@ function loadCloudSyncHashes(workspaceRoot, stateKey) {
|
|
|
3776
4176
|
}
|
|
3777
4177
|
function saveCloudSyncHashes(workspaceRoot, stateKey, manifests) {
|
|
3778
4178
|
const filePath = cloudSyncStatePath(workspaceRoot);
|
|
3779
|
-
let store = {
|
|
3780
|
-
|
|
4179
|
+
let store = {
|
|
4180
|
+
version: 1,
|
|
4181
|
+
manifestSchemaVersion: CACHE_SCHEMA_VERSION,
|
|
4182
|
+
workspaces: {}
|
|
4183
|
+
};
|
|
4184
|
+
if (existsSync4(filePath)) {
|
|
3781
4185
|
try {
|
|
3782
4186
|
const parsed = JSON.parse(readFileSync5(filePath, "utf8"));
|
|
3783
|
-
if (parsed && typeof parsed === "object" && isRecord(parsed.workspaces)) {
|
|
4187
|
+
if (parsed && typeof parsed === "object" && parsed.manifestSchemaVersion === CACHE_SCHEMA_VERSION && isRecord(parsed.workspaces)) {
|
|
3784
4188
|
store = {
|
|
3785
4189
|
version: 1,
|
|
4190
|
+
manifestSchemaVersion: CACHE_SCHEMA_VERSION,
|
|
3786
4191
|
workspaces: parsed.workspaces
|
|
3787
4192
|
};
|
|
3788
4193
|
}
|
|
3789
4194
|
} catch {
|
|
3790
|
-
store = {
|
|
4195
|
+
store = {
|
|
4196
|
+
version: 1,
|
|
4197
|
+
manifestSchemaVersion: CACHE_SCHEMA_VERSION,
|
|
4198
|
+
workspaces: {}
|
|
4199
|
+
};
|
|
3791
4200
|
}
|
|
3792
4201
|
}
|
|
3793
4202
|
const nextMap = {};
|
|
3794
4203
|
for (const manifest of manifests) {
|
|
3795
|
-
nextMap[manifest.relativePath] = manifest
|
|
4204
|
+
nextMap[manifest.relativePath] = computeManifestSyncHash(manifest);
|
|
3796
4205
|
}
|
|
3797
4206
|
store.workspaces[stateKey] = nextMap;
|
|
3798
4207
|
mkdirSync2(path7.dirname(filePath), { recursive: true });
|
|
3799
|
-
|
|
4208
|
+
writeFileSync3(filePath, JSON.stringify(store, null, 2), "utf8");
|
|
3800
4209
|
}
|
|
3801
4210
|
function computeCloudSyncDelta(scan, apiUrl) {
|
|
3802
4211
|
const baseUrl = apiUrl.replace(/\/+$/, "");
|
|
3803
4212
|
const stateKey = `${baseUrl}::${scan.workspaceId}`;
|
|
3804
|
-
const priorHashes = loadCloudSyncHashes(scan.rootDir, stateKey);
|
|
4213
|
+
const priorHashes = scan.schemaInvalidated ? null : loadCloudSyncHashes(scan.rootDir, stateKey);
|
|
3805
4214
|
if (!priorHashes) {
|
|
3806
4215
|
return {
|
|
3807
4216
|
delta: scan.allManifests,
|
|
@@ -3814,7 +4223,7 @@ function computeCloudSyncDelta(scan, apiUrl) {
|
|
|
3814
4223
|
const delta = [];
|
|
3815
4224
|
for (const manifest of scan.allManifests) {
|
|
3816
4225
|
activePaths.add(manifest.relativePath);
|
|
3817
|
-
if (priorHashes[manifest.relativePath] !== manifest
|
|
4226
|
+
if (priorHashes[manifest.relativePath] !== computeManifestSyncHash(manifest)) {
|
|
3818
4227
|
delta.push(manifest);
|
|
3819
4228
|
}
|
|
3820
4229
|
}
|
|
@@ -4140,7 +4549,7 @@ function createMcpDispatcher(options = {}) {
|
|
|
4140
4549
|
},
|
|
4141
4550
|
serverInfo: {
|
|
4142
4551
|
name: "tipolink-mcp",
|
|
4143
|
-
version:
|
|
4552
|
+
version: TIPOLINK_MCP_VERSION
|
|
4144
4553
|
}
|
|
4145
4554
|
}
|
|
4146
4555
|
};
|
|
@@ -4378,6 +4787,7 @@ export {
|
|
|
4378
4787
|
DEFAULT_PORTAL_URL,
|
|
4379
4788
|
JsonRpcStreamParser,
|
|
4380
4789
|
TIPOLINK_MCP_TOOLS,
|
|
4790
|
+
TIPOLINK_MCP_VERSION,
|
|
4381
4791
|
createMcpDispatcher,
|
|
4382
4792
|
encodeJsonRpcFrame,
|
|
4383
4793
|
executeTipolinkTool,
|