@kiturone/kapibala 0.0.9 → 0.1.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/index.d.ts CHANGED
@@ -239,6 +239,18 @@ declare class KapibalaError extends Error {
239
239
  dispatchOutcome?: 'not_sent' | 'succeeded' | 'failed' | 'unknown';
240
240
  });
241
241
  }
242
+ declare const SESSION_SAFE_MESSAGES: {
243
+ readonly SESSION_LOCKED: "会话已被其他持有者占用";
244
+ readonly SESSION_RECOVERY_IN_PROGRESS: "会话正在恢复";
245
+ readonly SESSION_LOCK_OWNER_CHANGED: "会话锁持有者已变化";
246
+ readonly SESSION_NOT_FOUND: "未找到指定会话";
247
+ readonly SESSION_ID_AMBIGUOUS: "会话前缀不唯一";
248
+ readonly HISTORY_PAGE_INVALID: "历史页参数无效";
249
+ };
250
+ /** 会话身份与存储锁的稳定分类;不将内部诊断文本当作机器协议。 */
251
+ type SessionErrorCode = keyof typeof SESSION_SAFE_MESSAGES;
252
+ /** 生成固定安全文案的会话错误;内部 message 保留兼容诊断,重试必须由调用者决定。 */
253
+ declare function createSessionError(code: SessionErrorCode, message: string): KapibalaError;
242
254
  /** 工具向外部发送前在微任务复核或状态检查中被撤销/拒绝;dispatchOutcome 固定 not_sent。 */
243
255
  declare class PreDispatchError extends KapibalaError {
244
256
  constructor(message: string, options?: {
@@ -775,6 +787,12 @@ declare function indexInteractions(input: readonly CanonicalMessage[], terminals
775
787
  protectedMessageIds: string[];
776
788
  };
777
789
 
790
+ /** 可选单文件读取预算;省略保持旧行为,超限不得被当成 JSON 尾损坏恢复。 */
791
+ interface HistoryReadOptions {
792
+ /** 编码字节总量上限,必须为正安全整数;不限制已打开事务的追加落盘。 */
793
+ maxReadBytes?: number;
794
+ }
795
+
778
796
  /**
779
797
  * 旧版单文件 JSONL MessageStore:每行一条消息,无版本化状态能力。
780
798
  * 写入为同步追加,不做 fsync 或单写者保护;恢复时容错跳过损坏行并闭合悬挂事务。
@@ -819,7 +837,7 @@ declare const SESSION_SCHEMA_VERSION = 2;
819
837
  /** 默认主分支标识。 */
820
838
  declare const MAIN_BRANCH_ID = "main";
821
839
  /** 会话记录类型:header 只出现一次,message 承载正文,其余为分支或全局控制记录。 */
822
- type SessionRecordType = 'header' | 'message' | 'run_started' | 'run_finished' | 'message_state' | 'history_repair' | 'usage' | 'checkpoint' | 'context_pruned' | 'compaction_state' | 'title' | 'reset' | 'legacy_import' | 'branch_created' | 'branch_selected' | 'branch_summary' | 'archive_state';
840
+ type SessionRecordType = 'header' | 'message' | 'run_started' | 'run_finished' | 'message_state' | 'history_repair' | 'usage' | 'checkpoint' | 'context_pruned' | 'compaction_state' | 'title' | 'reset' | 'legacy_import' | 'branch_created' | 'branch_selected' | 'branch_summary' | 'archive_state' | 'pin_state';
823
841
  /**
824
842
  * 判断指定记录类型是否属于全局控制记录。
825
843
  *
@@ -924,6 +942,7 @@ declare function assertClosedToolTransaction(records: SessionRecord[], targetRec
924
942
  * 调用者须在打开前取得单写者锁;本类不允许静默跳过中部损坏或重复身份。
925
943
  */
926
944
  declare class SessionStore implements StatefulMessageStore {
945
+ private readonly readOptions;
927
946
  readonly filePath: string;
928
947
  private queue;
929
948
  private records;
@@ -945,9 +964,9 @@ declare class SessionStore implements StatefulMessageStore {
945
964
  /** 注册可重建缓存的写后通知;缓存失败只诊断,不撤销或毒化已 fsync 的正文。 */
946
965
  setAppendObserver(observer: (record: SessionRecord) => void, onDiagnostic?: (message: string) => void): void;
947
966
  /** 以独占创建方式安装新头部(默认生成 Schema v2 格式),已有文件明确失败,绝不覆盖其它会话。 */
948
- static create(filePath: string, header: SessionHeader): Promise<SessionStore>;
967
+ static create(filePath: string, header: SessionHeader, options?: HistoryReadOptions): Promise<SessionStore>;
949
968
  /** 打开并验证已有会话;尾部残片先保存到隔离文件,中部损坏与未知版本拒绝恢复。 */
950
- static open(filePath: string): Promise<SessionStore>;
969
+ static open(filePath: string, options?: HistoryReadOptions): Promise<SessionStore>;
951
970
  /** 获取完整记录快照,等候已排队写入后读取;调用者不能借此修改内部记录。 */
952
971
  readRecords(): Promise<SessionRecord[]>;
953
972
  /** 消息级持久化,补稳定身份并保留所有终态字段,成功后方可进入下一次写入。 */
@@ -992,6 +1011,16 @@ declare class SessionStore implements StatefulMessageStore {
992
1011
  * 查询当前会话是否处于已归档状态。
993
1012
  */
994
1013
  isArchived(): Promise<boolean>;
1014
+ /**
1015
+ * 追加会话置顶控制记录。
1016
+ *
1017
+ * 约束:
1018
+ * - 置顶状态记录为全局控制记录(parentId 为 null,不推进分支上下文叶子);
1019
+ * - payload 结构为 { pinned: boolean },最后一次写入生效;
1020
+ * - 置顶只影响列表排序,不改变正文活动时间,因此不会让会话挤进「最近」;
1021
+ * - v1 历史会话禁止变更置顶状态。
1022
+ */
1023
+ setPinnedState(pinned: boolean): Promise<SessionRecord>;
995
1024
  /**
996
1025
  * 获取当前会话中所有已知分支的元数据与状态列表。
997
1026
  */
@@ -1070,8 +1099,8 @@ interface ProjectIdentity {
1070
1099
  }
1071
1100
  /** Windows 桶和头部使用相同大小写规范,POSIX 保持路径大小写语义。 */
1072
1101
  declare function normalizedProjectRoot(root: string): string;
1073
- /** 解析真实工作树根;同工作树子目录共用桶,非 Git 目录和不同 worktree 独立。不会改变 cwd。 */
1074
- declare function resolveSessionProject(cwd: string): ProjectIdentity;
1102
+ /** 选择历史桶身份;exact 不提升显式根,git 保留同工作树子目录共桶的兼容行为。 */
1103
+ declare function resolveSessionProject(cwd: string, mode?: 'git' | 'exact'): ProjectIdentity;
1075
1104
  /**
1076
1105
  * 会话 sidecar 缓存元数据;可随时从正文重建,校验失败即丢弃,不是恢复依据。
1077
1106
  * 正文 JSONL 始终是唯一真源。
@@ -1112,6 +1141,10 @@ interface SessionMetadata {
1112
1141
  activeLeafId?: string | null;
1113
1142
  /** 会话是否已归档。 */
1114
1143
  archived?: boolean;
1144
+ /** 会话是否置顶;只在列表排序时前置,不改变活动时间与继续最近会话的判定。 */
1145
+ pinned?: boolean;
1146
+ /** 预算不足时仅提供定位与提示,不把超限文件误判为损坏或写入不完整缓存。 */
1147
+ unavailableReason?: 'HISTORY_READ_LIMIT';
1115
1148
  }
1116
1149
  /** 打开的会话句柄:持有单写者锁与 Store,宿主用毕必须 release。 */
1117
1150
  interface ManagedSession {
@@ -1137,6 +1170,10 @@ interface SessionManagerOptions {
1137
1170
  projectRoot?: string;
1138
1171
  /** 执行或参考目录;若未提供工作区根,以此解析项目工作树。 */
1139
1172
  cwd?: string;
1173
+ /** exact 固定显式根的历史归属;缺省按 Git 工作树分桶,旧调用不迁移历史。 */
1174
+ projectRootMode?: 'git' | 'exact';
1175
+ /** 元数据重建、升级、打开和重载共用的单文件字节预算;省略保持原行为。 */
1176
+ maxReadBytes?: number;
1140
1177
  homeDirectory?: string;
1141
1178
  onDiagnostic?: (message: string) => void;
1142
1179
  }
@@ -1148,16 +1185,19 @@ declare class SessionManager {
1148
1185
  readonly directory: string;
1149
1186
  private readonly handles;
1150
1187
  private readonly diagnostic?;
1188
+ private readonly readOptions;
1151
1189
  constructor(options?: SessionManagerOptions);
1152
1190
  /** 默认新建独立空会话,写入头部并持有单写者锁;不读取其它正文。 */
1153
1191
  create(): Promise<ManagedSession>;
1154
1192
  /**
1155
1193
  * 按正文活动排序分页;有效 sidecar 只读元数据,不读取完整 JSONL。默认排除已归档会话。
1156
- * pageSize 由调用方显式给出时必须在 1–100 之间;非法页参数直接失败,不静默修正。
1194
+ * pageSize 由调用方显式给出时必须在 1–100 之间;filter 在分页前筛选元数据,调用方须自行处理敏感信息。
1195
+ * 置顶项整体前置、组内仍按活动时间排序;排序只作用于本方法的返回值,不影响 continueRecent。
1157
1196
  */
1158
1197
  list(page?: number, options?: {
1159
1198
  includeArchived?: boolean;
1160
1199
  pageSize?: number;
1200
+ filter?: (metadata: SessionMetadata) => boolean;
1161
1201
  }): Promise<{
1162
1202
  items: SessionMetadata[];
1163
1203
  total: number;
@@ -1167,18 +1207,49 @@ declare class SessionManager {
1167
1207
  /** 解析完整 ID 或唯一前缀对应的会话文件与 ID。 */
1168
1208
  private resolveSession;
1169
1209
  /**
1170
- * 逻辑归档指定会话。
1210
+ * 归档、恢复、重命名与置顶都向正文追加一条全局控制记录,共用同一套前置约束。
1171
1211
  *
1172
1212
  * 约束:
1173
1213
  * - 必须取得会话独占锁;
1174
- * - 若会话当前正处于活动打开状态,拒绝归档并抛出 SESSION_IN_USE;
1175
- * - 向会话正文追加 archive_state { archived: true } 并刷新 sidecar 缓存。
1214
+ * - 若会话当前正处于活动打开状态,拒绝并抛出 SESSION_IN_USE(调用方先关闭句柄);
1215
+ * - v1 只读历史不能变更,明确以 LEGACY_SESSION_READ_ONLY 失败而不是静默忽略;
1216
+ * - 写入后按正文重建 sidecar,状态只以正文记录为准。
1217
+ */
1218
+ private appendControlRecord;
1219
+ /**
1220
+ * 逻辑归档指定会话:向正文追加 archive_state { archived: true } 并刷新 sidecar 缓存。
1176
1221
  */
1177
1222
  archiveSession(id: string): Promise<void>;
1178
1223
  /**
1179
- * 恢复已逻辑归档的会话。
1224
+ * 恢复已逻辑归档的会话:追加 archive_state { archived: false },正文保持不动。
1180
1225
  */
1181
1226
  restoreSession(id: string): Promise<void>;
1227
+ /**
1228
+ * 单独重命名指定会话,不保留句柄:追加 title 记录后立即释放写锁。
1229
+ *
1230
+ * 与 `rename` 的分工:本方法面向「没有打开该会话」的宿主(桌面侧栏、设置页),
1231
+ * 因此不接受活动句柄;已打开的会话由宿主经自己的 Store 追加,避免同进程锁冲突。
1232
+ */
1233
+ renameSession(id: string, title: string): Promise<void>;
1234
+ /**
1235
+ * 切换会话置顶:追加 pin_state { pinned } 控制记录,只在列表排序时前置。
1236
+ *
1237
+ * 置顶不是「最近活动」,因此不写 run_started、也不改 lastActivityAt;
1238
+ * 关闭置顶后会话回到按活动时间排序的原有位置。
1239
+ */
1240
+ pinSession(id: string, pinned: boolean): Promise<void>;
1241
+ /**
1242
+ * 物理删除指定会话的正文与 sidecar 缓存。
1243
+ *
1244
+ * 约束与边界:
1245
+ * - 删除不可逆,本方法不提供回收站或软删除,调用方必须先取得用户确认;
1246
+ * - 本 Manager 已持有句柄的会话拒绝(SESSION_IN_USE),避免删掉正在追加的文件;
1247
+ * - 其它进程持锁时以 SESSION_LOCKED 失败,不抢占他人写入权,也不做「先等一会儿」的重试;
1248
+ * - 只删该会话自己的 `.jsonl` 与 `.meta.json`;桶目录内其它文件(含 `*.tmp-*` 残片)不动;
1249
+ * - 删除前复核首条头部身份与桶归属:文件名匹配但正文身份不符的残留文件删除会放大错误;
1250
+ * - 缓存先删、正文后删:缓存本可重建,若正文删除失败该会话会在下次浏览时自动重建缓存。
1251
+ */
1252
+ deleteSession(id: string): Promise<void>;
1182
1253
  /** 一次扫描建立排序目录,分页和继续最近会话共用;有效缓存不读取正文。 */
1183
1254
  private allMetadata;
1184
1255
  /**
@@ -1194,7 +1265,12 @@ declare class SessionManager {
1194
1265
  continueRecent(options?: {
1195
1266
  autoUpgradeLegacy?: boolean;
1196
1267
  }): Promise<ManagedSession>;
1197
- /** 标题作为独立耐久记录;标题或浏览不改变正文活动排序。 */
1268
+ /**
1269
+ * 重命名已打开或待打开的会话;标题作为独立耐久记录,标题或浏览都不改变正文活动排序。
1270
+ *
1271
+ * 未持有句柄时临时打开并在追加后释放:只改标题不该把会话一直挂在写锁上,
1272
+ * 否则同进程后续的归档、删除与置顶都会被自己占住的锁挡掉。
1273
+ */
1198
1274
  rename(id: string, title: string): Promise<void>;
1199
1275
  /** 等候所有存储队列后释放句柄;宿主必须先结束 AgentSession 的工具/摘要清理。 */
1200
1276
  close(): Promise<void>;
@@ -1239,6 +1315,8 @@ declare class SessionManager {
1239
1315
  }): Promise<ManagedSession>;
1240
1316
  /** 绑定写后缓存与锁生命周期;正文优先,缓存失败不使保存成功的消息消失。 */
1241
1317
  private attach;
1318
+ /** 超限列表只解析有界头部并核对桶身份,不读取正文、不生成可误用的耐久缓存。 */
1319
+ private readOversizedMetadata;
1242
1320
  /** 缓存通过文件名、身份、统计与正文 stat 校验;失败交由正文重建。 */
1243
1321
  private readMetadata;
1244
1322
  /** 浏览仅解析完整记录;严格打开由 SessionStore 验证,浏览不能改写残片。 */
@@ -1893,6 +1971,8 @@ interface ToolMetadata {
1893
1971
  }
1894
1972
  /** 工具执行期由宿主注入的运行环境;信号取消后工具应尽快清理在途资源再返回。 */
1895
1973
  interface ToolContext {
1974
+ /** 父会话实际协调器的内存引用;spawn 必须显式传递,禁止放入模型输入或持久记录。 */
1975
+ readonly leaseCoordinator?: WorkspaceLeaseCoordinator;
1896
1976
  /** 显式工作区物理根路径,经 native realpath 规范化。 */
1897
1977
  workspaceRoot?: string;
1898
1978
  /** 显式命令执行工作目录绝对路径(位于 workspaceRoot 内部)。 */
@@ -2031,8 +2111,6 @@ declare class WorkspaceLeaseCoordinator {
2031
2111
  timeoutMs?: number;
2032
2112
  }): Promise<T>;
2033
2113
  }
2034
- /** 运行时共享写租约协调器单例。 */
2035
- declare const sharedWorkspaceLeaseCoordinator: WorkspaceLeaseCoordinator;
2036
2114
 
2037
2115
  type CompactionReason = 'threshold' | 'manual' | 'overflow';
2038
2116
  /**
@@ -2659,7 +2737,6 @@ declare class HookRegistry {
2659
2737
  emit<K extends 'session:start' | 'session:end' | 'model:after' | 'tool:after' | 'error'>(point: K, ctx: HookContext, ...args: any[]): Promise<void>;
2660
2738
  }
2661
2739
 
2662
- /** ToolExecutor 的构造项;审计写入需要 eventLogger 与 sessionId 同时提供,否则不产生审计。 */
2663
2740
  /** 宿主运行级硬限制;优先于模式、审批及缓存,文案和字段不得携带凭据。 */
2664
2741
  interface ToolHardDenial {
2665
2742
  code: string;
@@ -2667,6 +2744,7 @@ interface ToolHardDenial {
2667
2744
  retryPolicy: ToolResultBlock['retryPolicy'];
2668
2745
  fields?: Record<string, unknown>;
2669
2746
  }
2747
+ /** ToolExecutor 的构造项;审计写入需要 eventLogger 与 sessionId 同时提供,否则不产生审计。 */
2670
2748
  interface ExecutorOptions {
2671
2749
  /** 在最终参数上补充硬拒绝,不能把拒绝转为授权。 */
2672
2750
  hardDenial?: (tool: Tool, input: Record<string, unknown>) => ToolHardDenial | undefined;
@@ -2704,6 +2782,7 @@ interface ExecutorOptions {
2704
2782
  /** 会话内 allow_session / deny_session 审批缓存;缺省使用实例私有缓存。 */
2705
2783
  approvalCache?: SessionApprovalCache;
2706
2784
  }
2785
+
2707
2786
  /**
2708
2787
  * 工具执行器:按「审计 → 钩子裁决 → 权限裁决 → 执行 → 结果闭合」处理单次调用。
2709
2788
  * 所有拒绝与异常都闭合为 isError 的工具结果,不向调用方抛出;
@@ -2771,14 +2850,6 @@ declare class ToolExecutor {
2771
2850
  outputBytes: number;
2772
2851
  }) => void, forcedDeny?: boolean): Promise<ToolResultBlock>;
2773
2852
  private executeResolved;
2774
- /**
2775
- * 给工具执行加超时护栏:Promise.race 在超时后reject,循环拿到 isError 结果继续运转,
2776
- * 不会因某个异步工具(如未来接入的网络/exec 工具)挂起而永久卡死。
2777
- *
2778
- * 局限:同步 CPU 密集型实现会阻塞事件循环,timer 同样无法触发;
2779
- * 因此内置工具仍需避免执行用户可控的同步高复杂度计算。
2780
- */
2781
- private withTimeout;
2782
2853
  /**
2783
2854
  * 构建当前会话在派生时刻的父权限策略快照。
2784
2855
  */
@@ -3225,6 +3296,7 @@ interface AgentLoopOptions {
3225
3296
  getMode?: () => SessionMode;
3226
3297
  permissionRules?: readonly PermissionRule[];
3227
3298
  }
3299
+
3228
3300
  /**
3229
3301
  * 主执行循环:按 turn 推进「模型请求 → 整批校验 → 工具调度 → 历史闭合」。
3230
3302
  * run 会就地追加传入的 history,assistant 与全部 tool_result 在同一同步临界段落入,
@@ -3576,12 +3648,18 @@ declare class SessionInbox {
3576
3648
  */
3577
3649
 
3578
3650
  /** 子代理会话执行器类型;生产环境调用真实的 AgentSession,测试环境可注入 Mock。 */
3579
- type SubagentSessionRunner = (record: AgentTaskRecord, signal: AbortSignal) => Promise<{
3651
+ type SubagentSessionRunner = (record: AgentTaskRecord, signal: AbortSignal, context: SubagentRunnerContext) => Promise<{
3580
3652
  summary: string;
3581
3653
  modelId?: string;
3582
3654
  }>;
3655
+ /** 子任务仅在内存中接收父协调器;runner 创建子会话时必须注入,不可序列化到任务记录。 */
3656
+ interface SubagentRunnerContext {
3657
+ readonly leaseCoordinator: WorkspaceLeaseCoordinator;
3658
+ }
3583
3659
  /** 启动子代理时的调用方上下文。 */
3584
3660
  interface SpawnContext {
3661
+ /** 父会话实际持有的协调器;缺失时在受理和持久副作用前拒绝启动。 */
3662
+ readonly leaseCoordinator: WorkspaceLeaseCoordinator;
3585
3663
  /** 根任务标识;若为根会话直接派生,可缺省由 Runtime 自动初始化。 */
3586
3664
  rootTaskId?: string;
3587
3665
  /** 父会话会话 ID。 */
@@ -3617,6 +3695,7 @@ interface AgentRuntimeOptions {
3617
3695
  * 后台子代理任务树调度与状态机协调器。
3618
3696
  */
3619
3697
  declare class AgentRuntime {
3698
+ private readonly runnerContexts;
3620
3699
  private readonly tasks;
3621
3700
  private readonly controllers;
3622
3701
  private readonly timers;
@@ -3810,9 +3889,8 @@ interface PreparedTaskResult {
3810
3889
  /** 可选技能名称;存在时按显式技能流程处理。 */
3811
3890
  skillName?: string;
3812
3891
  }
3813
-
3814
- /** AgentSession 的构造配置;除主任务绑定外均可缺省,缺省行为见各字段。 */
3815
- interface SessionConfig {
3892
+ /** 会话的非根选项;扩展配置时与 SessionConfig 的显式根联合组合,不能隐式推导工作区。 */
3893
+ interface SessionOptions {
3816
3894
  /** 宿主显式技能配置;缺省不扫描home,项目根需独立信任。 */
3817
3895
  skills?: SkillOptions;
3818
3896
  /** 持久会话身份;有版本化 Store 时须与头部一致,日志实例身份保持独立。 */
@@ -3826,12 +3904,8 @@ interface SessionConfig {
3826
3904
  defaultProvider: ModelProvider;
3827
3905
  /** 消息级落盘通道;支持状态能力的 Store 额外启用持久压缩与交互终态。 */
3828
3906
  store?: MessageStore;
3829
- /** 文件访问与沙箱隔离的物理根绝对路径,经 native realpath 规范化;缺失时抛出 WORKSPACE_ROOT_REQUIRED。 */
3830
- workspaceRoot?: string;
3831
3907
  /** 默认命令执行目录绝对路径,必须位于 workspaceRoot 内部;缺省为 workspaceRoot。 */
3832
3908
  executionCwd?: string;
3833
- /** 工具执行与会话基目录兼容别名;与 workspaceRoot 冲突时失败。 */
3834
- rootDir?: string;
3835
3909
  systemPrompt?: string;
3836
3910
  maxSteps?: number;
3837
3911
  logger?: (msg: string) => void;
@@ -3852,7 +3926,7 @@ interface SessionConfig {
3852
3926
  onDiagnostic?: (message: string) => void;
3853
3927
  /** 会话持有的沙箱实例;缺省基于 workspaceRoot 自动创建独占实例。 */
3854
3928
  sandbox?: PathSandbox;
3855
- /** 共享工作区写租约协调器;缺省使用全局共享单例。 */
3929
+ /** 宿主显式共享的写租约协调器;缺省为本会话独占实例,不隐含跨会话互斥。 */
3856
3930
  leaseCoordinator?: WorkspaceLeaseCoordinator;
3857
3931
  /** 父任务或任务树根 ID,用于多智能体任务层级限制与追踪。 */
3858
3932
  rootTaskId?: string;
@@ -3861,6 +3935,14 @@ interface SessionConfig {
3861
3935
  /** 当前子会话对应的 agentId。 */
3862
3936
  agentId?: string;
3863
3937
  }
3938
+ /** 显式工作区根至少提供其一;保留 rootDir-only 兼容输入,双字段物理冲突在构造时拒绝。 */
3939
+ type SessionConfig = SessionOptions & ({
3940
+ workspaceRoot: string;
3941
+ rootDir?: string;
3942
+ } | {
3943
+ workspaceRoot?: never;
3944
+ rootDir: string;
3945
+ });
3864
3946
  /** getStats 返回的统计快照;全部字段为独立副本,宿主修改不影响会话内部状态。 */
3865
3947
  interface SessionStats {
3866
3948
  conversationId?: string;
@@ -3881,6 +3963,7 @@ interface SessionStats {
3881
3963
  /** 最近一次内部模型请求的窗口占用;无实测时仅提供窗口上限。 */
3882
3964
  contextUsage: ContextUsage;
3883
3965
  }
3966
+
3884
3967
  /**
3885
3968
  * 宿主无关的 Agent 会话门面:统一模型路由、工具执行、权限与上下文压缩。
3886
3969
  * 每次用户输入产生一个 run;历史与状态经 MessageStore 持久化,恢复后语义连续。
@@ -4095,4 +4178,4 @@ declare class AgentSession {
4095
4178
  private findClosedToolMessages;
4096
4179
  }
4097
4180
 
4098
- export { AbortError, AgentLoop, type AgentLoopOptions, type AgentNotification, type AgentPlugin, AgentRuntime, type AgentRuntimeOptions, AgentSession, type AgentTaskLimits, type AgentTaskOrigin, type AgentTaskRecord, type AgentTaskStatus, AnthropicProvider, type AnthropicProviderOptions, type ApprovalChannel, type ApprovalChoice, type ApprovalRequest, type BranchInfo, type CanonicalMessage, type Capability, type CatalogOptions, type ChatCapabilities, type ChildGrant, type ChildLimits, type CommandResult, type ConflictPolicy, type ContentBlock, type ContextBudget, ContextBudgetError, ContextManager, type ContextManagerOptions, ContextOverflowError, type ContextSnapshot, ContextStorageError, type ContextSummary, type ContextUsage, type ContextWindowValue, CrossProjectSessionCatalog, DEFAULT_CHILD_LIMITS, DEFAULT_CONTEXT_WINDOW_TOKENS, DEFAULT_MAX_STEPS, DEFAULT_MAX_SUBAGENT_DEPTH, DEFAULT_TIMEOUT_MS, type DerivedChildPolicy, type EventLogger, type ExecutorOptions, FatalError, type FileDetails, FileLogSink, type FileLogSinkOptions, type FileObservation, HARD_LIMIT_MAX_SUBAGENT_DEPTH, type HistoryRepair, type HookContext, type HookHandlers, type HookPoint, HookRegistry, type InstructionLoadOptions, type InstructionSnapshot, type InstructionSource, type InteractionBoundary, type InteractionTerminal, JSONLMessageStore, KapibalaError, type ListAgentsFilter, type LogChannel, type LogEvent, type LogField, type LogInput, type LogLevel, type LogSink, MAIN_BRANCH_ID, MAX_ACTIVE_TASKS_PER_RUNTIME, MAX_ACTIVE_TASKS_PER_TREE, MAX_TOTAL_TASKS_PER_TREE, 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, type ParentPolicySnapshot, 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, ROLE_PRESETS, type RedactedThinkingBlock, type RequestPreparation, type ResolvedContextWindow, type RolePresetDefinition, type RunCommandInput, type RunMetrics, SESSION_SCHEMA_VERSION, SESSION_SCHEMA_VERSION_V1, SESSION_SCHEMA_VERSION_V2, SKILL_LIMITS, SUMMARY_OUTPUT_BUFFER_MULTIPLIER, type SafeRegexMatchResult, type SandboxConfig, type SearchHit, type SearchOptions, type SearchResponse, SessionApprovalCache, SessionBusyError, type SessionCatalogEntry, type SessionConfig, type SessionEvent, type SessionHeader, SessionInbox, SessionLock, SessionManager, type SessionManagerOptions, type SessionMessageSink, 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 SpawnAgentParams, type SpawnAgentReceipt, type SpawnContext, type StatefulMessageStore, type StepLogEntry, type StepLogStage, StructuredLogger, SubagentOutbox, type SubagentOutboxOptions, type SubagentRole, type SubagentSessionRunner, type SubagentSourceMetadata, 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, type WorkspaceContext, WorkspaceLeaseCoordinator, type WorkspaceResolutionInput, type WorkspaceWriteLease, assembleCanonicalToolResults, assertClosedToolTransaction, builtinTools, classifyBashOutput, cleanupCommandResults, commandAuditSummary, compareSkillPaths, computeProjectKey, createAgentTools, createCancelAgentTool, createContextBudget, createDefaultLogSinks, createListAgentsTool, createLogId, createMessageId, createRunCommandTool, createSpawnAgentTool, createWaitAgentTool, defineTool, deriveChildPolicy, describeModelError, detectShell, editFileTool, escapeSkillXml, estimateSkillTokens, executionFingerprint, extractFileDetails, findSkillContent, formatNotificationContent, formatSkillCatalog, getRolePreset, globTool, grepTool, identifyHistory, indexInteractions, inspectSkillContent, intersectSkillTools, isActiveTaskStatus, isGlobalControlRecordType, isPathInside, isSamePath, isSkillName, isTerminalTaskStatus, isTextBlock, isThinkingBlock, isToolResultBlock, isToolUseBlock, isWithinSkillRoot, isWriteOperation, listSkillResources, loadInstructions, normalizeDriveLetter, normalizeHistory, normalizeSkillTools, normalizedProjectRoot, parseSkillDocument, projectSafeFields, readBoundedSkillText, readFileTool, readSkillResource, recoverIncompleteAudit, renderFileDetails, renderSkillReloads, requestFingerprint, resolveContextWindow, resolveSessionProject, resolveWorkspaceContext, safeRegexMatch, sanitizeModelErrorMessage, sanitizeSessionTitle, scanSkillRoot, sharedWorkspaceLeaseCoordinator, skillDigest, skillFailure, skillPathKey, stableJsonStringify, stableSerialize, supportsSessionState, tightenMode, toNativePhysicalPath, toToolDefinition, truncateToolOutput, validateModelBinding, validatePermissionRules, validateSummary, visibleTools, writeFileTool };
4181
+ export { AbortError, AgentLoop, type AgentLoopOptions, type AgentNotification, type AgentPlugin, AgentRuntime, type AgentRuntimeOptions, AgentSession, type AgentTaskLimits, type AgentTaskOrigin, type AgentTaskRecord, type AgentTaskStatus, AnthropicProvider, type AnthropicProviderOptions, type ApprovalChannel, type ApprovalChoice, type ApprovalRequest, type BranchInfo, type CanonicalMessage, type Capability, type CatalogOptions, type ChatCapabilities, type ChildGrant, type ChildLimits, type CommandResult, type ConflictPolicy, type ContentBlock, type ContextBudget, ContextBudgetError, ContextManager, type ContextManagerOptions, ContextOverflowError, type ContextSnapshot, ContextStorageError, type ContextSummary, type ContextUsage, type ContextWindowValue, CrossProjectSessionCatalog, DEFAULT_CHILD_LIMITS, DEFAULT_CONTEXT_WINDOW_TOKENS, DEFAULT_MAX_STEPS, DEFAULT_MAX_SUBAGENT_DEPTH, DEFAULT_TIMEOUT_MS, type DerivedChildPolicy, type EventLogger, type ExecutorOptions, FatalError, type FileDetails, FileLogSink, type FileLogSinkOptions, type FileObservation, HARD_LIMIT_MAX_SUBAGENT_DEPTH, type HistoryReadOptions, type HistoryRepair, type HookContext, type HookHandlers, type HookPoint, HookRegistry, type InstructionLoadOptions, type InstructionSnapshot, type InstructionSource, type InteractionBoundary, type InteractionTerminal, JSONLMessageStore, KapibalaError, type ListAgentsFilter, type LogChannel, type LogEvent, type LogField, type LogInput, type LogLevel, type LogSink, MAIN_BRANCH_ID, MAX_ACTIVE_TASKS_PER_RUNTIME, MAX_ACTIVE_TASKS_PER_TREE, MAX_TOTAL_TASKS_PER_TREE, 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, type ParentPolicySnapshot, 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, ROLE_PRESETS, type RedactedThinkingBlock, type RequestPreparation, type ResolvedContextWindow, type RolePresetDefinition, type RunCommandInput, type RunMetrics, SESSION_SCHEMA_VERSION, SESSION_SCHEMA_VERSION_V1, SESSION_SCHEMA_VERSION_V2, SKILL_LIMITS, SUMMARY_OUTPUT_BUFFER_MULTIPLIER, type SafeRegexMatchResult, type SandboxConfig, type SearchHit, type SearchOptions, type SearchResponse, SessionApprovalCache, SessionBusyError, type SessionCatalogEntry, type SessionConfig, type SessionErrorCode, type SessionEvent, type SessionHeader, SessionInbox, SessionLock, SessionManager, type SessionManagerOptions, type SessionMessageSink, type SessionMetadata, type SessionMode, type SessionOptions, 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 SpawnAgentParams, type SpawnAgentReceipt, type SpawnContext, type StatefulMessageStore, type StepLogEntry, type StepLogStage, StructuredLogger, SubagentOutbox, type SubagentOutboxOptions, type SubagentRole, type SubagentRunnerContext, type SubagentSessionRunner, type SubagentSourceMetadata, 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, type WorkspaceContext, WorkspaceLeaseCoordinator, type WorkspaceResolutionInput, type WorkspaceWriteLease, assembleCanonicalToolResults, assertClosedToolTransaction, builtinTools, classifyBashOutput, cleanupCommandResults, commandAuditSummary, compareSkillPaths, computeProjectKey, createAgentTools, createCancelAgentTool, createContextBudget, createDefaultLogSinks, createListAgentsTool, createLogId, createMessageId, createRunCommandTool, createSessionError, createSpawnAgentTool, createWaitAgentTool, defineTool, deriveChildPolicy, describeModelError, detectShell, editFileTool, escapeSkillXml, estimateSkillTokens, executionFingerprint, extractFileDetails, findSkillContent, formatNotificationContent, formatSkillCatalog, getRolePreset, globTool, grepTool, identifyHistory, indexInteractions, inspectSkillContent, intersectSkillTools, isActiveTaskStatus, isGlobalControlRecordType, isPathInside, isSamePath, isSkillName, isTerminalTaskStatus, isTextBlock, isThinkingBlock, isToolResultBlock, isToolUseBlock, isWithinSkillRoot, isWriteOperation, listSkillResources, loadInstructions, normalizeDriveLetter, normalizeHistory, normalizeSkillTools, normalizedProjectRoot, parseSkillDocument, projectSafeFields, readBoundedSkillText, readFileTool, readSkillResource, recoverIncompleteAudit, renderFileDetails, renderSkillReloads, requestFingerprint, resolveContextWindow, resolveSessionProject, resolveWorkspaceContext, safeRegexMatch, sanitizeModelErrorMessage, sanitizeSessionTitle, scanSkillRoot, skillDigest, skillFailure, skillPathKey, stableJsonStringify, stableSerialize, supportsSessionState, tightenMode, toNativePhysicalPath, toToolDefinition, truncateToolOutput, validateModelBinding, validatePermissionRules, validateSummary, visibleTools, writeFileTool };