@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,6 +2,7 @@ import { Deferred } from '@celljs/core';
|
|
|
2
2
|
import { type AgentInputItem, ApprovalOptions, type Checkpoint, FinalStopReason, NotificationType, PermissionMode, ReasoningEffortLevel, type ResponseStreamEvent, type RunItem, type RunResult, type RunState, type RunToolApprovalItem, type SdkCapabilities, SessionEndReason, SessionStartSource, type StreamedRunResult, type TerminalEvent, type ToolDeferOverlaySnapshot, ToolPermissionContext, type Usage } from '../../../../cbc-shared/lib/node/index.js';
|
|
3
3
|
import { Command } from '../../../../product/lib/common/index.js';
|
|
4
4
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
5
|
+
import type { CompactionLineage } from '../context/compaction-lineage.js';
|
|
5
6
|
import { BackgroundTask } from './background-task-protocol.js';
|
|
6
7
|
import type { SessionRunStateSnapshot } from './session-run-state-machine-protocol.js';
|
|
7
8
|
import type { Lane, LanePointer, SessionKey, SessionStoreEntry } from './session-store-contract.js';
|
|
@@ -86,9 +87,11 @@ export type AgentState = 'agent_pending' | 'agent_start' | 'agent_tool_start' |
|
|
|
86
87
|
* 则 emit,触发 UI 显示"正在同步文件"提示)
|
|
87
88
|
*/
|
|
88
89
|
export type AgentPhase = 'preparing' | 'model_requesting' | 'model_streaming' | 'model_done' | 'tool_executing' | 'waiting_for_permission' | 'waiting_for_user' | 'retrying' | 'finalization_file_projection_sync' | 'finalization_file_projection_sync_notify' | 'idle';
|
|
90
|
+
export type AgentRetryReason = 'network';
|
|
89
91
|
export interface AgentPhaseInfo {
|
|
90
92
|
phase: AgentPhase;
|
|
91
93
|
toolName?: string;
|
|
94
|
+
toolCallId?: string;
|
|
92
95
|
streamingToolName?: string;
|
|
93
96
|
startedAt: number;
|
|
94
97
|
/**
|
|
@@ -101,6 +104,13 @@ export interface AgentPhaseInfo {
|
|
|
101
104
|
current: number;
|
|
102
105
|
total: number;
|
|
103
106
|
};
|
|
107
|
+
/**
|
|
108
|
+
* 仅 retrying phase 使用,经 ACP `_meta['codebuddy.ai/agentPhase']` 透传给上层。
|
|
109
|
+
* 缺省表示原因未分类(如流超时),不代表网络正常。
|
|
110
|
+
*/
|
|
111
|
+
retry?: {
|
|
112
|
+
reason: AgentRetryReason;
|
|
113
|
+
};
|
|
104
114
|
}
|
|
105
115
|
export declare const AgentPhaseUtils: {
|
|
106
116
|
/** Create an AgentPhaseInfo with the current timestamp. */
|
|
@@ -177,6 +187,8 @@ export interface PreToolUseHookResult {
|
|
|
177
187
|
permissionDecision?: 'allow' | 'deny' | 'ask';
|
|
178
188
|
permissionDecisionReason?: string;
|
|
179
189
|
runtimeSecurity?: Record<string, unknown>;
|
|
190
|
+
/** PreToolUse `continue:false` — stop the current turn after the deny result is recorded. */
|
|
191
|
+
preventContinuation?: boolean;
|
|
180
192
|
}
|
|
181
193
|
export interface Session {
|
|
182
194
|
id: string;
|
|
@@ -206,6 +218,8 @@ export interface Session {
|
|
|
206
218
|
*/
|
|
207
219
|
replSandboxDepth?: number;
|
|
208
220
|
state?: RunState<any, any>;
|
|
221
|
+
/** Emitted after a physical run releases its lifecycle owner and abort links. */
|
|
222
|
+
runSettledSubject?: Subject<void>;
|
|
209
223
|
createdAt: number;
|
|
210
224
|
updatedAt: number;
|
|
211
225
|
meta?: Record<string, any>;
|
|
@@ -348,6 +362,14 @@ export interface Session {
|
|
|
348
362
|
* field and pass it through as `options.maxTurns` explicitly.
|
|
349
363
|
*/
|
|
350
364
|
lastRunMaxTurns?: number;
|
|
365
|
+
/**
|
|
366
|
+
* Latest agent-loop model call number (`providerData.stepSeq`). Unlike the
|
|
367
|
+
* SDK turn counter it survives runs, compaction and resume; see
|
|
368
|
+
* `allocateModelStepSeq`.
|
|
369
|
+
*/
|
|
370
|
+
modelStepSeq?: number;
|
|
371
|
+
/** Compactions of this Session's context; see `getCompactionLineage`. */
|
|
372
|
+
compactionLineage?: CompactionLineage;
|
|
351
373
|
queue: AgentInputItem[];
|
|
352
374
|
queueSubject: BehaviorSubject<AgentInputItem[]>;
|
|
353
375
|
/**
|
|
@@ -638,6 +660,12 @@ export interface Session {
|
|
|
638
660
|
* Context from UserPromptSubmit hook to be injected into current user message
|
|
639
661
|
*/
|
|
640
662
|
userPromptSubmitContext?: string;
|
|
663
|
+
/**
|
|
664
|
+
* Context from UserPromptExpansion hook (hookSpecificOutput.additionalContext),
|
|
665
|
+
* to be injected alongside the expanded prompt (Claude Code parity: same
|
|
666
|
+
* injection point as UserPromptSubmit — "alongside the submitted prompt").
|
|
667
|
+
*/
|
|
668
|
+
userPromptExpansionContext?: string;
|
|
641
669
|
/**
|
|
642
670
|
* Context from PostToolUse hook to be injected after tool execution
|
|
643
671
|
*/
|
|
@@ -849,7 +877,7 @@ export interface SubagentInvocationRecord {
|
|
|
849
877
|
lifecycle: SubagentLifecycleSnapshot;
|
|
850
878
|
}
|
|
851
879
|
export type SubagentLifecycleDescriptor = Omit<SubagentLifecycleSnapshot, 'status' | 'updatedAt' | 'usage'>;
|
|
852
|
-
export type CombineEvent = (AgentInputItemEvent | ModelRawResponseEvent | ResultEndEvent | InterruptResultEvent | NoticeEvent | SubagentStatusEvent | CompactionLifecycleEvent | TerminalEvent) & CombineEventMeta;
|
|
880
|
+
export type CombineEvent = (AgentInputItemEvent | AgentSdkStreamEvent | ModelRawResponseEvent | ResultEndEvent | InterruptResultEvent | NoticeEvent | SubagentStatusEvent | CompactionLifecycleEvent | TerminalEvent) & CombineEventMeta;
|
|
853
881
|
export interface CompactionLifecycleEvent {
|
|
854
882
|
type: 'compaction';
|
|
855
883
|
data: {
|
|
@@ -864,6 +892,11 @@ export interface SubagentStatusEvent {
|
|
|
864
892
|
type: 'subagent_status';
|
|
865
893
|
data: SubagentLifecycleSnapshot;
|
|
866
894
|
}
|
|
895
|
+
/** Original SDK stream payload, observed by the existing single stream consumer. */
|
|
896
|
+
export interface AgentSdkStreamEvent {
|
|
897
|
+
type: 'sdk';
|
|
898
|
+
data: import('../../../../cbc-shared/lib/node/index.js').RunStreamEvent;
|
|
899
|
+
}
|
|
867
900
|
export interface AgentInputItemEvent {
|
|
868
901
|
type: 'input';
|
|
869
902
|
data: AgentInputItem;
|
|
@@ -915,6 +948,8 @@ export interface SessionOptions {
|
|
|
915
948
|
debugToStderr?: boolean;
|
|
916
949
|
verbose?: boolean;
|
|
917
950
|
print?: boolean;
|
|
951
|
+
/** Host Bash output preference; omitted preserves the CLI's PTY selection. */
|
|
952
|
+
usePty?: boolean;
|
|
918
953
|
outputFormat?: 'text' | 'json' | 'stream-json';
|
|
919
954
|
inputFormat?: 'text' | 'stream-json';
|
|
920
955
|
/** Whether to persist the session transcript. Defaults to true; false keeps history in memory only. */
|
|
@@ -1050,6 +1085,13 @@ export interface SessionRewindMutationOptions {
|
|
|
1050
1085
|
cwd: string;
|
|
1051
1086
|
headMessageId: string | undefined;
|
|
1052
1087
|
}
|
|
1088
|
+
/**
|
|
1089
|
+
* model override 的意图来源:决定该值是否等价于「用户显式选择」。
|
|
1090
|
+
* - 'user':/model 命令、ACP set_model、SDK 控制信号等用户动作;
|
|
1091
|
+
* - 'declared':主 Agent 声明模型(declaredModel)联动写入;
|
|
1092
|
+
* - 'materialized':Web UI 会话装配期钉住的兜底解析值(非用户意图)。
|
|
1093
|
+
*/
|
|
1094
|
+
export type OverrideModelSource = 'user' | 'declared' | 'materialized';
|
|
1053
1095
|
export interface SessionManager {
|
|
1054
1096
|
getCurrent(): Session;
|
|
1055
1097
|
setCurrent(session: Session): void;
|
|
@@ -1123,9 +1165,11 @@ export interface SessionManager {
|
|
|
1123
1165
|
*
|
|
1124
1166
|
* 幂等:未注册的 sessionId 为 no-op。
|
|
1125
1167
|
*
|
|
1126
|
-
* @param
|
|
1168
|
+
* @param target 传 Session 对象时,索引键与身份校验同源——只有注册表当前持有
|
|
1169
|
+
* 的正是这个对象才释放,复用同一 sessionId 的后继对象不会被误清。只拿得到
|
|
1170
|
+
* id 的调用方(RPC、`remove(id)`)传字符串,此时不做身份校验。
|
|
1127
1171
|
*/
|
|
1128
|
-
releaseInMemory(
|
|
1172
|
+
releaseInMemory(target: string | Session): void;
|
|
1129
1173
|
/**
|
|
1130
1174
|
* 该 sessionId 是否已在本进程通过 get() 加载过(且尚未 remove()/releaseInMemory())。
|
|
1131
1175
|
*
|
|
@@ -1150,11 +1194,15 @@ export interface SessionManager {
|
|
|
1150
1194
|
setOverridePermissionMode(sessionId: string, mode: PermissionMode): void;
|
|
1151
1195
|
getOverridePermissionMode(sessionId: string): PermissionMode | undefined;
|
|
1152
1196
|
/**
|
|
1153
|
-
* 设置 session 的 model
|
|
1154
|
-
*
|
|
1197
|
+
* 设置 session 的 model 覆盖值。source 记录意图来源,供「是否用户显式选择」判定:
|
|
1198
|
+
* - 'user'(默认):/model 命令、ACP set_model、SDK 控制信号等用户动作;
|
|
1199
|
+
* - 'declared':主 Agent 声明模型(declaredModel)联动写入;
|
|
1200
|
+
* - 'materialized':Web UI 会话装配期钉住的兜底解析值(非用户意图)。
|
|
1155
1201
|
*/
|
|
1156
|
-
setOverrideModel(sessionId: string, model: string): void;
|
|
1202
|
+
setOverrideModel(sessionId: string, model: string, source?: OverrideModelSource): void;
|
|
1157
1203
|
getOverrideModel(sessionId: string): string | undefined;
|
|
1204
|
+
getOverrideModelSource(sessionId: string): OverrideModelSource | undefined;
|
|
1205
|
+
clearOverrideModel(sessionId: string): void;
|
|
1158
1206
|
/**
|
|
1159
1207
|
* 设置会话运行时模型:同步写 session.options.model + requestOptions.model + override map。
|
|
1160
1208
|
*
|
|
@@ -1163,7 +1211,7 @@ export interface SessionManager {
|
|
|
1163
1211
|
* 供 applyOverrideModel 每轮重建 requestOptions(Issue #82146)。/model 命令与模型面板
|
|
1164
1212
|
* 共用此入口;ACP set_model(applyRuntimeSessionModel)仍为独立实现,待统一收敛。
|
|
1165
1213
|
*/
|
|
1166
|
-
setRuntimeModel(session: Session | undefined, modelId: string): void;
|
|
1214
|
+
setRuntimeModel(session: Session | undefined, modelId: string, source?: OverrideModelSource): void;
|
|
1167
1215
|
/**
|
|
1168
1216
|
* 设置会话运行时 outputStyle:同步写 session.options.outputStyle。
|
|
1169
1217
|
*
|
|
@@ -1216,8 +1264,31 @@ export interface SessionManager {
|
|
|
1216
1264
|
*/
|
|
1217
1265
|
flushHistory(session: Session): Promise<void>;
|
|
1218
1266
|
}
|
|
1267
|
+
/**
|
|
1268
|
+
* Cumulative transcript persistence counters (issue #119545 埋点建议).
|
|
1269
|
+
* A best-effort side channel, so every reader must treat the numbers as a
|
|
1270
|
+
* snapshot that may be sampled at any moment.
|
|
1271
|
+
*/
|
|
1272
|
+
export interface TranscriptPersistenceMetrics {
|
|
1273
|
+
/** In-band retry attempts consumed. */
|
|
1274
|
+
retries: number;
|
|
1275
|
+
/** Batches that only landed because of a retry. */
|
|
1276
|
+
retrySucceeded: number;
|
|
1277
|
+
/** Batches given up on after the retry budget. */
|
|
1278
|
+
abandonedBatches: number;
|
|
1279
|
+
/** Lines lost with those batches. */
|
|
1280
|
+
abandonedLines: number;
|
|
1281
|
+
}
|
|
1219
1282
|
export interface SessionStore {
|
|
1220
1283
|
getSessionFilePath(id: string, parentSessionId?: string, cwd?: string): string;
|
|
1284
|
+
/**
|
|
1285
|
+
* Transcript persistence counters, when the implementation keeps any.
|
|
1286
|
+
* Optional so in-memory and host-delegating stores do not have to fake it.
|
|
1287
|
+
* Exposed so callers that observe a degradation can log the counters from
|
|
1288
|
+
* their own call site: the store's own abandon audit line is best-effort
|
|
1289
|
+
* and a lost line would otherwise take the only copy of the numbers.
|
|
1290
|
+
*/
|
|
1291
|
+
transcriptPersistenceMetrics?(): Readonly<TranscriptPersistenceMetrics>;
|
|
1221
1292
|
get(id: string, options?: SessionGetOptions): Promise<Session | undefined>;
|
|
1222
1293
|
getAcrossProjects(id: string, options?: SessionGetOptions): Promise<Session | undefined>;
|
|
1223
1294
|
save(session: Session, cwd?: string): Promise<void>;
|
|
@@ -1376,6 +1447,26 @@ export interface SessionHookManager {
|
|
|
1376
1447
|
* Does NOT support continueRequest.
|
|
1377
1448
|
*/
|
|
1378
1449
|
executeFinalStopHooks(session: Session, reason?: FinalStopReason): Promise<void>;
|
|
1450
|
+
/**
|
|
1451
|
+
* UserPromptExpansion — Claude Code 官方事件(非 cbc 专属扩展):任何用户输入的
|
|
1452
|
+
* 命令/skill 在展开成 prompt、送进模型之前统一从这里触发,可阻断展开。适用于
|
|
1453
|
+
* skill、自定义命令、Dynamic Workflow、MCP prompt 等一切"输入即展开"的路径,
|
|
1454
|
+
* 不是只服务某一个具体调用方(如统一资产门控)。
|
|
1455
|
+
*/
|
|
1456
|
+
executeUserPromptExpansionHooks(session: Session, payload: {
|
|
1457
|
+
/** Claude Code spec: 'slash_command' for skill/custom commands, 'mcp_prompt' for MCP prompts. */
|
|
1458
|
+
expansionType: 'slash_command' | 'mcp_prompt' | string;
|
|
1459
|
+
commandName: string;
|
|
1460
|
+
/** Claude Code spec: required field (empty string when no args), always sent. */
|
|
1461
|
+
commandArgs: string;
|
|
1462
|
+
/** e.g. Skill.source / Command.scope ('project' | 'user' | 'plugin' | 'mcp' | ...). */
|
|
1463
|
+
commandSource?: string;
|
|
1464
|
+
/** Claude Code spec: required field — raw, pre-expansion prompt text as typed by the user. */
|
|
1465
|
+
prompt: string;
|
|
1466
|
+
}): Promise<{
|
|
1467
|
+
allowed: boolean;
|
|
1468
|
+
message?: string;
|
|
1469
|
+
}>;
|
|
1379
1470
|
}
|
|
1380
1471
|
export interface RunItemProcessor {
|
|
1381
1472
|
process(runItem: RunItem): Promise<void>;
|
|
@@ -1444,6 +1535,7 @@ export interface InterruptionService {
|
|
|
1444
1535
|
approve(item: RunToolApprovalItem, options?: ApprovalOptions): void;
|
|
1445
1536
|
reject(item: RunToolApprovalItem, options?: {
|
|
1446
1537
|
decision?: 'deny' | 'rejectAndExitPlan';
|
|
1538
|
+
cancelTurn?: boolean;
|
|
1447
1539
|
}): void;
|
|
1448
1540
|
waitFor(session: Session): Promise<void>;
|
|
1449
1541
|
/** Resolve the main/leader session for a given session (returns self if already main). */
|
|
@@ -1494,9 +1586,10 @@ export interface InterruptionService {
|
|
|
1494
1586
|
*
|
|
1495
1587
|
* 幂等:session 未注册时为 no-op。只清内存映射,不动磁盘 jsonl。
|
|
1496
1588
|
*
|
|
1497
|
-
* @param
|
|
1589
|
+
* @param target 传 Session 对象时按对象身份校验,同 id 的后继对象不会被误清;
|
|
1590
|
+
* 只拿得到 id 的调用方传字符串,此时不做身份校验。
|
|
1498
1591
|
*/
|
|
1499
|
-
releaseSession(
|
|
1592
|
+
releaseSession(target: string | Session): void;
|
|
1500
1593
|
}
|
|
1501
1594
|
export interface MessageQueueManager {
|
|
1502
1595
|
enqueueMessage(session: Session, message: AgentInputItem): string;
|
|
@@ -1653,6 +1746,12 @@ export interface TurnMetricsReporter {
|
|
|
1653
1746
|
*/
|
|
1654
1747
|
unregister(sessionId: string): void;
|
|
1655
1748
|
}
|
|
1749
|
+
/** Ids of one model call, as stamped by the model wrapper. */
|
|
1750
|
+
export interface ModelCallGeneration {
|
|
1751
|
+
messageId: string;
|
|
1752
|
+
conversationRequestId?: string;
|
|
1753
|
+
stepSeq?: number;
|
|
1754
|
+
}
|
|
1656
1755
|
export interface ModelResponseMetadata {
|
|
1657
1756
|
/** 响应中的模型 ID */
|
|
1658
1757
|
model?: string;
|
|
@@ -1666,6 +1765,8 @@ export interface ModelResponseMetadata {
|
|
|
1666
1765
|
* 都带 providerData.messageId === 此值,handleContentFilteredResponse 据此剔除并替换为安全提示。
|
|
1667
1766
|
*/
|
|
1668
1767
|
contentFilterMessageId?: string;
|
|
1768
|
+
/** Correlation of the generation that just completed, as stamped by the model wrapper. */
|
|
1769
|
+
generation?: ModelCallGeneration;
|
|
1669
1770
|
usage?: {
|
|
1670
1771
|
prompt_tokens: number;
|
|
1671
1772
|
completion_tokens: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Observable } from 'rxjs';
|
|
2
|
-
import type { Session } from './session-protocol.js';
|
|
2
|
+
import type { AgentRetryReason, Session } from './session-protocol.js';
|
|
3
3
|
export declare const SessionRunStateMachine: unique symbol;
|
|
4
4
|
export declare const SessionRunStateProjectionService: unique symbol;
|
|
5
5
|
export declare const SESSION_RUN_STATE_PROJECTION_SCHEMA: 'session-run-state.v1';
|
|
@@ -114,6 +114,7 @@ export type SessionRunEvent = {
|
|
|
114
114
|
} | {
|
|
115
115
|
type: SessionRunEventType.TOOL_STARTED;
|
|
116
116
|
toolName?: string;
|
|
117
|
+
toolCallId?: string;
|
|
117
118
|
reason?: string;
|
|
118
119
|
} | {
|
|
119
120
|
type: SessionRunEventType.TOOL_ENDED;
|
|
@@ -143,6 +144,7 @@ export type SessionRunEvent = {
|
|
|
143
144
|
} | {
|
|
144
145
|
type: SessionRunEventType.RETRYING;
|
|
145
146
|
reason?: string;
|
|
147
|
+
retryReason?: AgentRetryReason;
|
|
146
148
|
} | {
|
|
147
149
|
type: SessionRunEventType.COMPACT_STARTED;
|
|
148
150
|
reason?: string;
|
|
@@ -188,6 +190,18 @@ export interface SessionRunStateMachine {
|
|
|
188
190
|
*/
|
|
189
191
|
getChange$(session: Session, skipFirst?: boolean): Observable<void>;
|
|
190
192
|
}
|
|
193
|
+
export declare const ModelRequestRetryPhase: unique symbol;
|
|
194
|
+
/**
|
|
195
|
+
* 模型请求层(宿主 provider)在同一次请求内部退避重发时,借此把会话投影为 retrying。
|
|
196
|
+
* 状态写入与守卫收口在 core,宿主只包住退避等待,不直接驱动状态机。
|
|
197
|
+
*/
|
|
198
|
+
export interface ModelRequestRetryPhase {
|
|
199
|
+
/**
|
|
200
|
+
* `wait` 期间会话显示 retrying 并携带 `reason`;结束(含抛错 / 取消)后恢复 model_requesting。
|
|
201
|
+
* 非本轮主请求(无 session、辅助型 purpose、状态不在 model_requesting)时只执行 `wait`。
|
|
202
|
+
*/
|
|
203
|
+
during<T>(session: Session | undefined, reason: AgentRetryReason, wait: () => Promise<T>): Promise<T>;
|
|
204
|
+
}
|
|
191
205
|
/**
|
|
192
206
|
* Pure derivations from a `SessionRunStatus`. The state machine implementation
|
|
193
207
|
* MUST keep its instance methods (`getLifecycle`, `isBusy`, etc.) consistent
|
package/cli/dist-server/types/workspace/cbc-core/lib/node/session/session-runtime-lifecycle.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Session } from './session-protocol.js';
|
|
2
|
+
export declare function isSessionRuntimeClosed(session: Session): boolean;
|
|
3
|
+
export declare function closeSessionRuntime(session: Session): void;
|
|
4
|
+
export declare function sessionRuntimeSignal(session: Session): AbortSignal;
|
|
5
|
+
export declare function assertSessionRuntimeOpen(session: Session | undefined): void;
|
|
@@ -2,7 +2,7 @@ import { Logger } from '@celljs/core';
|
|
|
2
2
|
import { type AgentInputItem } from '../../../../cbc-shared/lib/node/index.js';
|
|
3
3
|
import * as fs from 'fs/promises';
|
|
4
4
|
import { LocalJsonlSessionStore } from './local-jsonl-session-store.js';
|
|
5
|
-
import { type Session, SessionFactory, type SessionForkMutationOptions, type SessionGetOptions, type SessionRewindMutationOptions, SessionStore } from './session-protocol.js';
|
|
5
|
+
import { type Session, SessionFactory, type SessionForkMutationOptions, type SessionGetOptions, type SessionRewindMutationOptions, SessionStore, type TranscriptPersistenceMetrics } from './session-protocol.js';
|
|
6
6
|
import type { Lane, LanePointer, SessionKey, SessionStoreEntry } from './session-store-contract.js';
|
|
7
7
|
import { SessionImageStorage as ImageBlobService, SessionRestoreHost, SessionStoragePaths, SessionToolOutputStorage as ToolResultBlobService } from './session-store-host-protocol.js';
|
|
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 {};
|
package/cli/dist-server/types/workspace/cbc-core/lib/node/session/stream-timeout-retry-budget.d.ts
CHANGED
|
@@ -6,9 +6,28 @@ import type { Session } from './session-protocol.js';
|
|
|
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
|
*/
|