@jokeran/frontend-code-skimmer 0.4.6 → 0.4.8
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 +154 -131
- 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(i=>i.replace(/^\s*\*\s?/,"").replace(/\/\*\*/,"").replace(/\*\//,"").trim()).filter(i=>i.length>0).join(" ")}function
|
|
2
|
+
import*as q from'path';import q__default from'path';import {fileURLToPath}from'url';import {McpServer}from'@modelcontextprotocol/sdk/server/mcp.js';import {StdioServerTransport}from'@modelcontextprotocol/sdk/server/stdio.js';import is from'os';import*as te from'fs';import te__default from'fs';import cr,{createHash}from'crypto';import mr from'better-sqlite3';import ss from'fast-glob';import {createRequire}from'module';import {z as z$1}from'zod';function Je(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";case "new_call":return "constructor_call";default:return "method_call"}}function w(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 Ze(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 je(o){return cr.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 Te(o,e){return o===e?`L${o}`:`L${o}-L${e}`}function pe(o,e){return q__default.relative(e,o).replace(/\\/g,"/")}function Ue(o,e){if(!o)return e;try{return JSON.parse(o)}catch{return e}}function V(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 nn(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=Ze(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 Ee(o){return o.startsWith("use")&&o.length>3&&/[A-Z]/.test(o[3])}function rn(o,e,t){if(t===0||t>3)return;let n=w(o).split(" "),r=w(e).split(" ");for(let s of n)for(let i of r){let a=Ze(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 pr=[".ts",".tsx",".js",".jsx",".vue"],dr=["index.ts","index.tsx","index.js","index.jsx","index.vue"];function ur(o){return [...pr.map(e=>`${o}${e}`),...dr.map(e=>q.join(o,e))]}function Se(o){if(te.existsSync(o))try{if(te.statSync(o).isFile())return o}catch{}for(let e of ur(o))if(te.existsSync(e))return e;return o}var wt=["**/node_modules/**","**/dist/**","**/build/**","**/.git/**","**/coverage/**","**/.nuxt/**","**/.next/**","**/__tests__/**","**/docs/js/**","**/public/**/*.js","**/*.test.*","**/*.spec.*","**/*.min.js"],vt=["**/*.vue","**/*.js","**/*.jsx","**/*.ts","**/*.tsx"],on={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"]}},Ct=["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeDestroy","destroyed","activated","deactivated","errorCaptured"],$t=["onBeforeMount","onMounted","onBeforeUpdate","onUpdated","onBeforeUnmount","onUnmounted","onActivated","onDeactivated","onErrorCaptured","onRenderTracked","onRenderTriggered","onServerPrefetch"],an=["ref","reactive","shallowRef","shallowReactive","readonly"],cn=["computed"],ln=["watch","watchEffect","watchPostEffect","watchSyncEffect"],It=["useState","useReducer","useRef","useImperativeHandle"],Pt=["useMemo","useCallback"],Ot=["useEffect","useLayoutEffect","useInsertionEffect"],pn=["useContext","useDebugValue","useDeferredValue","useId","useSyncExternalStore","useTransition"],et=".skimmer-index.db",dn=30,un=4,fn=300;var fr=[{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,15 @@ import*as J from'path';import J__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)"]}
|
|
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)"]},{version:11,description:"\u6301\u4E45\u5316\u5F85\u8865\u7B97 precise \u7684\u6587\u4EF6\u961F\u5217\uFF0C\u907F\u514D watcher/\u8FDB\u7A0B\u91CD\u542F\u540E\u7CBE\u786E\u56FE\u8C31\u9648\u65E7",statements:[`CREATE TABLE IF NOT EXISTS precise_pending (
|
|
38
|
+
rel_path TEXT PRIMARY KEY,
|
|
39
|
+
priority TEXT NOT NULL DEFAULT 'normal',
|
|
40
|
+
added_at INTEGER NOT NULL
|
|
41
|
+
)`,"CREATE INDEX IF NOT EXISTS idx_precise_pending_priority ON precise_pending(priority, added_at)"]}];function mn(o){let e=[],t=[];o.exec(`CREATE TABLE IF NOT EXISTS schema_version (
|
|
38
42
|
version INTEGER PRIMARY KEY,
|
|
39
43
|
applied_at INTEGER NOT NULL,
|
|
40
44
|
description TEXT
|
|
41
|
-
)`);let n=o.prepare("SELECT MAX(version) as v FROM schema_version").get()?.v??0;for(let r of
|
|
45
|
+
)`);let n=o.prepare("SELECT MAX(version) as v FROM schema_version").get()?.v??0;for(let r of fr){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 hr(o,e){let t=q__default.posix.dirname(e),n=t==="."?[]:t.split("/").map(()=>"..");return q__default.resolve(q__default.dirname(o),...n)}function yr(o,e,t){if(!o)return o;if(q__default.isAbsolute(o)){let n=pe(Se(o),t);return n.startsWith("..")?o.replace(/\\/g,"/"):n}if(o.startsWith(".")){let n=Se(q__default.resolve(q__default.dirname(e),o)),r=pe(n,t);return r.startsWith("..")?o.replace(/\\/g,"/"):r}if(o.startsWith("@/")){let n=Se(q__default.resolve(t,"src",o.slice(2))),r=pe(n,t);return r.startsWith("..")?o.replace(/\\/g,"/"):r}return o.replace(/\\/g,"/")}var tt=class{db;constructor(e,t){let n=t||q__default.join(e,et);te__default.mkdirSync(q__default.dirname(n),{recursive:true}),this.db=new mr(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
46
|
-- \u6587\u4EF6\u5143\u4FE1\u606F
|
|
43
47
|
CREATE TABLE IF NOT EXISTS files (
|
|
44
48
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -179,11 +183,17 @@ import*as J from'path';import J__default from'path';import {fileURLToPath}from'u
|
|
|
179
183
|
last_seen_at INTEGER NOT NULL
|
|
180
184
|
);
|
|
181
185
|
|
|
186
|
+
CREATE TABLE IF NOT EXISTS precise_pending (
|
|
187
|
+
rel_path TEXT PRIMARY KEY,
|
|
188
|
+
priority TEXT NOT NULL DEFAULT 'normal',
|
|
189
|
+
added_at INTEGER NOT NULL
|
|
190
|
+
);
|
|
191
|
+
|
|
182
192
|
-- \u7D22\u5F15\uFF08\u4EC5\u4FDD\u7559\u65E7\u5217\u7D22\u5F15\u2014\u2014\u65B0\u5217\u7D22\u5F15\u5728 migration \u4E4B\u540E\u521B\u5EFA\uFF09
|
|
183
193
|
CREATE INDEX IF NOT EXISTS idx_symbols_name ON symbols(name);
|
|
184
194
|
CREATE INDEX IF NOT EXISTS idx_symbols_framework ON symbols(framework);
|
|
185
195
|
CREATE INDEX IF NOT EXISTS idx_behaviors_file ON behaviors(file_id);
|
|
186
|
-
`);let{applied:e,errors:t}=
|
|
196
|
+
`);let{applied:e,errors:t}=mn(this.db);e.length>0&&process.stderr.write(`[Frontend-Code-Skimmer] \u6570\u636E\u5E93\u8FC1\u79FB\u5B8C\u6210: v${e.join(", v")}
|
|
187
197
|
`),t.length>0&&process.stderr.write(`[Frontend-Code-Skimmer] \u8FC1\u79FB\u8B66\u544A: ${t.join("; ")}
|
|
188
198
|
`),this.db.exec(`
|
|
189
199
|
CREATE INDEX IF NOT EXISTS idx_behaviors_api_lc ON behaviors(api_name_lc, operation_lc);
|
|
@@ -198,6 +208,7 @@ import*as J from'path';import J__default from'path';import {fileURLToPath}from'u
|
|
|
198
208
|
CREATE INDEX IF NOT EXISTS idx_prop_writes_file ON property_writes(file_id);
|
|
199
209
|
CREATE INDEX IF NOT EXISTS idx_index_failures_file ON index_failures(file_path);
|
|
200
210
|
CREATE INDEX IF NOT EXISTS idx_index_failures_seen ON index_failures(last_seen_at DESC);
|
|
211
|
+
CREATE INDEX IF NOT EXISTS idx_precise_pending_priority ON precise_pending(priority, added_at);
|
|
201
212
|
|
|
202
213
|
CREATE VIRTUAL TABLE IF NOT EXISTS relations_fts USING fts5(
|
|
203
214
|
args,
|
|
@@ -225,7 +236,7 @@ import*as J from'path';import J__default from'path';import {fileURLToPath}from'u
|
|
|
225
236
|
INSERT INTO relations_fts(rowid, args)
|
|
226
237
|
VALUES (new.id, new.args);
|
|
227
238
|
END;
|
|
228
|
-
`);}saveParseResult(e,t,n,r,s,i,a=0,c="",l=""){let p=
|
|
239
|
+
`);}saveParseResult(e,t,n,r,s,i,a=0,c="",l=""){let p=q__default.extname(t).slice(1),u=hr(t,n);this.db.transaction(()=>{this.clearIndexFailures(n);let h=this.db.prepare("SELECT id FROM files WHERE path = ?").get(n),f;h?(f=h.id,this.db.prepare("DELETE FROM symbols WHERE file_id = ?").run(f),this.db.prepare(`
|
|
229
240
|
UPDATE files SET
|
|
230
241
|
abs_path = ?, framework = ?, content_hash = ?,
|
|
231
242
|
last_indexed_at = ?, file_size = ?, line_count = ?, file_mtime = ?,
|
|
@@ -240,31 +251,36 @@ import*as J from'path';import J__default from'path';import {fileURLToPath}from'u
|
|
|
240
251
|
signature, params_json, default_value, camel_words, jsdoc,
|
|
241
252
|
is_async, hook_deps_json, state_setter_name, parent_component)
|
|
242
253
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
243
|
-
`),
|
|
254
|
+
`),g=new Map,y=new Map,S=_=>_.internalKey||`${_.name}:${_.startLine}:${_.endLine}`,b=(_,N)=>{g.set(S(_),N);let A=y.get(_.name)||[];A.push({id:N,name:_.name,startLine:_.startLine,endLine:_.endLine}),y.set(_.name,A);},T=(_,N,A)=>{if(A&&g.has(A))return g.get(A);let k=y.get(_)||[];if(k.length===0)return;if(k.length===1||N==null)return k[0]?.id;let P=k.filter(I=>I.startLine<=N&&N<=I.endLine);return P.length===1?P[0].id:P.length>1?P.sort((I,B)=>I.endLine-I.startLine-(B.endLine-B.startLine)||Math.abs(I.startLine-N)-Math.abs(B.startLine-N))[0]?.id:k.slice().sort((I,B)=>Math.abs(I.startLine-N)-Math.abs(B.startLine-N)||I.endLine-I.startLine-(B.endLine-B.startLine))[0]?.id};for(let _ of e.symbols){let A=_.camelWords||w(_.name),k=_.name.toLowerCase(),P=_.category.toLowerCase(),I=m.run(f,_.name,k,_.category,P,_.framework,_.startLine,_.endLine,_.signature||null,_.params?JSON.stringify(_.params):null,_.defaultValue||null,A,_.jsdoc||null,_.isAsync?1:0,_.hookDeps?JSON.stringify(_.hookDeps):null,_.stateSetterName||null,_.parentComponent||null);b(_,I.lastInsertRowid);}let E=this.db.prepare(`
|
|
244
255
|
INSERT INTO relations (caller_id, callee_name, callee_name_lc, call_type, line_number, args,
|
|
245
256
|
source_kind, import_source, receiver_token, edge_kind)
|
|
246
257
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
247
|
-
`);for(let
|
|
258
|
+
`);for(let _ of e.relations){let N=T(_.callerName,_.callerLine,_.callerKey);if(N){let A=_.sourceKind||Je(_.callType);E.run(N,_.calleeName,_.calleeName.toLowerCase(),_.callType,_.line,_.args||null,A,_.importSource||null,_.receiverToken||null,_.edgeKind||"heuristic");}}if(this.db.prepare("DELETE FROM data_assignments WHERE file_id = ?").run(f),e.assignments?.length){let _=this.db.prepare(`
|
|
248
259
|
INSERT INTO data_assignments (symbol_name, symbol_name_lc, file_id, kind, source_layer, line_number, text_snippet)
|
|
249
260
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
250
|
-
`);for(let
|
|
261
|
+
`);for(let N of e.assignments)_.run(N.symbolName,N.symbolName.toLowerCase(),f,N.kind,N.sourceLayer||"unknown",N.line,N.text);}if(this.db.prepare("DELETE FROM property_writes WHERE file_id = ?").run(f),e.propertyWrites?.length){let _=this.db.prepare(`
|
|
251
262
|
INSERT INTO property_writes (object_name, object_name_lc, property_name, property_name_lc, file_id, kind, source_layer, line_number, text_snippet)
|
|
252
263
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
253
|
-
`);for(let
|
|
264
|
+
`);for(let N of e.propertyWrites)_.run(N.objectName,N.objectName.toLowerCase(),N.propertyName||null,N.propertyName?.toLowerCase()||"",f,N.kind,N.sourceLayer||"unknown",N.line,N.text);}if(this.db.prepare("DELETE FROM file_dependencies WHERE from_file = ?").run(n),e.fileDependencies?.length){let _=this.db.prepare(`
|
|
254
265
|
INSERT INTO file_dependencies (from_file, to_file, dependency_kind, line_number)
|
|
255
266
|
VALUES (?, ?, ?, ?)
|
|
256
|
-
`);for(let
|
|
267
|
+
`);for(let N of e.fileDependencies)_.run(n,yr(N.toFile,t,u),N.dependencyKind,N.line);}let L=this.db.prepare(`
|
|
257
268
|
INSERT INTO behaviors (symbol_id, file_id, category, api_name, api_name_lc, operation, operation_lc, detail, detail_lc, line_number)
|
|
258
269
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
259
|
-
`);for(let
|
|
270
|
+
`);for(let _ of e.behaviors){let N=T(_.symbolName,_.line,_.symbolKey);if(N){let A=_.detail||null;L.run(N,f,_.category,_.apiName,_.apiName.toLowerCase(),_.operation,_.operation.toLowerCase(),A,A?.toLowerCase()??"",_.line);}}if(e.errors?.length){let _=this.db.prepare(`
|
|
260
271
|
INSERT INTO index_failures (file_path, error, last_seen_at)
|
|
261
272
|
VALUES (?, ?, ?)
|
|
262
|
-
`),
|
|
273
|
+
`),N=Date.now();for(let A of e.errors)_.run(n,A,N);}})();}recordIndexFailure(e,t){this.clearIndexFailures(e),this.db.prepare(`
|
|
263
274
|
INSERT INTO index_failures (file_path, error, last_seen_at)
|
|
264
275
|
VALUES (?, ?, ?)
|
|
265
|
-
`).run(e,t,Date.now());}clearIndexFailures(e){this.db.prepare("DELETE FROM index_failures WHERE file_path = ?").run(e);}getFileHash(e){return this.db.prepare("SELECT content_hash FROM files WHERE path = ?").get(e)?.content_hash??null}getFileMeta(e){let t=this.db.prepare("SELECT content_hash, file_mtime, file_size FROM files WHERE path = ?").get(e);return t?{hash:t.content_hash,mtime:t.file_mtime??0,fileSize:t.file_size??0}:null}updateFileMtime(e,t){this.db.prepare("UPDATE files SET file_mtime = ? WHERE path = ?").run(t,e);}getFileSignatures(e){let t=this.db.prepare("SELECT content_hash, export_signature_hash, import_signature_hash FROM files WHERE path = ?").get(e);return t?{contentHash:t.content_hash,exportSignatureHash:t.export_signature_hash||"",importSignatureHash:t.import_signature_hash||""}:null}getReverseDependencies(e){return this.db.prepare("SELECT from_file FROM file_dependencies WHERE to_file = ? AND dependency_kind IN ('import', 're_export')").all(e).map(n=>n.from_file)}getReverseDependencyMap(){let e=this.db.prepare("SELECT from_file, to_file FROM file_dependencies WHERE dependency_kind IN ('import', 're_export')").all(),t=new Map;for(let{from_file:n,to_file:r}of e){let s=t.get(r)||[];s.push(n),t.set(r,s);}return t}getAllFilePaths(){return this.db.prepare("SELECT path FROM files ORDER BY path").all().map(t=>t.path)}getFileHashAndMtime(e){let t=this.db.prepare("SELECT content_hash, file_mtime FROM files WHERE path = ?").get(e);return t?{contentHash:t.content_hash,mtime:t.file_mtime??0}:null}
|
|
276
|
+
`).run(e,t,Date.now());}clearIndexFailures(e){this.db.prepare("DELETE FROM index_failures WHERE file_path = ?").run(e);}getFileHash(e){return this.db.prepare("SELECT content_hash FROM files WHERE path = ?").get(e)?.content_hash??null}getFileMeta(e){let t=this.db.prepare("SELECT content_hash, file_mtime, file_size FROM files WHERE path = ?").get(e);return t?{hash:t.content_hash,mtime:t.file_mtime??0,fileSize:t.file_size??0}:null}updateFileMtime(e,t){this.db.prepare("UPDATE files SET file_mtime = ? WHERE path = ?").run(t,e);}getFileSignatures(e){let t=this.db.prepare("SELECT content_hash, export_signature_hash, import_signature_hash FROM files WHERE path = ?").get(e);return t?{contentHash:t.content_hash,exportSignatureHash:t.export_signature_hash||"",importSignatureHash:t.import_signature_hash||""}:null}getReverseDependencies(e){return this.db.prepare("SELECT from_file FROM file_dependencies WHERE to_file = ? AND dependency_kind IN ('import', 're_export')").all(e).map(n=>n.from_file)}getReverseDependencyMap(){let e=this.db.prepare("SELECT from_file, to_file FROM file_dependencies WHERE dependency_kind IN ('import', 're_export')").all(),t=new Map;for(let{from_file:n,to_file:r}of e){let s=t.get(r)||[];s.push(n),t.set(r,s);}return t}getAllFilePaths(){return this.db.prepare("SELECT path FROM files ORDER BY path").all().map(t=>t.path)}getFileHashAndMtime(e){let t=this.db.prepare("SELECT content_hash, file_mtime FROM files WHERE path = ?").get(e);return t?{contentHash:t.content_hash,mtime:t.file_mtime??0}:null}enqueuePrecisePending(e,t){let n=Date.now(),r=i=>i==="high"?3:i==="normal"?2:1,s=this.db.prepare("SELECT priority, added_at FROM precise_pending WHERE rel_path = ?").get(e);if(!s){this.db.prepare("INSERT INTO precise_pending (rel_path, priority, added_at) VALUES (?, ?, ?)").run(e,t,n);return}r(t)>r(s.priority)&&this.db.prepare("UPDATE precise_pending SET priority = ? WHERE rel_path = ?").run(t,e);}deletePrecisePending(e){this.db.prepare("DELETE FROM precise_pending WHERE rel_path = ?").run(e);}clearPrecisePending(){this.db.prepare("DELETE FROM precise_pending").run();}getPrecisePendingCount(){return this.db.prepare("SELECT COUNT(*) as count FROM precise_pending").get().count}listPrecisePending(){return this.db.prepare(`
|
|
277
|
+
SELECT rel_path, priority
|
|
278
|
+
FROM precise_pending
|
|
279
|
+
ORDER BY CASE priority WHEN 'high' THEN 0 WHEN 'normal' THEN 1 ELSE 2 END, added_at
|
|
280
|
+
`).all().map(t=>({relPath:t.rel_path,priority:t.priority==="high"||t.priority==="low"?t.priority:"normal"}))}hasPreciseRelations(){return !!this.db.prepare("SELECT 1 as found FROM relations WHERE edge_kind = 'precise' LIMIT 1").get()}deleteFile(e){this.db.prepare("DELETE FROM file_dependencies WHERE from_file = ? OR to_file = ?").run(e,e),this.clearIndexFailures(e),this.deletePrecisePending(e),this.db.prepare("DELETE FROM files WHERE path = ?").run(e);}clearProjectIndex(){this.db.exec(`
|
|
266
281
|
DELETE FROM file_dependencies;
|
|
267
282
|
DELETE FROM index_failures;
|
|
283
|
+
DELETE FROM precise_pending;
|
|
268
284
|
DELETE FROM files;
|
|
269
285
|
`);}getFileOutline(e){let t=this.db.prepare("SELECT * FROM files WHERE path = ?").get(e);if(!t)return {file:void 0,symbols:[],behaviors:[]};let n=t.id,r=this.db.prepare(`
|
|
270
286
|
SELECT s.*, f.path as file_path
|
|
@@ -279,14 +295,14 @@ import*as J from'path';import J__default from'path';import {fileURLToPath}from'u
|
|
|
279
295
|
SELECT s.*, f.path as file_path, f.abs_path
|
|
280
296
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
281
297
|
WHERE s.name_lc = ?
|
|
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(
|
|
298
|
+
`,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(u=>`${u}*`).join(" ");try{let u=`
|
|
283
299
|
SELECT s.*, f.path as file_path, f.abs_path,
|
|
284
300
|
bm25(symbols_fts, 10.0, 1.0, 0.5, 0.5) as fts_rank
|
|
285
301
|
FROM symbols_fts
|
|
286
302
|
JOIN symbols s ON symbols_fts.rowid = s.id
|
|
287
303
|
JOIN files f ON s.file_id = f.id
|
|
288
304
|
WHERE symbols_fts MATCH ?
|
|
289
|
-
`,
|
|
305
|
+
`,d=[p];return t&&(u+=" AND s.category_lc = ?",d.push(t.toLowerCase())),n&&(u+=" AND s.framework = ?",d.push(n)),r&&(u+=" AND f.path_lc LIKE ?",d.push(`%${r.toLowerCase()}%`)),u+=` ORDER BY fts_rank LIMIT ${a}`,this.db.prepare(u).all(...d)}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
306
|
SELECT s.*, f.path as file_path, f.abs_path, 0 as fts_rank
|
|
291
307
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
292
308
|
WHERE (s.name_lc LIKE ? OR LOWER(s.camel_words) LIKE ?) ESCAPE '\\'
|
|
@@ -363,14 +379,14 @@ import*as J from'path';import J__default from'path';import {fileURLToPath}from'u
|
|
|
363
379
|
JOIN symbols s ON r.caller_id = s.id
|
|
364
380
|
JOIN files f ON s.file_id = f.id
|
|
365
381
|
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
|
|
382
|
+
`,a=[`"${r.replace(/"/g,'""')}"`];t&&(s+=" AND f.path_lc LIKE ?",a.push(`%${t.toLowerCase()}%`)),s+=" ORDER BY f.path, r.line_number LIMIT ?",a.push(n);let c=[],l=false,p=false;try{c=this.db.prepare(s).all(...a),c.length>0&&(l=!0);}catch{p=true;}let u=/[^a-zA-Z0-9_\u4e00-\u9fa5]/.test(r);if(!l&&(p||u)){let h=r.replace(/[\\%_]/g,"\\$&"),f=`
|
|
367
383
|
SELECT r.*, s.name as caller_name, s.start_line, s.end_line, s.category,
|
|
368
384
|
f.path as file_path
|
|
369
385
|
FROM relations r
|
|
370
386
|
JOIN symbols s ON r.caller_id = s.id
|
|
371
387
|
JOIN files f ON s.file_id = f.id
|
|
372
388
|
WHERE LOWER(COALESCE(r.args, '')) LIKE LOWER(?) ESCAPE '\\'
|
|
373
|
-
`,m=[`%${
|
|
389
|
+
`,m=[`%${h}%`];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
390
|
SELECT framework, COUNT(*) as count FROM files GROUP BY framework
|
|
375
391
|
`).all(),a=this.db.prepare(`
|
|
376
392
|
SELECT f.path, f.line_count, COUNT(s.id) as symbol_count
|
|
@@ -406,45 +422,46 @@ import*as J from'path';import J__default from'path';import {fileURLToPath}from'u
|
|
|
406
422
|
JOIN symbols s ON r.caller_id = s.id
|
|
407
423
|
JOIN files f ON s.file_id = f.id
|
|
408
424
|
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 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
|
|
411
|
-
`));}function
|
|
412
|
-
`),l;try{l=
|
|
413
|
-
`).length;n.symbols.push({name:"<template>",category:"lifecycle",framework:"vue2",startLine:p,endLine:p+
|
|
425
|
+
`,s=[e.toLowerCase()];return t&&(r+=" AND f.path_lc LIKE ?",s.push(`%${t.toLowerCase()}%`)),n&&(r+=" AND LOWER(COALESCE(r.args, '')) LIKE LOWER(?)",s.push(`%${n}%`)),r+=" ORDER BY f.path, r.line_number",this.db.prepare(r).all(...s)}close(){this.db.close();}};function X(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 ee(o){let e=o.object;return e?e.type==="Identifier"?String(e.name||""):e.type==="ThisExpression"?X(o):e.type==="MemberExpression"?e.object?.type==="ThisExpression"?X(e):ee(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 K(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=br(i,e);c&&r.push(c);}if(i.type==="MemberExpression"){let a=Er(i);a&&r.push(a);}}),Lr(r)}function br(o,e,t){let n=o.callee;if(!n)return null;let r=Be(o);if(n.type==="MemberExpression"||n.type==="OptionalMemberExpression"){let s=_r(n);if(!s)return null;let{apiName:i,operation:a}=s,c=o.arguments,l=ie(c?.[0]),p=xr(i);return p?{symbolName:e,category:p,apiName:i,operation:a,detail:l,line:r}:i==="this"&&nt(a)?{symbolName:e,category:"network",apiName:`this.${a}`,operation:"wrapped_call",detail:l||ie(c?.[1]),line:r}:gn(a)&&Ar(c)?{symbolName:e,category:"network",apiName:i,operation:a,detail:l||ie(c?.[1]),line:r}:nt(i)||nt(`${i}.${a}`)?{symbolName:e,category:"network",apiName:i,operation:gn(a)?a:"wrapped_call",detail:l||ie(c?.[1]),line:r}:null}if(n.type==="Identifier"){let s=n.name,i=Nr(s),a=o.arguments,c=ie(a?.[0]);return i?{symbolName:e,category:i.category,apiName:s,operation:i.operation,detail:c,line:r}:nt(s)?{symbolName:e,category:"network",apiName:s,operation:"wrapped_call",detail:c||ie(a?.[1]),line:r}:null}return null}function Er(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=Sr(n);if(!s)return null;r.type==="Identifier"?r.name:"";if(s==="this"||s===""){n.type==="MemberExpression"?n.property?.name:"";return null}return null}function _r(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 Nr(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 Be(o){return o.loc?.start?.line??0}function Tr(o){let e=o.loc;return {line:e?.start?.line??0,column:e?.start?.column??0}}function Sr(o){return o.type==="Identifier"?o.name:o.type==="ThisExpression"?"this":null}function xr(o){if(o==="this")return null;for(let[e,t]of Object.entries(on))if(o in t)return e;return null}function ie(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=rt(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=ie(i);if(c)return `${a}:${c}`}return "{...}"}}}function rt(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=rt(o.object)||"obj",r=o.property,s=r?.type==="Identifier"?String(r.name):rt(r)||"prop";return o.computed?`${n}[${s}]`:`${n}.${s}`}if(o.type==="CallExpression")return `${rt(o.callee)||"fn"}(...)`;if(o.type==="TemplateLiteral")return ie(o);let t=ie(o);return t?.startsWith("[\u53D8\u91CF: ")?t.replace(/^\[变量: /,"").replace(/\]$/,""):t}function nt(o){return /request|api|http|fetch|ajax|akscommonhandle|commonhandle/i.test(o)}function gn(o){return ["get","post","put","delete","patch","request"].includes(o.toLowerCase())}function Ar(o,e){if(!o||o.length===0)return false;for(let t of o.slice(0,2)){let n=ie(t);if(n&&(/https?:\/\//i.test(n)||n.includes("/")||/gw\d?\/|\/m\/|\/api\//i.test(n)))return true}return false}function Lr(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 xe(o,e,t){let n=[];return K(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=at(l);n.push({calleeName:c,line:Be(r),args:p});}}}}),n}function G(o,e,t,n=false){let r=[];return K(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&&!yn(a)){let c=i.arguments,l=at(c);r.push({calleeName:a,line:Be(i),args:l});}}}),ot(r)}function hn(o,e,t){let n=[];return K(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(...xe(a,e)),n.push(...st(a,e,t,true)),n.push(...it(a,e,t,true)));}),ot(n)}function st(o,e,t,n=false){let r=[];return K(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=ee(a),p=X(a);if(!l||!p||p===e||Rr(l)||yn(p))return;let u=i.arguments,d=at(u);r.push({calleeName:p,line:Be(i),args:d,receiverToken:l});}),ot(r)}function it(o,e,t,n=false){let r=[];return K(o,i=>{if(n&&i!==o&&(i.type==="FunctionDeclaration"||i.type==="ArrowFunctionExpression"||i.type==="FunctionExpression"||i.type==="ClassDeclaration"))return false;if(i.type!=="NewExpression")return;let a=i.callee;if(!a||a.type!=="Identifier")return;let c=String(a.name||"");if(!c||c===e||kr(c))return;let l=i.arguments;r.push({calleeName:c,line:Be(i),args:at(l)});}),ot(r)}function yn(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|trim|toLowerCase|toUpperCase|split|join|slice|substring|substr|replace|match|test|startsWith|endsWith|includes|map|filter|reduce|forEach|some|every|find|findIndex|push|pop|shift|unshift|splice|sort|reverse|concat|flat|flatMap|set|get|has|add|delete|clear|keys|values|entries)$/.test(o)}function Rr(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 kr(o){return /^(Object|Array|Map|Set|WeakMap|WeakSet|Date|Error|RegExp|Promise|URL|URLSearchParams|AbortController|FormData|Blob|File|Buffer|String|Number|Boolean|Symbol)$/.test(o)}function ot(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 at(o,e){if(!o||o.length===0)return;let t=o.slice(0,3).map(n=>ie(n)).filter(n=>!!n);return t.length>0?t.join(", "):void 0}function K(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&&K(r,e);else n&&typeof n=="object"&&n.type&&K(n,e);}}function ct(o,e){let t=[],n=new Set,r=o.split(`
|
|
426
|
+
`);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 u=e+s,d=`${p}:${u}:${a.index}`;n.has(d)||(n.add(d),t.push({calleeName:p,line:u}));}}return t}function bn(o,e){let t=[],n=new Set;return K(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 h=c.property?.name;h&&!/^\$/.test(h)&&(l=h);}let{line:p,column:u}=Tr(r),d=`${l}:${p}:${u}`;!l||n.has(d)||(n.add(d),t.push({calleeName:l,line:p}));}),t}var vr=createRequire(import.meta.url),En=false;function Cr(o){En||(En=true,process.stderr.write(`[Frontend-Code-Skimmer] precise import graph \u5DF2\u964D\u7EA7: ${String(o)}
|
|
427
|
+
`));}function _n(o,e,t){let n={filePath:o,imports:[],exports:[]};try{let r=vr("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=pt(o,c),p=i.importClause;if(!p){n.imports.push({localName:"",originalName:"",modulePath:c,resolvedFile:l,isDefault:!1,isReExport:!1});return}let u=p.namedBindings;if(u&&r.isNamedImports(u))for(let d of u.elements){let h=d.propertyName?d.propertyName.text:d.name.text;n.imports.push({localName:d.name.text,originalName:h,modulePath:c,resolvedFile:l,isDefault:!1,isReExport:!1});}u&&r.isNamespaceImport(u)&&n.imports.push({localName:u.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){Cr(r);}return n}function pt(o,e){let t=q.dirname(o);if(e.startsWith(".")){let n=q.resolve(t,e);return Se(n)}return e.startsWith("@/")?$r(o,e):e}function $r(o,e){let t=q.dirname(o);for(let n=0;n<10;n++){let r=q.join(t,"src");if(te.existsSync(r)&&te.statSync(r).isDirectory()){let i=q.join(r,e.replace(/^@\//,""));return Se(i)}let s=q.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:Je(o.callType),importSource:o.importSource,receiverToken:o.receiverToken,edgeKind:o.edgeKind||"heuristic"}}function ue(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:pt(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:pt(e,s.value),dependencyKind:"re_export",line:i?.start?.line??1});}}return t}function ut(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(dt(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(dt(l.name,t.get(l.name)));}continue}for(let c of r.specifiers||[]){let l=Ft(c.local),p=Ft(c.exported)||l;p&&(a?.value?n.push(`re_export:${p}:${a.value}`):n.push(dt(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=Ft(i);n.push(dt("default",a?t.get(a):void 0));continue}if(i.type==="FunctionDeclaration"||i.type==="FunctionExpression"||i.type==="ArrowFunctionExpression"){let a=(i.params||[]).map(c=>Dt(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 dt(o,e){return `${o}:${Ir(e)}`}function Ir(o){return o?o.category==="class"?"class":o.signature?`fn${o.signature.replace(/^[^(]*/,"")}`:o.category==="constant"?`const:${o.defaultValue||""}`:o.category:"unknown"}function Ft(o){if(o){if(o.type==="Identifier")return String(o.name||"");if(o.type==="StringLiteral")return String(o.value||"")}}function Dt(o){return o?o.type==="Identifier"?String(o.name||"param"):o.type==="AssignmentPattern"?Dt(o.left):o.type==="RestElement"?Dt(o.argument):"param":"param"}var Nn=createRequire(import.meta.url);var Ce=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=Nn("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(`
|
|
428
|
+
`),l;try{l=Nn("@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),u=ct(s.template.content,p);if(u.length>0){let d=s.template.content.split(`
|
|
429
|
+
`).length;n.symbols.push({name:"<template>",category:"lifecycle",framework:"vue2",startLine:p,endLine:p+d-1,camelWords:"template"});for(let h of u)n.relations.push(U({callerName:"<template>",callerLine:p,calleeName:h.calleeName,callType:"template_event",line:h.line}));}}}catch(r){n.errors?.push(`\u89E3\u6790\u5931\u8D25: ${String(r)}`);}return n}getScriptStartLine(e,t){let n=1;for(let r=0;r<t&&r<e.length;r++)e[r]===`
|
|
414
430
|
`&&n++;return n}extractFromAST(e,t,n,r,s){let i=t.split(`
|
|
415
|
-
`);s.fileDependencies=
|
|
416
|
-
`),m),S=s.symbols.length;s.symbols.push({name:
|
|
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,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=
|
|
420
|
-
`).length;n.symbols.push({name:"<template>",category:"lifecycle",framework:"vue3",startLine:l,endLine:l+
|
|
421
|
-
`),c=s.program.body;r.fileDependencies=
|
|
422
|
-
`);r.fileDependencies=
|
|
423
|
-
`),t(p)),
|
|
424
|
-
`),t(c)),
|
|
425
|
-
`),c);if(
|
|
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=
|
|
427
|
-
`),l),camelWords:
|
|
428
|
-
`),a),
|
|
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:
|
|
430
|
-
`),
|
|
431
|
-
`),c=(i.program||i).body,l=new Set;r.fileDependencies=
|
|
432
|
-
`),p),camelWords:
|
|
433
|
-
`),i.startLine),parentComponent:i.ownerClass,camelWords:
|
|
434
|
-
`),a),camelWords:
|
|
435
|
-
`),{assignments:l,propertyWrites:p}=
|
|
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?
|
|
437
|
-
`)):"";return {contentHash:t,exportSignatureHash:r,importSignatureHash:i}}function
|
|
438
|
-
`);for(let r of e){let s=r.result.errors||[];s.includes(n)||(r.result.errors=[...s,n]);}}}
|
|
439
|
-
`);
|
|
440
|
-
`);
|
|
441
|
-
`);}let
|
|
442
|
-
`)
|
|
431
|
+
`);s.fileDependencies=ue(e.body||[],s.filePath);let a=null;K(e,u=>{if(u.type==="ExportDefaultDeclaration"){let d=u.declaration;if(d?.type==="ObjectExpression")a=d;else if(d?.type==="CallExpression"){let h=d.arguments;h&&h.length>0&&h[0].type==="ObjectExpression"&&(a=h[0]);}else if(d?.type==="Identifier"){let h=d.name;K(e,f=>{if(f.type==="VariableDeclarator"&&f.id?.name===h){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&&(K(e,u=>{u.type==="ExportDefaultDeclaration"&&u.declaration?.type==="ClassDeclaration"&&(l=true,this.extractFromClassComponent(u.declaration,t,n,r,s));}),!l)){let u=null,d=0,h=["data","methods","computed","props","watch","components","created","mounted","mixins"];K(e,f=>{if(f.type==="ObjectExpression"){let m=f.properties||[],g=0;for(let y of m){let S=this.getPropKey(y);S&&h.includes(S)&&g++;}g>d&&(d=g,u=f);}}),d>=2&&u&&(a=u);}if(!a)return;let p=a.properties;for(let u of p||[]){let d=this.getPropKey(u);if(!d)continue;let h=u.type==="ObjectMethod"?u:u.value;if(!h)continue;let f=m=>m+r-1;switch(d){case "name":h?.type==="Literal"&&(String(h.value));break;case "data":this.extractData(h,i,f,s);break;case "props":this.extractProps(h,i,f,s);break;case "computed":this.extractComputedOrMethods(h,"computed",i,f,n,s);break;case "methods":this.extractComputedOrMethods(h,"method",i,f,n,s);break;case "watch":this.extractWatch(h,i,f,s);break;case "filters":this.extractComputedOrMethods(h,"filter",i,f,n,s);break;case "components":this.extractComponents(h,s);break;case "mixins":this.extractMixins(h,s);break;default:if(Ct.includes(d)){let m=f(this.getStartLine(u)),g=f(this.getEndLine(u)),y=V(n.join(`
|
|
432
|
+
`),m),S=s.symbols.length;s.symbols.push({name:d,category:"lifecycle",framework:"vue2",startLine:m,endLine:g,jsdoc:y,camelWords:w(d)});let b=z(h,d);s.behaviors.push(...b);let T=xe(h,d);for(let E of T){if(E.args){let L=String(E.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[S].camelWords+=` ${w(L)} ${L}`;}s.relations.push(U({callerName:d,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"?K(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:w(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:w(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(u=>this.getPropKey(u)==="default");p&&(l=this.getLiteralValue(p.value));}r.symbols.push({name:i,category:"prop",framework:"vue2",startLine:a,endLine:c,defaultValue:l,camelWords:w(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)),u=r(this.getEndLine(a)),d=V(s.join(`
|
|
433
|
+
`),p),h=this.extractParams(l),f=l.async===true,m=h?`${c}(${h.join(", ")})`:c;if(i.symbols.push({name:c,category:t,framework:"vue2",startLine:p,endLine:u,signature:m,params:h,isAsync:f,jsdoc:d,camelWords:w(c)}),t==="method"&&l){let g=z(l,c);i.behaviors.push(...g);let y=xe(l,c);for(let b of y){if(b.args){let T=String(b.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");i.symbols[i.symbols.length-1].camelWords+=` ${w(T)} ${T}`;}i.relations.push(U({callerName:c,callerLine:p,calleeName:b.calleeName,callType:"this_method",line:r(b.line),args:b.args}));}let S=G(l,c,s,true);for(let b of S){if(b.args){let T=String(b.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");i.symbols[i.symbols.length-1].camelWords+=` ${w(T)} ${T}`;}i.relations.push(U({callerName:c,callerLine:p,calleeName:b.calleeName,callType:"direct_call",line:r(b.line),args:b.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:w(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:w(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:w(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)),u=i(this.getEndLine(c)),d=V(n.join(`
|
|
434
|
+
`),p);if(c.type==="ClassMethod"){let f=Ct.includes(l)?"lifecycle":"method",m=this.extractParams(c),g=c.async===true,y=m?`${l}(${m.join(", ")})`:l;s.symbols.push({name:l,category:f,framework:"vue2",startLine:p,endLine:u,signature:y,params:m,isAsync:g,jsdoc:d,camelWords:w(l)});let S=z(c,l);s.behaviors.push(...S);let b=xe(c,l);for(let E of b){if(E.args){let L=String(E.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[s.symbols.length-1].camelWords+=` ${w(L)} ${L}`;}s.relations.push(U({callerName:l,callerLine:p,calleeName:E.calleeName,callType:"this_method",line:i(E.line),args:E.args}));}let T=G(c,l,n,true);for(let E of T){if(E.args){let L=String(E.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[s.symbols.length-1].camelWords+=` ${w(L)} ${L}`;}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 h=(c.decorators||[]).some(m=>m.expression?.callee?.name==="Prop"),f=this.getLiteralValue(c.value);s.symbols.push({name:l,category:h?"prop":"state",framework:"vue2",startLine:p,endLine:u,defaultValue:f,camelWords:w(l)});}}}};var Mt=createRequire(import.meta.url),ft=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}=Mt("@vue/compiler-sfc"),{descriptor:s}=r(t),i=t.split(`
|
|
435
|
+
`),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=ct(s.template.content,l);if(p.length>0){let u=s.template.content.split(`
|
|
436
|
+
`).length;n.symbols.push({name:"<template>",category:"lifecycle",framework:"vue3",startLine:l,endLine:l+u-1,camelWords:"template"});for(let d of p)n.relations.push(U({callerName:"<template>",callerLine:l,calleeName:d.calleeName,callType:"template_event",line:d.line}));}}}catch(r){n.errors?.push(`Vue3 \u89E3\u6790\u5931\u8D25: ${String(r)}`);}return n}parseSetupContent(e,t,n,r){let s;try{s=Mt("@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(`
|
|
437
|
+
`),c=s.program.body;r.fileDependencies=ue(c,r.filePath);for(let l of c||[])this.processTopLevelStatement(l,i,n,a,r);}parseScriptContent(e,t,n,r){let s;try{s=Mt("@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(`
|
|
438
|
+
`);r.fileDependencies=ue(s.program.body||[],r.filePath);let c=false;return K(s.program,l=>{if(l.type==="ExportDefaultDeclaration"&&l.declaration?.type==="ObjectExpression"){let p=l.declaration.properties?.find(u=>this.getPropKey(u)==="setup");if(p){c=true;let u=p.type==="ObjectMethod"?p:p.value;if(!u)return;let d=u.body;if(d?.type==="BlockStatement"){let h=d.body;for(let f of h||[])this.processTopLevelStatement(f,i,n,a,r);}}}}),c||K(s.program,l=>{if(!c&&l.type==="ObjectExpression"){let u=(l.properties||[]).find(d=>this.getPropKey(d)==="setup");if(u){c=true;let d=u.type==="ObjectMethod"?u:u.value;if(!d)return;let h=d.body;if(h?.type==="BlockStatement"){let f=h.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:u}=i(e),d=V(n.join(`
|
|
439
|
+
`),t(p)),h=this.extractParams(c),f=s.symbols.length;if(s.symbols.push({name:l,category:"method",framework:"vue3",startLine:t(p),endLine:t(u),signature:`${l}(${(h||[]).join(", ")})`,params:h,isAsync:c.async===true,jsdoc:d,camelWords:w(l)}),c.body){let m=z(c.body,l);s.behaviors.push(...m);let g=G(c.body,l);for(let y of g){if(y.args){let S=String(y.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[f].camelWords+=` ${w(S)} ${S}`;}s.relations.push(U({callerName:l,callerLine:t(p),calleeName:y.calleeName,callType:"direct_call",line:t(y.line),args:y.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=V(n.join(`
|
|
440
|
+
`),t(c)),u=this.extractParams(e),d=$t.includes(a);if(s.symbols.push({name:a,category:d?"lifecycle":Ee(a)?"hook":"method",framework:"vue3",startLine:t(c),endLine:t(l),signature:`${a}(${(u||[]).join(", ")})`,params:u,isAsync:e.async===true,jsdoc:p,camelWords:w(a)}),e.body){let h=z(e.body,a);s.behaviors.push(...h);let f=G(e.body,a);for(let m of f){if(m.args){let g=String(m.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[s.symbols.length-1].camelWords+=` ${w(g)} ${g}`;}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:u}=i(e);s.symbols.push({name:l,category:l==="defineProps"?"prop":l==="defineEmits"?"emit":"export",framework:"vue3",startLine:t(p),endLine:t(u),camelWords:w(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($t.includes(l)){let{start:p,end:u}=i(e);s.symbols.push({name:l,category:"lifecycle",framework:"vue3",startLine:t(p),endLine:t(u),camelWords:w(l)});let d=a.arguments;if(d?.[0]){let h=z(d[0],l);s.behaviors.push(...h);let f=G(d[0],l);for(let m of f){if(m.args){let g=String(m.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[s.symbols.length-1].camelWords+=` ${w(g)} ${g}`;}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=V(s.join(`
|
|
441
|
+
`),c);if(an.includes(a)){let u=t.arguments,d=u?.[0]?this.getLiteralValue(u[0]):void 0;return {name:e,category:"state",framework:"vue3",startLine:c,endLine:l,defaultValue:d,jsdoc:p,camelWords:w(e)}}return cn.includes(a)?{name:e,category:"computed",framework:"vue3",startLine:c,endLine:l,jsdoc:p,camelWords:w(e)}:ln.includes(a)?{name:e,category:"effect",framework:"vue3",startLine:c,endLine:l,camelWords:w(e)}:a==="provide"||a==="inject"?{name:e,category:"provide",framework:"vue3",startLine:c,endLine:l,camelWords:w(e)}:Ee(a)?{name:e,category:"hook",framework:"vue3",startLine:c,endLine:l,jsdoc:p,camelWords:w(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 Ce().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 Dr=createRequire(import.meta.url),Mr=[...It,...Pt,...Ot,...pn],He=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=Dr("@babel/parser").parse(t,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy"],errorRecovery:!0}),i=t.split(`
|
|
442
|
+
`);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=ue(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=ut(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,u=this.buildSymbolKey(i,l,p);if(n.symbols.push({name:i,category:"constant",framework:"react",startLine:l,endLine:p,internalKey:u,isExported:r,defaultValue:this.getLiteralValue(a),jsdoc:V(t.join(`
|
|
443
|
+
`),l),camelWords:w(i)}),!a)return;let d=z(a,i,t,true);n.behaviors.push(...d);let h=G(a,i,t,true);for(let f of h){let m=n.symbols.findIndex(g=>g.name===i&&g.startLine===l);if(f.args&&m!==-1){let g=String(f.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");n.symbols[m].camelWords+=` ${w(g)} ${g}`;}n.relations.push(U({callerName:i,callerLine:l,callerKey:u,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=Ee(s),p=!l&&/^[A-Z]/.test(s),u=V(t.join(`
|
|
444
|
+
`),a),d=this.extractParams(e),h=this.buildSymbolKey(s,a,c);n.symbols.push({name:s,category:l?"hook":p?"component":"function",framework:"react",startLine:a,endLine:c,internalKey:h,signature:`${s}(${(d||[]).join(", ")})`,params:d,isAsync:e.async===true,isExported:r,jsdoc:u,parentComponent:p?s:void 0,camelWords:w(s)});let f=e.body;if(f?.type!=="BlockStatement")return;let m=f.body;for(let b of m||[])this.processComponentStatement(b,s,t,n);let g=z(f,s,t,true);n.behaviors.push(...g);let y=G(f,s,t,true);for(let b of y){let T=n.symbols.findIndex(E=>E.name===s&&E.startLine===a);if(b.args&&T!==-1){let E=String(b.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");n.symbols[T].camelWords+=` ${w(E)} ${E}`;}n.relations.push(U({callerName:s,callerLine:a,callerKey:h,calleeName:b.calleeName,callType:"direct_call",line:b.line,args:b.args}));}let S=bn(f);for(let b of S)n.relations.push(U({callerName:s,callerLine:a,callerKey:h,calleeName:b.calleeName,callType:"jsx_event",line:b.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:u}=s(e),d=p,h=u;if(It.includes(l)&&l!=="useRef"){if(i.id?.type==="ArrayPattern"){let f=i.id.elements,m=f[0]?.name,g=f[1]?.name;if(m){let y=a.arguments;r.symbols.push({name:m,category:"state",framework:"react",startLine:d,endLine:h,internalKey:this.buildSymbolKey(m,d,h,t),stateSetterName:g,defaultValue:this.getLiteralValue(y?.[0]),parentComponent:t,camelWords:w(m)});}}else if(i.id?.type==="Identifier"){let f=i.id.name;r.symbols.push({name:f,category:"state",framework:"react",startLine:d,endLine:h,internalKey:this.buildSymbolKey(f,d,h,t),parentComponent:t,camelWords:w(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:d,endLine:h,internalKey:this.buildSymbolKey(f,d,h,t),defaultValue:this.getLiteralValue(m?.[0]),parentComponent:t,camelWords:w(f)});}if(Pt.includes(l)&&i.id?.type==="Identifier"){let f=i.id.name,g=a.arguments?.[1],y=this.extractDepsArray(g);r.symbols.push({name:f,category:"computed",framework:"react",startLine:d,endLine:h,internalKey:this.buildSymbolKey(f,d,h,t),hookDeps:y,parentComponent:t,camelWords:w(f)});}if(Ee(l)&&!Mr.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:d,endLine:h,internalKey:this.buildSymbolKey(f,d,h,t),parentComponent:t,camelWords:w(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(Ot.includes(c)){let{start:l,end:p}=s(e),u=i.arguments,d=u?.[1],h=this.extractDepsArray(d),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:h,parentComponent:t,camelWords:w(c)}),u?.[0]){let g=z(u[0],m,n,true).map(S=>({...S,symbolKey:f}));r.behaviors.push(...g);let y=G(u[0],m,n,true);for(let S of y){let b=r.symbols.findIndex(T=>T.name===c&&T.startLine===l);if(S.args&&b!==-1){let T=String(S.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");r.symbols[b].camelWords+=` ${w(T)} ${T}`;}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(!Ee(i)){let{start:a,end:c}=s(e),l=V(n.join(`
|
|
445
|
+
`),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:w(i)}),e.body){let u=z(e.body,i,n,true);r.behaviors.push(...u);let d=G(e.body,i,n,true);for(let h of d){let f=r.symbols.findIndex(m=>m.name===i&&m.startLine===a);if(h.args&&f!==-1){let m=String(h.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");r.symbols[f].camelWords+=` ${w(m)} ${m}`;}r.relations.push(U({callerName:i,callerLine:a,callerKey:this.buildSymbolKey(i,a,c,t),calleeName:h.calleeName,callType:"direct_call",line:h.line,args:h.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"&&Ee(p.name))continue;if(a.type==="CallExpression"&&a.callee?.name==="useCallback"){let y=a.arguments?.[1],S=this.extractDepsArray(y),{start:b,end:T}=s(e);r.symbols.push({name:l,category:"computed",framework:"react",startLine:b,endLine:T,internalKey:this.buildSymbolKey(l,b,T,t),hookDeps:S,parentComponent:t,camelWords:w(l)});continue}if(!c)continue;let{start:d,end:h}=s(e),f=V(n.join(`
|
|
446
|
+
`),d),m=this.extractParams(a);if(r.symbols.push({name:l,category:"method",framework:"react",startLine:d,endLine:h,internalKey:this.buildSymbolKey(l,d,h,t),signature:`${l}(${(m||[]).join(", ")})`,params:m,isAsync:a.async===true,jsdoc:f,parentComponent:t,camelWords:w(l)}),a.body){let g=z(a.body,l,n,true);r.behaviors.push(...g);let y=G(a.body,l,n,true);for(let S of y){let b=r.symbols.findIndex(T=>T.name===l&&T.startLine===d);if(S.args&&b!==-1){let T=String(S.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");r.symbols[b].camelWords+=` ${w(T)} ${T}`;}r.relations.push(U({callerName:l,callerLine:d,callerKey:this.buildSymbolKey(l,d,h,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 Ur=createRequire(import.meta.url),mt=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=Ur("@babel/parser").parse(t,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy","classProperties"],errorRecovery:!0}),a=t.split(`
|
|
447
|
+
`),c=(i.program||i).body,l=new Set;r.fileDependencies=ue(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=ut(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:u}=this.getLineRange(i),d=this.buildSymbolKey(c,p,u);if(l&&(l.type==="ArrowFunctionExpression"||l.type==="FunctionExpression")){this.addFunctionSymbol(c,l,t,n,r,{startLine:p,endLine:u,isExported:s});continue}if(r.symbols.push({name:c,category:"constant",framework:n,startLine:p,endLine:u,internalKey:d,isExported:s,defaultValue:this.getLiteralValue(l),jsdoc:V(t.join(`
|
|
448
|
+
`),p),camelWords:w(c)}),!l)continue;let h=z(l,c,t,true);r.behaviors.push(...h);let f=G(l,c,t,true);for(let y of f)r.relations.push(U({callerName:c,callerLine:p,callerKey:d,calleeName:y.calleeName,callType:"direct_call",line:y.line,args:y.args}));let m=st(l,c,t,true);for(let y of m)r.relations.push(U({callerName:c,callerLine:p,callerKey:d,calleeName:y.calleeName,callType:"direct_call",line:y.line,args:y.args,receiverToken:y.receiverToken}));let g=it(l,c,t,true);for(let y of g)r.relations.push(U({callerName:c,callerLine:p,callerKey:d,calleeName:y.calleeName,callType:"new_call",line:y.line,args:y.args}));}}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:V(n.join(`
|
|
449
|
+
`),i.startLine),parentComponent:i.ownerClass,camelWords:w(e)});let l=t.body;if(!l)return;let p=z(l,e,n,true);s.behaviors.push(...p);let u=G(l,e,n,true);for(let g of u)s.relations.push(U({callerName:e,callerLine:i.startLine,callerKey:a,calleeName:g.calleeName,callType:"direct_call",line:g.line,args:g.args}));let d=hn(l,e,n);for(let g of d)s.relations.push(U({callerName:e,callerLine:i.startLine,callerKey:a,calleeName:g.calleeName,callType:"direct_call",line:g.line,args:g.args}));let h=st(l,e,n,true);for(let g of h)s.relations.push(U({callerName:e,callerLine:i.startLine,callerKey:a,calleeName:g.calleeName,callType:"direct_call",line:g.line,args:g.args,receiverToken:g.receiverToken}));let f=it(l,e,n,true);for(let g of f)s.relations.push(U({callerName:e,callerLine:i.startLine,callerKey:a,calleeName:g.calleeName,callType:"new_call",line:g.line,args:g.args}));let m=xe(l,e);for(let g of m)s.relations.push(U({callerName:e,callerLine:i.startLine,callerKey:a,calleeName:g.calleeName,callType:"this_method",line:g.line,args:g.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:V(t.join(`
|
|
450
|
+
`),a),camelWords:w(i)});let l=e.body?.body;for(let p of l||[]){let u=p.key,d=u?.type==="Identifier"?String(u.name||""):"";if(!d||d==="constructor")continue;if(p.type==="ClassMethod"||p.type==="ClassPrivateMethod"){this.addFunctionSymbol(d,p,t,n,r,{startLine:this.getLineRange(p).start,endLine:this.getLineRange(p).end,isExported:false,ownerClass:i});continue}let h=p.value;h&&(h.type==="ArrowFunctionExpression"||h.type==="FunctionExpression")&&(p.type==="ClassProperty"||p.type==="PropertyDefinition")&&this.addFunctionSymbol(d,h,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 Wr=new Set(["FunctionDeclaration","ArrowFunctionExpression","FunctionExpression","ObjectMethod","ClassMethod","ClassProperty"]);function Tn(o,e){return !!e?.skipNestedFunctions&&Wr.has(String(o.type||""))}function fe(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;Tn(i,t)||fe(i,e,t);}continue}if(r&&typeof r=="object"&&r.type){let s=r;if(Tn(s,t))continue;fe(s,e,t);}}}}function Sn(o,e,t=true,n){let r=[],s=[],i=(a,c=120)=>Br(a,n,c);return fe(o,a=>{if(a.type==="VariableDeclarator"){let c=a.id;if(!c)return;let l=ht(c),p=i(a);for(let u of l)r.push({symbolName:u,kind:"declaration",line:_e(a),text:p,sourceLayer:ne(p,_e(a))});}if(a.type==="AssignmentExpression"){let c=a.left;if(!c)return;let l=i(a),p=_e(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 d=X(c);if(d){r.push({symbolName:d,kind:"assignment",line:p,text:l,sourceLayer:ne(l,p)});return}}if(c.type==="MemberExpression"){let u=ee(c);if(u&>(u)){let d=X(c);s.push({objectName:u,propertyName:d||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=_e(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 d=X(c);if(d){r.push({symbolName:d,kind:"update",line:p,text:l,sourceLayer:ne(l,p)});return}}if(c.type==="MemberExpression"){let u=ee(c);if(u&>(u)){let d=X(c);s.push({objectName:u,propertyName:d||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=ee(c);if(l&>(l)){let p=X(c);s.push({objectName:l,propertyName:p||void 0,line:_e(a),text:i(a),kind:"delete",sourceLayer:ne(i(a),_e(a))});}}}if(a.type==="CallExpression"||a.type==="OptionalCallExpression"){let c=a.callee;if(!c||c.type!=="MemberExpression"&&c.type!=="OptionalMemberExpression")return;let l=X(c);if(!l||!/^(push|pop|shift|unshift|splice|sort|reverse|copyWithin|fill)$/.test(l))return;let p=ee(c);if(!p||!gt(p))return;s.push({objectName:p,propertyName:l,line:_e(a),text:i(a),kind:"array_mutation",sourceLayer:ne(i(a),_e(a))});}},{skipNestedFunctions:t}),{assignments:r,propertyWrites:s}}function ht(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?ht(n):[]}):o.type==="ArrayPattern"?(o.elements||[]).flatMap(t=>t?ht(t):[]):o.type==="AssignmentPattern"?ht(o.left):[]}function gt(o){return !(/^[A-Z][A-Z]/.test(o)||/^(document|window|console|localStorage|sessionStorage|navigator|process|global|globalThis)$/.test(o))}function _e(o){return o.loc?.start?.line??1}function Br(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 Xr=createRequire(import.meta.url);function Ut(o,e){let t={files:new Map,resolutionCache:new Map,localShadowCache:new Map};for(let{path:n,content:r}of o){let s=_n(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,Kr(r));}return t}function Wt(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 Kr(o){let e=new Map;try{let n=Xr("@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)An(s,e);}catch{return e}return e}function An(o,e){if(o.type==="FunctionDeclaration"){let t=Le(o.id);if(!t)return;$e(t,o,e),Vr(qr(o),t,e);return}if(o.type==="VariableDeclaration"){Ln(o,void 0,e);return}if(o.type==="ClassDeclaration"){zr(o,e);return}if(o.type==="ExportNamedDeclaration"||o.type==="ExportDefaultDeclaration"){let t=o.declaration;if(!t)return;An(t,e);}}function Vr(o,e,t){for(let n of o){if(n.type==="FunctionDeclaration"){let r=Le(n.id);if(!r)continue;$e(r,n,t,e);continue}if(n.type==="VariableDeclaration"){Ln(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;$e(i,a,t,e,n);}}}function Ln(o,e,t){for(let n of o.declarations||[]){let r=Le(n.id),s=n.init;!r||!s||s.type!=="ArrowFunctionExpression"&&s.type!=="FunctionExpression"||$e(r,s,t,e,n);}}function zr(o,e){let t=Le(o.id);if(!t)return;let n=o.body?.body||[];for(let r of n){let s=Le(r.key);if(!s||s==="constructor")continue;if(r.type==="ClassMethod"||r.type==="ClassPrivateMethod"){$e(s,r,e,t);continue}let i=r.value;i&&(i.type==="ArrowFunctionExpression"||i.type==="FunctionExpression")&&(r.type==="ClassProperty"||r.type==="PropertyDefinition")&&$e(s,i,e,t,r);}}function $e(o,e,t,n,r){let s=Yr(r||e),i=Jr(o,s.start,s.end,n),a=Gr(e);t.set(i,a);}function Gr(o){let e=new Set;for(let n of o.params||[])for(let r of Ae(n))e.add(r);let t=o.body;return t&&jt(t,n=>{if(n.type==="VariableDeclarator"){for(let r of Ae(n.id))e.add(r);return}if(n.type==="FunctionDeclaration"){let r=Le(n.id);return r&&e.add(r),false}if(n.type==="ClassDeclaration"){let r=Le(n.id);return r&&e.add(r),false}}),e}function jt(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;xn(s)||jt(s,e);}continue}if(n&&typeof n=="object"&&n.type){let r=n;if(xn(r))continue;jt(r,e);}}}function xn(o){return ["FunctionDeclaration","FunctionExpression","ArrowFunctionExpression","ClassMethod","ClassPrivateMethod","ObjectMethod"].includes(String(o.type||""))}function Ae(o){return o?o.type==="Identifier"?[String(o.name||"")]:o.type==="AssignmentPattern"?Ae(o.left):o.type==="RestElement"?Ae(o.argument):o.type==="ArrayPattern"?(o.elements||[]).flatMap(e=>Ae(e)):o.type==="ObjectPattern"?(o.properties||[]).flatMap(e=>{if(e.type==="RestElement")return Ae(e.argument);let t=e.value||e.argument;return Ae(t)}):[]:[]}function Le(o){if(o&&o.type==="Identifier")return String(o.name||"")}function qr(o){let e=o.body;return !e||e.type!=="BlockStatement"?[]:e.body||[]}function Yr(o){let e=o.loc;return {start:e?.start?.line??1,end:e?.end?.line??1}}function Jr(o,e,t,n){return n?`${n}:${o}:${e}:${t}`:`root:${o}:${e}:${t}`}var Rn=createRequire(import.meta.url);function kn(o,e){let t=o.errors||[];t.includes(e)||(o.errors=[...t,e]);}var Bt=class extends He{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}},Qr=[new ft,new Ce,new He,new mt,new Bt];function Xe(o,e){for(let t of Qr)if(t.canParse(o,e)){let n=t.parse(o,e);return ts(n),es(n,e),n}return {framework:"js",filePath:o,symbols:[],relations:[],behaviors:[],errors:[`\u6CA1\u6709\u627E\u5230\u9002\u5408\u7684\u89E3\u6790\u5668: ${o}`]}}function es(o,e){if(o.symbols.length!==0)try{let t=e,n=o.filePath.endsWith(".vue"),r=0;if(n)try{let{parse:d}=Rn("@vue/compiler-sfc"),{descriptor:h}=d(e);if(h.scriptSetup?.content)t=h.scriptSetup.content,r=h.scriptSetup.loc.start.line-1;else if(h.script?.content)t=h.script.content,r=h.script.loc.start.line-1;else return}catch(d){kn(o,`\u751F\u547D\u5468\u671F\u63D0\u53D6\u8DF3\u8FC7: Vue SFC \u89E3\u6790\u5931\u8D25 - ${String(d)}`);return}let a=Rn("@babel/parser").parse(t,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy"],errorRecovery:!0}).program.body;if(!a?.length)return;let c=t.split(`
|
|
451
|
+
`),{assignments:l,propertyWrites:p}=Sn({type:"Program",body:a},o.filePath,!1,c);if(r>0){for(let d of l)d.line+=r;for(let d of p)d.line+=r;}let u=new Set(o.symbols.map(d=>d.name));o.assignments=l.filter(d=>u.has(d.symbolName)),o.propertyWrites=p.filter(d=>u.has(d.objectName));}catch(t){kn(o,`\u751F\u547D\u5468\u671F\u63D0\u53D6\u8DF3\u8FC7: AST \u89E3\u6790\u5931\u8D25 - ${String(t)}`);}}function ts(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 Ke(o,e){let t=ns(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?wn(n.join(`
|
|
452
|
+
`)):"",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?wn(s.join(`
|
|
453
|
+
`)):"";return {contentHash:t,exportSignatureHash:r,importSignatureHash:i}}function Ht(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 Xt(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 ns(o){return createHash("sha256").update(o,"utf-8").digest("hex").slice(0,16)}function wn(o){return createHash("sha256").update(o,"utf-8").digest("hex").slice(0,12)}var rs={maxFiles:20,maxTimeMs:1500},yt=class{pending=[];options;constructor(e){this.options={...rs,...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 bt=class{projectRoot;db;scheduler;constructor(e,t){this.projectRoot=e,this.db=t,this.scheduler=new yt;}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=Ut(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=Wt(r.result.relations,r.result.filePath,n,s);}}catch(t){let n=`precise enhancement \u5931\u8D25\uFF0C\u5DF2\u56DE\u9000\u5230\u672C\u5730 relations: ${String(t)}`;process.stderr.write(`[Frontend-Code-Skimmer] ${n}
|
|
454
|
+
`);for(let r of e){let s=r.result.errors||[];s.includes(n)||(r.result.errors=[...s,n]);}}}enqueuePrecise(e,t){this.scheduler.enqueue(e,t),this.db.enqueuePrecisePending(e,t);}hydratePendingPreciseQueue(){for(let e of this.db.listPrecisePending())this.scheduler.enqueue(e.relPath,e.priority);}enqueueAffectedPrecise(e,t){if(t==="unchanged")return;let n=this.db.getReverseDependencyMap(),{files:r,truncated:s}=Xt(e,t,n);s&&process.stderr.write(`[Frontend-Code-Skimmer] \u26A0\uFE0F ${e} \u7684 precise \u5F85\u8865\u7B97\u6269\u6563\u5DF2\u8FBE\u4E0A\u9650\uFF08200\uFF09\uFF0C\u90E8\u5206\u4E0B\u6E38\u6587\u4EF6\u5C06\u8DF3\u8FC7\u672C\u8F6E
|
|
455
|
+
`);let i=t==="export_changed"||t==="full_changed"?"high":t==="import_changed"?"normal":"low";for(let a of r)this.enqueuePrecise(a,i);}async indexProject(e){let t=Date.now(),n=e?.include||[...vt],r=e?.exclude||[...wt],s=e?.force||false,i=Date.now(),a=await ss(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,u=0,d=0;if((e?.precisionMode||"heuristic")==="precise"){let f=[];for(let m=0;m<a.length;m++){let g=a[m],y=pe(g,this.projectRoot);e?.onProgress?.(m+1,a.length,y);try{let S=te__default.statSync(g).mtimeMs,b=Date.now(),T=te__default.readFileSync(g,"utf-8"),E=Date.now()-b,L=Date.now(),_=Xe(g,T),N=Date.now()-L;p+=E,u+=N,f.push({absPath:g,relPath:y,result:_,parseMs:N,readMs:E,content:T,mtime:S});}catch(S){this.db.recordIndexFailure(y,String(S)),l.errors.push({file:y,error:String(S)});}}this.enhancePreciseRelations(f);for(let m of f){let g=Date.now();try{let y=je(m.content),S=Qe(m.content),b=Buffer.byteLength(m.content,"utf-8"),T=Ke(m.result,m.content);this.db.saveParseResult(m.result,m.absPath,m.relPath,y,b,S,m.mtime,T.exportSignatureHash,T.importSignatureHash),this.db.deletePrecisePending(m.relPath),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}))),d+=Date.now()-g;}catch(y){this.db.recordIndexFailure(m.relPath,String(y)),l.errors.push({file:m.relPath,error:String(y)});}}this.scheduler.clear();}else for(let f=0;f<a.length;f++){let m=a[f],g=pe(m,this.projectRoot);e?.onProgress?.(f+1,a.length,g);try{let y=await this.indexFile(m,g,s);y.skipped?l.skippedFiles++:(l.indexedFiles++,l.totalSymbols+=y.symbolCount,p+=y.readMs||0,u+=y.parseMs||0,d+=y.saveMs||0,y.errors?.length&&l.errors.push(...y.errors.map(S=>({file:g,error:S}))));}catch(y){this.db.recordIndexFailure(g,String(y)),l.errors.push({file:g,error:String(y)});}}return l.phaseTimings.readFilesMs=p,l.phaseTimings.parseMs=u,l.phaseTimings.saveToDbMs=d,l.phaseTimings.totalMs=Date.now()-t,l.durationMs=l.phaseTimings.totalMs,l}async selectivePrecise(e){let t=Date.now(),n=e?.maxFiles??20,r=e?.maxTimeMs??1500;this.hydratePendingPreciseQueue(),this.scheduler.configure({maxFiles:n,maxTimeMs:r});let s=this.db.getAllFilePaths(),i=this.db.getReverseDependencyMap(),a=new Set;for(let g of s){let y=this.fileAbsPath(g);if(!te__default.existsSync(y))continue;let S=this.db.getFileSignatures(g);if(!S){this.scheduler.enqueue(g,"low");continue}let b;try{b=te__default.statSync(y);let I=this.db.getFileHashAndMtime(g);if(I&&I.mtime===b.mtimeMs&&I.contentHash)continue}catch{continue}let T=te__default.readFileSync(y,"utf-8"),E=je(T);if(S.contentHash===E){this.db.updateFileMtime(g,b.mtimeMs);continue}let L=Xe(y,T),_=Ke(L,T),N=Ht(S,_);if(N==="unchanged")continue;let{files:A,truncated:k}=Xt(g,N,i);k&&process.stderr.write(`[Frontend-Code-Skimmer] \u26A0\uFE0F ${g} \u7684\u53CD\u5411\u4F9D\u8D56\u6269\u6563\u5DF2\u8FBE\u4E0A\u9650\uFF08200\uFF09\uFF0C\u90E8\u5206\u4E0B\u6E38\u6587\u4EF6\u5C06\u8DF3\u8FC7\u672C\u6B21 precise \u91CD\u7B97
|
|
456
|
+
`);for(let I of A)a.add(I);let P=N==="export_changed"||N==="full_changed"?"high":N==="import_changed"?"normal":"low";for(let I of A)this.scheduler.enqueue(I,P);}let{tasks:c,exceededBudget:l,remainingPending:p}=this.scheduler.dequeueBatch(),u=[],d=[],h=0;for(let g=0;g<c.length;g++){let S=c[g].relPath;if(a.add(S),Date.now()-t>=r){d.push(...c.slice(g));break}let b=this.fileAbsPath(S);if(!te__default.existsSync(b)){this.removeFile(S),this.db.deletePrecisePending(S);continue}try{let T=te__default.readFileSync(b,"utf-8"),E=Xe(b,T),L=je(T),_=Qe(T),N=Buffer.byteLength(T,"utf-8");u.push({absPath:b,relPath:S,result:E,content:T,hash:L,lineCount:_,fileSize:N,mtime:te__default.statSync(b).mtimeMs});}catch(T){this.db.recordIndexFailure(S,String(T)),process.stderr.write(`[Frontend-Code-Skimmer] Selective precise \u5931\u8D25: ${S} - ${String(T)}
|
|
457
|
+
`);}}d.length>0&&this.scheduler.requeue(d),this.enhancePreciseRelations(u);for(let g of u)try{let y=Ke(g.result,g.content);this.db.saveParseResult(g.result,g.absPath,g.relPath,g.hash,g.fileSize,g.lineCount,g.mtime,y.exportSignatureHash,y.importSignatureHash),this.db.deletePrecisePending(g.relPath),h++;}catch(y){this.db.recordIndexFailure(g.relPath,String(y)),process.stderr.write(`[Frontend-Code-Skimmer] Selective precise \u843D\u5E93\u5931\u8D25: ${g.relPath} - ${String(y)}
|
|
458
|
+
`);}let f=Date.now()-t,m=p+d.length;return process.stderr.write(`[Frontend-Code-Skimmer] Selective precise: ${h}/${a.size} affected, ${f}ms, pending: ${m}${l||d.length>0?" (budget limited)":""}
|
|
459
|
+
`),{reindexedFiles:h,affectedFiles:Array.from(a),skippedByBudget:m}}async indexFile(e,t,n=false){let r=0,s=0,i=null;if(!n){try{let L=te__default.statSync(e);r=L.mtimeMs,s=L.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=n?null:this.db.getFileSignatures(t),c=!n&&(this.db.hasPreciseRelations()||this.db.getPrecisePendingCount()>0),l=Date.now(),p=te__default.readFileSync(e,"utf-8"),u=Date.now()-l,d=je(p);if(!n&&i&&i.hash===d)return r>0&&i.mtime!==r&&this.db.updateFileMtime(t,r),{skipped:true,symbolCount:0,readMs:u,parseMs:0,saveMs:0};let h=Qe(p),f=Buffer.byteLength(p,"utf-8"),m=Date.now(),g=Xe(e,p),y=Date.now()-m,S=Ke(g,p),b=Ht(a,S),T=Date.now();this.db.clearIndexFailures(t),this.db.saveParseResult(g,e,t,d,f,h,r,S.exportSignatureHash,S.importSignatureHash),c&&this.enqueueAffectedPrecise(t,b);let E=Date.now()-T;return {skipped:false,symbolCount:g.symbols.length,readMs:u,parseMs:y,saveMs:E,errors:g.errors,changeType:b}}removeFile(e){this.db.deleteFile(e);}fileAbsPath(e){return q__default.join(this.projectRoot,e)}async startWatcher(){let{default:e}=await import('chokidar'),t=e.watch([...vt].map(r=>q__default.posix.join(this.projectRoot,r)),{cwd:this.projectRoot,ignored:[...wt],persistent:true,ignoreInitial:true,awaitWriteFinish:{stabilityThreshold:fn}}),n=async r=>{let s=pe(r,this.projectRoot);try{await this.indexFile(r,s),process.stderr.write(`[Frontend-Code-Skimmer] \u5DF2\u66F4\u65B0\u7D22\u5F15: ${s}
|
|
443
460
|
`);}catch(i){process.stderr.write(`[Frontend-Code-Skimmer] \u66F4\u65B0\u5931\u8D25: ${s} - ${String(i)}
|
|
444
|
-
`);}};return t.on("add",n).on("change",n).on("unlink",r=>{let s=
|
|
445
|
-
`);}),()=>t.close()}};var
|
|
461
|
+
`);}};return t.on("add",n).on("change",n).on("unlink",r=>{let s=pe(r,this.projectRoot);this.removeFile(s),process.stderr.write(`[Frontend-Code-Skimmer] \u5DF2\u5220\u9664\u7D22\u5F15: ${s}
|
|
462
|
+
`);}),()=>t.close()}};var as=8,cs=30,ls=14,ps=360*60*1e3,Et=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=q__default.join(is.homedir(),".frontend-code-skimmer","databases"),te__default.mkdirSync(this.globalCacheDir,{recursive:true}),this.defaultProject=process.env.SKIMMER_PROJECT||null,this.defaultProject&&(this.defaultProject=q__default.resolve(this.defaultProject)),this.maxOpenProjects=this.parsePositiveInt(process.env.SKIMMER_MAX_OPEN_PROJECTS,as);let e=this.parsePositiveInt(process.env.SKIMMER_DB_IDLE_MINUTES,cs),t=this.parsePositiveInt(process.env.SKIMMER_DB_TTL_DAYS,ls);this.maxIdleMs=e*60*1e3,this.dbTtlMs=t*24*60*60*1e3,this.maybeCleanupDiskCache(Date.now());}resolveProjectRoot(e){if(e){let t=q__default.resolve(e);if(!te__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=q__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 tt(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}
|
|
446
463
|
`),process.stderr.write(`[Frontend-Code-Skimmer] \u6570\u636E\u5E93: ${r}
|
|
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=
|
|
464
|
+
`),s}getContext(e){let t=this.resolveProjectRoot(e),n=this.getDatabase(t);return this.lastProject=t,{db:n,projectRoot:t}}getIndexer(e){let t=this.resolveProjectRoot(e),n=q__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 bt(n,s);return this.indexerCache.set(n,i),this.touchProject(n,r),this.lastProject=n,i}setLastProject(e){this.lastProject=q__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=q__default.resolve(e),r=this.watcherCleanups.get(n);if(r)try{r();}catch{}this.watcherCleanups.set(n,t);}hasWatcher(e){let t=q__default.resolve(e);return this.watcherCleanups.has(t)}closeProject(e){let t=q__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 q__default.resolve(process.env.SKIMMER_DB);let t=q__default.join(e,".agent","skimmer_find_symbol"),n=q__default.join(t,et);try{return te__default.mkdirSync(t,{recursive:!0}),te__default.accessSync(e,te__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 q__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<ps)return;this.lastDiskCleanupAt=e;let t=[];try{t=te__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(q__default.resolve(s));let r=e-this.dbTtlMs;for(let s of t){if(!s.isFile()||!s.name.endsWith(".db"))continue;let i=q__default.join(this.globalCacheDir,s.name);if(n.has(q__default.resolve(i)))continue;let a;try{a=te__default.statSync(i);}catch{continue}a.mtimeMs>=r||(this.safeUnlink(i),this.safeUnlink(`${i}-wal`),this.safeUnlink(`${i}-shm`));}}safeUnlink(e){try{te__default.existsSync(e)&&te__default.unlinkSync(e);}catch{}}};var _t=createRequire(import.meta.url);function $n(o,e){let t=[];if(o==="heuristic")return {effective:"heuristic",warnings:t};let n=_t("fs"),r=_t("path");if(!us(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{_t.resolve("typescript",{paths:[e]});}catch{try{_t.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 us(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 In(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
|
|
448
465
|
\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
|
|
449
466
|
\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
|
|
450
467
|
\u591A\u4E2A\u9879\u76EE\u4F1A\u5E76\u884C\u7F13\u5B58\uFF0C\u5207\u6362\u65E0\u9700\u91CD\u542F\u3002
|
|
@@ -455,45 +472,45 @@ import*as J from'path';import J__default from'path';import {fileURLToPath}from'u
|
|
|
455
472
|
- \u5F3A\u5236\u5168\u91CF\u91CD\u5EFA: force=true
|
|
456
473
|
- \u7CBE\u786E\u7CBE\u5EA6\u6A21\u5F0F: precision_mode="precise"\uFF08\u57FA\u4E8E TypeScript Compiler API \u505A\u8DE8\u6587\u4EF6 import/export \u7ED1\u5B9A\uFF09
|
|
457
474
|
|
|
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:
|
|
459
|
-
`);}});e.setLastProject(l);let m=0;try{let
|
|
460
|
-
`);}catch(
|
|
461
|
-
`);}let
|
|
462
|
-
`);}let
|
|
463
|
-
\u26A0\uFE0F \u89E3\u6790\u5931\u8D25 (${f.errors.length} \u4E2A):`);for(let
|
|
464
|
-
`)}]}});}function
|
|
465
|
-
`)}function
|
|
475
|
+
\u8FD4\u56DE: \u7D22\u5F15\u7EDF\u8BA1\uFF08\u6587\u4EF6\u6570\u3001\u7B26\u53F7\u6570\u3001\u8017\u65F6\u3001\u7CBE\u5EA6\u6A21\u5F0F\uFF09`,inputSchema:z$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:u,warnings:d}=$n(p,l),h=e.getIndexer(l),f=await h.indexProject({include:r,exclude:s,force:n,precisionMode:u,onProgress:(k,P)=>{(k%20===0||k===P)&&process.stderr.write(`[Frontend-Code-Skimmer] \u8FDB\u5EA6: ${k}/${P}
|
|
476
|
+
`);}});e.setLastProject(l);let m=0;try{let k=Date.now(),P=await h.startWatcher();m=Date.now()-k,e.registerWatcher(l,P),process.stderr.write(`[Frontend-Code-Skimmer] \u6587\u4EF6\u76D1\u542C\u5DF2\u542F\u52A8: ${l}
|
|
477
|
+
`);}catch(k){process.stderr.write(`[Frontend-Code-Skimmer] \u6587\u4EF6\u76D1\u542C\u542F\u52A8\u5931\u8D25\uFF08\u7D22\u5F15\u4ECD\u53EF\u7528\uFF09: ${String(k)}
|
|
478
|
+
`);}let g=null;if(a)try{let k=await h.selectivePrecise({maxFiles:c||20});g={reindexedFiles:k.reindexedFiles,affectedFiles:k.affectedFiles.length,skippedByBudget:k.skippedByBudget};}catch(k){process.stderr.write(`[Frontend-Code-Skimmer] Selective precise \u5931\u8D25: ${String(k)}
|
|
479
|
+
`);}let y=f.indexedFiles>0||f.totalFiles>0,S=f.totalSymbols>0,b=y?"\u2705 \u53EF\u7528":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",T=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=y?"\u2705 \u53EF\u7528":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",L=y?"\u2705 \u53EF\u7528\uFF08\u57FA\u4E8E\u6B63\u5219\u626B\u63CF\u6587\u4EF6\uFF09":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",_=f.phaseTimings,N=_?["","\u23F1\uFE0F \u3010\u9636\u6BB5\u8017\u65F6\u3011",` \u{1F50D} \u6587\u4EF6\u53D1\u73B0: ${_.discoverFilesMs}ms`,` \u{1F4D6} \u6587\u4EF6\u8BFB\u53D6: ${_.readFilesMs}ms`,` \u{1F52C} \u89E3\u6790: ${_.parseMs}ms`,` \u{1F4BE} \u6570\u636E\u5E93\u5199\u5165: ${_.saveToDbMs}ms`,` \u{1F4CA} \u603B\u8BA1: ${_.totalMs}ms`,` \u{1F4E1} \u6587\u4EF6\u76D1\u542C: ${m}ms`]:[],A=[`\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: ${u}`,` \u23F1\uFE0F \u8017\u65F6: ${f.durationMs}ms`,...N,"","\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 ${T}`,` skimmer_get_component_outline ${T}`,` skimmer_find_by_behavior ${E}`,` skimmer_trace_data_lifecycle ${L}`,` skimmer_trace_assignments ${L}`,` skimmer_get_code_slice ${b}`," 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){A.push(`
|
|
480
|
+
\u26A0\uFE0F \u89E3\u6790\u5931\u8D25 (${f.errors.length} \u4E2A):`);for(let k of f.errors.slice(0,5))A.push(` - ${k.file}: ${k.error}`);f.errors.length>5&&A.push(` ... \u8FD8\u6709 ${f.errors.length-5} \u4E2A`);}if(d.length>0){A.push(""),A.push("\u26A0\uFE0F \u7CBE\u5EA6\u964D\u7EA7:");for(let k of d)A.push(` - ${k}`);}if(g){A.push(""),A.push("\u{1F3AF} \u9009\u62E9\u6027 Precise \u91CD\u7B97:"),A.push(` \u{1F4CA} \u91CD\u7B97\u6587\u4EF6: ${g.reindexedFiles}`),A.push(` \u{1F517} \u5F71\u54CD\u6587\u4EF6: ${g.affectedFiles} (\u5019\u9009\u6570)`),g.skippedByBudget>0&&(A.push(` \u23F8\uFE0F \u8D85\u9884\u7B97\u8DF3\u8FC7\u7684\u6587\u4EF6: ${g.skippedByBudget}`),A.push(" \u{1F4A1} \u540E\u7EED watcher \u89E6\u53D1\u6216\u518D\u6B21\u8C03\u7528 selective_precise=true \u7EE7\u7EED"));let k=h.getScheduler().pendingCount;k>0&&A.push(` \u{1F4CB} Pending queue: ${k} \u6587\u4EF6\u5F85\u91CD\u7B97`);}return {content:[{type:"text",text:A.join(`
|
|
481
|
+
`)}]}});}function Vt(o,e,t){try{if(!e||!te__default.existsSync(e))return {stale:!1};let n=te__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 Pn(o,e,t=5){let n=e.slice(0,t),r=[],s=0;for(let i of n){if(!i.abs_path||!te__default.existsSync(i.abs_path))continue;s++;let{stale:a}=Vt(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(`
|
|
482
|
+
`)}function On(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
|
|
466
483
|
\u5305\u542B: props\u3001data/state\u3001computed\u3001methods/functions\u3001watch/effect\u3001lifecycle\u3001\u884C\u4E3A\u6807\u7B7E\u3002
|
|
467
484
|
\u884C\u4E3A\u6807\u7B7E\u81EA\u52A8\u6807\u51FA: [storage:localStorage.setItem] [network:axios.get] \u7B49\u3002
|
|
468
485
|
|
|
469
486
|
project_path \u53EF\u7701\u7565\uFF08\u4F7F\u7528\u4E0A\u6B21 skimmer_index_project \u6307\u5B9A\u7684\u9879\u76EE\uFF09\u3002
|
|
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
|
|
487
|
+
file_path \u4F7F\u7528\u76F8\u5BF9\u4E8E\u9879\u76EE\u6839\u76EE\u5F55\u7684\u8DEF\u5F84\uFF0C\u5982 "src/views/apply/index.vue"\u3002`,inputSchema:z$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 T=Math.round((performance.now()-s)*100)/100,E=H({durationMs:T,resultCount:0,backend:"indexed"});return {content:[{type:"text",text:`\u274C \u6587\u4EF6\u672A\u7D22\u5F15: ${t}
|
|
471
488
|
|
|
472
489
|
\u8BF7\u5148\u8FD0\u884C:
|
|
473
490
|
skimmer_index_project({ project_path: "${n||"<\u9879\u76EE\u8DEF\u5F84>"}" })
|
|
474
491
|
|
|
475
492
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
476
|
-
${W(E)}`}]}}let p="",
|
|
477
|
-
\u26A0\uFE0F [\u7D22\u5F15\u5DF2\u8FC7\u671F] ${
|
|
493
|
+
${W(E)}`}]}}let p="",u=a.abs_path,{stale:d,reason:h}=Vt(i,u,t);d&&(p=`
|
|
494
|
+
\u26A0\uFE0F [\u7D22\u5F15\u5DF2\u8FC7\u671F] ${h||""}\uFF0C\u884C\u53F7\u53EF\u80FD\u504F\u79FB\uFF08\u7D22\u5F15\u8BB0\u5F55 ${a.line_count} \u884C\uFF0C\u5B9E\u9645\u53EF\u80FD\u5DF2\u53D8\u5316\uFF09
|
|
478
495
|
\u7ACB\u5373\u91CD\u5EFA: skimmer_index_project({ force: true })
|
|
479
|
-
`);let f=new Map;for(let
|
|
480
|
-
${E} ${
|
|
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,
|
|
496
|
+
`);let f=new Map;for(let T of l){let E=T.symbol_id;f.has(E)||f.set(E,[]);let L=`[${T.category}:${T.api_name}.${T.operation}${T.detail?`("${T.detail}")`:""}]`,_=f.get(E);_.includes(L)||_.push(L);}let m=[];m.push(`\u{1F4C4} ${t} (${a.line_count} \u884C, ${a.framework})`),m.push(`${"\u2501".repeat(50)}`),p&&m.push(p);let g={};for(let T of c){if(T.name==="<template>")continue;let E=T.category;g[E]||(g[E]=[]),g[E].push(T);}let y=[{key:"prop",icon:"\u{1F4E6}",label:"Props"},{key:"state",icon:"\u{1F4CA}",label:"Data / State"},{key:"computed",icon:"\u{1F504}",label:"Computed"},{key:"method",icon:"\u26A1",label:"Methods / Functions"},{key:"effect",icon:"\u{1F440}",label:"Watch / Effect"},{key:"lifecycle",icon:"\u{1F517}",label:"Lifecycle"},{key:"hook",icon:"\u{1FA9D}",label:"Hooks"},{key:"component",icon:"\u{1F9E9}",label:"Components"},{key:"mixin",icon:"\u{1F500}",label:"Mixins"},{key:"provide",icon:"\u{1F489}",label:"Provide / Inject"},{key:"emit",icon:"\u{1F4E1}",label:"Emits"},{key:"filter",icon:"\u{1F50D}",label:"Filters"},{key:"function",icon:"\u{1F527}",label:"Functions"},{key:"constant",icon:"\u{1F4CC}",label:"Constants"}];for(let{key:T,icon:E,label:L}of y){let _=g[T];if(_?.length){m.push(`
|
|
497
|
+
${E} ${L} (${_.length}):`);for(let N of _){let A=N.name,k=Te(N.start_line,N.end_line),P=Ue(N.params_json,[]),I=P.length>0?`(${P.join(", ")})`:"",B=N.default_value?` = ${N.default_value}`:"",se=N.is_async?"async ":"",be=f.get(N.id),Re=be?.length?` ${be.slice(0,3).join(" ")}`:"",J=N.state_setter_name?` \u2192 ${N.state_setter_name}`:"",Ge=N.hook_deps_json?` [deps:${Ue(N.hook_deps_json,[]).join(",")}]`:"";m.push(` \u2022 ${se}${A}${I}${B}${J}${Ge} ${k}${Re}`);}}}m.push(`
|
|
498
|
+
${"\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,b=H({durationMs:S,resultCount:c.length,backend:"indexed"});return r&&(b.debug={scanned_files:1}),m.push(`
|
|
482
499
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
483
|
-
${W(
|
|
484
|
-
`)}]}});}var
|
|
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
|
|
486
|
-
`).length;return [{content:t[1],lineOffset:r}]}function
|
|
500
|
+
${W(b)}`),{content:[{type:"text",text:m.join(`
|
|
501
|
+
`)}]}});}var Ve=class{constructor(e){this.db=e;}db;search(e,t){let{category:n,framework:r,filePath:s,limit:i=dn,fuzzy:a=true,allowFallbackScan:c=false,debug:l=false}=t||{},p=e.trim(),u=new Map,d={},h=performance.now(),f=this.db.exactSearch(p,n,r,s);for(let L of f)u.set(L.id,{symbol:L,filePath:L.file_path,score:100,matchReason:"\u7CBE\u786E\u5339\u914D"});if(d["1_exact"]=Math.round((performance.now()-h)*100)/100,u.size>=i)return {results:this.rankResults(u,i)};let m=performance.now(),g=0,y=w(p),S=[p,y,...y.split(" ")].filter(Boolean).filter((L,_,N)=>N.indexOf(L)===_);for(let L of S){if(L.length<2)continue;let _=this.db.ftsSearch(L,n,r,s,i);g+=_.length;for(let N of _){let A=N.id;if(u.has(A))continue;let k=this.calcFtsScore(p,N.name);u.set(A,{symbol:N,filePath:N.file_path,score:k,matchReason:`FTS5 \u524D\u7F00\u5339\u914D ("${L}")`});}}if(d["2_fts"]=Math.round((performance.now()-m)*100)/100,u.size>=i)return {results:this.rankResults(u,i),debug:l?{phase_timings:d,candidate_count:g}:void 0};let b=a&&p.length>=3,T=0;if(b){let L=performance.now(),_=this.db.getAllSymbolNames(s),N=p.toLowerCase(),A=w(p).split(" ");for(let{name:k,file_path:P,id:I}of _){if(u.has(I))continue;T++;let B=Ze(N,k.toLowerCase()),se=Math.max(N.length,k.length),be=Math.min(un,Math.max(1,Math.floor(se*.28)));if(B<=be){let Z=Math.max(0,80-B*15),Y=this.db.getSymbolById(I);if(!Y||n&&Y.category!==n||r&&Y.framework!==r)continue;let qe=rn(p,k,B);u.set(I,{symbol:Y,filePath:P,score:Z,matchReason:`\u6A21\u7CCA\u5339\u914D (\u7F16\u8F91\u8DDD\u79BB=${B})`,spellingSuggestion:qe});continue}let Re=w(k).split(" "),J=A.filter(Z=>Re.some(Y=>Y.length>=3&&nn(Z,Y)>=75));if(A.length>1?J.length===A.length:J.length>0){let Z=50+J.length*10,Y=this.db.getSymbolById(I);if(!Y||n&&Y.category!==n||r&&Y.framework!==r)continue;u.set(I,{symbol:Y,filePath:P,score:Z,matchReason:`\u5355\u8BCD\u5339\u914D (${J.join(", ")})`});}}d["3_fuzzy"]=Math.round((performance.now()-L)*100)/100;}if(u.size===0&&c){let L=performance.now(),_=this.db.ftsSearchWithFallback(p,n,r,s,i);for(let N of _){let A=N.id;u.has(A)||u.set(A,{symbol:N,filePath:N.file_path,score:50,matchReason:"LIKE \u5168\u8868\u626B\u63CF fallback"});}d["4_fallback"]=Math.round((performance.now()-L)*100)/100;}let E=l?{phase_timings:d,candidate_count:g+T,fallback_reason:!b&&p.length<3?"\u67E5\u8BE2\u8FC7\u77ED (<3\u5B57\u7B26)\uFF0C\u8DF3\u8FC7\u6A21\u7CCA\u5339\u914D":void 0}:void 0;return {results:this.rankResults(u,i),debug:E}}calcFtsScore(e,t){let n=e.toLowerCase(),r=t.toLowerCase();if(r===n)return 98;if(r.startsWith(n))return 91;if(r.includes(n))return 80;let s=w(e).split(" "),i=w(t).split(" "),a=s.some(l=>i[0]?.startsWith(l))?8:0,c=s.filter(l=>i.some(p=>p.startsWith(l))).length;return Math.min(88,58+c*8+a)}rankResults(e,t){return Array.from(e.values()).sort((n,r)=>r.score-n.score).slice(0,t)}searchByBehavior(e){return this.db.behaviorSearch(e.category,e.apiName,e.operation,e.keyword,e.filePath).map(n=>({symbolName:n.symbol_name,category:n.category,apiName:n.api_name,operation:n.operation,detail:n.detail,line:n.line_number,filePath:n.file_path,startLine:n.start_line,endLine:n.end_line}))}};var Bn=createRequire(import.meta.url),Ne="\u9879\u76EE\u6839\u76EE\u5F55\uFF08\u53EF\u7701\u7565\uFF0C\u81EA\u52A8\u4F7F\u7528\u4E0A\u6B21 skimmer_index_project \u6307\u5B9A\u7684\u9879\u76EE\uFF09";function ge(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var ze="(?:=|\\+=|-=|\\*=|\\/=|%=|\\|=|&=|\\^=|&&=|\\|\\|=|\\?\\?=)",Hn="(?:push|pop|shift|unshift|splice|sort|reverse|copyWithin|fill)";async function Fn(o,e,t,n,r){if(!n)return null;let s=t.getPrecisePendingCount();if(s<=0)return null;let i=await o.getIndexer(e).selectivePrecise({maxFiles:r,maxTimeMs:1500});return {pendingBefore:s,reindexedFiles:i.reindexedFiles,affectedFiles:i.affectedFiles.length,skippedByBudget:i.skippedByBudget}}function Dn(o){if(!o)return [];let e=[`\u{1F504} \u5DF2\u81EA\u52A8\u8865\u7B97 pending precise: ${o.reindexedFiles}/${o.affectedFiles} \u6587\u4EF6\uFF08\u67E5\u8BE2\u524D\u5F85\u8865 ${o.pendingBefore}\uFF09`];return o.skippedByBudget>0&&e.push(` \u23F8\uFE0F \u4ECD\u6709 ${o.skippedByBudget} \u4E2A precise pending \u6587\u4EF6\u53D7\u9884\u7B97\u9650\u5236\u672A\u8865\u5B8C\uFF0C\u53EF\u518D\u6B21\u67E5\u8BE2\u6216\u8C03\u7528 selective_precise=true \u7EE7\u7EED`),e.push(""),e}function Ie(o,e,t){let n=[];for(let r of o){if(!r?.abs_path||!te__default.existsSync(r.abs_path))continue;let s=te__default.readFileSync(r.abs_path,"utf-8").split(`
|
|
502
|
+
`);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 Mn(o,e){let t=ge(o),n=[{kind:"declaration",regex:new RegExp(`\\b(?:const|let|var)\\s+${t}\\b`)},{kind:"assignment",regex:new RegExp(`\\b${t}\\b\\s*${ze}`)},{kind:"update",regex:new RegExp(`(?:\\+\\+|--)\\s*\\b${t}\\b|\\b${t}\\b\\s*(?:\\+\\+|--)`)}];return e&&n.push({kind:"property_assignment",regex:new RegExp(`\\b${t}\\.[A-Za-z_$][\\w$]*\\s*${ze}`)},{kind:"indexed_assignment",regex:new RegExp(`\\b${t}\\s*\\[[^\\]]+\\]\\s*${ze}`)},{kind:"array_mutation",regex:new RegExp(`\\b${t}\\.${Hn}\\s*\\(`)}),n}function At(o){try{return Bn("@babel/parser").parse(o,{sourceType:"module",plugins:["typescript","jsx","decorators-legacy"],errorRecovery:!0})}catch{return null}}function Lt(o,e){if(!o.endsWith(".vue"))return [{content:e,lineOffset:1}];try{let{parse:s}=Bn("@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(`
|
|
503
|
+
`).length;return [{content:t[1],lineOffset:r}]}function he(o,e){return (o.loc?.start?.line??1)+e-1}function Yt(o,e){if(o.type!=="MemberExpression")return false;let t=o.object;return !t||t.type!=="ThisExpression"?false:X(o)===e}function zt(o,e){return !!o&&o.type==="Identifier"&&String(o.name||"")===e}function Xn(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 Gt(o,e,t=2){if(!te__default.existsSync(o))return {snippet:"",startLine:e};let n=te__default.readFileSync(o,"utf-8").split(`
|
|
487
504
|
`),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(`
|
|
488
|
-
`),startLine:r+1}}function
|
|
489
|
-
`),a=
|
|
490
|
-
`),a=
|
|
491
|
-
`),c=
|
|
492
|
-
`),c=
|
|
505
|
+
`),startLine:r+1}}function Tt(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 jn={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 Un(o,e,t){let n=[];for(let r of o){if(!r.abs_path||!te__default.existsSync(r.abs_path))continue;let s=te__default.readFileSync(r.abs_path,"utf-8"),i=s.split(`
|
|
506
|
+
`),a=Lt(r.path||q__default.basename(r.abs_path),s);for(let c of a){let l=At(c.content);l&&fe(l,p=>{if(n.length>=t||p.type!=="VariableDeclarator")return;let u=p.id;if(!u||u.type!=="Identifier")return;let d=String(u.name||"");if(!d||d===e)return;let h=p.init;if(!h)return;let f=false;if(h.type==="Identifier"&&String(h.name||"")===e?f=true:h.type==="MemberExpression"&&(f=Yt(h,e)||X(h)===e),!f)return;let m=he(p,c.lineOffset),g=i[m-1]?.trim()||"";n.push({alias:d,filePath:r.path,abs_path:r.abs_path,line:m,text:g});});}}return n}function Wn(o,e,t){let n=[];for(let r of o){if(!r.abs_path||!te__default.existsSync(r.abs_path))continue;let s=te__default.readFileSync(r.abs_path,"utf-8"),i=s.split(`
|
|
507
|
+
`),a=Lt(r.path||q__default.basename(r.abs_path),s);for(let c of a){let l=At(c.content);l&&fe(l,p=>{if(n.length>=t||p.type!=="VariableDeclarator")return;let u=p.id;if(!u||u.type!=="ObjectPattern")return;let d=u.properties||[];for(let h of d){if(h.type!=="ObjectProperty"&&h.type!=="Property")continue;let f=h.key,m=h.value,g=f?.type==="Identifier"?String(f.name||""):null;if(g!==e)continue;let y=m?.type==="Identifier"?String(m.name||""):g;if(!y)continue;let S=he(p,c.lineOffset),b=i[S-1]?.trim()||"";n.push({alias:y,filePath:r.path,line:S,text:b});}});}}return n}function qt(o,e,t,n){let r=[];for(let s of o){if(!s.abs_path||!te__default.existsSync(s.abs_path))continue;let i=te__default.readFileSync(s.abs_path,"utf-8"),a=i.split(`
|
|
508
|
+
`),c=Lt(s.path||q__default.basename(s.abs_path),i);for(let l of c){let p=At(l.content);if(p&&(fe(p,u=>{if(!(r.length>=n)){if(u.type==="VariableDeclarator"){let d=u.id;if(zt(d,e)){let h=he(u,l.lineOffset);r.push({filePath:s.path,line:h,kind:"declaration",text:a[h-1]?.trim()||""});}}if(u.type==="AssignmentExpression"){let d=u.left;if(!d)return;let h=he(u,l.lineOffset);if(zt(d,e)||Yt(d,e)){r.push({filePath:s.path,line:h,kind:"assignment",text:a[h-1]?.trim()||""});return}t&&d.type==="MemberExpression"&&ee(d)===e&&r.push({filePath:s.path,line:h,kind:d.computed?"indexed_assignment":"property_assignment",text:a[h-1]?.trim()||""});}if(u.type==="UpdateExpression"){let d=u.argument;if(!d)return;if(zt(d,e)||Yt(d,e)){let h=he(u,l.lineOffset);r.push({filePath:s.path,line:h,kind:"update",text:a[h-1]?.trim()||""});}}if(t&&(u.type==="CallExpression"||u.type==="OptionalCallExpression")){let d=u.callee;if(!d||d.type!=="MemberExpression"&&d.type!=="OptionalMemberExpression"||ee(d)!==e)return;let f=X(d);if(!f||!/^(push|pop|shift|unshift|splice|sort|reverse|copyWithin|fill)$/.test(f))return;let m=he(u,l.lineOffset);r.push({filePath:s.path,line:m,kind:"array_mutation",text:a[m-1]?.trim()||""});}}}),r.length>=n))break}if(r.length>=n)break}return Xn(r).slice(0,n)}function St(o,e,t,n){let r=[];for(let s of o){if(!s.abs_path||!te__default.existsSync(s.abs_path))continue;let i=te__default.readFileSync(s.abs_path,"utf-8"),a=i.split(`
|
|
509
|
+
`),c=Lt(s.path||q__default.basename(s.abs_path),i);for(let l of c){let p=At(l.content);if(p&&(fe(p,u=>{if(!(r.length>=n)){if(u.type==="AssignmentExpression"){let d=u.left;if(!d||d.type!=="MemberExpression"||ee(d)!==e)return;let f=X(d);if(t&&f!==t)return;let m=he(u,l.lineOffset);r.push({filePath:s.path,line:m,kind:d.computed?"bracket":"dot",text:a[m-1]?.trim()||""});}if(u.type==="UpdateExpression"){let d=u.argument;if(!d||d.type!=="MemberExpression"||ee(d)!==e)return;let f=X(d);if(t&&f!==t)return;let m=he(u,l.lineOffset);r.push({filePath:s.path,line:m,kind:d.computed?"bracket":"dot",text:a[m-1]?.trim()||""});}if(u.type==="UnaryExpression"&&u.operator==="delete"){let d=u.argument;if(!d||d.type!=="MemberExpression"||ee(d)!==e)return;let f=X(d);if(t&&f!==t)return;let m=he(u,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 Xn(r).slice(0,n)}function Kn(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
|
|
493
510
|
\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
|
|
494
511
|
\u9A7C\u5CF0\u62C6\u8BCD\uFF1A\u641C "change cache" \u4E5F\u80FD\u627E\u5230 "changeCacheValue"\u3002
|
|
495
512
|
\u6846\u67B6\u611F\u77E5\uFF1A\u53EF\u6309 vue2/vue3/react \u8FC7\u6EE4\u3002
|
|
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(
|
|
513
|
+
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(Ne),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 u=performance.now(),{db:d}=e.getContext(n),h=new Ve(d),{results:f,debug:m}=h.search(t,{category:r==="all"?void 0:r,framework:s==="all"?void 0:s,filePath:i,fuzzy:a,limit:p,allowFallbackScan:c,debug:l}),g=Math.round((performance.now()-u)*100)/100,y=H({durationMs:g,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
|
|
497
514
|
|
|
498
515
|
\u{1F4A1} \u5C1D\u8BD5:
|
|
499
516
|
skimmer_find_by_behavior \u6309\u884C\u4E3A\u641C\u7D22
|
|
@@ -501,50 +518,56 @@ project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({query:z$1.string(
|
|
|
501
518
|
\u{1F4A1} \u5C1D\u8BD5: skimmer_find_symbol({ allow_fallback_scan: true }) \u542F\u7528\u5168\u8868\u626B\u63CF`}
|
|
502
519
|
|
|
503
520
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
504
|
-
${W(
|
|
505
|
-
`];return f.forEach((
|
|
506
|
-
${W(
|
|
521
|
+
${W(y)}`}]};let S=[`\u{1F50D} \u641C\u7D22 "${t}" \u2014 \u627E\u5230 ${f.length} \u4E2A\u7ED3\u679C
|
|
522
|
+
`];return f.forEach((b,T)=>{let E=b.symbol,L=Ue(E.params_json,[]),_=L.length>0?`(${L.join(", ")})`:"",N=Te(E.start_line,E.end_line);S.push(`${T+1}. ${E.name}${_} [${E.category}/${E.framework}] \u5339\u914D\u5EA6: ${b.score}%`),S.push(` \u{1F4C4} ${b.filePath}:${N}`),S.push(` \u{1F3AF} ${b.matchReason}`),b.spellingSuggestion&&S.push(` \u{1F4A1} ${b.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
|
|
523
|
+
${W(y)}`),{content:[{type:"text",text:S.join(`
|
|
507
524
|
`)}]}}),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
|
|
508
525
|
\u540C\u65F6\u8FD4\u56DE\u8BE5\u7B26\u53F7\u7684\u884C\u4E3A\u6807\u7B7E\uFF08\u64CD\u4F5C\u4E86\u54EA\u4E9B\u5916\u90E8 API\uFF09\u3002
|
|
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(
|
|
510
|
-
|
|
526
|
+
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(Ne),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 N=Math.round((performance.now()-i)*100)/100,A=H({durationMs:N,resultCount:0,backend:"indexed"}),k=a.exactSearch(n,void 0,void 0,void 0),P=k.length>0?`
|
|
527
|
+
|
|
528
|
+
\u{1F50E} \u540C\u540D\u7B26\u53F7\u5B58\u5728\u4E8E\u5176\u4ED6\u4F4D\u7F6E:
|
|
529
|
+
${k.slice(0,5).map((I,B)=>` ${B+1}. ${I.name} [${I.category}/${I.framework}] \u{1F4C4} ${I.file_path}:${Te(I.start_line,I.end_line)}`).join(`
|
|
530
|
+
`)}
|
|
531
|
+
|
|
532
|
+
\u{1F4A1} \u53EF\u6539\u7528: skimmer_get_code_slice({ file_path: "${k[0].file_path}", symbol_name: "${n}" })`:`
|
|
511
533
|
|
|
512
|
-
\u{1F4A1} \u8BD5\u8BD5: skimmer_find_symbol({ query: "${n}" })
|
|
534
|
+
\u{1F4A1} \u8BD5\u8BD5: skimmer_find_symbol({ query: "${n}" })`;return {content:[{type:"text",text:`\u274C \u672A\u627E\u5230: ${n}
|
|
535
|
+
\u{1F4C4} \u8BF7\u6C42\u6587\u4EF6: ${t}${P}
|
|
513
536
|
|
|
514
537
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
515
|
-
${W(
|
|
516
|
-
`),
|
|
517
|
-
`),
|
|
538
|
+
${W(A)}`}]}}let l=c.abs_path;if(!te__default.existsSync(l))return {content:[{type:"text",text:`\u274C \u6587\u4EF6\u4E0D\u5B58\u5728: ${l}`}]};let u=te__default.readFileSync(l,"utf-8").split(`
|
|
539
|
+
`),d=Math.max(1,c.start_line-s)-1,h=Math.min(u.length,c.end_line+s),f=u.slice(d,h).join(`
|
|
540
|
+
`),g=f.includes(n)?"":`
|
|
518
541
|
\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
|
|
519
|
-
\u6587\u4EF6\u5DF2\u88AB\u4FEE\u6539\u4F46\u7D22\u5F15\u672A\u66F4\u65B0\uFF0C\u884C\u53F7\u53EF\u80FD\u504F\u79FB ${
|
|
542
|
+
\u6587\u4EF6\u5DF2\u88AB\u4FEE\u6539\u4F46\u7D22\u5F15\u672A\u66F4\u65B0\uFF0C\u884C\u53F7\u53EF\u80FD\u504F\u79FB ${u.length-c.end_line} \u884C\u5DE6\u53F3\u3002
|
|
520
543
|
\u5EFA\u8BAE: skimmer_index_project({ force: true })
|
|
521
|
-
`,{behaviors:
|
|
522
|
-
\`\`\`${
|
|
544
|
+
`,{behaviors:y}=a.getFileOutline(t),S=y.filter(N=>N.symbol_id===c.id),b=l.split(".").pop()||"js",T=["tsx","jsx"].includes(b)?"jsx":["ts"].includes(b)?"typescript":"javascript",E=[`\u{1F4CD} ${c.name} [${c.category}/${c.framework}]`,`\u{1F4C4} ${t}:${Te(c.start_line,c.end_line)}`];if(g&&E.push(g),c.jsdoc&&E.push(`\u{1F4DD} ${c.jsdoc}`),S.length>0){let N=[...new Set(S.map(A=>`[${A.category}:${A.api_name}.${A.operation}${A.detail?`("${A.detail}")`:""}]`))];E.push(`\u{1F3F7}\uFE0F \u884C\u4E3A: ${N.join(" ")}`);}E.push(`
|
|
545
|
+
\`\`\`${T}`),E.push(f),E.push("```");let L=Math.round((performance.now()-i)*100)/100,_=H({durationMs:L,resultCount:1,backend:"indexed"});return E.push(`
|
|
523
546
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
524
|
-
${W(
|
|
547
|
+
${W(_)}`),{content:[{type:"text",text:E.join(`
|
|
525
548
|
`)}]}}),o.registerTool("skimmer_trace_assignments",{title:"\u8FFD\u8E2A\u53D8\u91CF\u8D4B\u503C\u94FE\u8DEF\uFF08\u8F7B\u91CF\uFF09",description:`\u3010\u964D\u7EA7\u5DE5\u5177\u3011\u4EC5\u5728\u4EE5\u4E0B\u573A\u666F\u5355\u72EC\u4F7F\u7528\uFF1A\u53EA\u9700\u67E5\u770B\u67D0\u4E2A\u7B80\u5355\u53D8\u91CF\uFF08\u975E\u5BF9\u8C61\uFF09\u7684\u8D4B\u503C\u4F4D\u7F6E\uFF0C\u4E14\u4E0D\u5173\u5FC3\u5C5E\u6027\u4FEE\u6539/\u53C2\u6570\u4F20\u9012/storage\u94FE\u8DEF\u3002
|
|
526
549
|
\u26A0\uFE0F \u7EDD\u5927\u591A\u6570\u53D8\u91CF\u6EAF\u6E90\u573A\u666F\u8BF7\u4F18\u5148\u4F7F\u7528 skimmer_trace_data_lifecycle\uFF0C\u5B83\u80FD\u4E00\u6B21\u62FF\u5230\u6240\u6709\u4FE1\u606F\u3002
|
|
527
550
|
\u2705 \u672C\u5DE5\u5177\u9002\u5408\uFF1Aloading / errorMsg / count \u8FD9\u7C7B\u7B80\u5355 flag \u7684\u8D4B\u503C\u8FFD\u8E2A\u3002
|
|
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(
|
|
551
|
+
\u274C \u4E0D\u9002\u5408\uFF1AstorageParams / savedData \u8FD9\u7C7B\u5BF9\u8C61\u3001\u9700\u8981\u8FFD\u8E2A\u5B8C\u6574\u6570\u636E\u6D41\u7684\u573A\u666F\u3002`,inputSchema:z$1.object({variable:z$1.string().describe('\u53D8\u91CF\u540D\uFF0C\u5982 "changeResult"'),project_path:z$1.string().optional().describe(Ne),file_path:z$1.string().optional().describe("\u9650\u5B9A\u6587\u4EF6\u8DEF\u5F84\uFF08\u5305\u542B\u5373\u53EF\uFF09"),include_properties:z$1.boolean().optional().default(true).describe("\u662F\u5426\u5305\u542B variable.xxx / variable[...] \u8D4B\u503C"),limit:z$1.number().optional().default(80)}),annotations:{readOnlyHint:true,destructiveHint:false}},async({variable:t,project_path:n,file_path:r,include_properties:s,limit:i})=>{let a=performance.now(),{db:c}=e.getContext(n),l=c.listFiles(r),p=Math.min(300,Math.max(1,i||80)),u=s??true,d=c.exactSearch(t,"state",void 0,r||void 0),h={vue2:"Vue2 data()",vue3:"Vue3 ref/reactive",react:"React useState/useRef"},f=d.filter(E=>E.default_value!=null).map(E=>({filePath:E.file_path,line:E.start_line,kind:`data_init(${h[E.framework]||E.framework})`,text:`${E.name}: ${E.default_value} \u2190 \u58F0\u660E\u521D\u59CB\u5316`})),m=qt(l,t,u,p);if(m.length===0){let E=Mn(t,u);m=Ie(l,E,p);}let g=new Map;for(let E of [...f,...m]){let L=`${E.filePath}:${E.line}`;g.has(L)||g.set(L,E);}let y=[...g.values()],S=Math.round((performance.now()-a)*100)/100;if(y.length===0){let E=H({durationMs:S,resultCount:0,backend:"ast_scan"});return {content:[{type:"text",text:`\u{1F9E9} \u53D8\u91CF\u8D4B\u503C\u8FFD\u8E2A: "${t}"
|
|
529
552
|
\u672A\u627E\u5230\u5339\u914D\u8D4B\u503C\u8BED\u53E5\uFF08\u5305\u62EC\u58F0\u660E\u521D\u59CB\u5316\uFF09
|
|
530
|
-
\u8FC7\u6EE4: file_path=${r||"*"} include_properties=${
|
|
553
|
+
\u8FC7\u6EE4: file_path=${r||"*"} include_properties=${u}
|
|
531
554
|
|
|
532
555
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
533
|
-
${W(E)}`}]}}let
|
|
556
|
+
${W(E)}`}]}}let b=[`\u{1F9E9} \u53D8\u91CF\u8D4B\u503C\u8FFD\u8E2A: "${t}"`,`\u8FC7\u6EE4: file_path=${r||"*"} include_properties=${u}`,`\u547D\u4E2D: ${y.length} \u5904${f.length>0?`\uFF08\u542B ${f.length} \u5904\u58F0\u660E\u521D\u59CB\u5316\uFF09`:""}`,""];y.forEach((E,L)=>{b.push(`${L+1}. [${E.kind}] \u{1F4C4} ${E.filePath}:L${E.line}`),b.push(` ${E.text}`);});let T=H({durationMs:S,resultCount:y.length,backend:"ast_scan"});return b.push(`
|
|
534
557
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
535
|
-
${W(
|
|
558
|
+
${W(T)}`),{content:[{type:"text",text:b.join(`
|
|
536
559
|
`)}]}}),o.registerTool("skimmer_trace_property_changes",{title:"\u8FFD\u8E2A\u5BF9\u8C61\u5C5E\u6027\u4FEE\u6539",description:`\u3010\u964D\u7EA7\u5DE5\u5177\u3011\u4EC5\u5728\u4EE5\u4E0B\u573A\u666F\u5355\u72EC\u4F7F\u7528\uFF1A\u9700\u8981\u7CBE\u786E\u8FC7\u6EE4\u67D0\u4E00\u4E2A\u5177\u4F53\u5C5E\u6027\u5B57\u6BB5\uFF08\u5982 storageParams.receiveAdr\uFF09\uFF0C\u800C\u4E0D\u9700\u8981\u6574\u4F53\u8D4B\u503C/\u53C2\u6570\u4F20\u9012/storage\u94FE\u8DEF\u4FE1\u606F\u3002
|
|
537
560
|
\u26A0\uFE0F \u7EDD\u5927\u591A\u6570\u5BF9\u8C61\u6EAF\u6E90\u573A\u666F\u8BF7\u4F18\u5148\u4F7F\u7528 skimmer_trace_data_lifecycle\uFF0C\u5B83\u80FD\u4E00\u6B21\u62FF\u5230\u6240\u6709\u4FE1\u606F\u3002
|
|
538
561
|
\u2705 \u672C\u5DE5\u5177\u9002\u5408\uFF1Aobject.specificProp \u7684\u5355\u5B57\u6BB5\u7EA7\u522B\u7CBE\u786E\u8FFD\u8E2A\u3002
|
|
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(
|
|
540
|
-
\u522B\u540D\u5C55\u5F00: ${
|
|
541
|
-
\u672A\u627E\u5230\u5339\u914D\u8BED\u53E5${
|
|
562
|
+
\u274C \u4E0D\u9002\u5408\uFF1A\u9700\u8981\u4E86\u89E3\u5BF9\u8C61\u6574\u4F53\u6765\u6E90\u6216\u6570\u636E\u6D41\u5411\u7684\u573A\u666F\u3002`,inputSchema:z$1.object({object:z$1.string().describe('\u5BF9\u8C61\u540D\uFF0C\u5982 "storageParams" / "params"'),property:z$1.string().optional().describe('\u5C5E\u6027\u540D\uFF0C\u5982 "receiveAdr"'),project_path:z$1.string().optional().describe(Ne),file_path:z$1.string().optional().describe("\u9650\u5B9A\u6587\u4EF6\u8DEF\u5F84\uFF08\u5305\u542B\u5373\u53EF\uFF09"),limit:z$1.number().optional().default(80)}),annotations:{readOnlyHint:true,destructiveHint:false}},async({object:t,property:n,project_path:r,file_path:s,limit:i})=>{let a=performance.now(),{db:c}=e.getContext(r),l=c.listFiles(s),p=Math.min(300,Math.max(1,i||80)),u=Un(l,t,20),d=Wn(l,t,20),h=[...new Set([...u.map(b=>b.alias),...d.map(b=>b.alias)].filter(b=>b!==t))],f=[t,...h],m=St(l,t,n,p);for(let b of h)m.push(...St(l,b,n,Math.floor(p/2)));if(m.length===0){let b="(?:=|\\+=|-=|\\*=|/=|%=|\\|=|&=|\\^=|&&=|\\|\\|=|\\?\\?=)",T=[];for(let E of f){let L=ge(E);if(n){let _=ge(n);T.push({kind:"dot",regex:new RegExp(`\\b${L}\\.${_}\\s*${b}`)},{kind:"bracket",regex:new RegExp(`\\b${L}\\s*\\[(?:'${_}'|"${_}")\\]\\s*${b}`)},{kind:"delete",regex:new RegExp(`\\bdelete\\s+${L}\\.(?:${_})\\b`)});}else T.push({kind:"dot",regex:new RegExp(`\\b${L}\\.[A-Za-z_$][\\w$]*\\s*${b}`)},{kind:"bracket",regex:new RegExp(`\\b${L}\\s*\\[(?:'[^']+'|"[^"]+")\\]\\s*${b}`)},{kind:"delete",regex:new RegExp(`\\bdelete\\s+${L}\\.[A-Za-z_$][\\w$]*\\b`)});}m=Ie(l,T,p);}let g=Math.round((performance.now()-a)*100)/100;if(m.length===0){let b=h.length>0?`
|
|
563
|
+
\u522B\u540D\u5C55\u5F00: ${h.join(", ")}\uFF08\u5747\u672A\u547D\u4E2D\uFF09`:"",T=H({durationMs:g,resultCount:0,backend:"ast_scan"});return {content:[{type:"text",text:`\u{1F9ED} \u5C5E\u6027\u4FEE\u6539\u8FFD\u8E2A: ${t}${n?`.${n}`:".*"}
|
|
564
|
+
\u672A\u627E\u5230\u5339\u914D\u8BED\u53E5${b}
|
|
542
565
|
\u8FC7\u6EE4: file_path=${s||"*"}
|
|
543
566
|
|
|
544
567
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
545
|
-
${W(
|
|
568
|
+
${W(T)}`}]}}let y=[`\u{1F9ED} \u5C5E\u6027\u4FEE\u6539\u8FFD\u8E2A: ${t}${n?`.${n}`:".*"}`,`\u8FC7\u6EE4: file_path=${s||"*"}`];if(h.length>0){let b=u.map(E=>E.alias).filter(E=>E!==t).join(", "),T=d.map(E=>E.alias).filter(E=>E!==t).join(", ");b&&y.push(`\u26A1 \u5F15\u7528\u522B\u540D: ${b}\uFF08\u901A\u8FC7 let alias = this.${t} \u5C55\u5F00\uFF09`),T&&y.push(`\u26A1 \u89E3\u6784\u522B\u540D: ${T}\uFF08\u901A\u8FC7 const { ${t}: alias } \u5C55\u5F00\uFF09`);}y.push(`\u547D\u4E2D: ${m.length} \u5904`,""),m.forEach((b,T)=>{y.push(`${T+1}. [${b.kind}] \u{1F4C4} ${b.filePath}:L${b.line}`),y.push(` ${b.text}`);});let S=H({durationMs:g,resultCount:m.length,backend:"ast_scan"});return y.push(`
|
|
546
569
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
547
|
-
${W(S)}`),{content:[{type:"text",text:
|
|
570
|
+
${W(S)}`),{content:[{type:"text",text:y.join(`
|
|
548
571
|
`)}]}}),o.registerTool("skimmer_find_by_behavior",{title:"\u6309\u884C\u4E3A\u6807\u7B7E\u641C\u7D22\u51FD\u6570",description:`\u6309 API \u8C03\u7528\u884C\u4E3A\u641C\u7D22\uFF0C\u5B8C\u5168\u7ED5\u8FC7\u547D\u540D\u95EE\u9898\u3002
|
|
549
572
|
\u793A\u4F8B:
|
|
550
573
|
- \u627E\u6240\u6709\u64CD\u4F5C localStorage \u7684\u51FD\u6570: { category: "storage" }
|
|
@@ -552,22 +575,22 @@ ${W(S)}`),{content:[{type:"text",text:b.join(`
|
|
|
552
575
|
- \u627E\u53D1\u8BF7\u6C42\u7684: { category: "network" }
|
|
553
576
|
- \u627E\u8DEF\u7531\u8DF3\u8F6C\u7684: { category: "router" }
|
|
554
577
|
- \u6309 key \u540D\u641C\u7D22: { keyword: "cacheData" }
|
|
555
|
-
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({project_path:z$1.string().optional().describe(
|
|
578
|
+
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({project_path:z$1.string().optional().describe(Ne),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),u=new Ve(l).searchByBehavior({category:n,apiName:r,operation:s,keyword:i,filePath:a}),d=new Set(["localstorage","sessionstorage","cookie"]);r||(u=u.filter(y=>y.category!=="storage"||d.has(y.apiName.toLowerCase())));let h=Math.round((performance.now()-c)*100)/100,f=H({durationMs:h,resultCount:u.length,backend:"indexed"});if(u.length===0)return {content:[{type:"text",text:`\u{1F3F7}\uFE0F \u672A\u627E\u5230\u5339\u914D\u7684\u884C\u4E3A
|
|
556
579
|
\u8FC7\u6EE4\u6761\u4EF6: ${JSON.stringify({category:n,api_name:r,operation:s,keyword:i,file_path:a})}
|
|
557
580
|
|
|
558
581
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
559
|
-
${W(f)}`}]};let m=new Map;for(let
|
|
560
|
-
`];for(let[
|
|
561
|
-
${W(f)}`),{content:[{type:"text",text:
|
|
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(
|
|
563
|
-
`]
|
|
582
|
+
${W(f)}`}]};let m=new Map;for(let y of u){let S=`${y.category}:${y.apiName}`;m.has(S)||m.set(S,[]),m.get(S).push(y);}let g=[`\u{1F3F7}\uFE0F \u884C\u4E3A\u641C\u7D22\u7ED3\u679C \u2014 ${u.length} \u6761
|
|
583
|
+
`];for(let[y,S]of m){let[b,T]=y.split(":"),E=new Map;for(let L of S)E.has(L.operation)||E.set(L.operation,[]),E.get(L.operation).push(L);g.push(`\u{1F4C2} ${b} \u2192 ${T}:`);for(let[L,_]of E){g.push(` ${L}:`);let N=new Map;for(let A of _){let k=`${A.symbolName}|${A.filePath}`;N.has(k)||N.set(k,{item:A,callLines:[]}),N.get(k).callLines.push(A.line);}for(let{item:A,callLines:k}of N.values()){let P=A.detail?` key="${A.detail}"`:"",I=k.length>1?` \xD7${k.length} (L${k.join(", L")})`:` L${k[0]||A.startLine}`;g.push(` \u2022 ${A.symbolName}${P}${I} \u{1F4C4} ${A.filePath}:${Te(A.startLine,A.endLine)}`);}}g.push("");}return g.push(`\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
584
|
+
${W(f)}`),{content:[{type:"text",text:g.join(`
|
|
585
|
+
`)}]}}),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(Ne),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'),auto_precise:z$1.boolean().optional().default(true).describe("\u5F53\u5B58\u5728 watcher/heuristic \u4EA7\u751F\u7684 precise pending \u65F6\uFF0C\u67E5\u8BE2\u524D\u81EA\u52A8\u6309\u9884\u7B97\u8865\u7B97 precise\uFF08\u9ED8\u8BA4 true\uFF09"),max_precise_files:z$1.number().optional().default(20).describe("auto_precise \u5355\u6B21\u6700\u591A\u8865\u7B97\u6587\u4EF6\u6570\uFF08\u9ED8\u8BA4 20\uFF09")}),annotations:{readOnlyHint:true,destructiveHint:false}},async({symbol_name:t,project_path:n,file_path:r,direction:s,arg_keyword:i,auto_precise:a,max_precise_files:c})=>{let l=performance.now(),{db:p,projectRoot:u}=e.getContext(n),d=await Fn(e,u,p,a!==false,Math.max(1,c||20)),h=p.getSymbolByName(t,r),f=[`\u{1F4CA} ${t} \u7684\u8C03\u7528\u56FE\u8C31
|
|
586
|
+
`];f.push(...Dn(d));let m=0,g=0,y=[],S=[],b=void 0;if(s==="callers"||s==="both"){if(y=p.getCallers(t,b,i),m+=y.length,g+=y.filter(N=>N.edge_kind==="precise").length,f.push(`\u2B06\uFE0F \u88AB\u8C03\u7528 (${y.length} \u5904):`),y.length===0)f.push(" \uFF08\u672A\u627E\u5230\u8C03\u7528\u8005\uFF09");else {let N={method_call:"",template_event:"\u{1F5BC}\uFE0F",jsx_event:"\u269B\uFE0F",hook_call:"\u{1FA9D}",import_call:"\u{1F4E5}",router_call:"\u{1F6E3}\uFE0F",store_dispatch:"\u{1F4E6}",store_commit:"\u{1F4E6}",constructor_call:"\u{1F195}"};for(let A of y){let k=A.args?` \u53C2\u6570: "${A.args}"`:"",P=A.source_kind||"",I=A.edge_kind||"",B=N[P]?` ${N[P]}`:"",se=I==="precise"?" [\u{1F3AF}precise]":"";f.push(` \u2022 ${A.caller_name} [${A.category}]${B}${se} \u{1F4C4} ${A.file_path}:L${A.start_line}${k}`);}}f.push("");}if((s==="callees"||s==="both")&&h){if(S=p.getCallees(h.id),m+=S.length,g+=S.filter(N=>N.edge_kind==="precise").length,f.push(`\u2B07\uFE0F \u8C03\u7528\u4E86 (${S.length} \u4E2A):`),S.length===0)f.push(" \uFF08\u672A\u5206\u6790\u5230\u8C03\u7528\u5173\u7CFB\uFF09");else for(let N of S){let A=N.args?`("${N.args}")`:"",P=(N.edge_kind||"")==="precise"?" [\u{1F3AF}precise]":"";f.push(` \u2022 ${N.callee_name}${A} [${N.call_type}]${P} L${N.line_number}`);}f.push("");}if(h){let{behaviors:N}=p.getFileOutline(h.file_path),A=N.filter(k=>k.symbol_id===h.id);if(A.length>0){f.push("\u{1F4E6} \u5916\u90E8\u72B6\u6001\u64CD\u4F5C:");for(let k of A){let P=k.detail?` ("${k.detail}")`:"";f.push(` \u2022 ${k.api_name}.${k.operation}${P} [${k.category}] L${k.line_number}`);}}}let T=Math.round((performance.now()-l)*100)/100,E=g>0?"precise":"heuristic",L=[];E==="heuristic"&&m>0&&L.push('\u5F53\u524D\u7ED3\u679C\u4E3A\u542F\u53D1\u5F0F\u8FB9\uFF1B\u5982\u5B58\u5728\u540C\u540D\u7B26\u53F7\u3001\u91CD\u5BFC\u51FA\u6216\u590D\u6742 import\uFF0C\u53EF\u7528 skimmer_index_project({ precision_mode: "precise" }) \u8FDB\u4E00\u6B65\u6D88\u6B67');let _=H({durationMs:T,resultCount:m,backend:"indexed",precisionEffective:E,precisionWarnings:L.length>0?L:void 0});return f.push(`
|
|
564
587
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
565
|
-
${W(
|
|
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(
|
|
567
|
-
`),
|
|
568
|
-
\u26A0\uFE0F \u4FEE\u6539\u65F6\u6CE8\u610F\u5916\u90E8\u72B6\u6001\u7684\u8BFB\u5199\u683C\u5F0F\u4FDD\u6301\u4E00\u81F4`);}let
|
|
588
|
+
${W(_)}`),{content:[{type:"text",text:f.join(`
|
|
589
|
+
`)}]}}),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(Ne),file_path:z$1.string().optional().describe("\u6587\u4EF6\u8DEF\u5F84\uFF08\u540C\u540D\u65F6\u7CBE\u786E\u5B9A\u4F4D\uFF09"),auto_precise:z$1.boolean().optional().default(true).describe("\u5F53\u5B58\u5728 watcher/heuristic \u4EA7\u751F\u7684 precise pending \u65F6\uFF0C\u67E5\u8BE2\u524D\u81EA\u52A8\u6309\u9884\u7B97\u8865\u7B97 precise\uFF08\u9ED8\u8BA4 true\uFF09"),max_precise_files:z$1.number().optional().default(20).describe("auto_precise \u5355\u6B21\u6700\u591A\u8865\u7B97\u6587\u4EF6\u6570\uFF08\u9ED8\u8BA4 20\uFF09")}),annotations:{readOnlyHint:true,destructiveHint:false}},async({symbol_name:t,project_path:n,file_path:r,auto_precise:s,max_precise_files:i})=>{let a=performance.now(),{db:c,projectRoot:l}=e.getContext(n),p=await Fn(e,l,c,s!==false,Math.max(1,i||20)),u=c.getSymbolByName(t,r),d=c.getCallers(t),{behaviors:h}=u?c.getFileOutline(u.file_path):{behaviors:[]},f=u?h.filter(E=>E.symbol_id===u.id):[],m=d.length===0?"\u{1F7E2}":d.length<=3?"\u{1F7E1}":"\u{1F534}",g=d.length===0?"\u4F4E":d.length<=3?"\u4E2D":"\u9AD8",y=[`\u{1F4A5} \u4FEE\u6539 ${t} \u7684\u5F71\u54CD\u8BC4\u4F30`,"\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501",...Dn(p),`${m} \u98CE\u9669\u7B49\u7EA7: ${g} (${d.length} \u5904\u76F4\u63A5\u8C03\u7528)`,""],S={method_call:"\u{1F4DE} \u65B9\u6CD5\u8C03\u7528",template_event:"\u{1F5BC}\uFE0F \u6A21\u677F\u4E8B\u4EF6",jsx_event:"\u269B\uFE0F JSX\u4E8B\u4EF6",hook_call:"\u{1FA9D} Hook\u8C03\u7528",import_call:"\u{1F4E5} \u5BFC\u5165\u8C03\u7528",router_call:"\u{1F6E3}\uFE0F \u8DEF\u7531",store_dispatch:"\u{1F4E6} Store",store_commit:"\u{1F4E6} Commit",constructor_call:"\u{1F195} \u6784\u9020\u5B9E\u4F8B"};if(d.length>0?(y.push("\u{1F534} \u76F4\u63A5\u5F71\u54CD:"),d.forEach((E,L)=>{let _=E.source_kind||"",N=S[_]?` ${S[_]}`:"";y.push(` ${L+1}. ${E.caller_name} [${E.category}]${N} \u{1F4C4} ${E.file_path}:L${E.start_line}`);}),y.push("")):y.push(`\u2705 \u65E0\u8C03\u7528\u8005\uFF0C\u5F71\u54CD\u8303\u56F4\u53EF\u63A7
|
|
590
|
+
`),u){let E=c.getFileDependencies(u.file_path,"to");if(E.length>0){y.push(`\u{1F4C2} \u6587\u4EF6\u4F9D\u8D56 (${E.length} \u4E2A\u6587\u4EF6 import \u4E86\u6B64\u6587\u4EF6):`);let L={import:"\u{1F4E5}",re_export:"\u{1F504}",component_ref:"\u{1F9E9}",store_ref:"\u{1F4E6}",api_ref:"\u{1F310}"};E.slice(0,10).forEach(_=>{y.push(` ${L[_.dependency_kind]||"\u2022"} ${_.from_file} (${_.dependency_kind})`);}),y.push("");}}if(f.length>0){y.push("\u{1F4E6} \u5916\u90E8\u72B6\u6001\u5F71\u54CD:");for(let E of f)y.push(` \u2022 ${E.api_name}.${E.operation}${E.detail?` key="${E.detail}"`:""} [${E.category}]`);y.push(`
|
|
591
|
+
\u26A0\uFE0F \u4FEE\u6539\u65F6\u6CE8\u610F\u5916\u90E8\u72B6\u6001\u7684\u8BFB\u5199\u683C\u5F0F\u4FDD\u6301\u4E00\u81F4`);}let b=Math.round((performance.now()-a)*100)/100,T=H({durationMs:b,resultCount:d.length,backend:"indexed"});return y.push(`
|
|
569
592
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
570
|
-
${W(
|
|
593
|
+
${W(T)}`),{content:[{type:"text",text:y.join(`
|
|
571
594
|
`)}]}}),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
|
|
572
595
|
|
|
573
596
|
\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
|
|
@@ -586,39 +609,39 @@ ${W(h)}`),{content:[{type:"text",text:g.join(`
|
|
|
586
609
|
\u65E7\u65B9\u5F0F: trace_assignments \u2192 find_symbol \u2192 get_code_slice \u2192 find_by_behavior \u2192 trace_key_flow
|
|
587
610
|
\u65B0\u65B9\u5F0F: skimmer_trace_data_lifecycle({ variable: "xxx" }) \u2190 \u76F4\u63A5\u5F97\u5230\u5168\u90E8
|
|
588
611
|
|
|
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(
|
|
590
|
-
`+f.staleFilePaths.slice(0,3).map(
|
|
612
|
+
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({variable:z$1.string().describe('\u8981\u8FFD\u8E2A\u7684\u53D8\u91CF\u540D\u6216 key\uFF0C\u5982 "storageParams" / "savedData"'),project_path:z$1.string().optional().describe(Ne),file_path:z$1.string().optional().describe('\u9650\u5B9A\u6587\u4EF6\u8DEF\u5F84\uFF08\u5305\u542B\u5373\u53EF\uFF0C\u5982 "src/views/apply/index.vue"\uFF09'),storage_api:z$1.enum(["localStorage","sessionStorage","all"]).optional().default("all").describe("storage \u843D\u70B9\u8FC7\u6EE4"),max_depth:z$1.number().optional().default(2).describe("storage \u94FE\u8DEF\u5411\u4E0B\u8FFD\u8E2A\u6DF1\u5EA6\uFF081-5\uFF09"),limit:z$1.number().optional().default(40).describe("\u6BCF\u7EF4\u5EA6\u6700\u5927\u7ED3\u679C\u6570")}),annotations:{readOnlyHint:true,destructiveHint:false}},async({variable:t,project_path:n,file_path:r,storage_api:s,max_depth:i,limit:a})=>{let c=performance.now(),{db:l}=e.getContext(n),p=Math.min(5,Math.max(1,i||2)),u=Math.min(120,Math.max(1,a||40)),d=l.listFiles(r),h="",f=Pn(l,d,r?d.length:5);f.stale&&(h=`\u26A0\uFE0F [\u7D22\u5F15\u5DF2\u8FC7\u671F] \u4EE5\u4E0B\u6587\u4EF6\u5DF2\u4FEE\u6539\u4F46\u7D22\u5F15\u672A\u66F4\u65B0\uFF0C\u2462 \u53C2\u6570\u4F20\u9012 \u548C \u2464 storage \u94FE\u8DEF\u7684\u884C\u53F7\u53EF\u80FD\u504F\u79FB:
|
|
613
|
+
`+f.staleFilePaths.slice(0,3).map(x=>` \u2022 ${x}`).join(`
|
|
591
614
|
`)+`
|
|
592
615
|
\u5EFA\u8BAE: skimmer_index_project({ force: true })
|
|
593
|
-
`);let m=
|
|
594
|
-
\u{1F517} \u53D1\u73B0\u522B\u540D: ${
|
|
616
|
+
`);let m=Wn(d,t,20),g=[...new Set(m.map(x=>x.alias).filter(x=>x!==t))],y=Un(d,t,20),S=[...new Set(y.map(x=>x.alias).filter(x=>x!==t))],b=[...new Set([...g,...S])],E=[t,...b],L=l.exactSearch(t,"state",void 0,r||void 0),_={vue2:"Vue2 data()",vue3:"Vue3 ref/reactive",react:"React useState/useRef"},N=L.filter(x=>x.default_value!=null).map(x=>({filePath:x.file_path,line:x.start_line,kind:`data_init(${_[x.framework]||x.framework})`,text:`${x.name}: ${x.default_value} \u2190 \u58F0\u660E\u521D\u59CB\u5316`})),A=false,k=l.getAssignments(t,r,u),P=[];k.length>0?(P=k.map(x=>({filePath:x.file_path,line:x.line_number,kind:x.kind,text:x.text_snippet||"",sourceLayer:x.source_layer||void 0})),A=true):P=qt(d,t,false,u);for(let x of b){let $=l.getAssignments(x,r,Math.floor(u/2));$.length>0?P.push(...$.map(R=>({filePath:R.file_path,line:R.line_number,kind:R.kind,text:R.text_snippet||"",sourceLayer:R.source_layer||void 0}))):P.push(...qt(d,x,false,Math.floor(u/2)));}let I=P.length===0?Ie(d,Mn(t,false),u):[],B=new Map;for(let x of [...N,...P.length>0?P:I]){let $=`${x.filePath}:${x.line}`;B.has($)||B.set($,x);}let se=[...B.values()],be=false,Re=l.getPropertyWrites(t,void 0,r,u),J=[];Re.length>0?(J=Re.map(x=>({filePath:x.file_path,line:x.line_number,kind:x.kind,text:x.text_snippet||"",sourceLayer:x.source_layer||void 0})),be=true):J=St(d,t,void 0,u);for(let x of b){let $=l.getPropertyWrites(x,void 0,r,Math.floor(u/2));$.length>0?J.push(...$.map(R=>({filePath:R.file_path,line:R.line_number,kind:R.kind,text:R.text_snippet||"",sourceLayer:R.source_layer||void 0}))):J.push(...St(d,x,void 0,Math.floor(u/2)));}let Ge=J.length===0?Ie(d,[{kind:"dot",regex:new RegExp(`\\b${ge(t)}\\.[A-Za-z_$][\\w$]*\\s*${ze}`)},{kind:"bracket",regex:new RegExp(`\\b${ge(t)}\\s*\\[(?:'[^']+'|"[^"]+")\\]\\s*${ze}`)},{kind:"array_mutation",regex:new RegExp(`\\b${ge(t)}\\.${Hn}\\s*\\(`)},{kind:"delete",regex:new RegExp(`\\bdelete\\s+${ge(t)}\\.[A-Za-z_$][\\w$]*\\b`)}],u):[],ke=J.length>0?J:Ge,Z=l.findRelationsByArgKeyword(t,r,u);for(let x of b)Z.push(...l.findRelationsByArgKeyword(x,r,Math.floor(u/2)));let Y=[],qe=[],Zt=[];for(let x of E){let $=ge(x),R=/^[a-zA-Z_$][\w$]*$/.test(x)?"\\b":"";Y.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}[^)]*\\)`)}),qe.push(`${R}${$}${R}\\s*(?:=|\\+=|-=|\\*=|\\/=)(?!=)|\\b(?:const|let|var)\\s+${$}\\b`),Zt.push(`${R}${$}${R}\\.\\w+\\s*(?:=|\\+=|-=)(?!=)|${R}${$}${R}\\s*\\[`);}let Zn=Ie(d,Y,u),Qn=new RegExp(qe.join("|")),er=new RegExp(Zt.join("|")),Oe=Zn.filter(x=>!Qn.test(x.text)&&!er.test(x.text)),Rt=new Map,Qt=(x,$)=>{if(!Rt.has(x)){let{behaviors:F}=l.getFileOutline(x),O=new Map;for(let j of F){let re=String(j.symbol_name||"");O.has(re)||O.set(re,[]),O.get(re).push(j);}Rt.set(x,O);}return (Rt.get(x)?.get($)||[]).filter(F=>String(F.category||"")!=="storage"?false:s==="all"?true:String(F.api_name||"").toLowerCase()===s.toLowerCase())},tr=(x,$)=>{let R=[],F=[{name:x,filePath:$,path:[x],level:0}],O=new Set([`${$}::${x}`]);for(;F.length>0;){let j=F.shift(),re=Qt(j.filePath,j.name);if(re.length>0){R.push({path:j.path,file:j.filePath,behaviors:re});continue}if(j.level>=p)continue;let Q=l.getSymbolByName(j.name,j.filePath);if(Q||(Q=l.getSymbolByName(j.name)),!Q)continue;let le=String(Q.file_path||Q.abs_path||j.filePath),Fe=Qt(le,j.name);if(Fe.length>0){R.push({path:j.path,file:le,behaviors:Fe});continue}let kt=l.getCallees(Q.id);for(let De of kt){let Me=String(De.callee_name||"");if(!Me||Me.startsWith("$"))continue;let tn=`${le}::${Me}`;O.has(tn)||(O.add(tn),F.push({name:Me,filePath:le,path:[...j.path,Me],level:j.level+1}));}}return R},nr=b.length>0?`
|
|
617
|
+
\u{1F517} \u53D1\u73B0\u522B\u540D: ${b.map(x=>`"${x}"`).join(", ")}\uFF08\u5DF2\u4E00\u5E76\u8FFD\u8E2A\u5C5E\u6027\u4FEE\u6539\uFF09`:"",we=[];y.length>0&&(we.push(` \u{1F517} \u5F15\u7528\u522B\u540D\u4F20\u64AD (${y.length} \u5904) \u2014 \u8FD9\u4E9B\u5C40\u90E8\u53D8\u91CF\u662F "${t}" \u7684\u5F15\u7528\uFF0C\u5176\u5C5E\u6027\u4FEE\u6539\u4E5F\u88AB\u8FFD\u8E2A:`),y.slice(0,10).forEach(x=>{let R=d.find(j=>j.path===x.filePath)?.abs_path||x.abs_path,F=Tt("alias_ref"),O=R?Gt(R,x.line,2):{snippet:""};we.push(` \u{1F4C4} ${x.filePath}:L${x.line} "${x.alias}" = ... ${F}`),we.push(` ${x.text}`),O.snippet&&we.push(O.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}${nr}`,""];if(h&&C.push(h),C.push(`\u2460 \u58F0\u660E & \u6574\u4F53\u8D4B\u503C (${se.length} \u5904)`),se.length===0)C.push(" \uFF08\u672A\u627E\u5230\uFF09");else {let x={init:[],cache:[],user:[],unknown:[]};for(let R of se){let F=R.sourceLayer||ne(R.text,R.line);x[F].push(R);}let $=["init","cache","user","unknown"];for(let R of $){let F=x[R];!F||F.length===0||(C.push(` \u25B8 ${jn[R]} (${F.length} \u5904)`),F.slice(0,8).forEach(O=>{let j=b.includes(O.text.split("=")[0]?.trim().replace(/^(?:const|let|var)\s+/,"")||""),re=Tt(O.kind,j);C.push(` \u{1F4C4} ${O.filePath}:L${O.line} [${O.kind}] ${re}`),C.push(` ${O.text}`);}));}we.length>0&&(C.push(""),C.push(...we));}if(C.push(""),C.push(`\u2461 \u5C5E\u6027\u4FEE\u6539 (${ke.length} \u5904)`),ke.length===0)C.push(' \uFF08\u672A\u627E\u5230 object.prop \u6216 object["prop"] \u5199\u5165\uFF09'),b.length>0&&C.push(` \u2139\uFE0F \u5DF2\u8FFD\u8E2A\u522B\u540D: ${b.map(x=>`"${x}"`).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 x={init:[],cache:[],user:[],unknown:[]};for(let R of ke){let F=R.sourceLayer||ne(R.text,R.line);x[F].push(R);}let $=["init","cache","user","unknown"];for(let R of $){let F=x[R];!F||F.length===0||(C.push(` \u25B8 ${jn[R]} (${F.length} \u5904)`),F.slice(0,8).forEach(O=>{let j=b.some(De=>O.text.startsWith(De)),re=Tt(O.kind,j),le=d.find(De=>De.path===O.filePath)?.abs_path||"",Fe=le?Gt(le,O.line,2):{snippet:""},kt=j?" \u{1F517}(via alias)":"";C.push(` \u{1F4C4} ${O.filePath}:L${O.line} [${O.kind}] ${re}${kt}`),Fe.snippet&&C.push(Fe.snippet);}));}}if(C.push(""),C.push(`\u2462 \u4F5C\u4E3A\u53C2\u6570\u88AB\u4F20\u5165\u8C03\u7528 (${Z.length} \u5904)`),Z.length===0?C.push(" \uFF08\u672A\u53D1\u73B0\u4EE5\u8BE5\u53D8\u91CF\u4F5C\u4E3A\u53C2\u6570\u7684\u51FD\u6570\u8C03\u7528\uFF09"):Z.slice(0,20).forEach(x=>{let $=String(x.args||"");C.push(` \u{1F4C4} ${x.file_path}:L${x.line_number} ${x.caller_name} \u2192 ${x.callee_name} \u53C2\u6570: "${$}"`);}),C.push(""),C.push(`\u2463 \u8BFB\u53D6/\u4F7F\u7528 (${Oe.length} \u5904)`),Oe.length===0)C.push(" \uFF08\u672A\u53D1\u73B0 template \u7ED1\u5B9A / watch / computed / return \u4E2D\u7684\u5F15\u7528\uFF09");else {let x=new Map;for(let R of Oe)x.has(R.kind)||x.set(R.kind,[]),x.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,F]of x)C.push(` \u25B8 ${$[R]||R}`),F.slice(0,8).forEach(O=>C.push(` \u{1F4C4} ${O.filePath}:L${O.line} ${O.text}`));}C.push("");let ve=0;C.push(`\u2464 Storage \u843D\u70B9\u8FFD\u8E2A (storage_api=${s}, depth=${p})`);let rr=s==="localStorage"?"localStorage":s==="sessionStorage"?"sessionStorage":"(?:localStorage|sessionStorage)",sr=E.map(x=>({kind:"direct_storage",regex:new RegExp(`${rr}\\.(?:setItem|getItem|removeItem|clear)\\(.*?\\b${ge(x)}\\b`)})),Ye=Ie(d,sr,u);if(Ye.length>0&&(ve+=1,C.push(` \u843D\u70B9 [\u76F4\u63A5\u547D\u4E2D\u5B58\u50A8] ${Tt("direct_storage")}:`),Ye.slice(0,15).forEach(x=>{let R=d.find(O=>O.path===x.filePath)?.abs_path||"",F=R?Gt(R,x.line,2):{snippet:""};C.push(` \u{1F4C4} ${x.filePath}:L${x.line} ${x.text.trim()}`),F.snippet&&C.push(F.snippet);})),Z.length===0&&Ye.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 x=new Map;for(let $ of Z){let R=`${$.file_path}::${$.callee_name}`;x.has(R)||x.set(R,$);}for(let[,$]of x){let R=String($.callee_name||""),F=String($.file_path||""),O=tr(R,F);O.length!==0&&(ve+=1,O.slice(0,3).forEach(j=>{let re=j.file!==F?` \u2197 \u8DE8\u6587\u4EF6: ${j.file}`:"";C.push(` \u94FE\u8DEF: ${j.path.join(" \u2192 ")}${re}`),j.behaviors.forEach(Q=>{let le=Q.detail?`("${String(Q.detail)}")`:"";C.push(` \u843D\u70B9: ${Q.api_name}.${Q.operation}${le} [${Q.category}] L${Q.line_number}`);});}));}ve===0&&Ye.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 ir=b.length>0?` (\u542B ${b.length} \u4E2A\u522B\u540D: ${b.slice(0,3).map(x=>`"${x}"`).join(", ")})`:"";C.push(`\u2705 \u6C47\u603B${ir}:`),C.push(` \u2460 \u58F0\u660E/\u8D4B\u503C: ${se.length} \u5904`),C.push(` \u2461 \u5C5E\u6027\u4FEE\u6539: ${ke.length} \u5904 (\u5DF2\u8FFD\u8E2A\u522B\u540D: ${b.map(x=>`"${x}"`).join(", ")||"\u65E0"})`),C.push(` \u2462 \u53C2\u6570\u4F20\u9012: ${Z.length} \u5904`),C.push(` \u2463 \u8BFB\u53D6\u5F15\u7528: ${Oe.length} \u5904`),C.push(` \u2464 storage: ${ve>0?`\u2713 \u53D1\u73B0\u5199\u5165\u94FE\u8DEF (${ve} \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 or=Math.round((performance.now()-c)*100)/100,ar=se.length+ke.length+Z.length+Oe.length+ve,en=H({durationMs:or,resultCount:ar,backend:A&&be?"indexed":A||be?"hybrid":"fallback_scan"});return f.stale&&(en.index_freshness=f),C.push(`
|
|
595
618
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
596
|
-
${W(
|
|
597
|
-
`)}]}});}function
|
|
619
|
+
${W(en)}`),{content:[{type:"text",text:C.join(`
|
|
620
|
+
`)}]}});}function zn(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
|
|
598
621
|
\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
|
|
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
|
|
600
|
-
`)}]}});}var
|
|
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(
|
|
622
|
+
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 T=r.getLastIndexedTime();return T?new Date(T).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),u=e.hasWatcher(s),f=e.listProjects().find(T=>T.root===s)?.dbPath||"",m=i.dbSize||0,g={dbPath:f,indexedFiles:c,totalSymbols:l,totalRelations:i.relationCount||0,totalBehaviors:i.behaviorCount||0,lastIndexedAt:a,failureCount:i.failureCount||0,failedFiles:p.map(T=>({file:T.file_path,error:T.error})),watcherActive:u,dbSizeBytes:m},y=Math.round((performance.now()-n)*100)/100,S=H({durationMs:y,resultCount:1,backend:"indexed"}),b=[`\u{1F3E5} \u7D22\u5F15\u5065\u5EB7\u68C0\u67E5 \u2014 ${s}`,"\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501","","\u{1F4CA} \u7D22\u5F15\u7EDF\u8BA1:",` \u{1F4C1} \u5DF2\u7D22\u5F15\u6587\u4EF6: ${g.indexedFiles}`,` \u{1F523} \u7B26\u53F7\u6570: ${g.totalSymbols}`,` \u{1F517} \u8C03\u7528\u5173\u7CFB: ${g.totalRelations}`,` \u{1F3F7}\uFE0F \u884C\u4E3A\u6807\u7B7E: ${g.totalBehaviors}`,` \u{1F4C5} \u6700\u540E\u7D22\u5F15\u65F6\u95F4: ${g.lastIndexedAt}`,` \u2757 \u5931\u8D25\u6587\u4EF6\u603B\u6570: ${g.failureCount}`,"","\u{1F50C} \u8FD0\u884C\u65F6\u72B6\u6001:",` \u{1F4C2} \u6587\u4EF6\u76D1\u542C: ${g.watcherActive?"\u2705 \u6D3B\u8DC3":"\u274C \u672A\u542F\u52A8"}`,` \u{1F4BE} \u6570\u636E\u5E93\u5927\u5C0F: ${Math.round(g.dbSizeBytes/1024)} KB`,` \u{1F4CD} \u6570\u636E\u5E93\u8DEF\u5F84: ${g.dbPath||"\uFF08\u5185\u5B58\uFF09"}`,"","\u{1F4A1} \u5EFA\u8BAE:"];if(g.totalSymbols===0&&g.indexedFiles>0?b.push(" \u26A0\uFE0F \u6709\u6587\u4EF6\u4F46\u7B26\u53F7\u6570\u4E3A0 \u2014 \u53EF\u80FD\u9700\u8981\u8C03\u6574\u89E3\u6790\u89C4\u5219\u6216\u5F3A\u5236\u91CD\u5EFA"):g.indexedFiles===0?b.push(" \u274C \u5C1A\u672A\u7D22\u5F15 \u2014 \u8FD0\u884C skimmer_index_project \u5F00\u59CB\u7D22\u5F15"):b.push(" \u2705 \u7D22\u5F15\u72B6\u6001\u6B63\u5E38"),!g.watcherActive&&g.indexedFiles>0&&b.push(" \u{1F4A1} \u6587\u4EF6\u76D1\u542C\u672A\u542F\u52A8 \u2014 \u8FD0\u884C skimmer_index_project \u53EF\u81EA\u52A8\u5F00\u542F"),g.failedFiles.length>0){b.push(""),b.push("\u26A0\uFE0F \u6700\u8FD1\u5931\u8D25\u6587\u4EF6\u6837\u672C:");for(let T of g.failedFiles.slice(0,5))b.push(` - ${T.file}: ${T.error}`);}return b.push(""),b.push("\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500"),b.push(W(S)),{content:[{type:"text",text:b.join(`
|
|
623
|
+
`)}]}});}var ms="\u9879\u76EE\u6839\u76EE\u5F55\uFF08\u53EF\u7701\u7565\uFF0C\u4F7F\u7528\u4E0A\u6B21\u7D22\u5F15\u7684\u9879\u76EE\uFF09";function Gn(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
|
|
624
|
+
\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(ms),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,g=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
|
|
602
625
|
|
|
603
626
|
\u4F7F\u7528 skimmer_index_project({ project_path: "/your/project" }) \u5F00\u59CB\u7D22\u5F15
|
|
604
627
|
|
|
605
628
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
606
|
-
${W(
|
|
607
|
-
`];return f.forEach((S,
|
|
629
|
+
${W(g)}`}]};let y=[`\u{1F4CB} \u5DF2\u7D22\u5F15\u7684\u9879\u76EE (${f.length} \u4E2A):
|
|
630
|
+
`];return f.forEach((S,b)=>{y.push(`${b+1}. ${S.root}`),y.push(` \u6570\u636E\u5E93: ${S.dbPath}`);}),y.push(`
|
|
608
631
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
609
|
-
${W(
|
|
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
|
|
632
|
+
${W(g)}`),{content:[{type:"text",text:y.join(`
|
|
633
|
+
`)}]}}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 u=a.behaviorStats;if(u?.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 u)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 d=Math.round((performance.now()-r)*100)/100,h=H({durationMs:d,resultCount:1,backend:"indexed"});return c.push(`
|
|
611
634
|
\u2500\u2500 \u5143\u4FE1\u606F \u2500\u2500
|
|
612
|
-
${W(
|
|
613
|
-
`)}]}});}function
|
|
614
|
-
`);try{let{projectRoot:n}=
|
|
615
|
-
`);let i=await r.startWatcher();
|
|
635
|
+
${W(h)}`),{content:[{type:"text",text:c.join(`
|
|
636
|
+
`)}]}});}function Yn(o){let e=[q__default.resolve(o,"../package.json"),q__default.resolve(o,"../../package.json")];for(let t of e)try{let n=JSON.parse(te__default.readFileSync(t,"utf-8"));if(typeof n.version=="string"&&n.version.trim())return n.version.trim()}catch{}return "0.0.0-dev"}var ye=new Et,Jn=Yn(q__default.dirname(fileURLToPath(import.meta.url))),Pe=new McpServer({name:"frontend-code-skimmer",version:Jn});In(Pe,ye);On(Pe,ye);Kn(Pe,ye);zn(Pe,ye);Gn(Pe,ye);async function _s(){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}
|
|
637
|
+
`);try{let{projectRoot:n}=ye.getContext(process.env.SKIMMER_PROJECT),r=ye.getIndexer(n),s=await r.indexProject();process.stderr.write(`[Frontend-Code-Skimmer] \u5B8C\u6210: ${s.indexedFiles} \u6587\u4EF6, ${s.totalSymbols} \u7B26\u53F7
|
|
638
|
+
`);let i=await r.startWatcher();ye.registerWatcher(n,i),process.stderr.write(`[Frontend-Code-Skimmer] \u6587\u4EF6\u76D1\u542C\u5DF2\u542F\u52A8: ${n}
|
|
616
639
|
`);}catch(n){process.stderr.write(`[Frontend-Code-Skimmer] \u7D22\u5F15\u5931\u8D25: ${String(n)}
|
|
617
|
-
`);}}let e=new StdioServerTransport;await
|
|
640
|
+
`);}}let e=new StdioServerTransport;await Pe.connect(e),process.stderr.write(`[Frontend-Code-Skimmer MCP] \u5DF2\u542F\u52A8 (v${Jn})
|
|
618
641
|
`),process.stderr.write(`[Frontend-Code-Skimmer MCP] \u652F\u6301\u6846\u67B6: Vue 2 / Vue 3 / React Hooks
|
|
619
642
|
`),process.stderr.write(`[Frontend-Code-Skimmer MCP] \u652F\u6301\u7CBE\u5EA6: heuristic / precise (\u8DE8\u6587\u4EF6 import \u7ED1\u5B9A)
|
|
620
643
|
`),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
|
|
621
644
|
`),process.env.SKIMMER_PROJECT?process.stderr.write(`[Frontend-Code-Skimmer MCP] \u9ED8\u8BA4\u9879\u76EE: ${process.env.SKIMMER_PROJECT}
|
|
622
645
|
`):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
|
|
623
|
-
`);let t=()=>{
|
|
646
|
+
`);let t=()=>{ye.closeAll(),process.exit(0);};process.on("SIGINT",t),process.on("SIGTERM",t);}_s().catch(o=>{process.stderr.write(`[Frontend-Code-Skimmer MCP] \u542F\u52A8\u5931\u8D25: ${String(o)}
|
|
624
647
|
`),process.exit(1);});
|