@kevlns/v-cli 0.2.18 → 0.3.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/dist/sdk.d.ts ADDED
@@ -0,0 +1,1172 @@
1
+ /**
2
+ * 工程根锚定与路径安全。
3
+ *
4
+ * 规则(全部 fail-closed,测试覆盖):
5
+ * - 工程根由显式 --project(或默认 cwd)解析;必须存在且是目录,随后取 realpath 作为锚。
6
+ * - 业务相对路径拒绝:绝对路径(含盘符、UNC、/ 与 \ 开头)、空段、"." 与 ".."、
7
+ * NUL;解析结果必须落在工程根内。
8
+ * - 符号链接/联接(junction)越界拒绝:对"最深的已存在祖先"取 realpath 再核对包含关系;
9
+ * 目标本身是符号链接时同样拒绝(不跟随、不写入链接目标)。
10
+ */
11
+ interface ProjectRoot {
12
+ /** 解析后的绝对路径(保留调用方书写形式) */
13
+ root: string;
14
+ /** 工程根 realpath(包含关系判定的基准) */
15
+ realRoot: string;
16
+ }
17
+ declare class PathSafetyError extends Error {
18
+ readonly code: string;
19
+ constructor(code: string, message: string);
20
+ }
21
+ /** 解析并锚定工程根;不存在/不是目录时抛出 */
22
+ declare function resolveProjectRoot(input?: string, cwd?: string): ProjectRoot;
23
+ /** 拆分相对路径为段;非法即抛 */
24
+ declare function splitSafeRelative(relative: string, label: string): string[];
25
+ /**
26
+ * 把相对路径解析到工程根内;任何越界(绝对路径/../符号链接逃逸)都拒绝。
27
+ * 返回绝对路径与(若存在)realpath。绑定路径允许 "." 表示工程根本身。
28
+ */
29
+ declare function resolveInsideProject(project: ProjectRoot, relative: string, label: string): {
30
+ path: string;
31
+ realPath: string | null;
32
+ };
33
+
34
+ /**
35
+ * 工程级 v-cli 配置:.vant/config/v-cli.json —— 通用配置外壳。
36
+ *
37
+ * 职责分离(硬边界,测试覆盖):
38
+ * - 核心只定义外壳:schemaVersion + bindings(按 Provider ID 分组)。
39
+ * 每个绑定段的结构、字段、路径由对应 Provider 的绑定契约自包含声明与校验
40
+ * (见 core/execution/types.ts 的 ProviderBindingContract);核心对路径字段做
41
+ * 重解析强核对(不信任 Provider 返回的路径字符串)。
42
+ * - 角色 / workflow / 项目组织属于 Vant 的 .vant/config/project.json,v-cli 既不读也不写;
43
+ * 配置里出现这类字段会被明确拒绝(单一真源,不做双份配置)。
44
+ * - 失败语义:绑定段缺失的 Provider 不阻断其他 Provider(运行期由前置条件失败);
45
+ * 已声明但无效的绑定(未知 Provider / schema 不符 / 路径越界 / 强核对不一致)
46
+ * 使整个配置 fail-closed。
47
+ * - 无配置文件时不猜测:报错并给出 `v-cli project init` 初始化指引。
48
+ * - project init 幂等补全:已有段只增不改;--reset 显式重置(先备份到 .vant/state/config-backups/);
49
+ * 也绝不改动任何 Vant 配置文件。
50
+ */
51
+
52
+ declare const PROJECT_CLI_CONFIG_RELATIVE = ".vant/config/v-cli.json";
53
+ /** Vant 组织层配置:v-cli 只做只读提示,永不写入 */
54
+ declare const VANT_PROJECT_CONFIG_RELATIVE = ".vant/config/project.json";
55
+ declare const OPERATIONS_RELATIVE = ".vant/state/operations";
56
+ /** 通用配置外壳:绑定段内容由 Provider 契约定义 */
57
+ interface ProjectCliConfig {
58
+ schemaVersion: 1;
59
+ /** Provider ID -> 绑定段(结构由该 Provider 的 binding.schema 定义) */
60
+ bindings: Record<string, unknown>;
61
+ }
62
+ /** 外壳校验(不含 Provider 字段语义):结构、Vant 职责键、危险键 */
63
+ declare function validateProjectCliConfig(raw: unknown): string[];
64
+ /** 已注册 Provider 集合(绑定校验的输入;Map<providerId, provider>) */
65
+ type ProviderSet = Map<string, CapabilityProvider>;
66
+ declare function toProviderSet(providers: Iterable<CapabilityProvider>): ProviderSet;
67
+ interface ResolvedProviderBinding {
68
+ providerId: string;
69
+ /** Provider 语义归一后的绑定段(缺省为原始段) */
70
+ section: Record<string, unknown>;
71
+ dirs: Record<string, string>;
72
+ files: Record<string, string>;
73
+ warnings: string[];
74
+ }
75
+ /**
76
+ * 解析并强核对全部绑定段(核心安全闸门):
77
+ * - 未知 Provider 的绑定段 → 错误(fail-closed);
78
+ * - Provider.resolve 抛错/返回错误/返回畸形 → 错误;
79
+ * - 路径字段强核对:核心从 raw[field] 自行 resolveInsideProject 重解析,
80
+ * 与 resolve 返回的 dirs/files 逐一字符串比对(基准 .path);resolve 夹带
81
+ * 未声明的 dirs/files 键、或声明字段缺解析结果 → 错误;
82
+ * - 非 required 路径字段缺失为合法(不得出现在 dirs/files);
83
+ * - 路径违规不抛出中断:记入错误列表并置 pathUnsafe=true(保留其余已发现错误)。
84
+ */
85
+ declare function resolveBindings(project: ProjectRoot, config: ProjectCliConfig, providers: ProviderSet): {
86
+ ok: true;
87
+ bindings: Record<string, ResolvedProviderBinding>;
88
+ } | {
89
+ ok: false;
90
+ errors: string[];
91
+ pathUnsafe: boolean;
92
+ };
93
+ type LoadProjectConfigResult = {
94
+ ok: true;
95
+ file: string;
96
+ config: ProjectCliConfig;
97
+ /** Provider ID -> 已解析绑定(含安全路径与语义段) */
98
+ resolved: Record<string, ResolvedProviderBinding>;
99
+ /** 已注册但配置未声明绑定的 Provider id */
100
+ unbound: string[];
101
+ } | {
102
+ ok: false;
103
+ file: string;
104
+ kind: "missing" | "invalid" | "unsafe-binding";
105
+ errors: string[];
106
+ hint: string;
107
+ };
108
+ /** 读取并校验工程级 v-cli 配置(外壳 + 各 Provider 绑定契约 + 路径强核对) */
109
+ declare function loadProjectConfig(project: ProjectRoot, providers: ProviderSet): LoadProjectConfigResult;
110
+ interface RenderedConfig {
111
+ content: string;
112
+ bytes: number;
113
+ sha256: string;
114
+ }
115
+ /** 生成配置内容(确定性):外壳 + 各 Provider 默认段(overrides 为完整段替换) */
116
+ declare function renderProjectConfig(project: ProjectRoot, providers: Iterable<CapabilityProvider>, overrides?: Record<string, Record<string, unknown>>): RenderedConfig & {
117
+ warnings: string[];
118
+ bindings: Record<string, unknown>;
119
+ };
120
+ type InitAction = "created" | "reconciled" | "unchanged" | "reset" | "refused";
121
+ type InitProjectConfigResult = {
122
+ ok: true;
123
+ action: Exclude<InitAction, "refused">;
124
+ /** true = 仅报告将要做的变更,未写任何文件 */
125
+ dryRun: boolean;
126
+ /** 本次新增的 provider 段 id(reconciled 路径;created/reset 为全部生成段) */
127
+ added: string[];
128
+ file: string;
129
+ relativeFile: string;
130
+ bytes: number;
131
+ sha256: string;
132
+ projectRoot: string;
133
+ /** 结果文件中的绑定段(provider id -> section) */
134
+ bindings: Record<string, unknown>;
135
+ /** --reset 时旧配置的备份路径(.vant/state 内,不入 Git;dry-run 不产生) */
136
+ backupPath?: string;
137
+ /** 执行前配置文件是否已存在(文本输出区分 reset/等价创建) */
138
+ existed: boolean;
139
+ /** 只读提示:检测到的 Vant 配置文件(v-cli 不修改) */
140
+ vantConfig: {
141
+ file: string;
142
+ exists: boolean;
143
+ };
144
+ warnings: string[];
145
+ } | {
146
+ ok: false;
147
+ action: "refused";
148
+ file: string;
149
+ relativeFile: string;
150
+ projectRoot: string;
151
+ reason: string;
152
+ vantConfig: {
153
+ file: string;
154
+ exists: boolean;
155
+ };
156
+ };
157
+ /**
158
+ * 初始化/幂等补全 .vant/config/v-cli.json(不触碰 .vant/config/project.json):
159
+ *
160
+ * - 配置不存在 → 创建(有 defaultBinding 的 Provider 生成默认段,--binding 完整覆盖该段)。
161
+ * - 配置已存在(默认路径)→ **幂等补全**:只为"缺失绑定段且 Provider 有 defaultBinding"的
162
+ * Provider 补默认段;已有段的键、值与键序不动(文件整体按规范 2 空格格式重排——
163
+ * v-cli 自产的 canonical 文件补全后逐字节稳定,手编的非规范格式会被规范化)。全段齐备 → unchanged。
164
+ * - `reset: true` → **显式重置**:先把旧配置字节原样备份到 .vant/state/config-backups/,
165
+ * 再按默认段(+ --binding 覆盖)原子替换。绝不在默认路径删除任何内容。
166
+ * - `dryRun: true` → 只报告将要做的变更(added / action),不写任何文件。
167
+ *
168
+ * 所有写入路径先过全量校验(外壳 + 绑定契约 + 强核对),失败拒绝且不落盘。
169
+ */
170
+ declare function initProjectConfig(project: ProjectRoot, providers: ProviderSet, overrides?: Record<string, Record<string, unknown>>, options?: {
171
+ reset?: boolean;
172
+ dryRun?: boolean;
173
+ }): InitProjectConfigResult;
174
+ interface ProjectInspection {
175
+ projectRoot: string;
176
+ realRoot: string;
177
+ config: {
178
+ file: string;
179
+ relativeFile: string;
180
+ exists: boolean;
181
+ valid: boolean;
182
+ kind: "ok" | "missing" | "invalid" | "unsafe-binding";
183
+ errors: string[];
184
+ hint: string | null;
185
+ schemaVersion: number | null;
186
+ bindings: Record<string, unknown>;
187
+ /** 按注册集合逐 Provider 的绑定状态(与运行期同一入口) */
188
+ providerBindings: Array<{
189
+ providerId: string;
190
+ state: "bound" | "missing-binding" | "invalid";
191
+ dirs: Record<string, string>;
192
+ files: Record<string, string>;
193
+ warnings: string[];
194
+ errors: string[];
195
+ }>;
196
+ };
197
+ vant: {
198
+ dir: string;
199
+ exists: boolean;
200
+ configFiles: string[];
201
+ projectConfigFile: string;
202
+ projectConfigExists: boolean;
203
+ };
204
+ state: {
205
+ dir: string;
206
+ exists: boolean;
207
+ operationCount: number;
208
+ };
209
+ initHint: string;
210
+ }
211
+ /** 只读检查:不执行任何工具,不写任何文件;检查面与当前注册 Provider 集合一致 */
212
+ declare function inspectProject(project: ProjectRoot, providers: ProviderSet): ProjectInspection;
213
+
214
+ /**
215
+ * 异步执行句柄(阶段 C):可序列化身份凭证 + 落盘证据回读校验。
216
+ *
217
+ * 设计要点(对应计划 §6 与 survey §4):
218
+ * - 句柄由内核在异步触发结果中产出(Provider 只提供 backendTaskId 种子);
219
+ * 调用方提交的句柄**不可信**——查询/取消前必须经 verifyExecutionHandle 全量校验。
220
+ * - 校验依据是**落盘证据的一致性核对**(启动 operation 的 result.json),不是密码学签名:
221
+ * integrity 摘要仅防手滑改动/截断(survey §9 决策 5)。
222
+ * - 禁止"证据缺失/校验失败时回退最近一次任务";不能恢复的句柄给出明确错误。
223
+ * - 每次查询/取消是独立 operationId(runCapability 天然保证);校验只**读**启动目录,绝不复用覆盖。
224
+ */
225
+
226
+ declare const EXECUTION_HANDLE_VERSION = 1;
227
+ /** Provider 在异步触发结果中提供的后端身份种子(内核发行前校验形状) */
228
+ interface ExecutionHandleSeed {
229
+ /** 后端可验证的任务身份;后端无身份协议时必须显式为 null(禁止 v-cli 侧编造) */
230
+ backendTaskId: string | null;
231
+ }
232
+ /** 可序列化执行句柄(随触发结果返回并落盘) */
233
+ interface ExecutionHandle {
234
+ schemaVersion: typeof EXECUTION_HANDLE_VERSION;
235
+ providerId: string;
236
+ /** 触发能力 id(如 unity.test-start) */
237
+ capabilityId: string;
238
+ /** 原始启动操作 id(证据目录锚点) */
239
+ originOperationId: string;
240
+ backendTaskId: string | null;
241
+ /** 目标工程身份(v-cli 解析的 realpath + 配置文件路径) */
242
+ project: {
243
+ root: string;
244
+ configFile: string;
245
+ };
246
+ startedAt: string;
247
+ /** false = 未落盘启动(--no-persist),不可跨进程恢复 */
248
+ recoverable: boolean;
249
+ /** 证据目录(工程内相对路径,恒为 .vant/state/operations/<originOperationId>) */
250
+ recordDir: string;
251
+ /** 完整性提示摘要(canonical(handle 去本字段) 的 sha256;非签名) */
252
+ integrity: {
253
+ algo: "sha256";
254
+ digest: string;
255
+ };
256
+ }
257
+ /** 递归键排序的稳定序列化(integrity 计算基准) */
258
+ declare function canonicalize(value: unknown): string;
259
+ /** 由内核补全句柄(Provider 种子 + 内核掌握的身份字段);persist=false → recoverable=false */
260
+ declare function buildExecutionHandle(input: {
261
+ seed: ExecutionHandleSeed;
262
+ providerId: string;
263
+ capabilityId: string;
264
+ operationId: string;
265
+ project: ProjectRoot;
266
+ configFile: string;
267
+ startedAt: string;
268
+ persisted: boolean;
269
+ }): ExecutionHandle;
270
+ type HandleVerification = {
271
+ ok: true;
272
+ /** 从启动 operation 落盘证据读回的关联材料(供查询/取消能力组装结果与证据) */
273
+ record: {
274
+ operationId: string;
275
+ capabilityId: string;
276
+ providerId: string;
277
+ backendTaskId: string | null;
278
+ recordDir: string;
279
+ startedAt: string | null;
280
+ execution: {
281
+ status: string;
282
+ lifecycle: string;
283
+ } | null;
284
+ acceptance: {
285
+ status: string;
286
+ pending: boolean;
287
+ } | null;
288
+ };
289
+ /** 已通过的身份核对项(写入验收证据) */
290
+ checks: string[];
291
+ } | {
292
+ ok: false;
293
+ code: string;
294
+ errors: string[];
295
+ };
296
+ /**
297
+ * 校验调用方提交的句柄(不可信输入),并从落盘证据恢复原始执行关联。
298
+ * 任何不一致 → 明确拒绝(不回退最近任务、不猜测)。
299
+ */
300
+ declare function verifyExecutionHandle(input: {
301
+ project: ProjectRoot;
302
+ handle: unknown;
303
+ /** 查询/取消能力所属 provider(防跨 Provider 句柄) */
304
+ expectProviderId: string;
305
+ /** 期望的触发能力 id(可选,收紧到具体触发器) */
306
+ expectCapabilityId?: string;
307
+ }): HandleVerification;
308
+
309
+ /** JSON Schema 子集(本阶段支持的形态,注册时校验) */
310
+ type JsonSchemaType = "object" | "array" | "string" | "number" | "integer" | "boolean" | "null";
311
+ interface JsonSchemaObject {
312
+ type: "object";
313
+ description?: string;
314
+ /** true 时允许 null(用于"缺失即 null"的输出字段) */
315
+ nullable?: boolean;
316
+ properties?: Record<string, JsonSchema>;
317
+ required?: string[];
318
+ additionalProperties?: boolean | JsonSchema;
319
+ minProperties?: number;
320
+ maxProperties?: number;
321
+ }
322
+ interface JsonSchemaArray {
323
+ type: "array";
324
+ description?: string;
325
+ /** true 时允许 null(用于"缺失即 null"的输出字段) */
326
+ nullable?: boolean;
327
+ items?: JsonSchema;
328
+ minItems?: number;
329
+ maxItems?: number;
330
+ }
331
+ interface JsonSchemaString {
332
+ type: "string";
333
+ description?: string;
334
+ /** true 时允许 null(用于"缺失即 null"的输出字段) */
335
+ nullable?: boolean;
336
+ enum?: string[];
337
+ minLength?: number;
338
+ maxLength?: number;
339
+ pattern?: string;
340
+ }
341
+ interface JsonSchemaNumber {
342
+ type: "number" | "integer";
343
+ description?: string;
344
+ /** true 时允许 null(用于"缺失即 null"的输出字段) */
345
+ nullable?: boolean;
346
+ enum?: number[];
347
+ minimum?: number;
348
+ maximum?: number;
349
+ }
350
+ interface JsonSchemaBoolean {
351
+ type: "boolean";
352
+ description?: string;
353
+ /** true 时允许 null(用于"缺失即 null"的输出字段) */
354
+ nullable?: boolean;
355
+ enum?: boolean[];
356
+ }
357
+ interface JsonSchemaNull {
358
+ type: "null";
359
+ description?: string;
360
+ nullable?: boolean;
361
+ }
362
+ type JsonSchema = JsonSchemaObject | JsonSchemaArray | JsonSchemaString | JsonSchemaNumber | JsonSchemaBoolean | JsonSchemaNull;
363
+ /** 描述里的前置条件声明(检查实现由 provider 提供,注册时核对一一对应) */
364
+ interface PreconditionDeclaration {
365
+ /** 稳定 id,例如 "unity.pipeline-ready" */
366
+ id: string;
367
+ description: string;
368
+ }
369
+ type PreconditionStatus = "satisfied" | "violated" | "skipped" | "unknown";
370
+ interface PreconditionOutcome {
371
+ id: string;
372
+ status: PreconditionStatus;
373
+ detail: string;
374
+ evidence?: Evidence[];
375
+ }
376
+ /** 副作用声明(运行时实现上报的副作用必须落在声明集合内,否则视为契约违约) */
377
+ type SideEffectKind = "process-exec" | "fs-write" | "fs-read" | "engine-state" | "network";
378
+ interface SideEffectDeclaration {
379
+ id: string;
380
+ kind: SideEffectKind;
381
+ description: string;
382
+ reversible: boolean;
383
+ }
384
+ interface SideEffectRecord {
385
+ kind: SideEffectKind;
386
+ description: string;
387
+ reversible: boolean;
388
+ details?: Record<string, unknown>;
389
+ }
390
+ /** 资源需求(声明 + 组织层注入授权;本阶段内核不实现资源锁) */
391
+ type ResourceKind = "project-workspace" | "engine-editor" | "build-target" | "user-cache" | "network";
392
+ type ResourceMode = "exclusive" | "shared";
393
+ interface ResourceRequirement {
394
+ kind: ResourceKind;
395
+ mode: ResourceMode;
396
+ scope: "project" | "machine";
397
+ description: string;
398
+ }
399
+ /** 重试语义(本阶段内核单次尝试;声明供调用方/组织层消费) */
400
+ interface RetrySemantics {
401
+ /** 同一入参重复执行是否安全(幂等/只读) */
402
+ safe: boolean;
403
+ /** >= 1;> 1 表示调用方可重试 */
404
+ maxAttempts: number;
405
+ strategy: "none" | "rerun" | "poll-status";
406
+ description: string;
407
+ }
408
+ interface CapabilityDescriptor {
409
+ /** 稳定 capability id,必须带 provider 命名空间前缀(如 unity.compile) */
410
+ id: string;
411
+ /** 语义化版本,如 "0.1.0" */
412
+ version: string;
413
+ description: string;
414
+ inputSchema: JsonSchema;
415
+ outputSchema: JsonSchema;
416
+ preconditions: PreconditionDeclaration[];
417
+ sideEffects: SideEffectDeclaration[];
418
+ resources: ResourceRequirement[];
419
+ retry: RetrySemantics;
420
+ /** 单次尝试的建议超时(毫秒);调用方与实现都可进一步收紧 */
421
+ timeoutMs?: number;
422
+ tags?: string[];
423
+ }
424
+ interface ProviderInfo {
425
+ id: string;
426
+ version: string;
427
+ description: string;
428
+ }
429
+ type ProviderState = "available" | "missing" | "platform-mismatch" | "invalid" | "unavailable";
430
+ interface ProviderStatus {
431
+ state: ProviderState;
432
+ detail: string;
433
+ tool?: {
434
+ name: string;
435
+ version?: string;
436
+ path?: string;
437
+ };
438
+ }
439
+ /** 执行状态:只描述本次调用本身 */
440
+ type ExecutionStatus = "succeeded" | "failed" | "cancelled" | "unknown";
441
+ /**
442
+ * 生命周期:描述底层引擎工作(任务级六态,阶段 C 扩展):
443
+ * accepted=已接受启动、running=进行中、completed=正常终态、failed=失败终态、
444
+ * cancelled=后端确认取消、unknown=不可解释/不可知。
445
+ */
446
+ type ExecutionLifecycle = "completed" | "accepted" | "running" | "failed" | "cancelled" | "unknown";
447
+ /** 验收状态:只描述业务结论 */
448
+ type AcceptanceStatus = "passed" | "failed" | "not-run";
449
+ type ErrorCategory = "request" | "config" | "precondition" | "resource" | "process" | "protocol" | "output" | "acceptance" | "internal";
450
+ interface StructuredError {
451
+ code: string;
452
+ category: ErrorCategory;
453
+ message: string;
454
+ retryable: boolean;
455
+ details?: unknown;
456
+ }
457
+ interface Evidence {
458
+ kind: "process-exit" | "protocol-envelope" | "protocol-field" | "file" | "report" | "probe" | "declared";
459
+ description: string;
460
+ data?: unknown;
461
+ }
462
+ interface Artifact {
463
+ kind: "log" | "tool-json" | "report" | "exec-log";
464
+ path: string | null;
465
+ description: string;
466
+ sha256?: string;
467
+ bytes?: number;
468
+ }
469
+ interface LogRef {
470
+ bytes: number;
471
+ truncated: boolean;
472
+ sha256: string;
473
+ /** 持久化后的文件名(相对 operation 目录);未落盘为 null */
474
+ file: string | null;
475
+ /** 便于快速查看的尾部片段 */
476
+ tail: string;
477
+ }
478
+ interface ProjectBindingInfo {
479
+ /** 工程根绝对路径(realpath) */
480
+ root: string;
481
+ /** .vant/config/v-cli.json 绝对路径 */
482
+ configFile: string;
483
+ /** 已安全解析的绑定路径(provider id -> 字段名 -> 绝对路径) */
484
+ bindingDirs: Record<string, Record<string, string>>;
485
+ }
486
+ interface CapabilityRunResult<Out = unknown> {
487
+ schemaVersion: 1;
488
+ operationId: string;
489
+ capability: {
490
+ id: string;
491
+ version: string;
492
+ description: string;
493
+ };
494
+ provider: ProviderInfo & {
495
+ tool?: {
496
+ name: string;
497
+ version?: string;
498
+ path?: string;
499
+ } | null;
500
+ };
501
+ project: ProjectBindingInfo;
502
+ invocation: {
503
+ taskId: string | null;
504
+ runId: string | null;
505
+ /** 本次操作的主进程调用(受控 argv;不含 shell 字符串) */
506
+ command: {
507
+ file: string;
508
+ args: string[];
509
+ } | null;
510
+ startedAt: string;
511
+ finishedAt: string;
512
+ durationMs: number;
513
+ };
514
+ execution: {
515
+ status: ExecutionStatus;
516
+ lifecycle: ExecutionLifecycle;
517
+ exitCode: number | null;
518
+ signal: string | null;
519
+ attempts: number;
520
+ error: StructuredError | null;
521
+ };
522
+ /** 异步触发句柄(触发类能力且调用成功时产出;其余为 null) */
523
+ handle: ExecutionHandle | null;
524
+ acceptance: {
525
+ status: AcceptanceStatus;
526
+ reason: string;
527
+ /** true 表示"尚未有结论,应轮询 followUp" */
528
+ pending: boolean;
529
+ evidence: Evidence[];
530
+ };
531
+ preconditions: PreconditionOutcome[];
532
+ resources: {
533
+ declared: ResourceRequirement[];
534
+ authorization: "not-enforced" | "granted" | "denied";
535
+ grantId: string | null;
536
+ denials: {
537
+ kind: string;
538
+ reason: string;
539
+ }[];
540
+ };
541
+ sideEffects: SideEffectRecord[];
542
+ artifacts: Artifact[];
543
+ logs: {
544
+ stdout: LogRef;
545
+ stderr: LogRef;
546
+ };
547
+ output: Out | null;
548
+ followUp: {
549
+ capabilityId: string | null;
550
+ hint: string;
551
+ }[];
552
+ notes: string[];
553
+ warnings: string[];
554
+ persisted: {
555
+ status: "saved" | "disabled" | "failed";
556
+ dir: string | null;
557
+ files: string[];
558
+ error: string | null;
559
+ };
560
+ }
561
+ /** 资源授权请求(组织层注入的校验钩子输入) */
562
+ interface ResourceAuthorizationRequest {
563
+ operationId: string;
564
+ capabilityId: string;
565
+ providerId: string;
566
+ projectRoot: string;
567
+ taskId: string | null;
568
+ runId: string | null;
569
+ requirements: ResourceRequirement[];
570
+ }
571
+ interface ResourceAuthorizationDecision {
572
+ granted: boolean;
573
+ reason?: string;
574
+ grantId?: string;
575
+ denials?: {
576
+ kind: string;
577
+ reason: string;
578
+ }[];
579
+ }
580
+ type ResourceAuthorizer = (request: ResourceAuthorizationRequest) => ResourceAuthorizationDecision | Promise<ResourceAuthorizationDecision>;
581
+ /** 操作事件记录器(落盘或无操作) */
582
+ interface OperationLogger {
583
+ event(type: string, message: string, data?: unknown): void;
584
+ warn(message: string): void;
585
+ }
586
+ /** provider 实现可用的执行上下文 */
587
+ interface CapabilityExecutionContext {
588
+ operationId: string;
589
+ projectRoot: string;
590
+ /** 锚定后的工程根(realpath 语义;句柄校验等需要 ProjectRoot 的内核入口直接用它) */
591
+ projectAnchor: ProjectRoot;
592
+ configFile: string;
593
+ /** 已校验的工程级 v-cli 配置(.vant/config/v-cli.json) */
594
+ config: ProjectCliConfig;
595
+ /** 本 provider 的已校验绑定段(无绑定为 null;消费而非重新解析 ctx.config) */
596
+ binding: Record<string, unknown> | null;
597
+ /** 本 provider 的绑定路径(pathField 字段名 -> 绝对路径) */
598
+ bindingDirs: Record<string, string>;
599
+ taskId: string | null;
600
+ runId: string | null;
601
+ signal: AbortSignal;
602
+ log: OperationLogger;
603
+ /** 明确的测试/SDK 不落盘模式 */
604
+ persist: boolean;
605
+ now(): Date;
606
+ }
607
+ /** 实现返回的结构化结果(内核补全 project/时间/日志/持久化等字段) */
608
+ interface ImplementationOutcome<Out = unknown> {
609
+ execution: {
610
+ status: ExecutionStatus;
611
+ lifecycle: ExecutionLifecycle;
612
+ exitCode?: number | null;
613
+ signal?: string | null;
614
+ error?: StructuredError | null;
615
+ };
616
+ acceptance: {
617
+ status: AcceptanceStatus;
618
+ reason: string;
619
+ pending?: boolean;
620
+ evidence?: Evidence[];
621
+ };
622
+ output?: Out;
623
+ /** 主进程原始输出:由内核落盘为 stdout.log / stderr.log */
624
+ rawOutput?: {
625
+ stdout: string;
626
+ stderr: string;
627
+ stdoutTruncated?: boolean;
628
+ stderrTruncated?: boolean;
629
+ };
630
+ evidence?: Evidence[];
631
+ artifacts?: Artifact[];
632
+ sideEffects?: SideEffectRecord[];
633
+ followUp?: {
634
+ capabilityId: string | null;
635
+ hint: string;
636
+ }[];
637
+ notes?: string[];
638
+ /** 实现实际发起的主进程调用(受控 argv) */
639
+ command?: {
640
+ file: string;
641
+ args: string[];
642
+ } | null;
643
+ /** 工具版本等归属信息 */
644
+ tool?: {
645
+ name: string;
646
+ version?: string;
647
+ path?: string;
648
+ } | null;
649
+ /** 异步触发句柄种子(backendTaskId 等);内核补全身份与完整性后进入结果 */
650
+ handle?: ExecutionHandleSeed;
651
+ }
652
+ type PreconditionChecker = (input: Record<string, unknown>, ctx: CapabilityExecutionContext) => Promise<PreconditionOutcome> | PreconditionOutcome;
653
+ interface CapabilityImplementation {
654
+ /** 与 descriptor.preconditions 一一对应(注册时校验) */
655
+ preconditions?: Record<string, PreconditionChecker>;
656
+ execute(input: Record<string, unknown>, ctx: CapabilityExecutionContext): Promise<ImplementationOutcome>;
657
+ }
658
+ interface CapabilityRegistration {
659
+ descriptor: CapabilityDescriptor;
660
+ implementation: CapabilityImplementation;
661
+ }
662
+ /** Provider:状态发现(不执行工具)+ 能力注册 + 自包含绑定契约 */
663
+ interface CapabilityProvider {
664
+ id: string;
665
+ version: string;
666
+ description: string;
667
+ /** 只做发现(读包/读配置),不得执行被包装工具 */
668
+ status(): Promise<ProviderStatus> | ProviderStatus;
669
+ capabilities(): CapabilityRegistration[];
670
+ /** bindings.<providerId> 段的契约:schema + 路径字段声明 + 语义校验与解析 */
671
+ binding: ProviderBindingContract;
672
+ /** 可选:project init 生成默认绑定段(未实现则 init 不为该 provider 生成段) */
673
+ defaultBinding?: ProviderDefaultBinding;
674
+ }
675
+ /** 绑定段中的路径字段声明:核心据此统一做越界/符号链接强核对 */
676
+ interface ProviderPathField {
677
+ /** 绑定段内字段名(须出现在 binding.schema.properties) */
678
+ field: string;
679
+ kind: "dir" | "file";
680
+ required: boolean;
681
+ }
682
+ interface ProviderBindingResolutionOk {
683
+ ok: true;
684
+ /** 字段名 -> 已安全解析的绝对路径(kind:"dir" 的 pathFields) */
685
+ dirs: Record<string, string>;
686
+ /** 字段名 -> 已安全解析的绝对路径(kind:"file" 的 pathFields) */
687
+ files: Record<string, string>;
688
+ /** Provider 语义归一后的绑定段(运行期注入 ctx.binding;缺省用原始段) */
689
+ section?: Record<string, unknown>;
690
+ warnings: string[];
691
+ }
692
+ interface ProviderBindingResolutionError {
693
+ ok: false;
694
+ errors: string[];
695
+ }
696
+ type ProviderBindingResolution = ProviderBindingResolutionOk | ProviderBindingResolutionError;
697
+ interface ProviderBindingResolveInput {
698
+ project: ProjectRoot;
699
+ /** bindings.<providerId> 原始对象 */
700
+ raw: unknown;
701
+ /** 路径解析统一入口(核心注入;"." 表示工程根本身) */
702
+ resolveInsideProject: typeof resolveInsideProject;
703
+ }
704
+ interface ProviderBindingContract {
705
+ /** bindings.<providerId> 段的 JSON Schema(顶层必须是 object) */
706
+ schema: JsonSchema;
707
+ /** 声明的路径字段(核心对 resolve 结果做重解析强核对;注册表保存冻结快照) */
708
+ pathFields: readonly ProviderPathField[];
709
+ /** 语义校验与解析:字段类型/值域由 Provider 自定,路径必须走注入的 resolveInsideProject */
710
+ resolve(input: ProviderBindingResolveInput): ProviderBindingResolution;
711
+ }
712
+ /** project init 默认绑定段生成器(可选能力) */
713
+ type ProviderDefaultBinding = (project: ProjectRoot) => {
714
+ section: Record<string, unknown>;
715
+ warnings: string[];
716
+ };
717
+ interface CapabilitySummary {
718
+ id: string;
719
+ version: string;
720
+ description: string;
721
+ provider: ProviderInfo;
722
+ tags: string[];
723
+ preconditions: string[];
724
+ sideEffectKinds: SideEffectKind[];
725
+ resources: {
726
+ kind: ResourceKind;
727
+ mode: ResourceMode;
728
+ scope: ResourceRequirement["scope"];
729
+ }[];
730
+ retry: RetrySemantics;
731
+ }
732
+
733
+ /** 结构化错误:统一 code/category/message/retryable/details */
734
+
735
+ declare function structuredError(code: string, category: ErrorCategory, message: string, options?: {
736
+ retryable?: boolean;
737
+ details?: unknown;
738
+ }): StructuredError;
739
+ /** 实现可抛出该错误以返回结构化失败(内核不再包成 internal) */
740
+ declare class CapabilityError extends Error {
741
+ readonly structured: StructuredError;
742
+ constructor(structured: StructuredError);
743
+ }
744
+ /** 注册期错误:包含全部校验失败项(重复 id / 非法 schema / 非法元数据) */
745
+ declare class CapabilityRegistrationError extends Error {
746
+ readonly errors: string[];
747
+ constructor(errors: string[]);
748
+ }
749
+ declare function toStructuredError(err: unknown): StructuredError;
750
+
751
+ /**
752
+ * Capability / Provider 注册表:注册即校验,list/describe 只读描述(绝不执行工具)。
753
+ *
754
+ * 拒绝条件(全部在注册期抛出 CapabilityRegistrationError,错误项逐条列出):
755
+ * - provider/capability id 非法或重复(跨 provider 全局唯一)
756
+ * - capability id 未带 provider 命名空间前缀
757
+ * - 版本号、描述、tags 等元数据类型错误
758
+ * - 输入/输出 schema 不是合法 JSON Schema 子集,或顶层不是 object
759
+ * - 前置条件 / 副作用 / 资源 / 重试语义缺失或非法
760
+ * - descriptor.preconditions 与 implementation.preconditions 不一一对应
761
+ */
762
+
763
+ /** 校验 provider 元数据(注册 provider 时) */
764
+ declare function validateProvider(provider: unknown): string[];
765
+ /** 校验 capability 描述与实现;providerId 用于命名空间前缀核对 */
766
+ declare function validateCapability(descriptor: unknown, implementation: unknown, providerId: string): string[];
767
+ interface Entry {
768
+ descriptor: CapabilityDescriptor;
769
+ implementation: CapabilityImplementation;
770
+ provider: ProviderInfo;
771
+ }
772
+ declare class CapabilityRegistry {
773
+ private readonly providersById;
774
+ private readonly entries;
775
+ /** 注册 provider 及其全部能力;任一项非法则整体拒绝,不产生部分注册 */
776
+ registerProvider(provider: CapabilityProvider): void;
777
+ /** provider 发现状态(只读发现,不执行工具) */
778
+ providerStatus(providerId: string): Promise<ProviderStatus | undefined>;
779
+ providers(): ProviderInfo[];
780
+ /** 已注册 provider 对象(配置绑定校验用;顺序为注册顺序) */
781
+ listProviders(): CapabilityProvider[];
782
+ getProvider(id: string): CapabilityProvider | undefined;
783
+ list(): CapabilitySummary[];
784
+ describe(id: string): (CapabilityDescriptor & {
785
+ provider: ProviderInfo & {
786
+ binding: {
787
+ schema: JsonSchema;
788
+ pathFields: CapabilityProvider["binding"]["pathFields"];
789
+ };
790
+ };
791
+ }) | undefined;
792
+ get(id: string): Entry | undefined;
793
+ has(id: string): boolean;
794
+ private summarize;
795
+ }
796
+
797
+ /**
798
+ * 受控进程执行器:显式 argv 数组、shell:false、输出捕获与截断、超时/取消即杀。
799
+ *
800
+ * 设计要点:
801
+ * - 永远不拼接 shell 字符串(no shell: true),不存在注入面。
802
+ * - 取消(AbortSignal)与超时都会 kill 子进程;只有观察到子进程真正退出,
803
+ * killConfirmed 才为 true —— "取消未确认不得标记 cancelled" 的判定依据。
804
+ * - 执行器可注入(SDK/测试用假执行器驱动真实协议 fixture)。
805
+ */
806
+ interface ProcessInvocation {
807
+ /** 可执行文件(JS 入口请配 process.execPath) */
808
+ file: string;
809
+ args: string[];
810
+ cwd?: string;
811
+ /** 叠加在 process.env 之上(undefined 值表示删除该变量) */
812
+ env?: Record<string, string | undefined>;
813
+ timeoutMs?: number;
814
+ signal?: AbortSignal;
815
+ /** 单流保留上限(字节,默认 8 MiB,超出截断并标记) */
816
+ maxOutputBytes?: number;
817
+ }
818
+ interface ProcessOutcome {
819
+ exitCode: number | null;
820
+ signal: NodeJS.Signals | null;
821
+ stdout: string;
822
+ stderr: string;
823
+ stdoutTruncated: boolean;
824
+ stderrTruncated: boolean;
825
+ timedOut: boolean;
826
+ aborted: boolean;
827
+ /** 我们请求了终止且观察到子进程退出 */
828
+ killConfirmed: boolean;
829
+ durationMs: number;
830
+ startedAt: string;
831
+ finishedAt: string;
832
+ /** spawn 本身失败(如文件不存在) */
833
+ error: {
834
+ code: string;
835
+ message: string;
836
+ } | null;
837
+ }
838
+ interface ProcessExecutor {
839
+ run(invocation: ProcessInvocation): Promise<ProcessOutcome>;
840
+ }
841
+ /** 真实执行器:spawn(shell:false) + 逐流捕获 + 超时/取消杀进程 */
842
+ declare class NodeProcessExecutor implements ProcessExecutor {
843
+ run(invocation: ProcessInvocation): Promise<ProcessOutcome>;
844
+ }
845
+
846
+ /**
847
+ * 执行内核(与 commander CLI 分离,可被 SDK/MCP/Agent 直接调用)。
848
+ *
849
+ * 单次运行的生命周期:
850
+ * 锚定工程根 → 读工程配置 → 校验真实输入 → 资源授权(组织层注入)→ 前置条件
851
+ * → 实现执行 → 校验真实输出与副作用声明 → 组装结果 → 落盘记录
852
+ *
853
+ * 硬性语义:
854
+ * - 进程退出码 0 不代表业务验收通过:验收状态由实现基于证据给出。
855
+ * - 取消只有确认(观察到子进程终止)才标记 cancelled,否则 unknown。
856
+ * - 前置条件 violated/unknown 一律 fail-closed,不执行。
857
+ * - 未注册 capability / 工程根不可用 / 配置缺失或非法 / operationId 非法或已存在
858
+ * 属于请求级失败:抛 CapabilityError(CLI 输出稀疏错误对象,退出码 2)。
859
+ */
860
+
861
+ interface CapabilityRunRequest {
862
+ capabilityId: string;
863
+ /** 显式工程根(--project);缺省用 cwd */
864
+ projectRoot?: string;
865
+ cwd?: string;
866
+ input?: Record<string, unknown>;
867
+ operationId?: string;
868
+ taskId?: string;
869
+ runId?: string;
870
+ /** false = 不落盘模式(测试/SDK 探测);默认 true */
871
+ persist?: boolean;
872
+ signal?: AbortSignal;
873
+ /** 组织层注入的资源授权校验(本阶段内核不实现资源锁) */
874
+ authorize?: ResourceAuthorizer;
875
+ }
876
+ interface CapabilityRuntimeDeps {
877
+ /** 注入时钟(测试确定化) */
878
+ clock?: () => Date;
879
+ /** 内核警告出口(默认 stderr) */
880
+ warn?: (message: string) => void;
881
+ }
882
+ /**
883
+ * 把进程执行结果规范化为执行状态:
884
+ * 超时/未确认取消一律 unknown(业务结论不可知),确认取消才是 cancelled。
885
+ */
886
+ declare function executionFromProcess(outcome: ProcessOutcome, options?: {
887
+ failureCode?: string;
888
+ }): {
889
+ status: ExecutionStatus;
890
+ lifecycle: ExecutionLifecycle;
891
+ exitCode: number | null;
892
+ signal: string | null;
893
+ error: StructuredError | null;
894
+ };
895
+ /**
896
+ * 结果 → 进程退出码(与 JSON 契约对齐)。
897
+ * 顺序很重要:请求级失败 → 2;执行未成功按执行状态给码;**0 只在执行 succeeded 且验收 passed 时出现**
898
+ * (验收 passed 永远不能覆盖失败/未知的执行状态)。
899
+ */
900
+ declare function exitCodeForResult(result: CapabilityRunResult): number;
901
+ /** 执行一个 capability(唯一入口;CLI 与 SDK 共用) */
902
+ declare function runCapability(registry: CapabilityRegistry, request: CapabilityRunRequest, deps?: CapabilityRuntimeDeps): Promise<CapabilityRunResult>;
903
+ /** 便捷封装:把结构化结果序列化为稳定 JSON 文本(CLI/SDK 共用) */
904
+ declare function formatResultJson(result: CapabilityRunResult): string;
905
+
906
+ type OfficialPluginStatus = "available" | "missing" | "invalid" | "platform-mismatch";
907
+ /** 官方插件命令的完整清单元数据(与 v-cli.plugin.json agent.commands 对齐) */
908
+ interface OfficialCommandInfo {
909
+ path: string[];
910
+ usage: string;
911
+ description: string;
912
+ arguments: {
913
+ name: string;
914
+ required: boolean;
915
+ description: string;
916
+ }[];
917
+ options: {
918
+ flags: string;
919
+ description: string;
920
+ }[];
921
+ output: {
922
+ format: string;
923
+ description: string;
924
+ };
925
+ exitCodes: Record<string, string>;
926
+ safety: string[];
927
+ }
928
+ interface OfficialPluginInfo {
929
+ source: "official";
930
+ package: string;
931
+ name: string;
932
+ description: string;
933
+ status: OfficialPluginStatus;
934
+ platform: string;
935
+ version?: string;
936
+ /** 可执行入口绝对路径(仅 available 时给出) */
937
+ bin?: string;
938
+ requiredPlatforms?: string[];
939
+ error?: string;
940
+ whenToUse?: string;
941
+ globalOptions?: {
942
+ flags: string;
943
+ description: string;
944
+ }[];
945
+ commands?: OfficialCommandInfo[];
946
+ runtime?: Record<string, unknown>;
947
+ environment?: {
948
+ name: string;
949
+ description: string;
950
+ }[];
951
+ }
952
+
953
+ /**
954
+ * Unity provider(首个 provider):把已安装的 @kevlns/u-cli-mod 包能力
955
+ * 包装成结构化 capability,受控 argv 调用(无 shell 拼接),
956
+ * 目标工程由 .vant/config/v-cli.json 的 bindings.unity.projectDir 统一绑定。
957
+ *
958
+ * 能力集(本阶段):unity.doctor / unity.editor-status / unity.compile /
959
+ * unity.compile-status / unity.test-start / unity.test-status / unity.test-cancel。
960
+ *
961
+ * 语义边界:
962
+ * - 触发类(compile / test-start)只报告 accepted/running,验收一律 not-run(pending),
963
+ * 完成判定必须轮询对应状态能力。
964
+ * - 状态类只按证据判定:字段缺失、取值不在已知值域、报告缺失 → 一律不通过
965
+ * (failed 或 not-run),并把实际读到的字段写进证据。
966
+ * - exec 前的就绪判据来自包内 AGENTS.md(doctor cli.state=valid &&
967
+ * pipeline.installed=true && pipeline.state=current),由前置条件 unity.pipeline-ready
968
+ * 自动执行 doctor 核对;不提供跳过检查的输入选项。
969
+ */
970
+
971
+ declare const UNITY_PROVIDER_ID = "unity";
972
+ declare const UNITY_PROVIDER_VERSION = "0.2.0";
973
+ /** bindings.unity 绑定段(Provider 自包含契约) */
974
+ type UnityTestMode = "EditMode" | "PlayMode";
975
+ interface UnityBinding {
976
+ /** 相对工程根的 Unity 工程目录("." 表示工程根自身) */
977
+ projectDir: string;
978
+ /** 可选:钉扎 Editor 版本(doctor 返回不一致即前置条件不满足) */
979
+ editorVersion?: string;
980
+ /** 可选:test-start 未显式传 mode 时的默认值 */
981
+ testMode?: UnityTestMode;
982
+ }
983
+ /** 绑定契约:schema 声明 + 路径字段 + 语义校验(路径解析走核心注入的统一入口) */
984
+ declare const unityBindingContract: ProviderBindingContract;
985
+ interface UnityProviderDeps {
986
+ executor: ProcessExecutor;
987
+ /** 后端发现;默认走 v-cli 官方插件白名单发现(不执行工具) */
988
+ discoverBackend?: () => OfficialPluginInfo;
989
+ /** 追加环境变量(默认继承父进程环境) */
990
+ env?: Record<string, string | undefined>;
991
+ timeoutSlackMs?: number;
992
+ }
993
+ /** 受控 argv:exec 目标工程 / 等待预算 / JSON 格式 / Pipeline 命令 */
994
+ declare function buildExecArgv(options: {
995
+ projectDir: string;
996
+ waitSeconds: number;
997
+ pipelineCommand: string;
998
+ pipelineArgs?: string[];
999
+ }): string[];
1000
+ declare function buildDoctorArgv(options: {
1001
+ projectDir: string;
1002
+ allowRunningEditor: boolean;
1003
+ }): string[];
1004
+ declare function createUnityProvider(deps: UnityProviderDeps): CapabilityProvider;
1005
+
1006
+ /**
1007
+ * Figma provider(阶段 E):把已安装的 @kevlns/figma-to-uprefab 的离线
1008
+ * staging contract 校验与只读诊断包装成结构化 capability。
1009
+ *
1010
+ * 边界(计划 §8,硬约束):
1011
+ * - 只做离线验证:contract/doctor 全程无网络,不调用任何 Figma REST/收费接口。
1012
+ * - 不做 source→IR 转换、不推广生成资产到生产路径、不修改 UIConfig。
1013
+ * - 不读取也不输出 Figma 凭据:经 v-cli 托管配置注入 uiSystem/staging(无令牌字段),
1014
+ * 验证过程不要求配置访问令牌(doctor 对 token 的 [FAIL] 如实报告,不作为通过条件)。
1015
+ * - 路径边界:projectDir/stagingRoot 为绑定路径字段(核心强核对:相对工程根、
1016
+ * 越界/链接在执行前拒绝);staging 内容的资产越界由插件自身 fail-closed(CON_/PAT_ 码族)。
1017
+ *
1018
+ * 托管配置(阶段 A 实证的路线):每次执行生成 .vant/state/figma/user-config.json
1019
+ * (projects 键 = Unity 工程绝对路径的规范化形式,与工具 normalizeProjectKey 一致:
1020
+ * 正斜杠 + win32 小写),经 env FIGMA_TO_UPREFAB_CONFIG 指给插件——不触碰用户真实配置。
1021
+ */
1022
+
1023
+ declare const FIGMA_PROVIDER_ID = "figma";
1024
+ declare const FIGMA_PROVIDER_VERSION = "0.1.0";
1025
+ /** bindings.figma 绑定段(Provider 自包含契约) */
1026
+ interface FigmaBinding {
1027
+ /** 相对 v-cli 工程根的 Unity 工程目录 */
1028
+ projectDir: string;
1029
+ /** 相对 v-cli 工程根的 staging 根目录(index 与各 root 所在) */
1030
+ stagingRoot: string;
1031
+ /** 可选:缺失 IR 报 warning 而非 error(转发 --allow-missing-ir) */
1032
+ allowMissingIr?: boolean;
1033
+ }
1034
+ declare const figmaBindingContract: ProviderBindingContract;
1035
+ interface FigmaProviderDeps {
1036
+ executor: ProcessExecutor;
1037
+ discoverBackend?: () => OfficialPluginInfo;
1038
+ env?: Record<string, string | undefined>;
1039
+ }
1040
+ declare function createFigmaProvider(deps: FigmaProviderDeps): CapabilityProvider;
1041
+
1042
+ /**
1043
+ * 默认 capability 注册表:显式装配内置 Provider。
1044
+ *
1045
+ * 位于 src/ 根(不在 src/core/** 内):core 不得 import providers(方向约束,
1046
+ * 测试覆盖)。SDK/CLI 缺省用它;调用方可通过 providers 提供完整集合。
1047
+ */
1048
+
1049
+ interface DefaultRegistryOptions {
1050
+ executor?: ProcessExecutor;
1051
+ /** 完整 Provider 集合(提供即完全替代内置装配;顺序即注册顺序) */
1052
+ providers?: CapabilityProvider[];
1053
+ /** 覆盖 Unity 后端发现(测试/夹具注入;providers 提供时忽略) */
1054
+ discoverBackend?: UnityProviderDeps["discoverBackend"];
1055
+ /** 覆盖 Figma 后端发现(测试/夹具注入;providers 提供时忽略) */
1056
+ figmaDiscoverBackend?: FigmaProviderDeps["discoverBackend"];
1057
+ /** 覆盖 Unity 后端环境变量(providers 提供时忽略) */
1058
+ unityEnv?: Record<string, string | undefined>;
1059
+ }
1060
+ /** 构建注册表;注册失败是编码错误,直接抛出 */
1061
+ declare function createDefaultRegistry(options?: DefaultRegistryOptions): CapabilityRegistry;
1062
+
1063
+ /**
1064
+ * 轻量 JSON Schema 子集:既校验"schema 定义本身"(注册期),
1065
+ * 也校验"真实值"(运行期输入/输出)。零依赖,错误信息带 JSON Pointer。
1066
+ *
1067
+ * 支持的关键字:type / properties / required / additionalProperties /
1068
+ * minProperties / maxProperties / items / minItems / maxItems / enum /
1069
+ * minLength / maxLength / pattern / minimum / maximum。
1070
+ */
1071
+
1072
+ declare const JSON_TYPES: readonly JsonSchemaType[];
1073
+ /** 校验 schema 定义本身;返回错误列表(空 = 合法) */
1074
+ declare function validateSchemaDefinition(schema: unknown, label: string): string[];
1075
+ /**
1076
+ * 校验真实值;返回错误列表(空 = 通过)。
1077
+ * schema 必须已通过 validateSchemaDefinition(未校验的畸形 schema 会被保守拒绝)。
1078
+ */
1079
+ declare function validateValue(value: unknown, schema: JsonSchema, pointer?: string): string[];
1080
+
1081
+ /**
1082
+ * 操作记录:.vant/state/operations/<operationId>/
1083
+ *
1084
+ * - 本地记录,不是任务中心:不做队列、不做锁、不跨进程协调(见 spec 文档)。
1085
+ * - operationId 严格校验(字符集/长度/保留名),越界与符号链接写入一律拒绝;
1086
+ * 已存在的 operationId 一律拒绝(mkdir 非递归 + wx 写入,绝不覆盖)。
1087
+ * - 保存:input.json(脱敏摘要)、events.jsonl(事件/日志)、result.json(结果证据)、
1088
+ * stdout.log / stderr.log(原始输出,带上限与截断标记)。
1089
+ * - 允许"不落盘"模式(测试/SDK):不创建任何目录/文件,事件丢弃(取舍见 spec)。
1090
+ */
1091
+
1092
+ declare class OperationExistsError extends Error {
1093
+ readonly code = "operation-exists";
1094
+ constructor(operationId: string, dir: string);
1095
+ }
1096
+ /** 校验 operationId;返回错误列表(空 = 合法) */
1097
+ declare function validateOperationId(operationId: unknown): string[];
1098
+ declare function generateOperationId(capabilityId: string, now?: Date, entropy?: string): string;
1099
+ interface OperationEvent {
1100
+ seq: number;
1101
+ at: string;
1102
+ type: string;
1103
+ message: string;
1104
+ data?: unknown;
1105
+ }
1106
+ interface WriteLogsInput {
1107
+ stdout: string;
1108
+ stderr: string;
1109
+ stdoutTruncated?: boolean;
1110
+ stderrTruncated?: boolean;
1111
+ }
1112
+ interface OperationSummary {
1113
+ operationId: string;
1114
+ dir: string | null;
1115
+ files: string[];
1116
+ events: OperationEvent[];
1117
+ failure: string | null;
1118
+ }
1119
+ /**
1120
+ * 操作记录写入器。reserve() 失败会抛出(越界/已存在/非法 id 都是硬失败);
1121
+ * reserve() 之后的写入失败不抛出,记录到 failure 并由结果如实上报。
1122
+ */
1123
+ declare class OperationStore implements OperationLogger {
1124
+ readonly operationId: string;
1125
+ readonly dir: string | null;
1126
+ readonly enabled: boolean;
1127
+ private events;
1128
+ private writtenFiles;
1129
+ private seq;
1130
+ private failure;
1131
+ private constructor();
1132
+ /** 不落盘模式:无目录、无文件、事件丢弃 */
1133
+ static disabled(operationId: string): OperationStore;
1134
+ /** 预留 operation 目录;越界/符号链接/非法 id/已存在 → 抛错(绝不覆盖) */
1135
+ static reserve(project: ProjectRoot, operationId: string, now?: Date): OperationStore;
1136
+ get persistedFiles(): string[];
1137
+ get failureMessage(): string | null;
1138
+ get recordedEvents(): OperationEvent[];
1139
+ private write;
1140
+ event(type: string, message: string, data?: unknown): void;
1141
+ warn(message: string): void;
1142
+ writeInput(payload: unknown): void;
1143
+ writeLogs(input: WriteLogsInput): {
1144
+ stdout: LogRef;
1145
+ stderr: LogRef;
1146
+ };
1147
+ private writeLog;
1148
+ writeResult(result: unknown): void;
1149
+ summary(): OperationSummary;
1150
+ }
1151
+
1152
+ /**
1153
+ * 凭据脱敏:落盘前对输入/参数做键名匹配替换。
1154
+ *
1155
+ * 目的:默认参数不把凭据写进 .vant/state/operations 记录。
1156
+ * 说明:这是"键名 + 值形态"的保守脱敏,不是内容级 DLP;
1157
+ * 工具自身 stdout/stderr 属于证据原文,按日志原样保存(见 spec 文档的取舍说明)。
1158
+ */
1159
+ interface RedactionResult<T> {
1160
+ value: T;
1161
+ /** 被替换的键路径(JSON Pointer 风格) */
1162
+ redactedPaths: string[];
1163
+ }
1164
+ declare function redactSecrets<T>(input: T): RedactionResult<T>;
1165
+ /** argv 级脱敏:`--token=xxx` / `--token xxx` 形态直接替换值 */
1166
+ declare function redactArgv(argv: string[]): RedactionResult<string[]>;
1167
+ declare const REDACTION_PLACEHOLDER = "***redacted***";
1168
+
1169
+ /** 版本常量:与 package.json 保持一致(有测试保证) */
1170
+ declare const VERSION = "0.3.0";
1171
+
1172
+ export { type AcceptanceStatus, type Artifact, type CapabilityDescriptor, CapabilityError, type CapabilityExecutionContext, type CapabilityImplementation, type CapabilityProvider, type CapabilityRegistration, CapabilityRegistrationError, CapabilityRegistry, type CapabilityRunRequest, type CapabilityRunResult, type CapabilityRuntimeDeps, type CapabilitySummary, type DefaultRegistryOptions, EXECUTION_HANDLE_VERSION, type ErrorCategory, type Evidence, type ExecutionHandle, type ExecutionHandleSeed, type ExecutionLifecycle, type ExecutionStatus, FIGMA_PROVIDER_ID, FIGMA_PROVIDER_VERSION, type FigmaBinding, type FigmaProviderDeps, type HandleVerification, type ImplementationOutcome, type InitProjectConfigResult, JSON_TYPES, type JsonSchema, type JsonSchemaArray, type JsonSchemaBoolean, type JsonSchemaNull, type JsonSchemaNumber, type JsonSchemaObject, type JsonSchemaString, type JsonSchemaType, type LoadProjectConfigResult, type LogRef, NodeProcessExecutor, OPERATIONS_RELATIVE, OperationExistsError, type OperationLogger, OperationStore, type OperationSummary, PROJECT_CLI_CONFIG_RELATIVE, PathSafetyError, type PreconditionChecker, type PreconditionDeclaration, type PreconditionOutcome, type ProcessExecutor, type ProcessInvocation, type ProcessOutcome, type ProjectBindingInfo, type ProjectCliConfig, type ProjectInspection, type ProjectRoot, type ProviderBindingContract, type ProviderBindingResolution, type ProviderBindingResolutionError, type ProviderBindingResolutionOk, type ProviderBindingResolveInput, type ProviderDefaultBinding, type ProviderInfo, type ProviderPathField, type ProviderSet, type ProviderState, type ProviderStatus, REDACTION_PLACEHOLDER, type ResolvedProviderBinding, type ResourceAuthorizationDecision, type ResourceAuthorizationRequest, type ResourceAuthorizer, type ResourceKind, type ResourceMode, type ResourceRequirement, type RetrySemantics, type SideEffectDeclaration, type SideEffectKind, type SideEffectRecord, type StructuredError, UNITY_PROVIDER_ID, UNITY_PROVIDER_VERSION, type UnityBinding, type UnityProviderDeps, type UnityTestMode, VANT_PROJECT_CONFIG_RELATIVE, VERSION, buildDoctorArgv, buildExecArgv, buildExecutionHandle, canonicalize, createDefaultRegistry, createFigmaProvider, createUnityProvider, executionFromProcess, exitCodeForResult, figmaBindingContract, formatResultJson, generateOperationId, initProjectConfig, inspectProject, loadProjectConfig, redactArgv, redactSecrets, renderProjectConfig, resolveBindings, resolveInsideProject, resolveProjectRoot, runCapability, splitSafeRelative, structuredError, toProviderSet, toStructuredError, unityBindingContract, validateCapability, validateOperationId, validateProjectCliConfig, validateProvider, validateSchemaDefinition, validateValue, verifyExecutionHandle };