@tencent-ai/agent-harness 0.2.0-beta.1 → 0.2.0-beta.3

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.
Files changed (226) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +1 -1
  3. package/cli/CHANGELOG.md +135 -0
  4. package/cli/dist-server/shared.cjs +455 -387
  5. package/cli/dist-server/types/node/acp/acp-protocol.d.ts +40 -12
  6. package/cli/dist-server/types/node/acp/usage-by-category-calculator.d.ts +21 -0
  7. package/cli/dist-server/types/node/bash-sandbox/bash-sandbox-protocol.d.ts +3 -0
  8. package/cli/dist-server/types/node/cli/cli-protocol.d.ts +3 -0
  9. package/cli/dist-server/types/node/cli/stream-json-protocol.d.ts +23 -2
  10. package/cli/dist-server/types/node/data-fs/index.d.ts +13 -1
  11. package/cli/dist-server/types/node/hooks/hook-protocol.d.ts +2 -2
  12. package/cli/dist-server/types/node/sensitive-content/sensitive-content-protocol.d.ts +7 -0
  13. package/cli/dist-server/types/node/server/boot.d.ts +7 -4
  14. package/{lib/components → cli/dist-server/types/node/server/formats}/acp/acp-error-model.d.ts +1 -1
  15. package/{lib/components → cli/dist-server/types/node/server/formats}/acp/acp-protocol.d.ts +2 -3
  16. package/cli/dist-server/types/node/server/formats/acp/index.d.ts +12 -0
  17. package/cli/dist-server/types/node/server/formats/acp/projection.d.ts +10 -0
  18. package/cli/dist-server/types/node/server/index.d.ts +1 -1
  19. package/cli/dist-server/types/node/server/sessions.d.ts +27 -2
  20. package/cli/dist-server/types/node/server/types.d.ts +65 -7
  21. package/cli/dist-server/types/node/settings/settings-protocol.d.ts +5 -0
  22. package/cli/dist-server/types/node/tools/tool-protocol.d.ts +128 -4
  23. package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-protocol.d.ts +60 -2
  24. package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-purpose-protocol.d.ts +8 -4
  25. package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-purpose-scope.d.ts +46 -0
  26. package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-service.d.ts +28 -3
  27. package/cli/dist-server/types/vendor/cbc-core/node/agent/index.d.ts +4 -0
  28. package/cli/dist-server/types/vendor/cbc-core/node/agent/interceptors/input-interceptors.d.ts +1 -6
  29. package/cli/dist-server/types/vendor/cbc-core/node/agent/model-call-failure.d.ts +9 -0
  30. package/cli/dist-server/types/vendor/cbc-core/node/agent/model-step-sequence.d.ts +11 -0
  31. package/cli/dist-server/types/vendor/cbc-core/node/agent/runner-factory.d.ts +56 -20
  32. package/cli/dist-server/types/vendor/cbc-core/node/agent/speaker-label.d.ts +44 -0
  33. package/cli/dist-server/types/vendor/cbc-core/node/agent/tool-call-loop-detector-service.d.ts +5 -4
  34. package/cli/dist-server/types/vendor/cbc-core/node/agent/tool-call-loop-guard-protocol.d.ts +1 -1
  35. package/cli/dist-server/types/vendor/cbc-core/node/agent/tool-call-loop-pattern.d.ts +16 -4
  36. package/cli/dist-server/types/vendor/cbc-core/node/context/compaction-lineage.d.ts +39 -0
  37. package/cli/dist-server/types/vendor/cbc-core/node/context/context-compact-summarizer.d.ts +2 -0
  38. package/cli/dist-server/types/vendor/cbc-core/node/context/context-protocol.d.ts +17 -0
  39. package/cli/dist-server/types/vendor/cbc-core/node/context/index.d.ts +1 -0
  40. package/cli/dist-server/types/vendor/cbc-core/node/context/pre-message-compact-strategy.d.ts +1 -2
  41. package/cli/dist-server/types/vendor/cbc-core/node/hooks/agent-trigger.d.ts +6 -22
  42. package/cli/dist-server/types/vendor/cbc-core/node/hooks/hook-protocol.d.ts +4 -1
  43. package/cli/dist-server/types/vendor/cbc-core/node/session/idle-queue-drain-service.d.ts +4 -56
  44. package/cli/dist-server/types/vendor/cbc-core/node/session/index.d.ts +4 -0
  45. package/cli/dist-server/types/vendor/cbc-core/node/session/interruption-service.d.ts +63 -9
  46. package/cli/dist-server/types/vendor/cbc-core/node/session/model-request-retry-phase.d.ts +16 -0
  47. package/cli/dist-server/types/vendor/cbc-core/node/session/model-response-interceptors.d.ts +33 -0
  48. package/cli/dist-server/types/vendor/cbc-core/node/session/recovery-budget.d.ts +55 -0
  49. package/cli/dist-server/types/vendor/cbc-core/node/session/session-hook-manager.d.ts +15 -0
  50. package/cli/dist-server/types/vendor/cbc-core/node/session/session-manager-host-protocol.d.ts +3 -2
  51. package/cli/dist-server/types/vendor/cbc-core/node/session/session-manager.d.ts +17 -4
  52. package/cli/dist-server/types/vendor/cbc-core/node/session/session-persistence-error.d.ts +43 -0
  53. package/cli/dist-server/types/vendor/cbc-core/node/session/session-protocol.d.ts +110 -9
  54. package/cli/dist-server/types/vendor/cbc-core/node/session/session-run-state-machine-protocol.d.ts +15 -1
  55. package/cli/dist-server/types/vendor/cbc-core/node/session/session-runtime-lifecycle.d.ts +5 -0
  56. package/cli/dist-server/types/vendor/cbc-core/node/session/session-store.d.ts +150 -4
  57. package/cli/dist-server/types/vendor/cbc-core/node/session/stream-timeout-retry-budget.d.ts +20 -1
  58. package/cli/dist-server/types/vendor/cbc-core/node/trace/turn-context.d.ts +28 -1
  59. package/cli/dist-server/types/vendor/cbc-core/node/utils/command-message-utils.d.ts +20 -0
  60. package/cli/dist-server/types/vendor/cbc-core/node/utils/history-utils.d.ts +27 -4
  61. package/cli/dist-server/types/vendor/cbc-core/node/utils/index.d.ts +1 -0
  62. package/cli/dist-server/types/vendor/cbc-core/node/utils/input-item-utils.d.ts +8 -0
  63. package/cli/dist-server/types/vendor/cbc-core/node/utils/message-utils.d.ts +12 -0
  64. package/cli/dist-server/types/vendor/cbc-core/node/utils/model-utils.d.ts +7 -0
  65. package/cli/dist-server/types/vendor/cbc-core/node/utils/queue-dispatch-utils.d.ts +24 -2
  66. package/cli/dist-server/types/vendor/cbc-core/node/utils/session-utils.d.ts +4 -1
  67. package/cli/dist-server/types/vendor/cbc-core/node/utils/string-retention-utils.d.ts +4 -0
  68. package/cli/dist-server/types/vendor/cbc-core/node/utils/token-utils.d.ts +3 -1
  69. package/cli/dist-server/types/vendor/cbc-shared/node/agent/openai-agents-types.d.ts +1 -0
  70. package/cli/dist-server/types/vendor/cbc-shared/node/checkpoint/checkpoint-types.d.ts +6 -0
  71. package/cli/dist-server/types/vendor/cbc-shared/node/hooks/hook-types.d.ts +7 -1
  72. package/cli/dist-server/types/vendor/cbc-shared/node/index.d.ts +2 -0
  73. package/cli/dist-server/types/vendor/cbc-shared/node/model/model-errors.d.ts +36 -4
  74. package/cli/dist-server/types/vendor/cbc-shared/node/tools/tool-names.d.ts +1 -0
  75. package/cli/dist-server/types/vendor/cbc-shared/node/utils/retry-backoff.d.ts +30 -0
  76. package/cli/dist-server/types/vendor/cbc-shared/node/utils/retry-policy.d.ts +26 -0
  77. package/cli/dist-server/types/workspace/agent-client-protocol/lib/common/index.d.ts +1 -0
  78. package/cli/dist-server/types/workspace/agent-client-protocol/lib/common/sandbox-rule-context.d.ts +38 -0
  79. package/cli/dist-server/types/workspace/authentication/lib/common/account-scoped-external-link-authentication-provider.d.ts +5 -5
  80. package/cli/dist-server/types/workspace/authentication/lib/common/account-utils.d.ts +25 -0
  81. package/cli/dist-server/types/workspace/authentication/lib/common/authentication-manager.d.ts +8 -2
  82. package/cli/dist-server/types/workspace/authentication/lib/common/authentication-observation.d.ts +36 -0
  83. package/cli/dist-server/types/workspace/authentication/lib/common/authentication-protocol.d.ts +40 -2
  84. package/cli/dist-server/types/workspace/authentication/lib/common/external-link-authentication-provider.d.ts +21 -5
  85. package/cli/dist-server/types/workspace/authentication/lib/common/index.d.ts +1 -0
  86. package/cli/dist-server/types/workspace/authentication/lib/common/wx-authentication-provider.d.ts +2 -2
  87. package/cli/dist-server/types/workspace/cbc-checkpoint/lib/node/checkpoint/checkpoint-protocol.d.ts +2 -0
  88. package/cli/dist-server/types/workspace/cbc-checkpoint/lib/node/checkpoint/checkpoint-service.d.ts +1 -0
  89. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-protocol.d.ts +60 -2
  90. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-purpose-protocol.d.ts +8 -4
  91. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-purpose-scope.d.ts +46 -0
  92. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-service.d.ts +28 -3
  93. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/index.d.ts +4 -0
  94. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/interceptors/input-interceptors.d.ts +1 -6
  95. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/model-call-failure.d.ts +9 -0
  96. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/model-step-sequence.d.ts +11 -0
  97. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/runner-factory.d.ts +56 -20
  98. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/speaker-label.d.ts +44 -0
  99. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/tool-call-loop-detector-service.d.ts +5 -4
  100. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/tool-call-loop-guard-protocol.d.ts +1 -1
  101. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/tool-call-loop-pattern.d.ts +16 -4
  102. package/cli/dist-server/types/workspace/cbc-core/lib/node/context/compaction-lineage.d.ts +39 -0
  103. package/cli/dist-server/types/workspace/cbc-core/lib/node/context/context-compact-summarizer.d.ts +2 -0
  104. package/cli/dist-server/types/workspace/cbc-core/lib/node/context/context-protocol.d.ts +17 -0
  105. package/cli/dist-server/types/workspace/cbc-core/lib/node/context/index.d.ts +1 -0
  106. package/cli/dist-server/types/workspace/cbc-core/lib/node/context/pre-message-compact-strategy.d.ts +1 -2
  107. package/cli/dist-server/types/workspace/cbc-core/lib/node/hooks/agent-trigger.d.ts +6 -22
  108. package/cli/dist-server/types/workspace/cbc-core/lib/node/hooks/hook-protocol.d.ts +4 -1
  109. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/idle-queue-drain-service.d.ts +4 -56
  110. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/index.d.ts +4 -0
  111. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/interruption-service.d.ts +63 -9
  112. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/model-request-retry-phase.d.ts +16 -0
  113. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/model-response-interceptors.d.ts +33 -0
  114. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/recovery-budget.d.ts +55 -0
  115. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-hook-manager.d.ts +15 -0
  116. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-manager-host-protocol.d.ts +3 -2
  117. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-manager.d.ts +17 -4
  118. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-persistence-error.d.ts +43 -0
  119. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-protocol.d.ts +110 -9
  120. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-run-state-machine-protocol.d.ts +15 -1
  121. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-runtime-lifecycle.d.ts +5 -0
  122. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-store.d.ts +150 -4
  123. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/stream-timeout-retry-budget.d.ts +20 -1
  124. package/cli/dist-server/types/workspace/cbc-core/lib/node/trace/turn-context.d.ts +28 -1
  125. package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/command-message-utils.d.ts +20 -0
  126. package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/history-utils.d.ts +27 -4
  127. package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/index.d.ts +1 -0
  128. package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/input-item-utils.d.ts +8 -0
  129. package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/message-utils.d.ts +12 -0
  130. package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/model-utils.d.ts +7 -0
  131. package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/queue-dispatch-utils.d.ts +24 -2
  132. package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/session-utils.d.ts +4 -1
  133. package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/string-retention-utils.d.ts +4 -0
  134. package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/token-utils.d.ts +3 -1
  135. package/cli/dist-server/types/workspace/cbc-shared/lib/node/agent/openai-agents-types.d.ts +1 -0
  136. package/cli/dist-server/types/workspace/cbc-shared/lib/node/checkpoint/checkpoint-types.d.ts +6 -0
  137. package/cli/dist-server/types/workspace/cbc-shared/lib/node/hooks/hook-types.d.ts +7 -1
  138. package/cli/dist-server/types/workspace/cbc-shared/lib/node/index.d.ts +2 -0
  139. package/cli/dist-server/types/workspace/cbc-shared/lib/node/model/model-errors.d.ts +36 -4
  140. package/cli/dist-server/types/workspace/cbc-shared/lib/node/tools/tool-names.d.ts +1 -0
  141. package/cli/dist-server/types/workspace/cbc-shared/lib/node/utils/retry-backoff.d.ts +30 -0
  142. package/cli/dist-server/types/workspace/cbc-shared/lib/node/utils/retry-policy.d.ts +26 -0
  143. package/cli/dist-server/types/workspace/cbc-workflow/lib/node/workflow/workflow-execution.d.ts +14 -1
  144. package/cli/dist-server/types/workspace/cbc-workflow/lib/node/workflow/workflow-manager.d.ts +7 -0
  145. package/cli/dist-server/types/workspace/cbc-worktree/lib/node/worktree/worktree-service.d.ts +5 -0
  146. package/cli/dist-server/types/workspace/cbc-worktree/lib/node/worktree/worktree-session.d.ts +3 -0
  147. package/cli/dist-server/types/workspace/core/lib/common/protocol.d.ts +8 -1
  148. package/cli/dist-server/types/workspace/product/lib/common/cloud-product-provider.d.ts +9 -0
  149. package/cli/dist-server/types/workspace/product/lib/common/index.d.ts +2 -0
  150. package/cli/dist-server/types/workspace/product/lib/common/pick-market-skill-id.d.ts +13 -0
  151. package/cli/dist-server/types/workspace/product/lib/common/tencent-docs-endpoint.d.ts +37 -0
  152. package/cli/dist-server/types/workspace/product/lib/common/tool-control-catalog.d.ts +2 -2
  153. package/cli/dist-server/types/workspace/product/lib/common/types/config.d.ts +12 -0
  154. package/cli/dist-server/types/workspace/product/lib/common/types/features.d.ts +63 -11
  155. package/cli/dist-server/types/workspace/product/lib/common/types/language-model.d.ts +66 -0
  156. package/cli/dist-server/types/workspace/product/lib/common/types/product.d.ts +22 -1
  157. package/cli/dist-server/types/workspace/sandbox-cli/lib/common/backup-policy.d.ts +10 -1
  158. package/cli/dist-server/types/workspace/sandbox-cli/lib/common/center-protocol.generated.d.ts +375 -4
  159. package/cli/dist-server/types/workspace/sandbox-cli/lib/common/file-policy.d.ts +5 -2
  160. package/cli/dist-server/types/workspace/sandbox-cli/lib/common/http-policy.d.ts +20 -0
  161. package/cli/dist-server/types/workspace/sandbox-cli/lib/common/rule-config.d.ts +10 -0
  162. package/cli/dist-server/types/workspace/sandbox-cli/lib/node/sandbox-center-client.d.ts +219 -0
  163. package/cli/dist-server/types/workspace/telemetry/lib/common/event/types/craft.d.ts +43 -3
  164. package/cli/package.json +1 -1
  165. package/cli/product.cloudhosted.json +4 -4
  166. package/cli/product.internal.json +268 -45
  167. package/cli/product.ioa.json +354 -161
  168. package/cli/product.json +338 -352
  169. package/cli/product.selfhosted.json +2 -2
  170. package/cli/vendor/shim/brokered-bin/7z +675 -0
  171. package/cli/vendor/shim/brokered-bin/7za +675 -0
  172. package/cli/vendor/shim/brokered-bin/7zz +675 -0
  173. package/cli/vendor/shim/brokered-bin/rar +675 -0
  174. package/cli/vendor/shim/brokered-bin/tar +675 -0
  175. package/cli/vendor/shim/brokered-bin/zip +187 -0
  176. package/docs/README.md +1 -0
  177. package/docs/in-process.md +42 -2
  178. package/docs/protocol.md +7 -1
  179. package/docs/server.md +2 -0
  180. package/lib/agent/v2.js +1 -1
  181. package/lib/application/services.d.ts +3 -1
  182. package/lib/application/services.js +1 -1
  183. package/lib/client/client.js +1 -1
  184. package/lib/client/mcp.d.ts +1 -1
  185. package/lib/client/mcp.js +1 -1
  186. package/lib/components/acp-mcp-transport.d.mts +84 -1
  187. package/lib/components/question-elicitation.d.mts +20 -1
  188. package/lib/components/sandbox-center.d.mts +2 -0
  189. package/lib/components/sandbox-center.mjs +1 -0
  190. package/lib/components/{acp/acp-prompt-input.d.ts → session/prompt-input.d.ts} +1 -1
  191. package/lib/components/session-config.d.mts +2 -0
  192. package/lib/components/session-config.mjs +1 -1
  193. package/lib/components/session-replay.d.mts +6 -7
  194. package/lib/components/session-replay.mjs +1 -1
  195. package/lib/effect-runtime/mcp-lifecycle.mjs +1 -1
  196. package/lib/harness/create-harness.js +1 -1
  197. package/lib/harness/runtime.js +1 -1
  198. package/lib/harness/types.d.ts +3 -0
  199. package/lib/integration/agent-integration.d.ts +5 -0
  200. package/lib/integration/executor-supervisor.js +1 -1
  201. package/lib/public.d.ts +1 -0
  202. package/lib/runtime/private-runtime-role.js +1 -1
  203. package/lib/runtime/sandbox-center.d.ts +21 -0
  204. package/lib/runtime/sandbox-center.js +1 -0
  205. package/lib/server/public.d.ts +1 -0
  206. package/lib/session/agent-backend.d.ts +5 -0
  207. package/lib/session/agent-backend.js +1 -1
  208. package/lib/session/config-defaults.d.ts +4 -0
  209. package/lib/session/config-defaults.js +1 -0
  210. package/lib/session/config-store.d.ts +1 -1
  211. package/lib/session/config-store.js +1 -1
  212. package/lib/session/local-fs.js +1 -1
  213. package/lib/session/replay.d.ts +2 -2
  214. package/lib/session/replay.js +1 -1
  215. package/lib/session/server-config.d.ts +11 -2
  216. package/lib/session/server-config.js +1 -1
  217. package/lib/session/server-events.d.ts +10 -8
  218. package/lib/session/server-events.js +1 -1
  219. package/lib/session/server-interactions.js +1 -1
  220. package/lib/session/server-mcp.js +1 -1
  221. package/package.json +27 -16
  222. package/lib/components/acp/acp-client-channel.d.ts +0 -36
  223. package/lib/components/acp/acp-mcp-transport.d.ts +0 -84
  224. package/lib/components/acp/acp-question-elicitation.d.ts +0 -20
  225. package/lib/session/local-options.d.ts +0 -50
  226. package/lib/session/local-options.js +0 -1
@@ -0,0 +1,55 @@
1
+ import type { Session } from './session-protocol';
2
+ /**
3
+ * `finish_reason=error` 三种表现(已有输出 / 仅 reasoning / 零 token)共用的预算键。
4
+ *
5
+ * 三者是同一次上游故障的不同形态,而且会在恢复过程中互相转化(第一次零 token、
6
+ * 重试后只吐 reasoning、再重试吐了内容后又 error)。各记各的会让一次故障的总轮数
7
+ * 远超约定上限,所以必须认领同一个键。
8
+ */
9
+ export declare const ERROR_RECOVERY_COUNT_META_KEY = "errorRecoveryCount";
10
+ /**
11
+ * 流开始之后的网络错误(错误仍带原始 errno)使用的预算键。
12
+ *
13
+ * 响应头之前的连接失败由模型层连接级重试处理,耗尽后被归一化成 HTTP 502 上抛,
14
+ * 不会再走到这里——两层不会为同一次失败接力。
15
+ */
16
+ export declare const NETWORK_RECOVERY_COUNT_META_KEY = "networkErrorRetryCount";
17
+ /**
18
+ * `finish_reason=error` 后注入给模型的续写提示。
19
+ *
20
+ * 与截断续写(TRUNCATION_CONTINUATION_PROMPT)的区别是刻意去掉了「把剩下的工作拆小」:
21
+ * 那句是在修「一次输出太长」的因果,上游内部错误与输出长度无关,带上它既是错误归因,
22
+ * 也可能让模型把任务切碎、多烧轮次。同样不告诉模型「是服务端出错」——那会给它道歉和
23
+ * 复述的由头,与 no apology / no recap 自相矛盾。
24
+ */
25
+ export declare const ERROR_RECOVERY_PROMPT: string;
26
+ /**
27
+ * 包成 error-recovery system-reminder:stream-json 等输出通道会把只含 system-reminder
28
+ * 的内部用户消息清空丢弃,避免恢复提示混进用户可见的对话。
29
+ */
30
+ export declare function buildErrorRecoveryReminder(): string;
31
+ export declare function readRecoveryBudgetCount(session: Session, key: string): number;
32
+ export declare function hasExhaustedRecoveryBudget(session: Session, key: string, limit?: number): boolean;
33
+ /**
34
+ * 同步完成「判定 + 认领」,返回本次恢复的序号(1-based);预算已用尽返回 `undefined`。
35
+ *
36
+ * 判定与消耗必须在同一个同步段里完成:分散到 `await` 两侧时,两处调用可能同时在
37
+ * `count = limit - 1` 通过检查,上限就不再成立。
38
+ */
39
+ export declare function claimRecoveryBudget(session: Session, key: string, limit?: number): number | undefined;
40
+ /** 认领后没有真正发起恢复(退避期间被取消、发起失败)时退回额度。 */
41
+ export declare function releaseRecoveryBudget(session: Session, key: string): void;
42
+ /** 清零并返回旧值,供日志使用。 */
43
+ export declare function resetRecoveryBudget(session: Session, key: string): number;
44
+ /**
45
+ * 「下一个模型请求是自动恢复轮」的一次性标记。
46
+ *
47
+ * 恢复轮的首 token 时限比首次请求短(见模型层)。这个标记在发起恢复 run 前由恢复
48
+ * 入口显式写入,由模型层在该 run 的第一个模型请求上读取并清除——之后同一 run 的工具
49
+ * 循环请求回到普通时限。不能改用重试计数反推「是否恢复轮」:计数跨多个模型请求累计,
50
+ * 反推会让恢复链之后的所有请求都被当成恢复轮。
51
+ */
52
+ export declare const RECOVERY_REQUEST_PENDING_META_KEY = "recoveryRequestPending";
53
+ export declare function markRecoveryRequestPending(session: Session): void;
54
+ export declare function consumeRecoveryRequestPending(session: Session | undefined): boolean;
55
+ export declare function clearRecoveryRequestPending(session: Session): void;
@@ -208,4 +208,19 @@ export declare class SessionHookManagerImpl implements SessionHookManager {
208
208
  * Does NOT support continueRequest.
209
209
  */
210
210
  executeFinalStopHooks(session: Session, reason?: FinalStopReason): Promise<void>;
211
+ /**
212
+ * UserPromptExpansion — Claude Code 官方事件:任何用户输入的命令/skill 展开成
213
+ * prompt、送进模型之前统一从这里触发,可阻断展开。`command_args` / `prompt` 按
214
+ * 官方 schema 是必填字段(无参数时发空串,而不是整个省略 key)。
215
+ */
216
+ executeUserPromptExpansionHooks(session: Session, payload: {
217
+ expansionType: 'slash_command' | 'mcp_prompt' | string;
218
+ commandName: string;
219
+ commandArgs: string;
220
+ commandSource?: string;
221
+ prompt: string;
222
+ }): Promise<{
223
+ allowed: boolean;
224
+ message?: string;
225
+ }>;
211
226
  }
@@ -1,5 +1,5 @@
1
1
  import type { AgentInputItem } from '../../../cbc-shared/node/index.js';
2
- import type { ModelResponseMetadata, Session } from './session-protocol';
2
+ import type { ModelCallGeneration, ModelResponseMetadata, Session } from './session-protocol';
3
3
  export declare const SessionCheckpointHost: unique symbol;
4
4
  export interface SessionCheckpointHost {
5
5
  createCheckpoint(session: Session): Promise<void>;
@@ -57,7 +57,8 @@ export declare const SessionResponseTelemetryHost: unique symbol;
57
57
  export interface SessionResponseTelemetryHost {
58
58
  reportChatRequestResponseTelemetry(session: Session, result: NonNullable<Session['resultSubject']['value']>, isSuccessful: boolean, error: unknown, metadata: ModelResponseMetadata): Promise<void>;
59
59
  reportMessageResponseTelemetryStream(session: Session, usage: SessionResponseUsage | undefined, metadata: ModelResponseMetadata, error: unknown): Promise<void>;
60
- reportChatMessageStatus(session: Session, errorCode: string, error?: unknown): Promise<void>;
60
+ /** Status of one model call (`generation`); run failures no model call owns are not reported. */
61
+ reportChatMessageStatus(session: Session, errorCode: string, generation: ModelCallGeneration, error?: unknown): Promise<void>;
61
62
  }
62
63
  export type SessionResponseTelemetrySnapshot = Pick<NonNullable<Session['telemetry']>, 'modelId' | 'modelName' | 'currentTurn' | 'traceId'>;
63
64
  export declare const SessionResponseObserver: unique symbol;
@@ -4,7 +4,7 @@ import { Logger } from '../../../../workspace/telemetry/lib/common/index.js';
4
4
  import { BehaviorSubject } from 'rxjs';
5
5
  import { SessionRequestContextHost, SessionSettingsHost as SettingsManager, SessionUsageHost as UserStateManager } from './session-host-protocol';
6
6
  import { SessionBackgroundTaskHost as ToolManager, SessionCheckpointHost as CheckpointService, SessionProgressHost as ProgressSyncService, SessionResponseObserver as GalileoSessionBridge, SessionResponseTelemetryHost as TelemetryService, SessionSchedulerHost as CronSchedulerService, SessionSensitiveProjectionHost, SessionTaskLifecycleHost as AgentTaskManager } from './session-manager-host-protocol';
7
- import { AgentInputItemProcessor, InterruptionService, ModelResponseInterceptor, ModelResponseMetadata, Session, SessionFactory, SessionGetOptions, SessionHookManager, SessionManager, SessionStore } from './session-protocol';
7
+ import { AgentInputItemProcessor, InterruptionService, ModelResponseInterceptor, ModelResponseMetadata, OverrideModelSource, Session, SessionFactory, SessionGetOptions, SessionHookManager, SessionManager, SessionStore } from './session-protocol';
8
8
  import { SessionRunStateMachine } from './session-run-state-machine-protocol';
9
9
  export declare class SessionManagerImpl implements SessionManager, ApplicationLifecycle<Application> {
10
10
  protected readonly sessionFactory: SessionFactory;
@@ -33,8 +33,19 @@ export declare class SessionManagerImpl implements SessionManager, ApplicationLi
33
33
  private sessionStartTimes;
34
34
  private addHistoryLocks;
35
35
  private resultSubscriptions;
36
+ private readonly resultSubscriptionOwners;
37
+ /**
38
+ * 每个 sessionId 当前活着的会话对象。身份守卫不能只认 result 订阅的登记:
39
+ * 订阅由调用方事后 `initRunResultHandler` 挂上(teammate / agent-task),而
40
+ * drain / team-inbox / turn-metrics 在 create 时就按 id 注册了,中间那段
41
+ * 「已注册、无订阅」的窗口里 owner 读不到,旧任务的延迟释放会摘掉同 id 后继
42
+ * 会话的注册。WeakRef:登记不得延长会话寿命,deref 为空即无需保护的对象。
43
+ */
44
+ private readonly liveSessionsById;
36
45
  private overridePermissionModes;
37
46
  private overrideModels;
47
+ /** 与 overrideModels 同生命周期的意图来源(user / declared / materialized)。 */
48
+ private overrideModelSources;
38
49
  /**
39
50
  * Issue #12554:会话级 thinking override(按 sessionId 隔离)。
40
51
  * 由 ACP setSessionConfigOption('thought_level') 或 prompt _meta 写入。
@@ -177,13 +188,15 @@ export declare class SessionManagerImpl implements SessionManager, ApplicationLi
177
188
  *
178
189
  * 幂等:未注册的 id 为 no-op;DI 容错:精简变体缺 service 时降级跳过。
179
190
  */
180
- releaseInMemory(id: string): void;
191
+ releaseInMemory(target: string | Session): void;
181
192
  rename(session: Session, name: string): Promise<void>;
182
193
  setOverridePermissionMode(sessionId: string, mode: PermissionMode): void;
183
194
  getOverridePermissionMode(sessionId: string): PermissionMode | undefined;
184
- setOverrideModel(sessionId: string, model: string): void;
195
+ setOverrideModel(sessionId: string, model: string, source?: OverrideModelSource): void;
185
196
  getOverrideModel(sessionId: string): string | undefined;
186
- setRuntimeModel(session: Session | undefined, modelId: string): void;
197
+ getOverrideModelSource(sessionId: string): OverrideModelSource | undefined;
198
+ clearOverrideModel(sessionId: string): void;
199
+ setRuntimeModel(session: Session | undefined, modelId: string, source?: OverrideModelSource): void;
187
200
  setRuntimeOutputStyle(session: Session | undefined, style: string): void;
188
201
  /**
189
202
  * Issue #83229:把 settings.json 中的 model / outputStyle 读一次"钉"进 session.options,
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Typed local-transcript I/O failure (issue #119545).
3
+ *
4
+ * The only reason this type exists: `addHistory` must be able to tell "the
5
+ * local JSONL copy could not be written" apart from "this turn is broken".
6
+ * Windows `EBUSY` on the transcript is a third-party sharing violation, and a
7
+ * side-channel copy must never terminate a turn that is still executing tools.
8
+ *
9
+ * Everything else about persistence stays best-effort on purpose: there is no
10
+ * pending queue, no cross-process outbox and no durability barrier, so nothing
11
+ * else in the runtime waits on, or can be vetoed by, this file.
12
+ */
13
+ export type SessionPersistencePhase = 'open' | 'stat' | 'write' | 'close' | 'rollback';
14
+ export type SessionPersistenceRollbackOutcome = 'not-needed' | 'succeeded' | 'failed';
15
+ export interface SessionPersistenceErrorOptions {
16
+ phase: SessionPersistencePhase;
17
+ cause: unknown;
18
+ attempt?: number;
19
+ rollbackOutcome?: SessionPersistenceRollbackOutcome;
20
+ retryable?: boolean;
21
+ }
22
+ /**
23
+ * Windows sharing violations and their POSIX lookalikes. `EBUSY` is the one
24
+ * this ticket measured (25% of appends within 10ms of the previous write);
25
+ * `EPERM` / `EACCES` ride along because the same scanners produce them.
26
+ */
27
+ export declare function isRetryableSessionPersistenceError(error: unknown): boolean;
28
+ export declare class SessionPersistenceError extends Error {
29
+ readonly phase: SessionPersistencePhase;
30
+ readonly code?: string;
31
+ readonly attempt: number;
32
+ readonly rollbackOutcome: SessionPersistenceRollbackOutcome;
33
+ readonly retryable: boolean;
34
+ constructor(options: SessionPersistenceErrorOptions);
35
+ }
36
+ /**
37
+ * Duck-typed on purpose: core and the host package can each hold their own copy
38
+ * of this class, so `instanceof` is not reliable across the package boundary.
39
+ * The required fields keep a foreign error named `SessionPersistenceError` from
40
+ * being mistaken for one of ours — an unrecognized error still fails the run,
41
+ * which is the safe direction.
42
+ */
43
+ export declare function isSessionPersistenceError(error: unknown): error is SessionPersistenceError;
@@ -2,6 +2,7 @@ import { Deferred } from '@celljs/core';
2
2
  import { type AgentInputItem, ApprovalOptions, type Checkpoint, FinalStopReason, NotificationType, PermissionMode, ReasoningEffortLevel, type ResponseStreamEvent, type RunItem, type RunResult, type RunState, type RunToolApprovalItem, type SdkCapabilities, SessionEndReason, SessionStartSource, type StreamedRunResult, type TerminalEvent, type ToolDeferOverlaySnapshot, ToolPermissionContext, type Usage } from '../../../cbc-shared/node/index.js';
3
3
  import { Command } from '../../../../workspace/product/lib/common/index.js';
4
4
  import { BehaviorSubject, Subject } from 'rxjs';
5
+ import type { CompactionLineage } from '../context/compaction-lineage';
5
6
  import { BackgroundTask } from './background-task-protocol';
6
7
  import type { SessionRunStateSnapshot } from './session-run-state-machine-protocol';
7
8
  import type { Lane, LanePointer, SessionKey, SessionStoreEntry } from './session-store-contract';
@@ -86,9 +87,11 @@ export type AgentState = 'agent_pending' | 'agent_start' | 'agent_tool_start' |
86
87
  * 则 emit,触发 UI 显示"正在同步文件"提示)
87
88
  */
88
89
  export type AgentPhase = 'preparing' | 'model_requesting' | 'model_streaming' | 'model_done' | 'tool_executing' | 'waiting_for_permission' | 'waiting_for_user' | 'retrying' | 'finalization_file_projection_sync' | 'finalization_file_projection_sync_notify' | 'idle';
90
+ export type AgentRetryReason = 'network';
89
91
  export interface AgentPhaseInfo {
90
92
  phase: AgentPhase;
91
93
  toolName?: string;
94
+ toolCallId?: string;
92
95
  streamingToolName?: string;
93
96
  startedAt: number;
94
97
  /**
@@ -101,6 +104,13 @@ export interface AgentPhaseInfo {
101
104
  current: number;
102
105
  total: number;
103
106
  };
107
+ /**
108
+ * 仅 retrying phase 使用,经 ACP `_meta['codebuddy.ai/agentPhase']` 透传给上层。
109
+ * 缺省表示原因未分类(如流超时),不代表网络正常。
110
+ */
111
+ retry?: {
112
+ reason: AgentRetryReason;
113
+ };
104
114
  }
105
115
  export declare const AgentPhaseUtils: {
106
116
  /** Create an AgentPhaseInfo with the current timestamp. */
@@ -177,6 +187,8 @@ export interface PreToolUseHookResult {
177
187
  permissionDecision?: 'allow' | 'deny' | 'ask';
178
188
  permissionDecisionReason?: string;
179
189
  runtimeSecurity?: Record<string, unknown>;
190
+ /** PreToolUse `continue:false` — stop the current turn after the deny result is recorded. */
191
+ preventContinuation?: boolean;
180
192
  }
181
193
  export interface Session {
182
194
  id: string;
@@ -206,6 +218,8 @@ export interface Session {
206
218
  */
207
219
  replSandboxDepth?: number;
208
220
  state?: RunState<any, any>;
221
+ /** Emitted after a physical run releases its lifecycle owner and abort links. */
222
+ runSettledSubject?: Subject<void>;
209
223
  createdAt: number;
210
224
  updatedAt: number;
211
225
  meta?: Record<string, any>;
@@ -348,6 +362,14 @@ export interface Session {
348
362
  * field and pass it through as `options.maxTurns` explicitly.
349
363
  */
350
364
  lastRunMaxTurns?: number;
365
+ /**
366
+ * Latest agent-loop model call number (`providerData.stepSeq`). Unlike the
367
+ * SDK turn counter it survives runs, compaction and resume; see
368
+ * `allocateModelStepSeq`.
369
+ */
370
+ modelStepSeq?: number;
371
+ /** Compactions of this Session's context; see `getCompactionLineage`. */
372
+ compactionLineage?: CompactionLineage;
351
373
  queue: AgentInputItem[];
352
374
  queueSubject: BehaviorSubject<AgentInputItem[]>;
353
375
  /**
@@ -638,6 +660,12 @@ export interface Session {
638
660
  * Context from UserPromptSubmit hook to be injected into current user message
639
661
  */
640
662
  userPromptSubmitContext?: string;
663
+ /**
664
+ * Context from UserPromptExpansion hook (hookSpecificOutput.additionalContext),
665
+ * to be injected alongside the expanded prompt (Claude Code parity: same
666
+ * injection point as UserPromptSubmit — "alongside the submitted prompt").
667
+ */
668
+ userPromptExpansionContext?: string;
641
669
  /**
642
670
  * Context from PostToolUse hook to be injected after tool execution
643
671
  */
@@ -849,7 +877,7 @@ export interface SubagentInvocationRecord {
849
877
  lifecycle: SubagentLifecycleSnapshot;
850
878
  }
851
879
  export type SubagentLifecycleDescriptor = Omit<SubagentLifecycleSnapshot, 'status' | 'updatedAt' | 'usage'>;
852
- export type CombineEvent = (AgentInputItemEvent | ModelRawResponseEvent | ResultEndEvent | InterruptResultEvent | NoticeEvent | SubagentStatusEvent | CompactionLifecycleEvent | TerminalEvent) & CombineEventMeta;
880
+ export type CombineEvent = (AgentInputItemEvent | AgentSdkStreamEvent | ModelRawResponseEvent | ResultEndEvent | InterruptResultEvent | NoticeEvent | SubagentStatusEvent | CompactionLifecycleEvent | TerminalEvent) & CombineEventMeta;
853
881
  export interface CompactionLifecycleEvent {
854
882
  type: 'compaction';
855
883
  data: {
@@ -864,6 +892,11 @@ export interface SubagentStatusEvent {
864
892
  type: 'subagent_status';
865
893
  data: SubagentLifecycleSnapshot;
866
894
  }
895
+ /** Original SDK stream payload, observed by the existing single stream consumer. */
896
+ export interface AgentSdkStreamEvent {
897
+ type: 'sdk';
898
+ data: import('../../../cbc-shared/node/index.js').RunStreamEvent;
899
+ }
867
900
  export interface AgentInputItemEvent {
868
901
  type: 'input';
869
902
  data: AgentInputItem;
@@ -915,6 +948,8 @@ export interface SessionOptions {
915
948
  debugToStderr?: boolean;
916
949
  verbose?: boolean;
917
950
  print?: boolean;
951
+ /** Host Bash output preference; omitted preserves the CLI's PTY selection. */
952
+ usePty?: boolean;
918
953
  outputFormat?: 'text' | 'json' | 'stream-json';
919
954
  inputFormat?: 'text' | 'stream-json';
920
955
  /** Whether to persist the session transcript. Defaults to true; false keeps history in memory only. */
@@ -1050,6 +1085,13 @@ export interface SessionRewindMutationOptions {
1050
1085
  cwd: string;
1051
1086
  headMessageId: string | undefined;
1052
1087
  }
1088
+ /**
1089
+ * model override 的意图来源:决定该值是否等价于「用户显式选择」。
1090
+ * - 'user':/model 命令、ACP set_model、SDK 控制信号等用户动作;
1091
+ * - 'declared':主 Agent 声明模型(declaredModel)联动写入;
1092
+ * - 'materialized':Web UI 会话装配期钉住的兜底解析值(非用户意图)。
1093
+ */
1094
+ export type OverrideModelSource = 'user' | 'declared' | 'materialized';
1053
1095
  export interface SessionManager {
1054
1096
  getCurrent(): Session;
1055
1097
  setCurrent(session: Session): void;
@@ -1123,9 +1165,11 @@ export interface SessionManager {
1123
1165
  *
1124
1166
  * 幂等:未注册的 sessionId 为 no-op。
1125
1167
  *
1126
- * @param id 已完成 subagent 的 session id
1168
+ * @param target 传 Session 对象时,索引键与身份校验同源——只有注册表当前持有
1169
+ * 的正是这个对象才释放,复用同一 sessionId 的后继对象不会被误清。只拿得到
1170
+ * id 的调用方(RPC、`remove(id)`)传字符串,此时不做身份校验。
1127
1171
  */
1128
- releaseInMemory(id: string): void;
1172
+ releaseInMemory(target: string | Session): void;
1129
1173
  /**
1130
1174
  * 该 sessionId 是否已在本进程通过 get() 加载过(且尚未 remove()/releaseInMemory())。
1131
1175
  *
@@ -1150,11 +1194,15 @@ export interface SessionManager {
1150
1194
  setOverridePermissionMode(sessionId: string, mode: PermissionMode): void;
1151
1195
  getOverridePermissionMode(sessionId: string): PermissionMode | undefined;
1152
1196
  /**
1153
- * 设置 session 的 model 覆盖值(来自 SDK control signal)
1154
- * 这些值会覆盖 CLI 参数和配置文件的设置
1197
+ * 设置 session 的 model 覆盖值。source 记录意图来源,供「是否用户显式选择」判定:
1198
+ * - 'user'(默认):/model 命令、ACP set_model、SDK 控制信号等用户动作;
1199
+ * - 'declared':主 Agent 声明模型(declaredModel)联动写入;
1200
+ * - 'materialized':Web UI 会话装配期钉住的兜底解析值(非用户意图)。
1155
1201
  */
1156
- setOverrideModel(sessionId: string, model: string): void;
1202
+ setOverrideModel(sessionId: string, model: string, source?: OverrideModelSource): void;
1157
1203
  getOverrideModel(sessionId: string): string | undefined;
1204
+ getOverrideModelSource(sessionId: string): OverrideModelSource | undefined;
1205
+ clearOverrideModel(sessionId: string): void;
1158
1206
  /**
1159
1207
  * 设置会话运行时模型:同步写 session.options.model + requestOptions.model + override map。
1160
1208
  *
@@ -1163,7 +1211,7 @@ export interface SessionManager {
1163
1211
  * 供 applyOverrideModel 每轮重建 requestOptions(Issue #82146)。/model 命令与模型面板
1164
1212
  * 共用此入口;ACP set_model(applyRuntimeSessionModel)仍为独立实现,待统一收敛。
1165
1213
  */
1166
- setRuntimeModel(session: Session | undefined, modelId: string): void;
1214
+ setRuntimeModel(session: Session | undefined, modelId: string, source?: OverrideModelSource): void;
1167
1215
  /**
1168
1216
  * 设置会话运行时 outputStyle:同步写 session.options.outputStyle。
1169
1217
  *
@@ -1216,8 +1264,31 @@ export interface SessionManager {
1216
1264
  */
1217
1265
  flushHistory(session: Session): Promise<void>;
1218
1266
  }
1267
+ /**
1268
+ * Cumulative transcript persistence counters (issue #119545 埋点建议).
1269
+ * A best-effort side channel, so every reader must treat the numbers as a
1270
+ * snapshot that may be sampled at any moment.
1271
+ */
1272
+ export interface TranscriptPersistenceMetrics {
1273
+ /** In-band retry attempts consumed. */
1274
+ retries: number;
1275
+ /** Batches that only landed because of a retry. */
1276
+ retrySucceeded: number;
1277
+ /** Batches given up on after the retry budget. */
1278
+ abandonedBatches: number;
1279
+ /** Lines lost with those batches. */
1280
+ abandonedLines: number;
1281
+ }
1219
1282
  export interface SessionStore {
1220
1283
  getSessionFilePath(id: string, parentSessionId?: string, cwd?: string): string;
1284
+ /**
1285
+ * Transcript persistence counters, when the implementation keeps any.
1286
+ * Optional so in-memory and host-delegating stores do not have to fake it.
1287
+ * Exposed so callers that observe a degradation can log the counters from
1288
+ * their own call site: the store's own abandon audit line is best-effort
1289
+ * and a lost line would otherwise take the only copy of the numbers.
1290
+ */
1291
+ transcriptPersistenceMetrics?(): Readonly<TranscriptPersistenceMetrics>;
1221
1292
  get(id: string, options?: SessionGetOptions): Promise<Session | undefined>;
1222
1293
  getAcrossProjects(id: string, options?: SessionGetOptions): Promise<Session | undefined>;
1223
1294
  save(session: Session, cwd?: string): Promise<void>;
@@ -1376,6 +1447,26 @@ export interface SessionHookManager {
1376
1447
  * Does NOT support continueRequest.
1377
1448
  */
1378
1449
  executeFinalStopHooks(session: Session, reason?: FinalStopReason): Promise<void>;
1450
+ /**
1451
+ * UserPromptExpansion — Claude Code 官方事件(非 cbc 专属扩展):任何用户输入的
1452
+ * 命令/skill 在展开成 prompt、送进模型之前统一从这里触发,可阻断展开。适用于
1453
+ * skill、自定义命令、Dynamic Workflow、MCP prompt 等一切"输入即展开"的路径,
1454
+ * 不是只服务某一个具体调用方(如统一资产门控)。
1455
+ */
1456
+ executeUserPromptExpansionHooks(session: Session, payload: {
1457
+ /** Claude Code spec: 'slash_command' for skill/custom commands, 'mcp_prompt' for MCP prompts. */
1458
+ expansionType: 'slash_command' | 'mcp_prompt' | string;
1459
+ commandName: string;
1460
+ /** Claude Code spec: required field (empty string when no args), always sent. */
1461
+ commandArgs: string;
1462
+ /** e.g. Skill.source / Command.scope ('project' | 'user' | 'plugin' | 'mcp' | ...). */
1463
+ commandSource?: string;
1464
+ /** Claude Code spec: required field — raw, pre-expansion prompt text as typed by the user. */
1465
+ prompt: string;
1466
+ }): Promise<{
1467
+ allowed: boolean;
1468
+ message?: string;
1469
+ }>;
1379
1470
  }
1380
1471
  export interface RunItemProcessor {
1381
1472
  process(runItem: RunItem): Promise<void>;
@@ -1444,6 +1535,7 @@ export interface InterruptionService {
1444
1535
  approve(item: RunToolApprovalItem, options?: ApprovalOptions): void;
1445
1536
  reject(item: RunToolApprovalItem, options?: {
1446
1537
  decision?: 'deny' | 'rejectAndExitPlan';
1538
+ cancelTurn?: boolean;
1447
1539
  }): void;
1448
1540
  waitFor(session: Session): Promise<void>;
1449
1541
  /** Resolve the main/leader session for a given session (returns self if already main). */
@@ -1494,9 +1586,10 @@ export interface InterruptionService {
1494
1586
  *
1495
1587
  * 幂等:session 未注册时为 no-op。只清内存映射,不动磁盘 jsonl。
1496
1588
  *
1497
- * @param sessionId 已完成 subagent 的 session id
1589
+ * @param target 传 Session 对象时按对象身份校验,同 id 的后继对象不会被误清;
1590
+ * 只拿得到 id 的调用方传字符串,此时不做身份校验。
1498
1591
  */
1499
- releaseSession(sessionId: string): void;
1592
+ releaseSession(target: string | Session): void;
1500
1593
  }
1501
1594
  export interface MessageQueueManager {
1502
1595
  enqueueMessage(session: Session, message: AgentInputItem): string;
@@ -1653,6 +1746,12 @@ export interface TurnMetricsReporter {
1653
1746
  */
1654
1747
  unregister(sessionId: string): void;
1655
1748
  }
1749
+ /** Ids of one model call, as stamped by the model wrapper. */
1750
+ export interface ModelCallGeneration {
1751
+ messageId: string;
1752
+ conversationRequestId?: string;
1753
+ stepSeq?: number;
1754
+ }
1656
1755
  export interface ModelResponseMetadata {
1657
1756
  /** 响应中的模型 ID */
1658
1757
  model?: string;
@@ -1666,6 +1765,8 @@ export interface ModelResponseMetadata {
1666
1765
  * 都带 providerData.messageId === 此值,handleContentFilteredResponse 据此剔除并替换为安全提示。
1667
1766
  */
1668
1767
  contentFilterMessageId?: string;
1768
+ /** Correlation of the generation that just completed, as stamped by the model wrapper. */
1769
+ generation?: ModelCallGeneration;
1669
1770
  usage?: {
1670
1771
  prompt_tokens: number;
1671
1772
  completion_tokens: number;
@@ -1,5 +1,5 @@
1
1
  import type { Observable } from 'rxjs';
2
- import type { Session } from './session-protocol';
2
+ import type { AgentRetryReason, Session } from './session-protocol';
3
3
  export declare const SessionRunStateMachine: unique symbol;
4
4
  export declare const SessionRunStateProjectionService: unique symbol;
5
5
  export declare const SESSION_RUN_STATE_PROJECTION_SCHEMA: 'session-run-state.v1';
@@ -114,6 +114,7 @@ export type SessionRunEvent = {
114
114
  } | {
115
115
  type: SessionRunEventType.TOOL_STARTED;
116
116
  toolName?: string;
117
+ toolCallId?: string;
117
118
  reason?: string;
118
119
  } | {
119
120
  type: SessionRunEventType.TOOL_ENDED;
@@ -143,6 +144,7 @@ export type SessionRunEvent = {
143
144
  } | {
144
145
  type: SessionRunEventType.RETRYING;
145
146
  reason?: string;
147
+ retryReason?: AgentRetryReason;
146
148
  } | {
147
149
  type: SessionRunEventType.COMPACT_STARTED;
148
150
  reason?: string;
@@ -188,6 +190,18 @@ export interface SessionRunStateMachine {
188
190
  */
189
191
  getChange$(session: Session, skipFirst?: boolean): Observable<void>;
190
192
  }
193
+ export declare const ModelRequestRetryPhase: unique symbol;
194
+ /**
195
+ * 模型请求层(宿主 provider)在同一次请求内部退避重发时,借此把会话投影为 retrying。
196
+ * 状态写入与守卫收口在 core,宿主只包住退避等待,不直接驱动状态机。
197
+ */
198
+ export interface ModelRequestRetryPhase {
199
+ /**
200
+ * `wait` 期间会话显示 retrying 并携带 `reason`;结束(含抛错 / 取消)后恢复 model_requesting。
201
+ * 非本轮主请求(无 session、辅助型 purpose、状态不在 model_requesting)时只执行 `wait`。
202
+ */
203
+ during<T>(session: Session | undefined, reason: AgentRetryReason, wait: () => Promise<T>): Promise<T>;
204
+ }
191
205
  /**
192
206
  * Pure derivations from a `SessionRunStatus`. The state machine implementation
193
207
  * MUST keep its instance methods (`getLifecycle`, `isBusy`, etc.) consistent
@@ -0,0 +1,5 @@
1
+ import type { Session } from './session-protocol';
2
+ export declare function isSessionRuntimeClosed(session: Session): boolean;
3
+ export declare function closeSessionRuntime(session: Session): void;
4
+ export declare function sessionRuntimeSignal(session: Session): AbortSignal;
5
+ export declare function assertSessionRuntimeOpen(session: Session | undefined): void;