@jokeran/frontend-code-skimmer 0.2.0 → 0.2.3
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 +163 -91
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
`&&e++;return e}function
|
|
4
|
-
`),
|
|
5
|
-
`),a;try{a=
|
|
6
|
-
`&&
|
|
7
|
-
`),i=null;
|
|
8
|
-
`),
|
|
9
|
-
`),
|
|
10
|
-
`),
|
|
11
|
-
`),i=!!s.scriptSetup,c=!!s.script;if(i){let a=s.scriptSetup,
|
|
12
|
-
`),c=s.program.body;for(let a of c||[])this.processTopLevelStatement(a,o,
|
|
13
|
-
`),c=false;
|
|
14
|
-
`),t(
|
|
15
|
-
`),c)
|
|
16
|
-
`);
|
|
17
|
-
`)
|
|
18
|
-
`),
|
|
19
|
-
`),
|
|
2
|
+
import W from'path';import'url';import Vt from'crypto';import {createRequire}from'module';import M from'fs';import En from'fast-glob';import {McpServer}from'@modelcontextprotocol/sdk/server/mcp.js';import {StdioServerTransport}from'@modelcontextprotocol/sdk/server/stdio.js';import Jt from'os';import zt from'better-sqlite3';import {z as z$1}from'zod';var Bt=Object.defineProperty;var z=(l,e)=>()=>(l&&(e=l(l=0)),e);var Kt=(l,e)=>{for(var t in e)Bt(l,t,{get:e[t],enumerable:true});};var L=z(()=>{});function A(l){return l.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 Ne(l,e){let t=l.length,n=e.length,r=Array.from({length:t+1},(s,o)=>Array.from({length:n+1},(i,c)=>o===0?c:c===0?o:0));for(let s=1;s<=t;s++)for(let o=1;o<=n;o++)l[s-1]===e[o-1]?r[s][o]=r[s-1][o-1]:r[s][o]=1+Math.min(r[s-1][o],r[s][o-1],r[s-1][o-1]);return r[t][n]}function ot(l){return Vt.createHash("md5").update(l).digest("hex")}function it(l){if(!l)return 0;let e=1;for(let t=0;t<l.length;t++)l[t]===`
|
|
3
|
+
`&&e++;return e}function ie(l,e){return l===e?`L${l}`:`L${l}-L${e}`}function Se(l,e){return W.relative(e,l).replace(/\\/g,"/")}function pe(l,e){if(!l)return e;try{return JSON.parse(l)}catch{return e}}function B(l,e){let t=l.split(`
|
|
4
|
+
`),r=e-1-1;for(;r>=0&&t[r].trim()==="";)r--;if(r<0||!t[r].trim().endsWith("*/"))return;let s=r;for(;s>0&&!t[s].trim().startsWith("/**");)s--;if(t[s].trim().startsWith("/**"))return t.slice(s,r+1).map(o=>o.replace(/^\s*\*\s?/,"").replace(/\/\*\*/,"").replace(/\*\//,"").trim()).filter(o=>o.length>0).join(" ")}function at(l,e){let t=l.toLowerCase(),n=e.toLowerCase();if(t===n)return 100;if(n.includes(t)||t.includes(n))return 85;let r=Ne(t,n),s=Math.max(t.length,n.length);if(s===0)return 100;let o=Math.max(0,100-r/s*100);return Math.round(o)}function Q(l){return l.startsWith("use")&&l.length>3&&/[A-Z]/.test(l[3])}function ct(l,e,t){if(t===0||t>3)return;let n=A(l).split(" "),r=A(e).split(" ");for(let s of n)for(let o of r){let i=Ne(s,o);if(i>0&&i<=3&&s!==o)return `"${s}" \u53EF\u80FD\u662F "${o}" \u7684\u62FC\u5199\u9519\u8BEF (\u7F16\u8F91\u8DDD\u79BB=${i})`}}var G=z(()=>{L();});var De,Me,lt,We,Ue,pt,dt,ut,He,Be,Ke,ft,_e,mt,gt,ht,J=z(()=>{L();De=["**/node_modules/**","**/dist/**","**/build/**","**/.git/**","**/coverage/**","**/.nuxt/**","**/.next/**","**/__tests__/**","**/*.test.*","**/*.spec.*","**/*.min.js"],Me=["**/*.vue","**/*.js","**/*.jsx","**/*.ts","**/*.tsx"],lt={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"]}},We=["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeDestroy","destroyed","activated","deactivated","errorCaptured"],Ue=["onBeforeMount","onMounted","onBeforeUpdate","onUpdated","onBeforeUnmount","onUnmounted","onActivated","onDeactivated","onErrorCaptured","onRenderTracked","onRenderTriggered","onServerPrefetch"],pt=["ref","reactive","shallowRef","shallowReactive","readonly"],dt=["computed"],ut=["watch","watchEffect","watchPostEffect","watchSyncEffect"],He=["useState","useReducer","useRef","useImperativeHandle"],Be=["useMemo","useCallback"],Ke=["useEffect","useLayoutEffect","useInsertionEffect"],ft=["useContext","useDebugValue","useDeferredValue","useId","useSyncExternalStore","useTransition"],_e=".skimmer-index.db",mt=30,gt=4,ht=300;});function U(l,e,t,n=false){let r=[];return D(l,o=>{if(n&&o!==l&&(o.type==="FunctionDeclaration"||o.type==="ArrowFunctionExpression"||o.type==="FunctionExpression"||o.type==="ClassDeclaration"))return false;if(o.type==="CallExpression"){let c=en(o,e);c&&r.push(c);}if(o.type==="MemberExpression"){let i=tn(o);i&&r.push(i);}}),cn(r)}function en(l,e,t){let n=l.callee;if(!n)return null;let r=Xe(l);if(n.type==="MemberExpression"){let s=nn(n);if(!s)return null;let{apiName:o,operation:i}=s,c=l.arguments,a=V(c?.[0]),f=on(o);return f?{symbolName:e,category:f,apiName:o,operation:i,detail:a,line:r}:o==="this"&&Te(i)?{symbolName:e,category:"network",apiName:`this.${i}`,operation:"wrapped_call",detail:a||V(c?.[1]),line:r}:bt(i)&&an(c)?{symbolName:e,category:"network",apiName:o,operation:i,detail:a||V(c?.[1]),line:r}:Te(o)||Te(`${o}.${i}`)?{symbolName:e,category:"network",apiName:o,operation:bt(i)?i:"wrapped_call",detail:a||V(c?.[1]),line:r}:null}if(n.type==="Identifier"){let s=n.name,o=rn(s),i=l.arguments,c=V(i?.[0]);return o?{symbolName:e,category:o.category,apiName:s,operation:o.operation,detail:c,line:r}:Te(s)?{symbolName:e,category:"network",apiName:s,operation:"wrapped_call",detail:c||V(i?.[1]),line:r}:null}return null}function tn(l,e,t){let n=l.object,r=l.property;if(!n||!r||n.type!=="MemberExpression"&&n.type!=="ThisExpression"&&n.type!=="Identifier")return null;let s=sn(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 nn(l){let e=l.object,t=l.property;if(!e||!t||t.type!=="Identifier")return null;let n=t.name;if(e.type==="MemberExpression"){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 rn(l){let e={fetch:"network",setTimeout:"timer",setInterval:"timer",clearTimeout:"timer",clearInterval:"timer",requestAnimationFrame:"timer",navigate:"router"};return e[l]?{category:e[l],operation:l}:null}function Xe(l){return l.loc?.start?.line??0}function sn(l){return l.type==="Identifier"?l.name:l.type==="ThisExpression"?"this":null}function on(l){if(l==="this")return null;for(let[e,t]of Object.entries(lt))if(l in t)return e;return null}function V(l,e){if(l){if(l.type==="Literal"||l.type==="StringLiteral"||l.type==="NumericLiteral"||l.type==="BooleanLiteral")return String(l.value);if(l.type==="NullLiteral")return "null";if(l.type==="TemplateLiteral"){let t=l.quasis,n=l.expressions||[],r=[];for(let o=0;o<t.length;o++){let i=t[o].value?.cooked||"";if(i&&r.push(i),o<n.length){let c=$e(n[o])||"expr";r.push(`\${${c}}`);}}return r.join("")||"${expr}"}if(l.type==="Identifier")return `[\u53D8\u91CF: ${l.name}]`;if(l.type==="ObjectExpression"){let t=l.properties||[],n=["url","uri","path","api","endpoint"];for(let r of t){let s=r.key,o=r.value;if(!s||!o)continue;let i=s.type==="Identifier"?String(s.name):s.type==="Literal"?String(s.value):"";if(!n.includes(i))continue;let c=V(o);if(c)return `${i}:${c}`}return "{...}"}}}function $e(l,e){if(!l)return;if(l.type==="Identifier")return l.name;if(l.type==="ThisExpression")return "this";if(l.type==="Literal"||l.type==="StringLiteral"||l.type==="NumericLiteral"||l.type==="BooleanLiteral")return String(l.value);if(l.type==="NullLiteral")return "null";if(l.type==="MemberExpression"){let n=$e(l.object)||"obj",r=l.property,s=r?.type==="Identifier"?String(r.name):$e(r)||"prop";return l.computed?`${n}[${s}]`:`${n}.${s}`}if(l.type==="CallExpression")return `${$e(l.callee)||"fn"}(...)`;if(l.type==="TemplateLiteral")return V(l);let t=V(l);return t?.startsWith("[\u53D8\u91CF: ")?t.replace(/^\[变量: /,"").replace(/\]$/,""):t}function Te(l){return /request|api|http|fetch|ajax|akscommonhandle|commonhandle/i.test(l)}function bt(l){return ["get","post","put","delete","patch","request"].includes(l.toLowerCase())}function an(l,e){if(!l||l.length===0)return false;for(let t of l.slice(0,2)){let n=V(t);if(n&&(/https?:\/\//i.test(n)||n.includes("/")||/gw\d?\/|\/m\/|\/api\//i.test(n)))return true}return false}function cn(l){let e=new Set;return l.filter(t=>{let n=`${t.apiName}:${t.operation}:${t.line}`;return e.has(n)?false:(e.add(n),true)})}function Re(l,e,t){let n=[];return D(l,r=>{if(r.type==="CallExpression"&&r.callee?.type==="MemberExpression"){let s=r.callee,o=s.object,i=s.property;if(o.type==="ThisExpression"&&i.type==="Identifier"){let c=i.name;if(!c.startsWith("$")&&c!==e){let a=r.arguments,f=yt(a);n.push({calleeName:c,line:Xe(r),args:f});}}}}),n}function q(l,e,t,n=false){let r=[];return D(l,o=>{if(n&&o!==l&&(o.type==="FunctionDeclaration"||o.type==="ArrowFunctionExpression"||o.type==="FunctionExpression"||o.type==="ClassDeclaration"))return false;if(o.type==="CallExpression"&&o.callee?.type==="Identifier"){let i=o.callee.name;if(i!==e&&!ln(i)){let c=o.arguments,a=yt(c);r.push({calleeName:i,line:Xe(o),args:a});}}}),r}function ln(l){return /^(useState|useEffect|useMemo|useCallback|useRef|useContext|useReducer|ref|reactive|computed|watch|watchEffect|console|setTimeout|setInterval|Math|Object|Array|JSON|String|Number|Boolean|Promise|require|import)$/.test(l)}function yt(l,e){if(!l||l.length===0)return;let t=l.slice(0,3).map(n=>V(n)).filter(n=>!!n);return t.length>0?t.join(", "):void 0}function D(l,e){if(!(!l||typeof l!="object")&&e(l)!==false)for(let t of Object.keys(l)){if(t==="type"||t==="loc"||t==="start"||t==="end")continue;let n=l[t];if(Array.isArray(n))for(let r of n)r&&typeof r=="object"&&r.type&&D(r,e);else n&&typeof n=="object"&&n.type&&D(n,e);}}var ke=z(()=>{L();J();});var Et,ae,ze=z(()=>{L();J();ke();G();Et=createRequire(import.meta.url),ae=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=Et("vue-template-compiler").parseComponent(t);if(!s.script?.content)return n;let o=s.script.content,i=this.getScriptStartLine(t,s.script.start),c=t.split(`
|
|
5
|
+
`),a;try{a=Et("@babel/parser").parse(o,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy"],errorRecovery:!0});}catch(f){return n.errors?.push(`AST \u89E3\u6790\u5931\u8D25: ${String(f)}`),n}this.extractFromAST(a.program,o,c,i,n);}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]===`
|
|
6
|
+
`&&n++;return n}extractFromAST(e,t,n,r,s){let o=t.split(`
|
|
7
|
+
`),i=null;D(e,d=>{if(d.type==="ExportDefaultDeclaration"){let p=d.declaration;if(p?.type==="ObjectExpression")i=p;else if(p?.type==="CallExpression"){let u=p.arguments;u&&u.length>0&&u[0].type==="ObjectExpression"&&(i=u[0]);}else if(p?.type==="Identifier"){let u=p.name;D(e,m=>{if(m.type==="VariableDeclarator"&&m.id?.name===u){if(m.init?.type==="ObjectExpression")i=m.init;else if(m.init?.type==="CallExpression"){let g=m.init.arguments;g&&g.length>0&&g[0].type==="ObjectExpression"&&(i=g[0]);}}});}}});let a=false;if(!i&&(D(e,d=>{d.type==="ExportDefaultDeclaration"&&d.declaration?.type==="ClassDeclaration"&&(a=true,this.extractFromClassComponent(d.declaration,t,n,r,s));}),!a)){let d=null,p=0,u=["data","methods","computed","props","watch","components","created","mounted","mixins"];D(e,m=>{if(m.type==="ObjectExpression"){let g=m.properties||[],b=0;for(let E of g){let N=this.getPropKey(E);N&&u.includes(N)&&b++;}b>p&&(p=b,d=m);}}),p>=2&&d&&(i=d);}if(!i)return;let f=i.properties;for(let d of f||[]){let p=this.getPropKey(d);if(!p)continue;let u=d.type==="ObjectMethod"?d:d.value;if(!u)continue;let m=g=>g+r-1;switch(p){case "name":u?.type==="Literal"&&(String(u.value));break;case "data":this.extractData(u,o,m,s);break;case "props":this.extractProps(u,o,m,s);break;case "computed":this.extractComputedOrMethods(u,"computed",o,m,n,s);break;case "methods":this.extractComputedOrMethods(u,"method",o,m,n,s);break;case "watch":this.extractWatch(u,o,m,s);break;case "filters":this.extractComputedOrMethods(u,"filter",o,m,n,s);break;case "components":this.extractComponents(u,s);break;case "mixins":this.extractMixins(u,s);break;default:if(We.includes(p)){let g=m(this.getStartLine(d)),b=m(this.getEndLine(d)),E=B(n.join(`
|
|
8
|
+
`),g),N=s.symbols.length;s.symbols.push({name:p,category:"lifecycle",framework:"vue2",startLine:g,endLine:b,jsdoc:E,camelWords:A(p)});let h=U(u,p);s.behaviors.push(...h);let S=Re(u,p);for(let k of S){if(k.args){let w=String(k.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[N].camelWords+=` ${A(w)} ${w}`;}s.relations.push({callerName:p,callerLine:g,calleeName:k.calleeName,callType:"this_method",line:m(k.line),args:k.args});}}break}}}extractData(e,t,n,r){let s=null;if(e.type==="FunctionExpression"||e.type==="ArrowFunctionExpression"||e.type==="ObjectMethod"?D(e.body,o=>{o.type==="ReturnStatement"&&o.argument?.type==="ObjectExpression"&&(s=o.argument);}):e.type==="ObjectExpression"&&(s=e),!!s)for(let o of s.properties){let i=this.getPropKey(o);if(!i)continue;let c=n(this.getStartLine(o)),a=n(this.getEndLine(o)),f=this.getLiteralValue(o.value);r.symbols.push({name:i,category:"state",framework:"vue2",startLine:c,endLine:a,defaultValue:f,camelWords:A(i)});}}extractProps(e,t,n,r){if(e.type==="ArrayExpression"){for(let s of e.elements||[])if(s?.type==="Literal"){let o=String(s.value);r.symbols.push({name:o,category:"prop",framework:"vue2",startLine:n(this.getStartLine(s)),endLine:n(this.getEndLine(s)),camelWords:A(o)});}}else if(e.type==="ObjectExpression")for(let s of e.properties||[]){let o=this.getPropKey(s);if(!o)continue;let i=n(this.getStartLine(s)),c=n(this.getEndLine(s)),a;if(s.value?.type==="ObjectExpression"){let f=s.value.properties?.find(d=>this.getPropKey(d)==="default");f&&(a=this.getLiteralValue(f.value));}r.symbols.push({name:o,category:"prop",framework:"vue2",startLine:i,endLine:c,defaultValue:a,camelWords:A(o)});}}extractComputedOrMethods(e,t,n,r,s,o){if(e.type==="ObjectExpression")for(let i of e.properties||[]){let c=this.getPropKey(i);if(!c)continue;let a=i.type==="ObjectMethod"?i:i.value;if(!a)continue;let f=r(this.getStartLine(i)),d=r(this.getEndLine(i)),p=B(s.join(`
|
|
9
|
+
`),f),u=this.extractParams(a),m=a.async===true,g=u?`${c}(${u.join(", ")})`:c;if(o.symbols.push({name:c,category:t,framework:"vue2",startLine:f,endLine:d,signature:g,params:u,isAsync:m,jsdoc:p,camelWords:A(c)}),t==="method"&&a){let b=U(a,c);o.behaviors.push(...b);let E=Re(a,c);for(let N of E){if(N.args){let h=String(N.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");o.symbols[o.symbols.length-1].camelWords+=` ${A(h)} ${h}`;}o.relations.push({callerName:c,callerLine:f,calleeName:N.calleeName,callType:"this_method",line:r(N.line),args:N.args});}}}}extractWatch(e,t,n,r){if(e.type==="ObjectExpression")for(let s of e.properties||[]){let o=this.getPropKey(s);if(!o)continue;let i=n(this.getStartLine(s)),c=n(this.getEndLine(s));r.symbols.push({name:o,category:"effect",framework:"vue2",startLine:i,endLine:c,camelWords:A(o)});}}extractComponents(e,t){if(e.type==="ObjectExpression")for(let n of e.properties||[]){let r=this.getPropKey(n);r&&t.symbols.push({name:r,category:"component",framework:"vue2",startLine:this.getStartLine(n),endLine:this.getEndLine(n),camelWords:A(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:A(r)});}}getPropKey(e){if(!e)return null;let t=e.key;return t?t.type==="Identifier"?t.name:t.type==="Literal"?String(t.value):null:null}getStartLine(e){return e?.loc?.start?.line??1}getEndLine(e){return e?.loc?.end?.line??1}extractParams(e){if(!e)return;let t=e.params;if(t)return t.map(n=>n.type==="Identifier"?n.name:n.type==="AssignmentPattern"?n.left?.name||"?":n.type==="RestElement"?`...${n.argument?.name||""}`:n.type==="TSParameterProperty"&&n.parameter?.name||"?")}getLiteralValue(e){if(e){if(e.type==="Literal"||e.type==="StringLiteral"||e.type==="NumericLiteral"||e.type==="BooleanLiteral")return String(e.value);if(e.type==="NullLiteral"||e.value===null)return "null";if(e.type==="ObjectExpression")return "{}";if(e.type==="ArrayExpression")return "[]";if(e.type==="Identifier"&&e.name==="undefined")return "undefined";if(e.type==="ArrowFunctionExpression"||e.type==="FunctionExpression"||e.type==="ObjectMethod")return "function"}}extractFromClassComponent(e,t,n,r,s){let o=c=>c+r-1,i=e.body;if(!(!i||i.type!=="ClassBody"))for(let c of i.body||[]){let a=this.getPropKey(c);if(!a)continue;let f=o(this.getStartLine(c)),d=o(this.getEndLine(c)),p=B(n.join(`
|
|
10
|
+
`),f);if(c.type==="ClassMethod"){let m=We.includes(a)?"lifecycle":"method",g=this.extractParams(c),b=c.async===true,E=g?`${a}(${g.join(", ")})`:a;s.symbols.push({name:a,category:m,framework:"vue2",startLine:f,endLine:d,signature:E,params:g,isAsync:b,jsdoc:p,camelWords:A(a)});let N=U(c,a);s.behaviors.push(...N);let h=Re(c,a);for(let S of h){if(S.args){let k=String(S.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[s.symbols.length-1].camelWords+=` ${A(k)} ${k}`;}s.relations.push({callerName:a,callerLine:f,calleeName:S.calleeName,callType:"this_method",line:o(S.line),args:S.args});}}else if(c.type==="ClassProperty"){let u=(c.decorators||[]).some(g=>g.expression?.callee?.name==="Prop"),m=this.getLiteralValue(c.value);s.symbols.push({name:a,category:u?"prop":"state",framework:"vue2",startLine:f,endLine:d,defaultValue:m,camelWords:A(a)});}}}};});var Ge,ve,Nt=z(()=>{L();J();ke();G();ze();Ge=createRequire(import.meta.url),ve=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}=Ge("@vue/compiler-sfc"),{descriptor:s}=r(t),o=t.split(`
|
|
11
|
+
`),i=!!s.scriptSetup,c=!!s.script;if(i){let a=s.scriptSetup,f=a.loc.start.line;this.parseSetupContent(a.content,f,o,n);}else if(c){let a=s.script,f=a.loc.start.line;this.parseScriptContent(a.content,f,o,n)||this.populateFromOptionsApiFallback(e,t,n);}}catch(r){n.errors?.push(`Vue3 \u89E3\u6790\u5931\u8D25: ${String(r)}`);}return n}parseSetupContent(e,t,n,r){let s;try{s=Ge("@babel/parser").parse(e,{sourceType:"module",plugins:["typescript","jsx","decorators-legacy"],errorRecovery:!0});}catch(a){r.errors?.push(`AST \u89E3\u6790\u5931\u8D25: ${String(a)}`);return}let o=a=>a+t-1,i=e.split(`
|
|
12
|
+
`),c=s.program.body;for(let a of c||[])this.processTopLevelStatement(a,o,n,i,r);}parseScriptContent(e,t,n,r){let s;try{s=Ge("@babel/parser").parse(e,{sourceType:"module",plugins:["typescript","jsx","decorators-legacy"],errorRecovery:!0});}catch(a){return r.errors?.push(`AST \u89E3\u6790\u5931\u8D25: ${String(a)}`),false}let o=a=>a+t-1,i=e.split(`
|
|
13
|
+
`),c=false;return D(s.program,a=>{if(a.type==="ExportDefaultDeclaration"&&a.declaration?.type==="ObjectExpression"){let f=a.declaration.properties?.find(d=>this.getPropKey(d)==="setup");if(f){c=true;let d=f.type==="ObjectMethod"?f:f.value;if(!d)return;let p=d.body;if(p?.type==="BlockStatement"){let u=p.body;for(let m of u||[])this.processTopLevelStatement(m,o,n,i,r);}}}}),c||D(s.program,a=>{if(!c&&a.type==="ObjectExpression"){let d=(a.properties||[]).find(p=>this.getPropKey(p)==="setup");if(d){c=true;let p=d.type==="ObjectMethod"?d:d.value;if(!p)return;let u=p.body;if(u?.type==="BlockStatement"){let m=u.body;for(let g of m||[])this.processTopLevelStatement(g,o,n,i,r);}}}}),c}processTopLevelStatement(e,t,n,r,s){let o=i=>{let c=i?.loc;return {start:c?.start?.line??1,end:c?.end?.line??1}};if(e.type==="VariableDeclaration")for(let i of e.declarations||[]){if(i.id?.type!=="Identifier"&&i.id?.type!=="ArrayPattern")continue;let c=i.init;if(c&&i.id.type==="Identifier"){let a=i.id.name;if(c.type==="ArrowFunctionExpression"||c.type==="FunctionExpression"){let{start:f,end:d}=o(e),p=B(n.join(`
|
|
14
|
+
`),t(f)),u=this.extractParams(c),m=s.symbols.length;if(s.symbols.push({name:a,category:"method",framework:"vue3",startLine:t(f),endLine:t(d),signature:`${a}(${(u||[]).join(", ")})`,params:u,isAsync:c.async===true,jsdoc:p,camelWords:A(a)}),c.body){let g=U(c.body,a);s.behaviors.push(...g);let b=q(c.body,a);for(let E of b){if(E.args){let N=String(E.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[m].camelWords+=` ${A(N)} ${N}`;}s.relations.push({callerName:a,callerLine:t(f),calleeName:E.calleeName,callType:"direct_call",line:t(E.line),args:E.args});}}}else {let f=this.classifyVue3Declaration(a,c,t,o(e),n);f&&s.symbols.push(f);}}}if(e.type==="FunctionDeclaration"&&e.id?.type==="Identifier"){let i=e.id.name,{start:c,end:a}=o(e),f=B(n.join(`
|
|
15
|
+
`),t(c)),d=this.extractParams(e),p=Ue.includes(i);if(s.symbols.push({name:i,category:p?"lifecycle":Q(i)?"hook":"method",framework:"vue3",startLine:t(c),endLine:t(a),signature:`${i}(${(d||[]).join(", ")})`,params:d,isAsync:e.async===true,jsdoc:f,camelWords:A(i)}),e.body){let u=U(e.body,i);s.behaviors.push(...u);let m=q(e.body,i);for(let g of m){if(g.args){let b=String(g.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[s.symbols.length-1].camelWords+=` ${A(b)} ${b}`;}s.relations.push({callerName:i,callerLine:t(c),calleeName:g.calleeName,callType:"direct_call",line:t(g.line),args:g.args});}}}if(e.type==="ExpressionStatement"&&e.expression?.type==="CallExpression"){let c=e.expression.callee;if(c?.type==="Identifier"){let a=c.name;if(["defineProps","defineEmits","defineExpose"].includes(a)){let{start:f,end:d}=o(e);s.symbols.push({name:a,category:a==="defineProps"?"prop":a==="defineEmits"?"emit":"export",framework:"vue3",startLine:t(f),endLine:t(d),camelWords:A(a)});}}}if(e.type==="ExpressionStatement"&&e.expression?.type==="CallExpression"){let i=e.expression,c=i.callee;if(c?.type==="Identifier"){let a=c.name;if(Ue.includes(a)){let{start:f,end:d}=o(e);s.symbols.push({name:a,category:"lifecycle",framework:"vue3",startLine:t(f),endLine:t(d),camelWords:A(a)});let p=i.arguments;if(p?.[0]){let u=U(p[0],a);s.behaviors.push(...u);let m=q(p[0],a);for(let g of m){if(g.args){let b=String(g.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[s.symbols.length-1].camelWords+=` ${A(b)} ${b}`;}s.relations.push({callerName:a,callerLine:t(f),calleeName:g.calleeName,callType:"direct_call",line:t(g.line),args:g.args});}}}}}}classifyVue3Declaration(e,t,n,r,s){if(t.type!=="CallExpression")return null;let o=t.callee;if(o?.type!=="Identifier")return null;let i=o.name,c=n(r.start),a=n(r.end),f=B(s.join(`
|
|
16
|
+
`),c);if(pt.includes(i)){let d=t.arguments,p=d?.[0]?this.getLiteralValue(d[0]):void 0;return {name:e,category:"state",framework:"vue3",startLine:c,endLine:a,defaultValue:p,jsdoc:f,camelWords:A(e)}}return dt.includes(i)?{name:e,category:"computed",framework:"vue3",startLine:c,endLine:a,jsdoc:f,camelWords:A(e)}:ut.includes(i)?{name:e,category:"effect",framework:"vue3",startLine:c,endLine:a,camelWords:A(e)}:i==="provide"||i==="inject"?{name:e,category:"provide",framework:"vue3",startLine:c,endLine:a,camelWords:A(e)}:Q(i)?{name:e,category:"hook",framework:"vue3",startLine:c,endLine:a,jsdoc:f,camelWords:A(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 ae().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 fn,mn,de,St=z(()=>{L();J();ke();G();fn=createRequire(import.meta.url),mn=[...He,...Be,...Ke,...ft],de=class{name="ReactParser";canParse(e,t){let n=e.split(".").pop()?.toLowerCase();return ["jsx","tsx","js","ts"].includes(n||"")?t.includes("useState")||t.includes("useEffect")||t.includes("from 'react'")||t.includes('from "react"')||t.includes("React.")||t.includes("jsx")||t.includes("JSX"):false}parse(e,t){let n={framework:"react",filePath:e,symbols:[],relations:[],behaviors:[],errors:[]};try{let s=fn("@babel/parser").parse(t,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy"],errorRecovery:!0}),o=t.split(`
|
|
17
|
+
`);this.extractFromAST(s.program?s.program:s,o,n);}catch(r){n.errors?.push(`React \u89E3\u6790\u5931\u8D25: ${String(r)}`);}return n}extractFromAST(e,t,n){let r=e.body;for(let s of r||[]){if(s.type==="FunctionDeclaration"||s.type==="ExportDefaultDeclaration"&&s.declaration?.type==="FunctionDeclaration"||s.type==="ExportNamedDeclaration"&&s.declaration?.type==="FunctionDeclaration"){let o=s.type==="FunctionDeclaration"?s:s.declaration;o&&o.id?.type==="Identifier"&&this.processFunction(o,t,n);}if(s.type==="VariableDeclaration"||s.type==="ExportNamedDeclaration"&&s.declaration?.type==="VariableDeclaration"||s.type==="ExportDefaultDeclaration"&&s.declaration?.type==="VariableDeclaration"){let o=s.type==="VariableDeclaration"?s:s.declaration;if(o)for(let i of o.declarations||[]){let c=i.init;if(c&&(c.type==="ArrowFunctionExpression"||c.type==="FunctionExpression")&&i.id?.type==="Identifier"){let a={...c,id:i.id,loc:{start:o.loc?.start??c.loc?.start,end:c.loc?.end}};this.processFunction(a,t,n);}}}}}processFunction(e,t,n){let r=e.id?.name;if(!r)return;let s=e.loc,o=s?.start?.line??1,i=s?.end?.line??1,c=Q(r),a=!c&&/^[A-Z]/.test(r),f=B(t.join(`
|
|
18
|
+
`),o),d=this.extractParams(e),p=this.buildSymbolKey(r,o,i);n.symbols.push({name:r,category:c?"hook":a?"component":"function",framework:"react",startLine:o,endLine:i,internalKey:p,signature:`${r}(${(d||[]).join(", ")})`,params:d,isAsync:e.async===true,jsdoc:f,parentComponent:a?r:void 0,camelWords:A(r)});let u=e.body;if(u?.type!=="BlockStatement")return;let m=u.body;for(let E of m||[])this.processComponentStatement(E,r,t,n);let g=U(u,r,t,true);n.behaviors.push(...g);let b=q(u,r,t,true);for(let E of b){let N=n.symbols.findIndex(h=>h.name===r&&h.startLine===o);if(E.args&&N!==-1){let h=String(E.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");n.symbols[N].camelWords+=` ${A(h)} ${h}`;}n.relations.push({callerName:r,callerLine:o,callerKey:p,calleeName:E.calleeName,callType:"direct_call",line:E.line,args:E.args});}}processComponentStatement(e,t,n,r){let s=o=>{let i=o?.loc;return {start:i?.start?.line??1,end:i?.end?.line??1}};if(e.type==="VariableDeclaration")for(let o of e.declarations||[]){let i=o.init;if(!i||i.type!=="CallExpression")continue;let c=i.callee;if(c?.type!=="Identifier")continue;let a=c.name,{start:f,end:d}=s(e),p=f,u=d;if(He.includes(a)&&a!=="useRef"){if(o.id?.type==="ArrayPattern"){let m=o.id.elements,g=m[0]?.name,b=m[1]?.name;if(g){let E=i.arguments;r.symbols.push({name:g,category:"state",framework:"react",startLine:p,endLine:u,internalKey:this.buildSymbolKey(g,p,u,t),stateSetterName:b,defaultValue:this.getLiteralValue(E?.[0]),parentComponent:t,camelWords:A(g)});}}else if(o.id?.type==="Identifier"){let m=o.id.name;r.symbols.push({name:m,category:"state",framework:"react",startLine:p,endLine:u,internalKey:this.buildSymbolKey(m,p,u,t),parentComponent:t,camelWords:A(m)});}}if(a==="useRef"&&o.id?.type==="Identifier"){let m=o.id.name,g=i.arguments;r.symbols.push({name:m,category:"state",framework:"react",startLine:p,endLine:u,internalKey:this.buildSymbolKey(m,p,u,t),defaultValue:this.getLiteralValue(g?.[0]),parentComponent:t,camelWords:A(m)});}if(Be.includes(a)&&o.id?.type==="Identifier"){let m=o.id.name,b=i.arguments?.[1],E=this.extractDepsArray(b);r.symbols.push({name:m,category:"computed",framework:"react",startLine:p,endLine:u,internalKey:this.buildSymbolKey(m,p,u,t),hookDeps:E,parentComponent:t,camelWords:A(m)});}if(Q(a)&&!mn.includes(a)){let m=o.id?.type==="Identifier"?o.id.name:o.id?.type==="ObjectPattern"?"{...}":"?";r.symbols.push({name:m,category:"hook",framework:"react",startLine:p,endLine:u,internalKey:this.buildSymbolKey(m,p,u,t),parentComponent:t,camelWords:A(m)});}}if(e.type==="ExpressionStatement"&&e.expression?.type==="CallExpression"){let o=e.expression,i=o.callee;if(i?.type==="Identifier"){let c=i.name;if(Ke.includes(c)){let{start:a,end:f}=s(e),d=o.arguments,p=d?.[1],u=this.extractDepsArray(p),m=this.buildSymbolKey(c,a,f,t),g=`${t}.${c}`;if(r.symbols.push({name:c,category:"effect",framework:"react",startLine:a,endLine:f,internalKey:m,hookDeps:u,parentComponent:t,camelWords:A(c)}),d?.[0]){let b=U(d[0],g,n,true).map(N=>({...N,symbolKey:m}));r.behaviors.push(...b);let E=q(d[0],g,n,true);for(let N of E){let h=r.symbols.findIndex(S=>S.name===c&&S.startLine===a);if(N.args&&h!==-1){let S=String(N.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");r.symbols[h].camelWords+=` ${A(S)} ${S}`;}r.relations.push({callerName:g,callerLine:a,callerKey:m,calleeName:N.calleeName,callType:"direct_call",line:N.line,args:N.args});}}}}}if(e.type==="FunctionDeclaration"&&e.id?.type==="Identifier"){let o=e.id.name;if(!Q(o)){let{start:i,end:c}=s(e),a=B(n.join(`
|
|
19
|
+
`),i),f=this.extractParams(e);if(r.symbols.push({name:o,category:"method",framework:"react",startLine:i,endLine:c,internalKey:this.buildSymbolKey(o,i,c,t),signature:`${o}(${(f||[]).join(", ")})`,params:f,isAsync:e.async===true,jsdoc:a,parentComponent:t,camelWords:A(o)}),e.body){let d=U(e.body,o,n,true);r.behaviors.push(...d);let p=q(e.body,o,n,true);for(let u of p){let m=r.symbols.findIndex(g=>g.name===o&&g.startLine===i);if(u.args&&m!==-1){let g=String(u.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");r.symbols[m].camelWords+=` ${A(g)} ${g}`;}r.relations.push({callerName:o,callerLine:i,callerKey:this.buildSymbolKey(o,i,c,t),calleeName:u.calleeName,callType:"direct_call",line:u.line,args:u.args});}}}}if(e.type==="VariableDeclaration")for(let o of e.declarations||[]){let i=o.init;if(!i)continue;let c=i.type==="ArrowFunctionExpression"||i.type==="FunctionExpression";if(!c||o.id?.type!=="Identifier")continue;let a=o.id.name,f=i.type==="CallExpression"?i.callee:null;if(f?.type==="Identifier"&&Q(f.name))continue;if(i.type==="CallExpression"&&i.callee?.name==="useCallback"){let E=i.arguments?.[1],N=this.extractDepsArray(E),{start:h,end:S}=s(e);r.symbols.push({name:a,category:"computed",framework:"react",startLine:h,endLine:S,internalKey:this.buildSymbolKey(a,h,S,t),hookDeps:N,parentComponent:t,camelWords:A(a)});continue}if(!c)continue;let{start:p,end:u}=s(e),m=B(n.join(`
|
|
20
|
+
`),p),g=this.extractParams(i);if(r.symbols.push({name:a,category:"method",framework:"react",startLine:p,endLine:u,internalKey:this.buildSymbolKey(a,p,u,t),signature:`${a}(${(g||[]).join(", ")})`,params:g,isAsync:i.async===true,jsdoc:m,parentComponent:t,camelWords:A(a)}),i.body){let b=U(i.body,a,n,true);r.behaviors.push(...b);let E=q(i.body,a,n,true);for(let N of E){let h=r.symbols.findIndex(S=>S.name===a&&S.startLine===p);if(N.args&&h!==-1){let S=String(N.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");r.symbols[h].camelWords+=` ${A(S)} ${S}`;}r.relations.push({callerName:a,callerLine:p,callerKey:this.buildSymbolKey(a,p,u,t),calleeName:N.calleeName,callType:"direct_call",line:N.line,args:N.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}`}};});function _t(l,e){for(let t of gn)if(t.canParse(l,e)){let n=t.parse(l,e);return hn(n),n}return {framework:"js",filePath:l,symbols:[],relations:[],behaviors:[],errors:[`\u6CA1\u6709\u627E\u5230\u9002\u5408\u7684\u89E3\u6790\u5668: ${l}`]}}function hn(l){if(!l.relations.length||!l.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(l.behaviors.filter(r=>r.category==="network").map(r=>r.symbolName));if(t.size===0)return;let n=new Set(l.behaviors.map(r=>`${r.symbolName}:${r.category}:${r.apiName}:${r.operation}:${r.line}`));for(let r of l.relations){if(!t.has(r.calleeName)||t.has(r.callerName)||e.has(r.callerName))continue;let s={symbolName:r.callerName,symbolKey:r.callerKey,category:"network",apiName:"wrapped_network",operation:r.calleeName,detail:r.args,line:r.line},o=`${s.symbolName}:${s.category}:${s.apiName}:${s.operation}:${s.line}`;n.has(o)||(n.add(o),l.behaviors.push(s));}}var Je,gn,At=z(()=>{L();ze();Nt();St();Je=class extends de{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}},gn=[new ve,new ae,new de,new Je];});var xt={};Kt(xt,{Indexer:()=>ue});var ue,Ye=z(()=>{L();At();G();J();ue=class{projectRoot;db;constructor(e,t){this.projectRoot=e,this.db=t;}async indexProject(e){let t=Date.now(),n=e?.include||[...Me],r=e?.exclude||[...De],s=e?.force||false,o=await En(n,{cwd:this.projectRoot,ignore:r,absolute:true,onlyFiles:true}),i={totalFiles:o.length,indexedFiles:0,skippedFiles:0,totalSymbols:0,durationMs:0,errors:[]};for(let c=0;c<o.length;c++){let a=o[c],f=Se(a,this.projectRoot);e?.onProgress?.(c+1,o.length,f);try{let d=await this.indexFile(a,f,s);d.skipped?i.skippedFiles++:(i.indexedFiles++,i.totalSymbols+=d.symbolCount,d.errors?.length&&i.errors.push(...d.errors.map(p=>({file:f,error:p}))));}catch(d){i.errors.push({file:f,error:String(d)});}}return i.durationMs=Date.now()-t,i}async indexFile(e,t,n=false){let r=M.readFileSync(e,"utf-8"),s=ot(r);if(!n&&this.db.getFileHash(t)===s)return {skipped:true,symbolCount:0};let o=it(r),i=Buffer.byteLength(r,"utf-8"),c=_t(e,r);return this.db.saveParseResult(c,e,t,s,i,o),{skipped:false,symbolCount:c.symbols.length,errors:c.errors}}removeFile(e){this.db.deleteFile(e);}async startWatcher(){let{default:e}=await import('chokidar'),t=e.watch([...Me].map(r=>W.posix.join(this.projectRoot,r)),{cwd:this.projectRoot,ignored:[...De],persistent:true,ignoreInitial:true,awaitWriteFinish:{stabilityThreshold:ht}}),n=async r=>{let s=Se(r,this.projectRoot);try{await this.indexFile(r,s),process.stderr.write(`[Frontend-Code-Skimmer] \u5DF2\u66F4\u65B0\u7D22\u5F15: ${s}
|
|
20
21
|
`);}catch(o){process.stderr.write(`[Frontend-Code-Skimmer] \u66F4\u65B0\u5931\u8D25: ${s} - ${String(o)}
|
|
21
|
-
`);}};return t.on("add",
|
|
22
|
-
`);}),()=>t.close()}};});
|
|
22
|
+
`);}};return t.on("add",n).on("change",n).on("unlink",r=>{let s=Se(r,this.projectRoot);this.removeFile(s),process.stderr.write(`[Frontend-Code-Skimmer] \u5DF2\u5220\u9664\u7D22\u5F15: ${s}
|
|
23
|
+
`);}),()=>t.close()}};});L();L();L();G();J();var Ae=class{db;constructor(e,t){let n=t||W.join(e,_e);M.mkdirSync(W.dirname(n),{recursive:true}),this.db=new zt(n),this.initialize();}initialize(){this.db.pragma("journal_mode = WAL"),this.db.pragma("foreign_keys = ON"),this.db.pragma("synchronous = NORMAL"),this.db.exec(`
|
|
23
24
|
-- \u6587\u4EF6\u5143\u4FE1\u606F
|
|
24
25
|
CREATE TABLE IF NOT EXISTS files (
|
|
25
26
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -117,87 +118,154 @@ import D from'path';import'url';import Rt from'crypto';import {createRequire}fro
|
|
|
117
118
|
CREATE INDEX IF NOT EXISTS idx_behaviors_category ON behaviors(category);
|
|
118
119
|
CREATE INDEX IF NOT EXISTS idx_behaviors_api ON behaviors(api_name, operation);
|
|
119
120
|
CREATE INDEX IF NOT EXISTS idx_behaviors_file ON behaviors(file_id);
|
|
120
|
-
|
|
121
|
+
|
|
122
|
+
-- \u8C03\u7528\u5173\u7CFB\u53C2\u6570 FTS5 \u5168\u6587\u641C\u7D22\u865A\u62DF\u8868
|
|
123
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS relations_fts USING fts5(
|
|
124
|
+
args,
|
|
125
|
+
content='relations',
|
|
126
|
+
content_rowid='id',
|
|
127
|
+
tokenize='porter unicode61'
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
CREATE TRIGGER IF NOT EXISTS relations_fts_insert
|
|
131
|
+
AFTER INSERT ON relations BEGIN
|
|
132
|
+
INSERT INTO relations_fts(rowid, args)
|
|
133
|
+
VALUES (new.id, new.args);
|
|
134
|
+
END;
|
|
135
|
+
|
|
136
|
+
CREATE TRIGGER IF NOT EXISTS relations_fts_delete
|
|
137
|
+
AFTER DELETE ON relations BEGIN
|
|
138
|
+
INSERT INTO relations_fts(relations_fts, rowid, args)
|
|
139
|
+
VALUES ('delete', old.id, old.args);
|
|
140
|
+
END;
|
|
141
|
+
|
|
142
|
+
CREATE TRIGGER IF NOT EXISTS relations_fts_update
|
|
143
|
+
AFTER UPDATE ON relations BEGIN
|
|
144
|
+
INSERT INTO relations_fts(relations_fts, rowid, args)
|
|
145
|
+
VALUES ('delete', old.id, old.args);
|
|
146
|
+
INSERT INTO relations_fts(rowid, args)
|
|
147
|
+
VALUES (new.id, new.args);
|
|
148
|
+
END;
|
|
149
|
+
`);try{this.db.exec("ALTER TABLE relations ADD COLUMN args TEXT;");}catch{}try{this.db.prepare("SELECT 1 FROM relations_fts LIMIT 1").get()||this.db.exec("INSERT OR IGNORE INTO relations_fts(rowid, args) SELECT id, args FROM relations WHERE args IS NOT NULL;");}catch{}}saveParseResult(e,t,n,r,s,o){let i=W.extname(t).slice(1);this.db.transaction(()=>{let a=this.db.prepare("SELECT id FROM files WHERE path = ?").get(n),f;a?(f=a.id,this.db.prepare("DELETE FROM symbols WHERE file_id = ?").run(f),this.db.prepare(`
|
|
121
150
|
UPDATE files SET
|
|
122
151
|
abs_path = ?, framework = ?, content_hash = ?,
|
|
123
152
|
last_indexed_at = ?, file_size = ?, line_count = ?
|
|
124
153
|
WHERE id = ?
|
|
125
|
-
`).run(t,e.framework,
|
|
154
|
+
`).run(t,e.framework,r,Date.now(),s,o,f)):f=this.db.prepare(`
|
|
126
155
|
INSERT INTO files (path, abs_path, file_type, framework, content_hash, last_indexed_at, file_size, line_count)
|
|
127
156
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
128
|
-
`).run(
|
|
157
|
+
`).run(n,t,i,e.framework,r,Date.now(),s,o).lastInsertRowid;let d=this.db.prepare(`
|
|
129
158
|
INSERT INTO symbols (file_id, name, category, framework, start_line, end_line,
|
|
130
159
|
signature, params_json, default_value, camel_words, jsdoc,
|
|
131
160
|
is_async, hook_deps_json, state_setter_name, parent_component)
|
|
132
161
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
133
|
-
`),
|
|
162
|
+
`),p=new Map,u=new Map,m=h=>h.internalKey||`${h.name}:${h.startLine}:${h.endLine}`,g=(h,S)=>{p.set(m(h),S);let k=u.get(h.name)||[];k.push({id:S,name:h.name,startLine:h.startLine,endLine:h.endLine}),u.set(h.name,k);},b=(h,S,k)=>{if(k&&p.has(k))return p.get(k);let w=u.get(h)||[];if(w.length===0)return;if(w.length===1||S==null)return w[0]?.id;let K=w.filter(P=>P.startLine<=S&&S<=P.endLine);return K.length===1?K[0].id:K.length>1?K.sort((P,I)=>P.endLine-P.startLine-(I.endLine-I.startLine)||Math.abs(P.startLine-S)-Math.abs(I.startLine-S))[0]?.id:w.slice().sort((P,I)=>Math.abs(P.startLine-S)-Math.abs(I.startLine-S)||P.endLine-P.startLine-(I.endLine-I.startLine))[0]?.id};for(let h of e.symbols){let k=h.camelWords||A(h.name),w=d.run(f,h.name,h.category,h.framework,h.startLine,h.endLine,h.signature||null,h.params?JSON.stringify(h.params):null,h.defaultValue||null,k,h.jsdoc||null,h.isAsync?1:0,h.hookDeps?JSON.stringify(h.hookDeps):null,h.stateSetterName||null,h.parentComponent||null);g(h,w.lastInsertRowid);}let E=this.db.prepare(`
|
|
134
163
|
INSERT INTO relations (caller_id, callee_name, call_type, line_number, args)
|
|
135
164
|
VALUES (?, ?, ?, ?, ?)
|
|
136
|
-
`);for(let
|
|
165
|
+
`);for(let h of e.relations){let S=b(h.callerName,h.callerLine,h.callerKey);S&&E.run(S,h.calleeName,h.callType,h.line,h.args||null);}let N=this.db.prepare(`
|
|
137
166
|
INSERT INTO behaviors (symbol_id, file_id, category, api_name, operation, detail, line_number)
|
|
138
167
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
139
|
-
`);for(let
|
|
168
|
+
`);for(let h of e.behaviors){let S=b(h.symbolName,h.line,h.symbolKey);S&&N.run(S,f,h.category,h.apiName,h.operation,h.detail||null,h.line);}})();}getFileHash(e){return this.db.prepare("SELECT content_hash FROM files WHERE path = ?").get(e)?.content_hash??null}deleteFile(e){this.db.prepare("DELETE FROM files WHERE path = ?").run(e);}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(`
|
|
140
169
|
SELECT s.*, f.path as file_path
|
|
141
170
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
142
171
|
WHERE s.file_id = ?
|
|
143
172
|
ORDER BY s.start_line ASC
|
|
144
|
-
`).all(
|
|
173
|
+
`).all(n),s=this.db.prepare(`
|
|
145
174
|
SELECT b.*, s.name as symbol_name
|
|
146
175
|
FROM behaviors b JOIN symbols s ON b.symbol_id = s.id
|
|
147
176
|
WHERE b.file_id = ?
|
|
148
|
-
`).all(
|
|
177
|
+
`).all(n);return {file:t,symbols:r,behaviors:s}}listFiles(e){let t="SELECT path, abs_path, framework, line_count FROM files",n=[];return e&&(t+=" WHERE path LIKE ?",n.push(`%${e}%`)),t+=" ORDER BY path",this.db.prepare(t).all(...n)}exactSearch(e,t,n,r){let s=`
|
|
149
178
|
SELECT s.*, f.path as file_path, f.abs_path
|
|
150
179
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
151
180
|
WHERE LOWER(s.name) = LOWER(?)
|
|
152
|
-
`,o=[e];return t&&(s+=" AND s.category = ?",o.push(t)),
|
|
181
|
+
`,o=[e];return t&&(s+=" AND s.category = ?",o.push(t)),n&&(s+=" AND s.framework = ?",o.push(n)),r&&(s+=" AND f.path LIKE ?",o.push(`%${r}%`)),s+=" LIMIT 30",this.db.prepare(s).all(...o)}ftsSearch(e,t,n,r){let s=e.trim().split(/\s+/).map(o=>`${o}*`).join(" ");try{let o=`
|
|
153
182
|
SELECT s.*, f.path as file_path, f.abs_path,
|
|
154
183
|
symbols_fts.rank as fts_rank
|
|
155
184
|
FROM symbols_fts
|
|
156
185
|
JOIN symbols s ON symbols_fts.rowid = s.id
|
|
157
186
|
JOIN files f ON s.file_id = f.id
|
|
158
187
|
WHERE symbols_fts MATCH ?
|
|
159
|
-
`,
|
|
188
|
+
`,i=[s];return t&&(o+=" AND s.category = ?",i.push(t)),n&&(o+=" AND s.framework = ?",i.push(n)),r&&(o+=" AND f.path LIKE ?",i.push(`%${r}%`)),o+=" ORDER BY symbols_fts.rank LIMIT 20",this.db.prepare(o).all(...i)}catch{return []}}getAllSymbolNames(e){let t=`
|
|
160
189
|
SELECT DISTINCT s.name, f.path as file_path, s.id
|
|
161
190
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
162
|
-
`,
|
|
191
|
+
`,n=[];return e&&(t+=" WHERE f.path LIKE ?",n.push(`%${e}%`)),this.db.prepare(t).all(...n)}getSymbolById(e){return this.db.prepare(`
|
|
163
192
|
SELECT s.*, f.path as file_path, f.abs_path
|
|
164
193
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
165
194
|
WHERE s.id = ?
|
|
166
|
-
`).get(e)}getSymbolByName(e,t){
|
|
195
|
+
`).get(e)}getSymbolByName(e,t){if(t){let r=this.db.prepare(`
|
|
167
196
|
SELECT s.*, f.path as file_path, f.abs_path
|
|
168
197
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
169
198
|
WHERE s.name = ? AND f.path = ?
|
|
170
|
-
|
|
199
|
+
LIMIT 1
|
|
200
|
+
`).get(e,t);return r||(r=this.db.prepare(`
|
|
201
|
+
SELECT s.*, f.path as file_path, f.abs_path
|
|
202
|
+
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
203
|
+
WHERE s.name = ? AND f.path LIKE ?
|
|
204
|
+
ORDER BY
|
|
205
|
+
LENGTH(f.path) ASC,
|
|
206
|
+
CASE s.category
|
|
207
|
+
WHEN 'component' THEN 1
|
|
208
|
+
WHEN 'hook' THEN 2
|
|
209
|
+
WHEN 'method' THEN 3
|
|
210
|
+
WHEN 'state' THEN 4
|
|
211
|
+
ELSE 5
|
|
212
|
+
END ASC,
|
|
213
|
+
s.parent_component IS NULL DESC,
|
|
214
|
+
f.line_count DESC
|
|
215
|
+
LIMIT 1
|
|
216
|
+
`).get(e,`%${t}%`)),r}if(!((this.db.prepare(`
|
|
217
|
+
SELECT COUNT(DISTINCT f.path) as c
|
|
218
|
+
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
219
|
+
WHERE s.name = ?
|
|
220
|
+
`).get(e)?.c||0)>1))return this.db.prepare(`
|
|
171
221
|
SELECT s.*, f.path as file_path, f.abs_path
|
|
172
222
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
173
223
|
WHERE s.name = ?
|
|
224
|
+
ORDER BY
|
|
225
|
+
CASE s.category
|
|
226
|
+
WHEN 'component' THEN 1
|
|
227
|
+
WHEN 'hook' THEN 2
|
|
228
|
+
WHEN 'method' THEN 3
|
|
229
|
+
WHEN 'state' THEN 4
|
|
230
|
+
ELSE 5
|
|
231
|
+
END ASC,
|
|
232
|
+
s.parent_component IS NULL DESC,
|
|
233
|
+
f.line_count DESC
|
|
174
234
|
LIMIT 1
|
|
175
|
-
`).get(e)}behaviorSearch(e,t,r,
|
|
235
|
+
`).get(e)}behaviorSearch(e,t,n,r,s){let o=`
|
|
176
236
|
SELECT b.*, s.name as symbol_name, s.start_line, s.end_line, s.category as symbol_category,
|
|
177
237
|
f.path as file_path
|
|
178
238
|
FROM behaviors b
|
|
179
239
|
JOIN symbols s ON b.symbol_id = s.id
|
|
180
240
|
JOIN files f ON b.file_id = f.id
|
|
181
241
|
WHERE 1=1
|
|
182
|
-
`,i=[];return e&&(o+=" AND b.category = ?",i.push(e)),t&&(o+=" AND LOWER(b.api_name) = LOWER(?)",i.push(t)),
|
|
242
|
+
`,i=[];return e&&(o+=" AND b.category = ?",i.push(e)),t&&(o+=" AND LOWER(b.api_name) = LOWER(?)",i.push(t)),n&&(o+=" AND LOWER(b.operation) = LOWER(?)",i.push(n)),r&&(o+=" AND (LOWER(b.detail) LIKE LOWER(?) OR LOWER(b.api_name) LIKE LOWER(?))",i.push(`%${r}%`,`%${r}%`)),s&&(o+=" AND f.path LIKE ?",i.push(`%${s}%`)),o+=" ORDER BY f.path, b.line_number LIMIT 50",this.db.prepare(o).all(...i)}getCallers(e,t,n){let r=`
|
|
183
243
|
SELECT r.*, s.name as caller_name, s.start_line, s.end_line, s.category,
|
|
184
244
|
f.path as file_path
|
|
185
245
|
FROM relations r
|
|
186
246
|
JOIN symbols s ON r.caller_id = s.id
|
|
187
247
|
JOIN files f ON s.file_id = f.id
|
|
188
248
|
WHERE r.callee_name = ?
|
|
189
|
-
`,s=[e];return t&&(
|
|
249
|
+
`,s=[e];return t&&(r+=" AND f.path LIKE ?",s.push(`%${t}%`)),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)}getCallees(e){return this.db.prepare(`
|
|
190
250
|
SELECT r.*, r.callee_name
|
|
191
251
|
FROM relations r
|
|
192
252
|
WHERE r.caller_id = ?
|
|
193
|
-
`).all(e)}findRelationsByArgKeyword(e,t,
|
|
253
|
+
`).all(e)}findRelationsByArgKeyword(e,t,n=50){let r=e.trim();if(!r)return [];let s=`
|
|
194
254
|
SELECT r.*, s.name as caller_name, s.start_line, s.end_line, s.category,
|
|
195
255
|
f.path as file_path
|
|
196
|
-
FROM
|
|
256
|
+
FROM relations_fts fts
|
|
257
|
+
JOIN relations r ON fts.rowid = r.id
|
|
197
258
|
JOIN symbols s ON r.caller_id = s.id
|
|
198
259
|
JOIN files f ON s.file_id = f.id
|
|
199
|
-
WHERE
|
|
200
|
-
`,
|
|
260
|
+
WHERE fts.args MATCH ?
|
|
261
|
+
`,i=[`"${r.replace(/"/g,'""')}"`];t&&(s+=" AND f.path LIKE ?",i.push(`%${t}%`)),s+=" ORDER BY f.path, r.line_number LIMIT ?",i.push(n);let c=[],a=false,f=false;try{c=this.db.prepare(s).all(...i),c.length>0&&(a=!0);}catch{f=true;}let d=/[^a-zA-Z0-9_\u4e00-\u9fa5]/.test(r);if(!a&&(f||d)){let u=r.replace(/[\\%_]/g,"\\$&"),m=`
|
|
262
|
+
SELECT r.*, s.name as caller_name, s.start_line, s.end_line, s.category,
|
|
263
|
+
f.path as file_path
|
|
264
|
+
FROM relations r
|
|
265
|
+
JOIN symbols s ON r.caller_id = s.id
|
|
266
|
+
JOIN files f ON s.file_id = f.id
|
|
267
|
+
WHERE LOWER(COALESCE(r.args, '')) LIKE LOWER(?) ESCAPE '\\'
|
|
268
|
+
`,g=[`%${u}%`];t&&(m+=" AND f.path LIKE ?",g.push(`%${t}%`)),m+=" ORDER BY f.path, r.line_number LIMIT ?",g.push(n),c=this.db.prepare(m).all(...g);}return c}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(`
|
|
201
269
|
SELECT framework, COUNT(*) as count FROM files GROUP BY framework
|
|
202
270
|
`).all(),o=this.db.prepare(`
|
|
203
271
|
SELECT f.path, f.line_count, COUNT(s.id) as symbol_count
|
|
@@ -206,9 +274,9 @@ import D from'path';import'url';import Rt from'crypto';import {createRequire}fro
|
|
|
206
274
|
ORDER BY f.line_count DESC LIMIT 10
|
|
207
275
|
`).all(),i=this.db.prepare(`
|
|
208
276
|
SELECT category, COUNT(*) as count FROM behaviors GROUP BY category ORDER BY count DESC
|
|
209
|
-
`).all(),c=this.db.prepare("SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size()").get()?.size??0;return {fileCount:e,symbolCount:t,behaviorCount:
|
|
277
|
+
`).all(),c=this.db.prepare("SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size()").get()?.size??0;return {fileCount:e,symbolCount:t,behaviorCount:n,relationCount:r,frameworkBreakdown:s,topFiles:o,behaviorStats:i,dbSize:c}}close(){this.db.close();}};J();var Yt=8,qt=30,Zt=14,Qt=360*60*1e3,xe=class{dbCache=new Map;accessTimes=new Map;dbPaths=new Map;lastProject=null;globalCacheDir;defaultProject;maxOpenProjects;maxIdleMs;dbTtlMs;lastDiskCleanupAt=0;constructor(){this.globalCacheDir=W.join(Jt.homedir(),".frontend-code-skimmer","databases"),M.mkdirSync(this.globalCacheDir,{recursive:true}),this.defaultProject=process.env.SKIMMER_PROJECT||null,this.defaultProject&&(this.defaultProject=W.resolve(this.defaultProject)),this.maxOpenProjects=this.parsePositiveInt(process.env.SKIMMER_MAX_OPEN_PROJECTS,Yt);let e=this.parsePositiveInt(process.env.SKIMMER_DB_IDLE_MINUTES,qt),t=this.parsePositiveInt(process.env.SKIMMER_DB_TTL_DAYS,Zt);this.maxIdleMs=e*60*1e3,this.dbTtlMs=t*24*60*60*1e3,this.maybeCleanupDiskCache(Date.now());}resolveProjectRoot(e){if(e){let t=W.resolve(e);if(!M.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=W.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 Ae(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}
|
|
210
278
|
`),process.stderr.write(`[Frontend-Code-Skimmer] \u6570\u636E\u5E93: ${r}
|
|
211
|
-
`),
|
|
279
|
+
`),s}getContext(e){let t=this.resolveProjectRoot(e),n=this.getDatabase(t);return this.lastProject=t,{db:n,projectRoot:t}}setLastProject(e){this.lastProject=W.resolve(e);}listProjects(){return Array.from(this.dbCache.entries()).map(([e])=>({root:e,dbPath:this.dbPaths.get(e)||this.resolveDbPath(e)}))}closeProject(e){let t=W.resolve(e),n=this.dbCache.get(t);n&&(n.close(),this.dbCache.delete(t),this.accessTimes.delete(t),this.dbPaths.delete(t),this.lastProject===t&&(this.lastProject=null));}closeAll(){for(let e of this.dbCache.values())e.close();this.dbCache.clear(),this.accessTimes.clear(),this.dbPaths.clear(),this.lastProject=null;}resolveDbPath(e){if(process.env.SKIMMER_DB&&this.dbCache.size===0)return W.resolve(process.env.SKIMMER_DB);let t=W.join(e,".agent","skimmer_find_symbol"),n=W.join(t,_e);try{return M.mkdirSync(t,{recursive:!0}),M.accessSync(e,M.constants.W_OK),n}catch{let r=e.replace(/[/\\:]/g,"_").replace(/^_+/,"").slice(-60);return W.join(this.globalCacheDir,`${r}.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){for(let t of this.dbCache.keys()){if(t===this.lastProject)continue;let n=this.accessTimes.get(t)??e;e-n>this.maxIdleMs&&this.closeProject(t);}}maybeCleanupDiskCache(e){if(e-this.lastDiskCleanupAt<Qt)return;this.lastDiskCleanupAt=e;let t=[];try{t=M.readdirSync(this.globalCacheDir,{withFileTypes:!0});}catch{return}let n=new Set;for(let s of this.dbPaths.values())s.startsWith(this.globalCacheDir)&&n.add(W.resolve(s));let r=e-this.dbTtlMs;for(let s of t){if(!s.isFile()||!s.name.endsWith(".db"))continue;let o=W.join(this.globalCacheDir,s.name);if(n.has(W.resolve(o)))continue;let i;try{i=M.statSync(o);}catch{continue}i.mtimeMs>=r||(this.safeUnlink(o),this.safeUnlink(`${o}-wal`),this.safeUnlink(`${o}-shm`));}}safeUnlink(e){try{M.existsSync(e)&&M.unlinkSync(e);}catch{}}};L();Ye();function Tt(l,e){l.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
|
|
212
280
|
\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
|
|
213
281
|
\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
|
|
214
282
|
\u591A\u4E2A\u9879\u76EE\u4F1A\u5E76\u884C\u7F13\u5B58\uFF0C\u5207\u6362\u65E0\u9700\u91CD\u542F\u3002
|
|
@@ -218,78 +286,81 @@ import D from'path';import'url';import Rt from'crypto';import {createRequire}fro
|
|
|
218
286
|
- \u4EE3\u7801\u53D8\u66F4\u540E\u5237\u65B0: \u76F8\u540C\u8DEF\u5F84\u518D\u6B21\u8C03\u7528\uFF08\u81EA\u52A8\u68C0\u6D4B\u53D8\u66F4\uFF0C\u589E\u91CF\u66F4\u65B0\uFF09
|
|
219
287
|
- \u5F3A\u5236\u5168\u91CF\u91CD\u5EFA: force=true
|
|
220
288
|
|
|
221
|
-
\u8FD4\u56DE: \u7D22\u5F15\u7EDF\u8BA1\uFF08\u6587\u4EF6\u6570\u3001\u7B26\u53F7\u6570\u3001\u8017\u65F6\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")}),annotations:{readOnlyHint:false,destructiveHint:false,idempotentHint:true}},async({project_path:t,force:
|
|
222
|
-
`);}});e.setLastProject(i);let u=[`\u2705 \u7D22\u5F15\u5B8C\u6210 \u2014 ${i}`,"\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"
|
|
223
|
-
\u26A0\uFE0F \u89E3\u6790\u5931\u8D25 (${a.errors.length} \u4E2A):`);for(let
|
|
224
|
-
`)}]}});}
|
|
289
|
+
\u8FD4\u56DE: \u7D22\u5F15\u7EDF\u8BA1\uFF08\u6587\u4EF6\u6570\u3001\u7B26\u53F7\u6570\u3001\u8017\u65F6\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")}),annotations:{readOnlyHint:false,destructiveHint:false,idempotentHint:true}},async({project_path:t,force:n,include:r,exclude:s})=>{let{db:o,projectRoot:i}=e.getContext(t),a=await new ue(i,o).indexProject({include:r,exclude:s,force:n,onProgress:(E,N)=>{(E%20===0||E===N)&&process.stderr.write(`[Frontend-Code-Skimmer] \u8FDB\u5EA6: ${E}/${N}
|
|
290
|
+
`);}});e.setLastProject(i);let f=a.indexedFiles>0||a.totalFiles>0,d=a.totalSymbols>0,p=f?"\u2705 \u53EF\u7528":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",u=d?"\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",m=f?"\u2705 \u53EF\u7528":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",g=f?"\u2705 \u53EF\u7528\uFF08\u57FA\u4E8E\u6B63\u5219\u626B\u63CF\u6587\u4EF6\uFF09":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",b=[`\u2705 \u7D22\u5F15\u5B8C\u6210 \u2014 ${i}`,"\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: ${a.totalFiles}`,` \u{1F504} \u5DF2\u7D22\u5F15: ${a.indexedFiles}`,` \u23E9 \u5DF2\u8DF3\u8FC7: ${a.skippedFiles} (\u5185\u5BB9\u672A\u53D8)`,` \u{1F523} \u603B\u7B26\u53F7\u6570: ${a.totalSymbols}`,` \u23F1\uFE0F \u8017\u65F6: ${a.durationMs}ms`,"","\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 ${u}`,` skimmer_get_component_outline ${u}`,` skimmer_find_by_behavior ${m}`,` skimmer_trace_data_lifecycle ${g}`,` skimmer_trace_assignments ${g}`,` skimmer_get_code_slice ${p}`,"","\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"];if(a.errors.length>0){b.push(`
|
|
291
|
+
\u26A0\uFE0F \u89E3\u6790\u5931\u8D25 (${a.errors.length} \u4E2A):`);for(let E of a.errors.slice(0,5))b.push(` - ${E.file}: ${E.error}`);a.errors.length>5&&b.push(` ... \u8FD8\u6709 ${a.errors.length-5} \u4E2A`);}return {content:[{type:"text",text:b.join(`
|
|
292
|
+
`)}]}});}L();G();function $t(l,e){l.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
|
|
225
293
|
\u5305\u542B: props\u3001data/state\u3001computed\u3001methods/functions\u3001watch/effect\u3001lifecycle\u3001\u884C\u4E3A\u6807\u7B7E\u3002
|
|
226
294
|
\u884C\u4E3A\u6807\u7B7E\u81EA\u52A8\u6807\u51FA: [storage:localStorage.setItem] [network:axios.get] \u7B49\u3002
|
|
227
295
|
|
|
228
296
|
project_path \u53EF\u7701\u7565\uFF08\u4F7F\u7528\u4E0A\u6B21 skimmer_index_project \u6307\u5B9A\u7684\u9879\u76EE\uFF09\u3002
|
|
229
|
-
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")}),annotations:{readOnlyHint:true,destructiveHint:false}},async({file_path:t,project_path:
|
|
297
|
+
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")}),annotations:{readOnlyHint:true,destructiveHint:false}},async({file_path:t,project_path:n})=>{let{db:r}=e.getContext(n),{file:s,symbols:o,behaviors:i}=r.getFileOutline(t);if(!s)return {content:[{type:"text",text:`\u274C \u6587\u4EF6\u672A\u7D22\u5F15: ${t}
|
|
230
298
|
|
|
231
299
|
\u8BF7\u5148\u8FD0\u884C:
|
|
232
|
-
skimmer_index_project({ project_path: "${
|
|
233
|
-
${
|
|
300
|
+
skimmer_index_project({ project_path: "${n||"<\u9879\u76EE\u8DEF\u5F84>"}" })`}]};let c=new Map;for(let p of i){let u=p.symbol_id;c.has(u)||c.set(u,[]);let m=`[${p.category}:${p.api_name}.${p.operation}${p.detail?`("${p.detail}")`:""}]`,g=c.get(u);g.includes(m)||g.push(m);}let a=[];a.push(`\u{1F4C4} ${t} (${s.line_count} \u884C, ${s.framework})`),a.push(`${"\u2501".repeat(50)}`);let f={};for(let p of o){let u=p.category;f[u]||(f[u]=[]),f[u].push(p);}let d=[{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:p,icon:u,label:m}of d){let g=f[p];if(g?.length){a.push(`
|
|
301
|
+
${u} ${m} (${g.length}):`);for(let b of g){let E=b.name,N=ie(b.start_line,b.end_line),h=pe(b.params_json,[]),S=h.length>0?`(${h.join(", ")})`:"",k=b.default_value?` = ${b.default_value}`:"",w=b.is_async?"async ":"",K=c.get(b.id),P=K?.length?` ${K.slice(0,3).join(" ")}`:"",I=b.state_setter_name?` \u2192 ${b.state_setter_name}`:"",he=b.hook_deps_json?` [deps:${pe(b.hook_deps_json,[]).join(",")}]`:"";a.push(` \u2022 ${w}${E}${S}${k}${I}${he} ${N}${P}`);}}}return a.push(`
|
|
234
302
|
${"\u2500".repeat(50)}`),a.push(`\u{1F4A1} \u67E5\u770B\u5177\u4F53\u4EE3\u7801: skimmer_get_code_slice({ file_path: "${t}", symbol_name: "\u65B9\u6CD5\u540D" })`),{content:[{type:"text",text:a.join(`
|
|
235
|
-
`)}]}});}
|
|
236
|
-
`);for(let o=0;o<s.length;o++){let i=s[o];for(let c of e)if(c.regex.test(i)){
|
|
237
|
-
`).length;return [{content:t[1],lineOffset:
|
|
238
|
-
`),
|
|
239
|
-
`),
|
|
240
|
-
`),
|
|
303
|
+
`)}]}});}L();L();G();J();var fe=class{constructor(e){this.db=e;}search(e,t){let{category:n,framework:r,filePath:s,limit:o=mt,fuzzy:i=true}=t||{},c=new Map,a=this.db.exactSearch(e,n,r,s);for(let g of a){let b=g.id;c.set(b,{symbol:g,filePath:g.file_path,score:100,matchReason:"\u7CBE\u786E\u5339\u914D"});}if(c.size>=o)return this.rankResults(c,o);let f=A(e),d=[e,f,...f.split(" ")].filter(Boolean);for(let g of d){if(g.length<2)continue;let b=this.db.ftsSearch(g,n,r,s);for(let E of b){let N=E.id;if(c.has(N))continue;let h=this.calcFtsScore(e,E.name);c.set(N,{symbol:E,filePath:E.file_path,score:h,matchReason:`FTS5 \u5168\u6587\u5339\u914D (${g})`});}}if(!i||c.size>=o)return this.rankResults(c,o);let p=this.db.getAllSymbolNames(s),u=e.toLowerCase(),m=A(e).split(" ");for(let{name:g,file_path:b,id:E}of p){if(c.has(E))continue;let N=Ne(u,g.toLowerCase());if(N<=gt){let k=Math.max(0,80-N*15),w=this.db.getSymbolById(E);if(!w||n&&w.category!==n||r&&w.framework!==r)continue;let K=ct(e,g,N);c.set(E,{symbol:w,filePath:b,score:k,matchReason:`\u6A21\u7CCA\u5339\u914D (\u7F16\u8F91\u8DDD\u79BB=${N})`,spellingSuggestion:K});continue}let h=A(g).split(" "),S=m.filter(k=>h.some(w=>at(k,w)>=75));if(S.length>0&&S.length>=Math.ceil(m.length*.6)){let k=50+S.length*10,w=this.db.getSymbolById(E);if(!w||n&&w.category!==n||r&&w.framework!==r)continue;c.set(E,{symbol:w,filePath:b,score:k,matchReason:`\u5355\u8BCD\u5339\u914D (${S.join(", ")})`});}}return this.rankResults(c,o)}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}))}calcFtsScore(e,t){let n=e.toLowerCase(),r=t.toLowerCase();if(r===n)return 98;if(r.startsWith(n))return 88;if(r.includes(n))return 78;let s=A(e).split(" "),o=A(t).split(" ");return 60+s.filter(c=>o.some(a=>a.startsWith(c))).length*8}rankResults(e,t){return Array.from(e.values()).sort((n,r)=>r.score-n.score).slice(0,t)}};G();var wt=createRequire(import.meta.url),Z="\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 me(l){return l.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ce(l,e,t){let n=[];for(let r of l){if(!r?.abs_path||!M.existsSync(r.abs_path))continue;let s=M.readFileSync(r.abs_path,"utf-8").split(`
|
|
304
|
+
`);for(let o=0;o<s.length;o++){let i=s[o];for(let c of e)if(c.regex.test(i)){n.push({filePath:r.path,line:o+1,kind:c.kind,text:i.trim()});break}if(n.length>=t)return n}}return n}function Rt(l,e){let t=me(l),n="(?:=|\\+=|-=|\\*=|/=|%=|\\|=|&=|\\^=|&&=|\\|\\|=|\\?\\?=)",r=[{kind:"declaration",regex:new RegExp(`\\b(?:const|let|var)\\s+${t}\\b`)},{kind:"assignment",regex:new RegExp(`\\b${t}\\b\\s*${n}`)},{kind:"update",regex:new RegExp(`(?:\\+\\+|--)\\s*\\b${t}\\b|\\b${t}\\b\\s*(?:\\+\\+|--)`)}];return e&&r.push({kind:"property_assignment",regex:new RegExp(`\\b${t}\\.[A-Za-z_$][\\w$]*\\s*${n}`)},{kind:"indexed_assignment",regex:new RegExp(`\\b${t}\\s*\\[[^\\]]+\\]\\s*${n}`)}),r}function se(l,e){if(!(!l||typeof l!="object")){e(l);for(let t of Object.keys(l)){if(t==="type"||t==="loc"||t==="start"||t==="end")continue;let n=l[t];if(Array.isArray(n))for(let r of n)r&&typeof r=="object"&&r.type&&se(r,e);else n&&typeof n=="object"&&n.type&&se(n,e);}}}function Pe(l){try{return wt("@babel/parser").parse(l,{sourceType:"module",plugins:["typescript","jsx","decorators-legacy"],errorRecovery:!0})}catch{return null}}function Ie(l,e){if(!l.endsWith(".vue"))return [{content:e,lineOffset:1}];try{let{parse:s}=wt("@vue/compiler-sfc"),{descriptor:o}=s(e),i=[];if(o.script?.content&&i.push({content:o.script.content,lineOffset:o.script.loc.start.line}),o.scriptSetup?.content&&i.push({content:o.scriptSetup.content,lineOffset:o.scriptSetup.loc.start.line}),i.length>0)return i}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(`
|
|
305
|
+
`).length;return [{content:t[1],lineOffset:r}]}function ee(l,e){return (l.loc?.start?.line??1)+e-1}function re(l){let e=l.property;return e?e.type==="Identifier"?String(e.name||""):e.type==="Literal"?String(e.value||""):null:null}function kt(l,e){if(l.type!=="MemberExpression")return false;let t=l.object;return !t||t.type!=="ThisExpression"?false:re(l)===e}function Ze(l,e){return !!l&&l.type==="Identifier"&&String(l.name||"")===e}function we(l){let e=l.object;return e?e.type==="Identifier"?String(e.name||""):e.type==="MemberExpression"&&e.object?.type==="ThisExpression"&&re(e)||null:null}function Ct(l){let e=new Set;return l.filter(t=>{let n=`${t.filePath}:${t.line}:${t.kind}:${t.text}`;return e.has(n)?false:(e.add(n),true)})}function Qe(l,e,t=2){if(!M.existsSync(l))return {snippet:"",startLine:e};let n=M.readFileSync(l,"utf-8").split(`
|
|
306
|
+
`),r=Math.max(0,e-1-t),s=Math.min(n.length-1,e-1+t);return {snippet:n.slice(r,s+1).map((i,c)=>{let a=r+c+1;return ` ${a===e?"\u25B6":" "} ${String(a).padStart(4)} \u2502 ${i}`}).join(`
|
|
307
|
+
`),startLine:r+1}}function Le(l,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}[l]??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}]`}function vt(l,e){let t=l;return /created|mounted|beforeMount|setup\s*\(|\bdata\s*\(/.test(t)?"init":/getItem|localStorage|sessionStorage|\bfetch\b|\bload[A-Z]|\bget[A-Z]/.test(t)?"cache":/@click|@change|@input|onClick|onChange|handle[A-Z]|\bwatch\b/.test(t)?"user":e<=30?"init":"unknown"}var Lt={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 Sn(l,e,t){let n=[];for(let r of l){if(!r.abs_path||!M.existsSync(r.abs_path))continue;let s=M.readFileSync(r.abs_path,"utf-8"),o=s.split(`
|
|
308
|
+
`),i=Ie(r.path||W.basename(r.abs_path),s);for(let c of i){let a=Pe(c.content);a&&se(a,f=>{if(n.length>=t||f.type!=="VariableDeclarator")return;let d=f.id;if(!d||d.type!=="Identifier")return;let p=String(d.name||"");if(!p||p===e)return;let u=f.init;if(!u)return;let m=false;if(u.type==="Identifier"&&String(u.name||"")===e&&(m=true),!m&&u.type==="MemberExpression"&&re(u)===e&&(m=true),m||se(u,E=>{m||(E.type==="Identifier"&&String(E.name||"")===e&&(m=true),E.type==="MemberExpression"&&re(E)===e&&(m=true));}),!m)return;let g=ee(f,c.lineOffset),b=o[g-1]?.trim()||"";n.push({alias:p,filePath:r.path,abs_path:r.abs_path,line:g,text:b});});}}return n}function _n(l,e,t){let n=[];for(let r of l){if(!r.abs_path||!M.existsSync(r.abs_path))continue;let s=M.readFileSync(r.abs_path,"utf-8"),o=s.split(`
|
|
309
|
+
`),i=Ie(r.path||W.basename(r.abs_path),s);for(let c of i){let a=Pe(c.content);a&&se(a,f=>{if(n.length>=t||f.type!=="VariableDeclarator")return;let d=f.id;if(!d||d.type!=="ObjectPattern")return;let p=d.properties||[];for(let u of p){if(u.type!=="ObjectProperty"&&u.type!=="Property")continue;let m=u.key,g=u.value,b=m?.type==="Identifier"?String(m.name||""):null;if(b!==e)continue;let E=g?.type==="Identifier"?String(g.name||""):b;if(!E)continue;let N=ee(f,c.lineOffset),h=o[N-1]?.trim()||"";n.push({alias:E,filePath:r.path,line:N,text:h});}});}}return n}function et(l,e,t,n){let r=[];for(let s of l){if(!s.abs_path||!M.existsSync(s.abs_path))continue;let o=M.readFileSync(s.abs_path,"utf-8"),i=o.split(`
|
|
310
|
+
`),c=Ie(s.path||W.basename(s.abs_path),o);for(let a of c){let f=Pe(a.content);if(f&&(se(f,d=>{if(!(r.length>=n)){if(d.type==="VariableDeclarator"){let p=d.id;if(Ze(p,e)){let u=ee(d,a.lineOffset);r.push({filePath:s.path,line:u,kind:"declaration",text:i[u-1]?.trim()||""});}}if(d.type==="AssignmentExpression"){let p=d.left;if(!p)return;let u=ee(d,a.lineOffset);if(Ze(p,e)||kt(p,e)){r.push({filePath:s.path,line:u,kind:"assignment",text:i[u-1]?.trim()||""});return}t&&p.type==="MemberExpression"&&we(p)===e&&r.push({filePath:s.path,line:u,kind:p.computed?"indexed_assignment":"property_assignment",text:i[u-1]?.trim()||""});}if(d.type==="UpdateExpression"){let p=d.argument;if(!p)return;if(Ze(p,e)||kt(p,e)){let u=ee(d,a.lineOffset);r.push({filePath:s.path,line:u,kind:"update",text:i[u-1]?.trim()||""});}}}}),r.length>=n))break}if(r.length>=n)break}return Ct(r).slice(0,n)}function tt(l,e,t,n){let r=[];for(let s of l){if(!s.abs_path||!M.existsSync(s.abs_path))continue;let o=M.readFileSync(s.abs_path,"utf-8"),i=o.split(`
|
|
311
|
+
`),c=Ie(s.path||W.basename(s.abs_path),o);for(let a of c){let f=Pe(a.content);if(f&&(se(f,d=>{if(!(r.length>=n)){if(d.type==="AssignmentExpression"){let p=d.left;if(!p||p.type!=="MemberExpression"||we(p)!==e)return;let m=re(p);if(t&&m!==t)return;let g=ee(d,a.lineOffset);r.push({filePath:s.path,line:g,kind:p.computed?"bracket":"dot",text:i[g-1]?.trim()||""});}if(d.type==="UpdateExpression"){let p=d.argument;if(!p||p.type!=="MemberExpression"||we(p)!==e)return;let m=re(p);if(t&&m!==t)return;let g=ee(d,a.lineOffset);r.push({filePath:s.path,line:g,kind:p.computed?"bracket":"dot",text:i[g-1]?.trim()||""});}if(d.type==="UnaryExpression"&&d.operator==="delete"){let p=d.argument;if(!p||p.type!=="MemberExpression"||we(p)!==e)return;let m=re(p);if(t&&m!==t)return;let g=ee(d,a.lineOffset);r.push({filePath:s.path,line:g,kind:"delete",text:i[g-1]?.trim()||""});}}}),r.length>=n))break}if(r.length>=n)break}return Ct(r).slice(0,n)}function Pt(l,e){l.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
|
|
241
312
|
\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
|
|
242
313
|
\u9A7C\u5CF0\u62C6\u8BCD\uFF1A\u641C "change cache" \u4E5F\u80FD\u627E\u5230 "changeCacheValue"\u3002
|
|
243
314
|
\u6846\u67B6\u611F\u77E5\uFF1A\u53EF\u6309 vue2/vue3/react \u8FC7\u6EE4\u3002
|
|
244
|
-
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(
|
|
315
|
+
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(Z),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\uFF09"),limit:z$1.number().optional().default(15)}),annotations:{readOnlyHint:true,destructiveHint:false}},async({query:t,project_path:n,category:r,framework:s,file_path:o,fuzzy:i,limit:c})=>{let{db:a}=e.getContext(n),d=new fe(a).search(t,{category:r==="all"?void 0:r,framework:s==="all"?void 0:s,filePath:o,fuzzy:i,limit:c});if(d.length===0)return {content:[{type:"text",text:`\u{1F50D} \u641C\u7D22 "${t}" \u65E0\u7ED3\u679C
|
|
245
316
|
|
|
246
317
|
\u{1F4A1} \u5C1D\u8BD5:
|
|
247
318
|
skimmer_find_by_behavior \u6309\u884C\u4E3A\u641C\u7D22
|
|
248
|
-
\u4F8B\u5982: skimmer_find_by_behavior({ category: "storage" })`}]};let
|
|
249
|
-
`];return d.forEach((
|
|
250
|
-
`)}]}}),
|
|
319
|
+
\u4F8B\u5982: skimmer_find_by_behavior({ category: "storage" })`}]};let p=[`\u{1F50D} \u641C\u7D22 "${t}" \u2014 \u627E\u5230 ${d.length} \u4E2A\u7ED3\u679C
|
|
320
|
+
`];return d.forEach((u,m)=>{let g=u.symbol,b=pe(g.params_json,[]),E=b.length>0?`(${b.join(", ")})`:"",N=ie(g.start_line,g.end_line);p.push(`${m+1}. ${g.name}${E} [${g.category}/${g.framework}] \u5339\u914D\u5EA6: ${u.score}%`),p.push(` \u{1F4C4} ${u.filePath}:${N}`),p.push(` \u{1F3AF} ${u.matchReason}`),u.spellingSuggestion&&p.push(` \u{1F4A1} ${u.spellingSuggestion}`),g.default_value&&p.push(` \u{1F4CC} \u9ED8\u8BA4\u503C: ${g.default_value}`),p.push("");}),{content:[{type:"text",text:p.join(`
|
|
321
|
+
`)}]}}),l.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
|
|
251
322
|
\u540C\u65F6\u8FD4\u56DE\u8BE5\u7B26\u53F7\u7684\u884C\u4E3A\u6807\u7B7E\uFF08\u64CD\u4F5C\u4E86\u54EA\u4E9B\u5916\u90E8 API\uFF09\u3002
|
|
252
|
-
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(
|
|
323
|
+
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(Z),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{db:o}=e.getContext(r),i=o.getSymbolByName(n,t);if(!i)return {content:[{type:"text",text:`\u274C \u672A\u627E\u5230: ${n}
|
|
253
324
|
\u{1F4C4} \u6587\u4EF6: ${t}
|
|
254
325
|
|
|
255
|
-
\u{1F4A1} \u8BD5\u8BD5: skimmer_find_symbol({ query: "${
|
|
256
|
-
`),d=Math.max(1,i.start_line-s)-1,
|
|
257
|
-
`),{behaviors:
|
|
258
|
-
\`\`\`${E}`),
|
|
259
|
-
`)}]}}),
|
|
326
|
+
\u{1F4A1} \u8BD5\u8BD5: skimmer_find_symbol({ query: "${n}" })`}]};let c=i.abs_path;if(!M.existsSync(c))return {content:[{type:"text",text:`\u274C \u6587\u4EF6\u4E0D\u5B58\u5728: ${c}`}]};let f=M.readFileSync(c,"utf-8").split(`
|
|
327
|
+
`),d=Math.max(1,i.start_line-s)-1,p=Math.min(f.length,i.end_line+s),u=f.slice(d,p).join(`
|
|
328
|
+
`),{behaviors:m}=o.getFileOutline(t),g=m.filter(h=>h.symbol_id===i.id),b=c.split(".").pop()||"js",E=["tsx","jsx"].includes(b)?"jsx":["ts"].includes(b)?"typescript":"javascript",N=[`\u{1F4CD} ${i.name} [${i.category}/${i.framework}]`,`\u{1F4C4} ${t}:${ie(i.start_line,i.end_line)}`];if(i.jsdoc&&N.push(`\u{1F4DD} ${i.jsdoc}`),g.length>0){let h=[...new Set(g.map(S=>`[${S.category}:${S.api_name}.${S.operation}${S.detail?`("${S.detail}")`:""}]`))];N.push(`\u{1F3F7}\uFE0F \u884C\u4E3A: ${h.join(" ")}`);}return N.push(`
|
|
329
|
+
\`\`\`${E}`),N.push(u),N.push("```"),{content:[{type:"text",text:N.join(`
|
|
330
|
+
`)}]}}),l.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
|
|
260
331
|
\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
|
|
261
332
|
\u2705 \u672C\u5DE5\u5177\u9002\u5408\uFF1Aloading / errorMsg / count \u8FD9\u7C7B\u7B80\u5355 flag \u7684\u8D4B\u503C\u8FFD\u8E2A\u3002
|
|
262
|
-
\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(
|
|
333
|
+
\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(Z),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:o})=>{let{db:i}=e.getContext(n),c=i.listFiles(r),a=Math.min(300,Math.max(1,o||80)),f=s??true,d=et(c,t,f,a);if(d.length===0){let u=Rt(t,f);d=ce(c,u,a);}if(d.length===0)return {content:[{type:"text",text:`\u{1F9E9} \u53D8\u91CF\u8D4B\u503C\u8FFD\u8E2A: "${t}"
|
|
263
334
|
\u672A\u627E\u5230\u5339\u914D\u8D4B\u503C\u8BED\u53E5
|
|
264
|
-
\u8FC7\u6EE4: file_path=${
|
|
265
|
-
`)}]}}),
|
|
335
|
+
\u8FC7\u6EE4: file_path=${r||"*"} include_properties=${f}`}]};let p=[`\u{1F9E9} \u53D8\u91CF\u8D4B\u503C\u8FFD\u8E2A: "${t}"`,`\u8FC7\u6EE4: file_path=${r||"*"} include_properties=${f}`,`\u547D\u4E2D: ${d.length} \u5904`,""];return d.forEach((u,m)=>{p.push(`${m+1}. [${u.kind}] \u{1F4C4} ${u.filePath}:L${u.line}`),p.push(` ${u.text}`);}),{content:[{type:"text",text:p.join(`
|
|
336
|
+
`)}]}}),l.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
|
|
266
337
|
\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
|
|
267
338
|
\u2705 \u672C\u5DE5\u5177\u9002\u5408\uFF1Aobject.specificProp \u7684\u5355\u5B57\u6BB5\u7EA7\u522B\u7CBE\u786E\u8FFD\u8E2A\u3002
|
|
268
|
-
\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(
|
|
339
|
+
\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(Z),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:o})=>{let{db:i}=e.getContext(r),c=i.listFiles(s),a=Math.min(300,Math.max(1,o||80)),f=tt(c,t,n,a);if(f.length===0){let p=me(t),u="(?:=|\\+=|-=|\\*=|/=|%=|\\|=|&=|\\^=|&&=|\\|\\|=|\\?\\?=)",m=[];if(n){let g=me(n);m.push({kind:"dot",regex:new RegExp(`\\b${p}\\.${g}\\s*${u}`)},{kind:"bracket",regex:new RegExp(`\\b${p}\\s*\\[(?:'${g}'|"${g}")\\]\\s*${u}`)},{kind:"delete",regex:new RegExp(`\\bdelete\\s+${p}\\.(?:${g})\\b`)});}else m.push({kind:"dot",regex:new RegExp(`\\b${p}\\.[A-Za-z_$][\\w$]*\\s*${u}`)},{kind:"bracket",regex:new RegExp(`\\b${p}\\s*\\[(?:'[^']+'|"[^"]+")\\]\\s*${u}`)},{kind:"delete",regex:new RegExp(`\\bdelete\\s+${p}\\.[A-Za-z_$][\\w$]*\\b`)});f=ce(c,m,a);}if(f.length===0)return {content:[{type:"text",text:`\u{1F9ED} \u5C5E\u6027\u4FEE\u6539\u8FFD\u8E2A: ${t}${n?`.${n}`:".*"}
|
|
269
340
|
\u672A\u627E\u5230\u5339\u914D\u8BED\u53E5
|
|
270
|
-
\u8FC7\u6EE4: file_path=${s||"*"}`}]};let d=[`\u{1F9ED} \u5C5E\u6027\u4FEE\u6539\u8FFD\u8E2A: ${t}${
|
|
271
|
-
`)}]}}),
|
|
341
|
+
\u8FC7\u6EE4: file_path=${s||"*"}`}]};let d=[`\u{1F9ED} \u5C5E\u6027\u4FEE\u6539\u8FFD\u8E2A: ${t}${n?`.${n}`:".*"}`,`\u8FC7\u6EE4: file_path=${s||"*"}`,`\u547D\u4E2D: ${f.length} \u5904`,""];return f.forEach((p,u)=>{d.push(`${u+1}. [${p.kind}] \u{1F4C4} ${p.filePath}:L${p.line}`),d.push(` ${p.text}`);}),{content:[{type:"text",text:d.join(`
|
|
342
|
+
`)}]}}),l.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
|
|
272
343
|
\u793A\u4F8B:
|
|
273
344
|
- \u627E\u6240\u6709\u64CD\u4F5C localStorage \u7684\u51FD\u6570: { category: "storage" }
|
|
274
345
|
- \u627E\u5199\u5165 localStorage \u7684: { api_name: "localStorage", operation: "setItem" }
|
|
275
346
|
- \u627E\u53D1\u8BF7\u6C42\u7684: { category: "network" }
|
|
276
347
|
- \u627E\u8DEF\u7531\u8DF3\u8F6C\u7684: { category: "router" }
|
|
277
348
|
- \u6309 key \u540D\u641C\u7D22: { keyword: "cacheData" }
|
|
278
|
-
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({project_path:z$1.string().optional().describe(
|
|
279
|
-
\u8FC7\u6EE4\u6761\u4EF6: ${JSON.stringify({category:
|
|
280
|
-
`];for(let[
|
|
281
|
-
`)}]}}),
|
|
282
|
-
`];if(s==="callers"||s==="both"){let
|
|
283
|
-
`)}]}}),
|
|
284
|
-
`),a.length>0){
|
|
285
|
-
\u26A0\uFE0F \u4FEE\u6539\u65F6\u6CE8\u610F\u5916\u90E8\u72B6\u6001\u7684\u8BFB\u5199\u683C\u5F0F\u4FDD\u6301\u4E00\u81F4`);}return {content:[{type:"text",text:
|
|
286
|
-
`)}]}}),
|
|
287
|
-
\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(
|
|
349
|
+
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({project_path:z$1.string().optional().describe(Z),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:o,file_path:i})=>{let{db:c}=e.getContext(t),f=new fe(c).searchByBehavior({category:n,apiName:r,operation:s,keyword:o,filePath:i});if(f.length===0)return {content:[{type:"text",text:`\u{1F3F7}\uFE0F \u672A\u627E\u5230\u5339\u914D\u7684\u884C\u4E3A
|
|
350
|
+
\u8FC7\u6EE4\u6761\u4EF6: ${JSON.stringify({category:n,api_name:r,operation:s,keyword:o,file_path:i})}`}]};let d=new Map;for(let u of f){let m=`${u.category}:${u.apiName}`;d.has(m)||d.set(m,[]),d.get(m).push(u);}let p=[`\u{1F3F7}\uFE0F \u884C\u4E3A\u641C\u7D22\u7ED3\u679C \u2014 ${f.length} \u6761
|
|
351
|
+
`];for(let[u,m]of d){let[g,b]=u.split(":"),E=new Map;for(let N of m)E.has(N.operation)||E.set(N.operation,[]),E.get(N.operation).push(N);p.push(`\u{1F4C2} ${g} \u2192 ${b}:`);for(let[N,h]of E){p.push(` ${N}:`);for(let S of h){let k=S.detail?` key="${S.detail}"`:"";p.push(` \u2022 ${S.symbolName}${k} \u{1F4C4} ${S.filePath}:${ie(S.startLine,S.endLine)}`);}}p.push("");}return {content:[{type:"text",text:p.join(`
|
|
352
|
+
`)}]}}),l.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(Z),file_path:z$1.string().optional().describe("\u6587\u4EF6\u8DEF\u5F84\uFF08\u540C\u540D\u51FD\u6570\u65F6\u7528\u4E8E\u7CBE\u786E\u5B9A\u4F4D\uFF09"),direction:z$1.enum(["callers","callees","both"]).optional().default("both"),arg_keyword:z$1.string().optional().describe('\u8C03\u7528\u53C2\u6570\u5173\u952E\u5B57\u8FC7\u6EE4\uFF08\u5982 "storageParams"\uFF09')}),annotations:{readOnlyHint:true,destructiveHint:false}},async({symbol_name:t,project_path:n,file_path:r,direction:s,arg_keyword:o})=>{let{db:i}=e.getContext(n),c=i.getSymbolByName(t,r),a=[`\u{1F4CA} ${t} \u7684\u8C03\u7528\u56FE\u8C31
|
|
353
|
+
`];if(s==="callers"||s==="both"){let f=i.getCallers(t,r,o);if(a.push(`\u2B06\uFE0F \u88AB\u8C03\u7528 (${f.length} \u5904):`),f.length===0)a.push(" \uFF08\u672A\u627E\u5230\u8C03\u7528\u8005\uFF09");else for(let d of f){let p=d.args?` \u53C2\u6570: "${d.args}"`:"";a.push(` \u2022 ${d.caller_name} [${d.category}] \u{1F4C4} ${d.file_path}:L${d.start_line}${p}`);}a.push("");}if((s==="callees"||s==="both")&&c){let f=i.getCallees(c.id);if(a.push(`\u2B07\uFE0F \u8C03\u7528\u4E86 (${f.length} \u4E2A):`),f.length===0)a.push(" \uFF08\u672A\u5206\u6790\u5230\u8C03\u7528\u5173\u7CFB\uFF09");else for(let d of f){let p=d.args?`("${d.args}")`:"";a.push(` \u2022 ${d.callee_name}${p} [${d.call_type}] L${d.line_number}`);}a.push("");}if(c){let{behaviors:f}=i.getFileOutline(c.file_path),d=f.filter(p=>p.symbol_id===c.id);if(d.length>0){a.push("\u{1F4E6} \u5916\u90E8\u72B6\u6001\u64CD\u4F5C:");for(let p of d){let u=p.detail?` ("${p.detail}")`:"";a.push(` \u2022 ${p.api_name}.${p.operation}${u} [${p.category}] L${p.line_number}`);}}}return {content:[{type:"text",text:a.join(`
|
|
354
|
+
`)}]}}),l.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(Z),file_path:z$1.string().optional().describe("\u6587\u4EF6\u8DEF\u5F84\uFF08\u540C\u540D\u65F6\u7CBE\u786E\u5B9A\u4F4D\uFF09")}),annotations:{readOnlyHint:true,destructiveHint:false}},async({symbol_name:t,project_path:n,file_path:r})=>{let{db:s}=e.getContext(n),o=s.getCallers(t,r),i=s.getSymbolByName(t,r),{behaviors:c}=i?s.getFileOutline(i.file_path):{behaviors:[]},a=i?c.filter(u=>u.symbol_id===i.id):[],f=o.length===0?"\u{1F7E2}":o.length<=3?"\u{1F7E1}":"\u{1F534}",d=o.length===0?"\u4F4E":o.length<=3?"\u4E2D":"\u9AD8",p=[`\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",`${f} \u98CE\u9669\u7B49\u7EA7: ${d} (${o.length} \u5904\u76F4\u63A5\u8C03\u7528)`,""];if(o.length>0?(p.push("\u{1F534} \u76F4\u63A5\u5F71\u54CD:"),o.forEach((u,m)=>{p.push(` ${m+1}. ${u.caller_name} [${u.category}] \u{1F4C4} ${u.file_path}:L${u.start_line}`);}),p.push("")):p.push(`\u2705 \u65E0\u8C03\u7528\u8005\uFF0C\u5F71\u54CD\u8303\u56F4\u53EF\u63A7
|
|
355
|
+
`),a.length>0){p.push("\u{1F4E6} \u5916\u90E8\u72B6\u6001\u5F71\u54CD:");for(let u of a)p.push(` \u2022 ${u.api_name}.${u.operation}${u.detail?` key="${u.detail}"`:""} [${u.category}]`);p.push(`
|
|
356
|
+
\u26A0\uFE0F \u4FEE\u6539\u65F6\u6CE8\u610F\u5916\u90E8\u72B6\u6001\u7684\u8BFB\u5199\u683C\u5F0F\u4FDD\u6301\u4E00\u81F4`);}return {content:[{type:"text",text:p.join(`
|
|
357
|
+
`)}]}}),l.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
|
|
358
|
+
\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(Z),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})=>{if(n){let d=e.listProjects();if(d.length===0)return {content:[{type:"text",text:`\u{1F4CB} \u5F53\u524D\u6CA1\u6709\u5DF2\u7D22\u5F15\u7684\u9879\u76EE
|
|
288
359
|
|
|
289
|
-
\u4F7F\u7528 skimmer_index_project({ project_path: "/your/project" }) \u5F00\u59CB\u7D22\u5F15`}]};let
|
|
290
|
-
`];return d.forEach((
|
|
291
|
-
`)}]}}let{db:
|
|
292
|
-
`)}]}}),
|
|
360
|
+
\u4F7F\u7528 skimmer_index_project({ project_path: "/your/project" }) \u5F00\u59CB\u7D22\u5F15`}]};let p=[`\u{1F4CB} \u5DF2\u7D22\u5F15\u7684\u9879\u76EE (${d.length} \u4E2A):
|
|
361
|
+
`];return d.forEach((u,m)=>{p.push(`${m+1}. ${u.root}`),p.push(` \u6570\u636E\u5E93: ${u.dbPath}`);}),{content:[{type:"text",text:p.join(`
|
|
362
|
+
`)}]}}let{db:r,projectRoot:s}=e.getContext(t),o=r.getProjectStats(),i=["\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} ${s}`,"",`\u{1F4C8} \u6574\u4F53: \u6587\u4EF6 ${o.fileCount} | \u7B26\u53F7 ${o.symbolCount} | \u884C\u4E3A\u6807\u7B7E ${o.behaviorCount} | \u8C03\u7528\u5173\u7CFB ${o.relationCount}`,""],c=o.frameworkBreakdown;if(c?.length){let d={vue2:"\u{1F7E2} Vue2",vue3:"\u{1F535} Vue3",react:"\u269B\uFE0F React",js:"\u{1F4DC} JS",ts:"\u{1F4D8} TS"};i.push("\u{1F527} \u6846\u67B6\u5206\u5E03:");for(let p of c)i.push(` ${d[p.framework]||p.framework}: ${p.count} \u4E2A`);i.push("");}let a=o.topFiles;a?.length&&(i.push("\u{1F5C2}\uFE0F Top 10 \u6700\u5927\u6587\u4EF6:"),a.forEach((d,p)=>i.push(` ${p+1}. ${d.path} (${d.line_count} \u884C, ${d.symbol_count} \u7B26\u53F7)`)),i.push(""));let f=o.behaviorStats;if(f?.length){let d={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"};i.push("\u{1F3F7}\uFE0F \u884C\u4E3A\u7EDF\u8BA1:");for(let p of f)i.push(` ${d[p.category]||p.category}: ${p.count} \u5904`);i.push("");}return i.push(`\u{1F4BD} \u6570\u636E\u5E93: ${Math.round(o.dbSize/1024)} KB`),{content:[{type:"text",text:i.join(`
|
|
363
|
+
`)}]}}),l.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
|
|
293
364
|
|
|
294
365
|
\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
|
|
295
366
|
- "xxx \u662F\u4ECE\u54EA\u91CC\u6765\u7684\uFF1F" / "xxx \u662F\u600E\u4E48\u8D4B\u503C\u7684\uFF1F"
|
|
@@ -307,14 +378,15 @@ project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({project_path:z$1.
|
|
|
307
378
|
\u65E7\u65B9\u5F0F: trace_assignments \u2192 find_symbol \u2192 get_code_slice \u2192 find_by_behavior \u2192 trace_key_flow
|
|
308
379
|
\u65B0\u65B9\u5F0F: skimmer_trace_data_lifecycle({ variable: "xxx" }) \u2190 \u76F4\u63A5\u5F97\u5230\u5168\u90E8
|
|
309
380
|
|
|
310
|
-
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(
|
|
311
|
-
`)}]}});}var
|
|
312
|
-
`);
|
|
313
|
-
`);}
|
|
314
|
-
`);}
|
|
381
|
+
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(Z),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:o,limit:i})=>{let {db:c}=e.getContext(n),a=Math.min(5,Math.max(1,o||2)),f=Math.min(120,Math.max(1,i||40)),d=c.listFiles(r),p=_n(d,t,20),u=[...new Set(p.map(y=>y.alias).filter(y=>y!==t))],m=Sn(d,t,20),g=[...new Set(m.map(y=>y.alias).filter(y=>y!==t))],b=[...new Set([...u,...g])],N=[t,...b],h=et(d,t,false,f);for(let y of b)h.push(...et(d,y,false,Math.floor(f/2)));let S=h.length===0?ce(d,Rt(t,false),f):[],k=h.length>0?h:S,w=tt(d,t,void 0,f);for(let y of b)w.push(...tt(d,y,void 0,Math.floor(f/2)));let K=w.length===0?ce(d,[{kind:"dot",regex:new RegExp(`\\b${t}\\.[A-Za-z_$][\\w$]*\\s*(?:=|\\+=|-=|\\*=|\\/=|%=|\\|=|&=|\\^=|&&=|\\|\\|=|\\?\\?=)`)},{kind:"bracket",regex:new RegExp(`\\b${t}\\s*\\[(?:'[^']+'|"[^"]+")\\]\\s*(?:=|\\+=)`)},{kind:"delete",regex:new RegExp(`\\bdelete\\s+${t}\\.[A-Za-z_$][\\w$]*\\b`)}],f):[],P=w.length>0?w:K,I=c.findRelationsByArgKeyword(t,r,f);for(let y of b)I.push(...c.findRelationsByArgKeyword(y,r,Math.floor(f/2)));let he=[],nt=[],rt=[];for(let y of N){let R=me(y),_=/^[a-zA-Z_$][\w$]*$/.test(y)?"\\b":"";he.push({kind:"template",regex:new RegExp(`(?::\\w+|v-model|v-if|v-show|@\\w+)="[^"]*${_}${R}${_}|\\{\\{[^}]*${_}${R}${_}[^}]*\\}\\}`)},{kind:"return",regex:new RegExp(`\\breturn\\b[^=]*${_}${R}${_}`)},{kind:"watch",regex:new RegExp(`watch[^(]*['"]\\.?${R}['"]`)},{kind:"computed_read",regex:new RegExp(`=>[^=]*${_}${R}${_}|return[^=]*${_}${R}${_}`)},{kind:"arg_usage",regex:new RegExp(`\\(\\s*[^)]*${_}${R}${_}[^)]*\\)`)}),nt.push(`${_}${R}${_}\\s*(?:=|\\+=|-=|\\*=|\\/=)(?!=)|\\b(?:const|let|var)\\s+${R}\\b`),rt.push(`${_}${R}${_}\\.\\w+\\s*(?:=|\\+=|-=)(?!=)|${_}${R}${_}\\s*\\[`);}let It=ce(d,he,f),Ot=new RegExp(nt.join("|")),jt=new RegExp(rt.join("|")),be=It.filter(y=>!Ot.test(y.text)&&!jt.test(y.text)),je=new Map,Ft=(y,R)=>{if(!je.has(y)){let{behaviors:v}=c.getFileOutline(y),$=new Map;for(let C of v){let H=String(C.symbol_name||"");$.has(H)||$.set(H,[]),$.get(H).push(C);}je.set(y,$);}return (je.get(y)?.get(R)||[]).filter(v=>String(v.category||"")!=="storage"?false:s==="all"?true:String(v.api_name||"").toLowerCase()===s.toLowerCase())},Dt=(y,R)=>{let _=[],v=[{name:y,filePath:R,path:[y],level:0}],$=new Set([`${R}::${y}`]);for(;v.length>0;){let C=v.shift(),H=Ft(C.filePath,C.name);if(H.length>0){_.push({path:C.path,file:C.filePath,behaviors:H});continue}if(C.level>=a)continue;let O=c.getSymbolByName(C.name,C.filePath);if(O||(O=c.getSymbolByName(C.name)),!O)continue;let te=String(O.file_path||O.abs_path||C.filePath),Ee=c.getCallees(O.id);for(let Fe of Ee){let X=String(Fe.callee_name||"");if(!X||X.startsWith("$"))continue;let st=`${te}::${X}`;$.has(st)||($.add(st),v.push({name:X,filePath:te,path:[...C.path,X],level:C.level+1}));}}return _},Mt=b.length>0?`
|
|
382
|
+
\u{1F517} \u53D1\u73B0\u522B\u540D: ${b.map(y=>`"${y}"`).join(", ")}\uFF08\u5DF2\u4E00\u5E76\u8FFD\u8E2A\u5C5E\u6027\u4FEE\u6539\uFF09`:"",oe=[];m.length>0&&(oe.push(` \u{1F517} \u5F15\u7528\u522B\u540D\u4F20\u64AD (${m.length} \u5904) \u2014 \u8FD9\u4E9B\u5C40\u90E8\u53D8\u91CF\u662F "${t}" \u7684\u5F15\u7528\uFF0C\u5176\u5C5E\u6027\u4FEE\u6539\u4E5F\u88AB\u8FFD\u8E2A:`),m.slice(0,10).forEach(y=>{let _=d.find(C=>C.path===y.filePath)?.abs_path||y.abs_path,v=Le("alias_ref"),$=_?Qe(_,y.line,2):{snippet:""};oe.push(` \u{1F4C4} ${y.filePath}:L${y.line} "${y.alias}" = ... ${v}`),oe.push(` ${y.text}`),$.snippet&&oe.push($.snippet);}));let T=[`\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=${a}${Mt}`,""];if(T.push(`\u2460 \u58F0\u660E & \u6574\u4F53\u8D4B\u503C (${k.length} \u5904)`),k.length===0)T.push(" \uFF08\u672A\u627E\u5230\uFF09");else {let y={init:[],cache:[],user:[],unknown:[]};for(let _ of k){let v=vt(_.text,_.line);y[v].push(_);}let R=["init","cache","user","unknown"];for(let _ of R){let v=y[_];!v||v.length===0||(T.push(` \u25B8 ${Lt[_]} (${v.length} \u5904)`),v.slice(0,8).forEach($=>{let C=b.includes($.text.split("=")[0]?.trim().replace(/^(?:const|let|var)\s+/,"")||""),H=Le($.kind,C);T.push(` \u{1F4C4} ${$.filePath}:L${$.line} [${$.kind}] ${H}`),T.push(` ${$.text}`);}));}oe.length>0&&(T.push(""),T.push(...oe));}if(T.push(""),T.push(`\u2461 \u5C5E\u6027\u4FEE\u6539 (${P.length} \u5904)`),P.length===0)T.push(' \uFF08\u672A\u627E\u5230 object.prop \u6216 object["prop"] \u5199\u5165\uFF09'),b.length>0&&T.push(` \u2139\uFE0F \u5DF2\u8FFD\u8E2A\u522B\u540D: ${b.map(y=>`"${y}"`).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 y={init:[],cache:[],user:[],unknown:[]};for(let _ of P){let v=vt(_.text,_.line);y[v].push(_);}let R=["init","cache","user","unknown"];for(let _ of R){let v=y[_];!v||v.length===0||(T.push(` \u25B8 ${Lt[_]} (${v.length} \u5904)`),v.slice(0,8).forEach($=>{let C=b.some(X=>$.text.startsWith(X)),H=Le($.kind,C),te=d.find(X=>X.path===$.filePath)?.abs_path||"",Ee=te?Qe(te,$.line,2):{snippet:""},Fe=C?" \u{1F517}(via alias)":"";T.push(` \u{1F4C4} ${$.filePath}:L${$.line} [${$.kind}] ${H}${Fe}`),Ee.snippet&&T.push(Ee.snippet);}));}}if(T.push(""),T.push(`\u2462 \u4F5C\u4E3A\u53C2\u6570\u88AB\u4F20\u5165\u8C03\u7528 (${I.length} \u5904)`),I.length===0?T.push(" \uFF08\u672A\u53D1\u73B0\u4EE5\u8BE5\u53D8\u91CF\u4F5C\u4E3A\u53C2\u6570\u7684\u51FD\u6570\u8C03\u7528\uFF09"):I.slice(0,20).forEach(y=>{let R=String(y.args||"");T.push(` \u{1F4C4} ${y.file_path}:L${y.line_number} ${y.caller_name} \u2192 ${y.callee_name} \u53C2\u6570: "${R}"`);}),T.push(""),T.push(`\u2463 \u8BFB\u53D6/\u4F7F\u7528 (${be.length} \u5904)`),be.length===0)T.push(" \uFF08\u672A\u53D1\u73B0 template \u7ED1\u5B9A / watch / computed / return \u4E2D\u7684\u5F15\u7528\uFF09");else {let y=new Map;for(let _ of be)y.has(_.kind)||y.set(_.kind,[]),y.get(_.kind).push(_);let R={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[_,v]of y)T.push(` \u25B8 ${R[_]||_}`),v.slice(0,8).forEach($=>T.push(` \u{1F4C4} ${$.filePath}:L${$.line} ${$.text}`));}T.push("");let le=0;T.push(`\u2464 Storage \u843D\u70B9\u8FFD\u8E2A (storage_api=${s}, depth=${a})`);let Wt=s==="localStorage"?"localStorage":s==="sessionStorage"?"sessionStorage":"(?:localStorage|sessionStorage)",Ut=N.map(y=>({kind:"direct_storage",regex:new RegExp(`${Wt}\\.(?:setItem|getItem|removeItem|clear)\\(.*?\\b${me(y)}\\b`)})),ye=ce(d,Ut,f);if(ye.length>0&&(le+=1,T.push(` \u843D\u70B9 [\u76F4\u63A5\u547D\u4E2D\u5B58\u50A8] ${Le("direct_storage")}:`),ye.slice(0,15).forEach(y=>{let _=d.find($=>$.path===y.filePath)?.abs_path||"",v=_?Qe(_,y.line,2):{snippet:""};T.push(` \u{1F4C4} ${y.filePath}:L${y.line} ${y.text.trim()}`),v.snippet&&T.push(v.snippet);})),I.length===0&&ye.length===0)T.push(" \uFF08\u672A\u53D1\u73B0\u76F4\u63A5 Storage \u64CD\u4F5C\uFF0C\u4E14\u65E0\u8C03\u7528\u5165\u53E3\u5C55\u5F00\u8FFD\u8E2A\uFF09");else {let y=new Map;for(let R of I){let _=`${R.file_path}::${R.callee_name}`;y.has(_)||y.set(_,R);}for(let[,R]of y){let _=String(R.callee_name||""),v=String(R.file_path||""),$=Dt(_,v);$.length!==0&&(le+=1,$.slice(0,3).forEach(C=>{let H=C.file!==v?` \u2197 \u8DE8\u6587\u4EF6: ${C.file}`:"";T.push(` \u94FE\u8DEF: ${C.path.join(" \u2192 ")}${H}`),C.behaviors.forEach(O=>{let te=O.detail?`("${String(O.detail)}")`:"";T.push(` \u843D\u70B9: ${O.api_name}.${O.operation}${te} [${O.category}] L${O.line_number}`);});}));}le===0&&ye.length===0&&T.push(` \uFF08\u5728 depth=${a} \u5C42\u5185\u672A\u627E\u5230 storage \u5199\u5165\u94FE\u8DEF\uFF09`);}T.push(""),T.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 Ht=b.length>0?` (\u542B ${b.length} \u4E2A\u522B\u540D: ${b.slice(0,3).map(y=>`"${y}"`).join(", ")})`:"";return T.push(`\u2705 \u6C47\u603B${Ht}:`),T.push(` \u2460 \u58F0\u660E/\u8D4B\u503C: ${k.length} \u5904`),T.push(` \u2461 \u5C5E\u6027\u4FEE\u6539: ${P.length} \u5904 (\u5DF2\u8FFD\u8E2A\u522B\u540D: ${b.map(y=>`"${y}"`).join(", ")||"\u65E0"})`),T.push(` \u2462 \u53C2\u6570\u4F20\u9012: ${I.length} \u5904`),T.push(` \u2463 \u8BFB\u53D6\u5F15\u7528: ${be.length} \u5904`),T.push(` \u2464 storage: ${le>0?`\u2713 \u53D1\u73B0\u5199\u5165\u94FE\u8DEF (${le} \u6761)`:"\u2717 \u672A\u53D1\u73B0"}`),T.push(""),T.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"),T.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"),{content:[{type:"text",text:T.join(`
|
|
383
|
+
`)}]}});}var ge=new xe,Oe=new McpServer({name:"frontend-code-skimmer",version:"0.1.0"});Tt(Oe,ge);$t(Oe,ge);Pt(Oe,ge);async function Tn(){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}
|
|
384
|
+
`);try{let{Indexer:n}=await Promise.resolve().then(()=>(Ye(),xt)),{db:r,projectRoot:s}=ge.getContext(process.env.SKIMMER_PROJECT),i=await new n(s,r).indexProject();process.stderr.write(`[Frontend-Code-Skimmer] \u5B8C\u6210: ${i.indexedFiles} \u6587\u4EF6, ${i.totalSymbols} \u7B26\u53F7
|
|
385
|
+
`);}catch(n){process.stderr.write(`[Frontend-Code-Skimmer] \u7D22\u5F15\u5931\u8D25: ${String(n)}
|
|
386
|
+
`);}}let e=new StdioServerTransport;await Oe.connect(e),process.stderr.write(`[Frontend-Code-Skimmer MCP] \u5DF2\u542F\u52A8
|
|
315
387
|
`),process.stderr.write(`[Frontend-Code-Skimmer MCP] \u652F\u6301\u6846\u67B6: Vue 2 / Vue 3 / React Hooks
|
|
316
388
|
`),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
|
|
317
389
|
`),process.env.SKIMMER_PROJECT?process.stderr.write(`[Frontend-Code-Skimmer MCP] \u9ED8\u8BA4\u9879\u76EE: ${process.env.SKIMMER_PROJECT}
|
|
318
390
|
`):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
|
|
319
|
-
`);let t=()=>{
|
|
391
|
+
`);let t=()=>{ge.closeAll(),process.exit(0);};process.on("SIGINT",t),process.on("SIGTERM",t);}Tn().catch(l=>{process.stderr.write(`[Frontend-Code-Skimmer MCP] \u542F\u52A8\u5931\u8D25: ${String(l)}
|
|
320
392
|
`),process.exit(1);});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jokeran/frontend-code-skimmer",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Frontend-Code-Skimmer: 不读全文,只看骨架;不搜字符,搜语义关联。支持 Vue2/Vue3/React Hooks",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"build": "tsup",
|
|
21
21
|
"dev": "tsx watch src/index.ts",
|
|
22
22
|
"start": "node dist/index.js",
|
|
23
|
-
"clean": "rm -rf dist"
|
|
23
|
+
"clean": "rm -rf dist",
|
|
24
|
+
"test": "tsc -p tsconfig.test.json && node --test .tmp-test/tests/*.test.js"
|
|
24
25
|
},
|
|
25
26
|
"engines": {
|
|
26
27
|
"node": ">=18"
|