@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.
@@ -0,0 +1,1217 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const XCOMPILER_VERSION = "0.2.2";
4
+ declare const XCOMPILER_PLUGIN_API_VERSION = 1;
5
+
6
+ /** Supported target languages for generated projects. */
7
+ declare const LANGUAGES: readonly ["python", "typescript"];
8
+ type Language = (typeof LANGUAGES)[number];
9
+ /** Plan intent: greenfield generation, incremental work, or isolated self-bootstrap. */
10
+ declare const PLAN_INTENTS: readonly ["greenfield", "feature", "refactor", "self"];
11
+ type PlanIntent = (typeof PLAN_INTENTS)[number];
12
+ declare const ROLES: readonly ["Planner", "Architect", "Coder", "Tester", "Debugger"];
13
+ type Role = (typeof ROLES)[number];
14
+ interface StepSubtask {
15
+ id: string;
16
+ title: string;
17
+ description: string;
18
+ acceptance?: string;
19
+ outputs?: string[];
20
+ subTasks?: StepSubtask[];
21
+ }
22
+ declare const StepSchema: z.ZodObject<{
23
+ id: z.ZodString;
24
+ iterationId: z.ZodDefault<z.ZodString>;
25
+ phase: z.ZodEnum<{
26
+ REQUIREMENT_ANALYSIS: "REQUIREMENT_ANALYSIS";
27
+ HIGH_LEVEL_DESIGN: "HIGH_LEVEL_DESIGN";
28
+ DETAILED_DESIGN: "DETAILED_DESIGN";
29
+ CODE: "CODE";
30
+ UNIT_TEST: "UNIT_TEST";
31
+ INTEGRATION_TEST: "INTEGRATION_TEST";
32
+ MODULE_TEST: "MODULE_TEST";
33
+ FUNCTIONAL_TEST: "FUNCTIONAL_TEST";
34
+ DEBUG: "DEBUG";
35
+ }>;
36
+ title: z.ZodString;
37
+ description: z.ZodString;
38
+ systemPrompt: z.ZodString;
39
+ role: z.ZodEnum<{
40
+ Planner: "Planner";
41
+ Architect: "Architect";
42
+ Coder: "Coder";
43
+ Tester: "Tester";
44
+ Debugger: "Debugger";
45
+ }>;
46
+ tools: z.ZodDefault<z.ZodArray<z.ZodString>>;
47
+ inputs: z.ZodDefault<z.ZodArray<z.ZodString>>;
48
+ outputs: z.ZodDefault<z.ZodArray<z.ZodString>>;
49
+ subTasks: z.ZodOptional<z.ZodArray<z.ZodType<StepSubtask, unknown, z.core.$ZodTypeInternals<StepSubtask, unknown>>>>;
50
+ dependsOn: z.ZodDefault<z.ZodArray<z.ZodString>>;
51
+ acceptance: z.ZodString;
52
+ status: z.ZodDefault<z.ZodEnum<{
53
+ PENDING: "PENDING";
54
+ RUNNING: "RUNNING";
55
+ DONE: "DONE";
56
+ FAILED: "FAILED";
57
+ SKIPPED: "SKIPPED";
58
+ }>>;
59
+ retries: z.ZodDefault<z.ZodNumber>;
60
+ maxRetries: z.ZodDefault<z.ZodNumber>;
61
+ }, z.core.$strip>;
62
+ type Step = z.infer<typeof StepSchema>;
63
+ declare const PlanSchema: z.ZodPipe<z.ZodObject<{
64
+ version: z.ZodLiteral<"1">;
65
+ language: z.ZodDefault<z.ZodEnum<{
66
+ python: "python";
67
+ typescript: "typescript";
68
+ }>>;
69
+ intent: z.ZodDefault<z.ZodEnum<{
70
+ greenfield: "greenfield";
71
+ feature: "feature";
72
+ refactor: "refactor";
73
+ self: "self";
74
+ }>>;
75
+ projectType: z.ZodDefault<z.ZodEnum<{
76
+ application: "application";
77
+ library: "library";
78
+ mixed: "mixed";
79
+ }>>;
80
+ requirementDigest: z.ZodString;
81
+ complexityAssessment: z.ZodOptional<z.ZodObject<{
82
+ level: z.ZodEnum<{
83
+ simple: "simple";
84
+ moderate: "moderate";
85
+ complex: "complex";
86
+ }>;
87
+ rationale: z.ZodString;
88
+ splitRecommended: z.ZodDefault<z.ZodBoolean>;
89
+ userForcedPhaseSplit: z.ZodDefault<z.ZodBoolean>;
90
+ }, z.core.$strip>>;
91
+ implementationPhases: z.ZodOptional<z.ZodArray<z.ZodObject<{
92
+ id: z.ZodString;
93
+ title: z.ZodString;
94
+ objective: z.ZodString;
95
+ status: z.ZodDefault<z.ZodEnum<{
96
+ current: "current";
97
+ planned: "planned";
98
+ deferred: "deferred";
99
+ }>>;
100
+ scope: z.ZodDefault<z.ZodArray<z.ZodString>>;
101
+ deliverables: z.ZodDefault<z.ZodArray<z.ZodString>>;
102
+ dependsOn: z.ZodDefault<z.ZodArray<z.ZodString>>;
103
+ verificationGate: z.ZodOptional<z.ZodObject<{
104
+ summary: z.ZodString;
105
+ checks: z.ZodArray<z.ZodString>;
106
+ failurePolicy: z.ZodString;
107
+ }, z.core.$strip>>;
108
+ }, z.core.$strip>>>;
109
+ architectureModules: z.ZodOptional<z.ZodArray<z.ZodObject<{
110
+ id: z.ZodString;
111
+ name: z.ZodString;
112
+ responsibility: z.ZodString;
113
+ sourcePaths: z.ZodArray<z.ZodString>;
114
+ testPaths: z.ZodArray<z.ZodString>;
115
+ dependencies: z.ZodDefault<z.ZodArray<z.ZodString>>;
116
+ }, z.core.$strip>>>;
117
+ globalPrompt: z.ZodDefault<z.ZodString>;
118
+ baselineSummary: z.ZodDefault<z.ZodString>;
119
+ dependencies: z.ZodOptional<z.ZodArray<z.ZodString>>;
120
+ pythonRequirements: z.ZodOptional<z.ZodArray<z.ZodString>>;
121
+ userAddenda: z.ZodDefault<z.ZodString>;
122
+ createdAt: z.ZodString;
123
+ steps: z.ZodArray<z.ZodObject<{
124
+ id: z.ZodString;
125
+ iterationId: z.ZodDefault<z.ZodString>;
126
+ phase: z.ZodEnum<{
127
+ REQUIREMENT_ANALYSIS: "REQUIREMENT_ANALYSIS";
128
+ HIGH_LEVEL_DESIGN: "HIGH_LEVEL_DESIGN";
129
+ DETAILED_DESIGN: "DETAILED_DESIGN";
130
+ CODE: "CODE";
131
+ UNIT_TEST: "UNIT_TEST";
132
+ INTEGRATION_TEST: "INTEGRATION_TEST";
133
+ MODULE_TEST: "MODULE_TEST";
134
+ FUNCTIONAL_TEST: "FUNCTIONAL_TEST";
135
+ DEBUG: "DEBUG";
136
+ }>;
137
+ title: z.ZodString;
138
+ description: z.ZodString;
139
+ systemPrompt: z.ZodString;
140
+ role: z.ZodEnum<{
141
+ Planner: "Planner";
142
+ Architect: "Architect";
143
+ Coder: "Coder";
144
+ Tester: "Tester";
145
+ Debugger: "Debugger";
146
+ }>;
147
+ tools: z.ZodDefault<z.ZodArray<z.ZodString>>;
148
+ inputs: z.ZodDefault<z.ZodArray<z.ZodString>>;
149
+ outputs: z.ZodDefault<z.ZodArray<z.ZodString>>;
150
+ subTasks: z.ZodOptional<z.ZodArray<z.ZodType<StepSubtask, unknown, z.core.$ZodTypeInternals<StepSubtask, unknown>>>>;
151
+ dependsOn: z.ZodDefault<z.ZodArray<z.ZodString>>;
152
+ acceptance: z.ZodString;
153
+ status: z.ZodDefault<z.ZodEnum<{
154
+ PENDING: "PENDING";
155
+ RUNNING: "RUNNING";
156
+ DONE: "DONE";
157
+ FAILED: "FAILED";
158
+ SKIPPED: "SKIPPED";
159
+ }>>;
160
+ retries: z.ZodDefault<z.ZodNumber>;
161
+ maxRetries: z.ZodDefault<z.ZodNumber>;
162
+ }, z.core.$strip>>;
163
+ }, z.core.$strip>, z.ZodTransform<{
164
+ dependencies: string[];
165
+ version: "1";
166
+ language: "python" | "typescript";
167
+ intent: "greenfield" | "feature" | "refactor" | "self";
168
+ projectType: "application" | "library" | "mixed";
169
+ requirementDigest: string;
170
+ globalPrompt: string;
171
+ baselineSummary: string;
172
+ userAddenda: string;
173
+ createdAt: string;
174
+ steps: {
175
+ id: string;
176
+ iterationId: string;
177
+ phase: "REQUIREMENT_ANALYSIS" | "HIGH_LEVEL_DESIGN" | "DETAILED_DESIGN" | "CODE" | "UNIT_TEST" | "INTEGRATION_TEST" | "MODULE_TEST" | "FUNCTIONAL_TEST" | "DEBUG";
178
+ title: string;
179
+ description: string;
180
+ systemPrompt: string;
181
+ role: "Planner" | "Architect" | "Coder" | "Tester" | "Debugger";
182
+ tools: string[];
183
+ inputs: string[];
184
+ outputs: string[];
185
+ dependsOn: string[];
186
+ acceptance: string;
187
+ status: "PENDING" | "RUNNING" | "DONE" | "FAILED" | "SKIPPED";
188
+ retries: number;
189
+ maxRetries: number;
190
+ subTasks?: StepSubtask[] | undefined;
191
+ }[];
192
+ complexityAssessment?: {
193
+ level: "simple" | "moderate" | "complex";
194
+ rationale: string;
195
+ splitRecommended: boolean;
196
+ userForcedPhaseSplit: boolean;
197
+ } | undefined;
198
+ implementationPhases?: {
199
+ id: string;
200
+ title: string;
201
+ objective: string;
202
+ status: "current" | "planned" | "deferred";
203
+ scope: string[];
204
+ deliverables: string[];
205
+ dependsOn: string[];
206
+ verificationGate?: {
207
+ summary: string;
208
+ checks: string[];
209
+ failurePolicy: string;
210
+ } | undefined;
211
+ }[] | undefined;
212
+ architectureModules?: {
213
+ id: string;
214
+ name: string;
215
+ responsibility: string;
216
+ sourcePaths: string[];
217
+ testPaths: string[];
218
+ dependencies: string[];
219
+ }[] | undefined;
220
+ }, {
221
+ version: "1";
222
+ language: "python" | "typescript";
223
+ intent: "greenfield" | "feature" | "refactor" | "self";
224
+ projectType: "application" | "library" | "mixed";
225
+ requirementDigest: string;
226
+ globalPrompt: string;
227
+ baselineSummary: string;
228
+ userAddenda: string;
229
+ createdAt: string;
230
+ steps: {
231
+ id: string;
232
+ iterationId: string;
233
+ phase: "REQUIREMENT_ANALYSIS" | "HIGH_LEVEL_DESIGN" | "DETAILED_DESIGN" | "CODE" | "UNIT_TEST" | "INTEGRATION_TEST" | "MODULE_TEST" | "FUNCTIONAL_TEST" | "DEBUG";
234
+ title: string;
235
+ description: string;
236
+ systemPrompt: string;
237
+ role: "Planner" | "Architect" | "Coder" | "Tester" | "Debugger";
238
+ tools: string[];
239
+ inputs: string[];
240
+ outputs: string[];
241
+ dependsOn: string[];
242
+ acceptance: string;
243
+ status: "PENDING" | "RUNNING" | "DONE" | "FAILED" | "SKIPPED";
244
+ retries: number;
245
+ maxRetries: number;
246
+ subTasks?: StepSubtask[] | undefined;
247
+ }[];
248
+ complexityAssessment?: {
249
+ level: "simple" | "moderate" | "complex";
250
+ rationale: string;
251
+ splitRecommended: boolean;
252
+ userForcedPhaseSplit: boolean;
253
+ } | undefined;
254
+ implementationPhases?: {
255
+ id: string;
256
+ title: string;
257
+ objective: string;
258
+ status: "current" | "planned" | "deferred";
259
+ scope: string[];
260
+ deliverables: string[];
261
+ dependsOn: string[];
262
+ verificationGate?: {
263
+ summary: string;
264
+ checks: string[];
265
+ failurePolicy: string;
266
+ } | undefined;
267
+ }[] | undefined;
268
+ architectureModules?: {
269
+ id: string;
270
+ name: string;
271
+ responsibility: string;
272
+ sourcePaths: string[];
273
+ testPaths: string[];
274
+ dependencies: string[];
275
+ }[] | undefined;
276
+ dependencies?: string[] | undefined;
277
+ pythonRequirements?: string[] | undefined;
278
+ }>>;
279
+ type Plan = z.infer<typeof PlanSchema>;
280
+
281
+ type ChatRole = 'system' | 'user' | 'assistant';
282
+ interface ChatMessage {
283
+ role: ChatRole;
284
+ content: string;
285
+ }
286
+ interface ChatOptions {
287
+ temperature?: number;
288
+ maxTokens?: number;
289
+ /** Force JSON-only response if provider supports it. */
290
+ responseFormat?: 'text' | 'json';
291
+ /**
292
+ * 流式 token 回调。设置后 provider 会以增量方式推送 token;
293
+ * provider 仍会聚合并返回完整文本作为最终结果。
294
+ */
295
+ onToken?: (chunk: string) => void;
296
+ /**
297
+ * 流式模式下的“可提前结束”判定。用于兼容一些 provider:
298
+ * 输出内容本身已经完整,但既不及时发送 [DONE],也不主动断开连接。
299
+ * 返回 true 后 provider 应尽快结束本次流读取并返回当前 aggregate。
300
+ */
301
+ streamStopWhen?: (text: string) => boolean;
302
+ /**
303
+ * 可选验证钩子:provider 返回后调用。抛异常会被 FallbackClient
304
+ * 视为该 provider 失败,并切换到下一个。适用于:JSON 退化、
305
+ * 空输出、model token loop 等“表面成功但语义不可用”场景。
306
+ */
307
+ validate?: (text: string) => void;
308
+ /**
309
+ * 调用者可传入回调,与 LLM 输出一同拿到实际产出该响应的 provider 名。
310
+ * 主要用于追溯:在 FallbackClient 中服务于响应的是链中某一个后选 provider,
311
+ * 调用者(如 Executor)需要在审计 / Markdown 记录中为响应打上正确的“via 哪个模型”标签。
312
+ */
313
+ onProvider?: (name: string) => void;
314
+ /**
315
+ * 每次开始尝试候选 provider 时触发。用于 CLI 在等待首个 token 前显示
316
+ * 当前 provider 与模型;fallback 切换时会再次触发。
317
+ */
318
+ onProviderStart?: (name: string, model: string) => void;
319
+ }
320
+ interface LLMClient {
321
+ readonly name: string;
322
+ chat(messages: ChatMessage[], options?: ChatOptions): Promise<string>;
323
+ }
324
+
325
+ /**
326
+ * AuditLogger 把开发流水线中的所有交互/执行动作记录到两份产物:
327
+ *
328
+ * - `docs/process_log.md` —— 人类可读的过程记录,用于交付时汇总。
329
+ * - `.xcompiler/audit.jsonl` —— 机器可读的逐行 JSON,便于后续分析与回放。
330
+ *
331
+ * 设计原则:
332
+ * - 追加写入,永不删除。
333
+ * - 失败时不影响主流程(写盘异常仅打印 warning)。
334
+ * - 每条事件都带 ts / kind / payload。
335
+ */
336
+ 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';
337
+ interface AuditLoggerOptions {
338
+ /** workspace 根目录(绝对路径) */
339
+ root: string;
340
+ /** 命令名,例如 `xcompiler_build` / `xcompiler_run` */
341
+ command: string;
342
+ /** markdown 文件相对路径,默认 docs/process_log.md */
343
+ mdRelPath?: string;
344
+ /** jsonl 文件相对路径,默认 .xcompiler/audit.jsonl */
345
+ jsonlRelPath?: string;
346
+ /** full=完整内容;redacted=保留内容但遮蔽凭据(默认);metadata=仅保留长度与摘要。 */
347
+ contentMode?: AuditContentMode;
348
+ }
349
+ type AuditContentMode = 'full' | 'redacted' | 'metadata';
350
+ declare class AuditLogger {
351
+ private readonly mdAbs;
352
+ private readonly jsonlAbs;
353
+ private readonly command;
354
+ private readonly contentMode;
355
+ private startTs;
356
+ /** 串行化 markdown 追加,防止并发 appendFile 交错。 */
357
+ private mdQueue;
358
+ constructor(opts: AuditLoggerOptions);
359
+ start(meta?: Record<string, unknown>): Promise<void>;
360
+ end(summary?: Record<string, unknown>): Promise<void>;
361
+ /** 通用事件,jsonl + 简短 markdown 一行。 */
362
+ event(kind: AuditKind, message: string, data?: Record<string, unknown>): Promise<void>;
363
+ /** 用户输入 / 决策。会把内容以引用块写入 markdown。 */
364
+ userInput(label: string, content: string): Promise<void>;
365
+ userDecision(label: string, value: string): Promise<void>;
366
+ /** LLM 请求/响应:完整 prompt 与回包写入 markdown 折叠块。 */
367
+ llmRequest(role: string, model: string, messages: unknown, options?: unknown): Promise<void>;
368
+ llmResponse(role: string, model: string, content: string, meta?: Record<string, unknown>): Promise<void>;
369
+ llmError(role: string, model: string, err: unknown): Promise<void>;
370
+ /**
371
+ * 记录一轮 Executor 思考:thoughts 文本、计划调用的 actions、是否完成。
372
+ * 写入 jsonl + markdown 折叠块,交付时可作为"AI 思考过程完整记录"。
373
+ */
374
+ executorTurn(stepId: string, role: string, round: number, payload: {
375
+ thoughts?: string;
376
+ actions?: unknown[];
377
+ done?: boolean;
378
+ raw?: string;
379
+ provider?: string;
380
+ }): Promise<void>;
381
+ /** 记录 Planner 的思考阶段,比如 clarify / decompose 原始输出。 */
382
+ plannerThought(stage: string, content: string, meta?: Record<string, unknown> & {
383
+ provider?: string;
384
+ }): Promise<void>;
385
+ private ensureFiles;
386
+ private appendMd;
387
+ private appendJsonl;
388
+ }
389
+
390
+ declare const CLARIFICATION_CATEGORIES: readonly ["functionality", "data", "acceptance", "boundary", "quality", "extensibility"];
391
+ type ClarificationCategory = (typeof CLARIFICATION_CATEGORIES)[number];
392
+ declare const CLARIFICATION_OPTION_LABELS: readonly ["A", "B", "C", "D", "E"];
393
+ type ClarificationOptionLabel = (typeof CLARIFICATION_OPTION_LABELS)[number];
394
+ interface ClarifyOption {
395
+ label: ClarificationOptionLabel;
396
+ answer: string;
397
+ }
398
+ interface ClarifyQuestion {
399
+ id: string;
400
+ category: ClarificationCategory;
401
+ question: string;
402
+ why: string;
403
+ options: ClarifyOption[];
404
+ }
405
+ interface PlannerInput {
406
+ rawRequirement: string;
407
+ clarifications: Array<{
408
+ question: string;
409
+ answer: string;
410
+ category?: ClarificationCategory;
411
+ why?: string;
412
+ options?: ClarifyOption[];
413
+ }>;
414
+ /** 用户在澄清问答后补充的自定义需求(可为空)。 */
415
+ userAddenda?: string;
416
+ /** 增量开发时,现有工程基线摘要(文档 / 计划 / 源码树)。 */
417
+ baselineContext?: string;
418
+ /** 计划意图:greenfield / feature / refactor / self。 */
419
+ intent?: PlanIntent;
420
+ }
421
+
422
+ declare class Workspace {
423
+ readonly root: string;
424
+ constructor(root: string);
425
+ abs(...p: string[]): string;
426
+ ensure(dir: string): Promise<void>;
427
+ writeFile(rel: string, content: string): Promise<void>;
428
+ readFile(rel: string): Promise<string>;
429
+ exists(rel: string): Promise<boolean>;
430
+ remove(rel: string): Promise<void>;
431
+ }
432
+
433
+ interface ExecResult {
434
+ exitCode: number;
435
+ stdout: string;
436
+ stderr: string;
437
+ timedOut: boolean;
438
+ durationMs: number;
439
+ }
440
+ interface ExecExtra {
441
+ cwd?: string;
442
+ env?: Record<string, string>;
443
+ timeoutMs?: number;
444
+ }
445
+ /** 沙盒统一接口。任意 phase / tool 都通过此接口与运行时交互。 */
446
+ interface Sandbox {
447
+ /** 实现标识,便于审计与日志区分。 */
448
+ readonly kind: 'subprocess' | 'docker';
449
+ /**
450
+ * 构建/复用环境。
451
+ * - Python:`pip install -r requirements.txt` + venv。
452
+ * - TypeScript:`npm install`(依据 package.json)。
453
+ * manifestFile 为依赖清单在 workspace 内的相对路径;不存在则跳过安装。
454
+ * 返回是否真正重建。
455
+ */
456
+ build(manifestFile?: string): Promise<{
457
+ rebuilt: boolean;
458
+ reason: string;
459
+ }>;
460
+ /** 执行任意命令;cmd 视实现可能是宿主路径或容器内路径。 */
461
+ exec(cmd: string, argv: string[], extra?: ExecExtra): Promise<ExecResult>;
462
+ /**
463
+ * 运行工程入口程序。
464
+ * - Python:`python <args>`(自动选用 venv 内解释器)。
465
+ * - TypeScript:`npx tsx <args>`。
466
+ */
467
+ runProgram(args: string[], extra?: ExecExtra): Promise<ExecResult>;
468
+ /**
469
+ * 运行测试套件。
470
+ * - Python:`python -m pytest <args>`。
471
+ * - TypeScript:`npm test`(Vitest)。
472
+ */
473
+ runTests(args?: string[], extra?: ExecExtra): Promise<ExecResult>;
474
+ /**
475
+ * 安装额外依赖(不写入依赖清单)。
476
+ * - Python:`pip install <packages>`。
477
+ * - TypeScript:`npm install <packages>`。
478
+ */
479
+ installDeps(packages: string[]): Promise<ExecResult>;
480
+ }
481
+
482
+ type ToolPermissionOperation = 'shell_command' | 'file_write' | 'file_delete' | 'install_dependency' | 'config_change' | 'git_operation' | 'network_access' | 'test_command' | 'build_command' | 'external_read' | 'external_write';
483
+ interface ToolPermissionRequest {
484
+ id?: string;
485
+ operationType: ToolPermissionOperation;
486
+ target: string;
487
+ reason: string;
488
+ risk: string;
489
+ scope: string;
490
+ skippable: boolean;
491
+ denyBehavior: string;
492
+ stepId?: string;
493
+ tool?: string;
494
+ metadata?: Record<string, unknown>;
495
+ }
496
+ interface ToolPermissionDecision {
497
+ approved: boolean;
498
+ reason?: string;
499
+ }
500
+ type ToolPermissionRequester = (request: ToolPermissionRequest) => Promise<ToolPermissionDecision>;
501
+ interface ToolExecutionEvent {
502
+ status: 'started' | 'completed';
503
+ stepId: string;
504
+ tool: string;
505
+ target?: string;
506
+ args?: Record<string, unknown>;
507
+ ok?: boolean;
508
+ summary?: string;
509
+ error?: string;
510
+ changedFiles?: string[];
511
+ patch?: string;
512
+ }
513
+ type ToolExecutionReporter = (event: ToolExecutionEvent) => void | Promise<void>;
514
+ /** 工具调用的统一上下文。 */
515
+ interface ToolContext {
516
+ ws: Workspace;
517
+ sandbox: Sandbox;
518
+ audit?: AuditLogger;
519
+ /** 当前 Step 的 outputs 白名单(写操作必须落在白名单内)。 */
520
+ allowedWrites: string[];
521
+ /** 当前 Step 的 id(仅用于审计)。 */
522
+ stepId: string;
523
+ /** 目标语言(决定依赖清单文件等)。默认 python。 */
524
+ language?: Language;
525
+ /** 当前 Step 的 write_file / append_file 单次 content 字节预算。 */
526
+ writeChunkBytes?: number;
527
+ /** Optional protocol/UI permission hook for sensitive tool operations. */
528
+ requestPermission?: ToolPermissionRequester;
529
+ /** Optional protocol/UI event hook for tool calls and file changes. */
530
+ onToolEvent?: ToolExecutionReporter;
531
+ }
532
+ /** 单次工具调用的结果统一结构。 */
533
+ interface ToolResult<T = unknown> {
534
+ ok: boolean;
535
+ data?: T;
536
+ error?: string;
537
+ /** 用于摘要展示。 */
538
+ summary?: string;
539
+ }
540
+ interface Tool<A = unknown, R = unknown> {
541
+ readonly name: string;
542
+ readonly description: string;
543
+ /** 简要 JSON Schema 描述参数(仅用于 prompt,不强校验)。 */
544
+ readonly argsSchema: Record<string, unknown>;
545
+ run(args: A, ctx: ToolContext): Promise<ToolResult<R>>;
546
+ }
547
+
548
+ /**
549
+ * Skill:把一组原子工具组合为面向 LLM 的"高阶能力"。
550
+ *
551
+ * 在 M3 阶段 Skill 是一层"语义包装"——执行器仍然按 step.tools 中的工具名调用具体 Tool,
552
+ * 但 Step 可以声明 `tools: ["skill:patcher"]`,Skill Registry 会展开为底层工具集合,
553
+ * 并把 Skill 的 `prompt` 注入 system prompt,提示 LLM 该如何组合这些工具。
554
+ */
555
+ interface Skill {
556
+ /** 形如 `patcher` / `tester` / `dep_resolver`。 */
557
+ readonly name: string;
558
+ /** 注入到 system prompt 的简短指引(中文一句话)。 */
559
+ readonly prompt: string;
560
+ /** 该 Skill 暴露给 LLM 的底层工具名集合。 */
561
+ readonly tools: string[];
562
+ }
563
+
564
+ interface EngineRunSummary {
565
+ totalSteps: number;
566
+ executedSteps: number;
567
+ failedStepId?: string;
568
+ failureLog?: string;
569
+ failureReason?: string;
570
+ }
571
+ interface StepAttemptOutcome {
572
+ ok: boolean;
573
+ failureLog: string;
574
+ reason?: string;
575
+ }
576
+ /**
577
+ * XCompiler 的公共生命周期 Hook。
578
+ *
579
+ * Context 对象会按顺序传给所有 handler;插件可以原位补充或调整字段,但不得替换
580
+ * workspace / audit 等核心服务。涉及文件写入时仍必须通过 Tool 与 EditGuard。
581
+ */
582
+ interface HookContextMap {
583
+ 'compile.start': {
584
+ workspace: string;
585
+ intent: PlanIntent;
586
+ topicMode: boolean;
587
+ };
588
+ 'compile.afterClarify': {
589
+ rawRequirement: string;
590
+ questions: ClarifyQuestion[];
591
+ clarifications: PlannerInput['clarifications'];
592
+ userAddenda: string;
593
+ };
594
+ 'compile.beforeDecompose': {
595
+ input: PlannerInput;
596
+ };
597
+ 'compile.afterPlan': {
598
+ plan: Plan;
599
+ };
600
+ 'compile.finish': {
601
+ plan: Plan;
602
+ planPath: string;
603
+ };
604
+ 'run.before': {
605
+ plan: Plan;
606
+ };
607
+ 'run.after': {
608
+ plan: Plan;
609
+ result: EngineRunSummary;
610
+ };
611
+ 'run.error': {
612
+ plan: Plan;
613
+ error: unknown;
614
+ };
615
+ 'step.before': {
616
+ plan: Plan;
617
+ step: Step;
618
+ };
619
+ 'step.after': {
620
+ plan: Plan;
621
+ step: Step;
622
+ ok: boolean;
623
+ };
624
+ 'step.error': {
625
+ plan: Plan;
626
+ step: Step;
627
+ error: unknown;
628
+ };
629
+ 'step.attempt.before': {
630
+ plan: Plan;
631
+ step: Step;
632
+ role: Role;
633
+ debug: boolean;
634
+ retry: number;
635
+ };
636
+ 'step.attempt.after': {
637
+ plan: Plan;
638
+ step: Step;
639
+ role: Role;
640
+ debug: boolean;
641
+ retry: number;
642
+ outcome: StepAttemptOutcome;
643
+ };
644
+ 'tool.before': {
645
+ stepId: string;
646
+ tool: string;
647
+ args: unknown;
648
+ context: ToolContext;
649
+ };
650
+ 'tool.after': {
651
+ stepId: string;
652
+ tool: string;
653
+ args: unknown;
654
+ context: ToolContext;
655
+ result: ToolResult;
656
+ };
657
+ 'tool.error': {
658
+ stepId: string;
659
+ tool: string;
660
+ args: unknown;
661
+ context: ToolContext;
662
+ error: unknown;
663
+ };
664
+ 'llm.before': {
665
+ role: string;
666
+ model: string;
667
+ messages: ChatMessage[];
668
+ options?: ChatOptions;
669
+ };
670
+ 'llm.after': {
671
+ role: string;
672
+ model: string;
673
+ messages: ChatMessage[];
674
+ response: string;
675
+ durationMs: number;
676
+ };
677
+ 'llm.error': {
678
+ role: string;
679
+ model: string;
680
+ messages: ChatMessage[];
681
+ error: unknown;
682
+ durationMs: number;
683
+ };
684
+ }
685
+ type HookName = keyof HookContextMap;
686
+ type HookHandler<K extends HookName> = (context: HookContextMap[K]) => void | Promise<void>;
687
+ interface HookRegistrationOptions {
688
+ /** 数值越大越先执行;相同优先级保持插件及注册顺序。 */
689
+ priority?: number;
690
+ }
691
+ interface PluginApi {
692
+ /** 当前 XCompiler 核心版本。 */
693
+ readonly xcompilerVersion: string;
694
+ /** 当前插件 API 主版本;仅同一主版本兼容。 */
695
+ readonly pluginApiVersion: number;
696
+ on<K extends HookName>(hook: K, handler: HookHandler<K>, options?: HookRegistrationOptions): () => void;
697
+ registerTool(tool: Tool): void;
698
+ registerSkill(skill: Skill): void;
699
+ }
700
+ /** 可序列化的插件清单;后续 registry / marketplace 不需要加载插件代码即可读取。 */
701
+ interface XCompilerPluginManifest {
702
+ /** 全局唯一且稳定的插件 ID,例如 `company.policy-checker`。 */
703
+ id: string;
704
+ /** 插件自身版本,必须是完整 SemVer。 */
705
+ version: string;
706
+ /** 插件编译时面向的 XCompiler Plugin API 主版本。 */
707
+ apiVersion: number;
708
+ /** 插件可运行的最低 XCompiler 核心版本;必填完整 SemVer。 */
709
+ minXCompilerVersion: string;
710
+ /** 以下字段用于插件目录展示,不参与运行时兼容判定。 */
711
+ displayName?: string;
712
+ description?: string;
713
+ license?: string;
714
+ homepage?: string;
715
+ keywords?: string[];
716
+ }
717
+ type PluginCompatibilityCode = 'compatible' | 'invalid-runtime-version' | 'invalid-id' | 'invalid-plugin-version' | 'invalid-min-xcompiler-version' | 'api-version-mismatch' | 'xcompiler-version-too-old';
718
+ interface PluginCompatibilityReport {
719
+ compatible: boolean;
720
+ code: PluginCompatibilityCode;
721
+ pluginId: string;
722
+ pluginVersion: string;
723
+ xcompilerVersion: string;
724
+ pluginApiVersion: number;
725
+ message?: string;
726
+ }
727
+ interface XCompilerPlugin {
728
+ manifest: XCompilerPluginManifest;
729
+ /** 默认 continue:记录错误但不拖垮核心流程。 */
730
+ failureMode?: 'continue' | 'fail';
731
+ setup(api: PluginApi): void | Promise<void>;
732
+ }
733
+ interface PluginHostOptions {
734
+ plugins?: XCompilerPlugin[];
735
+ /** 强制所有插件错误中断主流程,适合 CI / 合规插件。 */
736
+ strict?: boolean;
737
+ audit?: AuditLogger;
738
+ /** 嵌入式宿主可显式传入版本;一般应使用内置默认值。 */
739
+ xcompilerVersion?: string;
740
+ pluginApiVersion?: number;
741
+ }
742
+ interface PluginExtensionTarget {
743
+ tools: {
744
+ get(name: string): Tool | undefined;
745
+ register(tool: Tool): void;
746
+ };
747
+ skills: {
748
+ get(name: string): Skill | undefined;
749
+ register(skill: Skill): void;
750
+ };
751
+ }
752
+
753
+ type RuntimeLogLevel = 'success' | 'warning' | 'error' | 'info' | 'dim' | 'accent' | 'raw';
754
+
755
+ interface RuntimeLogEvent {
756
+ type: 'log';
757
+ level: RuntimeLogLevel;
758
+ message: string;
759
+ }
760
+ interface RuntimeResultEvent {
761
+ type: 'result';
762
+ command: 'build' | 'run';
763
+ status: string;
764
+ data?: Record<string, unknown>;
765
+ }
766
+ interface RuntimeProgressEvent {
767
+ type: 'progress';
768
+ status: 'start' | 'succeed' | 'fail';
769
+ message: string;
770
+ }
771
+ interface RuntimeToolCallEvent {
772
+ type: 'tool_call';
773
+ status: ToolExecutionEvent['status'];
774
+ stepId: string;
775
+ tool: string;
776
+ target?: string;
777
+ ok?: boolean;
778
+ summary?: string;
779
+ error?: string;
780
+ }
781
+ interface RuntimeFileChangedEvent {
782
+ type: 'file_changed';
783
+ stepId: string;
784
+ tool: string;
785
+ path: string;
786
+ }
787
+ interface RuntimePatchProposedEvent {
788
+ type: 'patch_proposed';
789
+ stepId: string;
790
+ tool: string;
791
+ patch: string;
792
+ }
793
+ interface RuntimePermissionEvent {
794
+ type: 'permission';
795
+ status: 'requested' | 'approved' | 'denied';
796
+ request: ToolPermissionRequest;
797
+ }
798
+ type RuntimeEvent = RuntimeLogEvent | RuntimeProgressEvent | RuntimeResultEvent | RuntimeToolCallEvent | RuntimeFileChangedEvent | RuntimePatchProposedEvent | RuntimePermissionEvent;
799
+ interface RuntimeProgress {
800
+ succeed(message: string): void | Promise<void>;
801
+ fail(message: string): void | Promise<void>;
802
+ stop?(): void | Promise<void>;
803
+ }
804
+ interface RuntimeSelectChoice<T extends string = string> {
805
+ name: string;
806
+ value: T;
807
+ }
808
+ interface RuntimeInteraction {
809
+ input(args: {
810
+ message: string;
811
+ }): Promise<string>;
812
+ confirm(args: {
813
+ message: string;
814
+ default?: boolean;
815
+ }): Promise<boolean>;
816
+ editor(args: {
817
+ message: string;
818
+ default?: string;
819
+ postfix?: string;
820
+ }): Promise<string>;
821
+ select<T extends string>(args: {
822
+ message: string;
823
+ choices: RuntimeSelectChoice<T>[];
824
+ }): Promise<T>;
825
+ readMultiline(args: {
826
+ message: string;
827
+ }): Promise<string>;
828
+ pauseStdin?(): void;
829
+ }
830
+ interface RuntimeIO {
831
+ emit(event: RuntimeEvent): void | Promise<void>;
832
+ progress(message: string, opts?: {
833
+ animate?: boolean;
834
+ }): RuntimeProgress;
835
+ interaction?: RuntimeInteraction;
836
+ requestPermission?: ToolPermissionRequester;
837
+ }
838
+ declare const silentRuntimeIO: RuntimeIO;
839
+
840
+ interface CompileOptions {
841
+ workspace: string;
842
+ configPath?: string;
843
+ inputFile?: string;
844
+ /**
845
+ * 已澄清的 topic.md 直接输入:跳过 intake / clarify / Addenda / Gate 1,把该文件
846
+ * 内容当作冻结后的项目选题书,直接进入 decompose。常用于:
847
+ * - 用户上次已澄清并保留了 topic.md,重新跑 decompose 不想再问一遍
848
+ * - 离线编辑了 topic.md 想直接拿来出 plan.json
849
+ * 与 --input 互斥;同时给则 --topic 优先并打印警告。
850
+ */
851
+ topicFile?: string;
852
+ outputFile?: string;
853
+ intent?: PlanIntent;
854
+ baselinePlanFile?: string;
855
+ yes?: boolean;
856
+ force?: boolean;
857
+ /** Optional XXX.xc project file to create/update with config, plan, and progress. */
858
+ projectFilePath?: string;
859
+ /** Project-file history command label; defaults to build. */
860
+ projectCommand?: string;
861
+ /** 程序化插件入口;动态插件加载将在后续版本基于它实现。 */
862
+ plugins?: XCompilerPlugin[];
863
+ pluginStrict?: boolean;
864
+ /** Runtime event and interaction adapter. CLI supplies a terminal implementation; SDKs may stay silent. */
865
+ io?: RuntimeIO;
866
+ }
867
+ /** CLI 可映射为退出码、程序化调用方可捕获并安全收尾的编译终止。 */
868
+ declare class CompileExitError extends Error {
869
+ readonly exitCode: number;
870
+ constructor(exitCode: number, message: string);
871
+ }
872
+ declare function runCompile(opts: CompileOptions): Promise<{
873
+ planPath?: string;
874
+ }>;
875
+
876
+ /**
877
+ * 每个 LLM provider 的运行时评分(默认 1.0)。
878
+ *
879
+ * 设计动机:
880
+ * - 配置允许给一个角色挂多个 provider;运行时按评分降序选择当前"最可信"的。
881
+ * - 评分会随成功/失败动态调整:失败 -0.5 直到 0(=禁用);成功 +0.1 直到 cap=10。
882
+ * - preflight 检测到 ollama 服务器上**模型不存在**会直接把评分置 0。
883
+ * - 持久化到 config 同目录的 sidecar 文件 `llm_scores.yaml`,避免改写用户的 config.yaml
884
+ * (会丢注释)。配置里 `llm.scores` 段作为 sidecar 缺失时的初值。
885
+ */
886
+ declare class ScoreStore {
887
+ private readonly audit?;
888
+ static readonly DEFAULT = 1;
889
+ static readonly MIN = 0;
890
+ static readonly MAX = 10;
891
+ static readonly DECAY = 0.5;
892
+ static readonly BOOST = 0.1;
893
+ private readonly scores;
894
+ private dirty;
895
+ private writeQueue;
896
+ private readonly sidecarPath;
897
+ constructor(configPath: string, initial?: Record<string, number>, audit?: AuditLogger | undefined);
898
+ /** 异步加载 sidecar 文件;失败/不存在不抛错,使用 ctor 提供的初值。 */
899
+ load(): Promise<void>;
900
+ get(name: string): number;
901
+ /** 主动设置评分(如 preflight 把不存在的模型置 0)。 */
902
+ set(name: string, value: number, reason?: string): void;
903
+ decay(name: string, reason: string): void;
904
+ boost(name: string, reason: string): void;
905
+ /** 全量快照(用于测试与 audit 输出)。 */
906
+ snapshot(): Record<string, number>;
907
+ /** 等待待写入完成(CLI 退出前调用,确保评分已落盘)。 */
908
+ flush(): Promise<void>;
909
+ private scheduleSave;
910
+ private persist;
911
+ }
912
+
913
+ /** 插件注册、扩展能力合并与生命周期 Hook 调度中心。 */
914
+ declare class PluginHost {
915
+ private readonly plugins;
916
+ private readonly strict;
917
+ private readonly xcompilerVersion;
918
+ private readonly pluginApiVersion;
919
+ private readonly hooks;
920
+ private readonly contributedTools;
921
+ private readonly contributedSkills;
922
+ private audit?;
923
+ private initialized;
924
+ private registrationOrder;
925
+ constructor(options?: PluginHostOptions);
926
+ get size(): number;
927
+ /** 返回只读清单快照,供诊断、插件目录和未来 registry 使用。 */
928
+ get manifests(): readonly XCompilerPluginManifest[];
929
+ setAudit(audit: AuditLogger): void;
930
+ initialize(): Promise<void>;
931
+ /** 把插件贡献的 Tool / Skill 合并到 Engine 的默认注册表;禁止静默覆盖核心能力。 */
932
+ applyExtensions(target: PluginExtensionTarget): void;
933
+ emit<K extends HookName>(hook: K, context: HookContextMap[K]): Promise<void>;
934
+ /** 在不绕过原 Tool / EditGuard 的前提下增加 before / after / error Hook。 */
935
+ wrapTool<A, R>(tool: Tool<A, R>): Tool<A, R>;
936
+ /** 包装完整 LLM 调用;response 可由 after Hook 做结构化后处理。 */
937
+ wrapLLM(client: LLMClient, role: string): LLMClient;
938
+ private createApi;
939
+ private handleFailure;
940
+ }
941
+
942
+ interface ProjectAuditCheck {
943
+ name: string;
944
+ severity: 'error' | 'warn' | 'info';
945
+ ok: boolean;
946
+ summary: string;
947
+ detail?: string;
948
+ }
949
+ interface ProjectAuditResult {
950
+ ok: boolean;
951
+ warnings: number;
952
+ errors: number;
953
+ checks: ProjectAuditCheck[];
954
+ scope?: 'project' | 'iteration';
955
+ iterationId?: string;
956
+ }
957
+
958
+ interface EngineResult {
959
+ totalSteps: number;
960
+ executedSteps: number;
961
+ failedStepId?: string;
962
+ /** 失败 Step 的最终详细日志(reason + tool calls + 健康度)。 */
963
+ failureLog?: string;
964
+ failureReason?: string;
965
+ }
966
+
967
+ interface ExecuteOptions {
968
+ planPath: string;
969
+ workspace: string;
970
+ configPath?: string;
971
+ dryRun?: boolean;
972
+ fromStepId?: string;
973
+ onlyPhase?: string;
974
+ resetStatus?: boolean;
975
+ force?: boolean;
976
+ /** Optional XXX.xc project file to keep in sync with execution progress. */
977
+ projectFilePath?: string;
978
+ /** Project-file history command label; defaults to run. */
979
+ projectCommand?: string;
980
+ /** Whether to append a history row when execution starts; defaults to true. */
981
+ recordProjectHistory?: boolean;
982
+ /** @deprecated Runtime never mutates the host process. CLI adapters translate ExecuteResult to exit codes. */
983
+ setProcessExitCode?: boolean;
984
+ /** 程序化插件入口;CLI 文件加载器后续基于该入口实现。 */
985
+ plugins?: XCompilerPlugin[];
986
+ pluginStrict?: boolean;
987
+ /** Runtime event and interaction adapter. CLI supplies terminal rendering; SDKs may stay silent. */
988
+ io?: RuntimeIO;
989
+ /** Allow human terminal progress from lower-level engines. Defaults to true for CLI compatibility. */
990
+ terminalOutput?: boolean;
991
+ }
992
+ interface ExecuteResult {
993
+ status: 'ok' | 'failed' | 'error' | 'dry-run';
994
+ engine?: EngineResult;
995
+ audit?: ProjectAuditResult;
996
+ message?: string;
997
+ exitCode?: number;
998
+ }
999
+ declare function runExecute(opts: ExecuteOptions): Promise<ExecuteResult>;
1000
+
1001
+ interface WorkspaceOptions {
1002
+ output?: string;
1003
+ workspace?: string;
1004
+ baseDir?: string;
1005
+ name?: string;
1006
+ }
1007
+ declare function defaultProjectName(now?: Date): string;
1008
+ declare function resolveCompileWorkspace(opts: WorkspaceOptions): Promise<string>;
1009
+ declare function resolveEvolveWorkspace(opts: WorkspaceOptions, cwd?: string): Promise<string>;
1010
+
1011
+ type RuntimeBuildCommandOptions = Omit<CompileOptions, 'workspace'> & WorkspaceOptions;
1012
+ interface RuntimeBuildCommandResult {
1013
+ workspace: string;
1014
+ planPath?: string;
1015
+ }
1016
+ declare function runBuildCommand(opts: RuntimeBuildCommandOptions): Promise<RuntimeBuildCommandResult>;
1017
+ type RuntimeEvolveCommandOptions = Omit<CompileOptions, 'workspace' | 'outputFile' | 'projectCommand'> & WorkspaceOptions & {
1018
+ planOut?: string;
1019
+ cwd?: string;
1020
+ };
1021
+ interface RuntimeEvolveCommandResult {
1022
+ workspace: string;
1023
+ planPath?: string;
1024
+ execution?: ExecuteResult;
1025
+ }
1026
+ declare function runEvolveCommand(opts: RuntimeEvolveCommandOptions): Promise<RuntimeEvolveCommandResult>;
1027
+ type RuntimeRunCommandOptions = Omit<ExecuteOptions, 'planPath' | 'workspace' | 'projectCommand'> & {
1028
+ planArg?: string;
1029
+ output?: string;
1030
+ workspace?: string;
1031
+ cwd?: string;
1032
+ };
1033
+ declare function runRunCommand(opts: RuntimeRunCommandOptions): Promise<ExecuteResult>;
1034
+ type RuntimeLoadCommandOptions = Omit<ExecuteOptions, 'planPath' | 'workspace' | 'projectFilePath' | 'projectCommand'> & {
1035
+ projectFile: string;
1036
+ };
1037
+ declare function runLoadCommand(opts: RuntimeLoadCommandOptions): Promise<ExecuteResult>;
1038
+ type RuntimeAppendCommandOptions = Omit<CompileOptions, 'workspace' | 'baselinePlanFile' | 'outputFile' | 'projectFilePath' | 'projectCommand'> & {
1039
+ projectFile: string;
1040
+ planOut?: string;
1041
+ };
1042
+ interface RuntimeAppendCommandResult {
1043
+ workspace: string;
1044
+ planPath?: string;
1045
+ execution?: ExecuteResult;
1046
+ }
1047
+ declare function runAppendCommand(opts: RuntimeAppendCommandOptions): Promise<RuntimeAppendCommandResult>;
1048
+
1049
+ interface BootstrapOptions {
1050
+ repository?: string;
1051
+ configPath?: string;
1052
+ inputFile?: string;
1053
+ topicFile?: string;
1054
+ yes?: boolean;
1055
+ force?: boolean;
1056
+ promote?: boolean;
1057
+ cleanup?: boolean;
1058
+ worktree?: string;
1059
+ /** Opt into the experimental Docker qualification runner. */
1060
+ dockerQualification?: boolean;
1061
+ io?: RuntimeIO;
1062
+ }
1063
+ interface BootstrapCheck {
1064
+ name: string;
1065
+ command: string;
1066
+ required: boolean;
1067
+ ok: boolean;
1068
+ exitCode: number;
1069
+ durationMs: number;
1070
+ detail: string;
1071
+ }
1072
+ interface BootstrapWorkspace {
1073
+ repository: string;
1074
+ worktree: string;
1075
+ branch: string;
1076
+ baseCommit: string;
1077
+ runId: string;
1078
+ }
1079
+ interface BootstrapResult extends BootstrapWorkspace {
1080
+ status: 'cancelled' | 'compile-failed' | 'execution-failed' | 'qualification-failed' | 'qualified' | 'promoted';
1081
+ candidateCommit?: string;
1082
+ reportPath: string;
1083
+ checks: BootstrapCheck[];
1084
+ changedFiles: string[];
1085
+ }
1086
+ /**
1087
+ * Generation-based self-bootstrap: the loaded XCompiler process (N) edits a linked worktree
1088
+ * containing candidate N+1. The host checkout is never used as the execution workspace.
1089
+ */
1090
+ declare function runBootstrap(opts: BootstrapOptions): Promise<BootstrapResult>;
1091
+
1092
+ type CheckLevel = 'ok' | 'warn' | 'fail';
1093
+ interface CheckItem {
1094
+ level: CheckLevel;
1095
+ message: string;
1096
+ }
1097
+ interface CheckSection {
1098
+ title: string;
1099
+ items: CheckItem[];
1100
+ }
1101
+ interface DoctorReport {
1102
+ sections: CheckSection[];
1103
+ fails: number;
1104
+ warns: number;
1105
+ }
1106
+ interface DoctorOptions {
1107
+ configPath?: string;
1108
+ /** Probe timeout for LLM endpoints (ms). Default 3000. */
1109
+ probeTimeoutMs?: number;
1110
+ /** Skip outbound network probes (used by tests). */
1111
+ skipNetwork?: boolean;
1112
+ /** Override score lookup (defaults to config.llm.scores). */
1113
+ scoreStore?: ScoreStore;
1114
+ }
1115
+ /**
1116
+ * Run the full environment check. Always returns a report — does not throw.
1117
+ * Fatal config-load errors are recorded as a single fail item under [config].
1118
+ */
1119
+ declare function runDoctor(opts?: DoctorOptions): Promise<DoctorReport>;
1120
+
1121
+ interface RuntimeDoctorOptions extends DoctorOptions {
1122
+ /** Exit non-zero on warnings as well as failures. */
1123
+ strict?: boolean;
1124
+ }
1125
+ interface RuntimeDoctorResult {
1126
+ report: DoctorReport;
1127
+ exitCode: number;
1128
+ }
1129
+ declare function runDoctorCommand(opts?: RuntimeDoctorOptions): Promise<RuntimeDoctorResult>;
1130
+
1131
+ interface LsOptions {
1132
+ workspace: string;
1133
+ /** Maximum depth for recursively finding plan.json files. Defaults to 4. */
1134
+ maxDepth?: number;
1135
+ }
1136
+ interface PlanSummary {
1137
+ total: number;
1138
+ done: number;
1139
+ failed: number;
1140
+ pending: number;
1141
+ running: number;
1142
+ skipped: number;
1143
+ }
1144
+ interface LsPlanEntry {
1145
+ path: string;
1146
+ relativePath: string;
1147
+ language?: string;
1148
+ summary?: PlanSummary;
1149
+ requirementDigestLine?: string;
1150
+ error?: string;
1151
+ }
1152
+ interface LsResult {
1153
+ root: string;
1154
+ plans: LsPlanEntry[];
1155
+ }
1156
+ declare function runLsCommand(opts: LsOptions): Promise<LsResult>;
1157
+ interface ShowOptions {
1158
+ workspace: string;
1159
+ stepId: string;
1160
+ planPath?: string;
1161
+ /** Number of recent matching audit jsonl events. Defaults to 10. */
1162
+ auditTail?: number;
1163
+ }
1164
+ interface ShowOutputStatus {
1165
+ path: string;
1166
+ exists: boolean;
1167
+ }
1168
+ interface AuditLine {
1169
+ ts: string;
1170
+ kind: string;
1171
+ msg?: string;
1172
+ }
1173
+ interface ShowResult {
1174
+ root: string;
1175
+ planPath: string;
1176
+ stepId: string;
1177
+ step?: Step;
1178
+ outputs: ShowOutputStatus[];
1179
+ auditEvents: AuditLine[];
1180
+ exitCode: number;
1181
+ }
1182
+ declare function runShowCommand(opts: ShowOptions): Promise<ShowResult>;
1183
+ declare function summarizePlan(plan: Plan): PlanSummary;
1184
+ declare function findPlans(root: string, maxDepth: number): Promise<string[]>;
1185
+ declare function readAuditFor(file: string, stepId: string, tail: number): Promise<AuditLine[]>;
1186
+ type InspectStep = Step;
1187
+
1188
+ interface PluginRuntimeVersion {
1189
+ xcompilerVersion?: string;
1190
+ pluginApiVersion?: number;
1191
+ }
1192
+ /** 在加载插件代码前可独立调用的 manifest 兼容性检查。 */
1193
+ declare function checkPluginCompatibility(manifest: XCompilerPluginManifest, runtime?: PluginRuntimeVersion): PluginCompatibilityReport;
1194
+
1195
+ /** 无 Commander 副作用的程序化运行入口,供宿主应用和插件加载器使用。 */
1196
+
1197
+ interface XCompilerRuntimeOptions {
1198
+ io?: RuntimeIO;
1199
+ }
1200
+ declare class XCompilerRuntime {
1201
+ private readonly defaults;
1202
+ constructor(defaults?: XCompilerRuntimeOptions);
1203
+ build(opts: CompileOptions): ReturnType<typeof runCompile>;
1204
+ run(opts: ExecuteOptions): ReturnType<typeof runExecute>;
1205
+ buildCommand(opts: RuntimeBuildCommandOptions): ReturnType<typeof runBuildCommand>;
1206
+ evolveCommand(opts: RuntimeEvolveCommandOptions): ReturnType<typeof runEvolveCommand>;
1207
+ runCommand(opts: RuntimeRunCommandOptions): ReturnType<typeof runRunCommand>;
1208
+ loadCommand(opts: RuntimeLoadCommandOptions): ReturnType<typeof runLoadCommand>;
1209
+ appendCommand(opts: RuntimeAppendCommandOptions): ReturnType<typeof runAppendCommand>;
1210
+ bootstrap(opts: BootstrapOptions): ReturnType<typeof runBootstrap>;
1211
+ doctor(opts?: RuntimeDoctorOptions): ReturnType<typeof runDoctorCommand>;
1212
+ ls(opts: LsOptions): ReturnType<typeof runLsCommand>;
1213
+ show(opts: ShowOptions): ReturnType<typeof runShowCommand>;
1214
+ private withDefaults;
1215
+ }
1216
+
1217
+ export { type AuditLine, type BootstrapOptions, type BootstrapResult, type CheckLevel, CompileExitError, type CompileOptions, type DoctorOptions, type DoctorReport, type ExecuteOptions, type ExecuteResult, type InspectStep, type LsOptions, type LsPlanEntry, type LsResult, type PlanSummary, type PluginCompatibilityReport, PluginHost, type PluginHostOptions, type RuntimeAppendCommandOptions, type RuntimeAppendCommandResult, type RuntimeBuildCommandOptions, type RuntimeBuildCommandResult, type RuntimeDoctorOptions, type RuntimeDoctorResult, type RuntimeEvent, type RuntimeEvolveCommandOptions, type RuntimeEvolveCommandResult, type RuntimeFileChangedEvent, type RuntimeIO, type RuntimeInteraction, type RuntimeLoadCommandOptions, type RuntimeLogEvent, type RuntimeLogLevel, type RuntimePatchProposedEvent, type RuntimePermissionEvent, type RuntimeProgress, type RuntimeProgressEvent, type RuntimeResultEvent, type RuntimeRunCommandOptions, type RuntimeSelectChoice, type RuntimeToolCallEvent, type ShowOptions, type ShowOutputStatus, type ShowResult, type ToolExecutionEvent, type ToolExecutionReporter, type ToolPermissionDecision, type ToolPermissionOperation, type ToolPermissionRequest, type ToolPermissionRequester, type WorkspaceOptions, XCOMPILER_PLUGIN_API_VERSION, XCOMPILER_VERSION, type XCompilerPlugin, type XCompilerPluginManifest, XCompilerRuntime, type XCompilerRuntimeOptions, checkPluginCompatibility, defaultProjectName, findPlans, readAuditFor, resolveCompileWorkspace, resolveEvolveWorkspace, runAppendCommand, runBootstrap, runBuildCommand, runCompile, runDoctor, runDoctorCommand, runEvolveCommand, runExecute, runLoadCommand, runLsCommand, runRunCommand, runShowCommand, silentRuntimeIO, summarizePlan };