@jokeran/frontend-code-skimmer 0.4.8 → 0.5.1
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/README.md +47 -2
- package/dist/index.js +227 -179
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import*as
|
|
3
|
-
`&&e++;return e}function Te(
|
|
4
|
-
`),r=e-1-1;for(;r>=0&&t[r].trim()==="";)r--;if(r<0||!t[r].trim().endsWith("*/"))return;let s=r;for(;s>0&&!t[s].trim().startsWith("/**");)s--;if(t[s].trim().startsWith("/**"))return t.slice(s,r+1).map(
|
|
2
|
+
import*as te from'path';import te__default from'path';import {fileURLToPath}from'url';import {McpServer}from'@modelcontextprotocol/sdk/server/mcp.js';import {StdioServerTransport}from'@modelcontextprotocol/sdk/server/stdio.js';import bs from'os';import*as ne from'fs';import ne__default from'fs';import Nr,{createHash}from'crypto';import Rr from'better-sqlite3';import ys from'fast-glob';import {createRequire}from'module';import {z}from'zod';function tt(i){switch(i){case "template_event":return "template_event";case "jsx_event":return "jsx_event";case "hook_call":return "hook_call";case "import_func":return "import_call";case "new_call":return "constructor_call";default:return "method_call"}}function k(i){return i.replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").replace(/([a-z\d])([A-Z])/g,"$1 $2").replace(/_/g," ").replace(/-/g," ").toLowerCase().trim().replace(/\s+/g," ")}function nt(i,e){let t=i.length,n=e.length,r=Array.from({length:t+1},(s,o)=>Array.from({length:n+1},(a,c)=>o===0?c:c===0?o:0));for(let s=1;s<=t;s++)for(let o=1;o<=n;o++)i[s-1]===e[o-1]?r[s][o]=r[s-1][o-1]:r[s][o]=1+Math.min(r[s-1][o],r[s][o-1],r[s-1][o-1]);return r[t][n]}function Xe(i){return Nr.createHash("md5").update(i).digest("hex")}function rt(i){if(!i)return 0;let e=1;for(let t=0;t<i.length;t++)i[t]===`
|
|
3
|
+
`&&e++;return e}function Te(i,e){return i===e?`L${i}`:`L${i}-L${e}`}function he(i,e){return te__default.relative(e,i).replace(/\\/g,"/")}function Ke(i,e){if(!i)return e;try{return JSON.parse(i)}catch{return e}}function Y(i,e){let t=i.split(`
|
|
4
|
+
`),r=e-1-1;for(;r>=0&&t[r].trim()==="";)r--;if(r<0||!t[r].trim().endsWith("*/"))return;let s=r;for(;s>0&&!t[s].trim().startsWith("/**");)s--;if(t[s].trim().startsWith("/**"))return t.slice(s,r+1).map(o=>o.replace(/^\s*\*\s?/,"").replace(/\/\*\*/,"").replace(/\*\//,"").trim()).filter(o=>o.length>0).join(" ")}function pn(i,e){let t=i.toLowerCase(),n=e.toLowerCase();if(t===n)return 100;if(n.includes(t)||t.includes(n))return 85;let r=nt(t,n),s=Math.max(t.length,n.length);if(s===0)return 100;let o=Math.max(0,100-r/s*100);return Math.round(o)}function xe(i){return i.startsWith("use")&&i.length>3&&/[A-Z]/.test(i[3])}function un(i,e,t){if(t===0||t>3)return;let n=k(i).split(" "),r=k(e).split(" ");for(let s of n)for(let o of r){let a=nt(s,o);if(a>0&&a<=3&&s!==o)return `"${s}" \u53EF\u80FD\u662F "${o}" \u7684\u62FC\u5199\u9519\u8BEF (\u7F16\u8F91\u8DDD\u79BB=${a})`}}var Tr=[".ts",".tsx",".js",".jsx",".vue"],xr=["index.ts","index.tsx","index.js","index.jsx","index.vue"];function Ar(i){return [...Tr.map(e=>`${i}${e}`),...xr.map(e=>te.join(i,e))]}function ke(i){if(ne.existsSync(i))try{if(ne.statSync(i).isFile())return i}catch{}for(let e of Ar(i))if(ne.existsSync(e))return e;return i}var Pt=["**/node_modules/**","**/dist/**","**/build/**","**/.git/**","**/coverage/**","**/.nuxt/**","**/.next/**","**/__tests__/**","**/docs/js/**","**/public/**/*.js","**/*.test.*","**/*.spec.*","**/*.min.js"],Ft=["**/*.vue","**/*.js","**/*.jsx","**/*.ts","**/*.tsx"],fn={storage:{localStorage:["setItem","getItem","removeItem","clear","key"],sessionStorage:["setItem","getItem","removeItem","clear","key"],cookie:["cookie"]},network:{axios:["get","post","put","delete","patch","request","create"],fetch:["fetch"],XMLHttpRequest:["open","send"],$http:["get","post","put","delete"]},router:{$router:["push","replace","go","back","forward"],$route:[],useRouter:[],useRoute:[],navigate:[],history:["push","replace","go"]},vuex:{$store:["commit","dispatch","getters","state"],useStore:[],store:["commit","dispatch"]},dom:{document:["querySelector","getElementById","createElement","addEventListener"],window:["addEventListener","removeEventListener","open","close"],$refs:[],$nextTick:[],nextTick:[]},event:{$emit:[],EventBus:["emit","on","off"],dispatchEvent:[],emit:[]},timer:{setTimeout:[],setInterval:[],clearTimeout:[],clearInterval:[],requestAnimationFrame:[]},i18n:{$t:[],useI18n:[],t:[],i18n:["t","tc","te"]}},Ot=["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeDestroy","destroyed","activated","deactivated","errorCaptured"],Dt=["onBeforeMount","onMounted","onBeforeUpdate","onUpdated","onBeforeUnmount","onUnmounted","onActivated","onDeactivated","onErrorCaptured","onRenderTracked","onRenderTriggered","onServerPrefetch"],mn=["ref","reactive","shallowRef","shallowReactive","readonly"],gn=["computed"],hn=["watch","watchEffect","watchPostEffect","watchSyncEffect"],Mt=["useState","useReducer","useRef","useImperativeHandle"],jt=["useMemo","useCallback"],Bt=["useEffect","useLayoutEffect","useInsertionEffect"],yn=["useContext","useDebugValue","useDeferredValue","useId","useSyncExternalStore","useTransition"],st=".skimmer-index.db",bn=30,_n=4,En=300;var Lr=[{version:1,description:"\u5EFA\u7ACB schema_version \u8868",statements:[`CREATE TABLE IF NOT EXISTS schema_version (
|
|
5
5
|
version INTEGER PRIMARY KEY,
|
|
6
6
|
applied_at INTEGER NOT NULL,
|
|
7
7
|
description TEXT
|
|
@@ -38,11 +38,11 @@ import*as q from'path';import q__default from'path';import {fileURLToPath}from'u
|
|
|
38
38
|
rel_path TEXT PRIMARY KEY,
|
|
39
39
|
priority TEXT NOT NULL DEFAULT 'normal',
|
|
40
40
|
added_at INTEGER NOT NULL
|
|
41
|
-
)`,"CREATE INDEX IF NOT EXISTS idx_precise_pending_priority ON precise_pending(priority, added_at)"]}];function
|
|
41
|
+
)`,"CREATE INDEX IF NOT EXISTS idx_precise_pending_priority ON precise_pending(priority, added_at)"]}];function Nn(i){let e=[],t=[];i.exec(`CREATE TABLE IF NOT EXISTS schema_version (
|
|
42
42
|
version INTEGER PRIMARY KEY,
|
|
43
43
|
applied_at INTEGER NOT NULL,
|
|
44
44
|
description TEXT
|
|
45
|
-
)`);let n=
|
|
45
|
+
)`);let n=i.prepare("SELECT MAX(version) as v FROM schema_version").get()?.v??0;for(let r of Lr){if(r.version<=n)continue;let s=Date.now(),o=true;for(let a of r.statements)try{i.exec(a);}catch(c){let l=String(c);if(l.includes("duplicate column name"))continue;t.push(`v${r.version}: ${l.slice(0,120)}`),o=false;}i.prepare("INSERT OR REPLACE INTO schema_version (version, applied_at, description) VALUES (?, ?, ?)").run(r.version,s,o?r.description:`${r.description} (\u90E8\u5206\u8BED\u53E5\u8DF3\u8FC7)`),e.push(r.version);}return {applied:e,errors:t}}function kr(i,e){let t=te__default.posix.dirname(e),n=t==="."?[]:t.split("/").map(()=>"..");return te__default.resolve(te__default.dirname(i),...n)}function vr(i,e,t){if(!i)return i;if(te__default.isAbsolute(i)){let n=he(ke(i),t);return n.startsWith("..")?i.replace(/\\/g,"/"):n}if(i.startsWith(".")){let n=ke(te__default.resolve(te__default.dirname(e),i)),r=he(n,t);return r.startsWith("..")?i.replace(/\\/g,"/"):r}if(i.startsWith("@/")){let n=ke(te__default.resolve(t,"src",i.slice(2))),r=he(n,t);return r.startsWith("..")?i.replace(/\\/g,"/"):r}return i.replace(/\\/g,"/")}var it=class{db;constructor(e,t){let n=t||te__default.join(e,st);ne__default.mkdirSync(te__default.dirname(n),{recursive:true}),this.db=new Rr(n),this.initialize();}initialize(){this.db.pragma("journal_mode = WAL"),this.db.pragma("foreign_keys = ON"),this.db.pragma("synchronous = NORMAL"),this.db.exec(`
|
|
46
46
|
-- \u6587\u4EF6\u5143\u4FE1\u606F
|
|
47
47
|
CREATE TABLE IF NOT EXISTS files (
|
|
48
48
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -193,7 +193,7 @@ import*as q from'path';import q__default from'path';import {fileURLToPath}from'u
|
|
|
193
193
|
CREATE INDEX IF NOT EXISTS idx_symbols_name ON symbols(name);
|
|
194
194
|
CREATE INDEX IF NOT EXISTS idx_symbols_framework ON symbols(framework);
|
|
195
195
|
CREATE INDEX IF NOT EXISTS idx_behaviors_file ON behaviors(file_id);
|
|
196
|
-
`);let{applied:e,errors:t}=
|
|
196
|
+
`);let{applied:e,errors:t}=Nn(this.db);e.length>0&&process.stderr.write(`[Frontend-Code-Skimmer] \u6570\u636E\u5E93\u8FC1\u79FB\u5B8C\u6210: v${e.join(", v")}
|
|
197
197
|
`),t.length>0&&process.stderr.write(`[Frontend-Code-Skimmer] \u8FC1\u79FB\u8B66\u544A: ${t.join("; ")}
|
|
198
198
|
`),this.db.exec(`
|
|
199
199
|
CREATE INDEX IF NOT EXISTS idx_behaviors_api_lc ON behaviors(api_name_lc, operation_lc);
|
|
@@ -236,44 +236,44 @@ import*as q from'path';import q__default from'path';import {fileURLToPath}from'u
|
|
|
236
236
|
INSERT INTO relations_fts(rowid, args)
|
|
237
237
|
VALUES (new.id, new.args);
|
|
238
238
|
END;
|
|
239
|
-
`);}saveParseResult(e,t,n,r,s,
|
|
239
|
+
`);}saveParseResult(e,t,n,r,s,o,a=0,c="",l=""){let u=te__default.extname(t).slice(1),d=kr(t,n);this.db.transaction(()=>{this.clearIndexFailures(n);let h=this.db.prepare("SELECT id FROM files WHERE path = ?").get(n),m;h?(m=h.id,this.db.prepare("DELETE FROM symbols WHERE file_id = ?").run(m),this.db.prepare(`
|
|
240
240
|
UPDATE files SET
|
|
241
241
|
abs_path = ?, framework = ?, content_hash = ?,
|
|
242
242
|
last_indexed_at = ?, file_size = ?, line_count = ?, file_mtime = ?,
|
|
243
243
|
path_lc = LOWER(?),
|
|
244
244
|
export_signature_hash = ?, import_signature_hash = ?
|
|
245
245
|
WHERE id = ?
|
|
246
|
-
`).run(t,e.framework,r,Date.now(),s,
|
|
246
|
+
`).run(t,e.framework,r,Date.now(),s,o,a,n,c,l,m)):m=this.db.prepare(`
|
|
247
247
|
INSERT INTO files (path, path_lc, abs_path, file_type, framework, content_hash, last_indexed_at, file_size, line_count, file_mtime, export_signature_hash, import_signature_hash)
|
|
248
248
|
VALUES (?, LOWER(?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
249
|
-
`).run(n,n,t,
|
|
249
|
+
`).run(n,n,t,u,e.framework,r,Date.now(),s,o,a,c,l).lastInsertRowid;let f=this.db.prepare(`
|
|
250
250
|
INSERT INTO symbols (file_id, name, name_lc, category, category_lc, framework, start_line, end_line,
|
|
251
251
|
signature, params_json, default_value, camel_words, jsdoc,
|
|
252
252
|
is_async, hook_deps_json, state_setter_name, parent_component)
|
|
253
253
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
254
|
-
`),g=new Map,y=new Map,S
|
|
254
|
+
`),g=new Map,y=new Map,E=S=>S.internalKey||`${S.name}:${S.startLine}:${S.endLine}`,_=(S,b)=>{g.set(E(S),b);let N=y.get(S.name)||[];N.push({id:b,name:S.name,startLine:S.startLine,endLine:S.endLine}),y.set(S.name,N);},x=(S,b,N)=>{if(N&&g.has(N))return g.get(N);let L=y.get(S)||[];if(L.length===0)return;if(L.length===1||b==null)return L[0]?.id;let I=L.filter(C=>C.startLine<=b&&b<=C.endLine);return I.length===1?I[0].id:I.length>1?I.sort((C,P)=>C.endLine-C.startLine-(P.endLine-P.startLine)||Math.abs(C.startLine-b)-Math.abs(P.startLine-b))[0]?.id:L.slice().sort((C,P)=>Math.abs(C.startLine-b)-Math.abs(P.startLine-b)||C.endLine-C.startLine-(P.endLine-P.startLine))[0]?.id};for(let S of e.symbols){let N=S.camelWords||k(S.name),L=S.name.toLowerCase(),I=S.category.toLowerCase(),C=f.run(m,S.name,L,S.category,I,S.framework,S.startLine,S.endLine,S.signature||null,S.params?JSON.stringify(S.params):null,S.defaultValue||null,N,S.jsdoc||null,S.isAsync?1:0,S.hookDeps?JSON.stringify(S.hookDeps):null,S.stateSetterName||null,S.parentComponent||null);_(S,C.lastInsertRowid);}let T=this.db.prepare(`
|
|
255
255
|
INSERT INTO relations (caller_id, callee_name, callee_name_lc, call_type, line_number, args,
|
|
256
256
|
source_kind, import_source, receiver_token, edge_kind)
|
|
257
257
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
258
|
-
`);for(let
|
|
258
|
+
`);for(let S of e.relations){let b=x(S.callerName,S.callerLine,S.callerKey);if(b){let N=S.sourceKind||tt(S.callType);T.run(b,S.calleeName,S.calleeName.toLowerCase(),S.callType,S.line,S.args||null,N,S.importSource||null,S.receiverToken||null,S.edgeKind||"heuristic");}}if(this.db.prepare("DELETE FROM data_assignments WHERE file_id = ?").run(m),e.assignments?.length){let S=this.db.prepare(`
|
|
259
259
|
INSERT INTO data_assignments (symbol_name, symbol_name_lc, file_id, kind, source_layer, line_number, text_snippet)
|
|
260
260
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
261
|
-
`);for(let
|
|
261
|
+
`);for(let b of e.assignments)S.run(b.symbolName,b.symbolName.toLowerCase(),m,b.kind,b.sourceLayer||"unknown",b.line,b.text);}if(this.db.prepare("DELETE FROM property_writes WHERE file_id = ?").run(m),e.propertyWrites?.length){let S=this.db.prepare(`
|
|
262
262
|
INSERT INTO property_writes (object_name, object_name_lc, property_name, property_name_lc, file_id, kind, source_layer, line_number, text_snippet)
|
|
263
263
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
264
|
-
`);for(let
|
|
264
|
+
`);for(let b of e.propertyWrites)S.run(b.objectName,b.objectName.toLowerCase(),b.propertyName||null,b.propertyName?.toLowerCase()||"",m,b.kind,b.sourceLayer||"unknown",b.line,b.text);}if(this.db.prepare("DELETE FROM file_dependencies WHERE from_file = ?").run(n),e.fileDependencies?.length){let S=this.db.prepare(`
|
|
265
265
|
INSERT INTO file_dependencies (from_file, to_file, dependency_kind, line_number)
|
|
266
266
|
VALUES (?, ?, ?, ?)
|
|
267
|
-
`);for(let
|
|
267
|
+
`);for(let b of e.fileDependencies)S.run(n,vr(b.toFile,t,d),b.dependencyKind,b.line);}let w=this.db.prepare(`
|
|
268
268
|
INSERT INTO behaviors (symbol_id, file_id, category, api_name, api_name_lc, operation, operation_lc, detail, detail_lc, line_number)
|
|
269
269
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
270
|
-
`);for(let
|
|
270
|
+
`);for(let S of e.behaviors){let b=x(S.symbolName,S.line,S.symbolKey);if(b){let N=S.detail||null;w.run(b,m,S.category,S.apiName,S.apiName.toLowerCase(),S.operation,S.operation.toLowerCase(),N,N?.toLowerCase()??"",S.line);}}if(e.errors?.length){let S=this.db.prepare(`
|
|
271
271
|
INSERT INTO index_failures (file_path, error, last_seen_at)
|
|
272
272
|
VALUES (?, ?, ?)
|
|
273
|
-
`),
|
|
273
|
+
`),b=Date.now();for(let N of e.errors)S.run(n,N,b);}})();}recordIndexFailure(e,t){this.clearIndexFailures(e),this.db.prepare(`
|
|
274
274
|
INSERT INTO index_failures (file_path, error, last_seen_at)
|
|
275
275
|
VALUES (?, ?, ?)
|
|
276
|
-
`).run(e,t,Date.now());}clearIndexFailures(e){this.db.prepare("DELETE FROM index_failures WHERE file_path = ?").run(e);}getFileHash(e){return this.db.prepare("SELECT content_hash FROM files WHERE path = ?").get(e)?.content_hash??null}getFileMeta(e){let t=this.db.prepare("SELECT content_hash, file_mtime, file_size FROM files WHERE path = ?").get(e);return t?{hash:t.content_hash,mtime:t.file_mtime??0,fileSize:t.file_size??0}:null}updateFileMtime(e,t){this.db.prepare("UPDATE files SET file_mtime = ? WHERE path = ?").run(t,e);}getFileSignatures(e){let t=this.db.prepare("SELECT content_hash, export_signature_hash, import_signature_hash FROM files WHERE path = ?").get(e);return t?{contentHash:t.content_hash,exportSignatureHash:t.export_signature_hash||"",importSignatureHash:t.import_signature_hash||""}:null}getReverseDependencies(e){return this.db.prepare("SELECT from_file FROM file_dependencies WHERE to_file = ? AND dependency_kind IN ('import', 're_export')").all(e).map(n=>n.from_file)}getReverseDependencyMap(){let e=this.db.prepare("SELECT from_file, to_file FROM file_dependencies WHERE dependency_kind IN ('import', 're_export')").all(),t=new Map;for(let{from_file:n,to_file:r}of e){let s=t.get(r)||[];s.push(n),t.set(r,s);}return t}getAllFilePaths(){return this.db.prepare("SELECT path FROM files ORDER BY path").all().map(t=>t.path)}getFileHashAndMtime(e){let t=this.db.prepare("SELECT content_hash, file_mtime FROM files WHERE path = ?").get(e);return t?{contentHash:t.content_hash,mtime:t.file_mtime??0}:null}enqueuePrecisePending(e,t){let n=Date.now(),r=
|
|
276
|
+
`).run(e,t,Date.now());}clearIndexFailures(e){this.db.prepare("DELETE FROM index_failures WHERE file_path = ?").run(e);}getFileHash(e){return this.db.prepare("SELECT content_hash FROM files WHERE path = ?").get(e)?.content_hash??null}getFileMeta(e){let t=this.db.prepare("SELECT content_hash, file_mtime, file_size FROM files WHERE path = ?").get(e);return t?{hash:t.content_hash,mtime:t.file_mtime??0,fileSize:t.file_size??0}:null}updateFileMtime(e,t){this.db.prepare("UPDATE files SET file_mtime = ? WHERE path = ?").run(t,e);}getFileSignatures(e){let t=this.db.prepare("SELECT content_hash, export_signature_hash, import_signature_hash FROM files WHERE path = ?").get(e);return t?{contentHash:t.content_hash,exportSignatureHash:t.export_signature_hash||"",importSignatureHash:t.import_signature_hash||""}:null}getReverseDependencies(e){return this.db.prepare("SELECT from_file FROM file_dependencies WHERE to_file = ? AND dependency_kind IN ('import', 're_export')").all(e).map(n=>n.from_file)}getReverseDependencyMap(){let e=this.db.prepare("SELECT from_file, to_file FROM file_dependencies WHERE dependency_kind IN ('import', 're_export')").all(),t=new Map;for(let{from_file:n,to_file:r}of e){let s=t.get(r)||[];s.push(n),t.set(r,s);}return t}getAllFilePaths(){return this.db.prepare("SELECT path FROM files ORDER BY path").all().map(t=>t.path)}getFileHashAndMtime(e){let t=this.db.prepare("SELECT content_hash, file_mtime FROM files WHERE path = ?").get(e);return t?{contentHash:t.content_hash,mtime:t.file_mtime??0}:null}enqueuePrecisePending(e,t){let n=Date.now(),r=o=>o==="high"?3:o==="normal"?2:1,s=this.db.prepare("SELECT priority, added_at FROM precise_pending WHERE rel_path = ?").get(e);if(!s){this.db.prepare("INSERT INTO precise_pending (rel_path, priority, added_at) VALUES (?, ?, ?)").run(e,t,n);return}r(t)>r(s.priority)&&this.db.prepare("UPDATE precise_pending SET priority = ? WHERE rel_path = ?").run(t,e);}deletePrecisePending(e){this.db.prepare("DELETE FROM precise_pending WHERE rel_path = ?").run(e);}clearPrecisePending(){this.db.prepare("DELETE FROM precise_pending").run();}getPrecisePendingCount(){return this.db.prepare("SELECT COUNT(*) as count FROM precise_pending").get().count}listPrecisePending(){return this.db.prepare(`
|
|
277
277
|
SELECT rel_path, priority
|
|
278
278
|
FROM precise_pending
|
|
279
279
|
ORDER BY CASE priority WHEN 'high' THEN 0 WHEN 'normal' THEN 1 ELSE 2 END, added_at
|
|
@@ -295,18 +295,18 @@ import*as q from'path';import q__default from'path';import {fileURLToPath}from'u
|
|
|
295
295
|
SELECT s.*, f.path as file_path, f.abs_path
|
|
296
296
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
297
297
|
WHERE s.name_lc = ?
|
|
298
|
-
`,
|
|
298
|
+
`,o=[e.toLowerCase()];return t&&(s+=" AND s.category_lc = ?",o.push(t.toLowerCase())),n&&(s+=" AND s.framework = ?",o.push(n)),r&&(s+=" AND f.path_lc LIKE ?",o.push(`%${r.toLowerCase()}%`)),s+=" LIMIT 30",this.db.prepare(s).all(...o)}ftsSearch(e,t,n,r,s=20,o=true){let a=Math.max(1,Math.min(200,s)),l=e.replace(/[^\w\u4e00-\u9fa5\s]/g," ").trim().split(/\s+/).filter(u=>u.length>=2);if(l.length>0){let u=l.map(d=>`${d}*`).join(" ");try{let d=`
|
|
299
299
|
SELECT s.*, f.path as file_path, f.abs_path,
|
|
300
300
|
bm25(symbols_fts, 10.0, 1.0, 0.5, 0.5) as fts_rank
|
|
301
301
|
FROM symbols_fts
|
|
302
302
|
JOIN symbols s ON symbols_fts.rowid = s.id
|
|
303
303
|
JOIN files f ON s.file_id = f.id
|
|
304
304
|
WHERE symbols_fts MATCH ?
|
|
305
|
-
`,
|
|
305
|
+
`,p=[u];return t&&(d+=" AND s.category_lc = ?",p.push(t.toLowerCase())),n&&(d+=" AND s.framework = ?",p.push(n)),r&&(d+=" AND f.path_lc LIKE ?",p.push(`%${r.toLowerCase()}%`)),d+=` ORDER BY fts_rank LIMIT ${a}`,this.db.prepare(d).all(...p)}catch{if(o)return []}}return o?[]:this.ftsLikeFallback(e,t,n,r,a)}ftsSearchWithFallback(e,t,n,r,s=20){return this.ftsSearch(e,t,n,r,s,false)}ftsLikeFallback(e,t,n,r,s=20){let o=e.toLowerCase().replace(/[\\%_]/g,"\\$&"),a=`
|
|
306
306
|
SELECT s.*, f.path as file_path, f.abs_path, 0 as fts_rank
|
|
307
307
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
308
308
|
WHERE (s.name_lc LIKE ? OR LOWER(s.camel_words) LIKE ?) ESCAPE '\\'
|
|
309
|
-
`,c=[`%${
|
|
309
|
+
`,c=[`%${o}%`,`%${o}%`];return t&&(a+=" AND s.category_lc = ?",c.push(t.toLowerCase())),n&&(a+=" AND s.framework = ?",c.push(n)),r&&(a+=" AND f.path_lc LIKE ?",c.push(`%${r.toLowerCase()}%`)),a+=` LIMIT ${Math.max(1,Math.min(200,s))}`,this.db.prepare(a).all(...c)}getAllSymbolNames(e){let t=`
|
|
310
310
|
SELECT DISTINCT s.name, f.path as file_path, s.id
|
|
311
311
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
312
312
|
`,n=[];return e&&(t+=" WHERE f.path_lc LIKE ?",n.push(`%${e.toLowerCase()}%`)),this.db.prepare(t).all(...n)}getSymbolById(e){return this.db.prepare(`
|
|
@@ -353,14 +353,14 @@ import*as q from'path';import q__default from'path';import {fileURLToPath}from'u
|
|
|
353
353
|
s.parent_component IS NULL DESC,
|
|
354
354
|
f.line_count DESC
|
|
355
355
|
LIMIT 1
|
|
356
|
-
`).get(e.toLowerCase())}behaviorSearch(e,t,n,r,s){let
|
|
356
|
+
`).get(e.toLowerCase())}behaviorSearch(e,t,n,r,s){let o=`
|
|
357
357
|
SELECT b.*, s.name as symbol_name, s.start_line, s.end_line, s.category as symbol_category,
|
|
358
358
|
f.path as file_path
|
|
359
359
|
FROM behaviors b
|
|
360
360
|
JOIN symbols s ON b.symbol_id = s.id
|
|
361
361
|
JOIN files f ON b.file_id = f.id
|
|
362
362
|
WHERE 1=1
|
|
363
|
-
`,a=[];return e&&(
|
|
363
|
+
`,a=[];return e&&(o+=" AND b.category = ?",a.push(e)),t&&(o+=" AND b.api_name_lc = ?",a.push(t.toLowerCase())),n&&(o+=" AND b.operation_lc = ?",a.push(n.toLowerCase())),r&&(o+=" AND (b.detail_lc LIKE ? OR b.api_name_lc LIKE ?)",a.push(`%${r.toLowerCase()}%`,`%${r.toLowerCase()}%`)),s&&(o+=" AND f.path_lc LIKE ?",a.push(`%${s.toLowerCase()}%`)),o+=" ORDER BY f.path, b.line_number LIMIT 50",this.db.prepare(o).all(...a)}getCallers(e,t,n){let r=`
|
|
364
364
|
SELECT r.*, s.name as caller_name, s.start_line, s.end_line, s.category,
|
|
365
365
|
f.path as file_path
|
|
366
366
|
FROM relations r
|
|
@@ -379,14 +379,14 @@ import*as q from'path';import q__default from'path';import {fileURLToPath}from'u
|
|
|
379
379
|
JOIN symbols s ON r.caller_id = s.id
|
|
380
380
|
JOIN files f ON s.file_id = f.id
|
|
381
381
|
WHERE fts.args MATCH ?
|
|
382
|
-
`,a=[`"${r.replace(/"/g,'""')}"`];t&&(s+=" AND f.path_lc LIKE ?",a.push(`%${t.toLowerCase()}%`)),s+=" ORDER BY f.path, r.line_number LIMIT ?",a.push(n);let c=[],l=false,
|
|
382
|
+
`,a=[`"${r.replace(/"/g,'""')}"`];t&&(s+=" AND f.path_lc LIKE ?",a.push(`%${t.toLowerCase()}%`)),s+=" ORDER BY f.path, r.line_number LIMIT ?",a.push(n);let c=[],l=false,u=false;try{c=this.db.prepare(s).all(...a),c.length>0&&(l=!0);}catch{u=true;}let d=/[^a-zA-Z0-9_\u4e00-\u9fa5]/.test(r);if(!l&&(u||d)){let h=r.replace(/[\\%_]/g,"\\$&"),m=`
|
|
383
383
|
SELECT r.*, s.name as caller_name, s.start_line, s.end_line, s.category,
|
|
384
384
|
f.path as file_path
|
|
385
385
|
FROM relations r
|
|
386
386
|
JOIN symbols s ON r.caller_id = s.id
|
|
387
387
|
JOIN files f ON s.file_id = f.id
|
|
388
388
|
WHERE LOWER(COALESCE(r.args, '')) LIKE LOWER(?) ESCAPE '\\'
|
|
389
|
-
`,
|
|
389
|
+
`,f=[`%${h}%`];t&&(m+=" AND f.path_lc LIKE ?",f.push(`%${t.toLowerCase()}%`)),m+=" ORDER BY f.path, r.line_number LIMIT ?",f.push(n),c=this.db.prepare(m).all(...f);}return c}getLastIndexedTime(){return this.db.prepare("SELECT MAX(last_indexed_at) as ts FROM files").get()?.ts??null}getProjectStats(){let e=this.db.prepare("SELECT COUNT(*) as c FROM files").get().c,t=this.db.prepare("SELECT COUNT(*) as c FROM symbols").get().c,n=this.db.prepare("SELECT COUNT(*) as c FROM behaviors").get().c,r=this.db.prepare("SELECT COUNT(*) as c FROM relations").get().c,s=this.db.prepare("SELECT COUNT(*) as c FROM index_failures").get().c,o=this.db.prepare(`
|
|
390
390
|
SELECT framework, COUNT(*) as count FROM files GROUP BY framework
|
|
391
391
|
`).all(),a=this.db.prepare(`
|
|
392
392
|
SELECT f.path, f.line_count, COUNT(s.id) as symbol_count
|
|
@@ -395,7 +395,7 @@ import*as q from'path';import q__default from'path';import {fileURLToPath}from'u
|
|
|
395
395
|
ORDER BY f.line_count DESC LIMIT 10
|
|
396
396
|
`).all(),c=this.db.prepare(`
|
|
397
397
|
SELECT category, COUNT(*) as count FROM behaviors GROUP BY category ORDER BY count DESC
|
|
398
|
-
`).all(),l=this.db.prepare("SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size()").get()?.size??0;return {fileCount:e,symbolCount:t,behaviorCount:n,relationCount:r,failureCount:s,frameworkBreakdown:
|
|
398
|
+
`).all(),l=this.db.prepare("SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size()").get()?.size??0;return {fileCount:e,symbolCount:t,behaviorCount:n,relationCount:r,failureCount:s,frameworkBreakdown:o,topFiles:a,behaviorStats:c,dbSize:l}}getIndexFailures(e=20){return this.db.prepare(`
|
|
399
399
|
SELECT file_path, error, last_seen_at
|
|
400
400
|
FROM index_failures
|
|
401
401
|
ORDER BY last_seen_at DESC, id DESC
|
|
@@ -415,53 +415,54 @@ import*as q from'path';import q__default from'path';import {fileURLToPath}from'u
|
|
|
415
415
|
SELECT pw.*, f.path as file_path
|
|
416
416
|
FROM property_writes pw JOIN files f ON pw.file_id = f.id
|
|
417
417
|
WHERE pw.object_name_lc = ?
|
|
418
|
-
`,
|
|
418
|
+
`,o=[e.toLowerCase()];return t&&(s+=" AND pw.property_name_lc = ?",o.push(t.toLowerCase())),n&&(s+=" AND f.path_lc LIKE ?",o.push(`%${n.toLowerCase()}%`)),s+=" ORDER BY f.path, pw.line_number LIMIT ?",o.push(r),this.db.prepare(s).all(...o)}getCallersWithSourceKind(e,t,n){let r=`
|
|
419
419
|
SELECT r.*, s.name as caller_name, s.start_line, s.end_line, s.category,
|
|
420
420
|
f.path as file_path
|
|
421
421
|
FROM relations r
|
|
422
422
|
JOIN symbols s ON r.caller_id = s.id
|
|
423
423
|
JOIN files f ON s.file_id = f.id
|
|
424
424
|
WHERE r.callee_name_lc = ?
|
|
425
|
-
`,s=[e.toLowerCase()];return t&&(r+=" AND f.path_lc LIKE ?",s.push(`%${t.toLowerCase()}%`)),n&&(r+=" AND LOWER(COALESCE(r.args, '')) LIKE LOWER(?)",s.push(`%${n}%`)),r+=" ORDER BY f.path, r.line_number",this.db.prepare(r).all(...s)}close(){this.db.close();}};function
|
|
426
|
-
`);for(let s=0;s<r.length;s++){let
|
|
427
|
-
`));}function
|
|
428
|
-
`),l;try{l=
|
|
429
|
-
`).length;n.symbols.push({name:"<template>",category:"lifecycle",framework:"vue2",startLine:
|
|
430
|
-
`&&n++;return n}extractFromAST(e,t,n,r,s){let
|
|
431
|
-
`);s.fileDependencies=
|
|
432
|
-
`),
|
|
433
|
-
`),
|
|
434
|
-
`),
|
|
435
|
-
`),a=!!s.scriptSetup,c=!!s.script;if(a){let l=s.scriptSetup,
|
|
436
|
-
`).length;n.symbols.push({name:"<template>",category:"lifecycle",framework:"vue3",startLine:l,endLine:l+
|
|
437
|
-
`),c=s.program.body;r.fileDependencies=
|
|
438
|
-
`);r.fileDependencies=
|
|
439
|
-
`),t(
|
|
440
|
-
`),t(c)),
|
|
441
|
-
`),c);if(
|
|
442
|
-
`);this.extractFromAST(s.program?s.program:s,
|
|
443
|
-
`),l),camelWords:
|
|
444
|
-
`),a),
|
|
445
|
-
`),a),
|
|
446
|
-
`),
|
|
447
|
-
`),c=(
|
|
448
|
-
`),
|
|
449
|
-
`),
|
|
450
|
-
`),a),camelWords:
|
|
451
|
-
`),{assignments:l,propertyWrites:
|
|
452
|
-
`)):"",s=[];if(
|
|
453
|
-
`)):"";return {contentHash:t,exportSignatureHash:r,importSignatureHash:
|
|
454
|
-
`);for(let r of e){let s=r.result.errors||[];s.includes(n)||(r.result.errors=[...s,n]);}}}enqueuePrecise(e,t){this.scheduler.enqueue(e,t),this.db.enqueuePrecisePending(e,t);}hydratePendingPreciseQueue(){for(let e of this.db.listPrecisePending())this.scheduler.enqueue(e.relPath,e.priority);}enqueueAffectedPrecise(e,t){if(t==="unchanged")return;let n=this.db.getReverseDependencyMap(),{files:r,truncated:s}=
|
|
455
|
-
`);let
|
|
456
|
-
`);for(let
|
|
457
|
-
`);}}
|
|
458
|
-
`);}let
|
|
459
|
-
`),{reindexedFiles:h,affectedFiles:Array.from(a),skippedByBudget:
|
|
460
|
-
`);}catch(
|
|
461
|
-
`);}};return t.on("add",n).on("change",n).on("unlink",r=>{let s=
|
|
462
|
-
`);})
|
|
425
|
+
`,s=[e.toLowerCase()];return t&&(r+=" AND f.path_lc LIKE ?",s.push(`%${t.toLowerCase()}%`)),n&&(r+=" AND LOWER(COALESCE(r.args, '')) LIKE LOWER(?)",s.push(`%${n}%`)),r+=" ORDER BY f.path, r.line_number",this.db.prepare(r).all(...s)}close(){this.db.close();}};function G(i){let e=i.property;return e?e.type==="Identifier"?String(e.name||""):e.type==="Literal"||e.type==="StringLiteral"?String(e.value||""):null:null}function se(i){let e=i.object;return e?e.type==="Identifier"?String(e.name||""):e.type==="ThisExpression"?G(i):e.type==="MemberExpression"?e.object?.type==="ThisExpression"?G(e):se(e):null:null}function ie(i,e){let t=i||"";return /created|mounted|beforeMount|setup\s*\(|\bdata\s*\(/.test(t)?"init":/getItem|localStorage|sessionStorage|\bfetch\b|\bload[A-Z]|\bget[A-Z]/.test(t)?"cache":/@click|@change|@input|onClick|onChange|handle[A-Z]|\bwatch\b/.test(t)?"user":e<=30?"init":"unknown"}function J(i,e,t,n=false){let r=[];return q(i,o=>{if(n&&o!==i&&(o.type==="FunctionDeclaration"||o.type==="ArrowFunctionExpression"||o.type==="FunctionExpression"||o.type==="ClassDeclaration"))return false;if(o.type==="CallExpression"||o.type==="OptionalCallExpression"){let c=Cr(o,e);c&&r.push(c);}if(o.type==="MemberExpression"){let a=Ir(o);a&&r.push(a);}}),jr(r)}function Cr(i,e,t){let n=i.callee;if(!n)return null;let r=Ve(i);if(n.type==="MemberExpression"||n.type==="OptionalMemberExpression"){let s=$r(n);if(!s)return null;let{apiName:o,operation:a}=s,c=i.arguments,l=le(c?.[0]),u=Dr(o);return u?{symbolName:e,category:u,apiName:o,operation:a,detail:l,line:r}:o==="this"&&ot(a)?{symbolName:e,category:"network",apiName:`this.${a}`,operation:"wrapped_call",detail:l||le(c?.[1]),line:r}:Sn(a)&&Mr(c)?{symbolName:e,category:"network",apiName:o,operation:a,detail:l||le(c?.[1]),line:r}:ot(o)||ot(`${o}.${a}`)?{symbolName:e,category:"network",apiName:o,operation:Sn(a)?a:"wrapped_call",detail:l||le(c?.[1]),line:r}:null}if(n.type==="Identifier"){let s=n.name,o=Pr(s),a=i.arguments,c=le(a?.[0]);return o?{symbolName:e,category:o.category,apiName:s,operation:o.operation,detail:c,line:r}:ot(s)?{symbolName:e,category:"network",apiName:s,operation:"wrapped_call",detail:c||le(a?.[1]),line:r}:null}return null}function Ir(i,e,t){let n=i.object,r=i.property;if(!n||!r||n.type!=="MemberExpression"&&n.type!=="ThisExpression"&&n.type!=="Identifier")return null;let s=Or(n);if(!s)return null;r.type==="Identifier"?r.name:"";if(s==="this"||s===""){n.type==="MemberExpression"?n.property?.name:"";return null}return null}function $r(i){let e=i.object,t=i.property;if(!e||!t||t.type!=="Identifier")return null;let n=t.name;if(e.type==="MemberExpression"||e.type==="OptionalMemberExpression"){let r=e.property?.name;if(r)return {apiName:r,operation:n}}return e.type==="Identifier"?{apiName:e.name,operation:n}:e.type==="ThisExpression"?{apiName:"this",operation:n}:null}function Pr(i){let e={fetch:"network",setTimeout:"timer",setInterval:"timer",clearTimeout:"timer",clearInterval:"timer",requestAnimationFrame:"timer",navigate:"router"};return e[i]?{category:e[i],operation:i}:null}function Ve(i){return i.loc?.start?.line??0}function Fr(i){let e=i.loc;return {line:e?.start?.line??0,column:e?.start?.column??0}}function Or(i){return i.type==="Identifier"?i.name:i.type==="ThisExpression"?"this":null}function Dr(i){if(i==="this")return null;for(let[e,t]of Object.entries(fn))if(i in t)return e;return null}function le(i,e){if(i){if(i.type==="Literal"||i.type==="StringLiteral"||i.type==="NumericLiteral"||i.type==="BooleanLiteral")return String(i.value);if(i.type==="NullLiteral")return "null";if(i.type==="TemplateLiteral"){let t=i.quasis,n=i.expressions||[],r=[];for(let o=0;o<t.length;o++){let a=t[o].value?.cooked||"";if(a&&r.push(a),o<n.length){let c=at(n[o])||"expr";r.push(`\${${c}}`);}}return r.join("")||"${expr}"}if(i.type==="Identifier")return `[\u53D8\u91CF: ${i.name}]`;if(i.type==="ObjectExpression"){let t=i.properties||[],n=["url","uri","path","api","endpoint"];for(let r of t){let s=r.key,o=r.value;if(!s||!o)continue;let a=s.type==="Identifier"?String(s.name):s.type==="Literal"?String(s.value):"";if(!n.includes(a))continue;let c=le(o);if(c)return `${a}:${c}`}return "{...}"}}}function at(i,e){if(!i)return;if(i.type==="Identifier")return i.name;if(i.type==="ThisExpression")return "this";if(i.type==="Literal"||i.type==="StringLiteral"||i.type==="NumericLiteral"||i.type==="BooleanLiteral")return String(i.value);if(i.type==="NullLiteral")return "null";if(i.type==="MemberExpression"){let n=at(i.object)||"obj",r=i.property,s=r?.type==="Identifier"?String(r.name):at(r)||"prop";return i.computed?`${n}[${s}]`:`${n}.${s}`}if(i.type==="CallExpression")return `${at(i.callee)||"fn"}(...)`;if(i.type==="TemplateLiteral")return le(i);let t=le(i);return t?.startsWith("[\u53D8\u91CF: ")?t.replace(/^\[变量: /,"").replace(/\]$/,""):t}function ot(i){return /request|api|http|fetch|ajax|akscommonhandle|commonhandle/i.test(i)}function Sn(i){return ["get","post","put","delete","patch","request"].includes(i.toLowerCase())}function Mr(i,e){if(!i||i.length===0)return false;for(let t of i.slice(0,2)){let n=le(t);if(n&&(/https?:\/\//i.test(n)||n.includes("/")||/gw\d?\/|\/m\/|\/api\//i.test(n)))return true}return false}function jr(i){let e=new Set;return i.filter(t=>{let n=`${t.apiName}:${t.operation}:${t.line}`;return e.has(n)?false:(e.add(n),true)})}function ve(i,e,t){let n=[];return q(i,r=>{if(r.type==="CallExpression"&&r.callee?.type==="MemberExpression"){let s=r.callee,o=s.object,a=s.property;if(o.type==="ThisExpression"&&a.type==="Identifier"){let c=a.name;if(!c.startsWith("$")&&c!==e){let l=r.arguments,u=ut(l);n.push({calleeName:c,line:Ve(r),args:u});}}}}),n}function Q(i,e,t,n=false){let r=[];return q(i,o=>{if(n&&o!==i&&(o.type==="FunctionDeclaration"||o.type==="ArrowFunctionExpression"||o.type==="FunctionExpression"||o.type==="ClassDeclaration"))return false;if(o.type==="CallExpression"&&o.callee?.type==="Identifier"){let a=o.callee.name;if(a!==e&&!xn(a)){let c=o.arguments,l=ut(c);r.push({calleeName:a,line:Ve(o),args:l});}}}),pt(r)}function Tn(i,e,t){let n=[];return q(i,s=>{if(s!==i&&(s.type==="FunctionDeclaration"||s.type==="ArrowFunctionExpression"||s.type==="FunctionExpression"||s.type==="ClassDeclaration"))return false;if(s.type!=="CallExpression"&&s.type!=="OptionalCallExpression")return;let o=s.arguments||[];for(let a of o)a.type!=="ArrowFunctionExpression"&&a.type!=="FunctionExpression"||(n.push(...Q(a,e,t,true)),n.push(...ve(a,e)),n.push(...ct(a,e,t,true)),n.push(...lt(a,e,t,true)));}),pt(n)}function ct(i,e,t,n=false){let r=[];return q(i,o=>{if(n&&o!==i&&(o.type==="FunctionDeclaration"||o.type==="ArrowFunctionExpression"||o.type==="FunctionExpression"||o.type==="ClassDeclaration"))return false;if(o.type!=="CallExpression"&&o.type!=="OptionalCallExpression")return;let a=o.callee;if(!a||a.type!=="MemberExpression"&&a.type!=="OptionalMemberExpression")return;let c=a.object;if(!c||c.type==="ThisExpression")return;let l=se(a),u=G(a);if(!l||!u||u===e||Br(l)||xn(u))return;let d=o.arguments,p=ut(d);r.push({calleeName:u,line:Ve(o),args:p,receiverToken:l});}),pt(r)}function lt(i,e,t,n=false){let r=[];return q(i,o=>{if(n&&o!==i&&(o.type==="FunctionDeclaration"||o.type==="ArrowFunctionExpression"||o.type==="FunctionExpression"||o.type==="ClassDeclaration"))return false;if(o.type!=="NewExpression")return;let a=o.callee;if(!a||a.type!=="Identifier")return;let c=String(a.name||"");if(!c||c===e||Wr(c))return;let l=o.arguments;r.push({calleeName:c,line:Ve(o),args:ut(l)});}),pt(r)}function xn(i){return /^(useState|useEffect|useMemo|useCallback|useRef|useContext|useReducer|ref|reactive|computed|watch|watchEffect|console|setTimeout|setInterval|Math|Object|Array|JSON|String|Number|Boolean|Promise|require|import|trim|toLowerCase|toUpperCase|split|join|slice|substring|substr|replace|match|test|startsWith|endsWith|includes|map|filter|reduce|forEach|some|every|find|findIndex|push|pop|shift|unshift|splice|sort|reverse|concat|flat|flatMap|set|get|has|add|delete|clear|keys|values|entries)$/.test(i)}function Br(i){return /^(console|Math|Object|Array|JSON|String|Number|Boolean|Promise|Reflect|Date|Error|RegExp|Symbol|process|fs|path|os|assert|test|document|window|localStorage|sessionStorage|navigator|global|globalThis)$/.test(i)}function Wr(i){return /^(Object|Array|Map|Set|WeakMap|WeakSet|Date|Error|RegExp|Promise|URL|URLSearchParams|AbortController|FormData|Blob|File|Buffer|String|Number|Boolean|Symbol)$/.test(i)}function pt(i){let e=new Set;return i.filter(t=>{let n=`${t.receiverToken||""}:${t.calleeName}:${t.line}:${t.args||""}`;return e.has(n)?false:(e.add(n),true)})}function ut(i,e){if(!i||i.length===0)return;let t=i.slice(0,3).map(n=>le(n)).filter(n=>!!n);return t.length>0?t.join(", "):void 0}function q(i,e){if(!(!i||typeof i!="object")&&e(i)!==false)for(let t of Object.keys(i)){if(t==="type"||t==="loc"||t==="start"||t==="end")continue;let n=i[t];if(Array.isArray(n))for(let r of n)r&&typeof r=="object"&&r.type&&q(r,e);else n&&typeof n=="object"&&n.type&&q(n,e);}}function dt(i,e){let t=[],n=new Set,r=i.split(`
|
|
426
|
+
`);for(let s=0;s<r.length;s++){let o=/(?:@|v-on:)[a-z][a-z0-9-]*(?:\.[a-z-]+)*="([^"]+)"/g,a;for(;(a=o.exec(r[s]))!==null;){let l=a[1].trim().match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(?:\([^)]*\))?$/);if(!l)continue;let u=l[1];if(u.startsWith("$"))continue;let d=e+s,p=`${u}:${d}:${a.index}`;n.has(p)||(n.add(p),t.push({calleeName:u,line:d}));}}return t}function An(i,e){let t=[],n=new Set;return q(i,r=>{if(r.type!=="JSXAttribute")return;let s=r.name,o=r.value;if(!s||!o)return;let a=s.type==="JSXIdentifier"?String(s.name):"";if(!/^on[A-Z]/.test(a)||o.type!=="JSXExpressionContainer")return;let c=o.expression;if(!c)return;let l;if(c.type==="Identifier")l=c.name;else if(c.type==="MemberExpression"){let h=c.property?.name;h&&!/^\$/.test(h)&&(l=h);}let{line:u,column:d}=Fr(r),p=`${l}:${u}:${d}`;!l||n.has(p)||(n.add(p),t.push({calleeName:l,line:u}));}),t}var Hr=createRequire(import.meta.url),Ln=false;function Xr(i){Ln||(Ln=true,process.stderr.write(`[Frontend-Code-Skimmer] precise import graph \u5DF2\u964D\u7EA7: ${String(i)}
|
|
427
|
+
`));}function Rn(i,e,t){let n={filePath:i,imports:[],exports:[]};try{let r=Hr("typescript"),s=r.createSourceFile(i,e,r.ScriptTarget.Latest,!0);r.forEachChild(s,o=>{if(r.isImportDeclaration(o)){let a=o.moduleSpecifier;if(!a||!r.isStringLiteral(a))return;let c=a.text,l=mt(i,c),u=o.importClause;if(!u){n.imports.push({localName:"",originalName:"",modulePath:c,resolvedFile:l,isDefault:!1,isReExport:!1});return}let d=u.namedBindings;if(d&&r.isNamedImports(d))for(let p of d.elements){let h=p.propertyName?p.propertyName.text:p.name.text;n.imports.push({localName:p.name.text,originalName:h,modulePath:c,resolvedFile:l,isDefault:!1,isReExport:!1});}d&&r.isNamespaceImport(d)&&n.imports.push({localName:d.name.text,originalName:"*",modulePath:c,resolvedFile:l,isDefault:!1,isReExport:!1}),u.name&&n.imports.push({localName:u.name.text,originalName:"default",modulePath:c,resolvedFile:l,isDefault:!0,isReExport:!1});}if(r.isExportDeclaration(o)){let a=o.moduleSpecifier;if(a&&r.isStringLiteral(a)){let c=a.text,l=o.exportClause;if(l&&r.isNamedExports(l))for(let u of l.elements)n.exports.push({name:u.name.text,isDefault:!1,source:"re_export",reExportFrom:c});}else if(o.exportClause){let c=o.exportClause;if(r.isNamedExports(c))for(let l of c.elements)n.exports.push({name:l.name.text,isDefault:!1,source:"local"});}}if(r.isExportAssignment(o)&&(o.isExportEquals||n.exports.push({name:"default",isDefault:!0,source:"local"})),(r.isFunctionDeclaration(o)||r.isVariableStatement(o)||r.isClassDeclaration(o))&&o.modifiers?.some(a=>a.kind===r.SyntaxKind.ExportKeyword)){if(r.isFunctionDeclaration(o)&&o.name)n.exports.push({name:o.name.text,isDefault:o.name.text==="default",source:"local"});else if(r.isClassDeclaration(o)&&o.name)n.exports.push({name:o.name.text,isDefault:o.name.text==="default",source:"local"});else if(r.isVariableStatement(o))for(let a of o.declarationList.declarations)r.isIdentifier(a.name)&&n.exports.push({name:a.name.text,isDefault:!1,source:"local"});}});}catch(r){Xr(r);}return n}function mt(i,e){let t=te.dirname(i);if(e.startsWith(".")){let n=te.resolve(t,e);return ke(n)}return e.startsWith("@/")?Kr(i,e):e}function Kr(i,e){let t=te.dirname(i);for(let n=0;n<10;n++){let r=te.join(t,"src");if(ne.existsSync(r)&&ne.statSync(r).isDirectory()){let o=te.join(r,e.replace(/^@\//,""));return ke(o)}let s=te.dirname(t);if(s===t)break;t=s;}return e}function W(i){return {callerName:i.callerName,callerLine:i.callerLine,callerKey:i.callerKey,calleeName:i.calleeName,callType:i.callType,line:i.line,args:i.args,sourceKind:tt(i.callType),importSource:i.importSource,receiverToken:i.receiverToken,edgeKind:i.edgeKind||"heuristic"}}function be(i,e){let t=[];for(let n of i){let r=n.type;if(r==="ImportDeclaration"){let s=n.source,o=n.loc;s?.value&&t.push({fromFile:e,toFile:mt(e,s.value),dependencyKind:"import",line:o?.start?.line??1});}if(r==="ExportNamedDeclaration"||r==="ExportAllDeclaration"){let s=n.source,o=n.loc;s?.value&&t.push({fromFile:e,toFile:mt(e,s.value),dependencyKind:"re_export",line:o?.start?.line??1});}}return t}function ht(i,e){let t=new Map(e.map(r=>[r.name,r])),n=[];for(let r of i){let s=r.type;if(s==="ExportNamedDeclaration"){let o=r.declaration,a=r.source;if(o){if(o.type==="FunctionDeclaration"||o.type==="ClassDeclaration"){let c=o.id;c?.name&&n.push(gt(c.name,t.get(c.name)));}else if(o.type==="VariableDeclaration")for(let c of o.declarations||[]){let l=c.id;l?.type==="Identifier"&&l.name&&n.push(gt(l.name,t.get(l.name)));}continue}for(let c of r.specifiers||[]){let l=Wt(c.local),u=Wt(c.exported)||l;u&&(a?.value?n.push(`re_export:${u}:${a.value}`):n.push(gt(u,l?t.get(l):void 0)));}continue}if(s==="ExportAllDeclaration"){let o=r.source;o?.value&&n.push(`re_export_all:${o.value}`);continue}if(s==="ExportDefaultDeclaration"){let o=r.declaration;if(!o){n.push("default:unknown");continue}if(o.type==="Identifier"){let a=Wt(o);n.push(gt("default",a?t.get(a):void 0));continue}if(o.type==="FunctionDeclaration"||o.type==="FunctionExpression"||o.type==="ArrowFunctionExpression"){let a=(o.params||[]).map(c=>Ut(c)).join(", ");n.push(`default:fn(${a})`);continue}if(o.type==="ClassDeclaration"||o.type==="ClassExpression"){n.push("default:class");continue}n.push(`default:${String(o.type||"unknown")}`);}}return n.sort()}function gt(i,e){return `${i}:${zr(e)}`}function zr(i){return i?i.category==="class"?"class":i.signature?`fn${i.signature.replace(/^[^(]*/,"")}`:i.category==="constant"?`const:${i.defaultValue||""}`:i.category:"unknown"}function Wt(i){if(i){if(i.type==="Identifier")return String(i.name||"");if(i.type==="StringLiteral")return String(i.value||"")}}function Ut(i){return i?i.type==="Identifier"?String(i.name||"param"):i.type==="AssignmentPattern"?Ut(i.left):i.type==="RestElement"?Ut(i.argument):"param":"param"}var wn=createRequire(import.meta.url);var De=class{name="Vue2Parser";canParse(e,t){return e.endsWith(".vue")}parse(e,t){let n={framework:"vue2",filePath:e,symbols:[],relations:[],behaviors:[],errors:[]};try{let s=wn("vue-template-compiler").parseComponent(t);if(!s.script?.content)return n;let o=s.script.content,a=this.getScriptStartLine(t,s.script.start),c=t.split(`
|
|
428
|
+
`),l;try{l=wn("@babel/parser").parse(o,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy"],errorRecovery:!0});}catch(u){return n.errors?.push(`AST \u89E3\u6790\u5931\u8D25: ${String(u)}`),n}if(this.extractFromAST(l.program,o,c,a,n),s.template?.content){let u=this.getScriptStartLine(t,s.template.start),d=dt(s.template.content,u);if(d.length>0){let p=s.template.content.split(`
|
|
429
|
+
`).length;n.symbols.push({name:"<template>",category:"lifecycle",framework:"vue2",startLine:u,endLine:u+p-1,camelWords:"template"});for(let h of d)n.relations.push(W({callerName:"<template>",callerLine:u,calleeName:h.calleeName,callType:"template_event",line:h.line}));}}}catch(r){n.errors?.push(`\u89E3\u6790\u5931\u8D25: ${String(r)}`);}return n}getScriptStartLine(e,t){let n=1;for(let r=0;r<t&&r<e.length;r++)e[r]===`
|
|
430
|
+
`&&n++;return n}extractFromAST(e,t,n,r,s){let o=t.split(`
|
|
431
|
+
`);s.fileDependencies=be(e.body||[],s.filePath);let a=null;q(e,d=>{if(d.type==="ExportDefaultDeclaration"){let p=d.declaration;if(p?.type==="ObjectExpression")a=p;else if(p?.type==="CallExpression"){let h=p.arguments;h&&h.length>0&&h[0].type==="ObjectExpression"&&(a=h[0]);}else if(p?.type==="Identifier"){let h=p.name;q(e,m=>{if(m.type==="VariableDeclarator"&&m.id?.name===h){if(m.init?.type==="ObjectExpression")a=m.init;else if(m.init?.type==="CallExpression"){let f=m.init.arguments;f&&f.length>0&&f[0].type==="ObjectExpression"&&(a=f[0]);}}});}}});let l=false;if(!a&&(q(e,d=>{d.type==="ExportDefaultDeclaration"&&d.declaration?.type==="ClassDeclaration"&&(l=true,this.extractFromClassComponent(d.declaration,t,n,r,s));}),!l)){let d=null,p=0,h=["data","methods","computed","props","watch","components","created","mounted","mixins"];q(e,m=>{if(m.type==="ObjectExpression"){let f=m.properties||[],g=0;for(let y of f){let E=this.getPropKey(y);E&&h.includes(E)&&g++;}g>p&&(p=g,d=m);}}),p>=2&&d&&(a=d);}if(!a)return;let u=a.properties;for(let d of u||[]){let p=this.getPropKey(d);if(!p)continue;let h=d.type==="ObjectMethod"?d:d.value;if(!h)continue;let m=f=>f+r-1;switch(p){case "name":h?.type==="Literal"&&(String(h.value));break;case "data":this.extractData(h,o,m,s);break;case "props":this.extractProps(h,o,m,s);break;case "computed":this.extractComputedOrMethods(h,"computed",o,m,n,s);break;case "methods":this.extractComputedOrMethods(h,"method",o,m,n,s);break;case "watch":this.extractWatch(h,o,m,s);break;case "filters":this.extractComputedOrMethods(h,"filter",o,m,n,s);break;case "components":this.extractComponents(h,s);break;case "mixins":this.extractMixins(h,s);break;default:if(Ot.includes(p)){let f=m(this.getStartLine(d)),g=m(this.getEndLine(d)),y=Y(n.join(`
|
|
432
|
+
`),f),E=s.symbols.length;s.symbols.push({name:p,category:"lifecycle",framework:"vue2",startLine:f,endLine:g,jsdoc:y,camelWords:k(p)});let _=J(h,p);s.behaviors.push(..._);let x=ve(h,p);for(let T of x){if(T.args){let w=String(T.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[E].camelWords+=` ${k(w)} ${w}`;}s.relations.push(W({callerName:p,callerLine:f,calleeName:T.calleeName,callType:"this_method",line:m(T.line),args:T.args}));}}break}}}extractData(e,t,n,r){let s=null;if(e.type==="FunctionExpression"||e.type==="ArrowFunctionExpression"||e.type==="ObjectMethod"?q(e.body,o=>{o.type==="ReturnStatement"&&o.argument?.type==="ObjectExpression"&&(s=o.argument);}):e.type==="ObjectExpression"&&(s=e),!!s)for(let o of s.properties){let a=this.getPropKey(o);if(!a)continue;let c=n(this.getStartLine(o)),l=n(this.getEndLine(o)),u=this.getLiteralValue(o.value);r.symbols.push({name:a,category:"state",framework:"vue2",startLine:c,endLine:l,defaultValue:u,camelWords:k(a)});}}extractProps(e,t,n,r){if(e.type==="ArrayExpression"){for(let s of e.elements||[])if(s?.type==="Literal"){let o=String(s.value);r.symbols.push({name:o,category:"prop",framework:"vue2",startLine:n(this.getStartLine(s)),endLine:n(this.getEndLine(s)),camelWords:k(o)});}}else if(e.type==="ObjectExpression")for(let s of e.properties||[]){let o=this.getPropKey(s);if(!o)continue;let a=n(this.getStartLine(s)),c=n(this.getEndLine(s)),l;if(s.value?.type==="ObjectExpression"){let u=s.value.properties?.find(d=>this.getPropKey(d)==="default");u&&(l=this.getLiteralValue(u.value));}r.symbols.push({name:o,category:"prop",framework:"vue2",startLine:a,endLine:c,defaultValue:l,camelWords:k(o)});}}extractComputedOrMethods(e,t,n,r,s,o){if(e.type==="ObjectExpression")for(let a of e.properties||[]){let c=this.getPropKey(a);if(!c)continue;let l=a.type==="ObjectMethod"?a:a.value;if(!l)continue;let u=r(this.getStartLine(a)),d=r(this.getEndLine(a)),p=Y(s.join(`
|
|
433
|
+
`),u),h=this.extractParams(l),m=l.async===true,f=h?`${c}(${h.join(", ")})`:c;if(o.symbols.push({name:c,category:t,framework:"vue2",startLine:u,endLine:d,signature:f,params:h,isAsync:m,jsdoc:p,camelWords:k(c)}),t==="method"&&l){let g=J(l,c);o.behaviors.push(...g);let y=ve(l,c);for(let _ of y){if(_.args){let x=String(_.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");o.symbols[o.symbols.length-1].camelWords+=` ${k(x)} ${x}`;}o.relations.push(W({callerName:c,callerLine:u,calleeName:_.calleeName,callType:"this_method",line:r(_.line),args:_.args}));}let E=Q(l,c,s,true);for(let _ of E){if(_.args){let x=String(_.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");o.symbols[o.symbols.length-1].camelWords+=` ${k(x)} ${x}`;}o.relations.push(W({callerName:c,callerLine:u,calleeName:_.calleeName,callType:"direct_call",line:r(_.line),args:_.args}));}}}}extractWatch(e,t,n,r){if(e.type==="ObjectExpression")for(let s of e.properties||[]){let o=this.getPropKey(s);if(!o)continue;let a=n(this.getStartLine(s)),c=n(this.getEndLine(s));r.symbols.push({name:o,category:"effect",framework:"vue2",startLine:a,endLine:c,camelWords:k(o)});}}extractComponents(e,t){if(e.type==="ObjectExpression")for(let n of e.properties||[]){let r=this.getPropKey(n);r&&t.symbols.push({name:r,category:"component",framework:"vue2",startLine:this.getStartLine(n),endLine:this.getEndLine(n),camelWords:k(r)});}}extractMixins(e,t){if(e.type==="ArrayExpression")for(let n of e.elements||[]){let r=n?.type==="Identifier"?n.name:null;r&&t.symbols.push({name:r,category:"mixin",framework:"vue2",startLine:this.getStartLine(n),endLine:this.getEndLine(n),camelWords:k(r)});}}getPropKey(e){if(!e)return null;let t=e.key;return t?t.type==="Identifier"?t.name:t.type==="Literal"?String(t.value):null:null}getStartLine(e){return e?.loc?.start?.line??1}getEndLine(e){return e?.loc?.end?.line??1}extractParams(e){if(!e)return;let t=e.params;if(t)return t.map(n=>n.type==="Identifier"?n.name:n.type==="AssignmentPattern"?n.left?.name||"?":n.type==="RestElement"?`...${n.argument?.name||""}`:n.type==="TSParameterProperty"&&n.parameter?.name||"?")}getLiteralValue(e){if(e){if(e.type==="Literal"||e.type==="StringLiteral"||e.type==="NumericLiteral"||e.type==="BooleanLiteral")return String(e.value);if(e.type==="NullLiteral"||e.value===null)return "null";if(e.type==="ObjectExpression")return "{}";if(e.type==="ArrayExpression")return "[]";if(e.type==="Identifier"&&e.name==="undefined")return "undefined";if(e.type==="ArrowFunctionExpression"||e.type==="FunctionExpression"||e.type==="ObjectMethod")return "function"}}extractFromClassComponent(e,t,n,r,s){let o=c=>c+r-1,a=e.body;if(!(!a||a.type!=="ClassBody"))for(let c of a.body||[]){let l=this.getPropKey(c);if(!l)continue;let u=o(this.getStartLine(c)),d=o(this.getEndLine(c)),p=Y(n.join(`
|
|
434
|
+
`),u);if(c.type==="ClassMethod"){let m=Ot.includes(l)?"lifecycle":"method",f=this.extractParams(c),g=c.async===true,y=f?`${l}(${f.join(", ")})`:l;s.symbols.push({name:l,category:m,framework:"vue2",startLine:u,endLine:d,signature:y,params:f,isAsync:g,jsdoc:p,camelWords:k(l)});let E=J(c,l);s.behaviors.push(...E);let _=ve(c,l);for(let T of _){if(T.args){let w=String(T.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[s.symbols.length-1].camelWords+=` ${k(w)} ${w}`;}s.relations.push(W({callerName:l,callerLine:u,calleeName:T.calleeName,callType:"this_method",line:o(T.line),args:T.args}));}let x=Q(c,l,n,true);for(let T of x){if(T.args){let w=String(T.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[s.symbols.length-1].camelWords+=` ${k(w)} ${w}`;}s.relations.push(W({callerName:l,callerLine:u,calleeName:T.calleeName,callType:"direct_call",line:o(T.line),args:T.args}));}}else if(c.type==="ClassProperty"){let h=(c.decorators||[]).some(f=>f.expression?.callee?.name==="Prop"),m=this.getLiteralValue(c.value);s.symbols.push({name:l,category:h?"prop":"state",framework:"vue2",startLine:u,endLine:d,defaultValue:m,camelWords:k(l)});}}}};var Ht=createRequire(import.meta.url),yt=class{name="Vue3Parser";canParse(e,t){return e.endsWith(".vue")?this.looksLikeVue3File(t):false}parse(e,t){let n={framework:"vue3",filePath:e,symbols:[],relations:[],behaviors:[],errors:[]};try{let{parse:r}=Ht("@vue/compiler-sfc"),{descriptor:s}=r(t),o=t.split(`
|
|
435
|
+
`),a=!!s.scriptSetup,c=!!s.script;if(a){let l=s.scriptSetup,u=l.loc.start.line;this.parseSetupContent(l.content,u,o,n);}else if(c){let l=s.script,u=l.loc.start.line;this.parseScriptContent(l.content,u,o,n)||this.populateFromOptionsApiFallback(e,t,n);}if(s.template?.content){let l=s.template.loc.start.line,u=dt(s.template.content,l);if(u.length>0){let d=s.template.content.split(`
|
|
436
|
+
`).length;n.symbols.push({name:"<template>",category:"lifecycle",framework:"vue3",startLine:l,endLine:l+d-1,camelWords:"template"});for(let p of u)n.relations.push(W({callerName:"<template>",callerLine:l,calleeName:p.calleeName,callType:"template_event",line:p.line}));}}}catch(r){n.errors?.push(`Vue3 \u89E3\u6790\u5931\u8D25: ${String(r)}`);}return n}parseSetupContent(e,t,n,r){let s;try{s=Ht("@babel/parser").parse(e,{sourceType:"module",plugins:["typescript","jsx","decorators-legacy"],errorRecovery:!0});}catch(l){r.errors?.push(`AST \u89E3\u6790\u5931\u8D25: ${String(l)}`);return}let o=l=>l+t-1,a=e.split(`
|
|
437
|
+
`),c=s.program.body;r.fileDependencies=be(c,r.filePath);for(let l of c||[])this.processTopLevelStatement(l,o,n,a,r);}parseScriptContent(e,t,n,r){let s;try{s=Ht("@babel/parser").parse(e,{sourceType:"module",plugins:["typescript","jsx","decorators-legacy"],errorRecovery:!0});}catch(l){return r.errors?.push(`AST \u89E3\u6790\u5931\u8D25: ${String(l)}`),false}let o=l=>l+t-1,a=e.split(`
|
|
438
|
+
`);r.fileDependencies=be(s.program.body||[],r.filePath);let c=false;return q(s.program,l=>{if(l.type==="ExportDefaultDeclaration"&&l.declaration?.type==="ObjectExpression"){let u=l.declaration.properties?.find(d=>this.getPropKey(d)==="setup");if(u){c=true;let d=u.type==="ObjectMethod"?u:u.value;if(!d)return;let p=d.body;if(p?.type==="BlockStatement"){let h=p.body;for(let m of h||[])this.processTopLevelStatement(m,o,n,a,r);}}}}),c||q(s.program,l=>{if(!c&&l.type==="ObjectExpression"){let d=(l.properties||[]).find(p=>this.getPropKey(p)==="setup");if(d){c=true;let p=d.type==="ObjectMethod"?d:d.value;if(!p)return;let h=p.body;if(h?.type==="BlockStatement"){let m=h.body;for(let f of m||[])this.processTopLevelStatement(f,o,n,a,r);}}}}),c}processTopLevelStatement(e,t,n,r,s){let o=a=>{let c=a?.loc;return {start:c?.start?.line??1,end:c?.end?.line??1}};if(e.type==="VariableDeclaration")for(let a of e.declarations||[]){if(a.id?.type!=="Identifier"&&a.id?.type!=="ArrayPattern")continue;let c=a.init;if(c&&a.id.type==="Identifier"){let l=a.id.name;if(c.type==="ArrowFunctionExpression"||c.type==="FunctionExpression"){let{start:u,end:d}=o(e),p=Y(n.join(`
|
|
439
|
+
`),t(u)),h=this.extractParams(c),m=s.symbols.length;if(s.symbols.push({name:l,category:"method",framework:"vue3",startLine:t(u),endLine:t(d),signature:`${l}(${(h||[]).join(", ")})`,params:h,isAsync:c.async===true,jsdoc:p,camelWords:k(l)}),c.body){let f=J(c.body,l);s.behaviors.push(...f);let g=Q(c.body,l);for(let y of g){if(y.args){let E=String(y.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[m].camelWords+=` ${k(E)} ${E}`;}s.relations.push(W({callerName:l,callerLine:t(u),calleeName:y.calleeName,callType:"direct_call",line:t(y.line),args:y.args}));}}}else {let u=this.classifyVue3Declaration(l,c,t,o(e),n);u&&s.symbols.push(u);}}}if(e.type==="FunctionDeclaration"&&e.id?.type==="Identifier"){let a=e.id.name,{start:c,end:l}=o(e),u=Y(n.join(`
|
|
440
|
+
`),t(c)),d=this.extractParams(e),p=Dt.includes(a);if(s.symbols.push({name:a,category:p?"lifecycle":xe(a)?"hook":"method",framework:"vue3",startLine:t(c),endLine:t(l),signature:`${a}(${(d||[]).join(", ")})`,params:d,isAsync:e.async===true,jsdoc:u,camelWords:k(a)}),e.body){let h=J(e.body,a);s.behaviors.push(...h);let m=Q(e.body,a);for(let f of m){if(f.args){let g=String(f.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[s.symbols.length-1].camelWords+=` ${k(g)} ${g}`;}s.relations.push(W({callerName:a,callerLine:t(c),calleeName:f.calleeName,callType:"direct_call",line:t(f.line),args:f.args}));}}}if(e.type==="ExpressionStatement"&&e.expression?.type==="CallExpression"){let c=e.expression.callee;if(c?.type==="Identifier"){let l=c.name;if(["defineProps","defineEmits","defineExpose"].includes(l)){let{start:u,end:d}=o(e);s.symbols.push({name:l,category:l==="defineProps"?"prop":l==="defineEmits"?"emit":"export",framework:"vue3",startLine:t(u),endLine:t(d),camelWords:k(l)});}}}if(e.type==="ExpressionStatement"&&e.expression?.type==="CallExpression"){let a=e.expression,c=a.callee;if(c?.type==="Identifier"){let l=c.name;if(Dt.includes(l)){let{start:u,end:d}=o(e);s.symbols.push({name:l,category:"lifecycle",framework:"vue3",startLine:t(u),endLine:t(d),camelWords:k(l)});let p=a.arguments;if(p?.[0]){let h=J(p[0],l);s.behaviors.push(...h);let m=Q(p[0],l);for(let f of m){if(f.args){let g=String(f.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[s.symbols.length-1].camelWords+=` ${k(g)} ${g}`;}s.relations.push(W({callerName:l,callerLine:t(u),calleeName:f.calleeName,callType:"direct_call",line:t(f.line),args:f.args}));}}}}}}classifyVue3Declaration(e,t,n,r,s){if(t.type!=="CallExpression")return null;let o=t.callee;if(o?.type!=="Identifier")return null;let a=o.name,c=n(r.start),l=n(r.end),u=Y(s.join(`
|
|
441
|
+
`),c);if(mn.includes(a)){let d=t.arguments,p=d?.[0]?this.getLiteralValue(d[0]):void 0;return {name:e,category:"state",framework:"vue3",startLine:c,endLine:l,defaultValue:p,jsdoc:u,camelWords:k(e)}}return gn.includes(a)?{name:e,category:"computed",framework:"vue3",startLine:c,endLine:l,jsdoc:u,camelWords:k(e)}:hn.includes(a)?{name:e,category:"effect",framework:"vue3",startLine:c,endLine:l,camelWords:k(e)}:a==="provide"||a==="inject"?{name:e,category:"provide",framework:"vue3",startLine:c,endLine:l,camelWords:k(e)}:xe(a)?{name:e,category:"hook",framework:"vue3",startLine:c,endLine:l,jsdoc:u,camelWords:k(e)}:null}getPropKey(e){let t=e?.key;return t?t.type==="Identifier"?t.name:t.type==="Literal"?String(t.value):null:null}extractParams(e){let t=e.params;if(t)return t.map(n=>n.type==="Identifier"?n.name:n.type==="AssignmentPattern"?n.left?.name||"?":n.type==="RestElement"?`...${n.argument?.name||""}`:n.type==="ObjectPattern"?"{...}":n.type==="TSParameterProperty"&&n.parameter?.name||"?")}getLiteralValue(e){if(e){if(e.type==="Literal"||e.type==="StringLiteral"||e.type==="NumericLiteral"||e.type==="BooleanLiteral")return String(e.value);if(e.type==="NullLiteral")return "null";if(e.type==="ObjectExpression")return "{}";if(e.type==="ArrayExpression")return "[]"}}looksLikeVue3File(e){return e.includes("<script setup")?true:/\bdefine(?:Props|Emits|Expose|Slots|Model)\s*\(/.test(e)||/\bwithDefaults\s*\(/.test(e)||/\bdefineComponent\s*\(/.test(e)||/\bsetup\s*\(/.test(e)||/\b(?:ref|reactive|shallowRef|shallowReactive|readonly|computed|watch|watchEffect|watchPostEffect|watchSyncEffect|provide|inject|nextTick|onBeforeMount|onMounted|onBeforeUpdate|onUpdated|onBeforeUnmount|onUnmounted|onActivated|onDeactivated|onErrorCaptured|onRenderTracked|onRenderTriggered|onServerPrefetch)\s*\(/.test(e)}populateFromOptionsApiFallback(e,t,n){let r=new De().parse(e,t);n.symbols=r.symbols.map(s=>({...s,framework:"vue3"})),n.relations=r.relations,n.behaviors=r.behaviors,n.errors=[...n.errors||[],...r.errors||[]];}};var Yr=createRequire(import.meta.url),Jr=[...Mt,...jt,...Bt,...yn],Ge=class{name="ReactParser";canParse(e,t){let n=e.split(".").pop()?.toLowerCase();return ["jsx","tsx","js","ts"].includes(n||"")?n==="ts"?/from\s+['"]react['"]/.test(t)||/require\(\s*['"]react['"]\s*\)/.test(t)||/\bReact\./.test(t):t.includes("useState")||t.includes("useEffect")||t.includes("from 'react'")||t.includes('from "react"')||t.includes("React.")?true:n==="jsx"||n==="tsx"||n==="js"?t.includes("jsx")||t.includes("JSX")||this.containsLikelyJsx(t):false:false}containsLikelyJsx(e){return /(?:^|\breturn\b|[=(,:{?&|;>])[\s([]*<[A-Za-z][\w.:-]*(?:\s|\/?>)/m.test(e)||/<>|<\/>/.test(e)}parse(e,t){let n={framework:"react",filePath:e,symbols:[],relations:[],behaviors:[],errors:[]};try{let s=Yr("@babel/parser").parse(t,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy"],errorRecovery:!0}),o=t.split(`
|
|
442
|
+
`);this.extractFromAST(s.program?s.program:s,o,n);}catch(r){n.errors?.push(`React \u89E3\u6790\u5931\u8D25: ${String(r)}`);}return n}extractFromAST(e,t,n){let r=e.body;n.fileDependencies=be(r,n.filePath);for(let s of r||[]){if(s.type==="FunctionDeclaration"||s.type==="ExportDefaultDeclaration"&&s.declaration?.type==="FunctionDeclaration"||s.type==="ExportNamedDeclaration"&&s.declaration?.type==="FunctionDeclaration"){let o=s.type==="FunctionDeclaration"?s:s.declaration,a=s.type!=="FunctionDeclaration";o&&o.id?.type==="Identifier"&&this.processFunction(o,t,n,a);}if(s.type==="VariableDeclaration"||s.type==="ExportNamedDeclaration"&&s.declaration?.type==="VariableDeclaration"||s.type==="ExportDefaultDeclaration"&&s.declaration?.type==="VariableDeclaration"){let o=s.type==="VariableDeclaration"?s:s.declaration,a=s.type!=="VariableDeclaration";if(o)for(let c of o.declarations||[]){let l=c.init;if(l&&(l.type==="ArrowFunctionExpression"||l.type==="FunctionExpression")&&c.id?.type==="Identifier"){let u={...l,id:c.id,loc:{start:o.loc?.start??l.loc?.start,end:l.loc?.end}};this.processFunction(u,t,n,a);continue}this.processTopLevelVariableDeclaration(c,t,n,a);}}}n.exportSignatureEntries=ht(r,n.symbols);}processTopLevelVariableDeclaration(e,t,n,r){let s=e.id;if(!s||s.type!=="Identifier")return;let o=s.name;if(!o)return;let a=e.init,c=e.loc,l=c?.start?.line??1,u=c?.end?.line??1,d=this.buildSymbolKey(o,l,u);if(n.symbols.push({name:o,category:"constant",framework:"react",startLine:l,endLine:u,internalKey:d,isExported:r,defaultValue:this.getLiteralValue(a),jsdoc:Y(t.join(`
|
|
443
|
+
`),l),camelWords:k(o)}),!a)return;let p=J(a,o,t,true);n.behaviors.push(...p);let h=Q(a,o,t,true);for(let m of h){let f=n.symbols.findIndex(g=>g.name===o&&g.startLine===l);if(m.args&&f!==-1){let g=String(m.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");n.symbols[f].camelWords+=` ${k(g)} ${g}`;}n.relations.push(W({callerName:o,callerLine:l,callerKey:d,calleeName:m.calleeName,callType:"direct_call",line:m.line,args:m.args}));}}processFunction(e,t,n,r=false){let s=e.id?.name;if(!s)return;let o=e.loc,a=o?.start?.line??1,c=o?.end?.line??1,l=xe(s),u=!l&&/^[A-Z]/.test(s),d=Y(t.join(`
|
|
444
|
+
`),a),p=this.extractParams(e),h=this.buildSymbolKey(s,a,c);n.symbols.push({name:s,category:l?"hook":u?"component":"function",framework:"react",startLine:a,endLine:c,internalKey:h,signature:`${s}(${(p||[]).join(", ")})`,params:p,isAsync:e.async===true,isExported:r,jsdoc:d,parentComponent:u?s:void 0,camelWords:k(s)});let m=e.body;if(m?.type!=="BlockStatement")return;let f=m.body;for(let _ of f||[])this.processComponentStatement(_,s,t,n);let g=J(m,s,t,true);n.behaviors.push(...g);let y=Q(m,s,t,true);for(let _ of y){let x=n.symbols.findIndex(T=>T.name===s&&T.startLine===a);if(_.args&&x!==-1){let T=String(_.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");n.symbols[x].camelWords+=` ${k(T)} ${T}`;}n.relations.push(W({callerName:s,callerLine:a,callerKey:h,calleeName:_.calleeName,callType:"direct_call",line:_.line,args:_.args}));}let E=An(m);for(let _ of E)n.relations.push(W({callerName:s,callerLine:a,callerKey:h,calleeName:_.calleeName,callType:"jsx_event",line:_.line}));}processComponentStatement(e,t,n,r){let s=o=>{let a=o?.loc;return {start:a?.start?.line??1,end:a?.end?.line??1}};if(e.type==="VariableDeclaration")for(let o of e.declarations||[]){let a=o.init;if(!a||a.type!=="CallExpression")continue;let c=a.callee;if(c?.type!=="Identifier")continue;let l=c.name,{start:u,end:d}=s(e),p=u,h=d;if(Mt.includes(l)&&l!=="useRef"){if(o.id?.type==="ArrayPattern"){let m=o.id.elements,f=m[0]?.name,g=m[1]?.name;if(f){let y=a.arguments;r.symbols.push({name:f,category:"state",framework:"react",startLine:p,endLine:h,internalKey:this.buildSymbolKey(f,p,h,t),stateSetterName:g,defaultValue:this.getLiteralValue(y?.[0]),parentComponent:t,camelWords:k(f)});}}else if(o.id?.type==="Identifier"){let m=o.id.name;r.symbols.push({name:m,category:"state",framework:"react",startLine:p,endLine:h,internalKey:this.buildSymbolKey(m,p,h,t),parentComponent:t,camelWords:k(m)});}}if(l==="useRef"&&o.id?.type==="Identifier"){let m=o.id.name,f=a.arguments;r.symbols.push({name:m,category:"state",framework:"react",startLine:p,endLine:h,internalKey:this.buildSymbolKey(m,p,h,t),defaultValue:this.getLiteralValue(f?.[0]),parentComponent:t,camelWords:k(m)});}if(jt.includes(l)&&o.id?.type==="Identifier"){let m=o.id.name,g=a.arguments?.[1],y=this.extractDepsArray(g);r.symbols.push({name:m,category:"computed",framework:"react",startLine:p,endLine:h,internalKey:this.buildSymbolKey(m,p,h,t),hookDeps:y,parentComponent:t,camelWords:k(m)});}if(xe(l)&&!Jr.includes(l)){let m=o.id?.type==="Identifier"?o.id.name:o.id?.type==="ObjectPattern"?"{...}":"?";r.symbols.push({name:m,category:"hook",framework:"react",startLine:p,endLine:h,internalKey:this.buildSymbolKey(m,p,h,t),parentComponent:t,camelWords:k(m)});}}if(e.type==="ExpressionStatement"&&e.expression?.type==="CallExpression"){let o=e.expression,a=o.callee;if(a?.type==="Identifier"){let c=a.name;if(Bt.includes(c)){let{start:l,end:u}=s(e),d=o.arguments,p=d?.[1],h=this.extractDepsArray(p),m=this.buildSymbolKey(c,l,u,t),f=`${t}.${c}`;if(r.symbols.push({name:c,category:"effect",framework:"react",startLine:l,endLine:u,internalKey:m,hookDeps:h,parentComponent:t,camelWords:k(c)}),d?.[0]){let g=J(d[0],f,n,true).map(E=>({...E,symbolKey:m}));r.behaviors.push(...g);let y=Q(d[0],f,n,true);for(let E of y){let _=r.symbols.findIndex(x=>x.name===c&&x.startLine===l);if(E.args&&_!==-1){let x=String(E.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");r.symbols[_].camelWords+=` ${k(x)} ${x}`;}r.relations.push(W({callerName:f,callerLine:l,callerKey:m,calleeName:E.calleeName,callType:"direct_call",line:E.line,args:E.args}));}}}}}if(e.type==="FunctionDeclaration"&&e.id?.type==="Identifier"){let o=e.id.name;if(!xe(o)){let{start:a,end:c}=s(e),l=Y(n.join(`
|
|
445
|
+
`),a),u=this.extractParams(e);if(r.symbols.push({name:o,category:"method",framework:"react",startLine:a,endLine:c,internalKey:this.buildSymbolKey(o,a,c,t),signature:`${o}(${(u||[]).join(", ")})`,params:u,isAsync:e.async===true,jsdoc:l,parentComponent:t,camelWords:k(o)}),e.body){let d=J(e.body,o,n,true);r.behaviors.push(...d);let p=Q(e.body,o,n,true);for(let h of p){let m=r.symbols.findIndex(f=>f.name===o&&f.startLine===a);if(h.args&&m!==-1){let f=String(h.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");r.symbols[m].camelWords+=` ${k(f)} ${f}`;}r.relations.push(W({callerName:o,callerLine:a,callerKey:this.buildSymbolKey(o,a,c,t),calleeName:h.calleeName,callType:"direct_call",line:h.line,args:h.args}));}}}}if(e.type==="VariableDeclaration")for(let o of e.declarations||[]){let a=o.init;if(!a)continue;let c=a.type==="ArrowFunctionExpression"||a.type==="FunctionExpression";if(!c||o.id?.type!=="Identifier")continue;let l=o.id.name,u=a.type==="CallExpression"?a.callee:null;if(u?.type==="Identifier"&&xe(u.name))continue;if(a.type==="CallExpression"&&a.callee?.name==="useCallback"){let y=a.arguments?.[1],E=this.extractDepsArray(y),{start:_,end:x}=s(e);r.symbols.push({name:l,category:"computed",framework:"react",startLine:_,endLine:x,internalKey:this.buildSymbolKey(l,_,x,t),hookDeps:E,parentComponent:t,camelWords:k(l)});continue}if(!c)continue;let{start:p,end:h}=s(e),m=Y(n.join(`
|
|
446
|
+
`),p),f=this.extractParams(a);if(r.symbols.push({name:l,category:"method",framework:"react",startLine:p,endLine:h,internalKey:this.buildSymbolKey(l,p,h,t),signature:`${l}(${(f||[]).join(", ")})`,params:f,isAsync:a.async===true,jsdoc:m,parentComponent:t,camelWords:k(l)}),a.body){let g=J(a.body,l,n,true);r.behaviors.push(...g);let y=Q(a.body,l,n,true);for(let E of y){let _=r.symbols.findIndex(x=>x.name===l&&x.startLine===p);if(E.args&&_!==-1){let x=String(E.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");r.symbols[_].camelWords+=` ${k(x)} ${x}`;}r.relations.push(W({callerName:l,callerLine:p,callerKey:this.buildSymbolKey(l,p,h,t),calleeName:E.calleeName,callType:"direct_call",line:E.line,args:E.args}));}}}}extractDepsArray(e){if(!(!e||e.type!=="ArrayExpression"))return (e.elements||[]).filter(t=>!!t&&t.type==="Identifier").map(t=>t.name)}extractParams(e){let t=e.params;if(t)return t.map(n=>n.type==="Identifier"?n.name:n.type==="ObjectPattern"?"{...}":n.type==="ArrayPattern"?"[...]":n.type==="AssignmentPattern"?n.left?.name||"?":n.type==="RestElement"?`...${n.argument?.name||""}`:n.type==="TSParameterProperty"&&n.parameter?.name||"?")}getLiteralValue(e){if(e){if(e.type==="Literal"||e.type==="StringLiteral"||e.type==="NumericLiteral"||e.type==="BooleanLiteral")return String(e.value);if(e.type==="NullLiteral")return "null";if(e.type==="ObjectExpression")return "{}";if(e.type==="ArrayExpression")return "[]";if(e.type==="Identifier"&&e.name==="null")return "null"}}buildSymbolKey(e,t,n,r){return `${r||"root"}:${e}:${t}:${n}`}};var Zr=createRequire(import.meta.url),bt=class{name="ToolingTsParser";canParse(e){let t=e.split(".").pop()?.toLowerCase();return ["js","jsx","ts","tsx"].includes(t||"")}parse(e,t){let n=e.endsWith(".ts")||e.endsWith(".tsx")?"ts":"js",r={framework:n,filePath:e,symbols:[],relations:[],behaviors:[],errors:[]};try{let o=Zr("@babel/parser").parse(t,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy","classProperties"],errorRecovery:!0}),a=t.split(`
|
|
447
|
+
`),c=(o.program||o).body,l=new Set;r.fileDependencies=be(c||[],e);for(let u of c||[])this.processTopLevelStatement(u,a,n,r,l);if(l.size>0)for(let u of r.symbols)l.has(u.name)&&(u.isExported=!0);r.exportSignatureEntries=ht(c||[],r.symbols);}catch(s){r.errors?.push(`Tooling \u89E3\u6790\u5931\u8D25: ${String(s)}`);}return r}processTopLevelStatement(e,t,n,r,s){if(e.type==="FunctionDeclaration"){this.addTopLevelFunction(e,t,n,r,false);return}if(e.type==="ExportNamedDeclaration"||e.type==="ExportDefaultDeclaration"){let o=e.declaration;if(!o){this.collectDeferredExportNames(e,s);return}if(o.type==="FunctionDeclaration"){this.addTopLevelFunction(o,t,n,r,true);return}if(o.type==="ClassDeclaration"){this.addClass(o,t,n,r,true);return}if(o.type==="VariableDeclaration"){this.processVariableDeclaration(o,t,n,r,true);return}this.collectDeferredExportNames(e,s);return}if(e.type==="ClassDeclaration"){this.addClass(e,t,n,r,false);return}e.type==="VariableDeclaration"&&this.processVariableDeclaration(e,t,n,r,false);}collectDeferredExportNames(e,t){if(e.type==="ExportNamedDeclaration"){if(e.source?.type==="StringLiteral")return;for(let r of e.specifiers||[]){let s=r.local;s?.type==="Identifier"&&t.add(String(s.name||""));}return}if(e.type==="ExportDefaultDeclaration"){let n=e.declaration;n?.type==="Identifier"&&t.add(String(n.name||""));}}processVariableDeclaration(e,t,n,r,s){for(let o of e.declarations||[]){let a=o.id;if(!a||a.type!=="Identifier")continue;let c=String(a.name||"");if(!c)continue;let l=o.init,{start:u,end:d}=this.getLineRange(o),p=this.buildSymbolKey(c,u,d);if(l&&(l.type==="ArrowFunctionExpression"||l.type==="FunctionExpression")){this.addFunctionSymbol(c,l,t,n,r,{startLine:u,endLine:d,isExported:s});continue}if(r.symbols.push({name:c,category:"constant",framework:n,startLine:u,endLine:d,internalKey:p,isExported:s,defaultValue:this.getLiteralValue(l),jsdoc:Y(t.join(`
|
|
448
|
+
`),u),camelWords:k(c)}),!l)continue;let h=J(l,c,t,true);r.behaviors.push(...h);let m=Q(l,c,t,true);for(let y of m)r.relations.push(W({callerName:c,callerLine:u,callerKey:p,calleeName:y.calleeName,callType:"direct_call",line:y.line,args:y.args}));let f=ct(l,c,t,true);for(let y of f)r.relations.push(W({callerName:c,callerLine:u,callerKey:p,calleeName:y.calleeName,callType:"direct_call",line:y.line,args:y.args,receiverToken:y.receiverToken}));let g=lt(l,c,t,true);for(let y of g)r.relations.push(W({callerName:c,callerLine:u,callerKey:p,calleeName:y.calleeName,callType:"new_call",line:y.line,args:y.args}));}}addTopLevelFunction(e,t,n,r,s){let o=e.id?.name;if(!o)return;let{start:a,end:c}=this.getLineRange(e);this.addFunctionSymbol(o,e,t,n,r,{startLine:a,endLine:c,isExported:s});}addFunctionSymbol(e,t,n,r,s,o){let a=this.buildSymbolKey(e,o.startLine,o.endLine,o.ownerClass),c=this.extractParams(t);s.symbols.push({name:e,category:o.ownerClass?"method":"function",framework:r,startLine:o.startLine,endLine:o.endLine,internalKey:a,signature:`${e}(${(c||[]).join(", ")})`,params:c,isAsync:t.async===true,isExported:o.isExported,jsdoc:Y(n.join(`
|
|
449
|
+
`),o.startLine),parentComponent:o.ownerClass,camelWords:k(e)});let l=t.body;if(!l)return;let u=J(l,e,n,true);s.behaviors.push(...u);let d=Q(l,e,n,true);for(let g of d)s.relations.push(W({callerName:e,callerLine:o.startLine,callerKey:a,calleeName:g.calleeName,callType:"direct_call",line:g.line,args:g.args}));let p=Tn(l,e,n);for(let g of p)s.relations.push(W({callerName:e,callerLine:o.startLine,callerKey:a,calleeName:g.calleeName,callType:"direct_call",line:g.line,args:g.args}));let h=ct(l,e,n,true);for(let g of h)s.relations.push(W({callerName:e,callerLine:o.startLine,callerKey:a,calleeName:g.calleeName,callType:"direct_call",line:g.line,args:g.args,receiverToken:g.receiverToken}));let m=lt(l,e,n,true);for(let g of m)s.relations.push(W({callerName:e,callerLine:o.startLine,callerKey:a,calleeName:g.calleeName,callType:"new_call",line:g.line,args:g.args}));let f=ve(l,e);for(let g of f)s.relations.push(W({callerName:e,callerLine:o.startLine,callerKey:a,calleeName:g.calleeName,callType:"this_method",line:g.line,args:g.args}));}addClass(e,t,n,r,s){let o=e.id?.name;if(!o)return;let{start:a,end:c}=this.getLineRange(e);r.symbols.push({name:o,category:"class",framework:n,startLine:a,endLine:c,isExported:s,jsdoc:Y(t.join(`
|
|
450
|
+
`),a),camelWords:k(o)});let l=e.body?.body;for(let u of l||[]){let d=u.key,p=d?.type==="Identifier"?String(d.name||""):"";if(!p||p==="constructor")continue;if(u.type==="ClassMethod"||u.type==="ClassPrivateMethod"){this.addFunctionSymbol(p,u,t,n,r,{startLine:this.getLineRange(u).start,endLine:this.getLineRange(u).end,isExported:false,ownerClass:o});continue}let h=u.value;h&&(h.type==="ArrowFunctionExpression"||h.type==="FunctionExpression")&&(u.type==="ClassProperty"||u.type==="PropertyDefinition")&&this.addFunctionSymbol(p,h,t,n,r,{startLine:this.getLineRange(u).start,endLine:this.getLineRange(u).end,isExported:false,ownerClass:o});}}extractParams(e){let t=e.params;return t?.length?t.map(n=>{if(n.type==="Identifier")return String(n.name||"");if(n.type==="AssignmentPattern"){let r=n.left;return r?.type==="Identifier"?String(r.name||""):"param"}return "param"}):[]}getLiteralValue(e){if(e){if(e.type==="StringLiteral"||e.type==="NumericLiteral"||e.type==="BooleanLiteral")return String(e.value);if(e.type==="NullLiteral")return "null";if(e.type==="ObjectExpression")return "{...}";if(e.type==="ArrayExpression")return "[...]"}}buildSymbolKey(e,t,n,r){return `${r||"root"}:${e}:${t}:${n}`}getLineRange(e){let t=e.loc;return {start:t?.start?.line??1,end:t?.end?.line??1}}};var es=new Set(["FunctionDeclaration","ArrowFunctionExpression","FunctionExpression","ObjectMethod","ClassMethod","ClassProperty"]);function kn(i,e){return !!e?.skipNestedFunctions&&es.has(String(i.type||""))}function _e(i,e,t){if(!(!i||typeof i!="object")){e(i);for(let n of Object.keys(i)){if(n==="type"||n==="loc"||n==="start"||n==="end")continue;let r=i[n];if(Array.isArray(r)){for(let s of r){if(!s||typeof s!="object"||!s.type)continue;let o=s;kn(o,t)||_e(o,e,t);}continue}if(r&&typeof r=="object"&&r.type){let s=r;if(kn(s,t))continue;_e(s,e,t);}}}}function vn(i,e,t=true,n){let r=[],s=[],o=(a,c=120)=>ts(a,n,c);return _e(i,a=>{if(a.type==="VariableDeclarator"){let c=a.id;if(!c)return;let l=Et(c),u=o(a);for(let d of l)r.push({symbolName:d,kind:"declaration",line:Ae(a),text:u,sourceLayer:ie(u,Ae(a))});}if(a.type==="AssignmentExpression"){let c=a.left;if(!c)return;let l=o(a),u=Ae(a);if(c.type==="Identifier"&&r.push({symbolName:c.name,kind:"assignment",line:u,text:l,sourceLayer:ie(l,u)}),c.type==="MemberExpression"&&c.object?.type==="ThisExpression"){let p=G(c);if(p){r.push({symbolName:p,kind:"assignment",line:u,text:l,sourceLayer:ie(l,u)});return}}if(c.type==="MemberExpression"){let d=se(c);if(d&&_t(d)){let p=G(c);s.push({objectName:d,propertyName:p||void 0,line:u,text:l,kind:c.computed?"bracket":"dot",sourceLayer:ie(l,u)});}}}if(a.type==="UpdateExpression"){let c=a.argument;if(!c)return;let l=o(a),u=Ae(a);if(c.type==="Identifier"&&r.push({symbolName:c.name,kind:"update",line:u,text:l,sourceLayer:ie(l,u)}),c.type==="MemberExpression"&&c.object?.type==="ThisExpression"){let p=G(c);if(p){r.push({symbolName:p,kind:"update",line:u,text:l,sourceLayer:ie(l,u)});return}}if(c.type==="MemberExpression"){let d=se(c);if(d&&_t(d)){let p=G(c);s.push({objectName:d,propertyName:p||void 0,line:u,text:l,kind:c.computed?"bracket":"dot",sourceLayer:ie(l,u)});}}}if(a.type==="UnaryExpression"&&a.operator==="delete"){let c=a.argument;if(c?.type==="MemberExpression"){let l=se(c);if(l&&_t(l)){let u=G(c);s.push({objectName:l,propertyName:u||void 0,line:Ae(a),text:o(a),kind:"delete",sourceLayer:ie(o(a),Ae(a))});}}}if(a.type==="CallExpression"||a.type==="OptionalCallExpression"){let c=a.callee;if(!c||c.type!=="MemberExpression"&&c.type!=="OptionalMemberExpression")return;let l=G(c);if(!l||!/^(push|pop|shift|unshift|splice|sort|reverse|copyWithin|fill)$/.test(l))return;let u=se(c);if(!u||!_t(u))return;s.push({objectName:u,propertyName:l,line:Ae(a),text:o(a),kind:"array_mutation",sourceLayer:ie(o(a),Ae(a))});}},{skipNestedFunctions:t}),{assignments:r,propertyWrites:s}}function Et(i){return i.type==="Identifier"?[i.name]:i.type==="ObjectPattern"?(i.properties||[]).flatMap(t=>{let n=t.type==="ObjectProperty"||t.type==="Property"?t.value:t;return n?Et(n):[]}):i.type==="ArrayPattern"?(i.elements||[]).flatMap(t=>t?Et(t):[]):i.type==="AssignmentPattern"?Et(i.left):[]}function _t(i){return !(/^[A-Z][A-Z]/.test(i)||/^(document|window|console|localStorage|sessionStorage|navigator|process|global|globalThis)$/.test(i))}function Ae(i){return i.loc?.start?.line??1}function ts(i,e,t=120){if(e){let r=i.loc;if(r?.start?.line&&r?.end?.line){let s=r.start.line-1,o=Math.min(r.end.line-1,s+5);return e.slice(s,o+1).map(c=>c.trim()).filter(c=>c).join(" ").slice(0,t)}}let n=i.loc;return n?.start?.line?`L${n.start.line}`:String(i.type||"?")}var rs=createRequire(import.meta.url);function Kt(i,e){let t={files:new Map,resolutionCache:new Map,localShadowCache:new Map};for(let{path:n,content:r}of i){let s=Rn(n,r);t.files.set(n,s);let o=new Map;for(let a of s.imports)a.localName&&o.set(a.localName,`${a.resolvedFile}::${a.originalName}`);t.resolutionCache.set(n,o),t.localShadowCache.set(n,ss(r));}return t}function zt(i,e,t,n){if(t.files.size===0)return i;let r=t.resolutionCache.get(e);if(!r||r.size===0)return i;let s=t.localShadowCache.get(e);return t.files.get(e)?i.map(c=>{let l=r.get(c.calleeName);return !l||c.callerKey&&s?.get(c.callerKey)?.has(c.calleeName)||n.has(c.calleeName)?c:{...c,edgeKind:"precise",importSource:c.importSource||l}}):i}function ss(i){let e=new Map;try{let n=rs("@babel/parser").parse(i,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy","classProperties"],errorRecovery:!0}),r=(n.program||n).body;if(!r?.length)return e;for(let s of r)In(s,e);}catch{return e}return e}function In(i,e){if(i.type==="FunctionDeclaration"){let t=Ie(i.id);if(!t)return;Me(t,i,e),is(cs(i),t,e);return}if(i.type==="VariableDeclaration"){$n(i,void 0,e);return}if(i.type==="ClassDeclaration"){os(i,e);return}if(i.type==="ExportNamedDeclaration"||i.type==="ExportDefaultDeclaration"){let t=i.declaration;if(!t)return;In(t,e);}}function is(i,e,t){for(let n of i){if(n.type==="FunctionDeclaration"){let r=Ie(n.id);if(!r)continue;Me(r,n,t,e);continue}if(n.type==="VariableDeclaration"){$n(n,e,t);continue}if(n.type==="ExpressionStatement"){let r=n.expression;if(r?.type!=="CallExpression")continue;let s=r.callee,o=s?.type==="Identifier"?String(s.name||""):"";if(!/^use[A-Z]/.test(o))continue;let a=r.arguments?.[0];if(!a||a.type!=="ArrowFunctionExpression"&&a.type!=="FunctionExpression")continue;Me(o,a,t,e,n);}}}function $n(i,e,t){for(let n of i.declarations||[]){let r=Ie(n.id),s=n.init;!r||!s||s.type!=="ArrowFunctionExpression"&&s.type!=="FunctionExpression"||Me(r,s,t,e,n);}}function os(i,e){let t=Ie(i.id);if(!t)return;let n=i.body?.body||[];for(let r of n){let s=Ie(r.key);if(!s||s==="constructor")continue;if(r.type==="ClassMethod"||r.type==="ClassPrivateMethod"){Me(s,r,e,t);continue}let o=r.value;o&&(o.type==="ArrowFunctionExpression"||o.type==="FunctionExpression")&&(r.type==="ClassProperty"||r.type==="PropertyDefinition")&&Me(s,o,e,t,r);}}function Me(i,e,t,n,r){let s=ls(r||e),o=ps(i,s.start,s.end,n),a=as(e);t.set(o,a);}function as(i){let e=new Set;for(let n of i.params||[])for(let r of Ce(n))e.add(r);let t=i.body;return t&&Xt(t,n=>{if(n.type==="VariableDeclarator"){for(let r of Ce(n.id))e.add(r);return}if(n.type==="FunctionDeclaration"){let r=Ie(n.id);return r&&e.add(r),false}if(n.type==="ClassDeclaration"){let r=Ie(n.id);return r&&e.add(r),false}}),e}function Xt(i,e){if(!(!i||typeof i!="object")&&e(i)!==false)for(let t of Object.keys(i)){if(t==="type"||t==="loc"||t==="start"||t==="end")continue;let n=i[t];if(Array.isArray(n)){for(let r of n){if(!r||typeof r!="object"||!r.type)continue;let s=r;Cn(s)||Xt(s,e);}continue}if(n&&typeof n=="object"&&n.type){let r=n;if(Cn(r))continue;Xt(r,e);}}}function Cn(i){return ["FunctionDeclaration","FunctionExpression","ArrowFunctionExpression","ClassMethod","ClassPrivateMethod","ObjectMethod"].includes(String(i.type||""))}function Ce(i){return i?i.type==="Identifier"?[String(i.name||"")]:i.type==="AssignmentPattern"?Ce(i.left):i.type==="RestElement"?Ce(i.argument):i.type==="ArrayPattern"?(i.elements||[]).flatMap(e=>Ce(e)):i.type==="ObjectPattern"?(i.properties||[]).flatMap(e=>{if(e.type==="RestElement")return Ce(e.argument);let t=e.value||e.argument;return Ce(t)}):[]:[]}function Ie(i){if(i&&i.type==="Identifier")return String(i.name||"")}function cs(i){let e=i.body;return !e||e.type!=="BlockStatement"?[]:e.body||[]}function ls(i){let e=i.loc;return {start:e?.start?.line??1,end:e?.end?.line??1}}function ps(i,e,t,n){return n?`${n}:${i}:${e}:${t}`:`root:${i}:${e}:${t}`}var Pn=createRequire(import.meta.url);function Fn(i,e){let t=i.errors||[];t.includes(e)||(i.errors=[...t,e]);}var Vt=class extends Ge{name="JsTsFallbackParser";canParse(e){let t=e.split(".").pop()?.toLowerCase();return ["js","ts","jsx","tsx"].includes(t||"")}parse(e,t){let n=super.parse(e,t);return n.framework=e.endsWith(".ts")||e.endsWith(".tsx")?"ts":"js",n}},ds=[new yt,new De,new Ge,new bt,new Vt];function qe(i,e){for(let t of ds)if(t.canParse(i,e)){let n=t.parse(i,e);return ms(n),fs(n,e),n}return {framework:"js",filePath:i,symbols:[],relations:[],behaviors:[],errors:[`\u6CA1\u6709\u627E\u5230\u9002\u5408\u7684\u89E3\u6790\u5668: ${i}`]}}function fs(i,e){if(i.symbols.length!==0)try{let t=e,n=i.filePath.endsWith(".vue"),r=0;if(n)try{let{parse:p}=Pn("@vue/compiler-sfc"),{descriptor:h}=p(e);if(h.scriptSetup?.content)t=h.scriptSetup.content,r=h.scriptSetup.loc.start.line-1;else if(h.script?.content)t=h.script.content,r=h.script.loc.start.line-1;else return}catch(p){Fn(i,`\u751F\u547D\u5468\u671F\u63D0\u53D6\u8DF3\u8FC7: Vue SFC \u89E3\u6790\u5931\u8D25 - ${String(p)}`);return}let a=Pn("@babel/parser").parse(t,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy"],errorRecovery:!0}).program.body;if(!a?.length)return;let c=t.split(`
|
|
451
|
+
`),{assignments:l,propertyWrites:u}=vn({type:"Program",body:a},i.filePath,!1,c);if(r>0){for(let p of l)p.line+=r;for(let p of u)p.line+=r;}let d=new Set(i.symbols.map(p=>p.name));i.assignments=l.filter(p=>d.has(p.symbolName)),i.propertyWrites=u.filter(p=>d.has(p.objectName));}catch(t){Fn(i,`\u751F\u547D\u5468\u671F\u63D0\u53D6\u8DF3\u8FC7: AST \u89E3\u6790\u5931\u8D25 - ${String(t)}`);}}function ms(i){if(!i.relations.length||!i.behaviors.length)return;let e=new Set(["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeDestroy","destroyed","activated","deactivated","errorCaptured","setup","onBeforeMount","onMounted","onBeforeUpdate","onUpdated","onBeforeUnmount","onUnmounted","onActivated","onDeactivated","onErrorCaptured","componentDidMount","componentDidUpdate","componentWillUnmount","componentDidCatch","getDerivedStateFromProps","getSnapshotBeforeUpdate","render","init","initialize"]),t=new Set(i.behaviors.filter(r=>r.category==="network").map(r=>r.symbolName));if(t.size===0)return;let n=new Set(i.behaviors.map(r=>`${r.symbolName}:${r.category}:${r.apiName}:${r.operation}:${r.line}`));for(let r of i.relations){if(!t.has(r.calleeName)||t.has(r.callerName)||e.has(r.callerName))continue;let s={symbolName:r.callerName,symbolKey:r.callerKey,category:"network",apiName:"wrapped_network",operation:r.calleeName,detail:r.args,line:r.line},o=`${s.symbolName}:${s.category}:${s.apiName}:${s.operation}:${s.line}`;n.has(o)||(n.add(o),i.behaviors.push(s));}}function Ye(i,e){let t=gs(e),n=i.exportSignatureEntries?.length?[...i.exportSignatureEntries]:(()=>{let a=[];for(let c of i.symbols)if(c.isExported){let l=c.signature||"";a.push(`${c.name}:${l}`);}return a.sort(),a})(),r=n.length>0?On(n.join(`
|
|
452
|
+
`)):"",s=[];if(i.fileDependencies&&i.fileDependencies.length>0)for(let a of i.fileDependencies)(a.dependencyKind==="import"||a.dependencyKind==="re_export")&&s.push(a.toFile);s.sort();let o=s.length>0?On(s.join(`
|
|
453
|
+
`)):"";return {contentHash:t,exportSignatureHash:r,importSignatureHash:o}}function Gt(i,e){if(!i)return "full_changed";if(i.contentHash===e.contentHash)return "unchanged";let t=i.exportSignatureHash!==e.exportSignatureHash,n=i.importSignatureHash!==e.importSignatureHash;return t&&n?"full_changed":t?"export_changed":n?"import_changed":"body_only"}function qt(i,e,t,n=200){if(e==="unchanged")return {files:[],truncated:false};if(e==="body_only")return {files:[i],truncated:false};if(e==="import_changed")return {files:[i],truncated:false};let r=new Set([i]),s=[i];for(;s.length>0;){let o=s.shift(),a=t.get(o)||[];for(let c of a)if(!r.has(c)){if(r.add(c),r.size>=n)return {files:Array.from(r),truncated:true};s.push(c);}}return {files:Array.from(r),truncated:false}}function gs(i){return createHash("sha256").update(i,"utf-8").digest("hex").slice(0,16)}function On(i){return createHash("sha256").update(i,"utf-8").digest("hex").slice(0,12)}var hs={maxFiles:20,maxTimeMs:1500},Nt=class{pending=[];options;constructor(e){this.options={...hs,...e};}configure(e){this.options={...this.options,...e};}enqueue(e,t){let n=this.pending.find(r=>r.relPath===e);if(n){let r={high:3,normal:2,low:1};r[t]>r[n.priority]&&(n.priority=t);return}this.pending.push({relPath:e,priority:t,addedAt:Date.now()});}dequeueBatch(){if(this.pending.length===0)return {tasks:[],exceededBudget:false,remainingPending:0};let e={high:0,normal:1,low:2};this.pending.sort((s,o)=>{let a=e[s.priority],c=e[o.priority];return a!==c?a-c:s.addedAt-o.addedAt});let t=[],n=this.pending.length>this.options.maxFiles;for(let s=0;s<Math.min(this.options.maxFiles,this.pending.length);s++)t.push(this.pending[s]);let r=new Set(t.map(s=>s.relPath));return this.pending=this.pending.filter(s=>!r.has(s.relPath)),{tasks:t,exceededBudget:n,remainingPending:this.pending.length}}requeue(e){if(e.length===0)return;let t=new Set(this.pending.map(r=>r.relPath)),n=e.filter(r=>!t.has(r.relPath));this.pending=[...n,...this.pending];}clear(){this.pending=[];}get pendingCount(){return this.pending.length}get budget(){return this.options}summary(){return this.pending.map(e=>({relPath:e.relPath,priority:e.priority}))}};var St=class{projectRoot;db;scheduler;constructor(e,t){this.projectRoot=e,this.db=t,this.scheduler=new Nt;}getScheduler(){return this.scheduler}enhancePreciseRelations(e){try{let t=e.filter(({absPath:r})=>/\.(ts|tsx|js|jsx)$/i.test(r)).map(({absPath:r,content:s})=>({path:r,content:s})),n=Kt(t,"precise");if(n.files.size===0)return;for(let r of e){if(r.result.relations.length===0)continue;let s=new Set(r.result.symbols.map(o=>o.name));r.result.relations=zt(r.result.relations,r.result.filePath,n,s);}}catch(t){let n=`precise enhancement \u5931\u8D25\uFF0C\u5DF2\u56DE\u9000\u5230\u672C\u5730 relations: ${String(t)}`;process.stderr.write(`[Frontend-Code-Skimmer] ${n}
|
|
454
|
+
`);for(let r of e){let s=r.result.errors||[];s.includes(n)||(r.result.errors=[...s,n]);}}}enqueuePrecise(e,t){this.scheduler.enqueue(e,t),this.db.enqueuePrecisePending(e,t);}hydratePendingPreciseQueue(){for(let e of this.db.listPrecisePending())this.scheduler.enqueue(e.relPath,e.priority);}enqueueAffectedPrecise(e,t){if(t==="unchanged")return;let n=this.db.getReverseDependencyMap(),{files:r,truncated:s}=qt(e,t,n);s&&process.stderr.write(`[Frontend-Code-Skimmer] \u26A0\uFE0F ${e} \u7684 precise \u5F85\u8865\u7B97\u6269\u6563\u5DF2\u8FBE\u4E0A\u9650\uFF08200\uFF09\uFF0C\u90E8\u5206\u4E0B\u6E38\u6587\u4EF6\u5C06\u8DF3\u8FC7\u672C\u8F6E
|
|
455
|
+
`);let o=t==="export_changed"||t==="full_changed"?"high":t==="import_changed"?"normal":"low";for(let a of r)this.enqueuePrecise(a,o);}async indexProject(e){let t=Date.now(),n=e?.include||[...Ft],r=e?.exclude||[...Pt],s=e?.force||false,o=Date.now(),a=await ys(n,{cwd:this.projectRoot,ignore:r,absolute:true,onlyFiles:true}),c=Date.now()-o,l={totalFiles:a.length,indexedFiles:0,skippedFiles:0,totalSymbols:0,durationMs:0,phaseTimings:{discoverFilesMs:c,readFilesMs:0,parseMs:0,saveToDbMs:0,totalMs:0},errors:[]};s&&(this.scheduler.clear(),this.db.clearProjectIndex());let u=0,d=0,p=0;if((e?.precisionMode||"heuristic")==="precise"){let m=[];for(let f=0;f<a.length;f++){let g=a[f],y=he(g,this.projectRoot);e?.onProgress?.(f+1,a.length,y);try{let E=ne__default.statSync(g).mtimeMs,_=Date.now(),x=ne__default.readFileSync(g,"utf-8"),T=Date.now()-_,w=Date.now(),S=qe(g,x),b=Date.now()-w;u+=T,d+=b,m.push({absPath:g,relPath:y,result:S,parseMs:b,readMs:T,content:x,mtime:E});}catch(E){this.db.recordIndexFailure(y,String(E)),l.errors.push({file:y,error:String(E)});}}this.enhancePreciseRelations(m);for(let f of m){let g=Date.now();try{let y=Xe(f.content),E=rt(f.content),_=Buffer.byteLength(f.content,"utf-8"),x=Ye(f.result,f.content);this.db.saveParseResult(f.result,f.absPath,f.relPath,y,_,E,f.mtime,x.exportSignatureHash,x.importSignatureHash),this.db.deletePrecisePending(f.relPath),l.indexedFiles++,l.totalSymbols+=f.result.symbols.length,f.result.errors?.length&&l.errors.push(...f.result.errors.map(T=>({file:f.relPath,error:T}))),p+=Date.now()-g;}catch(y){this.db.recordIndexFailure(f.relPath,String(y)),l.errors.push({file:f.relPath,error:String(y)});}}this.scheduler.clear();}else for(let m=0;m<a.length;m++){let f=a[m],g=he(f,this.projectRoot);e?.onProgress?.(m+1,a.length,g);try{let y=await this.indexFile(f,g,s);y.skipped?l.skippedFiles++:(l.indexedFiles++,l.totalSymbols+=y.symbolCount,u+=y.readMs||0,d+=y.parseMs||0,p+=y.saveMs||0,y.errors?.length&&l.errors.push(...y.errors.map(E=>({file:g,error:E}))));}catch(y){this.db.recordIndexFailure(g,String(y)),l.errors.push({file:g,error:String(y)});}}return l.phaseTimings.readFilesMs=u,l.phaseTimings.parseMs=d,l.phaseTimings.saveToDbMs=p,l.phaseTimings.totalMs=Date.now()-t,l.durationMs=l.phaseTimings.totalMs,l}async selectivePrecise(e){let t=Date.now(),n=e?.maxFiles??20,r=e?.maxTimeMs??1500;this.hydratePendingPreciseQueue(),this.scheduler.configure({maxFiles:n,maxTimeMs:r});let s=this.db.getAllFilePaths(),o=this.db.getReverseDependencyMap(),a=new Set;for(let g of s){let y=this.fileAbsPath(g);if(!ne__default.existsSync(y))continue;let E=this.db.getFileSignatures(g);if(!E){this.scheduler.enqueue(g,"low");continue}let _;try{_=ne__default.statSync(y);let C=this.db.getFileHashAndMtime(g);if(C&&C.mtime===_.mtimeMs&&C.contentHash)continue}catch{continue}let x=ne__default.readFileSync(y,"utf-8"),T=Xe(x);if(E.contentHash===T){this.db.updateFileMtime(g,_.mtimeMs);continue}let w=qe(y,x),S=Ye(w,x),b=Gt(E,S);if(b==="unchanged")continue;let{files:N,truncated:L}=qt(g,b,o);L&&process.stderr.write(`[Frontend-Code-Skimmer] \u26A0\uFE0F ${g} \u7684\u53CD\u5411\u4F9D\u8D56\u6269\u6563\u5DF2\u8FBE\u4E0A\u9650\uFF08200\uFF09\uFF0C\u90E8\u5206\u4E0B\u6E38\u6587\u4EF6\u5C06\u8DF3\u8FC7\u672C\u6B21 precise \u91CD\u7B97
|
|
456
|
+
`);for(let C of N)a.add(C);let I=b==="export_changed"||b==="full_changed"?"high":b==="import_changed"?"normal":"low";for(let C of N)this.scheduler.enqueue(C,I);}let{tasks:c,exceededBudget:l,remainingPending:u}=this.scheduler.dequeueBatch(),d=[],p=[],h=0;for(let g=0;g<c.length;g++){let E=c[g].relPath;if(a.add(E),Date.now()-t>=r){p.push(...c.slice(g));break}let _=this.fileAbsPath(E);if(!ne__default.existsSync(_)){this.removeFile(E),this.db.deletePrecisePending(E);continue}try{let x=ne__default.readFileSync(_,"utf-8"),T=qe(_,x),w=Xe(x),S=rt(x),b=Buffer.byteLength(x,"utf-8");d.push({absPath:_,relPath:E,result:T,content:x,hash:w,lineCount:S,fileSize:b,mtime:ne__default.statSync(_).mtimeMs});}catch(x){this.db.recordIndexFailure(E,String(x)),process.stderr.write(`[Frontend-Code-Skimmer] Selective precise \u5931\u8D25: ${E} - ${String(x)}
|
|
457
|
+
`);}}p.length>0&&this.scheduler.requeue(p),this.enhancePreciseRelations(d);for(let g of d)try{let y=Ye(g.result,g.content);this.db.saveParseResult(g.result,g.absPath,g.relPath,g.hash,g.fileSize,g.lineCount,g.mtime,y.exportSignatureHash,y.importSignatureHash),this.db.deletePrecisePending(g.relPath),h++;}catch(y){this.db.recordIndexFailure(g.relPath,String(y)),process.stderr.write(`[Frontend-Code-Skimmer] Selective precise \u843D\u5E93\u5931\u8D25: ${g.relPath} - ${String(y)}
|
|
458
|
+
`);}let m=Date.now()-t,f=u+p.length;return process.stderr.write(`[Frontend-Code-Skimmer] Selective precise: ${h}/${a.size} affected, ${m}ms, pending: ${f}${l||p.length>0?" (budget limited)":""}
|
|
459
|
+
`),{reindexedFiles:h,affectedFiles:Array.from(a),skippedByBudget:f}}async indexFile(e,t,n=false){let r=0,s=0,o=null;if(!n){try{let w=ne__default.statSync(e);r=w.mtimeMs,s=w.size;}catch{}if(o=this.db.getFileMeta(t),o&&o.mtime>0&&o.mtime===r&&!(o.fileSize>0&&o.fileSize!==s))return {skipped:true,symbolCount:0,readMs:0,parseMs:0,saveMs:0}}let a=n?null:this.db.getFileSignatures(t),c=!n&&(this.db.hasPreciseRelations()||this.db.getPrecisePendingCount()>0),l=Date.now(),u=ne__default.readFileSync(e,"utf-8"),d=Date.now()-l,p=Xe(u);if(!n&&o&&o.hash===p)return r>0&&o.mtime!==r&&this.db.updateFileMtime(t,r),{skipped:true,symbolCount:0,readMs:d,parseMs:0,saveMs:0};let h=rt(u),m=Buffer.byteLength(u,"utf-8"),f=Date.now(),g=qe(e,u),y=Date.now()-f,E=Ye(g,u),_=Gt(a,E),x=Date.now();this.db.clearIndexFailures(t),this.db.saveParseResult(g,e,t,p,m,h,r,E.exportSignatureHash,E.importSignatureHash),c&&this.enqueueAffectedPrecise(t,_);let T=Date.now()-x;return {skipped:false,symbolCount:g.symbols.length,readMs:d,parseMs:y,saveMs:T,errors:g.errors,changeType:_}}removeFile(e){this.db.deleteFile(e);}fileAbsPath(e){return te__default.join(this.projectRoot,e)}async startWatcher(){let{default:e}=await import('chokidar'),t=e.watch([...Ft].map(r=>te__default.posix.join(this.projectRoot,r)),{cwd:this.projectRoot,ignored:[...Pt],persistent:true,ignoreInitial:true,awaitWriteFinish:{stabilityThreshold:En}}),n=async r=>{let s=he(r,this.projectRoot);try{await this.indexFile(r,s),process.stderr.write(`[Frontend-Code-Skimmer] \u5DF2\u66F4\u65B0\u7D22\u5F15: ${s}
|
|
460
|
+
`);}catch(o){process.stderr.write(`[Frontend-Code-Skimmer] \u66F4\u65B0\u5931\u8D25: ${s} - ${String(o)}
|
|
461
|
+
`);}};return t.on("add",n).on("change",n).on("unlink",r=>{let s=he(r,this.projectRoot);this.removeFile(s),process.stderr.write(`[Frontend-Code-Skimmer] \u5DF2\u5220\u9664\u7D22\u5F15: ${s}
|
|
462
|
+
`);}).on("error",async r=>{process.stderr.write(`[Frontend-Code-Skimmer] \u6587\u4EF6\u76D1\u542C\u9519\u8BEF\uFF08\u7D22\u5F15\u4ECD\u53EF\u7528\uFF09: ${String(r)}
|
|
463
|
+
`);try{await t.close();}catch{}}),()=>t.close()}};var Es=8,Ns=30,Ss=14,Ts=360*60*1e3,Tt=class{dbCache=new Map;accessTimes=new Map;indexerCache=new Map;dbPaths=new Map;watcherCleanups=new Map;lastProject=null;globalCacheDir;defaultProject;maxOpenProjects;maxIdleMs;dbTtlMs;lastDiskCleanupAt=0;constructor(){this.globalCacheDir=te__default.join(bs.homedir(),".frontend-code-skimmer","databases"),ne__default.mkdirSync(this.globalCacheDir,{recursive:true}),this.defaultProject=process.env.SKIMMER_PROJECT||null,this.defaultProject&&(this.defaultProject=te__default.resolve(this.defaultProject)),this.maxOpenProjects=this.parsePositiveInt(process.env.SKIMMER_MAX_OPEN_PROJECTS,Es);let e=this.parsePositiveInt(process.env.SKIMMER_DB_IDLE_MINUTES,Ns),t=this.parsePositiveInt(process.env.SKIMMER_DB_TTL_DAYS,Ss);this.maxIdleMs=e*60*1e3,this.dbTtlMs=t*24*60*60*1e3,this.maybeCleanupDiskCache(Date.now());}resolveProjectRoot(e){if(e){let t=te__default.resolve(e);if(!ne__default.existsSync(t))throw new Error(`\u9879\u76EE\u8DEF\u5F84\u4E0D\u5B58\u5728: ${t}`);return t}return this.lastProject?this.lastProject:this.defaultProject?this.defaultProject:process.cwd()}getDatabase(e){let t=te__default.resolve(e),n=Date.now();if(this.evictIdleDatabases(n),this.maybeCleanupDiskCache(n),this.dbCache.has(t))return this.touchProject(t,n),this.dbCache.get(t);this.evictLruIfNeeded(n);let r=this.resolveDbPath(t),s=new it(t,r);return this.dbCache.set(t,s),this.dbPaths.set(t,r),this.touchProject(t,n),this.lastProject=t,process.stderr.write(`[Frontend-Code-Skimmer] \u5DF2\u8FDE\u63A5\u9879\u76EE: ${t}
|
|
463
464
|
`),process.stderr.write(`[Frontend-Code-Skimmer] \u6570\u636E\u5E93: ${r}
|
|
464
|
-
`),s}getContext(e){let t=this.resolveProjectRoot(e),n=this.getDatabase(t);return this.lastProject=t,{db:n,projectRoot:t}}getIndexer(e){let t=this.resolveProjectRoot(e),n=
|
|
465
|
+
`),s}getContext(e){let t=this.resolveProjectRoot(e),n=this.getDatabase(t);return this.lastProject=t,{db:n,projectRoot:t}}getIndexer(e){let t=this.resolveProjectRoot(e),n=te__default.resolve(t),r=Date.now();if(this.evictIdleDatabases(r),this.maybeCleanupDiskCache(r),this.indexerCache.has(n))return this.touchProject(n,r),this.lastProject=n,this.indexerCache.get(n);let s=this.getDatabase(n),o=new St(n,s);return this.indexerCache.set(n,o),this.touchProject(n,r),this.lastProject=n,o}setLastProject(e){this.lastProject=te__default.resolve(e);}listProjects(){return Array.from(this.dbCache.entries()).map(([e])=>({root:e,dbPath:this.dbPaths.get(e)||this.resolveDbPath(e)}))}registerWatcher(e,t){let n=te__default.resolve(e),r=this.watcherCleanups.get(n);if(r)try{r();}catch{}this.watcherCleanups.set(n,t);}hasWatcher(e){let t=te__default.resolve(e);return this.watcherCleanups.has(t)}closeProject(e){let t=te__default.resolve(e),n=this.watcherCleanups.get(t);if(n){try{n();}catch{}this.watcherCleanups.delete(t);}let r=this.dbCache.get(t);r&&(r.close(),this.dbCache.delete(t),this.accessTimes.delete(t),this.indexerCache.delete(t),this.dbPaths.delete(t),this.lastProject===t&&(this.lastProject=null));}closeAll(){for(let e of this.watcherCleanups.values())try{e();}catch{}this.watcherCleanups.clear();for(let e of this.dbCache.values())e.close();this.dbCache.clear(),this.indexerCache.clear(),this.accessTimes.clear(),this.dbPaths.clear(),this.lastProject=null;}resolveDbPath(e){if(process.env.SKIMMER_DB&&this.dbCache.size===0)return te__default.resolve(process.env.SKIMMER_DB);let t=te__default.join(e,".agent","skimmer_find_symbol"),n=te__default.join(t,st);try{return ne__default.mkdirSync(t,{recursive:!0}),ne__default.accessSync(e,ne__default.constants.W_OK),n}catch{let r=createHash("md5").update(e).digest("hex").slice(0,8),s=e.replace(/[/\\:]/g,"_").replace(/^_+/,"").slice(-40);return te__default.join(this.globalCacheDir,`${r}_${s}.db`)}}parsePositiveInt(e,t){let n=Number.parseInt(String(e||""),10);return Number.isFinite(n)&&n>0?n:t}touchProject(e,t){this.accessTimes.set(e,t);}evictLruIfNeeded(e){for(;this.dbCache.size>=this.maxOpenProjects;){let t=null,n=Number.POSITIVE_INFINITY;for(let r of this.dbCache.keys()){let s=this.accessTimes.get(r)??e;s<n&&(n=s,t=r);}if(!t)break;this.closeProject(t);}}evictIdleDatabases(e){let t=[];for(let n of this.dbCache.keys()){if(n===this.lastProject)continue;let r=this.accessTimes.get(n)??e;e-r>this.maxIdleMs&&t.push(n);}for(let n of t)this.closeProject(n);}maybeCleanupDiskCache(e){if(e-this.lastDiskCleanupAt<Ts)return;this.lastDiskCleanupAt=e;let t=[];try{t=ne__default.readdirSync(this.globalCacheDir,{withFileTypes:!0});}catch{return}let n=new Set;for(let s of this.dbPaths.values())s.startsWith(this.globalCacheDir)&&n.add(te__default.resolve(s));let r=e-this.dbTtlMs;for(let s of t){if(!s.isFile()||!s.name.endsWith(".db"))continue;let o=te__default.join(this.globalCacheDir,s.name);if(n.has(te__default.resolve(o)))continue;let a;try{a=ne__default.statSync(o);}catch{continue}a.mtimeMs>=r||(this.safeUnlink(o),this.safeUnlink(`${o}-wal`),this.safeUnlink(`${o}-shm`));}}safeUnlink(e){try{ne__default.existsSync(e)&&ne__default.unlinkSync(e);}catch{}}};var xt=createRequire(import.meta.url);function jn(i,e){let t=[];if(i==="heuristic")return {effective:"heuristic",warnings:t};let n=xt("fs"),r=xt("path");if(!As(e,n,r))return t.push("precise \u6A21\u5F0F\u964D\u7EA7\u4E3A heuristic: \u9879\u76EE\u5185\u672A\u627E\u5230 tsconfig\uFF08\u5DF2\u68C0\u67E5\u6839\u76EE\u5F55\u53CA\u6700\u591A 3 \u5C42\u5B50\u76EE\u5F55\uFF09"),{effective:"heuristic",warnings:t};try{xt.resolve("typescript",{paths:[e]});}catch{try{xt.resolve("typescript");}catch{return t.push("precise \u6A21\u5F0F\u964D\u7EA7\u4E3A heuristic: typescript \u5305\u4E0D\u53EF\u7528\uFF08\u53EF\u80FD\u9700\u8981 npm install\uFF09"),{effective:"heuristic",warnings:t}}}return {effective:"precise",warnings:t}}function As(i,e,t){let n=["tsconfig.json","tsconfig.base.json","tsconfig.app.json","tsconfig.lib.json","tsconfig.node.json"],r=new Set([".git","node_modules","dist","build","coverage",".next",".nuxt"]),s=[{dir:i,depth:0}];for(;s.length>0;){let o=s.shift();if(!o)break;for(let c of n){let l=t.join(o.dir,c);if(e.existsSync(l))return l}if(o.depth>=3)continue;let a;try{a=e.readdirSync(o.dir,{withFileTypes:!0});}catch{continue}for(let c of a)c.isDirectory()&&(r.has(c.name)||s.push({dir:t.join(o.dir,c.name),depth:o.depth+1}));}return null}function Bn(i,e){i.registerTool("skimmer_index_project",{title:"\u7D22\u5F15\u9879\u76EE\u4EE3\u7801\uFF08\u652F\u6301\u4EFB\u610F\u9879\u76EE\uFF09",description:`\u521D\u59CB\u5316\u6216\u589E\u91CF\u66F4\u65B0\u524D\u7AEF\u9879\u76EE\u4EE3\u7801\u7D22\u5F15\u3002\u652F\u6301 Vue2/Vue3/React Hooks\u3002
|
|
465
466
|
\u6BCF\u6B21\u8C03\u7528\u5FC5\u987B\u4F20\u5165 project_path\uFF08\u9879\u76EE\u6839\u76EE\u5F55\u7EDD\u5BF9\u8DEF\u5F84\uFF09\uFF0C\u65E0\u9700\u5728\u542F\u52A8\u65F6\u56FA\u5B9A\u9879\u76EE\u3002
|
|
466
467
|
\u4F18\u5148\u4ECE\u7F16\u8F91\u5668\u5DE5\u4F5C\u533A\u3001\u5DF2\u6253\u5F00\u6587\u4EF6\u548C\u5F53\u524D\u4E0A\u4E0B\u6587\u4E2D\u81EA\u52A8\u63A8\u65AD project_path\uFF0C\u907F\u514D\u5411\u7528\u6237\u8FFD\u95EE\u8DEF\u5F84\u3002
|
|
467
468
|
\u591A\u4E2A\u9879\u76EE\u4F1A\u5E76\u884C\u7F13\u5B58\uFF0C\u5207\u6362\u65E0\u9700\u91CD\u542F\u3002
|
|
@@ -472,45 +473,53 @@ import*as q from'path';import q__default from'path';import {fileURLToPath}from'u
|
|
|
472
473
|
- \u5F3A\u5236\u5168\u91CF\u91CD\u5EFA: force=true
|
|
473
474
|
- \u7CBE\u786E\u7CBE\u5EA6\u6A21\u5F0F: precision_mode="precise"\uFF08\u57FA\u4E8E TypeScript Compiler API \u505A\u8DE8\u6587\u4EF6 import/export \u7ED1\u5B9A\uFF09
|
|
474
475
|
|
|
475
|
-
\u8FD4\u56DE: \u7D22\u5F15\u7EDF\u8BA1\uFF08\u6587\u4EF6\u6570\u3001\u7B26\u53F7\u6570\u3001\u8017\u65F6\u3001\u7CBE\u5EA6\u6A21\u5F0F\uFF09`,inputSchema:z
|
|
476
|
-
`);}});e.setLastProject(l);let
|
|
477
|
-
`);}catch(
|
|
478
|
-
`);}let g=null;if(a)try{let
|
|
479
|
-
`);}let y=
|
|
480
|
-
\u26A0\uFE0F \u89E3\u6790\u5931\u8D25 (${
|
|
481
|
-
`)}]}});}function
|
|
482
|
-
`)}function
|
|
476
|
+
\u8FD4\u56DE: \u7D22\u5F15\u7EDF\u8BA1\uFF08\u6587\u4EF6\u6570\u3001\u7B26\u53F7\u6570\u3001\u8017\u65F6\u3001\u7CBE\u5EA6\u6A21\u5F0F\uFF09`,inputSchema:z.object({project_path:z.string().describe('\u9879\u76EE\u6839\u76EE\u5F55\u7684\u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u5982 "/Users/xxx/projects/my-app"'),force:z.boolean().optional().default(false).describe("\u662F\u5426\u5F3A\u5236\u5168\u91CF\u91CD\u5EFA\uFF08\u9ED8\u8BA4\u589E\u91CF\uFF0C\u53EA\u66F4\u65B0\u53D8\u66F4\u6587\u4EF6\uFF09"),include:z.array(z.string()).optional().describe('\u8981\u5305\u542B\u7684\u6587\u4EF6 glob \u6A21\u5F0F\uFF0C\u5982 ["**/*.vue","**/*.tsx"]'),exclude:z.array(z.string()).optional().describe("\u8981\u989D\u5916\u6392\u9664\u7684 glob \u6A21\u5F0F"),precision_mode:z.enum(["heuristic","precise"]).optional().default("heuristic").describe("\u5206\u6790\u7CBE\u5EA6\u6A21\u5F0F: heuristic(\u5FEB\u901F\uFF0C\u9ED8\u8BA4) | precise(\u8DE8\u6587\u4EF6 import/export \u7ED1\u5B9A\uFF0C\u9700\u8981\u9879\u76EE\u5185\u5B58\u5728 tsconfig)"),selective_precise:z.boolean().optional().default(false).describe("Phase 5: \u662F\u5426\u5728\u7D22\u5F15\u540E\u6267\u884C\u9009\u62E9\u6027 precise \u91CD\u7B97\uFF08\u4EC5\u91CD\u7B97\u53D8\u66F4\u6587\u4EF6+\u53D7\u5F71\u54CD\u6587\u4EF6\uFF09"),max_precise_files:z.number().optional().default(20).describe("\u9009\u62E9\u6027 precise \u5355\u6B21\u6700\u5927\u6587\u4EF6\u6570\uFF08\u9ED8\u8BA4 20\uFF09")}),annotations:{readOnlyHint:false,destructiveHint:false,idempotentHint:true}},async({project_path:t,force:n,include:r,exclude:s,precision_mode:o,selective_precise:a,max_precise_files:c})=>{let{projectRoot:l}=e.getContext(t),u=o||"heuristic",{effective:d,warnings:p}=jn(u,l),h=e.getIndexer(l),m=await h.indexProject({include:r,exclude:s,force:n,precisionMode:d,onProgress:(L,I)=>{(L%20===0||L===I)&&process.stderr.write(`[Frontend-Code-Skimmer] \u8FDB\u5EA6: ${L}/${I}
|
|
477
|
+
`);}});e.setLastProject(l);let f=0;try{let L=Date.now(),I=await h.startWatcher();f=Date.now()-L,e.registerWatcher(l,I),process.stderr.write(`[Frontend-Code-Skimmer] \u6587\u4EF6\u76D1\u542C\u5DF2\u542F\u52A8: ${l}
|
|
478
|
+
`);}catch(L){process.stderr.write(`[Frontend-Code-Skimmer] \u6587\u4EF6\u76D1\u542C\u542F\u52A8\u5931\u8D25\uFF08\u7D22\u5F15\u4ECD\u53EF\u7528\uFF09: ${String(L)}
|
|
479
|
+
`);}let g=null;if(a)try{let L=await h.selectivePrecise({maxFiles:c||20});g={reindexedFiles:L.reindexedFiles,affectedFiles:L.affectedFiles.length,skippedByBudget:L.skippedByBudget};}catch(L){process.stderr.write(`[Frontend-Code-Skimmer] Selective precise \u5931\u8D25: ${String(L)}
|
|
480
|
+
`);}let y=m.indexedFiles>0||m.totalFiles>0,E=m.totalSymbols>0,_=y?"\u2705 \u53EF\u7528":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",x=E?"\u2705 \u53EF\u7528":"\u26A0\uFE0F \u7B26\u53F7\u6570\u4E3A0\uFF08\u89E3\u6790\u53EF\u80FD\u672A\u63D0\u53D6\u5230\u7B26\u53F7\uFF0C\u4F46\u6587\u4EF6\u641C\u7D22\u4ECD\u53EF\u7528\uFF09",T=y?"\u2705 \u53EF\u7528":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",w=y?"\u2705 \u53EF\u7528\uFF08\u57FA\u4E8E\u6B63\u5219\u626B\u63CF\u6587\u4EF6\uFF09":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",S=m.phaseTimings,b=S?["","\u23F1\uFE0F \u3010\u9636\u6BB5\u8017\u65F6\u3011",` \u{1F50D} \u6587\u4EF6\u53D1\u73B0: ${S.discoverFilesMs}ms`,` \u{1F4D6} \u6587\u4EF6\u8BFB\u53D6: ${S.readFilesMs}ms`,` \u{1F52C} \u89E3\u6790: ${S.parseMs}ms`,` \u{1F4BE} \u6570\u636E\u5E93\u5199\u5165: ${S.saveToDbMs}ms`,` \u{1F4CA} \u603B\u8BA1: ${S.totalMs}ms`,` \u{1F4E1} \u6587\u4EF6\u76D1\u542C: ${f}ms`]:[],N=[`\u2705 \u7D22\u5F15\u5B8C\u6210 \u2014 ${l}`,"\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501","","\u{1F4CA} \u3010\u7EDF\u8BA1\u6570\u91CF\u3011\uFF08\u6CE8\u610F\uFF1A\u7B26\u53F7\u65700\u53EF\u80FD\u662F\u89E3\u6790\u89C4\u5219\u672A\u547D\u4E2D\uFF0C\u4E0D\u4EE3\u8868\u7D22\u5F15\u5931\u8D25\uFF09",` \u{1F4C1} \u603B\u6587\u4EF6\u6570: ${m.totalFiles}`,` \u{1F504} \u5DF2\u7D22\u5F15: ${m.indexedFiles}`,` \u23E9 \u5DF2\u8DF3\u8FC7: ${m.skippedFiles} (\u5185\u5BB9\u672A\u53D8)`,` \u{1F523} \u603B\u7B26\u53F7\u6570: ${m.totalSymbols}`,` \u{1F3AF} \u7CBE\u5EA6\u6A21\u5F0F: ${d}`,` \u23F1\uFE0F \u8017\u65F6: ${m.durationMs}ms`,...b,"","\u{1F50C} \u3010\u53EF\u67E5\u8BE2\u80FD\u529B\u72B6\u6001\u3011\uFF08\u4E0E\u7B26\u53F7\u6570\u65E0\u5173\uFF0C\u53EA\u8981\u6587\u4EF6\u626B\u63CF\u5B8C\u6210\u5373\u53EF\u7528\uFF09",` skimmer_find_symbol ${x}`,` skimmer_get_component_outline ${x}`,` skimmer_find_by_behavior ${T}`,` skimmer_trace_data_lifecycle ${w}`,` skimmer_trace_assignments ${w}`,` skimmer_get_code_slice ${_}`," skimmer_index_health \u2705 \u53EF\u7528","","\u{1F4A1} \u540E\u7EED\u5DE5\u5177\u8C03\u7528\u53EF\u7701\u7565 project_path\uFF08\u81EA\u52A8\u4F7F\u7528\u6B64\u9879\u76EE\uFF09"," \u5982\u7B26\u53F7\u6570\u4E3A0\u4F46\u5DE5\u5177\u4ECD\u8FD4\u56DE\u7ED3\u679C\uFF0C\u5C5E\u6B63\u5E38\u73B0\u8C61\uFF08\u6B63\u5219\u626B\u63CF\u8DEF\u5F84\u4E0D\u4F9D\u8D56\u7B26\u53F7\u7D22\u5F15\uFF09","\u{1F441}\uFE0F \u6587\u4EF6\u76D1\u542C\u5DF2\u542F\u52A8 \u2014 \u4EE3\u7801\u53D8\u66F4\u5C06\u81EA\u52A8\u589E\u91CF\u66F4\u65B0\u7D22\u5F15\uFF08\u65E0\u9700\u624B\u52A8\u91CD\u65B0\u7D22\u5F15\uFF09"];if(m.errors.length>0){N.push(`
|
|
481
|
+
\u26A0\uFE0F \u89E3\u6790\u5931\u8D25 (${m.errors.length} \u4E2A):`);for(let L of m.errors.slice(0,5))N.push(` - ${L.file}: ${L.error}`);m.errors.length>5&&N.push(` ... \u8FD8\u6709 ${m.errors.length-5} \u4E2A`);}if(p.length>0){N.push(""),N.push("\u26A0\uFE0F \u7CBE\u5EA6\u964D\u7EA7:");for(let L of p)N.push(` - ${L}`);}if(g){N.push(""),N.push("\u{1F3AF} \u9009\u62E9\u6027 Precise \u91CD\u7B97:"),N.push(` \u{1F4CA} \u91CD\u7B97\u6587\u4EF6: ${g.reindexedFiles}`),N.push(` \u{1F517} \u5F71\u54CD\u6587\u4EF6: ${g.affectedFiles} (\u5019\u9009\u6570)`),g.skippedByBudget>0&&(N.push(` \u23F8\uFE0F \u8D85\u9884\u7B97\u8DF3\u8FC7\u7684\u6587\u4EF6: ${g.skippedByBudget}`),N.push(" \u{1F4A1} \u540E\u7EED watcher \u89E6\u53D1\u6216\u518D\u6B21\u8C03\u7528 selective_precise=true \u7EE7\u7EED"));let L=h.getScheduler().pendingCount;L>0&&N.push(` \u{1F4CB} Pending queue: ${L} \u6587\u4EF6\u5F85\u91CD\u7B97`);}return {content:[{type:"text",text:N.join(`
|
|
482
|
+
`)}]}});}function Jt(i,e,t){try{if(!e||!ne__default.existsSync(e))return {stale:!1};let n=ne__default.statSync(e),r=i.getFileMeta(t);if(!r)return {stale:!1};let s=r.mtime>0&&n.mtimeMs>r.mtime,o=r.fileSize>0&&n.size!==r.fileSize;return s||o?{stale:!0,reason:o?`\u6587\u4EF6\u5927\u5C0F\u5DEE\u5F02 ${n.size-r.fileSize>0?"+":""}${n.size-r.fileSize} \u5B57\u8282`:"\u6587\u4EF6\u4FEE\u6539\u65F6\u95F4\u66F4\u65B0"}:{stale:!1}}catch{return {stale:false}}}function Wn(i,e,t=5){let n=e.slice(0,t),r=[],s=0;for(let o of n){if(!o.abs_path||!ne__default.existsSync(o.abs_path))continue;s++;let{stale:a}=Jt(i,o.abs_path,o.path);a&&r.push(o.path);}return {stale:r.length>0,reason:r.length>0?`${r.length}/${s} \u6587\u4EF6\u5DF2\u4FEE\u6539\u4F46\u7D22\u5F15\u672A\u66F4\u65B0`:void 0,checkedFiles:s,staleFiles:r.length,staleFilePaths:r.slice(0,5)}}function Z(i){return {duration_ms:i.durationMs,result_count:i.resultCount,backend:i.backend,index_freshness:i.indexFreshness,project_count:i.projectCount??1,debug:i.debug,precision_mode_requested:i.precisionRequested,precision_mode_effective:i.precisionEffective,precision_warnings:i.precisionWarnings}}function X(i){let e=[`\u23F1\uFE0F \u8017\u65F6: ${i.duration_ms}ms | \u{1F4CA} \u7ED3\u679C\u6570: ${i.result_count} | \u{1F527} \u540E\u7AEF: ${i.backend}`];if(i.precision_mode_effective){let t=i.precision_mode_effective==="precise"?"\u{1F3AF} \u7CBE\u786E":"\u26A1 \u542F\u53D1\u5F0F",n=i.precision_mode_requested!==i.precision_mode_effective?` (\u8BF7\u6C42: ${i.precision_mode_requested})`:"";e.push(`\u{1F4D0} \u7CBE\u5EA6\u6A21\u5F0F: ${t}${n}`);}if(i.precision_warnings&&i.precision_warnings.length>0)for(let t of i.precision_warnings)e.push(`\u26A0\uFE0F \u7CBE\u5EA6\u8B66\u544A: ${t}`);if(i.index_freshness){let t=i.index_freshness;t.stale?(e.push(`\u26A0\uFE0F \u7D22\u5F15\u65B0\u9C9C\u5EA6: \u5DF2\u8FC7\u671F (${t.staleFiles}/${t.checkedFiles} \u6587\u4EF6) \u2014 ${t.reason||""}`),t.staleFilePaths.length>0&&e.push(` \u8FC7\u671F\u6587\u4EF6: ${t.staleFilePaths.join(", ")}`)):e.push(`\u2705 \u7D22\u5F15\u65B0\u9C9C\u5EA6: \u6700\u65B0 (\u5DF2\u68C0\u67E5 ${t.checkedFiles} \u6587\u4EF6)`);}if(i.debug){if(e.push("\u2500\u2500 \u8C03\u8BD5\u4FE1\u606F \u2500\u2500"),i.debug.phase_timings){e.push("\u9636\u6BB5\u8017\u65F6:");for(let[t,n]of Object.entries(i.debug.phase_timings))e.push(` ${t}: ${n}ms`);}i.debug.query_plan&&e.push(`\u67E5\u8BE2\u8BA1\u5212: ${i.debug.query_plan}`),i.debug.candidate_count!==void 0&&e.push(`\u5019\u9009\u6570: ${i.debug.candidate_count}`),i.debug.scanned_files!==void 0&&e.push(`\u626B\u63CF\u6587\u4EF6\u6570: ${i.debug.scanned_files}`),i.debug.fallback_reason&&e.push(`\u964D\u7EA7\u539F\u56E0: ${i.debug.fallback_reason}`);}return e.join(`
|
|
483
|
+
`)}function Un(i,e){i.registerTool("skimmer_get_component_outline",{title:"\u83B7\u53D6\u7EC4\u4EF6/\u6587\u4EF6\u7ED3\u6784\u9AA8\u67B6",description:`\u5C06\u6570\u5343\u884C\u4EE3\u7801\u538B\u7F29\u4E3A\u6E05\u6670\u7684\u7ED3\u6784\u9AA8\u67B6\uFF08\u7EA6 30-80 \u884C\uFF09\uFF0C\u8282\u7701 90%+ Token\u3002
|
|
483
484
|
\u5305\u542B: props\u3001data/state\u3001computed\u3001methods/functions\u3001watch/effect\u3001lifecycle\u3001\u884C\u4E3A\u6807\u7B7E\u3002
|
|
484
485
|
\u884C\u4E3A\u6807\u7B7E\u81EA\u52A8\u6807\u51FA: [storage:localStorage.setItem] [network:axios.get] \u7B49\u3002
|
|
485
486
|
|
|
486
487
|
project_path \u53EF\u7701\u7565\uFF08\u4F7F\u7528\u4E0A\u6B21 skimmer_index_project \u6307\u5B9A\u7684\u9879\u76EE\uFF09\u3002
|
|
487
|
-
file_path \u4F7F\u7528\u76F8\u5BF9\u4E8E\u9879\u76EE\u6839\u76EE\u5F55\u7684\u8DEF\u5F84\uFF0C\u5982 "src/views/apply/index.vue"\u3002`,inputSchema:z
|
|
488
|
+
file_path \u4F7F\u7528\u76F8\u5BF9\u4E8E\u9879\u76EE\u6839\u76EE\u5F55\u7684\u8DEF\u5F84\uFF0C\u5982 "src/views/apply/index.vue"\u3002`,inputSchema:z.object({file_path:z.string().describe('\u6587\u4EF6\u76F8\u5BF9\u8DEF\u5F84\uFF0C\u5982 "src/views/apply/index.vue"'),project_path:z.string().optional().describe("\u9879\u76EE\u6839\u76EE\u5F55\uFF08\u53EF\u7701\u7565\uFF0C\u4F7F\u7528\u4E0A\u6B21\u7D22\u5F15\u7684\u9879\u76EE\uFF09"),debug:z.boolean().optional().default(false).describe("\u662F\u5426\u8F93\u51FA\u8C03\u8BD5\u5143\u4FE1\u606F")}),annotations:{readOnlyHint:true,destructiveHint:false}},async({file_path:t,project_path:n,debug:r})=>{let s=performance.now(),{db:o}=e.getContext(n),{file:a,symbols:c,behaviors:l}=o.getFileOutline(t);if(!a){let x=Math.round((performance.now()-s)*100)/100,T=Z({durationMs:x,resultCount:0,backend:"indexed"});return {content:[{type:"text",text:`\u274C \u6587\u4EF6\u672A\u7D22\u5F15: ${t}
|
|
488
489
|
|
|
489
490
|
\u8BF7\u5148\u8FD0\u884C:
|
|
490
491
|
skimmer_index_project({ project_path: "${n||"<\u9879\u76EE\u8DEF\u5F84>"}" })
|
|
491
492
|
|
|
492
493
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
493
|
-
${
|
|
494
|
+
${X(T)}`}]}}let u="",d=a.abs_path,{stale:p,reason:h}=Jt(o,d,t);p&&(u=`
|
|
494
495
|
\u26A0\uFE0F [\u7D22\u5F15\u5DF2\u8FC7\u671F] ${h||""}\uFF0C\u884C\u53F7\u53EF\u80FD\u504F\u79FB\uFF08\u7D22\u5F15\u8BB0\u5F55 ${a.line_count} \u884C\uFF0C\u5B9E\u9645\u53EF\u80FD\u5DF2\u53D8\u5316\uFF09
|
|
495
496
|
\u7ACB\u5373\u91CD\u5EFA: skimmer_index_project({ force: true })
|
|
496
|
-
`);let
|
|
497
|
-
${
|
|
498
|
-
${"\u2500".repeat(50)}`),
|
|
497
|
+
`);let m=new Map;for(let x of l){let T=x.symbol_id;m.has(T)||m.set(T,[]);let w=`[${x.category}:${x.api_name}.${x.operation}${x.detail?`("${x.detail}")`:""}]`,S=m.get(T);S.includes(w)||S.push(w);}let f=[];f.push(`\u{1F4C4} ${t} (${a.line_count} \u884C, ${a.framework})`),f.push(`${"\u2501".repeat(50)}`),u&&f.push(u);let g={};for(let x of c){if(x.name==="<template>")continue;let T=x.category;g[T]||(g[T]=[]),g[T].push(x);}let y=[{key:"prop",icon:"\u{1F4E6}",label:"Props"},{key:"state",icon:"\u{1F4CA}",label:"Data / State"},{key:"computed",icon:"\u{1F504}",label:"Computed"},{key:"method",icon:"\u26A1",label:"Methods / Functions"},{key:"effect",icon:"\u{1F440}",label:"Watch / Effect"},{key:"lifecycle",icon:"\u{1F517}",label:"Lifecycle"},{key:"hook",icon:"\u{1FA9D}",label:"Hooks"},{key:"component",icon:"\u{1F9E9}",label:"Components"},{key:"mixin",icon:"\u{1F500}",label:"Mixins"},{key:"provide",icon:"\u{1F489}",label:"Provide / Inject"},{key:"emit",icon:"\u{1F4E1}",label:"Emits"},{key:"filter",icon:"\u{1F50D}",label:"Filters"},{key:"function",icon:"\u{1F527}",label:"Functions"},{key:"constant",icon:"\u{1F4CC}",label:"Constants"}];for(let{key:x,icon:T,label:w}of y){let S=g[x];if(S?.length){f.push(`
|
|
498
|
+
${T} ${w} (${S.length}):`);for(let b of S){let N=b.name,L=Te(b.start_line,b.end_line),I=Ke(b.params_json,[]),C=I.length>0?`(${I.join(", ")})`:"",P=b.default_value?` = ${b.default_value}`:"",K=b.is_async?"async ":"",V=m.get(b.id),pe=V?.length?` ${V.slice(0,3).join(" ")}`:"",ee=b.state_setter_name?` \u2192 ${b.state_setter_name}`:"",Re=b.hook_deps_json?` [deps:${Ke(b.hook_deps_json,[]).join(",")}]`:"";f.push(` \u2022 ${K}${N}${C}${P}${ee}${Re} ${L}${pe}`);}}}f.push(`
|
|
499
|
+
${"\u2500".repeat(50)}`),f.push(`\u{1F4A1} \u67E5\u770B\u5177\u4F53\u4EE3\u7801: skimmer_get_code_slice({ file_path: "${t}", symbol_name: "\u65B9\u6CD5\u540D" })`);let E=Math.round((performance.now()-s)*100)/100,_=Z({durationMs:E,resultCount:c.length,backend:"indexed"});return r&&(_.debug={scanned_files:1}),f.push(`
|
|
499
500
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
500
|
-
${
|
|
501
|
-
`)}]}});}var Ve=class{constructor(e){this.db=e;}db;search(e,t){let{category:n,framework:r,filePath:s,limit:i=dn,fuzzy:a=true,allowFallbackScan:c=false,debug:l=false}=t||{},p=e.trim(),u=new Map,d={},h=performance.now(),f=this.db.exactSearch(p,n,r,s);for(let L of f)u.set(L.id,{symbol:L,filePath:L.file_path,score:100,matchReason:"\u7CBE\u786E\u5339\u914D"});if(d["1_exact"]=Math.round((performance.now()-h)*100)/100,u.size>=i)return {results:this.rankResults(u,i)};let m=performance.now(),g=0,y=w(p),S=[p,y,...y.split(" ")].filter(Boolean).filter((L,_,N)=>N.indexOf(L)===_);for(let L of S){if(L.length<2)continue;let _=this.db.ftsSearch(L,n,r,s,i);g+=_.length;for(let N of _){let A=N.id;if(u.has(A))continue;let k=this.calcFtsScore(p,N.name);u.set(A,{symbol:N,filePath:N.file_path,score:k,matchReason:`FTS5 \u524D\u7F00\u5339\u914D ("${L}")`});}}if(d["2_fts"]=Math.round((performance.now()-m)*100)/100,u.size>=i)return {results:this.rankResults(u,i),debug:l?{phase_timings:d,candidate_count:g}:void 0};let b=a&&p.length>=3,T=0;if(b){let L=performance.now(),_=this.db.getAllSymbolNames(s),N=p.toLowerCase(),A=w(p).split(" ");for(let{name:k,file_path:P,id:I}of _){if(u.has(I))continue;T++;let B=Ze(N,k.toLowerCase()),se=Math.max(N.length,k.length),be=Math.min(un,Math.max(1,Math.floor(se*.28)));if(B<=be){let Z=Math.max(0,80-B*15),Y=this.db.getSymbolById(I);if(!Y||n&&Y.category!==n||r&&Y.framework!==r)continue;let qe=rn(p,k,B);u.set(I,{symbol:Y,filePath:P,score:Z,matchReason:`\u6A21\u7CCA\u5339\u914D (\u7F16\u8F91\u8DDD\u79BB=${B})`,spellingSuggestion:qe});continue}let Re=w(k).split(" "),J=A.filter(Z=>Re.some(Y=>Y.length>=3&&nn(Z,Y)>=75));if(A.length>1?J.length===A.length:J.length>0){let Z=50+J.length*10,Y=this.db.getSymbolById(I);if(!Y||n&&Y.category!==n||r&&Y.framework!==r)continue;u.set(I,{symbol:Y,filePath:P,score:Z,matchReason:`\u5355\u8BCD\u5339\u914D (${J.join(", ")})`});}}d["3_fuzzy"]=Math.round((performance.now()-L)*100)/100;}if(u.size===0&&c){let L=performance.now(),_=this.db.ftsSearchWithFallback(p,n,r,s,i);for(let N of _){let A=N.id;u.has(A)||u.set(A,{symbol:N,filePath:N.file_path,score:50,matchReason:"LIKE \u5168\u8868\u626B\u63CF fallback"});}d["4_fallback"]=Math.round((performance.now()-L)*100)/100;}let E=l?{phase_timings:d,candidate_count:g+T,fallback_reason:!b&&p.length<3?"\u67E5\u8BE2\u8FC7\u77ED (<3\u5B57\u7B26)\uFF0C\u8DF3\u8FC7\u6A21\u7CCA\u5339\u914D":void 0}:void 0;return {results:this.rankResults(u,i),debug:E}}calcFtsScore(e,t){let n=e.toLowerCase(),r=t.toLowerCase();if(r===n)return 98;if(r.startsWith(n))return 91;if(r.includes(n))return 80;let s=w(e).split(" "),i=w(t).split(" "),a=s.some(l=>i[0]?.startsWith(l))?8:0,c=s.filter(l=>i.some(p=>p.startsWith(l))).length;return Math.min(88,58+c*8+a)}rankResults(e,t){return Array.from(e.values()).sort((n,r)=>r.score-n.score).slice(0,t)}searchByBehavior(e){return this.db.behaviorSearch(e.category,e.apiName,e.operation,e.keyword,e.filePath).map(n=>({symbolName:n.symbol_name,category:n.category,apiName:n.api_name,operation:n.operation,detail:n.detail,line:n.line_number,filePath:n.file_path,startLine:n.start_line,endLine:n.end_line}))}};var Bn=createRequire(import.meta.url),Ne="\u9879\u76EE\u6839\u76EE\u5F55\uFF08\u53EF\u7701\u7565\uFF0C\u81EA\u52A8\u4F7F\u7528\u4E0A\u6B21 skimmer_index_project \u6307\u5B9A\u7684\u9879\u76EE\uFF09";function ge(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var ze="(?:=|\\+=|-=|\\*=|\\/=|%=|\\|=|&=|\\^=|&&=|\\|\\|=|\\?\\?=)",Hn="(?:push|pop|shift|unshift|splice|sort|reverse|copyWithin|fill)";async function Fn(o,e,t,n,r){if(!n)return null;let s=t.getPrecisePendingCount();if(s<=0)return null;let i=await o.getIndexer(e).selectivePrecise({maxFiles:r,maxTimeMs:1500});return {pendingBefore:s,reindexedFiles:i.reindexedFiles,affectedFiles:i.affectedFiles.length,skippedByBudget:i.skippedByBudget}}function Dn(o){if(!o)return [];let e=[`\u{1F504} \u5DF2\u81EA\u52A8\u8865\u7B97 pending precise: ${o.reindexedFiles}/${o.affectedFiles} \u6587\u4EF6\uFF08\u67E5\u8BE2\u524D\u5F85\u8865 ${o.pendingBefore}\uFF09`];return o.skippedByBudget>0&&e.push(` \u23F8\uFE0F \u4ECD\u6709 ${o.skippedByBudget} \u4E2A precise pending \u6587\u4EF6\u53D7\u9884\u7B97\u9650\u5236\u672A\u8865\u5B8C\uFF0C\u53EF\u518D\u6B21\u67E5\u8BE2\u6216\u8C03\u7528 selective_precise=true \u7EE7\u7EED`),e.push(""),e}function Ie(o,e,t){let n=[];for(let r of o){if(!r?.abs_path||!te__default.existsSync(r.abs_path))continue;let s=te__default.readFileSync(r.abs_path,"utf-8").split(`
|
|
502
|
-
`)
|
|
503
|
-
`).
|
|
501
|
+
${X(_)}`),{content:[{type:"text",text:f.join(`
|
|
502
|
+
`)}]}});}var U={symbolWordHitBoost:8,compactSpanBoost:4,fileCoherence:{maxBoost:40,perExtraHit:24},noisePenalty:{testFile:-40,exampleFile:-18,declarationFile:-25},fileRoleBoost:{businessByIntent:{symbol_like:0,behavior_like:14,api_like:24,natural_language:12},componentByIntent:{symbol_like:0,behavior_like:6,api_like:8,natural_language:4},utilityByIntent:{symbol_like:0,behavior_like:-10,api_like:-22,natural_language:-6}},behaviorMatchBoost:{category:20,apiByIntent:{symbol_like:20,behavior_like:22,api_like:26,natural_language:20},operationByIntent:{symbol_like:25,behavior_like:25,api_like:30,natural_language:25},keyword:10},behaviorKeywordMatchBoost:{detail:18,api:10,operation:8,category:12,apiByIntent:{symbol_like:12,behavior_like:12,api_like:18,natural_language:12},operationByIntent:{symbol_like:15,behavior_like:15,api_like:20,natural_language:15}},byIntent:{symbol_like:{symbolCandidateAdjust:12,behaviorCandidateBase:110,behaviorKeywordCandidateBase:86,executableDefinitionBoost:10,behaviorDefinitionBoost:5,allowFileCoherence:false},behavior_like:{symbolCandidateAdjust:-2,behaviorCandidateBase:115,behaviorKeywordCandidateBase:92,executableDefinitionBoost:14,behaviorDefinitionBoost:7,allowFileCoherence:true},api_like:{symbolCandidateAdjust:-18,behaviorCandidateBase:124,behaviorKeywordCandidateBase:102,executableDefinitionBoost:14,behaviorDefinitionBoost:10,allowFileCoherence:true},natural_language:{symbolCandidateAdjust:-10,behaviorCandidateBase:112,behaviorKeywordCandidateBase:92,executableDefinitionBoost:16,behaviorDefinitionBoost:8,allowFileCoherence:true}}};var Ls=new Set(["function","method","hook","effect","lifecycle"]);function Hn(i,e,t){let n=Array.from(i,a=>({...a}));if(n.length===0)return [];let r=new Map;for(let a of n)r.set(a.filePath,(r.get(a.filePath)||0)+1);for(let a of n){let c=[],l=Rs(a,e);l>0&&(a.score+=l,c.push(`definition boost(${l})`));let u=ws(a,r,e);u>0&&(a.score+=u,c.push(`file coherence(${r.get(a.filePath)||1})`));let d=ks(a.filePath);d!==0&&(a.score+=d,c.push(`noise penalty(${d})`));let p=vs(a.filePath,e);p!==0&&(a.score+=p,c.push(`file role(${p})`)),c.length>0&&(a.matchReason=`${a.matchReason} + ${c.join(" + ")}`);}let s=n.sort((a,c)=>c.score-a.score||a.filePath.localeCompare(c.filePath)).slice(0,t),o=Ps(s);return s.map((a,c)=>({...a,displayScore:o[c]??0}))}function Rs(i,e){let t=U.byIntent[e],n=0;Ls.has(i.category||"")&&(n+=t.executableDefinitionBoost),(i.behaviors?.length||0)>0&&(n+=t.behaviorDefinitionBoost);let r=Math.max(1,i.endLine-i.startLine+1);return n>0&&r<=30&&(n+=U.compactSpanBoost),n}function ws(i,e,t){if(!U.byIntent[t].allowFileCoherence)return 0;let n=e.get(i.filePath)||0;return n<=1?0:Math.min(U.fileCoherence.maxBoost,(n-1)*U.fileCoherence.perExtraHit)}function ks(i){let e=i.toLowerCase();return e.includes("__tests__")||e.includes("/tests/")||e.endsWith(".test.ts")||e.endsWith(".spec.ts")?U.noisePenalty.testFile:/(mock|fixture|demo|example|sample)/.test(e)?U.noisePenalty.exampleFile:e.endsWith(".d.ts")?U.noisePenalty.declarationFile:0}function vs(i,e){let t=i.toLowerCase();return $s(t)?U.fileRoleBoost.utilityByIntent[e]:Cs(t)?U.fileRoleBoost.businessByIntent[e]:Is(t)?U.fileRoleBoost.componentByIntent[e]:0}function Cs(i){return /(^|\/)(views|pages|screens|features|modules)\//.test(i)}function Is(i){return /(^|\/)components\//.test(i)}function $s(i){return /(^|\/)(config|utils|helpers|lib|shared)\//.test(i)||/(utils?|helpers?|storage|cache|fetch)\.(js|ts|vue|tsx|jsx)$/.test(i)}function Ps(i){if(i.length===0)return [];if(i.length===1)return [100];let e=i.map(r=>r.score),t=Math.max(...e),n=Math.min(...e);return t===n?i.map((r,s)=>Math.max(0,100-s*5)):e.map(r=>{let s=55+(r-n)/(t-n)*45;return Math.max(0,Math.min(100,Math.round(s)))})}var Xn=new Set(["a","an","and","are","as","at","be","by","for","from","how","in","into","is","of","on","or","the","to","with","where","what","which"]);function Lt(i){let e=i.trim();if(!e)return "natural_language";let t=en(e);return Fs(e,t)?"api_like":/[A-Z]/.test(e)||/[_./:#()[\]{}]/.test(e)||/^[a-zA-Z][a-zA-Z0-9]+$/.test(e)?"symbol_like":t?"behavior_like":"natural_language"}function Zt(i){return i.toLowerCase().replace(/[^a-z0-9_\u4e00-\u9fa5\s]/gi," ").split(/\s+/).filter(Boolean).filter(t=>!Xn.has(t)).join(" ")||i}function Kn(i){return i.toLowerCase().replace(/[^a-z0-9_\u4e00-\u9fa5\s-]/gi," ").split(/[\s-]+/).filter(Boolean).filter(e=>e.length>=3).filter(e=>!Xn.has(e))}function en(i){let e=i.toLowerCase(),t=Vn(i),n=ce(t,["cache","storage","localstorage","sessionstorage","draft","\u8349\u7A3F","\u7F13\u5B58"]),r=ce(t,["fetch","axios","request","api","network","http"]),s=ce(t,["route","router","navigate","jump","push","replace","\u8DEF\u7531","\u8DF3\u8F6C"]);return n?{category:"storage",apiName:e.includes("sessionstorage")?"sessionStorage":e.includes("localstorage")?"localStorage":void 0,operation:Os(t)}:r?{category:"network",apiName:e.includes("axios")?"axios":e.includes("fetch")?"fetch":void 0,operation:Ds(t)}:s?{category:"router",operation:/(push|replace|jump|navigate|跳转)/.test(e)?"push":void 0}:null}function zn(i,e,t){if(!t)return false;if(i==="api_like"||i==="behavior_like"||i==="natural_language")return true;let n=Vn(e);return ce(n,["localstorage","sessionstorage","axios","fetch","router","navigate"])}function Fs(i,e){let t=i.toLowerCase(),n=/\b[a-z_$][\w$]*\s*\.\s*[a-z_$][\w$]*/i.test(i),r=/(localstorage|sessionstorage|axios|fetch|\$router|router|navigate|history)/.test(t),s=/(setitem|getitem|removeitem|clear|push|replace|get|post|put|delete|patch|navigate|dispatch|commit)/.test(t);return !!(r&&(s||n)||n&&e?.category||e?.apiName&&e?.operation)}function Os(i){if(Qt(i,["get","item"]))return "getItem";if(Qt(i,["set","item"]))return "setItem";if(Qt(i,["remove","item"]))return "removeItem";if(ce(i,["read","load","restore","getitem","\u8BFB\u53D6","\u6062\u590D"]))return "getItem";if(ce(i,["remove","delete","clear","\u6E05\u9664","\u5220\u9664","removeitem"]))return "removeItem";if(ce(i,["save","write","persist","store","setitem","\u7F13\u5B58","\u5199\u5165"]))return "setItem"}function Ds(i){if(ce(i,["post","create","submit"]))return "post";if(ce(i,["put","update"]))return "put";if(ce(i,["delete","remove"]))return "delete";if(ce(i,["patch"]))return "patch";if(ce(i,["get","fetch","load","request"]))return "get"}function Vn(i){return k(i).toLowerCase().replace(/[^a-z0-9_\u4e00-\u9fa5\s-]/gi," ").split(/[\s-]+/).filter(Boolean)}function ce(i,e){return e.some(t=>i.includes(t))}function Qt(i,e){for(let t=0;t<=i.length-e.length;t+=1)if(e.every((n,r)=>i[t+r]===n))return true;return false}var $e=class{constructor(e){this.db=e;}db;search(e,t){let{category:n,framework:r,filePath:s,limit:o=bn,fuzzy:a=true,allowFallbackScan:c=false,debug:l=false}=t||{},u=e.trim(),d=new Map,p={},h=performance.now(),m=this.db.exactSearch(u,n,r,s);for(let w of m)d.set(w.id,{symbol:w,filePath:w.file_path,score:100,matchReason:"\u7CBE\u786E\u5339\u914D"});if(p["1_exact"]=Math.round((performance.now()-h)*100)/100,d.size>=o)return {results:this.rankResults(d,o)};let f=performance.now(),g=0,y=k(u),E=[u,y,...y.split(" ")].filter(Boolean).filter((w,S,b)=>b.indexOf(w)===S);for(let w of E){if(w.length<2)continue;let S=this.db.ftsSearch(w,n,r,s,o);g+=S.length;for(let b of S){let N=b.id;if(d.has(N))continue;let L=this.calcFtsScore(u,b.name);d.set(N,{symbol:b,filePath:b.file_path,score:L,matchReason:`FTS5 \u524D\u7F00\u5339\u914D ("${w}")`});}}if(p["2_fts"]=Math.round((performance.now()-f)*100)/100,d.size>=o)return {results:this.rankResults(d,o),debug:l?{phase_timings:p,candidate_count:g}:void 0};let _=a&&u.length>=3,x=0;if(_){let w=performance.now(),S=this.db.getAllSymbolNames(s),b=u.toLowerCase(),N=k(u).split(" ");for(let{name:L,file_path:I,id:C}of S){if(d.has(C))continue;x++;let P=nt(b,L.toLowerCase()),K=Math.max(b.length,L.length),V=Math.min(_n,Math.max(1,Math.floor(K*.28)));if(P<=V){let H=Math.max(0,80-P*15),z=this.db.getSymbolById(C);if(!z||n&&z.category!==n||r&&z.framework!==r)continue;let we=un(u,L,P);d.set(C,{symbol:z,filePath:I,score:H,matchReason:`\u6A21\u7CCA\u5339\u914D (\u7F16\u8F91\u8DDD\u79BB=${P})`,spellingSuggestion:we});continue}let pe=k(L).split(" "),ee=N.filter(H=>pe.some(z=>z.length>=3&&pn(H,z)>=75));if(N.length>1?ee.length===N.length:ee.length>0){let H=50+ee.length*10,z=this.db.getSymbolById(C);if(!z||n&&z.category!==n||r&&z.framework!==r)continue;d.set(C,{symbol:z,filePath:I,score:H,matchReason:`\u5355\u8BCD\u5339\u914D (${ee.join(", ")})`});}}p["3_fuzzy"]=Math.round((performance.now()-w)*100)/100;}if(d.size===0&&c){let w=performance.now(),S=this.db.ftsSearchWithFallback(u,n,r,s,o);for(let b of S){let N=b.id;d.has(N)||d.set(N,{symbol:b,filePath:b.file_path,score:50,matchReason:"LIKE \u5168\u8868\u626B\u63CF fallback"});}p["4_fallback"]=Math.round((performance.now()-w)*100)/100;}let T=l?{phase_timings:p,candidate_count:g+x,fallback_reason:!_&&u.length<3?"\u67E5\u8BE2\u8FC7\u77ED (<3\u5B57\u7B26)\uFF0C\u8DF3\u8FC7\u6A21\u7CCA\u5339\u914D":void 0}:void 0;return {results:this.rankResults(d,o),debug:T}}calcFtsScore(e,t){let n=e.toLowerCase(),r=t.toLowerCase();if(r===n)return 98;if(r.startsWith(n))return 91;if(r.includes(n))return 80;let s=k(e).split(" "),o=k(t).split(" "),a=s.some(l=>o[0]?.startsWith(l))?8:0,c=s.filter(l=>o.some(u=>u.startsWith(l))).length;return Math.min(88,58+c*8+a)}rankResults(e,t){return Array.from(e.values()).sort((n,r)=>r.score-n.score).slice(0,t)}searchByBehavior(e){return this.db.behaviorSearch(e.category,e.apiName,e.operation,e.keyword,e.filePath).map(n=>({symbolId:n.symbol_id,symbolName:n.symbol_name,category:n.category,apiName:n.api_name,operation:n.operation,detail:n.detail,line:n.line_number,filePath:n.file_path,startLine:n.start_line,endLine:n.end_line}))}searchSnippets(e,t){let n=e.trim();if(!n)return [];let{filePath:r,limit:s=8,contextLines:o=1,maxLines:a=24}=t||{},c=Lt(n),l=new Map,u=Kn(n),d=Zt(n),p=this.search(d,{filePath:r,limit:Math.max(s*2,8),fuzzy:c!=="natural_language",allowFallbackScan:false}).results;for(let y of p){let E=y.symbol,_=this.buildSnippetCandidateFromSymbol({symbol:E,filePath:y.filePath,baseScore:this.scoreSymbolCandidate(c,n,y),matchReason:this.describeSymbolReason(c,y.matchReason)});_&&this.mergeSnippetCandidate(l,_);}let h=en(n),f=zn(c,n,h)?h:null;if(f){let y=this.searchByBehavior({category:f.category,apiName:f.apiName,operation:f.operation,keyword:f.keyword,filePath:r});for(let E of y){let _=E.symbolId;if(typeof _!="number")continue;let x=this.db.getSymbolById(_);if(!x)continue;let T=this.buildSnippetCandidateFromSymbol({symbol:x,filePath:E.filePath,baseScore:this.scoreBehaviorCandidate(f,c,E),matchReason:this.describeBehaviorReason(f,E)});T&&this.mergeSnippetCandidate(l,T);}}if(u.length>0)for(let y of u.slice(0,3)){let E=this.searchByBehavior({category:f?.category,apiName:f?.apiName,operation:f?.operation,keyword:y,filePath:r});for(let _ of E){let x=_.symbolId;if(typeof x!="number")continue;let T=this.db.getSymbolById(x);if(!T)continue;let w=this.buildSnippetCandidateFromSymbol({symbol:T,filePath:_.filePath,baseScore:this.scoreBehaviorKeywordCandidate(y,f,c,_),matchReason:`behavior keyword "${y}" \u547D\u4E2D \u2192 ${_.apiName}.${_.operation}`});w&&this.mergeSnippetCandidate(l,w);}}return Hn(l.values(),c,s).map(y=>this.toSnippetResult(y,o,a,y.displayScore)).filter(y=>!!y)}scoreSymbolCandidate(e,t,n){let r=U.byIntent[e],s=n.score+r.symbolCandidateAdjust,o=n.symbol,a=String(o.name||""),c=String(o.signature||""),l=String(o.jsdoc||""),d=Zt(t).toLowerCase().split(/\s+/).filter(Boolean),p=`${a} ${c} ${l}`.toLowerCase();if(d.length>0){let h=d.filter(m=>p.includes(m)).length;s+=h*U.symbolWordHitBoost;}return s}scoreBehaviorCandidate(e,t,n){let s=U.byIntent[t].behaviorCandidateBase;return e.category&&n.category===e.category&&(s+=U.behaviorMatchBoost.category),e.apiName&&n.apiName.toLowerCase()===e.apiName.toLowerCase()&&(s+=U.behaviorMatchBoost.apiByIntent[t]),e.operation&&n.operation.toLowerCase()===e.operation.toLowerCase()&&(s+=U.behaviorMatchBoost.operationByIntent[t]),e.keyword&&(n.detail||"").toLowerCase().includes(e.keyword.toLowerCase())&&(s+=U.behaviorMatchBoost.keyword),s}scoreBehaviorKeywordCandidate(e,t,n,r){let o=U.byIntent[n].behaviorKeywordCandidateBase;return (r.detail||"").toLowerCase().includes(e.toLowerCase())&&(o+=U.behaviorKeywordMatchBoost.detail),r.apiName.toLowerCase().includes(e.toLowerCase())&&(o+=U.behaviorKeywordMatchBoost.api),r.operation.toLowerCase().includes(e.toLowerCase())&&(o+=U.behaviorKeywordMatchBoost.operation),t?.category&&r.category===t.category&&(o+=U.behaviorKeywordMatchBoost.category),t?.apiName&&r.apiName.toLowerCase()===t.apiName.toLowerCase()&&(o+=U.behaviorKeywordMatchBoost.apiByIntent[n]),t?.operation&&r.operation.toLowerCase()===t.operation.toLowerCase()&&(o+=U.behaviorKeywordMatchBoost.operationByIntent[n]),o}describeSymbolReason(e,t){return e==="symbol_like"?`symbol \u547D\u4E2D: ${t}`:e==="api_like"?`API \u67E5\u8BE2\u8865\u5145\u547D\u4E2D: ${t}`:e==="natural_language"?`\u81EA\u7136\u8BED\u8A00\u8865\u5145\u547D\u4E2D: ${t}`:`\u6DF7\u5408\u547D\u4E2D: ${t}`}describeBehaviorReason(e,t){return `behavior \u547D\u4E2D (${[e.category?`category=${e.category}`:null,e.apiName?`api=${e.apiName}`:null,e.operation?`operation=${e.operation}`:null].filter(Boolean).join(", ")||"\u5173\u952E\u8BCD"}) \u2192 ${t.apiName}.${t.operation}`}buildSnippetCandidateFromSymbol(e){let t=e.symbol,n=String(t.abs_path||""),r=e.filePath||String(t.file_path||""),s=Number(t.start_line||0),o=Number(t.end_line||0),a=Number(t.id||0),c=String(t.name||"");if(!n||!r||!s||!o||!c)return null;let l=this.getBehaviorLabels(r,a);return {key:`${r}:${s}:${o}:${c}`,symbolName:c,category:String(t.category||""),framework:String(t.framework||""),filePath:r,absPath:n,startLine:s,endLine:o,score:e.baseScore,matchReason:e.matchReason,behaviors:l}}mergeSnippetCandidate(e,t){let n=e.get(t.key);if(!n){e.set(t.key,t);return}n.score=Math.max(n.score,t.score),n.matchReason.includes(t.matchReason)||(n.matchReason=`${n.matchReason} + ${t.matchReason}`),n.behaviors=[...new Set([...n.behaviors||[],...t.behaviors||[]])];}toSnippetResult(e,t,n,r){if(!ne__default.existsSync(e.absPath))return null;let o=ne__default.readFileSync(e.absPath,"utf-8").split(`
|
|
503
|
+
`),a=Math.max(0,e.startLine-1-t),c=Math.min(o.length-1,e.endLine-1+t),l=Math.min(c,a+Math.max(1,n)-1),u=o.slice(a,l+1).join(`
|
|
504
|
+
`),p=u.includes(e.symbolName)?void 0:`\u26A0\uFE0F [\u884C\u53F7\u504F\u79FB] \u7D22\u5F15\u8BB0\u5F55 ${e.symbolName} \u5728 ${e.filePath}:L${e.startLine}-L${e.endLine}\uFF0C\u4F46\u5F53\u524D\u4F4D\u7F6E\u7247\u6BB5\u672A\u51FA\u73B0\u8BE5\u7B26\u53F7\uFF1B\u6587\u4EF6\u53EF\u80FD\u5DF2\u4FEE\u6539\u4F46\u672A\u91CD\u65B0\u7D22\u5F15\u3002\u5EFA\u8BAE: skimmer_index_project({ force: true })`;return {symbolName:e.symbolName,category:e.category,framework:e.framework,filePath:e.filePath,startLine:a+1,endLine:l+1,snippet:u,score:r,matchReason:e.matchReason,behaviors:e.behaviors,offsetWarning:p}}getBehaviorLabels(e,t){return this.db.getFileOutline(e).behaviors.filter(r=>r.symbol_id===t).map(r=>`[${r.category}:${r.api_name}.${r.operation}${r.detail?`("${r.detail}")`:""}]`)}};function Yn(i){let e=i.toLowerCase();return /数据流|数据流向|怎么赋值|从哪来|去了哪|传递|修改|生命周期|循环|来源|流向|追踪|数据链/.test(e)?"lifecycle":/影响|风险|改了|改动|修改.*后果|波及|会不会|破坏|影响面|改动.*影响/.test(e)?"blast_radius":/localStorage|sessionStorage|cookie|API|存储|写入|读取|请求|接口|fetch|axios|路由|跳转|行为|操作.*API/.test(e)?"behavior":/谁调用了|被谁|调用.*关系|调用链|call|依赖|层级|调用堆栈|调用图/.test(e)?"call_graph":/源码|代码.*片段|怎么实现|怎么写的|实现.*细节|读代码/.test(e)?"code_slice":/找|搜索|查.*代码|查.*函数|在哪里|哪个文件|找到|检索/.test(e)||/[a-z]+[A-Z]/.test(e)?"search":"generic"}function Jn(i){let e=[],t=i.match(/[a-z_][a-zA-Z0-9_]*[A-Z][a-zA-Z0-9_]*/g);t&&e.push(...t);let n=i.match(/\b[A-Z][a-z]+[A-Z][a-zA-Z0-9_]*/g);n&&e.push(...n);let r=i.matchAll(/['"]([a-zA-Z_$][\w$]*)['"]/g);for(let o of r)e.push(o[1]);let s=i.match(/[\u4e00-\u9fff]+([a-zA-Z]\w{2,})/g);if(s)for(let o of s){let a=o.replace(/[\u4e00-\u9fff]/g,"");a.length>=2&&e.push(a);}return [...new Set(e)]}var qn={lifecycle:["symbol_lookup","lifecycle_trace","call_graph","behavior_scan"],blast_radius:["symbol_lookup","blast_radius","call_graph","behavior_scan"],behavior:["symbol_lookup","behavior_scan","snippet_search"],call_graph:["symbol_lookup","call_graph","code_slice"],search:["symbol_lookup","snippet_search","behavior_scan"],code_slice:["symbol_lookup","code_slice","behavior_scan"],generic:["symbol_lookup","snippet_search","behavior_scan","call_graph"]};function Qn(i,e,t,n){return {intent:i,validatedSymbols:t,dimensions:qn[i]||qn.generic,question:n}}var sr=createRequire(import.meta.url),Le="\u9879\u76EE\u6839\u76EE\u5F55\uFF08\u53EF\u7701\u7565\uFF0C\u81EA\u52A8\u4F7F\u7528\u4E0A\u6B21 skimmer_index_project \u6307\u5B9A\u7684\u9879\u76EE\uFF09";function Pe(i){return i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var Je="(?:=|\\+=|-=|\\*=|\\/=|%=|\\|=|&=|\\^=|&&=|\\|\\|=|\\?\\?=)",ir="(?:push|pop|shift|unshift|splice|sort|reverse|copyWithin|fill)";async function Zn(i,e,t,n,r){if(!n)return null;let s=t.getPrecisePendingCount();if(s<=0)return null;let o=await i.getIndexer(e).selectivePrecise({maxFiles:r,maxTimeMs:1500});return {pendingBefore:s,reindexedFiles:o.reindexedFiles,affectedFiles:o.affectedFiles.length,skippedByBudget:o.skippedByBudget}}function er(i){if(!i)return [];let e=[`\u{1F504} \u5DF2\u81EA\u52A8\u8865\u7B97 pending precise: ${i.reindexedFiles}/${i.affectedFiles} \u6587\u4EF6\uFF08\u67E5\u8BE2\u524D\u5F85\u8865 ${i.pendingBefore}\uFF09`];return i.skippedByBudget>0&&e.push(` \u23F8\uFE0F \u4ECD\u6709 ${i.skippedByBudget} \u4E2A precise pending \u6587\u4EF6\u53D7\u9884\u7B97\u9650\u5236\u672A\u8865\u5B8C\uFF0C\u53EF\u518D\u6B21\u67E5\u8BE2\u6216\u8C03\u7528 selective_precise=true \u7EE7\u7EED`),e.push(""),e}function Rt(i,e,t){let n=[];for(let r of i){if(!r?.abs_path||!ne__default.existsSync(r.abs_path))continue;let s=ne__default.readFileSync(r.abs_path,"utf-8").split(`
|
|
505
|
+
`);for(let o=0;o<s.length;o++){let a=s[o];for(let c of e)if(c.regex.test(a)){n.push({filePath:r.path,line:o+1,kind:c.kind,text:a.trim()});break}if(n.length>=t)return n}}return n}function js(i,e){let t=Pe(i),n=[{kind:"declaration",regex:new RegExp(`\\b(?:const|let|var)\\s+${t}\\b`)},{kind:"assignment",regex:new RegExp(`\\b${t}\\b\\s*${Je}`)},{kind:"update",regex:new RegExp(`(?:\\+\\+|--)\\s*\\b${t}\\b|\\b${t}\\b\\s*(?:\\+\\+|--)`)}];return n}function vt(i){try{return sr("@babel/parser").parse(i,{sourceType:"module",plugins:["typescript","jsx","decorators-legacy"],errorRecovery:!0})}catch{return null}}function Ct(i,e){if(!i.endsWith(".vue"))return [{content:e,lineOffset:1}];try{let{parse:s}=sr("@vue/compiler-sfc"),{descriptor:o}=s(e),a=[];if(o.script?.content&&a.push({content:o.script.content,lineOffset:o.script.loc.start.line}),o.scriptSetup?.content&&a.push({content:o.scriptSetup.content,lineOffset:o.scriptSetup.loc.start.line}),a.length>0)return a}catch{}let t=e.match(/<script\b[^>]*>([\s\S]*?)<\/script>/i);if(!t||!t[1])return [];let r=e.slice(0,t.index||0).split(`
|
|
506
|
+
`).length;return [{content:t[1],lineOffset:r}]}function Ne(i,e){return (i.loc?.start?.line??1)+e-1}function rn(i,e){if(i.type!=="MemberExpression")return false;let t=i.object;return !t||t.type!=="ThisExpression"?false:G(i)===e}function tn(i,e){return !!i&&i.type==="Identifier"&&String(i.name||"")===e}function or(i){let e=new Set;return i.filter(t=>{let n=`${t.filePath}:${t.line}:${t.kind}:${t.text}`;return e.has(n)?false:(e.add(n),true)})}function nn(i,e,t=2){if(!ne__default.existsSync(i))return {snippet:"",startLine:e};let n=ne__default.readFileSync(i,"utf-8").split(`
|
|
504
507
|
`),r=Math.max(0,e-1-t),s=Math.min(n.length-1,e-1+t);return {snippet:n.slice(r,s+1).map((a,c)=>{let l=r+c+1;return ` ${l===e?"\u25B6":" "} ${String(l).padStart(4)} \u2502 ${a}`}).join(`
|
|
505
|
-
`),startLine:r+1}}function
|
|
506
|
-
`),a=
|
|
507
|
-
`),a=
|
|
508
|
-
`),c=
|
|
509
|
-
`),c=
|
|
510
|
-
\
|
|
511
|
-
\
|
|
512
|
-
\
|
|
513
|
-
|
|
508
|
+
`),startLine:r+1}}function wt(i,e=false){let n=Math.max(50,({declaration:95,assignment:85,update:80,property_assignment:75,indexed_assignment:75,dot:75,bracket:75,delete:70,direct_storage:90,alias_ref:70,regex_fallback:60}[i]??65)-(e?5:0)),r=n>=90?"\u25CF\u25CF\u25CF\u25CF\u25CF":n>=80?"\u25CF\u25CF\u25CF\u25CF\u25CB":n>=70?"\u25CF\u25CF\u25CF\u25CB\u25CB":n>=60?"\u25CF\u25CF\u25CB\u25CB\u25CB":"\u25CF\u25CB\u25CB\u25CB\u25CB";return `[\u7F6E\u4FE1\u5EA6 ${n}% ${r}]`}var tr={init:"\u{1F331} \u521D\u59CB\u5316\u6765\u6E90",cache:"\u{1F4BE} \u7F13\u5B58\u56DE\u663E",user:"\u{1F5B1}\uFE0F \u7528\u6237\u4EA4\u4E92",unknown:"\u2753 \u672A\u77E5\u6765\u6E90"};function Bs(i,e,t){let n=[];for(let r of i){if(!r.abs_path||!ne__default.existsSync(r.abs_path))continue;let s=ne__default.readFileSync(r.abs_path,"utf-8"),o=s.split(`
|
|
509
|
+
`),a=Ct(r.path||te__default.basename(r.abs_path),s);for(let c of a){let l=vt(c.content);l&&_e(l,u=>{if(n.length>=t||u.type!=="VariableDeclarator")return;let d=u.id;if(!d||d.type!=="Identifier")return;let p=String(d.name||"");if(!p||p===e)return;let h=u.init;if(!h)return;let m=false;if(h.type==="Identifier"&&String(h.name||"")===e?m=true:h.type==="MemberExpression"&&(m=rn(h,e)||G(h)===e),!m)return;let f=Ne(u,c.lineOffset),g=o[f-1]?.trim()||"";n.push({alias:p,filePath:r.path,abs_path:r.abs_path,line:f,text:g});});}}return n}function Ws(i,e,t){let n=[];for(let r of i){if(!r.abs_path||!ne__default.existsSync(r.abs_path))continue;let s=ne__default.readFileSync(r.abs_path,"utf-8"),o=s.split(`
|
|
510
|
+
`),a=Ct(r.path||te__default.basename(r.abs_path),s);for(let c of a){let l=vt(c.content);l&&_e(l,u=>{if(n.length>=t||u.type!=="VariableDeclarator")return;let d=u.id;if(!d||d.type!=="ObjectPattern")return;let p=d.properties||[];for(let h of p){if(h.type!=="ObjectProperty"&&h.type!=="Property")continue;let m=h.key,f=h.value,g=m?.type==="Identifier"?String(m.name||""):null;if(g!==e)continue;let y=f?.type==="Identifier"?String(f.name||""):g;if(!y)continue;let E=Ne(u,c.lineOffset),_=o[E-1]?.trim()||"";n.push({alias:y,filePath:r.path,line:E,text:_});}});}}return n}function nr(i,e,t,n){let r=[];for(let s of i){if(!s.abs_path||!ne__default.existsSync(s.abs_path))continue;let o=ne__default.readFileSync(s.abs_path,"utf-8"),a=o.split(`
|
|
511
|
+
`),c=Ct(s.path||te__default.basename(s.abs_path),o);for(let l of c){let u=vt(l.content);if(u&&(_e(u,d=>{if(!(r.length>=n)){if(d.type==="VariableDeclarator"){let p=d.id;if(tn(p,e)){let h=Ne(d,l.lineOffset);r.push({filePath:s.path,line:h,kind:"declaration",text:a[h-1]?.trim()||""});}}if(d.type==="AssignmentExpression"){let p=d.left;if(!p)return;let h=Ne(d,l.lineOffset);if(tn(p,e)||rn(p,e)){r.push({filePath:s.path,line:h,kind:"assignment",text:a[h-1]?.trim()||""});return}}if(d.type==="UpdateExpression"){let p=d.argument;if(!p)return;if(tn(p,e)||rn(p,e)){let h=Ne(d,l.lineOffset);r.push({filePath:s.path,line:h,kind:"update",text:a[h-1]?.trim()||""});}}}}),r.length>=n))break}if(r.length>=n)break}return or(r).slice(0,n)}function rr(i,e,t,n){let r=[];for(let s of i){if(!s.abs_path||!ne__default.existsSync(s.abs_path))continue;let o=ne__default.readFileSync(s.abs_path,"utf-8"),a=o.split(`
|
|
512
|
+
`),c=Ct(s.path||te__default.basename(s.abs_path),o);for(let l of c){let u=vt(l.content);if(u&&(_e(u,d=>{if(!(r.length>=n)){if(d.type==="AssignmentExpression"){let p=d.left;if(!p||p.type!=="MemberExpression"||se(p)!==e)return;G(p);let f=Ne(d,l.lineOffset);r.push({filePath:s.path,line:f,kind:p.computed?"bracket":"dot",text:a[f-1]?.trim()||""});}if(d.type==="UpdateExpression"){let p=d.argument;if(!p||p.type!=="MemberExpression"||se(p)!==e)return;G(p);let f=Ne(d,l.lineOffset);r.push({filePath:s.path,line:f,kind:p.computed?"bracket":"dot",text:a[f-1]?.trim()||""});}if(d.type==="UnaryExpression"&&d.operator==="delete"){let p=d.argument;if(!p||p.type!=="MemberExpression"||se(p)!==e)return;G(p);let f=Ne(d,l.lineOffset);r.push({filePath:s.path,line:f,kind:"delete",text:a[f-1]?.trim()||""});}}}),r.length>=n))break}if(r.length>=n)break}return or(r).slice(0,n)}function ar(i,e){i.registerTool("skimmer_find_symbol",{title:"\u{1F50D} \u7B26\u53F7\u540D\u641C\u7D22",description:`\u641C\u7B26\u53F7\u540D\u7528\u8FD9\u4E2A\u3002\u4F60\u77E5\u9053\u786E\u5207\u7684\u51FD\u6570/\u53D8\u91CF/\u7EC4\u4EF6\u540D\u65F6\u8C03\u7528\u3002
|
|
513
|
+
\u652F\u6301\u4E09\u5C42\u641C\u7D22\uFF1A\u7CBE\u786E\u5339\u914D \u2192 FTS5\u5168\u6587 \u2192 Levenshtein\u6A21\u7CCA\u3002
|
|
514
|
+
\u652F\u6301\u62FC\u5199\u7EA0\u6B63\u9A7C\u5CF0\u62C6\u8BCD\u3002
|
|
515
|
+
\u53EF\u6309 vue2/vue3/react \u6846\u67B6\u8FC7\u6EE4\u3002
|
|
516
|
+
|
|
517
|
+
\u26A1 \u6BD4 search_snippets \u7CBE\u786E\u4F46\u4EC5\u9002\u7528\u4E8E\u7B26\u53F7\u540D\u67E5\u8BE2\u3002
|
|
518
|
+
\u274C "save to cache" \u8FD9\u7C7B\u81EA\u7136\u8BED\u8A00 \u2192 skimmer_search_snippets
|
|
519
|
+
\u274C \u8981\u67E5\u627E API \u884C\u4E3A \u2192 skimmer_find_by_behavior
|
|
520
|
+
\u{1F4A1} \u60F3\u8981\u4E00\u6B21\u62FF\u5168\u5B9A\u4E49+\u8C03\u7528\u94FE+\u884C\u4E3A \u2192 skimmer_query
|
|
521
|
+
|
|
522
|
+
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z.object({query:z.string().describe('\u641C\u7D22\u8BCD\uFF0C\u5982 "changeCash" \u6216 "handle submit"'),project_path:z.string().optional().describe(Le),category:z.enum(["state","computed","method","effect","prop","lifecycle","hook","component","mixin","function","all"]).optional().default("all").describe("\u7B26\u53F7\u7C7B\u578B\u8FC7\u6EE4"),framework:z.enum(["vue2","vue3","react","all"]).optional().default("all"),file_path:z.string().optional().describe('\u9650\u5B9A\u6587\u4EF6\u8DEF\u5F84\u641C\u7D22\uFF08\u5305\u542B\u5373\u53EF\uFF0C\u5982 "index.vue"\uFF09'),fuzzy:z.boolean().optional().default(true).describe("\u662F\u5426\u542F\u7528\u6A21\u7CCA\u5339\u914D\uFF08\u9ED8\u8BA4 true\uFF0C\u77ED\u67E5\u8BE2\u81EA\u52A8\u7981\u7528\uFF09"),allow_fallback_scan:z.boolean().optional().default(false).describe("0\u547D\u4E2D\u65F6\u662F\u5426\u5141\u8BB8 LIKE \u5168\u8868\u626B\u63CF\uFF08\u9ED8\u8BA4\u4E0D\u542F\u7528\uFF0C\u6602\u8D35\u64CD\u4F5C\uFF09"),debug:z.boolean().optional().default(false).describe("\u662F\u5426\u8F93\u51FA\u5404\u9636\u6BB5\u8017\u65F6\u548C\u5019\u9009\u6570"),limit:z.number().optional().default(15)}),annotations:{readOnlyHint:true,destructiveHint:false}},async({query:t,project_path:n,category:r,framework:s,file_path:o,fuzzy:a,allow_fallback_scan:c,debug:l,limit:u})=>{let d=performance.now(),{db:p}=e.getContext(n),h=new $e(p),{results:m,debug:f}=h.search(t,{category:r==="all"?void 0:r,framework:s==="all"?void 0:s,filePath:o,fuzzy:a,limit:u,allowFallbackScan:c,debug:l}),g=Math.round((performance.now()-d)*100)/100,y=Z({durationMs:g,resultCount:m.length,backend:"indexed",debug:l?f:void 0});if(m.length===0)return {content:[{type:"text",text:`\u{1F50D} \u641C\u7D22 "${t}" \u65E0\u7ED3\u679C
|
|
514
523
|
|
|
515
524
|
\u{1F4A1} \u5C1D\u8BD5:
|
|
516
525
|
skimmer_find_by_behavior \u6309\u884C\u4E3A\u641C\u7D22
|
|
@@ -518,130 +527,169 @@ project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({query:z$1.string(
|
|
|
518
527
|
\u{1F4A1} \u5C1D\u8BD5: skimmer_find_symbol({ allow_fallback_scan: true }) \u542F\u7528\u5168\u8868\u626B\u63CF`}
|
|
519
528
|
|
|
520
529
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
521
|
-
${
|
|
522
|
-
`];return
|
|
523
|
-
${
|
|
524
|
-
`)}]}}),
|
|
525
|
-
\
|
|
526
|
-
|
|
530
|
+
${X(y)}`}]};let E=[`\u{1F50D} \u641C\u7D22 "${t}" \u2014 \u627E\u5230 ${m.length} \u4E2A\u7ED3\u679C
|
|
531
|
+
`];return m.forEach((_,x)=>{let T=_.symbol,w=Ke(T.params_json,[]),S=w.length>0?`(${w.join(", ")})`:"",b=Te(T.start_line,T.end_line);E.push(`${x+1}. ${T.name}${S} [${T.category}/${T.framework}] \u5339\u914D\u5EA6: ${_.score}%`),E.push(` \u{1F4C4} ${_.filePath}:${b}`),E.push(` \u{1F3AF} ${_.matchReason}`),_.spellingSuggestion&&E.push(` \u{1F4A1} ${_.spellingSuggestion}`),T.default_value&&E.push(` \u{1F4CC} \u9ED8\u8BA4\u503C: ${T.default_value}`),E.push("");}),E.push(`\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
532
|
+
${X(y)}`),{content:[{type:"text",text:E.join(`
|
|
533
|
+
`)}]}}),i.registerTool("skimmer_search_snippets",{title:"\u{1F50E} \u81EA\u7136\u8BED\u8A00\u641C\u4EE3\u7801",description:`\u81EA\u7136\u8BED\u8A00\u641C\u4EE3\u7801\u7528\u8FD9\u4E2A\u3002\u4F60\u4E0D\u77E5\u9053\u786E\u5207\u7684\u7B26\u53F7\u540D\u65F6\uFF0C\u7528\u81EA\u7136\u8BED\u8A00\u63CF\u8FF0\u529F\u80FD\u3002
|
|
534
|
+
\u793A\u4F8B: "save to cache" / "authentication flow" / "localStorage setItem"
|
|
535
|
+
|
|
536
|
+
\u26A1 \u9002\u5408\u81EA\u7136\u8BED\u8A00\u7B2C\u4E00\u8DF3\u67E5\u8BE2\uFF0C\u4E5F\u517C\u5BB9\u7B26\u53F7\u540D\u3002
|
|
537
|
+
\u274C \u7CBE\u786E\u7B26\u53F7\u540D\u641C\u7D22 \u2192 skimmer_find_symbol
|
|
538
|
+
\u274C \u6309 API \u884C\u4E3A\u8FC7\u6EE4 \u2192 skimmer_find_by_behavior
|
|
539
|
+
\u{1F4A1} \u60F3\u8981\u4E00\u6B21\u62FF\u5168\u5B9A\u4E49+\u8C03\u7528\u94FE+\u884C\u4E3A \u2192 skimmer_query
|
|
540
|
+
|
|
541
|
+
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z.object({query:z.string().describe('\u81EA\u7136\u8BED\u8A00\u3001\u884C\u4E3A\u63CF\u8FF0\u6216\u7B26\u53F7\u540D\uFF0C\u5982 "save to cache" / "localStorage setItem" / "changeCacheValue"'),project_path:z.string().optional().describe(Le),file_path:z.string().optional().describe('\u9650\u5B9A\u6587\u4EF6\u8DEF\u5F84\u641C\u7D22\uFF08\u5305\u542B\u5373\u53EF\uFF0C\u5982 "src/service/cache.ts"\uFF09'),context_lines:z.number().optional().default(1).describe("\u7247\u6BB5\u4E0A\u4E0B\u6587\u884C\u6570"),max_lines:z.number().optional().default(24).describe("\u5355\u4E2A\u7247\u6BB5\u6700\u5927\u884C\u6570"),limit:z.number().optional().default(8).describe("\u8FD4\u56DE\u7247\u6BB5\u6570")}),annotations:{readOnlyHint:true,destructiveHint:false}},async({query:t,project_path:n,file_path:r,context_lines:s,max_lines:o,limit:a})=>{let c=performance.now(),{db:l}=e.getContext(n),u=new $e(l),d=Lt(t),p=u.searchSnippets(t,{filePath:r,contextLines:s,maxLines:o,limit:a}),h=Math.round((performance.now()-c)*100)/100,m=Z({durationMs:h,resultCount:p.length,backend:"indexed"});if(p.length===0)return {content:[{type:"text",text:`\u{1F50E} \u4EE3\u7801\u7247\u6BB5\u641C\u7D22 "${t}" \u65E0\u7ED3\u679C
|
|
542
|
+
|
|
543
|
+
\u{1F4A1} \u5C1D\u8BD5:
|
|
544
|
+
1. \u7528\u66F4\u5177\u4F53\u7684\u884C\u4E3A\u8BCD\uFF0C\u5982 "localStorage setItem"
|
|
545
|
+
2. \u7528 skimmer_find_symbol \u641C\u7B26\u53F7\u540D
|
|
546
|
+
3. \u7528 skimmer_find_by_behavior \u6309\u884C\u4E3A\u8FC7\u6EE4
|
|
547
|
+
|
|
548
|
+
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
549
|
+
${X(m)}`}]};let f=[`\u{1F50E} \u4EE3\u7801\u7247\u6BB5\u641C\u7D22 "${t}" \u2014 \u627E\u5230 ${p.length} \u4E2A\u7ED3\u679C`,`\u{1F9ED} \u67E5\u8BE2\u610F\u56FE: ${d}
|
|
550
|
+
`];for(let[g,y]of p.entries()){f.push(`${g+1}. ${y.symbolName} [${y.category||"unknown"}/${y.framework||"unknown"}] \u5339\u914D\u5EA6: ${y.score}%`),f.push(` \u{1F4C4} ${y.filePath}:${Te(y.startLine,y.endLine)}`),f.push(` \u{1F3AF} ${y.matchReason}`),y.behaviors?.length&&f.push(` \u{1F3F7}\uFE0F ${y.behaviors.join(" ")}`),y.offsetWarning&&f.push(` ${y.offsetWarning}`);let E=y.filePath.split(".").pop()||"js",_=["tsx","jsx"].includes(E)?"jsx":E==="ts"?"typescript":E==="vue"?"vue":"javascript";f.push(` \`\`\`${_}`),f.push(y.snippet),f.push(" ```"),f.push("");}return f.push(`\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
551
|
+
${X(m)}`),{content:[{type:"text",text:f.join(`
|
|
552
|
+
`)}]}}),i.registerTool("skimmer_get_code_slice",{title:"\u{1F4C4} \u8BFB\u53D6\u7B26\u53F7\u6E90\u7801",description:`\u8BFB\u53D6\u6307\u5B9A\u51FD\u6570/\u53D8\u91CF\u7684\u5B8C\u6574\u6E90\u7801\uFF0C\u907F\u514D\u8BFB\u5927\u6587\u4EF6\u6D6A\u8D39 Token\u3002
|
|
553
|
+
\u81EA\u52A8\u9644\u5E26\u884C\u4E3A\u6807\u7B7E\uFF08\u64CD\u4F5C\u4E86\u54EA\u4E9B\u5916\u90E8 API\uFF09\u3002
|
|
554
|
+
\u81EA\u52A8\u8FD4\u56DE\u8C03\u7528\u8005/\u88AB\u8C03\u8005\u6458\u8981\uFF08\u524D 3 \u6761\uFF09\uFF0C\u51CF\u5C11\u540E\u7EED\u989D\u5916\u67E5\u8BE2\u3002
|
|
555
|
+
|
|
556
|
+
\u{1F4A1} \u5982\u679C\u4F60\u8FD8\u9700\u8981\u5B8C\u6574\u7684\u8C03\u7528\u5173\u7CFB\u548C\u5F71\u54CD\u8BC4\u4F30\uFF0C
|
|
557
|
+
\u8BF7\u7528 skimmer_query \u4E00\u6B21\u62FF\u5168\uFF08\u7701 3~5 \u6B21\u989D\u5916\u8C03\u7528\uFF09\u3002
|
|
558
|
+
\u274C \u53EA\u67E5\u8C03\u7528\u5173\u7CFB \u2192 skimmer_get_call_graph
|
|
559
|
+
\u274C \u505A\u4FEE\u6539\u5F71\u54CD\u8BC4\u4F30 \u2192 skimmer_get_blast_radius
|
|
560
|
+
|
|
561
|
+
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z.object({file_path:z.string().describe("\u6587\u4EF6\u76F8\u5BF9\u8DEF\u5F84\uFF08\u76F8\u5BF9\u4E8E\u9879\u76EE\u6839\u76EE\u5F55\uFF09"),symbol_name:z.string().describe("\u51FD\u6570\u6216\u53D8\u91CF\u540D"),project_path:z.string().optional().describe(Le),context_lines:z.number().optional().default(0).describe("\u4E0A\u4E0B\u65B9\u989D\u5916\u5C55\u793A\u7684\u884C\u6570")}),annotations:{readOnlyHint:true,destructiveHint:false}},async({file_path:t,symbol_name:n,project_path:r,context_lines:s})=>{let o=performance.now(),{db:a}=e.getContext(r),c=a.getSymbolByName(n,t);if(!c){let b=Math.round((performance.now()-o)*100)/100,N=Z({durationMs:b,resultCount:0,backend:"indexed"}),L=a.exactSearch(n,void 0,void 0,void 0),I=L.length>0?`
|
|
527
562
|
|
|
528
563
|
\u{1F50E} \u540C\u540D\u7B26\u53F7\u5B58\u5728\u4E8E\u5176\u4ED6\u4F4D\u7F6E:
|
|
529
|
-
${
|
|
564
|
+
${L.slice(0,5).map((C,P)=>` ${P+1}. ${C.name} [${C.category}/${C.framework}] \u{1F4C4} ${C.file_path}:${Te(C.start_line,C.end_line)}`).join(`
|
|
530
565
|
`)}
|
|
531
566
|
|
|
532
|
-
\u{1F4A1} \u53EF\u6539\u7528: skimmer_get_code_slice({ file_path: "${
|
|
567
|
+
\u{1F4A1} \u53EF\u6539\u7528: skimmer_get_code_slice({ file_path: "${L[0].file_path}", symbol_name: "${n}" })`:`
|
|
533
568
|
|
|
534
569
|
\u{1F4A1} \u8BD5\u8BD5: skimmer_find_symbol({ query: "${n}" })`;return {content:[{type:"text",text:`\u274C \u672A\u627E\u5230: ${n}
|
|
535
|
-
\u{1F4C4} \u8BF7\u6C42\u6587\u4EF6: ${t}${
|
|
570
|
+
\u{1F4C4} \u8BF7\u6C42\u6587\u4EF6: ${t}${I}
|
|
536
571
|
|
|
537
572
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
538
|
-
${
|
|
539
|
-
`),
|
|
540
|
-
`),g=
|
|
573
|
+
${X(N)}`}]}}let l=c.abs_path;if(!ne__default.existsSync(l))return {content:[{type:"text",text:`\u274C \u6587\u4EF6\u4E0D\u5B58\u5728: ${l}`}]};let d=ne__default.readFileSync(l,"utf-8").split(`
|
|
574
|
+
`),p=Math.max(1,c.start_line-s)-1,h=Math.min(d.length,c.end_line+s),m=d.slice(p,h).join(`
|
|
575
|
+
`),g=m.includes(n)?"":`
|
|
541
576
|
\u26A0\uFE0F [\u884C\u53F7\u504F\u79FB] \u7D22\u5F15\u8BB0\u5F55 ${n} \u5728 L${c.start_line}\uFF0C\u4F46\u8BE5\u4F4D\u7F6E\u672A\u627E\u5230\u6B64\u7B26\u53F7\u3002
|
|
542
|
-
\u6587\u4EF6\u5DF2\u88AB\u4FEE\u6539\u4F46\u7D22\u5F15\u672A\u66F4\u65B0\uFF0C\u884C\u53F7\u53EF\u80FD\u504F\u79FB ${
|
|
577
|
+
\u6587\u4EF6\u5DF2\u88AB\u4FEE\u6539\u4F46\u7D22\u5F15\u672A\u66F4\u65B0\uFF0C\u884C\u53F7\u53EF\u80FD\u504F\u79FB ${d.length-c.end_line} \u884C\u5DE6\u53F3\u3002
|
|
543
578
|
\u5EFA\u8BAE: skimmer_index_project({ force: true })
|
|
544
|
-
`,{behaviors:y}=a.getFileOutline(t),
|
|
545
|
-
\`\`\`${
|
|
546
|
-
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
547
|
-
${W(_)}`),{content:[{type:"text",text:E.join(`
|
|
548
|
-
`)}]}}),o.registerTool("skimmer_trace_assignments",{title:"\u8FFD\u8E2A\u53D8\u91CF\u8D4B\u503C\u94FE\u8DEF\uFF08\u8F7B\u91CF\uFF09",description:`\u3010\u964D\u7EA7\u5DE5\u5177\u3011\u4EC5\u5728\u4EE5\u4E0B\u573A\u666F\u5355\u72EC\u4F7F\u7528\uFF1A\u53EA\u9700\u67E5\u770B\u67D0\u4E2A\u7B80\u5355\u53D8\u91CF\uFF08\u975E\u5BF9\u8C61\uFF09\u7684\u8D4B\u503C\u4F4D\u7F6E\uFF0C\u4E14\u4E0D\u5173\u5FC3\u5C5E\u6027\u4FEE\u6539/\u53C2\u6570\u4F20\u9012/storage\u94FE\u8DEF\u3002
|
|
549
|
-
\u26A0\uFE0F \u7EDD\u5927\u591A\u6570\u53D8\u91CF\u6EAF\u6E90\u573A\u666F\u8BF7\u4F18\u5148\u4F7F\u7528 skimmer_trace_data_lifecycle\uFF0C\u5B83\u80FD\u4E00\u6B21\u62FF\u5230\u6240\u6709\u4FE1\u606F\u3002
|
|
550
|
-
\u2705 \u672C\u5DE5\u5177\u9002\u5408\uFF1Aloading / errorMsg / count \u8FD9\u7C7B\u7B80\u5355 flag \u7684\u8D4B\u503C\u8FFD\u8E2A\u3002
|
|
551
|
-
\u274C \u4E0D\u9002\u5408\uFF1AstorageParams / savedData \u8FD9\u7C7B\u5BF9\u8C61\u3001\u9700\u8981\u8FFD\u8E2A\u5B8C\u6574\u6570\u636E\u6D41\u7684\u573A\u666F\u3002`,inputSchema:z$1.object({variable:z$1.string().describe('\u53D8\u91CF\u540D\uFF0C\u5982 "changeResult"'),project_path:z$1.string().optional().describe(Ne),file_path:z$1.string().optional().describe("\u9650\u5B9A\u6587\u4EF6\u8DEF\u5F84\uFF08\u5305\u542B\u5373\u53EF\uFF09"),include_properties:z$1.boolean().optional().default(true).describe("\u662F\u5426\u5305\u542B variable.xxx / variable[...] \u8D4B\u503C"),limit:z$1.number().optional().default(80)}),annotations:{readOnlyHint:true,destructiveHint:false}},async({variable:t,project_path:n,file_path:r,include_properties:s,limit:i})=>{let a=performance.now(),{db:c}=e.getContext(n),l=c.listFiles(r),p=Math.min(300,Math.max(1,i||80)),u=s??true,d=c.exactSearch(t,"state",void 0,r||void 0),h={vue2:"Vue2 data()",vue3:"Vue3 ref/reactive",react:"React useState/useRef"},f=d.filter(E=>E.default_value!=null).map(E=>({filePath:E.file_path,line:E.start_line,kind:`data_init(${h[E.framework]||E.framework})`,text:`${E.name}: ${E.default_value} \u2190 \u58F0\u660E\u521D\u59CB\u5316`})),m=qt(l,t,u,p);if(m.length===0){let E=Mn(t,u);m=Ie(l,E,p);}let g=new Map;for(let E of [...f,...m]){let L=`${E.filePath}:${E.line}`;g.has(L)||g.set(L,E);}let y=[...g.values()],S=Math.round((performance.now()-a)*100)/100;if(y.length===0){let E=H({durationMs:S,resultCount:0,backend:"ast_scan"});return {content:[{type:"text",text:`\u{1F9E9} \u53D8\u91CF\u8D4B\u503C\u8FFD\u8E2A: "${t}"
|
|
552
|
-
\u672A\u627E\u5230\u5339\u914D\u8D4B\u503C\u8BED\u53E5\uFF08\u5305\u62EC\u58F0\u660E\u521D\u59CB\u5316\uFF09
|
|
553
|
-
\u8FC7\u6EE4: file_path=${r||"*"} include_properties=${u}
|
|
554
|
-
|
|
579
|
+
`,{behaviors:y}=a.getFileOutline(t),E=y.filter(b=>b.symbol_id===c.id),_=l.split(".").pop()||"js",x=["tsx","jsx"].includes(_)?"jsx":["ts"].includes(_)?"typescript":"javascript",T=[`\u{1F4CD} ${c.name} [${c.category}/${c.framework}]`,`\u{1F4C4} ${t}:${Te(c.start_line,c.end_line)}`];if(g&&T.push(g),c.jsdoc&&T.push(`\u{1F4DD} ${c.jsdoc}`),E.length>0){let b=[...new Set(E.map(N=>`[${N.category}:${N.api_name}.${N.operation}${N.detail?`("${N.detail}")`:""}]`))];T.push(`\u{1F3F7}\uFE0F \u884C\u4E3A: ${b.join(" ")}`);}T.push(`
|
|
580
|
+
\`\`\`${x}`),T.push(m),T.push("```");let w=Math.round((performance.now()-o)*100)/100,S=Z({durationMs:w,resultCount:1,backend:"indexed"});return T.push(`
|
|
555
581
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
556
|
-
${
|
|
557
|
-
\
|
|
558
|
-
|
|
559
|
-
`)}]}}),o.registerTool("skimmer_trace_property_changes",{title:"\u8FFD\u8E2A\u5BF9\u8C61\u5C5E\u6027\u4FEE\u6539",description:`\u3010\u964D\u7EA7\u5DE5\u5177\u3011\u4EC5\u5728\u4EE5\u4E0B\u573A\u666F\u5355\u72EC\u4F7F\u7528\uFF1A\u9700\u8981\u7CBE\u786E\u8FC7\u6EE4\u67D0\u4E00\u4E2A\u5177\u4F53\u5C5E\u6027\u5B57\u6BB5\uFF08\u5982 storageParams.receiveAdr\uFF09\uFF0C\u800C\u4E0D\u9700\u8981\u6574\u4F53\u8D4B\u503C/\u53C2\u6570\u4F20\u9012/storage\u94FE\u8DEF\u4FE1\u606F\u3002
|
|
560
|
-
\u26A0\uFE0F \u7EDD\u5927\u591A\u6570\u5BF9\u8C61\u6EAF\u6E90\u573A\u666F\u8BF7\u4F18\u5148\u4F7F\u7528 skimmer_trace_data_lifecycle\uFF0C\u5B83\u80FD\u4E00\u6B21\u62FF\u5230\u6240\u6709\u4FE1\u606F\u3002
|
|
561
|
-
\u2705 \u672C\u5DE5\u5177\u9002\u5408\uFF1Aobject.specificProp \u7684\u5355\u5B57\u6BB5\u7EA7\u522B\u7CBE\u786E\u8FFD\u8E2A\u3002
|
|
562
|
-
\u274C \u4E0D\u9002\u5408\uFF1A\u9700\u8981\u4E86\u89E3\u5BF9\u8C61\u6574\u4F53\u6765\u6E90\u6216\u6570\u636E\u6D41\u5411\u7684\u573A\u666F\u3002`,inputSchema:z$1.object({object:z$1.string().describe('\u5BF9\u8C61\u540D\uFF0C\u5982 "storageParams" / "params"'),property:z$1.string().optional().describe('\u5C5E\u6027\u540D\uFF0C\u5982 "receiveAdr"'),project_path:z$1.string().optional().describe(Ne),file_path:z$1.string().optional().describe("\u9650\u5B9A\u6587\u4EF6\u8DEF\u5F84\uFF08\u5305\u542B\u5373\u53EF\uFF09"),limit:z$1.number().optional().default(80)}),annotations:{readOnlyHint:true,destructiveHint:false}},async({object:t,property:n,project_path:r,file_path:s,limit:i})=>{let a=performance.now(),{db:c}=e.getContext(r),l=c.listFiles(s),p=Math.min(300,Math.max(1,i||80)),u=Un(l,t,20),d=Wn(l,t,20),h=[...new Set([...u.map(b=>b.alias),...d.map(b=>b.alias)].filter(b=>b!==t))],f=[t,...h],m=St(l,t,n,p);for(let b of h)m.push(...St(l,b,n,Math.floor(p/2)));if(m.length===0){let b="(?:=|\\+=|-=|\\*=|/=|%=|\\|=|&=|\\^=|&&=|\\|\\|=|\\?\\?=)",T=[];for(let E of f){let L=ge(E);if(n){let _=ge(n);T.push({kind:"dot",regex:new RegExp(`\\b${L}\\.${_}\\s*${b}`)},{kind:"bracket",regex:new RegExp(`\\b${L}\\s*\\[(?:'${_}'|"${_}")\\]\\s*${b}`)},{kind:"delete",regex:new RegExp(`\\bdelete\\s+${L}\\.(?:${_})\\b`)});}else T.push({kind:"dot",regex:new RegExp(`\\b${L}\\.[A-Za-z_$][\\w$]*\\s*${b}`)},{kind:"bracket",regex:new RegExp(`\\b${L}\\s*\\[(?:'[^']+'|"[^"]+")\\]\\s*${b}`)},{kind:"delete",regex:new RegExp(`\\bdelete\\s+${L}\\.[A-Za-z_$][\\w$]*\\b`)});}m=Ie(l,T,p);}let g=Math.round((performance.now()-a)*100)/100;if(m.length===0){let b=h.length>0?`
|
|
563
|
-
\u522B\u540D\u5C55\u5F00: ${h.join(", ")}\uFF08\u5747\u672A\u547D\u4E2D\uFF09`:"",T=H({durationMs:g,resultCount:0,backend:"ast_scan"});return {content:[{type:"text",text:`\u{1F9ED} \u5C5E\u6027\u4FEE\u6539\u8FFD\u8E2A: ${t}${n?`.${n}`:".*"}
|
|
564
|
-
\u672A\u627E\u5230\u5339\u914D\u8BED\u53E5${b}
|
|
565
|
-
\u8FC7\u6EE4: file_path=${s||"*"}
|
|
582
|
+
${X(S)}`),{content:[{type:"text",text:T.join(`
|
|
583
|
+
`)}]}}),i.registerTool("skimmer_find_by_behavior",{title:"\u{1F3F7}\uFE0F \u6309 API \u884C\u4E3A\u641C\u7D22\u51FD\u6570",description:`\u641C API \u884C\u4E3A\u7528\u8FD9\u4E2A\u3002\u4F60\u77E5\u9053\u8C03\u7528\u4E86\u4EC0\u4E48 API \u4F46\u4E0D\u77E5\u9053\u51FD\u6570\u540D\u3002
|
|
584
|
+
\u652F\u6301\u6309\u7C7B\u522B(category)\u3001API\u540D(api_name)\u3001\u64CD\u4F5C(operation)\u3001\u53C2\u6570\u503C(keyword)\u8FC7\u6EE4\u3002
|
|
566
585
|
|
|
567
|
-
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
568
|
-
${W(T)}`}]}}let y=[`\u{1F9ED} \u5C5E\u6027\u4FEE\u6539\u8FFD\u8E2A: ${t}${n?`.${n}`:".*"}`,`\u8FC7\u6EE4: file_path=${s||"*"}`];if(h.length>0){let b=u.map(E=>E.alias).filter(E=>E!==t).join(", "),T=d.map(E=>E.alias).filter(E=>E!==t).join(", ");b&&y.push(`\u26A1 \u5F15\u7528\u522B\u540D: ${b}\uFF08\u901A\u8FC7 let alias = this.${t} \u5C55\u5F00\uFF09`),T&&y.push(`\u26A1 \u89E3\u6784\u522B\u540D: ${T}\uFF08\u901A\u8FC7 const { ${t}: alias } \u5C55\u5F00\uFF09`);}y.push(`\u547D\u4E2D: ${m.length} \u5904`,""),m.forEach((b,T)=>{y.push(`${T+1}. [${b.kind}] \u{1F4C4} ${b.filePath}:L${b.line}`),y.push(` ${b.text}`);});let S=H({durationMs:g,resultCount:m.length,backend:"ast_scan"});return y.push(`
|
|
569
|
-
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
570
|
-
${W(S)}`),{content:[{type:"text",text:y.join(`
|
|
571
|
-
`)}]}}),o.registerTool("skimmer_find_by_behavior",{title:"\u6309\u884C\u4E3A\u6807\u7B7E\u641C\u7D22\u51FD\u6570",description:`\u6309 API \u8C03\u7528\u884C\u4E3A\u641C\u7D22\uFF0C\u5B8C\u5168\u7ED5\u8FC7\u547D\u540D\u95EE\u9898\u3002
|
|
572
586
|
\u793A\u4F8B:
|
|
573
587
|
- \u627E\u6240\u6709\u64CD\u4F5C localStorage \u7684\u51FD\u6570: { category: "storage" }
|
|
574
588
|
- \u627E\u5199\u5165 localStorage \u7684: { api_name: "localStorage", operation: "setItem" }
|
|
575
589
|
- \u627E\u53D1\u8BF7\u6C42\u7684: { category: "network" }
|
|
576
590
|
- \u627E\u8DEF\u7531\u8DF3\u8F6C\u7684: { category: "router" }
|
|
577
591
|
- \u6309 key \u540D\u641C\u7D22: { keyword: "cacheData" }
|
|
578
|
-
|
|
579
|
-
\u8FC7\
|
|
592
|
+
|
|
593
|
+
\u26A1 \u5B8C\u5168\u7ED5\u8FC7\u547D\u540D\u95EE\u9898\u3002
|
|
594
|
+
\u274C \u81EA\u7136\u8BED\u8A00\u63CF\u8FF0 \u2192 skimmer_search_snippets
|
|
595
|
+
\u274C \u77E5\u9053\u7B26\u53F7\u540D \u2192 skimmer_find_symbol
|
|
596
|
+
\u{1F4A1} \u60F3\u8981\u4E00\u6B21\u62FF\u5168 \u2192 skimmer_query
|
|
597
|
+
|
|
598
|
+
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z.object({project_path:z.string().optional().describe(Le),category:z.enum(["storage","network","router","vuex","dom","event","timer","i18n"]).optional().describe("\u884C\u4E3A\u7C7B\u522B"),api_name:z.string().optional().describe('"localStorage" / "axios" / "$router"'),operation:z.string().optional().describe('"setItem" / "get" / "push" / "commit"'),keyword:z.string().optional().describe('\u5728\u53C2\u6570\u503C\u4E2D\u641C\u7D22\uFF08\u5982 key \u540D "cacheData"\uFF09'),file_path:z.string().optional().describe('\u9650\u5B9A\u6587\u4EF6\u8DEF\u5F84\u641C\u7D22\uFF08\u5305\u542B\u5373\u53EF\uFF0C\u5982 "src/views/apply/index.vue"\uFF09')}),annotations:{readOnlyHint:true,destructiveHint:false}},async({project_path:t,category:n,api_name:r,operation:s,keyword:o,file_path:a})=>{let c=performance.now(),{db:l}=e.getContext(t),d=new $e(l).searchByBehavior({category:n,apiName:r,operation:s,keyword:o,filePath:a}),p=new Set(["localstorage","sessionstorage","cookie"]);r||(d=d.filter(y=>y.category!=="storage"||p.has(y.apiName.toLowerCase())));let h=Math.round((performance.now()-c)*100)/100,m=Z({durationMs:h,resultCount:d.length,backend:"indexed"});if(d.length===0)return {content:[{type:"text",text:`\u{1F3F7}\uFE0F \u672A\u627E\u5230\u5339\u914D\u7684\u884C\u4E3A
|
|
599
|
+
\u8FC7\u6EE4\u6761\u4EF6: ${JSON.stringify({category:n,api_name:r,operation:s,keyword:o,file_path:a})}
|
|
580
600
|
|
|
581
601
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
582
|
-
${
|
|
583
|
-
`];for(let[y,
|
|
584
|
-
${
|
|
585
|
-
`)}]}}),
|
|
586
|
-
|
|
602
|
+
${X(m)}`}]};let f=new Map;for(let y of d){let E=`${y.category}:${y.apiName}`;f.has(E)||f.set(E,[]),f.get(E).push(y);}let g=[`\u{1F3F7}\uFE0F \u884C\u4E3A\u641C\u7D22\u7ED3\u679C \u2014 ${d.length} \u6761
|
|
603
|
+
`];for(let[y,E]of f){let[_,x]=y.split(":"),T=new Map;for(let w of E)T.has(w.operation)||T.set(w.operation,[]),T.get(w.operation).push(w);g.push(`\u{1F4C2} ${_} \u2192 ${x}:`);for(let[w,S]of T){g.push(` ${w}:`);let b=new Map;for(let N of S){let L=`${N.symbolName}|${N.filePath}`;b.has(L)||b.set(L,{item:N,callLines:[]}),b.get(L).callLines.push(N.line);}for(let{item:N,callLines:L}of b.values()){let I=N.detail?` key="${N.detail}"`:"",C=L.length>1?` \xD7${L.length} (L${L.join(", L")})`:` L${L[0]||N.startLine}`;g.push(` \u2022 ${N.symbolName}${I}${C} \u{1F4C4} ${N.filePath}:${Te(N.startLine,N.endLine)}`);}}g.push("");}return g.push(`\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
604
|
+
${X(m)}`),{content:[{type:"text",text:g.join(`
|
|
605
|
+
`)}]}}),i.registerTool("skimmer_get_call_graph",{title:"\u{1F504} \u67E5\u770B\u8C03\u7528\u5173\u7CFB",description:`\u67E5\u770B\u51FD\u6570\u88AB\u8C01\u8C03\u7528(callers)\u4EE5\u53CA\u5B83\u8C03\u7528\u4E86\u4EC0\u4E48(callees)\u3002
|
|
606
|
+
\u652F\u6301 direction: 'callers' | 'callees' | 'both'\u3002
|
|
607
|
+
|
|
608
|
+
\u{1F4A1} \u5982\u679C\u4F60\u8FD8\u9700\u8981\u5B9A\u4E49\u4EE3\u7801+\u884C\u4E3A\u6807\u7B7E+\u5F71\u54CD\u8BC4\u4F30\uFF0C\u8BF7\u7528 skimmer_query \u4E00\u6B21\u62FF\u5168\u3002
|
|
609
|
+
\u5355\u72EC\u770B\u8C03\u7528\u5173\u7CFB\u7528\u672C\u5DE5\u5177\u6700\u7CBE\u786E\u3002
|
|
610
|
+
\u274C \u4E00\u6B21\u6027\u770B\u5168\u8C8C \u2192 skimmer_query
|
|
611
|
+
|
|
612
|
+
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z.object({symbol_name:z.string().describe("\u51FD\u6570\u540D"),project_path:z.string().optional().describe(Le),file_path:z.string().optional().describe("\u6587\u4EF6\u8DEF\u5F84\uFF08\u540C\u540D\u51FD\u6570\u65F6\u7528\u4E8E\u7CBE\u786E\u5B9A\u4F4D\uFF09"),direction:z.enum(["callers","callees","both"]).optional().default("both"),arg_keyword:z.string().optional().describe('\u8C03\u7528\u53C2\u6570\u5173\u952E\u5B57\u8FC7\u6EE4\uFF08\u5982 "storageParams"\uFF09'),auto_precise:z.boolean().optional().default(true).describe("\u5F53\u5B58\u5728 watcher/heuristic \u4EA7\u751F\u7684 precise pending \u65F6\uFF0C\u67E5\u8BE2\u524D\u81EA\u52A8\u6309\u9884\u7B97\u8865\u7B97 precise\uFF08\u9ED8\u8BA4 true\uFF09"),max_precise_files:z.number().optional().default(20).describe("auto_precise \u5355\u6B21\u6700\u591A\u8865\u7B97\u6587\u4EF6\u6570\uFF08\u9ED8\u8BA4 20\uFF09")}),annotations:{readOnlyHint:true,destructiveHint:false}},async({symbol_name:t,project_path:n,file_path:r,direction:s,arg_keyword:o,auto_precise:a,max_precise_files:c})=>{let l=performance.now(),{db:u,projectRoot:d}=e.getContext(n),p=await Zn(e,d,u,a!==false,Math.max(1,c||20)),h=u.getSymbolByName(t,r),m=[`\u{1F4CA} ${t} \u7684\u8C03\u7528\u56FE\u8C31
|
|
613
|
+
`];m.push(...er(p));let f=0,g=0,y=[],E=[],_=void 0;if(s==="callers"||s==="both"){if(y=u.getCallers(t,_,o),f+=y.length,g+=y.filter(b=>b.edge_kind==="precise").length,m.push(`\u2B06\uFE0F \u88AB\u8C03\u7528 (${y.length} \u5904):`),y.length===0)m.push(" \uFF08\u672A\u627E\u5230\u8C03\u7528\u8005\uFF09");else {let b={method_call:"",template_event:"\u{1F5BC}\uFE0F",jsx_event:"\u269B\uFE0F",hook_call:"\u{1FA9D}",import_call:"\u{1F4E5}",router_call:"\u{1F6E3}\uFE0F",store_dispatch:"\u{1F4E6}",store_commit:"\u{1F4E6}",constructor_call:"\u{1F195}"};for(let N of y){let L=N.args?` \u53C2\u6570: "${N.args}"`:"",I=N.source_kind||"",C=N.edge_kind||"",P=b[I]?` ${b[I]}`:"",K=C==="precise"?" [\u{1F3AF}precise]":"";m.push(` \u2022 ${N.caller_name} [${N.category}]${P}${K} \u{1F4C4} ${N.file_path}:L${N.start_line}${L}`);}}m.push("");}if((s==="callees"||s==="both")&&h){if(E=u.getCallees(h.id),f+=E.length,g+=E.filter(b=>b.edge_kind==="precise").length,m.push(`\u2B07\uFE0F \u8C03\u7528\u4E86 (${E.length} \u4E2A):`),E.length===0)m.push(" \uFF08\u672A\u5206\u6790\u5230\u8C03\u7528\u5173\u7CFB\uFF09");else for(let b of E){let N=b.args?`("${b.args}")`:"",I=(b.edge_kind||"")==="precise"?" [\u{1F3AF}precise]":"";m.push(` \u2022 ${b.callee_name}${N} [${b.call_type}]${I} L${b.line_number}`);}m.push("");}if(h){let{behaviors:b}=u.getFileOutline(h.file_path),N=b.filter(L=>L.symbol_id===h.id);if(N.length>0){m.push("\u{1F4E6} \u5916\u90E8\u72B6\u6001\u64CD\u4F5C:");for(let L of N){let I=L.detail?` ("${L.detail}")`:"";m.push(` \u2022 ${L.api_name}.${L.operation}${I} [${L.category}] L${L.line_number}`);}}}let x=Math.round((performance.now()-l)*100)/100,T=g>0?"precise":"heuristic",w=[];T==="heuristic"&&f>0&&w.push('\u5F53\u524D\u7ED3\u679C\u4E3A\u542F\u53D1\u5F0F\u8FB9\uFF1B\u5982\u5B58\u5728\u540C\u540D\u7B26\u53F7\u3001\u91CD\u5BFC\u51FA\u6216\u590D\u6742 import\uFF0C\u53EF\u7528 skimmer_index_project({ precision_mode: "precise" }) \u8FDB\u4E00\u6B65\u6D88\u6B67');let S=Z({durationMs:x,resultCount:f,backend:"indexed",precisionEffective:T,precisionWarnings:w.length>0?w:void 0});return m.push(`
|
|
587
614
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
588
|
-
${
|
|
589
|
-
`)}]}}),
|
|
590
|
-
|
|
591
|
-
|
|
615
|
+
${X(S)}`),{content:[{type:"text",text:m.join(`
|
|
616
|
+
`)}]}}),i.registerTool("skimmer_get_blast_radius",{title:"\u{1F4A5} \u4FEE\u6539\u5F71\u54CD\u8BC4\u4F30",description:`\u5206\u6790\u4FEE\u6539\u67D0\u51FD\u6570\u4F1A\u5F71\u54CD\u54EA\u4E9B\u8C03\u7528\u70B9\uFF0C\u7ED9\u51FA\u98CE\u9669\u7B49\u7EA7\u3002\u4FEE\u6539\u524D\u5FC5\u8C03\u3002
|
|
617
|
+
\u81EA\u52A8\u7EDF\u8BA1\u8C03\u7528\u70B9\u6570\u3001\u6587\u4EF6\u4F9D\u8D56\u3001\u5916\u90E8\u72B6\u6001\u5F71\u54CD\u3002
|
|
618
|
+
|
|
619
|
+
\u{1F4A1} \u5982\u679C\u4F60\u53EA\u662F\u60F3\u4E86\u89E3\u4E00\u4E2A\u51FD\u6570\u7684\u5168\u8C8C\uFF08\u5305\u542B\u5B9A\u4E49+\u8C03\u7528\u94FE+\u4EE3\u7801+\u884C\u4E3A\uFF09\uFF0C
|
|
620
|
+
\u8BF7\u7528 skimmer_query\uFF0C\u5B83\u5305\u542B\u7B80\u5316\u7248\u5F71\u54CD\u5206\u6790\u3002
|
|
621
|
+
\u274C \u53EA\u67E5\u8C03\u7528\u5173\u7CFB \u2192 skimmer_get_call_graph
|
|
622
|
+
\u274C \u4E00\u6B21\u6027\u770B\u5168\u8C8C \u2192 skimmer_query
|
|
623
|
+
|
|
624
|
+
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z.object({symbol_name:z.string().describe("\u8981\u4FEE\u6539\u7684\u51FD\u6570\u540D"),project_path:z.string().optional().describe(Le),file_path:z.string().optional().describe("\u6587\u4EF6\u8DEF\u5F84\uFF08\u540C\u540D\u65F6\u7CBE\u786E\u5B9A\u4F4D\uFF09"),auto_precise:z.boolean().optional().default(true).describe("\u5F53\u5B58\u5728 watcher/heuristic \u4EA7\u751F\u7684 precise pending \u65F6\uFF0C\u67E5\u8BE2\u524D\u81EA\u52A8\u6309\u9884\u7B97\u8865\u7B97 precise\uFF08\u9ED8\u8BA4 true\uFF09"),max_precise_files:z.number().optional().default(20).describe("auto_precise \u5355\u6B21\u6700\u591A\u8865\u7B97\u6587\u4EF6\u6570\uFF08\u9ED8\u8BA4 20\uFF09")}),annotations:{readOnlyHint:true,destructiveHint:false}},async({symbol_name:t,project_path:n,file_path:r,auto_precise:s,max_precise_files:o})=>{let a=performance.now(),{db:c,projectRoot:l}=e.getContext(n),u=await Zn(e,l,c,s!==false,Math.max(1,o||20)),d=c.getSymbolByName(t,r),p=c.getCallers(t),{behaviors:h}=d?c.getFileOutline(d.file_path):{behaviors:[]},m=d?h.filter(T=>T.symbol_id===d.id):[],f=p.length===0?"\u{1F7E2}":p.length<=3?"\u{1F7E1}":"\u{1F534}",g=p.length===0?"\u4F4E":p.length<=3?"\u4E2D":"\u9AD8",y=[`\u{1F4A5} \u4FEE\u6539 ${t} \u7684\u5F71\u54CD\u8BC4\u4F30`,"\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501",...er(u),`${f} \u98CE\u9669\u7B49\u7EA7: ${g} (${p.length} \u5904\u76F4\u63A5\u8C03\u7528)`,""],E={method_call:"\u{1F4DE} \u65B9\u6CD5\u8C03\u7528",template_event:"\u{1F5BC}\uFE0F \u6A21\u677F\u4E8B\u4EF6",jsx_event:"\u269B\uFE0F JSX\u4E8B\u4EF6",hook_call:"\u{1FA9D} Hook\u8C03\u7528",import_call:"\u{1F4E5} \u5BFC\u5165\u8C03\u7528",router_call:"\u{1F6E3}\uFE0F \u8DEF\u7531",store_dispatch:"\u{1F4E6} Store",store_commit:"\u{1F4E6} Commit",constructor_call:"\u{1F195} \u6784\u9020\u5B9E\u4F8B"};if(p.length>0?(y.push("\u{1F534} \u76F4\u63A5\u5F71\u54CD:"),p.forEach((T,w)=>{let S=T.source_kind||"",b=E[S]?` ${E[S]}`:"";y.push(` ${w+1}. ${T.caller_name} [${T.category}]${b} \u{1F4C4} ${T.file_path}:L${T.start_line}`);}),y.push("")):y.push(`\u2705 \u65E0\u8C03\u7528\u8005\uFF0C\u5F71\u54CD\u8303\u56F4\u53EF\u63A7
|
|
625
|
+
`),d){let T=c.getFileDependencies(d.file_path,"to");if(T.length>0){y.push(`\u{1F4C2} \u6587\u4EF6\u4F9D\u8D56 (${T.length} \u4E2A\u6587\u4EF6 import \u4E86\u6B64\u6587\u4EF6):`);let w={import:"\u{1F4E5}",re_export:"\u{1F504}",component_ref:"\u{1F9E9}",store_ref:"\u{1F4E6}",api_ref:"\u{1F310}"};T.slice(0,10).forEach(S=>{y.push(` ${w[S.dependency_kind]||"\u2022"} ${S.from_file} (${S.dependency_kind})`);}),y.push("");}}if(m.length>0){y.push("\u{1F4E6} \u5916\u90E8\u72B6\u6001\u5F71\u54CD:");for(let T of m)y.push(` \u2022 ${T.api_name}.${T.operation}${T.detail?` key="${T.detail}"`:""} [${T.category}]`);y.push(`
|
|
626
|
+
\u26A0\uFE0F \u4FEE\u6539\u65F6\u6CE8\u610F\u5916\u90E8\u72B6\u6001\u7684\u8BFB\u5199\u683C\u5F0F\u4FDD\u6301\u4E00\u81F4`);}let _=Math.round((performance.now()-a)*100)/100,x=Z({durationMs:_,resultCount:p.length,backend:"indexed"});return y.push(`
|
|
592
627
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
593
|
-
${
|
|
594
|
-
`)}]}}),
|
|
595
|
-
|
|
596
|
-
\u{1F3AF} \
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
\
|
|
609
|
-
\u65E7\u65B9\u5F0F: trace_assignments \u2192 find_symbol \u2192 get_code_slice \u2192 find_by_behavior \u2192 trace_key_flow
|
|
610
|
-
\u65B0\u65B9\u5F0F: skimmer_trace_data_lifecycle({ variable: "xxx" }) \u2190 \u76F4\u63A5\u5F97\u5230\u5168\u90E8
|
|
611
|
-
|
|
612
|
-
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({variable:z$1.string().describe('\u8981\u8FFD\u8E2A\u7684\u53D8\u91CF\u540D\u6216 key\uFF0C\u5982 "storageParams" / "savedData"'),project_path:z$1.string().optional().describe(Ne),file_path:z$1.string().optional().describe('\u9650\u5B9A\u6587\u4EF6\u8DEF\u5F84\uFF08\u5305\u542B\u5373\u53EF\uFF0C\u5982 "src/views/apply/index.vue"\uFF09'),storage_api:z$1.enum(["localStorage","sessionStorage","all"]).optional().default("all").describe("storage \u843D\u70B9\u8FC7\u6EE4"),max_depth:z$1.number().optional().default(2).describe("storage \u94FE\u8DEF\u5411\u4E0B\u8FFD\u8E2A\u6DF1\u5EA6\uFF081-5\uFF09"),limit:z$1.number().optional().default(40).describe("\u6BCF\u7EF4\u5EA6\u6700\u5927\u7ED3\u679C\u6570")}),annotations:{readOnlyHint:true,destructiveHint:false}},async({variable:t,project_path:n,file_path:r,storage_api:s,max_depth:i,limit:a})=>{let c=performance.now(),{db:l}=e.getContext(n),p=Math.min(5,Math.max(1,i||2)),u=Math.min(120,Math.max(1,a||40)),d=l.listFiles(r),h="",f=Pn(l,d,r?d.length:5);f.stale&&(h=`\u26A0\uFE0F [\u7D22\u5F15\u5DF2\u8FC7\u671F] \u4EE5\u4E0B\u6587\u4EF6\u5DF2\u4FEE\u6539\u4F46\u7D22\u5F15\u672A\u66F4\u65B0\uFF0C\u2462 \u53C2\u6570\u4F20\u9012 \u548C \u2464 storage \u94FE\u8DEF\u7684\u884C\u53F7\u53EF\u80FD\u504F\u79FB:
|
|
613
|
-
`+f.staleFilePaths.slice(0,3).map(x=>` \u2022 ${x}`).join(`
|
|
628
|
+
${X(x)}`),{content:[{type:"text",text:y.join(`
|
|
629
|
+
`)}]}}),i.registerTool("skimmer_trace_data_lifecycle",{title:"\u{1F30A} \u53D8\u91CF\u751F\u547D\u5468\u671F\u8FFD\u8E2A\uFF08\u9996\u9009\uFF09",description:`\u2B50\u3010\u9996\u9009\u5DE5\u5177\u3011\u8FFD\u8E2A\u53D8\u91CF/\u72B6\u6001\u7684\u5B8C\u6574\u6570\u636E\u751F\u547D\u5468\u671F\uFF0C\u4E00\u6B21\u8C03\u7528\u805A\u5408 4 \u4E2A\u7EF4\u5EA6\u3002
|
|
630
|
+
|
|
631
|
+
\u{1F3AF} \u573A\u666F\uFF1A"xxx \u662F\u4ECE\u54EA\u91CC\u6765\u7684\uFF1F" / "xxx \u88AB\u8C01\u4FEE\u6539\u8FC7\uFF1F" / "xxx \u5199\u5165\u4E86\u54EA\u4E2A API\uFF1F"
|
|
632
|
+
|
|
633
|
+
\u{1F4CA} \u81EA\u52A8\u805A\u5408 4 \u4E2A\u7EF4\u5EA6\uFF1A
|
|
634
|
+
\u2460 \u58F0\u660E\u8D4B\u503C \u2461 \u5C5E\u6027\u4FEE\u6539 \u2462 \u53C2\u6570\u4F20\u9012 \u2463 Storage \u843D\u70B9
|
|
635
|
+
|
|
636
|
+
\u26A1 \u66FF\u4EE3\u65E7 4 \u6B65\uFF1Atrace \u2192 find \u2192 code_slice \u2192 find_by_behavior
|
|
637
|
+
|
|
638
|
+
\u{1F4A1} \u5982\u679C\u4F60\u9700\u8981\u5206\u6790\u4E00\u4E2A\u51FD\u6570/\u7EC4\u4EF6\u7684\u5168\u8C8C\uFF08\u542B\u8C03\u7528\u94FE+\u5F71\u54CD\u8BC4\u4F30\uFF09\uFF0C
|
|
639
|
+
\u800C\u975E\u8FFD\u8E2A\u5355\u4E2A\u53D8\u91CF\u7684\u6570\u636E\u6D41\u5411\uFF0C\u8BF7\u7528 skimmer_query\u3002
|
|
640
|
+
\u274C \u53EA\u9700\u8981\u770B\u4EE3\u7801\u6216\u8C03\u7528\u5173\u7CFB \u2192 skimmer_get_code_slice / skimmer_get_call_graph
|
|
641
|
+
|
|
642
|
+
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z.object({variable:z.string().describe('\u8981\u8FFD\u8E2A\u7684\u53D8\u91CF\u540D\u6216 key\uFF0C\u5982 "storageParams" / "savedData"'),project_path:z.string().optional().describe(Le),file_path:z.string().optional().describe('\u9650\u5B9A\u6587\u4EF6\u8DEF\u5F84\uFF08\u5305\u542B\u5373\u53EF\uFF0C\u5982 "src/views/apply/index.vue"\uFF09'),storage_api:z.enum(["localStorage","sessionStorage","all"]).optional().default("all").describe("storage \u843D\u70B9\u8FC7\u6EE4"),max_depth:z.number().optional().default(2).describe("storage \u94FE\u8DEF\u5411\u4E0B\u8FFD\u8E2A\u6DF1\u5EA6\uFF081-5\uFF09"),limit:z.number().optional().default(40).describe("\u6BCF\u7EF4\u5EA6\u6700\u5927\u7ED3\u679C\u6570")}),annotations:{readOnlyHint:true,destructiveHint:false}},async({variable:t,project_path:n,file_path:r,storage_api:s,max_depth:o,limit:a})=>{let c=performance.now(),{db:l}=e.getContext(n),u=Math.min(5,Math.max(1,o||2)),d=Math.min(120,Math.max(1,a||40)),p=l.listFiles(r),h="",m=Wn(l,p,r?p.length:5);m.stale&&(h=`\u26A0\uFE0F [\u7D22\u5F15\u5DF2\u8FC7\u671F] \u4EE5\u4E0B\u6587\u4EF6\u5DF2\u4FEE\u6539\u4F46\u7D22\u5F15\u672A\u66F4\u65B0\uFF0C\u2462 \u53C2\u6570\u4F20\u9012 \u548C \u2464 storage \u94FE\u8DEF\u7684\u884C\u53F7\u53EF\u80FD\u504F\u79FB:
|
|
643
|
+
`+m.staleFilePaths.slice(0,3).map(A=>` \u2022 ${A}`).join(`
|
|
614
644
|
`)+`
|
|
615
645
|
\u5EFA\u8BAE: skimmer_index_project({ force: true })
|
|
616
|
-
`);let
|
|
617
|
-
\u{1F517} \u53D1\u73B0\u522B\u540D: ${
|
|
646
|
+
`);let f=Ws(p,t,20),g=[...new Set(f.map(A=>A.alias).filter(A=>A!==t))],y=Bs(p,t,20),E=[...new Set(y.map(A=>A.alias).filter(A=>A!==t))],_=[...new Set([...g,...E])],T=[t,..._],w=l.exactSearch(t,"state",void 0,r||void 0),S={vue2:"Vue2 data()",vue3:"Vue3 ref/reactive",react:"React useState/useRef"},b=w.filter(A=>A.default_value!=null).map(A=>({filePath:A.file_path,line:A.start_line,kind:`data_init(${S[A.framework]||A.framework})`,text:`${A.name}: ${A.default_value} \u2190 \u58F0\u660E\u521D\u59CB\u5316`})),N=false,L=l.getAssignments(t,r,d),I=[];L.length>0?(I=L.map(A=>({filePath:A.file_path,line:A.line_number,kind:A.kind,text:A.text_snippet||"",sourceLayer:A.source_layer||void 0})),N=true):I=nr(p,t,false,d);for(let A of _){let F=l.getAssignments(A,r,Math.floor(d/2));F.length>0?I.push(...F.map(R=>({filePath:R.file_path,line:R.line_number,kind:R.kind,text:R.text_snippet||"",sourceLayer:R.source_layer||void 0}))):I.push(...nr(p,A,false,Math.floor(d/2)));}let C=I.length===0?Rt(p,js(t),d):[],P=new Map;for(let A of [...b,...I.length>0?I:C]){let F=`${A.filePath}:${A.line}`;P.has(F)||P.set(F,A);}let K=[...P.values()],V=false,pe=l.getPropertyWrites(t,void 0,r,d),ee=[];pe.length>0?(ee=pe.map(A=>({filePath:A.file_path,line:A.line_number,kind:A.kind,text:A.text_snippet||"",sourceLayer:A.source_layer||void 0})),V=true):ee=rr(p,t,void 0,d);for(let A of _){let F=l.getPropertyWrites(A,void 0,r,Math.floor(d/2));F.length>0?ee.push(...F.map(R=>({filePath:R.file_path,line:R.line_number,kind:R.kind,text:R.text_snippet||"",sourceLayer:R.source_layer||void 0}))):ee.push(...rr(p,A,void 0,Math.floor(d/2)));}let Re=ee.length===0?Rt(p,[{kind:"dot",regex:new RegExp(`\\b${Pe(t)}\\.[A-Za-z_$][\\w$]*\\s*${Je}`)},{kind:"bracket",regex:new RegExp(`\\b${Pe(t)}\\s*\\[(?:'[^']+'|"[^"]+")\\]\\s*${Je}`)},{kind:"array_mutation",regex:new RegExp(`\\b${Pe(t)}\\.${ir}\\s*\\(`)},{kind:"delete",regex:new RegExp(`\\bdelete\\s+${Pe(t)}\\.[A-Za-z_$][\\w$]*\\b`)}],d):[],me=ee.length>0?ee:Re,H=l.findRelationsByArgKeyword(t,r,d);for(let A of _)H.push(...l.findRelationsByArgKeyword(A,r,Math.floor(d/2)));let z=[],we=[],Qe=[];for(let A of T){let F=Pe(A),R=/^[a-zA-Z_$][\w$]*$/.test(A)?"\\b":"";z.push({kind:"template",regex:new RegExp(`(?::\\w+|v-model|v-if|v-show|@\\w+)="[^"]*${R}${F}${R}|\\{\\{[^}]*${R}${F}${R}[^}]*\\}\\}`)},{kind:"return",regex:new RegExp(`\\breturn\\b[^=]*${R}${F}${R}`)},{kind:"watch",regex:new RegExp(`watch[^(]*['"]\\.?${F}['"]`)},{kind:"computed_read",regex:new RegExp(`=>[^=]*${R}${F}${R}|return[^=]*${R}${F}${R}`)},{kind:"arg_usage",regex:new RegExp(`\\(\\s*[^)]*${R}${F}${R}[^)]*\\)`)}),we.push(`${R}${F}${R}\\s*(?:=|\\+=|-=|\\*=|\\/=)(?!=)|\\b(?:const|let|var)\\s+${F}\\b`),Qe.push(`${R}${F}${R}\\.\\w+\\s*(?:=|\\+=|-=)(?!=)|${R}${F}${R}\\s*\\[`);}let Ze=Rt(p,z,d),on=new RegExp(we.join("|")),oe=new RegExp(Qe.join("|")),Be=Ze.filter(A=>!on.test(A.text)&&!oe.test(A.text)),It=new Map,an=(A,F)=>{if(!It.has(A)){let{behaviors:j}=l.getFileOutline(A),M=new Map;for(let B of j){let ae=String(B.symbol_name||"");M.has(ae)||M.set(ae,[]),M.get(ae).push(B);}It.set(A,M);}return (It.get(A)?.get(F)||[]).filter(j=>String(j.category||"")!=="storage"?false:s==="all"?true:String(j.api_name||"").toLowerCase()===s.toLowerCase())},mr=(A,F)=>{let R=[],j=[{name:A,filePath:F,path:[A],level:0}],M=new Set([`${F}::${A}`]);for(;j.length>0;){let B=j.shift(),ae=an(B.filePath,B.name);if(ae.length>0){R.push({path:B.path,file:B.filePath,behaviors:ae});continue}if(B.level>=u)continue;let re=l.getSymbolByName(B.name,B.filePath);if(re||(re=l.getSymbolByName(B.name)),!re)continue;let ge=String(re.file_path||re.abs_path||B.filePath),We=an(ge,B.name);if(We.length>0){R.push({path:B.path,file:ge,behaviors:We});continue}let $t=l.getCallees(re.id);for(let Ue of $t){let He=String(Ue.callee_name||"");if(!He||He.startsWith("$"))continue;let ln=`${ge}::${He}`;M.has(ln)||(M.add(ln),j.push({name:He,filePath:ge,path:[...B.path,He],level:B.level+1}));}}return R},gr=_.length>0?`
|
|
647
|
+
\u{1F517} \u53D1\u73B0\u522B\u540D: ${_.map(A=>`"${A}"`).join(", ")}\uFF08\u5DF2\u4E00\u5E76\u8FFD\u8E2A\u5C5E\u6027\u4FEE\u6539\uFF09`:"",Fe=[];y.length>0&&(Fe.push(` \u{1F517} \u5F15\u7528\u522B\u540D\u4F20\u64AD (${y.length} \u5904) \u2014 \u8FD9\u4E9B\u5C40\u90E8\u53D8\u91CF\u662F "${t}" \u7684\u5F15\u7528\uFF0C\u5176\u5C5E\u6027\u4FEE\u6539\u4E5F\u88AB\u8FFD\u8E2A:`),y.slice(0,10).forEach(A=>{let R=p.find(B=>B.path===A.filePath)?.abs_path||A.abs_path,j=wt("alias_ref"),M=R?nn(R,A.line,2):{snippet:""};Fe.push(` \u{1F4C4} ${A.filePath}:L${A.line} "${A.alias}" = ... ${j}`),Fe.push(` ${A.text}`),M.snippet&&Fe.push(M.snippet);}));let $=[`\u{1F52C} \u53D8\u91CF\u751F\u547D\u5468\u671F\u8FFD\u8E2A: "${t}"`,"\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501",`\u8FC7\u6EE4: file_path=${r||"*"} storage_api=${s} depth=${u}${gr}`,""];if(h&&$.push(h),$.push(`\u2460 \u58F0\u660E & \u6574\u4F53\u8D4B\u503C (${K.length} \u5904)`),K.length===0)$.push(" \uFF08\u672A\u627E\u5230\uFF09");else {let A={init:[],cache:[],user:[],unknown:[]};for(let R of K){let j=R.sourceLayer||ie(R.text,R.line);A[j].push(R);}let F=["init","cache","user","unknown"];for(let R of F){let j=A[R];!j||j.length===0||($.push(` \u25B8 ${tr[R]} (${j.length} \u5904)`),j.slice(0,8).forEach(M=>{let B=_.includes(M.text.split("=")[0]?.trim().replace(/^(?:const|let|var)\s+/,"")||""),ae=wt(M.kind,B);$.push(` \u{1F4C4} ${M.filePath}:L${M.line} [${M.kind}] ${ae}`),$.push(` ${M.text}`);}));}Fe.length>0&&($.push(""),$.push(...Fe));}if($.push(""),$.push(`\u2461 \u5C5E\u6027\u4FEE\u6539 (${me.length} \u5904)`),me.length===0)$.push(' \uFF08\u672A\u627E\u5230 object.prop \u6216 object["prop"] \u5199\u5165\uFF09'),_.length>0&&$.push(` \u2139\uFE0F \u5DF2\u8FFD\u8E2A\u522B\u540D: ${_.map(A=>`"${A}"`).join(", ")} \u7684\u5C5E\u6027\u4FEE\u6539\uFF08\u5982\u4ECD\u672A\u627E\u5230\uFF0C\u8868\u793A\u771F\u6B63\u65E0\u95F4\u63A5\u5199\u5165\uFF09`);else {let A={init:[],cache:[],user:[],unknown:[]};for(let R of me){let j=R.sourceLayer||ie(R.text,R.line);A[j].push(R);}let F=["init","cache","user","unknown"];for(let R of F){let j=A[R];!j||j.length===0||($.push(` \u25B8 ${tr[R]} (${j.length} \u5904)`),j.slice(0,8).forEach(M=>{let B=_.some(Ue=>M.text.startsWith(Ue)),ae=wt(M.kind,B),ge=p.find(Ue=>Ue.path===M.filePath)?.abs_path||"",We=ge?nn(ge,M.line,2):{snippet:""},$t=B?" \u{1F517}(via alias)":"";$.push(` \u{1F4C4} ${M.filePath}:L${M.line} [${M.kind}] ${ae}${$t}`),We.snippet&&$.push(We.snippet);}));}}if($.push(""),$.push(`\u2462 \u4F5C\u4E3A\u53C2\u6570\u88AB\u4F20\u5165\u8C03\u7528 (${H.length} \u5904)`),H.length===0?$.push(" \uFF08\u672A\u53D1\u73B0\u4EE5\u8BE5\u53D8\u91CF\u4F5C\u4E3A\u53C2\u6570\u7684\u51FD\u6570\u8C03\u7528\uFF09"):H.slice(0,20).forEach(A=>{let F=String(A.args||"");$.push(` \u{1F4C4} ${A.file_path}:L${A.line_number} ${A.caller_name} \u2192 ${A.callee_name} \u53C2\u6570: "${F}"`);}),$.push(""),$.push(`\u2463 \u8BFB\u53D6/\u4F7F\u7528 (${Be.length} \u5904)`),Be.length===0)$.push(" \uFF08\u672A\u53D1\u73B0 template \u7ED1\u5B9A / watch / computed / return \u4E2D\u7684\u5F15\u7528\uFF09");else {let A=new Map;for(let R of Be)A.has(R.kind)||A.set(R.kind,[]),A.get(R.kind).push(R);let F={template:"\u{1F5BC}\uFE0F template \u7ED1\u5B9A",return:"\u21A9\uFE0F return \u8FD4\u56DE",watch:"\u{1F441}\uFE0F watch \u76D1\u542C",computed_read:"\u{1F9EE} computed \u5F15\u7528",arg_usage:"\u{1F4E8} \u51FD\u6570\u53C2\u6570\u4F7F\u7528"};for(let[R,j]of A)$.push(` \u25B8 ${F[R]||R}`),j.slice(0,8).forEach(M=>$.push(` \u{1F4C4} ${M.filePath}:L${M.line} ${M.text}`));}$.push("");let Oe=0;$.push(`\u2464 Storage \u843D\u70B9\u8FFD\u8E2A (storage_api=${s}, depth=${u})`);let hr=s==="localStorage"?"localStorage":s==="sessionStorage"?"sessionStorage":"(?:localStorage|sessionStorage)",yr=T.map(A=>({kind:"direct_storage",regex:new RegExp(`${hr}\\.(?:setItem|getItem|removeItem|clear)\\(.*?\\b${Pe(A)}\\b`)})),et=Rt(p,yr,d);if(et.length>0&&(Oe+=1,$.push(` \u843D\u70B9 [\u76F4\u63A5\u547D\u4E2D\u5B58\u50A8] ${wt("direct_storage")}:`),et.slice(0,15).forEach(A=>{let R=p.find(M=>M.path===A.filePath)?.abs_path||"",j=R?nn(R,A.line,2):{snippet:""};$.push(` \u{1F4C4} ${A.filePath}:L${A.line} ${A.text.trim()}`),j.snippet&&$.push(j.snippet);})),H.length===0&&et.length===0)$.push(" \uFF08\u672A\u53D1\u73B0\u76F4\u63A5 Storage \u64CD\u4F5C\uFF0C\u4E14\u65E0\u8C03\u7528\u5165\u53E3\u5C55\u5F00\u8FFD\u8E2A\uFF09");else {let A=new Map;for(let F of H){let R=`${F.file_path}::${F.callee_name}`;A.has(R)||A.set(R,F);}for(let[,F]of A){let R=String(F.callee_name||""),j=String(F.file_path||""),M=mr(R,j);M.length!==0&&(Oe+=1,M.slice(0,3).forEach(B=>{let ae=B.file!==j?` \u2197 \u8DE8\u6587\u4EF6: ${B.file}`:"";$.push(` \u94FE\u8DEF: ${B.path.join(" \u2192 ")}${ae}`),B.behaviors.forEach(re=>{let ge=re.detail?`("${String(re.detail)}")`:"";$.push(` \u843D\u70B9: ${re.api_name}.${re.operation}${ge} [${re.category}] L${re.line_number}`);});}));}Oe===0&&et.length===0&&$.push(` \uFF08\u5728 depth=${u} \u5C42\u5185\u672A\u627E\u5230 storage \u5199\u5165\u94FE\u8DEF\uFF09`);}$.push(""),$.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");let br=_.length>0?` (\u542B ${_.length} \u4E2A\u522B\u540D: ${_.slice(0,3).map(A=>`"${A}"`).join(", ")})`:"";$.push(`\u2705 \u6C47\u603B${br}:`),$.push(` \u2460 \u58F0\u660E/\u8D4B\u503C: ${K.length} \u5904`),$.push(` \u2461 \u5C5E\u6027\u4FEE\u6539: ${me.length} \u5904 (\u5DF2\u8FFD\u8E2A\u522B\u540D: ${_.map(A=>`"${A}"`).join(", ")||"\u65E0"})`),$.push(` \u2462 \u53C2\u6570\u4F20\u9012: ${H.length} \u5904`),$.push(` \u2463 \u8BFB\u53D6\u5F15\u7528: ${Be.length} \u5904`),$.push(` \u2464 storage: ${Oe>0?`\u2713 \u53D1\u73B0\u5199\u5165\u94FE\u8DEF (${Oe} \u6761)`:"\u2717 \u672A\u53D1\u73B0"}`),$.push(""),$.push("\u{1F4A1} \u6765\u6E90\u5206\u5C42\u8BF4\u660E: \u{1F331}\u521D\u59CB\u5316 = lifecycle/data | \u{1F4BE}\u7F13\u5B58\u56DE\u663E = storage\u8BFB/fetch | \u{1F5B1}\uFE0F\u7528\u6237\u4EA4\u4E92 = \u4E8B\u4EF6/watch"),$.push("\u{1F4CA} \u7F6E\u4FE1\u5EA6: \u25CF\u25CF\u25CF\u25CF\u25CF \u226590% \u25CF\u25CF\u25CF\u25CF\u25CB \u226580% \u25CF\u25CF\u25CF\u25CB\u25CB \u226570% \u25CF\u25CF\u25CB\u25CB\u25CB \u226560% \u9700\u4EBA\u5DE5\u9A8C\u8BC1\u884C\u53F7\u786E\u8BA4");let _r=Math.round((performance.now()-c)*100)/100,Er=K.length+me.length+H.length+Be.length+Oe,cn=Z({durationMs:_r,resultCount:Er,backend:N&&V?"indexed":N||V?"hybrid":"fallback_scan"});return m.stale&&(cn.index_freshness=m),$.push(`
|
|
618
648
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
619
|
-
${
|
|
620
|
-
`)}]}})
|
|
649
|
+
${X(cn)}`),{content:[{type:"text",text:$.join(`
|
|
650
|
+
`)}]}}),i.registerTool("skimmer_query",{title:"\u26A1 \u667A\u80FD\u5206\u6790\uFF08\u4E00\u952E\u805A\u5408\uFF09",description:`\u{1F680} \u3010\u63A8\u8350\u5165\u53E3\u3011\u7528\u81EA\u7136\u8BED\u8A00\u63CF\u8FF0\u4F60\u60F3\u67E5\u7684\u5185\u5BB9\uFF0C\u540E\u7AEF\u81EA\u52A8\u5206\u6D3E 4~6 \u8DEF\u5E76\u884C\u67E5\u8BE2\uFF0C\u4E00\u6B21\u8FD4\u56DE\u5168\u8C8C\u3002
|
|
651
|
+
\u63A5\u53D7\u4EFB\u4F55\u5173\u4E8E\u4EE3\u7801\u7684\u5206\u6790\u95EE\u9898\uFF0C\u540E\u7AEF\u81EA\u52A8\u5224\u65AD\u4F60\u8981\u67E5\u4EC0\u4E48\u5E76\u6267\u884C\u591A\u8DEF\u5E76\u884C\u67E5\u8BE2\u3002
|
|
652
|
+
|
|
653
|
+
\u{1F3AF} \u573A\u666F\u793A\u4F8B:
|
|
654
|
+
- "\u5E2E\u6211\u67E5\u4E00\u4E0B\u63D0\u4EA4\u6309\u94AE\u7684\u6570\u636E\u6D41"
|
|
655
|
+
- "persistDraft \u6539\u4E86\u4F1A\u5F71\u54CD\u54EA\u4E9B\u5730\u65B9\uFF1F"
|
|
656
|
+
- "\u6240\u6709\u5199 localStorage \u7684\u5730\u65B9"
|
|
657
|
+
- "storageParams \u662F\u600E\u4E48\u8D4B\u503C\u7684"
|
|
658
|
+
- "submit \u8FD9\u4E2A\u6309\u94AE\u7684\u903B\u8F91"
|
|
659
|
+
|
|
660
|
+
\u{1F4CA} \u81EA\u52A8\u805A\u5408\u4EE5\u4E0B\u7EF4\u5EA6\uFF08\u540E\u7AEF\u6309\u9700\u9009\u62E9\uFF09\uFF1A
|
|
661
|
+
\u7B26\u53F7\u641C\u7D22 / \u4EE3\u7801\u7247\u6BB5 / \u8C03\u7528\u94FE / \u884C\u4E3A\u6807\u7B7E / \u5F71\u54CD\u8BC4\u4F30 / \u6570\u636E\u751F\u547D\u5468\u671F
|
|
662
|
+
|
|
663
|
+
\u26A1 \u66FF\u4EE3 4~6 \u6B21\u7EC6\u7C92\u5EA6\u5DE5\u5177\u8C03\u7528\uFF0C\u538B\u7F29\u4E3A 1 \u6B21\uFF08\u540E\u7AEF 40~80ms \u5E76\u884C\u67E5\u8BE2\uFF09\u3002
|
|
664
|
+
|
|
665
|
+
\u53C2\u6570\u8BBE\u8BA1\uFF1A\u96F6\u53EF\u9009\u9879\uFF0C\u5168\u90E8\u540E\u7AEF\u81EA\u52A8\u51B3\u7B56\u3002`,inputSchema:z.object({question:z.string().describe('\u81EA\u7136\u8BED\u8A00\u95EE\u9898\uFF0C\u5982 "\u5E2E\u6211\u67E5\u4E00\u4E0B\u63D0\u4EA4\u6309\u94AE\u7684\u6570\u636E\u6D41"'),project_path:z.string().optional().describe(Le)}),annotations:{readOnlyHint:true,destructiveHint:false}},async({question:t,project_path:n})=>{let r=performance.now(),{db:s}=e.getContext(n),o=new $e(s),a=Yn(t),c=Jn(t),l=[];for(let b of c)s.exactSearch(b,void 0,void 0,void 0).length>0&&l.push(b);let u=Qn(a,c,l,t),d=[],p=[];if(u.dimensions.includes("symbol_lookup")&&(d.push((async()=>({dimension:"symbol_lookup",results:o.search(t,{limit:5})}))()),p.push("\u{1F50D} \u7B26\u53F7\u641C\u7D22")),u.dimensions.includes("snippet_search")&&(d.push((async()=>({dimension:"snippet_search",results:o.searchSnippets(t,{limit:5})}))()),p.push("\u{1F50E} \u4EE3\u7801\u7247\u6BB5")),u.dimensions.includes("behavior_scan")&&(d.push((async()=>({dimension:"behavior_scan",results:o.searchByBehavior({keyword:t})}))()),p.push("\u{1F3F7}\uFE0F \u884C\u4E3A\u6807\u7B7E")),u.dimensions.includes("call_graph")&&l.length>0){let b=l[0];d.push((async()=>{let N=s.getCallers(b).slice(0,8),L=s.getSymbolByName(b),I=L?.id?s.getCallees(L.id).slice(0,8):[];return {dimension:"call_graph",target:b,callers:N,callees:I}})()),p.push("\u{1F504} \u8C03\u7528\u5173\u7CFB");}if(u.dimensions.includes("lifecycle_trace")&&l.length>0){let b=l[0];d.push((async()=>{let N=s.getAssignments(b,void 0,10),L=s.getPropertyWrites(b,void 0,void 0,10),I=s.findRelationsByArgKeyword(b,void 0,10),C=[],P=new Set,K=(V,pe,ee=[],Re=0)=>{if(!V||Re>3)return [];let me=`${pe||"*"}::${V}`;if(P.has(me))return [];P.add(me);let H=s.getSymbolByName(V,pe);if(H||(H=s.getSymbolByName(V)),!H)return [];let z=String(H.file_path||pe||""),we=[...ee,V],{behaviors:Qe}=s.getFileOutline(z),Ze=Qe.filter(oe=>String(oe.symbol_name||"")===V&&String(oe.category||"")==="storage").map(oe=>({path:we,file:z,apiName:String(oe.api_name||""),operation:String(oe.operation||""),detail:String(oe.detail||""),category:String(oe.category||""),lineNumber:oe.line_number||"?"}));return Ze.length>0?Ze:(H.id?s.getCallees(H.id):[]).flatMap(oe=>K(String(oe.callee_name||""),z,we,Re+1))};for(let V of I)C.push(...K(String(V.callee_name||""),String(V.file_path||"")));return C.push(...K(b)),{dimension:"lifecycle_trace",target:b,assignHits:N,propWrites:L,relationRows:I,storageEndpoints:C}})()),p.push("\u{1F30A} \u6570\u636E\u6D41");}if(u.dimensions.includes("blast_radius")&&l.length>0){let b=l[0];d.push((async()=>{let N=s.getCallers(b),L=N.length===0?"\u{1F7E2} \u4F4E":N.length<=3?"\u{1F7E1} \u4E2D":"\u{1F534} \u9AD8";return {dimension:"blast_radius",target:b,callerCount:N.length,risk:L}})()),p.push("\u{1F4A5} \u5F71\u54CD\u8BC4\u4F30");}if(u.dimensions.includes("code_slice")&&l.length>0){let b=l[0];d.push((async()=>{let N=s.getSymbolByName(b),L="";if(N?.abs_path&&ne__default.existsSync(N.abs_path)){let I=ne__default.readFileSync(N.abs_path,"utf-8").split(`
|
|
666
|
+
`),C=Math.max(0,(N.start_line||1)-1),P=Math.min(I.length,(N.end_line||1)+2);L=I.slice(C,P).join(`
|
|
667
|
+
`);}return {dimension:"code_slice",target:b,snippet:L}})()),p.push("\u{1F4C4} \u6E90\u7801");}let h=await Promise.allSettled(d),m=[];for(let b of h)b.status==="fulfilled"&&m.push(b.value);let f=[`\u{1F4CA} \u667A\u80FD\u5206\u6790: "${t.slice(0,40)}${t.length>40?"...":""}"`,`\u{1F3AF} \u5206\u6790\u610F\u56FE: ${a}${l.length>0?` | \u{1F9E9} \u5339\u914D\u7B26\u53F7: ${l.slice(0,4).join(", ")}${l.length>4?"...":""}`:" | \u{1F9E9} \u672A\u5339\u914D\u5230\u5DF2\u77E5\u7B26\u53F7"}`,"\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501",""],g=m.find(b=>b.dimension==="code_slice");g?.snippet&&(f.push(`\u{1F4C4} ${g.target} \u6E90\u7801:`),f.push("```"),f.push(g.snippet),f.push("```"),f.push(""));let y=m.find(b=>b.dimension==="call_graph");if(y){let b=y.callers,N=y.callees;b.length>0&&(f.push(`\u{1F4DE} ${y.target} \u88AB\u8C03\u7528 (${b.length}):`),b.forEach(L=>f.push(` \u2022 ${L.caller_name} @ ${L.file_path}:L${L.start_line||"?"}`))),N.length>0&&(f.push(`\u{1F504} \u5185\u90E8\u8C03\u7528 (${N.length}):`),N.forEach(L=>f.push(` \u2022 ${L.callee_name}`))),f.push("");}let E=m.find(b=>b.dimension==="lifecycle_trace");if(E){let b=E.assignHits||[],N=E.propWrites||[],L=E.relationRows||[],I=E.storageEndpoints||[];if(b.length>0||N.length>0||L.length>0||I.length>0){if(f.push(`\u{1F30A} ${E.target} \u6570\u636E\u6D41:`),b.length>0&&f.push(` \u{1F4DD} \u8D4B\u503C ${b.length} \u5904`),N.length>0&&f.push(` \u270F\uFE0F \u5C5E\u6027\u4FEE\u6539 ${N.length} \u5904`),L.length>0&&f.push(` \u{1F4E4} \u4F5C\u4E3A\u53C2\u6570\u4F20\u5165 ${L.length} \u5904`),I.length>0){let C=new Map;for(let P of I){let K=`${P.path.join(">")}::${P.file}::${P.lineNumber}::${P.apiName}.${P.operation}`;C.has(K)||C.set(K,P);}f.push(` \u{1F4BE} Storage \u843D\u70B9 ${C.size} \u6761:`),[...C.values()].slice(0,5).forEach(P=>{let K=P.detail?`("${P.detail}")`:"";f.push(` \u2022 ${P.path.join(" \u2192 ")} \u2192 ${P.apiName}.${P.operation}${K} @ ${P.file}:L${P.lineNumber}`);});}f.push("");}}let _=m.find(b=>b.dimension==="blast_radius");if(_){let b=_.callerCount;f.push(`\u{1F4A5} ${_.target} \u5F71\u54CD\u9762: ${b} \u4E2A\u8C03\u7528\u70B9 | ${_.risk}`),f.push("");}let x=m.find(b=>b.dimension==="behavior_scan");if(x){let b=x.results;b.length>0&&(f.push(`\u{1F3F7}\uFE0F \u884C\u4E3A\u6807\u7B7E (${b.length}):`),b.slice(0,8).forEach(N=>{let L=N.detail?`("${N.detail}")`:"";f.push(` \u2022 ${N.apiName}.${N.operation}${L} [${N.category}] ${N.symbolName} @ ${N.filePath}`);}),f.push(""));}let T=m.find(b=>b.dimension==="symbol_lookup");if(T){let b=T.results;b.length>0&&!E&&!g&&(f.push(`\u{1F50D} \u76F8\u5173\u7B26\u53F7 (${b.length}):`),b.slice(0,5).forEach(N=>{f.push(` \u2022 ${N.name} [${N.category}/${N.framework}] @ ${N.file_path}`);}),f.push(""));}let w=Math.round((performance.now()-r)*100)/100,S=p.join(" | ");return f.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"),f.push(`\u26A1 \u672C\u6B21\u67E5\u8BE2\u805A\u5408\u4E86 ${m.length} \u4E2A\u7EF4\u5EA6`),f.push(` ${S}`),f.push(`\u26A1 \u540E\u7AEF\u8017\u65F6: ${w}ms`),f.push(""),f.push("\u{1F4A1} \u5982\u9700\u6DF1\u5165\u67D0\u4E2A\u7EF4\u5EA6:"),f.push(" \u770B\u6E90\u7801 \u2192 skimmer_get_code_slice"),f.push(" \u770B\u8C03\u7528\u94FE \u2192 skimmer_get_call_graph"),f.push(" \u505A\u5F71\u54CD\u8BC4\u4F30 \u2192 skimmer_get_blast_radius"),f.push(" \u8FFD\u8E2A\u6570\u636E\u6D41 \u2192 skimmer_trace_data_lifecycle"),{content:[{type:"text",text:f.join(`
|
|
668
|
+
`)}]}});}function lr(i,e){i.registerTool("skimmer_index_health",{title:"\u7D22\u5F15\u5065\u5EB7\u68C0\u67E5",description:`\u68C0\u67E5\u5F53\u524D\u9879\u76EE\u7D22\u5F15\u7684\u5065\u5EB7\u72B6\u6001\u3002
|
|
621
669
|
\u8FD4\u56DE: \u7D22\u5F15\u6587\u4EF6\u6570\u3001\u7B26\u53F7\u6570\u3001\u5173\u7CFB\u6570\u3001\u884C\u4E3A\u6570\u3001\u6700\u540E\u66F4\u65B0\u65F6\u95F4\u3001\u5931\u8D25\u6587\u4EF6\u3001watcher \u72B6\u6001\u3001\u6570\u636E\u5E93\u5927\u5C0F\u3002
|
|
622
|
-
project_path \u53EF\u7701\u7565\uFF08\u81EA\u52A8\u4F7F\u7528\u4E0A\u6B21\u7D22\u5F15\u7684\u9879\u76EE\uFF09\u3002`,inputSchema:z
|
|
623
|
-
`)}]}});}var
|
|
624
|
-
\u652F\u6301\u5217\u51FA\u5F53\u524D\u6240\u6709\u5DF2\u7F13\u5B58\u7684\u9879\u76EE\u3002project_path \u53EF\u7701\u7565\u3002`,inputSchema:z
|
|
670
|
+
project_path \u53EF\u7701\u7565\uFF08\u81EA\u52A8\u4F7F\u7528\u4E0A\u6B21\u7D22\u5F15\u7684\u9879\u76EE\uFF09\u3002`,inputSchema:z.object({project_path:z.string().optional().describe("\u9879\u76EE\u6839\u76EE\u5F55\uFF08\u53EF\u7701\u7565\uFF0C\u4F7F\u7528\u4E0A\u6B21\u7D22\u5F15\u7684\u9879\u76EE\uFF09")}),annotations:{readOnlyHint:true,destructiveHint:false}},async({project_path:t})=>{let n=performance.now(),{db:r,projectRoot:s}=e.getContext(t),o=r.getProjectStats(),a=(()=>{try{let x=r.getLastIndexedTime();return x?new Date(x).toISOString():"\u6682\u65E0\u7D22\u5F15\u6570\u636E"}catch{return "\u6682\u65E0\u7D22\u5F15\u6570\u636E"}})(),c=o.fileCount||0,l=o.symbolCount||0,u=r.getIndexFailures(10),d=e.hasWatcher(s),m=e.listProjects().find(x=>x.root===s)?.dbPath||"",f=o.dbSize||0,g={dbPath:m,indexedFiles:c,totalSymbols:l,totalRelations:o.relationCount||0,totalBehaviors:o.behaviorCount||0,lastIndexedAt:a,failureCount:o.failureCount||0,failedFiles:u.map(x=>({file:x.file_path,error:x.error})),watcherActive:d,dbSizeBytes:f},y=Math.round((performance.now()-n)*100)/100,E=Z({durationMs:y,resultCount:1,backend:"indexed"}),_=[`\u{1F3E5} \u7D22\u5F15\u5065\u5EB7\u68C0\u67E5 \u2014 ${s}`,"\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501","","\u{1F4CA} \u7D22\u5F15\u7EDF\u8BA1:",` \u{1F4C1} \u5DF2\u7D22\u5F15\u6587\u4EF6: ${g.indexedFiles}`,` \u{1F523} \u7B26\u53F7\u6570: ${g.totalSymbols}`,` \u{1F517} \u8C03\u7528\u5173\u7CFB: ${g.totalRelations}`,` \u{1F3F7}\uFE0F \u884C\u4E3A\u6807\u7B7E: ${g.totalBehaviors}`,` \u{1F4C5} \u6700\u540E\u7D22\u5F15\u65F6\u95F4: ${g.lastIndexedAt}`,` \u2757 \u5931\u8D25\u6587\u4EF6\u603B\u6570: ${g.failureCount}`,"","\u{1F50C} \u8FD0\u884C\u65F6\u72B6\u6001:",` \u{1F4C2} \u6587\u4EF6\u76D1\u542C: ${g.watcherActive?"\u2705 \u6D3B\u8DC3":"\u274C \u672A\u542F\u52A8"}`,` \u{1F4BE} \u6570\u636E\u5E93\u5927\u5C0F: ${Math.round(g.dbSizeBytes/1024)} KB`,` \u{1F4CD} \u6570\u636E\u5E93\u8DEF\u5F84: ${g.dbPath||"\uFF08\u5185\u5B58\uFF09"}`,"","\u{1F4A1} \u5EFA\u8BAE:"];if(g.totalSymbols===0&&g.indexedFiles>0?_.push(" \u26A0\uFE0F \u6709\u6587\u4EF6\u4F46\u7B26\u53F7\u6570\u4E3A0 \u2014 \u53EF\u80FD\u9700\u8981\u8C03\u6574\u89E3\u6790\u89C4\u5219\u6216\u5F3A\u5236\u91CD\u5EFA"):g.indexedFiles===0?_.push(" \u274C \u5C1A\u672A\u7D22\u5F15 \u2014 \u8FD0\u884C skimmer_index_project \u5F00\u59CB\u7D22\u5F15"):_.push(" \u2705 \u7D22\u5F15\u72B6\u6001\u6B63\u5E38"),!g.watcherActive&&g.indexedFiles>0&&_.push(" \u{1F4A1} \u6587\u4EF6\u76D1\u542C\u672A\u542F\u52A8 \u2014 \u8FD0\u884C skimmer_index_project \u53EF\u81EA\u52A8\u5F00\u542F"),g.failedFiles.length>0){_.push(""),_.push("\u26A0\uFE0F \u6700\u8FD1\u5931\u8D25\u6587\u4EF6\u6837\u672C:");for(let x of g.failedFiles.slice(0,5))_.push(` - ${x.file}: ${x.error}`);}return _.push(""),_.push("\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500"),_.push(X(E)),{content:[{type:"text",text:_.join(`
|
|
671
|
+
`)}]}});}var Us="\u9879\u76EE\u6839\u76EE\u5F55\uFF08\u53EF\u7701\u7565\uFF0C\u4F7F\u7528\u4E0A\u6B21\u7D22\u5F15\u7684\u9879\u76EE\uFF09";function pr(i,e){i.registerTool("skimmer_get_project_overview",{title:"\u83B7\u53D6\u9879\u76EE\u6574\u4F53\u6982\u89C8",description:`\u8FD4\u56DE\u9879\u76EE\u7684\u5168\u666F\u7EDF\u8BA1\uFF1A\u6587\u4EF6\u6570\u3001\u6846\u67B6\u5206\u5E03\u3001\u6700\u5927\u6587\u4EF6\u3001\u884C\u4E3A\u7EDF\u8BA1\u3002
|
|
672
|
+
\u652F\u6301\u5217\u51FA\u5F53\u524D\u6240\u6709\u5DF2\u7F13\u5B58\u7684\u9879\u76EE\u3002project_path \u53EF\u7701\u7565\u3002`,inputSchema:z.object({project_path:z.string().optional().describe(Us),list_all_projects:z.boolean().optional().default(false).describe("\u662F\u5426\u5217\u51FA\u6240\u6709\u5DF2\u7D22\u5F15\u7684\u9879\u76EE")}),annotations:{readOnlyHint:true,destructiveHint:false}},async({project_path:t,list_all_projects:n})=>{let r=performance.now();if(n){let m=e.listProjects(),f=Math.round((performance.now()-r)*100)/100,g=Z({durationMs:f,resultCount:m.length,backend:"indexed"});if(m.length===0)return {content:[{type:"text",text:`\u{1F4CB} \u5F53\u524D\u6CA1\u6709\u5DF2\u7D22\u5F15\u7684\u9879\u76EE
|
|
625
673
|
|
|
626
674
|
\u4F7F\u7528 skimmer_index_project({ project_path: "/your/project" }) \u5F00\u59CB\u7D22\u5F15
|
|
627
675
|
|
|
628
676
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
629
|
-
${
|
|
630
|
-
`];return
|
|
677
|
+
${X(g)}`}]};let y=[`\u{1F4CB} \u5DF2\u7D22\u5F15\u7684\u9879\u76EE (${m.length} \u4E2A):
|
|
678
|
+
`];return m.forEach((E,_)=>{y.push(`${_+1}. ${E.root}`),y.push(` \u6570\u636E\u5E93: ${E.dbPath}`);}),y.push(`
|
|
631
679
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
632
|
-
${
|
|
633
|
-
`)}]}}let{db:s,projectRoot:
|
|
680
|
+
${X(g)}`),{content:[{type:"text",text:y.join(`
|
|
681
|
+
`)}]}}let{db:s,projectRoot:o}=e.getContext(t),a=s.getProjectStats(),c=["\u{1F4CA} \u9879\u76EE\u6982\u89C8","\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501",`\u{1F4C1} ${o}`,"",`\u{1F4C8} \u6574\u4F53: \u6587\u4EF6 ${a.fileCount} | \u7B26\u53F7 ${a.symbolCount} | \u884C\u4E3A\u6807\u7B7E ${a.behaviorCount} | \u8C03\u7528\u5173\u7CFB ${a.relationCount}`,""],l=a.frameworkBreakdown;if(l?.length){let m={vue2:"\u{1F7E2} Vue2",vue3:"\u{1F535} Vue3",react:"\u269B\uFE0F React",js:"\u{1F4DC} JS",ts:"\u{1F4D8} TS"};c.push("\u{1F527} \u6846\u67B6\u5206\u5E03:");for(let f of l)c.push(` ${m[f.framework]||f.framework}: ${f.count} \u4E2A`);c.push("");}let u=a.topFiles;u?.length&&(c.push("\u{1F5C2}\uFE0F Top 10 \u6700\u5927\u6587\u4EF6:"),u.forEach((m,f)=>{c.push(` ${f+1}. ${m.path} (${m.line_count} \u884C, ${m.symbol_count} \u7B26\u53F7)`);}),c.push(""));let d=a.behaviorStats;if(d?.length){let m={storage:"\u{1F4BE} \u5B58\u50A8",network:"\u{1F310} \u7F51\u7EDC",router:"\u{1F6E3}\uFE0F \u8DEF\u7531",vuex:"\u{1F4E6} Vuex",dom:"\u{1F5A5}\uFE0F DOM",event:"\u{1F4E1} \u4E8B\u4EF6",timer:"\u23F1\uFE0F \u5B9A\u65F6\u5668",i18n:"\u{1F30D} \u56FD\u9645\u5316"};c.push("\u{1F3F7}\uFE0F \u884C\u4E3A\u7EDF\u8BA1:");for(let f of d)c.push(` ${m[f.category]||f.category}: ${f.count} \u5904`);c.push("");}c.push(`\u{1F4BD} \u6570\u636E\u5E93: ${Math.round(a.dbSize/1024)} KB`);let p=Math.round((performance.now()-r)*100)/100,h=Z({durationMs:p,resultCount:1,backend:"indexed"});return c.push(`
|
|
634
682
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
635
|
-
${
|
|
636
|
-
`)}]}});}function
|
|
637
|
-
`);try{let{projectRoot:n}=
|
|
638
|
-
`);let
|
|
683
|
+
${X(h)}`),{content:[{type:"text",text:c.join(`
|
|
684
|
+
`)}]}});}function dr(i){let e=[te__default.resolve(i,"../package.json"),te__default.resolve(i,"../../package.json")];for(let t of e)try{let n=JSON.parse(ne__default.readFileSync(t,"utf-8"));if(typeof n.version=="string"&&n.version.trim())return n.version.trim()}catch{}return "0.0.0-dev"}var Se=new Tt,fr=dr(te__default.dirname(fileURLToPath(import.meta.url))),je=new McpServer({name:"frontend-code-skimmer",version:fr});Bn(je,Se);Un(je,Se);ar(je,Se);lr(je,Se);pr(je,Se);async function Gs(){if(process.env.SKIMMER_AUTO_INDEX==="true"&&process.env.SKIMMER_PROJECT){process.stderr.write(`[Frontend-Code-Skimmer] \u81EA\u52A8\u7D22\u5F15: ${process.env.SKIMMER_PROJECT}
|
|
685
|
+
`);try{let{projectRoot:n}=Se.getContext(process.env.SKIMMER_PROJECT),r=Se.getIndexer(n),s=await r.indexProject();process.stderr.write(`[Frontend-Code-Skimmer] \u5B8C\u6210: ${s.indexedFiles} \u6587\u4EF6, ${s.totalSymbols} \u7B26\u53F7
|
|
686
|
+
`);let o=await r.startWatcher();Se.registerWatcher(n,o),process.stderr.write(`[Frontend-Code-Skimmer] \u6587\u4EF6\u76D1\u542C\u5DF2\u542F\u52A8: ${n}
|
|
639
687
|
`);}catch(n){process.stderr.write(`[Frontend-Code-Skimmer] \u7D22\u5F15\u5931\u8D25: ${String(n)}
|
|
640
|
-
`);}}let e=new StdioServerTransport;await
|
|
688
|
+
`);}}let e=new StdioServerTransport;await je.connect(e),process.stderr.write(`[Frontend-Code-Skimmer MCP] \u5DF2\u542F\u52A8 (v${fr})
|
|
641
689
|
`),process.stderr.write(`[Frontend-Code-Skimmer MCP] \u652F\u6301\u6846\u67B6: Vue 2 / Vue 3 / React Hooks
|
|
642
690
|
`),process.stderr.write(`[Frontend-Code-Skimmer MCP] \u652F\u6301\u7CBE\u5EA6: heuristic / precise (\u8DE8\u6587\u4EF6 import \u7ED1\u5B9A)
|
|
643
691
|
`),process.stderr.write(`[Frontend-Code-Skimmer MCP] \u652F\u6301\u6A21\u5F0F: \u52A8\u6001\u4EFB\u610F\u9879\u76EE\uFF08\u65E0\u9700\u542F\u52A8\u65F6\u6307\u5B9A\uFF09
|
|
644
692
|
`),process.env.SKIMMER_PROJECT?process.stderr.write(`[Frontend-Code-Skimmer MCP] \u9ED8\u8BA4\u9879\u76EE: ${process.env.SKIMMER_PROJECT}
|
|
645
693
|
`):process.stderr.write(`[Frontend-Code-Skimmer MCP] \u63D0\u793A: \u672A\u8BBE\u7F6E SKIMMER_PROJECT\uFF0C\u6BCF\u6B21\u8C03\u7528\u5DE5\u5177\u65F6\u8BF7\u4F20\u5165 project_path
|
|
646
|
-
`);let t=()=>{
|
|
694
|
+
`);let t=()=>{Se.closeAll(),process.exit(0);};process.on("SIGINT",t),process.on("SIGTERM",t);}Gs().catch(i=>{process.stderr.write(`[Frontend-Code-Skimmer MCP] \u542F\u52A8\u5931\u8D25: ${String(i)}
|
|
647
695
|
`),process.exit(1);});
|