@xcompiler/cli 0.2.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.
- package/LICENSE +201 -0
- package/NOTICE +10 -0
- package/README.CN.md +272 -0
- package/README.md +274 -0
- package/dist/acp/index.d.ts +1135 -0
- package/dist/acp/index.js +13452 -0
- package/dist/acp/index.js.map +1 -0
- package/dist/cli/xcompiler.d.ts +2 -0
- package/dist/cli/xcompiler.js +14815 -0
- package/dist/cli/xcompiler.js.map +1 -0
- package/dist/cli/xcompiler_build.d.ts +2 -0
- package/dist/cli/xcompiler_build.js +8009 -0
- package/dist/cli/xcompiler_build.js.map +1 -0
- package/dist/cli/xcompiler_run.d.ts +2 -0
- package/dist/cli/xcompiler_run.js +10736 -0
- package/dist/cli/xcompiler_run.js.map +1 -0
- package/dist/plugins/index.d.ts +809 -0
- package/dist/plugins/index.js +1829 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/runtime/runtime.d.ts +1217 -0
- package/dist/runtime/runtime.js +13397 -0
- package/dist/runtime/runtime.js.map +1 -0
- package/docs/acp.md +64 -0
- package/docs/plugin_api.md +106 -0
- package/docs/self_bootstrap.md +88 -0
- package/docs/versioning.md +33 -0
- package/package.json +108 -0
|
@@ -0,0 +1,1135 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Readable, Writable } from 'node:stream';
|
|
3
|
+
|
|
4
|
+
type JsonRpcId = string | number | null;
|
|
5
|
+
interface JsonRpcRequest {
|
|
6
|
+
jsonrpc: '2.0';
|
|
7
|
+
id: JsonRpcId;
|
|
8
|
+
method: string;
|
|
9
|
+
params?: unknown;
|
|
10
|
+
}
|
|
11
|
+
interface JsonRpcNotification {
|
|
12
|
+
jsonrpc: '2.0';
|
|
13
|
+
method: string;
|
|
14
|
+
params?: unknown;
|
|
15
|
+
}
|
|
16
|
+
interface JsonRpcSuccess {
|
|
17
|
+
jsonrpc: '2.0';
|
|
18
|
+
id: JsonRpcId;
|
|
19
|
+
result: unknown;
|
|
20
|
+
}
|
|
21
|
+
interface JsonRpcFailure {
|
|
22
|
+
jsonrpc: '2.0';
|
|
23
|
+
id: JsonRpcId;
|
|
24
|
+
error: JsonRpcErrorObject;
|
|
25
|
+
}
|
|
26
|
+
interface JsonRpcErrorObject {
|
|
27
|
+
code: number;
|
|
28
|
+
message: string;
|
|
29
|
+
data?: unknown;
|
|
30
|
+
}
|
|
31
|
+
type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcSuccess | JsonRpcFailure;
|
|
32
|
+
declare const JsonRpcErrorCode: {
|
|
33
|
+
readonly ParseError: -32700;
|
|
34
|
+
readonly InvalidRequest: -32600;
|
|
35
|
+
readonly MethodNotFound: -32601;
|
|
36
|
+
readonly InvalidParams: -32602;
|
|
37
|
+
readonly InternalError: -32603;
|
|
38
|
+
readonly SessionNotFound: -32001;
|
|
39
|
+
readonly TaskNotFound: -32002;
|
|
40
|
+
readonly PendingRequestNotFound: -32003;
|
|
41
|
+
readonly RuntimeError: -32010;
|
|
42
|
+
readonly CancellationUnsupported: -32020;
|
|
43
|
+
};
|
|
44
|
+
declare const AcpMethod: {
|
|
45
|
+
readonly Initialize: "initialize";
|
|
46
|
+
readonly Shutdown: "shutdown";
|
|
47
|
+
readonly SessionNew: "session/new";
|
|
48
|
+
readonly SessionPrompt: "session/prompt";
|
|
49
|
+
readonly SessionCancel: "session/cancel";
|
|
50
|
+
readonly SessionClose: "session/close";
|
|
51
|
+
readonly SessionSetMode: "session/set_mode";
|
|
52
|
+
readonly SessionUpdate: "session/update";
|
|
53
|
+
readonly SessionRequestPermission: "session/request_permission";
|
|
54
|
+
readonly LegacySessionCreate: "xcompiler/session/create";
|
|
55
|
+
readonly LegacySessionClose: "xcompiler/session/close";
|
|
56
|
+
readonly LegacyTaskStart: "xcompiler/task/start";
|
|
57
|
+
readonly LegacyTaskCancel: "xcompiler/task/cancel";
|
|
58
|
+
readonly LegacyConfirmationRespond: "xcompiler/confirmation/respond";
|
|
59
|
+
readonly LegacyPermissionRespond: "xcompiler/permission/respond";
|
|
60
|
+
readonly LegacyEvent: "xcompiler/event";
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** Supported target languages for generated projects. */
|
|
64
|
+
declare const LANGUAGES: readonly ["python", "typescript"];
|
|
65
|
+
type Language = (typeof LANGUAGES)[number];
|
|
66
|
+
/** Plan intent: greenfield generation, incremental work, or isolated self-bootstrap. */
|
|
67
|
+
declare const PLAN_INTENTS: readonly ["greenfield", "feature", "refactor", "self"];
|
|
68
|
+
type PlanIntent = (typeof PLAN_INTENTS)[number];
|
|
69
|
+
declare const ROLES: readonly ["Planner", "Architect", "Coder", "Tester", "Debugger"];
|
|
70
|
+
type Role = (typeof ROLES)[number];
|
|
71
|
+
interface StepSubtask {
|
|
72
|
+
id: string;
|
|
73
|
+
title: string;
|
|
74
|
+
description: string;
|
|
75
|
+
acceptance?: string;
|
|
76
|
+
outputs?: string[];
|
|
77
|
+
subTasks?: StepSubtask[];
|
|
78
|
+
}
|
|
79
|
+
declare const StepSchema: z.ZodObject<{
|
|
80
|
+
id: z.ZodString;
|
|
81
|
+
iterationId: z.ZodDefault<z.ZodString>;
|
|
82
|
+
phase: z.ZodEnum<{
|
|
83
|
+
REQUIREMENT_ANALYSIS: "REQUIREMENT_ANALYSIS";
|
|
84
|
+
HIGH_LEVEL_DESIGN: "HIGH_LEVEL_DESIGN";
|
|
85
|
+
DETAILED_DESIGN: "DETAILED_DESIGN";
|
|
86
|
+
CODE: "CODE";
|
|
87
|
+
UNIT_TEST: "UNIT_TEST";
|
|
88
|
+
INTEGRATION_TEST: "INTEGRATION_TEST";
|
|
89
|
+
MODULE_TEST: "MODULE_TEST";
|
|
90
|
+
FUNCTIONAL_TEST: "FUNCTIONAL_TEST";
|
|
91
|
+
DEBUG: "DEBUG";
|
|
92
|
+
}>;
|
|
93
|
+
title: z.ZodString;
|
|
94
|
+
description: z.ZodString;
|
|
95
|
+
systemPrompt: z.ZodString;
|
|
96
|
+
role: z.ZodEnum<{
|
|
97
|
+
Planner: "Planner";
|
|
98
|
+
Architect: "Architect";
|
|
99
|
+
Coder: "Coder";
|
|
100
|
+
Tester: "Tester";
|
|
101
|
+
Debugger: "Debugger";
|
|
102
|
+
}>;
|
|
103
|
+
tools: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
104
|
+
inputs: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
105
|
+
outputs: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
106
|
+
subTasks: z.ZodOptional<z.ZodArray<z.ZodType<StepSubtask, unknown, z.core.$ZodTypeInternals<StepSubtask, unknown>>>>;
|
|
107
|
+
dependsOn: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
108
|
+
acceptance: z.ZodString;
|
|
109
|
+
status: z.ZodDefault<z.ZodEnum<{
|
|
110
|
+
PENDING: "PENDING";
|
|
111
|
+
RUNNING: "RUNNING";
|
|
112
|
+
DONE: "DONE";
|
|
113
|
+
FAILED: "FAILED";
|
|
114
|
+
SKIPPED: "SKIPPED";
|
|
115
|
+
}>>;
|
|
116
|
+
retries: z.ZodDefault<z.ZodNumber>;
|
|
117
|
+
maxRetries: z.ZodDefault<z.ZodNumber>;
|
|
118
|
+
}, z.core.$strip>;
|
|
119
|
+
type Step = z.infer<typeof StepSchema>;
|
|
120
|
+
declare const PlanSchema: z.ZodPipe<z.ZodObject<{
|
|
121
|
+
version: z.ZodLiteral<"1">;
|
|
122
|
+
language: z.ZodDefault<z.ZodEnum<{
|
|
123
|
+
python: "python";
|
|
124
|
+
typescript: "typescript";
|
|
125
|
+
}>>;
|
|
126
|
+
intent: z.ZodDefault<z.ZodEnum<{
|
|
127
|
+
greenfield: "greenfield";
|
|
128
|
+
feature: "feature";
|
|
129
|
+
refactor: "refactor";
|
|
130
|
+
self: "self";
|
|
131
|
+
}>>;
|
|
132
|
+
projectType: z.ZodDefault<z.ZodEnum<{
|
|
133
|
+
application: "application";
|
|
134
|
+
library: "library";
|
|
135
|
+
mixed: "mixed";
|
|
136
|
+
}>>;
|
|
137
|
+
requirementDigest: z.ZodString;
|
|
138
|
+
complexityAssessment: z.ZodOptional<z.ZodObject<{
|
|
139
|
+
level: z.ZodEnum<{
|
|
140
|
+
simple: "simple";
|
|
141
|
+
moderate: "moderate";
|
|
142
|
+
complex: "complex";
|
|
143
|
+
}>;
|
|
144
|
+
rationale: z.ZodString;
|
|
145
|
+
splitRecommended: z.ZodDefault<z.ZodBoolean>;
|
|
146
|
+
userForcedPhaseSplit: z.ZodDefault<z.ZodBoolean>;
|
|
147
|
+
}, z.core.$strip>>;
|
|
148
|
+
implementationPhases: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
149
|
+
id: z.ZodString;
|
|
150
|
+
title: z.ZodString;
|
|
151
|
+
objective: z.ZodString;
|
|
152
|
+
status: z.ZodDefault<z.ZodEnum<{
|
|
153
|
+
current: "current";
|
|
154
|
+
planned: "planned";
|
|
155
|
+
deferred: "deferred";
|
|
156
|
+
}>>;
|
|
157
|
+
scope: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
158
|
+
deliverables: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
159
|
+
dependsOn: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
160
|
+
verificationGate: z.ZodOptional<z.ZodObject<{
|
|
161
|
+
summary: z.ZodString;
|
|
162
|
+
checks: z.ZodArray<z.ZodString>;
|
|
163
|
+
failurePolicy: z.ZodString;
|
|
164
|
+
}, z.core.$strip>>;
|
|
165
|
+
}, z.core.$strip>>>;
|
|
166
|
+
architectureModules: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
167
|
+
id: z.ZodString;
|
|
168
|
+
name: z.ZodString;
|
|
169
|
+
responsibility: z.ZodString;
|
|
170
|
+
sourcePaths: z.ZodArray<z.ZodString>;
|
|
171
|
+
testPaths: z.ZodArray<z.ZodString>;
|
|
172
|
+
dependencies: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
173
|
+
}, z.core.$strip>>>;
|
|
174
|
+
globalPrompt: z.ZodDefault<z.ZodString>;
|
|
175
|
+
baselineSummary: z.ZodDefault<z.ZodString>;
|
|
176
|
+
dependencies: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
177
|
+
pythonRequirements: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
178
|
+
userAddenda: z.ZodDefault<z.ZodString>;
|
|
179
|
+
createdAt: z.ZodString;
|
|
180
|
+
steps: z.ZodArray<z.ZodObject<{
|
|
181
|
+
id: z.ZodString;
|
|
182
|
+
iterationId: z.ZodDefault<z.ZodString>;
|
|
183
|
+
phase: z.ZodEnum<{
|
|
184
|
+
REQUIREMENT_ANALYSIS: "REQUIREMENT_ANALYSIS";
|
|
185
|
+
HIGH_LEVEL_DESIGN: "HIGH_LEVEL_DESIGN";
|
|
186
|
+
DETAILED_DESIGN: "DETAILED_DESIGN";
|
|
187
|
+
CODE: "CODE";
|
|
188
|
+
UNIT_TEST: "UNIT_TEST";
|
|
189
|
+
INTEGRATION_TEST: "INTEGRATION_TEST";
|
|
190
|
+
MODULE_TEST: "MODULE_TEST";
|
|
191
|
+
FUNCTIONAL_TEST: "FUNCTIONAL_TEST";
|
|
192
|
+
DEBUG: "DEBUG";
|
|
193
|
+
}>;
|
|
194
|
+
title: z.ZodString;
|
|
195
|
+
description: z.ZodString;
|
|
196
|
+
systemPrompt: z.ZodString;
|
|
197
|
+
role: z.ZodEnum<{
|
|
198
|
+
Planner: "Planner";
|
|
199
|
+
Architect: "Architect";
|
|
200
|
+
Coder: "Coder";
|
|
201
|
+
Tester: "Tester";
|
|
202
|
+
Debugger: "Debugger";
|
|
203
|
+
}>;
|
|
204
|
+
tools: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
205
|
+
inputs: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
206
|
+
outputs: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
207
|
+
subTasks: z.ZodOptional<z.ZodArray<z.ZodType<StepSubtask, unknown, z.core.$ZodTypeInternals<StepSubtask, unknown>>>>;
|
|
208
|
+
dependsOn: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
209
|
+
acceptance: z.ZodString;
|
|
210
|
+
status: z.ZodDefault<z.ZodEnum<{
|
|
211
|
+
PENDING: "PENDING";
|
|
212
|
+
RUNNING: "RUNNING";
|
|
213
|
+
DONE: "DONE";
|
|
214
|
+
FAILED: "FAILED";
|
|
215
|
+
SKIPPED: "SKIPPED";
|
|
216
|
+
}>>;
|
|
217
|
+
retries: z.ZodDefault<z.ZodNumber>;
|
|
218
|
+
maxRetries: z.ZodDefault<z.ZodNumber>;
|
|
219
|
+
}, z.core.$strip>>;
|
|
220
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
221
|
+
dependencies: string[];
|
|
222
|
+
version: "1";
|
|
223
|
+
language: "python" | "typescript";
|
|
224
|
+
intent: "greenfield" | "feature" | "refactor" | "self";
|
|
225
|
+
projectType: "application" | "library" | "mixed";
|
|
226
|
+
requirementDigest: string;
|
|
227
|
+
globalPrompt: string;
|
|
228
|
+
baselineSummary: string;
|
|
229
|
+
userAddenda: string;
|
|
230
|
+
createdAt: string;
|
|
231
|
+
steps: {
|
|
232
|
+
id: string;
|
|
233
|
+
iterationId: string;
|
|
234
|
+
phase: "REQUIREMENT_ANALYSIS" | "HIGH_LEVEL_DESIGN" | "DETAILED_DESIGN" | "CODE" | "UNIT_TEST" | "INTEGRATION_TEST" | "MODULE_TEST" | "FUNCTIONAL_TEST" | "DEBUG";
|
|
235
|
+
title: string;
|
|
236
|
+
description: string;
|
|
237
|
+
systemPrompt: string;
|
|
238
|
+
role: "Planner" | "Architect" | "Coder" | "Tester" | "Debugger";
|
|
239
|
+
tools: string[];
|
|
240
|
+
inputs: string[];
|
|
241
|
+
outputs: string[];
|
|
242
|
+
dependsOn: string[];
|
|
243
|
+
acceptance: string;
|
|
244
|
+
status: "PENDING" | "RUNNING" | "DONE" | "FAILED" | "SKIPPED";
|
|
245
|
+
retries: number;
|
|
246
|
+
maxRetries: number;
|
|
247
|
+
subTasks?: StepSubtask[] | undefined;
|
|
248
|
+
}[];
|
|
249
|
+
complexityAssessment?: {
|
|
250
|
+
level: "simple" | "moderate" | "complex";
|
|
251
|
+
rationale: string;
|
|
252
|
+
splitRecommended: boolean;
|
|
253
|
+
userForcedPhaseSplit: boolean;
|
|
254
|
+
} | undefined;
|
|
255
|
+
implementationPhases?: {
|
|
256
|
+
id: string;
|
|
257
|
+
title: string;
|
|
258
|
+
objective: string;
|
|
259
|
+
status: "current" | "planned" | "deferred";
|
|
260
|
+
scope: string[];
|
|
261
|
+
deliverables: string[];
|
|
262
|
+
dependsOn: string[];
|
|
263
|
+
verificationGate?: {
|
|
264
|
+
summary: string;
|
|
265
|
+
checks: string[];
|
|
266
|
+
failurePolicy: string;
|
|
267
|
+
} | undefined;
|
|
268
|
+
}[] | undefined;
|
|
269
|
+
architectureModules?: {
|
|
270
|
+
id: string;
|
|
271
|
+
name: string;
|
|
272
|
+
responsibility: string;
|
|
273
|
+
sourcePaths: string[];
|
|
274
|
+
testPaths: string[];
|
|
275
|
+
dependencies: string[];
|
|
276
|
+
}[] | undefined;
|
|
277
|
+
}, {
|
|
278
|
+
version: "1";
|
|
279
|
+
language: "python" | "typescript";
|
|
280
|
+
intent: "greenfield" | "feature" | "refactor" | "self";
|
|
281
|
+
projectType: "application" | "library" | "mixed";
|
|
282
|
+
requirementDigest: string;
|
|
283
|
+
globalPrompt: string;
|
|
284
|
+
baselineSummary: string;
|
|
285
|
+
userAddenda: string;
|
|
286
|
+
createdAt: string;
|
|
287
|
+
steps: {
|
|
288
|
+
id: string;
|
|
289
|
+
iterationId: string;
|
|
290
|
+
phase: "REQUIREMENT_ANALYSIS" | "HIGH_LEVEL_DESIGN" | "DETAILED_DESIGN" | "CODE" | "UNIT_TEST" | "INTEGRATION_TEST" | "MODULE_TEST" | "FUNCTIONAL_TEST" | "DEBUG";
|
|
291
|
+
title: string;
|
|
292
|
+
description: string;
|
|
293
|
+
systemPrompt: string;
|
|
294
|
+
role: "Planner" | "Architect" | "Coder" | "Tester" | "Debugger";
|
|
295
|
+
tools: string[];
|
|
296
|
+
inputs: string[];
|
|
297
|
+
outputs: string[];
|
|
298
|
+
dependsOn: string[];
|
|
299
|
+
acceptance: string;
|
|
300
|
+
status: "PENDING" | "RUNNING" | "DONE" | "FAILED" | "SKIPPED";
|
|
301
|
+
retries: number;
|
|
302
|
+
maxRetries: number;
|
|
303
|
+
subTasks?: StepSubtask[] | undefined;
|
|
304
|
+
}[];
|
|
305
|
+
complexityAssessment?: {
|
|
306
|
+
level: "simple" | "moderate" | "complex";
|
|
307
|
+
rationale: string;
|
|
308
|
+
splitRecommended: boolean;
|
|
309
|
+
userForcedPhaseSplit: boolean;
|
|
310
|
+
} | undefined;
|
|
311
|
+
implementationPhases?: {
|
|
312
|
+
id: string;
|
|
313
|
+
title: string;
|
|
314
|
+
objective: string;
|
|
315
|
+
status: "current" | "planned" | "deferred";
|
|
316
|
+
scope: string[];
|
|
317
|
+
deliverables: string[];
|
|
318
|
+
dependsOn: string[];
|
|
319
|
+
verificationGate?: {
|
|
320
|
+
summary: string;
|
|
321
|
+
checks: string[];
|
|
322
|
+
failurePolicy: string;
|
|
323
|
+
} | undefined;
|
|
324
|
+
}[] | undefined;
|
|
325
|
+
architectureModules?: {
|
|
326
|
+
id: string;
|
|
327
|
+
name: string;
|
|
328
|
+
responsibility: string;
|
|
329
|
+
sourcePaths: string[];
|
|
330
|
+
testPaths: string[];
|
|
331
|
+
dependencies: string[];
|
|
332
|
+
}[] | undefined;
|
|
333
|
+
dependencies?: string[] | undefined;
|
|
334
|
+
pythonRequirements?: string[] | undefined;
|
|
335
|
+
}>>;
|
|
336
|
+
type Plan = z.infer<typeof PlanSchema>;
|
|
337
|
+
|
|
338
|
+
type ChatRole = 'system' | 'user' | 'assistant';
|
|
339
|
+
interface ChatMessage {
|
|
340
|
+
role: ChatRole;
|
|
341
|
+
content: string;
|
|
342
|
+
}
|
|
343
|
+
interface ChatOptions {
|
|
344
|
+
temperature?: number;
|
|
345
|
+
maxTokens?: number;
|
|
346
|
+
/** Force JSON-only response if provider supports it. */
|
|
347
|
+
responseFormat?: 'text' | 'json';
|
|
348
|
+
/**
|
|
349
|
+
* 流式 token 回调。设置后 provider 会以增量方式推送 token;
|
|
350
|
+
* provider 仍会聚合并返回完整文本作为最终结果。
|
|
351
|
+
*/
|
|
352
|
+
onToken?: (chunk: string) => void;
|
|
353
|
+
/**
|
|
354
|
+
* 流式模式下的“可提前结束”判定。用于兼容一些 provider:
|
|
355
|
+
* 输出内容本身已经完整,但既不及时发送 [DONE],也不主动断开连接。
|
|
356
|
+
* 返回 true 后 provider 应尽快结束本次流读取并返回当前 aggregate。
|
|
357
|
+
*/
|
|
358
|
+
streamStopWhen?: (text: string) => boolean;
|
|
359
|
+
/**
|
|
360
|
+
* 可选验证钩子:provider 返回后调用。抛异常会被 FallbackClient
|
|
361
|
+
* 视为该 provider 失败,并切换到下一个。适用于:JSON 退化、
|
|
362
|
+
* 空输出、model token loop 等“表面成功但语义不可用”场景。
|
|
363
|
+
*/
|
|
364
|
+
validate?: (text: string) => void;
|
|
365
|
+
/**
|
|
366
|
+
* 调用者可传入回调,与 LLM 输出一同拿到实际产出该响应的 provider 名。
|
|
367
|
+
* 主要用于追溯:在 FallbackClient 中服务于响应的是链中某一个后选 provider,
|
|
368
|
+
* 调用者(如 Executor)需要在审计 / Markdown 记录中为响应打上正确的“via 哪个模型”标签。
|
|
369
|
+
*/
|
|
370
|
+
onProvider?: (name: string) => void;
|
|
371
|
+
/**
|
|
372
|
+
* 每次开始尝试候选 provider 时触发。用于 CLI 在等待首个 token 前显示
|
|
373
|
+
* 当前 provider 与模型;fallback 切换时会再次触发。
|
|
374
|
+
*/
|
|
375
|
+
onProviderStart?: (name: string, model: string) => void;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* AuditLogger 把开发流水线中的所有交互/执行动作记录到两份产物:
|
|
380
|
+
*
|
|
381
|
+
* - `docs/process_log.md` —— 人类可读的过程记录,用于交付时汇总。
|
|
382
|
+
* - `.xcompiler/audit.jsonl` —— 机器可读的逐行 JSON,便于后续分析与回放。
|
|
383
|
+
*
|
|
384
|
+
* 设计原则:
|
|
385
|
+
* - 追加写入,永不删除。
|
|
386
|
+
* - 失败时不影响主流程(写盘异常仅打印 warning)。
|
|
387
|
+
* - 每条事件都带 ts / kind / payload。
|
|
388
|
+
*/
|
|
389
|
+
type AuditKind = 'session.start' | 'session.end' | 'user.input' | 'user.decision' | 'llm.request' | 'llm.response' | 'llm.error' | 'llm.score' | 'fs.write' | 'plan.persist' | 'topic.persist' | 'phase.start' | 'phase.end' | 'tool.call' | 'tool.result' | 'sandbox.exec' | 'executor.turn' | 'planner.thought' | 'conftest.autogen' | 'issue.record' | 'issue.route' | 'issue.resolve' | 'note';
|
|
390
|
+
interface AuditLoggerOptions {
|
|
391
|
+
/** workspace 根目录(绝对路径) */
|
|
392
|
+
root: string;
|
|
393
|
+
/** 命令名,例如 `xcompiler_build` / `xcompiler_run` */
|
|
394
|
+
command: string;
|
|
395
|
+
/** markdown 文件相对路径,默认 docs/process_log.md */
|
|
396
|
+
mdRelPath?: string;
|
|
397
|
+
/** jsonl 文件相对路径,默认 .xcompiler/audit.jsonl */
|
|
398
|
+
jsonlRelPath?: string;
|
|
399
|
+
/** full=完整内容;redacted=保留内容但遮蔽凭据(默认);metadata=仅保留长度与摘要。 */
|
|
400
|
+
contentMode?: AuditContentMode;
|
|
401
|
+
}
|
|
402
|
+
type AuditContentMode = 'full' | 'redacted' | 'metadata';
|
|
403
|
+
declare class AuditLogger {
|
|
404
|
+
private readonly mdAbs;
|
|
405
|
+
private readonly jsonlAbs;
|
|
406
|
+
private readonly command;
|
|
407
|
+
private readonly contentMode;
|
|
408
|
+
private startTs;
|
|
409
|
+
/** 串行化 markdown 追加,防止并发 appendFile 交错。 */
|
|
410
|
+
private mdQueue;
|
|
411
|
+
constructor(opts: AuditLoggerOptions);
|
|
412
|
+
start(meta?: Record<string, unknown>): Promise<void>;
|
|
413
|
+
end(summary?: Record<string, unknown>): Promise<void>;
|
|
414
|
+
/** 通用事件,jsonl + 简短 markdown 一行。 */
|
|
415
|
+
event(kind: AuditKind, message: string, data?: Record<string, unknown>): Promise<void>;
|
|
416
|
+
/** 用户输入 / 决策。会把内容以引用块写入 markdown。 */
|
|
417
|
+
userInput(label: string, content: string): Promise<void>;
|
|
418
|
+
userDecision(label: string, value: string): Promise<void>;
|
|
419
|
+
/** LLM 请求/响应:完整 prompt 与回包写入 markdown 折叠块。 */
|
|
420
|
+
llmRequest(role: string, model: string, messages: unknown, options?: unknown): Promise<void>;
|
|
421
|
+
llmResponse(role: string, model: string, content: string, meta?: Record<string, unknown>): Promise<void>;
|
|
422
|
+
llmError(role: string, model: string, err: unknown): Promise<void>;
|
|
423
|
+
/**
|
|
424
|
+
* 记录一轮 Executor 思考:thoughts 文本、计划调用的 actions、是否完成。
|
|
425
|
+
* 写入 jsonl + markdown 折叠块,交付时可作为"AI 思考过程完整记录"。
|
|
426
|
+
*/
|
|
427
|
+
executorTurn(stepId: string, role: string, round: number, payload: {
|
|
428
|
+
thoughts?: string;
|
|
429
|
+
actions?: unknown[];
|
|
430
|
+
done?: boolean;
|
|
431
|
+
raw?: string;
|
|
432
|
+
provider?: string;
|
|
433
|
+
}): Promise<void>;
|
|
434
|
+
/** 记录 Planner 的思考阶段,比如 clarify / decompose 原始输出。 */
|
|
435
|
+
plannerThought(stage: string, content: string, meta?: Record<string, unknown> & {
|
|
436
|
+
provider?: string;
|
|
437
|
+
}): Promise<void>;
|
|
438
|
+
private ensureFiles;
|
|
439
|
+
private appendMd;
|
|
440
|
+
private appendJsonl;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
declare const CLARIFICATION_CATEGORIES: readonly ["functionality", "data", "acceptance", "boundary", "quality", "extensibility"];
|
|
444
|
+
type ClarificationCategory = (typeof CLARIFICATION_CATEGORIES)[number];
|
|
445
|
+
declare const CLARIFICATION_OPTION_LABELS: readonly ["A", "B", "C", "D", "E"];
|
|
446
|
+
type ClarificationOptionLabel = (typeof CLARIFICATION_OPTION_LABELS)[number];
|
|
447
|
+
interface ClarifyOption {
|
|
448
|
+
label: ClarificationOptionLabel;
|
|
449
|
+
answer: string;
|
|
450
|
+
}
|
|
451
|
+
interface ClarifyQuestion {
|
|
452
|
+
id: string;
|
|
453
|
+
category: ClarificationCategory;
|
|
454
|
+
question: string;
|
|
455
|
+
why: string;
|
|
456
|
+
options: ClarifyOption[];
|
|
457
|
+
}
|
|
458
|
+
interface PlannerInput {
|
|
459
|
+
rawRequirement: string;
|
|
460
|
+
clarifications: Array<{
|
|
461
|
+
question: string;
|
|
462
|
+
answer: string;
|
|
463
|
+
category?: ClarificationCategory;
|
|
464
|
+
why?: string;
|
|
465
|
+
options?: ClarifyOption[];
|
|
466
|
+
}>;
|
|
467
|
+
/** 用户在澄清问答后补充的自定义需求(可为空)。 */
|
|
468
|
+
userAddenda?: string;
|
|
469
|
+
/** 增量开发时,现有工程基线摘要(文档 / 计划 / 源码树)。 */
|
|
470
|
+
baselineContext?: string;
|
|
471
|
+
/** 计划意图:greenfield / feature / refactor / self。 */
|
|
472
|
+
intent?: PlanIntent;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
declare class Workspace {
|
|
476
|
+
readonly root: string;
|
|
477
|
+
constructor(root: string);
|
|
478
|
+
abs(...p: string[]): string;
|
|
479
|
+
ensure(dir: string): Promise<void>;
|
|
480
|
+
writeFile(rel: string, content: string): Promise<void>;
|
|
481
|
+
readFile(rel: string): Promise<string>;
|
|
482
|
+
exists(rel: string): Promise<boolean>;
|
|
483
|
+
remove(rel: string): Promise<void>;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
interface ExecResult {
|
|
487
|
+
exitCode: number;
|
|
488
|
+
stdout: string;
|
|
489
|
+
stderr: string;
|
|
490
|
+
timedOut: boolean;
|
|
491
|
+
durationMs: number;
|
|
492
|
+
}
|
|
493
|
+
interface ExecExtra {
|
|
494
|
+
cwd?: string;
|
|
495
|
+
env?: Record<string, string>;
|
|
496
|
+
timeoutMs?: number;
|
|
497
|
+
}
|
|
498
|
+
/** 沙盒统一接口。任意 phase / tool 都通过此接口与运行时交互。 */
|
|
499
|
+
interface Sandbox {
|
|
500
|
+
/** 实现标识,便于审计与日志区分。 */
|
|
501
|
+
readonly kind: 'subprocess' | 'docker';
|
|
502
|
+
/**
|
|
503
|
+
* 构建/复用环境。
|
|
504
|
+
* - Python:`pip install -r requirements.txt` + venv。
|
|
505
|
+
* - TypeScript:`npm install`(依据 package.json)。
|
|
506
|
+
* manifestFile 为依赖清单在 workspace 内的相对路径;不存在则跳过安装。
|
|
507
|
+
* 返回是否真正重建。
|
|
508
|
+
*/
|
|
509
|
+
build(manifestFile?: string): Promise<{
|
|
510
|
+
rebuilt: boolean;
|
|
511
|
+
reason: string;
|
|
512
|
+
}>;
|
|
513
|
+
/** 执行任意命令;cmd 视实现可能是宿主路径或容器内路径。 */
|
|
514
|
+
exec(cmd: string, argv: string[], extra?: ExecExtra): Promise<ExecResult>;
|
|
515
|
+
/**
|
|
516
|
+
* 运行工程入口程序。
|
|
517
|
+
* - Python:`python <args>`(自动选用 venv 内解释器)。
|
|
518
|
+
* - TypeScript:`npx tsx <args>`。
|
|
519
|
+
*/
|
|
520
|
+
runProgram(args: string[], extra?: ExecExtra): Promise<ExecResult>;
|
|
521
|
+
/**
|
|
522
|
+
* 运行测试套件。
|
|
523
|
+
* - Python:`python -m pytest <args>`。
|
|
524
|
+
* - TypeScript:`npm test`(Vitest)。
|
|
525
|
+
*/
|
|
526
|
+
runTests(args?: string[], extra?: ExecExtra): Promise<ExecResult>;
|
|
527
|
+
/**
|
|
528
|
+
* 安装额外依赖(不写入依赖清单)。
|
|
529
|
+
* - Python:`pip install <packages>`。
|
|
530
|
+
* - TypeScript:`npm install <packages>`。
|
|
531
|
+
*/
|
|
532
|
+
installDeps(packages: string[]): Promise<ExecResult>;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
type ToolPermissionOperation = 'shell_command' | 'file_write' | 'file_delete' | 'install_dependency' | 'config_change' | 'git_operation' | 'network_access' | 'test_command' | 'build_command' | 'external_read' | 'external_write';
|
|
536
|
+
interface ToolPermissionRequest {
|
|
537
|
+
id?: string;
|
|
538
|
+
operationType: ToolPermissionOperation;
|
|
539
|
+
target: string;
|
|
540
|
+
reason: string;
|
|
541
|
+
risk: string;
|
|
542
|
+
scope: string;
|
|
543
|
+
skippable: boolean;
|
|
544
|
+
denyBehavior: string;
|
|
545
|
+
stepId?: string;
|
|
546
|
+
tool?: string;
|
|
547
|
+
metadata?: Record<string, unknown>;
|
|
548
|
+
}
|
|
549
|
+
interface ToolPermissionDecision {
|
|
550
|
+
approved: boolean;
|
|
551
|
+
reason?: string;
|
|
552
|
+
}
|
|
553
|
+
type ToolPermissionRequester = (request: ToolPermissionRequest) => Promise<ToolPermissionDecision>;
|
|
554
|
+
interface ToolExecutionEvent {
|
|
555
|
+
status: 'started' | 'completed';
|
|
556
|
+
stepId: string;
|
|
557
|
+
tool: string;
|
|
558
|
+
target?: string;
|
|
559
|
+
args?: Record<string, unknown>;
|
|
560
|
+
ok?: boolean;
|
|
561
|
+
summary?: string;
|
|
562
|
+
error?: string;
|
|
563
|
+
changedFiles?: string[];
|
|
564
|
+
patch?: string;
|
|
565
|
+
}
|
|
566
|
+
type ToolExecutionReporter = (event: ToolExecutionEvent) => void | Promise<void>;
|
|
567
|
+
/** 工具调用的统一上下文。 */
|
|
568
|
+
interface ToolContext {
|
|
569
|
+
ws: Workspace;
|
|
570
|
+
sandbox: Sandbox;
|
|
571
|
+
audit?: AuditLogger;
|
|
572
|
+
/** 当前 Step 的 outputs 白名单(写操作必须落在白名单内)。 */
|
|
573
|
+
allowedWrites: string[];
|
|
574
|
+
/** 当前 Step 的 id(仅用于审计)。 */
|
|
575
|
+
stepId: string;
|
|
576
|
+
/** 目标语言(决定依赖清单文件等)。默认 python。 */
|
|
577
|
+
language?: Language;
|
|
578
|
+
/** 当前 Step 的 write_file / append_file 单次 content 字节预算。 */
|
|
579
|
+
writeChunkBytes?: number;
|
|
580
|
+
/** Optional protocol/UI permission hook for sensitive tool operations. */
|
|
581
|
+
requestPermission?: ToolPermissionRequester;
|
|
582
|
+
/** Optional protocol/UI event hook for tool calls and file changes. */
|
|
583
|
+
onToolEvent?: ToolExecutionReporter;
|
|
584
|
+
}
|
|
585
|
+
/** 单次工具调用的结果统一结构。 */
|
|
586
|
+
interface ToolResult<T = unknown> {
|
|
587
|
+
ok: boolean;
|
|
588
|
+
data?: T;
|
|
589
|
+
error?: string;
|
|
590
|
+
/** 用于摘要展示。 */
|
|
591
|
+
summary?: string;
|
|
592
|
+
}
|
|
593
|
+
interface Tool<A = unknown, R = unknown> {
|
|
594
|
+
readonly name: string;
|
|
595
|
+
readonly description: string;
|
|
596
|
+
/** 简要 JSON Schema 描述参数(仅用于 prompt,不强校验)。 */
|
|
597
|
+
readonly argsSchema: Record<string, unknown>;
|
|
598
|
+
run(args: A, ctx: ToolContext): Promise<ToolResult<R>>;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Skill:把一组原子工具组合为面向 LLM 的"高阶能力"。
|
|
603
|
+
*
|
|
604
|
+
* 在 M3 阶段 Skill 是一层"语义包装"——执行器仍然按 step.tools 中的工具名调用具体 Tool,
|
|
605
|
+
* 但 Step 可以声明 `tools: ["skill:patcher"]`,Skill Registry 会展开为底层工具集合,
|
|
606
|
+
* 并把 Skill 的 `prompt` 注入 system prompt,提示 LLM 该如何组合这些工具。
|
|
607
|
+
*/
|
|
608
|
+
interface Skill {
|
|
609
|
+
/** 形如 `patcher` / `tester` / `dep_resolver`。 */
|
|
610
|
+
readonly name: string;
|
|
611
|
+
/** 注入到 system prompt 的简短指引(中文一句话)。 */
|
|
612
|
+
readonly prompt: string;
|
|
613
|
+
/** 该 Skill 暴露给 LLM 的底层工具名集合。 */
|
|
614
|
+
readonly tools: string[];
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
interface EngineRunSummary {
|
|
618
|
+
totalSteps: number;
|
|
619
|
+
executedSteps: number;
|
|
620
|
+
failedStepId?: string;
|
|
621
|
+
failureLog?: string;
|
|
622
|
+
failureReason?: string;
|
|
623
|
+
}
|
|
624
|
+
interface StepAttemptOutcome {
|
|
625
|
+
ok: boolean;
|
|
626
|
+
failureLog: string;
|
|
627
|
+
reason?: string;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* XCompiler 的公共生命周期 Hook。
|
|
631
|
+
*
|
|
632
|
+
* Context 对象会按顺序传给所有 handler;插件可以原位补充或调整字段,但不得替换
|
|
633
|
+
* workspace / audit 等核心服务。涉及文件写入时仍必须通过 Tool 与 EditGuard。
|
|
634
|
+
*/
|
|
635
|
+
interface HookContextMap {
|
|
636
|
+
'compile.start': {
|
|
637
|
+
workspace: string;
|
|
638
|
+
intent: PlanIntent;
|
|
639
|
+
topicMode: boolean;
|
|
640
|
+
};
|
|
641
|
+
'compile.afterClarify': {
|
|
642
|
+
rawRequirement: string;
|
|
643
|
+
questions: ClarifyQuestion[];
|
|
644
|
+
clarifications: PlannerInput['clarifications'];
|
|
645
|
+
userAddenda: string;
|
|
646
|
+
};
|
|
647
|
+
'compile.beforeDecompose': {
|
|
648
|
+
input: PlannerInput;
|
|
649
|
+
};
|
|
650
|
+
'compile.afterPlan': {
|
|
651
|
+
plan: Plan;
|
|
652
|
+
};
|
|
653
|
+
'compile.finish': {
|
|
654
|
+
plan: Plan;
|
|
655
|
+
planPath: string;
|
|
656
|
+
};
|
|
657
|
+
'run.before': {
|
|
658
|
+
plan: Plan;
|
|
659
|
+
};
|
|
660
|
+
'run.after': {
|
|
661
|
+
plan: Plan;
|
|
662
|
+
result: EngineRunSummary;
|
|
663
|
+
};
|
|
664
|
+
'run.error': {
|
|
665
|
+
plan: Plan;
|
|
666
|
+
error: unknown;
|
|
667
|
+
};
|
|
668
|
+
'step.before': {
|
|
669
|
+
plan: Plan;
|
|
670
|
+
step: Step;
|
|
671
|
+
};
|
|
672
|
+
'step.after': {
|
|
673
|
+
plan: Plan;
|
|
674
|
+
step: Step;
|
|
675
|
+
ok: boolean;
|
|
676
|
+
};
|
|
677
|
+
'step.error': {
|
|
678
|
+
plan: Plan;
|
|
679
|
+
step: Step;
|
|
680
|
+
error: unknown;
|
|
681
|
+
};
|
|
682
|
+
'step.attempt.before': {
|
|
683
|
+
plan: Plan;
|
|
684
|
+
step: Step;
|
|
685
|
+
role: Role;
|
|
686
|
+
debug: boolean;
|
|
687
|
+
retry: number;
|
|
688
|
+
};
|
|
689
|
+
'step.attempt.after': {
|
|
690
|
+
plan: Plan;
|
|
691
|
+
step: Step;
|
|
692
|
+
role: Role;
|
|
693
|
+
debug: boolean;
|
|
694
|
+
retry: number;
|
|
695
|
+
outcome: StepAttemptOutcome;
|
|
696
|
+
};
|
|
697
|
+
'tool.before': {
|
|
698
|
+
stepId: string;
|
|
699
|
+
tool: string;
|
|
700
|
+
args: unknown;
|
|
701
|
+
context: ToolContext;
|
|
702
|
+
};
|
|
703
|
+
'tool.after': {
|
|
704
|
+
stepId: string;
|
|
705
|
+
tool: string;
|
|
706
|
+
args: unknown;
|
|
707
|
+
context: ToolContext;
|
|
708
|
+
result: ToolResult;
|
|
709
|
+
};
|
|
710
|
+
'tool.error': {
|
|
711
|
+
stepId: string;
|
|
712
|
+
tool: string;
|
|
713
|
+
args: unknown;
|
|
714
|
+
context: ToolContext;
|
|
715
|
+
error: unknown;
|
|
716
|
+
};
|
|
717
|
+
'llm.before': {
|
|
718
|
+
role: string;
|
|
719
|
+
model: string;
|
|
720
|
+
messages: ChatMessage[];
|
|
721
|
+
options?: ChatOptions;
|
|
722
|
+
};
|
|
723
|
+
'llm.after': {
|
|
724
|
+
role: string;
|
|
725
|
+
model: string;
|
|
726
|
+
messages: ChatMessage[];
|
|
727
|
+
response: string;
|
|
728
|
+
durationMs: number;
|
|
729
|
+
};
|
|
730
|
+
'llm.error': {
|
|
731
|
+
role: string;
|
|
732
|
+
model: string;
|
|
733
|
+
messages: ChatMessage[];
|
|
734
|
+
error: unknown;
|
|
735
|
+
durationMs: number;
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
type HookName = keyof HookContextMap;
|
|
739
|
+
type HookHandler<K extends HookName> = (context: HookContextMap[K]) => void | Promise<void>;
|
|
740
|
+
interface HookRegistrationOptions {
|
|
741
|
+
/** 数值越大越先执行;相同优先级保持插件及注册顺序。 */
|
|
742
|
+
priority?: number;
|
|
743
|
+
}
|
|
744
|
+
interface PluginApi {
|
|
745
|
+
/** 当前 XCompiler 核心版本。 */
|
|
746
|
+
readonly xcompilerVersion: string;
|
|
747
|
+
/** 当前插件 API 主版本;仅同一主版本兼容。 */
|
|
748
|
+
readonly pluginApiVersion: number;
|
|
749
|
+
on<K extends HookName>(hook: K, handler: HookHandler<K>, options?: HookRegistrationOptions): () => void;
|
|
750
|
+
registerTool(tool: Tool): void;
|
|
751
|
+
registerSkill(skill: Skill): void;
|
|
752
|
+
}
|
|
753
|
+
/** 可序列化的插件清单;后续 registry / marketplace 不需要加载插件代码即可读取。 */
|
|
754
|
+
interface XCompilerPluginManifest {
|
|
755
|
+
/** 全局唯一且稳定的插件 ID,例如 `company.policy-checker`。 */
|
|
756
|
+
id: string;
|
|
757
|
+
/** 插件自身版本,必须是完整 SemVer。 */
|
|
758
|
+
version: string;
|
|
759
|
+
/** 插件编译时面向的 XCompiler Plugin API 主版本。 */
|
|
760
|
+
apiVersion: number;
|
|
761
|
+
/** 插件可运行的最低 XCompiler 核心版本;必填完整 SemVer。 */
|
|
762
|
+
minXCompilerVersion: string;
|
|
763
|
+
/** 以下字段用于插件目录展示,不参与运行时兼容判定。 */
|
|
764
|
+
displayName?: string;
|
|
765
|
+
description?: string;
|
|
766
|
+
license?: string;
|
|
767
|
+
homepage?: string;
|
|
768
|
+
keywords?: string[];
|
|
769
|
+
}
|
|
770
|
+
interface XCompilerPlugin {
|
|
771
|
+
manifest: XCompilerPluginManifest;
|
|
772
|
+
/** 默认 continue:记录错误但不拖垮核心流程。 */
|
|
773
|
+
failureMode?: 'continue' | 'fail';
|
|
774
|
+
setup(api: PluginApi): void | Promise<void>;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
type RuntimeLogLevel = 'success' | 'warning' | 'error' | 'info' | 'dim' | 'accent' | 'raw';
|
|
778
|
+
|
|
779
|
+
interface RuntimeLogEvent {
|
|
780
|
+
type: 'log';
|
|
781
|
+
level: RuntimeLogLevel;
|
|
782
|
+
message: string;
|
|
783
|
+
}
|
|
784
|
+
interface RuntimeResultEvent {
|
|
785
|
+
type: 'result';
|
|
786
|
+
command: 'build' | 'run';
|
|
787
|
+
status: string;
|
|
788
|
+
data?: Record<string, unknown>;
|
|
789
|
+
}
|
|
790
|
+
interface RuntimeProgressEvent {
|
|
791
|
+
type: 'progress';
|
|
792
|
+
status: 'start' | 'succeed' | 'fail';
|
|
793
|
+
message: string;
|
|
794
|
+
}
|
|
795
|
+
interface RuntimeToolCallEvent {
|
|
796
|
+
type: 'tool_call';
|
|
797
|
+
status: ToolExecutionEvent['status'];
|
|
798
|
+
stepId: string;
|
|
799
|
+
tool: string;
|
|
800
|
+
target?: string;
|
|
801
|
+
ok?: boolean;
|
|
802
|
+
summary?: string;
|
|
803
|
+
error?: string;
|
|
804
|
+
}
|
|
805
|
+
interface RuntimeFileChangedEvent {
|
|
806
|
+
type: 'file_changed';
|
|
807
|
+
stepId: string;
|
|
808
|
+
tool: string;
|
|
809
|
+
path: string;
|
|
810
|
+
}
|
|
811
|
+
interface RuntimePatchProposedEvent {
|
|
812
|
+
type: 'patch_proposed';
|
|
813
|
+
stepId: string;
|
|
814
|
+
tool: string;
|
|
815
|
+
patch: string;
|
|
816
|
+
}
|
|
817
|
+
interface RuntimePermissionEvent {
|
|
818
|
+
type: 'permission';
|
|
819
|
+
status: 'requested' | 'approved' | 'denied';
|
|
820
|
+
request: ToolPermissionRequest;
|
|
821
|
+
}
|
|
822
|
+
type RuntimeEvent = RuntimeLogEvent | RuntimeProgressEvent | RuntimeResultEvent | RuntimeToolCallEvent | RuntimeFileChangedEvent | RuntimePatchProposedEvent | RuntimePermissionEvent;
|
|
823
|
+
interface RuntimeProgress {
|
|
824
|
+
succeed(message: string): void | Promise<void>;
|
|
825
|
+
fail(message: string): void | Promise<void>;
|
|
826
|
+
stop?(): void | Promise<void>;
|
|
827
|
+
}
|
|
828
|
+
interface RuntimeSelectChoice<T extends string = string> {
|
|
829
|
+
name: string;
|
|
830
|
+
value: T;
|
|
831
|
+
}
|
|
832
|
+
interface RuntimeInteraction {
|
|
833
|
+
input(args: {
|
|
834
|
+
message: string;
|
|
835
|
+
}): Promise<string>;
|
|
836
|
+
confirm(args: {
|
|
837
|
+
message: string;
|
|
838
|
+
default?: boolean;
|
|
839
|
+
}): Promise<boolean>;
|
|
840
|
+
editor(args: {
|
|
841
|
+
message: string;
|
|
842
|
+
default?: string;
|
|
843
|
+
postfix?: string;
|
|
844
|
+
}): Promise<string>;
|
|
845
|
+
select<T extends string>(args: {
|
|
846
|
+
message: string;
|
|
847
|
+
choices: RuntimeSelectChoice<T>[];
|
|
848
|
+
}): Promise<T>;
|
|
849
|
+
readMultiline(args: {
|
|
850
|
+
message: string;
|
|
851
|
+
}): Promise<string>;
|
|
852
|
+
pauseStdin?(): void;
|
|
853
|
+
}
|
|
854
|
+
interface RuntimeIO {
|
|
855
|
+
emit(event: RuntimeEvent): void | Promise<void>;
|
|
856
|
+
progress(message: string, opts?: {
|
|
857
|
+
animate?: boolean;
|
|
858
|
+
}): RuntimeProgress;
|
|
859
|
+
interaction?: RuntimeInteraction;
|
|
860
|
+
requestPermission?: ToolPermissionRequester;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
interface CompileOptions {
|
|
864
|
+
workspace: string;
|
|
865
|
+
configPath?: string;
|
|
866
|
+
inputFile?: string;
|
|
867
|
+
/**
|
|
868
|
+
* 已澄清的 topic.md 直接输入:跳过 intake / clarify / Addenda / Gate 1,把该文件
|
|
869
|
+
* 内容当作冻结后的项目选题书,直接进入 decompose。常用于:
|
|
870
|
+
* - 用户上次已澄清并保留了 topic.md,重新跑 decompose 不想再问一遍
|
|
871
|
+
* - 离线编辑了 topic.md 想直接拿来出 plan.json
|
|
872
|
+
* 与 --input 互斥;同时给则 --topic 优先并打印警告。
|
|
873
|
+
*/
|
|
874
|
+
topicFile?: string;
|
|
875
|
+
outputFile?: string;
|
|
876
|
+
intent?: PlanIntent;
|
|
877
|
+
baselinePlanFile?: string;
|
|
878
|
+
yes?: boolean;
|
|
879
|
+
force?: boolean;
|
|
880
|
+
/** Optional XXX.xc project file to create/update with config, plan, and progress. */
|
|
881
|
+
projectFilePath?: string;
|
|
882
|
+
/** Project-file history command label; defaults to build. */
|
|
883
|
+
projectCommand?: string;
|
|
884
|
+
/** 程序化插件入口;动态插件加载将在后续版本基于它实现。 */
|
|
885
|
+
plugins?: XCompilerPlugin[];
|
|
886
|
+
pluginStrict?: boolean;
|
|
887
|
+
/** Runtime event and interaction adapter. CLI supplies a terminal implementation; SDKs may stay silent. */
|
|
888
|
+
io?: RuntimeIO;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
interface ProjectAuditCheck {
|
|
892
|
+
name: string;
|
|
893
|
+
severity: 'error' | 'warn' | 'info';
|
|
894
|
+
ok: boolean;
|
|
895
|
+
summary: string;
|
|
896
|
+
detail?: string;
|
|
897
|
+
}
|
|
898
|
+
interface ProjectAuditResult {
|
|
899
|
+
ok: boolean;
|
|
900
|
+
warnings: number;
|
|
901
|
+
errors: number;
|
|
902
|
+
checks: ProjectAuditCheck[];
|
|
903
|
+
scope?: 'project' | 'iteration';
|
|
904
|
+
iterationId?: string;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
interface EngineResult {
|
|
908
|
+
totalSteps: number;
|
|
909
|
+
executedSteps: number;
|
|
910
|
+
failedStepId?: string;
|
|
911
|
+
/** 失败 Step 的最终详细日志(reason + tool calls + 健康度)。 */
|
|
912
|
+
failureLog?: string;
|
|
913
|
+
failureReason?: string;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
interface ExecuteOptions {
|
|
917
|
+
planPath: string;
|
|
918
|
+
workspace: string;
|
|
919
|
+
configPath?: string;
|
|
920
|
+
dryRun?: boolean;
|
|
921
|
+
fromStepId?: string;
|
|
922
|
+
onlyPhase?: string;
|
|
923
|
+
resetStatus?: boolean;
|
|
924
|
+
force?: boolean;
|
|
925
|
+
/** Optional XXX.xc project file to keep in sync with execution progress. */
|
|
926
|
+
projectFilePath?: string;
|
|
927
|
+
/** Project-file history command label; defaults to run. */
|
|
928
|
+
projectCommand?: string;
|
|
929
|
+
/** Whether to append a history row when execution starts; defaults to true. */
|
|
930
|
+
recordProjectHistory?: boolean;
|
|
931
|
+
/** @deprecated Runtime never mutates the host process. CLI adapters translate ExecuteResult to exit codes. */
|
|
932
|
+
setProcessExitCode?: boolean;
|
|
933
|
+
/** 程序化插件入口;CLI 文件加载器后续基于该入口实现。 */
|
|
934
|
+
plugins?: XCompilerPlugin[];
|
|
935
|
+
pluginStrict?: boolean;
|
|
936
|
+
/** Runtime event and interaction adapter. CLI supplies terminal rendering; SDKs may stay silent. */
|
|
937
|
+
io?: RuntimeIO;
|
|
938
|
+
/** Allow human terminal progress from lower-level engines. Defaults to true for CLI compatibility. */
|
|
939
|
+
terminalOutput?: boolean;
|
|
940
|
+
}
|
|
941
|
+
interface ExecuteResult {
|
|
942
|
+
status: 'ok' | 'failed' | 'error' | 'dry-run';
|
|
943
|
+
engine?: EngineResult;
|
|
944
|
+
audit?: ProjectAuditResult;
|
|
945
|
+
message?: string;
|
|
946
|
+
exitCode?: number;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
interface WorkspaceOptions {
|
|
950
|
+
output?: string;
|
|
951
|
+
workspace?: string;
|
|
952
|
+
baseDir?: string;
|
|
953
|
+
name?: string;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
type RuntimeBuildCommandOptions = Omit<CompileOptions, 'workspace'> & WorkspaceOptions;
|
|
957
|
+
interface RuntimeBuildCommandResult {
|
|
958
|
+
workspace: string;
|
|
959
|
+
planPath?: string;
|
|
960
|
+
}
|
|
961
|
+
type RuntimeRunCommandOptions = Omit<ExecuteOptions, 'planPath' | 'workspace' | 'projectCommand'> & {
|
|
962
|
+
planArg?: string;
|
|
963
|
+
output?: string;
|
|
964
|
+
workspace?: string;
|
|
965
|
+
cwd?: string;
|
|
966
|
+
};
|
|
967
|
+
|
|
968
|
+
interface AcpInitializeResult {
|
|
969
|
+
protocolVersion: number;
|
|
970
|
+
agentInfo: {
|
|
971
|
+
name: 'xcompiler';
|
|
972
|
+
title: string;
|
|
973
|
+
version: string;
|
|
974
|
+
};
|
|
975
|
+
agentCapabilities: {
|
|
976
|
+
loadSession: boolean;
|
|
977
|
+
promptCapabilities: {
|
|
978
|
+
image: boolean;
|
|
979
|
+
audio: boolean;
|
|
980
|
+
embeddedContext: boolean;
|
|
981
|
+
};
|
|
982
|
+
mcpCapabilities: {
|
|
983
|
+
http: boolean;
|
|
984
|
+
sse: boolean;
|
|
985
|
+
};
|
|
986
|
+
sessionCapabilities: {
|
|
987
|
+
close: Record<string, never>;
|
|
988
|
+
};
|
|
989
|
+
auth: Record<string, never>;
|
|
990
|
+
};
|
|
991
|
+
authMethods: unknown[];
|
|
992
|
+
}
|
|
993
|
+
interface AcpSession {
|
|
994
|
+
id: string;
|
|
995
|
+
workspace?: string;
|
|
996
|
+
createdAt: string;
|
|
997
|
+
tasks: Map<string, AcpTask>;
|
|
998
|
+
pendingInteractions: Map<string, PendingInteraction>;
|
|
999
|
+
pendingPermissions: Map<string, PendingPermission>;
|
|
1000
|
+
}
|
|
1001
|
+
type AcpTaskStatus = 'running' | 'waiting_for_confirmation' | 'waiting_for_permission' | 'completed' | 'failed' | 'cancel_requested' | 'cancelled';
|
|
1002
|
+
interface AcpTask {
|
|
1003
|
+
id: string;
|
|
1004
|
+
sessionId: string;
|
|
1005
|
+
status: AcpTaskStatus;
|
|
1006
|
+
workspace: string;
|
|
1007
|
+
userTask: string;
|
|
1008
|
+
protocol: 'acp' | 'legacy';
|
|
1009
|
+
phase: 'build' | 'run' | 'complete';
|
|
1010
|
+
planPath?: string;
|
|
1011
|
+
changedFiles: string[];
|
|
1012
|
+
startedAt: string;
|
|
1013
|
+
completedAt?: string;
|
|
1014
|
+
cancellationRequested?: boolean;
|
|
1015
|
+
}
|
|
1016
|
+
interface PendingInteraction {
|
|
1017
|
+
id: string;
|
|
1018
|
+
taskId: string;
|
|
1019
|
+
sessionId: string;
|
|
1020
|
+
phase: 'build' | 'run';
|
|
1021
|
+
kind: 'input' | 'confirm' | 'select' | 'editor' | 'multiline';
|
|
1022
|
+
message: string;
|
|
1023
|
+
choices?: Array<{
|
|
1024
|
+
name: string;
|
|
1025
|
+
value: string;
|
|
1026
|
+
}>;
|
|
1027
|
+
resolve: (value: unknown) => void;
|
|
1028
|
+
reject: (reason: Error) => void;
|
|
1029
|
+
}
|
|
1030
|
+
interface PendingPermission {
|
|
1031
|
+
id: string;
|
|
1032
|
+
taskId: string;
|
|
1033
|
+
sessionId: string;
|
|
1034
|
+
request: unknown;
|
|
1035
|
+
resolve: (approved: boolean, reason?: string) => void;
|
|
1036
|
+
reject: (reason: Error) => void;
|
|
1037
|
+
}
|
|
1038
|
+
interface AcpCodeTaskParams {
|
|
1039
|
+
sessionId: string;
|
|
1040
|
+
workspace: string;
|
|
1041
|
+
task: string;
|
|
1042
|
+
configPath?: string;
|
|
1043
|
+
intent?: RuntimeBuildCommandOptions['intent'];
|
|
1044
|
+
requirePlanConfirmation?: boolean;
|
|
1045
|
+
autoRunAfterBuild?: boolean;
|
|
1046
|
+
force?: boolean;
|
|
1047
|
+
}
|
|
1048
|
+
interface AcpRuntimeFacade {
|
|
1049
|
+
build(opts: RuntimeBuildCommandOptions): Promise<RuntimeBuildCommandResult>;
|
|
1050
|
+
run(opts: RuntimeRunCommandOptions): Promise<ExecuteResult>;
|
|
1051
|
+
}
|
|
1052
|
+
interface AcpServerLogger {
|
|
1053
|
+
info(message: string): void;
|
|
1054
|
+
warn(message: string): void;
|
|
1055
|
+
error(message: string): void;
|
|
1056
|
+
}
|
|
1057
|
+
interface AcpServerOptions {
|
|
1058
|
+
runtime?: AcpRuntimeFacade;
|
|
1059
|
+
logger?: AcpServerLogger;
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
declare class AcpSessionStore {
|
|
1063
|
+
private readonly sessions;
|
|
1064
|
+
create(workspace?: string): AcpSession;
|
|
1065
|
+
get(sessionId: string): AcpSession;
|
|
1066
|
+
close(sessionId: string): void;
|
|
1067
|
+
closeAll(): void;
|
|
1068
|
+
createTask(session: AcpSession, input: {
|
|
1069
|
+
workspace: string;
|
|
1070
|
+
userTask: string;
|
|
1071
|
+
protocol: 'acp' | 'legacy';
|
|
1072
|
+
}): AcpTask;
|
|
1073
|
+
getTask(sessionId: string, taskId: string): AcpTask;
|
|
1074
|
+
addInteraction(session: AcpSession, pending: PendingInteraction): void;
|
|
1075
|
+
resolveInteraction(sessionId: string, requestId: string, value: unknown): void;
|
|
1076
|
+
addPermission(session: AcpSession, pending: PendingPermission): void;
|
|
1077
|
+
resolvePermission(sessionId: string, requestId: string, approved: boolean, reason?: string): void;
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
interface AcpTransport {
|
|
1081
|
+
send(message: JsonRpcMessage): void;
|
|
1082
|
+
onMessage(handler: (message: unknown) => void | Promise<void>): void;
|
|
1083
|
+
onClose(handler: () => void | Promise<void>): void;
|
|
1084
|
+
start(): Promise<void>;
|
|
1085
|
+
close(): void;
|
|
1086
|
+
}
|
|
1087
|
+
declare class StdioTransport implements AcpTransport {
|
|
1088
|
+
private readonly input;
|
|
1089
|
+
private readonly output;
|
|
1090
|
+
private messageHandler;
|
|
1091
|
+
private closeHandler;
|
|
1092
|
+
private closed;
|
|
1093
|
+
private rl?;
|
|
1094
|
+
constructor(input?: Readable, output?: Writable);
|
|
1095
|
+
send(message: JsonRpcMessage): void;
|
|
1096
|
+
onMessage(handler: (message: unknown) => void | Promise<void>): void;
|
|
1097
|
+
onClose(handler: () => void | Promise<void>): void;
|
|
1098
|
+
start(): Promise<void>;
|
|
1099
|
+
close(): void;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
declare class AcpServer {
|
|
1103
|
+
readonly sessions: AcpSessionStore;
|
|
1104
|
+
private readonly runtime;
|
|
1105
|
+
private readonly logger;
|
|
1106
|
+
private readonly pendingClientRequests;
|
|
1107
|
+
private transport?;
|
|
1108
|
+
constructor(opts?: AcpServerOptions);
|
|
1109
|
+
start(transport: AcpTransport): Promise<void>;
|
|
1110
|
+
handleMessage(message: unknown): Promise<JsonRpcMessage | undefined>;
|
|
1111
|
+
private dispatchRequest;
|
|
1112
|
+
private dispatchNotification;
|
|
1113
|
+
private initialize;
|
|
1114
|
+
private createSession;
|
|
1115
|
+
private closeSession;
|
|
1116
|
+
private prompt;
|
|
1117
|
+
private startTask;
|
|
1118
|
+
private cancelTask;
|
|
1119
|
+
private respondConfirmation;
|
|
1120
|
+
private respondPermission;
|
|
1121
|
+
private runCodeTask;
|
|
1122
|
+
private createRuntimeIO;
|
|
1123
|
+
private createInteraction;
|
|
1124
|
+
private requestInteraction;
|
|
1125
|
+
private requestPermission;
|
|
1126
|
+
private runtimeProgress;
|
|
1127
|
+
private dispatchClientResponse;
|
|
1128
|
+
private notifyTask;
|
|
1129
|
+
private notifyUpdate;
|
|
1130
|
+
private errorResponse;
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
declare function runAcpStdioServer(): Promise<void>;
|
|
1134
|
+
|
|
1135
|
+
export { type AcpCodeTaskParams, type AcpInitializeResult, AcpMethod, type AcpRuntimeFacade, AcpServer, type AcpServerLogger, type AcpServerOptions, type AcpSession, type AcpTask, type AcpTransport, JsonRpcErrorCode, type JsonRpcFailure, type JsonRpcId, type JsonRpcMessage, type JsonRpcNotification, type JsonRpcRequest, type JsonRpcSuccess, StdioTransport, runAcpStdioServer };
|