@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
|
@@ -2,7 +2,7 @@ import { Logger } from '@celljs/core';
|
|
|
2
2
|
import { type AgentInputItem } from '../../../cbc-shared/node/index.js';
|
|
3
3
|
import * as fs from 'fs/promises';
|
|
4
4
|
import { LocalJsonlSessionStore } from './local-jsonl-session-store';
|
|
5
|
-
import { type Session, SessionFactory, type SessionForkMutationOptions, type SessionGetOptions, type SessionRewindMutationOptions, SessionStore } from './session-protocol';
|
|
5
|
+
import { type Session, SessionFactory, type SessionForkMutationOptions, type SessionGetOptions, type SessionRewindMutationOptions, SessionStore, type TranscriptPersistenceMetrics } from './session-protocol';
|
|
6
6
|
import type { Lane, LanePointer, SessionKey, SessionStoreEntry } from './session-store-contract';
|
|
7
7
|
import { SessionImageStorage as ImageBlobService, SessionRestoreHost, SessionStoragePaths, SessionToolOutputStorage as ToolResultBlobService } from './session-store-host-protocol';
|
|
8
8
|
/**
|
|
@@ -10,6 +10,27 @@ import { SessionImageStorage as ImageBlobService, SessionRestoreHost, SessionSto
|
|
|
10
10
|
* 达到此阈值且遇到 user message 时停止逆序读取,避免启动时全量读 JSONL。
|
|
11
11
|
*/
|
|
12
12
|
export declare const DEFAULT_SESSION_MAX_ITEMS = 1000;
|
|
13
|
+
/**
|
|
14
|
+
* 每追加这么多条 history 行,就把当前 session-meta 快照重新补写到文件尾部。
|
|
15
|
+
*
|
|
16
|
+
* 读侧按 item 数封顶逆序读,只在窗口内找 session-meta;写侧按内容去重,身份
|
|
17
|
+
* 不变就只有创建时那一行(文件第 1 行)。会话一长,读窗口够不到它 → resume
|
|
18
|
+
* 静默丢 `codebuddy.ai/mainAgent`(PTC 掉回 cli、REPL 消失)/ `multitaskMode`
|
|
19
|
+
* / `codebuddy.ai/a2aContexts` / `codebuddy.ai/hostKind`(#128860)。
|
|
20
|
+
*
|
|
21
|
+
* 取值远小于 {@link DEFAULT_SESSION_MAX_ITEMS},读侧即使把上限调低也仍能覆盖;
|
|
22
|
+
* 代价是每 200 行多一条约 200 字节的行(≈0.1%)。
|
|
23
|
+
*
|
|
24
|
+
* **与 {@link SESSION_META_HEAD_SCAN_BYTES} 是配对约束,必须满足**
|
|
25
|
+
* `SESSION_META_TAIL_REFRESH_LINES × 单行平均字节 << SESSION_META_HEAD_SCAN_BYTES`:
|
|
26
|
+
* 写侧靠本行距把快照压在文件尾部,读侧只有 256KB 的文件头兜底窗口 —— 一旦尾部快照
|
|
27
|
+
* 滑出头部窗口,长会话 resume 丢键(#128860 本体)就会以另一种形式回归。
|
|
28
|
+
* 当前 200 × ~200B ≈ 40KB,对 256KB 有约 6× 余量。**调大本值或让单行显著变长
|
|
29
|
+
* (例如工具结果外置后仍很大的行)都必须同步核对另一侧**,spec 里有一条边界断言钉住。
|
|
30
|
+
*/
|
|
31
|
+
export declare const SESSION_META_TAIL_REFRESH_LINES = 200;
|
|
32
|
+
/** 文件头 session-meta 兜底读取的字节窗口(存量会话用,不做全量回扫)。与上者配对,见其注释。导出以便 spec 钉住配对约束。 */
|
|
33
|
+
export declare const SESSION_META_HEAD_SCAN_BYTES: number;
|
|
13
34
|
/**
|
|
14
35
|
* Keys of session.meta that persist across processes (the off-tree
|
|
15
36
|
* session-meta line; bin resume only — served sessions never write). A
|
|
@@ -22,6 +43,37 @@ export declare const DEFAULT_SESSION_MAX_ITEMS = 1000;
|
|
|
22
43
|
* Role / locks / parentSessionId stay runtime-only.
|
|
23
44
|
*/
|
|
24
45
|
export declare const PERSISTED_SESSION_META_KEYS: readonly ['codebuddy.ai/mainAgent', 'codebuddy.ai/hostKind', 'multitaskMode', 'codebuddy.ai/a2aContexts'];
|
|
46
|
+
/**
|
|
47
|
+
* 白名单里「缺席即删除」的键:只认最新那一行的存在性,不向更早的行按键继承。
|
|
48
|
+
*
|
|
49
|
+
* 其余键(mainAgent / hostKind / a2aContexts)只会被赋值、不会被 delete,所以
|
|
50
|
+
* 读侧按键继承——某个写方视野不全(只快照了自己关心的键)不能把别的键擦掉
|
|
51
|
+
* (#128860:`/multitask` 盖章写出只含 multitaskMode 的行,把 PTC 站立身份永久
|
|
52
|
+
* 抹掉,`/agent-mode` 变成 Standard(cli))。
|
|
53
|
+
*
|
|
54
|
+
* `multitaskMode` 是唯一会被真正 delete 的键(multitask/session-flags.ts 的
|
|
55
|
+
* clearMultitaskSession),所以必须留在这里,否则"关掉多任务"会被更早的
|
|
56
|
+
* `true` 复活。**新增白名单键时**:只要它的"缺席"承载语义,就必须登记到本表。
|
|
57
|
+
*
|
|
58
|
+
* 注意「缺席」要能写进文件才算数:子集被删空时 `persistSessionMeta` 会补一条
|
|
59
|
+
* `meta: {}` 的墓碑行,否则最新那条仍是删除前的快照,缺席永远不会出现。墓碑是
|
|
60
|
+
* **整份空快照**:本表登记第二个键之后,为删 A 写的墓碑会连带把 B 也判成缺席,
|
|
61
|
+
* 届时得改成按键墓碑,别直接往表里加。
|
|
62
|
+
*/
|
|
63
|
+
export declare const SNAPSHOT_ONLY_SESSION_META_KEYS: ReadonlyArray<string>;
|
|
64
|
+
/**
|
|
65
|
+
* 参与合并的一条 session-meta 行。
|
|
66
|
+
*
|
|
67
|
+
* `id` 可能是空串:#94203 才给这行加上自身 UUIDv7,更早写下的存量行没有 id
|
|
68
|
+
* (CHANGELOG 明确「兼容旧的无 ID 记录」)。任何按 id 判等的地方都必须先处理
|
|
69
|
+
* 这个缺失,见 {@link SessionStoreImpl.metaLineIdentity}。
|
|
70
|
+
*/
|
|
71
|
+
interface SessionMetaLine {
|
|
72
|
+
id: string;
|
|
73
|
+
meta: Record<string, unknown>;
|
|
74
|
+
/** 行原文(trim 后)。缺 id 的存量行靠它做判等。 */
|
|
75
|
+
raw: string;
|
|
76
|
+
}
|
|
25
77
|
/**
|
|
26
78
|
* 解析 session 历史回放的 maxItems。
|
|
27
79
|
*
|
|
@@ -46,6 +98,7 @@ export declare class SessionStoreImpl implements SessionStore {
|
|
|
46
98
|
protected readonly paths: SessionStoragePaths;
|
|
47
99
|
protected readonly restoreHost: SessionRestoreHost;
|
|
48
100
|
private writeLocks;
|
|
101
|
+
private readonly transcriptMetrics;
|
|
49
102
|
private readonly transcriptAuditOnce;
|
|
50
103
|
private transcriptAuditSequence;
|
|
51
104
|
/**
|
|
@@ -113,6 +166,16 @@ export declare class SessionStoreImpl implements SessionStore {
|
|
|
113
166
|
* behavioral loop: externalize → Read → externalize → Read …).
|
|
114
167
|
*/
|
|
115
168
|
private externalizeToolResultIfNeeded;
|
|
169
|
+
/**
|
|
170
|
+
* Externalize the UI-only copy of a tool result. Tool implementations commonly store
|
|
171
|
+
* the same payload again in providerData.toolResult.content/renderer; keeping that copy
|
|
172
|
+
* defeats output externalization and can make a single JSONL row hundreds of KiB.
|
|
173
|
+
*
|
|
174
|
+
* The render payload is persisted as one JSON document. History keeps a text renderer
|
|
175
|
+
* pointing at that file, so clients always have a visible fallback instead of trying to
|
|
176
|
+
* parse a <persisted-output> marker as the original media/custom renderer payload.
|
|
177
|
+
*/
|
|
178
|
+
private externalizeToolRenderDataIfNeeded;
|
|
116
179
|
/**
|
|
117
180
|
* Handle externalization for structured array output.
|
|
118
181
|
* Iterates through array elements and externalizes any input_text items that exceed the threshold.
|
|
@@ -139,7 +202,25 @@ export declare class SessionStoreImpl implements SessionStore {
|
|
|
139
202
|
*/
|
|
140
203
|
getSessionMetaFilePath(id: string, parentSessionId?: string, cwd?: string): string;
|
|
141
204
|
private lastPersistedMeta;
|
|
205
|
+
/** 各转录文件「距上次 session-meta 行」的 history 行数(进程内,用于尾部刷新节流)。 */
|
|
206
|
+
private historyLinesSinceMeta;
|
|
207
|
+
/** 读侧靠文件头兜底才拿到 meta 的转录文件:下一批 append 立即把快照补到尾部。 */
|
|
208
|
+
private staleTailMeta;
|
|
209
|
+
/**
|
|
210
|
+
* 「据已知,该转录尾部最新那条 session-meta 还带着非空子集」——决定子集被删空时
|
|
211
|
+
* 要不要补墓碑。
|
|
212
|
+
*
|
|
213
|
+
* 判据必须是**文件事实**而不是"本进程写过什么":resume 只 `get()` 不 `save()`
|
|
214
|
+
* (agent-task.ts 的子代理恢复就是这样),进程内缓存恒空,冷启动后第一轮就关掉
|
|
215
|
+
* 多任务会写不出墓碑,"关掉"永远落不了盘。所以读侧 load 完也要维护它。
|
|
216
|
+
*
|
|
217
|
+
* 仍是进程内状态:同一转录被两个进程同时写时,另一方的非空写入本进程不可见
|
|
218
|
+
* (与 `lastPersistedMeta` 同一层限制)。
|
|
219
|
+
*/
|
|
220
|
+
private tailMetaNonEmpty;
|
|
142
221
|
private persistedMetaSubset;
|
|
222
|
+
/** 一条 off-tree session-meta 行的字节形式。空 `persisted` 即墓碑快照。 */
|
|
223
|
+
private metaSnapshotLine;
|
|
143
224
|
/** The off-tree session-meta line, or undefined when there is nothing to persist. */
|
|
144
225
|
protected sessionMetaLineFor(fileId: string, meta: Session['meta']): string | undefined;
|
|
145
226
|
/**
|
|
@@ -150,7 +231,59 @@ export declare class SessionStoreImpl implements SessionStore {
|
|
|
150
231
|
* .meta.json overwrite. Bin surface only — served sessions never reach
|
|
151
232
|
* here (persistence gate; locked by spec).
|
|
152
233
|
*/
|
|
153
|
-
protected persistSessionMeta(fileId: string, meta: Session['meta'], parentSessionId?: string, cwd?: string
|
|
234
|
+
protected persistSessionMeta(fileId: string, meta: Session['meta'], parentSessionId?: string, cwd?: string, options?: {
|
|
235
|
+
force?: boolean;
|
|
236
|
+
}): Promise<void>;
|
|
237
|
+
/**
|
|
238
|
+
* 尾部快照刚落盘后的进程内状态收尾 —— 四份状态必须一起动。
|
|
239
|
+
*
|
|
240
|
+
* `lastPersistedMeta` / `historyLinesSinceMeta` / `staleTailMeta` / `tailMetaNonEmpty`
|
|
241
|
+
* 都以 filePath 为键、都描述「这个转录尾部最新那条 meta 现在是什么」。任何往尾部
|
|
242
|
+
* 写快照的路径(persistSessionMeta / initializeForkHistory)都要走这里:在调用点
|
|
243
|
+
* 手写四行,下一次再加状态时必然漏一处 —— fork 初始化就是这么漏的(lastPersistedMeta
|
|
244
|
+
* 写了,另外三份没写,导致 fork 后关掉多任务写不出墓碑、行数计数带着旧值)。
|
|
245
|
+
*/
|
|
246
|
+
private markTailMetaPersisted;
|
|
247
|
+
/**
|
|
248
|
+
* 让「最新 session-meta」始终留在读侧的逆序窗口内(#128860 根治的写入侧)。
|
|
249
|
+
*
|
|
250
|
+
* 只在 history 真正落盘之后调用:每 {@link SESSION_META_TAIL_REFRESH_LINES}
|
|
251
|
+
* 行补写一次快照;读侧走过文件头兜底的文件(存量长会话)立即补写一次,
|
|
252
|
+
* 这样同一个会话只会退化一次。
|
|
253
|
+
*
|
|
254
|
+
* 失败不能拖垮本轮 append —— 转录字节已经写成功了,meta 下一批还会重试。
|
|
255
|
+
*/
|
|
256
|
+
private refreshTailSessionMeta;
|
|
257
|
+
/**
|
|
258
|
+
* 文件头的 session-meta 兜底读取。
|
|
259
|
+
*
|
|
260
|
+
* `session-meta` 创建行通常在文件靠前的位置(新建会话是第 1 行;子会话/迁移过的
|
|
261
|
+
* 会话可能更靠后),而 history 逆序读有 item 上限——长会话倒着读到不了那里
|
|
262
|
+
* (#128860)。这里只读文件头一小段,不做全量回扫:
|
|
263
|
+
* 29MB 的会话里末尾 1100 行只占 20% 字节,回扫到头会把 resume 的读 I/O 放大 5×。
|
|
264
|
+
*
|
|
265
|
+
* 返回窗口内所有 session-meta 的 meta(文件序,旧→新),由
|
|
266
|
+
* {@link composeSessionMeta} 统一合并。
|
|
267
|
+
*/
|
|
268
|
+
protected readHeadSessionMeta(filePath: string): Promise<SessionMetaLine[] | undefined>;
|
|
269
|
+
/**
|
|
270
|
+
* 合并去重用的行身份。
|
|
271
|
+
*
|
|
272
|
+
* 不能直接用 `id`:#94203 之前的存量行没有 id,兜成空串会让「头部的创建行」
|
|
273
|
+
* 和「尾部的残缺行」撞成同一个键 —— 头部那条被当成"已经见过"丢掉,正好复现
|
|
274
|
+
* 本 issue 要修的丢键现场(本机实测 2607 条 meta 行里 1195 条没有 id)。
|
|
275
|
+
* 缺 id 时退回整行原文:内容相同的两行参与合并是幂等的,丢一条无害。
|
|
276
|
+
*/
|
|
277
|
+
private metaLineIdentity;
|
|
278
|
+
/**
|
|
279
|
+
* 把若干条 session-meta(文件序,旧→新)合成一份 meta 事实。
|
|
280
|
+
*
|
|
281
|
+
* - {@link SNAPSHOT_ONLY_SESSION_META_KEYS}:只认最新那一行(缺席=已删除)。
|
|
282
|
+
* - 其余白名单键:按键向更早的行继承,最新的值优先。写方只快照了自己视野
|
|
283
|
+
* 里的键时,别人的键不会被顺带擦掉(#128860 的第二处:`/multitask` 写出
|
|
284
|
+
* 只含 multitaskMode 的行,PTC 站立身份被永久抹掉)。
|
|
285
|
+
*/
|
|
286
|
+
protected composeSessionMeta(metaLinesOldestFirst: ReadonlyArray<SessionMetaLine>): Record<string, unknown> | undefined;
|
|
154
287
|
private findSubagentSessionByStoreId;
|
|
155
288
|
protected deserializeSessionFromJsonl(id: string, options?: SessionGetOptions): Promise<Session | undefined>;
|
|
156
289
|
/**
|
|
@@ -225,13 +358,25 @@ export declare class SessionStoreImpl implements SessionStore {
|
|
|
225
358
|
*/
|
|
226
359
|
protected isNonUserSession(session: Session): boolean;
|
|
227
360
|
appendHistory(id: string, input: AgentInputItem[], parentSessionId?: string, session?: Session, cwd?: string): Promise<void>;
|
|
361
|
+
protected openJsonlFile(filePath: string, flags: string): ReturnType<typeof fs.open>;
|
|
362
|
+
/** Short, in-band only: this runs on the addHistory chain, so it is turn latency. */
|
|
363
|
+
protected transcriptRetryDelaysMs(): readonly number[];
|
|
364
|
+
protected sleepBeforeTranscriptRetry(delayMs: number): Promise<void>;
|
|
365
|
+
/** Cumulative transcript persistence counters (issue #119545 埋点). */
|
|
366
|
+
transcriptPersistenceMetrics(): Readonly<TranscriptPersistenceMetrics>;
|
|
228
367
|
/**
|
|
229
|
-
* The transcript-line writer
|
|
230
|
-
* appendHistory body: exclusive-create or append open, chunked line
|
|
368
|
+
* The transcript-line writer: exclusive-create or append open, chunked line
|
|
231
369
|
* writes, and on failure a rollback (unlink a file this batch created,
|
|
232
370
|
* truncate to the original size otherwise) with forensic audit logs.
|
|
371
|
+
*
|
|
372
|
+
* A retryable failure gets a short in-band retry. When the budget runs out
|
|
373
|
+
* the batch is abandoned and reported as a typed error — the local copy is
|
|
374
|
+
* allowed to lose its tail, and `addHistory` keeps the turn running. Read
|
|
375
|
+
* paths repair the gap (unpaired tool calls are filtered out of model
|
|
376
|
+
* input), so the cost of a loss is a shorter history, not a broken one.
|
|
233
377
|
*/
|
|
234
378
|
protected writeTranscriptLines(sessionFilePath: string, lines: string[], key?: SessionKey): Promise<void>;
|
|
379
|
+
private writeTranscriptLinesOnce;
|
|
235
380
|
private readonly entriesStoreInstances;
|
|
236
381
|
/**
|
|
237
382
|
* The embedded SessionStore-contract backend — the single jsonl writer
|
|
@@ -312,3 +457,4 @@ export declare class SessionStoreImpl implements SessionStore {
|
|
|
312
457
|
private cleanupFailedFork;
|
|
313
458
|
rewindSession(source: Session, options: SessionRewindMutationOptions): Promise<void>;
|
|
314
459
|
}
|
|
460
|
+
export {};
|
|
@@ -6,9 +6,28 @@ import type { Session } from './session-protocol';
|
|
|
6
6
|
* terminal results are suppressed only while a retry will actually be scheduled.
|
|
7
7
|
*/
|
|
8
8
|
export declare function hasExhaustedStreamTimeoutRetryBudget(session: Session, isFirstTokenTimeout: boolean): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* `finish_reason=error` 且没有可用输出的两种空流:reasoning-only 与 no-token。
|
|
11
|
+
* placeholder(空 200 / 心跳帧)仍是会话层终态,由拦截器切一次备站。
|
|
12
|
+
*
|
|
13
|
+
* 额外的时长闸门(#132616):这两种 kind 之所以可重试,前提是「上游瞬时失败」——秒级
|
|
14
|
+
* 空响应重跑一次大概率就好了。但当这条流已经跑满上游的硬时限才收到 error 时,前提不成立:
|
|
15
|
+
* 同一段 prompt 重跑必然再次跑满同一个时限。实测 7 个会话全部重试、全部再次撞墙、0 次恢复,
|
|
16
|
+
* 而 `#130098` 把预算从 1 提到 3 之后,同样的输入会从 2×900s 变成 4×900s ≈ 60 分钟静默。
|
|
17
|
+
* 重试的期望收益不随 elapsed 增长,成本却线性增长,所以按 elapsed 收口。
|
|
18
|
+
*/
|
|
9
19
|
export declare function isRetryableEmptyStreamError(error: unknown): boolean;
|
|
10
20
|
/**
|
|
11
21
|
* Empty 200 / placeholder-only:拦截器最多切一次备站,会话层终态(#115866)。
|
|
12
|
-
* reasoning-only + finish_reason=error
|
|
22
|
+
* reasoning-only / no-token + finish_reason=error:上游瞬时失败,按 error 预算重试;
|
|
23
|
+
* 已烧满上游硬时限的那些除外,见 {@link isRetryableEmptyStreamError} 的时长闸门(#132616)。
|
|
24
|
+
* 流空闲超时 / 首 token 超时:按各自的超时预算重试。
|
|
13
25
|
*/
|
|
14
26
|
export declare function shouldAutoRetryStreamTimeout(session: Session, error: unknown): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* 为一次流错误恢复认领额度,返回序号(1-based);不可重试或已耗尽返回 `undefined`。
|
|
29
|
+
* 调用方必须先用 {@link shouldAutoRetryStreamTimeout} 判定,本函数只负责同步认领。
|
|
30
|
+
*/
|
|
31
|
+
export declare function claimStreamRecoveryAttempt(session: Session, error: unknown): number | undefined;
|
|
32
|
+
/** 认领后没有真正发起恢复时退回额度。 */
|
|
33
|
+
export declare function releaseStreamRecoveryAttempt(session: Session, error: unknown): void;
|
|
@@ -34,6 +34,33 @@ export interface TurnContext {
|
|
|
34
34
|
/** Canonical id assigned when the external user input is admitted. */
|
|
35
35
|
conversationRequestId?: string;
|
|
36
36
|
}
|
|
37
|
+
export interface RequestOwner {
|
|
38
|
+
readonly session: Session;
|
|
39
|
+
readonly requestId: string;
|
|
40
|
+
readonly turn: TurnContext;
|
|
41
|
+
latestExecution?: object;
|
|
42
|
+
}
|
|
43
|
+
export type RequestTerminalOutcome = 'written' | 'failed' | 'unconfirmed';
|
|
44
|
+
export interface RequestTerminal {
|
|
45
|
+
readonly attempt: object;
|
|
46
|
+
outcome?: RequestTerminalOutcome;
|
|
47
|
+
readonly completed: Promise<RequestTerminalOutcome>;
|
|
48
|
+
}
|
|
49
|
+
export declare function getRequestOwner(ref: object): RequestOwner | undefined;
|
|
50
|
+
export declare function getRequestExecution(ref: object): object | undefined;
|
|
51
|
+
export declare function associateRequestOwner(ref: object, owner: RequestOwner, execution?: object): void;
|
|
52
|
+
/** Carry physical execution through admission without inventing a request owner. */
|
|
53
|
+
export declare function associateRequestExecution(ref: object, execution: object): void;
|
|
54
|
+
/** Reserve completion ownership at admission, retaining the prior result if startup fails. */
|
|
55
|
+
export declare function beginRequestExecution(owner: RequestOwner, execution: object): void;
|
|
56
|
+
/** A failed startup never owns a result; restore only the execution it actually replaced. */
|
|
57
|
+
export declare function abandonRequestExecution(execution: object): Session['resultSubject']['value'];
|
|
58
|
+
export declare function getRequestTerminal(owner: RequestOwner, destination: string): RequestTerminal | undefined;
|
|
59
|
+
export declare function claimRequestTerminal(owner: RequestOwner, destination: string, attempt: object): boolean;
|
|
60
|
+
export declare function settleRequestTerminal(owner: RequestOwner, destination: string, attempt: object, outcome: RequestTerminalOutcome): void;
|
|
61
|
+
/** The admission boundary, not trace binding, creates a new logical request. */
|
|
62
|
+
export declare function admitRequestOwner(session: Session, requestId: string): RequestOwner;
|
|
63
|
+
export declare function runInRequestOwner<T>(owner: RequestOwner, callback: () => T): T;
|
|
37
64
|
/** Transient provider-data key; stripped before history/model persistence. */
|
|
38
65
|
export declare const TURN_CARRIER_CANDIDATE_KEY = "codebuddy.ai/turnCarrierCandidate";
|
|
39
66
|
export declare const BAGGAGE_KEY_SESSION_ID = "codebuddy.session_id";
|
|
@@ -83,7 +110,7 @@ export declare function bindCurrentTurnContext(session: Session, conversationReq
|
|
|
83
110
|
/** Carrier for one exact admitted request; never returns the latest other turn. */
|
|
84
111
|
export declare function turnCarrierForRequest(session: Session, conversationRequestId: string | undefined): W3CTraceContextMeta;
|
|
85
112
|
/** Release an exact request binding. */
|
|
86
|
-
export declare function releaseTurnContext(session: Session, conversationRequestId: string | undefined): void;
|
|
113
|
+
export declare function releaseTurnContext(session: Session, conversationRequestId: string | undefined, owner?: RequestOwner): void;
|
|
87
114
|
/** The current turn as an injectable three-key carrier; `{}` outside a turn. */
|
|
88
115
|
export declare function currentTurnCarrier(): W3CTraceContextMeta;
|
|
89
116
|
/**
|
|
@@ -58,6 +58,26 @@ export declare abstract class CommandMessageUtils {
|
|
|
58
58
|
* 解析XML格式的命令输出
|
|
59
59
|
*/
|
|
60
60
|
static parseOutput(xmlText: string): ParseCommandMessage | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* 是否为本地命令在会话历史里留下的记账项:caveat、命令回显(`<command-name>`)、
|
|
63
|
+
* 命令输出(`<local-command-stdout>`)、本地 bash 的输入输出、plan 输出。
|
|
64
|
+
*
|
|
65
|
+
* 这些 item 的 role 是 user、也不带 skipRun,因此按「真实用户消息」判定会命中;
|
|
66
|
+
* 但它们只是本地命令的痕迹,**不代表用户开启了新一轮对话**。调用方(如 TUI 的
|
|
67
|
+
* loading 计时器)需要区分「新一轮」和「本地命令留痕」时用这个判据。
|
|
68
|
+
*
|
|
69
|
+
* 识别口径复用 parseInput / parseOutput / parsePlanOutput,避免调用方各自
|
|
70
|
+
* 维护一份 XML 标签清单而漂移。
|
|
71
|
+
*/
|
|
72
|
+
static isLocalCommandRecord(text: string): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* {@link isLocalCommandRecord} 的 item 版本。
|
|
75
|
+
*
|
|
76
|
+
* 必须读 **原始** content:`MessageContentUtils.extractTextContent` 已经把命令 XML
|
|
77
|
+
* 拆开(`<command-name>/doctor</command-name>` → `/doctor`),拿它的结果再判就永远
|
|
78
|
+
* 判不出来。
|
|
79
|
+
*/
|
|
80
|
+
static isLocalCommandRecordItem(item: UserMessageItem): boolean;
|
|
61
81
|
/**
|
|
62
82
|
* 解析计划输出
|
|
63
83
|
*/
|
|
@@ -226,10 +226,10 @@ export declare abstract class HistoryUtils {
|
|
|
226
226
|
* <conversation_history_summary>…</conversation_history_summary> 包裹的正文)。
|
|
227
227
|
*
|
|
228
228
|
* 规则(与 replaceCompactWithSummary / getCompactHistory 对齐):
|
|
229
|
-
* 1.
|
|
230
|
-
* 2.
|
|
231
|
-
* 3.
|
|
232
|
-
*
|
|
229
|
+
* 1. 查看 compact-agent assistant,或 PreMessage/MaxToken 写入的显式 compact boundary
|
|
230
|
+
* 2. 从后向前扫描,命中第一条可用摘要即返回
|
|
231
|
+
* 3. compact assistant 继续要求结构化 summary envelope;显式 boundary 同时支持
|
|
232
|
+
* 工程压缩的 `<cb_summary>` 与 LLM summary envelope
|
|
233
233
|
* 4. 全程扫描都拿不到 → 返回 `undefined`(history 中**从未**出现过合法摘要)
|
|
234
234
|
*
|
|
235
235
|
* ⚠️ 不适合用于"判断本次 compact run 是否成功"!
|
|
@@ -364,6 +364,29 @@ export declare abstract class HistoryUtils {
|
|
|
364
364
|
*/
|
|
365
365
|
static filterApiErrorMessages(history: AgentInputItem[]): AgentInputItem[];
|
|
366
366
|
static filterRenameHistory(history: AgentInputItem[]): AgentInputItem[];
|
|
367
|
+
/**
|
|
368
|
+
* 让 model input 里的 tool_call 与 tool_result 严格一一配对(issue #119545)。
|
|
369
|
+
*
|
|
370
|
+
* 背景:工具结果丢失(状态机吞掉 TOOL_ENDED、持久化缺口、压缩切断)后,历史里会留下
|
|
371
|
+
* 只有 call、没有任何 result 的孤儿。上游对 tool_calls 强制配对,一条孤儿就让整个
|
|
372
|
+
* 请求 400,会话从此不可恢复——而本地历史里的孤儿是持久化的,每次恢复都会重现。
|
|
373
|
+
*
|
|
374
|
+
* 三类都处理,因为上游拒的是"不配对"这件事本身,方向无关:
|
|
375
|
+
* 1. call 没有任何同 callId 的结果项 → 丢 call;
|
|
376
|
+
* 2. 同一 callId 出现多条 call(重放/重试残留)→ 只留最后一条;
|
|
377
|
+
* 3. 结果项的 callId 没有留下来的 call(头部被截断,或 call 属于上面两类)→ 丢结果。
|
|
378
|
+
*
|
|
379
|
+
* 判据只看"存在性",不看结果的真伪:skipRun 占位/拒绝、partial aborted 等伪结果都算
|
|
380
|
+
* 配对,它们的取舍归 filterTruncatedToolCalls,两者职责不重叠。改写只落在当轮副本上,
|
|
381
|
+
* 因此日志按轮聚合成一条并截断样本。
|
|
382
|
+
*/
|
|
383
|
+
static filterUnpairedToolCalls(modelData: {
|
|
384
|
+
input: AgentInputItem[];
|
|
385
|
+
instructions?: string;
|
|
386
|
+
}, logger?: Logger): {
|
|
387
|
+
input: AgentInputItem[];
|
|
388
|
+
instructions?: string;
|
|
389
|
+
};
|
|
367
390
|
static getItemsNeedingFill(history: AgentInputItem[]): FunctionCallItem[];
|
|
368
391
|
static getFillItemsForNeedingFill(itemsNeedingFill: FunctionCallItem[]): FunctionCallResultItem[];
|
|
369
392
|
/**
|
|
@@ -256,6 +256,14 @@ export declare abstract class InputItemUtils {
|
|
|
256
256
|
static isUserInterrupted(item: AgentInputItem): boolean;
|
|
257
257
|
static isSuccessfulFunctionCallResultItem(item: AgentInputItem): item is FunctionCallResultItem;
|
|
258
258
|
static isCompactBoundaryMessage(item: AgentInputItem): boolean;
|
|
259
|
+
/**
|
|
260
|
+
* 仅凭 providerData 结构化标记判定 compact boundary,不使用内容正则兜底。
|
|
261
|
+
*
|
|
262
|
+
* 会删除或改写消息的路径(如 replaceCompactWithSummary)必须用这个版本:
|
|
263
|
+
* 内容兜底会把用户粘贴的 `<cb_summary>` / `<conversation_history_summary>` 文本
|
|
264
|
+
* 误判为 boundary,导致真实用户输入被移除。
|
|
265
|
+
*/
|
|
266
|
+
static isStructuredCompactBoundaryMessage(item: AgentInputItem): boolean;
|
|
259
267
|
static isReplayRecoverableCompactMessage(item: AgentInputItem): item is UserMessageItem;
|
|
260
268
|
static isCompactUserMessage(item: AgentInputItem): item is UserMessageItem;
|
|
261
269
|
private static hasCompactBoundaryContent;
|
|
@@ -79,6 +79,18 @@ export declare abstract class MessageUtils {
|
|
|
79
79
|
static createFilteredCopyForCompaction(messages: AgentInputItem[]): AgentInputItem[];
|
|
80
80
|
private static filterHiddenSystemRemindersForCompaction;
|
|
81
81
|
static stripSystemRemindersOutsideUserQuery(text: string): string;
|
|
82
|
+
/**
|
|
83
|
+
* 压缩链路的统计日志出口。
|
|
84
|
+
*
|
|
85
|
+
* **禁止改回 `process.stderr.write` / `process.stdout.write`**(issue #76749):
|
|
86
|
+
* TUI 下裸写 stderr 会破坏 Ink 帧间光标定位,导致行级 diff 错位、spinner 残留。
|
|
87
|
+
* 走 logger 落盘即可,既保留排查信息又不碰 TTY。
|
|
88
|
+
*
|
|
89
|
+
* `catch` 有意整段吞掉,不做分级上报:日志出口的任何失败(容器未就绪、logger 自身
|
|
90
|
+
* 抛错)都不得影响压缩本身;而「失败时改走 stderr 兜底」恰会在异常路径上重新引入
|
|
91
|
+
* 本 issue 要修掉的 TTY 裸写。统计丢失是可接受的降级。
|
|
92
|
+
*/
|
|
93
|
+
private static logCompaction;
|
|
82
94
|
/**
|
|
83
95
|
* Microcompact: clear output of old tool results (> 1 hour) to reduce token count.
|
|
84
96
|
* Modifies items in place. Should be called BEFORE createFilteredCopyForCompaction.
|
|
@@ -70,6 +70,13 @@ export declare abstract class ModelUtils {
|
|
|
70
70
|
*/
|
|
71
71
|
private static readRuntimeModelId;
|
|
72
72
|
static isHunyuanModel(session: Session): Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* ImageGen 实际使用的图片模型是否为混元。
|
|
75
|
+
*
|
|
76
|
+
* 取「产品配置里第一个带 text-to-image tag 的模型」,与 image-service 的解析顺序一致;
|
|
77
|
+
* 配置里没有图片模型时会走客户端的混元兜底模型,同样按混元处理。
|
|
78
|
+
*/
|
|
79
|
+
static isHunyuanImageModel(): Promise<boolean>;
|
|
73
80
|
static isMandatoryApprovalTarget(session: Session, targetToolName: string): Promise<boolean>;
|
|
74
81
|
}
|
|
75
82
|
export {};
|
|
@@ -17,7 +17,8 @@ import type { Session } from '../session/session-protocol';
|
|
|
17
17
|
* 取;CLI **不再自动 drain**。后果有两条,改这块代码前必须知道:
|
|
18
18
|
* 1. `session.queue` 降级为 rich queue 的**展示镜像**(只给 CLI TUI 看),镜像段由
|
|
19
19
|
* `RichMessageQueueManagerImpl.syncToSessionQueue` 整体重建;
|
|
20
|
-
* 2.
|
|
20
|
+
* 2. 主会话的 legacy 自动 drain 路径被短路。子任务没有客户端派发者,仍由
|
|
21
|
+
* MessageQueueAgentRunInterceptor 消费非镜像项(包括普通 user 消息)。
|
|
21
22
|
*
|
|
22
23
|
* 因此在 Mode B 下 `session.queue` 是两个所有者共用的数组:镜像段属于 rich queue,
|
|
23
24
|
* 系统注入项(后台任务通知 / channel / teammate / ACP steer 等)属于各自的注入方。任何一方读写它时
|
|
@@ -63,9 +64,30 @@ export declare abstract class QueueDispatchUtils {
|
|
|
63
64
|
* 从 `session.queue` 里挑出「自动 drain 通道」该消费的项。
|
|
64
65
|
*
|
|
65
66
|
* Mode A:整个队列都是待发输入,原样返回(保持既有行为)。
|
|
66
|
-
* Mode B
|
|
67
|
+
* Mode B 主会话:只返回系统注入项。子任务:所有非镜像项都是真实待发输入。
|
|
67
68
|
*/
|
|
68
69
|
static ownedQueueItems(session: Session): AgentInputItem[];
|
|
70
|
+
/** Task runtimes have no client queue dispatcher, including restored child sessions. */
|
|
71
|
+
static isTaskQueue(session: Session): boolean;
|
|
72
|
+
/** The legacy interceptor owns all Mode A input and Mode B task input, never rich mirrors. */
|
|
73
|
+
static usesLocalQueueDispatch(session: Session): boolean;
|
|
74
|
+
static autoDrainQueueItems(session: Session): AgentInputItem[];
|
|
75
|
+
/**
|
|
76
|
+
* Observe which items one drain invocation actually consumed.
|
|
77
|
+
*
|
|
78
|
+
* **`input` is matched by array *identity*, not contents** — a copy observes
|
|
79
|
+
* nothing, and the caller then reads a failed drain as having consumed
|
|
80
|
+
* nothing. Per instance rather than per session because a session-wide
|
|
81
|
+
* snapshot cannot tell this batch apart from a competing run's.
|
|
82
|
+
*
|
|
83
|
+
* @returns disposer; call it once the run settles.
|
|
84
|
+
*/
|
|
85
|
+
static observeQueueDrain(input: AgentInputItem[], observer: (items: AgentInputItem[], signal?: AbortSignal) => void): () => void;
|
|
86
|
+
/**
|
|
87
|
+
* Report the items consumed for `input`. No-op when nobody observes that
|
|
88
|
+
* exact array instance — see {@link observeQueueDrain} for the contract.
|
|
89
|
+
*/
|
|
90
|
+
static recordQueueDrain(input: AgentInputItem[], items: AgentInputItem[], signal?: AbortSignal): void;
|
|
69
91
|
/**
|
|
70
92
|
* Async check — reads product config when env var is not set.
|
|
71
93
|
*/
|
|
@@ -11,7 +11,10 @@ export declare abstract class SessionUtils {
|
|
|
11
11
|
* session 中发生实际可见的 ID 冲突。
|
|
12
12
|
*/
|
|
13
13
|
static subAgentId(): string;
|
|
14
|
-
static isSubAgent(session:
|
|
14
|
+
static isSubAgent(session: {
|
|
15
|
+
id?: string;
|
|
16
|
+
storeId?: string;
|
|
17
|
+
}): boolean;
|
|
15
18
|
/**
|
|
16
19
|
* Clone one history item for a fork without duplicating large string payloads.
|
|
17
20
|
*
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Materialize an independent string without changing its UTF-16 code units. */
|
|
2
|
+
export declare function copyString(value: string): string;
|
|
3
|
+
/** Truncate by JavaScript string length and detach the retained prefix from its parent. */
|
|
4
|
+
export declare function truncateAndCopyString(value: string, maxLength: number, suffix?: string): string;
|
|
@@ -64,7 +64,9 @@ export declare class TokenUtils {
|
|
|
64
64
|
* tool call 执行后产生的 function_call_result(这些结果在 API 返回后才追加到 history)。
|
|
65
65
|
* 为了更准确地判断是否需要触发压缩,需要把这部分 token 补上。
|
|
66
66
|
*
|
|
67
|
-
* 从 history
|
|
67
|
+
* 从 history 末尾往前扫描,只收集紧挨在末尾的连续 function_call_result。
|
|
68
|
+
* 一遇到非 function_call_result(含 function_call)即停止:function_call 属于上一轮
|
|
69
|
+
* 已经进过请求的内容,穿过它会把更早轮次的 result 重复计入 inputTokens(#133055)。
|
|
68
70
|
* 注意:估算前会移除图片内容,避免 base64 图片数据导致 token 严重偏高。
|
|
69
71
|
*/
|
|
70
72
|
static estimateTrailingToolResultTokens(history: any[]): number;
|
|
@@ -31,6 +31,7 @@ import type { AgentOutputType, getAllMcpTools as getAllMcpToolsFn, MaxTurnsExcee
|
|
|
31
31
|
import type { TextOutput, UnknownContext, UserContent } from '@openai/agents-core/types';
|
|
32
32
|
import type { AcpTerminalStateItem, FileHistorySnapshotItem, ModelUsageItem, ResendForkNoticeItem } from './custom-input-item-types';
|
|
33
33
|
export * from './custom-input-item-types';
|
|
34
|
+
export type { RunStreamEvent } from '@openai/agents-core';
|
|
34
35
|
export type Agent<TContext = UnknownContext, TOutput extends AgentOutputType = TextOutput> = AgentTypeCtor<TContext, TOutput>;
|
|
35
36
|
export type RunContext<TContext = UnknownContext> = RunContextTypeCtor<TContext>;
|
|
36
37
|
export type Runner = RunnerTypeCtor;
|
|
@@ -64,4 +64,10 @@ export interface CheckpointFileChangeStats {
|
|
|
64
64
|
additions: number;
|
|
65
65
|
/** 删除行数 */
|
|
66
66
|
deletions: number;
|
|
67
|
+
/**
|
|
68
|
+
* 行数为近似值(PTC/Code Mode 兜底:files 来自本轮 trackFile 快照,additions/deletions
|
|
69
|
+
* 暂记 0)。需要精确行数的调用方(如 TUI rewind 面板)据此异步调用
|
|
70
|
+
* compareWithCurrentFiles 补齐后清除本标记。仅内存态,不持久化。
|
|
71
|
+
*/
|
|
72
|
+
approximate?: boolean;
|
|
67
73
|
}
|
|
@@ -83,7 +83,13 @@ export declare enum HookEvent {
|
|
|
83
83
|
FILE_CHANGED = "FileChanged",
|
|
84
84
|
CWD_CHANGED = "CwdChanged",
|
|
85
85
|
/** Terminal event; does not support continueRequest. */
|
|
86
|
-
FINAL_STOP = "FinalStop"
|
|
86
|
+
FINAL_STOP = "FinalStop",
|
|
87
|
+
/**
|
|
88
|
+
* Triggered when a user-typed command/skill expands into a prompt, before
|
|
89
|
+
* it reaches the model. Can block the expansion.
|
|
90
|
+
* Claude Code parity: matcher filters on `command_name`.
|
|
91
|
+
*/
|
|
92
|
+
USER_PROMPT_EXPANSION = "UserPromptExpansion"
|
|
87
93
|
}
|
|
88
94
|
/** Hook script stdout payload. */
|
|
89
95
|
export interface HookOutput {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from './agent/openai-agents-types';
|
|
2
2
|
export * from './agent-home/agent-home-envelope-body';
|
|
3
3
|
export * from './utils/abort-utils';
|
|
4
|
+
export * from './utils/retry-backoff';
|
|
5
|
+
export * from './utils/retry-policy';
|
|
4
6
|
export * from './settings/settings-types';
|
|
5
7
|
export * from './tools/tool-permission-types';
|
|
6
8
|
export * from './tools/tool-permission-messages';
|
|
@@ -17,10 +17,26 @@ export declare class StreamTimeoutError extends CustomError {
|
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* placeholder:空 200 / 心跳占位,拦截器最多切一次备站,会话层终态。
|
|
20
|
-
* reasoning-only:已流出思考、finish_reason=error 且无可用输出(#63761 / #122115
|
|
21
|
-
*
|
|
20
|
+
* reasoning-only:已流出思考、finish_reason=error 且无可用输出(#63761 / #122115)。
|
|
21
|
+
* no-token:finish_reason=error 到达时一个模型 token 都没有(连 reasoning 也没有)。
|
|
22
|
+
*
|
|
23
|
+
* reasoning-only 与 no-token 按「上游瞬时失败」处理,会话层按 error 恢复预算重试——
|
|
24
|
+
* 但仅限流没跑太久的那些:已经烧满上游硬时限的同样形态重跑必然再次跑满,由
|
|
25
|
+
* `isRetryableEmptyStreamError` 按 {@link EmptyStreamError.elapsedMs} 收口(#132616)。
|
|
26
|
+
* placeholder 必须与 no-token 分开——两者共用一个值时,放开 no-token 会连带
|
|
27
|
+
* 推翻空 200 的终态判定。
|
|
28
|
+
*/
|
|
29
|
+
export type EmptyStreamKind = 'placeholder' | 'reasoning-only' | 'no-token';
|
|
30
|
+
/**
|
|
31
|
+
* 空流错误的结构化 category,两条上报通道共用一个值。
|
|
32
|
+
*
|
|
33
|
+
* ACP 侧 `classifyErrorAsRequestError` 早就用它(前端按此映射业务码 3008「模型服务未返回消息」);
|
|
34
|
+
* stream-json 侧此前没有任何结构化维度,`errors_info` 整体缺席,sandbox-proxy 的
|
|
35
|
+
* `BuildErrorMessageFromCLIErrors` 只能兜底成 `category=internal`,再由
|
|
36
|
+
* `ClassifyInBandPromptError` 推出 `error_origin=cli`——把上游故障记成 CLI 内部错误。
|
|
37
|
+
* 挂到错误对象的 `data` 上让两条通道读到同一个值,不再各说各话。
|
|
22
38
|
*/
|
|
23
|
-
export
|
|
39
|
+
export declare const EMPTY_STREAM_ERROR_CATEGORY = "empty_model_response";
|
|
24
40
|
/**
|
|
25
41
|
* 空流错误
|
|
26
42
|
* 语义上仍然是"上游没有提供模型输出",所以继承 StreamTimeoutError
|
|
@@ -29,10 +45,26 @@ export type EmptyStreamKind = 'placeholder' | 'reasoning-only';
|
|
|
29
45
|
* 典型触发:某些 OpenAI 兼容网关在后端异常时没有透传错误码,而是发一帧全空
|
|
30
46
|
* `{"delta":{"role":"assistant","content":"","tool_calls":[],"refusal":""},"finish_reason":""}`
|
|
31
47
|
* 然后直接关闭连接——用户看到的现象是 cbc 当前轮"空响应"并被 ACP 分类为 refusal。
|
|
48
|
+
*
|
|
49
|
+
* message **必须**按 kind 分开写:三种 kind 共用一句「only placeholder chunks」会谎报失败形态。
|
|
50
|
+
* 0924 沙箱实测的 reasoning-only 样本里上游发了 20397 帧 / 9.5 MB 真实 reasoning,
|
|
51
|
+
* 与「只有占位帧」正相反;而下游报表、看板、排障全靠这个字符串归因,于是把上游
|
|
52
|
+
* ~900s 时限问题记成了 CLI 内部错误(#132616)。
|
|
32
53
|
*/
|
|
33
54
|
export declare class EmptyStreamError extends StreamTimeoutError {
|
|
34
55
|
readonly emptyStreamKind: EmptyStreamKind;
|
|
35
|
-
|
|
56
|
+
/**
|
|
57
|
+
* 流从打开到判定空流的时长。
|
|
58
|
+
*
|
|
59
|
+
* 用来区分「上游瞬时抖动(秒级空响应)」和「跑满上游硬时限(0924 实测 ~900s)」——
|
|
60
|
+
* 后者重跑同一段 prompt 必然再次跑满,重试只是把静默时长翻倍,见
|
|
61
|
+
* `isRetryableEmptyStreamError` 的时长闸门。
|
|
62
|
+
*/
|
|
63
|
+
readonly elapsedMs: number;
|
|
64
|
+
readonly data: Readonly<{
|
|
65
|
+
category: "empty_model_response";
|
|
66
|
+
}>;
|
|
67
|
+
constructor(chunkCount: number, totalBytes: number, kind?: EmptyStreamKind, elapsedMs?: number);
|
|
36
68
|
}
|
|
37
69
|
/**
|
|
38
70
|
* 认证缺失错误
|
|
@@ -63,6 +63,7 @@ export declare enum ToolNames {
|
|
|
63
63
|
WAIT_FOR_MCP_SERVERS = "WaitForMcpServers",
|
|
64
64
|
WORKFLOW = "Workflow",
|
|
65
65
|
VIDEO_GEN = "VideoGen",
|
|
66
|
+
AUDIO_TRANSCRIBE = "AudioTranscribe",
|
|
66
67
|
REPORT_FINDINGS = "ReportFindings",
|
|
67
68
|
MONITOR = "Monitor",
|
|
68
69
|
LIST_AGENTS = "ListAgents",
|