@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.
- package/CHANGELOG.md +44 -0
- package/README.md +1 -1
- package/cli/CHANGELOG.md +135 -0
- package/cli/dist-server/shared.cjs +455 -387
- package/cli/dist-server/types/node/acp/acp-protocol.d.ts +40 -12
- package/cli/dist-server/types/node/acp/usage-by-category-calculator.d.ts +21 -0
- package/cli/dist-server/types/node/bash-sandbox/bash-sandbox-protocol.d.ts +3 -0
- package/cli/dist-server/types/node/cli/cli-protocol.d.ts +3 -0
- package/cli/dist-server/types/node/cli/stream-json-protocol.d.ts +23 -2
- package/cli/dist-server/types/node/data-fs/index.d.ts +13 -1
- package/cli/dist-server/types/node/hooks/hook-protocol.d.ts +2 -2
- package/cli/dist-server/types/node/sensitive-content/sensitive-content-protocol.d.ts +7 -0
- package/cli/dist-server/types/node/server/boot.d.ts +7 -4
- package/{lib/components → cli/dist-server/types/node/server/formats}/acp/acp-error-model.d.ts +1 -1
- package/{lib/components → cli/dist-server/types/node/server/formats}/acp/acp-protocol.d.ts +2 -3
- package/cli/dist-server/types/node/server/formats/acp/index.d.ts +12 -0
- package/cli/dist-server/types/node/server/formats/acp/projection.d.ts +10 -0
- package/cli/dist-server/types/node/server/index.d.ts +1 -1
- package/cli/dist-server/types/node/server/sessions.d.ts +27 -2
- package/cli/dist-server/types/node/server/types.d.ts +65 -7
- package/cli/dist-server/types/node/settings/settings-protocol.d.ts +5 -0
- package/cli/dist-server/types/node/tools/tool-protocol.d.ts +128 -4
- package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-protocol.d.ts +60 -2
- package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-purpose-protocol.d.ts +8 -4
- package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-purpose-scope.d.ts +46 -0
- package/cli/dist-server/types/vendor/cbc-core/node/agent/agent-service.d.ts +28 -3
- package/cli/dist-server/types/vendor/cbc-core/node/agent/index.d.ts +4 -0
- package/cli/dist-server/types/vendor/cbc-core/node/agent/interceptors/input-interceptors.d.ts +1 -6
- package/cli/dist-server/types/vendor/cbc-core/node/agent/model-call-failure.d.ts +9 -0
- package/cli/dist-server/types/vendor/cbc-core/node/agent/model-step-sequence.d.ts +11 -0
- package/cli/dist-server/types/vendor/cbc-core/node/agent/runner-factory.d.ts +56 -20
- package/cli/dist-server/types/vendor/cbc-core/node/agent/speaker-label.d.ts +44 -0
- package/cli/dist-server/types/vendor/cbc-core/node/agent/tool-call-loop-detector-service.d.ts +5 -4
- package/cli/dist-server/types/vendor/cbc-core/node/agent/tool-call-loop-guard-protocol.d.ts +1 -1
- package/cli/dist-server/types/vendor/cbc-core/node/agent/tool-call-loop-pattern.d.ts +16 -4
- package/cli/dist-server/types/vendor/cbc-core/node/context/compaction-lineage.d.ts +39 -0
- package/cli/dist-server/types/vendor/cbc-core/node/context/context-compact-summarizer.d.ts +2 -0
- package/cli/dist-server/types/vendor/cbc-core/node/context/context-protocol.d.ts +17 -0
- package/cli/dist-server/types/vendor/cbc-core/node/context/index.d.ts +1 -0
- package/cli/dist-server/types/vendor/cbc-core/node/context/pre-message-compact-strategy.d.ts +1 -2
- package/cli/dist-server/types/vendor/cbc-core/node/hooks/agent-trigger.d.ts +6 -22
- package/cli/dist-server/types/vendor/cbc-core/node/hooks/hook-protocol.d.ts +4 -1
- package/cli/dist-server/types/vendor/cbc-core/node/session/idle-queue-drain-service.d.ts +4 -56
- package/cli/dist-server/types/vendor/cbc-core/node/session/index.d.ts +4 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/interruption-service.d.ts +63 -9
- package/cli/dist-server/types/vendor/cbc-core/node/session/model-request-retry-phase.d.ts +16 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/model-response-interceptors.d.ts +33 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/recovery-budget.d.ts +55 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-hook-manager.d.ts +15 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-manager-host-protocol.d.ts +3 -2
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-manager.d.ts +17 -4
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-persistence-error.d.ts +43 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-protocol.d.ts +110 -9
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-run-state-machine-protocol.d.ts +15 -1
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-runtime-lifecycle.d.ts +5 -0
- package/cli/dist-server/types/vendor/cbc-core/node/session/session-store.d.ts +150 -4
- package/cli/dist-server/types/vendor/cbc-core/node/session/stream-timeout-retry-budget.d.ts +20 -1
- package/cli/dist-server/types/vendor/cbc-core/node/trace/turn-context.d.ts +28 -1
- package/cli/dist-server/types/vendor/cbc-core/node/utils/command-message-utils.d.ts +20 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/history-utils.d.ts +27 -4
- package/cli/dist-server/types/vendor/cbc-core/node/utils/index.d.ts +1 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/input-item-utils.d.ts +8 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/message-utils.d.ts +12 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/model-utils.d.ts +7 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/queue-dispatch-utils.d.ts +24 -2
- package/cli/dist-server/types/vendor/cbc-core/node/utils/session-utils.d.ts +4 -1
- package/cli/dist-server/types/vendor/cbc-core/node/utils/string-retention-utils.d.ts +4 -0
- package/cli/dist-server/types/vendor/cbc-core/node/utils/token-utils.d.ts +3 -1
- package/cli/dist-server/types/vendor/cbc-shared/node/agent/openai-agents-types.d.ts +1 -0
- package/cli/dist-server/types/vendor/cbc-shared/node/checkpoint/checkpoint-types.d.ts +6 -0
- package/cli/dist-server/types/vendor/cbc-shared/node/hooks/hook-types.d.ts +7 -1
- package/cli/dist-server/types/vendor/cbc-shared/node/index.d.ts +2 -0
- package/cli/dist-server/types/vendor/cbc-shared/node/model/model-errors.d.ts +36 -4
- package/cli/dist-server/types/vendor/cbc-shared/node/tools/tool-names.d.ts +1 -0
- package/cli/dist-server/types/vendor/cbc-shared/node/utils/retry-backoff.d.ts +30 -0
- package/cli/dist-server/types/vendor/cbc-shared/node/utils/retry-policy.d.ts +26 -0
- package/cli/dist-server/types/workspace/agent-client-protocol/lib/common/index.d.ts +1 -0
- package/cli/dist-server/types/workspace/agent-client-protocol/lib/common/sandbox-rule-context.d.ts +38 -0
- package/cli/dist-server/types/workspace/authentication/lib/common/account-scoped-external-link-authentication-provider.d.ts +5 -5
- package/cli/dist-server/types/workspace/authentication/lib/common/account-utils.d.ts +25 -0
- package/cli/dist-server/types/workspace/authentication/lib/common/authentication-manager.d.ts +8 -2
- package/cli/dist-server/types/workspace/authentication/lib/common/authentication-observation.d.ts +36 -0
- package/cli/dist-server/types/workspace/authentication/lib/common/authentication-protocol.d.ts +40 -2
- package/cli/dist-server/types/workspace/authentication/lib/common/external-link-authentication-provider.d.ts +21 -5
- package/cli/dist-server/types/workspace/authentication/lib/common/index.d.ts +1 -0
- package/cli/dist-server/types/workspace/authentication/lib/common/wx-authentication-provider.d.ts +2 -2
- package/cli/dist-server/types/workspace/cbc-checkpoint/lib/node/checkpoint/checkpoint-protocol.d.ts +2 -0
- package/cli/dist-server/types/workspace/cbc-checkpoint/lib/node/checkpoint/checkpoint-service.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-protocol.d.ts +60 -2
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-purpose-protocol.d.ts +8 -4
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-purpose-scope.d.ts +46 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/agent-service.d.ts +28 -3
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/index.d.ts +4 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/interceptors/input-interceptors.d.ts +1 -6
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/model-call-failure.d.ts +9 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/model-step-sequence.d.ts +11 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/runner-factory.d.ts +56 -20
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/speaker-label.d.ts +44 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/tool-call-loop-detector-service.d.ts +5 -4
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/tool-call-loop-guard-protocol.d.ts +1 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/tool-call-loop-pattern.d.ts +16 -4
- package/cli/dist-server/types/workspace/cbc-core/lib/node/context/compaction-lineage.d.ts +39 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/context/context-compact-summarizer.d.ts +2 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/context/context-protocol.d.ts +17 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/context/index.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/context/pre-message-compact-strategy.d.ts +1 -2
- package/cli/dist-server/types/workspace/cbc-core/lib/node/hooks/agent-trigger.d.ts +6 -22
- package/cli/dist-server/types/workspace/cbc-core/lib/node/hooks/hook-protocol.d.ts +4 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/idle-queue-drain-service.d.ts +4 -56
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/index.d.ts +4 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/interruption-service.d.ts +63 -9
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/model-request-retry-phase.d.ts +16 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/model-response-interceptors.d.ts +33 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/recovery-budget.d.ts +55 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-hook-manager.d.ts +15 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-manager-host-protocol.d.ts +3 -2
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-manager.d.ts +17 -4
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-persistence-error.d.ts +43 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-protocol.d.ts +110 -9
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-run-state-machine-protocol.d.ts +15 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-runtime-lifecycle.d.ts +5 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-store.d.ts +150 -4
- package/cli/dist-server/types/workspace/cbc-core/lib/node/session/stream-timeout-retry-budget.d.ts +20 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/trace/turn-context.d.ts +28 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/command-message-utils.d.ts +20 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/history-utils.d.ts +27 -4
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/index.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/input-item-utils.d.ts +8 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/message-utils.d.ts +12 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/model-utils.d.ts +7 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/queue-dispatch-utils.d.ts +24 -2
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/session-utils.d.ts +4 -1
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/string-retention-utils.d.ts +4 -0
- package/cli/dist-server/types/workspace/cbc-core/lib/node/utils/token-utils.d.ts +3 -1
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/agent/openai-agents-types.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/checkpoint/checkpoint-types.d.ts +6 -0
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/hooks/hook-types.d.ts +7 -1
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/index.d.ts +2 -0
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/model/model-errors.d.ts +36 -4
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/tools/tool-names.d.ts +1 -0
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/utils/retry-backoff.d.ts +30 -0
- package/cli/dist-server/types/workspace/cbc-shared/lib/node/utils/retry-policy.d.ts +26 -0
- package/cli/dist-server/types/workspace/cbc-workflow/lib/node/workflow/workflow-execution.d.ts +14 -1
- package/cli/dist-server/types/workspace/cbc-workflow/lib/node/workflow/workflow-manager.d.ts +7 -0
- package/cli/dist-server/types/workspace/cbc-worktree/lib/node/worktree/worktree-service.d.ts +5 -0
- package/cli/dist-server/types/workspace/cbc-worktree/lib/node/worktree/worktree-session.d.ts +3 -0
- package/cli/dist-server/types/workspace/core/lib/common/protocol.d.ts +8 -1
- package/cli/dist-server/types/workspace/product/lib/common/cloud-product-provider.d.ts +9 -0
- package/cli/dist-server/types/workspace/product/lib/common/index.d.ts +2 -0
- package/cli/dist-server/types/workspace/product/lib/common/pick-market-skill-id.d.ts +13 -0
- package/cli/dist-server/types/workspace/product/lib/common/tencent-docs-endpoint.d.ts +37 -0
- package/cli/dist-server/types/workspace/product/lib/common/tool-control-catalog.d.ts +2 -2
- package/cli/dist-server/types/workspace/product/lib/common/types/config.d.ts +12 -0
- package/cli/dist-server/types/workspace/product/lib/common/types/features.d.ts +63 -11
- package/cli/dist-server/types/workspace/product/lib/common/types/language-model.d.ts +66 -0
- package/cli/dist-server/types/workspace/product/lib/common/types/product.d.ts +22 -1
- package/cli/dist-server/types/workspace/sandbox-cli/lib/common/backup-policy.d.ts +10 -1
- package/cli/dist-server/types/workspace/sandbox-cli/lib/common/center-protocol.generated.d.ts +375 -4
- package/cli/dist-server/types/workspace/sandbox-cli/lib/common/file-policy.d.ts +5 -2
- package/cli/dist-server/types/workspace/sandbox-cli/lib/common/http-policy.d.ts +20 -0
- package/cli/dist-server/types/workspace/sandbox-cli/lib/common/rule-config.d.ts +10 -0
- package/cli/dist-server/types/workspace/sandbox-cli/lib/node/sandbox-center-client.d.ts +219 -0
- package/cli/dist-server/types/workspace/telemetry/lib/common/event/types/craft.d.ts +43 -3
- package/cli/package.json +1 -1
- package/cli/product.cloudhosted.json +4 -4
- package/cli/product.internal.json +268 -45
- package/cli/product.ioa.json +354 -161
- package/cli/product.json +338 -352
- package/cli/product.selfhosted.json +2 -2
- package/cli/vendor/shim/brokered-bin/7z +675 -0
- package/cli/vendor/shim/brokered-bin/7za +675 -0
- package/cli/vendor/shim/brokered-bin/7zz +675 -0
- package/cli/vendor/shim/brokered-bin/rar +675 -0
- package/cli/vendor/shim/brokered-bin/tar +675 -0
- package/cli/vendor/shim/brokered-bin/zip +187 -0
- package/docs/README.md +1 -0
- package/docs/in-process.md +42 -2
- package/docs/protocol.md +7 -1
- package/docs/server.md +2 -0
- package/lib/agent/v2.js +1 -1
- package/lib/application/services.d.ts +3 -1
- package/lib/application/services.js +1 -1
- package/lib/client/client.js +1 -1
- package/lib/client/mcp.d.ts +1 -1
- package/lib/client/mcp.js +1 -1
- package/lib/components/acp-mcp-transport.d.mts +84 -1
- package/lib/components/question-elicitation.d.mts +20 -1
- package/lib/components/sandbox-center.d.mts +2 -0
- package/lib/components/sandbox-center.mjs +1 -0
- package/lib/components/{acp/acp-prompt-input.d.ts → session/prompt-input.d.ts} +1 -1
- package/lib/components/session-config.d.mts +2 -0
- package/lib/components/session-config.mjs +1 -1
- package/lib/components/session-replay.d.mts +6 -7
- package/lib/components/session-replay.mjs +1 -1
- package/lib/effect-runtime/mcp-lifecycle.mjs +1 -1
- package/lib/harness/create-harness.js +1 -1
- package/lib/harness/runtime.js +1 -1
- package/lib/harness/types.d.ts +3 -0
- package/lib/integration/agent-integration.d.ts +5 -0
- package/lib/integration/executor-supervisor.js +1 -1
- package/lib/public.d.ts +1 -0
- package/lib/runtime/private-runtime-role.js +1 -1
- package/lib/runtime/sandbox-center.d.ts +21 -0
- package/lib/runtime/sandbox-center.js +1 -0
- package/lib/server/public.d.ts +1 -0
- package/lib/session/agent-backend.d.ts +5 -0
- package/lib/session/agent-backend.js +1 -1
- package/lib/session/config-defaults.d.ts +4 -0
- package/lib/session/config-defaults.js +1 -0
- package/lib/session/config-store.d.ts +1 -1
- package/lib/session/config-store.js +1 -1
- package/lib/session/local-fs.js +1 -1
- package/lib/session/replay.d.ts +2 -2
- package/lib/session/replay.js +1 -1
- package/lib/session/server-config.d.ts +11 -2
- package/lib/session/server-config.js +1 -1
- package/lib/session/server-events.d.ts +10 -8
- package/lib/session/server-events.js +1 -1
- package/lib/session/server-interactions.js +1 -1
- package/lib/session/server-mcp.js +1 -1
- package/package.json +27 -16
- package/lib/components/acp/acp-client-channel.d.ts +0 -36
- package/lib/components/acp/acp-mcp-transport.d.ts +0 -84
- package/lib/components/acp/acp-question-elicitation.d.ts +0 -20
- package/lib/session/local-options.d.ts +0 -50
- package/lib/session/local-options.js +0 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export declare function resolveMessageSpeakerLabel(input: {
|
|
2
|
+
session?: {
|
|
3
|
+
id?: string;
|
|
4
|
+
storeId?: string;
|
|
5
|
+
meta?: Record<string, unknown>;
|
|
6
|
+
} | undefined;
|
|
7
|
+
runAgentName?: string;
|
|
8
|
+
}): string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* 子会话的**展示名**(给人看):团队成员用成员名,其余子代理用自身预设名(`meta.agentName`);
|
|
11
|
+
* 主会话 / 无会话 / 无身份线索返回 undefined。**只用于展示与遥测标签,不要拿它查表。**
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveSubAgentDisplayName(session: {
|
|
14
|
+
id?: string;
|
|
15
|
+
storeId?: string;
|
|
16
|
+
meta?: Record<string, unknown>;
|
|
17
|
+
} | undefined): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* 子会话的**查表键**(REPL 沙箱白名单 / overlay 缓存用):只认「预设名」这一种语义。
|
|
20
|
+
*
|
|
21
|
+
* 与展示名刻意分开(评审):团队成员会把自己的成员名写进 `meta.agentName`(teammate-runner),
|
|
22
|
+
* 于是 `meta.agentName` 同时承载「预设名」与「成员名」两种含义 —— 拿成员名去查 agent 配置查不到,
|
|
23
|
+
* 只能落到默认 agent 的兜底(既不是成员自己的白名单、也不是「不过滤」)。取不到可信的预设名时
|
|
24
|
+
* 返回 undefined = 不额外收窄(与改动前一致),不去猜。
|
|
25
|
+
*/
|
|
26
|
+
export declare function resolveSubAgentAgentKey(session: {
|
|
27
|
+
id?: string;
|
|
28
|
+
storeId?: string;
|
|
29
|
+
meta?: Record<string, unknown>;
|
|
30
|
+
} | undefined): string | undefined;
|
|
31
|
+
/** 展示名的**派发侧镜像**:子会话还没建时拿不到 `meta.teamContext`,但这对值就是稍后写进 session 的同一对。 */
|
|
32
|
+
export declare function resolveSubAgentDisplayNameFromParts(input: {
|
|
33
|
+
memberName?: string;
|
|
34
|
+
presetName?: string;
|
|
35
|
+
}): string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* 查表键的**派发侧镜像**(AgentManager.sandboxScopedAgentView 传身份用):
|
|
38
|
+
* 预设名与成员名**同值**(团队成员把自己的名字写进 meta.agentName)时判为「没有可信预设名」→ undefined,
|
|
39
|
+
* 与运行期 `resolveSubAgentAgentKey` 同源 —— 否则派发侧按成员名收窄、执行侧判不到,两边分叉。
|
|
40
|
+
*/
|
|
41
|
+
export declare function resolveSubAgentAgentKeyFromParts(input: {
|
|
42
|
+
memberName?: string;
|
|
43
|
+
presetName?: string;
|
|
44
|
+
}): string | undefined;
|
package/cli/dist-server/types/vendor/cbc-core/node/agent/tool-call-loop-detector-service.d.ts
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* wastes tokens/credits.
|
|
7
7
|
*
|
|
8
8
|
* Detection rules:
|
|
9
|
-
* 1. Generic loop: blacklisted tool with identical arguments 4 consecutive times
|
|
9
|
+
* 1. Generic loop: blacklisted tool with semantically identical JSON arguments 4 consecutive times
|
|
10
10
|
* 2. Read file loop: Read tool targeting the same file_path 40 consecutive times
|
|
11
|
-
* 3. Non-blacklist loop: any tool NOT in blacklist with identical arguments 40 consecutive times
|
|
11
|
+
* 3. Non-blacklist loop: any tool NOT in blacklist with semantically identical JSON arguments 40 consecutive times
|
|
12
12
|
*/
|
|
13
13
|
import type { AgentInputItem } from '../../../cbc-shared/node/index.js';
|
|
14
14
|
import { Logger } from '../../../../workspace/telemetry/lib/common/index.js';
|
|
@@ -38,14 +38,15 @@ export declare class ToolCallLoopDetectorImpl implements ToolCallLoopDetector {
|
|
|
38
38
|
arguments: string;
|
|
39
39
|
}>;
|
|
40
40
|
/**
|
|
41
|
-
* Check for generic loop: same tool with identical arguments
|
|
41
|
+
* Check for generic loop: same tool with semantically identical JSON arguments
|
|
42
|
+
* N consecutive times. Malformed or very large argument payloads retain exact-string semantics.
|
|
42
43
|
*/
|
|
43
44
|
protected checkGenericLoop(tailCalls: Array<{
|
|
44
45
|
name: string;
|
|
45
46
|
arguments: string;
|
|
46
47
|
}>): LoopDetectionResult;
|
|
47
48
|
/**
|
|
48
|
-
* Check for non-blacklist tool loop: any tool NOT in the blacklist with identical arguments
|
|
49
|
+
* Check for non-blacklist tool loop: any tool NOT in the blacklist with semantically identical JSON arguments
|
|
49
50
|
* called N consecutive times (threshold: NON_BLACKLIST_LOOP_THRESHOLD).
|
|
50
51
|
* Scans from the tail of input, collecting only non-blacklist function_call items.
|
|
51
52
|
*/
|
|
@@ -27,7 +27,7 @@ export declare const TOOL_CALL_LOOP_STOPPED_MESSAGE = "Request aborted: user sto
|
|
|
27
27
|
* - `ToolCallLoopDetector` 在**模型请求前**拦截,静默向模型注入停止消息,用户无感;
|
|
28
28
|
* 它覆盖的是旧的三条规则(黑名单同参 4 次 / Read 同文件 40 次 / 非黑名单同参 40 次)。
|
|
29
29
|
* - `ToolCallLoopGuard` 在**工具执行前**拦截,弹窗让用户自己决定继续还是停止;
|
|
30
|
-
* 它覆盖新增的两条规则(同工具连续 40 次 / 周期序列重复 10 轮)。
|
|
30
|
+
* 它覆盖新增的两条规则(同工具连续 40 次,Bash 与 Write 单独放到 80 次 / 周期序列重复 10 轮)。
|
|
31
31
|
*
|
|
32
32
|
* 两者刻意并存:旧规则的静默语义已被线上验证,不因新能力回归。
|
|
33
33
|
*/
|
|
@@ -5,8 +5,13 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { ToolCallLoopTriggerType } from '../../../../workspace/telemetry/lib/common/event/types/craft.js';
|
|
7
7
|
export interface ToolCallLoopThresholds {
|
|
8
|
-
/** 同一工具连续调用达到该次数即判定为循环。 */
|
|
8
|
+
/** 同一工具连续调用达到该次数即判定为循环。Bash / Write 走单独阈值。 */
|
|
9
9
|
consecutiveThreshold: number;
|
|
10
|
+
/**
|
|
11
|
+
* Bash 与 Write 连续调用的单独阈值。长任务里模型会连续跑很多条命令、
|
|
12
|
+
* 或连续落很多个文件,只看工具名时 40 次容易把正常推进误判成循环。
|
|
13
|
+
*/
|
|
14
|
+
bashConsecutiveThreshold: number;
|
|
10
15
|
/** AAB 块需要连续重复的轮数。 */
|
|
11
16
|
sequenceRepeats: number;
|
|
12
17
|
}
|
|
@@ -17,6 +22,9 @@ export interface ToolCallLoopHit {
|
|
|
17
22
|
/** 重复序列的周期长度;AAB 恒为 3,连续同工具恒为 1。 */
|
|
18
23
|
patternLength: number;
|
|
19
24
|
}
|
|
25
|
+
/** 与 `ToolNames.BASH` / `ToolNames.WRITE` 对齐。模式识别层不依赖 agent-protocol,避免把工具名枚举拉进来。 */
|
|
26
|
+
export declare const BASH_LOOP_TOOL_NAME = "Bash";
|
|
27
|
+
export declare const WRITE_LOOP_TOOL_NAME = "Write";
|
|
20
28
|
export declare const DEFAULT_TOOL_CALL_LOOP_THRESHOLDS: ToolCallLoopThresholds;
|
|
21
29
|
/** AAB 块的长度。多工具循环只识别这一种形状,因此是常量而非可配阈值。 */
|
|
22
30
|
export declare const AAB_PERIOD = 3;
|
|
@@ -36,7 +44,7 @@ export declare class ToolCallLoopTracker {
|
|
|
36
44
|
* 记录一次即将执行的工具调用,返回本次是否命中循环。
|
|
37
45
|
*
|
|
38
46
|
* 命中优先级:先判连续同工具,再判 AAB 重复。两条规则的阈值默认不重叠
|
|
39
|
-
*
|
|
47
|
+
* (普通工具 40 次、Bash / Write 80 次 vs AAB 重复 10 轮),实践中不会互相抢占。
|
|
40
48
|
*/
|
|
41
49
|
record(toolName: string): ToolCallLoopHit | undefined;
|
|
42
50
|
/**
|
|
@@ -52,14 +60,18 @@ export declare class ToolCallLoopTracker {
|
|
|
52
60
|
* - `ABC`(三者互不相同)通常是正常的多步工作流(读文件 → 改文件 → 跑测试,
|
|
53
61
|
* 然后换下一个文件),按周期重复判它循环误伤面太大;
|
|
54
62
|
* - `ABAB` 这类两工具交替同样不判,避免把翻页 / 分批处理误当循环;
|
|
55
|
-
* - `AAA…` 属于连续同工具,由 consecutiveThreshold
|
|
63
|
+
* - `AAA…` 属于连续同工具,由 consecutiveThreshold / bashConsecutiveThreshold(Bash、Write)那条规则负责。
|
|
56
64
|
*
|
|
57
65
|
* `X ≠ Y` 顺带保证了 AAB 一定是本原周期(唯一可能的更短整除周期是 1,
|
|
58
66
|
* 那要求三个元素全等),所以不需要额外的本原性校验。
|
|
59
67
|
*/
|
|
60
68
|
export declare function matchesRepeatedAabSequence(history: readonly string[], repeats: number): boolean;
|
|
61
69
|
/**
|
|
62
|
-
*
|
|
70
|
+
* 读取阈值配置。环境变量只用于 QA 快速复现,生产不设置即走默认值。
|
|
63
71
|
* AAB 的周期是形状定义的一部分,不开放配置。
|
|
72
|
+
*
|
|
73
|
+
* `CBC_LOOP_GUARD_CONSECUTIVE_THRESHOLD` 只覆盖非 Bash / Write 工具。Bash 与 Write
|
|
74
|
+
* 共用 `CBC_LOOP_GUARD_BASH_CONSECUTIVE_THRESHOLD`,避免 QA 把通用阈值压低时
|
|
75
|
+
* 把长任务放宽一并关掉。
|
|
64
76
|
*/
|
|
65
77
|
export declare function resolveToolCallLoopThresholds(env?: NodeJS.ProcessEnv): ToolCallLoopThresholds;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CompactionKind, CompactionTrigger } from '../../../../workspace/telemetry/lib/common/index.js';
|
|
2
|
+
import type { Session } from '../session/session-protocol';
|
|
3
|
+
export type { CompactionKind, CompactionTrigger };
|
|
4
|
+
export declare function compactionKindOf(trigger: CompactionTrigger): CompactionKind;
|
|
5
|
+
/** Compactions of a Session's context. Never resets, like `modelStepSeq`. */
|
|
6
|
+
export interface CompactionLineage {
|
|
7
|
+
/** Completed compactions. */
|
|
8
|
+
count: number;
|
|
9
|
+
/** Compaction the current context starts from. */
|
|
10
|
+
lastId?: string;
|
|
11
|
+
/** Trigger of the completed compaction the next agent-loop model call reports. */
|
|
12
|
+
pending?: CompactionTrigger;
|
|
13
|
+
}
|
|
14
|
+
type LineageSession = Pick<Session, 'id' | 'history' | 'compactionLineage' | 'meta'>;
|
|
15
|
+
/** Compaction lineage of `session`, restored from its history after resume. */
|
|
16
|
+
export declare function getCompactionLineage(session: LineageSession): CompactionLineage;
|
|
17
|
+
/**
|
|
18
|
+
* Numbers a compaction boundary item before it enters history and stamps the running
|
|
19
|
+
* compaction onto it; the next agent-loop model call reports it.
|
|
20
|
+
*/
|
|
21
|
+
export declare function recordCompactionBoundary(session: LineageSession, providerData: Record<string, unknown>): void;
|
|
22
|
+
/** Compaction lineage of one model call (gateway headers, `chat_message_send`). */
|
|
23
|
+
export interface ModelCallCompaction {
|
|
24
|
+
/** Completed compactions of the Session when the call is sent. */
|
|
25
|
+
readonly count: number;
|
|
26
|
+
/** Compaction the call's context starts from. */
|
|
27
|
+
readonly id?: string;
|
|
28
|
+
/** Compaction calls: class of the running compaction (`X-Compaction`). */
|
|
29
|
+
readonly kind?: CompactionKind;
|
|
30
|
+
/** First agent-loop call after a compaction: its class (`X-Context-Compacted`) and trigger. */
|
|
31
|
+
readonly contextCompacted?: CompactionKind;
|
|
32
|
+
readonly trigger?: CompactionTrigger;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Compaction lineage for the model call in the current async chain. Only the first
|
|
36
|
+
* agent-loop call after a compaction reports it, like Claude Code's
|
|
37
|
+
* `consumePendingContextCompacted`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function resolveModelCallCompaction(session: LineageSession & Pick<Session, 'agentPurpose' | 'conversationRequestId'>): ModelCallCompaction;
|
|
@@ -16,6 +16,7 @@ import { CompactStrategy, type ContextCompactResult, ContextCompactSummarizeOpti
|
|
|
16
16
|
* 不包含任何具体的压缩逻辑实现。
|
|
17
17
|
*/
|
|
18
18
|
export declare class ContextCompactSummarizerImpl implements ContextCompactSummarizer {
|
|
19
|
+
private activeCompactions?;
|
|
19
20
|
protected readonly productManager: ProductManager;
|
|
20
21
|
protected readonly agentManager: AgentManager;
|
|
21
22
|
protected readonly logger: Logger;
|
|
@@ -25,6 +26,7 @@ export declare class ContextCompactSummarizerImpl implements ContextCompactSumma
|
|
|
25
26
|
protected readonly strategyProvider: Provider<CompactStrategy>;
|
|
26
27
|
compactAndSummarize(session: Session, options?: ContextCompactSummarizeOptions): Promise<boolean>;
|
|
27
28
|
compactWithResult(session: Session, options?: ContextCompactSummarizeOptions): Promise<ContextCompactResult>;
|
|
29
|
+
private compactWithResultOwned;
|
|
28
30
|
/**
|
|
29
31
|
* 按优先级匹配(PreMessage → MaxToken),跳过 Blocking(仅作最终兜底),执行第一个命中的策略;
|
|
30
32
|
* 都不命中则安全网回落到 Blocking。逻辑与压缩 span 化之前完全一致,只是把散落的 `return` 收敛成
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import type { AgentInputItem } from '../../../cbc-shared/node/index.js';
|
|
2
|
+
import type { CompactionTrigger } from '../../../../workspace/telemetry/lib/common/index.js';
|
|
1
3
|
import { Session } from '../session/session-protocol';
|
|
2
4
|
export declare const PromptContextProvider: unique symbol;
|
|
3
5
|
export declare const PromptContextInitializer: unique symbol;
|
|
4
6
|
export declare const ContextCompactSummarizer: unique symbol;
|
|
7
|
+
export declare const ManualCompactRequestHandler: unique symbol;
|
|
5
8
|
export declare const PromptRenderer: unique symbol;
|
|
6
9
|
export declare const COMPACT_PROMPT = "compact-prompt";
|
|
7
10
|
export declare const DEFAULT_TOKEN_THRESHOLD = 0.7;
|
|
@@ -190,6 +193,8 @@ export interface ContextCompactSummarizeOptions {
|
|
|
190
193
|
type?: CompactType;
|
|
191
194
|
/** Stable identity shared by live updates and the durable compact boundary. */
|
|
192
195
|
compactionId?: string;
|
|
196
|
+
/** Why this compaction runs; defaults from `type` (manual / pre_message_threshold / emergency_threshold). */
|
|
197
|
+
trigger?: CompactionTrigger;
|
|
193
198
|
}
|
|
194
199
|
export type ContextCompactSkipReason = 'already_compacting' | 'pending_interruption' | 'auto_disabled' | 'empty_history' | 'already_compacted' | 'non_default_agent' | 'below_threshold';
|
|
195
200
|
export type ContextCompactFailureReason = 'strategy_failed' | 'strategy_unavailable';
|
|
@@ -214,6 +219,8 @@ export declare function createCompactionId(): string;
|
|
|
214
219
|
export declare const SESSION_META_COMPACT_TYPE: 'compactType';
|
|
215
220
|
/** Current stable compaction identity, persisted onto the boundary item. */
|
|
216
221
|
export declare const SESSION_META_COMPACTION_ID: 'compactionId';
|
|
222
|
+
/** Trigger of the compaction the summarizer is running; unset for a typed `/compact`. */
|
|
223
|
+
export declare const SESSION_META_COMPACTION_TRIGGER: 'compactionTrigger';
|
|
217
224
|
/**
|
|
218
225
|
* session.meta 上标记当前 compact 成功后会继续执行一次真实 agent run。
|
|
219
226
|
*
|
|
@@ -321,6 +328,16 @@ export interface ContextCompactSummarizer {
|
|
|
321
328
|
/** Compatibility wrapper for existing automatic-compaction callers. */
|
|
322
329
|
compactAndSummarize(session: Session, options?: ContextCompactSummarizeOptions): Promise<boolean>;
|
|
323
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* Host-owned boundary for external `/compact` requests.
|
|
333
|
+
*
|
|
334
|
+
* AgentService invokes this before creating a normal run lifecycle when an
|
|
335
|
+
* interactive host opts in. Implementations must return false for internal compact
|
|
336
|
+
* inputs so strategy-owned internal runs cannot recursively re-enter this boundary.
|
|
337
|
+
*/
|
|
338
|
+
export interface ManualCompactRequestHandler {
|
|
339
|
+
tryHandle(input: string | AgentInputItem[], session: Session): Promise<boolean>;
|
|
340
|
+
}
|
|
324
341
|
export interface PromptRenderer {
|
|
325
342
|
render(template: string, context?: PromptContext): Promise<string>;
|
|
326
343
|
}
|
package/cli/dist-server/types/vendor/cbc-core/node/context/pre-message-compact-strategy.d.ts
CHANGED
|
@@ -4,8 +4,7 @@ import { CompactStrategyContext, ContextCompactSummarizeOptions } from './contex
|
|
|
4
4
|
/**
|
|
5
5
|
* PreMessage 压缩策略:在发送用户消息前触发。
|
|
6
6
|
*
|
|
7
|
-
* 触发条件:PRE_MESSAGE_AUTO 或 WorkBuddy
|
|
8
|
-
* CBC 手动 /compact 不走该策略,继续由 compact agent 路径处理。
|
|
7
|
+
* 触发条件:PRE_MESSAGE_AUTO 或 USER_COMMAND(WorkBuddy / TUI 手动压缩)。
|
|
9
8
|
*
|
|
10
9
|
* 流程:
|
|
11
10
|
* 1. Engineering compact (no LLM call)
|
|
@@ -1,31 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent-trigger payload helper, shared by SessionHookManager and ToolHookManager.
|
|
3
|
-
*
|
|
4
|
-
* Mirrors Claude Code's `createBaseHookInput` (utils/hooks.ts) so that every
|
|
5
|
-
* hook event carries enough context for users to branch on
|
|
6
|
-
* "main thread vs sub-agent" inside their Settings-level hooks.
|
|
7
|
-
*
|
|
8
|
-
* Rules (CC parity):
|
|
9
|
-
* - `agent_type` is the agent's display name; populated from `session.agentName`
|
|
10
|
-
* when set. On the main thread this is the `--agent` flag (when used) or the
|
|
11
|
-
* default agent name. Inside a sub-agent this is the sub-agent's `name`
|
|
12
|
-
* (e.g. "Explore", "Plan", "general-purpose").
|
|
13
|
-
* - `agent_id` is only meaningful inside a sub-agent run — CC leaves it
|
|
14
|
-
* `undefined` on the main thread. We honour the same convention by only
|
|
15
|
-
* emitting it when `session.storeId` is present (sub-agent sessions get a
|
|
16
|
-
* `agent-{8}` storeId; main sessions do not).
|
|
17
|
-
*
|
|
18
|
-
* Kept dependency-free so it can be imported from anywhere — including modules
|
|
19
|
-
* that must avoid pulling the full `../session` barrel (which transitively
|
|
20
|
-
* loads SessionManager / tips and triggers IoC initialisation).
|
|
21
|
-
*/
|
|
22
1
|
export interface AgentTriggerLike {
|
|
23
2
|
id?: string;
|
|
24
3
|
agentName?: string;
|
|
25
4
|
storeId?: string;
|
|
5
|
+
/** 会话 meta:身份标签要读 agentName / teamContext.memberName,parentSessionId 供子会话判定。 */
|
|
26
6
|
meta?: {
|
|
27
7
|
parentSessionId?: string;
|
|
28
|
-
|
|
8
|
+
agentName?: string;
|
|
9
|
+
teamContext?: {
|
|
10
|
+
memberName?: unknown;
|
|
11
|
+
};
|
|
12
|
+
} & Record<string, unknown>;
|
|
29
13
|
}
|
|
30
14
|
export declare function buildAgentTrigger(session: AgentTriggerLike | undefined | null): {
|
|
31
15
|
agent_id?: string;
|
|
@@ -31,7 +31,10 @@ export interface HookInput {
|
|
|
31
31
|
*/
|
|
32
32
|
reason?: SessionEndReason;
|
|
33
33
|
/**
|
|
34
|
-
* User prompt content
|
|
34
|
+
* User prompt content.
|
|
35
|
+
* - UserPromptSubmit: the submitted prompt text.
|
|
36
|
+
* - UserPromptExpansion: Claude Code spec required field, always sent — the
|
|
37
|
+
* raw, pre-expansion text as typed by the user (e.g. "/deploy prod").
|
|
35
38
|
*/
|
|
36
39
|
prompt?: string;
|
|
37
40
|
/**
|
|
@@ -1,44 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* =====================
|
|
6
|
-
* 用户在 agent 还在跑(streaming 末尾、工具执行中等)时输入新消息,UI 调
|
|
7
|
-
* `agentService.run([userMsg])` 进来,`MessageQueueAgentRunInterceptor`
|
|
8
|
-
* (input-interceptors.ts:77-84) 看到 `inConversation=true`,把消息塞进
|
|
9
|
-
* `session.queue` 并设 `skipRun=true`。当前 turn 自然结束、emit `agent_end`,
|
|
10
|
-
* 但**没有任何组件**会主动调一次 `agentService.run([], session)` 来触发
|
|
11
|
-
* interceptor 的 drain 分支(input-interceptors.ts:85-103,那条分支会
|
|
12
|
-
* `mergeConsecutiveUserMessages` 把队列里的消息拍成一个新 turn)。
|
|
13
|
-
*
|
|
14
|
-
* 结果:消息僵在 `session.queue`,UI 显示"已发送",agent 永远不回。
|
|
15
|
-
*
|
|
16
|
-
* `TeamInboxDispatchService` 看起来形态对,但它只检查
|
|
17
|
-
* `RichMessageQueueManager`(团队成员消息进的那个 queue),全 codebase 只有
|
|
18
|
-
* `team-create-tool.ts:332` 一处往 rich queue 写 —— 普通 TUI 用户输入完全
|
|
19
|
-
* 走 `session.queue`,团队 dispatcher 看不到。
|
|
20
|
-
*
|
|
21
|
-
* 这个 service 就填这个空:每个 session 都订阅 `agent_end`,guard 通过后
|
|
22
|
-
* 调一次空 input 的 `agentService.run`,让现有 interceptor 自己合并消费。
|
|
23
|
-
*
|
|
24
|
-
* 与 TeamInboxDispatchService 的关系
|
|
25
|
-
* ==================================
|
|
26
|
-
* - Mode A(默认):`isDeferredDispatchEnabledSync()===false`。
|
|
27
|
-
* IdleQueueDrainService 接管 `session.queue` 的 drain;TeamInboxDispatchService
|
|
28
|
-
* 也订阅了,但它看 rich queue(一般为空)→ short-circuit。
|
|
29
|
-
* - Mode B:`isDeferredDispatchEnabledSync()===true`。
|
|
30
|
-
* IdleQueueDrainService 入口 short-circuit;TeamInboxDispatchService 走
|
|
31
|
-
* rich queue 的 immediate/pending 路径。
|
|
32
|
-
* 两 service 各自有 `dispatching` Set,最坏情况下都是 short-circuit return,
|
|
33
|
-
* 不会双重发起 run。
|
|
34
|
-
*
|
|
35
|
-
* 它不做的事
|
|
36
|
-
* ==========
|
|
37
|
-
* - 不动 `session.queue` 里的内容(让 interceptor 现有 mergeConsecutive 逻辑
|
|
38
|
-
* 作为唯一消费点,避免逻辑漂移)。
|
|
39
|
-
* - 不在 compact 中触发(`session.isCompressing` guard)。
|
|
40
|
-
* - 不在 Mode B 中触发。
|
|
41
|
-
* - 不影响 cancel 路径的 abort 行为(只在 `agent_end` 后做兜底)。
|
|
2
|
+
* Wake local queues after a turn ends. Mode A owns session.queue; Mode B tasks
|
|
3
|
+
* own its non-mirror items. Mode B main sessions remain with rich queue.
|
|
4
|
+
* MessageQueueAgentRunInterceptor remains the only dequeue/merge point.
|
|
42
5
|
*/
|
|
43
6
|
import { Logger } from '../../../../workspace/telemetry/lib/common/index.js';
|
|
44
7
|
import { AgentManager, AgentService } from '../agent/agent-protocol';
|
|
@@ -64,21 +27,6 @@ export declare class IdleQueueDrainServiceImpl implements IdleQueueDrainService
|
|
|
64
27
|
* 空队列直接返回。
|
|
65
28
|
*/
|
|
66
29
|
requestDrain(session: Session): void;
|
|
67
|
-
/**
|
|
68
|
-
* Guard 链 + 调 agentService.run 触发 interceptor 的 drain 分支。
|
|
69
|
-
*
|
|
70
|
-
* Guard 顺序(逐个 short-circuit return):
|
|
71
|
-
* 1. 重入:同 session 上一次 tryDrain 还没 await 完。
|
|
72
|
-
* 2. compact 中:`session.isCompressing===true`。compact 自身的
|
|
73
|
-
* continue-run 也会 emit `agent_end`,必须避让。
|
|
74
|
-
* 3. Mode B:rich queue 通道由 TeamInboxDispatchService 处理。
|
|
75
|
-
* 4. DI 兜底:headless 等变体可能没拉到 AgentService/AgentManager。
|
|
76
|
-
* 5. 空队列:没东西好 drain。
|
|
77
|
-
* 6. 取消记账在途:见下方注释。
|
|
78
|
-
*
|
|
79
|
-
* 失败回灌:interceptor 在 line 95 已经 `clearQueue`,如果后续 run 抛错,
|
|
80
|
-
* 队列里的消息会"被消费但又没真消费",相当于丢了。所以在调 run 之前
|
|
81
|
-
* 快照 queue,run 抛错时检查 queue 是否被清空、被清空就把快照灌回。
|
|
82
|
-
*/
|
|
30
|
+
/** Reuse the existing idle drain and its pre-result failure restoration. */
|
|
83
31
|
private tryDrain;
|
|
84
32
|
}
|
|
@@ -8,6 +8,7 @@ export * from './session-response-host-protocol';
|
|
|
8
8
|
export * from './background-task-protocol';
|
|
9
9
|
export * from './root-session-scope';
|
|
10
10
|
export * from './session-factory';
|
|
11
|
+
export { assertSessionRuntimeOpen, closeSessionRuntime, isSessionRuntimeClosed, sessionRuntimeSignal, } from './session-runtime-lifecycle';
|
|
11
12
|
export * from './session-admission-service';
|
|
12
13
|
export * from './session-manager';
|
|
13
14
|
export * from './session-store';
|
|
@@ -25,14 +26,17 @@ export { getSessionCanUseTool, resolveCanUseTool, resolveCanUseToolOwner, setSes
|
|
|
25
26
|
export type { CanUseTool, CanUseToolOptions, CanUseToolOwner, PermissionBehavior, PermissionDecisionClassification, PermissionResult as CanUseToolPermissionResult, PermissionRuleValue, PermissionUpdate as CanUseToolPermissionUpdate, PermissionUpdateDestination, } from './can-use-tool';
|
|
26
27
|
export * from './dual-channel-interaction';
|
|
27
28
|
export * from './session-persistence';
|
|
29
|
+
export * from './session-persistence-error';
|
|
28
30
|
export * from './session-set-current';
|
|
29
31
|
export * from './cancel-session-runtime-state';
|
|
30
32
|
export * from './user-request-boundary';
|
|
31
33
|
export { isTruncationRecoveryActive } from './truncation-recovery';
|
|
32
34
|
export * from './aborted-stream-draft-store';
|
|
33
35
|
export * from './stream-timeout-retry-budget';
|
|
36
|
+
export { consumeRecoveryRequestPending } from './recovery-budget';
|
|
34
37
|
export * from './session-run-state-machine-protocol';
|
|
35
38
|
export * from './session-run-state-machine';
|
|
39
|
+
export * from './model-request-retry-phase';
|
|
36
40
|
export * from './session-run-state-projection-service';
|
|
37
41
|
export * from './local-jsonl-session-store';
|
|
38
42
|
export * from './transcript-branch';
|
|
@@ -8,12 +8,44 @@ import { InterruptionService, type PendingApprovalView, Session, SessionHookMana
|
|
|
8
8
|
import { SessionRunStateMachine } from './session-run-state-machine-protocol';
|
|
9
9
|
type IIdleQueueDrainService = import('./session-protocol').IdleQueueDrainService;
|
|
10
10
|
export declare class InterruptionServiceImpl implements InterruptionService {
|
|
11
|
+
private readonly resolvedSandboxItems;
|
|
11
12
|
private pendingInterruptions;
|
|
12
13
|
private itemToSessionMap;
|
|
13
14
|
private interruptionQueues;
|
|
14
15
|
private parentIdToMainSession;
|
|
15
16
|
private childToMainSession;
|
|
16
17
|
private waitForSubscriptions;
|
|
18
|
+
private readonly approvalSources;
|
|
19
|
+
private readonly handlingStates;
|
|
20
|
+
private readonly reportedStaleStates;
|
|
21
|
+
private readonly reportedDiscardedApprovals;
|
|
22
|
+
private readonly handledResults;
|
|
23
|
+
private readonly resumeProgress;
|
|
24
|
+
/**
|
|
25
|
+
* Terminal by design: a blocked continuation already proved it cannot make
|
|
26
|
+
* progress, and a later user request arrives on a *new* RunState, so the
|
|
27
|
+
* session is never stranded.
|
|
28
|
+
*/
|
|
29
|
+
private readonly blockedResumeStates;
|
|
30
|
+
/**
|
|
31
|
+
* Deliberately not `session.meta.consecutiveEmptyDrainCount`: the idle
|
|
32
|
+
* empty-drain guard both increments that counter (tripping this
|
|
33
|
+
* continuation early, aborting a legitimate resume) and resets it
|
|
34
|
+
* (stretching the budget without bound).
|
|
35
|
+
*/
|
|
36
|
+
private readonly resumeNoProgressCount;
|
|
37
|
+
private assertApprovalSource;
|
|
38
|
+
private approveSource;
|
|
39
|
+
private awaitPermissionReply;
|
|
40
|
+
/**
|
|
41
|
+
* A decision the user actually clicked must never disappear without a word.
|
|
42
|
+
*
|
|
43
|
+
* The card is dequeued and the deferred rejected, but the run that owned it
|
|
44
|
+
* is already gone — so nothing downstream surfaces the rejection and the
|
|
45
|
+
* user is left believing the tool was approved.
|
|
46
|
+
*/
|
|
47
|
+
private reportDiscardedDecision;
|
|
48
|
+
private reportStaleSource;
|
|
17
49
|
/**
|
|
18
50
|
* 权限审批全局真相源(方案一:统一数据源)。
|
|
19
51
|
*
|
|
@@ -61,12 +93,22 @@ export declare class InterruptionServiceImpl implements InterruptionService {
|
|
|
61
93
|
protected readonly idleQueueDrainService?: IIdleQueueDrainService;
|
|
62
94
|
protected readonly traceCollector?: SessionInterruptionTraceHost;
|
|
63
95
|
protected get startupProfiler(): SessionInterruptionProfilerHost;
|
|
96
|
+
/**
|
|
97
|
+
* 标记「用户取消本轮」的拒绝项(`reject(item, { cancelTurn: true })`)。
|
|
98
|
+
* 语义是取消当前 turn,而不是「拒绝并让模型带反馈续跑」。
|
|
99
|
+
* 记在 WeakSet 而不是 `rawItem.providerData`(那会落进历史),也不改
|
|
100
|
+
* deferred 的 reject 形状(下游按 error 类型分支的逻辑保持不变)。
|
|
101
|
+
*/
|
|
102
|
+
private readonly cancelTurnItems;
|
|
103
|
+
/** Claim before calling out: sandbox callbacks can throw or synchronously re-enter. */
|
|
104
|
+
private takeSandboxResolve;
|
|
64
105
|
approve(item: RunToolApprovalItem, options?: {
|
|
65
106
|
alwaysApprove?: boolean;
|
|
66
107
|
scope?: 'session' | 'localSettings';
|
|
67
108
|
}): void;
|
|
68
109
|
reject(item: RunToolApprovalItem, options?: {
|
|
69
110
|
decision?: 'deny' | 'rejectAndExitPlan';
|
|
111
|
+
cancelTurn?: boolean;
|
|
70
112
|
}): void;
|
|
71
113
|
/**
|
|
72
114
|
* 取消指定 session 上所有未决的 interruption Deferred。
|
|
@@ -101,8 +143,9 @@ export declare class InterruptionServiceImpl implements InterruptionService {
|
|
|
101
143
|
*
|
|
102
144
|
* 幂等:未注册的 sessionId 为 no-op。
|
|
103
145
|
*/
|
|
104
|
-
releaseSession(
|
|
105
|
-
protected handleInterruptions(session: Session, interruptions: RunToolApprovalItem[]): Promise<void>;
|
|
146
|
+
releaseSession(target: string | Session): void;
|
|
147
|
+
protected handleInterruptions(session: Session, interruptions: RunToolApprovalItem[], result?: RunResult<any, any> | StreamedRunResult<any, any> | undefined): Promise<void>;
|
|
148
|
+
private processInterruptions;
|
|
106
149
|
protected executePendingManualPostCompactHook(session: Session, result: RunResult<any, any> | StreamedRunResult<any, any>): Promise<void>;
|
|
107
150
|
waitFor(session: Session): Promise<void>;
|
|
108
151
|
/**
|
|
@@ -334,15 +377,26 @@ export declare class InterruptionServiceImpl implements InterruptionService {
|
|
|
334
377
|
private static sanitizeToolNotFoundMessage;
|
|
335
378
|
private hasRecentModelErrorRetry;
|
|
336
379
|
/**
|
|
337
|
-
*
|
|
338
|
-
*
|
|
380
|
+
* 网络 / 流错误自动恢复的统一前置步骤:认领额度 → 可取消的指数退避 → 标记恢复轮。
|
|
381
|
+
*
|
|
382
|
+
* 认领放在退避之前、且晚于本 catch 里的第一个 await:session-manager 的 gate 在
|
|
383
|
+
* `result.completed` reject 后同步读取同一份预算判据,认领若早于 gate 读取,最后
|
|
384
|
+
* 一次重试会被 gate 误判为「预算已耗尽」而提前下发终态。
|
|
385
|
+
*
|
|
386
|
+
* 退避期间会话处于 RETRYING:失败的 run 与写入中断结果的 skipRun run 都已收尾回 idle,
|
|
387
|
+
* 这里重新置为 busy,TUI 继续显示进行中并响应 Esc,用户新消息进队列而不是直接起 run。
|
|
388
|
+
* 恢复 run 带 bypassMessageQueue 从 RETRYING 直接发起,中间不回 idle,不留让新 run
|
|
389
|
+
* 插入的空窗;恢复 run 收尾(AGENT_ENDED)时回 idle 并带出排队消息。
|
|
390
|
+
*
|
|
391
|
+
* 退避期间用户取消时退回额度、以 RUN_FAILED 收回 idle 并返回 `cancelled`,调用方不得
|
|
392
|
+
* 再发起。取消信号在等待前现取:写入中断结果的 skipRun run 会替换 `session.abortController`,
|
|
393
|
+
* 用户此后按下的 Stop 作用在新 controller 上;排队消息接管 owner 时,其 abort 会级联到这里。
|
|
339
394
|
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
* 将 retry marker 推出 5 条消息的窗口,导致误判为"可以再次重试"
|
|
395
|
+
* 等待结束时若状态既不是 RETRYING 也不是 idle,说明 RETRYING 被迟到的收尾事件冲掉后
|
|
396
|
+
* 已有新 run 被接纳并在执行,返回 `superseded`,否则恢复 run 会与它同时写同一个会话。
|
|
397
|
+
* 此时不退回额度——新请求边界已经清零,再减一次会扣掉新链的额度。
|
|
344
398
|
*/
|
|
345
|
-
private
|
|
399
|
+
private prepareRecoveryAttempt;
|
|
346
400
|
/**
|
|
347
401
|
* CLI TUI 手打 `/compact` 裸跑成功后补发 SessionStart('compact')。
|
|
348
402
|
*
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AgentRetryReason, Session } from './session-protocol';
|
|
2
|
+
import { ModelRequestRetryPhase, SessionRunStateMachine } from './session-run-state-machine-protocol';
|
|
3
|
+
export declare class ModelRequestRetryPhaseImpl implements ModelRequestRetryPhase {
|
|
4
|
+
protected readonly stateMachine: SessionRunStateMachine;
|
|
5
|
+
during<T>(session: Session | undefined, reason: AgentRetryReason, wait: () => Promise<T>): Promise<T>;
|
|
6
|
+
/**
|
|
7
|
+
* 辅助型调用复用主 session 却不回送 AGENT_ENDED(#52320),不得驱动其状态;
|
|
8
|
+
* 状态已离开 MODEL_REQUESTING 说明另有路径在推进,此时不抢写。
|
|
9
|
+
*/
|
|
10
|
+
private enter;
|
|
11
|
+
/**
|
|
12
|
+
* 必须回到 MODEL_REQUESTING:RETRYING 不接收 TOOL_STARTED / MODEL_RESPONSE_DONE 等后续事件,
|
|
13
|
+
* 停留会让错误处理路径的转换被静默忽略。已被取消等事件推走时不再改写。
|
|
14
|
+
*/
|
|
15
|
+
private leave;
|
|
16
|
+
}
|
|
@@ -29,6 +29,24 @@ export declare class finishReasonErrorInterceptor implements ModelResponseInterc
|
|
|
29
29
|
protected readonly sessionStore: SessionStore;
|
|
30
30
|
protected readonly telemetryService: TelemetryService;
|
|
31
31
|
intercept(ctx: ModelResponseInterceptorContext): Promise<boolean | void>;
|
|
32
|
+
/**
|
|
33
|
+
* 处理「已经产出实质内容之后才 `finish_reason=error`」:自动续写,最多 3 次、1s 起步 2 倍退避。
|
|
34
|
+
*
|
|
35
|
+
* 没有任何实质输出就 error 的两种形态(仅 reasoning / 零 token)在模型层被转成可重试的
|
|
36
|
+
* EmptyStreamError,走 interruption-service 的流错误恢复;三者认领同一份 error 预算。
|
|
37
|
+
*
|
|
38
|
+
* 能走到这里说明这次 run 已经结束:SDK 只要本轮还有可执行的工具调用就会继续循环,
|
|
39
|
+
* 不会把控制权交回。因此不存在「参数完整但尚未执行」的工具调用;万一出现,每次构造
|
|
40
|
+
* 请求前的 `fillFunctionCallResultHistory` 也会补齐配对,不会因孤儿调用触发上游 400。
|
|
41
|
+
* 本期只统计孤儿数量用于验证这一推论,不改补齐逻辑。
|
|
42
|
+
*
|
|
43
|
+
* 预算用尽、退避期间被取消或发起失败时都**不返回 `true`**:没有重跑在路上,本轮必须
|
|
44
|
+
* 正常收敛给上层,否则 CLI 会一直等一个不存在的 run。
|
|
45
|
+
*/
|
|
46
|
+
private handleErrorFinishReason;
|
|
47
|
+
private writeErrorTerminalMessage;
|
|
48
|
+
/** 统计本轮以 error 收尾时残留的无配对结果工具调用,用于验证「此处不应有孤儿」的推论。 */
|
|
49
|
+
private logOrphanToolCallsOnError;
|
|
32
50
|
private shouldSkipExpectedSubagentToolCalls;
|
|
33
51
|
/**
|
|
34
52
|
* 处理 length 类型的完成原因:从断点续写(#119765)。
|
|
@@ -197,6 +215,21 @@ export declare class MediaContentErrorInterceptor implements ModelResponseInterc
|
|
|
197
215
|
private static readonly MAX_RETRY_ATTEMPTS;
|
|
198
216
|
private static readonly MAX_MIME_MISMATCH_RETRY_ATTEMPTS;
|
|
199
217
|
private static readonly GIF_UNSUPPORTED_ERROR_CODES;
|
|
218
|
+
/**
|
|
219
|
+
* Gateway business codes that mean "the model refused the images in this
|
|
220
|
+
* request" (`11135 InvalidInputImage`).
|
|
221
|
+
*
|
|
222
|
+
* The code is the only stable signal. The gateway folds several unrelated
|
|
223
|
+
* upstream causes into one hard-coded English sentence and overwrites the
|
|
224
|
+
* upstream text, so `ERROR_TYPE_PATTERNS` matching that sentence breaks the
|
|
225
|
+
* moment the wording is changed or localized (`docs/error-codes.md` already
|
|
226
|
+
* ships a Chinese user-facing string for this code). The code is carried on
|
|
227
|
+
* the error object all the way here — `error-analyzer` puts the parsed body
|
|
228
|
+
* code into the response, the SDK surfaces it as `APIError.error.code`, and
|
|
229
|
+
* `ErrorUtils.extractBizCode` recovers it — so key off it and keep the
|
|
230
|
+
* phrasing match only as a fallback for gateways that send no code.
|
|
231
|
+
*/
|
|
232
|
+
private static readonly IMAGE_REJECTED_ERROR_CODES;
|
|
200
233
|
private static readonly GIF_UNSUPPORTED_PLACEHOLDER;
|
|
201
234
|
private static readonly ERROR_TYPE_PATTERNS;
|
|
202
235
|
intercept(ctx: ModelResponseInterceptorContext): Promise<boolean | void>;
|