@kiturone/kapibala 0.0.4 → 0.0.6

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/index.d.ts CHANGED
@@ -1,3 +1,97 @@
1
+ /** 技能知识来源;层级决定覆盖顺序,不授予文件或执行权限。 */
2
+ type SkillScope = 'builtin' | 'global' | 'project';
3
+ /** 结构化技能诊断;路径及文案需由宿主安全展示,不包含正文或凭据。 */
4
+ interface SkillDiagnostic {
5
+ code: string;
6
+ level: 'warn' | 'error';
7
+ path: string;
8
+ message: string;
9
+ winnerPath?: string;
10
+ loserPath?: string;
11
+ }
12
+ /** 已校验的文件内容;available=false 的执行扩展仅供诊断,不得激活。 */
13
+ interface SkillDocument {
14
+ name: string;
15
+ description: string;
16
+ body: string;
17
+ when?: string;
18
+ license?: string;
19
+ compatibility?: string;
20
+ argumentHint?: string;
21
+ metadata?: Readonly<Record<string, string>>;
22
+ frontmatter: Readonly<Record<string, unknown>>;
23
+ allowedTools?: readonly string[];
24
+ modelInvocable: boolean;
25
+ userInvocable: boolean;
26
+ available: boolean;
27
+ unavailableReason?: string;
28
+ diagnostics: readonly SkillDiagnostic[];
29
+ }
30
+ /** 宿主显式提供的扫描根;项目缺省不可信,boundary 必须是授权物理边界。 */
31
+ interface SkillRoot {
32
+ path: string;
33
+ scope: SkillScope;
34
+ kind?: 'native' | 'agents';
35
+ trusted?: boolean;
36
+ boundary?: string;
37
+ }
38
+ /** 可查询元数据;文件指纹来自发现快照,加载前必须重新核验。 */
39
+ interface SkillMetadata extends Omit<SkillDocument, 'body' | 'frontmatter' | 'diagnostics'> {
40
+ scope: SkillScope;
41
+ sourceRoot: string;
42
+ filePath: string;
43
+ baseDir: string;
44
+ contentDigest: string;
45
+ /** 原词法发现身份;加载重核根链接,不以旧物理文件继续授权。 */
46
+ discoveryRoot: string;
47
+ discoveryPath: string;
48
+ priority: number;
49
+ disabled: boolean;
50
+ }
51
+ /** 完整快照实体;正文仅在校验通过后按需进入模型历史。 */
52
+ interface SkillDefinition extends SkillMetadata {
53
+ body: string;
54
+ }
55
+ /** 会话技能选项;无根即不扫描 home,disabled 名称不能由项目配置重新启用。 */
56
+ interface SkillOptions {
57
+ roots: readonly SkillRoot[];
58
+ enabled?: boolean;
59
+ disabled?: readonly string[];
60
+ }
61
+ /** 技能正文持久来源;只追踪事实,历史来源不恢复授权。 */
62
+ interface SkillContentSource {
63
+ version: 1;
64
+ name: string;
65
+ scope: SkillScope;
66
+ filePath: string;
67
+ baseDir: string;
68
+ contentDigest: string;
69
+ renderedDigest: string;
70
+ caller: 'user' | 'model';
71
+ runId: string;
72
+ invocationId: string;
73
+ }
74
+ /** 本轮活动记录;pending 只收紧,committed 后才可受控读取资源。 */
75
+ interface SkillActivation {
76
+ definition: SkillDefinition;
77
+ source: SkillContentSource;
78
+ state: 'pending' | 'committed';
79
+ allowedTools?: ReadonlySet<string>;
80
+ }
81
+ /** 统一默认限额;宿主不得另算一套目录、文件或响应预算。 */
82
+ declare const SKILL_LIMITS: Readonly<{
83
+ fileBytes: number;
84
+ frontmatterBytes: number;
85
+ depth: 6;
86
+ directories: 2000;
87
+ entries: 20000;
88
+ descriptionChars: 250;
89
+ catalogTokens: 2000;
90
+ queryTokens: 1000;
91
+ resourceBytes: number;
92
+ resourceFiles: 20;
93
+ }>;
94
+
1
95
  /** 内置适配器的实际请求目标;用于拒绝模型、协议或端点错配的绑定。 */
2
96
  interface ModelProviderBinding {
3
97
  protocol: ModelProtocol;
@@ -137,10 +231,20 @@ declare class KapibalaError extends Error {
137
231
  readonly code: string;
138
232
  readonly retryPolicy: 'never' | 'immediate' | 'backoff' | 'after_user_action';
139
233
  readonly safeMessage: string;
234
+ readonly dispatchOutcome?: 'not_sent' | 'succeeded' | 'failed' | 'unknown';
140
235
  constructor(message: string, options?: {
141
236
  code?: string;
142
237
  retryPolicy?: 'never' | 'immediate' | 'backoff' | 'after_user_action';
143
238
  safeMessage?: string;
239
+ dispatchOutcome?: 'not_sent' | 'succeeded' | 'failed' | 'unknown';
240
+ });
241
+ }
242
+ /** 工具向外部发送前在微任务复核或状态检查中被撤销/拒绝;dispatchOutcome 固定 not_sent。 */
243
+ declare class PreDispatchError extends KapibalaError {
244
+ constructor(message: string, options?: {
245
+ code?: string;
246
+ retryPolicy?: 'never' | 'after_user_action';
247
+ safeMessage?: string;
144
248
  });
145
249
  }
146
250
  /** 模型调用失败;message 已脱敏,对外诊断统一经 describeModelError 产出,retryPolicy 仅为处理建议。 */
@@ -242,9 +346,26 @@ interface ProviderStateBlock {
242
346
  }
243
347
  /** canonical 历史的内容块联合;provider_state 等私有块只在同 run、同模型与端点续答回传。 */
244
348
  type ContentBlock = TextBlock | ToolUseBlock | ToolResultBlock | ThinkingBlock | RedactedThinkingBlock | ProviderStateBlock;
349
+ /**
350
+ * 宿主准备受控 Prompt 时的来源元数据(v1)。
351
+ * 用于追踪 Prompt 来源、版本与内容摘要;不保存认证值或重复保存原始参数,
352
+ * 不发送到 Provider wire,不从历史恢复授权。
353
+ */
354
+ interface PromptContentSource {
355
+ version: 1;
356
+ server: string;
357
+ name: string;
358
+ scope?: string;
359
+ contentDigest?: string;
360
+ configIdentity?: string;
361
+ }
245
362
  interface TextBlock {
246
363
  type: 'text';
247
364
  text: string;
365
+ /** 宿主注入技能的可选来源;只追踪正文,缺失或恢复不授予权限。 */
366
+ skillSource?: SkillContentSource;
367
+ /** 宿主注入受控 Prompt 的可选来源;只追踪正文与审计摘要,缺失或恢复不授予权限。 */
368
+ promptSource?: PromptContentSource;
248
369
  /** 源 wire Item 元数据;正文被改写后由调用方清除,不作为业务身份。 */
249
370
  protocolMeta?: ProtocolItemMetadata;
250
371
  }
@@ -260,8 +381,23 @@ interface ToolUseBlock {
260
381
  /** 源 wire Item 元数据;内容被改写后由调用方清除,不作为业务身份。 */
261
382
  protocolMeta?: ProtocolItemMetadata;
262
383
  }
384
+ /**
385
+ * canonical 工具结果的可选 v1 执行事实元数据。
386
+ * 适配器按发送证据先记录 dispatchOutcome,执行器在发生本地钩子、校验、转换或审计失败时附加 hostError。
387
+ * 随 canonical 结果持久化;不直接上 Provider wire,不从历史中推断不存在的事实。
388
+ */
389
+ interface ToolResultExecution {
390
+ version: 1;
391
+ dispatchOutcome: 'not_sent' | 'succeeded' | 'failed' | 'unknown';
392
+ hostError?: {
393
+ phase: 'validation' | 'projection' | 'hook' | 'audit';
394
+ code: string;
395
+ };
396
+ }
263
397
  interface ToolResultBlock {
264
398
  type: 'tool_result';
399
+ /** 完整技能正文的宿主来源;不发送到Provider wire,不从历史恢复授权。 */
400
+ skillSource?: SkillContentSource;
265
401
  toolUseId: string;
266
402
  content: string;
267
403
  isError?: boolean;
@@ -271,6 +407,12 @@ interface ToolResultBlock {
271
407
  errorCode?: string;
272
408
  /** 不代表自动重试,只描述调用方应如何处理该错误。 */
273
409
  retryPolicy?: 'never' | 'immediate' | 'backoff' | 'after_user_action';
410
+ /**
411
+ * 可选 v1 执行事实元数据。
412
+ * 适配器按发送证据先记录 dispatchOutcome,执行器在发生本地钩子、校验、转换或审计失败时附加 hostError。
413
+ * 随 canonical 结果持久化;不直接上 Provider wire,不从历史中推断不存在的事实。
414
+ */
415
+ execution?: ToolResultExecution;
274
416
  }
275
417
  interface ThinkingBlock {
276
418
  type: 'thinking';
@@ -383,6 +525,11 @@ interface StepLogEntry {
383
525
  * 不应直接把本类型当作长期兼容的网络协议。
384
526
  */
385
527
  type SessionEvent = {
528
+ type: 'skill_loaded';
529
+ source: SkillContentSource;
530
+ messageId: string;
531
+ persistence: 'memory' | 'disk';
532
+ } | {
386
533
  type: 'session_resumed';
387
534
  conversationId: string;
388
535
  runtimeSessionId: string;
@@ -484,6 +631,13 @@ type SessionEvent = {
484
631
  usage?: Usage;
485
632
  ttftMs?: number;
486
633
  durationMs?: number;
634
+ } | {
635
+ type: 'mcp_prompt_loaded';
636
+ server: string;
637
+ name: string;
638
+ persistence: 'disk' | 'memory';
639
+ promptSource: PromptContentSource;
640
+ runId?: string;
487
641
  } | {
488
642
  type: 'turn_finish';
489
643
  turn: number;
@@ -1022,7 +1176,7 @@ declare class ContextManager {
1022
1176
  private publishSnapshot;
1023
1177
  /** 最终请求与只读估算共用来源和状态计数。 */
1024
1178
  private buildSnapshot;
1025
- /** 摘要以用户历史背景注入,不升级为系统指令或恢复旧授权。 */
1179
+ /** 摘要与技能重载事实由已验证原历史生成,不升级为系统指令或恢复旧授权;旧检查点同样适用。 */
1026
1180
  private summaryMessage;
1027
1181
  /**
1028
1182
  * 旧轮次仅在工具事务闭合时可摘要;成功可由旧记录推断,失败或中断必须有运行终态来源。
@@ -1273,37 +1427,89 @@ interface InstructionLoadOptions {
1273
1427
  */
1274
1428
  declare function loadInstructions(options: InstructionLoadOptions): InstructionSnapshot;
1275
1429
 
1276
- /** 受支持的解释器家族;wsl 是 Windows 上的 WSL bash launcher,路径与输出语义与 native bash 不同。 */
1277
- type ShellKind = 'bash' | 'wsl' | 'pwsh' | 'powershell';
1278
- /** auto / 具名解释器,或用户显式提供的解释器可执行文件全路径。 */
1279
- type ShellPreference = 'auto' | ShellKind | (string & {});
1280
- /** 探测成功后固定的解释器身份;executableDigest 参与命令审批指纹,解释器被替换即失配。 */
1281
- interface ShellEnvironment {
1282
- kind: ShellKind;
1283
- executable: string;
1284
- executableDigest: string;
1285
- cwd: string;
1430
+ /** 安全名称语法;不接受厂商命名空间、路径或连续连字符。 */
1431
+ declare function isSkillName(value: string): boolean;
1432
+ /** 解析常用 Frontmatter 子集;格式错误抛出,未知执行扩展返回不可执行诊断,正文不截断。 */
1433
+ declare function parseSkillDocument(content: string, filePath: string): SkillDocument;
1434
+
1435
+ /** 技能错误仅返回受控文案;retryPolicy 不触发工具内部重试。 */
1436
+ declare function skillFailure(code: string, message: string): KapibalaError;
1437
+ /** 以路径段判断物理边界,允许边界自身但不接受越界或其他盘符。 */
1438
+ declare function isWithinSkillRoot(root: string, target: string): boolean;
1439
+ /** Windows 物理身份忽略盘符/路径大小写,其他平台维持文件系统原义。 */
1440
+ declare function skillPathKey(value: string): string;
1441
+ /** 按 code point 排序,不使用受语言区域影响的比较器。 */
1442
+ declare function compareSkillPaths(left: string, right: string): number;
1443
+ /** 有界 UTF-8 读取;先检查文件类型/大小,增长中的文件也不能突破上限。 */
1444
+ declare function readBoundedSkillText(filePath: string, maximum: number, signal?: AbortSignal): Promise<string>;
1445
+ /** 原文件字节摘要;有效 UTF-8 的重新编码保留 BOM 与换行,不使用规范化正文替代。 */
1446
+ declare function skillDigest(content: string): string;
1447
+ /** 单根发现结果;诊断可包含无效候选,扫描结束后只保留元数据,不常驻正文。 */
1448
+ interface SkillScanResult {
1449
+ skills: SkillMetadata[];
1450
+ diagnostics: SkillDiagnostic[];
1451
+ }
1452
+ /** 扫描单根的技能边界;有界异步遍历,项目未声明信任时实体只供宿主诊断。 */
1453
+ declare function scanSkillRoot(root: SkillRoot, signal?: AbortSignal): Promise<SkillScanResult>;
1454
+
1455
+ /** 使用现有 Unicode 估算器计完整文本,非 ASCII 不按四字符折算。 */
1456
+ declare function estimateSkillTokens(text: string): number;
1457
+ /** 技能元数据的 XML 转义;不把未转义的描述或路径当作目录结构。 */
1458
+ declare function escapeSkillXml(text: string): string;
1459
+ /** 完整目录投影及遗漏统计;text 为空表示最小目录也无法容纳。 */
1460
+ interface SkillCatalog {
1461
+ text: string;
1462
+ included: number;
1463
+ omitted: number;
1464
+ estimatedTokens: number;
1465
+ }
1466
+ /** 生成确定性 L2.5;预算含标题、XML、转义及遗漏提示,只删完整条目。 */
1467
+ declare function formatSkillCatalog(skills: readonly SkillMetadata[], contextWindow?: number, remainingTokens?: number): SkillCatalog;
1468
+ /** 模型目录分页输入;游标只定位快照,不提供信任或正文访问授权。 */
1469
+ interface SkillQuery {
1470
+ query?: string;
1471
+ cursor?: string;
1472
+ limit?: number;
1473
+ }
1474
+ /** 有界模型元数据页;不包含正文,游标按实际返回条目推进。 */
1475
+ interface SkillQueryPage {
1476
+ skills: {
1477
+ name: string;
1478
+ description: string;
1479
+ scope: string;
1480
+ argumentHint?: string;
1481
+ }[];
1482
+ total: number;
1483
+ nextCursor?: string;
1286
1484
  }
1287
- interface ShellDetectOptions {
1288
- /** 'auto'、具名解释器,或解释器可执行文件全路径;含路径分隔符或 .exe 后缀按显式路径处理。 */
1289
- preference?: ShellPreference;
1290
- /** 探测与后续执行的基准目录;探测前先取 realpath,符号链接会被展开。 */
1291
- cwd: string;
1292
- /** 以下两项供测试注入平台与 PATH;缺省取当前进程的值。 */
1293
- platform?: NodeJS.Platform;
1294
- pathEnv?: string;
1485
+
1486
+ /** 确定性技能注册表;刷新原子替换快照,运行中加载必须与发现指纹一致。 */
1487
+ declare class SkillRegistry {
1488
+ private readonly options;
1489
+ private definitions;
1490
+ private warnings;
1491
+ private revisionValue;
1492
+ /** 固定宿主配置副本,外部对象变更不能静默改变本轮发现或信任。 */
1493
+ constructor(options: SkillOptions);
1494
+ /** 获取独立诊断副本,调用方不能修改生效候选或权限。 */
1495
+ get diagnostics(): SkillDiagnostic[];
1496
+ /** 快照游标身份随正文、来源、可用性变化而失效。 */
1497
+ get revision(): string;
1498
+ /** 是否由宿主启用;关闭只影响本次能力,不删除历史或文件。 */
1499
+ get enabled(): boolean;
1500
+ /** 每轮开始重新发现;取消不发布半个快照,非法单文件只产生诊断。 */
1501
+ refresh(signal?: AbortSignal): Promise<void>;
1502
+ /** 按名称查询胜出元数据副本;未知名称返回 undefined,正文仅由 load 校验后懒读取。 */
1503
+ get(name: string): SkillMetadata | undefined;
1504
+ /** 宿主可检查不可用条目;模型/用户视图分别施加调用控制,均不读取正文。 */
1505
+ list(caller?: 'host' | 'model' | 'user', query?: string): SkillMetadata[];
1506
+ /** 按当前快照校验调用控制与物理身份,不接受模型提供的信任或 caller 升级。 */
1507
+ load(name: string, caller: 'model' | 'user', signal?: AbortSignal): Promise<SkillDefinition>;
1508
+ /** 查询可信模型集合;过期游标可修正,预算不足不返回不前进的分页。 */
1509
+ queryModel(input?: SkillQuery, remainingTokens?: number): SkillQueryPage;
1510
+ /** 复核配置根、词法发现路径和原文件字节,返回本次有界读取文本;漂移要求新运行,不能热替换。 */
1511
+ verify(skill: SkillMetadata, signal?: AbortSignal): Promise<string>;
1295
1512
  }
1296
- /**
1297
- * 按 uname 输出分类 bash 家族:Git Bash/MSYS2/Cygwin 归 native bash,
1298
- * Windows 上报告 Linux 的是 WSL launcher(独立 kind,路径语义不同)。
1299
- */
1300
- declare function classifyBashOutput(unameOutput: string, platform: NodeJS.Platform): ShellKind | undefined;
1301
- /**
1302
- * 发现并固定实际解释器:只用 PATH 与用户显式给出的路径,不写死任何安装目录。
1303
- * auto 在 Windows 上按 native Bash → WSL → pwsh → powershell 依次兜底,
1304
- * bash 家族用运行时 uname 探针区分 Git Bash 与 WSL launcher。
1305
- */
1306
- declare function detectShell(options: ShellDetectOptions): ShellEnvironment;
1307
1513
 
1308
1514
  /** 本次会话的自动执行边界;FullAccess 只能由宿主为本次会话显式选择。 */
1309
1515
  type SessionMode = 'Approval' | 'Plan' | 'Auto' | 'FullAccess';
@@ -1368,7 +1574,28 @@ declare class PermissionPolicy {
1368
1574
  declare function visibleTools(tools: readonly Tool[], mode: SessionMode, rules?: readonly PermissionRule[]): Tool[];
1369
1575
 
1370
1576
  /** 执行能力的最小分类;权限规则、模式裁决与工具元数据声明共用这一词汇表。 */
1371
- type Capability = 'fs:read' | 'fs:write' | 'exec' | 'net:outbound' | 'env:read' | 'agent:spawn';
1577
+ type Capability = 'fs:read' | 'fs:write' | 'exec' | 'net:outbound' | 'env:read' | 'agent:spawn' | 'external:call';
1578
+ /**
1579
+ * 外部调用的精确执行身份;供审批缓存、发送前复核与审计消费。
1580
+ * 包含服务端物理身份、连接代次、目录 epoch 与定义摘要等不可伪造字段。
1581
+ */
1582
+ interface ToolExecutionIdentity {
1583
+ serverIdentity?: string;
1584
+ connectionGeneration?: number;
1585
+ catalogEpoch?: number;
1586
+ toolDigest?: string;
1587
+ [key: string]: unknown;
1588
+ }
1589
+ /**
1590
+ * 显式 opt-in 规范化执行结果;普通对象返回值保持兼容不强制包装。
1591
+ */
1592
+ interface ToolExecutionResult {
1593
+ content: string;
1594
+ isError?: boolean;
1595
+ errorCode?: string;
1596
+ retryPolicy?: 'never' | 'after_user_action';
1597
+ execution?: ToolResultExecution;
1598
+ }
1372
1599
  interface ToolMetadata {
1373
1600
  /** 注册来源标记(如 'builtin');注册表据此执行冲突策略并支持按源注销。 */
1374
1601
  source?: string;
@@ -1378,6 +1605,8 @@ interface ToolMetadata {
1378
1605
  permissions?: Capability[];
1379
1606
  /** 工具自身等待进程资源回收,执行器不可再使用通用 Promise.race 超时。 */
1380
1607
  managesTimeout?: boolean;
1608
+ /** 只读提示;工具声明自身无副作用,供 UI 展示与只读过滤参考。 */
1609
+ readOnlyHint?: boolean;
1381
1610
  }
1382
1611
  /** 工具执行期由宿主注入的运行环境;信号取消后工具应尽快清理在途资源再返回。 */
1383
1612
  interface ToolContext {
@@ -1392,6 +1621,13 @@ interface ToolContext {
1392
1621
  outputBytes: number;
1393
1622
  }) => void;
1394
1623
  }
1624
+ /**
1625
+ * 工具输入参数校验结果;valid 为 false 或抛出异常均阻止审批和发送。
1626
+ */
1627
+ interface ToolInputValidation {
1628
+ valid: boolean;
1629
+ message?: string;
1630
+ }
1395
1631
  /** 工具契约;parameters 是 JSON Schema,模型只能看到经 toToolDefinition 投影后的三个字段。 */
1396
1632
  interface Tool<TInput = Record<string, unknown>, TOutput = unknown> {
1397
1633
  readonly name: string;
@@ -1400,6 +1636,12 @@ interface Tool<TInput = Record<string, unknown>, TOutput = unknown> {
1400
1636
  readonly metadata?: ToolMetadata;
1401
1637
  /** 声明本次输入的精确执行目标,供审批展示与执行前指纹复核;无固定执行目标的工具不实现。 */
1402
1638
  approvalScope?(input: TInput, rootDir: string): ShellScope;
1639
+ /** 本次执行身份;审批缓存与执行前复核消费,缺省保持旧工具规则。 */
1640
+ executionIdentity?(input: TInput, rootDir: string): ToolExecutionIdentity;
1641
+ /** 无副作用地校验最终参数,不修改参数、不访问远端;异常与拒绝均阻止审批和发送。 */
1642
+ validateInput?(input: TInput): ToolInputValidation | undefined;
1643
+ /** 显式 opt-in 转换为标准执行结果;未提供时普通返回值继续作为常规输出。 */
1644
+ toExecutionResult?(raw: TOutput): ToolExecutionResult;
1403
1645
  execute(input: TInput, ctx: ToolContext): Promise<TOutput>;
1404
1646
  }
1405
1647
  /** 恒等构造器:只为工具实现提供类型推断与统一书写形式,不产生任何运行时包装。 */
@@ -1407,75 +1649,32 @@ declare function defineTool<TInput = Record<string, unknown>, TOutput = unknown>
1407
1649
  /** 投影为模型可见的工具描述;刻意丢弃 metadata 与 approvalScope,执行侧信息不进入协议。 */
1408
1650
  declare function toToolDefinition(tool: Tool): ToolDefinition;
1409
1651
 
1410
- /** run_command 的输入;cwd 相对工作区根解析,timeout_ms 合法区间 1..600000,越界在执行前失败。 */
1411
- interface RunCommandInput {
1412
- [key: string]: unknown;
1413
- command: string;
1414
- cwd?: string;
1415
- timeout_ms?: number;
1416
- }
1417
- /** 命令执行结果;output 只是内联前缀,完整输出超过内联上限的部分落盘为受管结果文件。 */
1418
- interface CommandResult {
1419
- /** 进程正常退出时的退出码;被信号终止时为 null。 */
1420
- exitCode: number | null;
1421
- /** stdout 与 stderr 交错合并的文本,最多前 64 KiB(按 UTF-8 字符边界截断)。 */
1422
- output: string;
1423
- /** output 并非全部输出的标志;超出内联上限的完整内容写入 outputFile。 */
1424
- outputTruncated: boolean;
1425
- /** 受管结果文件路径(工作区内 .kapibala/tool-results/),仅输出超过内联上限时存在。 */
1426
- outputFile?: string;
1427
- /** 结果文件触及 16 MiB 上限后被截断的标志。 */
1428
- outputFileTruncated: boolean;
1429
- /** 两个流产生的原始字节总数(不受截断影响),供进度与审计使用。 */
1430
- outputBytes: number;
1431
- shell: ShellEnvironment['kind'];
1432
- }
1433
- /** 仅清理受管 UUID 文件,避免删除用户在同目录保存的结果。 */
1434
- declare function cleanupCommandResults(rootDir: string, now?: number): void;
1435
- /** 使用固定解释器执行命令;超时和中止必须先处理进程树再返回。 */
1436
- declare function createRunCommandTool(environment: ShellEnvironment): Tool<RunCommandInput, CommandResult>;
1652
+ /** 归一化技能白名单;参数模式/未知名称不得退化成宽泛命令授权。 */
1653
+ declare function normalizeSkillTools(skill: SkillDefinition, tools: readonly Tool[]): ReadonlySet<string> | undefined;
1654
+ /** 多活动技能白名单取交集;未声明不参与,空集合不等于无限制。 */
1655
+ declare function intersectSkillTools(activations: Iterable<Pick<SkillActivation, 'allowedTools'>>): ReadonlySet<string> | undefined;
1437
1656
 
1438
- /** 路径沙箱配置;rootDir 是所有文件访问的词法与物理边界。 */
1439
- interface SandboxConfig {
1440
- rootDir: string;
1441
- /**
1442
- * v0.0.1 恒为严格模式:任何解析后落在 rootDir 之外的物理路径一律拒绝,
1443
- * 不存在 fail-open 开关。该字段为 v0.0.2 权限引擎预留,当前不改变校验行为。
1444
- */
1445
- allowSymlinks?: boolean;
1446
- }
1447
- /**
1448
- * 把文件访问限制在 rootDir 内:先做词法归一化检查,再展开符号链接做物理检查,两层都通过才放行。
1449
- * 实例会缓存 rootDir 的物理路径,应按 rootDir 复用实例,而不是每次调用新建。
1450
- */
1451
- declare class PathSandbox {
1452
- readonly rootDir: string;
1453
- readonly allowSymlinks: boolean;
1454
- private cachedRealRootDir?;
1455
- constructor(config: SandboxConfig);
1456
- /**
1457
- * rootDir 的物理路径。rootDir 自身可能是一个符号链接(如 macOS 的 /var → /private/var),
1458
- * 必须先归一化,否则物理路径与 rootDir 比较时会产生误判。
1459
- */
1460
- private get realRootDir();
1461
- /**
1462
- * 检查并解析安全路径
1463
- * 1. 解析相对路径为相对于 rootDir 的绝对路径
1464
- * 2. 词法检查:`..` 归一化后必须仍在 rootDir 内
1465
- * 3. 物理检查:解析符号链接后的真实路径必须仍在 rootDir 内
1466
- */
1467
- resolveSafePath(targetPath: string): string;
1468
- /**
1469
- * 把词法路径映射为物理路径。
1470
- *
1471
- * 关键点在于**向上回溯到最近一个真实存在的祖先**再取 realpath,然后把尚未存在的尾段拼回去:
1472
- * - 目标已存在 → 直接 realpath,符号链接立刻被展开;
1473
- * - 目标不存在(典型场景:write_file 新建文件) → 若只看目标本身,所有校验都会被跳过,
1474
- * 于是 `write_file('linkDir/new.txt')` 可以借道指向外部的 linkDir 越界写入。
1475
- * 回溯到 linkDir 取 realpath 即可识破这种穿透。
1476
- */
1477
- private toPhysicalPath;
1657
+ /** 受控文本范围;offset 用于 UTF-8 大行续读,不能与行范围混用。 */
1658
+ interface SkillResourceInput {
1659
+ name: string;
1660
+ path: string;
1661
+ startLine?: number;
1662
+ endLine?: number;
1663
+ offset?: number;
1478
1664
  }
1665
+ /** 只读资源页;nextOffset 是完整 UTF-8 字符边界,不代表文件执行授权。 */
1666
+ interface SkillResourcePage {
1667
+ text: string;
1668
+ truncated: boolean;
1669
+ nextOffset?: number;
1670
+ }
1671
+ /** 读取技能根内文本;复核物理边界,有界返回并关闭文件,不扩大普通文件沙箱。 */
1672
+ declare function readSkillResource(skill: SkillDefinition, input: SkillResourceInput, signal?: AbortSignal): Promise<SkillResourcePage>;
1673
+ /** 限量列出包内资源名而不读取正文;外部链接、默认忽略目录及深层资源不展开。 */
1674
+ declare function listSkillResources(skill: SkillDefinition, signal?: AbortSignal): Promise<{
1675
+ files: string[];
1676
+ truncated: boolean;
1677
+ }>;
1479
1678
 
1480
1679
  /**
1481
1680
  * 人工审批的五选一结果。allow_once / deny_once 只作用于本次执行;
@@ -1490,6 +1689,10 @@ interface ApprovalRequest {
1490
1689
  input: Record<string, unknown>;
1491
1690
  rootDir: string;
1492
1691
  shell?: ShellScope;
1692
+ /**
1693
+ * 本次调用的外部执行身份;深度哈希纳入审批缓存键,断连重连或目录变更后旧会话批准自动失效。
1694
+ */
1695
+ executionIdentity?: ToolExecutionIdentity;
1493
1696
  /** 宿主是否允许本次请求写入会话级允许缓存;deny_session 的缓存不受此限制。 */
1494
1697
  sessionAllowed: boolean;
1495
1698
  }
@@ -1509,71 +1712,70 @@ declare class SessionApprovalCache {
1509
1712
 
1510
1713
  /** 同名工具冲突策略:error 直接抛错;prefer-builtin 保留既有内置注册;prefer-last 后到者覆盖。 */
1511
1714
  type ConflictPolicy = 'error' | 'prefer-builtin' | 'prefer-last';
1715
+ /**
1716
+ * 不可变工具注册表快照;捕获特定时刻的工具定义、执行引用与版本。
1717
+ * 外部注册表后续的增删改绝不改写已有快照视图。
1718
+ */
1719
+ interface ToolRegistrySnapshot {
1720
+ readonly version: number;
1721
+ get(name: string): Tool | undefined;
1722
+ has(name: string): boolean;
1723
+ resolve(name: string): Tool;
1724
+ list(): Tool[];
1725
+ definitions(): ToolDefinition[];
1726
+ sourceOf(name: string): string | undefined;
1727
+ }
1512
1728
  /**
1513
1729
  * 按名称索引的工具注册表。冲突按构造时给定的策略处理,胜出条目的来源标签保持不变;
1514
- * 来源标签支持按源批量注册与注销,注销只移除以该标签注册的工具,不回收冲突中保留的内置实现。
1730
+ * 支持原子来源替换(replaceSource)、不可变运行快照(snapshot)与来源注销。
1515
1731
  */
1516
1732
  declare class ToolRegistry {
1517
1733
  private readonly tools;
1518
1734
  private readonly toolSources;
1519
1735
  private readonly conflictPolicy;
1736
+ private version;
1520
1737
  constructor(options?: {
1521
1738
  conflictPolicy?: ConflictPolicy;
1522
1739
  });
1740
+ /** 获取当前注册表版本号;每次有效变更(注册、替换、注销)单调自增。 */
1741
+ get currentVersion(): number;
1523
1742
  register(tool: Tool, opts?: {
1524
1743
  source?: string;
1525
1744
  }): void;
1745
+ /**
1746
+ * 原子替换指定来源的全部工具:
1747
+ * 1. 预检候选批内自身重名:若候选批次内包含同名工具,整批拒绝;
1748
+ * 2. 预检跨来源冲突:若候选工具被其它来源占用且策略不允许覆盖,整批拒绝;
1749
+ * 3. 同步原子提交:预检全部通过后一次性清理该来源旧工具并写入新工具;失败时完全保持旧状态不变。
1750
+ */
1751
+ replaceSource(source: string, tools: Tool[]): void;
1752
+ /**
1753
+ * 注册指定来源的工具集。
1754
+ *
1755
+ * 语义与约束:
1756
+ * 1. 委托给 `replaceSource` 实现整源原子替换(新集合未包含的该来源旧工具将被注销移除,非增量累加);
1757
+ * 2. 默认禁止跨来源名称冲突(抛出 KapibalaError TOOL_CONFLICT);若 options 配置了 conflictPolicy: 'prefer-last' 则允许覆盖旧来源同名工具;
1758
+ * 3. 预检阶段发现批内同名重复时整批拒绝,绝不破坏注册表原子状态。
1759
+ */
1526
1760
  registerSource(source: string, tools: Tool[]): void;
1527
1761
  unregisterSource(source: string): void;
1528
1762
  get(name: string): Tool | undefined;
1763
+ has(name: string): boolean;
1764
+ /** 获取工具对应的来源标记。 */
1765
+ sourceOf(name: string): string | undefined;
1766
+ /** 注销指定名称及来源记录;调用方须核对实例身份,不能移除同名替代工具。 */
1767
+ unregister(name: string): void;
1529
1768
  /** 未命中时抛 ToolNotFound,并携带当前全部可用名称辅助模型自纠。 */
1530
1769
  resolve(name: string): Tool;
1531
1770
  list(): Tool[];
1532
1771
  definitions(): ToolDefinition[];
1772
+ /**
1773
+ * 捕获当前注册表的不可变只读快照。
1774
+ * 注册表后续的增删改绝不改变该快照的定义列表、工具执行实例与来源版本。
1775
+ */
1776
+ snapshot(): ToolRegistrySnapshot;
1533
1777
  }
1534
1778
 
1535
- declare const readFileTool: Tool<{
1536
- path: string;
1537
- startLine?: number;
1538
- endLine?: number;
1539
- }, string>;
1540
- declare const writeFileTool: Tool<{
1541
- path: string;
1542
- content: string;
1543
- }, string>;
1544
- declare const editFileTool: Tool<{
1545
- path: string;
1546
- targetContent: string;
1547
- replacementContent: string;
1548
- }, string>;
1549
- declare const globTool: Tool<{
1550
- pattern: string;
1551
- subDirectory?: string;
1552
- }, string>;
1553
- declare const grepTool: Tool<{
1554
- pattern: string;
1555
- path?: string;
1556
- }, string>;
1557
- /** 五个内置文件工具的聚合;全部经 PathSandbox 校验,路径越界或符号链接穿透一律拒绝。 */
1558
- declare const builtinTools: (Tool<{
1559
- path: string;
1560
- startLine?: number;
1561
- endLine?: number;
1562
- }, string> | Tool<{
1563
- path: string;
1564
- content: string;
1565
- }, string> | Tool<{
1566
- path: string;
1567
- targetContent: string;
1568
- replacementContent: string;
1569
- }, string> | Tool<{
1570
- pattern: string;
1571
- subDirectory?: string;
1572
- }, string> | Tool<{
1573
- pattern: string;
1574
- path?: string;
1575
- }, string>)[];
1576
-
1577
1779
  /**
1578
1780
  * 运行时钩子契约:宿主与插件在固定切点观察或调整流程。
1579
1781
  * 通知型切点由 HookRegistry.emit 串行触发;需要返回值的 model:before / tool:before
@@ -1639,26 +1841,20 @@ declare class HookRegistry {
1639
1841
  emit<K extends 'session:start' | 'session:end' | 'model:after' | 'tool:after' | 'error'>(point: K, ctx: HookContext, ...args: any[]): Promise<void>;
1640
1842
  }
1641
1843
 
1642
- /** setup 收到的能力入口;tools / hooks 是会话共享的注册表,注册的条目影响后续所有执行。 */
1643
- interface PluginContext {
1644
- readonly tools: ToolRegistry;
1645
- readonly hooks: HookRegistry;
1646
- /** 本次会话的绝对工具根目录;工具的路径解析与审批都以此为基准。 */
1647
- readonly rootDir: string;
1648
- readonly logger?: (msg: string) => void;
1649
- }
1650
- /** 插件生命周期:setup 在会话空闲时挂载执行一次,teardown 在会话销毁时逐个调用以回收资源。 */
1651
- interface AgentPlugin {
1652
- /** 用于挂载失败与 teardown 的诊断信息。 */
1653
- readonly name: string;
1654
- readonly version?: string;
1655
- setup(ctx: PluginContext): void | Promise<void>;
1656
- teardown?(): void | Promise<void>;
1657
- }
1658
-
1659
1844
  /** ToolExecutor 的构造项;审计写入需要 eventLogger 与 sessionId 同时提供,否则不产生审计。 */
1845
+ /** 宿主运行级硬限制;优先于模式、审批及缓存,文案和字段不得携带凭据。 */
1846
+ interface ToolHardDenial {
1847
+ code: string;
1848
+ message: string;
1849
+ retryPolicy: ToolResultBlock['retryPolicy'];
1850
+ fields?: Record<string, unknown>;
1851
+ }
1660
1852
  interface ExecutorOptions {
1661
- tools: ToolRegistry;
1853
+ /** 在最终参数上补充硬拒绝,不能把拒绝转为授权。 */
1854
+ hardDenial?: (tool: Tool, input: Record<string, unknown>) => ToolHardDenial | undefined;
1855
+ /** 结果钩子和执行审计完成后调用;用于在同批次下一调用前安装宿主收紧状态。 */
1856
+ onToolResult?: (tool: Tool, input: Record<string, unknown>, result: ToolResultBlock) => void | Promise<void>;
1857
+ tools: ToolRegistry | ToolRegistrySnapshot;
1662
1858
  hooks: HookRegistry;
1663
1859
  /** 工具执行的绝对根目录;路径解析与审批均以此为基准。 */
1664
1860
  rootDir: string;
@@ -1684,6 +1880,8 @@ interface ExecutorOptions {
1684
1880
  * 同一 run 内参数完全相同的 never 失败会被拒绝重复执行。
1685
1881
  */
1686
1882
  declare class ToolExecutor {
1883
+ private readonly hardDenial?;
1884
+ private readonly onToolResult?;
1687
1885
  private readonly tools;
1688
1886
  private readonly hooks;
1689
1887
  private readonly rootDir;
@@ -1703,13 +1901,16 @@ declare class ToolExecutor {
1703
1901
  constructor(options: ExecutorOptions);
1704
1902
  /** 中止本轮正在等待或执行的工具;调用方仍须等待 runAll 完成资源回收及结果审计。 */
1705
1903
  cancel(): void;
1706
- /** 串行执行全部调用并返回与入参顺序一致的结果;某个结果要求用户介入后,其余调用直接拒绝。 */
1904
+ /**
1905
+ * 串行执行全部调用并返回与入参顺序一致的结果;某个结果要求用户介入后,其余调用直接拒绝。
1906
+ * onResult 在每个最终结果(含拒绝/失败)产生后提供独立快照,供在途预算估算,不代表历史已提交;回调不得抛错。
1907
+ */
1707
1908
  runAll(calls: ToolUseBlock[], onProgress?: (event: {
1708
1909
  id: string;
1709
1910
  name: string;
1710
1911
  elapsedMs: number;
1711
1912
  outputBytes: number;
1712
- }) => void): Promise<ToolResultBlock[]>;
1913
+ }) => void, onResult?: (result: ToolResultBlock) => void): Promise<ToolResultBlock[]>;
1713
1914
  /**
1714
1915
  * 在最终参数上裁决并审计一次调用,所有拒绝和异常均闭合为工具结果。
1715
1916
  * 为调用记录本次绝对工具根目录,供跨目录恢复后的文件事实解析;不使用历史目录授权。
@@ -1731,6 +1932,280 @@ declare class ToolExecutor {
1731
1932
  private withTimeout;
1732
1933
  }
1733
1934
 
1935
+ /** 加载预检结果;只有最终成功工具结果或真实用户消息提交后才形成活动资格。 */
1936
+ interface PreparedSkill {
1937
+ /** 本轮完整正文仍可见时只引用,引用结果不附完整正文来源。 */
1938
+ alreadyPresent?: boolean;
1939
+ definition: SkillDefinition;
1940
+ source: SkillContentSource;
1941
+ text: string;
1942
+ allowedTools?: ReadonlySet<string>;
1943
+ }
1944
+ /** 会话内技能运行状态;控制工具按实例身份识别,pending 只收紧而不授予资源。 */
1945
+ declare class SkillRuntime {
1946
+ readonly registry: SkillRegistry;
1947
+ private readonly tools;
1948
+ private readonly onResourceRead?;
1949
+ readonly loaderTool: Tool;
1950
+ readonly queryTool: Tool;
1951
+ readonly resourceTool: Tool;
1952
+ private readonly controls;
1953
+ private readonly prepared;
1954
+ private readonly active;
1955
+ private runId;
1956
+ private history;
1957
+ private projection;
1958
+ private reservedTokens;
1959
+ private remaining;
1960
+ /** 注册表和工具集合属于一个Session;不跨会话共享授权或隐式目录。 */
1961
+ constructor(registry: SkillRegistry, tools: ToolRegistry, onResourceRead?: ((source: SkillContentSource, input: SkillResourceInput, page: SkillResourcePage) => Promise<void>) | undefined);
1962
+ /**
1963
+ * 开始新运行;历史正文只作事实,必须由本轮加载重新激活。
1964
+ * remaining 必须扣除在途 assistant 和普通工具结果;尚未提交的成功技能正文由本类独立预留,不重复扣除。
1965
+ */
1966
+ begin(runId: string, history: () => readonly CanonicalMessage[], remaining: () => number, projection?: () => readonly CanonicalMessage[]): void;
1967
+ /** 按实际集合安装实例工具;同名插件不覆盖为受信任工具,也不能制造目录引导。 */
1968
+ syncTools(): void;
1969
+ /** 清空本轮状态;调用方必须先等待工具和历史事务清理,不能提前释放会话锁。 */
1970
+ clear(): void;
1971
+ /** 查询本轮活动状态副本,避免宿主修改限制。 */
1972
+ get activations(): SkillActivation[];
1973
+ /** 预检正文、限制和输入空间;调用方由宿主固定,不读取模型伪造caller。 */
1974
+ prepare(name: string, caller: 'model' | 'user', signal?: AbortSignal): Promise<PreparedSkill>;
1975
+ /** 真实用户入口安装pending;正文需进入用户消息,提交前不提供资源。 */
1976
+ acceptUser(prepared: PreparedSkill): void;
1977
+ /** 最终工具结果通过执行器钩子/审计后安装收紧;同名或仿造结果不激活。 */
1978
+ acceptResult(tool: Tool, result: ToolResultBlock): void;
1979
+ /** 业务调用的动态硬拒绝;控制工具仅按实例豁免,仍须宿主权限裁决。 */
1980
+ denial(tool: Tool): ToolHardDenial | undefined;
1981
+ /** 完整消息提交后记录审计再发布事件;失败不回滚历史,但不提交资源资格。 */
1982
+ commit(audit: (source: SkillContentSource, messageId: string) => Promise<void>, persistence: 'memory' | 'disk'): Promise<SessionEvent[]>;
1983
+ /** 检查最终模型投影的完整活动指导;钩子或压缩不能移走后继续执行。 */
1984
+ assertProjection(messages: readonly CanonicalMessage[]): void;
1985
+ /** 只读本轮已提交技能资源;文件/来源漂移要求重新开始,不重放脚本。 */
1986
+ readResource(input: SkillResourceInput, signal?: AbortSignal): Promise<SkillResourcePage>;
1987
+ }
1988
+
1989
+ /** 技能正文在实际投影中的状态;来源只关联事实,present 不代表当前运行获得授权。 */
1990
+ interface SkillContextState {
1991
+ source: SkillContentSource;
1992
+ messageId: string;
1993
+ state: 'present' | 'requires_reload';
1994
+ }
1995
+ /** 查找真实投影中的完整正文来源;字段缺失、未知版本或文本摘要不匹配不用于去重。 */
1996
+ declare function findSkillContent(history: readonly CanonicalMessage[], source: SkillContentSource): {
1997
+ messageId: string;
1998
+ source: SkillContentSource;
1999
+ } | undefined;
2000
+ /** 比较原始来源与真实投影,以最后一次相同文件/版本正文为准;不恢复旧授权或执行动作。 */
2001
+ declare function inspectSkillContent(raw: readonly CanonicalMessage[], projected: readonly CanonicalMessage[]): SkillContextState[];
2002
+ /** 将离开投影的旧正文表示为有界重载事实;最多50条,遗漏数明确,不把历史包装成当前指令。 */
2003
+ declare function renderSkillReloads(covered: readonly CanonicalMessage[]): string;
2004
+
2005
+ /** 受支持的解释器家族;wsl 是 Windows 上的 WSL bash launcher,路径与输出语义与 native bash 不同。 */
2006
+ type ShellKind = 'bash' | 'wsl' | 'pwsh' | 'powershell';
2007
+ /** auto / 具名解释器,或用户显式提供的解释器可执行文件全路径。 */
2008
+ type ShellPreference = 'auto' | ShellKind | (string & {});
2009
+ /** 探测成功后固定的解释器身份;executableDigest 参与命令审批指纹,解释器被替换即失配。 */
2010
+ interface ShellEnvironment {
2011
+ kind: ShellKind;
2012
+ executable: string;
2013
+ executableDigest: string;
2014
+ cwd: string;
2015
+ }
2016
+ interface ShellDetectOptions {
2017
+ /** 'auto'、具名解释器,或解释器可执行文件全路径;含路径分隔符或 .exe 后缀按显式路径处理。 */
2018
+ preference?: ShellPreference;
2019
+ /** 探测与后续执行的基准目录;探测前先取 realpath,符号链接会被展开。 */
2020
+ cwd: string;
2021
+ /** 以下两项供测试注入平台与 PATH;缺省取当前进程的值。 */
2022
+ platform?: NodeJS.Platform;
2023
+ pathEnv?: string;
2024
+ }
2025
+ /**
2026
+ * 按 uname 输出分类 bash 家族:Git Bash/MSYS2/Cygwin 归 native bash,
2027
+ * Windows 上报告 Linux 的是 WSL launcher(独立 kind,路径语义不同)。
2028
+ */
2029
+ declare function classifyBashOutput(unameOutput: string, platform: NodeJS.Platform): ShellKind | undefined;
2030
+ /**
2031
+ * 发现并固定实际解释器:只用 PATH 与用户显式给出的路径,不写死任何安装目录。
2032
+ * auto 在 Windows 上按 native Bash → WSL → pwsh → powershell 依次兜底,
2033
+ * bash 家族用运行时 uname 探针区分 Git Bash 与 WSL launcher。
2034
+ */
2035
+ declare function detectShell(options: ShellDetectOptions): ShellEnvironment;
2036
+
2037
+ /** run_command 的输入;cwd 相对工作区根解析,timeout_ms 合法区间 1..600000,越界在执行前失败。 */
2038
+ interface RunCommandInput {
2039
+ [key: string]: unknown;
2040
+ command: string;
2041
+ cwd?: string;
2042
+ timeout_ms?: number;
2043
+ }
2044
+ /** 命令执行结果;output 只是内联前缀,完整输出超过内联上限的部分落盘为受管结果文件。 */
2045
+ interface CommandResult {
2046
+ /** 进程正常退出时的退出码;被信号终止时为 null。 */
2047
+ exitCode: number | null;
2048
+ /** stdout 与 stderr 交错合并的文本,最多前 64 KiB(按 UTF-8 字符边界截断)。 */
2049
+ output: string;
2050
+ /** output 并非全部输出的标志;超出内联上限的完整内容写入 outputFile。 */
2051
+ outputTruncated: boolean;
2052
+ /** 受管结果文件路径(工作区内 .kapibala/tool-results/),仅输出超过内联上限时存在。 */
2053
+ outputFile?: string;
2054
+ /** 结果文件触及 16 MiB 上限后被截断的标志。 */
2055
+ outputFileTruncated: boolean;
2056
+ /** 两个流产生的原始字节总数(不受截断影响),供进度与审计使用。 */
2057
+ outputBytes: number;
2058
+ shell: ShellEnvironment['kind'];
2059
+ }
2060
+ /** 仅清理受管 UUID 文件,避免删除用户在同目录保存的结果。 */
2061
+ declare function cleanupCommandResults(rootDir: string, now?: number): void;
2062
+ /** 使用固定解释器执行命令;超时和中止必须先处理进程树再返回。 */
2063
+ declare function createRunCommandTool(environment: ShellEnvironment): Tool<RunCommandInput, CommandResult>;
2064
+
2065
+ /** 路径沙箱配置;rootDir 是所有文件访问的词法与物理边界。 */
2066
+ interface SandboxConfig {
2067
+ rootDir: string;
2068
+ /**
2069
+ * v0.0.1 恒为严格模式:任何解析后落在 rootDir 之外的物理路径一律拒绝,
2070
+ * 不存在 fail-open 开关。该字段为 v0.0.2 权限引擎预留,当前不改变校验行为。
2071
+ */
2072
+ allowSymlinks?: boolean;
2073
+ }
2074
+ /**
2075
+ * 把文件访问限制在 rootDir 内:先做词法归一化检查,再展开符号链接做物理检查,两层都通过才放行。
2076
+ * 实例会缓存 rootDir 的物理路径,应按 rootDir 复用实例,而不是每次调用新建。
2077
+ */
2078
+ declare class PathSandbox {
2079
+ readonly rootDir: string;
2080
+ readonly allowSymlinks: boolean;
2081
+ private cachedRealRootDir?;
2082
+ constructor(config: SandboxConfig);
2083
+ /**
2084
+ * rootDir 的物理路径。rootDir 自身可能是一个符号链接(如 macOS 的 /var → /private/var),
2085
+ * 必须先归一化,否则物理路径与 rootDir 比较时会产生误判。
2086
+ */
2087
+ private get realRootDir();
2088
+ /**
2089
+ * 检查并解析安全路径
2090
+ * 1. 解析相对路径为相对于 rootDir 的绝对路径
2091
+ * 2. 词法检查:`..` 归一化后必须仍在 rootDir 内
2092
+ * 3. 物理检查:解析符号链接后的真实路径必须仍在 rootDir 内
2093
+ */
2094
+ resolveSafePath(targetPath: string): string;
2095
+ /**
2096
+ * 把词法路径映射为物理路径。
2097
+ *
2098
+ * 关键点在于**向上回溯到最近一个真实存在的祖先**再取 realpath,然后把尚未存在的尾段拼回去:
2099
+ * - 目标已存在 → 直接 realpath,符号链接立刻被展开;
2100
+ * - 目标不存在(典型场景:write_file 新建文件) → 若只看目标本身,所有校验都会被跳过,
2101
+ * 于是 `write_file('linkDir/new.txt')` 可以借道指向外部的 linkDir 越界写入。
2102
+ * 回溯到 linkDir 取 realpath 即可识破这种穿透。
2103
+ */
2104
+ private toPhysicalPath;
2105
+ }
2106
+
2107
+ declare const readFileTool: Tool<{
2108
+ path: string;
2109
+ startLine?: number;
2110
+ endLine?: number;
2111
+ }, string>;
2112
+ declare const writeFileTool: Tool<{
2113
+ path: string;
2114
+ content: string;
2115
+ }, string>;
2116
+ declare const editFileTool: Tool<{
2117
+ path: string;
2118
+ targetContent: string;
2119
+ replacementContent: string;
2120
+ }, string>;
2121
+ declare const globTool: Tool<{
2122
+ pattern: string;
2123
+ subDirectory?: string;
2124
+ }, string>;
2125
+ declare const grepTool: Tool<{
2126
+ pattern: string;
2127
+ path?: string;
2128
+ }, string>;
2129
+ /** 五个内置文件工具的聚合;全部经 PathSandbox 校验,路径越界或符号链接穿透一律拒绝。 */
2130
+ declare const builtinTools: (Tool<{
2131
+ path: string;
2132
+ startLine?: number;
2133
+ endLine?: number;
2134
+ }, string> | Tool<{
2135
+ path: string;
2136
+ content: string;
2137
+ }, string> | Tool<{
2138
+ path: string;
2139
+ targetContent: string;
2140
+ replacementContent: string;
2141
+ }, string> | Tool<{
2142
+ pattern: string;
2143
+ subDirectory?: string;
2144
+ }, string> | Tool<{
2145
+ pattern: string;
2146
+ path?: string;
2147
+ }, string>)[];
2148
+
2149
+ /** setup 收到的能力入口;tools / hooks 是会话共享的注册表,注册的条目影响后续所有执行。 */
2150
+ interface PluginContext {
2151
+ readonly tools: ToolRegistry;
2152
+ readonly hooks: HookRegistry;
2153
+ /** 本次会话的绝对工具根目录;工具的路径解析与审批都以此为基准。 */
2154
+ readonly rootDir: string;
2155
+ readonly logger?: (msg: string) => void;
2156
+ }
2157
+ /**
2158
+ * 插件声明的命令贡献描述元数据。
2159
+ *
2160
+ * 约束、边界与为什么:
2161
+ * 1. 纯元数据定义:只包含名称、描述、用法与变更标记,禁止引入 ANSI 渲染、Readline 或 TTY 依赖,坚守 Core Headless 铁律;
2162
+ * 2. 供宿主(CLI/TUI/Web)按需消费并装配到人机交互界面;非交互或 Headless 宿主可安全忽略本字段;
2163
+ * 3. 别名与主名均遵循全小写规范,防止跨平台输入歧义。
2164
+ */
2165
+ interface PluginCommandContribution {
2166
+ /** 命令主名称(不含前导斜杠,如 'mcp' 或 'prompts')。 */
2167
+ readonly name: string;
2168
+ /** 命令用途说明,供帮助菜单展示。 */
2169
+ readonly description: string;
2170
+ /** 格式化调用用法(如 '/mcp [tools <server>]')。 */
2171
+ readonly usage?: string;
2172
+ /** 可选别名列表(如 ['plugin'])。 */
2173
+ readonly aliases?: readonly string[];
2174
+ /** 命令是否产生状态变更;true 表示写操作(受忙碌状态门拦截),false 表示纯只读诊断。 */
2175
+ readonly mutates?: boolean;
2176
+ }
2177
+ /**
2178
+ * 插件声明的扩展贡献元数据聚合容器。
2179
+ *
2180
+ * 约束与边界:
2181
+ * 1. 声明式规范:允许外部扩展包一次性声明技能根目录、交互命令与扩展元数据;
2182
+ * 2. 宿主(CLI)在会话挂载插件时自动读取并完成装配,无需在宿主层硬编码插件内部命令。
2183
+ */
2184
+ interface PluginContribution {
2185
+ /** 插件显式携带或依赖的技能根目录集合(绝对物理路径)。 */
2186
+ readonly skillsRoots?: readonly string[];
2187
+ /** 插件贡献给宿主交互终端的斜杠命令列表。 */
2188
+ readonly commands?: readonly PluginCommandContribution[];
2189
+ }
2190
+ /**
2191
+ * 插件生命周期契约:setup 在会话空闲时挂载执行一次,teardown 在会话销毁时逐个调用以回收资源。
2192
+ * 遵循「一 Session 一插件实例」约束,实现外部生态向 Agent Harness 的受控单向注入。
2193
+ */
2194
+ interface AgentPlugin {
2195
+ /** 插件唯一识别名称,用于诊断输出与依赖追踪。 */
2196
+ readonly name: string;
2197
+ /** 插件语义版本号,默认遵循包版本。 */
2198
+ readonly version?: string;
2199
+ /** 插件用途与功能描述。 */
2200
+ readonly description?: string;
2201
+ /** 插件声明的扩展贡献元数据(命令清单、技能目录等)。 */
2202
+ readonly contributes?: PluginContribution;
2203
+ /** 挂载执行入口;仅在空闲状态调用,可向 tools / hooks 注册能力。 */
2204
+ setup(ctx: PluginContext): void | Promise<void>;
2205
+ /** 销毁回收入口;必须幂等执行,彻底清理进程、网络连接或定时器。 */
2206
+ teardown?(): void | Promise<void>;
2207
+ }
2208
+
1734
2209
  /** Chat 端点配置;能力覆盖只改变请求字段和完成边界,不改变协议身份。 */
1735
2210
  interface OpenAIProviderOptions {
1736
2211
  baseURL: string;
@@ -1866,9 +2341,15 @@ declare class OpenAIResponsesProvider implements ModelProvider {
1866
2341
  private toUsage;
1867
2342
  }
1868
2343
 
2344
+ /** 分层提示选项;目录受实际工具定义和请求剩余空间约束,不能用同名工具冒充加载能力。 */
1869
2345
  interface PromptAssemblerOptions {
2346
+ /** 可信技能快照;仅匹配加载工具实例实际可见时注入L2.5。 */
2347
+ skills?: SkillRegistry;
2348
+ skillLoader?: Tool;
2349
+ contextWindow?: number;
2350
+ skillBudgetTokens?: number;
1870
2351
  /** 提供时才生成 L2 工具清单段;缺省表示本次运行不向模型展示任何工具。 */
1871
- tools?: ToolRegistry;
2352
+ tools?: ToolRegistry | ToolRegistrySnapshot;
1872
2353
  /** L3 环境段展示的工作区根目录;文件工具的沙箱边界与其保持一致。 */
1873
2354
  rootDir: string;
1874
2355
  agentName?: string;
@@ -1884,6 +2365,7 @@ interface PromptAssemblerOptions {
1884
2365
  * 各段之间以 `\n\n---\n\n` 分隔;不提供的内容整段跳过,不做占位填充。
1885
2366
  */
1886
2367
  declare class PromptAssembler {
2368
+ private readonly options;
1887
2369
  private readonly tools?;
1888
2370
  private readonly rootDir;
1889
2371
  private readonly agentName;
@@ -1893,11 +2375,14 @@ declare class PromptAssembler {
1893
2375
  constructor(options: PromptAssemblerOptions);
1894
2376
  /** 按固定层级拼装系统提示词;同一选项集总是产出相同文本,便于审计与缓存。 */
1895
2377
  assemble(): string;
2378
+ /** 返回与 assemble 相同的目录统计;加载器被隐藏、替换或禁用时省略执行目录。 */
2379
+ getSkillCatalog(): SkillCatalog;
1896
2380
  private getL1Behavior;
1897
2381
  private getL2Tools;
1898
2382
  private getL3Environment;
1899
2383
  }
1900
2384
 
2385
+ /** 循环宿主配置;请求投影与在途预算只操作临时视图,历史仍按完整工具事务追加。 */
1901
2386
  interface AgentLoopOptions {
1902
2387
  /** 本次交互身份,内部步骤仍独立编号。 */
1903
2388
  interactionId?: string;
@@ -1910,9 +2395,11 @@ interface AgentLoopOptions {
1910
2395
  prepareRequest?: RequestPreparation;
1911
2396
  /** 每次收到 usage 后回调;attemptId 标识 run:step:attempt,便于按尝试归因。 */
1912
2397
  onUsage?: (request: ModelRequest, usage: Usage, attemptId: string) => Promise<void>;
2398
+ /** 在途批次预算视图;含当前 assistant 和已完成结果,不能作为落盘或授权依据,闭合后清空;回调不得抛错。 */
2399
+ onToolBatchUpdate?: (messages: readonly CanonicalMessage[]) => void;
1913
2400
  provider: ModelProvider;
1914
2401
  executor: ToolExecutor;
1915
- tools: ToolRegistry;
2402
+ tools: ToolRegistry | ToolRegistrySnapshot;
1916
2403
  hooks: HookRegistry;
1917
2404
  systemPrompt?: string;
1918
2405
  /** 单次 run 的最大 turn 数,耗尽时以 error 事件收尾;缺省 20。 */
@@ -1939,6 +2426,7 @@ declare class AgentLoop {
1939
2426
  private readonly projectHistory?;
1940
2427
  private readonly prepareRequest?;
1941
2428
  private readonly onUsage?;
2429
+ private readonly onToolBatchUpdate?;
1942
2430
  private readonly provider;
1943
2431
  private readonly executor;
1944
2432
  private readonly tools;
@@ -1964,8 +2452,32 @@ declare class AgentLoop {
1964
2452
  run(history: CanonicalMessage[]): AsyncIterable<SessionEvent>;
1965
2453
  }
1966
2454
 
2455
+ /**
2456
+ * 任务准备上下文;提供当前会话取消信号、runId 与不可变工具快照。
2457
+ */
2458
+ interface PreparedTaskContext {
2459
+ signal?: AbortSignal;
2460
+ runId: string;
2461
+ tools: ToolRegistrySnapshot;
2462
+ }
2463
+ /**
2464
+ * 任务准备产物;包含要附加到 User 消息的内容块,以及提交前的身份复核回调。
2465
+ */
2466
+ interface PreparedTaskResult {
2467
+ /** 任务附加内容块或纯文本(如 Prompt 内容或技能正文)。 */
2468
+ content: ContentBlock[] | string;
2469
+ /** 可选来源元数据;仅在 content 为 string 时由宿主自动包装为带来源的 TextBlock。 */
2470
+ promptSource?: PromptContentSource;
2471
+ /** 最终提交前核对准备身份;若在此期间目录变化或连接重置,返回 false 拒绝提交并零发送闭合。 */
2472
+ verifyIdentity?: () => boolean | Promise<boolean>;
2473
+ /** 可选技能名称;存在时按显式技能流程处理。 */
2474
+ skillName?: string;
2475
+ }
2476
+
1967
2477
  /** AgentSession 的构造配置;除主任务绑定外均可缺省,缺省行为见各字段。 */
1968
2478
  interface SessionConfig {
2479
+ /** 宿主显式技能配置;缺省不扫描home,项目根需独立信任。 */
2480
+ skills?: SkillOptions;
1969
2481
  /** 持久会话身份;有版本化 Store 时须与头部一致,日志实例身份保持独立。 */
1970
2482
  conversationId?: string;
1971
2483
  tokenEstimator?: TokenEstimator;
@@ -2022,6 +2534,8 @@ interface SessionStats {
2022
2534
  * 运行或清理进行中,改变状态的公开方法一律被拒绝;Core 不承担任何界面职责。
2023
2535
  */
2024
2536
  declare class AgentSession {
2537
+ private readonly skillRegistry?;
2538
+ private readonly skillRuntime?;
2025
2539
  private persistentId;
2026
2540
  private readonly configuredConversationId?;
2027
2541
  private readonly estimator?;
@@ -2073,6 +2587,12 @@ declare class AgentSession {
2073
2587
  init(): Promise<void>;
2074
2588
  /** 挂载插件并执行 setup;销毁后或运行中拒绝,setup 失败的插件不进入已装列表。 */
2075
2589
  use(plugin: AgentPlugin): Promise<void>;
2590
+ /**
2591
+ * 获取当前会话已成功挂载的扩展插件只读列表。
2592
+ *
2593
+ * 保证返回当前状态的独立切片,外部修改不污染内部挂载表。
2594
+ */
2595
+ getPlugins(): readonly AgentPlugin[];
2076
2596
  /**
2077
2597
  * 空闲时原子替换角色的模型绑定;本方法不改变当前角色或工具权限。
2078
2598
  * @param profile 模型协议、请求目标和输出预算。
@@ -2093,6 +2613,8 @@ declare class AgentSession {
2093
2613
  /** 只在空闲时切换本次会话模式;宿主负责 FullAccess 的显式选择交互。 */
2094
2614
  switchMode(mode: SessionMode): void;
2095
2615
  getMode(): SessionMode;
2616
+ /** 获取当前会话生效的权限规则列表。 */
2617
+ getPermissionRules(): readonly PermissionRule[];
2096
2618
  /** 返回最近一次成功装载的来源路径,不暴露指令正文。 */
2097
2619
  getInstructionSources(): string[];
2098
2620
  /** 稳定会话身份,独立于当前进程日志实例和每次用户交互。 */
@@ -2101,6 +2623,17 @@ declare class AgentSession {
2101
2623
  getHistory(): CanonicalMessage[];
2102
2624
  /** 返回当前投影视图,区别于原始历史;不执行模型或 Hook。 */
2103
2625
  getContextHistory(): CanonicalMessage[];
2626
+ /** 查询技能元数据、诊断与本轮活动状态;只读,不加载正文或改变权限。 */
2627
+ getSkills(query?: string): {
2628
+ skills: SkillMetadata[];
2629
+ diagnostics: SkillDiagnostic[];
2630
+ activations: SkillActivation[];
2631
+ content: SkillContextState[];
2632
+ catalog: {
2633
+ included: number;
2634
+ omitted: number;
2635
+ };
2636
+ };
2104
2637
  /** 查询最近最终请求的预算快照,尚未准备请求时返回 undefined。 */
2105
2638
  getContextSnapshot(): ContextSnapshot | undefined;
2106
2639
  /** 执行中止后的工具/摘要与存储收口期间仍返回 true。 */
@@ -2129,11 +2662,35 @@ declare class AgentSession {
2129
2662
  signal?: AbortSignal;
2130
2663
  role?: PrimaryModelRole;
2131
2664
  }): AsyncIterable<SessionEvent>;
2665
+ /** 显式用户技能入口;任务原文单条提交,与普通run共享互斥、取消及清理,不恢复历史授权。 */
2666
+ runSkill(name: string, task: string, options?: {
2667
+ signal?: AbortSignal;
2668
+ role?: PrimaryModelRole;
2669
+ }): AsyncIterable<SessionEvent>;
2670
+ /**
2671
+ * 受控任务准备入口:在同一运行锁内异步准备文本块/来源,预算和存储成功后才进入模型。
2672
+ *
2673
+ * @param task 用户显式任务正文(或命令描述)。
2674
+ * @param prepare 异步任务准备函数;在锁内执行,若准备失败或取消则释放锁且零 append。
2675
+ * @param options 可选中止信号与显式主任务角色。
2676
+ * @returns 结构化事件的异步流。
2677
+ * @throws {SessionBusyError} 当前会话忙碌时抛出。
2678
+ */
2679
+ runPreparedTask(task: string, prepare: (context: PreparedTaskContext) => Promise<PreparedTaskResult>, options?: {
2680
+ signal?: AbortSignal;
2681
+ role?: PrimaryModelRole;
2682
+ }): AsyncIterable<SessionEvent>;
2132
2683
  /** 单次任务执行主体;调用方 return 的中止与 finally 清理由外层统一协调。 */
2133
2684
  private runOperation;
2134
2685
  /** 幂等销毁:卸载插件后发出 session:end;运行中拒绝,teardown 失败聚合抛出且不完成销毁。 */
2135
2686
  destroy(): Promise<void>;
2136
2687
  private assertIdle;
2688
+ /** 实际请求、静态统计和手动压缩共用目录空间推导;先计正文、工具和非目录提示,再预算整段目录。 */
2689
+ private createPromptAssembler;
2690
+ /** 完整消息提交后完成技能审计;审计失败保留真实历史,停止本轮且不发布成功事件。 */
2691
+ private commitSkills;
2692
+ /** 显式加载仍按同一读取策略、精确缓存与宿主审批裁决;拒绝/取消/审计失败时不追加用户任务。 */
2693
+ private authorizeSkill;
2137
2694
  /**
2138
2695
  * 计算最近一次内部模型请求的上下文占用;无 usage 时显式标注预算估算。
2139
2696
  * run 累计 promptTokens 会重复计算每一步都重发的历史,不能用于窗口占用率。
@@ -2164,4 +2721,4 @@ declare class AgentSession {
2164
2721
  private findClosedToolMessages;
2165
2722
  }
2166
2723
 
2167
- export { AbortError, AgentLoop, type AgentLoopOptions, type AgentPlugin, AgentSession, AnthropicProvider, type AnthropicProviderOptions, type ApprovalChannel, type ApprovalChoice, type ApprovalRequest, type CanonicalMessage, type Capability, type ChatCapabilities, type CommandResult, type ConflictPolicy, type ContentBlock, type ContextBudget, ContextBudgetError, ContextManager, type ContextManagerOptions, ContextOverflowError, type ContextSnapshot, ContextStorageError, type ContextSummary, type ContextUsage, type ContextWindowValue, DEFAULT_CONTEXT_WINDOW_TOKENS, type EventLogger, type ExecutorOptions, FatalError, type FileDetails, FileLogSink, type FileLogSinkOptions, type FileObservation, type HistoryRepair, type HookContext, type HookHandlers, type HookPoint, HookRegistry, type InstructionLoadOptions, type InstructionSnapshot, type InstructionSource, type InteractionBoundary, type InteractionTerminal, JSONLMessageStore, KapibalaError, type LogChannel, type LogEvent, type LogField, type LogInput, type LogLevel, type LogSink, type ManagedSession, type MessageRole, type MessageStore, ModelError, type ModelErrorCategory, type ModelErrorInfo, type ModelErrorOptions, type ModelEvent, type ModelProfile, type ModelProtocol, type ModelProvider, type ModelProviderBinding, type ModelRequest, type ModelRole, type ModelRouter, type NormalizedHistory, OpenAICompatibleProvider, type OpenAIProviderOptions, OpenAIResponsesProvider, type OpenAIResponsesProviderOptions, PathSandbox, type PermissionAction, type PermissionDecision, PermissionPolicy, type PermissionRequest, type PermissionRule, type PluginContext, type PrimaryModelRole, type ProjectIdentity, PromptAssembler, type PromptAssemblerOptions, type ProtocolItemMetadata, type ProtocolOrigin, type ProviderStateBlock, type RedactedThinkingBlock, type RequestPreparation, type ResolvedContextWindow, type RunCommandInput, type RunMetrics, SESSION_SCHEMA_VERSION, SUMMARY_OUTPUT_BUFFER_MULTIPLIER, type SandboxConfig, SessionApprovalCache, SessionBusyError, type SessionConfig, type SessionEvent, type SessionHeader, SessionLock, SessionManager, type SessionManagerOptions, type SessionMetadata, type SessionMode, type SessionRecord, type SessionRecordType, type SessionState, type SessionStats, SessionStore, type ShellDetectOptions, type ShellEnvironment, type ShellKind, type ShellPreference, type ShellScope, SimpleModelRouter, type StatefulMessageStore, type StepLogEntry, type StepLogStage, StructuredLogger, type SummaryCandidate, SummaryService, type SummaryServiceOptions, type TextBlock, type ThinkingBlock, type TokenEstimate, type TokenEstimator, type Tool, type ToolContext, type ToolDecision, type ToolDefinition, ToolError, ToolExecutor, type ToolMetadata, ToolNotFound, ToolRegistry, type ToolResultBlock, type ToolUseBlock, TransportError, type TurnMetrics, UnicodeTokenEstimator, type Usage, assembleCanonicalToolResults, builtinTools, classifyBashOutput, cleanupCommandResults, commandAuditSummary, createContextBudget, createDefaultLogSinks, createLogId, createMessageId, createRunCommandTool, defineTool, describeModelError, detectShell, editFileTool, executionFingerprint, extractFileDetails, globTool, grepTool, identifyHistory, indexInteractions, isTextBlock, isThinkingBlock, isToolResultBlock, isToolUseBlock, loadInstructions, normalizeHistory, projectSafeFields, readFileTool, recoverIncompleteAudit, renderFileDetails, requestFingerprint, resolveContextWindow, resolveSessionProject, sanitizeModelErrorMessage, sanitizeSessionTitle, stableJsonStringify, stableSerialize, supportsSessionState, toToolDefinition, truncateToolOutput, validateModelBinding, validatePermissionRules, validateSummary, visibleTools, writeFileTool };
2724
+ export { AbortError, AgentLoop, type AgentLoopOptions, type AgentPlugin, AgentSession, AnthropicProvider, type AnthropicProviderOptions, type ApprovalChannel, type ApprovalChoice, type ApprovalRequest, type CanonicalMessage, type Capability, type ChatCapabilities, type CommandResult, type ConflictPolicy, type ContentBlock, type ContextBudget, ContextBudgetError, ContextManager, type ContextManagerOptions, ContextOverflowError, type ContextSnapshot, ContextStorageError, type ContextSummary, type ContextUsage, type ContextWindowValue, DEFAULT_CONTEXT_WINDOW_TOKENS, type EventLogger, type ExecutorOptions, FatalError, type FileDetails, FileLogSink, type FileLogSinkOptions, type FileObservation, type HistoryRepair, type HookContext, type HookHandlers, type HookPoint, HookRegistry, type InstructionLoadOptions, type InstructionSnapshot, type InstructionSource, type InteractionBoundary, type InteractionTerminal, JSONLMessageStore, KapibalaError, type LogChannel, type LogEvent, type LogField, type LogInput, type LogLevel, type LogSink, type ManagedSession, type MessageRole, type MessageStore, ModelError, type ModelErrorCategory, type ModelErrorInfo, type ModelErrorOptions, type ModelEvent, type ModelProfile, type ModelProtocol, type ModelProvider, type ModelProviderBinding, type ModelRequest, type ModelRole, type ModelRouter, type NormalizedHistory, OpenAICompatibleProvider, type OpenAIProviderOptions, OpenAIResponsesProvider, type OpenAIResponsesProviderOptions, PathSandbox, type PermissionAction, type PermissionDecision, PermissionPolicy, type PermissionRequest, type PermissionRule, type PluginCommandContribution, type PluginContext, type PluginContribution, PreDispatchError, type PreparedSkill, type PreparedTaskContext, type PreparedTaskResult, type PrimaryModelRole, type ProjectIdentity, PromptAssembler, type PromptAssemblerOptions, type PromptContentSource, type ProtocolItemMetadata, type ProtocolOrigin, type ProviderStateBlock, type RedactedThinkingBlock, type RequestPreparation, type ResolvedContextWindow, type RunCommandInput, type RunMetrics, SESSION_SCHEMA_VERSION, SKILL_LIMITS, SUMMARY_OUTPUT_BUFFER_MULTIPLIER, type SandboxConfig, SessionApprovalCache, SessionBusyError, type SessionConfig, type SessionEvent, type SessionHeader, SessionLock, SessionManager, type SessionManagerOptions, type SessionMetadata, type SessionMode, type SessionRecord, type SessionRecordType, type SessionState, type SessionStats, SessionStore, type ShellDetectOptions, type ShellEnvironment, type ShellKind, type ShellPreference, type ShellScope, SimpleModelRouter, type SkillActivation, type SkillCatalog, type SkillContentSource, type SkillContextState, type SkillDefinition, type SkillDiagnostic, type SkillDocument, type SkillMetadata, type SkillOptions, type SkillQuery, type SkillQueryPage, SkillRegistry, type SkillResourceInput, type SkillResourcePage, type SkillRoot, SkillRuntime, type SkillScanResult, type SkillScope, type StatefulMessageStore, type StepLogEntry, type StepLogStage, StructuredLogger, type SummaryCandidate, SummaryService, type SummaryServiceOptions, type TextBlock, type ThinkingBlock, type TokenEstimate, type TokenEstimator, type Tool, type ToolContext, type ToolDecision, type ToolDefinition, ToolError, type ToolExecutionIdentity, type ToolExecutionResult, ToolExecutor, type ToolHardDenial, type ToolInputValidation, type ToolMetadata, ToolNotFound, ToolRegistry, type ToolRegistrySnapshot, type ToolResultBlock, type ToolResultExecution, type ToolUseBlock, TransportError, type TurnMetrics, UnicodeTokenEstimator, type Usage, assembleCanonicalToolResults, builtinTools, classifyBashOutput, cleanupCommandResults, commandAuditSummary, compareSkillPaths, createContextBudget, createDefaultLogSinks, createLogId, createMessageId, createRunCommandTool, defineTool, describeModelError, detectShell, editFileTool, escapeSkillXml, estimateSkillTokens, executionFingerprint, extractFileDetails, findSkillContent, formatSkillCatalog, globTool, grepTool, identifyHistory, indexInteractions, inspectSkillContent, intersectSkillTools, isSkillName, isTextBlock, isThinkingBlock, isToolResultBlock, isToolUseBlock, isWithinSkillRoot, listSkillResources, loadInstructions, normalizeHistory, normalizeSkillTools, parseSkillDocument, projectSafeFields, readBoundedSkillText, readFileTool, readSkillResource, recoverIncompleteAudit, renderFileDetails, renderSkillReloads, requestFingerprint, resolveContextWindow, resolveSessionProject, sanitizeModelErrorMessage, sanitizeSessionTitle, scanSkillRoot, skillDigest, skillFailure, skillPathKey, stableJsonStringify, stableSerialize, supportsSessionState, toToolDefinition, truncateToolOutput, validateModelBinding, validatePermissionRules, validateSummary, visibleTools, writeFileTool };