@liangjie559567/ultrapower 7.2.0 → 7.4.0

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 (92) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/agents/AGENTS.md +1 -1
  4. package/bridge/AGENTS.md +1 -1
  5. package/bridge/codex-server.cjs +2 -2
  6. package/bridge/gemini-server.cjs +1 -1
  7. package/bridge/mcp-server.cjs +17 -1
  8. package/commands/AGENTS.md +1 -1
  9. package/dist/cli/utils/setup.d.ts.map +1 -1
  10. package/dist/cli/utils/setup.js +19 -1
  11. package/dist/cli/utils/setup.js.map +1 -1
  12. package/dist/cli/utils/update.d.ts.map +1 -1
  13. package/dist/cli/utils/update.js +3 -1
  14. package/dist/cli/utils/update.js.map +1 -1
  15. package/dist/features/mcp-autodiscovery/capability-matcher.d.ts +17 -0
  16. package/dist/features/mcp-autodiscovery/capability-matcher.d.ts.map +1 -0
  17. package/dist/features/mcp-autodiscovery/capability-matcher.js +26 -0
  18. package/dist/features/mcp-autodiscovery/capability-matcher.js.map +1 -0
  19. package/dist/features/mcp-autodiscovery/config-injector.d.ts +11 -0
  20. package/dist/features/mcp-autodiscovery/config-injector.d.ts.map +1 -0
  21. package/dist/features/mcp-autodiscovery/config-injector.js +28 -0
  22. package/dist/features/mcp-autodiscovery/config-injector.js.map +1 -0
  23. package/dist/features/mcp-autodiscovery/index.d.ts +6 -0
  24. package/dist/features/mcp-autodiscovery/index.d.ts.map +1 -0
  25. package/dist/features/mcp-autodiscovery/index.js +5 -0
  26. package/dist/features/mcp-autodiscovery/index.js.map +1 -0
  27. package/dist/features/mcp-autodiscovery/installer.d.ts +10 -0
  28. package/dist/features/mcp-autodiscovery/installer.d.ts.map +1 -0
  29. package/dist/features/mcp-autodiscovery/installer.js +21 -0
  30. package/dist/features/mcp-autodiscovery/installer.js.map +1 -0
  31. package/dist/features/mcp-autodiscovery/registry-client.d.ts +9 -0
  32. package/dist/features/mcp-autodiscovery/registry-client.d.ts.map +1 -0
  33. package/dist/features/mcp-autodiscovery/registry-client.js +34 -0
  34. package/dist/features/mcp-autodiscovery/registry-client.js.map +1 -0
  35. package/dist/features/mcp-autodiscovery/types.d.ts +19 -0
  36. package/dist/features/mcp-autodiscovery/types.d.ts.map +1 -0
  37. package/dist/features/mcp-autodiscovery/types.js +2 -0
  38. package/dist/features/mcp-autodiscovery/types.js.map +1 -0
  39. package/dist/features/unified-context/context-manager.d.ts +24 -0
  40. package/dist/features/unified-context/context-manager.d.ts.map +1 -0
  41. package/dist/features/unified-context/context-manager.js +59 -0
  42. package/dist/features/unified-context/context-manager.js.map +1 -0
  43. package/dist/features/unified-context/index.d.ts +3 -0
  44. package/dist/features/unified-context/index.d.ts.map +1 -0
  45. package/dist/features/unified-context/index.js +3 -0
  46. package/dist/features/unified-context/index.js.map +1 -0
  47. package/dist/features/unified-context/mcp-memory-client.d.ts +14 -0
  48. package/dist/features/unified-context/mcp-memory-client.d.ts.map +1 -0
  49. package/dist/features/unified-context/mcp-memory-client.js +68 -0
  50. package/dist/features/unified-context/mcp-memory-client.js.map +1 -0
  51. package/dist/lib/atomic-write.d.ts.map +1 -1
  52. package/dist/lib/atomic-write.js +21 -2
  53. package/dist/lib/atomic-write.js.map +1 -1
  54. package/dist/lib/upgrade.d.ts +12 -0
  55. package/dist/lib/upgrade.d.ts.map +1 -0
  56. package/dist/lib/upgrade.js +119 -0
  57. package/dist/lib/upgrade.js.map +1 -0
  58. package/dist/mcp/adapters/memory-adapter.d.ts +2 -2
  59. package/dist/mcp/adapters/state-adapter.d.ts +4 -4
  60. package/dist/mcp/adapters/trace-adapter.d.ts +1 -1
  61. package/dist/team/message-router.d.ts +2 -2
  62. package/dist/team/message-router.d.ts.map +1 -1
  63. package/dist/team/message-router.js +4 -4
  64. package/dist/team/message-router.js.map +1 -1
  65. package/dist/team/task-router.d.ts +1 -1
  66. package/dist/team/task-router.d.ts.map +1 -1
  67. package/dist/team/task-router.js +2 -2
  68. package/dist/team/task-router.js.map +1 -1
  69. package/dist/team/unified-team.d.ts +4 -1
  70. package/dist/team/unified-team.d.ts.map +1 -1
  71. package/dist/team/unified-team.js +17 -8
  72. package/dist/team/unified-team.js.map +1 -1
  73. package/docs/AGENTS.md +4 -3
  74. package/docs/CLAUDE.md +1 -1
  75. package/docs/INSTALL.md +47 -7
  76. package/docs/REFERENCE.md +1 -1
  77. package/docs/UPGRADE.md +88 -0
  78. package/docs/UPGRADE_VERIFICATION.md +6 -6
  79. package/docs/dev-standards/AGENTS.md +68 -0
  80. package/docs/mcp-intelligent-orchestration.md +302 -0
  81. package/docs/migration/v6.0.0.md +2 -2
  82. package/docs/plans/2026-03-14-mcp-intelligent-orchestration.md +679 -0
  83. package/docs/standards/README.md +1 -1
  84. package/hooks/AGENTS.md +1 -1
  85. package/package.json +1 -1
  86. package/scripts/AGENTS.md +1 -1
  87. package/scripts/plugin-setup.mjs +23 -22
  88. package/scripts/upgrade-complete.sh +34 -0
  89. package/scripts/upgrade.mjs +158 -0
  90. package/skills/AGENTS.md +3 -2
  91. package/templates/AGENTS.md +1 -1
  92. package/templates/hooks/session-start.mjs +2 -2
@@ -0,0 +1,679 @@
1
+ # MCP 智能编排系统实现计划
2
+
3
+ > **For Claude:** REQUIRED SUB-SKILL: Use ultrapower:executing-plans to implement this plan task-by-task.
4
+
5
+ **Goal:** 构建基于 MCP 生态的自动发现、统一上下文和智能编排系统
6
+
7
+ **Architecture:**
8
+ - Phase 1: 集成 MCP Memory 服务器实现跨 agent 统一上下文
9
+ - Phase 2: 实现 MCP Registry 客户端支持能力自动发现
10
+ - Phase 3: 构建自动安装器和安全验证机制
11
+
12
+ **Tech Stack:**
13
+ - MCP SDK (@modelcontextprotocol/sdk)
14
+ - MCP Memory Server (官方知识图谱)
15
+ - TypeScript, Zod, Better-SQLite3
16
+
17
+ ---
18
+
19
+ ## Phase 1: MCP Memory 集成(统一上下文)
20
+
21
+ ### Task 1: MCP Memory 客户端封装
22
+
23
+ **Files:**
24
+ * Create: `src/features/unified-context/mcp-memory-client.ts`
25
+ * Create: `src/features/unified-context/index.ts`
26
+ * Create: `src/features/unified-context/__tests__/mcp-memory-client.test.ts`
27
+
28
+ **Step 1: 编写测试**
29
+
30
+ ```typescript
31
+ // src/features/unified-context/__tests__/mcp-memory-client.test.ts
32
+ import { describe, it, expect, beforeEach } from 'vitest';
33
+ import { MCPMemoryClient } from '../mcp-memory-client';
34
+
35
+ describe('MCPMemoryClient', () => {
36
+ let client: MCPMemoryClient;
37
+
38
+ beforeEach(() => {
39
+ client = new MCPMemoryClient();
40
+ });
41
+
42
+ it('should connect to MCP Memory server', async () => {
43
+ await expect(client.connect()).resolves.not.toThrow();
44
+ });
45
+
46
+ it('should store and retrieve context', async () => {
47
+ await client.connect();
48
+ await client.storeContext('test-key', { data: 'test-value' });
49
+ const result = await client.getContext('test-key');
50
+ expect(result).toEqual({ data: 'test-value' });
51
+ });
52
+
53
+ it('should create knowledge graph entities', async () => {
54
+ await client.connect();
55
+ const entityId = await client.createEntity({
56
+ name: 'test-entity',
57
+ type: 'context',
58
+ observations: ['test observation']
59
+ });
60
+ expect(entityId).toBeDefined();
61
+ });
62
+ });
63
+ ```
64
+
65
+ **Step 2: 运行测试验证失败**
66
+
67
+ ```bash
68
+ npm test src/features/unified-context/__tests__/mcp-memory-client.test.ts
69
+ ```
70
+ Expected: FAIL - MCPMemoryClient not defined
71
+
72
+ **Step 3: 实现最小客户端**
73
+
74
+ ```typescript
75
+ // src/features/unified-context/mcp-memory-client.ts
76
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
77
+ import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
78
+
79
+ export class MCPMemoryClient {
80
+ private client: Client | null = null;
81
+ private transport: StdioClientTransport | null = null;
82
+
83
+ async connect(): Promise<void> {
84
+ this.transport = new StdioClientTransport({
85
+ command: 'npx',
86
+ args: ['-y', '@modelcontextprotocol/server-memory']
87
+ });
88
+
89
+ this.client = new Client({
90
+ name: 'ultrapower-memory-client',
91
+ version: '1.0.0'
92
+ }, {
93
+ capabilities: {}
94
+ });
95
+
96
+ await this.client.connect(this.transport);
97
+ }
98
+
99
+ async storeContext(key: string, value: unknown): Promise<void> {
100
+ if (!this.client) throw new Error('Not connected');
101
+
102
+ await this.client.callTool({
103
+ name: 'create_entities',
104
+ arguments: {
105
+ entities: [{
106
+ name: key,
107
+ entityType: 'context',
108
+ observations: [JSON.stringify(value)]
109
+ }]
110
+ }
111
+ });
112
+ }
113
+
114
+ async getContext(key: string): Promise<unknown> {
115
+ if (!this.client) throw new Error('Not connected');
116
+
117
+ const result = await this.client.callTool({
118
+ name: 'search_nodes',
119
+ arguments: { query: key }
120
+ });
121
+
122
+ const content = result.content[0];
123
+ if (content.type === 'text') {
124
+ const match = content.text.match(/observations: \[(.*?)\]/);
125
+ if (match) {
126
+ return JSON.parse(match[1].replace(/'/g, '"'));
127
+ }
128
+ }
129
+ return null;
130
+ }
131
+
132
+ async createEntity(entity: {
133
+ name: string;
134
+ type: string;
135
+ observations: string[];
136
+ }): Promise<string> {
137
+ if (!this.client) throw new Error('Not connected');
138
+
139
+ const result = await this.client.callTool({
140
+ name: 'create_entities',
141
+ arguments: {
142
+ entities: [{
143
+ name: entity.name,
144
+ entityType: entity.type,
145
+ observations: entity.observations
146
+ }]
147
+ }
148
+ });
149
+
150
+ return entity.name;
151
+ }
152
+
153
+ async disconnect(): Promise<void> {
154
+ if (this.client) {
155
+ await this.client.close();
156
+ this.client = null;
157
+ }
158
+ }
159
+ }
160
+ ```
161
+
162
+ **Step 4: 运行测试验证通过**
163
+
164
+ ```bash
165
+ npm test src/features/unified-context/__tests__/mcp-memory-client.test.ts
166
+ ```
167
+ Expected: PASS
168
+
169
+ **Step 5: 提交**
170
+
171
+ ```bash
172
+ git add src/features/unified-context/
173
+ git commit -m "feat(unified-context): add MCP Memory client wrapper"
174
+ ```
175
+
176
+ ---
177
+
178
+ ### Task 2: 统一上下文管理器
179
+
180
+ **Files:**
181
+ * Create: `src/features/unified-context/context-manager.ts`
182
+ * Create: `src/features/unified-context/__tests__/context-manager.test.ts`
183
+ * Modify: `src/features/unified-context/index.ts`
184
+
185
+ **Step 1: 编写测试**
186
+
187
+ ```typescript
188
+ // src/features/unified-context/__tests__/context-manager.test.ts
189
+ import { describe, it, expect, beforeEach, afterEach } from 'vitest';
190
+ import { UnifiedContextManager } from '../context-manager';
191
+
192
+ describe('UnifiedContextManager', () => {
193
+ let manager: UnifiedContextManager;
194
+
195
+ beforeEach(async () => {
196
+ manager = new UnifiedContextManager();
197
+ await manager.initialize();
198
+ });
199
+
200
+ afterEach(async () => {
201
+ await manager.shutdown();
202
+ });
203
+
204
+ it('should share context across agents', async () => {
205
+ await manager.setAgentContext('agent-1', { task: 'implement feature' });
206
+ const context = await manager.getSharedContext();
207
+ expect(context['agent-1']).toEqual({ task: 'implement feature' });
208
+ });
209
+
210
+ it('should sync context updates', async () => {
211
+ await manager.setAgentContext('agent-1', { status: 'in-progress' });
212
+ await manager.setAgentContext('agent-2', { status: 'waiting' });
213
+
214
+ const allContexts = await manager.getAllAgentContexts();
215
+ expect(allContexts).toHaveLength(2);
216
+ });
217
+
218
+ it('should create knowledge graph relations', async () => {
219
+ await manager.createRelation('task-1', 'depends-on', 'task-2');
220
+ const relations = await manager.getRelations('task-1');
221
+ expect(relations).toContainEqual({
222
+ from: 'task-1',
223
+ type: 'depends-on',
224
+ to: 'task-2'
225
+ });
226
+ });
227
+ });
228
+ ```
229
+
230
+ **Step 2: 运行测试验证失败**
231
+
232
+ ```bash
233
+ npm test src/features/unified-context/__tests__/context-manager.test.ts
234
+ ```
235
+ Expected: FAIL - UnifiedContextManager not defined
236
+
237
+ **Step 3: 实现上下文管理器**
238
+
239
+ ```typescript
240
+ // src/features/unified-context/context-manager.ts
241
+ import { MCPMemoryClient } from './mcp-memory-client.js';
242
+
243
+ interface AgentContext {
244
+ [key: string]: unknown;
245
+ }
246
+
247
+ interface Relation {
248
+ from: string;
249
+ type: string;
250
+ to: string;
251
+ }
252
+
253
+ export class UnifiedContextManager {
254
+ private memoryClient: MCPMemoryClient;
255
+ private initialized = false;
256
+
257
+ constructor() {
258
+ this.memoryClient = new MCPMemoryClient();
259
+ }
260
+
261
+ async initialize(): Promise<void> {
262
+ await this.memoryClient.connect();
263
+ this.initialized = true;
264
+ }
265
+
266
+ async setAgentContext(agentId: string, context: AgentContext): Promise<void> {
267
+ if (!this.initialized) throw new Error('Not initialized');
268
+
269
+ await this.memoryClient.createEntity({
270
+ name: `agent-context-${agentId}`,
271
+ type: 'agent-context',
272
+ observations: [JSON.stringify(context)]
273
+ });
274
+ }
275
+
276
+ async getSharedContext(): Promise<Record<string, AgentContext>> {
277
+ if (!this.initialized) throw new Error('Not initialized');
278
+
279
+ // 简化实现:返回所有 agent 上下文
280
+ return {};
281
+ }
282
+
283
+ async getAllAgentContexts(): Promise<AgentContext[]> {
284
+ if (!this.initialized) throw new Error('Not initialized');
285
+
286
+ // 简化实现:查询所有 agent-context 类型实体
287
+ return [];
288
+ }
289
+
290
+ async createRelation(from: string, type: string, to: string): Promise<void> {
291
+ if (!this.initialized) throw new Error('Not initialized');
292
+
293
+ await this.memoryClient.createEntity({
294
+ name: `relation-${from}-${to}`,
295
+ type: 'relation',
296
+ observations: [JSON.stringify({ from, type, to })]
297
+ });
298
+ }
299
+
300
+ async getRelations(entityId: string): Promise<Relation[]> {
301
+ if (!this.initialized) throw new Error('Not initialized');
302
+
303
+ // 简化实现:查询相关关系
304
+ return [];
305
+ }
306
+
307
+ async shutdown(): Promise<void> {
308
+ await this.memoryClient.disconnect();
309
+ this.initialized = false;
310
+ }
311
+ }
312
+ ```
313
+
314
+ **Step 4: 运行测试验证通过**
315
+
316
+ ```bash
317
+ npm test src/features/unified-context/__tests__/context-manager.test.ts
318
+ ```
319
+ Expected: PASS
320
+
321
+ **Step 5: 提交**
322
+
323
+ ```bash
324
+ git add src/features/unified-context/
325
+ git commit -m "feat(unified-context): add context manager with MCP Memory backend"
326
+ ```
327
+
328
+ ---
329
+
330
+ ### Task 3: 集成到 Team Pipeline
331
+
332
+ **Files:**
333
+ * Modify: `src/team/pipeline.ts:45-60`
334
+ * Modify: `src/team/agent-spawner.ts:30-45`
335
+ * Create: `src/team/__tests__/unified-context-integration.test.ts`
336
+
337
+ **Step 1: 编写集成测试**
338
+
339
+ ```typescript
340
+ // src/team/__tests__/unified-context-integration.test.ts
341
+ import { describe, it, expect } from 'vitest';
342
+ import { TeamPipeline } from '../pipeline';
343
+ import { UnifiedContextManager } from '../../features/unified-context';
344
+
345
+ describe('Team Pipeline with Unified Context', () => {
346
+ it('should share context across team agents', async () => {
347
+ const contextManager = new UnifiedContextManager();
348
+ await contextManager.initialize();
349
+
350
+ const pipeline = new TeamPipeline({
351
+ contextManager,
352
+ teamName: 'test-team'
353
+ });
354
+
355
+ await pipeline.start();
356
+ // 验证所有 agents 可访问共享上下文
357
+ });
358
+ });
359
+ ```
360
+
361
+ **Step 2: 修改 Team Pipeline 注入上下文管理器**
362
+
363
+ ```typescript
364
+ // src/team/pipeline.ts (修改 45-60 行)
365
+ import { UnifiedContextManager } from '../features/unified-context/index.js';
366
+
367
+ export class TeamPipeline {
368
+ private contextManager?: UnifiedContextManager;
369
+
370
+ constructor(options: { contextManager?: UnifiedContextManager }) {
371
+ this.contextManager = options.contextManager;
372
+ }
373
+
374
+ async start() {
375
+ if (this.contextManager) {
376
+ await this.contextManager.initialize();
377
+ }
378
+ // 现有逻辑...
379
+ }
380
+ }
381
+ ```
382
+
383
+ **Step 3: 修改 Agent Spawner 传递上下文**
384
+
385
+ ```typescript
386
+ // src/team/agent-spawner.ts (修改 30-45 行)
387
+ async spawnAgent(agentType: string, prompt: string) {
388
+ const agentContext = await this.contextManager?.getSharedContext();
389
+
390
+ return Agent({
391
+ subagent_type: agentType,
392
+ prompt: `${prompt}\n\nShared Context: ${JSON.stringify(agentContext)}`,
393
+ // ...
394
+ });
395
+ }
396
+ ```
397
+
398
+ **Step 4: 运行测试**
399
+
400
+ ```bash
401
+ npm test src/team/__tests__/unified-context-integration.test.ts
402
+ ```
403
+
404
+ **Step 5: 提交**
405
+
406
+ ```bash
407
+ git add src/team/ src/features/unified-context/
408
+ git commit -m "feat(team): integrate unified context manager into Team Pipeline"
409
+ ```
410
+
411
+ ---
412
+
413
+ ## Phase 2: MCP Registry 客户端(能力发现)
414
+
415
+ ### Task 4: Registry API 客户端
416
+
417
+ **Files:**
418
+ * Create: `src/features/mcp-autodiscovery/registry-client.ts`
419
+ * Create: `src/features/mcp-autodiscovery/types.ts`
420
+ * Create: `src/features/mcp-autodiscovery/__tests__/registry-client.test.ts`
421
+
422
+ **Step 1: 定义类型**
423
+
424
+ ```typescript
425
+ // src/features/mcp-autodiscovery/types.ts
426
+ export interface MCPServerDescriptor {
427
+ id: string;
428
+ name: string;
429
+ version: string;
430
+ description: string;
431
+ capabilities: string[];
432
+ repository?: string;
433
+ package?: {
434
+ type: 'npm' | 'uvx' | 'docker';
435
+ name: string;
436
+ };
437
+ official: boolean;
438
+ }
439
+
440
+ export interface CapabilityQuery {
441
+ capability?: string;
442
+ search?: string;
443
+ official?: boolean;
444
+ }
445
+ ```
446
+
447
+ **Step 2: 编写测试**
448
+
449
+ ```typescript
450
+ // src/features/mcp-autodiscovery/__tests__/registry-client.test.ts
451
+ import { describe, it, expect } from 'vitest';
452
+ import { MCPRegistryClient } from '../registry-client';
453
+
454
+ describe('MCPRegistryClient', () => {
455
+ it('should fetch servers from registry', async () => {
456
+ const client = new MCPRegistryClient();
457
+ const servers = await client.listServers();
458
+ expect(servers).toBeInstanceOf(Array);
459
+ });
460
+
461
+ it('should search by capability', async () => {
462
+ const client = new MCPRegistryClient();
463
+ const servers = await client.searchByCapability('web-scraping');
464
+ expect(servers.length).toBeGreaterThan(0);
465
+ });
466
+
467
+ it('should filter official servers', async () => {
468
+ const client = new MCPRegistryClient();
469
+ const servers = await client.listServers({ official: true });
470
+ expect(servers.every(s => s.official)).toBe(true);
471
+ });
472
+ });
473
+ ```
474
+
475
+ **Step 3: 实现客户端**
476
+
477
+ ```typescript
478
+ // src/features/mcp-autodiscovery/registry-client.ts
479
+ import type { MCPServerDescriptor, CapabilityQuery } from './types.js';
480
+
481
+ const REGISTRY_API = 'https://registry.modelcontextprotocol.io/v0.1';
482
+
483
+ export class MCPRegistryClient {
484
+ private cache: Map<string, MCPServerDescriptor[]> = new Map();
485
+ private cacheExpiry = 3600000; // 1 hour
486
+
487
+ async listServers(query?: CapabilityQuery): Promise<MCPServerDescriptor[]> {
488
+ const cacheKey = JSON.stringify(query || {});
489
+ const cached = this.cache.get(cacheKey);
490
+ if (cached) return cached;
491
+
492
+ const params = new URLSearchParams();
493
+ if (query?.capability) params.set('capability', query.capability);
494
+ if (query?.search) params.set('search', query.search);
495
+ if (query?.official !== undefined) params.set('official', String(query.official));
496
+
497
+ const response = await fetch(`${REGISTRY_API}/servers?${params}`);
498
+ const data = await response.json();
499
+
500
+ this.cache.set(cacheKey, data.servers);
501
+ setTimeout(() => this.cache.delete(cacheKey), this.cacheExpiry);
502
+
503
+ return data.servers;
504
+ }
505
+
506
+ async searchByCapability(capability: string): Promise<MCPServerDescriptor[]> {
507
+ return this.listServers({ capability });
508
+ }
509
+
510
+ async getServerById(id: string): Promise<MCPServerDescriptor | null> {
511
+ const servers = await this.listServers();
512
+ return servers.find(s => s.id === id) || null;
513
+ }
514
+ }
515
+ ```
516
+
517
+ **Step 4: 运行测试**
518
+
519
+ ```bash
520
+ npm test src/features/mcp-autodiscovery/__tests__/registry-client.test.ts
521
+ ```
522
+
523
+ **Step 5: 提交**
524
+
525
+ ```bash
526
+ git add src/features/mcp-autodiscovery/
527
+ git commit -m "feat(mcp-autodiscovery): add MCP Registry API client"
528
+ ```
529
+
530
+ ---
531
+
532
+ ### Task 5: 能力匹配引擎
533
+
534
+ **Files:**
535
+ * Create: `src/features/mcp-autodiscovery/capability-matcher.ts`
536
+ * Create: `src/features/mcp-autodiscovery/__tests__/capability-matcher.test.ts`
537
+
538
+ **Step 1: 编写测试**
539
+
540
+ ```typescript
541
+ // src/features/mcp-autodiscovery/__tests__/capability-matcher.test.ts
542
+ import { describe, it, expect } from 'vitest';
543
+ import { CapabilityMatcher } from '../capability-matcher';
544
+
545
+ describe('CapabilityMatcher', () => {
546
+ it('should match task requirements to server capabilities', async () => {
547
+ const matcher = new CapabilityMatcher();
548
+ const matches = await matcher.findMatches({
549
+ taskDescription: 'scrape data from website',
550
+ requiredCapabilities: ['web-scraping', 'data-extraction']
551
+ });
552
+
553
+ expect(matches.length).toBeGreaterThan(0);
554
+ expect(matches[0].confidence).toBeGreaterThan(0.7);
555
+ });
556
+
557
+ it('should rank matches by confidence', async () => {
558
+ const matcher = new CapabilityMatcher();
559
+ const matches = await matcher.findMatches({
560
+ taskDescription: 'fetch web content',
561
+ requiredCapabilities: ['web']
562
+ });
563
+
564
+ // 验证按置信度降序排列
565
+ for (let i = 1; i < matches.length; i++) {
566
+ expect(matches[i-1].confidence).toBeGreaterThanOrEqual(matches[i].confidence);
567
+ }
568
+ });
569
+ });
570
+ ```
571
+
572
+ **Step 2: 实现匹配引擎**
573
+
574
+ ```typescript
575
+ // src/features/mcp-autodiscovery/capability-matcher.ts
576
+ import { MCPRegistryClient } from './registry-client.js';
577
+ import type { MCPServerDescriptor } from './types.js';
578
+
579
+ interface TaskRequirement {
580
+ taskDescription: string;
581
+ requiredCapabilities: string[];
582
+ }
583
+
584
+ interface Match {
585
+ server: MCPServerDescriptor;
586
+ confidence: number;
587
+ matchedCapabilities: string[];
588
+ }
589
+
590
+ export class CapabilityMatcher {
591
+ private registryClient: MCPRegistryClient;
592
+
593
+ constructor() {
594
+ this.registryClient = new MCPRegistryClient();
595
+ }
596
+
597
+ async findMatches(requirement: TaskRequirement): Promise<Match[]> {
598
+ const allServers = await this.registryClient.listServers();
599
+ const matches: Match[] = [];
600
+
601
+ for (const server of allServers) {
602
+ const matchedCaps = requirement.requiredCapabilities.filter(
603
+ cap => server.capabilities.some(sc => sc.includes(cap) || cap.includes(sc))
604
+ );
605
+
606
+ if (matchedCaps.length > 0) {
607
+ const confidence = matchedCaps.length / requirement.requiredCapabilities.length;
608
+ matches.push({
609
+ server,
610
+ confidence,
611
+ matchedCapabilities: matchedCaps
612
+ });
613
+ }
614
+ }
615
+
616
+ return matches.sort((a, b) => b.confidence - a.confidence);
617
+ }
618
+ }
619
+ ```
620
+
621
+ **Step 3: 运行测试**
622
+
623
+ ```bash
624
+ npm test src/features/mcp-autodiscovery/__tests__/capability-matcher.test.ts
625
+ ```
626
+
627
+ **Step 4: 提交**
628
+
629
+ ```bash
630
+ git add src/features/mcp-autodiscovery/
631
+ git commit -m "feat(mcp-autodiscovery): add capability matching engine"
632
+ ```
633
+
634
+ ---
635
+
636
+ ## Phase 3: 自动安装器(安全验证)
637
+
638
+ ### Task 6: MCP 服务器安装器
639
+
640
+ **Files:**
641
+ * Create: `src/features/mcp-autodiscovery/installer.ts`
642
+ * Create: `src/features/mcp-autodiscovery/__tests__/installer.test.ts`
643
+
644
+ **Implementation:** 支持 npm、uvx、docker 三种安装方式,包含安全白名单验证。
645
+
646
+ ### Task 7: 配置自动注入
647
+
648
+ **Files:**
649
+ * Modify: `src/mcp/mcp-config.ts`
650
+ * Create: `src/features/mcp-autodiscovery/config-injector.ts`
651
+
652
+ **Implementation:** 自动更新 `.mcp.json` 配置文件。
653
+
654
+ ---
655
+
656
+ ## 验证清单
657
+
658
+ - [ ] Phase 1 所有测试通过
659
+ - [ ] Phase 2 所有测试通过
660
+ - [ ] Phase 3 所有测试通过
661
+ - [ ] 集成测试通过
662
+ - [ ] 文档更新(README、AGENTS.md)
663
+ - [ ] 性能测试(上下文同步延迟 < 100ms)
664
+
665
+ ---
666
+
667
+ ## 风险与缓解
668
+
669
+ | 风险 | 缓解措施 |
670
+ | ------ | --------- |
671
+ | MCP Memory 服务器不稳定 | 实现降级到本地 SQLite |
672
+ | Registry API 限流 | 本地缓存 + 指数退避 |
673
+ | 安全漏洞(恶意 MCP 服务器) | 官方服务器白名单 + 沙箱隔离 |
674
+
675
+ ---
676
+
677
+ **Estimated Time:** 3-4 周
678
+ **Priority:** P0(核心功能)
679
+ **Dependencies:** @modelcontextprotocol/sdk, @modelcontextprotocol/server-memory
@@ -5,7 +5,7 @@
5
5
  > **最后更新**: 2026-03-02
6
6
  > **真理之源**: `docs/standards/audit-report.md`
7
7
 
8
- ultrapower v7.2.0 具备 49 个 agents、70 个 skills、35 个 hooks 的完整体系。本规范体系从现有代码反向提取,覆盖运行时防护、Hook 执行顺序、状态机、Agent 生命周期、用户使用指南和贡献规范,使 ultrapower 从"能用"升级为"可靠、易用、可扩展"。
8
+ ultrapower v7.3.0 具备 49 个 agents、70 个 skills、35 个 hooks 的完整体系。本规范体系从现有代码反向提取,覆盖运行时防护、Hook 执行顺序、状态机、Agent 生命周期、用户使用指南和贡献规范,使 ultrapower 从"能用"升级为"可靠、易用、可扩展"。
9
9
 
10
10
  ---
11
11
 
package/hooks/AGENTS.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <!-- Parent: ../AGENTS.md -->
2
- <!-- Generated: 2026-02-27 | Updated: 2026-02-27 -->
2
+ <!-- Generated: 2026-03-14 | Updated: 2026-03-14 -->
3
3
 
4
4
  # hooks/
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liangjie559567/ultrapower",
3
- "version": "7.2.0",
3
+ "version": "7.4.0",
4
4
  "description": "Disciplined multi-agent orchestration: workflow enforcement + parallel execution",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/scripts/AGENTS.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <!-- Parent: ../AGENTS.md -->
2
- <!-- Generated: 2026-02-27 | Updated: 2026-02-27 -->
2
+ <!-- Generated: 2026-03-14 | Updated: 2026-03-14 -->
3
3
 
4
4
  # scripts/
5
5