@nick848/sf-cli 1.0.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.
- package/LICENSE +21 -0
- package/README.md +151 -0
- package/dist/cli/index.js +6029 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.d.mts +1961 -0
- package/dist/index.d.ts +1961 -0
- package/dist/index.js +7655 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +7590 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +92 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1961 @@
|
|
|
1
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* AI模型相关类型定义
|
|
6
|
+
*/
|
|
7
|
+
type MessageRole = 'system' | 'user' | 'assistant' | 'tool';
|
|
8
|
+
interface ToolCall {
|
|
9
|
+
id: string;
|
|
10
|
+
type: 'function';
|
|
11
|
+
function: {
|
|
12
|
+
name: string;
|
|
13
|
+
arguments: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
interface ChatMessage {
|
|
17
|
+
role: MessageRole;
|
|
18
|
+
content: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
toolCalls?: ToolCall[];
|
|
21
|
+
toolCallId?: string;
|
|
22
|
+
}
|
|
23
|
+
type FinishReason = 'stop' | 'length' | 'tool_call' | 'content_filter' | 'error' | 'end_turn' | 'max_tokens' | 'stop_sequence';
|
|
24
|
+
interface TokenUsage$1 {
|
|
25
|
+
inputTokens: number;
|
|
26
|
+
outputTokens: number;
|
|
27
|
+
totalTokens: number;
|
|
28
|
+
}
|
|
29
|
+
interface ChatResponse {
|
|
30
|
+
id: string;
|
|
31
|
+
model: string;
|
|
32
|
+
content: string;
|
|
33
|
+
toolCalls?: ToolCall[];
|
|
34
|
+
usage: TokenUsage$1;
|
|
35
|
+
finishReason: FinishReason;
|
|
36
|
+
latency?: number;
|
|
37
|
+
}
|
|
38
|
+
interface StreamChunk {
|
|
39
|
+
id: string;
|
|
40
|
+
model: string;
|
|
41
|
+
delta: string;
|
|
42
|
+
finishReason?: FinishReason;
|
|
43
|
+
}
|
|
44
|
+
type ModelProvider = 'glm' | 'openai' | 'anthropic' | 'qwen' | 'deepseek';
|
|
45
|
+
interface ModelConfig {
|
|
46
|
+
provider: ModelProvider;
|
|
47
|
+
model: string;
|
|
48
|
+
apiKey: string;
|
|
49
|
+
apiEndpoint?: string;
|
|
50
|
+
temperature?: number;
|
|
51
|
+
maxTokens?: number;
|
|
52
|
+
timeout?: number;
|
|
53
|
+
retries?: number;
|
|
54
|
+
}
|
|
55
|
+
interface RequestOptions {
|
|
56
|
+
temperature?: number;
|
|
57
|
+
maxTokens?: number;
|
|
58
|
+
topP?: number;
|
|
59
|
+
stopSequences?: string[];
|
|
60
|
+
tools?: ToolDefinition[];
|
|
61
|
+
toolChoice?: 'auto' | 'none' | {
|
|
62
|
+
type: 'function';
|
|
63
|
+
function: {
|
|
64
|
+
name: string;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
systemPrompt?: string;
|
|
68
|
+
timeout?: number;
|
|
69
|
+
}
|
|
70
|
+
interface ToolDefinition {
|
|
71
|
+
type: 'function';
|
|
72
|
+
function: {
|
|
73
|
+
name: string;
|
|
74
|
+
description: string;
|
|
75
|
+
parameters: Record<string, unknown>;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
interface TokenStats$1 {
|
|
79
|
+
totalInput: number;
|
|
80
|
+
totalOutput: number;
|
|
81
|
+
byModel: Record<string, TokenUsage$1>;
|
|
82
|
+
byAgent: Record<string, TokenUsage$1>;
|
|
83
|
+
byDate: Record<string, TokenUsage$1>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Agent 系统类型定义
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
type AgentId = 'frontend-dev' | 'code-reviewer' | 'architect' | 'tester';
|
|
91
|
+
type AgentStatus = 'idle' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
92
|
+
type AgentTriggerType = 'manual' | 'workflow' | 'intent' | 'event';
|
|
93
|
+
type ToolPermissionLevel = 'full' | 'limited' | 'confirm' | 'none';
|
|
94
|
+
interface AgentTool {
|
|
95
|
+
name: string;
|
|
96
|
+
description: string;
|
|
97
|
+
permission: ToolPermissionLevel;
|
|
98
|
+
parameters?: Record<string, unknown>;
|
|
99
|
+
}
|
|
100
|
+
interface AgentCapability {
|
|
101
|
+
id: string;
|
|
102
|
+
name: string;
|
|
103
|
+
description: string;
|
|
104
|
+
inputSchema?: Record<string, unknown>;
|
|
105
|
+
outputSchema?: Record<string, unknown>;
|
|
106
|
+
}
|
|
107
|
+
interface AgentTrigger {
|
|
108
|
+
type: AgentTriggerType;
|
|
109
|
+
condition: {
|
|
110
|
+
workflowStep?: WorkflowStep;
|
|
111
|
+
intent?: string[];
|
|
112
|
+
event?: string;
|
|
113
|
+
};
|
|
114
|
+
priority: number;
|
|
115
|
+
}
|
|
116
|
+
interface AgentConstraints {
|
|
117
|
+
files?: {
|
|
118
|
+
maxFileSize?: number;
|
|
119
|
+
maxFilesPerTask?: number;
|
|
120
|
+
allowedExtensions?: string[];
|
|
121
|
+
protectedPaths?: string[];
|
|
122
|
+
};
|
|
123
|
+
code?: {
|
|
124
|
+
maxLineLength?: number;
|
|
125
|
+
maxFunctionLength?: number;
|
|
126
|
+
maxFileLines?: number;
|
|
127
|
+
requireTypes?: boolean;
|
|
128
|
+
requireTests?: boolean;
|
|
129
|
+
};
|
|
130
|
+
dependencies?: {
|
|
131
|
+
allowedLicenses?: string[];
|
|
132
|
+
requireApproval?: string[];
|
|
133
|
+
blacklist?: string[];
|
|
134
|
+
};
|
|
135
|
+
behavior?: {
|
|
136
|
+
requireConfirmation?: string[];
|
|
137
|
+
autoCommit?: boolean;
|
|
138
|
+
autoPush?: boolean;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
interface AgentDefinition {
|
|
142
|
+
id: AgentId;
|
|
143
|
+
name: string;
|
|
144
|
+
description: string;
|
|
145
|
+
icon: string;
|
|
146
|
+
version: string;
|
|
147
|
+
role: string;
|
|
148
|
+
capabilities: AgentCapability[];
|
|
149
|
+
tools: AgentTool[];
|
|
150
|
+
triggers: AgentTrigger[];
|
|
151
|
+
constraints: AgentConstraints;
|
|
152
|
+
systemPrompt: string;
|
|
153
|
+
taskPromptTemplate: string;
|
|
154
|
+
outputFormat?: {
|
|
155
|
+
type: 'text' | 'json' | 'markdown';
|
|
156
|
+
schema?: Record<string, unknown>;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
interface ProjectContext {
|
|
160
|
+
agentsMd: string;
|
|
161
|
+
configYaml: string;
|
|
162
|
+
devStandards: string;
|
|
163
|
+
}
|
|
164
|
+
interface AgentExecutionContext {
|
|
165
|
+
taskId: string;
|
|
166
|
+
workflowId?: string;
|
|
167
|
+
workflowStep?: WorkflowStep;
|
|
168
|
+
requirement: string;
|
|
169
|
+
files?: string[];
|
|
170
|
+
context?: string;
|
|
171
|
+
norms?: string[];
|
|
172
|
+
previousOutput?: string;
|
|
173
|
+
projectContext?: ProjectContext;
|
|
174
|
+
}
|
|
175
|
+
interface AgentExecutionResult {
|
|
176
|
+
success: boolean;
|
|
177
|
+
output: string;
|
|
178
|
+
structuredOutput?: Record<string, unknown>;
|
|
179
|
+
filesChanged?: string[];
|
|
180
|
+
tokensUsed: {
|
|
181
|
+
input: number;
|
|
182
|
+
output: number;
|
|
183
|
+
};
|
|
184
|
+
duration: number;
|
|
185
|
+
error?: string;
|
|
186
|
+
suggestions?: string[];
|
|
187
|
+
}
|
|
188
|
+
interface AgentSession {
|
|
189
|
+
id: string;
|
|
190
|
+
agentId: AgentId;
|
|
191
|
+
status: AgentStatus;
|
|
192
|
+
context: AgentExecutionContext;
|
|
193
|
+
messages: ChatMessage[];
|
|
194
|
+
result?: AgentExecutionResult;
|
|
195
|
+
startedAt: Date;
|
|
196
|
+
completedAt?: Date;
|
|
197
|
+
}
|
|
198
|
+
interface AgentScheduleRequest {
|
|
199
|
+
agentId: AgentId;
|
|
200
|
+
context: AgentExecutionContext;
|
|
201
|
+
options?: {
|
|
202
|
+
timeout?: number;
|
|
203
|
+
maxRetries?: number;
|
|
204
|
+
streamOutput?: boolean;
|
|
205
|
+
onProgress?: (chunk: string) => void;
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
interface AgentRegistry {
|
|
209
|
+
agents: Map<AgentId, AgentDefinition>;
|
|
210
|
+
customAgents: Map<string, AgentDefinition>;
|
|
211
|
+
}
|
|
212
|
+
interface ToolExecutor {
|
|
213
|
+
name: string;
|
|
214
|
+
execute: (params: Record<string, unknown>, context: AgentExecutionContext) => Promise<unknown>;
|
|
215
|
+
}
|
|
216
|
+
interface AgentEvent {
|
|
217
|
+
type: 'started' | 'progress' | 'completed' | 'failed' | 'cancelled';
|
|
218
|
+
agentId: AgentId;
|
|
219
|
+
sessionId: string;
|
|
220
|
+
timestamp: Date;
|
|
221
|
+
data?: unknown;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* MCP (Model Context Protocol) 相关类型定义
|
|
226
|
+
*/
|
|
227
|
+
interface MCPToolSchema {
|
|
228
|
+
name: string;
|
|
229
|
+
description: string;
|
|
230
|
+
inputSchema: {
|
|
231
|
+
type: 'object';
|
|
232
|
+
properties: Record<string, {
|
|
233
|
+
type: string;
|
|
234
|
+
description: string;
|
|
235
|
+
enum?: string[];
|
|
236
|
+
}>;
|
|
237
|
+
required?: string[];
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
interface MCPToolCall {
|
|
241
|
+
name: string;
|
|
242
|
+
arguments: Record<string, unknown>;
|
|
243
|
+
}
|
|
244
|
+
interface MCPToolResult {
|
|
245
|
+
content: Array<{
|
|
246
|
+
type: 'text' | 'image' | 'resource';
|
|
247
|
+
text?: string;
|
|
248
|
+
data?: string;
|
|
249
|
+
mimeType?: string;
|
|
250
|
+
}>;
|
|
251
|
+
isError?: boolean;
|
|
252
|
+
}
|
|
253
|
+
interface MCPResource {
|
|
254
|
+
uri: string;
|
|
255
|
+
name: string;
|
|
256
|
+
description?: string;
|
|
257
|
+
mimeType?: string;
|
|
258
|
+
}
|
|
259
|
+
interface MCPResourceContent {
|
|
260
|
+
uri: string;
|
|
261
|
+
mimeType?: string;
|
|
262
|
+
text?: string;
|
|
263
|
+
blob?: string;
|
|
264
|
+
}
|
|
265
|
+
type MCPTransportType = 'stdio' | 'http' | 'websocket';
|
|
266
|
+
interface MCPServerConfig {
|
|
267
|
+
name: string;
|
|
268
|
+
transport: MCPTransportType;
|
|
269
|
+
command?: string;
|
|
270
|
+
args?: string[];
|
|
271
|
+
url?: string;
|
|
272
|
+
env?: Record<string, string>;
|
|
273
|
+
timeout?: number;
|
|
274
|
+
retryAttempts?: number;
|
|
275
|
+
}
|
|
276
|
+
interface MCPClientConfig {
|
|
277
|
+
servers: MCPServerConfig[];
|
|
278
|
+
defaultTimeout?: number;
|
|
279
|
+
}
|
|
280
|
+
type MCPConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'error';
|
|
281
|
+
interface MCPConnectionState {
|
|
282
|
+
serverName: string;
|
|
283
|
+
status: MCPConnectionStatus;
|
|
284
|
+
error?: string;
|
|
285
|
+
lastConnected?: Date;
|
|
286
|
+
toolsAvailable: string[];
|
|
287
|
+
resourcesAvailable: string[];
|
|
288
|
+
}
|
|
289
|
+
interface DesignSpec {
|
|
290
|
+
id: string;
|
|
291
|
+
name: string;
|
|
292
|
+
platform: 'lanhu' | 'figma';
|
|
293
|
+
url: string;
|
|
294
|
+
width: number;
|
|
295
|
+
height: number;
|
|
296
|
+
scale: number;
|
|
297
|
+
layers: DesignLayer[];
|
|
298
|
+
styles: DesignStyle;
|
|
299
|
+
assets: DesignAsset[];
|
|
300
|
+
extractedAt: Date;
|
|
301
|
+
}
|
|
302
|
+
interface DesignLayer {
|
|
303
|
+
id: string;
|
|
304
|
+
name: string;
|
|
305
|
+
type: 'frame' | 'group' | 'text' | 'shape' | 'image';
|
|
306
|
+
x: number;
|
|
307
|
+
y: number;
|
|
308
|
+
width: number;
|
|
309
|
+
height: number;
|
|
310
|
+
visible: boolean;
|
|
311
|
+
opacity: number;
|
|
312
|
+
children?: DesignLayer[];
|
|
313
|
+
styles?: Partial<DesignStyle>;
|
|
314
|
+
text?: string;
|
|
315
|
+
}
|
|
316
|
+
interface DesignStyle {
|
|
317
|
+
colors: DesignColor[];
|
|
318
|
+
typography: DesignTypography[];
|
|
319
|
+
spacing: DesignSpacing[];
|
|
320
|
+
borders: DesignBorder[];
|
|
321
|
+
shadows: DesignShadow[];
|
|
322
|
+
}
|
|
323
|
+
interface DesignColor {
|
|
324
|
+
name?: string;
|
|
325
|
+
value: string;
|
|
326
|
+
usage?: string;
|
|
327
|
+
}
|
|
328
|
+
interface DesignTypography {
|
|
329
|
+
fontFamily: string;
|
|
330
|
+
fontSize: number;
|
|
331
|
+
fontWeight: number;
|
|
332
|
+
lineHeight: number;
|
|
333
|
+
letterSpacing?: number;
|
|
334
|
+
textAlign?: 'left' | 'center' | 'right';
|
|
335
|
+
}
|
|
336
|
+
interface DesignSpacing {
|
|
337
|
+
type: 'margin' | 'padding' | 'gap';
|
|
338
|
+
value: number;
|
|
339
|
+
unit: 'px' | 'rem' | '%';
|
|
340
|
+
}
|
|
341
|
+
interface DesignBorder {
|
|
342
|
+
width: number;
|
|
343
|
+
style: 'solid' | 'dashed' | 'dotted';
|
|
344
|
+
color: string;
|
|
345
|
+
radius?: number;
|
|
346
|
+
}
|
|
347
|
+
interface DesignShadow {
|
|
348
|
+
type: 'box' | 'text';
|
|
349
|
+
x: number;
|
|
350
|
+
y: number;
|
|
351
|
+
blur: number;
|
|
352
|
+
spread?: number;
|
|
353
|
+
color: string;
|
|
354
|
+
}
|
|
355
|
+
interface DesignAsset {
|
|
356
|
+
id: string;
|
|
357
|
+
name: string;
|
|
358
|
+
type: 'image' | 'icon' | 'svg';
|
|
359
|
+
url: string;
|
|
360
|
+
width?: number;
|
|
361
|
+
height?: number;
|
|
362
|
+
format?: string;
|
|
363
|
+
}
|
|
364
|
+
interface DesignParseResult {
|
|
365
|
+
success: boolean;
|
|
366
|
+
spec?: DesignSpec;
|
|
367
|
+
componentCode?: string;
|
|
368
|
+
styleCode?: string;
|
|
369
|
+
errors?: string[];
|
|
370
|
+
warnings?: string[];
|
|
371
|
+
}
|
|
372
|
+
interface IMCPAdapter {
|
|
373
|
+
readonly name: string;
|
|
374
|
+
readonly platform: 'lanhu' | 'figma';
|
|
375
|
+
initialize(config: MCPServerConfig): Promise<void>;
|
|
376
|
+
connect(): Promise<void>;
|
|
377
|
+
disconnect(): Promise<void>;
|
|
378
|
+
isConnected(): boolean;
|
|
379
|
+
listTools(): Promise<MCPToolSchema[]>;
|
|
380
|
+
callTool(call: MCPToolCall): Promise<MCPToolResult>;
|
|
381
|
+
listResources(): Promise<MCPResource[]>;
|
|
382
|
+
readResource(uri: string): Promise<MCPResourceContent>;
|
|
383
|
+
getDesignSpec(url: string): Promise<DesignSpec>;
|
|
384
|
+
extractStyles(spec: DesignSpec): Promise<DesignStyle>;
|
|
385
|
+
generateCode(spec: DesignSpec, options?: CodeGenOptions): Promise<string>;
|
|
386
|
+
}
|
|
387
|
+
interface CodeGenOptions {
|
|
388
|
+
framework?: 'react' | 'vue' | 'html';
|
|
389
|
+
styleType?: 'css' | 'scss' | 'tailwind' | 'styled-components';
|
|
390
|
+
componentType?: 'functional' | 'class';
|
|
391
|
+
typescript?: boolean;
|
|
392
|
+
}
|
|
393
|
+
interface MCPManagerState {
|
|
394
|
+
adapters: Map<string, IMCPAdapter>;
|
|
395
|
+
connections: Map<string, MCPConnectionState>;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* 类型定义 - 核心类型
|
|
400
|
+
*/
|
|
401
|
+
|
|
402
|
+
interface CLIConfig {
|
|
403
|
+
model: string;
|
|
404
|
+
apiKey: string;
|
|
405
|
+
apiEndpoint?: string;
|
|
406
|
+
yolo: boolean;
|
|
407
|
+
locale: string;
|
|
408
|
+
theme: 'light' | 'dark' | 'auto';
|
|
409
|
+
}
|
|
410
|
+
type WorkflowStep = 'explore' | 'new' | 'continue' | 'apply' | 'archive' | 'propose';
|
|
411
|
+
type WorkflowType = 'complex' | 'simple';
|
|
412
|
+
type WorkflowStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
413
|
+
interface WorkflowState {
|
|
414
|
+
id: string;
|
|
415
|
+
type: WorkflowType;
|
|
416
|
+
currentStep: WorkflowStep;
|
|
417
|
+
steps: WorkflowStepRecord[];
|
|
418
|
+
requirement: string;
|
|
419
|
+
title?: string;
|
|
420
|
+
complexity: number;
|
|
421
|
+
artifacts: string[];
|
|
422
|
+
status: WorkflowStatus;
|
|
423
|
+
createdAt: Date;
|
|
424
|
+
updatedAt?: Date;
|
|
425
|
+
completedAt?: Date;
|
|
426
|
+
cancelledAt?: Date;
|
|
427
|
+
cancelReason?: string;
|
|
428
|
+
}
|
|
429
|
+
interface WorkflowStepRecord {
|
|
430
|
+
step: WorkflowStep;
|
|
431
|
+
status: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
432
|
+
startedAt?: Date;
|
|
433
|
+
completedAt?: Date;
|
|
434
|
+
output?: string;
|
|
435
|
+
agent?: 'frontend-dev' | 'code-reviewer' | 'architect' | 'tester';
|
|
436
|
+
}
|
|
437
|
+
interface WorkflowTransition {
|
|
438
|
+
from: WorkflowStep;
|
|
439
|
+
to: WorkflowStep;
|
|
440
|
+
timestamp: Date;
|
|
441
|
+
reason?: string;
|
|
442
|
+
}
|
|
443
|
+
interface ChangeRecord {
|
|
444
|
+
id: string;
|
|
445
|
+
title: string;
|
|
446
|
+
status: WorkflowStatus;
|
|
447
|
+
created: Date;
|
|
448
|
+
completed?: Date;
|
|
449
|
+
complexity: number;
|
|
450
|
+
workflow: WorkflowType;
|
|
451
|
+
spec?: string;
|
|
452
|
+
summary?: string;
|
|
453
|
+
}
|
|
454
|
+
interface ContextMessage {
|
|
455
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
456
|
+
content: string;
|
|
457
|
+
tokens?: number;
|
|
458
|
+
}
|
|
459
|
+
interface ContextState {
|
|
460
|
+
messages: ContextMessage[];
|
|
461
|
+
totalTokens: number;
|
|
462
|
+
limit: number;
|
|
463
|
+
}
|
|
464
|
+
interface Task {
|
|
465
|
+
id: string;
|
|
466
|
+
type: 'feature' | 'bugfix' | 'refactor' | 'docs';
|
|
467
|
+
description: string;
|
|
468
|
+
status: 'pending' | 'in_progress' | 'review' | 'completed' | 'archived';
|
|
469
|
+
complexity: number;
|
|
470
|
+
workflow: WorkflowState;
|
|
471
|
+
files: string[];
|
|
472
|
+
createdAt: Date;
|
|
473
|
+
updatedAt: Date;
|
|
474
|
+
}
|
|
475
|
+
interface FileOperation {
|
|
476
|
+
type: 'read' | 'write' | 'edit' | 'delete';
|
|
477
|
+
path: string;
|
|
478
|
+
content?: string;
|
|
479
|
+
changes?: FileChange[];
|
|
480
|
+
}
|
|
481
|
+
interface FileChange {
|
|
482
|
+
startLine: number;
|
|
483
|
+
endLine: number;
|
|
484
|
+
oldContent: string;
|
|
485
|
+
newContent: string;
|
|
486
|
+
}
|
|
487
|
+
interface TokenUsage {
|
|
488
|
+
input: number;
|
|
489
|
+
output: number;
|
|
490
|
+
total: number;
|
|
491
|
+
byAgent: Partial<Record<'frontend-dev' | 'code-reviewer' | 'architect' | 'tester', number>>;
|
|
492
|
+
byStep: Partial<Record<WorkflowStep, number>>;
|
|
493
|
+
}
|
|
494
|
+
interface HealthReport {
|
|
495
|
+
overallScore: number;
|
|
496
|
+
categories: {
|
|
497
|
+
quality: number;
|
|
498
|
+
security: number;
|
|
499
|
+
performance: number;
|
|
500
|
+
maintainability: number;
|
|
501
|
+
};
|
|
502
|
+
issues: HealthIssue[];
|
|
503
|
+
suggestions: string[];
|
|
504
|
+
generatedAt: Date;
|
|
505
|
+
}
|
|
506
|
+
interface HealthIssue {
|
|
507
|
+
severity: 'error' | 'warning' | 'info';
|
|
508
|
+
category: string;
|
|
509
|
+
file: string;
|
|
510
|
+
line: number;
|
|
511
|
+
message: string;
|
|
512
|
+
suggestion?: string;
|
|
513
|
+
}
|
|
514
|
+
interface DevStandard {
|
|
515
|
+
id: string;
|
|
516
|
+
category: string;
|
|
517
|
+
description: string;
|
|
518
|
+
weight: number;
|
|
519
|
+
source: 'code-analysis' | 'conversation' | 'forced';
|
|
520
|
+
examples: string[];
|
|
521
|
+
createdAt: Date;
|
|
522
|
+
updatedAt: Date;
|
|
523
|
+
}
|
|
524
|
+
interface StandardWeight {
|
|
525
|
+
standardId: string;
|
|
526
|
+
weight: number;
|
|
527
|
+
occurrences: number;
|
|
528
|
+
lastOccurrence: Date;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* 配置管理服务
|
|
533
|
+
* 管理CLI配置的加载、保存和访问
|
|
534
|
+
* API Key 使用加密存储
|
|
535
|
+
*/
|
|
536
|
+
|
|
537
|
+
declare class ConfigManager {
|
|
538
|
+
private config;
|
|
539
|
+
private configPath;
|
|
540
|
+
private projectPath;
|
|
541
|
+
private encryptionKey;
|
|
542
|
+
constructor();
|
|
543
|
+
load(projectPath: string): Promise<void>;
|
|
544
|
+
save(): Promise<void>;
|
|
545
|
+
get<K extends keyof CLIConfig>(key: K): CLIConfig[K];
|
|
546
|
+
set<K extends keyof CLIConfig>(key: K, value: CLIConfig[K]): void;
|
|
547
|
+
getAll(): CLIConfig;
|
|
548
|
+
update(updates: Partial<CLIConfig>): void;
|
|
549
|
+
/**
|
|
550
|
+
* 加密敏感数据
|
|
551
|
+
*/
|
|
552
|
+
private encrypt;
|
|
553
|
+
/**
|
|
554
|
+
* 解密敏感数据
|
|
555
|
+
*/
|
|
556
|
+
private decrypt;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* AI模型调用服务
|
|
561
|
+
* 统一的模型调用接口,管理多个模型适配器
|
|
562
|
+
*/
|
|
563
|
+
|
|
564
|
+
declare class ModelService {
|
|
565
|
+
private adapters;
|
|
566
|
+
private currentConfig;
|
|
567
|
+
private stats;
|
|
568
|
+
private configManager;
|
|
569
|
+
private statsPath;
|
|
570
|
+
constructor(configManager: ConfigManager);
|
|
571
|
+
/**
|
|
572
|
+
* 初始化服务
|
|
573
|
+
*/
|
|
574
|
+
initialize(statsDir: string): Promise<void>;
|
|
575
|
+
/**
|
|
576
|
+
* 配置模型
|
|
577
|
+
*/
|
|
578
|
+
configureModel(config: ModelConfig): Promise<void>;
|
|
579
|
+
/**
|
|
580
|
+
* 发送消息
|
|
581
|
+
*/
|
|
582
|
+
sendMessage(messages: ChatMessage[], options?: RequestOptions & {
|
|
583
|
+
agent?: string;
|
|
584
|
+
}): Promise<ChatResponse>;
|
|
585
|
+
/**
|
|
586
|
+
* 流式发送消息
|
|
587
|
+
*/
|
|
588
|
+
streamMessage(messages: ChatMessage[], options?: RequestOptions & {
|
|
589
|
+
agent?: string;
|
|
590
|
+
}): AsyncGenerator<StreamChunk>;
|
|
591
|
+
/**
|
|
592
|
+
* 计算Token数量
|
|
593
|
+
*/
|
|
594
|
+
countTokens(text: string): number;
|
|
595
|
+
/**
|
|
596
|
+
* 获取当前模型
|
|
597
|
+
*/
|
|
598
|
+
getCurrentModel(): string | null;
|
|
599
|
+
/**
|
|
600
|
+
* 获取当前提供商
|
|
601
|
+
*/
|
|
602
|
+
getCurrentProvider(): ModelProvider | null;
|
|
603
|
+
/**
|
|
604
|
+
* 获取Token统计
|
|
605
|
+
*/
|
|
606
|
+
getStats(): TokenStats$1;
|
|
607
|
+
/**
|
|
608
|
+
* 获取今日统计
|
|
609
|
+
*/
|
|
610
|
+
getTodayStats(): TokenUsage$1;
|
|
611
|
+
/**
|
|
612
|
+
* 重置统计
|
|
613
|
+
*/
|
|
614
|
+
resetStats(): void;
|
|
615
|
+
/**
|
|
616
|
+
* 验证API Key
|
|
617
|
+
*/
|
|
618
|
+
validateApiKey(provider: ModelProvider, apiKey: string): Promise<boolean>;
|
|
619
|
+
private getProviderFromModel;
|
|
620
|
+
private updateStats;
|
|
621
|
+
private loadStats;
|
|
622
|
+
private saveStats;
|
|
623
|
+
private wrapError;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* MCP 客户端基类
|
|
628
|
+
*/
|
|
629
|
+
declare abstract class MCPAdapterBase implements IMCPAdapter {
|
|
630
|
+
abstract readonly name: string;
|
|
631
|
+
abstract readonly platform: 'lanhu' | 'figma';
|
|
632
|
+
protected client: Client | null;
|
|
633
|
+
protected transport: StdioClientTransport | null;
|
|
634
|
+
protected config: MCPServerConfig | null;
|
|
635
|
+
protected connectionStatus: MCPConnectionStatus;
|
|
636
|
+
protected tools: MCPToolSchema[];
|
|
637
|
+
protected resources: MCPResource[];
|
|
638
|
+
/**
|
|
639
|
+
* 初始化适配器
|
|
640
|
+
*/
|
|
641
|
+
initialize(config: MCPServerConfig): Promise<void>;
|
|
642
|
+
/**
|
|
643
|
+
* 连接到 MCP 服务器
|
|
644
|
+
*/
|
|
645
|
+
connect(): Promise<void>;
|
|
646
|
+
/**
|
|
647
|
+
* 断开连接
|
|
648
|
+
*/
|
|
649
|
+
disconnect(): Promise<void>;
|
|
650
|
+
/**
|
|
651
|
+
* 检查是否已连接
|
|
652
|
+
*/
|
|
653
|
+
isConnected(): boolean;
|
|
654
|
+
/**
|
|
655
|
+
* 获取连接状态
|
|
656
|
+
*/
|
|
657
|
+
getConnectionStatus(): MCPConnectionStatus;
|
|
658
|
+
/**
|
|
659
|
+
* 获取可用工具列表
|
|
660
|
+
*/
|
|
661
|
+
listTools(): Promise<MCPToolSchema[]>;
|
|
662
|
+
/**
|
|
663
|
+
* 调用工具
|
|
664
|
+
*/
|
|
665
|
+
callTool(call: MCPToolCall): Promise<MCPToolResult>;
|
|
666
|
+
/**
|
|
667
|
+
* 获取可用资源列表
|
|
668
|
+
*/
|
|
669
|
+
listResources(): Promise<MCPResource[]>;
|
|
670
|
+
/**
|
|
671
|
+
* 读取资源内容
|
|
672
|
+
*/
|
|
673
|
+
readResource(uri: string): Promise<MCPResourceContent>;
|
|
674
|
+
/**
|
|
675
|
+
* 刷新能力列表
|
|
676
|
+
*/
|
|
677
|
+
protected refreshCapabilities(): Promise<void>;
|
|
678
|
+
/**
|
|
679
|
+
* 获取工具
|
|
680
|
+
*/
|
|
681
|
+
getTool(name: string): MCPToolSchema | undefined;
|
|
682
|
+
/**
|
|
683
|
+
* 检查工具是否可用
|
|
684
|
+
*/
|
|
685
|
+
hasTool(name: string): boolean;
|
|
686
|
+
abstract getDesignSpec(url: string): Promise<DesignSpec>;
|
|
687
|
+
abstract extractStyles(spec: DesignSpec): Promise<DesignStyle>;
|
|
688
|
+
abstract generateCode(spec: DesignSpec, options?: CodeGenOptions): Promise<string>;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* 蓝湖 MCP 适配器
|
|
693
|
+
* 通过 MCP 协议连接蓝湖设计平台
|
|
694
|
+
*/
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* 蓝湖 MCP 适配器
|
|
698
|
+
*
|
|
699
|
+
* 配置示例:
|
|
700
|
+
* {
|
|
701
|
+
* name: 'lanhu',
|
|
702
|
+
* transport: 'stdio',
|
|
703
|
+
* command: 'npx',
|
|
704
|
+
* args: ['-y', '@lanhu/mcp-server'],
|
|
705
|
+
* env: {
|
|
706
|
+
* LANHU_TOKEN: 'your-token',
|
|
707
|
+
* }
|
|
708
|
+
* }
|
|
709
|
+
*/
|
|
710
|
+
declare class LanhuMCPAdapter extends MCPAdapterBase {
|
|
711
|
+
readonly name = "lanhu";
|
|
712
|
+
readonly platform: "lanhu";
|
|
713
|
+
/**
|
|
714
|
+
* 初始化适配器
|
|
715
|
+
*/
|
|
716
|
+
initialize(config: MCPServerConfig): Promise<void>;
|
|
717
|
+
/**
|
|
718
|
+
* 获取设计稿规格
|
|
719
|
+
*/
|
|
720
|
+
getDesignSpec(url: string): Promise<DesignSpec>;
|
|
721
|
+
/**
|
|
722
|
+
* 解析设计规格
|
|
723
|
+
*/
|
|
724
|
+
private parseDesignSpec;
|
|
725
|
+
/**
|
|
726
|
+
* 解析图层
|
|
727
|
+
*/
|
|
728
|
+
private parseLayers;
|
|
729
|
+
/**
|
|
730
|
+
* 解析图层类型
|
|
731
|
+
*/
|
|
732
|
+
private parseLayerType;
|
|
733
|
+
/**
|
|
734
|
+
* 解析图层样式
|
|
735
|
+
*/
|
|
736
|
+
private parseLayerStyles;
|
|
737
|
+
/**
|
|
738
|
+
* 解析样式
|
|
739
|
+
*/
|
|
740
|
+
private parseStyles;
|
|
741
|
+
/**
|
|
742
|
+
* 解析颜色
|
|
743
|
+
*/
|
|
744
|
+
private parseColors;
|
|
745
|
+
/**
|
|
746
|
+
* 解析排版
|
|
747
|
+
*/
|
|
748
|
+
private parseTypography;
|
|
749
|
+
/**
|
|
750
|
+
* 解析资源
|
|
751
|
+
*/
|
|
752
|
+
private parseAssets;
|
|
753
|
+
/**
|
|
754
|
+
* 解析资源类型
|
|
755
|
+
*/
|
|
756
|
+
private parseAssetType;
|
|
757
|
+
/**
|
|
758
|
+
* 从 URL 提取 ID
|
|
759
|
+
*/
|
|
760
|
+
private extractIdFromUrl;
|
|
761
|
+
/**
|
|
762
|
+
* 提取样式
|
|
763
|
+
*/
|
|
764
|
+
extractStyles(spec: DesignSpec): Promise<DesignStyle>;
|
|
765
|
+
/**
|
|
766
|
+
* 颜色去重
|
|
767
|
+
*/
|
|
768
|
+
private deduplicateColors;
|
|
769
|
+
/**
|
|
770
|
+
* 排版去重
|
|
771
|
+
*/
|
|
772
|
+
private deduplicateTypography;
|
|
773
|
+
/**
|
|
774
|
+
* 生成代码
|
|
775
|
+
*/
|
|
776
|
+
generateCode(spec: DesignSpec, options?: CodeGenOptions): Promise<string>;
|
|
777
|
+
/**
|
|
778
|
+
* 本地代码生成
|
|
779
|
+
*/
|
|
780
|
+
private generateCodeLocally;
|
|
781
|
+
/**
|
|
782
|
+
* 生成样式代码
|
|
783
|
+
*/
|
|
784
|
+
private generateStyleCode;
|
|
785
|
+
/**
|
|
786
|
+
* 生成组件代码
|
|
787
|
+
*/
|
|
788
|
+
private generateComponentCode;
|
|
789
|
+
/**
|
|
790
|
+
* 生成导入语句
|
|
791
|
+
*/
|
|
792
|
+
private generateImports;
|
|
793
|
+
/**
|
|
794
|
+
* 生成图层代码
|
|
795
|
+
*/
|
|
796
|
+
private generateLayersCode;
|
|
797
|
+
/**
|
|
798
|
+
* 生成 Tailwind 类名
|
|
799
|
+
*/
|
|
800
|
+
private generateTailwindClasses;
|
|
801
|
+
/**
|
|
802
|
+
* 生成内联样式
|
|
803
|
+
*/
|
|
804
|
+
private generateInlineStyles;
|
|
805
|
+
/**
|
|
806
|
+
* 转换为组件名
|
|
807
|
+
*/
|
|
808
|
+
private toComponentName;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
/**
|
|
812
|
+
* Figma MCP 适配器
|
|
813
|
+
* 通过 MCP 协议连接 Figma 设计平台
|
|
814
|
+
*/
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* Figma MCP 适配器
|
|
818
|
+
*
|
|
819
|
+
* 配置示例:
|
|
820
|
+
* {
|
|
821
|
+
* name: 'figma',
|
|
822
|
+
* transport: 'stdio',
|
|
823
|
+
* command: 'npx',
|
|
824
|
+
* args: ['-y', '@figma/mcp-server'],
|
|
825
|
+
* env: {
|
|
826
|
+
* FIGMA_ACCESS_TOKEN: 'your-token',
|
|
827
|
+
* }
|
|
828
|
+
* }
|
|
829
|
+
*/
|
|
830
|
+
declare class FigmaMCPAdapter extends MCPAdapterBase {
|
|
831
|
+
readonly name = "figma";
|
|
832
|
+
readonly platform: "figma";
|
|
833
|
+
/**
|
|
834
|
+
* 初始化适配器
|
|
835
|
+
*/
|
|
836
|
+
initialize(config: MCPServerConfig): Promise<void>;
|
|
837
|
+
/**
|
|
838
|
+
* 获取设计稿规格
|
|
839
|
+
*/
|
|
840
|
+
getDesignSpec(url: string): Promise<DesignSpec>;
|
|
841
|
+
/**
|
|
842
|
+
* 解析 Figma URL
|
|
843
|
+
*/
|
|
844
|
+
private parseFigmaUrl;
|
|
845
|
+
/**
|
|
846
|
+
* 解析设计规格
|
|
847
|
+
*/
|
|
848
|
+
private parseDesignSpec;
|
|
849
|
+
/**
|
|
850
|
+
* 解析 Figma 图层
|
|
851
|
+
*/
|
|
852
|
+
private parseFigmaLayers;
|
|
853
|
+
/**
|
|
854
|
+
* 映射 Figma 节点类型
|
|
855
|
+
*/
|
|
856
|
+
private mapFigmaNodeType;
|
|
857
|
+
/**
|
|
858
|
+
* 提取图层样式
|
|
859
|
+
*/
|
|
860
|
+
private extractLayerStyles;
|
|
861
|
+
/**
|
|
862
|
+
* 从文档提取全局样式
|
|
863
|
+
*/
|
|
864
|
+
private extractStylesFromDocument;
|
|
865
|
+
/**
|
|
866
|
+
* RGBA 转 Hex
|
|
867
|
+
*/
|
|
868
|
+
private rgbaToHex;
|
|
869
|
+
/**
|
|
870
|
+
* 解析资源
|
|
871
|
+
*/
|
|
872
|
+
private parseAssets;
|
|
873
|
+
/**
|
|
874
|
+
* 映射资源类型
|
|
875
|
+
*/
|
|
876
|
+
private mapAssetType;
|
|
877
|
+
/**
|
|
878
|
+
* 颜色去重
|
|
879
|
+
*/
|
|
880
|
+
private deduplicateColors;
|
|
881
|
+
/**
|
|
882
|
+
* 排版去重
|
|
883
|
+
*/
|
|
884
|
+
private deduplicateTypography;
|
|
885
|
+
/**
|
|
886
|
+
* 提取样式
|
|
887
|
+
*/
|
|
888
|
+
extractStyles(spec: DesignSpec): Promise<DesignStyle>;
|
|
889
|
+
/**
|
|
890
|
+
* 生成代码
|
|
891
|
+
*/
|
|
892
|
+
generateCode(spec: DesignSpec, options?: CodeGenOptions): Promise<string>;
|
|
893
|
+
/**
|
|
894
|
+
* 本地代码生成
|
|
895
|
+
*/
|
|
896
|
+
private generateCodeLocally;
|
|
897
|
+
/**
|
|
898
|
+
* 生成导入语句
|
|
899
|
+
*/
|
|
900
|
+
private generateImports;
|
|
901
|
+
/**
|
|
902
|
+
* 生成 JSX
|
|
903
|
+
*/
|
|
904
|
+
private generateJSX;
|
|
905
|
+
/**
|
|
906
|
+
* 生成 Tailwind 样式类
|
|
907
|
+
*/
|
|
908
|
+
private generateTailwindStyle;
|
|
909
|
+
/**
|
|
910
|
+
* 生成内联样式
|
|
911
|
+
*/
|
|
912
|
+
private generateInlineStyle;
|
|
913
|
+
/**
|
|
914
|
+
* 生成 Styled Components
|
|
915
|
+
*/
|
|
916
|
+
private generateStyledComponents;
|
|
917
|
+
/**
|
|
918
|
+
* 生成 CSS 样式
|
|
919
|
+
*/
|
|
920
|
+
private generateCSSStyles;
|
|
921
|
+
/**
|
|
922
|
+
* 转换为组件名
|
|
923
|
+
*/
|
|
924
|
+
private toComponentName;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* MCP 服务管理器
|
|
929
|
+
* 统一管理所有 MCP 服务连接
|
|
930
|
+
*/
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* MCP 管理器
|
|
934
|
+
*/
|
|
935
|
+
declare class MCPManager {
|
|
936
|
+
private adapters;
|
|
937
|
+
private connectionStates;
|
|
938
|
+
private configs;
|
|
939
|
+
constructor();
|
|
940
|
+
/**
|
|
941
|
+
* 注册 MCP 服务器
|
|
942
|
+
*/
|
|
943
|
+
registerServer(config: MCPServerConfig): Promise<void>;
|
|
944
|
+
/**
|
|
945
|
+
* 创建适配器
|
|
946
|
+
*/
|
|
947
|
+
private createAdapter;
|
|
948
|
+
/**
|
|
949
|
+
* 连接到指定服务器
|
|
950
|
+
*/
|
|
951
|
+
connect(serverName: string): Promise<void>;
|
|
952
|
+
/**
|
|
953
|
+
* 连接所有服务器
|
|
954
|
+
*/
|
|
955
|
+
connectAll(): Promise<Map<string, Error | null>>;
|
|
956
|
+
/**
|
|
957
|
+
* 断开指定服务器
|
|
958
|
+
*/
|
|
959
|
+
disconnect(serverName: string): Promise<void>;
|
|
960
|
+
/**
|
|
961
|
+
* 断开所有服务器
|
|
962
|
+
*/
|
|
963
|
+
disconnectAll(): Promise<void>;
|
|
964
|
+
/**
|
|
965
|
+
* 获取连接状态
|
|
966
|
+
*/
|
|
967
|
+
getConnectionState(serverName: string): MCPConnectionState | undefined;
|
|
968
|
+
/**
|
|
969
|
+
* 获取所有连接状态
|
|
970
|
+
*/
|
|
971
|
+
getAllConnectionStates(): MCPConnectionState[];
|
|
972
|
+
/**
|
|
973
|
+
* 获取适配器
|
|
974
|
+
*/
|
|
975
|
+
getAdapter(serverName: string): IMCPAdapter | undefined;
|
|
976
|
+
/**
|
|
977
|
+
* 获取蓝湖适配器
|
|
978
|
+
*/
|
|
979
|
+
getLanhuAdapter(): LanhuMCPAdapter | undefined;
|
|
980
|
+
/**
|
|
981
|
+
* 获取 Figma 适配器
|
|
982
|
+
*/
|
|
983
|
+
getFigmaAdapter(): FigmaMCPAdapter | undefined;
|
|
984
|
+
/**
|
|
985
|
+
* 调用工具
|
|
986
|
+
*/
|
|
987
|
+
callTool(serverName: string, call: MCPToolCall): Promise<MCPToolResult>;
|
|
988
|
+
/**
|
|
989
|
+
* 获取设计稿
|
|
990
|
+
*/
|
|
991
|
+
getDesignSpec(url: string): Promise<DesignSpec>;
|
|
992
|
+
/**
|
|
993
|
+
* 生成代码
|
|
994
|
+
*/
|
|
995
|
+
generateCode(spec: DesignSpec, options?: CodeGenOptions): Promise<string>;
|
|
996
|
+
/**
|
|
997
|
+
* 列出所有可用工具
|
|
998
|
+
*/
|
|
999
|
+
listAllTools(): Map<string, MCPToolSchema[]>;
|
|
1000
|
+
/**
|
|
1001
|
+
* 检查服务器是否可用
|
|
1002
|
+
*/
|
|
1003
|
+
isServerAvailable(serverName: string): boolean;
|
|
1004
|
+
/**
|
|
1005
|
+
* 获取已注册的服务器列表
|
|
1006
|
+
*/
|
|
1007
|
+
getRegisteredServers(): string[];
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* 创建 MCP 管理器实例
|
|
1011
|
+
*/
|
|
1012
|
+
declare function createMCPManager(): MCPManager;
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* 命令解析器
|
|
1016
|
+
* 解析用户输入的各种命令格式
|
|
1017
|
+
*/
|
|
1018
|
+
declare enum CommandType {
|
|
1019
|
+
SLASH = "slash",// 斜杠命令 /help
|
|
1020
|
+
AT = "at",// 文件引用 @file
|
|
1021
|
+
DOLLAR = "dollar",// Agent调用 $agent
|
|
1022
|
+
SHELL = "shell",// Shell命令 !command
|
|
1023
|
+
NATURAL = "natural",// 自然语言
|
|
1024
|
+
YOLO = "yolo"
|
|
1025
|
+
}
|
|
1026
|
+
interface ParsedCommand {
|
|
1027
|
+
type: CommandType;
|
|
1028
|
+
raw: string;
|
|
1029
|
+
command?: string;
|
|
1030
|
+
args?: string[];
|
|
1031
|
+
path?: string;
|
|
1032
|
+
agent?: string;
|
|
1033
|
+
shellCommand?: string;
|
|
1034
|
+
}
|
|
1035
|
+
interface ParseResult {
|
|
1036
|
+
success: boolean;
|
|
1037
|
+
command?: ParsedCommand;
|
|
1038
|
+
error?: string;
|
|
1039
|
+
}
|
|
1040
|
+
declare class CommandParser {
|
|
1041
|
+
private readonly slashCommands;
|
|
1042
|
+
private readonly builtInAgents;
|
|
1043
|
+
parse(input: string): ParseResult;
|
|
1044
|
+
private parseSlashCommand;
|
|
1045
|
+
private parseAtPath;
|
|
1046
|
+
private parseAgentCall;
|
|
1047
|
+
private parseShellCommand;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
/**
|
|
1051
|
+
* 上下文管理器
|
|
1052
|
+
* 管理对话上下文、Token计算、自动压缩
|
|
1053
|
+
*/
|
|
1054
|
+
|
|
1055
|
+
interface TokenStats {
|
|
1056
|
+
total: number;
|
|
1057
|
+
byRole: Record<string, number>;
|
|
1058
|
+
bySource: Record<string, number>;
|
|
1059
|
+
messageCount: number;
|
|
1060
|
+
systemTokens: number;
|
|
1061
|
+
userTokens: number;
|
|
1062
|
+
assistantTokens: number;
|
|
1063
|
+
toolTokens: number;
|
|
1064
|
+
}
|
|
1065
|
+
interface CompressionResult {
|
|
1066
|
+
originalTokens: number;
|
|
1067
|
+
compressedTokens: number;
|
|
1068
|
+
savedTokens: number;
|
|
1069
|
+
messagesKept: number;
|
|
1070
|
+
messagesCompressed: number;
|
|
1071
|
+
summary?: string;
|
|
1072
|
+
}
|
|
1073
|
+
interface ContextManagerOptions {
|
|
1074
|
+
limit?: number;
|
|
1075
|
+
projectPath?: string;
|
|
1076
|
+
persistPath?: string;
|
|
1077
|
+
}
|
|
1078
|
+
declare class ContextManager {
|
|
1079
|
+
private state;
|
|
1080
|
+
private projectPath;
|
|
1081
|
+
private persistPath;
|
|
1082
|
+
private tokenEstimateCache;
|
|
1083
|
+
constructor(options?: ContextManagerOptions);
|
|
1084
|
+
initialize(projectPath: string): Promise<void>;
|
|
1085
|
+
/**
|
|
1086
|
+
* 添加消息
|
|
1087
|
+
*/
|
|
1088
|
+
addMessage(message: ContextMessage): void;
|
|
1089
|
+
/**
|
|
1090
|
+
* 批量添加消息
|
|
1091
|
+
*/
|
|
1092
|
+
addMessages(messages: ContextMessage[]): void;
|
|
1093
|
+
/**
|
|
1094
|
+
* 获取所有消息
|
|
1095
|
+
*/
|
|
1096
|
+
getMessages(): ContextMessage[];
|
|
1097
|
+
/**
|
|
1098
|
+
* 获取最近的 N 条消息
|
|
1099
|
+
*/
|
|
1100
|
+
getRecentMessages(count: number): ContextMessage[];
|
|
1101
|
+
/**
|
|
1102
|
+
* 获取系统消息
|
|
1103
|
+
*/
|
|
1104
|
+
getSystemMessages(): ContextMessage[];
|
|
1105
|
+
/**
|
|
1106
|
+
* 获取 Token 统计
|
|
1107
|
+
*/
|
|
1108
|
+
getTokenStats(): TokenStats;
|
|
1109
|
+
/**
|
|
1110
|
+
* 获取当前 Token 数
|
|
1111
|
+
*/
|
|
1112
|
+
getTokenCount(): number;
|
|
1113
|
+
/**
|
|
1114
|
+
* 获取剩余 Token 数
|
|
1115
|
+
*/
|
|
1116
|
+
getRemainingTokens(): number;
|
|
1117
|
+
/**
|
|
1118
|
+
* 获取使用百分比
|
|
1119
|
+
*/
|
|
1120
|
+
getUsagePercentage(): number;
|
|
1121
|
+
/**
|
|
1122
|
+
* 获取上下文限制
|
|
1123
|
+
*/
|
|
1124
|
+
getLimit(): number;
|
|
1125
|
+
/**
|
|
1126
|
+
* 设置上下文限制
|
|
1127
|
+
*/
|
|
1128
|
+
setLimit(limit: number): void;
|
|
1129
|
+
/**
|
|
1130
|
+
* 清空上下文
|
|
1131
|
+
*/
|
|
1132
|
+
clear(): void;
|
|
1133
|
+
/**
|
|
1134
|
+
* 检查是否需要压缩
|
|
1135
|
+
*/
|
|
1136
|
+
needsCompression(): boolean;
|
|
1137
|
+
/**
|
|
1138
|
+
* 执行压缩
|
|
1139
|
+
*/
|
|
1140
|
+
compress(): CompressionResult;
|
|
1141
|
+
/**
|
|
1142
|
+
* 计算 Token 数
|
|
1143
|
+
*/
|
|
1144
|
+
private countTokens;
|
|
1145
|
+
/**
|
|
1146
|
+
* 生成摘要
|
|
1147
|
+
*/
|
|
1148
|
+
private generateSummary;
|
|
1149
|
+
/**
|
|
1150
|
+
* 异步持久化
|
|
1151
|
+
*/
|
|
1152
|
+
private persistAsync;
|
|
1153
|
+
/**
|
|
1154
|
+
* 持久化上下文
|
|
1155
|
+
*/
|
|
1156
|
+
persist(): Promise<void>;
|
|
1157
|
+
/**
|
|
1158
|
+
* 加载持久化的上下文
|
|
1159
|
+
*/
|
|
1160
|
+
private loadPersistedContext;
|
|
1161
|
+
/**
|
|
1162
|
+
* 获取状态显示字符串
|
|
1163
|
+
*/
|
|
1164
|
+
getStatusString(): string;
|
|
1165
|
+
/**
|
|
1166
|
+
* 格式化 Token 数
|
|
1167
|
+
*/
|
|
1168
|
+
private formatTokens;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
/**
|
|
1172
|
+
* 规范学习系统
|
|
1173
|
+
* 从代码分析和对话中学习开发规范
|
|
1174
|
+
*/
|
|
1175
|
+
|
|
1176
|
+
interface NormsConfig {
|
|
1177
|
+
projectPath: string;
|
|
1178
|
+
normsDir: string;
|
|
1179
|
+
}
|
|
1180
|
+
interface PatternOccurrence {
|
|
1181
|
+
patternId: string;
|
|
1182
|
+
timestamp: Date;
|
|
1183
|
+
source: 'code-analysis' | 'conversation' | 'forced';
|
|
1184
|
+
context: string;
|
|
1185
|
+
filePath?: string;
|
|
1186
|
+
}
|
|
1187
|
+
interface ScanResult {
|
|
1188
|
+
filesScanned: number;
|
|
1189
|
+
patternsFound: number;
|
|
1190
|
+
standardsExtracted: number;
|
|
1191
|
+
duration: number;
|
|
1192
|
+
errors: string[];
|
|
1193
|
+
}
|
|
1194
|
+
interface ValidationResult {
|
|
1195
|
+
isValid: boolean;
|
|
1196
|
+
violations: StandardViolation[];
|
|
1197
|
+
suggestions: string[];
|
|
1198
|
+
}
|
|
1199
|
+
interface StandardViolation {
|
|
1200
|
+
standardId: string;
|
|
1201
|
+
description: string;
|
|
1202
|
+
severity: 'error' | 'warning' | 'info';
|
|
1203
|
+
suggestion: string;
|
|
1204
|
+
}
|
|
1205
|
+
interface StandardHint {
|
|
1206
|
+
standardId: string;
|
|
1207
|
+
category: string;
|
|
1208
|
+
hint: string;
|
|
1209
|
+
weight: number;
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* 规范管理器
|
|
1213
|
+
* 负责从代码和对话中学习开发规范
|
|
1214
|
+
*/
|
|
1215
|
+
declare class NormsManager {
|
|
1216
|
+
private config;
|
|
1217
|
+
private standards;
|
|
1218
|
+
private weights;
|
|
1219
|
+
private occurrences;
|
|
1220
|
+
private initialized;
|
|
1221
|
+
constructor(config: NormsConfig);
|
|
1222
|
+
initialize(): Promise<void>;
|
|
1223
|
+
/**
|
|
1224
|
+
* 扫描整个项目
|
|
1225
|
+
*/
|
|
1226
|
+
scanProject(projectPath: string): Promise<ScanResult>;
|
|
1227
|
+
/**
|
|
1228
|
+
* 从单个文件学习规范
|
|
1229
|
+
*/
|
|
1230
|
+
learnFromFile(filePath: string, content: string): Promise<DevStandard[]>;
|
|
1231
|
+
/**
|
|
1232
|
+
* 从对话中沉淀规范
|
|
1233
|
+
*/
|
|
1234
|
+
learnFromConversation(message: string, response: string): Promise<DevStandard[]>;
|
|
1235
|
+
/**
|
|
1236
|
+
* 添加强制规范
|
|
1237
|
+
*/
|
|
1238
|
+
addForcedStandard(standard: Omit<DevStandard, 'source' | 'weight' | 'createdAt' | 'updatedAt'>): Promise<void>;
|
|
1239
|
+
/**
|
|
1240
|
+
* 获取适用规范
|
|
1241
|
+
*/
|
|
1242
|
+
getApplicableStandards(context: string): DevStandard[];
|
|
1243
|
+
/**
|
|
1244
|
+
* 验证代码是否符合规范
|
|
1245
|
+
*/
|
|
1246
|
+
validateAgainstStandards(code: string, standards?: DevStandard[]): ValidationResult;
|
|
1247
|
+
/**
|
|
1248
|
+
* 获取规范提示
|
|
1249
|
+
*/
|
|
1250
|
+
getStandardHints(context: string): StandardHint[];
|
|
1251
|
+
/**
|
|
1252
|
+
* 记录规范出现
|
|
1253
|
+
*/
|
|
1254
|
+
recordOccurrence(occurrence: PatternOccurrence): Promise<void>;
|
|
1255
|
+
/**
|
|
1256
|
+
* 获取有效规范(按权重排序)
|
|
1257
|
+
*/
|
|
1258
|
+
getEffectiveStandards(minWeight?: number): DevStandard[];
|
|
1259
|
+
/**
|
|
1260
|
+
* 每周汇总更新
|
|
1261
|
+
*/
|
|
1262
|
+
weeklyAggregate(): Promise<void>;
|
|
1263
|
+
/**
|
|
1264
|
+
* 提取代码模式
|
|
1265
|
+
*/
|
|
1266
|
+
private extractPatterns;
|
|
1267
|
+
/**
|
|
1268
|
+
* TypeScript 模式检测
|
|
1269
|
+
*/
|
|
1270
|
+
private extractTypeScriptPatterns;
|
|
1271
|
+
/**
|
|
1272
|
+
* JavaScript 模式检测
|
|
1273
|
+
*/
|
|
1274
|
+
private extractJavaScriptPatterns;
|
|
1275
|
+
/**
|
|
1276
|
+
* React 模式检测
|
|
1277
|
+
*/
|
|
1278
|
+
private extractReactPatterns;
|
|
1279
|
+
/**
|
|
1280
|
+
* Vue 模式检测
|
|
1281
|
+
*/
|
|
1282
|
+
private extractVuePatterns;
|
|
1283
|
+
/**
|
|
1284
|
+
* 样式模式检测
|
|
1285
|
+
*/
|
|
1286
|
+
private extractStylePatterns;
|
|
1287
|
+
/**
|
|
1288
|
+
* Markdown 模式检测
|
|
1289
|
+
*/
|
|
1290
|
+
private extractMarkdownPatterns;
|
|
1291
|
+
/**
|
|
1292
|
+
* 通用模式检测
|
|
1293
|
+
*/
|
|
1294
|
+
private extractCommonPatterns;
|
|
1295
|
+
/**
|
|
1296
|
+
* 从对话中提取规范
|
|
1297
|
+
*/
|
|
1298
|
+
private extractStandardsFromConversation;
|
|
1299
|
+
/**
|
|
1300
|
+
* 创建规范模式
|
|
1301
|
+
*/
|
|
1302
|
+
private createPattern;
|
|
1303
|
+
/**
|
|
1304
|
+
* 检查代码违规
|
|
1305
|
+
*/
|
|
1306
|
+
private checkViolation;
|
|
1307
|
+
/**
|
|
1308
|
+
* 计算权重
|
|
1309
|
+
*/
|
|
1310
|
+
private calculateWeight;
|
|
1311
|
+
/**
|
|
1312
|
+
* 获取初始权重
|
|
1313
|
+
*/
|
|
1314
|
+
private getInitialWeight;
|
|
1315
|
+
/**
|
|
1316
|
+
* 收集项目文件
|
|
1317
|
+
*/
|
|
1318
|
+
private collectProjectFiles;
|
|
1319
|
+
/**
|
|
1320
|
+
* 添加或更新规范
|
|
1321
|
+
*/
|
|
1322
|
+
private addOrUpdateStandard;
|
|
1323
|
+
/**
|
|
1324
|
+
* 确保规范目录存在
|
|
1325
|
+
*/
|
|
1326
|
+
private ensureNormsDir;
|
|
1327
|
+
/**
|
|
1328
|
+
* 加载已有规范
|
|
1329
|
+
*/
|
|
1330
|
+
private loadStandards;
|
|
1331
|
+
/**
|
|
1332
|
+
* 加载权重数据
|
|
1333
|
+
*/
|
|
1334
|
+
private loadWeights;
|
|
1335
|
+
/**
|
|
1336
|
+
* 保存规范
|
|
1337
|
+
*/
|
|
1338
|
+
saveStandards(): Promise<void>;
|
|
1339
|
+
/**
|
|
1340
|
+
* 保存权重
|
|
1341
|
+
*/
|
|
1342
|
+
saveWeights(): Promise<void>;
|
|
1343
|
+
/**
|
|
1344
|
+
* 生成周报
|
|
1345
|
+
*/
|
|
1346
|
+
private generateWeeklyReport;
|
|
1347
|
+
/**
|
|
1348
|
+
* 保存周报
|
|
1349
|
+
*/
|
|
1350
|
+
private saveWeeklyReport;
|
|
1351
|
+
/**
|
|
1352
|
+
* 更新 devstanded.md
|
|
1353
|
+
*/
|
|
1354
|
+
private updateDevStandedMd;
|
|
1355
|
+
/**
|
|
1356
|
+
* 生成 devstanded.md 内容
|
|
1357
|
+
*/
|
|
1358
|
+
private generateDevStandedMd;
|
|
1359
|
+
/**
|
|
1360
|
+
* 清理旧的出现记录
|
|
1361
|
+
*/
|
|
1362
|
+
private cleanupOldOccurrences;
|
|
1363
|
+
private getWeekId;
|
|
1364
|
+
private getWeekStart;
|
|
1365
|
+
private groupByCategory;
|
|
1366
|
+
private getWeightLevel;
|
|
1367
|
+
private getCategoryBreakdown;
|
|
1368
|
+
private hasTypeAnnotations;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
interface REPLState {
|
|
1372
|
+
isRunning: boolean;
|
|
1373
|
+
currentTask: string | null;
|
|
1374
|
+
contextUsed: number;
|
|
1375
|
+
contextLimit: number;
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
/**
|
|
1379
|
+
* 命令执行器
|
|
1380
|
+
* 执行解析后的命令
|
|
1381
|
+
*/
|
|
1382
|
+
|
|
1383
|
+
interface ExecutorContext {
|
|
1384
|
+
contextManager: ContextManager;
|
|
1385
|
+
configManager: ConfigManager;
|
|
1386
|
+
modelService: ModelService;
|
|
1387
|
+
normsManager?: NormsManager;
|
|
1388
|
+
state: REPLState;
|
|
1389
|
+
options: {
|
|
1390
|
+
workingDirectory: string;
|
|
1391
|
+
model?: string;
|
|
1392
|
+
yolo?: boolean;
|
|
1393
|
+
};
|
|
1394
|
+
}
|
|
1395
|
+
interface ExecutionResult {
|
|
1396
|
+
output?: string;
|
|
1397
|
+
exit?: boolean;
|
|
1398
|
+
contextUsed?: number;
|
|
1399
|
+
}
|
|
1400
|
+
declare class CommandExecutor {
|
|
1401
|
+
execute(parseResult: ParseResult, ctx: ExecutorContext): Promise<ExecutionResult>;
|
|
1402
|
+
private executeSlashCommand;
|
|
1403
|
+
private executeFileReference;
|
|
1404
|
+
private executeAgent;
|
|
1405
|
+
private executeShell;
|
|
1406
|
+
private executeNaturalLanguage;
|
|
1407
|
+
private executeYolo;
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
/**
|
|
1411
|
+
* Agent 运行器
|
|
1412
|
+
* 简化的 Agent 调度入口,提供统一的 Agent 执行接口
|
|
1413
|
+
*/
|
|
1414
|
+
|
|
1415
|
+
interface AgentResult {
|
|
1416
|
+
output: string;
|
|
1417
|
+
contextUsed: number;
|
|
1418
|
+
}
|
|
1419
|
+
/**
|
|
1420
|
+
* 运行 Agent(简化版)
|
|
1421
|
+
*/
|
|
1422
|
+
declare function runAgent(agentId: string, args: string[], ctx: ExecutorContext): Promise<AgentResult>;
|
|
1423
|
+
/**
|
|
1424
|
+
* 获取 Agent 定义
|
|
1425
|
+
*/
|
|
1426
|
+
declare function getAgent(agentId: AgentId): AgentDefinition | undefined;
|
|
1427
|
+
/**
|
|
1428
|
+
* 列出所有 Agent
|
|
1429
|
+
*/
|
|
1430
|
+
declare function listAgents(): AgentDefinition[];
|
|
1431
|
+
/**
|
|
1432
|
+
* 获取工作流阶段对应的 Agent
|
|
1433
|
+
*/
|
|
1434
|
+
declare function getAgentsForStep(step: string): AgentDefinition[];
|
|
1435
|
+
|
|
1436
|
+
/**
|
|
1437
|
+
* Agent 执行引擎
|
|
1438
|
+
* 负责调度和执行 Agent,包括 Prompt 构建、模型调用、工具执行
|
|
1439
|
+
*/
|
|
1440
|
+
|
|
1441
|
+
/**
|
|
1442
|
+
* Agent 执行器
|
|
1443
|
+
*/
|
|
1444
|
+
declare class AgentExecutor {
|
|
1445
|
+
private modelService;
|
|
1446
|
+
private normsManager;
|
|
1447
|
+
private contextManager;
|
|
1448
|
+
private sessions;
|
|
1449
|
+
private eventListeners;
|
|
1450
|
+
constructor(modelService: ModelService, normsManager: NormsManager, contextManager: ContextManager);
|
|
1451
|
+
/**
|
|
1452
|
+
* 执行 Agent
|
|
1453
|
+
*/
|
|
1454
|
+
execute(request: AgentScheduleRequest): Promise<AgentExecutionResult>;
|
|
1455
|
+
/**
|
|
1456
|
+
* 流式执行 Agent
|
|
1457
|
+
*/
|
|
1458
|
+
executeStream(request: AgentScheduleRequest): AsyncGenerator<string, AgentExecutionResult, unknown>;
|
|
1459
|
+
/**
|
|
1460
|
+
* 获取会话状态
|
|
1461
|
+
*/
|
|
1462
|
+
getSession(sessionId: string): AgentSession | undefined;
|
|
1463
|
+
/**
|
|
1464
|
+
* 取消执行
|
|
1465
|
+
*/
|
|
1466
|
+
cancel(sessionId: string): boolean;
|
|
1467
|
+
/**
|
|
1468
|
+
* 添加事件监听器
|
|
1469
|
+
*/
|
|
1470
|
+
addEventListener(listener: (event: AgentEvent) => void): void;
|
|
1471
|
+
/**
|
|
1472
|
+
* 移除事件监听器
|
|
1473
|
+
*/
|
|
1474
|
+
removeEventListener(listener: (event: AgentEvent) => void): void;
|
|
1475
|
+
/**
|
|
1476
|
+
* 创建会话
|
|
1477
|
+
*/
|
|
1478
|
+
private createSession;
|
|
1479
|
+
/**
|
|
1480
|
+
* 构建消息列表
|
|
1481
|
+
*/
|
|
1482
|
+
private buildMessages;
|
|
1483
|
+
/**
|
|
1484
|
+
* 摘要上下文(限制长度)
|
|
1485
|
+
*/
|
|
1486
|
+
private summarizeContext;
|
|
1487
|
+
/**
|
|
1488
|
+
* 提取关键规范(从 devstanded.md)
|
|
1489
|
+
*/
|
|
1490
|
+
private extractKeyStandards;
|
|
1491
|
+
/**
|
|
1492
|
+
* 构建任务提示
|
|
1493
|
+
*/
|
|
1494
|
+
private buildTaskPrompt;
|
|
1495
|
+
/**
|
|
1496
|
+
* 解析输出
|
|
1497
|
+
*/
|
|
1498
|
+
private parseOutput;
|
|
1499
|
+
/**
|
|
1500
|
+
* 发送事件
|
|
1501
|
+
*/
|
|
1502
|
+
private emitEvent;
|
|
1503
|
+
}
|
|
1504
|
+
/**
|
|
1505
|
+
* 创建默认的 Agent 执行器
|
|
1506
|
+
*/
|
|
1507
|
+
declare function createAgentExecutor(modelService: ModelService, normsManager: NormsManager, contextManager: ContextManager): AgentExecutor;
|
|
1508
|
+
|
|
1509
|
+
/**
|
|
1510
|
+
* 内置 Agent 定义
|
|
1511
|
+
* 包含每个 Agent 的角色、能力、工具权限和 Prompt 模板
|
|
1512
|
+
*/
|
|
1513
|
+
|
|
1514
|
+
/**
|
|
1515
|
+
* 前端开发 Agent
|
|
1516
|
+
* 负责代码实现、组件开发、样式编写
|
|
1517
|
+
*/
|
|
1518
|
+
declare const FRONTEND_DEV_AGENT: AgentDefinition;
|
|
1519
|
+
/**
|
|
1520
|
+
* 代码审核 Agent
|
|
1521
|
+
* 负责代码质量检查、安全审查、最佳实践建议
|
|
1522
|
+
*/
|
|
1523
|
+
declare const CODE_REVIEWER_AGENT: AgentDefinition;
|
|
1524
|
+
/**
|
|
1525
|
+
* 架构师 Agent
|
|
1526
|
+
* 负责技术方案设计、架构决策、技术选型
|
|
1527
|
+
*/
|
|
1528
|
+
declare const ARCHITECT_AGENT: AgentDefinition;
|
|
1529
|
+
/**
|
|
1530
|
+
* 测试 Agent
|
|
1531
|
+
* 负责测试用例编写、测试执行、测试报告
|
|
1532
|
+
*/
|
|
1533
|
+
declare const TESTER_AGENT: AgentDefinition;
|
|
1534
|
+
/**
|
|
1535
|
+
* 所有内置 Agent 的映射表
|
|
1536
|
+
*/
|
|
1537
|
+
declare const BUILTIN_AGENTS: Record<AgentId, AgentDefinition>;
|
|
1538
|
+
/**
|
|
1539
|
+
* 获取 Agent 定义
|
|
1540
|
+
*/
|
|
1541
|
+
declare function getAgentDefinition(id: AgentId): AgentDefinition | undefined;
|
|
1542
|
+
/**
|
|
1543
|
+
* 获取所有内置 Agent
|
|
1544
|
+
*/
|
|
1545
|
+
declare function getAllAgents(): AgentDefinition[];
|
|
1546
|
+
/**
|
|
1547
|
+
* 根据工作流阶段获取应触发的 Agent
|
|
1548
|
+
*/
|
|
1549
|
+
declare function getAgentsForWorkflowStep(step: string): AgentDefinition[];
|
|
1550
|
+
|
|
1551
|
+
/**
|
|
1552
|
+
* Agent 自动调度器
|
|
1553
|
+
* 根据工作流阶段自动触发对应的 Agent 执行
|
|
1554
|
+
*/
|
|
1555
|
+
|
|
1556
|
+
/**
|
|
1557
|
+
* 调度策略
|
|
1558
|
+
*/
|
|
1559
|
+
type ScheduleStrategy = 'auto' | 'recommend' | 'manual';
|
|
1560
|
+
/**
|
|
1561
|
+
* 调度配置
|
|
1562
|
+
*/
|
|
1563
|
+
interface ScheduleConfig {
|
|
1564
|
+
agent: AgentId;
|
|
1565
|
+
strategy: ScheduleStrategy;
|
|
1566
|
+
waitForResult: boolean;
|
|
1567
|
+
requireConfirmation: boolean;
|
|
1568
|
+
fallbackAgent?: AgentId;
|
|
1569
|
+
}
|
|
1570
|
+
/**
|
|
1571
|
+
* 调度结果
|
|
1572
|
+
*/
|
|
1573
|
+
interface ScheduleResult {
|
|
1574
|
+
scheduled: boolean;
|
|
1575
|
+
agent?: AgentId;
|
|
1576
|
+
strategy: ScheduleStrategy;
|
|
1577
|
+
result?: AgentExecutionResult;
|
|
1578
|
+
message: string;
|
|
1579
|
+
}
|
|
1580
|
+
/**
|
|
1581
|
+
* 工作流阶段 → Agent 调度规则
|
|
1582
|
+
*
|
|
1583
|
+
* 设计原则:
|
|
1584
|
+
* - explore 阶段:架构师分析需求,输出技术方案
|
|
1585
|
+
* - new 阶段:前端开发实现核心代码
|
|
1586
|
+
* - continue 阶段:前端开发继续迭代
|
|
1587
|
+
* - apply 阶段:代码审核检查质量
|
|
1588
|
+
*/
|
|
1589
|
+
declare const SCHEDULE_RULES: Partial<Record<WorkflowStep, ScheduleConfig>>;
|
|
1590
|
+
/**
|
|
1591
|
+
* Agent 调度器
|
|
1592
|
+
*/
|
|
1593
|
+
declare class AgentScheduler {
|
|
1594
|
+
private executor;
|
|
1595
|
+
private lastScheduleResult;
|
|
1596
|
+
private onSchedule?;
|
|
1597
|
+
constructor(executor: AgentExecutor);
|
|
1598
|
+
/**
|
|
1599
|
+
* 设置调度回调
|
|
1600
|
+
*/
|
|
1601
|
+
setOnSchedule(callback: (result: ScheduleResult) => void): void;
|
|
1602
|
+
/**
|
|
1603
|
+
* 根据工作流阶段调度 Agent
|
|
1604
|
+
*/
|
|
1605
|
+
scheduleForStep(step: WorkflowStep, state: WorkflowState, options?: {
|
|
1606
|
+
strategy?: ScheduleStrategy;
|
|
1607
|
+
context?: Partial<AgentExecutionContext>;
|
|
1608
|
+
}): Promise<ScheduleResult>;
|
|
1609
|
+
/**
|
|
1610
|
+
* 执行 Agent
|
|
1611
|
+
*/
|
|
1612
|
+
private executeAgent;
|
|
1613
|
+
/**
|
|
1614
|
+
* 获取阶段的调度配置
|
|
1615
|
+
*/
|
|
1616
|
+
getScheduleConfig(step: WorkflowStep): ScheduleConfig | undefined;
|
|
1617
|
+
/**
|
|
1618
|
+
* 获取阶段的推荐 Agent
|
|
1619
|
+
*/
|
|
1620
|
+
getRecommendedAgent(step: WorkflowStep): AgentId | undefined;
|
|
1621
|
+
/**
|
|
1622
|
+
* 获取所有调度规则
|
|
1623
|
+
*/
|
|
1624
|
+
getAllScheduleRules(): Partial<Record<WorkflowStep, ScheduleConfig>>;
|
|
1625
|
+
/**
|
|
1626
|
+
* 获取上次调度结果
|
|
1627
|
+
*/
|
|
1628
|
+
getLastScheduleResult(): ScheduleResult | null;
|
|
1629
|
+
/**
|
|
1630
|
+
* 判断阶段是否需要自动调度
|
|
1631
|
+
*/
|
|
1632
|
+
shouldAutoSchedule(step: WorkflowStep): boolean;
|
|
1633
|
+
/**
|
|
1634
|
+
* 获取阶段可用的 Agent 列表
|
|
1635
|
+
*/
|
|
1636
|
+
getAvailableAgents(step: WorkflowStep): AgentId[];
|
|
1637
|
+
}
|
|
1638
|
+
/**
|
|
1639
|
+
* 创建调度器
|
|
1640
|
+
*/
|
|
1641
|
+
declare function createAgentScheduler(executor: AgentExecutor): AgentScheduler;
|
|
1642
|
+
/**
|
|
1643
|
+
* 获取调度规则描述
|
|
1644
|
+
*/
|
|
1645
|
+
declare function getScheduleRuleDescription(step: WorkflowStep): string;
|
|
1646
|
+
|
|
1647
|
+
/**
|
|
1648
|
+
* 工作流确认点系统
|
|
1649
|
+
* 在关键节点要求开发者确认才能继续
|
|
1650
|
+
*/
|
|
1651
|
+
|
|
1652
|
+
/**
|
|
1653
|
+
* 确认点类型
|
|
1654
|
+
*/
|
|
1655
|
+
type ConfirmationPointType = 'spec-review' | 'architecture' | 'code-review';
|
|
1656
|
+
/**
|
|
1657
|
+
* 确认点定义
|
|
1658
|
+
*/
|
|
1659
|
+
interface ConfirmationPoint {
|
|
1660
|
+
type: ConfirmationPointType;
|
|
1661
|
+
name: string;
|
|
1662
|
+
description: string;
|
|
1663
|
+
triggerStep: WorkflowStep;
|
|
1664
|
+
targetStep: WorkflowStep;
|
|
1665
|
+
required: boolean;
|
|
1666
|
+
timeout?: number;
|
|
1667
|
+
}
|
|
1668
|
+
/**
|
|
1669
|
+
* 确认状态
|
|
1670
|
+
*/
|
|
1671
|
+
interface ConfirmationStatus {
|
|
1672
|
+
type: ConfirmationPointType;
|
|
1673
|
+
confirmed: boolean;
|
|
1674
|
+
confirmedAt?: Date;
|
|
1675
|
+
confirmedBy?: string;
|
|
1676
|
+
comment?: string;
|
|
1677
|
+
}
|
|
1678
|
+
/**
|
|
1679
|
+
* 回滚规则
|
|
1680
|
+
* 定义从哪些阶段可以回滚到哪些阶段
|
|
1681
|
+
*
|
|
1682
|
+
* 复杂流程: explore → new → continue → apply → archive
|
|
1683
|
+
* 简单流程: propose → apply → archive
|
|
1684
|
+
*/
|
|
1685
|
+
declare const ROLLBACK_RULES: Record<WorkflowStep, WorkflowStep[]>;
|
|
1686
|
+
/**
|
|
1687
|
+
* 回滚原因类型
|
|
1688
|
+
*/
|
|
1689
|
+
type RollbackReason = 'code-review-failed' | 'requirement-changed' | 'design-issue' | 'user-request';
|
|
1690
|
+
/**
|
|
1691
|
+
* 回滚请求
|
|
1692
|
+
*/
|
|
1693
|
+
interface RollbackRequest {
|
|
1694
|
+
fromStep: WorkflowStep;
|
|
1695
|
+
toStep: WorkflowStep;
|
|
1696
|
+
reason: RollbackReason;
|
|
1697
|
+
description: string;
|
|
1698
|
+
timestamp: Date;
|
|
1699
|
+
}
|
|
1700
|
+
/**
|
|
1701
|
+
* 确认点管理器
|
|
1702
|
+
*/
|
|
1703
|
+
declare class ConfirmationManager {
|
|
1704
|
+
private confirmationPoints;
|
|
1705
|
+
private confirmations;
|
|
1706
|
+
constructor(customPoints?: ConfirmationPoint[]);
|
|
1707
|
+
/**
|
|
1708
|
+
* 获取指定阶段的确认点
|
|
1709
|
+
*/
|
|
1710
|
+
getConfirmationPointForTransition(from: WorkflowStep, to: WorkflowStep): ConfirmationPoint | undefined;
|
|
1711
|
+
/**
|
|
1712
|
+
* 检查是否需要确认
|
|
1713
|
+
*/
|
|
1714
|
+
needsConfirmation(from: WorkflowStep, to: WorkflowStep): boolean;
|
|
1715
|
+
/**
|
|
1716
|
+
* 获取确认点详情
|
|
1717
|
+
*/
|
|
1718
|
+
getConfirmationPoint(type: ConfirmationPointType): ConfirmationPoint | undefined;
|
|
1719
|
+
/**
|
|
1720
|
+
* 记录确认
|
|
1721
|
+
*/
|
|
1722
|
+
confirm(type: ConfirmationPointType, comment?: string): ConfirmationStatus;
|
|
1723
|
+
/**
|
|
1724
|
+
* 获取确认状态
|
|
1725
|
+
*/
|
|
1726
|
+
getConfirmationStatus(type: ConfirmationPointType): ConfirmationStatus | undefined;
|
|
1727
|
+
/**
|
|
1728
|
+
* 检查确认点是否已确认
|
|
1729
|
+
*/
|
|
1730
|
+
isConfirmed(type: ConfirmationPointType): boolean;
|
|
1731
|
+
/**
|
|
1732
|
+
* 清除确认状态(用于回滚后)
|
|
1733
|
+
*/
|
|
1734
|
+
clearConfirmation(type: ConfirmationPointType): void;
|
|
1735
|
+
/**
|
|
1736
|
+
* 清除所有确认状态
|
|
1737
|
+
*/
|
|
1738
|
+
clearAllConfirmations(): void;
|
|
1739
|
+
/**
|
|
1740
|
+
* 获取所有确认点
|
|
1741
|
+
*/
|
|
1742
|
+
getAllConfirmationPoints(): ConfirmationPoint[];
|
|
1743
|
+
/**
|
|
1744
|
+
* 获取指定阶段需要清除的确认点
|
|
1745
|
+
*/
|
|
1746
|
+
getConfirmationsToClear(targetStep: WorkflowStep): ConfirmationPointType[];
|
|
1747
|
+
}
|
|
1748
|
+
/**
|
|
1749
|
+
* 生成确认提示消息
|
|
1750
|
+
*/
|
|
1751
|
+
declare function generateConfirmationPrompt(point: ConfirmationPoint): string;
|
|
1752
|
+
/**
|
|
1753
|
+
* 生成回滚选项提示
|
|
1754
|
+
*/
|
|
1755
|
+
declare function generateRollbackPrompt(fromStep: WorkflowStep): string;
|
|
1756
|
+
|
|
1757
|
+
/**
|
|
1758
|
+
* OpenSpec 工作流引擎
|
|
1759
|
+
* 管理工作流状态、状态转换、确认点、回滚
|
|
1760
|
+
*/
|
|
1761
|
+
|
|
1762
|
+
interface WorkflowSnapshot {
|
|
1763
|
+
step: WorkflowStep;
|
|
1764
|
+
timestamp: Date;
|
|
1765
|
+
state: WorkflowState;
|
|
1766
|
+
artifacts: string[];
|
|
1767
|
+
}
|
|
1768
|
+
interface RollbackResult {
|
|
1769
|
+
success: boolean;
|
|
1770
|
+
from: WorkflowStep;
|
|
1771
|
+
to: WorkflowStep | null;
|
|
1772
|
+
message: string;
|
|
1773
|
+
snapshot?: WorkflowSnapshot;
|
|
1774
|
+
}
|
|
1775
|
+
interface ConfirmationResult {
|
|
1776
|
+
required: boolean;
|
|
1777
|
+
confirmed: boolean;
|
|
1778
|
+
point?: ConfirmationPoint;
|
|
1779
|
+
}
|
|
1780
|
+
declare class WorkflowEngine {
|
|
1781
|
+
private state;
|
|
1782
|
+
private projectPath;
|
|
1783
|
+
private openspecPath;
|
|
1784
|
+
private confirmationManager;
|
|
1785
|
+
private snapshots;
|
|
1786
|
+
private projectContext;
|
|
1787
|
+
private projectConfig;
|
|
1788
|
+
private devStandards;
|
|
1789
|
+
constructor();
|
|
1790
|
+
/**
|
|
1791
|
+
* 初始化工作流引擎
|
|
1792
|
+
*/
|
|
1793
|
+
initialize(projectPath: string): Promise<void>;
|
|
1794
|
+
/**
|
|
1795
|
+
* 加载项目上下文(AGENTS.md 和 config.yaml)
|
|
1796
|
+
*/
|
|
1797
|
+
private loadProjectContext;
|
|
1798
|
+
/**
|
|
1799
|
+
* 获取项目上下文
|
|
1800
|
+
*/
|
|
1801
|
+
getProjectContext(): {
|
|
1802
|
+
agentsMd: string;
|
|
1803
|
+
configYaml: string;
|
|
1804
|
+
devStandards: string;
|
|
1805
|
+
};
|
|
1806
|
+
/**
|
|
1807
|
+
* 启动新工作流
|
|
1808
|
+
*/
|
|
1809
|
+
start(requirement: string, complexity: number, options?: {
|
|
1810
|
+
title?: string;
|
|
1811
|
+
}): Promise<WorkflowState>;
|
|
1812
|
+
/**
|
|
1813
|
+
* 检查转换是否需要确认
|
|
1814
|
+
*/
|
|
1815
|
+
checkConfirmationNeeded(from: WorkflowStep, to: WorkflowStep): ConfirmationResult;
|
|
1816
|
+
/**
|
|
1817
|
+
* 确认检查点
|
|
1818
|
+
*/
|
|
1819
|
+
confirm(type: ConfirmationPointType, comment?: string): void;
|
|
1820
|
+
/**
|
|
1821
|
+
* 获取确认点信息
|
|
1822
|
+
*/
|
|
1823
|
+
getConfirmationPoint(type: ConfirmationPointType): ConfirmationPoint | undefined;
|
|
1824
|
+
/**
|
|
1825
|
+
* 获取当前转换需要的确认点
|
|
1826
|
+
*/
|
|
1827
|
+
getCurrentConfirmationPoint(): ConfirmationPoint | undefined;
|
|
1828
|
+
/**
|
|
1829
|
+
* 执行状态转换
|
|
1830
|
+
*/
|
|
1831
|
+
transition(targetStep: WorkflowStep, reason?: string): Promise<WorkflowTransition>;
|
|
1832
|
+
/**
|
|
1833
|
+
* 获取可回滚的目标阶段
|
|
1834
|
+
*/
|
|
1835
|
+
getRollbackTargets(): WorkflowStep[];
|
|
1836
|
+
/**
|
|
1837
|
+
* 检查是否可以回滚到指定阶段
|
|
1838
|
+
*/
|
|
1839
|
+
canRollbackTo(targetStep: WorkflowStep): boolean;
|
|
1840
|
+
/**
|
|
1841
|
+
* 执行回滚
|
|
1842
|
+
*/
|
|
1843
|
+
rollback(targetStep: WorkflowStep, reason: RollbackReason, description?: string): Promise<RollbackResult>;
|
|
1844
|
+
/**
|
|
1845
|
+
* 获取回滚原因描述
|
|
1846
|
+
*/
|
|
1847
|
+
getRollbackReasonDescription(reason: RollbackReason): string;
|
|
1848
|
+
/**
|
|
1849
|
+
* 获取当前状态
|
|
1850
|
+
*/
|
|
1851
|
+
getState(): WorkflowState | null;
|
|
1852
|
+
/**
|
|
1853
|
+
* 获取允许的下一步
|
|
1854
|
+
*/
|
|
1855
|
+
getAllowedTransitions(): WorkflowStep[];
|
|
1856
|
+
/**
|
|
1857
|
+
* 获取快照历史
|
|
1858
|
+
*/
|
|
1859
|
+
getSnapshots(): WorkflowSnapshot[];
|
|
1860
|
+
/**
|
|
1861
|
+
* 完成当前步骤
|
|
1862
|
+
*/
|
|
1863
|
+
completeCurrentStep(artifacts?: string[]): Promise<void>;
|
|
1864
|
+
/**
|
|
1865
|
+
* 归档工作流
|
|
1866
|
+
*/
|
|
1867
|
+
archive(summary: string): Promise<void>;
|
|
1868
|
+
/**
|
|
1869
|
+
* 取消工作流
|
|
1870
|
+
*/
|
|
1871
|
+
cancel(reason: string): Promise<void>;
|
|
1872
|
+
private ensureDirectories;
|
|
1873
|
+
private restoreState;
|
|
1874
|
+
private saveState;
|
|
1875
|
+
private restoreSnapshots;
|
|
1876
|
+
private saveSnapshots;
|
|
1877
|
+
private createSnapshot;
|
|
1878
|
+
private generateChangeId;
|
|
1879
|
+
private createChangeRecord;
|
|
1880
|
+
private updateChangeRecord;
|
|
1881
|
+
private formatChangeRecord;
|
|
1882
|
+
private createSpecDocument;
|
|
1883
|
+
}
|
|
1884
|
+
/**
|
|
1885
|
+
* 确认点需要确认错误
|
|
1886
|
+
*/
|
|
1887
|
+
declare class ConfirmationRequiredError extends Error {
|
|
1888
|
+
readonly point: ConfirmationPoint;
|
|
1889
|
+
constructor(message: string, point: ConfirmationPoint);
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
/**
|
|
1893
|
+
* 自动补全器
|
|
1894
|
+
* 提供命令、文件路径、历史记录的自动补全
|
|
1895
|
+
*/
|
|
1896
|
+
interface CompletionItem {
|
|
1897
|
+
text: string;
|
|
1898
|
+
displayText: string;
|
|
1899
|
+
description?: string;
|
|
1900
|
+
type: 'command' | 'agent' | 'file' | 'directory' | 'history' | 'option';
|
|
1901
|
+
}
|
|
1902
|
+
interface CompletionResult {
|
|
1903
|
+
items: CompletionItem[];
|
|
1904
|
+
start: number;
|
|
1905
|
+
end: number;
|
|
1906
|
+
}
|
|
1907
|
+
interface CompleterOptions {
|
|
1908
|
+
workingDirectory: string;
|
|
1909
|
+
history: string[];
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1912
|
+
* 自动补全器类
|
|
1913
|
+
*/
|
|
1914
|
+
declare class Completer {
|
|
1915
|
+
private parser;
|
|
1916
|
+
private workingDirectory;
|
|
1917
|
+
private history;
|
|
1918
|
+
private commandCache;
|
|
1919
|
+
private agentCache;
|
|
1920
|
+
private readonly slashCommands;
|
|
1921
|
+
private readonly agents;
|
|
1922
|
+
constructor(options: CompleterOptions);
|
|
1923
|
+
/**
|
|
1924
|
+
* 获取补全建议
|
|
1925
|
+
*/
|
|
1926
|
+
complete(input: string): Promise<CompletionResult | null>;
|
|
1927
|
+
/**
|
|
1928
|
+
* 斜杠命令补全
|
|
1929
|
+
*/
|
|
1930
|
+
private completeSlashCommand;
|
|
1931
|
+
/**
|
|
1932
|
+
* Agent 补全
|
|
1933
|
+
*/
|
|
1934
|
+
private completeAgent;
|
|
1935
|
+
/**
|
|
1936
|
+
* 文件路径补全
|
|
1937
|
+
*/
|
|
1938
|
+
private completeFilePath;
|
|
1939
|
+
/**
|
|
1940
|
+
* 历史记录补全
|
|
1941
|
+
*/
|
|
1942
|
+
private completeHistory;
|
|
1943
|
+
/**
|
|
1944
|
+
* 更新历史记录
|
|
1945
|
+
*/
|
|
1946
|
+
updateHistory(history: string[]): void;
|
|
1947
|
+
/**
|
|
1948
|
+
* 更新工作目录
|
|
1949
|
+
*/
|
|
1950
|
+
updateWorkingDirectory(dir: string): void;
|
|
1951
|
+
/**
|
|
1952
|
+
* 获取所有命令(用于帮助显示)
|
|
1953
|
+
*/
|
|
1954
|
+
getCommands(): CompletionItem[];
|
|
1955
|
+
/**
|
|
1956
|
+
* 获取所有Agent(用于帮助显示)
|
|
1957
|
+
*/
|
|
1958
|
+
getAgents(): CompletionItem[];
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
export { ARCHITECT_AGENT, type AgentCapability, type AgentConstraints, type AgentDefinition, type AgentEvent, type AgentExecutionContext, type AgentExecutionResult, AgentExecutor, type AgentId, type AgentRegistry, type AgentResult, type AgentScheduleRequest, AgentScheduler, type AgentSession, type AgentStatus, type AgentTool, type AgentTrigger, type AgentTriggerType, BUILTIN_AGENTS, type CLIConfig, CODE_REVIEWER_AGENT, type ChangeRecord, type CodeGenOptions, CommandExecutor, CommandParser, CommandType, Completer, ConfigManager, ConfirmationManager, type ConfirmationPoint, type ConfirmationPointType, ConfirmationRequiredError, type ConfirmationStatus, ContextManager, type ContextMessage, type ContextState, type DesignAsset, type DesignBorder, type DesignColor, type DesignLayer, type DesignParseResult, type DesignShadow, type DesignSpacing, type DesignSpec, type DesignStyle, type DesignTypography, type DevStandard, FRONTEND_DEV_AGENT, FigmaMCPAdapter, type FileChange, type FileOperation, type HealthIssue, type HealthReport, type IMCPAdapter, LanhuMCPAdapter, MCPAdapterBase, type MCPClientConfig, type MCPConnectionState, type MCPConnectionStatus, MCPManager, type MCPManagerState, type MCPResource, type MCPResourceContent, type MCPServerConfig, type MCPToolCall, type MCPToolResult, type MCPToolSchema, type MCPTransportType, ModelService, NormsManager, type ProjectContext, ROLLBACK_RULES, type RollbackReason, type RollbackRequest, SCHEDULE_RULES, type ScheduleConfig, type ScheduleResult, type ScheduleStrategy, type StandardWeight, TESTER_AGENT, type Task, type TokenUsage, type ToolExecutor, type ToolPermissionLevel, WorkflowEngine, type WorkflowState, type WorkflowStatus, type WorkflowStep, type WorkflowStepRecord, type WorkflowTransition, type WorkflowType, createAgentExecutor, createAgentScheduler, createMCPManager, generateConfirmationPrompt, generateRollbackPrompt, getAgent, getAgentDefinition, getAgentsForStep, getAgentsForWorkflowStep, getAllAgents, getScheduleRuleDescription, listAgents, runAgent };
|