tianxincode 1.0.48 → 1.0.49
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 +200 -200
- package/dist/cli/commands.js +18 -18
- package/dist/core/ai/agents/caller/prompts/role.txt +50 -50
- package/dist/core/ai/agents/chat/chat.agent.js +30 -30
- package/dist/core/ai/agents/chat/prompts/role.txt +30 -30
- package/dist/core/ai/agents/code/code.agent.js +6 -6
- package/dist/core/ai/agents/code/prompts/role.txt +50 -50
- package/dist/core/ai/agents/common/prompt/role.txt +51 -51
- package/dist/core/ai/agents/common/prompts.js +26 -26
- package/dist/core/ai/agents/design/design.agent.js +6 -6
- package/dist/core/ai/agents/design/prompts/role.txt +36 -36
- package/dist/core/ai/agents/dream/prompts/init.txt +20 -20
- package/dist/core/ai/agents/mem/mem.agent.js +5 -5
- package/dist/core/ai/agents/mem/prompts/role.txt +35 -35
- package/dist/core/ai/agents/skill/prompts/role.txt +61 -61
- package/dist/core/ai/agents/skill/skill.agent.js +26 -26
- package/dist/core/ai/agents/summarizer/prompts/role.txt +30 -30
- package/dist/core/ai/agents/task/prompts/role.txt +50 -50
- package/dist/core/ai/agents/task/task.agent.js +30 -30
- package/dist/core/db/db.service.d.ts.map +1 -1
- package/dist/core/db/db.service.js +2 -0
- package/dist/core/db/db.service.js.map +1 -1
- package/dist/core/db/init_sql/ai_log.init.js +15 -15
- package/dist/core/db/init_sql/code_snippet.init.js +11 -11
- package/dist/core/db/init_sql/config.init.js +15 -15
- package/dist/core/db/init_sql/custom_action.init.js +10 -10
- package/dist/core/db/init_sql/dingding.init.js +9 -9
- package/dist/core/db/init_sql/email.init.js +14 -14
- package/dist/core/db/init_sql/lsp.init.js +8 -8
- package/dist/core/db/init_sql/message_file.init.js +11 -11
- package/dist/core/db/init_sql/project.init.js +20 -20
- package/dist/core/db/init_sql/provider.init.js +35 -35
- package/dist/core/db/init_sql/scheduler.init.js +32 -32
- package/dist/core/db/init_sql/session.init.js +23 -23
- package/dist/core/db/init_sql/spec.init.js +15 -15
- package/dist/core/db/init_sql/waf_gateway.init.js +9 -9
- package/dist/core/db/init_sql/zihao.init.js +11 -11
- package/dist/core/lsp/sql.js +11 -11
- package/dist/core/tools/provider/bash.txt +47 -47
- package/dist/core/tools/provider/code_search.txt +20 -20
- package/dist/core/tools/provider/edit_file.txt +13 -13
- package/dist/core/tools/provider/glob.txt +12 -12
- package/dist/core/tools/provider/grep.txt +14 -14
- package/dist/core/tools/provider/lsp.txt +19 -19
- package/dist/core/tools/provider/memory.txt +21 -21
- package/dist/core/tools/provider/read_file.txt +17 -17
- package/dist/core/tools/provider/todo_read.txt +16 -16
- package/dist/core/tools/provider/todo_write.txt +48 -48
- package/dist/core/tools/provider/web_fetch.txt +17 -17
- package/dist/core/tools/provider/web_search.txt +18 -18
- package/dist/core/tools/provider/write_file.txt +11 -11
- package/dist/gateway/api/skill/detail_skill.d.ts.map +1 -1
- package/dist/gateway/api/skill/detail_skill.js +7 -5
- package/dist/gateway/api/skill/detail_skill.js.map +1 -1
- package/dist/gateway/cli/commands.js +18 -18
- package/dist/modules/ai/agents/chat/prompts/role.txt +30 -30
- package/dist/modules/ai/agents/code/prompts/role.txt +50 -50
- package/dist/modules/ai/agents/mem/prompts/role.txt +35 -35
- package/dist/modules/ai/agents/skill/prompts/role.txt +61 -61
- package/dist/modules/ai/agents/task/prompts/role.txt +50 -50
- package/dist/modules/ai/ai-log.service.js +10 -10
- package/dist/modules/ai/provider/openai/prompt/role.txt +51 -51
- package/dist/modules/ai/summarizer/summarizer.prompts.js +30 -30
- package/dist/modules/config/config.service.js +5 -5
- package/dist/modules/db/db.service.js +252 -252
- package/dist/modules/email/email.config.repository.js +1 -1
- package/dist/modules/repositories/project.repository.d.ts +28 -0
- package/dist/modules/repositories/project.repository.d.ts.map +1 -0
- package/dist/modules/repositories/project.repository.js +47 -0
- package/dist/modules/repositories/project.repository.js.map +1 -0
- package/dist/modules/scheduler/task-log.service.js +1 -1
- package/dist/modules/services/project/project.service.d.ts +14 -0
- package/dist/modules/services/project/project.service.d.ts.map +1 -0
- package/dist/modules/services/project/project.service.js +47 -0
- package/dist/modules/services/project/project.service.js.map +1 -0
- package/dist/modules/skill/skill.txt +36 -36
- package/dist/modules/spec/spec.injector.js +24 -24
- package/dist/modules/tools/provider/bash.txt +47 -47
- package/dist/modules/tools/provider/code_search.txt +20 -20
- package/dist/modules/tools/provider/edit_file.txt +13 -13
- package/dist/modules/tools/provider/glob.txt +12 -12
- package/dist/modules/tools/provider/grep.txt +14 -14
- package/dist/modules/tools/provider/lsp.txt +19 -19
- package/dist/modules/tools/provider/memory.txt +21 -21
- package/dist/modules/tools/provider/read_file.txt +17 -17
- package/dist/modules/tools/provider/todo_read.txt +16 -16
- package/dist/modules/tools/provider/todo_write.txt +48 -48
- package/dist/modules/tools/provider/web_fetch.txt +17 -17
- package/dist/modules/tools/provider/web_search.txt +18 -18
- package/dist/modules/tools/provider/write_file.txt +11 -11
- package/dist/modules/waf-gateway/waf-gateway.module.js +8 -8
- package/dist/modules/waf-gateway/waf-gateway.service.js +12 -12
- package/dist/repositories/project.repository.d.ts +28 -0
- package/dist/repositories/project.repository.d.ts.map +1 -0
- package/dist/repositories/project.repository.js +47 -0
- package/dist/repositories/project.repository.js.map +1 -0
- package/dist/repository/ai_log.repository.js +1 -1
- package/dist/repository/config.repository.js +5 -5
- package/dist/repository/email.repository.js +1 -1
- package/dist/repository/memory.repository.js +1 -1
- package/dist/repository/project.repository.js +3 -3
- package/dist/repository/scheduler.repository.js +2 -2
- package/dist/repository/session.repository.js +1 -1
- package/dist/repository/zihao-config.repository.js +1 -1
- package/dist/services/skill/skill.tool.d.ts.map +1 -1
- package/dist/services/skill/skill.tool.js +6 -1
- package/dist/services/skill/skill.tool.js.map +1 -1
- package/dist/services/skill/skill.txt +36 -36
- package/package.json +76 -76
- package/scripts/copy-txt.js +31 -31
- package/scripts/ink-scroll-demo.tsx +147 -147
- package/tsconfig.test.json +9 -9
- package/web/dist/assets/{ConfirmDialog-B2bVsPFI.js → ConfirmDialog-B03GcCHQ.js} +1 -1
- package/web/dist/assets/PcLayout-CYW3zqcs.css +1 -0
- package/web/dist/assets/{PcLayout-DeXNBHu2.js → PcLayout-ZTdJNg7G.js} +1 -1
- package/web/dist/assets/{aiLogsView-JvjhLmyo.js → aiLogsView-Bt8Xg1Qx.js} +1 -1
- package/web/dist/assets/{cssMode-sYHhwUZh.js → cssMode-CBb6D87U.js} +1 -1
- package/web/dist/assets/{customActionsView-Cvmzxvl4.js → customActionsView-DdjnHzwm.js} +1 -1
- package/web/dist/assets/deployView-CD7ji9IS.css +1 -0
- package/web/dist/assets/{deployView-CjV4ySrf.js → deployView-Cj51_Job.js} +1 -1
- package/web/dist/assets/designView-C3pSX4nP.css +1 -0
- package/web/dist/assets/designView-RT8tKEN9.js +18 -0
- package/web/dist/assets/devWorkflowView-BTozmaiN.js +36 -0
- package/web/dist/assets/devWorkflowView-DYhIfbCB.css +1 -0
- package/web/dist/assets/devWorkflowViewApp-CErbhC2s.css +1 -0
- package/web/dist/assets/{devWorkflowViewApp-DPlFgiS_.js → devWorkflowViewApp-DLslXEq9.js} +3 -3
- package/web/dist/assets/{fileZihao-DvZmuTYu.js → fileZihao-CtZ4bUIH.js} +1 -1
- package/web/dist/assets/{freemarker2-DTyAQBBj.js → freemarker2-CX3jc3l2.js} +1 -1
- package/web/dist/assets/gitChanges-D6QxPcii.css +1 -0
- package/web/dist/assets/{gitChanges-Cpf4HHoF.js → gitChanges-DFRvzL5I.js} +1 -1
- package/web/dist/assets/gitChangesApp-Bjn-MCmr.css +1 -0
- package/web/dist/assets/{gitChangesApp-BOURDd_l.js → gitChangesApp-ZI7-V8oB.js} +2 -2
- package/web/dist/assets/{handlebars-DiWIXxOG.js → handlebars-CTaQD6FN.js} +1 -1
- package/web/dist/assets/{html-BCQWkFzH.js → html-BruJsfYv.js} +1 -1
- package/web/dist/assets/{htmlMode-BbMA34cR.js → htmlMode-wewroXLr.js} +1 -1
- package/web/dist/assets/{index-C_tz4Wda.css → index-C0xmVTIn.css} +1 -1
- package/web/dist/assets/{index-C7axH05o.js → index-Cn73hS12.js} +9 -9
- package/web/dist/assets/{javascript-By4MYHaO.js → javascript-B4ku8P1-.js} +1 -1
- package/web/dist/assets/{jsonMode-5JIz7tDN.js → jsonMode-BIvVuBMG.js} +1 -1
- package/web/dist/assets/{liquid-BQBVii4f.js → liquid-Bo3G0Ep7.js} +1 -1
- package/web/dist/assets/{mdx-Cwk7nqzM.js → mdx-Duv0ylZz.js} +1 -1
- package/web/dist/assets/{mediaChat-DivTDoIv.js → mediaChat-RT7iqqYb.js} +1 -1
- package/web/dist/assets/{python-L_kGfe1T.js → python-CEhCctGm.js} +1 -1
- package/web/dist/assets/{razor-XGuHliMI.js → razor-DPK8nTD7.js} +1 -1
- package/web/dist/assets/{taskView-BcJ3LAxp.js → taskView-sOyebRqn.js} +1 -1
- package/web/dist/assets/{terminalView-q-UKzK0M.js → terminalView-GTYtDlus.js} +2 -2
- package/web/dist/assets/{terminalView-CQVYh6D3.css → terminalView-eZ0agsPP.css} +1 -1
- package/web/dist/assets/{tsMode-SuiD3mJa.js → tsMode-BZvUU1nf.js} +1 -1
- package/web/dist/assets/{typescript-DJcyqRjT.js → typescript-CmEn-k1B.js} +1 -1
- package/web/dist/assets/{wikiView-ygHSGyPp.css → wikiView-C-oqMnJM.css} +1 -1
- package/web/dist/assets/{wikiView-B3GIPUlD.js → wikiView-CRjg-cZ8.js} +1 -1
- package/web/dist/assets/{xml-DQgCzk55.js → xml-bjvdKeyy.js} +1 -1
- package/web/dist/assets/{yaml-DBdEYBPA.js → yaml-N5RXWxJk.js} +1 -1
- package/web/dist/index.html +2 -2
- package/web/package.json +28 -28
- package/dist/modules/ai/react/index.d.ts +0 -5
- package/dist/modules/ai/react/index.d.ts.map +0 -1
- package/dist/modules/ai/react/index.js +0 -4
- package/dist/modules/ai/react/index.js.map +0 -1
- package/dist/modules/ai/react/prompt/role.txt +0 -51
- package/dist/modules/ai/react/provider.parser.d.ts +0 -20
- package/dist/modules/ai/react/provider.parser.d.ts.map +0 -1
- package/dist/modules/ai/react/provider.parser.js +0 -88
- package/dist/modules/ai/react/provider.parser.js.map +0 -1
- package/dist/modules/ai/react/react.parser.d.ts +0 -80
- package/dist/modules/ai/react/react.parser.d.ts.map +0 -1
- package/dist/modules/ai/react/react.parser.js +0 -365
- package/dist/modules/ai/react/react.parser.js.map +0 -1
- package/dist/modules/ai/react/react.prompts.d.ts +0 -26
- package/dist/modules/ai/react/react.prompts.d.ts.map +0 -1
- package/dist/modules/ai/react/react.prompts.js +0 -170
- package/dist/modules/ai/react/react.prompts.js.map +0 -1
- package/dist/modules/ai/react/react.types.d.ts +0 -50
- package/dist/modules/ai/react/react.types.d.ts.map +0 -1
- package/dist/modules/ai/react/react.types.js +0 -2
- package/dist/modules/ai/react/react.types.js.map +0 -1
- package/dist/modules/ai/react/react.validator.d.ts +0 -14
- package/dist/modules/ai/react/react.validator.d.ts.map +0 -1
- package/dist/modules/ai/react/react.validator.js +0 -53
- package/dist/modules/ai/react/react.validator.js.map +0 -1
- package/dist/modules/ai/react.agent.d.ts +0 -82
- package/dist/modules/ai/react.agent.d.ts.map +0 -1
- package/dist/modules/ai/react.agent.js +0 -220
- package/dist/modules/ai/react.agent.js.map +0 -1
- package/dist/modules/skill/skill.service.d.ts +0 -72
- package/dist/modules/skill/skill.service.d.ts.map +0 -1
- package/dist/modules/skill/skill.service.js +0 -283
- package/dist/modules/skill/skill.service.js.map +0 -1
- package/dist/modules/tools/builtin/bash.d.ts +0 -3
- package/dist/modules/tools/builtin/bash.d.ts.map +0 -1
- package/dist/modules/tools/builtin/bash.js +0 -126
- package/dist/modules/tools/builtin/bash.js.map +0 -1
- package/dist/modules/tools/builtin/bash.tool.d.ts +0 -6
- package/dist/modules/tools/builtin/bash.tool.d.ts.map +0 -1
- package/dist/modules/tools/builtin/bash.tool.js +0 -52
- package/dist/modules/tools/builtin/bash.tool.js.map +0 -1
- package/dist/modules/tools/builtin/bash.txt +0 -69
- package/dist/modules/tools/builtin/code_search.d.ts +0 -3
- package/dist/modules/tools/builtin/code_search.d.ts.map +0 -1
- package/dist/modules/tools/builtin/code_search.js +0 -86
- package/dist/modules/tools/builtin/code_search.js.map +0 -1
- package/dist/modules/tools/builtin/code_search.txt +0 -41
- package/dist/modules/tools/builtin/edit-file.tool.d.ts +0 -6
- package/dist/modules/tools/builtin/edit-file.tool.d.ts.map +0 -1
- package/dist/modules/tools/builtin/edit-file.tool.js +0 -58
- package/dist/modules/tools/builtin/edit-file.tool.js.map +0 -1
- package/dist/modules/tools/builtin/edit_file.d.ts +0 -3
- package/dist/modules/tools/builtin/edit_file.d.ts.map +0 -1
- package/dist/modules/tools/builtin/edit_file.js +0 -105
- package/dist/modules/tools/builtin/edit_file.js.map +0 -1
- package/dist/modules/tools/builtin/edit_file.txt +0 -61
- package/dist/modules/tools/builtin/glob.d.ts +0 -3
- package/dist/modules/tools/builtin/glob.d.ts.map +0 -1
- package/dist/modules/tools/builtin/glob.js +0 -85
- package/dist/modules/tools/builtin/glob.js.map +0 -1
- package/dist/modules/tools/builtin/glob.tool.d.ts +0 -6
- package/dist/modules/tools/builtin/glob.tool.d.ts.map +0 -1
- package/dist/modules/tools/builtin/glob.tool.js +0 -81
- package/dist/modules/tools/builtin/glob.tool.js.map +0 -1
- package/dist/modules/tools/builtin/glob.txt +0 -33
- package/dist/modules/tools/builtin/grep.d.ts +0 -3
- package/dist/modules/tools/builtin/grep.d.ts.map +0 -1
- package/dist/modules/tools/builtin/grep.js +0 -94
- package/dist/modules/tools/builtin/grep.js.map +0 -1
- package/dist/modules/tools/builtin/grep.tool.d.ts +0 -6
- package/dist/modules/tools/builtin/grep.tool.d.ts.map +0 -1
- package/dist/modules/tools/builtin/grep.tool.js +0 -96
- package/dist/modules/tools/builtin/grep.tool.js.map +0 -1
- package/dist/modules/tools/builtin/grep.txt +0 -37
- package/dist/modules/tools/builtin/index.d.ts +0 -8
- package/dist/modules/tools/builtin/index.d.ts.map +0 -1
- package/dist/modules/tools/builtin/index.js +0 -80
- package/dist/modules/tools/builtin/index.js.map +0 -1
- package/dist/modules/tools/builtin/lsp.d.ts +0 -7
- package/dist/modules/tools/builtin/lsp.d.ts.map +0 -1
- package/dist/modules/tools/builtin/lsp.js +0 -126
- package/dist/modules/tools/builtin/lsp.js.map +0 -1
- package/dist/modules/tools/builtin/lsp.txt +0 -45
- package/dist/modules/tools/builtin/memory.d.ts +0 -3
- package/dist/modules/tools/builtin/memory.d.ts.map +0 -1
- package/dist/modules/tools/builtin/memory.js +0 -77
- package/dist/modules/tools/builtin/memory.js.map +0 -1
- package/dist/modules/tools/builtin/memory.txt +0 -58
- package/dist/modules/tools/builtin/read-file.tool.d.ts +0 -6
- package/dist/modules/tools/builtin/read-file.tool.d.ts.map +0 -1
- package/dist/modules/tools/builtin/read-file.tool.js +0 -46
- package/dist/modules/tools/builtin/read-file.tool.js.map +0 -1
- package/dist/modules/tools/builtin/read_file.d.ts +0 -3
- package/dist/modules/tools/builtin/read_file.d.ts.map +0 -1
- package/dist/modules/tools/builtin/read_file.js +0 -107
- package/dist/modules/tools/builtin/read_file.js.map +0 -1
- package/dist/modules/tools/builtin/read_file.txt +0 -38
- package/dist/modules/tools/builtin/todo_read.d.ts +0 -6
- package/dist/modules/tools/builtin/todo_read.d.ts.map +0 -1
- package/dist/modules/tools/builtin/todo_read.js +0 -25
- package/dist/modules/tools/builtin/todo_read.js.map +0 -1
- package/dist/modules/tools/builtin/todo_read.txt +0 -34
- package/dist/modules/tools/builtin/todo_write.d.ts +0 -6
- package/dist/modules/tools/builtin/todo_write.d.ts.map +0 -1
- package/dist/modules/tools/builtin/todo_write.js +0 -46
- package/dist/modules/tools/builtin/todo_write.js.map +0 -1
- package/dist/modules/tools/builtin/todo_write.txt +0 -67
- package/dist/modules/tools/builtin/web_fetch.d.ts +0 -3
- package/dist/modules/tools/builtin/web_fetch.d.ts.map +0 -1
- package/dist/modules/tools/builtin/web_fetch.js +0 -52
- package/dist/modules/tools/builtin/web_fetch.js.map +0 -1
- package/dist/modules/tools/builtin/web_fetch.txt +0 -38
- package/dist/modules/tools/builtin/web_search.d.ts +0 -3
- package/dist/modules/tools/builtin/web_search.d.ts.map +0 -1
- package/dist/modules/tools/builtin/web_search.js +0 -100
- package/dist/modules/tools/builtin/web_search.js.map +0 -1
- package/dist/modules/tools/builtin/web_search.txt +0 -43
- package/dist/modules/tools/builtin/write-file.tool.d.ts +0 -6
- package/dist/modules/tools/builtin/write-file.tool.d.ts.map +0 -1
- package/dist/modules/tools/builtin/write-file.tool.js +0 -38
- package/dist/modules/tools/builtin/write-file.tool.js.map +0 -1
- package/dist/modules/tools/builtin/write_file.d.ts +0 -3
- package/dist/modules/tools/builtin/write_file.d.ts.map +0 -1
- package/dist/modules/tools/builtin/write_file.js +0 -61
- package/dist/modules/tools/builtin/write_file.js.map +0 -1
- package/dist/modules/tools/builtin/write_file.txt +0 -58
- package/dist/modules/tools/provider/openai/tools.d.ts +0 -3
- package/dist/modules/tools/provider/openai/tools.d.ts.map +0 -1
- package/dist/modules/tools/provider/openai/tools.js +0 -212
- package/dist/modules/tools/provider/openai/tools.js.map +0 -1
- package/dist/modules/tools/provider/skill.d.ts +0 -6
- package/dist/modules/tools/provider/skill.d.ts.map +0 -1
- package/dist/modules/tools/provider/skill.js +0 -64
- package/dist/modules/tools/provider/skill.js.map +0 -1
- package/web/dist/assets/PcLayout-L-XuK1oQ.css +0 -1
- package/web/dist/assets/deployView-hCh3_M8H.css +0 -1
- package/web/dist/assets/designView-CqZ75hOS.css +0 -1
- package/web/dist/assets/designView-DrUNRVEE.js +0 -18
- package/web/dist/assets/devWorkflowView-BpdJTMEb.js +0 -36
- package/web/dist/assets/devWorkflowView-D7EKjoLj.css +0 -1
- package/web/dist/assets/devWorkflowViewApp-BYYMIdCm.css +0 -1
- package/web/dist/assets/gitChanges-BYj-Y2K-.css +0 -1
- package/web/dist/assets/gitChangesApp-Btw-XKcP.css +0 -1
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Skill 服务
|
|
3
|
-
*
|
|
4
|
-
* 职责:
|
|
5
|
-
* - Skill 加载和解析
|
|
6
|
-
* - Skill 管理
|
|
7
|
-
* - Skill 执行
|
|
8
|
-
*/
|
|
9
|
-
import * as fs from 'fs';
|
|
10
|
-
import * as path from 'path';
|
|
11
|
-
import * as yaml from 'js-yaml';
|
|
12
|
-
export class SkillService {
|
|
13
|
-
constructor(skillsDir) {
|
|
14
|
-
this.skills = new Map();
|
|
15
|
-
this.skillsDir = skillsDir || this.getDefaultSkillsDir();
|
|
16
|
-
this.loadBuiltinSkills();
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* 获取默认 Skills 目录
|
|
20
|
-
*/
|
|
21
|
-
getDefaultSkillsDir() {
|
|
22
|
-
const home = process.env.HOME || process.env.USERPROFILE || '.';
|
|
23
|
-
return path.join(home, '.txcode', 'skills');
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* 加载内置 Skills
|
|
27
|
-
*/
|
|
28
|
-
loadBuiltinSkills() {
|
|
29
|
-
const builtinSkills = this.getBuiltinSkills();
|
|
30
|
-
for (const skill of builtinSkills) {
|
|
31
|
-
this.skills.set(skill.name, skill);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* 获取内置 Skills
|
|
36
|
-
*/
|
|
37
|
-
getBuiltinSkills() {
|
|
38
|
-
return [
|
|
39
|
-
{
|
|
40
|
-
name: 'code_review',
|
|
41
|
-
description: '代码审查:分析代码质量,找出问题和改进点',
|
|
42
|
-
instructions: `你是一个代码审查专家。请对提供的代码进行全面审查:
|
|
43
|
-
|
|
44
|
-
1. **代码质量**:检查命名规范、代码风格、可读性
|
|
45
|
-
2. **潜在问题**:查找 bug、安全漏洞、性能问题
|
|
46
|
-
3. **最佳实践**:检查是否遵循最佳实践
|
|
47
|
-
4. **改进建议**:提供具体的改进建议
|
|
48
|
-
|
|
49
|
-
请用中文回复,格式清晰,重点突出。`,
|
|
50
|
-
tools: ['read_file', 'search_content', 'find_files'],
|
|
51
|
-
examples: [
|
|
52
|
-
{
|
|
53
|
-
input: '请审查 src/utils.ts 文件',
|
|
54
|
-
output: '我将对 src/utils.ts 进行代码审查...',
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
name: 'refactor',
|
|
60
|
-
description: '代码重构:重构代码以提高质量和可维护性',
|
|
61
|
-
instructions: `你是一个代码重构专家。请帮助重构代码:
|
|
62
|
-
|
|
63
|
-
1. **分析现状**:理解代码当前结构和问题
|
|
64
|
-
2. **重构方案**:提出重构方案和理由
|
|
65
|
-
3. **逐步实施**:小步重构,确保每步正确
|
|
66
|
-
4. **验证结果**:确保重构后功能不变
|
|
67
|
-
|
|
68
|
-
重构原则:
|
|
69
|
-
- 保持小步前进
|
|
70
|
-
- 每步都可测试
|
|
71
|
-
- 遵循 SOLID 原则
|
|
72
|
-
- 提高代码可读性`,
|
|
73
|
-
tools: ['read_file', 'write_file', 'edit_file', 'search_content'],
|
|
74
|
-
examples: [
|
|
75
|
-
{
|
|
76
|
-
input: '重构 src/handler.ts 使其更易维护',
|
|
77
|
-
output: '我将分析并重构 src/handler.ts...',
|
|
78
|
-
},
|
|
79
|
-
],
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
name: 'debug',
|
|
83
|
-
description: '调试问题:分析和修复代码中的问题',
|
|
84
|
-
instructions: `你是一个调试专家。请帮助定位和修复问题:
|
|
85
|
-
|
|
86
|
-
1. **复现问题**:理解问题的具体表现
|
|
87
|
-
2. **定位原因**:通过日志、断点、代码分析找到原因
|
|
88
|
-
3. **修复方案**:提出修复方案并实施
|
|
89
|
-
4. **验证修复**:确保问题已解决
|
|
90
|
-
|
|
91
|
-
调试技巧:
|
|
92
|
-
- 从错误信息入手
|
|
93
|
-
- 检查最近修改的代码
|
|
94
|
-
- 使用二分法定位问题
|
|
95
|
-
- 添加日志输出`,
|
|
96
|
-
tools: ['read_file', 'search_content', 'execute_bash', 'find_files'],
|
|
97
|
-
examples: [
|
|
98
|
-
{
|
|
99
|
-
input: '用户登录时报 500 错误,请帮忙调试',
|
|
100
|
-
output: '我来帮你调试这个登录错误...',
|
|
101
|
-
},
|
|
102
|
-
],
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
name: 'write_tests',
|
|
106
|
-
description: '编写测试:为代码编写单元测试',
|
|
107
|
-
instructions: `你是一个测试专家。请帮助编写高质量的测试:
|
|
108
|
-
|
|
109
|
-
1. **分析代码**:理解需要测试的功能
|
|
110
|
-
2. **设计用例**:覆盖正常、边界、异常情况
|
|
111
|
-
3. **编写测试**:使用项目现有的测试框架
|
|
112
|
-
4. **确保覆盖**:测试关键路径和边界条件
|
|
113
|
-
|
|
114
|
-
测试原则:
|
|
115
|
-
- AAA 模式(Arrange-Act-Assert)
|
|
116
|
-
- 每个测试只测一个场景
|
|
117
|
-
- 测试名称要清晰描述场景
|
|
118
|
-
- 使用 mock 隔离外部依赖`,
|
|
119
|
-
tools: ['read_file', 'write_file', 'search_content', 'execute_bash'],
|
|
120
|
-
examples: [
|
|
121
|
-
{
|
|
122
|
-
input: '为 src/utils.ts 编写测试',
|
|
123
|
-
output: '我来为 src/utils.ts 编写测试...',
|
|
124
|
-
},
|
|
125
|
-
],
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
name: 'explain',
|
|
129
|
-
description: '解释代码:详细解释代码的工作原理',
|
|
130
|
-
instructions: `你是一个代码解释专家。请详细解释代码:
|
|
131
|
-
|
|
132
|
-
1. **整体结构**:先概述代码的整体结构
|
|
133
|
-
2. **关键组件**:解释主要函数、类、模块
|
|
134
|
-
3. **执行流程**:描述代码的执行流程
|
|
135
|
-
4. **设计思路**:解释背后的设计思路
|
|
136
|
-
|
|
137
|
-
解释方式:
|
|
138
|
-
- 从整体到局部
|
|
139
|
-
- 用通俗易懂的语言
|
|
140
|
-
- 配合示例说明
|
|
141
|
-
- 指出关键细节`,
|
|
142
|
-
tools: ['read_file', 'search_content', 'find_files'],
|
|
143
|
-
examples: [
|
|
144
|
-
{
|
|
145
|
-
input: '解释 src/main.ts 的工作原理',
|
|
146
|
-
output: '我来解释 src/main.ts 的工作原理...',
|
|
147
|
-
},
|
|
148
|
-
],
|
|
149
|
-
},
|
|
150
|
-
];
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* 从文件加载 Skill
|
|
154
|
-
*/
|
|
155
|
-
loadSkillFromFile(filePath) {
|
|
156
|
-
try {
|
|
157
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
158
|
-
const skill = this.parseSkill(content);
|
|
159
|
-
if (skill) {
|
|
160
|
-
this.skills.set(skill.name, skill);
|
|
161
|
-
}
|
|
162
|
-
return skill;
|
|
163
|
-
}
|
|
164
|
-
catch {
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* 从目录加载 Skills
|
|
170
|
-
*/
|
|
171
|
-
loadSkillsFromDir(dirPath) {
|
|
172
|
-
const targetDir = dirPath || this.skillsDir;
|
|
173
|
-
if (!fs.existsSync(targetDir)) {
|
|
174
|
-
return 0;
|
|
175
|
-
}
|
|
176
|
-
const files = fs.readdirSync(targetDir);
|
|
177
|
-
let count = 0;
|
|
178
|
-
for (const file of files) {
|
|
179
|
-
if (file.endsWith('.yaml') || file.endsWith('.yml')) {
|
|
180
|
-
const skill = this.loadSkillFromFile(path.join(targetDir, file));
|
|
181
|
-
if (skill)
|
|
182
|
-
count++;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return count;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* 解析 Skill
|
|
189
|
-
*/
|
|
190
|
-
parseSkill(content) {
|
|
191
|
-
try {
|
|
192
|
-
const data = yaml.load(content);
|
|
193
|
-
if (data && data.name && data.instructions) {
|
|
194
|
-
return {
|
|
195
|
-
name: data.name,
|
|
196
|
-
description: data.description || '',
|
|
197
|
-
instructions: data.instructions,
|
|
198
|
-
tools: data.tools || [],
|
|
199
|
-
examples: data.examples || [],
|
|
200
|
-
metadata: data.metadata,
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
catch { }
|
|
205
|
-
return null;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* 获取 Skill
|
|
209
|
-
*/
|
|
210
|
-
get(name) {
|
|
211
|
-
return this.skills.get(name);
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* 获取所有 Skills
|
|
215
|
-
*/
|
|
216
|
-
getAll() {
|
|
217
|
-
return Array.from(this.skills.values());
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* 注册 Skill
|
|
221
|
-
*/
|
|
222
|
-
register(skill) {
|
|
223
|
-
this.skills.set(skill.name, skill);
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* 移除 Skill
|
|
227
|
-
*/
|
|
228
|
-
remove(name) {
|
|
229
|
-
return this.skills.delete(name);
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* 检查 Skill 是否存在
|
|
233
|
-
*/
|
|
234
|
-
has(name) {
|
|
235
|
-
return this.skills.has(name);
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* 获取 Skill 的系统提示
|
|
239
|
-
*/
|
|
240
|
-
getSystemPrompt(skillName) {
|
|
241
|
-
const skill = this.skills.get(skillName);
|
|
242
|
-
if (!skill)
|
|
243
|
-
return undefined;
|
|
244
|
-
let prompt = skill.instructions;
|
|
245
|
-
if (skill.tools && skill.tools.length > 0) {
|
|
246
|
-
prompt += `\n\n可用工具: ${skill.tools.join(', ')}`;
|
|
247
|
-
}
|
|
248
|
-
return prompt;
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* 搜索 Skills
|
|
252
|
-
*/
|
|
253
|
-
search(query) {
|
|
254
|
-
const lowerQuery = query.toLowerCase();
|
|
255
|
-
return this.getAll().filter(skill => skill.name.toLowerCase().includes(lowerQuery) ||
|
|
256
|
-
skill.description.toLowerCase().includes(lowerQuery));
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* 将 Skill 导出为 YAML
|
|
260
|
-
*/
|
|
261
|
-
exportToYaml(skillName) {
|
|
262
|
-
const skill = this.skills.get(skillName);
|
|
263
|
-
if (!skill)
|
|
264
|
-
return undefined;
|
|
265
|
-
const data = {
|
|
266
|
-
name: skill.name,
|
|
267
|
-
description: skill.description,
|
|
268
|
-
instructions: skill.instructions,
|
|
269
|
-
};
|
|
270
|
-
if (skill.tools && skill.tools.length > 0) {
|
|
271
|
-
data.tools = skill.tools;
|
|
272
|
-
}
|
|
273
|
-
if (skill.examples && skill.examples.length > 0) {
|
|
274
|
-
data.examples = skill.examples;
|
|
275
|
-
}
|
|
276
|
-
if (skill.metadata) {
|
|
277
|
-
data.metadata = skill.metadata;
|
|
278
|
-
}
|
|
279
|
-
return yaml.dump(data, { indent: 2 });
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
export const skillService = new SkillService();
|
|
283
|
-
//# sourceMappingURL=skill.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"skill.service.js","sourceRoot":"","sources":["../../../src/modules/skill/skill.service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,IAAI,MAAM,SAAS,CAAC;AAGhC,MAAM,OAAO,YAAY;IAIvB,YAAY,SAAkB;QAHtB,WAAM,GAAuB,IAAI,GAAG,EAAE,CAAC;QAI7C,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzD,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC3B,CAAC;I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AAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACzC,IAAI,CAAC,KAAK;YAAE,OAAO,SAAS,CAAC;QAE7B,MAAM,IAAI,GAAwB;YAChC,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,YAAY,EAAE,KAAK,CAAC,YAAY;SACjC,CAAC;QAEF,IAAI,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1C,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QAC3B,CAAC;QAED,IAAI,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChD,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QACjC,CAAC;QAED,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;YACnB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QACjC,CAAC;QAED,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;IACxC,CAAC;CACF;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../../src/modules/tools/builtin/bash.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAA2B,MAAM,kBAAkB,CAAA;AAyBhE,eAAO,MAAM,QAAQ,EAAE,IA6GtB,CAAA"}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'child_process';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import which from 'which';
|
|
5
|
-
const DEFAULT_TIMEOUT = 120000;
|
|
6
|
-
const MAX_BYTES = 50 * 1024;
|
|
7
|
-
const MAX_LINES = 2000;
|
|
8
|
-
function getShell() {
|
|
9
|
-
if (process.platform === 'win32') {
|
|
10
|
-
const gitPath = which.sync('git', { nothrow: true });
|
|
11
|
-
if (gitPath) {
|
|
12
|
-
const bashPath = path.resolve(path.dirname(gitPath), '..', '..', 'bin', 'bash.exe');
|
|
13
|
-
try {
|
|
14
|
-
if (fs.statSync(bashPath).isFile()) {
|
|
15
|
-
return bashPath;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
catch { }
|
|
19
|
-
}
|
|
20
|
-
return process.env.COMSPEC || 'cmd.exe';
|
|
21
|
-
}
|
|
22
|
-
return process.env.SHELL || '/bin/sh';
|
|
23
|
-
}
|
|
24
|
-
export const bashTool = {
|
|
25
|
-
name: 'bash',
|
|
26
|
-
description: '',
|
|
27
|
-
descriptionFile: 'bash.txt',
|
|
28
|
-
parameters: {
|
|
29
|
-
type: 'object',
|
|
30
|
-
properties: {
|
|
31
|
-
command: {
|
|
32
|
-
type: 'string',
|
|
33
|
-
description: '要执行的命令'
|
|
34
|
-
},
|
|
35
|
-
workdir: {
|
|
36
|
-
type: 'string',
|
|
37
|
-
description: '工作目录(可选,默认为当前目录)'
|
|
38
|
-
},
|
|
39
|
-
timeout: {
|
|
40
|
-
type: 'number',
|
|
41
|
-
description: '超时时间,毫秒(可选,默认 120000 = 2分钟)'
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
required: ['command']
|
|
45
|
-
},
|
|
46
|
-
execute: async (params, context) => {
|
|
47
|
-
const { command, workdir, timeout = DEFAULT_TIMEOUT } = params;
|
|
48
|
-
const cwd = workdir || context.workDir || process.cwd();
|
|
49
|
-
let output = '';
|
|
50
|
-
let exited = false;
|
|
51
|
-
const shell = getShell();
|
|
52
|
-
const isWindows = process.platform === 'win32';
|
|
53
|
-
const shellArg = isWindows && shell.endsWith('bash.exe') ? shell : undefined;
|
|
54
|
-
const proc = spawn(command, {
|
|
55
|
-
shell: shellArg || shell,
|
|
56
|
-
cwd,
|
|
57
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
58
|
-
windowsHide: isWindows
|
|
59
|
-
});
|
|
60
|
-
const killTree = () => {
|
|
61
|
-
if (process.platform === 'win32' && proc.pid) {
|
|
62
|
-
spawn('taskkill', ['/pid', String(proc.pid), '/f', '/t'], { stdio: 'ignore', windowsHide: true });
|
|
63
|
-
}
|
|
64
|
-
else if (proc.pid) {
|
|
65
|
-
try {
|
|
66
|
-
process.kill(-proc.pid, 'SIGTERM');
|
|
67
|
-
}
|
|
68
|
-
catch {
|
|
69
|
-
proc.kill('SIGTERM');
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
proc.stdout?.on('data', (chunk) => {
|
|
74
|
-
output += chunk.toString();
|
|
75
|
-
if (output.length > MAX_BYTES) {
|
|
76
|
-
output = output.slice(0, MAX_BYTES) + '\n\n[output truncated - exceeded ' + MAX_BYTES + ' bytes]';
|
|
77
|
-
killTree();
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
proc.stderr?.on('data', (chunk) => {
|
|
81
|
-
output += chunk.toString();
|
|
82
|
-
});
|
|
83
|
-
const abortHandler = () => {
|
|
84
|
-
killTree();
|
|
85
|
-
};
|
|
86
|
-
context.abortSignal?.addEventListener('abort', abortHandler);
|
|
87
|
-
const timeoutTimer = setTimeout(() => {
|
|
88
|
-
output += '\n\n[command timed out after ' + timeout + 'ms]';
|
|
89
|
-
killTree();
|
|
90
|
-
}, timeout);
|
|
91
|
-
try {
|
|
92
|
-
await new Promise((resolve, reject) => {
|
|
93
|
-
proc.on('exit', (code) => {
|
|
94
|
-
exited = true;
|
|
95
|
-
clearTimeout(timeoutTimer);
|
|
96
|
-
context.abortSignal?.removeEventListener('abort', abortHandler);
|
|
97
|
-
resolve();
|
|
98
|
-
});
|
|
99
|
-
proc.on('error', (err) => {
|
|
100
|
-
exited = true;
|
|
101
|
-
clearTimeout(timeoutTimer);
|
|
102
|
-
context.abortSignal?.removeEventListener('abort', abortHandler);
|
|
103
|
-
reject(err);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
catch (err) {
|
|
108
|
-
return {
|
|
109
|
-
success: false,
|
|
110
|
-
output,
|
|
111
|
-
error: err.message
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
const lines = output.split('\n').length;
|
|
115
|
-
if (lines > MAX_LINES) {
|
|
116
|
-
const truncated = output.split('\n').slice(0, MAX_LINES).join('\n');
|
|
117
|
-
output = truncated + '\n\n[output truncated - exceeded ' + MAX_LINES + ' lines]';
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
success: true,
|
|
121
|
-
output: output || '命令执行成功(无输出)',
|
|
122
|
-
metadata: { exitCode: proc.exitCode }
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
//# sourceMappingURL=bash.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bash.js","sourceRoot":"","sources":["../../../../src/modules/tools/builtin/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAErC,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,eAAe,GAAG,MAAM,CAAA;AAC9B,MAAM,SAAS,GAAG,EAAE,GAAG,IAAI,CAAA;AAC3B,MAAM,SAAS,GAAG,IAAI,CAAA;AAEtB,SAAS,QAAQ;IACf,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;QACpD,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,QAAQ,GAAG,IAAI,CA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AC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM;gBACN,KAAK,EAAE,GAAG,CAAC,OAAO;aACnB,CAAA;QACH,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAA;QACvC,IAAI,KAAK,GAAG,SAAS,EAAE,CAAC;YACtB,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACnE,MAAM,GAAG,SAAS,GAAG,mCAAmC,GAAG,SAAS,GAAG,SAAS,CAAA;QAClF,CAAC;QAED,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,MAAM,IAAI,aAAa;YAC/B,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE;SACtC,CAAA;IACH,CAAC;CACF,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bash.tool.d.ts","sourceRoot":"","sources":["../../../../src/modules/tools/builtin/bash.tool.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,eAAO,MAAM,QAAQ,EAAE,IAqDtB,CAAC"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bash 命令执行工具
|
|
3
|
-
*/
|
|
4
|
-
import { execSync } from 'child_process';
|
|
5
|
-
export const bashTool = {
|
|
6
|
-
name: 'execute_bash',
|
|
7
|
-
description: '执行 shell 命令。支持 git、npm、ls 等常见命令。',
|
|
8
|
-
parameters: {
|
|
9
|
-
type: 'object',
|
|
10
|
-
properties: {
|
|
11
|
-
command: {
|
|
12
|
-
type: 'string',
|
|
13
|
-
description: '要执行的命令',
|
|
14
|
-
},
|
|
15
|
-
workdir: {
|
|
16
|
-
type: 'string',
|
|
17
|
-
description: '工作目录(可选)',
|
|
18
|
-
},
|
|
19
|
-
timeout: {
|
|
20
|
-
type: 'number',
|
|
21
|
-
description: '超时时间(毫秒,可选,默认 120000)',
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
required: ['command'],
|
|
25
|
-
},
|
|
26
|
-
execute: async (params) => {
|
|
27
|
-
const { command, workdir, timeout = 120000 } = params;
|
|
28
|
-
const forbidden = ['rm -rf /', 'sudo', 'chmod 777', '> /dev/sd'];
|
|
29
|
-
if (forbidden.some(f => command.includes(f))) {
|
|
30
|
-
return `错误: 禁止执行的命令`;
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
const result = execSync(command, {
|
|
34
|
-
cwd: workdir,
|
|
35
|
-
timeout,
|
|
36
|
-
encoding: 'utf-8',
|
|
37
|
-
maxBuffer: 10 * 1024 * 1024,
|
|
38
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
39
|
-
});
|
|
40
|
-
return result.trim() || '命令执行成功(无输出)';
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
const stderr = error.stderr?.toString() || '';
|
|
44
|
-
const stdout = error.stdout?.toString() || '';
|
|
45
|
-
if (stderr) {
|
|
46
|
-
return `命令执行错误:\n${stderr}`;
|
|
47
|
-
}
|
|
48
|
-
return `错误: ${error.message}`;
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
//# sourceMappingURL=bash.tool.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bash.tool.js","sourceRoot":"","sources":["../../../../src/modules/tools/builtin/bash.tool.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,MAAM,CAAC,MAAM,QAAQ,GAAS;IAC5B,IAAI,EAAE,cAAc;IACpB,WAAW,EAAE,kCAAkC;IAC/C,U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AAC;gBACX,OAAO,YAAY,MAAM,EAAE,CAAC;YAC9B,CAAC;YACD,OAAO,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;QAChC,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
### 工具bash
|
|
2
|
-
在持久化 shell 会话中执行 bash 命令,支持可选超时,确保正确的处理和安全措施。
|
|
3
|
-
|
|
4
|
-
所有命令默认在 ${directory} 执行。如需在其他目录运行命令,使用 `workdir` 参数。**禁止使用 `cd <目录> && <命令>` 模式**,应该使用 `workdir` 参数代替。
|
|
5
|
-
|
|
6
|
-
**重要**:此工具仅用于终端操作如 git、npm、docker 等。**禁止**用于文件操作(读取、写入、编辑、搜索文件)——请使用专用工具。
|
|
7
|
-
|
|
8
|
-
## 执行前验证
|
|
9
|
-
|
|
10
|
-
1. **目录验证**:
|
|
11
|
-
- 如果命令会创建新目录或文件,先用 `ls` 验证父目录存在
|
|
12
|
-
- 例如:运行 "mkdir foo/bar" 前,先用 `ls foo` 确认 "foo" 存在
|
|
13
|
-
|
|
14
|
-
2. **命令执行**:
|
|
15
|
-
- 包含空格的路径必须用双引号包裹
|
|
16
|
-
- 正确示例:`mkdir "/Users/name/My Documents"`
|
|
17
|
-
- 错误示例:`mkdir /Users/name/My Documents`(会失败)
|
|
18
|
-
- 确保正确引用后执行命令
|
|
19
|
-
|
|
20
|
-
## 使用说明
|
|
21
|
-
|
|
22
|
-
- `command` 参数是必需的
|
|
23
|
-
- 可选超时时间(毫秒),默认 120000ms(2分钟)
|
|
24
|
-
- 请用 5-10 个字写清楚命令作用的描述
|
|
25
|
-
- 如果输出超过 2000 行或 51200 字节,会被截断并保存到文件
|
|
26
|
-
- 可以用 Read 的 offset/limit 读取特定部分,或用 grep 搜索全部内容
|
|
27
|
-
- **禁止**使用 `head`、`tail` 等命令限制输出
|
|
28
|
-
|
|
29
|
-
**禁止使用 bash 执行以下操作**,请使用专用工具:
|
|
30
|
-
- 文件搜索:用 glob(不用 find 或 ls)
|
|
31
|
-
- 内容搜索:用 grep(不用 grep 或 rg)
|
|
32
|
-
- 读取文件:用 read_file(不用 cat/head/tail)
|
|
33
|
-
- 编辑文件:用 edit_file(不用 sed/awk)
|
|
34
|
-
- 写入文件:用 write_file(不用 echo >/cat <<EOF)
|
|
35
|
-
- 输出文本:直接输出(不用 echo/printf)
|
|
36
|
-
|
|
37
|
-
**多命令执行**:
|
|
38
|
-
- 独立命令可以并行执行多个 Bash 调用
|
|
39
|
-
- 顺序依赖的命令用 `&&` 链接(如 `git add . && git commit -m "message" && git push`)
|
|
40
|
-
- 不关心前置结果时用 `;` 分隔
|
|
41
|
-
- **禁止**使用换行符分隔命令(在引号字符串中除外)
|
|
42
|
-
|
|
43
|
-
**注意事项**:
|
|
44
|
-
- 禁止使用交互式 git 命令(如 `git rebase -i` 或 `git add -i`)
|
|
45
|
-
- 除非用户明确要求,不要推送到远程
|
|
46
|
-
- 没有变更时不创建空提交
|
|
47
|
-
|
|
48
|
-
举例:
|
|
49
|
-
```xml
|
|
50
|
-
<react>
|
|
51
|
-
<thought>安装项目依赖</thought>
|
|
52
|
-
<action>
|
|
53
|
-
<action_name>bash</action_name>
|
|
54
|
-
<action_input>
|
|
55
|
-
<command>npm install</command>
|
|
56
|
-
<workdir>E:\ai\txcode</workdir>
|
|
57
|
-
</action_input>
|
|
58
|
-
</action>
|
|
59
|
-
<keep_context>true</keep_context>
|
|
60
|
-
</react>
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
参数说明:
|
|
64
|
-
|
|
65
|
-
| 字段 | 类型 | 说明 |
|
|
66
|
-
|------|------|
|
|
67
|
-
| `command` | string | 要执行的命令 |
|
|
68
|
-
| `workdir` | string | 工作目录(可选,默认为当前目录) |
|
|
69
|
-
| `timeout` | number | 超时时间,毫秒(可选,默认 120000 = 2分钟) |
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"code_search.d.ts","sourceRoot":"","sources":["../../../../src/modules/tools/builtin/code_search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAA2B,MAAM,kBAAkB,CAAA;AAkChE,eAAO,MAAM,cAAc,EAAE,IAkF5B,CAAA"}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
const API_CONFIG = {
|
|
2
|
-
BASE_URL: 'https://mcp.exa.ai',
|
|
3
|
-
ENDPOINTS: {
|
|
4
|
-
CONTEXT: '/mcp',
|
|
5
|
-
},
|
|
6
|
-
DEFAULT_TOKENS: 5000,
|
|
7
|
-
TIMEOUT: 30000,
|
|
8
|
-
};
|
|
9
|
-
export const codeSearchTool = {
|
|
10
|
-
name: 'code_search',
|
|
11
|
-
description: '',
|
|
12
|
-
descriptionFile: 'code_search.txt',
|
|
13
|
-
parameters: {
|
|
14
|
-
type: 'object',
|
|
15
|
-
properties: {
|
|
16
|
-
query: {
|
|
17
|
-
type: 'string',
|
|
18
|
-
description: '搜索查询字符串,用于查找 APIs、库和 SDK 的相关上下文。例如:React useState hook examples、Python pandas dataframe filtering、Express.js middleware'
|
|
19
|
-
},
|
|
20
|
-
tokens: {
|
|
21
|
-
type: 'number',
|
|
22
|
-
description: '返回的 token 数量(可选,1000-50000,默认 5000)。根据需要调整上下文量 - 特定问题用较低值,全面文档用较高值'
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
required: ['query']
|
|
26
|
-
},
|
|
27
|
-
execute: async (params, context) => {
|
|
28
|
-
const codeRequest = {
|
|
29
|
-
jsonrpc: '2.0',
|
|
30
|
-
id: 1,
|
|
31
|
-
method: 'tools/call',
|
|
32
|
-
params: {
|
|
33
|
-
name: 'get_code_context_exa',
|
|
34
|
-
arguments: {
|
|
35
|
-
query: params.query,
|
|
36
|
-
tokensNum: params.tokens || API_CONFIG.DEFAULT_TOKENS,
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
const timeoutTimer = setTimeout(() => {
|
|
41
|
-
throw new Error('Code search request timed out');
|
|
42
|
-
}, API_CONFIG.TIMEOUT);
|
|
43
|
-
try {
|
|
44
|
-
const response = await fetch(`${API_CONFIG.BASE_URL}${API_CONFIG.ENDPOINTS.CONTEXT}`, {
|
|
45
|
-
method: 'POST',
|
|
46
|
-
headers: {
|
|
47
|
-
accept: 'application/json, text/event-stream',
|
|
48
|
-
'content-type': 'application/json',
|
|
49
|
-
},
|
|
50
|
-
body: JSON.stringify(codeRequest),
|
|
51
|
-
signal: context.abortSignal,
|
|
52
|
-
});
|
|
53
|
-
clearTimeout(timeoutTimer);
|
|
54
|
-
if (!response.ok) {
|
|
55
|
-
const errorText = await response.text();
|
|
56
|
-
return { success: false, output: '', error: `Code search error (${response.status}): ${errorText}` };
|
|
57
|
-
}
|
|
58
|
-
const responseText = await response.text();
|
|
59
|
-
const lines = responseText.split('\n');
|
|
60
|
-
for (const line of lines) {
|
|
61
|
-
if (line.startsWith('data: ')) {
|
|
62
|
-
const data = JSON.parse(line.substring(6));
|
|
63
|
-
if (data.result && data.result.content && data.result.content.length > 0) {
|
|
64
|
-
return {
|
|
65
|
-
success: true,
|
|
66
|
-
output: data.result.content[0].text,
|
|
67
|
-
metadata: { query: params.query, tokens: params.tokens || API_CONFIG.DEFAULT_TOKENS },
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
success: true,
|
|
74
|
-
output: '未找到代码片段或文档。请尝试其他查询,或更具体地说明库/框架名称。',
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
clearTimeout(timeoutTimer);
|
|
79
|
-
if (err.message === 'Code search request timed out') {
|
|
80
|
-
return { success: false, output: '', error: '代码搜索请求超时' };
|
|
81
|
-
}
|
|
82
|
-
return { success: false, output: '', error: err.message };
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
//# sourceMappingURL=code_search.js.map
|