@jokeran/frontend-code-skimmer 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -34
- package/dist/index.js +123 -105
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,25 +12,43 @@ AI 代码助手的智能代码索引引擎,支持 **Vue 2 / Vue 3 / React Hook
|
|
|
12
12
|
- **同名函数串台**:`skimmer_find_symbol` / `skimmer_find_by_behavior` / `skimmer_get_call_graph` 支持 `file_path` 过滤
|
|
13
13
|
- **修改前评估影响**:`skimmer_get_blast_radius` 告诉你改一个函数会影响哪些地方
|
|
14
14
|
- **变量数据流追踪**:`skimmer_trace_data_lifecycle` 一次调用聚合声明、属性修改、参数传递、Storage 落点 4 个维度
|
|
15
|
+
- **索引过期行号偏移**:`skimmer_get_component_outline` 和 `skimmer_get_code_slice` 会自动检测索引是否过期并给出警告
|
|
15
16
|
|
|
16
|
-
##
|
|
17
|
+
## 11 个 MCP 工具
|
|
17
18
|
|
|
18
19
|
| 工具 | 用途 |
|
|
19
20
|
| -------------------------------- | -------------------------------------------- |
|
|
20
|
-
| `skimmer_index_project` |
|
|
21
|
-
| `skimmer_get_component_outline` | ⭐ 获取文件骨架(极致 Token
|
|
22
|
-
| `skimmer_find_symbol` |
|
|
23
|
-
| `skimmer_get_code_slice` |
|
|
24
|
-
| `skimmer_trace_assignments` |
|
|
25
|
-
| `skimmer_trace_property_changes` |
|
|
21
|
+
| `skimmer_index_project` | 初始化/更新代码索引(支持 `force: true` 全量重建) |
|
|
22
|
+
| `skimmer_get_component_outline` | ⭐ 获取文件骨架(极致 Token 节省,自动检测索引过期) |
|
|
23
|
+
| `skimmer_find_symbol` | 智能符号搜索(精确 → FTS5 → Levenshtein 三层,支持拼写错误) |
|
|
24
|
+
| `skimmer_get_code_slice` | 精准代码切片(只取一个函数,自动检测行号偏移) |
|
|
25
|
+
| `skimmer_trace_assignments` | 变量赋值链路追踪(轻量降级工具,AST 优先) |
|
|
26
|
+
| `skimmer_trace_property_changes` | 对象属性修改追踪(轻量降级工具) |
|
|
26
27
|
| `skimmer_find_by_behavior` | ⭐ 按行为标签搜索(绕过命名问题) |
|
|
27
|
-
| `skimmer_trace_data_lifecycle` | ⭐
|
|
28
|
-
| `skimmer_get_call_graph` |
|
|
28
|
+
| `skimmer_trace_data_lifecycle` | ⭐ 变量完整生命周期追踪(首选,一键聚合 5 维度) |
|
|
29
|
+
| `skimmer_get_call_graph` | 函数调用关系图谱(支持 callers / callees / both) |
|
|
29
30
|
| `skimmer_get_blast_radius` | 修改影响范围评估 |
|
|
30
|
-
| `skimmer_get_project_overview` |
|
|
31
|
+
| `skimmer_get_project_overview` | 项目整体概览(文件数、符号数、框架分布) |
|
|
31
32
|
|
|
32
33
|
## 安装
|
|
33
34
|
|
|
35
|
+
### 方式一:npx 直接使用(推荐)
|
|
36
|
+
|
|
37
|
+
无需克隆仓库,直接在 MCP 配置中使用:
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"mcpServers": {
|
|
42
|
+
"frontend-code-skimmer": {
|
|
43
|
+
"command": "npx",
|
|
44
|
+
"args": ["-y", "@jokeran/frontend-code-skimmer"]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 方式二:本地克隆构建
|
|
51
|
+
|
|
34
52
|
```bash
|
|
35
53
|
git clone <this-repo>
|
|
36
54
|
cd frontend-code-skimmer
|
|
@@ -40,7 +58,28 @@ npm run build
|
|
|
40
58
|
|
|
41
59
|
## 配置(Cursor / Claude Desktop)
|
|
42
60
|
|
|
43
|
-
|
|
61
|
+
### npx 安装(推荐)
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"mcpServers": {
|
|
66
|
+
"frontend-code-skimmer": {
|
|
67
|
+
"command": "npx",
|
|
68
|
+
"args": ["-y", "@jokeran/frontend-code-skimmer"],
|
|
69
|
+
"autoApprove": [
|
|
70
|
+
"skimmer_index_project", "skimmer_get_component_outline",
|
|
71
|
+
"skimmer_find_symbol", "skimmer_get_code_slice",
|
|
72
|
+
"skimmer_trace_assignments", "skimmer_trace_property_changes",
|
|
73
|
+
"skimmer_find_by_behavior", "skimmer_trace_data_lifecycle",
|
|
74
|
+
"skimmer_get_call_graph", "skimmer_get_blast_radius",
|
|
75
|
+
"skimmer_get_project_overview"
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### 本地构建安装
|
|
44
83
|
|
|
45
84
|
```json
|
|
46
85
|
{
|
|
@@ -48,23 +87,30 @@ npm run build
|
|
|
48
87
|
"frontend-code-skimmer": {
|
|
49
88
|
"command": "node",
|
|
50
89
|
"args": ["/path/to/frontend-code-skimmer/dist/index.js"],
|
|
51
|
-
"autoApprove": [
|
|
90
|
+
"autoApprove": [
|
|
91
|
+
"skimmer_index_project", "skimmer_get_component_outline",
|
|
92
|
+
"skimmer_find_symbol", "skimmer_get_code_slice",
|
|
93
|
+
"skimmer_trace_assignments", "skimmer_trace_property_changes",
|
|
94
|
+
"skimmer_find_by_behavior", "skimmer_trace_data_lifecycle",
|
|
95
|
+
"skimmer_get_call_graph", "skimmer_get_blast_radius",
|
|
96
|
+
"skimmer_get_project_overview"
|
|
97
|
+
]
|
|
52
98
|
}
|
|
53
99
|
}
|
|
54
100
|
}
|
|
55
101
|
```
|
|
56
102
|
|
|
57
|
-
|
|
103
|
+
不需要任何 `env` 配置。项目路径在**每次工具调用时动态指定**。
|
|
58
104
|
|
|
59
105
|
### 多项目工作流
|
|
60
106
|
|
|
61
107
|
```
|
|
62
|
-
优先从编辑器工作区、已打开文件和当前上下文自动推断项目根目录绝对路径,填入
|
|
108
|
+
优先从编辑器工作区、已打开文件和当前上下文自动推断项目根目录绝对路径,填入 project_path(无需向用户追问)。
|
|
63
109
|
|
|
64
110
|
项目 A: skimmer_index_project({ project_path: "/work/project-a" })
|
|
65
111
|
项目 B: skimmer_index_project({ project_path: "/work/project-b" })
|
|
66
112
|
|
|
67
|
-
→
|
|
113
|
+
→ 两个项目的索引同时缓存(最多 8 个项目,LRU 淘汰)
|
|
68
114
|
|
|
69
115
|
→ 查项目 A:
|
|
70
116
|
skimmer_get_component_outline({ project_path: "/work/project-a", file_path: "src/views/home.vue" })
|
|
@@ -73,40 +119,45 @@ npm run build
|
|
|
73
119
|
skimmer_find_symbol({ project_path: "/work/project-b", query: "handleSubmit" })
|
|
74
120
|
|
|
75
121
|
→ 省略 project_path 时,自动使用上次操作的项目:
|
|
76
|
-
skimmer_find_symbol({ query: "handleSubmit" })
|
|
122
|
+
skimmer_find_symbol({ query: "handleSubmit" })
|
|
77
123
|
|
|
78
|
-
→
|
|
79
|
-
skimmer_index_project({ project_path: "/work/project-a", force: true })
|
|
124
|
+
→ 文件修改后强制全量重建索引:
|
|
125
|
+
skimmer_index_project({ project_path: "/work/project-a", force: true })
|
|
80
126
|
```
|
|
81
127
|
|
|
82
128
|
### 数据库存放位置
|
|
83
129
|
|
|
84
|
-
| 情况 | 数据库位置
|
|
85
|
-
| ------------ |
|
|
86
|
-
| 项目目录可写 | `<项目根>/.
|
|
87
|
-
| 项目只读 | `~/.frontend-code-skimmer/databases
|
|
130
|
+
| 情况 | 数据库位置 |
|
|
131
|
+
| ------------ | ----------------------------------------------------------------- |
|
|
132
|
+
| 项目目录可写 | `<项目根>/.agent/skimmer_find_symbol/.skimmer-index.db` |
|
|
133
|
+
| 项目只读 | `~/.frontend-code-skimmer/databases/<hash>_<path尾部>.db` |
|
|
134
|
+
| 自定义路径 | `SKIMMER_DB` 环境变量指定的路径(仅单项目场景有效) |
|
|
88
135
|
|
|
89
136
|
## 环境变量(全部可选)
|
|
90
137
|
|
|
91
|
-
| 变量
|
|
92
|
-
|
|
|
93
|
-
| `
|
|
94
|
-
| `
|
|
95
|
-
| `
|
|
138
|
+
| 变量 | 说明 | 默认值 |
|
|
139
|
+
| -------------------------- | ------------------------------------------- | ------- |
|
|
140
|
+
| `SKIMMER_PROJECT` | 全局默认项目路径 | 无 |
|
|
141
|
+
| `SKIMMER_AUTO_INDEX` | 启动时自动索引默认项目(需配合上一项使用) | `false` |
|
|
142
|
+
| `SKIMMER_DB` | 自定义数据库路径(仅单项目场景有效) | 自动 |
|
|
143
|
+
| `SKIMMER_MAX_OPEN_PROJECTS`| 最大同时打开的项目数(LRU 淘汰) | `8` |
|
|
144
|
+
| `SKIMMER_DB_IDLE_MINUTES` | 项目空闲多久后自动关闭数据库连接(分钟) | `30` |
|
|
145
|
+
| `SKIMMER_DB_TTL_DAYS` | 全局缓存数据库的 TTL(天),过期自动清理 | `14` |
|
|
96
146
|
|
|
97
147
|
## 使用示例
|
|
98
148
|
|
|
99
149
|
### 1. 首次使用
|
|
100
150
|
|
|
101
151
|
```
|
|
102
|
-
调用 skimmer_index_project → 等待索引完成(50个文件约 2 秒)
|
|
152
|
+
调用 skimmer_index_project → 等待索引完成(50 个文件约 2 秒)
|
|
103
153
|
```
|
|
104
154
|
|
|
105
155
|
### 2. 快速了解组件
|
|
106
156
|
|
|
107
157
|
```
|
|
108
158
|
调用 skimmer_get_component_outline({ file_path: "src/views/apply/index.vue" })
|
|
109
|
-
→
|
|
159
|
+
→ 返回组件所有方法、状态、行为标签的骨架视图(7000 行 → 60 行)
|
|
160
|
+
→ 若文件在索引后被修改,自动输出 ⚠️ [索引已过期] 警告并提示重建
|
|
110
161
|
```
|
|
111
162
|
|
|
112
163
|
### 3. 查找拼写错误的函数
|
|
@@ -160,13 +211,23 @@ skimmer_get_call_graph({ symbol_name: "saveToCache", direction: "both" })
|
|
|
160
211
|
skimmer_get_blast_radius({ symbol_name: "saveToCache" })
|
|
161
212
|
```
|
|
162
213
|
|
|
214
|
+
### 8. 索引行号不准怎么办?
|
|
215
|
+
|
|
216
|
+
行号偏移的根本原因是索引未及时更新。排查步骤:
|
|
217
|
+
|
|
218
|
+
1. `skimmer_get_component_outline` 返回 `⚠️ [索引已过期]` → 立即执行第 2 步
|
|
219
|
+
2. `skimmer_get_code_slice` 返回 `⚠️ [行号偏移]` → 说明代码切片位置不对
|
|
220
|
+
3. 强制重建:`skimmer_index_project({ project_path: "...", force: true })`
|
|
221
|
+
|
|
222
|
+
> v0.2.7 起:增量索引同时校验 **mtime + 文件大小**,解决部分编辑器不更新 mtime 导致的漏检问题。
|
|
223
|
+
|
|
163
224
|
## 框架支持
|
|
164
225
|
|
|
165
|
-
| 框架 |
|
|
166
|
-
| ----- |
|
|
167
|
-
| Vue 2 | `vue-template-compiler`
|
|
168
|
-
| Vue 3 | `@vue/compiler-sfc`
|
|
169
|
-
| React |
|
|
226
|
+
| 框架 | SFC 分离 | AST 解析 | 支持的模式 |
|
|
227
|
+
| ----- | ------------------------ | -------------------- | ----------------------------------- |
|
|
228
|
+
| Vue 2 | `vue-template-compiler` | `@babel/parser` | Options API |
|
|
229
|
+
| Vue 3 | `@vue/compiler-sfc` | `@babel/parser` | `<script setup>` + Composition API |
|
|
230
|
+
| React | — | `@babel/parser` + JSX| 函数组件 + Hooks |
|
|
170
231
|
|
|
171
232
|
## 行为检测
|
|
172
233
|
|
package/dist/index.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import H from'path';import'url';import
|
|
3
|
-
`&&e++;return e}function
|
|
4
|
-
`),
|
|
5
|
-
`);for(let
|
|
6
|
-
`),
|
|
7
|
-
`).length;n.symbols.push({name:"<template>",category:"lifecycle",framework:"vue2",startLine:u,endLine:u+
|
|
8
|
-
`&&n++;return n}extractFromAST(e,t,n,r
|
|
9
|
-
`),i=null;j(e,
|
|
10
|
-
`),g),y=
|
|
11
|
-
`),u),f=this.extractParams(
|
|
12
|
-
`),u);if(
|
|
13
|
-
`),i=!!
|
|
14
|
-
`).length;n.symbols.push({name:"<template>",category:"lifecycle",framework:"vue3",startLine:
|
|
15
|
-
`),
|
|
16
|
-
`),
|
|
17
|
-
`),t(u)),f=this.extractParams(
|
|
18
|
-
`),t(
|
|
19
|
-
`),
|
|
20
|
-
`);this.extractFromAST(
|
|
21
|
-
`),o),
|
|
22
|
-
`),i),u=this.extractParams(e);if(
|
|
23
|
-
`),
|
|
24
|
-
`);}catch(o){process.stderr.write(`[Frontend-Code-Skimmer] \u66F4\u65B0\u5931\u8D25: ${
|
|
25
|
-
`);}};return t.on("add",n).on("change",n).on("unlink",
|
|
26
|
-
`);}),()=>t.close()}};});w();w();w();
|
|
2
|
+
import H from'path';import'url';import nn,{createHash}from'crypto';import {createRequire}from'module';import F from'fs';import Ln from'fast-glob';import {McpServer}from'@modelcontextprotocol/sdk/server/mcp.js';import {StdioServerTransport}from'@modelcontextprotocol/sdk/server/stdio.js';import an from'os';import rn from'better-sqlite3';import {z as z$1}from'zod';var en=Object.defineProperty;var J=(l,e)=>()=>(l&&(e=l(l=0)),e);var tn=(l,e)=>{for(var t in e)en(l,t,{get:e[t],enumerable:true});};var w=J(()=>{});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 Ae(l,e){let t=l.length,n=e.length,s=Array.from({length:t+1},(r,o)=>Array.from({length:n+1},(i,a)=>o===0?a:a===0?o:0));for(let r=1;r<=t;r++)for(let o=1;o<=n;o++)l[r-1]===e[o-1]?s[r][o]=s[r-1][o-1]:s[r][o]=1+Math.min(s[r-1][o],s[r][o-1],s[r-1][o-1]);return s[t][n]}function pt(l){return nn.createHash("md5").update(l).digest("hex")}function dt(l){if(!l)return 0;let e=1;for(let t=0;t<l.length;t++)l[t]===`
|
|
3
|
+
`&&e++;return e}function le(l,e){return l===e?`L${l}`:`L${l}-L${e}`}function xe(l,e){return H.relative(e,l).replace(/\\/g,"/")}function me(l,e){if(!l)return e;try{return JSON.parse(l)}catch{return e}}function V(l,e){let t=l.split(`
|
|
4
|
+
`),s=e-1-1;for(;s>=0&&t[s].trim()==="";)s--;if(s<0||!t[s].trim().endsWith("*/"))return;let r=s;for(;r>0&&!t[r].trim().startsWith("/**");)r--;if(t[r].trim().startsWith("/**"))return t.slice(r,s+1).map(o=>o.replace(/^\s*\*\s?/,"").replace(/\/\*\*/,"").replace(/\*\//,"").trim()).filter(o=>o.length>0).join(" ")}function ut(l,e){let t=l.toLowerCase(),n=e.toLowerCase();if(t===n)return 100;if(n.includes(t)||t.includes(n))return 85;let s=Ae(t,n),r=Math.max(t.length,n.length);if(r===0)return 100;let o=Math.max(0,100-s/r*100);return Math.round(o)}function ee(l){return l.startsWith("use")&&l.length>3&&/[A-Z]/.test(l[3])}function ft(l,e,t){if(t===0||t>3)return;let n=A(l).split(" "),s=A(e).split(" ");for(let r of n)for(let o of s){let i=Ae(r,o);if(i>0&&i<=3&&r!==o)return `"${r}" \u53EF\u80FD\u662F "${o}" \u7684\u62FC\u5199\u9519\u8BEF (\u7F16\u8F91\u8DDD\u79BB=${i})`}}var G=J(()=>{w();});var Ke,Ve,mt,ze,Xe,gt,ht,yt,Je,Ge,Ye,bt,$e,Et,Nt,_t,Y=J(()=>{w();Ke=["**/node_modules/**","**/dist/**","**/build/**","**/.git/**","**/coverage/**","**/.nuxt/**","**/.next/**","**/__tests__/**","**/*.test.*","**/*.spec.*","**/*.min.js"],Ve=["**/*.vue","**/*.js","**/*.jsx","**/*.ts","**/*.tsx"],mt={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"]}},ze=["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeDestroy","destroyed","activated","deactivated","errorCaptured"],Xe=["onBeforeMount","onMounted","onBeforeUpdate","onUpdated","onBeforeUnmount","onUnmounted","onActivated","onDeactivated","onErrorCaptured","onRenderTracked","onRenderTriggered","onServerPrefetch"],gt=["ref","reactive","shallowRef","shallowReactive","readonly"],ht=["computed"],yt=["watch","watchEffect","watchPostEffect","watchSyncEffect"],Je=["useState","useReducer","useRef","useImperativeHandle"],Ge=["useMemo","useCallback"],Ye=["useEffect","useLayoutEffect","useInsertionEffect"],bt=["useContext","useDebugValue","useDeferredValue","useId","useSyncExternalStore","useTransition"],$e=".skimmer-index.db",Et=30,Nt=4,_t=300;});function B(l,e,t,n=false){let s=[];return j(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 a=fn(o,e);a&&s.push(a);}if(o.type==="MemberExpression"){let i=mn(o);i&&s.push(i);}}),Nn(s)}function fn(l,e,t){let n=l.callee;if(!n)return null;let s=Le(l);if(n.type==="MemberExpression"){let r=gn(n);if(!r)return null;let{apiName:o,operation:i}=r,a=l.arguments,c=z(a?.[0]),u=bn(o);return u?{symbolName:e,category:u,apiName:o,operation:i,detail:c,line:s}:o==="this"&&Re(i)?{symbolName:e,category:"network",apiName:`this.${i}`,operation:"wrapped_call",detail:c||z(a?.[1]),line:s}:St(i)&&En(a)?{symbolName:e,category:"network",apiName:o,operation:i,detail:c||z(a?.[1]),line:s}:Re(o)||Re(`${o}.${i}`)?{symbolName:e,category:"network",apiName:o,operation:St(i)?i:"wrapped_call",detail:c||z(a?.[1]),line:s}:null}if(n.type==="Identifier"){let r=n.name,o=hn(r),i=l.arguments,a=z(i?.[0]);return o?{symbolName:e,category:o.category,apiName:r,operation:o.operation,detail:a,line:s}:Re(r)?{symbolName:e,category:"network",apiName:r,operation:"wrapped_call",detail:a||z(i?.[1]),line:s}:null}return null}function mn(l,e,t){let n=l.object,s=l.property;if(!n||!s||n.type!=="MemberExpression"&&n.type!=="ThisExpression"&&n.type!=="Identifier")return null;let r=yn(n);if(!r)return null;s.type==="Identifier"?s.name:"";if(r==="this"||r===""){n.type==="MemberExpression"?n.property?.name:"";return null}return null}function gn(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 s=e.property?.name;if(s)return {apiName:s,operation:n}}return e.type==="Identifier"?{apiName:e.name,operation:n}:e.type==="ThisExpression"?{apiName:"this",operation:n}:null}function hn(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 Le(l){return l.loc?.start?.line??0}function yn(l){return l.type==="Identifier"?l.name:l.type==="ThisExpression"?"this":null}function bn(l){if(l==="this")return null;for(let[e,t]of Object.entries(mt))if(l in t)return e;return null}function z(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||[],s=[];for(let o=0;o<t.length;o++){let i=t[o].value?.cooked||"";if(i&&s.push(i),o<n.length){let a=ve(n[o])||"expr";s.push(`\${${a}}`);}}return s.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 s of t){let r=s.key,o=s.value;if(!r||!o)continue;let i=r.type==="Identifier"?String(r.name):r.type==="Literal"?String(r.value):"";if(!n.includes(i))continue;let a=z(o);if(a)return `${i}:${a}`}return "{...}"}}}function ve(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=ve(l.object)||"obj",s=l.property,r=s?.type==="Identifier"?String(s.name):ve(s)||"prop";return l.computed?`${n}[${r}]`:`${n}.${r}`}if(l.type==="CallExpression")return `${ve(l.callee)||"fn"}(...)`;if(l.type==="TemplateLiteral")return z(l);let t=z(l);return t?.startsWith("[\u53D8\u91CF: ")?t.replace(/^\[变量: /,"").replace(/\]$/,""):t}function Re(l){return /request|api|http|fetch|ajax|akscommonhandle|commonhandle/i.test(l)}function St(l){return ["get","post","put","delete","patch","request"].includes(l.toLowerCase())}function En(l,e){if(!l||l.length===0)return false;for(let t of l.slice(0,2)){let n=z(t);if(n&&(/https?:\/\//i.test(n)||n.includes("/")||/gw\d?\/|\/m\/|\/api\//i.test(n)))return true}return false}function Nn(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 we(l,e,t){let n=[];return j(l,s=>{if(s.type==="CallExpression"&&s.callee?.type==="MemberExpression"){let r=s.callee,o=r.object,i=r.property;if(o.type==="ThisExpression"&&i.type==="Identifier"){let a=i.name;if(!a.startsWith("$")&&a!==e){let c=s.arguments,u=At(c);n.push({calleeName:a,line:Le(s),args:u});}}}}),n}function Z(l,e,t,n=false){let s=[];return j(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&&!_n(i)){let a=o.arguments,c=At(a);s.push({calleeName:i,line:Le(o),args:c});}}}),s}function _n(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 At(l,e){if(!l||l.length===0)return;let t=l.slice(0,3).map(n=>z(n)).filter(n=>!!n);return t.length>0?t.join(", "):void 0}function j(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 s of n)s&&typeof s=="object"&&s.type&&j(s,e);else n&&typeof n=="object"&&n.type&&j(n,e);}}function Ce(l,e){let t=[],n=new Set,s=l.split(`
|
|
5
|
+
`);for(let r=0;r<s.length;r++){let o=/(?:@|v-on:)[a-z][a-z0-9-]*(?:\.[a-z-]+)*="([^"]+)"/g,i;for(;(i=o.exec(s[r]))!==null;){let c=i[1].trim().match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(?:\([^)]*\))?$/);if(!c)continue;let u=c[1];u.startsWith("$")||n.has(u)||(n.add(u),t.push({calleeName:u,line:e+r}));}}return t}function xt(l,e){let t=[],n=new Set;return j(l,s=>{if(s.type!=="JSXAttribute")return;let r=s.name,o=s.value;if(!r||!o)return;let i=r.type==="JSXIdentifier"?String(r.name):"";if(!/^on[A-Z]/.test(i)||o.type!=="JSXExpressionContainer")return;let a=o.expression;if(!a)return;let c;if(a.type==="Identifier")c=a.name;else if(a.type==="MemberExpression"){let u=a.property?.name;u&&!/^\$/.test(u)&&(c=u);}!c||n.has(c)||(n.add(c),t.push({calleeName:c,line:Le(s)}));}),t}var Ie=J(()=>{w();Y();});var $t,pe,Ze=J(()=>{w();Y();Ie();G();$t=createRequire(import.meta.url),pe=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 r=$t("vue-template-compiler").parseComponent(t);if(!r.script?.content)return n;let o=r.script.content,i=this.getScriptStartLine(t,r.script.start),a=t.split(`
|
|
6
|
+
`),c;try{c=$t("@babel/parser").parse(o,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy"],errorRecovery:!0});}catch(u){return n.errors?.push(`AST \u89E3\u6790\u5931\u8D25: ${String(u)}`),n}if(this.extractFromAST(c.program,o,a,i,n),r.template?.content){let u=this.getScriptStartLine(t,r.template.start),p=Ce(r.template.content,u);if(p.length>0){let d=r.template.content.split(`
|
|
7
|
+
`).length;n.symbols.push({name:"<template>",category:"lifecycle",framework:"vue2",startLine:u,endLine:u+d-1,camelWords:"template"});for(let f of p)n.relations.push({callerName:"<template>",callerLine:u,calleeName:f.calleeName,callType:"template_event",line:f.line});}}}catch(s){n.errors?.push(`\u89E3\u6790\u5931\u8D25: ${String(s)}`);}return n}getScriptStartLine(e,t){let n=1;for(let s=0;s<t&&s<e.length;s++)e[s]===`
|
|
8
|
+
`&&n++;return n}extractFromAST(e,t,n,s,r){let o=t.split(`
|
|
9
|
+
`),i=null;j(e,p=>{if(p.type==="ExportDefaultDeclaration"){let d=p.declaration;if(d?.type==="ObjectExpression")i=d;else if(d?.type==="CallExpression"){let f=d.arguments;f&&f.length>0&&f[0].type==="ObjectExpression"&&(i=f[0]);}else if(d?.type==="Identifier"){let f=d.name;j(e,m=>{if(m.type==="VariableDeclarator"&&m.id?.name===f){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 c=false;if(!i&&(j(e,p=>{p.type==="ExportDefaultDeclaration"&&p.declaration?.type==="ClassDeclaration"&&(c=true,this.extractFromClassComponent(p.declaration,t,n,s,r));}),!c)){let p=null,d=0,f=["data","methods","computed","props","watch","components","created","mounted","mixins"];j(e,m=>{if(m.type==="ObjectExpression"){let g=m.properties||[],E=0;for(let h of g){let y=this.getPropKey(h);y&&f.includes(y)&&E++;}E>d&&(d=E,p=m);}}),d>=2&&p&&(i=p);}if(!i)return;let u=i.properties;for(let p of u||[]){let d=this.getPropKey(p);if(!d)continue;let f=p.type==="ObjectMethod"?p:p.value;if(!f)continue;let m=g=>g+s-1;switch(d){case "name":f?.type==="Literal"&&(String(f.value));break;case "data":this.extractData(f,o,m,r);break;case "props":this.extractProps(f,o,m,r);break;case "computed":this.extractComputedOrMethods(f,"computed",o,m,n,r);break;case "methods":this.extractComputedOrMethods(f,"method",o,m,n,r);break;case "watch":this.extractWatch(f,o,m,r);break;case "filters":this.extractComputedOrMethods(f,"filter",o,m,n,r);break;case "components":this.extractComponents(f,r);break;case "mixins":this.extractMixins(f,r);break;default:if(ze.includes(d)){let g=m(this.getStartLine(p)),E=m(this.getEndLine(p)),h=V(n.join(`
|
|
10
|
+
`),g),y=r.symbols.length;r.symbols.push({name:d,category:"lifecycle",framework:"vue2",startLine:g,endLine:E,jsdoc:h,camelWords:A(d)});let S=B(f,d);r.behaviors.push(...S);let b=we(f,d);for(let T of b){if(T.args){let v=String(T.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");r.symbols[y].camelWords+=` ${A(v)} ${v}`;}r.relations.push({callerName:d,callerLine:g,calleeName:T.calleeName,callType:"this_method",line:m(T.line),args:T.args});}}break}}}extractData(e,t,n,s){let r=null;if(e.type==="FunctionExpression"||e.type==="ArrowFunctionExpression"||e.type==="ObjectMethod"?j(e.body,o=>{o.type==="ReturnStatement"&&o.argument?.type==="ObjectExpression"&&(r=o.argument);}):e.type==="ObjectExpression"&&(r=e),!!r)for(let o of r.properties){let i=this.getPropKey(o);if(!i)continue;let a=n(this.getStartLine(o)),c=n(this.getEndLine(o)),u=this.getLiteralValue(o.value);s.symbols.push({name:i,category:"state",framework:"vue2",startLine:a,endLine:c,defaultValue:u,camelWords:A(i)});}}extractProps(e,t,n,s){if(e.type==="ArrayExpression"){for(let r of e.elements||[])if(r?.type==="Literal"){let o=String(r.value);s.symbols.push({name:o,category:"prop",framework:"vue2",startLine:n(this.getStartLine(r)),endLine:n(this.getEndLine(r)),camelWords:A(o)});}}else if(e.type==="ObjectExpression")for(let r of e.properties||[]){let o=this.getPropKey(r);if(!o)continue;let i=n(this.getStartLine(r)),a=n(this.getEndLine(r)),c;if(r.value?.type==="ObjectExpression"){let u=r.value.properties?.find(p=>this.getPropKey(p)==="default");u&&(c=this.getLiteralValue(u.value));}s.symbols.push({name:o,category:"prop",framework:"vue2",startLine:i,endLine:a,defaultValue:c,camelWords:A(o)});}}extractComputedOrMethods(e,t,n,s,r,o){if(e.type==="ObjectExpression")for(let i of e.properties||[]){let a=this.getPropKey(i);if(!a)continue;let c=i.type==="ObjectMethod"?i:i.value;if(!c)continue;let u=s(this.getStartLine(i)),p=s(this.getEndLine(i)),d=V(r.join(`
|
|
11
|
+
`),u),f=this.extractParams(c),m=c.async===true,g=f?`${a}(${f.join(", ")})`:a;if(o.symbols.push({name:a,category:t,framework:"vue2",startLine:u,endLine:p,signature:g,params:f,isAsync:m,jsdoc:d,camelWords:A(a)}),t==="method"&&c){let E=B(c,a);o.behaviors.push(...E);let h=we(c,a);for(let y of h){if(y.args){let S=String(y.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");o.symbols[o.symbols.length-1].camelWords+=` ${A(S)} ${S}`;}o.relations.push({callerName:a,callerLine:u,calleeName:y.calleeName,callType:"this_method",line:s(y.line),args:y.args});}}}}extractWatch(e,t,n,s){if(e.type==="ObjectExpression")for(let r of e.properties||[]){let o=this.getPropKey(r);if(!o)continue;let i=n(this.getStartLine(r)),a=n(this.getEndLine(r));s.symbols.push({name:o,category:"effect",framework:"vue2",startLine:i,endLine:a,camelWords:A(o)});}}extractComponents(e,t){if(e.type==="ObjectExpression")for(let n of e.properties||[]){let s=this.getPropKey(n);s&&t.symbols.push({name:s,category:"component",framework:"vue2",startLine:this.getStartLine(n),endLine:this.getEndLine(n),camelWords:A(s)});}}extractMixins(e,t){if(e.type==="ArrayExpression")for(let n of e.elements||[]){let s=n?.type==="Identifier"?n.name:null;s&&t.symbols.push({name:s,category:"mixin",framework:"vue2",startLine:this.getStartLine(n),endLine:this.getEndLine(n),camelWords:A(s)});}}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,s,r){let o=a=>a+s-1,i=e.body;if(!(!i||i.type!=="ClassBody"))for(let a of i.body||[]){let c=this.getPropKey(a);if(!c)continue;let u=o(this.getStartLine(a)),p=o(this.getEndLine(a)),d=V(n.join(`
|
|
12
|
+
`),u);if(a.type==="ClassMethod"){let m=ze.includes(c)?"lifecycle":"method",g=this.extractParams(a),E=a.async===true,h=g?`${c}(${g.join(", ")})`:c;r.symbols.push({name:c,category:m,framework:"vue2",startLine:u,endLine:p,signature:h,params:g,isAsync:E,jsdoc:d,camelWords:A(c)});let y=B(a,c);r.behaviors.push(...y);let S=we(a,c);for(let b of S){if(b.args){let T=String(b.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");r.symbols[r.symbols.length-1].camelWords+=` ${A(T)} ${T}`;}r.relations.push({callerName:c,callerLine:u,calleeName:b.calleeName,callType:"this_method",line:o(b.line),args:b.args});}}else if(a.type==="ClassProperty"){let f=(a.decorators||[]).some(g=>g.expression?.callee?.name==="Prop"),m=this.getLiteralValue(a.value);r.symbols.push({name:c,category:f?"prop":"state",framework:"vue2",startLine:u,endLine:p,defaultValue:m,camelWords:A(c)});}}}};});var Qe,Pe,Tt=J(()=>{w();Y();Ie();G();Ze();Qe=createRequire(import.meta.url),Pe=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:s}=Qe("@vue/compiler-sfc"),{descriptor:r}=s(t),o=t.split(`
|
|
13
|
+
`),i=!!r.scriptSetup,a=!!r.script;if(i){let c=r.scriptSetup,u=c.loc.start.line;this.parseSetupContent(c.content,u,o,n);}else if(a){let c=r.script,u=c.loc.start.line;this.parseScriptContent(c.content,u,o,n)||this.populateFromOptionsApiFallback(e,t,n);}if(r.template?.content){let c=r.template.loc.start.line,u=Ce(r.template.content,c);if(u.length>0){let p=r.template.content.split(`
|
|
14
|
+
`).length;n.symbols.push({name:"<template>",category:"lifecycle",framework:"vue3",startLine:c,endLine:c+p-1,camelWords:"template"});for(let d of u)n.relations.push({callerName:"<template>",callerLine:c,calleeName:d.calleeName,callType:"template_event",line:d.line});}}}catch(s){n.errors?.push(`Vue3 \u89E3\u6790\u5931\u8D25: ${String(s)}`);}return n}parseSetupContent(e,t,n,s){let r;try{r=Qe("@babel/parser").parse(e,{sourceType:"module",plugins:["typescript","jsx","decorators-legacy"],errorRecovery:!0});}catch(c){s.errors?.push(`AST \u89E3\u6790\u5931\u8D25: ${String(c)}`);return}let o=c=>c+t-1,i=e.split(`
|
|
15
|
+
`),a=r.program.body;for(let c of a||[])this.processTopLevelStatement(c,o,n,i,s);}parseScriptContent(e,t,n,s){let r;try{r=Qe("@babel/parser").parse(e,{sourceType:"module",plugins:["typescript","jsx","decorators-legacy"],errorRecovery:!0});}catch(c){return s.errors?.push(`AST \u89E3\u6790\u5931\u8D25: ${String(c)}`),false}let o=c=>c+t-1,i=e.split(`
|
|
16
|
+
`),a=false;return j(r.program,c=>{if(c.type==="ExportDefaultDeclaration"&&c.declaration?.type==="ObjectExpression"){let u=c.declaration.properties?.find(p=>this.getPropKey(p)==="setup");if(u){a=true;let p=u.type==="ObjectMethod"?u:u.value;if(!p)return;let d=p.body;if(d?.type==="BlockStatement"){let f=d.body;for(let m of f||[])this.processTopLevelStatement(m,o,n,i,s);}}}}),a||j(r.program,c=>{if(!a&&c.type==="ObjectExpression"){let p=(c.properties||[]).find(d=>this.getPropKey(d)==="setup");if(p){a=true;let d=p.type==="ObjectMethod"?p:p.value;if(!d)return;let f=d.body;if(f?.type==="BlockStatement"){let m=f.body;for(let g of m||[])this.processTopLevelStatement(g,o,n,i,s);}}}}),a}processTopLevelStatement(e,t,n,s,r){let o=i=>{let a=i?.loc;return {start:a?.start?.line??1,end:a?.end?.line??1}};if(e.type==="VariableDeclaration")for(let i of e.declarations||[]){if(i.id?.type!=="Identifier"&&i.id?.type!=="ArrayPattern")continue;let a=i.init;if(a&&i.id.type==="Identifier"){let c=i.id.name;if(a.type==="ArrowFunctionExpression"||a.type==="FunctionExpression"){let{start:u,end:p}=o(e),d=V(n.join(`
|
|
17
|
+
`),t(u)),f=this.extractParams(a),m=r.symbols.length;if(r.symbols.push({name:c,category:"method",framework:"vue3",startLine:t(u),endLine:t(p),signature:`${c}(${(f||[]).join(", ")})`,params:f,isAsync:a.async===true,jsdoc:d,camelWords:A(c)}),a.body){let g=B(a.body,c);r.behaviors.push(...g);let E=Z(a.body,c);for(let h of E){if(h.args){let y=String(h.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");r.symbols[m].camelWords+=` ${A(y)} ${y}`;}r.relations.push({callerName:c,callerLine:t(u),calleeName:h.calleeName,callType:"direct_call",line:t(h.line),args:h.args});}}}else {let u=this.classifyVue3Declaration(c,a,t,o(e),n);u&&r.symbols.push(u);}}}if(e.type==="FunctionDeclaration"&&e.id?.type==="Identifier"){let i=e.id.name,{start:a,end:c}=o(e),u=V(n.join(`
|
|
18
|
+
`),t(a)),p=this.extractParams(e),d=Xe.includes(i);if(r.symbols.push({name:i,category:d?"lifecycle":ee(i)?"hook":"method",framework:"vue3",startLine:t(a),endLine:t(c),signature:`${i}(${(p||[]).join(", ")})`,params:p,isAsync:e.async===true,jsdoc:u,camelWords:A(i)}),e.body){let f=B(e.body,i);r.behaviors.push(...f);let m=Z(e.body,i);for(let g of m){if(g.args){let E=String(g.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");r.symbols[r.symbols.length-1].camelWords+=` ${A(E)} ${E}`;}r.relations.push({callerName:i,callerLine:t(a),calleeName:g.calleeName,callType:"direct_call",line:t(g.line),args:g.args});}}}if(e.type==="ExpressionStatement"&&e.expression?.type==="CallExpression"){let a=e.expression.callee;if(a?.type==="Identifier"){let c=a.name;if(["defineProps","defineEmits","defineExpose"].includes(c)){let{start:u,end:p}=o(e);r.symbols.push({name:c,category:c==="defineProps"?"prop":c==="defineEmits"?"emit":"export",framework:"vue3",startLine:t(u),endLine:t(p),camelWords:A(c)});}}}if(e.type==="ExpressionStatement"&&e.expression?.type==="CallExpression"){let i=e.expression,a=i.callee;if(a?.type==="Identifier"){let c=a.name;if(Xe.includes(c)){let{start:u,end:p}=o(e);r.symbols.push({name:c,category:"lifecycle",framework:"vue3",startLine:t(u),endLine:t(p),camelWords:A(c)});let d=i.arguments;if(d?.[0]){let f=B(d[0],c);r.behaviors.push(...f);let m=Z(d[0],c);for(let g of m){if(g.args){let E=String(g.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");r.symbols[r.symbols.length-1].camelWords+=` ${A(E)} ${E}`;}r.relations.push({callerName:c,callerLine:t(u),calleeName:g.calleeName,callType:"direct_call",line:t(g.line),args:g.args});}}}}}}classifyVue3Declaration(e,t,n,s,r){if(t.type!=="CallExpression")return null;let o=t.callee;if(o?.type!=="Identifier")return null;let i=o.name,a=n(s.start),c=n(s.end),u=V(r.join(`
|
|
19
|
+
`),a);if(gt.includes(i)){let p=t.arguments,d=p?.[0]?this.getLiteralValue(p[0]):void 0;return {name:e,category:"state",framework:"vue3",startLine:a,endLine:c,defaultValue:d,jsdoc:u,camelWords:A(e)}}return ht.includes(i)?{name:e,category:"computed",framework:"vue3",startLine:a,endLine:c,jsdoc:u,camelWords:A(e)}:yt.includes(i)?{name:e,category:"effect",framework:"vue3",startLine:a,endLine:c,camelWords:A(e)}:i==="provide"||i==="inject"?{name:e,category:"provide",framework:"vue3",startLine:a,endLine:c,camelWords:A(e)}:ee(i)?{name:e,category:"hook",framework:"vue3",startLine:a,endLine:c,jsdoc:u,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 s=new pe().parse(e,t);n.symbols=s.symbols.map(r=>({...r,framework:"vue3"})),n.relations=s.relations,n.behaviors=s.behaviors,n.errors=[...n.errors||[],...s.errors||[]];}};});var $n,Tn,ge,kt=J(()=>{w();Y();Ie();G();$n=createRequire(import.meta.url),Tn=[...Je,...Ge,...Ye,...bt],ge=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 r=$n("@babel/parser").parse(t,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy"],errorRecovery:!0}),o=t.split(`
|
|
20
|
+
`);this.extractFromAST(r.program?r.program:r,o,n);}catch(s){n.errors?.push(`React \u89E3\u6790\u5931\u8D25: ${String(s)}`);}return n}extractFromAST(e,t,n){let s=e.body;for(let r of s||[]){if(r.type==="FunctionDeclaration"||r.type==="ExportDefaultDeclaration"&&r.declaration?.type==="FunctionDeclaration"||r.type==="ExportNamedDeclaration"&&r.declaration?.type==="FunctionDeclaration"){let o=r.type==="FunctionDeclaration"?r:r.declaration;o&&o.id?.type==="Identifier"&&this.processFunction(o,t,n);}if(r.type==="VariableDeclaration"||r.type==="ExportNamedDeclaration"&&r.declaration?.type==="VariableDeclaration"||r.type==="ExportDefaultDeclaration"&&r.declaration?.type==="VariableDeclaration"){let o=r.type==="VariableDeclaration"?r:r.declaration;if(o)for(let i of o.declarations||[]){let a=i.init;if(a&&(a.type==="ArrowFunctionExpression"||a.type==="FunctionExpression")&&i.id?.type==="Identifier"){let c={...a,id:i.id,loc:{start:o.loc?.start??a.loc?.start,end:a.loc?.end}};this.processFunction(c,t,n);}}}}}processFunction(e,t,n){let s=e.id?.name;if(!s)return;let r=e.loc,o=r?.start?.line??1,i=r?.end?.line??1,a=ee(s),c=!a&&/^[A-Z]/.test(s),u=V(t.join(`
|
|
21
|
+
`),o),p=this.extractParams(e),d=this.buildSymbolKey(s,o,i);n.symbols.push({name:s,category:a?"hook":c?"component":"function",framework:"react",startLine:o,endLine:i,internalKey:d,signature:`${s}(${(p||[]).join(", ")})`,params:p,isAsync:e.async===true,jsdoc:u,parentComponent:c?s:void 0,camelWords:A(s)});let f=e.body;if(f?.type!=="BlockStatement")return;let m=f.body;for(let y of m||[])this.processComponentStatement(y,s,t,n);let g=B(f,s,t,true);n.behaviors.push(...g);let E=Z(f,s,t,true);for(let y of E){let S=n.symbols.findIndex(b=>b.name===s&&b.startLine===o);if(y.args&&S!==-1){let b=String(y.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");n.symbols[S].camelWords+=` ${A(b)} ${b}`;}n.relations.push({callerName:s,callerLine:o,callerKey:d,calleeName:y.calleeName,callType:"direct_call",line:y.line,args:y.args});}let h=xt(f);for(let y of h)n.relations.push({callerName:s,callerLine:o,callerKey:d,calleeName:y.calleeName,callType:"jsx_event",line:y.line});}processComponentStatement(e,t,n,s){let r=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 a=i.callee;if(a?.type!=="Identifier")continue;let c=a.name,{start:u,end:p}=r(e),d=u,f=p;if(Je.includes(c)&&c!=="useRef"){if(o.id?.type==="ArrayPattern"){let m=o.id.elements,g=m[0]?.name,E=m[1]?.name;if(g){let h=i.arguments;s.symbols.push({name:g,category:"state",framework:"react",startLine:d,endLine:f,internalKey:this.buildSymbolKey(g,d,f,t),stateSetterName:E,defaultValue:this.getLiteralValue(h?.[0]),parentComponent:t,camelWords:A(g)});}}else if(o.id?.type==="Identifier"){let m=o.id.name;s.symbols.push({name:m,category:"state",framework:"react",startLine:d,endLine:f,internalKey:this.buildSymbolKey(m,d,f,t),parentComponent:t,camelWords:A(m)});}}if(c==="useRef"&&o.id?.type==="Identifier"){let m=o.id.name,g=i.arguments;s.symbols.push({name:m,category:"state",framework:"react",startLine:d,endLine:f,internalKey:this.buildSymbolKey(m,d,f,t),defaultValue:this.getLiteralValue(g?.[0]),parentComponent:t,camelWords:A(m)});}if(Ge.includes(c)&&o.id?.type==="Identifier"){let m=o.id.name,E=i.arguments?.[1],h=this.extractDepsArray(E);s.symbols.push({name:m,category:"computed",framework:"react",startLine:d,endLine:f,internalKey:this.buildSymbolKey(m,d,f,t),hookDeps:h,parentComponent:t,camelWords:A(m)});}if(ee(c)&&!Tn.includes(c)){let m=o.id?.type==="Identifier"?o.id.name:o.id?.type==="ObjectPattern"?"{...}":"?";s.symbols.push({name:m,category:"hook",framework:"react",startLine:d,endLine:f,internalKey:this.buildSymbolKey(m,d,f,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 a=i.name;if(Ye.includes(a)){let{start:c,end:u}=r(e),p=o.arguments,d=p?.[1],f=this.extractDepsArray(d),m=this.buildSymbolKey(a,c,u,t),g=`${t}.${a}`;if(s.symbols.push({name:a,category:"effect",framework:"react",startLine:c,endLine:u,internalKey:m,hookDeps:f,parentComponent:t,camelWords:A(a)}),p?.[0]){let E=B(p[0],g,n,true).map(y=>({...y,symbolKey:m}));s.behaviors.push(...E);let h=Z(p[0],g,n,true);for(let y of h){let S=s.symbols.findIndex(b=>b.name===a&&b.startLine===c);if(y.args&&S!==-1){let b=String(y.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[S].camelWords+=` ${A(b)} ${b}`;}s.relations.push({callerName:g,callerLine:c,callerKey:m,calleeName:y.calleeName,callType:"direct_call",line:y.line,args:y.args});}}}}}if(e.type==="FunctionDeclaration"&&e.id?.type==="Identifier"){let o=e.id.name;if(!ee(o)){let{start:i,end:a}=r(e),c=V(n.join(`
|
|
22
|
+
`),i),u=this.extractParams(e);if(s.symbols.push({name:o,category:"method",framework:"react",startLine:i,endLine:a,internalKey:this.buildSymbolKey(o,i,a,t),signature:`${o}(${(u||[]).join(", ")})`,params:u,isAsync:e.async===true,jsdoc:c,parentComponent:t,camelWords:A(o)}),e.body){let p=B(e.body,o,n,true);s.behaviors.push(...p);let d=Z(e.body,o,n,true);for(let f of d){let m=s.symbols.findIndex(g=>g.name===o&&g.startLine===i);if(f.args&&m!==-1){let g=String(f.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[m].camelWords+=` ${A(g)} ${g}`;}s.relations.push({callerName:o,callerLine:i,callerKey:this.buildSymbolKey(o,i,a,t),calleeName:f.calleeName,callType:"direct_call",line:f.line,args:f.args});}}}}if(e.type==="VariableDeclaration")for(let o of e.declarations||[]){let i=o.init;if(!i)continue;let a=i.type==="ArrowFunctionExpression"||i.type==="FunctionExpression";if(!a||o.id?.type!=="Identifier")continue;let c=o.id.name,u=i.type==="CallExpression"?i.callee:null;if(u?.type==="Identifier"&&ee(u.name))continue;if(i.type==="CallExpression"&&i.callee?.name==="useCallback"){let h=i.arguments?.[1],y=this.extractDepsArray(h),{start:S,end:b}=r(e);s.symbols.push({name:c,category:"computed",framework:"react",startLine:S,endLine:b,internalKey:this.buildSymbolKey(c,S,b,t),hookDeps:y,parentComponent:t,camelWords:A(c)});continue}if(!a)continue;let{start:d,end:f}=r(e),m=V(n.join(`
|
|
23
|
+
`),d),g=this.extractParams(i);if(s.symbols.push({name:c,category:"method",framework:"react",startLine:d,endLine:f,internalKey:this.buildSymbolKey(c,d,f,t),signature:`${c}(${(g||[]).join(", ")})`,params:g,isAsync:i.async===true,jsdoc:m,parentComponent:t,camelWords:A(c)}),i.body){let E=B(i.body,c,n,true);s.behaviors.push(...E);let h=Z(i.body,c,n,true);for(let y of h){let S=s.symbols.findIndex(b=>b.name===c&&b.startLine===d);if(y.args&&S!==-1){let b=String(y.args).replace(/[^a-zA-Z0-9_\u4e00-\u9fa5]/g," ");s.symbols[S].camelWords+=` ${A(b)} ${b}`;}s.relations.push({callerName:c,callerLine:d,callerKey:this.buildSymbolKey(c,d,f,t),calleeName:y.calleeName,callType:"direct_call",line:y.line,args:y.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,s){return `${s||"root"}:${e}:${t}:${n}`}};});function Rt(l,e){for(let t of kn)if(t.canParse(l,e)){let n=t.parse(l,e);return Rn(n),n}return {framework:"js",filePath:l,symbols:[],relations:[],behaviors:[],errors:[`\u6CA1\u6709\u627E\u5230\u9002\u5408\u7684\u89E3\u6790\u5668: ${l}`]}}function Rn(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(s=>s.category==="network").map(s=>s.symbolName));if(t.size===0)return;let n=new Set(l.behaviors.map(s=>`${s.symbolName}:${s.category}:${s.apiName}:${s.operation}:${s.line}`));for(let s of l.relations){if(!t.has(s.calleeName)||t.has(s.callerName)||e.has(s.callerName))continue;let r={symbolName:s.callerName,symbolKey:s.callerKey,category:"network",apiName:"wrapped_network",operation:s.calleeName,detail:s.args,line:s.line},o=`${r.symbolName}:${r.category}:${r.apiName}:${r.operation}:${r.line}`;n.has(o)||(n.add(o),l.behaviors.push(r));}}var et,kn,vt=J(()=>{w();Ze();Tt();kt();et=class extends ge{name="JsTsFallbackParser";canParse(e){let t=e.split(".").pop()?.toLowerCase();return ["js","ts","jsx","tsx"].includes(t||"")}parse(e,t){let n=super.parse(e,t);return n.framework=e.endsWith(".ts")||e.endsWith(".tsx")?"ts":"js",n}},kn=[new Pe,new pe,new ge,new et];});var wt={};tn(wt,{Indexer:()=>he});var he,tt=J(()=>{w();vt();G();Y();he=class{projectRoot;db;constructor(e,t){this.projectRoot=e,this.db=t;}async indexProject(e){let t=Date.now(),n=e?.include||[...Ve],s=e?.exclude||[...Ke],r=e?.force||false,o=await Ln(n,{cwd:this.projectRoot,ignore:s,absolute:true,onlyFiles:true}),i={totalFiles:o.length,indexedFiles:0,skippedFiles:0,totalSymbols:0,durationMs:0,errors:[]};for(let a=0;a<o.length;a++){let c=o[a],u=xe(c,this.projectRoot);e?.onProgress?.(a+1,o.length,u);try{let p=await this.indexFile(c,u,r);p.skipped?i.skippedFiles++:(i.indexedFiles++,i.totalSymbols+=p.symbolCount,p.errors?.length&&i.errors.push(...p.errors.map(d=>({file:u,error:d}))));}catch(p){i.errors.push({file:u,error:String(p)});}}return i.durationMs=Date.now()-t,i}async indexFile(e,t,n=false){let s=0,r=0,o=null;if(!n){try{let d=F.statSync(e);s=d.mtimeMs,r=d.size;}catch{}if(o=this.db.getFileMeta(t),o&&o.mtime>0&&o.mtime===s&&!(o.fileSize>0&&o.fileSize!==r))return {skipped:true,symbolCount:0}}let i=F.readFileSync(e,"utf-8"),a=pt(i);if(!n&&o&&o.hash===a)return s>0&&o.mtime!==s&&this.db.updateFileMtime(t,s),{skipped:true,symbolCount:0};let c=dt(i),u=Buffer.byteLength(i,"utf-8"),p=Rt(e,i);return this.db.saveParseResult(p,e,t,a,u,c,s),{skipped:false,symbolCount:p.symbols.length,errors:p.errors}}removeFile(e){this.db.deleteFile(e);}async startWatcher(){let{default:e}=await import('chokidar'),t=e.watch([...Ve].map(s=>H.posix.join(this.projectRoot,s)),{cwd:this.projectRoot,ignored:[...Ke],persistent:true,ignoreInitial:true,awaitWriteFinish:{stabilityThreshold:_t}}),n=async s=>{let r=xe(s,this.projectRoot);try{await this.indexFile(s,r),process.stderr.write(`[Frontend-Code-Skimmer] \u5DF2\u66F4\u65B0\u7D22\u5F15: ${r}
|
|
24
|
+
`);}catch(o){process.stderr.write(`[Frontend-Code-Skimmer] \u66F4\u65B0\u5931\u8D25: ${r} - ${String(o)}
|
|
25
|
+
`);}};return t.on("add",n).on("change",n).on("unlink",s=>{let r=xe(s,this.projectRoot);this.removeFile(r),process.stderr.write(`[Frontend-Code-Skimmer] \u5DF2\u5220\u9664\u7D22\u5F15: ${r}
|
|
26
|
+
`);}),()=>t.close()}};});w();w();w();G();Y();var Te=class{db;constructor(e,t){let n=t||H.join(e,$e);F.mkdirSync(H.dirname(n),{recursive:true}),this.db=new rn(n),this.initialize();}initialize(){this.db.pragma("journal_mode = WAL"),this.db.pragma("foreign_keys = ON"),this.db.pragma("synchronous = NORMAL"),this.db.exec(`
|
|
27
27
|
-- \u6587\u4EF6\u5143\u4FE1\u606F
|
|
28
28
|
CREATE TABLE IF NOT EXISTS files (
|
|
29
29
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -149,58 +149,62 @@ import H from'path';import'url';import Qt from'crypto';import {createRequire}fro
|
|
|
149
149
|
INSERT INTO relations_fts(rowid, args)
|
|
150
150
|
VALUES (new.id, new.args);
|
|
151
151
|
END;
|
|
152
|
-
`);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,
|
|
152
|
+
`);try{this.db.exec("ALTER TABLE relations ADD COLUMN args TEXT;");}catch{}try{this.db.exec("ALTER TABLE files ADD COLUMN file_mtime INTEGER DEFAULT 0;");}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,s,r,o,i=0){let a=H.extname(t).slice(1);this.db.transaction(()=>{let u=this.db.prepare("SELECT id FROM files WHERE path = ?").get(n),p;u?(p=u.id,this.db.prepare("DELETE FROM symbols WHERE file_id = ?").run(p),this.db.prepare(`
|
|
153
153
|
UPDATE files SET
|
|
154
154
|
abs_path = ?, framework = ?, content_hash = ?,
|
|
155
|
-
last_indexed_at = ?, file_size = ?, line_count = ?
|
|
155
|
+
last_indexed_at = ?, file_size = ?, line_count = ?, file_mtime = ?
|
|
156
156
|
WHERE id = ?
|
|
157
|
-
`).run(t,e.framework,
|
|
158
|
-
INSERT INTO files (path, abs_path, file_type, framework, content_hash, last_indexed_at, file_size, line_count)
|
|
159
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
160
|
-
`).run(n,t,
|
|
157
|
+
`).run(t,e.framework,s,Date.now(),r,o,i,p)):p=this.db.prepare(`
|
|
158
|
+
INSERT INTO files (path, abs_path, file_type, framework, content_hash, last_indexed_at, file_size, line_count, file_mtime)
|
|
159
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
160
|
+
`).run(n,t,a,e.framework,s,Date.now(),r,o,i).lastInsertRowid;let d=this.db.prepare(`
|
|
161
161
|
INSERT INTO symbols (file_id, name, category, framework, start_line, end_line,
|
|
162
162
|
signature, params_json, default_value, camel_words, jsdoc,
|
|
163
163
|
is_async, hook_deps_json, state_setter_name, parent_component)
|
|
164
164
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
165
|
-
`),
|
|
165
|
+
`),f=new Map,m=new Map,g=b=>b.internalKey||`${b.name}:${b.startLine}:${b.endLine}`,E=(b,T)=>{f.set(g(b),T);let v=m.get(b.name)||[];v.push({id:T,name:b.name,startLine:b.startLine,endLine:b.endLine}),m.set(b.name,v);},h=(b,T,v)=>{if(v&&f.has(v))return f.get(v);let C=m.get(b)||[];if(C.length===0)return;if(C.length===1||T==null)return C[0]?.id;let P=C.filter(O=>O.startLine<=T&&T<=O.endLine);return P.length===1?P[0].id:P.length>1?P.sort((O,M)=>O.endLine-O.startLine-(M.endLine-M.startLine)||Math.abs(O.startLine-T)-Math.abs(M.startLine-T))[0]?.id:C.slice().sort((O,M)=>Math.abs(O.startLine-T)-Math.abs(M.startLine-T)||O.endLine-O.startLine-(M.endLine-M.startLine))[0]?.id};for(let b of e.symbols){let v=b.camelWords||A(b.name),C=d.run(p,b.name,b.category,b.framework,b.startLine,b.endLine,b.signature||null,b.params?JSON.stringify(b.params):null,b.defaultValue||null,v,b.jsdoc||null,b.isAsync?1:0,b.hookDeps?JSON.stringify(b.hookDeps):null,b.stateSetterName||null,b.parentComponent||null);E(b,C.lastInsertRowid);}let y=this.db.prepare(`
|
|
166
166
|
INSERT INTO relations (caller_id, callee_name, call_type, line_number, args)
|
|
167
167
|
VALUES (?, ?, ?, ?, ?)
|
|
168
|
-
`);for(let b of e.relations){let
|
|
168
|
+
`);for(let b of e.relations){let T=h(b.callerName,b.callerLine,b.callerKey);T&&y.run(T,b.calleeName,b.callType,b.line,b.args||null);}let S=this.db.prepare(`
|
|
169
169
|
INSERT INTO behaviors (symbol_id, file_id, category, api_name, operation, detail, line_number)
|
|
170
170
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
171
|
-
`);for(let b of e.behaviors){let
|
|
171
|
+
`);for(let b of e.behaviors){let T=h(b.symbolName,b.line,b.symbolKey);T&&S.run(T,p,b.category,b.apiName,b.operation,b.detail||null,b.line);}})();}getFileHash(e){return this.db.prepare("SELECT content_hash FROM files WHERE path = ?").get(e)?.content_hash??null}getFileMeta(e){let t=this.db.prepare("SELECT content_hash, file_mtime, file_size FROM files WHERE path = ?").get(e);return t?{hash:t.content_hash,mtime:t.file_mtime??0,fileSize:t.file_size??0}:null}updateFileMtime(e,t){this.db.prepare("UPDATE files SET file_mtime = ? WHERE path = ?").run(t,e);}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,s=this.db.prepare(`
|
|
172
172
|
SELECT s.*, f.path as file_path
|
|
173
173
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
174
174
|
WHERE s.file_id = ?
|
|
175
175
|
ORDER BY s.start_line ASC
|
|
176
|
-
`).all(n),
|
|
176
|
+
`).all(n),r=this.db.prepare(`
|
|
177
177
|
SELECT b.*, s.name as symbol_name
|
|
178
178
|
FROM behaviors b JOIN symbols s ON b.symbol_id = s.id
|
|
179
179
|
WHERE b.file_id = ?
|
|
180
|
-
`).all(n);return {file:t,symbols:
|
|
180
|
+
`).all(n);return {file:t,symbols:s,behaviors:r}}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,s){let r=`
|
|
181
181
|
SELECT s.*, f.path as file_path, f.abs_path
|
|
182
182
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
183
183
|
WHERE LOWER(s.name) = LOWER(?)
|
|
184
|
-
`,o=[e];return t&&(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
184
|
+
`,o=[e];return t&&(r+=" AND s.category = ?",o.push(t)),n&&(r+=" AND s.framework = ?",o.push(n)),s&&(r+=" AND f.path LIKE ?",o.push(`%${s}%`)),r+=" LIMIT 30",this.db.prepare(r).all(...o)}ftsSearch(e,t,n,s,r=20){let o=Math.max(1,Math.min(200,r)),a=e.replace(/[^\w\u4e00-\u9fa5\s]/g," ").trim().split(/\s+/).filter(c=>c.length>=2);if(a.length>0){let c=a.map(u=>`${u}*`).join(" ");try{let u=`
|
|
185
|
+
SELECT s.*, f.path as file_path, f.abs_path,
|
|
186
|
+
bm25(symbols_fts, 10.0, 1.0, 0.5, 0.5) as fts_rank
|
|
187
|
+
FROM symbols_fts
|
|
188
|
+
JOIN symbols s ON symbols_fts.rowid = s.id
|
|
189
|
+
JOIN files f ON s.file_id = f.id
|
|
190
|
+
WHERE symbols_fts MATCH ?
|
|
191
|
+
`,p=[c];return t&&(u+=" AND s.category = ?",p.push(t)),n&&(u+=" AND s.framework = ?",p.push(n)),s&&(u+=" AND f.path LIKE ?",p.push(`%${s}%`)),u+=` ORDER BY fts_rank LIMIT ${o}`,this.db.prepare(u).all(...p)}catch{}}return this.ftsLikeFallback(e,t,n,s,o)}ftsLikeFallback(e,t,n,s,r=20){let o=e.replace(/[\\%_]/g,"\\$&"),i=`
|
|
192
|
+
SELECT s.*, f.path as file_path, f.abs_path, 0 as fts_rank
|
|
193
|
+
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
194
|
+
WHERE (LOWER(s.name) LIKE LOWER(?) OR LOWER(s.camel_words) LIKE LOWER(?)) ESCAPE '\\'
|
|
195
|
+
`,a=[`%${o}%`,`%${o}%`];return t&&(i+=" AND s.category = ?",a.push(t)),n&&(i+=" AND s.framework = ?",a.push(n)),s&&(i+=" AND f.path LIKE ?",a.push(`%${s}%`)),i+=` LIMIT ${Math.max(1,Math.min(200,r))}`,this.db.prepare(i).all(...a)}getAllSymbolNames(e){let t=`
|
|
192
196
|
SELECT DISTINCT s.name, f.path as file_path, s.id
|
|
193
197
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
194
198
|
`,n=[];return e&&(t+=" WHERE f.path LIKE ?",n.push(`%${e}%`)),this.db.prepare(t).all(...n)}getSymbolById(e){return this.db.prepare(`
|
|
195
199
|
SELECT s.*, f.path as file_path, f.abs_path
|
|
196
200
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
197
201
|
WHERE s.id = ?
|
|
198
|
-
`).get(e)}getSymbolByName(e,t){if(t){let
|
|
202
|
+
`).get(e)}getSymbolByName(e,t){if(t){let s=this.db.prepare(`
|
|
199
203
|
SELECT s.*, f.path as file_path, f.abs_path
|
|
200
204
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
201
205
|
WHERE s.name = ? AND f.path = ?
|
|
202
206
|
LIMIT 1
|
|
203
|
-
`).get(e,t);return
|
|
207
|
+
`).get(e,t);return s||(s=this.db.prepare(`
|
|
204
208
|
SELECT s.*, f.path as file_path, f.abs_path
|
|
205
209
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
206
210
|
WHERE s.name = ? AND f.path LIKE ?
|
|
@@ -216,7 +220,7 @@ import H from'path';import'url';import Qt from'crypto';import {createRequire}fro
|
|
|
216
220
|
s.parent_component IS NULL DESC,
|
|
217
221
|
f.line_count DESC
|
|
218
222
|
LIMIT 1
|
|
219
|
-
`).get(e,`%${t}%`)),
|
|
223
|
+
`).get(e,`%${t}%`)),s}if(!((this.db.prepare(`
|
|
220
224
|
SELECT COUNT(DISTINCT f.path) as c
|
|
221
225
|
FROM symbols s JOIN files f ON s.file_id = f.id
|
|
222
226
|
WHERE s.name = ?
|
|
@@ -235,25 +239,25 @@ import H from'path';import'url';import Qt from'crypto';import {createRequire}fro
|
|
|
235
239
|
s.parent_component IS NULL DESC,
|
|
236
240
|
f.line_count DESC
|
|
237
241
|
LIMIT 1
|
|
238
|
-
`).get(e)}behaviorSearch(e,t,n,r
|
|
242
|
+
`).get(e)}behaviorSearch(e,t,n,s,r){let o=`
|
|
239
243
|
SELECT b.*, s.name as symbol_name, s.start_line, s.end_line, s.category as symbol_category,
|
|
240
244
|
f.path as file_path
|
|
241
245
|
FROM behaviors b
|
|
242
246
|
JOIN symbols s ON b.symbol_id = s.id
|
|
243
247
|
JOIN files f ON b.file_id = f.id
|
|
244
248
|
WHERE 1=1
|
|
245
|
-
`,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)),
|
|
249
|
+
`,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)),s&&(o+=" AND (LOWER(b.detail) LIKE LOWER(?) OR LOWER(b.api_name) LIKE LOWER(?))",i.push(`%${s}%`,`%${s}%`)),r&&(o+=" AND f.path LIKE ?",i.push(`%${r}%`)),o+=" ORDER BY f.path, b.line_number LIMIT 50",this.db.prepare(o).all(...i)}getCallers(e,t,n){let s=`
|
|
246
250
|
SELECT r.*, s.name as caller_name, s.start_line, s.end_line, s.category,
|
|
247
251
|
f.path as file_path
|
|
248
252
|
FROM relations r
|
|
249
253
|
JOIN symbols s ON r.caller_id = s.id
|
|
250
254
|
JOIN files f ON s.file_id = f.id
|
|
251
255
|
WHERE r.callee_name = ?
|
|
252
|
-
`,
|
|
256
|
+
`,r=[e];return t&&(s+=" AND f.path LIKE ?",r.push(`%${t}%`)),n&&(s+=" AND LOWER(COALESCE(r.args, '')) LIKE LOWER(?)",r.push(`%${n}%`)),s+=" ORDER BY f.path, r.line_number",this.db.prepare(s).all(...r)}getCallees(e){return this.db.prepare(`
|
|
253
257
|
SELECT r.*, r.callee_name
|
|
254
258
|
FROM relations r
|
|
255
259
|
WHERE r.caller_id = ?
|
|
256
|
-
`).all(e)}findRelationsByArgKeyword(e,t,n=50){let
|
|
260
|
+
`).all(e)}findRelationsByArgKeyword(e,t,n=50){let s=e.trim();if(!s)return [];let r=`
|
|
257
261
|
SELECT r.*, s.name as caller_name, s.start_line, s.end_line, s.category,
|
|
258
262
|
f.path as file_path
|
|
259
263
|
FROM relations_fts fts
|
|
@@ -261,14 +265,14 @@ import H from'path';import'url';import Qt from'crypto';import {createRequire}fro
|
|
|
261
265
|
JOIN symbols s ON r.caller_id = s.id
|
|
262
266
|
JOIN files f ON s.file_id = f.id
|
|
263
267
|
WHERE fts.args MATCH ?
|
|
264
|
-
`,i=[`"${
|
|
268
|
+
`,i=[`"${s.replace(/"/g,'""')}"`];t&&(r+=" AND f.path LIKE ?",i.push(`%${t}%`)),r+=" ORDER BY f.path, r.line_number LIMIT ?",i.push(n);let a=[],c=false,u=false;try{a=this.db.prepare(r).all(...i),a.length>0&&(c=!0);}catch{u=true;}let p=/[^a-zA-Z0-9_\u4e00-\u9fa5]/.test(s);if(!c&&(u||p)){let f=s.replace(/[\\%_]/g,"\\$&"),m=`
|
|
265
269
|
SELECT r.*, s.name as caller_name, s.start_line, s.end_line, s.category,
|
|
266
270
|
f.path as file_path
|
|
267
271
|
FROM relations r
|
|
268
272
|
JOIN symbols s ON r.caller_id = s.id
|
|
269
273
|
JOIN files f ON s.file_id = f.id
|
|
270
274
|
WHERE LOWER(COALESCE(r.args, '')) LIKE LOWER(?) ESCAPE '\\'
|
|
271
|
-
`,g=[`%${f}%`];t&&(m+=" AND f.path LIKE ?",g.push(`%${t}%`)),m+=" ORDER BY f.path, r.line_number LIMIT ?",g.push(n),
|
|
275
|
+
`,g=[`%${f}%`];t&&(m+=" AND f.path LIKE ?",g.push(`%${t}%`)),m+=" ORDER BY f.path, r.line_number LIMIT ?",g.push(n),a=this.db.prepare(m).all(...g);}return a}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,s=this.db.prepare("SELECT COUNT(*) as c FROM relations").get().c,r=this.db.prepare(`
|
|
272
276
|
SELECT framework, COUNT(*) as count FROM files GROUP BY framework
|
|
273
277
|
`).all(),o=this.db.prepare(`
|
|
274
278
|
SELECT f.path, f.line_count, COUNT(s.id) as symbol_count
|
|
@@ -277,9 +281,9 @@ import H from'path';import'url';import Qt from'crypto';import {createRequire}fro
|
|
|
277
281
|
ORDER BY f.line_count DESC LIMIT 10
|
|
278
282
|
`).all(),i=this.db.prepare(`
|
|
279
283
|
SELECT category, COUNT(*) as count FROM behaviors GROUP BY category ORDER BY count DESC
|
|
280
|
-
`).all(),
|
|
281
|
-
`),process.stderr.write(`[Frontend-Code-Skimmer] \u6570\u636E\u5E93: ${
|
|
282
|
-
`),
|
|
284
|
+
`).all(),a=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:s,frameworkBreakdown:r,topFiles:o,behaviorStats:i,dbSize:a}}close(){this.db.close();}};Y();var ln=8,pn=30,dn=14,un=360*60*1e3,ke=class{dbCache=new Map;accessTimes=new Map;dbPaths=new Map;watcherCleanups=new Map;lastProject=null;globalCacheDir;defaultProject;maxOpenProjects;maxIdleMs;dbTtlMs;lastDiskCleanupAt=0;constructor(){this.globalCacheDir=H.join(an.homedir(),".frontend-code-skimmer","databases"),F.mkdirSync(this.globalCacheDir,{recursive:true}),this.defaultProject=process.env.SKIMMER_PROJECT||null,this.defaultProject&&(this.defaultProject=H.resolve(this.defaultProject)),this.maxOpenProjects=this.parsePositiveInt(process.env.SKIMMER_MAX_OPEN_PROJECTS,ln);let e=this.parsePositiveInt(process.env.SKIMMER_DB_IDLE_MINUTES,pn),t=this.parsePositiveInt(process.env.SKIMMER_DB_TTL_DAYS,dn);this.maxIdleMs=e*60*1e3,this.dbTtlMs=t*24*60*60*1e3,this.maybeCleanupDiskCache(Date.now());}resolveProjectRoot(e){if(e){let t=H.resolve(e);if(!F.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=H.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 s=this.resolveDbPath(t),r=new Te(t,s);return this.dbCache.set(t,r),this.dbPaths.set(t,s),this.touchProject(t,n),this.lastProject=t,process.stderr.write(`[Frontend-Code-Skimmer] \u5DF2\u8FDE\u63A5\u9879\u76EE: ${t}
|
|
285
|
+
`),process.stderr.write(`[Frontend-Code-Skimmer] \u6570\u636E\u5E93: ${s}
|
|
286
|
+
`),r}getContext(e){let t=this.resolveProjectRoot(e),n=this.getDatabase(t);return this.lastProject=t,{db:n,projectRoot:t}}setLastProject(e){this.lastProject=H.resolve(e);}listProjects(){return Array.from(this.dbCache.entries()).map(([e])=>({root:e,dbPath:this.dbPaths.get(e)||this.resolveDbPath(e)}))}registerWatcher(e,t){let n=H.resolve(e),s=this.watcherCleanups.get(n);if(s)try{s();}catch{}this.watcherCleanups.set(n,t);}closeProject(e){let t=H.resolve(e),n=this.watcherCleanups.get(t);if(n){try{n();}catch{}this.watcherCleanups.delete(t);}let s=this.dbCache.get(t);s&&(s.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.watcherCleanups.values())try{e();}catch{}this.watcherCleanups.clear();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 H.resolve(process.env.SKIMMER_DB);let t=H.join(e,".agent","skimmer_find_symbol"),n=H.join(t,$e);try{return F.mkdirSync(t,{recursive:!0}),F.accessSync(e,F.constants.W_OK),n}catch{let s=createHash("md5").update(e).digest("hex").slice(0,8),r=e.replace(/[/\\:]/g,"_").replace(/^_+/,"").slice(-40);return H.join(this.globalCacheDir,`${s}_${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 s of this.dbCache.keys()){let r=this.accessTimes.get(s)??e;r<n&&(n=r,t=s);}if(!t)break;this.closeProject(t);}}evictIdleDatabases(e){let t=[];for(let n of this.dbCache.keys()){if(n===this.lastProject)continue;let s=this.accessTimes.get(n)??e;e-s>this.maxIdleMs&&t.push(n);}for(let n of t)this.closeProject(n);}maybeCleanupDiskCache(e){if(e-this.lastDiskCleanupAt<un)return;this.lastDiskCleanupAt=e;let t=[];try{t=F.readdirSync(this.globalCacheDir,{withFileTypes:!0});}catch{return}let n=new Set;for(let r of this.dbPaths.values())r.startsWith(this.globalCacheDir)&&n.add(H.resolve(r));let s=e-this.dbTtlMs;for(let r of t){if(!r.isFile()||!r.name.endsWith(".db"))continue;let o=H.join(this.globalCacheDir,r.name);if(n.has(H.resolve(o)))continue;let i;try{i=F.statSync(o);}catch{continue}i.mtimeMs>=s||(this.safeUnlink(o),this.safeUnlink(`${o}-wal`),this.safeUnlink(`${o}-shm`));}}safeUnlink(e){try{F.existsSync(e)&&F.unlinkSync(e);}catch{}}};w();tt();function Ct(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
|
|
283
287
|
\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
|
|
284
288
|
\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
|
|
285
289
|
\u591A\u4E2A\u9879\u76EE\u4F1A\u5E76\u884C\u7F13\u5B58\uFF0C\u5207\u6362\u65E0\u9700\u91CD\u542F\u3002
|
|
@@ -289,60 +293,69 @@ import H from'path';import'url';import Qt from'crypto';import {createRequire}fro
|
|
|
289
293
|
- \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
|
|
290
294
|
- \u5F3A\u5236\u5168\u91CF\u91CD\u5EFA: force=true
|
|
291
295
|
|
|
292
|
-
\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:
|
|
293
|
-
`);}});e.setLastProject(i);let
|
|
294
|
-
|
|
295
|
-
`)
|
|
296
|
+
\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:s,exclude:r})=>{let{db:o,projectRoot:i}=e.getContext(t),a=new he(i,o),c=await a.indexProject({include:s,exclude:r,force:n,onProgress:(h,y)=>{(h%20===0||h===y)&&process.stderr.write(`[Frontend-Code-Skimmer] \u8FDB\u5EA6: ${h}/${y}
|
|
297
|
+
`);}});e.setLastProject(i);try{let h=await a.startWatcher();e.registerWatcher(i,h),process.stderr.write(`[Frontend-Code-Skimmer] \u6587\u4EF6\u76D1\u542C\u5DF2\u542F\u52A8: ${i}
|
|
298
|
+
`);}catch(h){process.stderr.write(`[Frontend-Code-Skimmer] \u6587\u4EF6\u76D1\u542C\u542F\u52A8\u5931\u8D25\uFF08\u7D22\u5F15\u4ECD\u53EF\u7528\uFF09: ${String(h)}
|
|
299
|
+
`);}let u=c.indexedFiles>0||c.totalFiles>0,p=c.totalSymbols>0,d=u?"\u2705 \u53EF\u7528":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",f=p?"\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=u?"\u2705 \u53EF\u7528":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",g=u?"\u2705 \u53EF\u7528\uFF08\u57FA\u4E8E\u6B63\u5219\u626B\u63CF\u6587\u4EF6\uFF09":"\u274C \u65E0\u53EF\u67E5\u8BE2\u6587\u4EF6",E=[`\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: ${c.totalFiles}`,` \u{1F504} \u5DF2\u7D22\u5F15: ${c.indexedFiles}`,` \u23E9 \u5DF2\u8DF3\u8FC7: ${c.skippedFiles} (\u5185\u5BB9\u672A\u53D8)`,` \u{1F523} \u603B\u7B26\u53F7\u6570: ${c.totalSymbols}`,` \u23F1\uFE0F \u8017\u65F6: ${c.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 ${f}`,` skimmer_get_component_outline ${f}`,` skimmer_find_by_behavior ${m}`,` skimmer_trace_data_lifecycle ${g}`,` skimmer_trace_assignments ${g}`,` skimmer_get_code_slice ${d}`,"","\u{1F4A1} \u540E\u7EED\u5DE5\u5177\u8C03\u7528\u53EF\u7701\u7565 project_path\uFF08\u81EA\u52A8\u4F7F\u7528\u6B64\u9879\u76EE\uFF09"," \u5982\u7B26\u53F7\u6570\u4E3A0\u4F46\u5DE5\u5177\u4ECD\u8FD4\u56DE\u7ED3\u679C\uFF0C\u5C5E\u6B63\u5E38\u73B0\u8C61\uFF08\u6B63\u5219\u626B\u63CF\u8DEF\u5F84\u4E0D\u4F9D\u8D56\u7B26\u53F7\u7D22\u5F15\uFF09","\u{1F441}\uFE0F \u6587\u4EF6\u76D1\u542C\u5DF2\u542F\u52A8 \u2014 \u4EE3\u7801\u53D8\u66F4\u5C06\u81EA\u52A8\u589E\u91CF\u66F4\u65B0\u7D22\u5F15\uFF08\u65E0\u9700\u624B\u52A8\u91CD\u65B0\u7D22\u5F15\uFF09"];if(c.errors.length>0){E.push(`
|
|
300
|
+
\u26A0\uFE0F \u89E3\u6790\u5931\u8D25 (${c.errors.length} \u4E2A):`);for(let h of c.errors.slice(0,5))E.push(` - ${h.file}: ${h.error}`);c.errors.length>5&&E.push(` ... \u8FD8\u6709 ${c.errors.length-5} \u4E2A`);}return {content:[{type:"text",text:E.join(`
|
|
301
|
+
`)}]}});}w();G();function Pt(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
|
|
296
302
|
\u5305\u542B: props\u3001data/state\u3001computed\u3001methods/functions\u3001watch/effect\u3001lifecycle\u3001\u884C\u4E3A\u6807\u7B7E\u3002
|
|
297
303
|
\u884C\u4E3A\u6807\u7B7E\u81EA\u52A8\u6807\u51FA: [storage:localStorage.setItem] [network:axios.get] \u7B49\u3002
|
|
298
304
|
|
|
299
305
|
project_path \u53EF\u7701\u7565\uFF08\u4F7F\u7528\u4E0A\u6B21 skimmer_index_project \u6307\u5B9A\u7684\u9879\u76EE\uFF09\u3002
|
|
300
|
-
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:
|
|
306
|
+
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:s}=e.getContext(n),{file:r,symbols:o,behaviors:i}=s.getFileOutline(t);if(!r)return {content:[{type:"text",text:`\u274C \u6587\u4EF6\u672A\u7D22\u5F15: ${t}
|
|
301
307
|
|
|
302
308
|
\u8BF7\u5148\u8FD0\u884C:
|
|
303
|
-
skimmer_index_project({ project_path: "${n||"<\u9879\u76EE\u8DEF\u5F84>"}" })`}]};let
|
|
304
|
-
${
|
|
305
|
-
|
|
306
|
-
`)}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
`)
|
|
310
|
-
`)
|
|
311
|
-
`),
|
|
312
|
-
`),
|
|
313
|
-
`),
|
|
314
|
-
`),
|
|
309
|
+
skimmer_index_project({ project_path: "${n||"<\u9879\u76EE\u8DEF\u5F84>"}" })`}]};let a="";try{let f=r.abs_path;if(f&&F.existsSync(f)){let m=F.statSync(f),g=r.file_mtime??0,E=r.file_size??0,h=g>0&&m.mtimeMs>g,y=E>0&&m.size!==E;(h||y)&&(a=`
|
|
310
|
+
\u26A0\uFE0F [\u7D22\u5F15\u5DF2\u8FC7\u671F] ${y?`\u6587\u4EF6\u5927\u5C0F\u5DEE\u5F02 ${m.size-E>0?"+":""}${m.size-E} \u5B57\u8282`:"\u6587\u4EF6\u4FEE\u6539\u65F6\u95F4\u66F4\u65B0"}\uFF0C\u884C\u53F7\u53EF\u80FD\u504F\u79FB\uFF08\u7D22\u5F15\u8BB0\u5F55 ${r.line_count} \u884C\uFF0C\u5B9E\u9645\u53EF\u80FD\u5DF2\u53D8\u5316\uFF09
|
|
311
|
+
\u7ACB\u5373\u91CD\u5EFA: skimmer_index_project({ force: true })
|
|
312
|
+
`);}}catch{}let c=new Map;for(let f of i){let m=f.symbol_id;c.has(m)||c.set(m,[]);let g=`[${f.category}:${f.api_name}.${f.operation}${f.detail?`("${f.detail}")`:""}]`,E=c.get(m);E.includes(g)||E.push(g);}let u=[];u.push(`\u{1F4C4} ${t} (${r.line_count} \u884C, ${r.framework})`),u.push(`${"\u2501".repeat(50)}`),a&&u.push(a);let p={};for(let f of o){if(f.name==="<template>")continue;let m=f.category;p[m]||(p[m]=[]),p[m].push(f);}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:f,icon:m,label:g}of d){let E=p[f];if(E?.length){u.push(`
|
|
313
|
+
${m} ${g} (${E.length}):`);for(let h of E){let y=h.name,S=le(h.start_line,h.end_line),b=me(h.params_json,[]),T=b.length>0?`(${b.join(", ")})`:"",v=h.default_value?` = ${h.default_value}`:"",C=h.is_async?"async ":"",P=c.get(h.id),O=P?.length?` ${P.slice(0,3).join(" ")}`:"",M=h.state_setter_name?` \u2192 ${h.state_setter_name}`:"",ae=h.hook_deps_json?` [deps:${me(h.hook_deps_json,[]).join(",")}]`:"";u.push(` \u2022 ${C}${y}${T}${v}${M}${ae} ${S}${O}`);}}}return u.push(`
|
|
314
|
+
${"\u2500".repeat(50)}`),u.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:u.join(`
|
|
315
|
+
`)}]}});}w();w();G();Y();var ye=class{constructor(e){this.db=e;}db;search(e,t){let{category:n,framework:s,filePath:r,limit:o=Et,fuzzy:i=true}=t||{},a=new Map,c=this.db.exactSearch(e,n,s,r);for(let g of c){let E=g.id;a.set(E,{symbol:g,filePath:g.file_path,score:100,matchReason:"\u7CBE\u786E\u5339\u914D"});}if(a.size>=o)return this.rankResults(a,o);let u=A(e),p=[e,u,...u.split(" ")].filter(Boolean);for(let g of p){if(g.length<2)continue;let E=this.db.ftsSearch(g,n,s,r,o);for(let h of E){let y=h.id;if(a.has(y))continue;let S=this.calcFtsScore(e,h.name);a.set(y,{symbol:h,filePath:h.file_path,score:S,matchReason:`FTS5 \u5168\u6587\u5339\u914D (${g})`});}}if(!i||a.size>=o)return this.rankResults(a,o);let d=this.db.getAllSymbolNames(r),f=e.toLowerCase(),m=A(e).split(" ");for(let{name:g,file_path:E,id:h}of d){if(a.has(h))continue;let y=Ae(f,g.toLowerCase()),S=Math.max(f.length,g.length),b=Math.min(Nt,Math.max(1,Math.floor(S*.28)));if(y<=b){let C=Math.max(0,80-y*15),P=this.db.getSymbolById(h);if(!P||n&&P.category!==n||s&&P.framework!==s)continue;let O=ft(e,g,y);a.set(h,{symbol:P,filePath:E,score:C,matchReason:`\u6A21\u7CCA\u5339\u914D (\u7F16\u8F91\u8DDD\u79BB=${y})`,spellingSuggestion:O});continue}let T=A(g).split(" "),v=m.filter(C=>T.some(P=>ut(C,P)>=75));if(v.length>0&&v.length>=Math.ceil(m.length*.5)){let C=50+v.length*10,P=this.db.getSymbolById(h);if(!P||n&&P.category!==n||s&&P.framework!==s)continue;a.set(h,{symbol:P,filePath:E,score:C,matchReason:`\u5355\u8BCD\u5339\u914D (${v.join(", ")})`});}}return this.rankResults(a,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(),s=t.toLowerCase();if(s===n)return 98;if(s.startsWith(n))return 91;if(s.includes(n))return 80;let r=A(e).split(" "),o=A(t).split(" "),i=r.some(c=>o[0]?.startsWith(c))?8:0,a=r.filter(c=>o.some(u=>u.startsWith(c))).length;return Math.min(88,58+a*8+i)}rankResults(e,t){return Array.from(e.values()).sort((n,s)=>s.score-n.score).slice(0,t)}};G();var Ut=createRequire(import.meta.url),Q="\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 be(l){return l.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function de(l,e,t){let n=[];for(let s of l){if(!s?.abs_path||!F.existsSync(s.abs_path))continue;let r=F.readFileSync(s.abs_path,"utf-8").split(`
|
|
316
|
+
`);for(let o=0;o<r.length;o++){let i=r[o];for(let a of e)if(a.regex.test(i)){n.push({filePath:s.path,line:o+1,kind:a.kind,text:i.trim()});break}if(n.length>=t)return n}}return n}function Ot(l,e){let t=be(l),n="(?:=|\\+=|-=|\\*=|/=|%=|\\|=|&=|\\^=|&&=|\\|\\|=|\\?\\?=)",s=[{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&&s.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}`)}),s}function ie(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 s of n)s&&typeof s=="object"&&s.type&&ie(s,e);else n&&typeof n=="object"&&n.type&&ie(n,e);}}}function De(l){try{return Ut("@babel/parser").parse(l,{sourceType:"module",plugins:["typescript","jsx","decorators-legacy"],errorRecovery:!0})}catch{return null}}function We(l,e){if(!l.endsWith(".vue"))return [{content:e,lineOffset:1}];try{let{parse:r}=Ut("@vue/compiler-sfc"),{descriptor:o}=r(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 s=e.slice(0,t.index||0).split(`
|
|
317
|
+
`).length;return [{content:t[1],lineOffset:s}]}function te(l,e){return (l.loc?.start?.line??1)+e-1}function oe(l){let e=l.property;return e?e.type==="Identifier"?String(e.name||""):e.type==="Literal"?String(e.value||""):null:null}function Ft(l,e){if(l.type!=="MemberExpression")return false;let t=l.object;return !t||t.type!=="ThisExpression"?false:oe(l)===e}function st(l,e){return !!l&&l.type==="Identifier"&&String(l.name||"")===e}function je(l){let e=l.object;return e?e.type==="Identifier"?String(e.name||""):e.type==="MemberExpression"&&e.object?.type==="ThisExpression"&&oe(e)||null:null}function Ht(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 rt(l,e,t=2){if(!F.existsSync(l))return {snippet:"",startLine:e};let n=F.readFileSync(l,"utf-8").split(`
|
|
318
|
+
`),s=Math.max(0,e-1-t),r=Math.min(n.length-1,e-1+t);return {snippet:n.slice(s,r+1).map((i,a)=>{let c=s+a+1;return ` ${c===e?"\u25B6":" "} ${String(c).padStart(4)} \u2502 ${i}`}).join(`
|
|
319
|
+
`),startLine:s+1}}function Oe(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)),s=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}% ${s}]`}function jt(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 Mt={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 Dt(l,e,t){let n=[];for(let s of l){if(!s.abs_path||!F.existsSync(s.abs_path))continue;let r=F.readFileSync(s.abs_path,"utf-8"),o=r.split(`
|
|
320
|
+
`),i=We(s.path||H.basename(s.abs_path),r);for(let a of i){let c=De(a.content);c&&ie(c,u=>{if(n.length>=t||u.type!=="VariableDeclarator")return;let p=u.id;if(!p||p.type!=="Identifier")return;let d=String(p.name||"");if(!d||d===e)return;let f=u.init;if(!f)return;let m=false;if(f.type==="Identifier"&&String(f.name||"")===e&&(m=true),!m&&f.type==="MemberExpression"&&oe(f)===e&&(m=true),m||ie(f,h=>{m||(h.type==="Identifier"&&String(h.name||"")===e&&(m=true),h.type==="MemberExpression"&&oe(h)===e&&(m=true));}),!m)return;let g=te(u,a.lineOffset),E=o[g-1]?.trim()||"";n.push({alias:d,filePath:s.path,abs_path:s.abs_path,line:g,text:E});});}}return n}function Wt(l,e,t){let n=[];for(let s of l){if(!s.abs_path||!F.existsSync(s.abs_path))continue;let r=F.readFileSync(s.abs_path,"utf-8"),o=r.split(`
|
|
321
|
+
`),i=We(s.path||H.basename(s.abs_path),r);for(let a of i){let c=De(a.content);c&&ie(c,u=>{if(n.length>=t||u.type!=="VariableDeclarator")return;let p=u.id;if(!p||p.type!=="ObjectPattern")return;let d=p.properties||[];for(let f of d){if(f.type!=="ObjectProperty"&&f.type!=="Property")continue;let m=f.key,g=f.value,E=m?.type==="Identifier"?String(m.name||""):null;if(E!==e)continue;let h=g?.type==="Identifier"?String(g.name||""):E;if(!h)continue;let y=te(u,a.lineOffset),S=o[y-1]?.trim()||"";n.push({alias:h,filePath:s.path,line:y,text:S});}});}}return n}function ot(l,e,t,n){let s=[];for(let r of l){if(!r.abs_path||!F.existsSync(r.abs_path))continue;let o=F.readFileSync(r.abs_path,"utf-8"),i=o.split(`
|
|
322
|
+
`),a=We(r.path||H.basename(r.abs_path),o);for(let c of a){let u=De(c.content);if(u&&(ie(u,p=>{if(!(s.length>=n)){if(p.type==="VariableDeclarator"){let d=p.id;if(st(d,e)){let f=te(p,c.lineOffset);s.push({filePath:r.path,line:f,kind:"declaration",text:i[f-1]?.trim()||""});}}if(p.type==="AssignmentExpression"){let d=p.left;if(!d)return;let f=te(p,c.lineOffset);if(st(d,e)||Ft(d,e)){s.push({filePath:r.path,line:f,kind:"assignment",text:i[f-1]?.trim()||""});return}t&&d.type==="MemberExpression"&&je(d)===e&&s.push({filePath:r.path,line:f,kind:d.computed?"indexed_assignment":"property_assignment",text:i[f-1]?.trim()||""});}if(p.type==="UpdateExpression"){let d=p.argument;if(!d)return;if(st(d,e)||Ft(d,e)){let f=te(p,c.lineOffset);s.push({filePath:r.path,line:f,kind:"update",text:i[f-1]?.trim()||""});}}}}),s.length>=n))break}if(s.length>=n)break}return Ht(s).slice(0,n)}function Fe(l,e,t,n){let s=[];for(let r of l){if(!r.abs_path||!F.existsSync(r.abs_path))continue;let o=F.readFileSync(r.abs_path,"utf-8"),i=o.split(`
|
|
323
|
+
`),a=We(r.path||H.basename(r.abs_path),o);for(let c of a){let u=De(c.content);if(u&&(ie(u,p=>{if(!(s.length>=n)){if(p.type==="AssignmentExpression"){let d=p.left;if(!d||d.type!=="MemberExpression"||je(d)!==e)return;let m=oe(d);if(t&&m!==t)return;let g=te(p,c.lineOffset);s.push({filePath:r.path,line:g,kind:d.computed?"bracket":"dot",text:i[g-1]?.trim()||""});}if(p.type==="UpdateExpression"){let d=p.argument;if(!d||d.type!=="MemberExpression"||je(d)!==e)return;let m=oe(d);if(t&&m!==t)return;let g=te(p,c.lineOffset);s.push({filePath:r.path,line:g,kind:d.computed?"bracket":"dot",text:i[g-1]?.trim()||""});}if(p.type==="UnaryExpression"&&p.operator==="delete"){let d=p.argument;if(!d||d.type!=="MemberExpression"||je(d)!==e)return;let m=oe(d);if(t&&m!==t)return;let g=te(p,c.lineOffset);s.push({filePath:r.path,line:g,kind:"delete",text:i[g-1]?.trim()||""});}}}),s.length>=n))break}if(s.length>=n)break}return Ht(s).slice(0,n)}function Bt(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
|
|
315
324
|
\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
|
|
316
325
|
\u9A7C\u5CF0\u62C6\u8BCD\uFF1A\u641C "change cache" \u4E5F\u80FD\u627E\u5230 "changeCacheValue"\u3002
|
|
317
326
|
\u6846\u67B6\u611F\u77E5\uFF1A\u53EF\u6309 vue2/vue3/react \u8FC7\u6EE4\u3002
|
|
318
|
-
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(
|
|
327
|
+
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(Q),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:s,framework:r,file_path:o,fuzzy:i,limit:a})=>{let{db:c}=e.getContext(n),p=new ye(c).search(t,{category:s==="all"?void 0:s,framework:r==="all"?void 0:r,filePath:o,fuzzy:i,limit:a});if(p.length===0)return {content:[{type:"text",text:`\u{1F50D} \u641C\u7D22 "${t}" \u65E0\u7ED3\u679C
|
|
319
328
|
|
|
320
329
|
\u{1F4A1} \u5C1D\u8BD5:
|
|
321
330
|
skimmer_find_by_behavior \u6309\u884C\u4E3A\u641C\u7D22
|
|
322
|
-
\u4F8B\u5982: skimmer_find_by_behavior({ category: "storage" })`}]};let
|
|
323
|
-
`];return
|
|
331
|
+
\u4F8B\u5982: skimmer_find_by_behavior({ category: "storage" })`}]};let d=[`\u{1F50D} \u641C\u7D22 "${t}" \u2014 \u627E\u5230 ${p.length} \u4E2A\u7ED3\u679C
|
|
332
|
+
`];return p.forEach((f,m)=>{let g=f.symbol,E=me(g.params_json,[]),h=E.length>0?`(${E.join(", ")})`:"",y=le(g.start_line,g.end_line);d.push(`${m+1}. ${g.name}${h} [${g.category}/${g.framework}] \u5339\u914D\u5EA6: ${f.score}%`),d.push(` \u{1F4C4} ${f.filePath}:${y}`),d.push(` \u{1F3AF} ${f.matchReason}`),f.spellingSuggestion&&d.push(` \u{1F4A1} ${f.spellingSuggestion}`),g.default_value&&d.push(` \u{1F4CC} \u9ED8\u8BA4\u503C: ${g.default_value}`),d.push("");}),{content:[{type:"text",text:d.join(`
|
|
324
333
|
`)}]}}),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
|
|
325
334
|
\u540C\u65F6\u8FD4\u56DE\u8BE5\u7B26\u53F7\u7684\u884C\u4E3A\u6807\u7B7E\uFF08\u64CD\u4F5C\u4E86\u54EA\u4E9B\u5916\u90E8 API\uFF09\u3002
|
|
326
|
-
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(
|
|
335
|
+
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(Q),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:s,context_lines:r})=>{let{db:o}=e.getContext(s),i=o.getSymbolByName(n,t);if(!i)return {content:[{type:"text",text:`\u274C \u672A\u627E\u5230: ${n}
|
|
327
336
|
\u{1F4C4} \u6587\u4EF6: ${t}
|
|
328
337
|
|
|
329
|
-
\u{1F4A1} \u8BD5\u8BD5: skimmer_find_symbol({ query: "${n}" })`}]};let
|
|
330
|
-
`),
|
|
331
|
-
`),
|
|
332
|
-
|
|
338
|
+
\u{1F4A1} \u8BD5\u8BD5: skimmer_find_symbol({ query: "${n}" })`}]};let a=i.abs_path;if(!F.existsSync(a))return {content:[{type:"text",text:`\u274C \u6587\u4EF6\u4E0D\u5B58\u5728: ${a}`}]};let u=F.readFileSync(a,"utf-8").split(`
|
|
339
|
+
`),p=Math.max(1,i.start_line-r)-1,d=Math.min(u.length,i.end_line+r),f=u.slice(p,d).join(`
|
|
340
|
+
`),g=f.includes(n)?"":`
|
|
341
|
+
\u26A0\uFE0F [\u884C\u53F7\u504F\u79FB] \u7D22\u5F15\u8BB0\u5F55 ${n} \u5728 L${i.start_line}\uFF0C\u4F46\u8BE5\u4F4D\u7F6E\u672A\u627E\u5230\u6B64\u7B26\u53F7\u3002
|
|
342
|
+
\u6587\u4EF6\u5DF2\u88AB\u4FEE\u6539\u4F46\u7D22\u5F15\u672A\u66F4\u65B0\uFF0C\u884C\u53F7\u53EF\u80FD\u504F\u79FB ${u.length-i.end_line} \u884C\u5DE6\u53F3\u3002
|
|
343
|
+
\u5EFA\u8BAE: skimmer_index_project({ force: true })
|
|
344
|
+
`,{behaviors:E}=o.getFileOutline(t),h=E.filter(T=>T.symbol_id===i.id),y=a.split(".").pop()||"js",S=["tsx","jsx"].includes(y)?"jsx":["ts"].includes(y)?"typescript":"javascript",b=[`\u{1F4CD} ${i.name} [${i.category}/${i.framework}]`,`\u{1F4C4} ${t}:${le(i.start_line,i.end_line)}`];if(g&&b.push(g),i.jsdoc&&b.push(`\u{1F4DD} ${i.jsdoc}`),h.length>0){let T=[...new Set(h.map(v=>`[${v.category}:${v.api_name}.${v.operation}${v.detail?`("${v.detail}")`:""}]`))];b.push(`\u{1F3F7}\uFE0F \u884C\u4E3A: ${T.join(" ")}`);}return b.push(`
|
|
345
|
+
\`\`\`${S}`),b.push(f),b.push("```"),{content:[{type:"text",text:b.join(`
|
|
333
346
|
`)}]}}),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
|
|
334
347
|
\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
|
|
335
348
|
\u2705 \u672C\u5DE5\u5177\u9002\u5408\uFF1Aloading / errorMsg / count \u8FD9\u7C7B\u7B80\u5355 flag \u7684\u8D4B\u503C\u8FFD\u8E2A\u3002
|
|
336
|
-
\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(
|
|
349
|
+
\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(Q),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:s,include_properties:r,limit:o})=>{let{db:i}=e.getContext(n),a=i.listFiles(s),c=Math.min(300,Math.max(1,o||80)),u=r??true,p=i.exactSearch(t,"state",void 0,s||void 0),d={vue2:"Vue2 data()",vue3:"Vue3 ref/reactive",react:"React useState/useRef"},f=p.filter(y=>y.default_value!=null).map(y=>({filePath:y.file_path,line:y.start_line,kind:`data_init(${d[y.framework]||y.framework})`,text:`${y.name}: ${y.default_value} \u2190 \u58F0\u660E\u521D\u59CB\u5316`})),m=ot(a,t,u,c);if(m.length===0){let y=Ot(t,u);m=de(a,y,c);}let g=new Map;for(let y of [...f,...m]){let S=`${y.filePath}:${y.line}`;g.has(S)||g.set(S,y);}let E=[...g.values()];if(E.length===0)return {content:[{type:"text",text:`\u{1F9E9} \u53D8\u91CF\u8D4B\u503C\u8FFD\u8E2A: "${t}"
|
|
337
350
|
\u672A\u627E\u5230\u5339\u914D\u8D4B\u503C\u8BED\u53E5\uFF08\u5305\u62EC\u58F0\u660E\u521D\u59CB\u5316\uFF09
|
|
338
|
-
\u8FC7\u6EE4: file_path=${
|
|
351
|
+
\u8FC7\u6EE4: file_path=${s||"*"} include_properties=${u}`}]};let h=[`\u{1F9E9} \u53D8\u91CF\u8D4B\u503C\u8FFD\u8E2A: "${t}"`,`\u8FC7\u6EE4: file_path=${s||"*"} include_properties=${u}`,`\u547D\u4E2D: ${E.length} \u5904${f.length>0?`\uFF08\u542B ${f.length} \u5904\u58F0\u660E\u521D\u59CB\u5316\uFF09`:""}`,""];return E.forEach((y,S)=>{h.push(`${S+1}. [${y.kind}] \u{1F4C4} ${y.filePath}:L${y.line}`),h.push(` ${y.text}`);}),{content:[{type:"text",text:h.join(`
|
|
339
352
|
`)}]}}),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
|
|
340
353
|
\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
|
|
341
354
|
\u2705 \u672C\u5DE5\u5177\u9002\u5408\uFF1Aobject.specificProp \u7684\u5355\u5B57\u6BB5\u7EA7\u522B\u7CBE\u786E\u8FFD\u8E2A\u3002
|
|
342
|
-
\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(
|
|
343
|
-
\u522B\u540D\u5C55\u5F00: ${
|
|
344
|
-
\u672A\u627E\u5230\u5339\u914D\u8BED\u53E5${
|
|
345
|
-
\u8FC7\u6EE4: file_path=${
|
|
355
|
+
\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(Q),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:s,file_path:r,limit:o})=>{let{db:i}=e.getContext(s),a=i.listFiles(r),c=Math.min(300,Math.max(1,o||80)),u=Dt(a,t,20),p=Wt(a,t,20),d=[...new Set([...u.map(E=>E.alias),...p.map(E=>E.alias)].filter(E=>E!==t))],f=[t,...d],m=Fe(a,t,n,c);for(let E of d)m.push(...Fe(a,E,n,Math.floor(c/2)));if(m.length===0){let E="(?:=|\\+=|-=|\\*=|/=|%=|\\|=|&=|\\^=|&&=|\\|\\|=|\\?\\?=)",h=[];for(let y of f){let S=be(y);if(n){let b=be(n);h.push({kind:"dot",regex:new RegExp(`\\b${S}\\.${b}\\s*${E}`)},{kind:"bracket",regex:new RegExp(`\\b${S}\\s*\\[(?:'${b}'|"${b}")\\]\\s*${E}`)},{kind:"delete",regex:new RegExp(`\\bdelete\\s+${S}\\.(?:${b})\\b`)});}else h.push({kind:"dot",regex:new RegExp(`\\b${S}\\.[A-Za-z_$][\\w$]*\\s*${E}`)},{kind:"bracket",regex:new RegExp(`\\b${S}\\s*\\[(?:'[^']+'|"[^"]+")\\]\\s*${E}`)},{kind:"delete",regex:new RegExp(`\\bdelete\\s+${S}\\.[A-Za-z_$][\\w$]*\\b`)});}m=de(a,h,c);}if(m.length===0){let E=d.length>0?`
|
|
356
|
+
\u522B\u540D\u5C55\u5F00: ${d.join(", ")}\uFF08\u5747\u672A\u547D\u4E2D\uFF09`:"";return {content:[{type:"text",text:`\u{1F9ED} \u5C5E\u6027\u4FEE\u6539\u8FFD\u8E2A: ${t}${n?`.${n}`:".*"}
|
|
357
|
+
\u672A\u627E\u5230\u5339\u914D\u8BED\u53E5${E}
|
|
358
|
+
\u8FC7\u6EE4: file_path=${r||"*"}`}]}}let g=[`\u{1F9ED} \u5C5E\u6027\u4FEE\u6539\u8FFD\u8E2A: ${t}${n?`.${n}`:".*"}`,`\u8FC7\u6EE4: file_path=${r||"*"}`];if(d.length>0){let E=u.map(y=>y.alias).filter(y=>y!==t).join(", "),h=p.map(y=>y.alias).filter(y=>y!==t).join(", ");E&&g.push(`\u26A1 \u5F15\u7528\u522B\u540D: ${E}\uFF08\u901A\u8FC7 let alias = this.${t} \u5C55\u5F00\uFF09`),h&&g.push(`\u26A1 \u89E3\u6784\u522B\u540D: ${h}\uFF08\u901A\u8FC7 const { ${t}: alias } \u5C55\u5F00\uFF09`);}return g.push(`\u547D\u4E2D: ${m.length} \u5904`,""),m.forEach((E,h)=>{g.push(`${h+1}. [${E.kind}] \u{1F4C4} ${E.filePath}:L${E.line}`),g.push(` ${E.text}`);}),{content:[{type:"text",text:g.join(`
|
|
346
359
|
`)}]}}),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
|
|
347
360
|
\u793A\u4F8B:
|
|
348
361
|
- \u627E\u6240\u6709\u64CD\u4F5C localStorage \u7684\u51FD\u6570: { category: "storage" }
|
|
@@ -350,20 +363,20 @@ project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({file_path:z$1.str
|
|
|
350
363
|
- \u627E\u53D1\u8BF7\u6C42\u7684: { category: "network" }
|
|
351
364
|
- \u627E\u8DEF\u7531\u8DF3\u8F6C\u7684: { category: "router" }
|
|
352
365
|
- \u6309 key \u540D\u641C\u7D22: { keyword: "cacheData" }
|
|
353
|
-
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({project_path:z$1.string().optional().describe(
|
|
354
|
-
\u8FC7\u6EE4\u6761\u4EF6: ${JSON.stringify({category:n,api_name:
|
|
355
|
-
`];for(let[m,g]of
|
|
356
|
-
`)}]}}),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(
|
|
357
|
-
`];if(
|
|
358
|
-
`)}]}}),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(
|
|
359
|
-
`),
|
|
360
|
-
\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:
|
|
366
|
+
project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({project_path:z$1.string().optional().describe(Q),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:s,operation:r,keyword:o,file_path:i})=>{let{db:a}=e.getContext(t),u=new ye(a).searchByBehavior({category:n,apiName:s,operation:r,keyword:o,filePath:i}),p=new Set(["localStorage","sessionStorage","cookie"]);if(s||(u=u.filter(m=>m.category!=="storage"||p.has(m.apiName.toLowerCase()))),u.length===0)return {content:[{type:"text",text:`\u{1F3F7}\uFE0F \u672A\u627E\u5230\u5339\u914D\u7684\u884C\u4E3A
|
|
367
|
+
\u8FC7\u6EE4\u6761\u4EF6: ${JSON.stringify({category:n,api_name:s,operation:r,keyword:o,file_path:i})}`}]};let d=new Map;for(let m of u){let g=`${m.category}:${m.apiName}`;d.has(g)||d.set(g,[]),d.get(g).push(m);}let f=[`\u{1F3F7}\uFE0F \u884C\u4E3A\u641C\u7D22\u7ED3\u679C \u2014 ${u.length} \u6761
|
|
368
|
+
`];for(let[m,g]of d){let[E,h]=m.split(":"),y=new Map;for(let S of g)y.has(S.operation)||y.set(S.operation,[]),y.get(S.operation).push(S);f.push(`\u{1F4C2} ${E} \u2192 ${h}:`);for(let[S,b]of y){f.push(` ${S}:`);let T=new Map;for(let v of b){let C=`${v.symbolName}|${v.filePath}`;T.has(C)||T.set(C,{item:v,callLines:[]}),T.get(C).callLines.push(v.line);}for(let{item:v,callLines:C}of T.values()){let P=v.detail?` key="${v.detail}"`:"",O=C.length>1?` \xD7${C.length} (L${C.join(", L")})`:` L${C[0]||v.startLine}`;f.push(` \u2022 ${v.symbolName}${P}${O} \u{1F4C4} ${v.filePath}:${le(v.startLine,v.endLine)}`);}}f.push("");}return {content:[{type:"text",text:f.join(`
|
|
369
|
+
`)}]}}),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(Q),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:s,direction:r,arg_keyword:o})=>{let{db:i}=e.getContext(n),a=i.getSymbolByName(t,s),c=[`\u{1F4CA} ${t} \u7684\u8C03\u7528\u56FE\u8C31
|
|
370
|
+
`];if(r==="callers"||r==="both"){let u=i.getCallers(t,s,o);if(c.push(`\u2B06\uFE0F \u88AB\u8C03\u7528 (${u.length} \u5904):`),u.length===0)c.push(" \uFF08\u672A\u627E\u5230\u8C03\u7528\u8005\uFF09");else for(let p of u){let d=p.args?` \u53C2\u6570: "${p.args}"`:"",f=p.call_type==="template_event"?" \u{1F5BC}\uFE0F [\u6A21\u677F\u4E8B\u4EF6\u5165\u53E3]":p.call_type==="jsx_event"?" \u269B\uFE0F [JSX\u4E8B\u4EF6\u5165\u53E3]":"";c.push(` \u2022 ${p.caller_name} [${p.category}]${f} \u{1F4C4} ${p.file_path}:L${p.start_line}${d}`);}c.push("");}if((r==="callees"||r==="both")&&a){let u=i.getCallees(a.id);if(c.push(`\u2B07\uFE0F \u8C03\u7528\u4E86 (${u.length} \u4E2A):`),u.length===0)c.push(" \uFF08\u672A\u5206\u6790\u5230\u8C03\u7528\u5173\u7CFB\uFF09");else for(let p of u){let d=p.args?`("${p.args}")`:"";c.push(` \u2022 ${p.callee_name}${d} [${p.call_type}] L${p.line_number}`);}c.push("");}if(a){let{behaviors:u}=i.getFileOutline(a.file_path),p=u.filter(d=>d.symbol_id===a.id);if(p.length>0){c.push("\u{1F4E6} \u5916\u90E8\u72B6\u6001\u64CD\u4F5C:");for(let d of p){let f=d.detail?` ("${d.detail}")`:"";c.push(` \u2022 ${d.api_name}.${d.operation}${f} [${d.category}] L${d.line_number}`);}}}return {content:[{type:"text",text:c.join(`
|
|
371
|
+
`)}]}}),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(Q),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:s})=>{let{db:r}=e.getContext(n),o=r.getCallers(t,s),i=r.getSymbolByName(t,s),{behaviors:a}=i?r.getFileOutline(i.file_path):{behaviors:[]},c=i?a.filter(f=>f.symbol_id===i.id):[],u=o.length===0?"\u{1F7E2}":o.length<=3?"\u{1F7E1}":"\u{1F534}",p=o.length===0?"\u4F4E":o.length<=3?"\u4E2D":"\u9AD8",d=[`\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",`${u} \u98CE\u9669\u7B49\u7EA7: ${p} (${o.length} \u5904\u76F4\u63A5\u8C03\u7528)`,""];if(o.length>0?(d.push("\u{1F534} \u76F4\u63A5\u5F71\u54CD:"),o.forEach((f,m)=>{let g=f.call_type==="template_event"?" \u{1F5BC}\uFE0F [\u6A21\u677F\u4E8B\u4EF6\u5165\u53E3]":f.call_type==="jsx_event"?" \u269B\uFE0F [JSX\u4E8B\u4EF6\u5165\u53E3]":"";d.push(` ${m+1}. ${f.caller_name} [${f.category}]${g} \u{1F4C4} ${f.file_path}:L${f.start_line}`);}),d.push("")):d.push(`\u2705 \u65E0\u8C03\u7528\u8005\uFF0C\u5F71\u54CD\u8303\u56F4\u53EF\u63A7
|
|
372
|
+
`),c.length>0){d.push("\u{1F4E6} \u5916\u90E8\u72B6\u6001\u5F71\u54CD:");for(let f of c)d.push(` \u2022 ${f.api_name}.${f.operation}${f.detail?` key="${f.detail}"`:""} [${f.category}]`);d.push(`
|
|
373
|
+
\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:d.join(`
|
|
361
374
|
`)}]}}),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
|
|
362
|
-
\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(
|
|
375
|
+
\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(Q),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 p=e.listProjects();if(p.length===0)return {content:[{type:"text",text:`\u{1F4CB} \u5F53\u524D\u6CA1\u6709\u5DF2\u7D22\u5F15\u7684\u9879\u76EE
|
|
363
376
|
|
|
364
|
-
\u4F7F\u7528 skimmer_index_project({ project_path: "/your/project" }) \u5F00\u59CB\u7D22\u5F15`}]};let
|
|
365
|
-
`];return
|
|
366
|
-
`)}]}}let{db:
|
|
377
|
+
\u4F7F\u7528 skimmer_index_project({ project_path: "/your/project" }) \u5F00\u59CB\u7D22\u5F15`}]};let d=[`\u{1F4CB} \u5DF2\u7D22\u5F15\u7684\u9879\u76EE (${p.length} \u4E2A):
|
|
378
|
+
`];return p.forEach((f,m)=>{d.push(`${m+1}. ${f.root}`),d.push(` \u6570\u636E\u5E93: ${f.dbPath}`);}),{content:[{type:"text",text:d.join(`
|
|
379
|
+
`)}]}}let{db:s,projectRoot:r}=e.getContext(t),o=s.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} ${r}`,"",`\u{1F4C8} \u6574\u4F53: \u6587\u4EF6 ${o.fileCount} | \u7B26\u53F7 ${o.symbolCount} | \u884C\u4E3A\u6807\u7B7E ${o.behaviorCount} | \u8C03\u7528\u5173\u7CFB ${o.relationCount}`,""],a=o.frameworkBreakdown;if(a?.length){let p={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 d of a)i.push(` ${p[d.framework]||d.framework}: ${d.count} \u4E2A`);i.push("");}let c=o.topFiles;c?.length&&(i.push("\u{1F5C2}\uFE0F Top 10 \u6700\u5927\u6587\u4EF6:"),c.forEach((p,d)=>i.push(` ${d+1}. ${p.path} (${p.line_count} \u884C, ${p.symbol_count} \u7B26\u53F7)`)),i.push(""));let u=o.behaviorStats;if(u?.length){let p={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 d of u)i.push(` ${p[d.category]||d.category}: ${d.count} \u5904`);i.push("");}return i.push(`\u{1F4BD} \u6570\u636E\u5E93: ${Math.round(o.dbSize/1024)} KB`),{content:[{type:"text",text:i.join(`
|
|
367
380
|
`)}]}}),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
|
|
368
381
|
|
|
369
382
|
\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
|
|
@@ -382,15 +395,20 @@ project_path \u53EF\u7701\u7565\u3002`,inputSchema:z$1.object({project_path:z$1.
|
|
|
382
395
|
\u65E7\u65B9\u5F0F: trace_assignments \u2192 find_symbol \u2192 get_code_slice \u2192 find_by_behavior \u2192 trace_key_flow
|
|
383
396
|
\u65B0\u65B9\u5F0F: skimmer_trace_data_lifecycle({ variable: "xxx" }) \u2190 \u76F4\u63A5\u5F97\u5230\u5168\u90E8
|
|
384
397
|
|
|
385
|
-
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(
|
|
386
|
-
|
|
387
|
-
`)
|
|
388
|
-
|
|
398
|
+
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(Q),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:s,storage_api:r,max_depth:o,limit:i})=>{let{db:a}=e.getContext(n),c=Math.min(5,Math.max(1,o||2)),u=Math.min(120,Math.max(1,i||40)),p=a.listFiles(s),d="";try{let N=s?p:p.slice(0,5),k=[];for(let _ of N){if(!_.abs_path||!F.existsSync(_.abs_path))continue;let L=F.statSync(_.abs_path),R=a.getFileMeta(_.path);if(!R)continue;(R.mtime>0&&L.mtimeMs>R.mtime||R.fileSize>0&&L.size!==R.fileSize)&&k.push(_.path);}k.length>0&&(d=`\u26A0\uFE0F [\u7D22\u5F15\u5DF2\u8FC7\u671F] \u4EE5\u4E0B\u6587\u4EF6\u5DF2\u4FEE\u6539\u4F46\u7D22\u5F15\u672A\u66F4\u65B0\uFF0C\u2462 \u53C2\u6570\u4F20\u9012 \u548C \u2464 storage \u94FE\u8DEF\u7684\u884C\u53F7\u53EF\u80FD\u504F\u79FB:
|
|
399
|
+
`+k.slice(0,3).map(_=>` \u2022 ${_}`).join(`
|
|
400
|
+
`)+`
|
|
401
|
+
\u5EFA\u8BAE: skimmer_index_project({ force: true })
|
|
402
|
+
`);}catch{}let f=Wt(p,t,20),m=[...new Set(f.map(N=>N.alias).filter(N=>N!==t))],g=Dt(p,t,20),E=[...new Set(g.map(N=>N.alias).filter(N=>N!==t))],h=[...new Set([...m,...E])],S=[t,...h],b=a.exactSearch(t,"state",void 0,s||void 0),T={vue2:"Vue2 data()",vue3:"Vue3 ref/reactive",react:"React useState/useRef"},v=b.filter(N=>N.default_value!=null).map(N=>({filePath:N.file_path,line:N.start_line,kind:`data_init(${T[N.framework]||N.framework})`,text:`${N.name}: ${N.default_value} \u2190 \u58F0\u660E\u521D\u59CB\u5316`})),C=ot(p,t,false,u);for(let N of h)C.push(...ot(p,N,false,Math.floor(u/2)));let P=C.length===0?de(p,Ot(t,false),u):[],O=new Map;for(let N of [...v,...C.length>0?C:P]){let k=`${N.filePath}:${N.line}`;O.has(k)||O.set(k,N);}let M=[...O.values()],ae=Fe(p,t,void 0,u);for(let N of h)ae.push(...Fe(p,N,void 0,Math.floor(u/2)));let Kt=ae.length===0?de(p,[{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`)}],u):[],Ee=ae.length>0?ae:Kt,ne=a.findRelationsByArgKeyword(t,s,u);for(let N of h)ne.push(...a.findRelationsByArgKeyword(N,s,Math.floor(u/2)));let it=[],at=[],ct=[];for(let N of S){let k=be(N),_=/^[a-zA-Z_$][\w$]*$/.test(N)?"\\b":"";it.push({kind:"template",regex:new RegExp(`(?::\\w+|v-model|v-if|v-show|@\\w+)="[^"]*${_}${k}${_}|\\{\\{[^}]*${_}${k}${_}[^}]*\\}\\}`)},{kind:"return",regex:new RegExp(`\\breturn\\b[^=]*${_}${k}${_}`)},{kind:"watch",regex:new RegExp(`watch[^(]*['"]\\.?${k}['"]`)},{kind:"computed_read",regex:new RegExp(`=>[^=]*${_}${k}${_}|return[^=]*${_}${k}${_}`)},{kind:"arg_usage",regex:new RegExp(`\\(\\s*[^)]*${_}${k}${_}[^)]*\\)`)}),at.push(`${_}${k}${_}\\s*(?:=|\\+=|-=|\\*=|\\/=)(?!=)|\\b(?:const|let|var)\\s+${k}\\b`),ct.push(`${_}${k}${_}\\.\\w+\\s*(?:=|\\+=|-=)(?!=)|${_}${k}${_}\\s*\\[`);}let Vt=de(p,it,u),zt=new RegExp(at.join("|")),Xt=new RegExp(ct.join("|")),Ne=Vt.filter(N=>!zt.test(N.text)&&!Xt.test(N.text)),He=new Map,Jt=(N,k)=>{if(!He.has(N)){let{behaviors:L}=a.getFileOutline(N),R=new Map;for(let I of L){let K=String(I.symbol_name||"");R.has(K)||R.set(K,[]),R.get(K).push(I);}He.set(N,R);}return (He.get(N)?.get(k)||[]).filter(L=>String(L.category||"")!=="storage"?false:r==="all"?true:String(L.api_name||"").toLowerCase()===r.toLowerCase())},Gt=(N,k)=>{let _=[],L=[{name:N,filePath:k,path:[N],level:0}],R=new Set([`${k}::${N}`]);for(;L.length>0;){let I=L.shift(),K=Jt(I.filePath,I.name);if(K.length>0){_.push({path:I.path,file:I.filePath,behaviors:K});continue}if(I.level>=c)continue;let D=a.getSymbolByName(I.name,I.filePath);if(D||(D=a.getSymbolByName(I.name)),!D)continue;let se=String(D.file_path||D.abs_path||I.filePath),Se=a.getCallees(D.id);for(let Be of Se){let X=String(Be.callee_name||"");if(!X||X.startsWith("$"))continue;let lt=`${se}::${X}`;R.has(lt)||(R.add(lt),L.push({name:X,filePath:se,path:[...I.path,X],level:I.level+1}));}}return _},Yt=h.length>0?`
|
|
403
|
+
\u{1F517} \u53D1\u73B0\u522B\u540D: ${h.map(N=>`"${N}"`).join(", ")}\uFF08\u5DF2\u4E00\u5E76\u8FFD\u8E2A\u5C5E\u6027\u4FEE\u6539\uFF09`:"",ce=[];g.length>0&&(ce.push(` \u{1F517} \u5F15\u7528\u522B\u540D\u4F20\u64AD (${g.length} \u5904) \u2014 \u8FD9\u4E9B\u5C40\u90E8\u53D8\u91CF\u662F "${t}" \u7684\u5F15\u7528\uFF0C\u5176\u5C5E\u6027\u4FEE\u6539\u4E5F\u88AB\u8FFD\u8E2A:`),g.slice(0,10).forEach(N=>{let _=p.find(I=>I.path===N.filePath)?.abs_path||N.abs_path,L=Oe("alias_ref"),R=_?rt(_,N.line,2):{snippet:""};ce.push(` \u{1F4C4} ${N.filePath}:L${N.line} "${N.alias}" = ... ${L}`),ce.push(` ${N.text}`),R.snippet&&ce.push(R.snippet);}));let $=[`\u{1F52C} \u53D8\u91CF\u751F\u547D\u5468\u671F\u8FFD\u8E2A: "${t}"`,"\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501",`\u8FC7\u6EE4: file_path=${s||"*"} storage_api=${r} depth=${c}${Yt}`,""];if(d&&$.push(d),$.push(`\u2460 \u58F0\u660E & \u6574\u4F53\u8D4B\u503C (${M.length} \u5904)`),M.length===0)$.push(" \uFF08\u672A\u627E\u5230\uFF09");else {let N={init:[],cache:[],user:[],unknown:[]};for(let _ of M){let L=jt(_.text,_.line);N[L].push(_);}let k=["init","cache","user","unknown"];for(let _ of k){let L=N[_];!L||L.length===0||($.push(` \u25B8 ${Mt[_]} (${L.length} \u5904)`),L.slice(0,8).forEach(R=>{let I=h.includes(R.text.split("=")[0]?.trim().replace(/^(?:const|let|var)\s+/,"")||""),K=Oe(R.kind,I);$.push(` \u{1F4C4} ${R.filePath}:L${R.line} [${R.kind}] ${K}`),$.push(` ${R.text}`);}));}ce.length>0&&($.push(""),$.push(...ce));}if($.push(""),$.push(`\u2461 \u5C5E\u6027\u4FEE\u6539 (${Ee.length} \u5904)`),Ee.length===0)$.push(' \uFF08\u672A\u627E\u5230 object.prop \u6216 object["prop"] \u5199\u5165\uFF09'),h.length>0&&$.push(` \u2139\uFE0F \u5DF2\u8FFD\u8E2A\u522B\u540D: ${h.map(N=>`"${N}"`).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 N={init:[],cache:[],user:[],unknown:[]};for(let _ of Ee){let L=jt(_.text,_.line);N[L].push(_);}let k=["init","cache","user","unknown"];for(let _ of k){let L=N[_];!L||L.length===0||($.push(` \u25B8 ${Mt[_]} (${L.length} \u5904)`),L.slice(0,8).forEach(R=>{let I=h.some(X=>R.text.startsWith(X)),K=Oe(R.kind,I),se=p.find(X=>X.path===R.filePath)?.abs_path||"",Se=se?rt(se,R.line,2):{snippet:""},Be=I?" \u{1F517}(via alias)":"";$.push(` \u{1F4C4} ${R.filePath}:L${R.line} [${R.kind}] ${K}${Be}`),Se.snippet&&$.push(Se.snippet);}));}}if($.push(""),$.push(`\u2462 \u4F5C\u4E3A\u53C2\u6570\u88AB\u4F20\u5165\u8C03\u7528 (${ne.length} \u5904)`),ne.length===0?$.push(" \uFF08\u672A\u53D1\u73B0\u4EE5\u8BE5\u53D8\u91CF\u4F5C\u4E3A\u53C2\u6570\u7684\u51FD\u6570\u8C03\u7528\uFF09"):ne.slice(0,20).forEach(N=>{let k=String(N.args||"");$.push(` \u{1F4C4} ${N.file_path}:L${N.line_number} ${N.caller_name} \u2192 ${N.callee_name} \u53C2\u6570: "${k}"`);}),$.push(""),$.push(`\u2463 \u8BFB\u53D6/\u4F7F\u7528 (${Ne.length} \u5904)`),Ne.length===0)$.push(" \uFF08\u672A\u53D1\u73B0 template \u7ED1\u5B9A / watch / computed / return \u4E2D\u7684\u5F15\u7528\uFF09");else {let N=new Map;for(let _ of Ne)N.has(_.kind)||N.set(_.kind,[]),N.get(_.kind).push(_);let k={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[_,L]of N)$.push(` \u25B8 ${k[_]||_}`),L.slice(0,8).forEach(R=>$.push(` \u{1F4C4} ${R.filePath}:L${R.line} ${R.text}`));}$.push("");let fe=0;$.push(`\u2464 Storage \u843D\u70B9\u8FFD\u8E2A (storage_api=${r}, depth=${c})`);let qt=r==="localStorage"?"localStorage":r==="sessionStorage"?"sessionStorage":"(?:localStorage|sessionStorage)",Zt=S.map(N=>({kind:"direct_storage",regex:new RegExp(`${qt}\\.(?:setItem|getItem|removeItem|clear)\\(.*?\\b${be(N)}\\b`)})),_e=de(p,Zt,u);if(_e.length>0&&(fe+=1,$.push(` \u843D\u70B9 [\u76F4\u63A5\u547D\u4E2D\u5B58\u50A8] ${Oe("direct_storage")}:`),_e.slice(0,15).forEach(N=>{let _=p.find(R=>R.path===N.filePath)?.abs_path||"",L=_?rt(_,N.line,2):{snippet:""};$.push(` \u{1F4C4} ${N.filePath}:L${N.line} ${N.text.trim()}`),L.snippet&&$.push(L.snippet);})),ne.length===0&&_e.length===0)$.push(" \uFF08\u672A\u53D1\u73B0\u76F4\u63A5 Storage \u64CD\u4F5C\uFF0C\u4E14\u65E0\u8C03\u7528\u5165\u53E3\u5C55\u5F00\u8FFD\u8E2A\uFF09");else {let N=new Map;for(let k of ne){let _=`${k.file_path}::${k.callee_name}`;N.has(_)||N.set(_,k);}for(let[,k]of N){let _=String(k.callee_name||""),L=String(k.file_path||""),R=Gt(_,L);R.length!==0&&(fe+=1,R.slice(0,3).forEach(I=>{let K=I.file!==L?` \u2197 \u8DE8\u6587\u4EF6: ${I.file}`:"";$.push(` \u94FE\u8DEF: ${I.path.join(" \u2192 ")}${K}`),I.behaviors.forEach(D=>{let se=D.detail?`("${String(D.detail)}")`:"";$.push(` \u843D\u70B9: ${D.api_name}.${D.operation}${se} [${D.category}] L${D.line_number}`);});}));}fe===0&&_e.length===0&&$.push(` \uFF08\u5728 depth=${c} \u5C42\u5185\u672A\u627E\u5230 storage \u5199\u5165\u94FE\u8DEF\uFF09`);}$.push(""),$.push("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501");let Qt=h.length>0?` (\u542B ${h.length} \u4E2A\u522B\u540D: ${h.slice(0,3).map(N=>`"${N}"`).join(", ")})`:"";return $.push(`\u2705 \u6C47\u603B${Qt}:`),$.push(` \u2460 \u58F0\u660E/\u8D4B\u503C: ${M.length} \u5904`),$.push(` \u2461 \u5C5E\u6027\u4FEE\u6539: ${Ee.length} \u5904 (\u5DF2\u8FFD\u8E2A\u522B\u540D: ${h.map(N=>`"${N}"`).join(", ")||"\u65E0"})`),$.push(` \u2462 \u53C2\u6570\u4F20\u9012: ${ne.length} \u5904`),$.push(` \u2463 \u8BFB\u53D6\u5F15\u7528: ${Ne.length} \u5904`),$.push(` \u2464 storage: ${fe>0?`\u2713 \u53D1\u73B0\u5199\u5165\u94FE\u8DEF (${fe} \u6761)`:"\u2717 \u672A\u53D1\u73B0"}`),$.push(""),$.push("\u{1F4A1} \u6765\u6E90\u5206\u5C42\u8BF4\u660E: \u{1F331}\u521D\u59CB\u5316 = lifecycle/data | \u{1F4BE}\u7F13\u5B58\u56DE\u663E = storage\u8BFB/fetch | \u{1F5B1}\uFE0F\u7528\u6237\u4EA4\u4E92 = \u4E8B\u4EF6/watch"),$.push("\u{1F4CA} \u7F6E\u4FE1\u5EA6: \u25CF\u25CF\u25CF\u25CF\u25CF \u226590% \u25CF\u25CF\u25CF\u25CF\u25CB \u226580% \u25CF\u25CF\u25CF\u25CB\u25CB \u226570% \u25CF\u25CF\u25CB\u25CB\u25CB \u226560% \u9700\u4EBA\u5DE5\u9A8C\u8BC1\u884C\u53F7\u786E\u8BA4"),{content:[{type:"text",text:$.join(`
|
|
404
|
+
`)}]}});}var ue=new ke,Ue=new McpServer({name:"frontend-code-skimmer",version:"0.1.0"});Ct(Ue,ue);Pt(Ue,ue);Bt(Ue,ue);async function Pn(){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}
|
|
405
|
+
`);try{let{Indexer:n}=await Promise.resolve().then(()=>(tt(),wt)),{db:s,projectRoot:r}=ue.getContext(process.env.SKIMMER_PROJECT),o=new n(r,s),i=await o.indexProject();process.stderr.write(`[Frontend-Code-Skimmer] \u5B8C\u6210: ${i.indexedFiles} \u6587\u4EF6, ${i.totalSymbols} \u7B26\u53F7
|
|
406
|
+
`);let a=await o.startWatcher();ue.registerWatcher(r,a),process.stderr.write(`[Frontend-Code-Skimmer] \u6587\u4EF6\u76D1\u542C\u5DF2\u542F\u52A8: ${r}
|
|
389
407
|
`);}catch(n){process.stderr.write(`[Frontend-Code-Skimmer] \u7D22\u5F15\u5931\u8D25: ${String(n)}
|
|
390
|
-
`);}}let e=new StdioServerTransport;await
|
|
408
|
+
`);}}let e=new StdioServerTransport;await Ue.connect(e),process.stderr.write(`[Frontend-Code-Skimmer MCP] \u5DF2\u542F\u52A8
|
|
391
409
|
`),process.stderr.write(`[Frontend-Code-Skimmer MCP] \u652F\u6301\u6846\u67B6: Vue 2 / Vue 3 / React Hooks
|
|
392
410
|
`),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
|
|
393
411
|
`),process.env.SKIMMER_PROJECT?process.stderr.write(`[Frontend-Code-Skimmer MCP] \u9ED8\u8BA4\u9879\u76EE: ${process.env.SKIMMER_PROJECT}
|
|
394
412
|
`):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
|
|
395
|
-
`);let t=()=>{
|
|
413
|
+
`);let t=()=>{ue.closeAll(),process.exit(0);};process.on("SIGINT",t),process.on("SIGTERM",t);}Pn().catch(l=>{process.stderr.write(`[Frontend-Code-Skimmer MCP] \u542F\u52A8\u5931\u8D25: ${String(l)}
|
|
396
414
|
`),process.exit(1);});
|
package/package.json
CHANGED