ccjk 12.0.7 → 12.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (299) hide show
  1. package/package.json +1 -1
  2. package/dist/chunks/agent-teams.mjs +0 -136
  3. package/dist/chunks/agent.mjs +0 -1439
  4. package/dist/chunks/agents.mjs +0 -3778
  5. package/dist/chunks/api-cli.mjs +0 -132
  6. package/dist/chunks/api-providers.mjs +0 -129
  7. package/dist/chunks/api.mjs +0 -112
  8. package/dist/chunks/auto-bootstrap.mjs +0 -358
  9. package/dist/chunks/auto-init.mjs +0 -7584
  10. package/dist/chunks/auto-updater.mjs +0 -410
  11. package/dist/chunks/banner.mjs +0 -188
  12. package/dist/chunks/bash.mjs +0 -187
  13. package/dist/chunks/boost.mjs +0 -397
  14. package/dist/chunks/ccjk-agents.mjs +0 -414
  15. package/dist/chunks/ccjk-all.mjs +0 -1028
  16. package/dist/chunks/ccjk-config.mjs +0 -261
  17. package/dist/chunks/ccjk-hooks.mjs +0 -1074
  18. package/dist/chunks/ccjk-mcp.mjs +0 -761
  19. package/dist/chunks/ccjk-setup.mjs +0 -763
  20. package/dist/chunks/ccjk-skills.mjs +0 -514
  21. package/dist/chunks/ccr.mjs +0 -98
  22. package/dist/chunks/ccu.mjs +0 -40
  23. package/dist/chunks/check-updates.mjs +0 -108
  24. package/dist/chunks/claude-code-config-manager.mjs +0 -750
  25. package/dist/chunks/claude-code-incremental-manager.mjs +0 -623
  26. package/dist/chunks/claude-config.mjs +0 -236
  27. package/dist/chunks/claude-wrapper.mjs +0 -85
  28. package/dist/chunks/cleanup-migration.mjs +0 -20
  29. package/dist/chunks/cli-hook.mjs +0 -2285
  30. package/dist/chunks/cloud-sync.mjs +0 -29
  31. package/dist/chunks/codex-config-switch.mjs +0 -451
  32. package/dist/chunks/codex-provider-manager.mjs +0 -236
  33. package/dist/chunks/codex-uninstaller.mjs +0 -404
  34. package/dist/chunks/codex.mjs +0 -2077
  35. package/dist/chunks/commands.mjs +0 -108
  36. package/dist/chunks/commands2.mjs +0 -413
  37. package/dist/chunks/commit.mjs +0 -138
  38. package/dist/chunks/completion.mjs +0 -515
  39. package/dist/chunks/config-consolidator.mjs +0 -172
  40. package/dist/chunks/config-switch.mjs +0 -317
  41. package/dist/chunks/config.mjs +0 -379
  42. package/dist/chunks/config2.mjs +0 -477
  43. package/dist/chunks/config3.mjs +0 -470
  44. package/dist/chunks/constants.mjs +0 -133
  45. package/dist/chunks/context-loader.mjs +0 -343
  46. package/dist/chunks/context.mjs +0 -372
  47. package/dist/chunks/convoy-manager.mjs +0 -880
  48. package/dist/chunks/dashboard.mjs +0 -476
  49. package/dist/chunks/doctor.mjs +0 -964
  50. package/dist/chunks/evolution.mjs +0 -382
  51. package/dist/chunks/features.mjs +0 -698
  52. package/dist/chunks/fish.mjs +0 -181
  53. package/dist/chunks/fs-operations.mjs +0 -192
  54. package/dist/chunks/health-alerts.mjs +0 -304
  55. package/dist/chunks/health-check.mjs +0 -532
  56. package/dist/chunks/help.mjs +0 -340
  57. package/dist/chunks/hook-installer.mjs +0 -45
  58. package/dist/chunks/index.mjs +0 -24
  59. package/dist/chunks/index10.mjs +0 -1171
  60. package/dist/chunks/index11.mjs +0 -1008
  61. package/dist/chunks/index12.mjs +0 -193
  62. package/dist/chunks/index13.mjs +0 -218
  63. package/dist/chunks/index14.mjs +0 -663
  64. package/dist/chunks/index2.mjs +0 -19
  65. package/dist/chunks/index3.mjs +0 -19092
  66. package/dist/chunks/index4.mjs +0 -8
  67. package/dist/chunks/index5.mjs +0 -7600
  68. package/dist/chunks/index6.mjs +0 -171
  69. package/dist/chunks/index7.mjs +0 -3583
  70. package/dist/chunks/index8.mjs +0 -19
  71. package/dist/chunks/index9.mjs +0 -616
  72. package/dist/chunks/init.mjs +0 -1606
  73. package/dist/chunks/installer.mjs +0 -690
  74. package/dist/chunks/installer2.mjs +0 -179
  75. package/dist/chunks/interview.mjs +0 -2927
  76. package/dist/chunks/json-config.mjs +0 -60
  77. package/dist/chunks/linux.mjs +0 -3863
  78. package/dist/chunks/macos.mjs +0 -69
  79. package/dist/chunks/main.mjs +0 -635
  80. package/dist/chunks/manager.mjs +0 -1048
  81. package/dist/chunks/marketplace.mjs +0 -949
  82. package/dist/chunks/mcp-cli.mjs +0 -204
  83. package/dist/chunks/mcp-performance.mjs +0 -187
  84. package/dist/chunks/mcp.mjs +0 -1231
  85. package/dist/chunks/menu.mjs +0 -652
  86. package/dist/chunks/metrics-display.mjs +0 -153
  87. package/dist/chunks/migrator.mjs +0 -178
  88. package/dist/chunks/monitor.mjs +0 -1856
  89. package/dist/chunks/notification.mjs +0 -1864
  90. package/dist/chunks/onboarding.mjs +0 -385
  91. package/dist/chunks/package.mjs +0 -3
  92. package/dist/chunks/paradigm.mjs +0 -74
  93. package/dist/chunks/permission-manager.mjs +0 -132
  94. package/dist/chunks/permissions.mjs +0 -265
  95. package/dist/chunks/persistence-manager.mjs +0 -794
  96. package/dist/chunks/persistence.mjs +0 -667
  97. package/dist/chunks/platform.mjs +0 -391
  98. package/dist/chunks/plugin.mjs +0 -1936
  99. package/dist/chunks/powershell.mjs +0 -213
  100. package/dist/chunks/prompts.mjs +0 -241
  101. package/dist/chunks/providers.mjs +0 -260
  102. package/dist/chunks/quick-actions.mjs +0 -320
  103. package/dist/chunks/quick-provider.mjs +0 -682
  104. package/dist/chunks/quick-setup.mjs +0 -412
  105. package/dist/chunks/remote.mjs +0 -497
  106. package/dist/chunks/session.mjs +0 -878
  107. package/dist/chunks/sessions.mjs +0 -106
  108. package/dist/chunks/silent-updater.mjs +0 -396
  109. package/dist/chunks/simple-config.mjs +0 -98
  110. package/dist/chunks/skill.mjs +0 -117
  111. package/dist/chunks/skill2.mjs +0 -9003
  112. package/dist/chunks/skills-sync.mjs +0 -6460
  113. package/dist/chunks/skills.mjs +0 -567
  114. package/dist/chunks/slash-commands.mjs +0 -207
  115. package/dist/chunks/smart-defaults.mjs +0 -412
  116. package/dist/chunks/smart-guide.mjs +0 -194
  117. package/dist/chunks/startup.mjs +0 -487
  118. package/dist/chunks/stats.mjs +0 -410
  119. package/dist/chunks/status.mjs +0 -289
  120. package/dist/chunks/team.mjs +0 -63
  121. package/dist/chunks/thinking.mjs +0 -626
  122. package/dist/chunks/trace.mjs +0 -57
  123. package/dist/chunks/uninstall.mjs +0 -849
  124. package/dist/chunks/update.mjs +0 -167
  125. package/dist/chunks/upgrade-manager.mjs +0 -204
  126. package/dist/chunks/version-checker.mjs +0 -881
  127. package/dist/chunks/vim.mjs +0 -903
  128. package/dist/chunks/windows.mjs +0 -14
  129. package/dist/chunks/workflows.mjs +0 -633
  130. package/dist/chunks/wsl.mjs +0 -129
  131. package/dist/chunks/zero-config.mjs +0 -374
  132. package/dist/chunks/zsh.mjs +0 -182
  133. package/dist/cli.d.mts +0 -1
  134. package/dist/cli.d.ts +0 -1
  135. package/dist/cli.mjs +0 -2199
  136. package/dist/i18n/locales/en/agent-teams.json +0 -18
  137. package/dist/i18n/locales/en/agentBrowser.json +0 -79
  138. package/dist/i18n/locales/en/agents.json +0 -135
  139. package/dist/i18n/locales/en/api.json +0 -63
  140. package/dist/i18n/locales/en/ccjk-agents.json +0 -33
  141. package/dist/i18n/locales/en/ccjk-all.json +0 -23
  142. package/dist/i18n/locales/en/ccjk-skills.json +0 -22
  143. package/dist/i18n/locales/en/ccjk.json +0 -276
  144. package/dist/i18n/locales/en/ccr.json +0 -65
  145. package/dist/i18n/locales/en/claude-md.json +0 -73
  146. package/dist/i18n/locales/en/cli.json +0 -152
  147. package/dist/i18n/locales/en/cloud-setup.json +0 -31
  148. package/dist/i18n/locales/en/cloud-sync.json +0 -147
  149. package/dist/i18n/locales/en/cloud.json +0 -40
  150. package/dist/i18n/locales/en/cloudPlugins.json +0 -118
  151. package/dist/i18n/locales/en/codex.json +0 -127
  152. package/dist/i18n/locales/en/cometix.json +0 -29
  153. package/dist/i18n/locales/en/common.json +0 -68
  154. package/dist/i18n/locales/en/config.json +0 -108
  155. package/dist/i18n/locales/en/configuration.json +0 -226
  156. package/dist/i18n/locales/en/context.json +0 -85
  157. package/dist/i18n/locales/en/dashboard.json +0 -78
  158. package/dist/i18n/locales/en/errors.json +0 -26
  159. package/dist/i18n/locales/en/evolution.json +0 -54
  160. package/dist/i18n/locales/en/hooks.json +0 -74
  161. package/dist/i18n/locales/en/hooksSync.json +0 -133
  162. package/dist/i18n/locales/en/installation.json +0 -83
  163. package/dist/i18n/locales/en/interview.json +0 -104
  164. package/dist/i18n/locales/en/language.json +0 -19
  165. package/dist/i18n/locales/en/lsp.json +0 -78
  166. package/dist/i18n/locales/en/marketplace.json +0 -116
  167. package/dist/i18n/locales/en/mcp.json +0 -178
  168. package/dist/i18n/locales/en/memory.json +0 -92
  169. package/dist/i18n/locales/en/menu.json +0 -143
  170. package/dist/i18n/locales/en/multi-config.json +0 -79
  171. package/dist/i18n/locales/en/notification.json +0 -307
  172. package/dist/i18n/locales/en/permissions.json +0 -95
  173. package/dist/i18n/locales/en/persistence.json +0 -127
  174. package/dist/i18n/locales/en/plugins.json +0 -146
  175. package/dist/i18n/locales/en/quick-actions.json +0 -78
  176. package/dist/i18n/locales/en/registry.json +0 -54
  177. package/dist/i18n/locales/en/remote.json +0 -93
  178. package/dist/i18n/locales/en/sandbox.json +0 -44
  179. package/dist/i18n/locales/en/setup.json +0 -44
  180. package/dist/i18n/locales/en/shencha.json +0 -14
  181. package/dist/i18n/locales/en/skills.json +0 -100
  182. package/dist/i18n/locales/en/skillsSync.json +0 -74
  183. package/dist/i18n/locales/en/smartGuide.json +0 -49
  184. package/dist/i18n/locales/en/stats.json +0 -20
  185. package/dist/i18n/locales/en/subagent.json +0 -69
  186. package/dist/i18n/locales/en/superpowers.json +0 -117
  187. package/dist/i18n/locales/en/team.json +0 -7
  188. package/dist/i18n/locales/en/thinking.json +0 -65
  189. package/dist/i18n/locales/en/tools.json +0 -42
  190. package/dist/i18n/locales/en/uninstall.json +0 -56
  191. package/dist/i18n/locales/en/updater.json +0 -29
  192. package/dist/i18n/locales/en/vim.json +0 -169
  193. package/dist/i18n/locales/en/workflow.json +0 -55
  194. package/dist/i18n/locales/en/workspace.json +0 -108
  195. package/dist/i18n/locales/zh-CN/agent-teams.json +0 -18
  196. package/dist/i18n/locales/zh-CN/agentBrowser.json +0 -79
  197. package/dist/i18n/locales/zh-CN/agents.json +0 -135
  198. package/dist/i18n/locales/zh-CN/api.json +0 -63
  199. package/dist/i18n/locales/zh-CN/ccjk-agents.json +0 -33
  200. package/dist/i18n/locales/zh-CN/ccjk-all.json +0 -23
  201. package/dist/i18n/locales/zh-CN/ccjk-skills.json +0 -22
  202. package/dist/i18n/locales/zh-CN/ccjk.json +0 -276
  203. package/dist/i18n/locales/zh-CN/ccr.json +0 -65
  204. package/dist/i18n/locales/zh-CN/claude-md.json +0 -73
  205. package/dist/i18n/locales/zh-CN/cli.json +0 -152
  206. package/dist/i18n/locales/zh-CN/cloud-setup.json +0 -31
  207. package/dist/i18n/locales/zh-CN/cloud-sync.json +0 -147
  208. package/dist/i18n/locales/zh-CN/cloud.json +0 -40
  209. package/dist/i18n/locales/zh-CN/cloudPlugins.json +0 -118
  210. package/dist/i18n/locales/zh-CN/codex.json +0 -127
  211. package/dist/i18n/locales/zh-CN/cometix.json +0 -29
  212. package/dist/i18n/locales/zh-CN/common.json +0 -68
  213. package/dist/i18n/locales/zh-CN/config.json +0 -108
  214. package/dist/i18n/locales/zh-CN/configuration.json +0 -224
  215. package/dist/i18n/locales/zh-CN/context.json +0 -85
  216. package/dist/i18n/locales/zh-CN/dashboard.json +0 -78
  217. package/dist/i18n/locales/zh-CN/errors.json +0 -26
  218. package/dist/i18n/locales/zh-CN/evolution.json +0 -54
  219. package/dist/i18n/locales/zh-CN/hooks.json +0 -74
  220. package/dist/i18n/locales/zh-CN/hooksSync.json +0 -133
  221. package/dist/i18n/locales/zh-CN/installation.json +0 -83
  222. package/dist/i18n/locales/zh-CN/interview.json +0 -104
  223. package/dist/i18n/locales/zh-CN/language.json +0 -19
  224. package/dist/i18n/locales/zh-CN/lsp.json +0 -78
  225. package/dist/i18n/locales/zh-CN/marketplace.json +0 -116
  226. package/dist/i18n/locales/zh-CN/mcp.json +0 -178
  227. package/dist/i18n/locales/zh-CN/memory.json +0 -92
  228. package/dist/i18n/locales/zh-CN/menu.json +0 -143
  229. package/dist/i18n/locales/zh-CN/multi-config.json +0 -79
  230. package/dist/i18n/locales/zh-CN/notification.json +0 -307
  231. package/dist/i18n/locales/zh-CN/permissions.json +0 -95
  232. package/dist/i18n/locales/zh-CN/persistence.json +0 -127
  233. package/dist/i18n/locales/zh-CN/plugins.json +0 -146
  234. package/dist/i18n/locales/zh-CN/quick-actions.json +0 -78
  235. package/dist/i18n/locales/zh-CN/registry.json +0 -54
  236. package/dist/i18n/locales/zh-CN/remote.json +0 -93
  237. package/dist/i18n/locales/zh-CN/sandbox.json +0 -44
  238. package/dist/i18n/locales/zh-CN/setup.json +0 -44
  239. package/dist/i18n/locales/zh-CN/shencha.json +0 -14
  240. package/dist/i18n/locales/zh-CN/skills.json +0 -100
  241. package/dist/i18n/locales/zh-CN/skillsSync.json +0 -74
  242. package/dist/i18n/locales/zh-CN/smartGuide.json +0 -49
  243. package/dist/i18n/locales/zh-CN/stats.json +0 -20
  244. package/dist/i18n/locales/zh-CN/subagent.json +0 -69
  245. package/dist/i18n/locales/zh-CN/superpowers.json +0 -117
  246. package/dist/i18n/locales/zh-CN/team.json +0 -7
  247. package/dist/i18n/locales/zh-CN/thinking.json +0 -65
  248. package/dist/i18n/locales/zh-CN/tools.json +0 -42
  249. package/dist/i18n/locales/zh-CN/uninstall.json +0 -56
  250. package/dist/i18n/locales/zh-CN/updater.json +0 -29
  251. package/dist/i18n/locales/zh-CN/vim.json +0 -169
  252. package/dist/i18n/locales/zh-CN/workflow.json +0 -55
  253. package/dist/i18n/locales/zh-CN/workspace.json +0 -108
  254. package/dist/index.d.mts +0 -5295
  255. package/dist/index.d.ts +0 -5295
  256. package/dist/index.mjs +0 -4941
  257. package/dist/shared/ccjk.B364Fu0N.mjs +0 -1819
  258. package/dist/shared/ccjk.BAGoDD49.mjs +0 -36
  259. package/dist/shared/ccjk.BBtCGd_g.mjs +0 -899
  260. package/dist/shared/ccjk.BFQ7yr5S.mjs +0 -16
  261. package/dist/shared/ccjk.BFxsJM0k.mjs +0 -599
  262. package/dist/shared/ccjk.BIxuVL3_.mjs +0 -25
  263. package/dist/shared/ccjk.BRZ9ww8S.mjs +0 -142
  264. package/dist/shared/ccjk.BoApaI4j.mjs +0 -28
  265. package/dist/shared/ccjk.BrPUmTqm.mjs +0 -266
  266. package/dist/shared/ccjk.BtB1e5jm.mjs +0 -171
  267. package/dist/shared/ccjk.BwfbSKN2.mjs +0 -1051
  268. package/dist/shared/ccjk.BxSmJ8B7.mjs +0 -243
  269. package/dist/shared/ccjk.Bx_rmYfN.mjs +0 -69
  270. package/dist/shared/ccjk.C2jHOZVP.mjs +0 -52
  271. package/dist/shared/ccjk.CL4Yat0G.mjs +0 -303
  272. package/dist/shared/ccjk.COweQ1RR.mjs +0 -5
  273. package/dist/shared/ccjk.CePkJq2S.mjs +0 -223
  274. package/dist/shared/ccjk.CfKKcvWy.mjs +0 -126
  275. package/dist/shared/ccjk.Cjgrln_h.mjs +0 -297
  276. package/dist/shared/ccjk.Cjj8SVrn.mjs +0 -54
  277. package/dist/shared/ccjk.CxpGa6MC.mjs +0 -2724
  278. package/dist/shared/ccjk.D5MFQT7w.mjs +0 -400
  279. package/dist/shared/ccjk.D6ycHbak.mjs +0 -270
  280. package/dist/shared/ccjk.D8ZLYSZZ.mjs +0 -299
  281. package/dist/shared/ccjk.DG_o24cZ.mjs +0 -88
  282. package/dist/shared/ccjk.DLLw-h4Y.mjs +0 -460
  283. package/dist/shared/ccjk.DOwtZMk8.mjs +0 -4019
  284. package/dist/shared/ccjk.DS7UESmF.mjs +0 -2451
  285. package/dist/shared/ccjk.DTdjs-qK.mjs +0 -1447
  286. package/dist/shared/ccjk.DXRAZcix.mjs +0 -66
  287. package/dist/shared/ccjk.DsYaCCx4.mjs +0 -317
  288. package/dist/shared/ccjk.J8YiPsOw.mjs +0 -259
  289. package/dist/shared/ccjk.KfSWcGlE.mjs +0 -38
  290. package/dist/shared/ccjk.RyizuzOI.mjs +0 -21
  291. package/dist/shared/ccjk.SPoXMvZD.mjs +0 -1242
  292. package/dist/shared/ccjk.T_cX87dY.mjs +0 -15
  293. package/dist/shared/ccjk.UIvifqNE.mjs +0 -1486
  294. package/dist/shared/ccjk._dESH4Rk.mjs +0 -111
  295. package/dist/shared/ccjk.bQ7Dh1g4.mjs +0 -249
  296. package/dist/shared/ccjk.c-ETfBZ_.mjs +0 -617
  297. package/dist/shared/ccjk.gDEDGD_t.mjs +0 -38
  298. package/dist/shared/ccjk.hoqrwWdN.mjs +0 -333
  299. package/dist/shared/ccjk.waa2ikKJ.mjs +0 -351
@@ -1,1439 +0,0 @@
1
- import a from './index2.mjs';
2
- import { existsSync, readFileSync, mkdirSync, writeFileSync, readdirSync } from 'node:fs';
3
- import { CCJK_CONFIG_DIR } from './constants.mjs';
4
- import { w as writeAgentFile } from '../shared/ccjk.CfKKcvWy.mjs';
5
- import { g as getPluginManager } from '../shared/ccjk.DTdjs-qK.mjs';
6
- import { homedir } from 'node:os';
7
- import { j as join } from '../shared/ccjk.bQ7Dh1g4.mjs';
8
- import '../shared/ccjk.BAGoDD49.mjs';
9
- import './index5.mjs';
10
- import 'node:process';
11
- import 'node:url';
12
- import './main.mjs';
13
- import 'module';
14
- import 'node:child_process';
15
- import 'node:path';
16
- import 'node:stream';
17
- import 'node:readline';
18
- import '../shared/ccjk.DsYaCCx4.mjs';
19
-
20
- const CLAUDE_CONFIG_PATH = join(homedir(), ".claude.json");
21
- const TOOL_CACHE_TTL = 5 * 60 * 1e3;
22
- class McpServerManager {
23
- servers = /* @__PURE__ */ new Map();
24
- toolCache = /* @__PURE__ */ new Map();
25
- configPath;
26
- initialized = false;
27
- constructor(configPath = CLAUDE_CONFIG_PATH) {
28
- this.configPath = configPath;
29
- }
30
- // ==========================================================================
31
- // Initialization
32
- // ==========================================================================
33
- /**
34
- * Initialize the manager by loading MCP configuration
35
- */
36
- async initialize() {
37
- if (this.initialized) {
38
- return;
39
- }
40
- await this.loadConfiguration();
41
- this.initialized = true;
42
- }
43
- /**
44
- * Load MCP configuration from file
45
- */
46
- async loadConfiguration() {
47
- const config = this.readConfigFile();
48
- if (!config?.mcpServers) {
49
- return;
50
- }
51
- for (const [name, serverConfig] of Object.entries(config.mcpServers)) {
52
- this.servers.set(name, {
53
- name,
54
- config: serverConfig,
55
- status: "unknown"
56
- });
57
- }
58
- }
59
- /**
60
- * Read the Claude configuration file
61
- */
62
- readConfigFile() {
63
- if (!existsSync(this.configPath)) {
64
- return null;
65
- }
66
- try {
67
- const content = readFileSync(this.configPath, "utf-8");
68
- return JSON.parse(content);
69
- } catch (error) {
70
- console.error(`Failed to read MCP config from ${this.configPath}:`, error);
71
- return null;
72
- }
73
- }
74
- /**
75
- * Reload configuration (useful after config changes)
76
- */
77
- async reload() {
78
- this.servers.clear();
79
- this.toolCache.clear();
80
- this.initialized = false;
81
- await this.initialize();
82
- }
83
- // ==========================================================================
84
- // Server Management
85
- // ==========================================================================
86
- /**
87
- * Get all configured MCP servers
88
- */
89
- getServers() {
90
- return Array.from(this.servers.values());
91
- }
92
- /**
93
- * Get a specific server by name
94
- */
95
- getServer(name) {
96
- return this.servers.get(name);
97
- }
98
- /**
99
- * Get server names
100
- */
101
- getServerNames() {
102
- return Array.from(this.servers.keys());
103
- }
104
- /**
105
- * Check if a server is configured
106
- */
107
- hasServer(name) {
108
- return this.servers.has(name);
109
- }
110
- // ==========================================================================
111
- // Tool Discovery
112
- // ==========================================================================
113
- /**
114
- * Get available tools from a specific MCP server
115
- *
116
- * This method attempts to discover tools by querying the MCP server.
117
- * Results are cached to avoid repeated queries.
118
- */
119
- async getServerTools(serverName) {
120
- const server = this.servers.get(serverName);
121
- if (!server) {
122
- return [];
123
- }
124
- const cached = this.toolCache.get(serverName);
125
- if (cached && Date.now() - cached.timestamp < TOOL_CACHE_TTL) {
126
- return cached.tools;
127
- }
128
- const tools = await this.discoverTools(server);
129
- this.toolCache.set(serverName, {
130
- tools,
131
- timestamp: Date.now()
132
- });
133
- server.tools = tools;
134
- server.lastUpdated = Date.now();
135
- return tools;
136
- }
137
- /**
138
- * Get all available tools from all configured servers
139
- */
140
- async getAllTools() {
141
- const allTools = [];
142
- for (const serverName of this.servers.keys()) {
143
- const tools = await this.getServerTools(serverName);
144
- allTools.push(...tools);
145
- }
146
- return allTools;
147
- }
148
- /**
149
- * Get tools for specific servers (used by AgentRuntime)
150
- *
151
- * @param mcpRefs - Array of MCP server references from agent definition
152
- */
153
- async getToolsForAgent(mcpRefs) {
154
- const tools = [];
155
- for (const ref of mcpRefs) {
156
- const serverTools = await this.getServerTools(ref.serverName);
157
- if (ref.tools && ref.tools.length > 0) {
158
- const filteredTools = serverTools.filter((t) => ref.tools.includes(t.name));
159
- tools.push(...filteredTools);
160
- } else {
161
- tools.push(...serverTools);
162
- }
163
- }
164
- return tools;
165
- }
166
- /**
167
- * Discover tools from an MCP server
168
- *
169
- * This is a simplified implementation that returns predefined tools
170
- * based on known MCP server types. In a full implementation, this would
171
- * actually connect to the MCP server and query its capabilities.
172
- */
173
- async discoverTools(server) {
174
- const tools = [];
175
- try {
176
- if (server.config.type === "stdio" && server.config.command) {
177
- const discoveredTools = await this.queryStdioServerTools(server);
178
- if (discoveredTools.length > 0) {
179
- server.status = "connected";
180
- return discoveredTools;
181
- }
182
- }
183
- if (server.config.type === "sse" && server.config.url) {
184
- const discoveredTools = await this.querySseServerTools(server);
185
- if (discoveredTools.length > 0) {
186
- server.status = "connected";
187
- return discoveredTools;
188
- }
189
- }
190
- const knownTools = this.getKnownServerTools(server.name, server.config);
191
- if (knownTools.length > 0) {
192
- server.status = "unknown";
193
- return knownTools;
194
- }
195
- server.status = "unknown";
196
- return tools;
197
- } catch (error) {
198
- server.status = "error";
199
- server.error = error instanceof Error ? error.message : String(error);
200
- return tools;
201
- }
202
- }
203
- /**
204
- * Query tools from a stdio-based MCP server
205
- *
206
- * Note: This is a placeholder implementation. Real MCP tool discovery
207
- * would require implementing the MCP protocol handshake.
208
- */
209
- async queryStdioServerTools(_server) {
210
- return [];
211
- }
212
- /**
213
- * Query tools from an SSE-based MCP server
214
- *
215
- * Note: This is a placeholder implementation.
216
- */
217
- async querySseServerTools(_server) {
218
- return [];
219
- }
220
- /**
221
- * Get known tools for common MCP servers
222
- *
223
- * This provides tool information for well-known MCP servers
224
- * without needing to actually connect to them.
225
- */
226
- getKnownServerTools(serverName, config) {
227
- const tools = [];
228
- const command = config.command || "";
229
- const args = config.args?.join(" ") || "";
230
- const identifier = `${serverName} ${command} ${args}`.toLowerCase();
231
- if (identifier.includes("filesystem") || identifier.includes("fs")) {
232
- tools.push(
233
- {
234
- server: serverName,
235
- name: "read_file",
236
- description: "Read the contents of a file",
237
- inputSchema: {
238
- type: "object",
239
- properties: {
240
- path: { type: "string", description: "Path to the file to read" }
241
- },
242
- required: ["path"]
243
- }
244
- },
245
- {
246
- server: serverName,
247
- name: "write_file",
248
- description: "Write content to a file",
249
- inputSchema: {
250
- type: "object",
251
- properties: {
252
- path: { type: "string", description: "Path to the file to write" },
253
- content: { type: "string", description: "Content to write" }
254
- },
255
- required: ["path", "content"]
256
- }
257
- },
258
- {
259
- server: serverName,
260
- name: "list_directory",
261
- description: "List contents of a directory",
262
- inputSchema: {
263
- type: "object",
264
- properties: {
265
- path: { type: "string", description: "Path to the directory" }
266
- },
267
- required: ["path"]
268
- }
269
- }
270
- );
271
- }
272
- if (identifier.includes("exa")) {
273
- tools.push(
274
- {
275
- server: serverName,
276
- name: "web_search",
277
- description: "Search the web using Exa",
278
- inputSchema: {
279
- type: "object",
280
- properties: {
281
- query: { type: "string", description: "Search query" },
282
- numResults: { type: "number", description: "Number of results to return" }
283
- },
284
- required: ["query"]
285
- }
286
- },
287
- {
288
- server: serverName,
289
- name: "find_similar",
290
- description: "Find similar content to a URL",
291
- inputSchema: {
292
- type: "object",
293
- properties: {
294
- url: { type: "string", description: "URL to find similar content for" }
295
- },
296
- required: ["url"]
297
- }
298
- }
299
- );
300
- }
301
- if (identifier.includes("github")) {
302
- tools.push(
303
- {
304
- server: serverName,
305
- name: "search_repositories",
306
- description: "Search GitHub repositories",
307
- inputSchema: {
308
- type: "object",
309
- properties: {
310
- query: { type: "string", description: "Search query" }
311
- },
312
- required: ["query"]
313
- }
314
- },
315
- {
316
- server: serverName,
317
- name: "get_file_contents",
318
- description: "Get contents of a file from a repository",
319
- inputSchema: {
320
- type: "object",
321
- properties: {
322
- owner: { type: "string", description: "Repository owner" },
323
- repo: { type: "string", description: "Repository name" },
324
- path: { type: "string", description: "File path" }
325
- },
326
- required: ["owner", "repo", "path"]
327
- }
328
- },
329
- {
330
- server: serverName,
331
- name: "create_issue",
332
- description: "Create a new issue in a repository",
333
- inputSchema: {
334
- type: "object",
335
- properties: {
336
- owner: { type: "string", description: "Repository owner" },
337
- repo: { type: "string", description: "Repository name" },
338
- title: { type: "string", description: "Issue title" },
339
- body: { type: "string", description: "Issue body" }
340
- },
341
- required: ["owner", "repo", "title"]
342
- }
343
- }
344
- );
345
- }
346
- if (identifier.includes("playwright")) {
347
- tools.push(
348
- {
349
- server: serverName,
350
- name: "browser_navigate",
351
- description: "Navigate to a URL",
352
- inputSchema: {
353
- type: "object",
354
- properties: {
355
- url: { type: "string", description: "URL to navigate to" }
356
- },
357
- required: ["url"]
358
- }
359
- },
360
- {
361
- server: serverName,
362
- name: "browser_snapshot",
363
- description: "Take an accessibility snapshot of the page",
364
- inputSchema: {
365
- type: "object",
366
- properties: {}
367
- }
368
- },
369
- {
370
- server: serverName,
371
- name: "browser_click",
372
- description: "Click on an element",
373
- inputSchema: {
374
- type: "object",
375
- properties: {
376
- element: { type: "string", description: "Element description" },
377
- ref: { type: "string", description: "Element reference" }
378
- },
379
- required: ["element", "ref"]
380
- }
381
- }
382
- );
383
- }
384
- if (identifier.includes("context7")) {
385
- tools.push(
386
- {
387
- server: serverName,
388
- name: "resolve-library-id",
389
- description: "Resolve a library name to Context7 library ID",
390
- inputSchema: {
391
- type: "object",
392
- properties: {
393
- libraryName: { type: "string", description: "Library name to search for" }
394
- },
395
- required: ["libraryName"]
396
- }
397
- },
398
- {
399
- server: serverName,
400
- name: "query-docs",
401
- description: "Query documentation for a library",
402
- inputSchema: {
403
- type: "object",
404
- properties: {
405
- libraryId: { type: "string", description: "Context7 library ID" },
406
- query: { type: "string", description: "Query string" }
407
- },
408
- required: ["libraryId", "query"]
409
- }
410
- }
411
- );
412
- }
413
- if (identifier.includes("fetch") || identifier.includes("http")) {
414
- tools.push({
415
- server: serverName,
416
- name: "fetch",
417
- description: "Fetch content from a URL",
418
- inputSchema: {
419
- type: "object",
420
- properties: {
421
- url: { type: "string", description: "URL to fetch" },
422
- method: { type: "string", description: "HTTP method", enum: ["GET", "POST", "PUT", "DELETE"] },
423
- headers: { type: "object", description: "Request headers" },
424
- body: { type: "string", description: "Request body" }
425
- },
426
- required: ["url"]
427
- }
428
- });
429
- }
430
- if (identifier.includes("memory") || identifier.includes("knowledge")) {
431
- tools.push(
432
- {
433
- server: serverName,
434
- name: "store_memory",
435
- description: "Store information in memory",
436
- inputSchema: {
437
- type: "object",
438
- properties: {
439
- key: { type: "string", description: "Memory key" },
440
- value: { type: "string", description: "Value to store" }
441
- },
442
- required: ["key", "value"]
443
- }
444
- },
445
- {
446
- server: serverName,
447
- name: "retrieve_memory",
448
- description: "Retrieve information from memory",
449
- inputSchema: {
450
- type: "object",
451
- properties: {
452
- key: { type: "string", description: "Memory key" }
453
- },
454
- required: ["key"]
455
- }
456
- }
457
- );
458
- }
459
- return tools;
460
- }
461
- // ==========================================================================
462
- // Tool Execution (Optional Proxy)
463
- // ==========================================================================
464
- /**
465
- * Execute a tool call through the MCP server
466
- *
467
- * Note: This is a placeholder for future implementation.
468
- * In a full implementation, this would:
469
- * 1. Connect to the appropriate MCP server
470
- * 2. Send the tool call request
471
- * 3. Return the response
472
- *
473
- * For now, agents should use Claude Code's native MCP integration.
474
- */
475
- async callTool(request) {
476
- const server = this.servers.get(request.server);
477
- if (!server) {
478
- return {
479
- success: false,
480
- error: `Server not found: ${request.server}`
481
- };
482
- }
483
- const startTime = Date.now();
484
- try {
485
- return {
486
- success: false,
487
- error: "Direct tool execution not yet implemented. Use Claude Code's native MCP integration.",
488
- duration: Date.now() - startTime
489
- };
490
- } catch (error) {
491
- return {
492
- success: false,
493
- error: error instanceof Error ? error.message : String(error),
494
- duration: Date.now() - startTime
495
- };
496
- }
497
- }
498
- // ==========================================================================
499
- // Utility Methods
500
- // ==========================================================================
501
- /**
502
- * Get tool information formatted for agent system prompt
503
- */
504
- formatToolsForPrompt(tools) {
505
- if (tools.length === 0) {
506
- return "";
507
- }
508
- const lines = ["## Available MCP Tools", ""];
509
- const byServer = /* @__PURE__ */ new Map();
510
- for (const tool of tools) {
511
- const serverTools = byServer.get(tool.server) || [];
512
- serverTools.push(tool);
513
- byServer.set(tool.server, serverTools);
514
- }
515
- for (const [server, serverTools] of byServer) {
516
- lines.push(`### ${server}`);
517
- lines.push("");
518
- for (const tool of serverTools) {
519
- lines.push(`**${tool.name}**: ${tool.description}`);
520
- const schema = tool.inputSchema;
521
- if (schema.properties) {
522
- const params = Object.entries(schema.properties);
523
- if (params.length > 0) {
524
- lines.push("Parameters:");
525
- for (const [name, prop] of params) {
526
- const required = schema.required?.includes(name) ? " (required)" : "";
527
- lines.push(` - \`${name}\`: ${prop.description || prop.type}${required}`);
528
- }
529
- }
530
- }
531
- lines.push("");
532
- }
533
- }
534
- return lines.join("\n");
535
- }
536
- /**
537
- * Check if the manager is initialized
538
- */
539
- isInitialized() {
540
- return this.initialized;
541
- }
542
- /**
543
- * Get configuration file path
544
- */
545
- getConfigPath() {
546
- return this.configPath;
547
- }
548
- /**
549
- * Clear tool cache
550
- */
551
- clearCache() {
552
- this.toolCache.clear();
553
- }
554
- }
555
- let managerInstance = null;
556
- async function getMcpServerManager() {
557
- if (!managerInstance) {
558
- managerInstance = new McpServerManager();
559
- await managerInstance.initialize();
560
- }
561
- return managerInstance;
562
- }
563
-
564
- const AGENT_TEMPLATES_DIR = join(CCJK_CONFIG_DIR, "agent-templates");
565
- class AgentBuilder {
566
- definition = {
567
- skills: [],
568
- mcpServers: [],
569
- capabilities: []
570
- };
571
- /**
572
- * Set agent ID
573
- */
574
- id(id) {
575
- this.definition.id = id;
576
- return this;
577
- }
578
- /**
579
- * Set agent name
580
- */
581
- name(name) {
582
- this.definition.name = typeof name === "string" ? { "en": name, "zh-CN": name } : name;
583
- return this;
584
- }
585
- /**
586
- * Set agent description
587
- */
588
- description(desc) {
589
- this.definition.description = typeof desc === "string" ? { "en": desc, "zh-CN": desc } : desc;
590
- return this;
591
- }
592
- /**
593
- * Set agent persona/role
594
- */
595
- persona(persona) {
596
- this.definition.persona = persona;
597
- return this;
598
- }
599
- /**
600
- * Set agent instructions
601
- */
602
- instructions(instructions) {
603
- this.definition.instructions = instructions;
604
- return this;
605
- }
606
- /**
607
- * Add a skill
608
- */
609
- addSkill(pluginId, options = {}) {
610
- this.definition.skills.push({
611
- pluginId,
612
- ...options
613
- });
614
- return this;
615
- }
616
- /**
617
- * Add multiple skills
618
- */
619
- addSkills(pluginIds) {
620
- for (const id of pluginIds) {
621
- this.addSkill(id);
622
- }
623
- return this;
624
- }
625
- /**
626
- * Add an MCP server
627
- */
628
- addMcpServer(serverName, options = {}) {
629
- this.definition.mcpServers.push({
630
- serverName,
631
- ...options
632
- });
633
- return this;
634
- }
635
- /**
636
- * Add multiple MCP servers
637
- */
638
- addMcpServers(serverNames) {
639
- for (const name of serverNames) {
640
- this.addMcpServer(name);
641
- }
642
- return this;
643
- }
644
- /**
645
- * Add capability
646
- */
647
- addCapability(capability) {
648
- if (!this.definition.capabilities.includes(capability)) {
649
- this.definition.capabilities.push(capability);
650
- }
651
- return this;
652
- }
653
- /**
654
- * Add multiple capabilities
655
- */
656
- addCapabilities(capabilities) {
657
- for (const cap of capabilities) {
658
- this.addCapability(cap);
659
- }
660
- return this;
661
- }
662
- /**
663
- * Set trigger patterns
664
- */
665
- triggers(patterns) {
666
- this.definition.triggers = patterns;
667
- return this;
668
- }
669
- /**
670
- * Build the agent definition
671
- */
672
- build() {
673
- if (!this.definition.id) {
674
- throw new Error("Agent ID is required");
675
- }
676
- if (!this.definition.name) {
677
- throw new Error("Agent name is required");
678
- }
679
- if (!this.definition.description) {
680
- throw new Error("Agent description is required");
681
- }
682
- if (!this.definition.persona) {
683
- this.definition.persona = "You are a helpful AI assistant.";
684
- }
685
- if (!this.definition.instructions) {
686
- this.definition.instructions = "";
687
- }
688
- return this.definition;
689
- }
690
- /**
691
- * Build and save the agent
692
- */
693
- async save() {
694
- const definition = this.build();
695
- const manager = await getPluginManager();
696
- await manager.createAgent(definition);
697
- return definition;
698
- }
699
- }
700
- class AgentCreator {
701
- /**
702
- * Create a new agent builder
703
- */
704
- create() {
705
- return new AgentBuilder();
706
- }
707
- /**
708
- * Create agent from template
709
- */
710
- async fromTemplate(templateId, overrides = {}) {
711
- const template = await this.loadTemplate(templateId);
712
- if (!template) {
713
- throw new Error(`Template not found: ${templateId}`);
714
- }
715
- const definition = {
716
- id: overrides.id || `${templateId}-${Date.now()}`,
717
- name: overrides.name || template.name || { "en": templateId, "zh-CN": templateId },
718
- description: overrides.description || template.description || { "en": "", "zh-CN": "" },
719
- persona: overrides.persona || template.persona || "",
720
- instructions: overrides.instructions || template.instructions || "",
721
- skills: [...template.skills || [], ...overrides.skills || []],
722
- mcpServers: [...template.mcpServers || [], ...overrides.mcpServers || []],
723
- capabilities: [.../* @__PURE__ */ new Set([...template.capabilities || [], ...overrides.capabilities || []])],
724
- triggers: overrides.triggers || template.triggers,
725
- intents: overrides.intents || template.intents
726
- };
727
- const manager = await getPluginManager();
728
- await manager.createAgent(definition);
729
- return definition;
730
- }
731
- /**
732
- * Create agent from skills only
733
- */
734
- async fromSkills(id, name, skillIds, options = {}) {
735
- const builder = this.create().id(id).name(name).description(options.description || `Agent using skills: ${skillIds.join(", ")}`).addSkills(skillIds);
736
- if (options.persona) {
737
- builder.persona(options.persona);
738
- }
739
- if (options.instructions) {
740
- builder.instructions(options.instructions);
741
- }
742
- return builder.save();
743
- }
744
- /**
745
- * Create agent from MCP servers only
746
- */
747
- async fromMcpServers(id, name, serverNames, options = {}) {
748
- const builder = this.create().id(id).name(name).description(options.description || `Agent using MCP servers: ${serverNames.join(", ")}`).addMcpServers(serverNames);
749
- if (options.persona) {
750
- builder.persona(options.persona);
751
- }
752
- if (options.instructions) {
753
- builder.instructions(options.instructions);
754
- }
755
- return builder.save();
756
- }
757
- /**
758
- * Load a template
759
- */
760
- async loadTemplate(templateId) {
761
- const builtIn = BUILT_IN_TEMPLATES[templateId];
762
- if (builtIn) {
763
- return builtIn;
764
- }
765
- const templatePath = join(AGENT_TEMPLATES_DIR, `${templateId}.json`);
766
- if (existsSync(templatePath)) {
767
- return JSON.parse(readFileSync(templatePath, "utf-8"));
768
- }
769
- return null;
770
- }
771
- /**
772
- * Save a template
773
- */
774
- async saveTemplate(templateId, template) {
775
- if (!existsSync(AGENT_TEMPLATES_DIR)) {
776
- mkdirSync(AGENT_TEMPLATES_DIR, { recursive: true });
777
- }
778
- const templatePath = join(AGENT_TEMPLATES_DIR, `${templateId}.json`);
779
- writeFileSync(templatePath, JSON.stringify(template, null, 2));
780
- }
781
- /**
782
- * List available templates
783
- */
784
- listTemplates() {
785
- const templates = Object.keys(BUILT_IN_TEMPLATES);
786
- if (existsSync(AGENT_TEMPLATES_DIR)) {
787
- const files = readdirSync(AGENT_TEMPLATES_DIR);
788
- for (const file of files) {
789
- if (file.endsWith(".json") || file.endsWith(".md")) {
790
- templates.push(file.replace(/\.(json|md)$/, ""));
791
- }
792
- }
793
- }
794
- return templates;
795
- }
796
- /**
797
- * Write agent to Claude Code compatible location (project-local .claude-code/agents/)
798
- */
799
- async writeToClaudeCode(agent, options) {
800
- return writeAgentFile(agent, {
801
- format: "markdown",
802
- projectDir: options?.projectDir,
803
- global: false
804
- });
805
- }
806
- }
807
- class AgentRuntime {
808
- context;
809
- constructor(context) {
810
- this.context = context;
811
- }
812
- /**
813
- * Create runtime from agent ID
814
- */
815
- static async fromAgentId(agentId) {
816
- const manager = await getPluginManager();
817
- const agent = manager.getAgent(agentId);
818
- if (!agent) {
819
- throw new Error(`Agent not found: ${agentId}`);
820
- }
821
- const skills = [];
822
- for (const skillRef of agent.skills) {
823
- const plugin = manager.getPlugin(skillRef.pluginId);
824
- if (plugin) {
825
- skills.push(plugin);
826
- }
827
- }
828
- let mcpTools = [];
829
- if (agent.mcpServers && agent.mcpServers.length > 0) {
830
- try {
831
- const mcpManager = await getMcpServerManager();
832
- mcpTools = await mcpManager.getToolsForAgent(agent.mcpServers);
833
- } catch (error) {
834
- console.warn("Failed to load MCP tools:", error instanceof Error ? error.message : String(error));
835
- }
836
- }
837
- return new AgentRuntime({
838
- agent,
839
- skills,
840
- mcpTools,
841
- task: "",
842
- history: []
843
- });
844
- }
845
- /**
846
- * Get the system prompt for this agent
847
- */
848
- getSystemPrompt() {
849
- const parts = [];
850
- parts.push(this.context.agent.persona);
851
- parts.push("");
852
- if (this.context.agent.instructions) {
853
- parts.push("## Instructions");
854
- parts.push(this.context.agent.instructions);
855
- parts.push("");
856
- }
857
- if (this.context.skills.length > 0) {
858
- parts.push("## Available Skills");
859
- parts.push("");
860
- for (const skill of this.context.skills) {
861
- if (skill.skill) {
862
- parts.push(`### ${skill.skill.title}`);
863
- parts.push(skill.skill.description);
864
- parts.push("");
865
- if (skill.skill.applicability.taskTypes.length > 0) {
866
- parts.push("**When to use:**");
867
- for (const task of skill.skill.applicability.taskTypes) {
868
- parts.push(`- ${task}`);
869
- }
870
- parts.push("");
871
- }
872
- if (skill.skill.rules && skill.skill.rules.length > 0) {
873
- parts.push("**Key Rules:**");
874
- const criticalRules = skill.skill.rules.filter((r) => r.priority === "critical" || r.priority === "high");
875
- for (const rule of criticalRules.slice(0, 5)) {
876
- parts.push(`- **${rule.id}**: ${rule.title}`);
877
- }
878
- parts.push("");
879
- }
880
- }
881
- }
882
- }
883
- if (this.context.mcpTools.length > 0) {
884
- parts.push("## Available MCP Tools");
885
- parts.push("");
886
- const byServer = /* @__PURE__ */ new Map();
887
- for (const tool of this.context.mcpTools) {
888
- const serverTools = byServer.get(tool.server) || [];
889
- serverTools.push(tool);
890
- byServer.set(tool.server, serverTools);
891
- }
892
- for (const [server, serverTools] of byServer) {
893
- parts.push(`### ${server}`);
894
- parts.push("");
895
- for (const tool of serverTools) {
896
- parts.push(`**${tool.name}**: ${tool.description}`);
897
- const schema = tool.inputSchema;
898
- if (schema.properties) {
899
- const params = Object.entries(schema.properties);
900
- if (params.length > 0) {
901
- parts.push("Parameters:");
902
- for (const [name, prop] of params) {
903
- const required = schema.required?.includes(name) ? " (required)" : "";
904
- parts.push(` - \`${name}\`: ${prop.description || prop.type}${required}`);
905
- }
906
- }
907
- }
908
- parts.push("");
909
- }
910
- }
911
- }
912
- if (this.context.agent.capabilities.length > 0) {
913
- parts.push("## Capabilities");
914
- parts.push("");
915
- for (const cap of this.context.agent.capabilities) {
916
- parts.push(`- ${this.formatCapability(cap)}`);
917
- }
918
- parts.push("");
919
- }
920
- return parts.join("\n");
921
- }
922
- /**
923
- * Get full skill content for context
924
- */
925
- getSkillContent() {
926
- const parts = [];
927
- for (const skill of this.context.skills) {
928
- if (skill.skill) {
929
- parts.push(`# ${skill.skill.title}`);
930
- parts.push("");
931
- parts.push(skill.skill.rawContent);
932
- parts.push("");
933
- parts.push("---");
934
- parts.push("");
935
- }
936
- }
937
- return parts.join("\n");
938
- }
939
- /**
940
- * Add message to history
941
- */
942
- addMessage(role, content) {
943
- this.context.history = this.context.history || [];
944
- this.context.history.push({
945
- role,
946
- content,
947
- timestamp: Date.now()
948
- });
949
- }
950
- /**
951
- * Get conversation history
952
- */
953
- getHistory() {
954
- return this.context.history || [];
955
- }
956
- /**
957
- * Set current task
958
- */
959
- setTask(task) {
960
- this.context.task = task;
961
- }
962
- /**
963
- * Format capability for display
964
- */
965
- formatCapability(cap) {
966
- const labels = {
967
- "code-generation": "Code Generation",
968
- "code-review": "Code Review",
969
- "testing": "Testing",
970
- "documentation": "Documentation",
971
- "deployment": "Deployment",
972
- "debugging": "Debugging",
973
- "refactoring": "Refactoring",
974
- "git-operations": "Git Operations",
975
- "file-management": "File Management",
976
- "web-search": "Web Search",
977
- "api-integration": "API Integration"
978
- };
979
- return labels[cap] || cap;
980
- }
981
- }
982
- const BUILT_IN_TEMPLATES = {
983
- "code-assistant": {
984
- name: { "en": "Code Assistant", "zh-CN": "\u4EE3\u7801\u52A9\u624B" },
985
- description: { "en": "General-purpose coding assistant", "zh-CN": "\u901A\u7528\u7F16\u7A0B\u52A9\u624B" },
986
- persona: `You are an expert software engineer with deep knowledge of multiple programming languages and frameworks. You write clean, efficient, and well-documented code. You follow best practices and design patterns.`,
987
- capabilities: ["code-generation", "code-review", "debugging", "refactoring"],
988
- instructions: `
989
- - Always explain your reasoning before writing code
990
- - Follow the project's existing code style
991
- - Write comprehensive error handling
992
- - Add helpful comments for complex logic
993
- - Suggest tests for new functionality
994
- `
995
- },
996
- "git-master": {
997
- name: { "en": "Git Master", "zh-CN": "Git \u5927\u5E08" },
998
- description: { "en": "Expert Git operations assistant", "zh-CN": "Git \u64CD\u4F5C\u4E13\u5BB6" },
999
- persona: `You are a Git expert who helps with version control operations. You write clear, conventional commit messages and help manage branches effectively.`,
1000
- capabilities: ["git-operations"],
1001
- instructions: `
1002
- - Use conventional commit format (feat:, fix:, docs:, etc.)
1003
- - Suggest appropriate branch names
1004
- - Help resolve merge conflicts
1005
- - Explain Git concepts when needed
1006
- `
1007
- },
1008
- "test-engineer": {
1009
- name: { "en": "Test Engineer", "zh-CN": "\u6D4B\u8BD5\u5DE5\u7A0B\u5E08" },
1010
- description: { "en": "Testing and quality assurance specialist", "zh-CN": "\u6D4B\u8BD5\u548C\u8D28\u91CF\u4FDD\u8BC1\u4E13\u5BB6" },
1011
- persona: `You are a QA engineer specializing in software testing. You write comprehensive test cases and help ensure code quality.`,
1012
- capabilities: ["testing", "code-review"],
1013
- instructions: `
1014
- - Write tests that cover edge cases
1015
- - Use appropriate testing frameworks (Jest, Vitest, etc.)
1016
- - Follow AAA pattern (Arrange, Act, Assert)
1017
- - Aim for high test coverage
1018
- - Include both unit and integration tests
1019
- `
1020
- },
1021
- "devops-engineer": {
1022
- name: { "en": "DevOps Engineer", "zh-CN": "DevOps \u5DE5\u7A0B\u5E08" },
1023
- description: { "en": "DevOps and deployment specialist", "zh-CN": "DevOps \u548C\u90E8\u7F72\u4E13\u5BB6" },
1024
- persona: `You are a DevOps engineer who helps with CI/CD, containerization, and deployment. You write efficient Dockerfiles and deployment configurations.`,
1025
- capabilities: ["deployment", "file-management"],
1026
- instructions: `
1027
- - Write optimized Dockerfiles with multi-stage builds
1028
- - Create comprehensive CI/CD pipelines
1029
- - Follow security best practices
1030
- - Use environment variables for configuration
1031
- - Document deployment procedures
1032
- `
1033
- },
1034
- "full-stack": {
1035
- name: { "en": "Full Stack Developer", "zh-CN": "\u5168\u6808\u5F00\u53D1\u8005" },
1036
- description: { "en": "Full stack development assistant", "zh-CN": "\u5168\u6808\u5F00\u53D1\u52A9\u624B" },
1037
- persona: `You are a full-stack developer proficient in both frontend and backend development. You build complete, production-ready applications.`,
1038
- capabilities: ["code-generation", "code-review", "testing", "documentation", "deployment"],
1039
- instructions: `
1040
- - Consider both frontend and backend implications
1041
- - Write responsive and accessible UI
1042
- - Design RESTful APIs
1043
- - Implement proper authentication and authorization
1044
- - Optimize for performance
1045
- `
1046
- }
1047
- };
1048
- let creatorInstance = null;
1049
- function getAgentCreator() {
1050
- if (!creatorInstance) {
1051
- creatorInstance = new AgentCreator();
1052
- }
1053
- return creatorInstance;
1054
- }
1055
- function createAgent() {
1056
- return new AgentBuilder();
1057
- }
1058
- async function createAgentFromTemplate(templateId, overrides = {}) {
1059
- const creator = getAgentCreator();
1060
- return creator.fromTemplate(templateId, overrides);
1061
- }
1062
- async function getAgentRuntime(agentId) {
1063
- return AgentRuntime.fromAgentId(agentId);
1064
- }
1065
-
1066
- async function handleAgentCommand(args, options = {}) {
1067
- const subcommand = args[0];
1068
- const restArgs = args.slice(1);
1069
- switch (subcommand) {
1070
- case "create":
1071
- case "new":
1072
- await createNewAgent(restArgs[0], options);
1073
- break;
1074
- case "list":
1075
- case "ls":
1076
- await listAgents(options);
1077
- break;
1078
- case "info":
1079
- case "show":
1080
- await showAgentInfo(restArgs[0], options);
1081
- break;
1082
- case "remove":
1083
- case "rm":
1084
- case "delete":
1085
- await removeAgent(restArgs[0]);
1086
- break;
1087
- case "run":
1088
- case "start":
1089
- await runAgent(restArgs[0], restArgs.slice(1).join(" "));
1090
- break;
1091
- case "templates":
1092
- await listTemplates(options);
1093
- break;
1094
- default:
1095
- showAgentHelp();
1096
- }
1097
- }
1098
- async function createNewAgent(name, options) {
1099
- if (!name) {
1100
- console.log(a.red("Error: Please specify an agent name"));
1101
- console.log(a.dim("Example: agent create my-assistant"));
1102
- return;
1103
- }
1104
- console.log(a.cyan(`
1105
- \u{1F916} Creating agent: ${name}
1106
- `));
1107
- try {
1108
- let agent;
1109
- if (options.template) {
1110
- console.log(a.dim(`Using template: ${options.template}`));
1111
- agent = await createAgentFromTemplate(options.template, {
1112
- id: name,
1113
- name: { "en": name, "zh-CN": name }
1114
- });
1115
- } else {
1116
- const builder = createAgent().id(name).name(name).description(`Custom agent: ${name}`);
1117
- if (options.skills && options.skills.length > 0) {
1118
- builder.addSkills(options.skills);
1119
- console.log(a.dim(`Adding skills: ${options.skills.join(", ")}`));
1120
- }
1121
- if (options.mcp && options.mcp.length > 0) {
1122
- builder.addMcpServers(options.mcp);
1123
- console.log(a.dim(`Adding MCP servers: ${options.mcp.join(", ")}`));
1124
- }
1125
- if (options.persona) {
1126
- builder.persona(options.persona);
1127
- }
1128
- agent = await builder.save();
1129
- }
1130
- console.log(a.green(`
1131
- \u2705 Agent created successfully!`));
1132
- console.log("");
1133
- console.log(a.bold("Agent Details:"));
1134
- console.log(a.dim(` ID: ${agent.id}`));
1135
- console.log(a.dim(` Name: ${agent.name.en}`));
1136
- console.log(a.dim(` Skills: ${agent.skills.length}`));
1137
- console.log(a.dim(` MCP Servers: ${agent.mcpServers.length}`));
1138
- console.log(a.dim(` Capabilities: ${agent.capabilities.join(", ")}`));
1139
- console.log("");
1140
- console.log(a.dim(`Run with: agent run ${agent.id}`));
1141
- } catch (error) {
1142
- console.log(a.red(`\u274C Failed to create agent: ${error instanceof Error ? error.message : error}`));
1143
- }
1144
- }
1145
- async function listAgents(options) {
1146
- const manager = await getPluginManager();
1147
- const agents = manager.listAgents();
1148
- if (options.json) {
1149
- console.log(JSON.stringify(agents, null, 2));
1150
- return;
1151
- }
1152
- console.log(a.cyan("\n\u{1F916} Installed Agents\n"));
1153
- if (agents.length === 0) {
1154
- console.log(a.dim("No agents created yet."));
1155
- console.log(a.dim("\nCreate an agent with:"));
1156
- console.log(a.dim(" agent create my-assistant --template code-assistant"));
1157
- console.log(a.dim(" agent create my-agent --skills git-helper,code-reviewer"));
1158
- return;
1159
- }
1160
- for (const agent of agents) {
1161
- const name = agent.name.en || agent.id;
1162
- console.log(` ${a.bold(name)} ${a.dim(`(${agent.id})`)}`);
1163
- console.log(a.dim(` ${agent.description.en}`));
1164
- const badges = [];
1165
- if (agent.skills.length > 0)
1166
- badges.push(`\u{1F4DA} ${agent.skills.length} skills`);
1167
- if (agent.mcpServers.length > 0)
1168
- badges.push(`\u{1F527} ${agent.mcpServers.length} MCP`);
1169
- if (agent.capabilities.length > 0)
1170
- badges.push(`\u26A1 ${agent.capabilities.length} capabilities`);
1171
- if (badges.length > 0) {
1172
- console.log(a.dim(` ${badges.join(" \u2022 ")}`));
1173
- }
1174
- console.log("");
1175
- }
1176
- console.log(a.dim(`Total: ${agents.length} agents`));
1177
- }
1178
- async function showAgentInfo(agentId, options) {
1179
- if (!agentId) {
1180
- console.log(a.red("Error: Please specify an agent ID"));
1181
- return;
1182
- }
1183
- const manager = await getPluginManager();
1184
- const agent = manager.getAgent(agentId);
1185
- if (!agent) {
1186
- console.log(a.red(`Agent not found: ${agentId}`));
1187
- return;
1188
- }
1189
- if (options.json) {
1190
- console.log(JSON.stringify(agent, null, 2));
1191
- return;
1192
- }
1193
- console.log("");
1194
- console.log(a.bold(a.cyan(`\u{1F916} ${agent.name.en}`)));
1195
- console.log(a.dim(`ID: ${agent.id}`));
1196
- console.log("");
1197
- console.log(a.bold("\u{1F4DD} Description"));
1198
- console.log(a.dim(` ${agent.description.en}`));
1199
- console.log("");
1200
- console.log(a.bold("\u{1F3AD} Persona"));
1201
- console.log(a.dim(` ${agent.persona.substring(0, 200)}${agent.persona.length > 200 ? "..." : ""}`));
1202
- console.log("");
1203
- if (agent.instructions) {
1204
- console.log(a.bold("\u{1F4CB} Instructions"));
1205
- const lines = agent.instructions.split("\n").slice(0, 5);
1206
- for (const line of lines) {
1207
- console.log(a.dim(` ${line}`));
1208
- }
1209
- if (agent.instructions.split("\n").length > 5) {
1210
- console.log(a.dim(" ..."));
1211
- }
1212
- console.log("");
1213
- }
1214
- if (agent.skills.length > 0) {
1215
- console.log(a.bold("\u{1F4DA} Skills"));
1216
- for (const skill of agent.skills) {
1217
- const plugin = manager.getPlugin(skill.pluginId);
1218
- const name = plugin?.manifest.name.en || skill.pluginId;
1219
- console.log(a.dim(` \u2022 ${name}`));
1220
- }
1221
- console.log("");
1222
- }
1223
- if (agent.mcpServers.length > 0) {
1224
- console.log(a.bold("\u{1F527} MCP Servers"));
1225
- for (const mcp of agent.mcpServers) {
1226
- console.log(a.dim(` \u2022 ${mcp.serverName}`));
1227
- if (mcp.tools && mcp.tools.length > 0) {
1228
- console.log(a.dim(` Tools: ${mcp.tools.join(", ")}`));
1229
- }
1230
- }
1231
- console.log("");
1232
- }
1233
- if (agent.capabilities.length > 0) {
1234
- console.log(a.bold("\u26A1 Capabilities"));
1235
- for (const cap of agent.capabilities) {
1236
- console.log(a.dim(` \u2022 ${formatCapability(cap)}`));
1237
- }
1238
- console.log("");
1239
- }
1240
- if (agent.triggers && agent.triggers.length > 0) {
1241
- console.log(a.bold("\u{1F3AF} Triggers"));
1242
- for (const trigger of agent.triggers) {
1243
- console.log(a.dim(` \u2022 ${trigger}`));
1244
- }
1245
- console.log("");
1246
- }
1247
- console.log(a.bold("\u{1F4AC} System Prompt Preview"));
1248
- try {
1249
- const runtime = await getAgentRuntime(agentId);
1250
- const prompt = runtime.getSystemPrompt();
1251
- const lines = prompt.split("\n").slice(0, 10);
1252
- for (const line of lines) {
1253
- console.log(a.dim(` ${line}`));
1254
- }
1255
- console.log(a.dim(" ..."));
1256
- } catch {
1257
- console.log(a.dim(" (Unable to generate preview)"));
1258
- }
1259
- }
1260
- async function removeAgent(agentId) {
1261
- if (!agentId) {
1262
- console.log(a.red("Error: Please specify an agent ID"));
1263
- return;
1264
- }
1265
- const manager = await getPluginManager();
1266
- const agent = manager.getAgent(agentId);
1267
- if (!agent) {
1268
- console.log(a.red(`Agent not found: ${agentId}`));
1269
- return;
1270
- }
1271
- console.log(a.yellow(`
1272
- \u26A0\uFE0F Removing agent: ${agent.name.en}`));
1273
- console.log(a.red("Agent removal not yet implemented"));
1274
- }
1275
- async function runAgent(agentId, task) {
1276
- if (!agentId) {
1277
- console.log(a.red("Error: Please specify an agent ID"));
1278
- return;
1279
- }
1280
- const manager = await getPluginManager();
1281
- const agent = manager.getAgent(agentId);
1282
- if (!agent) {
1283
- console.log(a.red(`Agent not found: ${agentId}`));
1284
- return;
1285
- }
1286
- console.log(a.cyan(`
1287
- \u{1F916} Starting agent: ${agent.name.en}
1288
- `));
1289
- try {
1290
- const runtime = await getAgentRuntime(agentId);
1291
- console.log(a.bold("System Prompt:"));
1292
- console.log(a.dim("\u2500".repeat(60)));
1293
- console.log(a.dim(runtime.getSystemPrompt()));
1294
- console.log(a.dim("\u2500".repeat(60)));
1295
- console.log("");
1296
- if (task) {
1297
- runtime.setTask(task);
1298
- console.log(a.bold("Task:"));
1299
- console.log(a.dim(task));
1300
- console.log("");
1301
- }
1302
- const skillContent = runtime.getSkillContent();
1303
- if (skillContent) {
1304
- console.log(a.bold("Skill Knowledge:"));
1305
- console.log(a.dim("\u2500".repeat(60)));
1306
- const lines = skillContent.split("\n").slice(0, 20);
1307
- for (const line of lines) {
1308
- console.log(a.dim(line));
1309
- }
1310
- if (skillContent.split("\n").length > 20) {
1311
- console.log(a.dim("... (truncated)"));
1312
- }
1313
- console.log(a.dim("\u2500".repeat(60)));
1314
- }
1315
- console.log("");
1316
- console.log(a.green("\u2705 Agent ready!"));
1317
- console.log(a.dim("The system prompt and skill knowledge above can be used with Claude."));
1318
- } catch (error) {
1319
- console.log(a.red(`\u274C Failed to start agent: ${error instanceof Error ? error.message : error}`));
1320
- }
1321
- }
1322
- async function listTemplates(options) {
1323
- const creator = getAgentCreator();
1324
- const templates = creator.listTemplates();
1325
- if (options.json) {
1326
- console.log(JSON.stringify(templates, null, 2));
1327
- return;
1328
- }
1329
- console.log(a.cyan("\n\u{1F4CB} Available Agent Templates\n"));
1330
- const templateInfo = {
1331
- "code-assistant": {
1332
- name: "Code Assistant",
1333
- description: "General-purpose coding assistant",
1334
- capabilities: ["code-generation", "code-review", "debugging", "refactoring"]
1335
- },
1336
- "git-master": {
1337
- name: "Git Master",
1338
- description: "Expert Git operations assistant",
1339
- capabilities: ["git-operations"]
1340
- },
1341
- "test-engineer": {
1342
- name: "Test Engineer",
1343
- description: "Testing and quality assurance specialist",
1344
- capabilities: ["testing", "code-review"]
1345
- },
1346
- "devops-engineer": {
1347
- name: "DevOps Engineer",
1348
- description: "DevOps and deployment specialist",
1349
- capabilities: ["deployment", "file-management"]
1350
- },
1351
- "full-stack": {
1352
- name: "Full Stack Developer",
1353
- description: "Full stack development assistant",
1354
- capabilities: ["code-generation", "code-review", "testing", "documentation", "deployment"]
1355
- }
1356
- };
1357
- for (const templateId of templates) {
1358
- const info = templateInfo[templateId];
1359
- if (info) {
1360
- console.log(` ${a.bold(info.name)} ${a.dim(`(${templateId})`)}`);
1361
- console.log(a.dim(` ${info.description}`));
1362
- console.log(a.dim(` Capabilities: ${info.capabilities.join(", ")}`));
1363
- console.log("");
1364
- } else {
1365
- console.log(` ${a.bold(templateId)}`);
1366
- console.log("");
1367
- }
1368
- }
1369
- console.log(a.dim("Create an agent from template:"));
1370
- console.log(a.dim(" agent create my-assistant --template code-assistant"));
1371
- }
1372
- function formatCapability(cap) {
1373
- const labels = {
1374
- "code-generation": "Code Generation",
1375
- "code-review": "Code Review",
1376
- "testing": "Testing",
1377
- "documentation": "Documentation",
1378
- "deployment": "Deployment",
1379
- "debugging": "Debugging",
1380
- "refactoring": "Refactoring",
1381
- "git-operations": "Git Operations",
1382
- "file-management": "File Management",
1383
- "web-search": "Web Search",
1384
- "api-integration": "API Integration"
1385
- };
1386
- return labels[cap] || cap;
1387
- }
1388
- function showAgentHelp() {
1389
- console.log(`
1390
- ${a.bold(a.cyan("\u{1F916} Agent Command"))}
1391
-
1392
- ${a.bold("Usage:")}
1393
- agent <command> [options]
1394
-
1395
- ${a.bold("Commands:")}
1396
- ${a.green("create")} <name> Create a new agent
1397
- ${a.green("list")} List all agents
1398
- ${a.green("info")} <id> Show agent details
1399
- ${a.green("remove")} <id> Remove an agent
1400
- ${a.green("run")} <id> [task] Run an agent
1401
- ${a.green("templates")} List available templates
1402
-
1403
- ${a.bold("Options:")}
1404
- --template <id> Use a template (code-assistant, git-master, etc.)
1405
- --skills <ids> Comma-separated skill IDs to include
1406
- --mcp <servers> Comma-separated MCP server names
1407
- --persona <text> Custom persona for the agent
1408
- --json Output as JSON
1409
-
1410
- ${a.bold("Examples:")}
1411
- ${a.dim("# Create from template")}
1412
- agent create my-assistant --template code-assistant
1413
-
1414
- ${a.dim("# Create with specific skills")}
1415
- agent create reviewer --skills code-reviewer,react-best-practices
1416
-
1417
- ${a.dim("# Create with MCP servers")}
1418
- agent create deployer --mcp vercel,github --skills vercel-deploy
1419
-
1420
- ${a.dim("# List all agents")}
1421
- agent list
1422
-
1423
- ${a.dim("# Run an agent")}
1424
- agent run my-assistant "Review this code"
1425
-
1426
- ${a.bold("Agent Composition:")}
1427
- Agents combine Skills (knowledge) + MCP (tools) + Persona (behavior)
1428
-
1429
- \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510
1430
- \u2502 Agent \u2502
1431
- \u2502 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502
1432
- \u2502 \u2502 Skills \u2502 +\u2502 MCP \u2502 +\u2502 Persona \u2502 \u2502
1433
- \u2502 \u2502(\u77E5\u8BC6\u5E93) \u2502 \u2502 (\u5DE5\u5177) \u2502 \u2502 (\u884C\u4E3A) \u2502 \u2502
1434
- \u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2502
1435
- \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518
1436
- `);
1437
- }
1438
-
1439
- export { handleAgentCommand as default, handleAgentCommand };