@tencent-ai/agent-harness 0.2.0-beta.2 → 0.2.0-beta.4

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 (182) hide show
  1. package/CHANGELOG.md +40 -2
  2. package/cli/CHANGELOG.md +64 -0
  3. package/cli/dist-server/shared.cjs +450 -329
  4. package/cli/dist-server/types/node/acp/acp-protocol.d.ts +8 -0
  5. package/cli/dist-server/types/node/bash-sandbox/bash-sandbox-protocol.d.ts +3 -0
  6. package/cli/dist-server/types/node/cli/cli-protocol.d.ts +3 -0
  7. package/cli/dist-server/types/node/cli/stream-json-protocol.d.ts +8 -1
  8. package/cli/dist-server/types/node/loopback/server-protocol.d.ts +5 -0
  9. package/cli/dist-server/types/node/sensitive-content/sensitive-content-protocol.d.ts +7 -0
  10. package/cli/dist-server/types/node/server/boot.d.ts +7 -4
  11. package/{lib/components → cli/dist-server/types/node/server/formats}/acp/acp-error-model.d.ts +1 -1
  12. package/{lib/components → cli/dist-server/types/node/server/formats}/acp/acp-protocol.d.ts +2 -3
  13. package/cli/dist-server/types/node/server/formats/acp/index.d.ts +12 -0
  14. package/cli/dist-server/types/node/server/formats/acp/projection.d.ts +10 -0
  15. package/cli/dist-server/types/node/server/index.d.ts +1 -1
  16. package/cli/dist-server/types/node/server/sessions.d.ts +3 -2
  17. package/cli/dist-server/types/node/server/types.d.ts +59 -7
  18. package/cli/dist-server/types/node/tools/tool-protocol.d.ts +39 -24
  19. package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-protocol.d.ts +31 -2
  20. package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-purpose-protocol.d.ts +8 -4
  21. package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-purpose-scope.d.ts +46 -0
  22. package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-service.d.ts +26 -3
  23. package/cli/dist-server/types/vendor/cbc-core/node/agent/index.d.ts +3 -0
  24. package/cli/dist-server/types/vendor/cbc-core/node/agent/model-call-failure.d.ts +9 -0
  25. package/cli/dist-server/types/vendor/cbc-core/node/agent/model-step-sequence.d.ts +11 -0
  26. package/cli/dist-server/types/vendor/cbc-core/node/agent/runner-factory.d.ts +43 -9
  27. package/cli/dist-server/types/vendor/cbc-core/node/agent/tool-call-loop-guard-protocol.d.ts +1 -1
  28. package/cli/dist-server/types/vendor/cbc-core/node/agent/tool-call-loop-pattern.d.ts +9 -8
  29. package/cli/dist-server/types/vendor/cbc-core/node/context/compaction-lineage.d.ts +39 -0
  30. package/cli/dist-server/types/vendor/cbc-core/node/context/context-compact-summarizer.d.ts +2 -0
  31. package/cli/dist-server/types/vendor/cbc-core/node/context/context-protocol.d.ts +17 -0
  32. package/cli/dist-server/types/vendor/cbc-core/node/context/index.d.ts +2 -0
  33. package/cli/dist-server/types/vendor/cbc-core/node/context/mods-bridge.d.ts +115 -0
  34. package/cli/dist-server/types/vendor/cbc-core/node/context/pre-message-compact-strategy.d.ts +1 -2
  35. package/cli/dist-server/types/vendor/cbc-core/node/message-queue/followup-queue-protocol.d.ts +3 -2
  36. package/cli/dist-server/types/vendor/cbc-core/node/message-queue/followup-queue.d.ts +1 -1
  37. package/cli/dist-server/types/vendor/cbc-core/node/message-queue/steer-input-buffer-protocol.d.ts +4 -0
  38. package/cli/dist-server/types/vendor/cbc-core/node/session/can-use-tool.d.ts +4 -0
  39. package/cli/dist-server/types/vendor/cbc-core/node/session/index.d.ts +1 -0
  40. package/cli/dist-server/types/vendor/cbc-core/node/session/interruption-service.d.ts +8 -0
  41. package/cli/dist-server/types/vendor/cbc-core/node/session/model-request-retry-phase.d.ts +16 -0
  42. package/cli/dist-server/types/vendor/cbc-core/node/session/model-response-interceptors.d.ts +15 -0
  43. package/cli/dist-server/types/vendor/cbc-core/node/session/session-manager-host-protocol.d.ts +3 -2
  44. package/cli/dist-server/types/vendor/cbc-core/node/session/session-manager.d.ts +37 -3
  45. package/cli/dist-server/types/vendor/cbc-core/node/session/session-protocol.d.ts +59 -5
  46. package/cli/dist-server/types/vendor/cbc-core/node/session/session-run-state-machine-protocol.d.ts +14 -1
  47. package/cli/dist-server/types/vendor/cbc-core/node/session/stream-timeout-retry-budget.d.ts +8 -1
  48. package/cli/dist-server/types/vendor/cbc-core/node/trace/turn-context.d.ts +28 -1
  49. package/cli/dist-server/types/vendor/cbc-core/node/utils/command-message-utils.d.ts +20 -0
  50. package/cli/dist-server/types/vendor/cbc-core/node/utils/history-utils.d.ts +4 -4
  51. package/cli/dist-server/types/vendor/cbc-core/node/utils/input-item-utils.d.ts +9 -1
  52. package/cli/dist-server/types/vendor/cbc-core/node/utils/token-utils.d.ts +3 -1
  53. package/cli/dist-server/types/vendor/cbc-shared/node/agent/openai-agents-types.d.ts +1 -0
  54. package/cli/dist-server/types/vendor/cbc-shared/node/checkpoint/checkpoint-types.d.ts +6 -0
  55. package/cli/dist-server/types/vendor/cbc-shared/node/model/model-errors.d.ts +30 -2
  56. package/cli/dist-server/types/workspace/agent-client-protocol/lib/common/index.d.ts +1 -0
  57. package/cli/dist-server/types/workspace/agent-client-protocol/lib/common/prompt-codec.d.ts +4 -0
  58. package/cli/dist-server/types/workspace/agent-client-protocol/lib/common/sandbox-rule-context.d.ts +38 -0
  59. package/cli/dist-server/types/workspace/agent-client-protocol/lib/common/types.d.ts +15 -1
  60. package/cli/dist-server/types/workspace/authentication/lib/common/account-scoped-external-link-authentication-provider.d.ts +3 -3
  61. package/cli/dist-server/types/workspace/authentication/lib/common/authentication-manager.d.ts +6 -0
  62. package/cli/dist-server/types/workspace/authentication/lib/common/authentication-observation.d.ts +36 -0
  63. package/cli/dist-server/types/workspace/authentication/lib/common/authentication-protocol.d.ts +21 -0
  64. package/cli/dist-server/types/workspace/authentication/lib/common/external-link-authentication-provider.d.ts +20 -4
  65. package/cli/dist-server/types/workspace/authentication/lib/common/index.d.ts +1 -0
  66. package/cli/dist-server/types/workspace/cbc-checkpoint/lib/node/checkpoint/checkpoint-protocol.d.ts +2 -0
  67. package/cli/dist-server/types/workspace/cbc-checkpoint/lib/node/checkpoint/checkpoint-service.d.ts +1 -0
  68. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-protocol.d.ts +31 -2
  69. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-purpose-protocol.d.ts +8 -4
  70. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-purpose-scope.d.ts +46 -0
  71. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-service.d.ts +26 -3
  72. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/index.d.ts +3 -0
  73. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/model-call-failure.d.ts +9 -0
  74. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/model-step-sequence.d.ts +11 -0
  75. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/runner-factory.d.ts +43 -9
  76. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/tool-call-loop-guard-protocol.d.ts +1 -1
  77. package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/tool-call-loop-pattern.d.ts +9 -8
  78. package/cli/dist-server/types/workspace/cbc-core/lib/node/context/compaction-lineage.d.ts +39 -0
  79. package/cli/dist-server/types/workspace/cbc-core/lib/node/context/context-compact-summarizer.d.ts +2 -0
  80. package/cli/dist-server/types/workspace/cbc-core/lib/node/context/context-protocol.d.ts +17 -0
  81. package/cli/dist-server/types/workspace/cbc-core/lib/node/context/index.d.ts +2 -0
  82. package/cli/dist-server/types/workspace/cbc-core/lib/node/context/mods-bridge.d.ts +115 -0
  83. package/cli/dist-server/types/workspace/cbc-core/lib/node/context/pre-message-compact-strategy.d.ts +1 -2
  84. package/cli/dist-server/types/workspace/cbc-core/lib/node/message-queue/followup-queue-protocol.d.ts +3 -2
  85. package/cli/dist-server/types/workspace/cbc-core/lib/node/message-queue/followup-queue.d.ts +1 -1
  86. package/cli/dist-server/types/workspace/cbc-core/lib/node/message-queue/steer-input-buffer-protocol.d.ts +4 -0
  87. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/can-use-tool.d.ts +4 -0
  88. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/index.d.ts +1 -0
  89. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/interruption-service.d.ts +8 -0
  90. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/model-request-retry-phase.d.ts +16 -0
  91. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/model-response-interceptors.d.ts +15 -0
  92. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-manager-host-protocol.d.ts +3 -2
  93. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-manager.d.ts +37 -3
  94. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-protocol.d.ts +59 -5
  95. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-run-state-machine-protocol.d.ts +14 -1
  96. package/cli/dist-server/types/workspace/cbc-core/lib/node/session/stream-timeout-retry-budget.d.ts +8 -1
  97. package/cli/dist-server/types/workspace/cbc-core/lib/node/trace/turn-context.d.ts +28 -1
  98. package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/command-message-utils.d.ts +20 -0
  99. package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/history-utils.d.ts +4 -4
  100. package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/input-item-utils.d.ts +9 -1
  101. package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/token-utils.d.ts +3 -1
  102. package/cli/dist-server/types/workspace/cbc-shared/lib/node/agent/openai-agents-types.d.ts +1 -0
  103. package/cli/dist-server/types/workspace/cbc-shared/lib/node/checkpoint/checkpoint-types.d.ts +6 -0
  104. package/cli/dist-server/types/workspace/cbc-shared/lib/node/model/model-errors.d.ts +30 -2
  105. package/cli/dist-server/types/workspace/cbc-worktree/lib/node/worktree/worktree-service.d.ts +5 -0
  106. package/cli/dist-server/types/workspace/core/lib/common/protocol.d.ts +8 -1
  107. package/cli/dist-server/types/workspace/product/lib/common/index.d.ts +1 -0
  108. package/cli/dist-server/types/workspace/product/lib/common/tencent-docs-endpoint.d.ts +37 -0
  109. package/cli/dist-server/types/workspace/product/lib/common/types/config.d.ts +12 -0
  110. package/cli/dist-server/types/workspace/product/lib/common/types/features.d.ts +17 -9
  111. package/cli/dist-server/types/workspace/product/lib/common/types/product.d.ts +15 -0
  112. package/cli/dist-server/types/workspace/prompts/lib/common/product-prompt-provider.d.ts +3 -1
  113. package/cli/dist-server/types/workspace/prompts/lib/common/prompt-protocol.d.ts +6 -0
  114. package/cli/dist-server/types/workspace/sandbox-cli/lib/common/center-protocol.generated.d.ts +5 -0
  115. package/cli/dist-server/types/workspace/sandbox-cli/lib/common/file-policy.d.ts +4 -1
  116. package/cli/dist-server/types/workspace/sandbox-cli/lib/common/http-policy.d.ts +20 -0
  117. package/cli/dist-server/types/workspace/sandbox-cli/lib/common/rule-config.d.ts +10 -0
  118. package/cli/dist-server/types/workspace/sandbox-cli/lib/node/sandbox-center-client.d.ts +3 -0
  119. package/cli/dist-server/types/workspace/telemetry/lib/common/event/types/craft.d.ts +43 -3
  120. package/cli/package.json +1 -1
  121. package/cli/product.cloudhosted.json +1 -803
  122. package/cli/product.internal.json +1 -1057
  123. package/cli/product.ioa.json +1 -1515
  124. package/cli/product.json +1 -2189
  125. package/cli/product.selfhosted.json +1 -364
  126. package/cli/vendor/shim/brokered-bin/7z +675 -0
  127. package/cli/vendor/shim/brokered-bin/7za +675 -0
  128. package/cli/vendor/shim/brokered-bin/7zz +675 -0
  129. package/cli/vendor/shim/brokered-bin/rar +675 -0
  130. package/cli/vendor/shim/brokered-bin/tar +675 -0
  131. package/cli/vendor/shim/brokered-bin/zip +187 -0
  132. package/docs/acp-v2.md +19 -0
  133. package/docs/client.md +7 -0
  134. package/docs/in-process.md +26 -2
  135. package/docs/product.md +4 -0
  136. package/docs/protocol.md +10 -2
  137. package/docs/server.md +2 -0
  138. package/lib/agent/v2.js +1 -1
  139. package/lib/application/services.js +1 -1
  140. package/lib/auth/module.d.ts +3 -1
  141. package/lib/auth/module.js +1 -1
  142. package/lib/client/client.js +1 -1
  143. package/lib/client/mcp.d.ts +1 -1
  144. package/lib/client/mcp.js +1 -1
  145. package/lib/components/acp-mcp-transport.d.mts +84 -1
  146. package/lib/components/question-elicitation.d.mts +20 -1
  147. package/lib/components/sandbox.d.mts +2 -0
  148. package/lib/components/sandbox.mjs +1 -0
  149. package/lib/components/{acp/acp-prompt-input.d.ts → session/prompt-input.d.ts} +1 -1
  150. package/lib/components/session-replay.d.mts +8 -7
  151. package/lib/components/session-replay.mjs +1 -1
  152. package/lib/effect-runtime/concurrency.d.mts +2 -4
  153. package/lib/effect-runtime/concurrency.mjs +1 -1
  154. package/lib/effect-runtime/mcp-lifecycle.mjs +1 -1
  155. package/lib/effect-runtime/process-runtime-context.d.ts +5 -1
  156. package/lib/harness/create-harness.js +1 -1
  157. package/lib/integration/agent-integration.d.ts +5 -0
  158. package/lib/protocol/acp-v2-credits.d.ts +10 -0
  159. package/lib/protocol/acp-v2-credits.js +1 -0
  160. package/lib/protocol/acp-v2-private-client.d.ts +1 -10
  161. package/lib/runtime/codebuddy-auth.d.ts +5 -3
  162. package/lib/runtime/codebuddy-auth.js +1 -1
  163. package/lib/runtime/private-runtime-role.js +1 -1
  164. package/lib/session/agent-backend.d.ts +3 -0
  165. package/lib/session/agent-backend.js +1 -1
  166. package/lib/session/config-defaults.d.ts +4 -0
  167. package/lib/session/config-defaults.js +1 -0
  168. package/lib/session/config-store.d.ts +1 -1
  169. package/lib/session/config-store.js +1 -1
  170. package/lib/session/replay.d.ts +3 -3
  171. package/lib/session/replay.js +1 -1
  172. package/lib/session/server-config.d.ts +11 -2
  173. package/lib/session/server-config.js +1 -1
  174. package/lib/session/server-events.d.ts +10 -8
  175. package/lib/session/server-events.js +1 -1
  176. package/lib/session/server-interactions.js +1 -1
  177. package/lib/session/server-mcp.js +1 -1
  178. package/lib/subagent/history.js +1 -1
  179. package/package.json +26 -20
  180. package/lib/components/acp/acp-client-channel.d.ts +0 -36
  181. package/lib/components/acp/acp-mcp-transport.d.ts +0 -84
  182. package/lib/components/acp/acp-question-elicitation.d.ts +0 -20
@@ -737,6 +737,8 @@ export interface AcpRequestTracking {
737
737
  conversationRequestId?: string;
738
738
  }
739
739
  export interface AcpPromptItem {
740
+ /** Host-validated mod receipt; never copied from client metadata. */
741
+ modsPromptSubmitted?: true;
740
742
  request: PromptRequest;
741
743
  responseDeferred: Deferred<PromptResponse>;
742
744
  tracking: AcpRequestTracking;
@@ -954,6 +956,12 @@ export interface AcpAgentManager {
954
956
  * 获取所有已注册的 AcpAgent 实例
955
957
  */
956
958
  getAll(): Map<string, AcpAgent>;
959
+ /**
960
+ * Subscribe to agent-registered events. Enables the mods paint pipe
961
+ * to push a first-frame MOD_RENDER to a newly-connected webui
962
+ * without waiting for the mod's own `$.ui.invalidate` cadence.
963
+ */
964
+ onAgentRegistered?(cb: (connectionId: string, agent: AcpAgent) => void): () => void;
957
965
  /**
958
966
  * 移除并释放指定连接的 AcpAgent 实例。重复移除同一连接是 no-op。
959
967
  * @param connectionId 连接 ID
@@ -33,6 +33,7 @@ export declare function resolveProgramBlacklistForPlatform(configuredPrograms: r
33
33
  * Bash 沙箱配置接口
34
34
  * 基于 SandboxRuntimeConfig,添加了额外的 CLI 特定配置
35
35
  */
36
+ export type MacOSUnlinkPolicy = 'allow' | 'ask' | 'deny';
36
37
  export interface SandboxConfig {
37
38
  /** 是否启用沙箱 */
38
39
  enabled?: boolean;
@@ -98,6 +99,8 @@ export interface SandboxConfig {
98
99
  systemToolPolicy?: SystemToolPolicy;
99
100
  /** 实验功能:工作空间内文件版本管理 */
100
101
  versionControl?: boolean;
102
+ /** macOS 非白名单直接 unlink 的自动兜底动作;历史缺省为 ask。 */
103
+ macosUnlinkPolicy?: MacOSUnlinkPolicy;
101
104
  /** 实验功能:工作空间内删除进回收站 */
102
105
  deleteProtection?: boolean;
103
106
  /** 实验功能:运行时删除回收站保护(Node/Python/Git Bash 注入) */
@@ -2,6 +2,9 @@ import { Command } from 'commander';
2
2
  export declare const CliDispatcher: unique symbol;
3
3
  export declare const CliProvider: unique symbol;
4
4
  export declare const DispatchStrategy: unique symbol;
5
+ /** Request-local controller/view handoff; never part of a wire message or Session. */
6
+ export declare const STREAM_JSON_RUN_RESULT = "codebuddy.streamJsonRunResult";
7
+ export declare const STREAM_JSON_COMPLETED_REQUEST = "codebuddy.streamJsonCompletedRequest";
5
8
  export interface CliDispatcher {
6
9
  dispatch(): Promise<void>;
7
10
  }
@@ -447,7 +447,14 @@ export type ResultMessage = ({
447
447
  * - 字段全部可选:`status` (HTTP 状态码)、`code` (SDK/业务码)、`category`
448
448
  * (与 acp-agent.ts `classifyErrorAsRequestError` 分类对齐)、`details` (脱敏文案)。
449
449
  *
450
- * 详见 `result-message-utils.ts` 的 `buildErrorsInfo` / `extractStructuredErrorInfo`。
450
+ * 例外(`is_error: true` 的终态):抛出物本身没有文案时(裸 `throw`、空 message 的
451
+ * `Error`、无 message 的对象),该槽位不再是 `null`,而是带
452
+ * `code: 'cbc_empty_error'` + 兜底 `details`。否则 `errors[i]` 与 `errors_info[i]`
453
+ * 同时为空,下游 `BuildErrorMessageFromCLIErrors` 会整条丢掉错误 `_meta`,
454
+ * 终态在观测侧退化为不可归因的 `stop_reason=refusal` + `error=""`。
455
+ *
456
+ * 详见 `result-message-utils.ts` 的 `buildErrorTerminalFields` /
457
+ * `buildErrorsInfo` / `extractStructuredErrorInfo`。
451
458
  */
452
459
  errors_info?: Array<{
453
460
  status?: number;
@@ -9,6 +9,11 @@ export interface CommonRequest extends SessionOptions {
9
9
  * 字段,只给 native 会话创建时盖站立键用。ACP 请求走 `acp:true`,不在这里盖。
10
10
  */
11
11
  agent?: string;
12
+ /** Request-level debug options forwarded from CLI/serve callers. */
13
+ debug?: boolean | string;
14
+ debugToStderr?: boolean;
15
+ /** Automatically connect to a single available IDE on startup. */
16
+ ide?: boolean;
12
17
  }
13
18
  export interface ResumeRequest {
14
19
  resume: boolean | string;
@@ -1,3 +1,4 @@
1
+ import type { SandboxRuleContext } from '../../workspace/agent-client-protocol/lib/common/index.js';
1
2
  export declare const SensitiveDecisionMediation: unique symbol;
2
3
  export declare const SensitiveContentMediation: unique symbol;
3
4
  export declare const SensitiveToolEgressGuard: unique symbol;
@@ -245,6 +246,11 @@ export type SensitiveDetectionOutcome = {
245
246
  } | {
246
247
  kind: 'detected';
247
248
  detectionRef: string;
249
+ ruleContext?: SandboxRuleContext;
250
+ ruleMatches?: Array<{
251
+ plaintext: string;
252
+ ruleContext: SandboxRuleContext;
253
+ }>;
248
254
  plaintexts: string[];
249
255
  /** 无可用密文条目的命中,仅作疑似提示展示,不参与加密/替换。 */
250
256
  unprotectablePlaintexts?: string[];
@@ -291,6 +297,7 @@ export interface SandboxCenterPort {
291
297
  export interface SensitiveApprovalPort {
292
298
  requestApproval(request: {
293
299
  detectionRef: string;
300
+ ruleContext?: SandboxRuleContext;
294
301
  direction: SensitiveReviewRequest['direction'];
295
302
  source: SensitiveReviewRequest['source'];
296
303
  allowedChoices: SensitiveApprovalChoice[];
@@ -1,15 +1,18 @@
1
1
  import 'reflect-metadata';
2
2
  import type { ProductConfiguration } from '../../workspace/product/lib/common/index.js';
3
+ declare module '@celljs/core/lib/common/container/dynamic-container' {
4
+ function createContainer(): Promise<import('@celljs/core').Container>;
5
+ }
3
6
  /**
4
- * Lazy 单次 boot;幂等。首个 start()/verb 驱动(ensureStarted 收口)。
7
+ * 每次生命周期内惰性且幂等。首个 start()/verb 驱动(ensureStarted 收口)。
5
8
  * boot 失败即出队:best-effort 释放半装配态后清缓存,下一次调用真重试——
6
9
  * rejected promise 常驻会把一次瞬时失败固化成进程终身拒绝(lamp 毒 pod
7
10
  * 判例:boot 崩一次后每个会话都撞 already-started,pod 成毒丸)。
8
11
  */
9
12
  export declare function ensureBoot(product?: ProductConfiguration): Promise<void>;
10
13
  /**
11
- * stop() 收尾的容器释放:Application.stop() 生命周期 + unbindAllAsync 归还
12
- * 内存给嵌入宿主。runtime 维持已停终态(verbs 继续按 stopped 拒绝);释放
13
- * 失败不阻断关停。
14
+ * stop() 收尾:Application.stop() → unbindAllAsync → Effect.dispose。
15
+ * 成功后可由新的显式 start() 构造全新容器;失败仍尝试全部阶段,但拒绝
16
+ * 再次 boot,避免旧 finalizer 与新实例共享进程级适配器。
14
17
  */
15
18
  export declare function releaseContainer(): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { type PromptResponse, RequestError } from '@agentclientprotocol/sdk';
1
+ import { type PromptResponse, RequestError } from '@agentclientprotocol/sdk-server';
2
2
  export declare const CODEBUDDY_ERROR_META_KEY = "codebuddy.ai/error";
3
3
  export declare const CODEBUDDY_ERROR_UPDATE_TYPE = "_codebuddy.ai/error";
4
4
  /**
@@ -1,6 +1,5 @@
1
- export type * from '@agentclientprotocol/sdk';
2
- export type { AcpClientChannel } from './acp-client-channel.js';
3
- export type { McpUiBroadcastPayload, ModelInfo } from '../../../cli/dist-server/types/node/acp/acp-protocol.js';
1
+ export type * from '@agentclientprotocol/sdk-server';
2
+ export type { McpUiBroadcastPayload, ModelInfo } from '../../../acp/acp-protocol';
4
3
  export interface AcpConnectionProfile {
5
4
  endpoint: 'canonical' | 'compatibility';
6
5
  compatibilityExtensions: boolean;
@@ -0,0 +1,12 @@
1
+ import type { FormattedSessionEvent, SessionSourceEvent } from '../../types';
2
+ /** Protocol presentation only. The Server remains the owner of run settlement. */
3
+ export declare class AcpSessionFormatter {
4
+ private readonly version;
5
+ private readonly lanes;
6
+ private readonly compactions;
7
+ private readonly streamedV1Messages;
8
+ constructor(version: 'acp-v1' | 'acp-v2');
9
+ format(source: SessionSourceEvent): Promise<FormattedSessionEvent<'acp-v1' | 'acp-v2'>[]>;
10
+ private wrap;
11
+ private model;
12
+ }
@@ -0,0 +1,10 @@
1
+ import type { SessionNotification } from '@agentclientprotocol/sdk-server';
2
+ import type { UpdateSessionNotification } from '@agentclientprotocol/sdk-server/experimental/v2';
3
+ import type { AgentInputItem } from '../../../../vendor/cbc-shared/node/index.js';
4
+ import type { AgentEvent } from '../../types';
5
+ export declare function itemNotifications(sessionId: string, item: AgentInputItem, replay: boolean, readFile?: (path: string) => Promise<Uint8Array>): Promise<SessionNotification[]>;
6
+ /** Live complete items and replay share content, tool and identity projection. */
7
+ export declare const projectAgentItem: (sessionId: string, item: AgentInputItem) => Promise<UpdateSessionNotification[]>;
8
+ /** Reuse the CLI's ACP extension vocabulary; the Agent only exports kernel facts. */
9
+ export declare const projectNativeEvent: (frame: AgentEvent) => Promise<SessionNotification[]>;
10
+ export declare function projectAgentEvent(frame: AgentEvent): Promise<UpdateSessionNotification[]>;
@@ -15,7 +15,7 @@ export { start } from './start';
15
15
  export { readSession } from './read-session';
16
16
  export { readSessionCatalog } from './read-session-catalog';
17
17
  export { createSession } from './create-session';
18
- export type { ReadSessionCatalogOptions, ReloadOptions, CreateSessionOptions, ConfigChange, NotifyConfigChangeOptions, AgentEvent, AgentDefinition, HookCallback, HookCallbackMatcher, HookEvent, HookInput, HookJSONOutput, QueryHooks, OrphanedExecSettlement, QueryOptions, QueryResult, QueryTicket, QueryInput, ReadSessionOptions, RewindOptions, RewindResult, RunAccount, RunAuth, RunCompletedEvent, RunStartedEvent, Sandbox, SandboxCapabilities, SandboxDriver, SandboxFactory, SandboxFileStat, SandboxShellResult, Server, SessionEvent, SessionCatalog, SessionEventOrigin, SessionEventListener, SessionSubscription, SessionSubscriptionExit, SessionSnapshot, SessionKey, SessionStore, SessionStoreEntry, StartOptions, StopReason, SteerOptions, SteerResult, } from './types';
18
+ export type { ReadSessionCatalogOptions, ReloadOptions, CreateSessionOptions, ConfigChange, NotifyConfigChangeOptions, AgentEvent, AgentDefinition, HookCallback, HookCallbackMatcher, HookEvent, HookInput, HookJSONOutput, QueryHooks, OrphanedExecSettlement, QueryOptions, QueryResult, QueryTicket, QueryInput, ReadSessionOptions, RewindOptions, RewindResult, RunAccount, RunAuth, RunCompletedEvent, RunStartedEvent, Sandbox, SandboxCapabilities, SandboxDriver, SandboxFactory, SandboxFileStat, SandboxShellResult, Server, SessionEvent, FormattedSessionEvent, SessionOutputFormat, SubscribeOptions, NativeSessionEvent, AgentSdkEvent, AcpSessionEvent, SessionCatalog, SessionEventOrigin, SessionEventListener, SessionSubscription, SessionSubscriptionExit, SessionSnapshot, SessionKey, SessionStore, SessionStoreEntry, StartOptions, StopReason, SteerOptions, SteerResult, } from './types';
19
19
  export { InMemorySessionStore } from './in-memory-session-store';
20
20
  export { WORKBUDDY_TOOLS } from './tool-presets';
21
21
  export { InMemoryFs, MountableFs, OverlayFs, ReadWriteFs } from './fs-kit';
@@ -1,5 +1,5 @@
1
1
  import { Session } from '../../vendor/cbc-core/node/index.js';
2
- import type { QueryInput, QueryOptions, QueryTicket, ReloadOptions, RewindOptions, RewindResult, SessionEventListener, SessionSubscription, SteerOptions, SteerResult } from './types';
2
+ import type { FormattedSessionEvent, QueryInput, QueryOptions, QueryTicket, ReloadOptions, RewindOptions, RewindResult, SessionOutputFormat, SessionSubscription, SteerOptions, SteerResult, SubscribeOptions } from './types';
3
3
  interface SettleOutcome {
4
4
  assistantText: string;
5
5
  completedError?: unknown;
@@ -46,7 +46,8 @@ export declare function interrupt(sessionId: string): Promise<void>;
46
46
  * whose queue exceeds the high-water mark is evicted — recover by
47
47
  * re-subscribing and catching up from the session store.
48
48
  */
49
- export declare function subscribe(sessionId: string, listener: SessionEventListener): SessionSubscription;
49
+ export declare function subscribe(sessionId: string, listener: (event: FormattedSessionEvent) => void | Promise<void>): SessionSubscription;
50
+ export declare function subscribe<F extends SessionOutputFormat>(sessionId: string, listener: (event: FormattedSessionEvent<F>) => void | Promise<void>, options: SubscribeOptions<F>): SessionSubscription;
50
51
  /**
51
52
  * Passivation hint. Optional, and never a terminal state: closing equals an
52
53
  * orderly crash, and any verb reactivates the session from storage.
@@ -4,8 +4,11 @@
4
4
  * docs/cloud-native/agent-cli-server.md): the SessionStore
5
5
  * adapter contract, the Sandbox family, and the stream-json event union.
6
6
  */
7
- import type { AgentPhaseInfo, CanUseTool, CombineEvent, SubagentEventReference, SubagentTokenUsageSnapshot, TranscriptStore as SessionStore } from '../../vendor/cbc-core/node/index.js';
8
- import type { ProductConfiguration } from '../../workspace/product/lib/common/index.js';
7
+ import type { SessionNotification } from '@agentclientprotocol/sdk-server';
8
+ import type { UpdateSessionNotification } from '@agentclientprotocol/sdk-server/experimental/v2';
9
+ import type { AgentPhaseInfo, CanUseTool, CombineEvent, SessionKey, SubagentEventReference, SubagentTokenUsageSnapshot, TranscriptStore as SessionStore } from '../../vendor/cbc-core/node/index.js';
10
+ import type { AgentInputItem, ResponseStreamEvent, RunStreamEvent } from '../../vendor/cbc-shared/node/index.js';
11
+ import type { Command, ProductConfiguration, Skill } from '../../workspace/product/lib/common/index.js';
9
12
  import type { RunAccount, RunAuth } from '../authentication/run-context';
10
13
  import type { Message } from '../cli/stream-json-protocol';
11
14
  import type { FileSystem, InitialFiles } from '../data-fs';
@@ -39,6 +42,7 @@ export interface StartOptions {
39
42
  * CODEBUDDY_AUTH_TOKEN / CODEBUDDY_SESSION_SKILL_DIRS)拒绝:凭据只认
40
43
  * query options(auth)与 start({ apiKey })。会话级差异走
41
44
  * `query({ settings: { env } })`——ALS 会话档,并行 run 各自解析无竞态。
45
+ * stop 或启动失败后恢复本次覆盖的环境值;宿主期间主动修改的值保留。
42
46
  */
43
47
  env?: Record<string, string>;
44
48
  /** Global SessionStore adapter (SDK shape). Durable events append here on settle. */
@@ -84,6 +88,7 @@ export interface StartOptions {
84
88
  * `stop()` drains in-flight work, then disconnects persistence. Supports
85
89
  * `await using`; deliberately no synchronous dispose — graceful shutdown is
86
90
  * inherently async.
91
+ * Await successful stop before starting a new runtime in the same process.
87
92
  */
88
93
  export interface Server {
89
94
  stop(): Promise<void>;
@@ -115,13 +120,15 @@ export interface RewindResult {
115
120
  }
116
121
  /** Durable Agent items, including message identities and conversation facts. */
117
122
  export interface SessionSnapshot {
123
+ /** Persisted standing Agent, independent of current Product defaults. */
124
+ mainAgent?: string;
118
125
  sessionId: string;
119
126
  cwd: string;
120
- history: import('../../vendor/cbc-shared/node/index.js').AgentInputItem[];
127
+ history: AgentInputItem[];
121
128
  /** Store-owned locators. Pass a key to readSession to read that child lazily. */
122
129
  subagents?: Array<{
123
130
  sessionId: string;
124
- key: import('../../vendor/cbc-core/node/index.js').SessionKey;
131
+ key: SessionKey;
125
132
  }>;
126
133
  }
127
134
  /**
@@ -396,7 +403,7 @@ export type SteerResult = {
396
403
  */
397
404
  export type SessionEvent = (Message | RunStartedEvent | RunCompletedEvent | AgentEvent) & {
398
405
  /** Complete Agent item behind a message frame, shared with readSession(). */
399
- readonly item?: import('../../vendor/cbc-shared/node/index.js').AgentInputItem;
406
+ readonly item?: AgentInputItem;
400
407
  /** Producer-owned identity. Background and child events retain their original run. */
401
408
  readonly origin?: SessionEventOrigin;
402
409
  };
@@ -435,13 +442,19 @@ export interface AgentEvent {
435
442
  } | {
436
443
  readonly type: 'catalog';
437
444
  readonly data: SessionCatalog;
445
+ } | {
446
+ readonly type: 'title';
447
+ readonly data: string;
448
+ } | {
449
+ readonly type: 'error';
450
+ readonly data: unknown;
438
451
  };
439
452
  readonly _requestId?: string;
440
453
  readonly _meta?: Record<string, unknown> | null;
441
454
  }
442
455
  export interface SessionCatalog {
443
- readonly commands: Array<Pick<import('../../workspace/product/lib/common/index.js').Command, 'name' | 'description' | 'argumentHint' | 'tags'>>;
444
- readonly skills: Array<Pick<import('../../workspace/product/lib/common/index.js').Skill, 'name' | 'description' | 'source' | 'userInvocable' | 'disableModelInvocation' | 'pluginInfo'>>;
456
+ readonly commands: Array<Pick<Command, 'name' | 'description' | 'argumentHint' | 'tags'>>;
457
+ readonly skills: Array<Pick<Skill, 'name' | 'description' | 'source' | 'userInvocable' | 'disableModelInvocation' | 'pluginInfo'>>;
445
458
  readonly skillOverrides?: Settings['skillOverrides'];
446
459
  }
447
460
  /** Refresh resident components before the next queued turn (including continuations).
@@ -469,6 +482,45 @@ export interface RunCompletedEvent extends QueryResult {
469
482
  readonly session_id: string;
470
483
  readonly _meta?: Record<string, unknown> | null;
471
484
  }
485
+ /** Selects only presentation; query lifecycle and persistence are shared. */
486
+ export type SessionOutputFormat = 'openai' | 'messages' | 'acp-v1' | 'acp-v2';
487
+ export interface SubscribeOptions<F extends SessionOutputFormat = 'messages'> {
488
+ readonly format: F;
489
+ }
490
+ /** All SDK stream event variants, with the original object as data (no JSON conversion). */
491
+ export interface AgentSdkEvent {
492
+ readonly type: 'agent_sdk';
493
+ readonly parentToolUseId?: string;
494
+ readonly session_id: string;
495
+ readonly data: RunStreamEvent;
496
+ readonly origin?: SessionEventOrigin;
497
+ readonly _meta?: Record<string, unknown> | null;
498
+ }
499
+ /** Native model facts used by formatters, never stream-json intermediates. */
500
+ export interface AgentModelEvent {
501
+ readonly type: 'agent_model';
502
+ readonly parentToolUseId?: string;
503
+ readonly session_id: string;
504
+ readonly data: ResponseStreamEvent;
505
+ readonly origin?: SessionEventOrigin;
506
+ readonly _meta?: Record<string, unknown> | null;
507
+ }
508
+ export interface AcpSessionEvent<F extends 'acp-v1' | 'acp-v2'> {
509
+ readonly type: 'acp_update';
510
+ readonly notification: F extends 'acp-v1' ? SessionNotification : UpdateSessionNotification;
511
+ readonly item?: AgentInputItem;
512
+ readonly origin?: SessionEventOrigin;
513
+ readonly _meta?: Record<string, unknown> | null;
514
+ }
515
+ export type NativeSessionEvent = (AgentSdkEvent | AgentEvent | RunStartedEvent | RunCompletedEvent) & {
516
+ readonly origin?: SessionEventOrigin;
517
+ };
518
+ export type FormattedSessionEvent<F extends SessionOutputFormat = 'messages'> = (F extends 'messages' ? SessionEvent : F extends 'acp-v1' | 'acp-v2' ? AcpSessionEvent<F> | AgentEvent | RunStartedEvent | RunCompletedEvent : NativeSessionEvent) & {
519
+ readonly origin?: SessionEventOrigin;
520
+ readonly item?: AgentInputItem;
521
+ };
522
+ /** Internal source union. ACP never consumes stream-json messages. */
523
+ export type SessionSourceEvent = SessionEvent | AgentSdkEvent | AgentModelEvent;
472
524
  export type SessionEventListener = (event: SessionEvent) => void | Promise<void>;
473
525
  export type SessionSubscriptionExit = {
474
526
  readonly reason: 'unsubscribed';
@@ -21,13 +21,13 @@ export declare const DEFAULT_SLASH_COMMAND_TOOL_CHAR_BUDGET = 8000;
21
21
  export declare const DEFAULT_SKILL_TOOL_CHAR_BUDGET = 8000;
22
22
  export declare const DEFAULT_AGENT_TOOL_CHAR_BUDGET = 30000;
23
23
  /** Per-entry hard cap for a single skill's description */
24
- export declare const MAX_SKILL_DESC_CHARS = 150;
24
+ export declare const MAX_SKILL_DESC_CHARS = 200;
25
25
  /** Minimum maxDescLen below which non-protected skills degrade to names-only (aligned with CC MIN_DESC_LENGTH=20) */
26
26
  export declare const MIN_SKILL_DESC_LENGTH = 20;
27
27
  /**
28
28
  * Env name for per-skill description hard-cap overrides.
29
29
  *
30
- * By default every skill's description is hard-capped to {@link MAX_SKILL_DESC_CHARS}(150)
30
+ * By default every skill's description is hard-capped to {@link MAX_SKILL_DESC_CHARS}(200)
31
31
  * per entry. A host can loosen (or tighten) this cap for **specific** skills — identified
32
32
  * by skill name — without changing the global default, by exporting this env.
33
33
  *
@@ -261,6 +261,8 @@ export interface Tool<TParameters extends ToolInputParameters = any, Context = U
261
261
  * The name of the tool. Must be unique within the agent.
262
262
  */
263
263
  name: string;
264
+ /** Host-created mod proxies dispatch once, inside their own execute method. */
265
+ readonly dispatchesModToolCall?: boolean;
264
266
  /**
265
267
  * Stability of the model-facing definition while the process is alive.
266
268
  * Agent tools default to stable; runtime-varying definitions opt into volatile.
@@ -349,6 +351,12 @@ export interface Tool<TParameters extends ToolInputParameters = any, Context = U
349
351
  }
350
352
  export type { BackgroundTask, TerminalEvidence } from '../../vendor/cbc-core/node/index.js';
351
353
  export interface ToolManager {
354
+ /** Dynamic definitions share the registry used by get/execute. Builtins cannot be replaced. */
355
+ register(tool: Tool): Promise<void>;
356
+ unregister(name: string): Promise<void>;
357
+ listDynamicToolNames(): string[];
358
+ /** Agent tool snapshots must be rebuilt when this version changes. */
359
+ readonly registryVersion: number;
352
360
  get<TParameters extends ToolInputParameters = any, Context = UnknownContext>(name: string, agentConfig?: ProductAgent, cachedProductConfig?: {
353
361
  agents?: any[];
354
362
  models?: any[];
@@ -377,6 +385,20 @@ export interface ToolManager {
377
385
  * 仅作用于 toolMap 中的内置工具;MCP 工具不走此路径。
378
386
  */
379
387
  ensureBuiltinDeferIndexed(toolName: string): Promise<boolean>;
388
+ /**
389
+ * 在工具执行前创建文件备份(file-history 快照),返回被跟踪的文件路径。
390
+ *
391
+ * 直连路径由 {@link executeToolWithHooks} 内部自动调用;REPL/Code Mode 沙箱
392
+ * 执行路径(DeferExecuteTool.routeToolCall → executeBuiltinTool)绕过该 hook
393
+ * 包装,需在真正执行工具前显式调用本方法,否则沙箱内的 Edit/Write 不产生
394
+ * FileHistorySnapshotItem,rewind 无快照可恢复(#130664)。
395
+ *
396
+ * 依赖 FileTrackService.trackFile 幂等(文件已在当前 checkpoint 即跳过),两条
397
+ * 路径都触达时也只落一次快照。
398
+ */
399
+ trackFileForToolCall(toolName: string, toolInput: unknown, session: Session, details?: {
400
+ toolCall: FunctionCallItem;
401
+ }): Promise<string | undefined>;
380
402
  addBackgroundTask(task: BackgroundTask): void;
381
403
  removeBackgroundTask(id: string): void;
382
404
  getBackgroundTasks(): BackgroundTask[];
@@ -926,26 +948,15 @@ export interface VideoService {
926
948
  }
927
949
  export declare const AudioTranscribeService: unique symbol;
928
950
  /**
929
- * 录音文件识别(长音频转文本)请求参数。
930
- * `channel_num:1` 由 service 固定注入,不暴露给调用方。
951
+ * tool 层已判定好的音频来源。
952
+ * 本地文件需要先上传 COS 才有公网可下载地址;调用方给出的 URL 直接提交。
931
953
  */
932
- export interface AudioTranscribeOptions {
933
- /** 说话人分离:0 关闭(默认)/ 1 开启(需 channel_num=1) */
934
- speaker_diarization?: 0 | 1;
935
- /** 临时热词表 "词|权重,..."(最多 128) */
936
- hotword_list?: string;
937
- /** 阿拉伯数字智能转换:0 / 1 / 3 */
938
- convert_num_mode?: 0 | 1 | 3;
939
- /** 脏词过滤:0 / 1 / 2 */
940
- filter_dirty?: 0 | 1 | 2;
941
- /** 标点过滤:0 / 1 / 2 */
942
- filter_punc?: 0 | 1 | 2;
943
- /** 语气词过滤:0 / 1 / 2 */
944
- filter_modal?: 0 | 1 | 2;
945
- /** 上游附加参数(合法 JSON 字符串),如 '{"Domain":3}' */
946
- extra?: string;
947
- }
948
- /** service 内部解析出的音频来源(COS-only:始终为 audio_url)。 */
954
+ export type AudioTranscribeSource = {
955
+ readonly filePath: string;
956
+ } | {
957
+ readonly audioUrl: string;
958
+ };
959
+ /** 提交给上游的音频来源(本服务始终用 audio_url,从不用 audio_data)。 */
949
960
  export interface AudioSource {
950
961
  audio_url: string;
951
962
  }
@@ -1022,11 +1033,15 @@ export interface AudioTranscribeResult {
1022
1033
  }
1023
1034
  /**
1024
1035
  * 录音文件识别服务接口。
1025
- * COS-only:本地文件先经后端预签名上传 COS,再以 audio_url 提交异步转写并轮询。
1036
+ * 本地文件先经后端预签名上传 COS 换取 download_url;调用方给的 URL 直接用。
1037
+ * 两种来源都以 audio_url 提交异步转写并轮询。
1038
+ *
1039
+ * 识别参数(`channel_num` / `speaker_diarization`)由 service 固定注入,
1040
+ * 按 #128310 不向 Agent 暴露开关。
1026
1041
  */
1027
1042
  export interface AudioTranscribeService {
1028
1043
  /**
1029
- * 转写本地音频文件:预签名上传 → 提交任务 → 轮询直至终态。
1044
+ * 转写音频:解析来源(本地文件则预签名上传)→ 提交任务 → 轮询直至终态。
1030
1045
  */
1031
- transcribe(filePath: string, options: AudioTranscribeOptions, context: RunContext<Session>): Promise<AudioTranscribeResult>;
1046
+ transcribe(source: AudioTranscribeSource, context: RunContext<Session>): Promise<AudioTranscribeResult>;
1032
1047
  }
@@ -550,6 +550,19 @@ export interface AgentServiceRunControlOptions {
550
550
  bypassMessageQueue?: boolean;
551
551
  /** Input is already present in Session history; do not append it again. */
552
552
  skipAddHistory?: boolean;
553
+ /** Let an interactive host route external `/compact` before normal run admission. */
554
+ routeManualCompact?: boolean;
555
+ /**
556
+ * Per-call out-signal of `runDefault`: invoked once, synchronously, after
557
+ * this call passed run admission (its startup controller is installed on
558
+ * the Session) and before the agent is resolved. Not invoked when admission
559
+ * throws. It says nothing about the model having started or the run
560
+ * succeeding; without `bypassMessageQueue` the run may still be queued
561
+ * afterwards (see `onEnqueued`). A throwing callback is logged and does not
562
+ * affect the run. Internal re-runs pass fresh options and never carry it; it
563
+ * is stripped before AgentRunRequest and the SDK.
564
+ */
565
+ onAdmitted?: () => void;
553
566
  }
554
567
  /** Options for an isolated run or an SDK RunState resume. */
555
568
  export type AgentStandardRunOptions<TContext = Session> = AgentSdkRunOptions<TContext> & AgentServiceRunControlOptions & {
@@ -566,6 +579,8 @@ export type AgentStandardRunOptions<TContext = Session> = AgentSdkRunOptions<TCo
566
579
  * cannot clobber each other's outcome.
567
580
  */
568
581
  onEnqueued?: () => void;
582
+ /** Exact result of this arrival, including execution after a queue drain. */
583
+ onResult?: (result: NonNullable<Session['resultSubject']['value']>) => void;
569
584
  };
570
585
  /**
571
586
  * Explicitly claim the current process-local logical turn.
@@ -585,12 +600,19 @@ export interface AgentService {
585
600
  tryCloseTaskSession?(session: Session, result: NonNullable<Session['resultSubject']['value']>): Promise<boolean>;
586
601
  /** Stop accepting task work and join its physical runs before releasing dependencies. */
587
602
  retireTaskSession?(session: Session): Promise<void>;
603
+ /**
604
+ * 有界等待该 session 上的物理 run 收尾(含它把最终产出写进 history)。
605
+ *
606
+ * `agent_end` 早于 run 的 finalize,所以「上一轮 history 已写完」不能靠 `agent_end`
607
+ * 判定;需要该因果的调用方(队列 drain)join 到这里。超时会放行并告警,不会挂死。
608
+ */
609
+ waitForRunsSettled?(session: Session): Promise<void>;
588
610
  run<TAgent extends Agent<any, any>>(agent: TAgent, input: string | AgentInputItem[], options: AgentCurrentContinuationOptions): Promise<void>;
589
611
  run<TAgent extends Agent<any, any>, TContext = Session>(agent: TAgent, input: string | AgentInputItem[] | RunState<TContext, TAgent>, options?: AgentStandardRunOptions<TContext>): Promise<void>;
590
612
  runDefault<TAgent extends Agent<any, any>>(input: string | AgentInputItem[], options: AgentCurrentContinuationOptions): Promise<void>;
591
613
  runDefault<TAgent extends Agent<any, any>, TContext = Session>(input: string | AgentInputItem[] | RunState<TContext, TAgent>, options?: AgentStandardRunOptions<TContext>): Promise<void>;
592
- runOneTime<TContext = Session>(agentName: string, input: string | AgentInputItem[], options?: NonStreamRunOptions<TContext>): Promise<string>;
593
- runOneTime<TContext = Session>(agentName: string, input: string | AgentInputItem[], options?: StreamRunOptions<TContext>): Promise<string>;
614
+ runOneTime<TContext = Session>(agentName: string, input: string | AgentInputItem[], options?: NonStreamRunOptions<TContext> & OneTimeRunOptions): Promise<string>;
615
+ runOneTime<TContext = Session>(agentName: string, input: string | AgentInputItem[], options?: StreamRunOptions<TContext> & OneTimeRunOptions): Promise<string>;
594
616
  /**
595
617
  * Run a one-shot agent call in a forked (isolated) session that inherits
596
618
  * the conversation history from the parent session. The forked session is
@@ -656,6 +678,11 @@ export interface ForkedAgentOptions {
656
678
  /** Optional cap on number of turns (default: 1 for one-shot) */
657
679
  maxTurns?: number;
658
680
  }
681
+ /** Options of `runOneTime` on top of the SDK run options. */
682
+ export interface OneTimeRunOptions {
683
+ /** X-Agent-Purpose of the call; defaults to the agent's `AGENT_PURPOSE_MAP` entry, else its name. */
684
+ purpose?: string;
685
+ }
659
686
  export interface RunRequest {
660
687
  prompt?: string;
661
688
  inputFormat?: 'text' | 'stream-json';
@@ -697,6 +724,8 @@ export interface AgentRunRequest<TContext = Session> extends SessionOptions {
697
724
  skipAddHistory?: boolean;
698
725
  bypassMessageQueue?: boolean;
699
726
  inputOrigin?: AgentRunOrigin;
727
+ /** Process-local arrival callback; never passed to the SDK. */
728
+ onResult?: AgentStandardRunOptions['onResult'];
700
729
  traceId?: string;
701
730
  /**
702
731
  * #59319-5: 普通 run 二次裁决发现 session 仍 busy 时由 AgentService 设置。
@@ -58,7 +58,9 @@ export declare enum AgentPurpose {
58
58
  /** Auto mode permission risk classification (runOneTime: AUTO_MODE_CLASSIFIER) */
59
59
  AutoModeClassifier = "auto_mode_classifier",
60
60
  /** Automation scheduled task execution */
61
- Automation = "automation"
61
+ Automation = "automation",
62
+ /** `/btw` side question on a forked Session (runForked); Claude Code's `side_question` source */
63
+ SideQuestion = "side_question"
62
64
  }
63
65
  /**
64
66
  * Dynamic purpose prefix for built-in subagents.
@@ -127,6 +129,9 @@ export declare const AUXILIARY_PURPOSES: ReadonlySet<string>;
127
129
  * 时 purpose 可能尚未设置的普通对话仍按原行为发出 MODEL_REQUEST_STARTED。
128
130
  */
129
131
  export declare function isAuxiliaryPurpose(purpose?: string): boolean;
132
+ /** Purposes of compaction summary calls (X-Agent-Type `compaction`). */
133
+ export declare const COMPACTION_PURPOSES: ReadonlySet<string>;
134
+ export declare function isCompactionPurpose(purpose?: string): boolean;
130
135
  /**
131
136
  * 按 purpose 旁路 agent 生命周期事件(agent_start / agent_end / tool / handoff)。
132
137
  *
@@ -145,9 +150,8 @@ export declare function isAuxiliaryPurpose(purpose?: string): boolean;
145
150
  *
146
151
  * 因此这里只收 PreMessage 这一种 purpose。
147
152
  *
148
- * 依赖前提:`PreMessageCompactStrategy` 在 runOneTime 前后设置 / 还原
149
- * `session.agentPurpose`,且用 try/finally 保证异常路径也会还原——否则 purpose 泄漏
150
- * 会让**主 run** 也被误旁路,反而放大本要修复的孤儿 run 问题。
153
+ * The purpose is scoped to the summary call (`runOneTime` → `runWithAgentPurpose`), so it
154
+ * cannot leak onto the pending main run.
151
155
  *
152
156
  * multi-session(#44317)回归时,PreMessage 承载应改回临时子 Session;本名单保留为
153
157
  * 冗余防线即可(临时 Session 上旁路是无害的)。
@@ -0,0 +1,46 @@
1
+ import type { AgentType } from '../../../../workspace/telemetry/lib/common/index.js';
2
+ interface PurposeCarrier {
3
+ agentPurpose?: string;
4
+ conversationRequestId?: string;
5
+ }
6
+ /**
7
+ * Runs an auxiliary model call (title, summary, WebFetch analysis, ...) on a
8
+ * caller-owned Session without writing its purpose / request id onto the shared
9
+ * Session, where a concurrent main run would read and send them as its own.
10
+ */
11
+ export declare function runWithAgentPurpose<T>(session: object, purpose: string, callback: () => T, options?: {
12
+ conversationRequestId?: string;
13
+ }): T;
14
+ /** True when the current async chain is an auxiliary call scoped to `session`. */
15
+ export declare function isInAgentPurposeScope(session: object | undefined): boolean;
16
+ /** Purpose of the model call running in the current async chain. */
17
+ export declare function getEffectiveAgentPurpose(session: PurposeCarrier | undefined): string | undefined;
18
+ /** Request id of the model call running in the current async chain. */
19
+ export declare function getEffectiveConversationRequestId(session: PurposeCarrier | undefined): string | undefined;
20
+ /** Purposes whose model calls are steps of a Session's own agent loop. */
21
+ export declare function isMainConversationPurpose(purpose: string | undefined): boolean;
22
+ /** True when the model call in the current async chain is a step of `session`'s agent loop. */
23
+ export declare function isMainLoopModelCall(session: PurposeCarrier | undefined): boolean;
24
+ /** True when the model call in the current async chain has an `AUXILIARY_PURPOSES` purpose. */
25
+ export declare function isAuxiliaryPurposeCall(session: PurposeCarrier | undefined): boolean;
26
+ /**
27
+ * Runs `callback` outside any purpose scope. A run started from a helper call's async
28
+ * chain (e.g. a queued message drained on its agent_end) is a new agent-loop run.
29
+ */
30
+ export declare function runOutsideAgentPurposeScope<T>(callback: () => T): T;
31
+ export type ModelCallAgentType = AgentType;
32
+ /** Role of the Session's own agent loop, for request-level events. */
33
+ export declare function resolveSessionAgentType(session: {
34
+ meta?: Record<string, unknown>;
35
+ }): 'main' | 'subagent' | 'team';
36
+ /**
37
+ * Role of the model call in the current async chain (X-Agent-Type / telemetry
38
+ * `agentType`), mirroring Claude Code's `x-claude-code-request-class`: compaction
39
+ * summaries report `compaction`, other one-shot helpers (title, WebFetch analysis,
40
+ * ...) report `auxiliary`, whatever Session they run on. The specific helper
41
+ * stays in X-Agent-Purpose.
42
+ */
43
+ export declare function resolveModelCallAgentType(session: PurposeCarrier & {
44
+ meta?: Record<string, unknown>;
45
+ }): ModelCallAgentType;
46
+ export {};