@jokeran/frontend-code-skimmer 0.4.5 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +129 -128
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import*as
|
|
3
|
-
`&&e++;return e}function
|
|
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 J from'path';import J__default from'path';import {fileURLToPath}from'url';import {McpServer}from'@modelcontextprotocol/sdk/server/mcp.js';import {StdioServerTransport}from'@modelcontextprotocol/sdk/server/stdio.js';import Qr from'os';import*as Q from'fs';import Q__default from'fs';import rr,{createHash}from'crypto';import lr from'better-sqlite3';import Zr from'fast-glob';import {createRequire}from'module';import {z as z$1}from'zod';function ze(o){switch(o){case "template_event":return "template_event";case "jsx_event":return "jsx_event";case "hook_call":return "hook_call";case "import_func":return "import_call";default:return "method_call"}}function k(o){return o.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 Ge(o,e){let t=o.length,n=e.length,r=Array.from({length:t+1},(s,i)=>Array.from({length:n+1},(a,c)=>i===0?c:c===0?i:0));for(let s=1;s<=t;s++)for(let i=1;i<=n;i++)o[s-1]===e[i-1]?r[s][i]=r[s-1][i-1]:r[s][i]=1+Math.min(r[s-1][i],r[s][i-1],r[s-1][i-1]);return r[t][n]}function Me(o){return rr.createHash("md5").update(o).digest("hex")}function qe(o){if(!o)return 0;let e=1;for(let t=0;t<o.length;t++)o[t]===`
|
|
3
|
+
`&&e++;return e}function ke(o,e){return o===e?`L${o}`:`L${o}-L${e}`}function de(o,e){return J__default.relative(e,o).replace(/\\/g,"/")}function je(o,e){if(!o)return e;try{return JSON.parse(o)}catch{return e}}function K(o,e){let t=o.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(i=>i.replace(/^\s*\*\s?/,"").replace(/\/\*\*/,"").replace(/\*\//,"").trim()).filter(i=>i.length>0).join(" ")}function Zt(o,e){let t=o.toLowerCase(),n=e.toLowerCase();if(t===n)return 100;if(n.includes(t)||t.includes(n))return 85;let r=Ge(t,n),s=Math.max(t.length,n.length);if(s===0)return 100;let i=Math.max(0,100-r/s*100);return Math.round(i)}function be(o){return o.startsWith("use")&&o.length>3&&/[A-Z]/.test(o[3])}function Qt(o,e,t){if(t===0||t>3)return;let n=k(o).split(" "),r=k(e).split(" ");for(let s of n)for(let i of r){let a=Ge(s,i);if(a>0&&a<=3&&s!==i)return `"${s}" \u53EF\u80FD\u662F "${i}" \u7684\u62FC\u5199\u9519\u8BEF (\u7F16\u8F91\u8DDD\u79BB=${a})`}}var ir=[".ts",".tsx",".js",".jsx",".vue"],or=["index.ts","index.tsx","index.js","index.jsx","index.vue"];function ar(o){return [...ir.map(e=>`${o}${e}`),...or.map(e=>J.join(o,e))]}function Ne(o){if(Q.existsSync(o))try{if(Q.statSync(o).isFile())return o}catch{}for(let e of ar(o))if(Q.existsSync(e))return e;return o}var Tt=["**/node_modules/**","**/dist/**","**/build/**","**/.git/**","**/coverage/**","**/.nuxt/**","**/.next/**","**/__tests__/**","**/docs/js/**","**/public/**/*.js","**/*.test.*","**/*.spec.*","**/*.min.js"],St=["**/*.vue","**/*.js","**/*.jsx","**/*.ts","**/*.tsx"],tn={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"]}},xt=["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeDestroy","destroyed","activated","deactivated","errorCaptured"],At=["onBeforeMount","onMounted","onBeforeUpdate","onUpdated","onBeforeUnmount","onUnmounted","onActivated","onDeactivated","onErrorCaptured","onRenderTracked","onRenderTriggered","onServerPrefetch"],nn=["ref","reactive","shallowRef","shallowReactive","readonly"],rn=["computed"],sn=["watch","watchEffect","watchPostEffect","watchSyncEffect"],Lt=["useState","useReducer","useRef","useImperativeHandle"],Rt=["useMemo","useCallback"],kt=["useEffect","useLayoutEffect","useInsertionEffect"],on=["useContext","useDebugValue","useDeferredValue","useId","useSyncExternalStore","useTransition"],Je=".skimmer-index.db",an=30,cn=4,ln=300;var cr=[{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
|
|
@@ -34,11 +34,11 @@ import*as z from'path';import z__default from'path';import {fileURLToPath}from'u
|
|
|
34
34
|
file_path TEXT NOT NULL,
|
|
35
35
|
error TEXT NOT NULL,
|
|
36
36
|
last_seen_at INTEGER NOT NULL
|
|
37
|
-
)`,"CREATE INDEX IF NOT EXISTS idx_index_failures_file ON index_failures(file_path)","CREATE INDEX IF NOT EXISTS idx_index_failures_seen ON index_failures(last_seen_at DESC)"]}];function
|
|
37
|
+
)`,"CREATE INDEX IF NOT EXISTS idx_index_failures_file ON index_failures(file_path)","CREATE INDEX IF NOT EXISTS idx_index_failures_seen ON index_failures(last_seen_at DESC)"]}];function pn(o){let e=[],t=[];o.exec(`CREATE TABLE IF NOT EXISTS schema_version (
|
|
38
38
|
version INTEGER PRIMARY KEY,
|
|
39
39
|
applied_at INTEGER NOT NULL,
|
|
40
40
|
description TEXT
|
|
41
|
-
)`);let n=
|
|
41
|
+
)`);let n=o.prepare("SELECT MAX(version) as v FROM schema_version").get()?.v??0;for(let r of cr){if(r.version<=n)continue;let s=Date.now(),i=true;for(let a of r.statements)try{o.exec(a);}catch(c){let l=String(c);if(l.includes("duplicate column name"))continue;t.push(`v${r.version}: ${l.slice(0,120)}`),i=false;}o.prepare("INSERT OR REPLACE INTO schema_version (version, applied_at, description) VALUES (?, ?, ?)").run(r.version,s,i?r.description:`${r.description} (\u90E8\u5206\u8BED\u53E5\u8DF3\u8FC7)`),e.push(r.version);}return {applied:e,errors:t}}function dr(o,e){let t=J__default.posix.dirname(e),n=t==="."?[]:t.split("/").map(()=>"..");return J__default.resolve(J__default.dirname(o),...n)}function ur(o,e,t){if(!o)return o;if(J__default.isAbsolute(o)){let n=de(Ne(o),t);return n.startsWith("..")?o.replace(/\\/g,"/"):n}if(o.startsWith(".")){let n=Ne(J__default.resolve(J__default.dirname(e),o)),r=de(n,t);return r.startsWith("..")?o.replace(/\\/g,"/"):r}if(o.startsWith("@/")){let n=Ne(J__default.resolve(t,"src",o.slice(2))),r=de(n,t);return r.startsWith("..")?o.replace(/\\/g,"/"):r}return o.replace(/\\/g,"/")}var Ye=class{db;constructor(e,t){let n=t||J__default.join(e,Je);Q__default.mkdirSync(J__default.dirname(n),{recursive:true}),this.db=new lr(n),this.initialize();}initialize(){this.db.pragma("journal_mode = WAL"),this.db.pragma("foreign_keys = ON"),this.db.pragma("synchronous = NORMAL"),this.db.exec(`
|
|
42
42
|
-- \u6587\u4EF6\u5143\u4FE1\u606F
|
|
43
43
|
CREATE TABLE IF NOT EXISTS files (
|
|
44
44
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -183,7 +183,7 @@ import*as z from'path';import z__default from'path';import {fileURLToPath}from'u
|
|
|
183
183
|
CREATE INDEX IF NOT EXISTS idx_symbols_name ON symbols(name);
|
|
184
184
|
CREATE INDEX IF NOT EXISTS idx_symbols_framework ON symbols(framework);
|
|
185
185
|
CREATE INDEX IF NOT EXISTS idx_behaviors_file ON behaviors(file_id);
|
|
186
|
-
`);let{applied:e,errors:t}=
|
|
186
|
+
`);let{applied:e,errors:t}=pn(this.db);e.length>0&&process.stderr.write(`[Frontend-Code-Skimmer] \u6570\u636E\u5E93\u8FC1\u79FB\u5B8C\u6210: v${e.join(", v")}
|
|
187
187
|
`),t.length>0&&process.stderr.write(`[Frontend-Code-Skimmer] \u8FC1\u79FB\u8B66\u544A: ${t.join("; ")}
|
|
188
188
|
`),this.db.exec(`
|
|
189
189
|
CREATE INDEX IF NOT EXISTS idx_behaviors_api_lc ON behaviors(api_name_lc, operation_lc);
|
|
@@ -225,22 +225,22 @@ import*as z from'path';import z__default from'path';import {fileURLToPath}from'u
|
|
|
225
225
|
INSERT INTO relations_fts(rowid, args)
|
|
226
226
|
VALUES (new.id, new.args);
|
|
227
227
|
END;
|
|
228
|
-
`);}saveParseResult(e,t,n,r,s,
|
|
228
|
+
`);}saveParseResult(e,t,n,r,s,i,a=0,c="",l=""){let p=J__default.extname(t).slice(1),d=dr(t,n);this.db.transaction(()=>{this.clearIndexFailures(n);let g=this.db.prepare("SELECT id FROM files WHERE path = ?").get(n),f;g?(f=g.id,this.db.prepare("DELETE FROM symbols WHERE file_id = ?").run(f),this.db.prepare(`
|
|
229
229
|
UPDATE files SET
|
|
230
230
|
abs_path = ?, framework = ?, content_hash = ?,
|
|
231
231
|
last_indexed_at = ?, file_size = ?, line_count = ?, file_mtime = ?,
|
|
232
232
|
path_lc = LOWER(?),
|
|
233
233
|
export_signature_hash = ?, import_signature_hash = ?
|
|
234
234
|
WHERE id = ?
|
|
235
|
-
`).run(t,e.framework,r,Date.now(),s,
|
|
235
|
+
`).run(t,e.framework,r,Date.now(),s,i,a,n,c,l,f)):f=this.db.prepare(`
|
|
236
236
|
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)
|
|
237
237
|
VALUES (?, LOWER(?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
238
|
-
`).run(n,n,t,p,e.framework,r,Date.now(),s,
|
|
238
|
+
`).run(n,n,t,p,e.framework,r,Date.now(),s,i,a,c,l).lastInsertRowid;let m=this.db.prepare(`
|
|
239
239
|
INSERT INTO symbols (file_id, name, name_lc, category, category_lc, framework, start_line, end_line,
|
|
240
240
|
signature, params_json, default_value, camel_words, jsdoc,
|
|
241
241
|
is_async, hook_deps_json, state_setter_name, parent_component)
|
|
242
242
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
243
|
-
`),h=new Map,b=new Map,S=N=>N.internalKey||`${N.name}:${N.startLine}:${N.endLine}`,y=(N,x)=>{h.set(S(N),x);let L=b.get(N.name)||[];L.push({id:x,name:N.name,startLine:N.startLine,endLine:N.endLine}),b.set(N.name,L);},_=(N,x,L)=>{if(L&&h.has(L))return h.get(L);let w=b.get(N)||[];if(w.length===0)return;if(w.length===1||x==null)return w[0]?.id;let M=w.filter(P=>P.startLine<=x&&x<=P.endLine);return M.length===1?M[0].id:M.length>1?M.sort((P,B)=>P.endLine-P.startLine-(B.endLine-B.startLine)||Math.abs(P.startLine-x)-Math.abs(B.startLine-x))[0]?.id:w.slice().sort((P,B)=>Math.abs(P.startLine-x)-Math.abs(B.startLine-x)||P.endLine-P.startLine-(B.endLine-B.startLine))[0]?.id};for(let N of e.symbols){let L=N.camelWords||k(N.name),w=N.name.toLowerCase(),M=N.category.toLowerCase(),P=
|
|
243
|
+
`),h=new Map,b=new Map,S=N=>N.internalKey||`${N.name}:${N.startLine}:${N.endLine}`,y=(N,x)=>{h.set(S(N),x);let L=b.get(N.name)||[];L.push({id:x,name:N.name,startLine:N.startLine,endLine:N.endLine}),b.set(N.name,L);},_=(N,x,L)=>{if(L&&h.has(L))return h.get(L);let w=b.get(N)||[];if(w.length===0)return;if(w.length===1||x==null)return w[0]?.id;let M=w.filter(P=>P.startLine<=x&&x<=P.endLine);return M.length===1?M[0].id:M.length>1?M.sort((P,B)=>P.endLine-P.startLine-(B.endLine-B.startLine)||Math.abs(P.startLine-x)-Math.abs(B.startLine-x))[0]?.id:w.slice().sort((P,B)=>Math.abs(P.startLine-x)-Math.abs(B.startLine-x)||P.endLine-P.startLine-(B.endLine-B.startLine))[0]?.id};for(let N of e.symbols){let L=N.camelWords||k(N.name),w=N.name.toLowerCase(),M=N.category.toLowerCase(),P=m.run(f,N.name,w,N.category,M,N.framework,N.startLine,N.endLine,N.signature||null,N.params?JSON.stringify(N.params):null,N.defaultValue||null,L,N.jsdoc||null,N.isAsync?1:0,N.hookDeps?JSON.stringify(N.hookDeps):null,N.stateSetterName||null,N.parentComponent||null);y(N,P.lastInsertRowid);}let E=this.db.prepare(`
|
|
244
244
|
INSERT INTO relations (caller_id, callee_name, callee_name_lc, call_type, line_number, args,
|
|
245
245
|
source_kind, import_source, receiver_token, edge_kind)
|
|
246
246
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
@@ -253,7 +253,7 @@ import*as z from'path';import z__default from'path';import {fileURLToPath}from'u
|
|
|
253
253
|
`);for(let x of e.propertyWrites)N.run(x.objectName,x.objectName.toLowerCase(),x.propertyName||null,x.propertyName?.toLowerCase()||"",f,x.kind,x.sourceLayer||"unknown",x.line,x.text);}if(this.db.prepare("DELETE FROM file_dependencies WHERE from_file = ?").run(n),e.fileDependencies?.length){let N=this.db.prepare(`
|
|
254
254
|
INSERT INTO file_dependencies (from_file, to_file, dependency_kind, line_number)
|
|
255
255
|
VALUES (?, ?, ?, ?)
|
|
256
|
-
`);for(let x of e.fileDependencies)N.run(n,
|
|
256
|
+
`);for(let x of e.fileDependencies)N.run(n,ur(x.toFile,t,d),x.dependencyKind,x.line);}let A=this.db.prepare(`
|
|
257
257
|
INSERT INTO behaviors (symbol_id, file_id, category, api_name, api_name_lc, operation, operation_lc, detail, detail_lc, line_number)
|
|
258
258
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
259
259
|
`);for(let N of e.behaviors){let x=_(N.symbolName,N.line,N.symbolKey);if(x){let L=N.detail||null;A.run(x,f,N.category,N.apiName,N.apiName.toLowerCase(),N.operation,N.operation.toLowerCase(),L,L?.toLowerCase()??"",N.line);}}if(e.errors?.length){let N=this.db.prepare(`
|
|
@@ -279,18 +279,18 @@ import*as z from'path';import z__default from'path';import {fileURLToPath}from'u
|
|
|
279
279
|
SELECT s.*, f.path as file_path, f.abs_path
|
|
280
280
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
281
281
|
WHERE s.name_lc = ?
|
|
282
|
-
`,
|
|
282
|
+
`,i=[e.toLowerCase()];return t&&(s+=" AND s.category_lc = ?",i.push(t.toLowerCase())),n&&(s+=" AND s.framework = ?",i.push(n)),r&&(s+=" AND f.path_lc LIKE ?",i.push(`%${r.toLowerCase()}%`)),s+=" LIMIT 30",this.db.prepare(s).all(...i)}ftsSearch(e,t,n,r,s=20,i=true){let a=Math.max(1,Math.min(200,s)),l=e.replace(/[^\w\u4e00-\u9fa5\s]/g," ").trim().split(/\s+/).filter(p=>p.length>=2);if(l.length>0){let p=l.map(d=>`${d}*`).join(" ");try{let d=`
|
|
283
283
|
SELECT s.*, f.path as file_path, f.abs_path,
|
|
284
284
|
bm25(symbols_fts, 10.0, 1.0, 0.5, 0.5) as fts_rank
|
|
285
285
|
FROM symbols_fts
|
|
286
286
|
JOIN symbols s ON symbols_fts.rowid = s.id
|
|
287
287
|
JOIN files f ON s.file_id = f.id
|
|
288
288
|
WHERE symbols_fts MATCH ?
|
|
289
|
-
`,u=[p];return t&&(d+=" AND s.category_lc = ?",u.push(t.toLowerCase())),n&&(d+=" AND s.framework = ?",u.push(n)),r&&(d+=" AND f.path_lc LIKE ?",u.push(`%${r.toLowerCase()}%`)),d+=` ORDER BY fts_rank LIMIT ${a}`,this.db.prepare(d).all(...u)}catch{if(
|
|
289
|
+
`,u=[p];return t&&(d+=" AND s.category_lc = ?",u.push(t.toLowerCase())),n&&(d+=" AND s.framework = ?",u.push(n)),r&&(d+=" AND f.path_lc LIKE ?",u.push(`%${r.toLowerCase()}%`)),d+=` ORDER BY fts_rank LIMIT ${a}`,this.db.prepare(d).all(...u)}catch{if(i)return []}}return i?[]: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 i=e.toLowerCase().replace(/[\\%_]/g,"\\$&"),a=`
|
|
290
290
|
SELECT s.*, f.path as file_path, f.abs_path, 0 as fts_rank
|
|
291
291
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
292
292
|
WHERE (s.name_lc LIKE ? OR LOWER(s.camel_words) LIKE ?) ESCAPE '\\'
|
|
293
|
-
`,c=[`%${
|
|
293
|
+
`,c=[`%${i}%`,`%${i}%`];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=`
|
|
294
294
|
SELECT DISTINCT s.name, f.path as file_path, s.id
|
|
295
295
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
296
296
|
`,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(`
|
|
@@ -337,14 +337,14 @@ import*as z from'path';import z__default from'path';import {fileURLToPath}from'u
|
|
|
337
337
|
s.parent_component IS NULL DESC,
|
|
338
338
|
f.line_count DESC
|
|
339
339
|
LIMIT 1
|
|
340
|
-
`).get(e.toLowerCase())}behaviorSearch(e,t,n,r,s){let
|
|
340
|
+
`).get(e.toLowerCase())}behaviorSearch(e,t,n,r,s){let i=`
|
|
341
341
|
SELECT b.*, s.name as symbol_name, s.start_line, s.end_line, s.category as symbol_category,
|
|
342
342
|
f.path as file_path
|
|
343
343
|
FROM behaviors b
|
|
344
344
|
JOIN symbols s ON b.symbol_id = s.id
|
|
345
345
|
JOIN files f ON b.file_id = f.id
|
|
346
346
|
WHERE 1=1
|
|
347
|
-
`,a=[];return e&&(
|
|
347
|
+
`,a=[];return e&&(i+=" AND b.category = ?",a.push(e)),t&&(i+=" AND b.api_name_lc = ?",a.push(t.toLowerCase())),n&&(i+=" AND b.operation_lc = ?",a.push(n.toLowerCase())),r&&(i+=" AND (b.detail_lc LIKE ? OR b.api_name_lc LIKE ?)",a.push(`%${r.toLowerCase()}%`,`%${r.toLowerCase()}%`)),s&&(i+=" AND f.path_lc LIKE ?",a.push(`%${s.toLowerCase()}%`)),i+=" ORDER BY f.path, b.line_number LIMIT 50",this.db.prepare(i).all(...a)}getCallers(e,t,n){let r=`
|
|
348
348
|
SELECT r.*, s.name as caller_name, s.start_line, s.end_line, s.category,
|
|
349
349
|
f.path as file_path
|
|
350
350
|
FROM relations r
|
|
@@ -363,14 +363,14 @@ import*as z from'path';import z__default from'path';import {fileURLToPath}from'u
|
|
|
363
363
|
JOIN symbols s ON r.caller_id = s.id
|
|
364
364
|
JOIN files f ON s.file_id = f.id
|
|
365
365
|
WHERE fts.args MATCH ?
|
|
366
|
-
`,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,p=false;try{c=this.db.prepare(s).all(...a),c.length>0&&(l=!0);}catch{p=true;}let d=/[^a-zA-Z0-9_\u4e00-\u9fa5]/.test(r);if(!l&&(p||d)){let
|
|
366
|
+
`,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,p=false;try{c=this.db.prepare(s).all(...a),c.length>0&&(l=!0);}catch{p=true;}let d=/[^a-zA-Z0-9_\u4e00-\u9fa5]/.test(r);if(!l&&(p||d)){let g=r.replace(/[\\%_]/g,"\\$&"),f=`
|
|
367
367
|
SELECT r.*, s.name as caller_name, s.start_line, s.end_line, s.category,
|
|
368
368
|
f.path as file_path
|
|
369
369
|
FROM relations r
|
|
370
370
|
JOIN symbols s ON r.caller_id = s.id
|
|
371
371
|
JOIN files f ON s.file_id = f.id
|
|
372
372
|
WHERE LOWER(COALESCE(r.args, '')) LIKE LOWER(?) ESCAPE '\\'
|
|
373
|
-
`,
|
|
373
|
+
`,m=[`%${g}%`];t&&(f+=" AND f.path_lc LIKE ?",m.push(`%${t.toLowerCase()}%`)),f+=" ORDER BY f.path, r.line_number LIMIT ?",m.push(n),c=this.db.prepare(f).all(...m);}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,i=this.db.prepare(`
|
|
374
374
|
SELECT framework, COUNT(*) as count FROM files GROUP BY framework
|
|
375
375
|
`).all(),a=this.db.prepare(`
|
|
376
376
|
SELECT f.path, f.line_count, COUNT(s.id) as symbol_count
|
|
@@ -379,7 +379,7 @@ import*as z from'path';import z__default from'path';import {fileURLToPath}from'u
|
|
|
379
379
|
ORDER BY f.line_count DESC LIMIT 10
|
|
380
380
|
`).all(),c=this.db.prepare(`
|
|
381
381
|
SELECT category, COUNT(*) as count FROM behaviors GROUP BY category ORDER BY count DESC
|
|
382
|
-
`).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:
|
|
382
|
+
`).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:i,topFiles:a,behaviorStats:c,dbSize:l}}getIndexFailures(e=20){return this.db.prepare(`
|
|
383
383
|
SELECT file_path, error, last_seen_at
|
|
384
384
|
FROM index_failures
|
|
385
385
|
ORDER BY last_seen_at DESC, id DESC
|
|
@@ -399,51 +399,52 @@ import*as z from'path';import z__default from'path';import {fileURLToPath}from'u
|
|
|
399
399
|
SELECT pw.*, f.path as file_path
|
|
400
400
|
FROM property_writes pw JOIN files f ON pw.file_id = f.id
|
|
401
401
|
WHERE pw.object_name_lc = ?
|
|
402
|
-
`,
|
|
402
|
+
`,i=[e.toLowerCase()];return t&&(s+=" AND pw.property_name_lc = ?",i.push(t.toLowerCase())),n&&(s+=" AND f.path_lc LIKE ?",i.push(`%${n.toLowerCase()}%`)),s+=" ORDER BY f.path, pw.line_number LIMIT ?",i.push(r),this.db.prepare(s).all(...i)}getCallersWithSourceKind(e,t,n){let r=`
|
|
403
403
|
SELECT r.*, s.name as caller_name, s.start_line, s.end_line, s.category,
|
|
404
404
|
f.path as file_path
|
|
405
405
|
FROM relations r
|
|
406
406
|
JOIN symbols s ON r.caller_id = s.id
|
|
407
407
|
JOIN files f ON s.file_id = f.id
|
|
408
408
|
WHERE r.callee_name_lc = ?
|
|
409
|
-
`,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
|
|
410
|
-
`);for(let s=0;s<r.length;s++){let
|
|
411
|
-
`));}function
|
|
412
|
-
`),l;try{l=
|
|
413
|
-
`).length;n.symbols.push({name:"<template>",category:"lifecycle",framework:"vue2",startLine:p,endLine:p+u-1,camelWords:"template"});for(let
|
|
414
|
-
`&&n++;return n}extractFromAST(e,t,n,r,s){let
|
|
415
|
-
`);s.fileDependencies=fe(e.body||[],s.filePath);let a=null;
|
|
416
|
-
`),
|
|
417
|
-
`),p),
|
|
418
|
-
`),p);if(c.type==="ClassMethod"){let f=
|
|
419
|
-
`),a=!!s.scriptSetup,c=!!s.script;if(a){let l=s.scriptSetup,p=l.loc.start.line;this.parseSetupContent(l.content,p,
|
|
420
|
-
`).length;n.symbols.push({name:"<template>",category:"lifecycle",framework:"vue3",startLine:l,endLine:l+d-1,camelWords:"template"});for(let u of p)n.relations.push(
|
|
421
|
-
`),c=s.program.body;r.fileDependencies=fe(c,r.filePath);for(let l of c||[])this.processTopLevelStatement(l,
|
|
422
|
-
`);r.fileDependencies=fe(s.program.body||[],r.filePath);let c=false;return
|
|
423
|
-
`),t(p)),
|
|
424
|
-
`),t(c)),d=this.extractParams(e),u=
|
|
425
|
-
`),c);if(
|
|
426
|
-
`);this.extractFromAST(s.program?s.program:s,
|
|
427
|
-
`),l),camelWords:k(
|
|
428
|
-
`),a),u=this.extractParams(e),
|
|
429
|
-
`),a),p=this.extractParams(e);if(r.symbols.push({name:
|
|
430
|
-
`),u),
|
|
431
|
-
`),c=(
|
|
432
|
-
`),
|
|
433
|
-
`),a),camelWords:k(o)});let l=e.body?.body;for(let p of l||[]){let d=p.key,u=d?.type==="Identifier"?String(d.name||""):"";if(!u||u==="constructor")continue;if(p.type==="ClassMethod"||p.type==="ClassPrivateMethod"){this.addFunctionSymbol(u,p,t,n,r,{startLine:this.getLineRange(p).start,endLine:this.getLineRange(p).end,isExported:false,ownerClass:o});continue}let m=p.value;m&&(m.type==="ArrowFunctionExpression"||m.type==="FunctionExpression")&&(p.type==="ClassProperty"||p.type==="PropertyDefinition")&&this.addFunctionSymbol(u,m,t,n,r,{startLine:this.getLineRange(p).start,endLine:this.getLineRange(p).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}}};function Z(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 ie(i){let e=i.object;return e?e.type==="Identifier"?String(e.name||""):e.type==="ThisExpression"?Z(i):e.type==="MemberExpression"?e.object?.type==="ThisExpression"?Z(e):ie(e):null:null}function te(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"}var Cr=new Set(["FunctionDeclaration","ArrowFunctionExpression","FunctionExpression","ObjectMethod","ClassMethod","ClassProperty"]);function mn(i,e){return !!e?.skipNestedFunctions&&Cr.has(String(i.type||""))}function me(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;mn(o,t)||me(o,e,t);}continue}if(r&&typeof r=="object"&&r.type){let s=r;if(mn(s,t))continue;me(s,e,t);}}}}function gn(i,e,t=true,n){let r=[],s=[],o=(a,c=120)=>Ir(a,n,c);return me(i,a=>{if(a.type==="VariableDeclarator"){let c=a.id;if(!c)return;let l=at(c),p=o(a);for(let d of l)r.push({symbolName:d,kind:"declaration",line:ve(a),text:p,sourceLayer:te(p,ve(a))});}if(a.type==="AssignmentExpression"){let c=a.left;if(!c)return;let l=o(a),p=ve(a);if(c.type==="Identifier"&&r.push({symbolName:c.name,kind:"assignment",line:p,text:l,sourceLayer:te(l,p)}),c.type==="MemberExpression"&&c.object?.type==="ThisExpression"){let u=Z(c);if(u){r.push({symbolName:u,kind:"assignment",line:p,text:l,sourceLayer:te(l,p)});return}}if(c.type==="MemberExpression"){let d=ie(c);if(d&&Ct(d)){let u=Z(c);s.push({objectName:d,propertyName:u||void 0,line:p,text:l,kind:c.computed?"bracket":"dot",sourceLayer:te(l,p)});}}}if(a.type==="UpdateExpression"){let c=a.argument;if(!c)return;let l=o(a),p=ve(a);if(c.type==="Identifier"&&r.push({symbolName:c.name,kind:"update",line:p,text:l,sourceLayer:te(l,p)}),c.type==="MemberExpression"&&c.object?.type==="ThisExpression"){let u=Z(c);if(u){r.push({symbolName:u,kind:"update",line:p,text:l,sourceLayer:te(l,p)});return}}if(c.type==="MemberExpression"){let d=ie(c);if(d&&Ct(d)){let u=Z(c);s.push({objectName:d,propertyName:u||void 0,line:p,text:l,kind:c.computed?"bracket":"dot",sourceLayer:te(l,p)});}}}if(a.type==="UnaryExpression"&&a.operator==="delete"){let c=a.argument;if(c?.type==="MemberExpression"){let l=ie(c);if(l&&Ct(l)){let p=Z(c);s.push({objectName:l,propertyName:p||void 0,line:ve(a),text:o(a),kind:"delete",sourceLayer:te(o(a),ve(a))});}}}},{skipNestedFunctions:t}),{assignments:r,propertyWrites:s}}function at(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?at(n):[]}):i.type==="ArrayPattern"?(i.elements||[]).flatMap(t=>t?at(t):[]):i.type==="AssignmentPattern"?at(i.left):[]}function Ct(i){return !(/^[A-Z][A-Z]/.test(i)||/^(document|window|console|localStorage|sessionStorage|navigator|process|global|globalThis)$/.test(i))}function ve(i){return i.loc?.start?.line??1}function Ir(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 Pr=createRequire(import.meta.url);function $t(i,e){let t={files:new Map,resolutionCache:new Map,localShadowCache:new Map};for(let{path:n,content:r}of i){let s=un(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,Or(r));}return t}function Pt(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 Or(i){let e=new Map;try{let n=Pr("@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)yn(s,e);}catch{return e}return e}function yn(i,e){if(i.type==="FunctionDeclaration"){let t=Se(i.id);if(!t)return;Ce(t,i,e),Fr(jr(i),t,e);return}if(i.type==="VariableDeclaration"){bn(i,void 0,e);return}if(i.type==="ClassDeclaration"){Dr(i,e);return}if(i.type==="ExportNamedDeclaration"||i.type==="ExportDefaultDeclaration"){let t=i.declaration;if(!t)return;yn(t,e);}}function Fr(i,e,t){for(let n of i){if(n.type==="FunctionDeclaration"){let r=Se(n.id);if(!r)continue;Ce(r,n,t,e);continue}if(n.type==="VariableDeclaration"){bn(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;Ce(o,a,t,e,n);}}}function bn(i,e,t){for(let n of i.declarations||[]){let r=Se(n.id),s=n.init;!r||!s||s.type!=="ArrowFunctionExpression"&&s.type!=="FunctionExpression"||Ce(r,s,t,e,n);}}function Dr(i,e){let t=Se(i.id);if(!t)return;let n=i.body?.body||[];for(let r of n){let s=Se(r.key);if(!s||s==="constructor")continue;if(r.type==="ClassMethod"||r.type==="ClassPrivateMethod"){Ce(s,r,e,t);continue}let o=r.value;o&&(o.type==="ArrowFunctionExpression"||o.type==="FunctionExpression")&&(r.type==="ClassProperty"||r.type==="PropertyDefinition")&&Ce(s,o,e,t,r);}}function Ce(i,e,t,n,r){let s=Ur(r||e),o=Wr(i,s.start,s.end,n),a=Mr(e);t.set(o,a);}function Mr(i){let e=new Set;for(let n of i.params||[])for(let r of Te(n))e.add(r);let t=i.body;return t&&It(t,n=>{if(n.type==="VariableDeclarator"){for(let r of Te(n.id))e.add(r);return}if(n.type==="FunctionDeclaration"){let r=Se(n.id);return r&&e.add(r),false}if(n.type==="ClassDeclaration"){let r=Se(n.id);return r&&e.add(r),false}}),e}function It(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;hn(s)||It(s,e);}continue}if(n&&typeof n=="object"&&n.type){let r=n;if(hn(r))continue;It(r,e);}}}function hn(i){return ["FunctionDeclaration","FunctionExpression","ArrowFunctionExpression","ClassMethod","ClassPrivateMethod","ObjectMethod"].includes(String(i.type||""))}function Te(i){return i?i.type==="Identifier"?[String(i.name||"")]:i.type==="AssignmentPattern"?Te(i.left):i.type==="RestElement"?Te(i.argument):i.type==="ArrayPattern"?(i.elements||[]).flatMap(e=>Te(e)):i.type==="ObjectPattern"?(i.properties||[]).flatMap(e=>{if(e.type==="RestElement")return Te(e.argument);let t=e.value||e.argument;return Te(t)}):[]:[]}function Se(i){if(i&&i.type==="Identifier")return String(i.name||"")}function jr(i){let e=i.body;return !e||e.type!=="BlockStatement"?[]:e.body||[]}function Ur(i){let e=i.loc;return {start:e?.start?.line??1,end:e?.end?.line??1}}function Wr(i,e,t,n){return n?`${n}:${i}:${e}:${t}`:`root:${i}:${e}:${t}`}var En=createRequire(import.meta.url);function _n(i,e){let t=i.errors||[];t.includes(e)||(i.errors=[...t,e]);}var Ot=class extends We{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}},Br=[new it,new we,new We,new ot,new Ot];function He(i,e){for(let t of Br)if(t.canParse(i,e)){let n=t.parse(i,e);return Kr(n),Xr(n,e),n}return {framework:"js",filePath:i,symbols:[],relations:[],behaviors:[],errors:[`\u6CA1\u6709\u627E\u5230\u9002\u5408\u7684\u89E3\u6790\u5668: ${i}`]}}function Xr(i,e){if(i.symbols.length!==0)try{let t=e,n=i.filePath.endsWith(".vue"),r=0;if(n)try{let{parse:u}=En("@vue/compiler-sfc"),{descriptor:m}=u(e);if(m.scriptSetup?.content)t=m.scriptSetup.content,r=m.scriptSetup.loc.start.line-1;else if(m.script?.content)t=m.script.content,r=m.script.loc.start.line-1;else return}catch(u){_n(i,`\u751F\u547D\u5468\u671F\u63D0\u53D6\u8DF3\u8FC7: Vue SFC \u89E3\u6790\u5931\u8D25 - ${String(u)}`);return}let a=En("@babel/parser").parse(t,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy"],errorRecovery:!0}).program.body;if(!a?.length)return;let c=t.split(`
|
|
434
|
-
`),
|
|
435
|
-
`)
|
|
436
|
-
`)):""
|
|
437
|
-
`);
|
|
438
|
-
`);for(let
|
|
439
|
-
`);
|
|
440
|
-
`);}let
|
|
441
|
-
`)
|
|
442
|
-
`);}catch(
|
|
409
|
+
`,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 q(o){let e=o.property;return e?e.type==="Identifier"?String(e.name||""):e.type==="Literal"||e.type==="StringLiteral"?String(e.value||""):null:null}function te(o){let e=o.object;return e?e.type==="Identifier"?String(e.name||""):e.type==="ThisExpression"?q(o):e.type==="MemberExpression"?e.object?.type==="ThisExpression"?q(e):te(e):null:null}function ne(o,e){let t=o||"";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 z(o,e,t,n=false){let r=[];return V(o,i=>{if(n&&i!==o&&(i.type==="FunctionDeclaration"||i.type==="ArrowFunctionExpression"||i.type==="FunctionExpression"||i.type==="ClassDeclaration"))return false;if(i.type==="CallExpression"||i.type==="OptionalCallExpression"){let c=fr(i,e);c&&r.push(c);}if(i.type==="MemberExpression"){let a=mr(i);a&&r.push(a);}}),Nr(r)}function fr(o,e,t){let n=o.callee;if(!n)return null;let r=et(o);if(n.type==="MemberExpression"||n.type==="OptionalMemberExpression"){let s=gr(n);if(!s)return null;let{apiName:i,operation:a}=s,c=o.arguments,l=re(c?.[0]),p=Er(i);return p?{symbolName:e,category:p,apiName:i,operation:a,detail:l,line:r}:i==="this"&&Ze(a)?{symbolName:e,category:"network",apiName:`this.${a}`,operation:"wrapped_call",detail:l||re(c?.[1]),line:r}:dn(a)&&_r(c)?{symbolName:e,category:"network",apiName:i,operation:a,detail:l||re(c?.[1]),line:r}:Ze(i)||Ze(`${i}.${a}`)?{symbolName:e,category:"network",apiName:i,operation:dn(a)?a:"wrapped_call",detail:l||re(c?.[1]),line:r}:null}if(n.type==="Identifier"){let s=n.name,i=hr(s),a=o.arguments,c=re(a?.[0]);return i?{symbolName:e,category:i.category,apiName:s,operation:i.operation,detail:c,line:r}:Ze(s)?{symbolName:e,category:"network",apiName:s,operation:"wrapped_call",detail:c||re(a?.[1]),line:r}:null}return null}function mr(o,e,t){let n=o.object,r=o.property;if(!n||!r||n.type!=="MemberExpression"&&n.type!=="ThisExpression"&&n.type!=="Identifier")return null;let s=br(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 gr(o){let e=o.object,t=o.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 hr(o){let e={fetch:"network",setTimeout:"timer",setInterval:"timer",clearTimeout:"timer",clearInterval:"timer",requestAnimationFrame:"timer",navigate:"router"};return e[o]?{category:e[o],operation:o}:null}function et(o){return o.loc?.start?.line??0}function yr(o){let e=o.loc;return {line:e?.start?.line??0,column:e?.start?.column??0}}function br(o){return o.type==="Identifier"?o.name:o.type==="ThisExpression"?"this":null}function Er(o){if(o==="this")return null;for(let[e,t]of Object.entries(tn))if(o in t)return e;return null}function re(o,e){if(o){if(o.type==="Literal"||o.type==="StringLiteral"||o.type==="NumericLiteral"||o.type==="BooleanLiteral")return String(o.value);if(o.type==="NullLiteral")return "null";if(o.type==="TemplateLiteral"){let t=o.quasis,n=o.expressions||[],r=[];for(let i=0;i<t.length;i++){let a=t[i].value?.cooked||"";if(a&&r.push(a),i<n.length){let c=Qe(n[i])||"expr";r.push(`\${${c}}`);}}return r.join("")||"${expr}"}if(o.type==="Identifier")return `[\u53D8\u91CF: ${o.name}]`;if(o.type==="ObjectExpression"){let t=o.properties||[],n=["url","uri","path","api","endpoint"];for(let r of t){let s=r.key,i=r.value;if(!s||!i)continue;let a=s.type==="Identifier"?String(s.name):s.type==="Literal"?String(s.value):"";if(!n.includes(a))continue;let c=re(i);if(c)return `${a}:${c}`}return "{...}"}}}function Qe(o,e){if(!o)return;if(o.type==="Identifier")return o.name;if(o.type==="ThisExpression")return "this";if(o.type==="Literal"||o.type==="StringLiteral"||o.type==="NumericLiteral"||o.type==="BooleanLiteral")return String(o.value);if(o.type==="NullLiteral")return "null";if(o.type==="MemberExpression"){let n=Qe(o.object)||"obj",r=o.property,s=r?.type==="Identifier"?String(r.name):Qe(r)||"prop";return o.computed?`${n}[${s}]`:`${n}.${s}`}if(o.type==="CallExpression")return `${Qe(o.callee)||"fn"}(...)`;if(o.type==="TemplateLiteral")return re(o);let t=re(o);return t?.startsWith("[\u53D8\u91CF: ")?t.replace(/^\[变量: /,"").replace(/\]$/,""):t}function Ze(o){return /request|api|http|fetch|ajax|akscommonhandle|commonhandle/i.test(o)}function dn(o){return ["get","post","put","delete","patch","request"].includes(o.toLowerCase())}function _r(o,e){if(!o||o.length===0)return false;for(let t of o.slice(0,2)){let n=re(t);if(n&&(/https?:\/\//i.test(n)||n.includes("/")||/gw\d?\/|\/m\/|\/api\//i.test(n)))return true}return false}function Nr(o){let e=new Set;return o.filter(t=>{let n=`${t.apiName}:${t.operation}:${t.line}`;return e.has(n)?false:(e.add(n),true)})}function Te(o,e,t){let n=[];return V(o,r=>{if(r.type==="CallExpression"&&r.callee?.type==="MemberExpression"){let s=r.callee,i=s.object,a=s.property;if(i.type==="ThisExpression"&&a.type==="Identifier"){let c=a.name;if(!c.startsWith("$")&&c!==e){let l=r.arguments,p=vt(l);n.push({calleeName:c,line:et(r),args:p});}}}}),n}function G(o,e,t,n=false){let r=[];return V(o,i=>{if(n&&i!==o&&(i.type==="FunctionDeclaration"||i.type==="ArrowFunctionExpression"||i.type==="FunctionExpression"||i.type==="ClassDeclaration"))return false;if(i.type==="CallExpression"&&i.callee?.type==="Identifier"){let a=i.callee.name;if(a!==e&&!fn(a)){let c=i.arguments,l=vt(c);r.push({calleeName:a,line:et(i),args:l});}}}),wt(r)}function un(o,e,t){let n=[];return V(o,s=>{if(s!==o&&(s.type==="FunctionDeclaration"||s.type==="ArrowFunctionExpression"||s.type==="FunctionExpression"||s.type==="ClassDeclaration"))return false;if(s.type!=="CallExpression"&&s.type!=="OptionalCallExpression")return;let i=s.arguments||[];for(let a of i)a.type!=="ArrowFunctionExpression"&&a.type!=="FunctionExpression"||(n.push(...G(a,e,t,true)),n.push(...Te(a,e)),n.push(...tt(a,e,t,true)));}),wt(n)}function tt(o,e,t,n=false){let r=[];return V(o,i=>{if(n&&i!==o&&(i.type==="FunctionDeclaration"||i.type==="ArrowFunctionExpression"||i.type==="FunctionExpression"||i.type==="ClassDeclaration"))return false;if(i.type!=="CallExpression"&&i.type!=="OptionalCallExpression")return;let a=i.callee;if(!a||a.type!=="MemberExpression"&&a.type!=="OptionalMemberExpression")return;let c=a.object;if(!c||c.type==="ThisExpression")return;let l=te(a),p=q(a);if(!l||!p||p===e||Tr(l)||fn(p))return;let d=i.arguments,u=vt(d);r.push({calleeName:p,line:et(i),args:u,receiverToken:l});}),wt(r)}function fn(o){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)$/.test(o)}function Tr(o){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(o)}function wt(o){let e=new Set;return o.filter(t=>{let n=`${t.receiverToken||""}:${t.calleeName}:${t.line}:${t.args||""}`;return e.has(n)?false:(e.add(n),true)})}function vt(o,e){if(!o||o.length===0)return;let t=o.slice(0,3).map(n=>re(n)).filter(n=>!!n);return t.length>0?t.join(", "):void 0}function V(o,e){if(!(!o||typeof o!="object")&&e(o)!==false)for(let t of Object.keys(o)){if(t==="type"||t==="loc"||t==="start"||t==="end")continue;let n=o[t];if(Array.isArray(n))for(let r of n)r&&typeof r=="object"&&r.type&&V(r,e);else n&&typeof n=="object"&&n.type&&V(n,e);}}function nt(o,e){let t=[],n=new Set,r=o.split(`
|
|
410
|
+
`);for(let s=0;s<r.length;s++){let i=/(?:@|v-on:)[a-z][a-z0-9-]*(?:\.[a-z-]+)*="([^"]+)"/g,a;for(;(a=i.exec(r[s]))!==null;){let l=a[1].trim().match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(?:\([^)]*\))?$/);if(!l)continue;let p=l[1];if(p.startsWith("$"))continue;let d=e+s,u=`${p}:${d}:${a.index}`;n.has(u)||(n.add(u),t.push({calleeName:p,line:d}));}}return t}function mn(o,e){let t=[],n=new Set;return V(o,r=>{if(r.type!=="JSXAttribute")return;let s=r.name,i=r.value;if(!s||!i)return;let a=s.type==="JSXIdentifier"?String(s.name):"";if(!/^on[A-Z]/.test(a)||i.type!=="JSXExpressionContainer")return;let c=i.expression;if(!c)return;let l;if(c.type==="Identifier")l=c.name;else if(c.type==="MemberExpression"){let g=c.property?.name;g&&!/^\$/.test(g)&&(l=g);}let{line:p,column:d}=yr(r),u=`${l}:${p}:${d}`;!l||n.has(u)||(n.add(u),t.push({calleeName:l,line:p}));}),t}var xr=createRequire(import.meta.url),gn=false;function Ar(o){gn||(gn=true,process.stderr.write(`[Frontend-Code-Skimmer] precise import graph \u5DF2\u964D\u7EA7: ${String(o)}
|
|
411
|
+
`));}function hn(o,e,t){let n={filePath:o,imports:[],exports:[]};try{let r=xr("typescript"),s=r.createSourceFile(o,e,r.ScriptTarget.Latest,!0);r.forEachChild(s,i=>{if(r.isImportDeclaration(i)){let a=i.moduleSpecifier;if(!a||!r.isStringLiteral(a))return;let c=a.text,l=st(o,c),p=i.importClause;if(!p){n.imports.push({localName:"",originalName:"",modulePath:c,resolvedFile:l,isDefault:!1,isReExport:!1});return}let d=p.namedBindings;if(d&&r.isNamedImports(d))for(let u of d.elements){let g=u.propertyName?u.propertyName.text:u.name.text;n.imports.push({localName:u.name.text,originalName:g,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}),p.name&&n.imports.push({localName:p.name.text,originalName:"default",modulePath:c,resolvedFile:l,isDefault:!0,isReExport:!1});}if(r.isExportDeclaration(i)){let a=i.moduleSpecifier;if(a&&r.isStringLiteral(a)){let c=a.text,l=i.exportClause;if(l&&r.isNamedExports(l))for(let p of l.elements)n.exports.push({name:p.name.text,isDefault:!1,source:"re_export",reExportFrom:c});}else if(i.exportClause){let c=i.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(i)&&(i.isExportEquals||n.exports.push({name:"default",isDefault:!0,source:"local"})),(r.isFunctionDeclaration(i)||r.isVariableStatement(i)||r.isClassDeclaration(i))&&i.modifiers?.some(a=>a.kind===r.SyntaxKind.ExportKeyword)){if(r.isFunctionDeclaration(i)&&i.name)n.exports.push({name:i.name.text,isDefault:i.name.text==="default",source:"local"});else if(r.isClassDeclaration(i)&&i.name)n.exports.push({name:i.name.text,isDefault:i.name.text==="default",source:"local"});else if(r.isVariableStatement(i))for(let a of i.declarationList.declarations)r.isIdentifier(a.name)&&n.exports.push({name:a.name.text,isDefault:!1,source:"local"});}});}catch(r){Ar(r);}return n}function st(o,e){let t=J.dirname(o);if(e.startsWith(".")){let n=J.resolve(t,e);return Ne(n)}return e.startsWith("@/")?Lr(o,e):e}function Lr(o,e){let t=J.dirname(o);for(let n=0;n<10;n++){let r=J.join(t,"src");if(Q.existsSync(r)&&Q.statSync(r).isDirectory()){let i=J.join(r,e.replace(/^@\//,""));return Ne(i)}let s=J.dirname(t);if(s===t)break;t=s;}return e}function U(o){return {callerName:o.callerName,callerLine:o.callerLine,callerKey:o.callerKey,calleeName:o.calleeName,callType:o.callType,line:o.line,args:o.args,sourceKind:ze(o.callType),importSource:o.importSource,receiverToken:o.receiverToken,edgeKind:o.edgeKind||"heuristic"}}function fe(o,e){let t=[];for(let n of o){let r=n.type;if(r==="ImportDeclaration"){let s=n.source,i=n.loc;s?.value&&t.push({fromFile:e,toFile:st(e,s.value),dependencyKind:"import",line:i?.start?.line??1});}if(r==="ExportNamedDeclaration"||r==="ExportAllDeclaration"){let s=n.source,i=n.loc;s?.value&&t.push({fromFile:e,toFile:st(e,s.value),dependencyKind:"re_export",line:i?.start?.line??1});}}return t}function ot(o,e){let t=new Map(e.map(r=>[r.name,r])),n=[];for(let r of o){let s=r.type;if(s==="ExportNamedDeclaration"){let i=r.declaration,a=r.source;if(i){if(i.type==="FunctionDeclaration"||i.type==="ClassDeclaration"){let c=i.id;c?.name&&n.push(it(c.name,t.get(c.name)));}else if(i.type==="VariableDeclaration")for(let c of i.declarations||[]){let l=c.id;l?.type==="Identifier"&&l.name&&n.push(it(l.name,t.get(l.name)));}continue}for(let c of r.specifiers||[]){let l=Ct(c.local),p=Ct(c.exported)||l;p&&(a?.value?n.push(`re_export:${p}:${a.value}`):n.push(it(p,l?t.get(l):void 0)));}continue}if(s==="ExportAllDeclaration"){let i=r.source;i?.value&&n.push(`re_export_all:${i.value}`);continue}if(s==="ExportDefaultDeclaration"){let i=r.declaration;if(!i){n.push("default:unknown");continue}if(i.type==="Identifier"){let a=Ct(i);n.push(it("default",a?t.get(a):void 0));continue}if(i.type==="FunctionDeclaration"||i.type==="FunctionExpression"||i.type==="ArrowFunctionExpression"){let a=(i.params||[]).map(c=>$t(c)).join(", ");n.push(`default:fn(${a})`);continue}if(i.type==="ClassDeclaration"||i.type==="ClassExpression"){n.push("default:class");continue}n.push(`default:${String(i.type||"unknown")}`);}}return n.sort()}function it(o,e){return `${o}:${Rr(e)}`}function Rr(o){return o?o.category==="class"?"class":o.signature?`fn${o.signature.replace(/^[^(]*/,"")}`:o.category==="constant"?`const:${o.defaultValue||""}`:o.category:"unknown"}function Ct(o){if(o){if(o.type==="Identifier")return String(o.name||"");if(o.type==="StringLiteral")return String(o.value||"")}}function $t(o){return o?o.type==="Identifier"?String(o.name||"param"):o.type==="AssignmentPattern"?$t(o.left):o.type==="RestElement"?$t(o.argument):"param":"param"}var yn=createRequire(import.meta.url);var we=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=yn("vue-template-compiler").parseComponent(t);if(!s.script?.content)return n;let i=s.script.content,a=this.getScriptStartLine(t,s.script.start),c=t.split(`
|
|
412
|
+
`),l;try{l=yn("@babel/parser").parse(i,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy"],errorRecovery:!0});}catch(p){return n.errors?.push(`AST \u89E3\u6790\u5931\u8D25: ${String(p)}`),n}if(this.extractFromAST(l.program,i,c,a,n),s.template?.content){let p=this.getScriptStartLine(t,s.template.start),d=nt(s.template.content,p);if(d.length>0){let u=s.template.content.split(`
|
|
413
|
+
`).length;n.symbols.push({name:"<template>",category:"lifecycle",framework:"vue2",startLine:p,endLine:p+u-1,camelWords:"template"});for(let g of d)n.relations.push(U({callerName:"<template>",callerLine:p,calleeName:g.calleeName,callType:"template_event",line:g.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]===`
|
|
414
|
+
`&&n++;return n}extractFromAST(e,t,n,r,s){let i=t.split(`
|
|
415
|
+
`);s.fileDependencies=fe(e.body||[],s.filePath);let a=null;V(e,d=>{if(d.type==="ExportDefaultDeclaration"){let u=d.declaration;if(u?.type==="ObjectExpression")a=u;else if(u?.type==="CallExpression"){let g=u.arguments;g&&g.length>0&&g[0].type==="ObjectExpression"&&(a=g[0]);}else if(u?.type==="Identifier"){let g=u.name;V(e,f=>{if(f.type==="VariableDeclarator"&&f.id?.name===g){if(f.init?.type==="ObjectExpression")a=f.init;else if(f.init?.type==="CallExpression"){let m=f.init.arguments;m&&m.length>0&&m[0].type==="ObjectExpression"&&(a=m[0]);}}});}}});let l=false;if(!a&&(V(e,d=>{d.type==="ExportDefaultDeclaration"&&d.declaration?.type==="ClassDeclaration"&&(l=true,this.extractFromClassComponent(d.declaration,t,n,r,s));}),!l)){let d=null,u=0,g=["data","methods","computed","props","watch","components","created","mounted","mixins"];V(e,f=>{if(f.type==="ObjectExpression"){let m=f.properties||[],h=0;for(let b of m){let S=this.getPropKey(b);S&&g.includes(S)&&h++;}h>u&&(u=h,d=f);}}),u>=2&&d&&(a=d);}if(!a)return;let p=a.properties;for(let d of p||[]){let u=this.getPropKey(d);if(!u)continue;let g=d.type==="ObjectMethod"?d:d.value;if(!g)continue;let f=m=>m+r-1;switch(u){case "name":g?.type==="Literal"&&(String(g.value));break;case "data":this.extractData(g,i,f,s);break;case "props":this.extractProps(g,i,f,s);break;case "computed":this.extractComputedOrMethods(g,"computed",i,f,n,s);break;case "methods":this.extractComputedOrMethods(g,"method",i,f,n,s);break;case "watch":this.extractWatch(g,i,f,s);break;case "filters":this.extractComputedOrMethods(g,"filter",i,f,n,s);break;case "components":this.extractComponents(g,s);break;case "mixins":this.extractMixins(g,s);break;default:if(xt.includes(u)){let m=f(this.getStartLine(d)),h=f(this.getEndLine(d)),b=K(n.join(`
|
|
416
|
+
`),m),S=s.symbols.length;s.symbols.push({name:u,category:"lifecycle",framework:"vue2",startLine:m,endLine:h,jsdoc:b,camelWords:k(u)});let y=z(g,u);s.behaviors.push(...y);let _=Te(g,u);for(let E of _){if(E.args){let A=String(E.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[S].camelWords+=` ${k(A)} ${A}`;}s.relations.push(U({callerName:u,callerLine:m,calleeName:E.calleeName,callType:"this_method",line:f(E.line),args:E.args}));}}break}}}extractData(e,t,n,r){let s=null;if(e.type==="FunctionExpression"||e.type==="ArrowFunctionExpression"||e.type==="ObjectMethod"?V(e.body,i=>{i.type==="ReturnStatement"&&i.argument?.type==="ObjectExpression"&&(s=i.argument);}):e.type==="ObjectExpression"&&(s=e),!!s)for(let i of s.properties){let a=this.getPropKey(i);if(!a)continue;let c=n(this.getStartLine(i)),l=n(this.getEndLine(i)),p=this.getLiteralValue(i.value);r.symbols.push({name:a,category:"state",framework:"vue2",startLine:c,endLine:l,defaultValue:p,camelWords:k(a)});}}extractProps(e,t,n,r){if(e.type==="ArrayExpression"){for(let s of e.elements||[])if(s?.type==="Literal"){let i=String(s.value);r.symbols.push({name:i,category:"prop",framework:"vue2",startLine:n(this.getStartLine(s)),endLine:n(this.getEndLine(s)),camelWords:k(i)});}}else if(e.type==="ObjectExpression")for(let s of e.properties||[]){let i=this.getPropKey(s);if(!i)continue;let a=n(this.getStartLine(s)),c=n(this.getEndLine(s)),l;if(s.value?.type==="ObjectExpression"){let p=s.value.properties?.find(d=>this.getPropKey(d)==="default");p&&(l=this.getLiteralValue(p.value));}r.symbols.push({name:i,category:"prop",framework:"vue2",startLine:a,endLine:c,defaultValue:l,camelWords:k(i)});}}extractComputedOrMethods(e,t,n,r,s,i){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 p=r(this.getStartLine(a)),d=r(this.getEndLine(a)),u=K(s.join(`
|
|
417
|
+
`),p),g=this.extractParams(l),f=l.async===true,m=g?`${c}(${g.join(", ")})`:c;if(i.symbols.push({name:c,category:t,framework:"vue2",startLine:p,endLine:d,signature:m,params:g,isAsync:f,jsdoc:u,camelWords:k(c)}),t==="method"&&l){let h=z(l,c);i.behaviors.push(...h);let b=Te(l,c);for(let y of b){if(y.args){let _=String(y.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");i.symbols[i.symbols.length-1].camelWords+=` ${k(_)} ${_}`;}i.relations.push(U({callerName:c,callerLine:p,calleeName:y.calleeName,callType:"this_method",line:r(y.line),args:y.args}));}let S=G(l,c,s,true);for(let y of S){if(y.args){let _=String(y.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");i.symbols[i.symbols.length-1].camelWords+=` ${k(_)} ${_}`;}i.relations.push(U({callerName:c,callerLine:p,calleeName:y.calleeName,callType:"direct_call",line:r(y.line),args:y.args}));}}}}extractWatch(e,t,n,r){if(e.type==="ObjectExpression")for(let s of e.properties||[]){let i=this.getPropKey(s);if(!i)continue;let a=n(this.getStartLine(s)),c=n(this.getEndLine(s));r.symbols.push({name:i,category:"effect",framework:"vue2",startLine:a,endLine:c,camelWords:k(i)});}}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 i=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 p=i(this.getStartLine(c)),d=i(this.getEndLine(c)),u=K(n.join(`
|
|
418
|
+
`),p);if(c.type==="ClassMethod"){let f=xt.includes(l)?"lifecycle":"method",m=this.extractParams(c),h=c.async===true,b=m?`${l}(${m.join(", ")})`:l;s.symbols.push({name:l,category:f,framework:"vue2",startLine:p,endLine:d,signature:b,params:m,isAsync:h,jsdoc:u,camelWords:k(l)});let S=z(c,l);s.behaviors.push(...S);let y=Te(c,l);for(let E of y){if(E.args){let A=String(E.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[s.symbols.length-1].camelWords+=` ${k(A)} ${A}`;}s.relations.push(U({callerName:l,callerLine:p,calleeName:E.calleeName,callType:"this_method",line:i(E.line),args:E.args}));}let _=G(c,l,n,true);for(let E of _){if(E.args){let A=String(E.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[s.symbols.length-1].camelWords+=` ${k(A)} ${A}`;}s.relations.push(U({callerName:l,callerLine:p,calleeName:E.calleeName,callType:"direct_call",line:i(E.line),args:E.args}));}}else if(c.type==="ClassProperty"){let g=(c.decorators||[]).some(m=>m.expression?.callee?.name==="Prop"),f=this.getLiteralValue(c.value);s.symbols.push({name:l,category:g?"prop":"state",framework:"vue2",startLine:p,endLine:d,defaultValue:f,camelWords:k(l)});}}}};var It=createRequire(import.meta.url),at=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}=It("@vue/compiler-sfc"),{descriptor:s}=r(t),i=t.split(`
|
|
419
|
+
`),a=!!s.scriptSetup,c=!!s.script;if(a){let l=s.scriptSetup,p=l.loc.start.line;this.parseSetupContent(l.content,p,i,n);}else if(c){let l=s.script,p=l.loc.start.line;this.parseScriptContent(l.content,p,i,n)||this.populateFromOptionsApiFallback(e,t,n);}if(s.template?.content){let l=s.template.loc.start.line,p=nt(s.template.content,l);if(p.length>0){let d=s.template.content.split(`
|
|
420
|
+
`).length;n.symbols.push({name:"<template>",category:"lifecycle",framework:"vue3",startLine:l,endLine:l+d-1,camelWords:"template"});for(let u of p)n.relations.push(U({callerName:"<template>",callerLine:l,calleeName:u.calleeName,callType:"template_event",line:u.line}));}}}catch(r){n.errors?.push(`Vue3 \u89E3\u6790\u5931\u8D25: ${String(r)}`);}return n}parseSetupContent(e,t,n,r){let s;try{s=It("@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 i=l=>l+t-1,a=e.split(`
|
|
421
|
+
`),c=s.program.body;r.fileDependencies=fe(c,r.filePath);for(let l of c||[])this.processTopLevelStatement(l,i,n,a,r);}parseScriptContent(e,t,n,r){let s;try{s=It("@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 i=l=>l+t-1,a=e.split(`
|
|
422
|
+
`);r.fileDependencies=fe(s.program.body||[],r.filePath);let c=false;return V(s.program,l=>{if(l.type==="ExportDefaultDeclaration"&&l.declaration?.type==="ObjectExpression"){let p=l.declaration.properties?.find(d=>this.getPropKey(d)==="setup");if(p){c=true;let d=p.type==="ObjectMethod"?p:p.value;if(!d)return;let u=d.body;if(u?.type==="BlockStatement"){let g=u.body;for(let f of g||[])this.processTopLevelStatement(f,i,n,a,r);}}}}),c||V(s.program,l=>{if(!c&&l.type==="ObjectExpression"){let d=(l.properties||[]).find(u=>this.getPropKey(u)==="setup");if(d){c=true;let u=d.type==="ObjectMethod"?d:d.value;if(!u)return;let g=u.body;if(g?.type==="BlockStatement"){let f=g.body;for(let m of f||[])this.processTopLevelStatement(m,i,n,a,r);}}}}),c}processTopLevelStatement(e,t,n,r,s){let i=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:p,end:d}=i(e),u=K(n.join(`
|
|
423
|
+
`),t(p)),g=this.extractParams(c),f=s.symbols.length;if(s.symbols.push({name:l,category:"method",framework:"vue3",startLine:t(p),endLine:t(d),signature:`${l}(${(g||[]).join(", ")})`,params:g,isAsync:c.async===true,jsdoc:u,camelWords:k(l)}),c.body){let m=z(c.body,l);s.behaviors.push(...m);let h=G(c.body,l);for(let b of h){if(b.args){let S=String(b.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[f].camelWords+=` ${k(S)} ${S}`;}s.relations.push(U({callerName:l,callerLine:t(p),calleeName:b.calleeName,callType:"direct_call",line:t(b.line),args:b.args}));}}}else {let p=this.classifyVue3Declaration(l,c,t,i(e),n);p&&s.symbols.push(p);}}}if(e.type==="FunctionDeclaration"&&e.id?.type==="Identifier"){let a=e.id.name,{start:c,end:l}=i(e),p=K(n.join(`
|
|
424
|
+
`),t(c)),d=this.extractParams(e),u=At.includes(a);if(s.symbols.push({name:a,category:u?"lifecycle":be(a)?"hook":"method",framework:"vue3",startLine:t(c),endLine:t(l),signature:`${a}(${(d||[]).join(", ")})`,params:d,isAsync:e.async===true,jsdoc:p,camelWords:k(a)}),e.body){let g=z(e.body,a);s.behaviors.push(...g);let f=G(e.body,a);for(let m of f){if(m.args){let h=String(m.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[s.symbols.length-1].camelWords+=` ${k(h)} ${h}`;}s.relations.push(U({callerName:a,callerLine:t(c),calleeName:m.calleeName,callType:"direct_call",line:t(m.line),args:m.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:p,end:d}=i(e);s.symbols.push({name:l,category:l==="defineProps"?"prop":l==="defineEmits"?"emit":"export",framework:"vue3",startLine:t(p),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(At.includes(l)){let{start:p,end:d}=i(e);s.symbols.push({name:l,category:"lifecycle",framework:"vue3",startLine:t(p),endLine:t(d),camelWords:k(l)});let u=a.arguments;if(u?.[0]){let g=z(u[0],l);s.behaviors.push(...g);let f=G(u[0],l);for(let m of f){if(m.args){let h=String(m.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[s.symbols.length-1].camelWords+=` ${k(h)} ${h}`;}s.relations.push(U({callerName:l,callerLine:t(p),calleeName:m.calleeName,callType:"direct_call",line:t(m.line),args:m.args}));}}}}}}classifyVue3Declaration(e,t,n,r,s){if(t.type!=="CallExpression")return null;let i=t.callee;if(i?.type!=="Identifier")return null;let a=i.name,c=n(r.start),l=n(r.end),p=K(s.join(`
|
|
425
|
+
`),c);if(nn.includes(a)){let d=t.arguments,u=d?.[0]?this.getLiteralValue(d[0]):void 0;return {name:e,category:"state",framework:"vue3",startLine:c,endLine:l,defaultValue:u,jsdoc:p,camelWords:k(e)}}return rn.includes(a)?{name:e,category:"computed",framework:"vue3",startLine:c,endLine:l,jsdoc:p,camelWords:k(e)}:sn.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)}:be(a)?{name:e,category:"hook",framework:"vue3",startLine:c,endLine:l,jsdoc:p,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 we().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 Cr=createRequire(import.meta.url),$r=[...Lt,...Rt,...kt,...on],We=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=Cr("@babel/parser").parse(t,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy"],errorRecovery:!0}),i=t.split(`
|
|
426
|
+
`);this.extractFromAST(s.program?s.program:s,i,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=fe(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 i=s.type==="FunctionDeclaration"?s:s.declaration,a=s.type!=="FunctionDeclaration";i&&i.id?.type==="Identifier"&&this.processFunction(i,t,n,a);}if(s.type==="VariableDeclaration"||s.type==="ExportNamedDeclaration"&&s.declaration?.type==="VariableDeclaration"||s.type==="ExportDefaultDeclaration"&&s.declaration?.type==="VariableDeclaration"){let i=s.type==="VariableDeclaration"?s:s.declaration,a=s.type!=="VariableDeclaration";if(i)for(let c of i.declarations||[]){let l=c.init;if(l&&(l.type==="ArrowFunctionExpression"||l.type==="FunctionExpression")&&c.id?.type==="Identifier"){let p={...l,id:c.id,loc:{start:i.loc?.start??l.loc?.start,end:l.loc?.end}};this.processFunction(p,t,n,a);continue}this.processTopLevelVariableDeclaration(c,t,n,a);}}}n.exportSignatureEntries=ot(r,n.symbols);}processTopLevelVariableDeclaration(e,t,n,r){let s=e.id;if(!s||s.type!=="Identifier")return;let i=s.name;if(!i)return;let a=e.init,c=e.loc,l=c?.start?.line??1,p=c?.end?.line??1,d=this.buildSymbolKey(i,l,p);if(n.symbols.push({name:i,category:"constant",framework:"react",startLine:l,endLine:p,internalKey:d,isExported:r,defaultValue:this.getLiteralValue(a),jsdoc:K(t.join(`
|
|
427
|
+
`),l),camelWords:k(i)}),!a)return;let u=z(a,i,t,true);n.behaviors.push(...u);let g=G(a,i,t,true);for(let f of g){let m=n.symbols.findIndex(h=>h.name===i&&h.startLine===l);if(f.args&&m!==-1){let h=String(f.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");n.symbols[m].camelWords+=` ${k(h)} ${h}`;}n.relations.push(U({callerName:i,callerLine:l,callerKey:d,calleeName:f.calleeName,callType:"direct_call",line:f.line,args:f.args}));}}processFunction(e,t,n,r=false){let s=e.id?.name;if(!s)return;let i=e.loc,a=i?.start?.line??1,c=i?.end?.line??1,l=be(s),p=!l&&/^[A-Z]/.test(s),d=K(t.join(`
|
|
428
|
+
`),a),u=this.extractParams(e),g=this.buildSymbolKey(s,a,c);n.symbols.push({name:s,category:l?"hook":p?"component":"function",framework:"react",startLine:a,endLine:c,internalKey:g,signature:`${s}(${(u||[]).join(", ")})`,params:u,isAsync:e.async===true,isExported:r,jsdoc:d,parentComponent:p?s:void 0,camelWords:k(s)});let f=e.body;if(f?.type!=="BlockStatement")return;let m=f.body;for(let y of m||[])this.processComponentStatement(y,s,t,n);let h=z(f,s,t,true);n.behaviors.push(...h);let b=G(f,s,t,true);for(let y of b){let _=n.symbols.findIndex(E=>E.name===s&&E.startLine===a);if(y.args&&_!==-1){let E=String(y.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");n.symbols[_].camelWords+=` ${k(E)} ${E}`;}n.relations.push(U({callerName:s,callerLine:a,callerKey:g,calleeName:y.calleeName,callType:"direct_call",line:y.line,args:y.args}));}let S=mn(f);for(let y of S)n.relations.push(U({callerName:s,callerLine:a,callerKey:g,calleeName:y.calleeName,callType:"jsx_event",line:y.line}));}processComponentStatement(e,t,n,r){let s=i=>{let a=i?.loc;return {start:a?.start?.line??1,end:a?.end?.line??1}};if(e.type==="VariableDeclaration")for(let i of e.declarations||[]){let a=i.init;if(!a||a.type!=="CallExpression")continue;let c=a.callee;if(c?.type!=="Identifier")continue;let l=c.name,{start:p,end:d}=s(e),u=p,g=d;if(Lt.includes(l)&&l!=="useRef"){if(i.id?.type==="ArrayPattern"){let f=i.id.elements,m=f[0]?.name,h=f[1]?.name;if(m){let b=a.arguments;r.symbols.push({name:m,category:"state",framework:"react",startLine:u,endLine:g,internalKey:this.buildSymbolKey(m,u,g,t),stateSetterName:h,defaultValue:this.getLiteralValue(b?.[0]),parentComponent:t,camelWords:k(m)});}}else if(i.id?.type==="Identifier"){let f=i.id.name;r.symbols.push({name:f,category:"state",framework:"react",startLine:u,endLine:g,internalKey:this.buildSymbolKey(f,u,g,t),parentComponent:t,camelWords:k(f)});}}if(l==="useRef"&&i.id?.type==="Identifier"){let f=i.id.name,m=a.arguments;r.symbols.push({name:f,category:"state",framework:"react",startLine:u,endLine:g,internalKey:this.buildSymbolKey(f,u,g,t),defaultValue:this.getLiteralValue(m?.[0]),parentComponent:t,camelWords:k(f)});}if(Rt.includes(l)&&i.id?.type==="Identifier"){let f=i.id.name,h=a.arguments?.[1],b=this.extractDepsArray(h);r.symbols.push({name:f,category:"computed",framework:"react",startLine:u,endLine:g,internalKey:this.buildSymbolKey(f,u,g,t),hookDeps:b,parentComponent:t,camelWords:k(f)});}if(be(l)&&!$r.includes(l)){let f=i.id?.type==="Identifier"?i.id.name:i.id?.type==="ObjectPattern"?"{...}":"?";r.symbols.push({name:f,category:"hook",framework:"react",startLine:u,endLine:g,internalKey:this.buildSymbolKey(f,u,g,t),parentComponent:t,camelWords:k(f)});}}if(e.type==="ExpressionStatement"&&e.expression?.type==="CallExpression"){let i=e.expression,a=i.callee;if(a?.type==="Identifier"){let c=a.name;if(kt.includes(c)){let{start:l,end:p}=s(e),d=i.arguments,u=d?.[1],g=this.extractDepsArray(u),f=this.buildSymbolKey(c,l,p,t),m=`${t}.${c}`;if(r.symbols.push({name:c,category:"effect",framework:"react",startLine:l,endLine:p,internalKey:f,hookDeps:g,parentComponent:t,camelWords:k(c)}),d?.[0]){let h=z(d[0],m,n,true).map(S=>({...S,symbolKey:f}));r.behaviors.push(...h);let b=G(d[0],m,n,true);for(let S of b){let y=r.symbols.findIndex(_=>_.name===c&&_.startLine===l);if(S.args&&y!==-1){let _=String(S.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");r.symbols[y].camelWords+=` ${k(_)} ${_}`;}r.relations.push(U({callerName:m,callerLine:l,callerKey:f,calleeName:S.calleeName,callType:"direct_call",line:S.line,args:S.args}));}}}}}if(e.type==="FunctionDeclaration"&&e.id?.type==="Identifier"){let i=e.id.name;if(!be(i)){let{start:a,end:c}=s(e),l=K(n.join(`
|
|
429
|
+
`),a),p=this.extractParams(e);if(r.symbols.push({name:i,category:"method",framework:"react",startLine:a,endLine:c,internalKey:this.buildSymbolKey(i,a,c,t),signature:`${i}(${(p||[]).join(", ")})`,params:p,isAsync:e.async===true,jsdoc:l,parentComponent:t,camelWords:k(i)}),e.body){let d=z(e.body,i,n,true);r.behaviors.push(...d);let u=G(e.body,i,n,true);for(let g of u){let f=r.symbols.findIndex(m=>m.name===i&&m.startLine===a);if(g.args&&f!==-1){let m=String(g.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");r.symbols[f].camelWords+=` ${k(m)} ${m}`;}r.relations.push(U({callerName:i,callerLine:a,callerKey:this.buildSymbolKey(i,a,c,t),calleeName:g.calleeName,callType:"direct_call",line:g.line,args:g.args}));}}}}if(e.type==="VariableDeclaration")for(let i of e.declarations||[]){let a=i.init;if(!a)continue;let c=a.type==="ArrowFunctionExpression"||a.type==="FunctionExpression";if(!c||i.id?.type!=="Identifier")continue;let l=i.id.name,p=a.type==="CallExpression"?a.callee:null;if(p?.type==="Identifier"&&be(p.name))continue;if(a.type==="CallExpression"&&a.callee?.name==="useCallback"){let b=a.arguments?.[1],S=this.extractDepsArray(b),{start:y,end:_}=s(e);r.symbols.push({name:l,category:"computed",framework:"react",startLine:y,endLine:_,internalKey:this.buildSymbolKey(l,y,_,t),hookDeps:S,parentComponent:t,camelWords:k(l)});continue}if(!c)continue;let{start:u,end:g}=s(e),f=K(n.join(`
|
|
430
|
+
`),u),m=this.extractParams(a);if(r.symbols.push({name:l,category:"method",framework:"react",startLine:u,endLine:g,internalKey:this.buildSymbolKey(l,u,g,t),signature:`${l}(${(m||[]).join(", ")})`,params:m,isAsync:a.async===true,jsdoc:f,parentComponent:t,camelWords:k(l)}),a.body){let h=z(a.body,l,n,true);r.behaviors.push(...h);let b=G(a.body,l,n,true);for(let S of b){let y=r.symbols.findIndex(_=>_.name===l&&_.startLine===u);if(S.args&&y!==-1){let _=String(S.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");r.symbols[y].camelWords+=` ${k(_)} ${_}`;}r.relations.push(U({callerName:l,callerLine:u,callerKey:this.buildSymbolKey(l,u,g,t),calleeName:S.calleeName,callType:"direct_call",line:S.line,args:S.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 Pr=createRequire(import.meta.url),ct=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 i=Pr("@babel/parser").parse(t,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy","classProperties"],errorRecovery:!0}),a=t.split(`
|
|
431
|
+
`),c=(i.program||i).body,l=new Set;r.fileDependencies=fe(c||[],e);for(let p of c||[])this.processTopLevelStatement(p,a,n,r,l);if(l.size>0)for(let p of r.symbols)l.has(p.name)&&(p.isExported=!0);r.exportSignatureEntries=ot(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 i=e.declaration;if(!i){this.collectDeferredExportNames(e,s);return}if(i.type==="FunctionDeclaration"){this.addTopLevelFunction(i,t,n,r,true);return}if(i.type==="ClassDeclaration"){this.addClass(i,t,n,r,true);return}if(i.type==="VariableDeclaration"){this.processVariableDeclaration(i,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 i of e.declarations||[]){let a=i.id;if(!a||a.type!=="Identifier")continue;let c=String(a.name||"");if(!c)continue;let l=i.init,{start:p,end:d}=this.getLineRange(i),u=this.buildSymbolKey(c,p,d);if(l&&(l.type==="ArrowFunctionExpression"||l.type==="FunctionExpression")){this.addFunctionSymbol(c,l,t,n,r,{startLine:p,endLine:d,isExported:s});continue}if(r.symbols.push({name:c,category:"constant",framework:n,startLine:p,endLine:d,internalKey:u,isExported:s,defaultValue:this.getLiteralValue(l),jsdoc:K(t.join(`
|
|
432
|
+
`),p),camelWords:k(c)}),!l)continue;let g=z(l,c,t,true);r.behaviors.push(...g);let f=G(l,c,t,true);for(let h of f)r.relations.push(U({callerName:c,callerLine:p,callerKey:u,calleeName:h.calleeName,callType:"direct_call",line:h.line,args:h.args}));let m=tt(l,c,t,true);for(let h of m)r.relations.push(U({callerName:c,callerLine:p,callerKey:u,calleeName:h.calleeName,callType:"direct_call",line:h.line,args:h.args,receiverToken:h.receiverToken}));}}addTopLevelFunction(e,t,n,r,s){let i=e.id?.name;if(!i)return;let{start:a,end:c}=this.getLineRange(e);this.addFunctionSymbol(i,e,t,n,r,{startLine:a,endLine:c,isExported:s});}addFunctionSymbol(e,t,n,r,s,i){let a=this.buildSymbolKey(e,i.startLine,i.endLine,i.ownerClass),c=this.extractParams(t);s.symbols.push({name:e,category:i.ownerClass?"method":"function",framework:r,startLine:i.startLine,endLine:i.endLine,internalKey:a,signature:`${e}(${(c||[]).join(", ")})`,params:c,isAsync:t.async===true,isExported:i.isExported,jsdoc:K(n.join(`
|
|
433
|
+
`),i.startLine),parentComponent:i.ownerClass,camelWords:k(e)});let l=t.body;if(!l)return;let p=z(l,e,n,true);s.behaviors.push(...p);let d=G(l,e,n,true);for(let m of d)s.relations.push(U({callerName:e,callerLine:i.startLine,callerKey:a,calleeName:m.calleeName,callType:"direct_call",line:m.line,args:m.args}));let u=un(l,e,n);for(let m of u)s.relations.push(U({callerName:e,callerLine:i.startLine,callerKey:a,calleeName:m.calleeName,callType:"direct_call",line:m.line,args:m.args}));let g=tt(l,e,n,true);for(let m of g)s.relations.push(U({callerName:e,callerLine:i.startLine,callerKey:a,calleeName:m.calleeName,callType:"direct_call",line:m.line,args:m.args,receiverToken:m.receiverToken}));let f=Te(l,e);for(let m of f)s.relations.push(U({callerName:e,callerLine:i.startLine,callerKey:a,calleeName:m.calleeName,callType:"this_method",line:m.line,args:m.args}));}addClass(e,t,n,r,s){let i=e.id?.name;if(!i)return;let{start:a,end:c}=this.getLineRange(e);r.symbols.push({name:i,category:"class",framework:n,startLine:a,endLine:c,isExported:s,jsdoc:K(t.join(`
|
|
434
|
+
`),a),camelWords:k(i)});let l=e.body?.body;for(let p of l||[]){let d=p.key,u=d?.type==="Identifier"?String(d.name||""):"";if(!u||u==="constructor")continue;if(p.type==="ClassMethod"||p.type==="ClassPrivateMethod"){this.addFunctionSymbol(u,p,t,n,r,{startLine:this.getLineRange(p).start,endLine:this.getLineRange(p).end,isExported:false,ownerClass:i});continue}let g=p.value;g&&(g.type==="ArrowFunctionExpression"||g.type==="FunctionExpression")&&(p.type==="ClassProperty"||p.type==="PropertyDefinition")&&this.addFunctionSymbol(u,g,t,n,r,{startLine:this.getLineRange(p).start,endLine:this.getLineRange(p).end,isExported:false,ownerClass:i});}}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 Or=new Set(["FunctionDeclaration","ArrowFunctionExpression","FunctionExpression","ObjectMethod","ClassMethod","ClassProperty"]);function bn(o,e){return !!e?.skipNestedFunctions&&Or.has(String(o.type||""))}function me(o,e,t){if(!(!o||typeof o!="object")){e(o);for(let n of Object.keys(o)){if(n==="type"||n==="loc"||n==="start"||n==="end")continue;let r=o[n];if(Array.isArray(r)){for(let s of r){if(!s||typeof s!="object"||!s.type)continue;let i=s;bn(i,t)||me(i,e,t);}continue}if(r&&typeof r=="object"&&r.type){let s=r;if(bn(s,t))continue;me(s,e,t);}}}}function En(o,e,t=true,n){let r=[],s=[],i=(a,c=120)=>Fr(a,n,c);return me(o,a=>{if(a.type==="VariableDeclarator"){let c=a.id;if(!c)return;let l=lt(c),p=i(a);for(let d of l)r.push({symbolName:d,kind:"declaration",line:ve(a),text:p,sourceLayer:ne(p,ve(a))});}if(a.type==="AssignmentExpression"){let c=a.left;if(!c)return;let l=i(a),p=ve(a);if(c.type==="Identifier"&&r.push({symbolName:c.name,kind:"assignment",line:p,text:l,sourceLayer:ne(l,p)}),c.type==="MemberExpression"&&c.object?.type==="ThisExpression"){let u=q(c);if(u){r.push({symbolName:u,kind:"assignment",line:p,text:l,sourceLayer:ne(l,p)});return}}if(c.type==="MemberExpression"){let d=te(c);if(d&&Pt(d)){let u=q(c);s.push({objectName:d,propertyName:u||void 0,line:p,text:l,kind:c.computed?"bracket":"dot",sourceLayer:ne(l,p)});}}}if(a.type==="UpdateExpression"){let c=a.argument;if(!c)return;let l=i(a),p=ve(a);if(c.type==="Identifier"&&r.push({symbolName:c.name,kind:"update",line:p,text:l,sourceLayer:ne(l,p)}),c.type==="MemberExpression"&&c.object?.type==="ThisExpression"){let u=q(c);if(u){r.push({symbolName:u,kind:"update",line:p,text:l,sourceLayer:ne(l,p)});return}}if(c.type==="MemberExpression"){let d=te(c);if(d&&Pt(d)){let u=q(c);s.push({objectName:d,propertyName:u||void 0,line:p,text:l,kind:c.computed?"bracket":"dot",sourceLayer:ne(l,p)});}}}if(a.type==="UnaryExpression"&&a.operator==="delete"){let c=a.argument;if(c?.type==="MemberExpression"){let l=te(c);if(l&&Pt(l)){let p=q(c);s.push({objectName:l,propertyName:p||void 0,line:ve(a),text:i(a),kind:"delete",sourceLayer:ne(i(a),ve(a))});}}}},{skipNestedFunctions:t}),{assignments:r,propertyWrites:s}}function lt(o){return o.type==="Identifier"?[o.name]:o.type==="ObjectPattern"?(o.properties||[]).flatMap(t=>{let n=t.type==="ObjectProperty"||t.type==="Property"?t.value:t;return n?lt(n):[]}):o.type==="ArrayPattern"?(o.elements||[]).flatMap(t=>t?lt(t):[]):o.type==="AssignmentPattern"?lt(o.left):[]}function Pt(o){return !(/^[A-Z][A-Z]/.test(o)||/^(document|window|console|localStorage|sessionStorage|navigator|process|global|globalThis)$/.test(o))}function ve(o){return o.loc?.start?.line??1}function Fr(o,e,t=120){if(e){let r=o.loc;if(r?.start?.line&&r?.end?.line){let s=r.start.line-1,i=Math.min(r.end.line-1,s+5);return e.slice(s,i+1).map(c=>c.trim()).filter(c=>c).join(" ").slice(0,t)}}let n=o.loc;return n?.start?.line?`L${n.start.line}`:String(o.type||"?")}var Mr=createRequire(import.meta.url);function Ft(o,e){let t={files:new Map,resolutionCache:new Map,localShadowCache:new Map};for(let{path:n,content:r}of o){let s=hn(n,r);t.files.set(n,s);let i=new Map;for(let a of s.imports)a.localName&&i.set(a.localName,`${a.resolvedFile}::${a.originalName}`);t.resolutionCache.set(n,i),t.localShadowCache.set(n,jr(r));}return t}function Dt(o,e,t,n){if(t.files.size===0)return o;let r=t.resolutionCache.get(e);if(!r||r.size===0)return o;let s=t.localShadowCache.get(e);return t.files.get(e)?o.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}}):o}function jr(o){let e=new Map;try{let n=Mr("@babel/parser").parse(o,{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)Nn(s,e);}catch{return e}return e}function Nn(o,e){if(o.type==="FunctionDeclaration"){let t=xe(o.id);if(!t)return;Ce(t,o,e),Ur(Br(o),t,e);return}if(o.type==="VariableDeclaration"){Tn(o,void 0,e);return}if(o.type==="ClassDeclaration"){Wr(o,e);return}if(o.type==="ExportNamedDeclaration"||o.type==="ExportDefaultDeclaration"){let t=o.declaration;if(!t)return;Nn(t,e);}}function Ur(o,e,t){for(let n of o){if(n.type==="FunctionDeclaration"){let r=xe(n.id);if(!r)continue;Ce(r,n,t,e);continue}if(n.type==="VariableDeclaration"){Tn(n,e,t);continue}if(n.type==="ExpressionStatement"){let r=n.expression;if(r?.type!=="CallExpression")continue;let s=r.callee,i=s?.type==="Identifier"?String(s.name||""):"";if(!/^use[A-Z]/.test(i))continue;let a=r.arguments?.[0];if(!a||a.type!=="ArrowFunctionExpression"&&a.type!=="FunctionExpression")continue;Ce(i,a,t,e,n);}}}function Tn(o,e,t){for(let n of o.declarations||[]){let r=xe(n.id),s=n.init;!r||!s||s.type!=="ArrowFunctionExpression"&&s.type!=="FunctionExpression"||Ce(r,s,t,e,n);}}function Wr(o,e){let t=xe(o.id);if(!t)return;let n=o.body?.body||[];for(let r of n){let s=xe(r.key);if(!s||s==="constructor")continue;if(r.type==="ClassMethod"||r.type==="ClassPrivateMethod"){Ce(s,r,e,t);continue}let i=r.value;i&&(i.type==="ArrowFunctionExpression"||i.type==="FunctionExpression")&&(r.type==="ClassProperty"||r.type==="PropertyDefinition")&&Ce(s,i,e,t,r);}}function Ce(o,e,t,n,r){let s=Xr(r||e),i=Kr(o,s.start,s.end,n),a=Hr(e);t.set(i,a);}function Hr(o){let e=new Set;for(let n of o.params||[])for(let r of Se(n))e.add(r);let t=o.body;return t&&Ot(t,n=>{if(n.type==="VariableDeclarator"){for(let r of Se(n.id))e.add(r);return}if(n.type==="FunctionDeclaration"){let r=xe(n.id);return r&&e.add(r),false}if(n.type==="ClassDeclaration"){let r=xe(n.id);return r&&e.add(r),false}}),e}function Ot(o,e){if(!(!o||typeof o!="object")&&e(o)!==false)for(let t of Object.keys(o)){if(t==="type"||t==="loc"||t==="start"||t==="end")continue;let n=o[t];if(Array.isArray(n)){for(let r of n){if(!r||typeof r!="object"||!r.type)continue;let s=r;_n(s)||Ot(s,e);}continue}if(n&&typeof n=="object"&&n.type){let r=n;if(_n(r))continue;Ot(r,e);}}}function _n(o){return ["FunctionDeclaration","FunctionExpression","ArrowFunctionExpression","ClassMethod","ClassPrivateMethod","ObjectMethod"].includes(String(o.type||""))}function Se(o){return o?o.type==="Identifier"?[String(o.name||"")]:o.type==="AssignmentPattern"?Se(o.left):o.type==="RestElement"?Se(o.argument):o.type==="ArrayPattern"?(o.elements||[]).flatMap(e=>Se(e)):o.type==="ObjectPattern"?(o.properties||[]).flatMap(e=>{if(e.type==="RestElement")return Se(e.argument);let t=e.value||e.argument;return Se(t)}):[]:[]}function xe(o){if(o&&o.type==="Identifier")return String(o.name||"")}function Br(o){let e=o.body;return !e||e.type!=="BlockStatement"?[]:e.body||[]}function Xr(o){let e=o.loc;return {start:e?.start?.line??1,end:e?.end?.line??1}}function Kr(o,e,t,n){return n?`${n}:${o}:${e}:${t}`:`root:${o}:${e}:${t}`}var Sn=createRequire(import.meta.url);function xn(o,e){let t=o.errors||[];t.includes(e)||(o.errors=[...t,e]);}var Mt=class extends We{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}},zr=[new at,new we,new We,new ct,new Mt];function He(o,e){for(let t of zr)if(t.canParse(o,e)){let n=t.parse(o,e);return qr(n),Gr(n,e),n}return {framework:"js",filePath:o,symbols:[],relations:[],behaviors:[],errors:[`\u6CA1\u6709\u627E\u5230\u9002\u5408\u7684\u89E3\u6790\u5668: ${o}`]}}function Gr(o,e){if(o.symbols.length!==0)try{let t=e,n=o.filePath.endsWith(".vue"),r=0;if(n)try{let{parse:u}=Sn("@vue/compiler-sfc"),{descriptor:g}=u(e);if(g.scriptSetup?.content)t=g.scriptSetup.content,r=g.scriptSetup.loc.start.line-1;else if(g.script?.content)t=g.script.content,r=g.script.loc.start.line-1;else return}catch(u){xn(o,`\u751F\u547D\u5468\u671F\u63D0\u53D6\u8DF3\u8FC7: Vue SFC \u89E3\u6790\u5931\u8D25 - ${String(u)}`);return}let a=Sn("@babel/parser").parse(t,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy"],errorRecovery:!0}).program.body;if(!a?.length)return;let c=t.split(`
|
|
435
|
+
`),{assignments:l,propertyWrites:p}=En({type:"Program",body:a},o.filePath,!1,c);if(r>0){for(let u of l)u.line+=r;for(let u of p)u.line+=r;}let d=new Set(o.symbols.map(u=>u.name));o.assignments=l.filter(u=>d.has(u.symbolName)),o.propertyWrites=p.filter(u=>d.has(u.objectName));}catch(t){xn(o,`\u751F\u547D\u5468\u671F\u63D0\u53D6\u8DF3\u8FC7: AST \u89E3\u6790\u5931\u8D25 - ${String(t)}`);}}function qr(o){if(!o.relations.length||!o.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(o.behaviors.filter(r=>r.category==="network").map(r=>r.symbolName));if(t.size===0)return;let n=new Set(o.behaviors.map(r=>`${r.symbolName}:${r.category}:${r.apiName}:${r.operation}:${r.line}`));for(let r of o.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},i=`${s.symbolName}:${s.category}:${s.apiName}:${s.operation}:${s.line}`;n.has(i)||(n.add(i),o.behaviors.push(s));}}function Be(o,e){let t=Jr(e),n=o.exportSignatureEntries?.length?[...o.exportSignatureEntries]:(()=>{let a=[];for(let c of o.symbols)if(c.isExported){let l=c.signature||"";a.push(`${c.name}:${l}`);}return a.sort(),a})(),r=n.length>0?An(n.join(`
|
|
436
|
+
`)):"",s=[];if(o.fileDependencies&&o.fileDependencies.length>0)for(let a of o.fileDependencies)(a.dependencyKind==="import"||a.dependencyKind==="re_export")&&s.push(a.toFile);s.sort();let i=s.length>0?An(s.join(`
|
|
437
|
+
`)):"";return {contentHash:t,exportSignatureHash:r,importSignatureHash:i}}function Rn(o,e){if(!o)return "full_changed";if(o.contentHash===e.contentHash)return "unchanged";let t=o.exportSignatureHash!==e.exportSignatureHash,n=o.importSignatureHash!==e.importSignatureHash;return t&&n?"full_changed":t?"export_changed":n?"import_changed":"body_only"}function kn(o,e,t,n=200){if(e==="unchanged")return {files:[],truncated:false};if(e==="body_only")return {files:[o],truncated:false};if(e==="import_changed")return {files:[o],truncated:false};let r=new Set([o]),s=[o];for(;s.length>0;){let i=s.shift(),a=t.get(i)||[];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 Jr(o){return createHash("sha256").update(o,"utf-8").digest("hex").slice(0,16)}function An(o){return createHash("sha256").update(o,"utf-8").digest("hex").slice(0,12)}var Yr={maxFiles:20,maxTimeMs:1500},pt=class{pending=[];options;constructor(e){this.options={...Yr,...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,i)=>{let a=e[s.priority],c=e[i.priority];return a!==c?a-c:s.addedAt-i.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 dt=class{projectRoot;db;scheduler;constructor(e,t){this.projectRoot=e,this.db=t,this.scheduler=new pt;}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=Ft(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(i=>i.name));r.result.relations=Dt(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}
|
|
438
|
+
`);for(let r of e){let s=r.result.errors||[];s.includes(n)||(r.result.errors=[...s,n]);}}}async indexProject(e){let t=Date.now(),n=e?.include||[...St],r=e?.exclude||[...Tt],s=e?.force||false,i=Date.now(),a=await Zr(n,{cwd:this.projectRoot,ignore:r,absolute:true,onlyFiles:true}),c=Date.now()-i,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 p=0,d=0,u=0;if((e?.precisionMode||"heuristic")==="precise"){let f=[];for(let m=0;m<a.length;m++){let h=a[m],b=de(h,this.projectRoot);e?.onProgress?.(m+1,a.length,b);try{let S=Q__default.statSync(h).mtimeMs,y=Date.now(),_=Q__default.readFileSync(h,"utf-8"),E=Date.now()-y,A=Date.now(),N=He(h,_),x=Date.now()-A;p+=E,d+=x,f.push({absPath:h,relPath:b,result:N,parseMs:x,readMs:E,content:_,mtime:S});}catch(S){this.db.recordIndexFailure(b,String(S)),l.errors.push({file:b,error:String(S)});}}this.enhancePreciseRelations(f);for(let m of f){let h=Date.now();try{let b=Me(m.content),S=qe(m.content),y=Buffer.byteLength(m.content,"utf-8"),_=Be(m.result,m.content);this.db.saveParseResult(m.result,m.absPath,m.relPath,b,y,S,m.mtime,_.exportSignatureHash,_.importSignatureHash),l.indexedFiles++,l.totalSymbols+=m.result.symbols.length,m.result.errors?.length&&l.errors.push(...m.result.errors.map(E=>({file:m.relPath,error:E}))),u+=Date.now()-h;}catch(b){this.db.recordIndexFailure(m.relPath,String(b)),l.errors.push({file:m.relPath,error:String(b)});}}}else for(let f=0;f<a.length;f++){let m=a[f],h=de(m,this.projectRoot);e?.onProgress?.(f+1,a.length,h);try{let b=await this.indexFile(m,h,s);b.skipped?l.skippedFiles++:(l.indexedFiles++,l.totalSymbols+=b.symbolCount,p+=b.readMs||0,d+=b.parseMs||0,u+=b.saveMs||0,b.errors?.length&&l.errors.push(...b.errors.map(S=>({file:h,error:S}))));}catch(b){this.db.recordIndexFailure(h,String(b)),l.errors.push({file:h,error:String(b)});}}return l.phaseTimings.readFilesMs=p,l.phaseTimings.parseMs=d,l.phaseTimings.saveToDbMs=u,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.scheduler.configure({maxFiles:n,maxTimeMs:r});let s=this.db.getAllFilePaths(),i=this.db.getReverseDependencyMap(),a=new Set;for(let h of s){let b=this.fileAbsPath(h);if(!Q__default.existsSync(b))continue;let S=this.db.getFileSignatures(h);if(!S){this.scheduler.enqueue(h,"low");continue}let y;try{y=Q__default.statSync(b);let P=this.db.getFileHashAndMtime(h);if(P&&P.mtime===y.mtimeMs&&P.contentHash)continue}catch{continue}let _=Q__default.readFileSync(b,"utf-8"),E=Me(_);if(S.contentHash===E){this.db.updateFileMtime(h,y.mtimeMs);continue}let A=He(b,_),N=Be(A,_),x=Rn(S,N);if(x==="unchanged")continue;let{files:L,truncated:w}=kn(h,x,i);w&&process.stderr.write(`[Frontend-Code-Skimmer] \u26A0\uFE0F ${h} \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
|
|
439
|
+
`);for(let P of L)a.add(P);let M=x==="export_changed"||x==="full_changed"?"high":x==="import_changed"?"normal":"low";for(let P of L)this.scheduler.enqueue(P,M);}let{tasks:c,exceededBudget:l,remainingPending:p}=this.scheduler.dequeueBatch(),d=[],u=[],g=0;for(let h=0;h<c.length;h++){let S=c[h].relPath;if(a.add(S),Date.now()-t>=r){u.push(...c.slice(h));break}let y=this.fileAbsPath(S);if(!Q__default.existsSync(y)){this.removeFile(S);continue}try{let _=Q__default.readFileSync(y,"utf-8"),E=He(y,_),A=Me(_),N=qe(_),x=Buffer.byteLength(_,"utf-8");d.push({absPath:y,relPath:S,result:E,content:_,hash:A,lineCount:N,fileSize:x,mtime:Q__default.statSync(y).mtimeMs});}catch(_){this.db.recordIndexFailure(S,String(_)),process.stderr.write(`[Frontend-Code-Skimmer] Selective precise \u5931\u8D25: ${S} - ${String(_)}
|
|
440
|
+
`);}}u.length>0&&this.scheduler.requeue(u),this.enhancePreciseRelations(d);for(let h of d)try{let b=Be(h.result,h.content);this.db.saveParseResult(h.result,h.absPath,h.relPath,h.hash,h.fileSize,h.lineCount,h.mtime,b.exportSignatureHash,b.importSignatureHash),g++;}catch(b){this.db.recordIndexFailure(h.relPath,String(b)),process.stderr.write(`[Frontend-Code-Skimmer] Selective precise \u843D\u5E93\u5931\u8D25: ${h.relPath} - ${String(b)}
|
|
441
|
+
`);}let f=Date.now()-t,m=p+u.length;return process.stderr.write(`[Frontend-Code-Skimmer] Selective precise: ${g}/${a.size} affected, ${f}ms, pending: ${m}${l||u.length>0?" (budget limited)":""}
|
|
442
|
+
`),{reindexedFiles:g,affectedFiles:Array.from(a),skippedByBudget:m}}async indexFile(e,t,n=false){let r=0,s=0,i=null;if(!n){try{let y=Q__default.statSync(e);r=y.mtimeMs,s=y.size;}catch{}if(i=this.db.getFileMeta(t),i&&i.mtime>0&&i.mtime===r&&!(i.fileSize>0&&i.fileSize!==s))return {skipped:true,symbolCount:0,readMs:0,parseMs:0,saveMs:0}}let a=Date.now(),c=Q__default.readFileSync(e,"utf-8"),l=Date.now()-a,p=Me(c);if(!n&&i&&i.hash===p)return r>0&&i.mtime!==r&&this.db.updateFileMtime(t,r),{skipped:true,symbolCount:0,readMs:l,parseMs:0,saveMs:0};let d=qe(c),u=Buffer.byteLength(c,"utf-8"),g=Date.now(),f=He(e,c),m=Date.now()-g,h=Be(f,c),b=Date.now();this.db.clearIndexFailures(t),this.db.saveParseResult(f,e,t,p,u,d,r,h.exportSignatureHash,h.importSignatureHash);let S=Date.now()-b;return {skipped:false,symbolCount:f.symbols.length,readMs:l,parseMs:m,saveMs:S,errors:f.errors}}removeFile(e){this.db.deleteFile(e);}fileAbsPath(e){return J__default.join(this.projectRoot,e)}async startWatcher(){let{default:e}=await import('chokidar'),t=e.watch([...St].map(r=>J__default.posix.join(this.projectRoot,r)),{cwd:this.projectRoot,ignored:[...Tt],persistent:true,ignoreInitial:true,awaitWriteFinish:{stabilityThreshold:ln}}),n=async r=>{let s=de(r,this.projectRoot);try{await this.indexFile(r,s),this.scheduler.enqueue(s,"normal"),process.stderr.write(`[Frontend-Code-Skimmer] \u5DF2\u66F4\u65B0\u7D22\u5F15: ${s}
|
|
443
|
+
`);}catch(i){process.stderr.write(`[Frontend-Code-Skimmer] \u66F4\u65B0\u5931\u8D25: ${s} - ${String(i)}
|
|
443
444
|
`);}};return t.on("add",n).on("change",n).on("unlink",r=>{let s=de(r,this.projectRoot);this.removeFile(s),process.stderr.write(`[Frontend-Code-Skimmer] \u5DF2\u5220\u9664\u7D22\u5F15: ${s}
|
|
444
|
-
`);}),()=>t.close()}};var
|
|
445
|
+
`);}),()=>t.close()}};var ts=8,ns=30,rs=14,ss=360*60*1e3,ut=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=J__default.join(Qr.homedir(),".frontend-code-skimmer","databases"),Q__default.mkdirSync(this.globalCacheDir,{recursive:true}),this.defaultProject=process.env.SKIMMER_PROJECT||null,this.defaultProject&&(this.defaultProject=J__default.resolve(this.defaultProject)),this.maxOpenProjects=this.parsePositiveInt(process.env.SKIMMER_MAX_OPEN_PROJECTS,ts);let e=this.parsePositiveInt(process.env.SKIMMER_DB_IDLE_MINUTES,ns),t=this.parsePositiveInt(process.env.SKIMMER_DB_TTL_DAYS,rs);this.maxIdleMs=e*60*1e3,this.dbTtlMs=t*24*60*60*1e3,this.maybeCleanupDiskCache(Date.now());}resolveProjectRoot(e){if(e){let t=J__default.resolve(e);if(!Q__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=J__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 Ye(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}
|
|
445
446
|
`),process.stderr.write(`[Frontend-Code-Skimmer] \u6570\u636E\u5E93: ${r}
|
|
446
|
-
`),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=
|
|
447
|
+
`),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=J__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),i=new dt(n,s);return this.indexerCache.set(n,i),this.touchProject(n,r),this.lastProject=n,i}setLastProject(e){this.lastProject=J__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=J__default.resolve(e),r=this.watcherCleanups.get(n);if(r)try{r();}catch{}this.watcherCleanups.set(n,t);}hasWatcher(e){let t=J__default.resolve(e);return this.watcherCleanups.has(t)}closeProject(e){let t=J__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 J__default.resolve(process.env.SKIMMER_DB);let t=J__default.join(e,".agent","skimmer_find_symbol"),n=J__default.join(t,Je);try{return Q__default.mkdirSync(t,{recursive:!0}),Q__default.accessSync(e,Q__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 J__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<ss)return;this.lastDiskCleanupAt=e;let t=[];try{t=Q__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(J__default.resolve(s));let r=e-this.dbTtlMs;for(let s of t){if(!s.isFile()||!s.name.endsWith(".db"))continue;let i=J__default.join(this.globalCacheDir,s.name);if(n.has(J__default.resolve(i)))continue;let a;try{a=Q__default.statSync(i);}catch{continue}a.mtimeMs>=r||(this.safeUnlink(i),this.safeUnlink(`${i}-wal`),this.safeUnlink(`${i}-shm`));}}safeUnlink(e){try{Q__default.existsSync(e)&&Q__default.unlinkSync(e);}catch{}}};var ft=createRequire(import.meta.url);function vn(o,e){let t=[];if(o==="heuristic")return {effective:"heuristic",warnings:t};let n=ft("fs"),r=ft("path");if(!os(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{ft.resolve("typescript",{paths:[e]});}catch{try{ft.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 os(o,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:o,depth:0}];for(;s.length>0;){let i=s.shift();if(!i)break;for(let c of n){let l=t.join(i.dir,c);if(e.existsSync(l))return l}if(i.depth>=3)continue;let a;try{a=e.readdirSync(i.dir,{withFileTypes:!0});}catch{continue}for(let c of a)c.isDirectory()&&(r.has(c.name)||s.push({dir:t.join(i.dir,c.name),depth:i.depth+1}));}return null}function Cn(o,e){o.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
|
|
447
448
|
\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
|
|
448
449
|
\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
|
|
449
450
|
\u591A\u4E2A\u9879\u76EE\u4F1A\u5E76\u884C\u7F13\u5B58\uFF0C\u5207\u6362\u65E0\u9700\u91CD\u542F\u3002
|
|
@@ -454,45 +455,45 @@ import*as z from'path';import z__default from'path';import {fileURLToPath}from'u
|
|
|
454
455
|
- \u5F3A\u5236\u5168\u91CF\u91CD\u5EFA: force=true
|
|
455
456
|
- \u7CBE\u786E\u7CBE\u5EA6\u6A21\u5F0F: precision_mode="precise"\uFF08\u57FA\u4E8E TypeScript Compiler API \u505A\u8DE8\u6587\u4EF6 import/export \u7ED1\u5B9A\uFF09
|
|
456
457
|
|
|
457
|
-
\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$1.object({project_path:z$1.string().describe('\u9879\u76EE\u6839\u76EE\u5F55\u7684\u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u5982 "/Users/xxx/projects/my-app"'),force:z$1.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$1.array(z$1.string()).optional().describe('\u8981\u5305\u542B\u7684\u6587\u4EF6 glob \u6A21\u5F0F\uFF0C\u5982 ["**/*.vue","**/*.tsx"]'),exclude:z$1.array(z$1.string()).optional().describe("\u8981\u989D\u5916\u6392\u9664\u7684 glob \u6A21\u5F0F"),precision_mode:z$1.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$1.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$1.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:
|
|
458
|
-
`);}});e.setLastProject(l);let
|
|
458
|
+
\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$1.object({project_path:z$1.string().describe('\u9879\u76EE\u6839\u76EE\u5F55\u7684\u7EDD\u5BF9\u8DEF\u5F84\uFF0C\u5982 "/Users/xxx/projects/my-app"'),force:z$1.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$1.array(z$1.string()).optional().describe('\u8981\u5305\u542B\u7684\u6587\u4EF6 glob \u6A21\u5F0F\uFF0C\u5982 ["**/*.vue","**/*.tsx"]'),exclude:z$1.array(z$1.string()).optional().describe("\u8981\u989D\u5916\u6392\u9664\u7684 glob \u6A21\u5F0F"),precision_mode:z$1.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$1.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$1.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:i,selective_precise:a,max_precise_files:c})=>{let{projectRoot:l}=e.getContext(t),p=i||"heuristic",{effective:d,warnings:u}=vn(p,l),g=e.getIndexer(l),f=await g.indexProject({include:r,exclude:s,force:n,precisionMode:d,onProgress:(w,M)=>{(w%20===0||w===M)&&process.stderr.write(`[Frontend-Code-Skimmer] \u8FDB\u5EA6: ${w}/${M}
|
|
459
|
+
`);}});e.setLastProject(l);let m=0;try{let w=Date.now(),M=await g.startWatcher();m=Date.now()-w,e.registerWatcher(l,M),process.stderr.write(`[Frontend-Code-Skimmer] \u6587\u4EF6\u76D1\u542C\u5DF2\u542F\u52A8: ${l}
|
|
459
460
|
`);}catch(w){process.stderr.write(`[Frontend-Code-Skimmer] \u6587\u4EF6\u76D1\u542C\u542F\u52A8\u5931\u8D25\uFF08\u7D22\u5F15\u4ECD\u53EF\u7528\uFF09: ${String(w)}
|
|
460
|
-
`);}let h=null;if(a)try{let w=await
|
|
461
|
-
`);}let b=f.indexedFiles>0||f.totalFiles>0,S=f.totalSymbols>0,y=b?"\u2705 \u53EF\u7528":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",_=S?"\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",E=b?"\u2705 \u53EF\u7528":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",A=b?"\u2705 \u53EF\u7528\uFF08\u57FA\u4E8E\u6B63\u5219\u626B\u63CF\u6587\u4EF6\uFF09":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",N=f.phaseTimings,x=N?["","\u23F1\uFE0F \u3010\u9636\u6BB5\u8017\u65F6\u3011",` \u{1F50D} \u6587\u4EF6\u53D1\u73B0: ${N.discoverFilesMs}ms`,` \u{1F4D6} \u6587\u4EF6\u8BFB\u53D6: ${N.readFilesMs}ms`,` \u{1F52C} \u89E3\u6790: ${N.parseMs}ms`,` \u{1F4BE} \u6570\u636E\u5E93\u5199\u5165: ${N.saveToDbMs}ms`,` \u{1F4CA} \u603B\u8BA1: ${N.totalMs}ms`,` \u{1F4E1} \u6587\u4EF6\u76D1\u542C: ${
|
|
462
|
-
\u26A0\uFE0F \u89E3\u6790\u5931\u8D25 (${f.errors.length} \u4E2A):`);for(let w of f.errors.slice(0,5))L.push(` - ${w.file}: ${w.error}`);f.errors.length>5&&L.push(` ... \u8FD8\u6709 ${f.errors.length-5} \u4E2A`);}if(u.length>0){L.push(""),L.push("\u26A0\uFE0F \u7CBE\u5EA6\u964D\u7EA7:");for(let w of u)L.push(` - ${w}`);}if(h){L.push(""),L.push("\u{1F3AF} \u9009\u62E9\u6027 Precise \u91CD\u7B97:"),L.push(` \u{1F4CA} \u91CD\u7B97\u6587\u4EF6: ${h.reindexedFiles}`),L.push(` \u{1F517} \u5F71\u54CD\u6587\u4EF6: ${h.affectedFiles} (\u5019\u9009\u6570)`),h.skippedByBudget>0&&(L.push(` \u23F8\uFE0F \u8D85\u9884\u7B97\u8DF3\u8FC7\u7684\u6587\u4EF6: ${h.skippedByBudget}`),L.push(" \u{1F4A1} \u540E\u7EED watcher \u89E6\u53D1\u6216\u518D\u6B21\u8C03\u7528 selective_precise=true \u7EE7\u7EED"));let w=
|
|
463
|
-
`)}]}});}function
|
|
464
|
-
`)}function
|
|
461
|
+
`);}let h=null;if(a)try{let w=await g.selectivePrecise({maxFiles:c||20});h={reindexedFiles:w.reindexedFiles,affectedFiles:w.affectedFiles.length,skippedByBudget:w.skippedByBudget};}catch(w){process.stderr.write(`[Frontend-Code-Skimmer] Selective precise \u5931\u8D25: ${String(w)}
|
|
462
|
+
`);}let b=f.indexedFiles>0||f.totalFiles>0,S=f.totalSymbols>0,y=b?"\u2705 \u53EF\u7528":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",_=S?"\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",E=b?"\u2705 \u53EF\u7528":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",A=b?"\u2705 \u53EF\u7528\uFF08\u57FA\u4E8E\u6B63\u5219\u626B\u63CF\u6587\u4EF6\uFF09":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",N=f.phaseTimings,x=N?["","\u23F1\uFE0F \u3010\u9636\u6BB5\u8017\u65F6\u3011",` \u{1F50D} \u6587\u4EF6\u53D1\u73B0: ${N.discoverFilesMs}ms`,` \u{1F4D6} \u6587\u4EF6\u8BFB\u53D6: ${N.readFilesMs}ms`,` \u{1F52C} \u89E3\u6790: ${N.parseMs}ms`,` \u{1F4BE} \u6570\u636E\u5E93\u5199\u5165: ${N.saveToDbMs}ms`,` \u{1F4CA} \u603B\u8BA1: ${N.totalMs}ms`,` \u{1F4E1} \u6587\u4EF6\u76D1\u542C: ${m}ms`]:[],L=[`\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: ${f.totalFiles}`,` \u{1F504} \u5DF2\u7D22\u5F15: ${f.indexedFiles}`,` \u23E9 \u5DF2\u8DF3\u8FC7: ${f.skippedFiles} (\u5185\u5BB9\u672A\u53D8)`,` \u{1F523} \u603B\u7B26\u53F7\u6570: ${f.totalSymbols}`,` \u{1F3AF} \u7CBE\u5EA6\u6A21\u5F0F: ${d}`,` \u23F1\uFE0F \u8017\u65F6: ${f.durationMs}ms`,...x,"","\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 ${_}`,` skimmer_get_component_outline ${_}`,` skimmer_find_by_behavior ${E}`,` skimmer_trace_data_lifecycle ${A}`,` skimmer_trace_assignments ${A}`,` skimmer_get_code_slice ${y}`," 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(f.errors.length>0){L.push(`
|
|
463
|
+
\u26A0\uFE0F \u89E3\u6790\u5931\u8D25 (${f.errors.length} \u4E2A):`);for(let w of f.errors.slice(0,5))L.push(` - ${w.file}: ${w.error}`);f.errors.length>5&&L.push(` ... \u8FD8\u6709 ${f.errors.length-5} \u4E2A`);}if(u.length>0){L.push(""),L.push("\u26A0\uFE0F \u7CBE\u5EA6\u964D\u7EA7:");for(let w of u)L.push(` - ${w}`);}if(h){L.push(""),L.push("\u{1F3AF} \u9009\u62E9\u6027 Precise \u91CD\u7B97:"),L.push(` \u{1F4CA} \u91CD\u7B97\u6587\u4EF6: ${h.reindexedFiles}`),L.push(` \u{1F517} \u5F71\u54CD\u6587\u4EF6: ${h.affectedFiles} (\u5019\u9009\u6570)`),h.skippedByBudget>0&&(L.push(` \u23F8\uFE0F \u8D85\u9884\u7B97\u8DF3\u8FC7\u7684\u6587\u4EF6: ${h.skippedByBudget}`),L.push(" \u{1F4A1} \u540E\u7EED watcher \u89E6\u53D1\u6216\u518D\u6B21\u8C03\u7528 selective_precise=true \u7EE7\u7EED"));let w=g.getScheduler().pendingCount;w>0&&L.push(` \u{1F4CB} Pending queue: ${w} \u6587\u4EF6\u5F85\u91CD\u7B97`);}return {content:[{type:"text",text:L.join(`
|
|
464
|
+
`)}]}});}function Ut(o,e,t){try{if(!e||!Q__default.existsSync(e))return {stale:!1};let n=Q__default.statSync(e),r=o.getFileMeta(t);if(!r)return {stale:!1};let s=r.mtime>0&&n.mtimeMs>r.mtime,i=r.fileSize>0&&n.size!==r.fileSize;return s||i?{stale:!0,reason:i?`\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 $n(o,e,t=5){let n=e.slice(0,t),r=[],s=0;for(let i of n){if(!i.abs_path||!Q__default.existsSync(i.abs_path))continue;s++;let{stale:a}=Ut(o,i.abs_path,i.path);a&&r.push(i.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 H(o){return {duration_ms:o.durationMs,result_count:o.resultCount,backend:o.backend,index_freshness:o.indexFreshness,project_count:o.projectCount??1,debug:o.debug,precision_mode_requested:o.precisionRequested,precision_mode_effective:o.precisionEffective,precision_warnings:o.precisionWarnings}}function W(o){let e=[`\u23F1\uFE0F \u8017\u65F6: ${o.duration_ms}ms | \u{1F4CA} \u7ED3\u679C\u6570: ${o.result_count} | \u{1F527} \u540E\u7AEF: ${o.backend}`];if(o.precision_mode_effective){let t=o.precision_mode_effective==="precise"?"\u{1F3AF} \u7CBE\u786E":"\u26A1 \u542F\u53D1\u5F0F",n=o.precision_mode_requested!==o.precision_mode_effective?` (\u8BF7\u6C42: ${o.precision_mode_requested})`:"";e.push(`\u{1F4D0} \u7CBE\u5EA6\u6A21\u5F0F: ${t}${n}`);}if(o.precision_warnings&&o.precision_warnings.length>0)for(let t of o.precision_warnings)e.push(`\u26A0\uFE0F \u7CBE\u5EA6\u8B66\u544A: ${t}`);if(o.index_freshness){let t=o.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(o.debug){if(e.push("\u2500\u2500 \u8C03\u8BD5\u4FE1\u606F \u2500\u2500"),o.debug.phase_timings){e.push("\u9636\u6BB5\u8017\u65F6:");for(let[t,n]of Object.entries(o.debug.phase_timings))e.push(` ${t}: ${n}ms`);}o.debug.query_plan&&e.push(`\u67E5\u8BE2\u8BA1\u5212: ${o.debug.query_plan}`),o.debug.candidate_count!==void 0&&e.push(`\u5019\u9009\u6570: ${o.debug.candidate_count}`),o.debug.scanned_files!==void 0&&e.push(`\u626B\u63CF\u6587\u4EF6\u6570: ${o.debug.scanned_files}`),o.debug.fallback_reason&&e.push(`\u964D\u7EA7\u539F\u56E0: ${o.debug.fallback_reason}`);}return e.join(`
|
|
465
|
+
`)}function In(o,e){o.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
|
|
465
466
|
\u5305\u542B: props\u3001data/state\u3001computed\u3001methods/functions\u3001watch/effect\u3001lifecycle\u3001\u884C\u4E3A\u6807\u7B7E\u3002
|
|
466
467
|
\u884C\u4E3A\u6807\u7B7E\u81EA\u52A8\u6807\u51FA: [storage:localStorage.setItem] [network:axios.get] \u7B49\u3002
|
|
467
468
|
|
|
468
469
|
project_path \u53EF\u7701\u7565\uFF08\u4F7F\u7528\u4E0A\u6B21 skimmer_index_project \u6307\u5B9A\u7684\u9879\u76EE\uFF09\u3002
|
|
469
|
-
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$1.object({file_path:z$1.string().describe('\u6587\u4EF6\u76F8\u5BF9\u8DEF\u5F84\uFF0C\u5982 "src/views/apply/index.vue"'),project_path:z$1.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$1.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:
|
|
470
|
+
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$1.object({file_path:z$1.string().describe('\u6587\u4EF6\u76F8\u5BF9\u8DEF\u5F84\uFF0C\u5982 "src/views/apply/index.vue"'),project_path:z$1.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$1.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:i}=e.getContext(n),{file:a,symbols:c,behaviors:l}=i.getFileOutline(t);if(!a){let _=Math.round((performance.now()-s)*100)/100,E=H({durationMs:_,resultCount:0,backend:"indexed"});return {content:[{type:"text",text:`\u274C \u6587\u4EF6\u672A\u7D22\u5F15: ${t}
|
|
470
471
|
|
|
471
472
|
\u8BF7\u5148\u8FD0\u884C:
|
|
472
473
|
skimmer_index_project({ project_path: "${n||"<\u9879\u76EE\u8DEF\u5F84>"}" })
|
|
473
474
|
|
|
474
475
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
475
|
-
${
|
|
476
|
-
\u26A0\uFE0F [\u7D22\u5F15\u5DF2\u8FC7\u671F] ${
|
|
476
|
+
${W(E)}`}]}}let p="",d=a.abs_path,{stale:u,reason:g}=Ut(i,d,t);u&&(p=`
|
|
477
|
+
\u26A0\uFE0F [\u7D22\u5F15\u5DF2\u8FC7\u671F] ${g||""}\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
|
|
477
478
|
\u7ACB\u5373\u91CD\u5EFA: skimmer_index_project({ force: true })
|
|
478
|
-
`);let f=new Map;for(let _ of l){let E=_.symbol_id;f.has(E)||f.set(E,[]);let A=`[${_.category}:${_.api_name}.${_.operation}${_.detail?`("${_.detail}")`:""}]`,N=f.get(E);N.includes(A)||N.push(A);}let
|
|
479
|
-
${E} ${A} (${N.length}):`);for(let x of N){let L=x.name,w=
|
|
480
|
-
${"\u2500".repeat(50)}`),
|
|
479
|
+
`);let f=new Map;for(let _ of l){let E=_.symbol_id;f.has(E)||f.set(E,[]);let A=`[${_.category}:${_.api_name}.${_.operation}${_.detail?`("${_.detail}")`:""}]`,N=f.get(E);N.includes(A)||N.push(A);}let m=[];m.push(`\u{1F4C4} ${t} (${a.line_count} \u884C, ${a.framework})`),m.push(`${"\u2501".repeat(50)}`),p&&m.push(p);let h={};for(let _ of c){if(_.name==="<template>")continue;let E=_.category;h[E]||(h[E]=[]),h[E].push(_);}let b=[{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:_,icon:E,label:A}of b){let N=h[_];if(N?.length){m.push(`
|
|
480
|
+
${E} ${A} (${N.length}):`);for(let x of N){let L=x.name,w=ke(x.start_line,x.end_line),M=je(x.params_json,[]),P=M.length>0?`(${M.join(", ")})`:"",B=x.default_value?` = ${x.default_value}`:"",ce=x.is_async?"async ":"",ye=f.get(x.id),Ae=ye?.length?` ${ye.slice(0,3).join(" ")}`:"",Y=x.state_setter_name?` \u2192 ${x.state_setter_name}`:"",le=x.hook_deps_json?` [deps:${je(x.hook_deps_json,[]).join(",")}]`:"";m.push(` \u2022 ${ce}${L}${P}${B}${Y}${le} ${w}${Ae}`);}}}m.push(`
|
|
481
|
+
${"\u2500".repeat(50)}`),m.push(`\u{1F4A1} \u67E5\u770B\u5177\u4F53\u4EE3\u7801: skimmer_get_code_slice({ file_path: "${t}", symbol_name: "\u65B9\u6CD5\u540D" })`);let S=Math.round((performance.now()-s)*100)/100,y=H({durationMs:S,resultCount:c.length,backend:"indexed"});return r&&(y.debug={scanned_files:1}),m.push(`
|
|
481
482
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
482
|
-
${
|
|
483
|
-
`)}]}});}var Xe=class{constructor(e){this.db=e;}db;search(e,t){let{category:n,framework:r,filePath:s,limit:
|
|
484
|
-
`);for(let
|
|
485
|
-
`).length;return [{content:t[1],lineOffset:r}]}function _e(
|
|
483
|
+
${W(y)}`),{content:[{type:"text",text:m.join(`
|
|
484
|
+
`)}]}});}var Xe=class{constructor(e){this.db=e;}db;search(e,t){let{category:n,framework:r,filePath:s,limit:i=an,fuzzy:a=true,allowFallbackScan:c=false,debug:l=false}=t||{},p=e.trim(),d=new Map,u={},g=performance.now(),f=this.db.exactSearch(p,n,r,s);for(let A of f)d.set(A.id,{symbol:A,filePath:A.file_path,score:100,matchReason:"\u7CBE\u786E\u5339\u914D"});if(u["1_exact"]=Math.round((performance.now()-g)*100)/100,d.size>=i)return {results:this.rankResults(d,i)};let m=performance.now(),h=0,b=k(p),S=[p,b,...b.split(" ")].filter(Boolean).filter((A,N,x)=>x.indexOf(A)===N);for(let A of S){if(A.length<2)continue;let N=this.db.ftsSearch(A,n,r,s,i);h+=N.length;for(let x of N){let L=x.id;if(d.has(L))continue;let w=this.calcFtsScore(p,x.name);d.set(L,{symbol:x,filePath:x.file_path,score:w,matchReason:`FTS5 \u524D\u7F00\u5339\u914D ("${A}")`});}}if(u["2_fts"]=Math.round((performance.now()-m)*100)/100,d.size>=i)return {results:this.rankResults(d,i),debug:l?{phase_timings:u,candidate_count:h}:void 0};let y=a&&p.length>=3,_=0;if(y){let A=performance.now(),N=this.db.getAllSymbolNames(s),x=p.toLowerCase(),L=k(p).split(" ");for(let{name:w,file_path:M,id:P}of N){if(d.has(P))continue;_++;let B=Ge(x,w.toLowerCase()),ce=Math.max(x.length,w.length),ye=Math.min(cn,Math.max(1,Math.floor(ce*.28)));if(B<=ye){let le=Math.max(0,80-B*15),X=this.db.getSymbolById(P);if(!X||n&&X.category!==n||r&&X.framework!==r)continue;let se=Qt(p,w,B);d.set(P,{symbol:X,filePath:M,score:le,matchReason:`\u6A21\u7CCA\u5339\u914D (\u7F16\u8F91\u8DDD\u79BB=${B})`,spellingSuggestion:se});continue}let Ae=k(w).split(" "),Y=L.filter(le=>Ae.some(X=>Zt(le,X)>=75));if(Y.length>0&&Y.length>=Math.ceil(L.length*.5)){let le=50+Y.length*10,X=this.db.getSymbolById(P);if(!X||n&&X.category!==n||r&&X.framework!==r)continue;d.set(P,{symbol:X,filePath:M,score:le,matchReason:`\u5355\u8BCD\u5339\u914D (${Y.join(", ")})`});}}u["3_fuzzy"]=Math.round((performance.now()-A)*100)/100;}if(d.size===0&&c){let A=performance.now(),N=this.db.ftsSearchWithFallback(p,n,r,s,i);for(let x of N){let L=x.id;d.has(L)||d.set(L,{symbol:x,filePath:x.file_path,score:50,matchReason:"LIKE \u5168\u8868\u626B\u63CF fallback"});}u["4_fallback"]=Math.round((performance.now()-A)*100)/100;}let E=l?{phase_timings:u,candidate_count:h+_,fallback_reason:!y&&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(d,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=k(e).split(" "),i=k(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 Mn=createRequire(import.meta.url),Ee="\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 Ke(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function $e(o,e,t){let n=[];for(let r of o){if(!r?.abs_path||!Q__default.existsSync(r.abs_path))continue;let s=Q__default.readFileSync(r.abs_path,"utf-8").split(`
|
|
485
|
+
`);for(let i=0;i<s.length;i++){let a=s[i];for(let c of e)if(c.regex.test(a)){n.push({filePath:r.path,line:i+1,kind:c.kind,text:a.trim()});break}if(n.length>=t)return n}}return n}function Pn(o,e){let t=Ke(o),n="(?:=|\\+=|-=|\\*=|/=|%=|\\|=|&=|\\^=|&&=|\\|\\|=|\\?\\?=)",r=[{kind:"declaration",regex:new RegExp(`\\b(?:const|let|var)\\s+${t}\\b`)},{kind:"assignment",regex:new RegExp(`\\b${t}\\b\\s*${n}`)},{kind:"update",regex:new RegExp(`(?:\\+\\+|--)\\s*\\b${t}\\b|\\b${t}\\b\\s*(?:\\+\\+|--)`)}];return e&&r.push({kind:"property_assignment",regex:new RegExp(`\\b${t}\\.[A-Za-z_$][\\w$]*\\s*${n}`)},{kind:"indexed_assignment",regex:new RegExp(`\\b${t}\\s*\\[[^\\]]+\\]\\s*${n}`)}),r}function bt(o){try{return Mn("@babel/parser").parse(o,{sourceType:"module",plugins:["typescript","jsx","decorators-legacy"],errorRecovery:!0})}catch{return null}}function Et(o,e){if(!o.endsWith(".vue"))return [{content:e,lineOffset:1}];try{let{parse:s}=Mn("@vue/compiler-sfc"),{descriptor:i}=s(e),a=[];if(i.script?.content&&a.push({content:i.script.content,lineOffset:i.script.loc.start.line}),i.scriptSetup?.content&&a.push({content:i.scriptSetup.content,lineOffset:i.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(`
|
|
486
|
+
`).length;return [{content:t[1],lineOffset:r}]}function _e(o,e){return (o.loc?.start?.line??1)+e-1}function Xt(o,e){if(o.type!=="MemberExpression")return false;let t=o.object;return !t||t.type!=="ThisExpression"?false:q(o)===e}function Wt(o,e){return !!o&&o.type==="Identifier"&&String(o.name||"")===e}function jn(o){let e=new Set;return o.filter(t=>{let n=`${t.filePath}:${t.line}:${t.kind}:${t.text}`;return e.has(n)?false:(e.add(n),true)})}function Ht(o,e,t=2){if(!Q__default.existsSync(o))return {snippet:"",startLine:e};let n=Q__default.readFileSync(o,"utf-8").split(`
|
|
486
487
|
`),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(`
|
|
487
|
-
`),startLine:r+1}}function
|
|
488
|
-
`),a=
|
|
489
|
-
`),a=
|
|
490
|
-
`),c=
|
|
491
|
-
`),c=
|
|
488
|
+
`),startLine:r+1}}function gt(o,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}[o]??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 On={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 Fn(o,e,t){let n=[];for(let r of o){if(!r.abs_path||!Q__default.existsSync(r.abs_path))continue;let s=Q__default.readFileSync(r.abs_path,"utf-8"),i=s.split(`
|
|
489
|
+
`),a=Et(r.path||J__default.basename(r.abs_path),s);for(let c of a){let l=bt(c.content);l&&me(l,p=>{if(n.length>=t||p.type!=="VariableDeclarator")return;let d=p.id;if(!d||d.type!=="Identifier")return;let u=String(d.name||"");if(!u||u===e)return;let g=p.init;if(!g)return;let f=false;if(g.type==="Identifier"&&String(g.name||"")===e?f=true:g.type==="MemberExpression"&&(f=Xt(g,e)||q(g)===e),!f)return;let m=_e(p,c.lineOffset),h=i[m-1]?.trim()||"";n.push({alias:u,filePath:r.path,abs_path:r.abs_path,line:m,text:h});});}}return n}function Dn(o,e,t){let n=[];for(let r of o){if(!r.abs_path||!Q__default.existsSync(r.abs_path))continue;let s=Q__default.readFileSync(r.abs_path,"utf-8"),i=s.split(`
|
|
490
|
+
`),a=Et(r.path||J__default.basename(r.abs_path),s);for(let c of a){let l=bt(c.content);l&&me(l,p=>{if(n.length>=t||p.type!=="VariableDeclarator")return;let d=p.id;if(!d||d.type!=="ObjectPattern")return;let u=d.properties||[];for(let g of u){if(g.type!=="ObjectProperty"&&g.type!=="Property")continue;let f=g.key,m=g.value,h=f?.type==="Identifier"?String(f.name||""):null;if(h!==e)continue;let b=m?.type==="Identifier"?String(m.name||""):h;if(!b)continue;let S=_e(p,c.lineOffset),y=i[S-1]?.trim()||"";n.push({alias:b,filePath:r.path,line:S,text:y});}});}}return n}function Bt(o,e,t,n){let r=[];for(let s of o){if(!s.abs_path||!Q__default.existsSync(s.abs_path))continue;let i=Q__default.readFileSync(s.abs_path,"utf-8"),a=i.split(`
|
|
491
|
+
`),c=Et(s.path||J__default.basename(s.abs_path),i);for(let l of c){let p=bt(l.content);if(p&&(me(p,d=>{if(!(r.length>=n)){if(d.type==="VariableDeclarator"){let u=d.id;if(Wt(u,e)){let g=_e(d,l.lineOffset);r.push({filePath:s.path,line:g,kind:"declaration",text:a[g-1]?.trim()||""});}}if(d.type==="AssignmentExpression"){let u=d.left;if(!u)return;let g=_e(d,l.lineOffset);if(Wt(u,e)||Xt(u,e)){r.push({filePath:s.path,line:g,kind:"assignment",text:a[g-1]?.trim()||""});return}t&&u.type==="MemberExpression"&&te(u)===e&&r.push({filePath:s.path,line:g,kind:u.computed?"indexed_assignment":"property_assignment",text:a[g-1]?.trim()||""});}if(d.type==="UpdateExpression"){let u=d.argument;if(!u)return;if(Wt(u,e)||Xt(u,e)){let g=_e(d,l.lineOffset);r.push({filePath:s.path,line:g,kind:"update",text:a[g-1]?.trim()||""});}}}}),r.length>=n))break}if(r.length>=n)break}return jn(r).slice(0,n)}function ht(o,e,t,n){let r=[];for(let s of o){if(!s.abs_path||!Q__default.existsSync(s.abs_path))continue;let i=Q__default.readFileSync(s.abs_path,"utf-8"),a=i.split(`
|
|
492
|
+
`),c=Et(s.path||J__default.basename(s.abs_path),i);for(let l of c){let p=bt(l.content);if(p&&(me(p,d=>{if(!(r.length>=n)){if(d.type==="AssignmentExpression"){let u=d.left;if(!u||u.type!=="MemberExpression"||te(u)!==e)return;let f=q(u);if(t&&f!==t)return;let m=_e(d,l.lineOffset);r.push({filePath:s.path,line:m,kind:u.computed?"bracket":"dot",text:a[m-1]?.trim()||""});}if(d.type==="UpdateExpression"){let u=d.argument;if(!u||u.type!=="MemberExpression"||te(u)!==e)return;let f=q(u);if(t&&f!==t)return;let m=_e(d,l.lineOffset);r.push({filePath:s.path,line:m,kind:u.computed?"bracket":"dot",text:a[m-1]?.trim()||""});}if(d.type==="UnaryExpression"&&d.operator==="delete"){let u=d.argument;if(!u||u.type!=="MemberExpression"||te(u)!==e)return;let f=q(u);if(t&&f!==t)return;let m=_e(d,l.lineOffset);r.push({filePath:s.path,line:m,kind:"delete",text:a[m-1]?.trim()||""});}}}),r.length>=n))break}if(r.length>=n)break}return jn(r).slice(0,n)}function Un(o,e){o.registerTool("skimmer_find_symbol",{title:"\u667A\u80FD\u7B26\u53F7\u641C\u7D22\uFF08\u652F\u6301\u62FC\u5199\u9519\u8BEF\uFF09",description:`\u4E09\u5C42\u641C\u7D22\uFF1A\u7CBE\u786E\u5339\u914D \u2192 FTS5\u5168\u6587 \u2192 Levenshtein\u6A21\u7CCA\u3002
|
|
492
493
|
\u89E3\u51B3\u62FC\u5199\u9519\u8BEF\uFF1A\u641C "changeCash" \u80FD\u627E\u5230 "changeCashValue"\uFF0C\u5E76\u63D0\u793A "cash \u53EF\u80FD\u662F cache \u7684\u62FC\u5199\u9519\u8BEF"\u3002
|
|
493
494
|
\u9A7C\u5CF0\u62C6\u8BCD\uFF1A\u641C "change cache" \u4E5F\u80FD\u627E\u5230 "changeCacheValue"\u3002
|
|
494
495
|
\u6846\u67B6\u611F\u77E5\uFF1A\u53EF\u6309 vue2/vue3/react \u8FC7\u6EE4\u3002
|
|
495
|
-
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({query:z$1.string().describe('\u641C\u7D22\u8BCD\uFF0C\u5982 "changeCash" \u6216 "handle submit"'),project_path:z$1.string().optional().describe(Ee),category:z$1.enum(["state","computed","method","effect","prop","lifecycle","hook","component","mixin","function","all"]).optional().default("all").describe("\u7B26\u53F7\u7C7B\u578B\u8FC7\u6EE4"),framework:z$1.enum(["vue2","vue3","react","all"]).optional().default("all"),file_path:z$1.string().optional().describe('\u9650\u5B9A\u6587\u4EF6\u8DEF\u5F84\u641C\u7D22\uFF08\u5305\u542B\u5373\u53EF\uFF0C\u5982 "index.vue"\uFF09'),fuzzy:z$1.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$1.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$1.boolean().optional().default(false).describe("\u662F\u5426\u8F93\u51FA\u5404\u9636\u6BB5\u8017\u65F6\u548C\u5019\u9009\u6570"),limit:z$1.number().optional().default(15)}),annotations:{readOnlyHint:true,destructiveHint:false}},async({query:t,project_path:n,category:r,framework:s,file_path:
|
|
496
|
+
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({query:z$1.string().describe('\u641C\u7D22\u8BCD\uFF0C\u5982 "changeCash" \u6216 "handle submit"'),project_path:z$1.string().optional().describe(Ee),category:z$1.enum(["state","computed","method","effect","prop","lifecycle","hook","component","mixin","function","all"]).optional().default("all").describe("\u7B26\u53F7\u7C7B\u578B\u8FC7\u6EE4"),framework:z$1.enum(["vue2","vue3","react","all"]).optional().default("all"),file_path:z$1.string().optional().describe('\u9650\u5B9A\u6587\u4EF6\u8DEF\u5F84\u641C\u7D22\uFF08\u5305\u542B\u5373\u53EF\uFF0C\u5982 "index.vue"\uFF09'),fuzzy:z$1.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$1.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$1.boolean().optional().default(false).describe("\u662F\u5426\u8F93\u51FA\u5404\u9636\u6BB5\u8017\u65F6\u548C\u5019\u9009\u6570"),limit:z$1.number().optional().default(15)}),annotations:{readOnlyHint:true,destructiveHint:false}},async({query:t,project_path:n,category:r,framework:s,file_path:i,fuzzy:a,allow_fallback_scan:c,debug:l,limit:p})=>{let d=performance.now(),{db:u}=e.getContext(n),g=new Xe(u),{results:f,debug:m}=g.search(t,{category:r==="all"?void 0:r,framework:s==="all"?void 0:s,filePath:i,fuzzy:a,limit:p,allowFallbackScan:c,debug:l}),h=Math.round((performance.now()-d)*100)/100,b=H({durationMs:h,resultCount:f.length,backend:"indexed",debug:l?m:void 0});if(f.length===0)return {content:[{type:"text",text:`\u{1F50D} \u641C\u7D22 "${t}" \u65E0\u7ED3\u679C
|
|
496
497
|
|
|
497
498
|
\u{1F4A1} \u5C1D\u8BD5:
|
|
498
499
|
skimmer_find_by_behavior \u6309\u884C\u4E3A\u641C\u7D22
|
|
@@ -500,74 +501,74 @@ project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({query:z$1.string(
|
|
|
500
501
|
\u{1F4A1} \u5C1D\u8BD5: skimmer_find_symbol({ allow_fallback_scan: true }) \u542F\u7528\u5168\u8868\u626B\u63CF`}
|
|
501
502
|
|
|
502
503
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
503
|
-
${
|
|
504
|
-
`];return f.forEach((y,_)=>{let E=y.symbol,A=je(E.params_json,[]),N=A.length>0?`(${A.join(", ")})`:"",x=
|
|
505
|
-
${
|
|
506
|
-
`)}]}}),
|
|
504
|
+
${W(b)}`}]};let S=[`\u{1F50D} \u641C\u7D22 "${t}" \u2014 \u627E\u5230 ${f.length} \u4E2A\u7ED3\u679C
|
|
505
|
+
`];return f.forEach((y,_)=>{let E=y.symbol,A=je(E.params_json,[]),N=A.length>0?`(${A.join(", ")})`:"",x=ke(E.start_line,E.end_line);S.push(`${_+1}. ${E.name}${N} [${E.category}/${E.framework}] \u5339\u914D\u5EA6: ${y.score}%`),S.push(` \u{1F4C4} ${y.filePath}:${x}`),S.push(` \u{1F3AF} ${y.matchReason}`),y.spellingSuggestion&&S.push(` \u{1F4A1} ${y.spellingSuggestion}`),E.default_value&&S.push(` \u{1F4CC} \u9ED8\u8BA4\u503C: ${E.default_value}`),S.push("");}),S.push(`\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
506
|
+
${W(b)}`),{content:[{type:"text",text:S.join(`
|
|
507
|
+
`)}]}}),o.registerTool("skimmer_get_code_slice",{title:"\u83B7\u53D6\u7CBE\u51C6\u4EE3\u7801\u7247\u6BB5",description:`\u8FD4\u56DE\u6307\u5B9A\u51FD\u6570/\u53D8\u91CF\u7684\u5B8C\u6574\u4EE3\u7801\uFF0C\u907F\u514D\u8BFB\u53D6\u5927\u6587\u4EF6\u6D6A\u8D39 Token\u3002
|
|
507
508
|
\u540C\u65F6\u8FD4\u56DE\u8BE5\u7B26\u53F7\u7684\u884C\u4E3A\u6807\u7B7E\uFF08\u64CD\u4F5C\u4E86\u54EA\u4E9B\u5916\u90E8 API\uFF09\u3002
|
|
508
|
-
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({file_path:z$1.string().describe("\u6587\u4EF6\u76F8\u5BF9\u8DEF\u5F84\uFF08\u76F8\u5BF9\u4E8E\u9879\u76EE\u6839\u76EE\u5F55\uFF09"),symbol_name:z$1.string().describe("\u51FD\u6570\u6216\u53D8\u91CF\u540D"),project_path:z$1.string().optional().describe(Ee),context_lines:z$1.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
|
|
509
|
+
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({file_path:z$1.string().describe("\u6587\u4EF6\u76F8\u5BF9\u8DEF\u5F84\uFF08\u76F8\u5BF9\u4E8E\u9879\u76EE\u6839\u76EE\u5F55\uFF09"),symbol_name:z$1.string().describe("\u51FD\u6570\u6216\u53D8\u91CF\u540D"),project_path:z$1.string().optional().describe(Ee),context_lines:z$1.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 i=performance.now(),{db:a}=e.getContext(r),c=a.getSymbolByName(n,t);if(!c){let x=Math.round((performance.now()-i)*100)/100,L=H({durationMs:x,resultCount:0,backend:"indexed"});return {content:[{type:"text",text:`\u274C \u672A\u627E\u5230: ${n}
|
|
509
510
|
\u{1F4C4} \u6587\u4EF6: ${t}
|
|
510
511
|
|
|
511
512
|
\u{1F4A1} \u8BD5\u8BD5: skimmer_find_symbol({ query: "${n}" })
|
|
512
513
|
|
|
513
514
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
514
|
-
${
|
|
515
|
-
`),u=Math.max(1,c.start_line-s)-1,
|
|
515
|
+
${W(L)}`}]}}let l=c.abs_path;if(!Q__default.existsSync(l))return {content:[{type:"text",text:`\u274C \u6587\u4EF6\u4E0D\u5B58\u5728: ${l}`}]};let d=Q__default.readFileSync(l,"utf-8").split(`
|
|
516
|
+
`),u=Math.max(1,c.start_line-s)-1,g=Math.min(d.length,c.end_line+s),f=d.slice(u,g).join(`
|
|
516
517
|
`),h=f.includes(n)?"":`
|
|
517
518
|
\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
|
|
518
519
|
\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
|
|
519
520
|
\u5EFA\u8BAE: skimmer_index_project({ force: true })
|
|
520
|
-
`,{behaviors:b}=a.getFileOutline(t),S=b.filter(x=>x.symbol_id===c.id),y=l.split(".").pop()||"js",_=["tsx","jsx"].includes(y)?"jsx":["ts"].includes(y)?"typescript":"javascript",E=[`\u{1F4CD} ${c.name} [${c.category}/${c.framework}]`,`\u{1F4C4} ${t}:${
|
|
521
|
-
\`\`\`${_}`),E.push(f),E.push("```");let A=Math.round((performance.now()-
|
|
521
|
+
`,{behaviors:b}=a.getFileOutline(t),S=b.filter(x=>x.symbol_id===c.id),y=l.split(".").pop()||"js",_=["tsx","jsx"].includes(y)?"jsx":["ts"].includes(y)?"typescript":"javascript",E=[`\u{1F4CD} ${c.name} [${c.category}/${c.framework}]`,`\u{1F4C4} ${t}:${ke(c.start_line,c.end_line)}`];if(h&&E.push(h),c.jsdoc&&E.push(`\u{1F4DD} ${c.jsdoc}`),S.length>0){let x=[...new Set(S.map(L=>`[${L.category}:${L.api_name}.${L.operation}${L.detail?`("${L.detail}")`:""}]`))];E.push(`\u{1F3F7}\uFE0F \u884C\u4E3A: ${x.join(" ")}`);}E.push(`
|
|
522
|
+
\`\`\`${_}`),E.push(f),E.push("```");let A=Math.round((performance.now()-i)*100)/100,N=H({durationMs:A,resultCount:1,backend:"indexed"});return E.push(`
|
|
522
523
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
523
|
-
${
|
|
524
|
-
`)}]}}),
|
|
524
|
+
${W(N)}`),{content:[{type:"text",text:E.join(`
|
|
525
|
+
`)}]}}),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
|
|
525
526
|
\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
|
|
526
527
|
\u2705 \u672C\u5DE5\u5177\u9002\u5408\uFF1Aloading / errorMsg / count \u8FD9\u7C7B\u7B80\u5355 flag \u7684\u8D4B\u503C\u8FFD\u8E2A\u3002
|
|
527
|
-
\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(Ee),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:
|
|
528
|
+
\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(Ee),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)),d=s??true,u=c.exactSearch(t,"state",void 0,r||void 0),g={vue2:"Vue2 data()",vue3:"Vue3 ref/reactive",react:"React useState/useRef"},f=u.filter(E=>E.default_value!=null).map(E=>({filePath:E.file_path,line:E.start_line,kind:`data_init(${g[E.framework]||E.framework})`,text:`${E.name}: ${E.default_value} \u2190 \u58F0\u660E\u521D\u59CB\u5316`})),m=Bt(l,t,d,p);if(m.length===0){let E=Pn(t,d);m=$e(l,E,p);}let h=new Map;for(let E of [...f,...m]){let A=`${E.filePath}:${E.line}`;h.has(A)||h.set(A,E);}let b=[...h.values()],S=Math.round((performance.now()-a)*100)/100;if(b.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}"
|
|
528
529
|
\u672A\u627E\u5230\u5339\u914D\u8D4B\u503C\u8BED\u53E5\uFF08\u5305\u62EC\u58F0\u660E\u521D\u59CB\u5316\uFF09
|
|
529
530
|
\u8FC7\u6EE4: file_path=${r||"*"} include_properties=${d}
|
|
530
531
|
|
|
531
532
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
532
|
-
${
|
|
533
|
+
${W(E)}`}]}}let y=[`\u{1F9E9} \u53D8\u91CF\u8D4B\u503C\u8FFD\u8E2A: "${t}"`,`\u8FC7\u6EE4: file_path=${r||"*"} include_properties=${d}`,`\u547D\u4E2D: ${b.length} \u5904${f.length>0?`\uFF08\u542B ${f.length} \u5904\u58F0\u660E\u521D\u59CB\u5316\uFF09`:""}`,""];b.forEach((E,A)=>{y.push(`${A+1}. [${E.kind}] \u{1F4C4} ${E.filePath}:L${E.line}`),y.push(` ${E.text}`);});let _=H({durationMs:S,resultCount:b.length,backend:"ast_scan"});return y.push(`
|
|
533
534
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
534
|
-
${
|
|
535
|
-
`)}]}}),
|
|
535
|
+
${W(_)}`),{content:[{type:"text",text:y.join(`
|
|
536
|
+
`)}]}}),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
|
|
536
537
|
\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
|
|
537
538
|
\u2705 \u672C\u5DE5\u5177\u9002\u5408\uFF1Aobject.specificProp \u7684\u5355\u5B57\u6BB5\u7EA7\u522B\u7CBE\u786E\u8FFD\u8E2A\u3002
|
|
538
|
-
\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(Ee),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:
|
|
539
|
-
\u522B\u540D\u5C55\u5F00: ${
|
|
539
|
+
\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(Ee),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)),d=Fn(l,t,20),u=Dn(l,t,20),g=[...new Set([...d.map(y=>y.alias),...u.map(y=>y.alias)].filter(y=>y!==t))],f=[t,...g],m=ht(l,t,n,p);for(let y of g)m.push(...ht(l,y,n,Math.floor(p/2)));if(m.length===0){let y="(?:=|\\+=|-=|\\*=|/=|%=|\\|=|&=|\\^=|&&=|\\|\\|=|\\?\\?=)",_=[];for(let E of f){let A=Ke(E);if(n){let N=Ke(n);_.push({kind:"dot",regex:new RegExp(`\\b${A}\\.${N}\\s*${y}`)},{kind:"bracket",regex:new RegExp(`\\b${A}\\s*\\[(?:'${N}'|"${N}")\\]\\s*${y}`)},{kind:"delete",regex:new RegExp(`\\bdelete\\s+${A}\\.(?:${N})\\b`)});}else _.push({kind:"dot",regex:new RegExp(`\\b${A}\\.[A-Za-z_$][\\w$]*\\s*${y}`)},{kind:"bracket",regex:new RegExp(`\\b${A}\\s*\\[(?:'[^']+'|"[^"]+")\\]\\s*${y}`)},{kind:"delete",regex:new RegExp(`\\bdelete\\s+${A}\\.[A-Za-z_$][\\w$]*\\b`)});}m=$e(l,_,p);}let h=Math.round((performance.now()-a)*100)/100;if(m.length===0){let y=g.length>0?`
|
|
540
|
+
\u522B\u540D\u5C55\u5F00: ${g.join(", ")}\uFF08\u5747\u672A\u547D\u4E2D\uFF09`:"",_=H({durationMs:h,resultCount:0,backend:"ast_scan"});return {content:[{type:"text",text:`\u{1F9ED} \u5C5E\u6027\u4FEE\u6539\u8FFD\u8E2A: ${t}${n?`.${n}`:".*"}
|
|
540
541
|
\u672A\u627E\u5230\u5339\u914D\u8BED\u53E5${y}
|
|
541
542
|
\u8FC7\u6EE4: file_path=${s||"*"}
|
|
542
543
|
|
|
543
544
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
544
|
-
${
|
|
545
|
+
${W(_)}`}]}}let b=[`\u{1F9ED} \u5C5E\u6027\u4FEE\u6539\u8FFD\u8E2A: ${t}${n?`.${n}`:".*"}`,`\u8FC7\u6EE4: file_path=${s||"*"}`];if(g.length>0){let y=d.map(E=>E.alias).filter(E=>E!==t).join(", "),_=u.map(E=>E.alias).filter(E=>E!==t).join(", ");y&&b.push(`\u26A1 \u5F15\u7528\u522B\u540D: ${y}\uFF08\u901A\u8FC7 let alias = this.${t} \u5C55\u5F00\uFF09`),_&&b.push(`\u26A1 \u89E3\u6784\u522B\u540D: ${_}\uFF08\u901A\u8FC7 const { ${t}: alias } \u5C55\u5F00\uFF09`);}b.push(`\u547D\u4E2D: ${m.length} \u5904`,""),m.forEach((y,_)=>{b.push(`${_+1}. [${y.kind}] \u{1F4C4} ${y.filePath}:L${y.line}`),b.push(` ${y.text}`);});let S=H({durationMs:h,resultCount:m.length,backend:"ast_scan"});return b.push(`
|
|
545
546
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
546
|
-
${
|
|
547
|
-
`)}]}}),
|
|
547
|
+
${W(S)}`),{content:[{type:"text",text:b.join(`
|
|
548
|
+
`)}]}}),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
|
|
548
549
|
\u793A\u4F8B:
|
|
549
550
|
- \u627E\u6240\u6709\u64CD\u4F5C localStorage \u7684\u51FD\u6570: { category: "storage" }
|
|
550
551
|
- \u627E\u5199\u5165 localStorage \u7684: { api_name: "localStorage", operation: "setItem" }
|
|
551
552
|
- \u627E\u53D1\u8BF7\u6C42\u7684: { category: "network" }
|
|
552
553
|
- \u627E\u8DEF\u7531\u8DF3\u8F6C\u7684: { category: "router" }
|
|
553
554
|
- \u6309 key \u540D\u641C\u7D22: { keyword: "cacheData" }
|
|
554
|
-
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({project_path:z$1.string().optional().describe(Ee),category:z$1.enum(["storage","network","router","vuex","dom","event","timer","i18n"]).optional().describe("\u884C\u4E3A\u7C7B\u522B"),api_name:z$1.string().optional().describe('"localStorage" / "axios" / "$router"'),operation:z$1.string().optional().describe('"setItem" / "get" / "push" / "commit"'),keyword:z$1.string().optional().describe('\u5728\u53C2\u6570\u503C\u4E2D\u641C\u7D22\uFF08\u5982 key \u540D "cacheData"\uFF09'),file_path:z$1.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:
|
|
555
|
-
\u8FC7\u6EE4\u6761\u4EF6: ${JSON.stringify({category:n,api_name:r,operation:s,keyword:
|
|
555
|
+
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({project_path:z$1.string().optional().describe(Ee),category:z$1.enum(["storage","network","router","vuex","dom","event","timer","i18n"]).optional().describe("\u884C\u4E3A\u7C7B\u522B"),api_name:z$1.string().optional().describe('"localStorage" / "axios" / "$router"'),operation:z$1.string().optional().describe('"setItem" / "get" / "push" / "commit"'),keyword:z$1.string().optional().describe('\u5728\u53C2\u6570\u503C\u4E2D\u641C\u7D22\uFF08\u5982 key \u540D "cacheData"\uFF09'),file_path:z$1.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:i,file_path:a})=>{let c=performance.now(),{db:l}=e.getContext(t),d=new Xe(l).searchByBehavior({category:n,apiName:r,operation:s,keyword:i,filePath:a}),u=new Set(["localstorage","sessionstorage","cookie"]);r||(d=d.filter(b=>b.category!=="storage"||u.has(b.apiName.toLowerCase())));let g=Math.round((performance.now()-c)*100)/100,f=H({durationMs:g,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
|
|
556
|
+
\u8FC7\u6EE4\u6761\u4EF6: ${JSON.stringify({category:n,api_name:r,operation:s,keyword:i,file_path:a})}
|
|
556
557
|
|
|
557
558
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
558
|
-
${
|
|
559
|
-
`];for(let[b,S]of
|
|
560
|
-
${
|
|
561
|
-
`)}]}}),
|
|
562
|
-
`],d=0,u=0,
|
|
559
|
+
${W(f)}`}]};let m=new Map;for(let b of d){let S=`${b.category}:${b.apiName}`;m.has(S)||m.set(S,[]),m.get(S).push(b);}let h=[`\u{1F3F7}\uFE0F \u884C\u4E3A\u641C\u7D22\u7ED3\u679C \u2014 ${d.length} \u6761
|
|
560
|
+
`];for(let[b,S]of m){let[y,_]=b.split(":"),E=new Map;for(let A of S)E.has(A.operation)||E.set(A.operation,[]),E.get(A.operation).push(A);h.push(`\u{1F4C2} ${y} \u2192 ${_}:`);for(let[A,N]of E){h.push(` ${A}:`);let x=new Map;for(let L of N){let w=`${L.symbolName}|${L.filePath}`;x.has(w)||x.set(w,{item:L,callLines:[]}),x.get(w).callLines.push(L.line);}for(let{item:L,callLines:w}of x.values()){let M=L.detail?` key="${L.detail}"`:"",P=w.length>1?` \xD7${w.length} (L${w.join(", L")})`:` L${w[0]||L.startLine}`;h.push(` \u2022 ${L.symbolName}${M}${P} \u{1F4C4} ${L.filePath}:${ke(L.startLine,L.endLine)}`);}}h.push("");}return h.push(`\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
561
|
+
${W(f)}`),{content:[{type:"text",text:h.join(`
|
|
562
|
+
`)}]}}),o.registerTool("skimmer_get_call_graph",{title:"\u83B7\u53D6\u51FD\u6570\u8C03\u7528\u5173\u7CFB\u56FE\u8C31",description:"\u67E5\u770B\u51FD\u6570\u88AB\u8C01\u8C03\u7528\uFF08callers\uFF09\u4EE5\u53CA\u5B83\u8C03\u7528\u4E86\u4EC0\u4E48\uFF08callees\uFF09\u3002project_path \u53EF\u7701\u7565\u3002",inputSchema:z$1.object({symbol_name:z$1.string().describe("\u51FD\u6570\u540D"),project_path:z$1.string().optional().describe(Ee),file_path:z$1.string().optional().describe("\u6587\u4EF6\u8DEF\u5F84\uFF08\u540C\u540D\u51FD\u6570\u65F6\u7528\u4E8E\u7CBE\u786E\u5B9A\u4F4D\uFF09"),direction:z$1.enum(["callers","callees","both"]).optional().default("both"),arg_keyword:z$1.string().optional().describe('\u8C03\u7528\u53C2\u6570\u5173\u952E\u5B57\u8FC7\u6EE4\uFF08\u5982 "storageParams"\uFF09')}),annotations:{readOnlyHint:true,destructiveHint:false}},async({symbol_name:t,project_path:n,file_path:r,direction:s,arg_keyword:i})=>{let a=performance.now(),{db:c}=e.getContext(n),l=c.getSymbolByName(t,r),p=[`\u{1F4CA} ${t} \u7684\u8C03\u7528\u56FE\u8C31
|
|
563
|
+
`],d=0,u=0,g=[],f=[],m=void 0;if(s==="callers"||s==="both"){if(g=c.getCallers(t,m,i),d+=g.length,u+=g.filter(_=>_.edge_kind==="precise").length,p.push(`\u2B06\uFE0F \u88AB\u8C03\u7528 (${g.length} \u5904):`),g.length===0)p.push(" \uFF08\u672A\u627E\u5230\u8C03\u7528\u8005\uFF09");else {let _={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}"};for(let E of g){let A=E.args?` \u53C2\u6570: "${E.args}"`:"",N=E.source_kind||"",x=E.edge_kind||"",L=_[N]?` ${_[N]}`:"",w=x==="precise"?" [\u{1F3AF}precise]":"";p.push(` \u2022 ${E.caller_name} [${E.category}]${L}${w} \u{1F4C4} ${E.file_path}:L${E.start_line}${A}`);}}p.push("");}if((s==="callees"||s==="both")&&l){if(f=c.getCallees(l.id),d+=f.length,u+=f.filter(_=>_.edge_kind==="precise").length,p.push(`\u2B07\uFE0F \u8C03\u7528\u4E86 (${f.length} \u4E2A):`),f.length===0)p.push(" \uFF08\u672A\u5206\u6790\u5230\u8C03\u7528\u5173\u7CFB\uFF09");else for(let _ of f){let E=_.args?`("${_.args}")`:"",N=(_.edge_kind||"")==="precise"?" [\u{1F3AF}precise]":"";p.push(` \u2022 ${_.callee_name}${E} [${_.call_type}]${N} L${_.line_number}`);}p.push("");}if(l){let{behaviors:_}=c.getFileOutline(l.file_path),E=_.filter(A=>A.symbol_id===l.id);if(E.length>0){p.push("\u{1F4E6} \u5916\u90E8\u72B6\u6001\u64CD\u4F5C:");for(let A of E){let N=A.detail?` ("${A.detail}")`:"";p.push(` \u2022 ${A.api_name}.${A.operation}${N} [${A.category}] L${A.line_number}`);}}}let h=Math.round((performance.now()-a)*100)/100,b=u>0?"precise":"heuristic",S=[];b==="heuristic"&&d>0&&S.push('\u5F53\u524D\u7ED3\u679C\u5747\u4E3A\u542F\u53D1\u5F0F\u5206\u6790\uFF0C\u4F7F\u7528 skimmer_index_project({ precision_mode: "precise" }) \u53EF\u83B7\u5F97\u8DE8\u6587\u4EF6 import/export \u7CBE\u786E\u7ED1\u5B9A');let y=H({durationMs:h,resultCount:d,backend:"indexed",precisionEffective:b,precisionWarnings:S.length>0?S:void 0});return p.push(`
|
|
563
564
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
564
|
-
${
|
|
565
|
-
`)}]}}),
|
|
566
|
-
`),a){let b=
|
|
567
|
-
\u26A0\uFE0F \u4FEE\u6539\u65F6\u6CE8\u610F\u5916\u90E8\u72B6\u6001\u7684\u8BFB\u5199\u683C\u5F0F\u4FDD\u6301\u4E00\u81F4`);}let
|
|
565
|
+
${W(y)}`),{content:[{type:"text",text:p.join(`
|
|
566
|
+
`)}]}}),o.registerTool("skimmer_get_blast_radius",{title:"\u8BC4\u4F30\u4FEE\u6539\u5F71\u54CD\u8303\u56F4",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\u8C03\u7528\u8BC4\u4F30\u98CE\u9669\u3002project_path \u53EF\u7701\u7565\u3002",inputSchema:z$1.object({symbol_name:z$1.string().describe("\u8981\u4FEE\u6539\u7684\u51FD\u6570\u540D"),project_path:z$1.string().optional().describe(Ee),file_path:z$1.string().optional().describe("\u6587\u4EF6\u8DEF\u5F84\uFF08\u540C\u540D\u65F6\u7CBE\u786E\u5B9A\u4F4D\uFF09")}),annotations:{readOnlyHint:true,destructiveHint:false}},async({symbol_name:t,project_path:n,file_path:r})=>{let s=performance.now(),{db:i}=e.getContext(n),a=i.getSymbolByName(t,r),c=i.getCallers(t),{behaviors:l}=a?i.getFileOutline(a.file_path):{behaviors:[]},p=a?l.filter(b=>b.symbol_id===a.id):[],d=c.length===0?"\u{1F7E2}":c.length<=3?"\u{1F7E1}":"\u{1F534}",u=c.length===0?"\u4F4E":c.length<=3?"\u4E2D":"\u9AD8",g=[`\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",`${d} \u98CE\u9669\u7B49\u7EA7: ${u} (${c.length} \u5904\u76F4\u63A5\u8C03\u7528)`,""],f={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"};if(c.length>0?(g.push("\u{1F534} \u76F4\u63A5\u5F71\u54CD:"),c.forEach((b,S)=>{let y=b.source_kind||"",_=f[y]?` ${f[y]}`:"";g.push(` ${S+1}. ${b.caller_name} [${b.category}]${_} \u{1F4C4} ${b.file_path}:L${b.start_line}`);}),g.push("")):g.push(`\u2705 \u65E0\u8C03\u7528\u8005\uFF0C\u5F71\u54CD\u8303\u56F4\u53EF\u63A7
|
|
567
|
+
`),a){let b=i.getFileDependencies(a.file_path,"to");if(b.length>0){g.push(`\u{1F4C2} \u6587\u4EF6\u4F9D\u8D56 (${b.length} \u4E2A\u6587\u4EF6 import \u4E86\u6B64\u6587\u4EF6):`);let S={import:"\u{1F4E5}",re_export:"\u{1F504}",component_ref:"\u{1F9E9}",store_ref:"\u{1F4E6}",api_ref:"\u{1F310}"};b.slice(0,10).forEach(y=>{g.push(` ${S[y.dependency_kind]||"\u2022"} ${y.from_file} (${y.dependency_kind})`);}),g.push("");}}if(p.length>0){g.push("\u{1F4E6} \u5916\u90E8\u72B6\u6001\u5F71\u54CD:");for(let b of p)g.push(` \u2022 ${b.api_name}.${b.operation}${b.detail?` key="${b.detail}"`:""} [${b.category}]`);g.push(`
|
|
568
|
+
\u26A0\uFE0F \u4FEE\u6539\u65F6\u6CE8\u610F\u5916\u90E8\u72B6\u6001\u7684\u8BFB\u5199\u683C\u5F0F\u4FDD\u6301\u4E00\u81F4`);}let m=Math.round((performance.now()-s)*100)/100,h=H({durationMs:m,resultCount:c.length,backend:"indexed"});return g.push(`
|
|
568
569
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
569
|
-
${
|
|
570
|
-
`)}]}}),
|
|
570
|
+
${W(h)}`),{content:[{type:"text",text:g.join(`
|
|
571
|
+
`)}]}}),o.registerTool("skimmer_trace_data_lifecycle",{title:"\u53D8\u91CF\u5B8C\u6574\u751F\u547D\u5468\u671F\u8FFD\u8E2A\uFF08\u4E00\u952E\u7248\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\uFF0C\u66FF\u4EE3\u8FC7\u53BB\u591A\u6B65\u624B\u52A8\u8FFD\u8E2A\u3002
|
|
571
572
|
|
|
572
573
|
\u{1F3AF} \u89E6\u53D1\u89C4\u5219\uFF08\u9047\u5230\u4EE5\u4E0B\u4EFB\u610F\u4E00\u79CD\u95EE\u9898\uFF0C\u76F4\u63A5\u4F7F\u7528\u672C\u5DE5\u5177\uFF09\uFF1A
|
|
573
574
|
- "xxx \u662F\u4ECE\u54EA\u91CC\u6765\u7684\uFF1F" / "xxx \u662F\u600E\u4E48\u8D4B\u503C\u7684\uFF1F"
|
|
@@ -585,39 +586,39 @@ ${U(h)}`),{content:[{type:"text",text:m.join(`
|
|
|
585
586
|
\u65E7\u65B9\u5F0F: trace_assignments \u2192 find_symbol \u2192 get_code_slice \u2192 find_by_behavior \u2192 trace_key_flow
|
|
586
587
|
\u65B0\u65B9\u5F0F: skimmer_trace_data_lifecycle({ variable: "xxx" }) \u2190 \u76F4\u63A5\u5F97\u5230\u5168\u90E8
|
|
587
588
|
|
|
588
|
-
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(Ee),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:
|
|
589
|
+
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(Ee),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)),d=Math.min(120,Math.max(1,a||40)),u=l.listFiles(r),g="",f=$n(l,u,r?u.length:5);f.stale&&(g=`\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:
|
|
589
590
|
`+f.staleFilePaths.slice(0,3).map(T=>` \u2022 ${T}`).join(`
|
|
590
591
|
`)+`
|
|
591
592
|
\u5EFA\u8BAE: skimmer_index_project({ force: true })
|
|
592
|
-
`);let
|
|
593
|
-
\u{1F517} \u53D1\u73B0\u522B\u540D: ${y.map(T=>`"${T}"`).join(", ")}\uFF08\u5DF2\u4E00\u5E76\u8FFD\u8E2A\u5C5E\u6027\u4FEE\u6539\uFF09`:"",
|
|
593
|
+
`);let m=Dn(u,t,20),h=[...new Set(m.map(T=>T.alias).filter(T=>T!==t))],b=Fn(u,t,20),S=[...new Set(b.map(T=>T.alias).filter(T=>T!==t))],y=[...new Set([...h,...S])],E=[t,...y],A=l.exactSearch(t,"state",void 0,r||void 0),N={vue2:"Vue2 data()",vue3:"Vue3 ref/reactive",react:"React useState/useRef"},x=A.filter(T=>T.default_value!=null).map(T=>({filePath:T.file_path,line:T.start_line,kind:`data_init(${N[T.framework]||T.framework})`,text:`${T.name}: ${T.default_value} \u2190 \u58F0\u660E\u521D\u59CB\u5316`})),L=false,w=l.getAssignments(t,r,d),M=[];w.length>0?(M=w.map(T=>({filePath:T.file_path,line:T.line_number,kind:T.kind,text:T.text_snippet||"",sourceLayer:T.source_layer||void 0})),L=true):M=Bt(u,t,false,d);for(let T of y){let $=l.getAssignments(T,r,Math.floor(d/2));$.length>0?M.push(...$.map(R=>({filePath:R.file_path,line:R.line_number,kind:R.kind,text:R.text_snippet||"",sourceLayer:R.source_layer||void 0}))):M.push(...Bt(u,T,false,Math.floor(d/2)));}let P=M.length===0?$e(u,Pn(t,false),d):[],B=new Map;for(let T of [...x,...M.length>0?M:P]){let $=`${T.filePath}:${T.line}`;B.has($)||B.set($,T);}let ce=[...B.values()],ye=false,Ae=l.getPropertyWrites(t,void 0,r,d),Y=[];Ae.length>0?(Y=Ae.map(T=>({filePath:T.file_path,line:T.line_number,kind:T.kind,text:T.text_snippet||"",sourceLayer:T.source_layer||void 0})),ye=true):Y=ht(u,t,void 0,d);for(let T of y){let $=l.getPropertyWrites(T,void 0,r,Math.floor(d/2));$.length>0?Y.push(...$.map(R=>({filePath:R.file_path,line:R.line_number,kind:R.kind,text:R.text_snippet||"",sourceLayer:R.source_layer||void 0}))):Y.push(...ht(u,T,void 0,Math.floor(d/2)));}let le=Y.length===0?$e(u,[{kind:"dot",regex:new RegExp(`\\b${t}\\.[A-Za-z_$][\\w$]*\\s*(?:=|\\+=|-=|\\*=|\\/=|%=|\\|=|&=|\\^=|&&=|\\|\\|=|\\?\\?=`)},{kind:"bracket",regex:new RegExp(`\\b${t}\\s*\\[(?:'[^']+'|"[^"]+")\\]\\s*(?:=|\\+=)`)},{kind:"delete",regex:new RegExp(`\\bdelete\\s+${t}\\.[A-Za-z_$][\\w$]*\\b`)}],d):[],X=Y.length>0?Y:le,se=l.findRelationsByArgKeyword(t,r,d);for(let T of y)se.push(...l.findRelationsByArgKeyword(T,r,Math.floor(d/2)));let Vt=[],zt=[],Gt=[];for(let T of E){let $=Ke(T),R=/^[a-zA-Z_$][\w$]*$/.test(T)?"\\b":"";Vt.push({kind:"template",regex:new RegExp(`(?::\\w+|v-model|v-if|v-show|@\\w+)="[^"]*${R}${$}${R}|\\{\\{[^}]*${R}${$}${R}[^}]*\\}\\}`)},{kind:"return",regex:new RegExp(`\\breturn\\b[^=]*${R}${$}${R}`)},{kind:"watch",regex:new RegExp(`watch[^(]*['"]\\.?${$}['"]`)},{kind:"computed_read",regex:new RegExp(`=>[^=]*${R}${$}${R}|return[^=]*${R}${$}${R}`)},{kind:"arg_usage",regex:new RegExp(`\\(\\s*[^)]*${R}${$}${R}[^)]*\\)`)}),zt.push(`${R}${$}${R}\\s*(?:=|\\+=|-=|\\*=|\\/=)(?!=)|\\b(?:const|let|var)\\s+${$}\\b`),Gt.push(`${R}${$}${R}\\.\\w+\\s*(?:=|\\+=|-=)(?!=)|${R}${$}${R}\\s*\\[`);}let zn=$e(u,Vt,d),Gn=new RegExp(zt.join("|")),qn=new RegExp(Gt.join("|")),Pe=zn.filter(T=>!Gn.test(T.text)&&!qn.test(T.text)),_t=new Map,qt=(T,$)=>{if(!_t.has(T)){let{behaviors:O}=l.getFileOutline(T),I=new Map;for(let j of O){let ee=String(j.symbol_name||"");I.has(ee)||I.set(ee,[]),I.get(ee).push(j);}_t.set(T,I);}return (_t.get(T)?.get($)||[]).filter(O=>String(O.category||"")!=="storage"?false:s==="all"?true:String(O.api_name||"").toLowerCase()===s.toLowerCase())},Jn=(T,$)=>{let R=[],O=[{name:T,filePath:$,path:[T],level:0}],I=new Set([`${$}::${T}`]);for(;O.length>0;){let j=O.shift(),ee=qt(j.filePath,j.name);if(ee.length>0){R.push({path:j.path,file:j.filePath,behaviors:ee});continue}if(j.level>=p)continue;let Z=l.getSymbolByName(j.name,j.filePath);if(Z||(Z=l.getSymbolByName(j.name)),!Z)continue;let pe=String(Z.file_path||Z.abs_path||j.filePath),Oe=qt(pe,j.name);if(Oe.length>0){R.push({path:j.path,file:pe,behaviors:Oe});continue}let Nt=l.getCallees(Z.id);for(let Fe of Nt){let De=String(Fe.callee_name||"");if(!De||De.startsWith("$"))continue;let Yt=`${pe}::${De}`;I.has(Yt)||(I.add(Yt),O.push({name:De,filePath:pe,path:[...j.path,De],level:j.level+1}));}}return R},Yn=y.length>0?`
|
|
594
|
+
\u{1F517} \u53D1\u73B0\u522B\u540D: ${y.map(T=>`"${T}"`).join(", ")}\uFF08\u5DF2\u4E00\u5E76\u8FFD\u8E2A\u5C5E\u6027\u4FEE\u6539\uFF09`:"",Le=[];b.length>0&&(Le.push(` \u{1F517} \u5F15\u7528\u522B\u540D\u4F20\u64AD (${b.length} \u5904) \u2014 \u8FD9\u4E9B\u5C40\u90E8\u53D8\u91CF\u662F "${t}" \u7684\u5F15\u7528\uFF0C\u5176\u5C5E\u6027\u4FEE\u6539\u4E5F\u88AB\u8FFD\u8E2A:`),b.slice(0,10).forEach(T=>{let R=u.find(j=>j.path===T.filePath)?.abs_path||T.abs_path,O=gt("alias_ref"),I=R?Ht(R,T.line,2):{snippet:""};Le.push(` \u{1F4C4} ${T.filePath}:L${T.line} "${T.alias}" = ... ${O}`),Le.push(` ${T.text}`),I.snippet&&Le.push(I.snippet);}));let C=[`\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=${p}${Yn}`,""];if(g&&C.push(g),C.push(`\u2460 \u58F0\u660E & \u6574\u4F53\u8D4B\u503C (${ce.length} \u5904)`),ce.length===0)C.push(" \uFF08\u672A\u627E\u5230\uFF09");else {let T={init:[],cache:[],user:[],unknown:[]};for(let R of ce){let O=R.sourceLayer||ne(R.text,R.line);T[O].push(R);}let $=["init","cache","user","unknown"];for(let R of $){let O=T[R];!O||O.length===0||(C.push(` \u25B8 ${On[R]} (${O.length} \u5904)`),O.slice(0,8).forEach(I=>{let j=y.includes(I.text.split("=")[0]?.trim().replace(/^(?:const|let|var)\s+/,"")||""),ee=gt(I.kind,j);C.push(` \u{1F4C4} ${I.filePath}:L${I.line} [${I.kind}] ${ee}`),C.push(` ${I.text}`);}));}Le.length>0&&(C.push(""),C.push(...Le));}if(C.push(""),C.push(`\u2461 \u5C5E\u6027\u4FEE\u6539 (${X.length} \u5904)`),X.length===0)C.push(' \uFF08\u672A\u627E\u5230 object.prop \u6216 object["prop"] \u5199\u5165\uFF09'),y.length>0&&C.push(` \u2139\uFE0F \u5DF2\u8FFD\u8E2A\u522B\u540D: ${y.map(T=>`"${T}"`).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 T={init:[],cache:[],user:[],unknown:[]};for(let R of X){let O=R.sourceLayer||ne(R.text,R.line);T[O].push(R);}let $=["init","cache","user","unknown"];for(let R of $){let O=T[R];!O||O.length===0||(C.push(` \u25B8 ${On[R]} (${O.length} \u5904)`),O.slice(0,8).forEach(I=>{let j=y.some(Fe=>I.text.startsWith(Fe)),ee=gt(I.kind,j),pe=u.find(Fe=>Fe.path===I.filePath)?.abs_path||"",Oe=pe?Ht(pe,I.line,2):{snippet:""},Nt=j?" \u{1F517}(via alias)":"";C.push(` \u{1F4C4} ${I.filePath}:L${I.line} [${I.kind}] ${ee}${Nt}`),Oe.snippet&&C.push(Oe.snippet);}));}}if(C.push(""),C.push(`\u2462 \u4F5C\u4E3A\u53C2\u6570\u88AB\u4F20\u5165\u8C03\u7528 (${se.length} \u5904)`),se.length===0?C.push(" \uFF08\u672A\u53D1\u73B0\u4EE5\u8BE5\u53D8\u91CF\u4F5C\u4E3A\u53C2\u6570\u7684\u51FD\u6570\u8C03\u7528\uFF09"):se.slice(0,20).forEach(T=>{let $=String(T.args||"");C.push(` \u{1F4C4} ${T.file_path}:L${T.line_number} ${T.caller_name} \u2192 ${T.callee_name} \u53C2\u6570: "${$}"`);}),C.push(""),C.push(`\u2463 \u8BFB\u53D6/\u4F7F\u7528 (${Pe.length} \u5904)`),Pe.length===0)C.push(" \uFF08\u672A\u53D1\u73B0 template \u7ED1\u5B9A / watch / computed / return \u4E2D\u7684\u5F15\u7528\uFF09");else {let T=new Map;for(let R of Pe)T.has(R.kind)||T.set(R.kind,[]),T.get(R.kind).push(R);let $={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,O]of T)C.push(` \u25B8 ${$[R]||R}`),O.slice(0,8).forEach(I=>C.push(` \u{1F4C4} ${I.filePath}:L${I.line} ${I.text}`));}C.push("");let Re=0;C.push(`\u2464 Storage \u843D\u70B9\u8FFD\u8E2A (storage_api=${s}, depth=${p})`);let Zn=s==="localStorage"?"localStorage":s==="sessionStorage"?"sessionStorage":"(?:localStorage|sessionStorage)",Qn=E.map(T=>({kind:"direct_storage",regex:new RegExp(`${Zn}\\.(?:setItem|getItem|removeItem|clear)\\(.*?\\b${Ke(T)}\\b`)})),Ve=$e(u,Qn,d);if(Ve.length>0&&(Re+=1,C.push(` \u843D\u70B9 [\u76F4\u63A5\u547D\u4E2D\u5B58\u50A8] ${gt("direct_storage")}:`),Ve.slice(0,15).forEach(T=>{let R=u.find(I=>I.path===T.filePath)?.abs_path||"",O=R?Ht(R,T.line,2):{snippet:""};C.push(` \u{1F4C4} ${T.filePath}:L${T.line} ${T.text.trim()}`),O.snippet&&C.push(O.snippet);})),se.length===0&&Ve.length===0)C.push(" \uFF08\u672A\u53D1\u73B0\u76F4\u63A5 Storage \u64CD\u4F5C\uFF0C\u4E14\u65E0\u8C03\u7528\u5165\u53E3\u5C55\u5F00\u8FFD\u8E2A\uFF09");else {let T=new Map;for(let $ of se){let R=`${$.file_path}::${$.callee_name}`;T.has(R)||T.set(R,$);}for(let[,$]of T){let R=String($.callee_name||""),O=String($.file_path||""),I=Jn(R,O);I.length!==0&&(Re+=1,I.slice(0,3).forEach(j=>{let ee=j.file!==O?` \u2197 \u8DE8\u6587\u4EF6: ${j.file}`:"";C.push(` \u94FE\u8DEF: ${j.path.join(" \u2192 ")}${ee}`),j.behaviors.forEach(Z=>{let pe=Z.detail?`("${String(Z.detail)}")`:"";C.push(` \u843D\u70B9: ${Z.api_name}.${Z.operation}${pe} [${Z.category}] L${Z.line_number}`);});}));}Re===0&&Ve.length===0&&C.push(` \uFF08\u5728 depth=${p} \u5C42\u5185\u672A\u627E\u5230 storage \u5199\u5165\u94FE\u8DEF\uFF09`);}C.push(""),C.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 er=y.length>0?` (\u542B ${y.length} \u4E2A\u522B\u540D: ${y.slice(0,3).map(T=>`"${T}"`).join(", ")})`:"";C.push(`\u2705 \u6C47\u603B${er}:`),C.push(` \u2460 \u58F0\u660E/\u8D4B\u503C: ${ce.length} \u5904`),C.push(` \u2461 \u5C5E\u6027\u4FEE\u6539: ${X.length} \u5904 (\u5DF2\u8FFD\u8E2A\u522B\u540D: ${y.map(T=>`"${T}"`).join(", ")||"\u65E0"})`),C.push(` \u2462 \u53C2\u6570\u4F20\u9012: ${se.length} \u5904`),C.push(` \u2463 \u8BFB\u53D6\u5F15\u7528: ${Pe.length} \u5904`),C.push(` \u2464 storage: ${Re>0?`\u2713 \u53D1\u73B0\u5199\u5165\u94FE\u8DEF (${Re} \u6761)`:"\u2717 \u672A\u53D1\u73B0"}`),C.push(""),C.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"),C.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 tr=Math.round((performance.now()-c)*100)/100,nr=ce.length+X.length+se.length+Pe.length+Re,Jt=H({durationMs:tr,resultCount:nr,backend:L&&ye?"indexed":L||ye?"hybrid":"fallback_scan"});return f.stale&&(Jt.index_freshness=f),C.push(`
|
|
594
595
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
595
|
-
${
|
|
596
|
-
`)}]}});}function
|
|
596
|
+
${W(Jt)}`),{content:[{type:"text",text:C.join(`
|
|
597
|
+
`)}]}});}function Hn(o,e){o.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
|
|
597
598
|
\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
|
|
598
|
-
project_path \u53EF\u7701\u7565\uFF08\u81EA\u52A8\u4F7F\u7528\u4E0A\u6B21\u7D22\u5F15\u7684\u9879\u76EE\uFF09\u3002`,inputSchema:z$1.object({project_path:z$1.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),
|
|
599
|
-
`)}]}});}var
|
|
600
|
-
\u652F\u6301\u5217\u51FA\u5F53\u524D\u6240\u6709\u5DF2\u7F13\u5B58\u7684\u9879\u76EE\u3002project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({project_path:z$1.string().optional().describe(
|
|
599
|
+
project_path \u53EF\u7701\u7565\uFF08\u81EA\u52A8\u4F7F\u7528\u4E0A\u6B21\u7D22\u5F15\u7684\u9879\u76EE\uFF09\u3002`,inputSchema:z$1.object({project_path:z$1.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),i=r.getProjectStats(),a=(()=>{try{let _=r.getLastIndexedTime();return _?new Date(_).toISOString():"\u6682\u65E0\u7D22\u5F15\u6570\u636E"}catch{return "\u6682\u65E0\u7D22\u5F15\u6570\u636E"}})(),c=i.fileCount||0,l=i.symbolCount||0,p=r.getIndexFailures(10),d=e.hasWatcher(s),f=e.listProjects().find(_=>_.root===s)?.dbPath||"",m=i.dbSize||0,h={dbPath:f,indexedFiles:c,totalSymbols:l,totalRelations:i.relationCount||0,totalBehaviors:i.behaviorCount||0,lastIndexedAt:a,failureCount:i.failureCount||0,failedFiles:p.map(_=>({file:_.file_path,error:_.error})),watcherActive:d,dbSizeBytes:m},b=Math.round((performance.now()-n)*100)/100,S=H({durationMs:b,resultCount:1,backend:"indexed"}),y=[`\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: ${h.indexedFiles}`,` \u{1F523} \u7B26\u53F7\u6570: ${h.totalSymbols}`,` \u{1F517} \u8C03\u7528\u5173\u7CFB: ${h.totalRelations}`,` \u{1F3F7}\uFE0F \u884C\u4E3A\u6807\u7B7E: ${h.totalBehaviors}`,` \u{1F4C5} \u6700\u540E\u7D22\u5F15\u65F6\u95F4: ${h.lastIndexedAt}`,` \u2757 \u5931\u8D25\u6587\u4EF6\u603B\u6570: ${h.failureCount}`,"","\u{1F50C} \u8FD0\u884C\u65F6\u72B6\u6001:",` \u{1F4C2} \u6587\u4EF6\u76D1\u542C: ${h.watcherActive?"\u2705 \u6D3B\u8DC3":"\u274C \u672A\u542F\u52A8"}`,` \u{1F4BE} \u6570\u636E\u5E93\u5927\u5C0F: ${Math.round(h.dbSizeBytes/1024)} KB`,` \u{1F4CD} \u6570\u636E\u5E93\u8DEF\u5F84: ${h.dbPath||"\uFF08\u5185\u5B58\uFF09"}`,"","\u{1F4A1} \u5EFA\u8BAE:"];if(h.totalSymbols===0&&h.indexedFiles>0?y.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"):h.indexedFiles===0?y.push(" \u274C \u5C1A\u672A\u7D22\u5F15 \u2014 \u8FD0\u884C skimmer_index_project \u5F00\u59CB\u7D22\u5F15"):y.push(" \u2705 \u7D22\u5F15\u72B6\u6001\u6B63\u5E38"),!h.watcherActive&&h.indexedFiles>0&&y.push(" \u{1F4A1} \u6587\u4EF6\u76D1\u542C\u672A\u542F\u52A8 \u2014 \u8FD0\u884C skimmer_index_project \u53EF\u81EA\u52A8\u5F00\u542F"),h.failedFiles.length>0){y.push(""),y.push("\u26A0\uFE0F \u6700\u8FD1\u5931\u8D25\u6587\u4EF6\u6837\u672C:");for(let _ of h.failedFiles.slice(0,5))y.push(` - ${_.file}: ${_.error}`);}return y.push(""),y.push("\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500"),y.push(W(S)),{content:[{type:"text",text:y.join(`
|
|
600
|
+
`)}]}});}var cs="\u9879\u76EE\u6839\u76EE\u5F55\uFF08\u53EF\u7701\u7565\uFF0C\u4F7F\u7528\u4E0A\u6B21\u7D22\u5F15\u7684\u9879\u76EE\uFF09";function Bn(o,e){o.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
|
|
601
|
+
\u652F\u6301\u5217\u51FA\u5F53\u524D\u6240\u6709\u5DF2\u7F13\u5B58\u7684\u9879\u76EE\u3002project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({project_path:z$1.string().optional().describe(cs),list_all_projects:z$1.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 f=e.listProjects(),m=Math.round((performance.now()-r)*100)/100,h=H({durationMs:m,resultCount:f.length,backend:"indexed"});if(f.length===0)return {content:[{type:"text",text:`\u{1F4CB} \u5F53\u524D\u6CA1\u6709\u5DF2\u7D22\u5F15\u7684\u9879\u76EE
|
|
601
602
|
|
|
602
603
|
\u4F7F\u7528 skimmer_index_project({ project_path: "/your/project" }) \u5F00\u59CB\u7D22\u5F15
|
|
603
604
|
|
|
604
605
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
605
|
-
${
|
|
606
|
+
${W(h)}`}]};let b=[`\u{1F4CB} \u5DF2\u7D22\u5F15\u7684\u9879\u76EE (${f.length} \u4E2A):
|
|
606
607
|
`];return f.forEach((S,y)=>{b.push(`${y+1}. ${S.root}`),b.push(` \u6570\u636E\u5E93: ${S.dbPath}`);}),b.push(`
|
|
607
608
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
608
|
-
${
|
|
609
|
-
`)}]}}let{db:s,projectRoot:
|
|
609
|
+
${W(h)}`),{content:[{type:"text",text:b.join(`
|
|
610
|
+
`)}]}}let{db:s,projectRoot:i}=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} ${i}`,"",`\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 f={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 m of l)c.push(` ${f[m.framework]||m.framework}: ${m.count} \u4E2A`);c.push("");}let p=a.topFiles;p?.length&&(c.push("\u{1F5C2}\uFE0F Top 10 \u6700\u5927\u6587\u4EF6:"),p.forEach((f,m)=>{c.push(` ${m+1}. ${f.path} (${f.line_count} \u884C, ${f.symbol_count} \u7B26\u53F7)`);}),c.push(""));let d=a.behaviorStats;if(d?.length){let f={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 m of d)c.push(` ${f[m.category]||m.category}: ${m.count} \u5904`);c.push("");}c.push(`\u{1F4BD} \u6570\u636E\u5E93: ${Math.round(a.dbSize/1024)} KB`);let u=Math.round((performance.now()-r)*100)/100,g=H({durationMs:u,resultCount:1,backend:"indexed"});return c.push(`
|
|
610
611
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
611
|
-
${
|
|
612
|
-
`)}]}});}function
|
|
612
|
+
${W(g)}`),{content:[{type:"text",text:c.join(`
|
|
613
|
+
`)}]}});}function Kn(o){let e=[J__default.resolve(o,"../package.json"),J__default.resolve(o,"../../package.json")];for(let t of e)try{let n=JSON.parse(Q__default.readFileSync(t,"utf-8"));if(typeof n.version=="string"&&n.version.trim())return n.version.trim()}catch{}return "0.0.0-dev"}var he=new ut,Vn=Kn(J__default.dirname(fileURLToPath(import.meta.url))),Ie=new McpServer({name:"frontend-code-skimmer",version:Vn});Cn(Ie,he);In(Ie,he);Un(Ie,he);Hn(Ie,he);Bn(Ie,he);async function ms(){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}
|
|
613
614
|
`);try{let{projectRoot:n}=he.getContext(process.env.SKIMMER_PROJECT),r=he.getIndexer(n),s=await r.indexProject();process.stderr.write(`[Frontend-Code-Skimmer] \u5B8C\u6210: ${s.indexedFiles} \u6587\u4EF6, ${s.totalSymbols} \u7B26\u53F7
|
|
614
|
-
`);let
|
|
615
|
+
`);let i=await r.startWatcher();he.registerWatcher(n,i),process.stderr.write(`[Frontend-Code-Skimmer] \u6587\u4EF6\u76D1\u542C\u5DF2\u542F\u52A8: ${n}
|
|
615
616
|
`);}catch(n){process.stderr.write(`[Frontend-Code-Skimmer] \u7D22\u5F15\u5931\u8D25: ${String(n)}
|
|
616
|
-
`);}}let e=new StdioServerTransport;await
|
|
617
|
+
`);}}let e=new StdioServerTransport;await Ie.connect(e),process.stderr.write(`[Frontend-Code-Skimmer MCP] \u5DF2\u542F\u52A8 (v${Vn})
|
|
617
618
|
`),process.stderr.write(`[Frontend-Code-Skimmer MCP] \u652F\u6301\u6846\u67B6: Vue 2 / Vue 3 / React Hooks
|
|
618
619
|
`),process.stderr.write(`[Frontend-Code-Skimmer MCP] \u652F\u6301\u7CBE\u5EA6: heuristic / precise (\u8DE8\u6587\u4EF6 import \u7ED1\u5B9A)
|
|
619
620
|
`),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
|
|
620
621
|
`),process.env.SKIMMER_PROJECT?process.stderr.write(`[Frontend-Code-Skimmer MCP] \u9ED8\u8BA4\u9879\u76EE: ${process.env.SKIMMER_PROJECT}
|
|
621
622
|
`):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
|
|
622
|
-
`);let t=()=>{he.closeAll(),process.exit(0);};process.on("SIGINT",t),process.on("SIGTERM",t);}
|
|
623
|
+
`);let t=()=>{he.closeAll(),process.exit(0);};process.on("SIGINT",t),process.on("SIGTERM",t);}ms().catch(o=>{process.stderr.write(`[Frontend-Code-Skimmer MCP] \u542F\u52A8\u5931\u8D25: ${String(o)}
|
|
623
624
|
`),process.exit(1);});
|