ccjk 2.6.2 → 3.0.2

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