@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
|
@@ -3,10 +3,11 @@ import { AuthenticationManager } from '../../../../authentication/lib/common/ind
|
|
|
3
3
|
import { type AbortLinkDisposer, Agent, type AgentInputItem, type NonStreamRunOptions, RunState, type StreamRunOptions } from '../../../../cbc-shared/lib/node/index.js';
|
|
4
4
|
import { type LanguageModel } from '../../../../product/lib/common/index.js';
|
|
5
5
|
import { Logger } from '../../../../telemetry/lib/common/index.js';
|
|
6
|
+
import { type ManualCompactRequestHandler as ManualCompactRequestHandlerContract } from '../context/context-protocol.js';
|
|
6
7
|
import { type FileRollbackOperationLock as FileRollbackOperationLockContract } from '../file-rollback/file-rollback-service-protocol.js';
|
|
7
8
|
import { Session, SessionManager } from '../session/session-protocol.js';
|
|
8
9
|
import { SessionRunStateMachine } from '../session/session-run-state-machine-protocol.js';
|
|
9
|
-
import { type AgentCurrentContinuationOptions, AgentManager, AgentRunInterceptor, AgentRunRequest, AgentService, type AgentStandardRunOptions, RunnerProvider } from './agent-protocol.js';
|
|
10
|
+
import { type AgentCurrentContinuationOptions, AgentManager, AgentRunInterceptor, AgentRunRequest, AgentService, type AgentStandardRunOptions, type OneTimeRunOptions, RunnerProvider } from './agent-protocol.js';
|
|
10
11
|
import { type AgentRunScope as IAgentRunScope } from './agent-run-scope.js';
|
|
11
12
|
import { AgentPluginRefresh, AgentRunObserver, AgentRuntimeResolver } from './agent-runtime-protocol.js';
|
|
12
13
|
export declare class AgentServiceImpl implements AgentService {
|
|
@@ -22,6 +23,7 @@ export declare class AgentServiceImpl implements AgentService {
|
|
|
22
23
|
protected readonly agentRunInterceptorProvider: Provider<AgentRunInterceptor>;
|
|
23
24
|
protected readonly fileRollbackOperationLock?: FileRollbackOperationLockContract;
|
|
24
25
|
protected readonly logger: Logger;
|
|
26
|
+
protected readonly manualCompactRequestHandler?: ManualCompactRequestHandlerContract;
|
|
25
27
|
/**
|
|
26
28
|
* Preserve the pre-start cancellation snapshot across runDefault's agent
|
|
27
29
|
* lookup controller and run()'s own controller. This is process-local
|
|
@@ -38,6 +40,22 @@ export declare class AgentServiceImpl implements AgentService {
|
|
|
38
40
|
*/
|
|
39
41
|
private lifecycleOwners;
|
|
40
42
|
protected getLifecycleOwners(): WeakMap<Session, AbortController>;
|
|
43
|
+
tryCloseTaskSession(session: Session, result: NonNullable<Session['resultSubject']['value']>): Promise<boolean>;
|
|
44
|
+
retireTaskSession(session: Session): Promise<void>;
|
|
45
|
+
waitForRunsSettled(session: Session): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* 有界 join:等到该 session 上的物理 run 全部交还 lifecycle owner 与 in-flight 信号。
|
|
48
|
+
*
|
|
49
|
+
* 为什么需要它而不是直接看 `agent_end`:`finalizeRun` 晚于本轮把最终产出写进
|
|
50
|
+
* history,`agent_end` 却早于 `finalizeRun`。任何依赖「上一轮 history 已写完」这个
|
|
51
|
+
* 因果的调用方(如队列 drain)必须 join 到这里。
|
|
52
|
+
*
|
|
53
|
+
* Bounded: `runSettledSubject` is optional, so a session built without
|
|
54
|
+
* one has nothing to observe and would hang the caller's cleanup — which
|
|
55
|
+
* owns hook, MCP and background-shell teardown. `agent_end` 也可能来自没有物理
|
|
56
|
+
* run 的路径(skipRun / 迟到事件),无界等待会把调用方永久挂住。
|
|
57
|
+
*/
|
|
58
|
+
private joinRunsSettled;
|
|
41
59
|
/** compare-and-delete:仅当 token 仍指向本轮 controller 时清除。 */
|
|
42
60
|
private clearLifecycleOwner;
|
|
43
61
|
/** 本轮是否是当前 lifecycle owner。 */
|
|
@@ -154,6 +172,7 @@ export declare class AgentServiceImpl implements AgentService {
|
|
|
154
172
|
protected resolveRunOneTimeModel(agentName: string, session?: Session): Promise<LanguageModel>;
|
|
155
173
|
run<TAgent extends Agent<any, any>>(agent: TAgent, input: string | AgentInputItem[], options: AgentCurrentContinuationOptions): Promise<void>;
|
|
156
174
|
run<TAgent extends Agent<any, any>, TContext = Session>(agent: TAgent, input: string | AgentInputItem[] | RunState<TContext, TAgent>, options?: AgentStandardRunOptions<TContext>): Promise<void>;
|
|
175
|
+
private runPipeline;
|
|
157
176
|
/**
|
|
158
177
|
* #59319-stream: 抽取的 physical run cleanup 逻辑。
|
|
159
178
|
* 非 stream 路径由 run() finally 同步调用;
|
|
@@ -187,8 +206,14 @@ export declare class AgentServiceImpl implements AgentService {
|
|
|
187
206
|
private prepareRunAdmission;
|
|
188
207
|
runDefault<TAgent extends Agent<any, any>>(input: string | AgentInputItem[], options: AgentCurrentContinuationOptions): Promise<void>;
|
|
189
208
|
runDefault<TAgent extends Agent<any, any>, TContext = Session>(input: string | AgentInputItem[] | RunState<TContext, TAgent>, options?: AgentStandardRunOptions<TContext>): Promise<void>;
|
|
190
|
-
|
|
191
|
-
|
|
209
|
+
/**
|
|
210
|
+
* Streams the text of a one-shot run on `session`. A reused caller Session is shared
|
|
211
|
+
* with its in-flight main run, so the call's purpose and request id live in its async
|
|
212
|
+
* scope instead of on the Session.
|
|
213
|
+
*/
|
|
214
|
+
private streamOneTimeText;
|
|
215
|
+
runOneTime<TContext = Session>(agentName: string, input: string | AgentInputItem[], options?: NonStreamRunOptions<TContext> & OneTimeRunOptions): Promise<string>;
|
|
216
|
+
runOneTime<TContext = Session>(agentName: string, input: string | AgentInputItem[], options?: StreamRunOptions<TContext> & OneTimeRunOptions): Promise<string>;
|
|
192
217
|
/**
|
|
193
218
|
* Enhanced version of runOneTime that supports per-request overrides
|
|
194
219
|
* for temperature, maxTokens, maxTurns, systemPrompt, and bypassPermissions.
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
export * from './agent-protocol.js';
|
|
2
2
|
export * from './agent-purpose-protocol.js';
|
|
3
|
+
export * from './agent-purpose-scope.js';
|
|
4
|
+
export * from './model-step-sequence.js';
|
|
5
|
+
export * from './model-call-failure.js';
|
|
3
6
|
export * from './agent-runtime-protocol.js';
|
|
4
7
|
export * from './agent-run-scope.js';
|
|
5
8
|
export * from './agent-service.js';
|
|
6
9
|
export * from './agent-factory.js';
|
|
7
10
|
export * from './runner-factory.js';
|
|
8
11
|
export * from './runner-provider.js';
|
|
12
|
+
export * from './speaker-label.js';
|
|
9
13
|
export * from './ordered-tools-agent.js';
|
|
10
14
|
export * from './tool-call-loop-detector-protocol.js';
|
|
11
15
|
export * from './tool-call-loop-detector-service.js';
|
package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/interceptors/input-interceptors.d.ts
CHANGED
|
@@ -17,12 +17,7 @@ export declare class MessageQueueAgentRunInterceptor implements AgentRunIntercep
|
|
|
17
17
|
protected readonly logger: Logger;
|
|
18
18
|
protected readonly stateMachine: SessionRunStateMachine;
|
|
19
19
|
intercept(request: AgentRunRequest): Promise<void>;
|
|
20
|
-
|
|
21
|
-
* 触发后不再重复打 error(防日志风暴);下次"有实际工作"分支复位 counter/flag,
|
|
22
|
-
* session 自动恢复处理能力。
|
|
23
|
-
*/
|
|
24
|
-
private trackEmptyDrainAndMaybeTripGuard;
|
|
25
|
-
private resetEmptyDrainLoopGuard;
|
|
20
|
+
private consumeQueueItems;
|
|
26
21
|
}
|
|
27
22
|
/**
|
|
28
23
|
* 用户查询包裹拦截器
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ModelCallGeneration } from '../session/session-protocol.js';
|
|
2
|
+
/**
|
|
3
|
+
* Marks `error` as the failure of one model call. The call's ids live in the model-call
|
|
4
|
+
* async scope, which does not reach the consumer of the SDK run stream; the error does.
|
|
5
|
+
* An error rethrown through an outer call keeps the innermost call's mark.
|
|
6
|
+
*/
|
|
7
|
+
export declare function markModelCallFailure<T>(error: T, sessionId: string, generation: ModelCallGeneration): T;
|
|
8
|
+
/** The model call of this Session that failed with `error`; undefined when the failure is not one. */
|
|
9
|
+
export declare function getFailedModelCall(error: unknown, sessionId: string): ModelCallGeneration | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Session } from '../session/session-protocol.js';
|
|
2
|
+
type StepSequenceSession = Pick<Session, 'id' | 'history' | 'agentPurpose' | 'modelStepSeq'>;
|
|
3
|
+
/** Latest step of the Session's agent loop, restored from persisted history after resume. */
|
|
4
|
+
export declare function currentModelStepSeq(session: StepSequenceSession): number;
|
|
5
|
+
/**
|
|
6
|
+
* Step number for the model call in the current async chain. Agent-loop calls
|
|
7
|
+
* advance the counter; auxiliary calls reuse the latest step. The counter never
|
|
8
|
+
* resets across runs, compaction continuations or teammate wake-ups.
|
|
9
|
+
*/
|
|
10
|
+
export declare function allocateModelStepSeq(session: StepSequenceSession): number;
|
|
11
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type RunConfig, Runner } from '../../../../cbc-shared/lib/node/index.js';
|
|
1
|
+
import { type AgentInputItem, type RunConfig, Runner } from '../../../../cbc-shared/lib/node/index.js';
|
|
2
2
|
import { ProductManager } from '../../../../product/lib/common/index.js';
|
|
3
3
|
import { Logger } from '../../../../telemetry/lib/common/index.js';
|
|
4
4
|
import { type NotificationInjectionBuffer as INotificationInjectionBuffer } from '../message-queue/notification-injection-buffer-protocol.js';
|
|
@@ -15,6 +15,15 @@ import { ToolCallLoopDetector } from './tool-call-loop-detector-protocol.js';
|
|
|
15
15
|
* Used by finishReasonErrorInterceptor to detect prior retries across both mechanisms.
|
|
16
16
|
*/
|
|
17
17
|
export declare const TRUNCATION_RETRY_MARKER = "Do NOT repeat the same oversized tool call. Break it into smaller operations.";
|
|
18
|
+
export interface ModelInputMemoryPressure {
|
|
19
|
+
heapUsed: number;
|
|
20
|
+
heapLimit: number;
|
|
21
|
+
headroom: number;
|
|
22
|
+
inputItems: number;
|
|
23
|
+
estimatedInputBytes?: number;
|
|
24
|
+
reject: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare function assessModelInputMemoryPressure(input: AgentInputItem[], heapUsed?: number, heapLimit?: number): ModelInputMemoryPressure;
|
|
18
27
|
/**
|
|
19
28
|
* Tool-specific hints for how to decompose a truncated tool call into smaller operations.
|
|
20
29
|
*/
|
|
@@ -72,6 +81,7 @@ export declare class RunnerFactoryImpl implements RunnerFactory {
|
|
|
72
81
|
*/
|
|
73
82
|
protected readonly acpBroadcastService?: AgentQueueOutput;
|
|
74
83
|
create(config?: Partial<RunConfig>): Promise<Runner>;
|
|
84
|
+
private assertModelInputCloneHeadroom;
|
|
75
85
|
/**
|
|
76
86
|
* 在每次模型请求前检查是否需要自动压缩。
|
|
77
87
|
* 此时所有工具都已执行完毕,可以安全地触发压缩。
|
|
@@ -80,10 +90,10 @@ export declare class RunnerFactoryImpl implements RunnerFactory {
|
|
|
80
90
|
/**
|
|
81
91
|
* Mode B:把「立即发送」队列项注入正在运行的 turn(#73022)。
|
|
82
92
|
*
|
|
83
|
-
* 调用点在 `callModelInputFilter`(见 `create()
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
93
|
+
* 调用点在 `callModelInputFilter`(见 `create()`),即**每次模型请求之前**。
|
|
94
|
+
* rich message / notification / drain prompt 仍在这里注入请求副本;真实 steer
|
|
95
|
+
* 由 `continuationInputProvider` 在 `prepareTurn` 前写入 SDK RunState,避免后续
|
|
96
|
+
* 工具 step 从权威状态重建请求时丢失。
|
|
87
97
|
*
|
|
88
98
|
* 注入内容已经进入本次模型请求,无需再为“曾经注入过”强制续圈。只有模型响应期间
|
|
89
99
|
* 新到达、尚未被取出的消息,才由 `__codebuddySteerPending` 在收尾时实时判定是否
|
|
@@ -101,6 +111,22 @@ export declare class RunnerFactoryImpl implements RunnerFactory {
|
|
|
101
111
|
* `create()` 注释)。payload 与授权同为调用局部值,天然不跨 run 共享。
|
|
102
112
|
*/
|
|
103
113
|
private injectSendNowItems;
|
|
114
|
+
/**
|
|
115
|
+
* Drain steer only at the SDK continuation boundary, before it prepares the next model step.
|
|
116
|
+
*
|
|
117
|
+
* The returned model items are installed by the SDK into RunState.generatedItems before
|
|
118
|
+
* `prepareTurn`. This makes steer authoritative input for every later tool/model step instead
|
|
119
|
+
* of an ephemeral `callModelInputFilter` addition. The visible history stays the bare user
|
|
120
|
+
* message; it is admitted exactly once, by the stream consumer, in RunState order.
|
|
121
|
+
*/
|
|
122
|
+
private takeSteerContinuationInput;
|
|
123
|
+
/**
|
|
124
|
+
* Visible-history + ACP admission of one drained steer group.
|
|
125
|
+
*
|
|
126
|
+
* Ordering is the caller's responsibility (continuation-history-queue.ts); this only performs
|
|
127
|
+
* the writes and must never throw back into the run.
|
|
128
|
+
*/
|
|
129
|
+
private admitSteerToVisibleHistory;
|
|
104
130
|
/**
|
|
105
131
|
* #100404:落定来源一(rich queue sendNow)的消费。
|
|
106
132
|
*
|
|
@@ -129,11 +155,11 @@ export declare class RunnerFactoryImpl implements RunnerFactory {
|
|
|
129
155
|
* (`session/session-manager.ts` 的 `MODEL_STREAM_STARTED`),涉及跨模块反向布线与
|
|
130
156
|
* 事件类型白名单依赖,另开 issue 跟进。
|
|
131
157
|
*
|
|
132
|
-
* **落史顺序反转(显式接受)**:`modelData.input` 的 push 顺序是来源一 →
|
|
133
|
-
* 但来源一的 `addHistory`
|
|
134
|
-
* 就地 addHistory。同一 model step 同时命中多个来源时,history
|
|
135
|
-
* steer
|
|
136
|
-
*
|
|
158
|
+
* **落史顺序反转(显式接受)**:`modelData.input` 的 filter push 顺序是来源一 → 三 → 四,
|
|
159
|
+
* 但来源一的 `addHistory` 推迟到本方法内执行,来源三/四仍在 `injectSendNowItems` 里
|
|
160
|
+
* 就地 addHistory。同一 model step 同时命中多个来源时,history 里队员消息会排在通知
|
|
161
|
+
* 之后,与模型当时看到的输入顺序相反。steer 已在更早的 SDK continuation 边界同时进入
|
|
162
|
+
* RunState 与可见历史,不参与这段反转。下游按 role/type 消费、不依赖交错位置,故接受。
|
|
137
163
|
*
|
|
138
164
|
* at-most-once 由**作用域**保证,不再依赖「commit 前清暂存」这类补偿动作:`pending` 是
|
|
139
165
|
* 单次 `callModelInputFilter` 调用的局部值,每次调用最多把它 commit 一次,也不可能被
|
|
@@ -211,10 +237,10 @@ export declare class RunnerFactoryImpl implements RunnerFactory {
|
|
|
211
237
|
* model / agent / argumentsDisplayText 等键同样会跟着走,它们是惰性字段、上游不解读,
|
|
212
238
|
* 这里不做处理;真正需要清掉的只有语义已经反转的 discard。
|
|
213
239
|
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
240
|
+
* 返回一个浅复制的新 item;providerData 仅在需要删除 discard 时 copy-on-write。
|
|
241
|
+
* session.history 与 SDK 传入的原 item 始终保持不变。
|
|
216
242
|
*/
|
|
217
|
-
private
|
|
243
|
+
private withRewrittenCallArguments;
|
|
218
244
|
/**
|
|
219
245
|
* SDK callModelInputFilter: called before every model API request within the SDK run loop.
|
|
220
246
|
*
|
|
@@ -240,13 +266,23 @@ export declare class RunnerFactoryImpl implements RunnerFactory {
|
|
|
240
266
|
* message instructing the model to break the call into smaller operations. This
|
|
241
267
|
* turns the SDK's automatic retry into a valid, useful request.
|
|
242
268
|
*
|
|
243
|
-
* Scope of the rewrite:
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
* we redo the same rewrite on every subsequent turn.
|
|
248
|
-
*
|
|
249
|
-
|
|
269
|
+
* Scope of the rewrite: this filter opts into the SDK's `preserveInputIdentity` mode,
|
|
270
|
+
* so existing history items arrive by identity and MUST remain immutable. Repairs use
|
|
271
|
+
* item-level copy-on-write and array-level shallow copies; the SDK still creates isolated
|
|
272
|
+
* model/session copies after the filter returns. `session.history` therefore keeps the
|
|
273
|
+
* malformed arguments and we redo the same rewrite on every subsequent turn. Anything
|
|
274
|
+
* reported from this path must be aggregated per turn rather than logged per call.
|
|
275
|
+
*/
|
|
276
|
+
/**
|
|
277
|
+
* 模型输入的两步修复,**顺序不能反**:
|
|
278
|
+
*
|
|
279
|
+
* 1. `filterTruncatedToolCalls` 先跑。截断(finish_reason=length)与坏 JSON 的
|
|
280
|
+
* call 正是「参数半截 + 没有任何 result」那一类;它删掉这些 call 的同时会注入
|
|
281
|
+
* 拆解引导与防循环停止标记。若先按配对摘掉它们,该分支因 `invalidCallIds` 为空
|
|
282
|
+
* 直接早退,模型拿不到任何引导,退回 #75892 那条老路,而且请求本身合法、无错可见。
|
|
283
|
+
* 2. `filterUnpairedToolCalls` 后跑,收掉剩下的孤儿(参数合法但结果丢失、重复 callId、
|
|
284
|
+
* 头部被截断留下的孤儿结果)。本地正文里的孤儿是持久化的,留着每次恢复都被上游 400。
|
|
250
285
|
*/
|
|
286
|
+
private repairModelInput;
|
|
251
287
|
private filterTruncatedToolCalls;
|
|
252
288
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export declare function resolveMessageSpeakerLabel(input: {
|
|
2
|
+
session?: {
|
|
3
|
+
id?: string;
|
|
4
|
+
storeId?: string;
|
|
5
|
+
meta?: Record<string, unknown>;
|
|
6
|
+
} | undefined;
|
|
7
|
+
runAgentName?: string;
|
|
8
|
+
}): string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* 子会话的**展示名**(给人看):团队成员用成员名,其余子代理用自身预设名(`meta.agentName`);
|
|
11
|
+
* 主会话 / 无会话 / 无身份线索返回 undefined。**只用于展示与遥测标签,不要拿它查表。**
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveSubAgentDisplayName(session: {
|
|
14
|
+
id?: string;
|
|
15
|
+
storeId?: string;
|
|
16
|
+
meta?: Record<string, unknown>;
|
|
17
|
+
} | undefined): string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* 子会话的**查表键**(REPL 沙箱白名单 / overlay 缓存用):只认「预设名」这一种语义。
|
|
20
|
+
*
|
|
21
|
+
* 与展示名刻意分开(评审):团队成员会把自己的成员名写进 `meta.agentName`(teammate-runner),
|
|
22
|
+
* 于是 `meta.agentName` 同时承载「预设名」与「成员名」两种含义 —— 拿成员名去查 agent 配置查不到,
|
|
23
|
+
* 只能落到默认 agent 的兜底(既不是成员自己的白名单、也不是「不过滤」)。取不到可信的预设名时
|
|
24
|
+
* 返回 undefined = 不额外收窄(与改动前一致),不去猜。
|
|
25
|
+
*/
|
|
26
|
+
export declare function resolveSubAgentAgentKey(session: {
|
|
27
|
+
id?: string;
|
|
28
|
+
storeId?: string;
|
|
29
|
+
meta?: Record<string, unknown>;
|
|
30
|
+
} | undefined): string | undefined;
|
|
31
|
+
/** 展示名的**派发侧镜像**:子会话还没建时拿不到 `meta.teamContext`,但这对值就是稍后写进 session 的同一对。 */
|
|
32
|
+
export declare function resolveSubAgentDisplayNameFromParts(input: {
|
|
33
|
+
memberName?: string;
|
|
34
|
+
presetName?: string;
|
|
35
|
+
}): string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* 查表键的**派发侧镜像**(AgentManager.sandboxScopedAgentView 传身份用):
|
|
38
|
+
* 预设名与成员名**同值**(团队成员把自己的名字写进 meta.agentName)时判为「没有可信预设名」→ undefined,
|
|
39
|
+
* 与运行期 `resolveSubAgentAgentKey` 同源 —— 否则派发侧按成员名收窄、执行侧判不到,两边分叉。
|
|
40
|
+
*/
|
|
41
|
+
export declare function resolveSubAgentAgentKeyFromParts(input: {
|
|
42
|
+
memberName?: string;
|
|
43
|
+
presetName?: string;
|
|
44
|
+
}): string | undefined;
|
package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/tool-call-loop-detector-service.d.ts
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* wastes tokens/credits.
|
|
7
7
|
*
|
|
8
8
|
* Detection rules:
|
|
9
|
-
* 1. Generic loop: blacklisted tool with identical arguments 4 consecutive times
|
|
9
|
+
* 1. Generic loop: blacklisted tool with semantically identical JSON arguments 4 consecutive times
|
|
10
10
|
* 2. Read file loop: Read tool targeting the same file_path 40 consecutive times
|
|
11
|
-
* 3. Non-blacklist loop: any tool NOT in blacklist with identical arguments 40 consecutive times
|
|
11
|
+
* 3. Non-blacklist loop: any tool NOT in blacklist with semantically identical JSON arguments 40 consecutive times
|
|
12
12
|
*/
|
|
13
13
|
import type { AgentInputItem } from '../../../../cbc-shared/lib/node/index.js';
|
|
14
14
|
import { Logger } from '../../../../telemetry/lib/common/index.js';
|
|
@@ -38,14 +38,15 @@ export declare class ToolCallLoopDetectorImpl implements ToolCallLoopDetector {
|
|
|
38
38
|
arguments: string;
|
|
39
39
|
}>;
|
|
40
40
|
/**
|
|
41
|
-
* Check for generic loop: same tool with identical arguments
|
|
41
|
+
* Check for generic loop: same tool with semantically identical JSON arguments
|
|
42
|
+
* N consecutive times. Malformed or very large argument payloads retain exact-string semantics.
|
|
42
43
|
*/
|
|
43
44
|
protected checkGenericLoop(tailCalls: Array<{
|
|
44
45
|
name: string;
|
|
45
46
|
arguments: string;
|
|
46
47
|
}>): LoopDetectionResult;
|
|
47
48
|
/**
|
|
48
|
-
* Check for non-blacklist tool loop: any tool NOT in the blacklist with identical arguments
|
|
49
|
+
* Check for non-blacklist tool loop: any tool NOT in the blacklist with semantically identical JSON arguments
|
|
49
50
|
* called N consecutive times (threshold: NON_BLACKLIST_LOOP_THRESHOLD).
|
|
50
51
|
* Scans from the tail of input, collecting only non-blacklist function_call items.
|
|
51
52
|
*/
|
package/cli/dist-server/types/workspace/cbc-core/lib/node/agent/tool-call-loop-guard-protocol.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare const TOOL_CALL_LOOP_STOPPED_MESSAGE = "Request aborted: user sto
|
|
|
27
27
|
* - `ToolCallLoopDetector` 在**模型请求前**拦截,静默向模型注入停止消息,用户无感;
|
|
28
28
|
* 它覆盖的是旧的三条规则(黑名单同参 4 次 / Read 同文件 40 次 / 非黑名单同参 40 次)。
|
|
29
29
|
* - `ToolCallLoopGuard` 在**工具执行前**拦截,弹窗让用户自己决定继续还是停止;
|
|
30
|
-
* 它覆盖新增的两条规则(同工具连续 40 次 / 周期序列重复 10 轮)。
|
|
30
|
+
* 它覆盖新增的两条规则(同工具连续 40 次,Bash 与 Write 单独放到 80 次 / 周期序列重复 10 轮)。
|
|
31
31
|
*
|
|
32
32
|
* 两者刻意并存:旧规则的静默语义已被线上验证,不因新能力回归。
|
|
33
33
|
*/
|
|
@@ -5,8 +5,13 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { ToolCallLoopTriggerType } from '../../../../telemetry/lib/common/event/types/craft.js';
|
|
7
7
|
export interface ToolCallLoopThresholds {
|
|
8
|
-
/** 同一工具连续调用达到该次数即判定为循环。 */
|
|
8
|
+
/** 同一工具连续调用达到该次数即判定为循环。Bash / Write 走单独阈值。 */
|
|
9
9
|
consecutiveThreshold: number;
|
|
10
|
+
/**
|
|
11
|
+
* Bash 与 Write 连续调用的单独阈值。长任务里模型会连续跑很多条命令、
|
|
12
|
+
* 或连续落很多个文件,只看工具名时 40 次容易把正常推进误判成循环。
|
|
13
|
+
*/
|
|
14
|
+
bashConsecutiveThreshold: number;
|
|
10
15
|
/** AAB 块需要连续重复的轮数。 */
|
|
11
16
|
sequenceRepeats: number;
|
|
12
17
|
}
|
|
@@ -17,6 +22,9 @@ export interface ToolCallLoopHit {
|
|
|
17
22
|
/** 重复序列的周期长度;AAB 恒为 3,连续同工具恒为 1。 */
|
|
18
23
|
patternLength: number;
|
|
19
24
|
}
|
|
25
|
+
/** 与 `ToolNames.BASH` / `ToolNames.WRITE` 对齐。模式识别层不依赖 agent-protocol,避免把工具名枚举拉进来。 */
|
|
26
|
+
export declare const BASH_LOOP_TOOL_NAME = "Bash";
|
|
27
|
+
export declare const WRITE_LOOP_TOOL_NAME = "Write";
|
|
20
28
|
export declare const DEFAULT_TOOL_CALL_LOOP_THRESHOLDS: ToolCallLoopThresholds;
|
|
21
29
|
/** AAB 块的长度。多工具循环只识别这一种形状,因此是常量而非可配阈值。 */
|
|
22
30
|
export declare const AAB_PERIOD = 3;
|
|
@@ -36,7 +44,7 @@ export declare class ToolCallLoopTracker {
|
|
|
36
44
|
* 记录一次即将执行的工具调用,返回本次是否命中循环。
|
|
37
45
|
*
|
|
38
46
|
* 命中优先级:先判连续同工具,再判 AAB 重复。两条规则的阈值默认不重叠
|
|
39
|
-
*
|
|
47
|
+
* (普通工具 40 次、Bash / Write 80 次 vs AAB 重复 10 轮),实践中不会互相抢占。
|
|
40
48
|
*/
|
|
41
49
|
record(toolName: string): ToolCallLoopHit | undefined;
|
|
42
50
|
/**
|
|
@@ -52,14 +60,18 @@ export declare class ToolCallLoopTracker {
|
|
|
52
60
|
* - `ABC`(三者互不相同)通常是正常的多步工作流(读文件 → 改文件 → 跑测试,
|
|
53
61
|
* 然后换下一个文件),按周期重复判它循环误伤面太大;
|
|
54
62
|
* - `ABAB` 这类两工具交替同样不判,避免把翻页 / 分批处理误当循环;
|
|
55
|
-
* - `AAA…` 属于连续同工具,由 consecutiveThreshold
|
|
63
|
+
* - `AAA…` 属于连续同工具,由 consecutiveThreshold / bashConsecutiveThreshold(Bash、Write)那条规则负责。
|
|
56
64
|
*
|
|
57
65
|
* `X ≠ Y` 顺带保证了 AAB 一定是本原周期(唯一可能的更短整除周期是 1,
|
|
58
66
|
* 那要求三个元素全等),所以不需要额外的本原性校验。
|
|
59
67
|
*/
|
|
60
68
|
export declare function matchesRepeatedAabSequence(history: readonly string[], repeats: number): boolean;
|
|
61
69
|
/**
|
|
62
|
-
*
|
|
70
|
+
* 读取阈值配置。环境变量只用于 QA 快速复现,生产不设置即走默认值。
|
|
63
71
|
* AAB 的周期是形状定义的一部分,不开放配置。
|
|
72
|
+
*
|
|
73
|
+
* `CBC_LOOP_GUARD_CONSECUTIVE_THRESHOLD` 只覆盖非 Bash / Write 工具。Bash 与 Write
|
|
74
|
+
* 共用 `CBC_LOOP_GUARD_BASH_CONSECUTIVE_THRESHOLD`,避免 QA 把通用阈值压低时
|
|
75
|
+
* 把长任务放宽一并关掉。
|
|
64
76
|
*/
|
|
65
77
|
export declare function resolveToolCallLoopThresholds(env?: NodeJS.ProcessEnv): ToolCallLoopThresholds;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CompactionKind, CompactionTrigger } from '../../../../telemetry/lib/common/index.js';
|
|
2
|
+
import type { Session } from '../session/session-protocol.js';
|
|
3
|
+
export type { CompactionKind, CompactionTrigger };
|
|
4
|
+
export declare function compactionKindOf(trigger: CompactionTrigger): CompactionKind;
|
|
5
|
+
/** Compactions of a Session's context. Never resets, like `modelStepSeq`. */
|
|
6
|
+
export interface CompactionLineage {
|
|
7
|
+
/** Completed compactions. */
|
|
8
|
+
count: number;
|
|
9
|
+
/** Compaction the current context starts from. */
|
|
10
|
+
lastId?: string;
|
|
11
|
+
/** Trigger of the completed compaction the next agent-loop model call reports. */
|
|
12
|
+
pending?: CompactionTrigger;
|
|
13
|
+
}
|
|
14
|
+
type LineageSession = Pick<Session, 'id' | 'history' | 'compactionLineage' | 'meta'>;
|
|
15
|
+
/** Compaction lineage of `session`, restored from its history after resume. */
|
|
16
|
+
export declare function getCompactionLineage(session: LineageSession): CompactionLineage;
|
|
17
|
+
/**
|
|
18
|
+
* Numbers a compaction boundary item before it enters history and stamps the running
|
|
19
|
+
* compaction onto it; the next agent-loop model call reports it.
|
|
20
|
+
*/
|
|
21
|
+
export declare function recordCompactionBoundary(session: LineageSession, providerData: Record<string, unknown>): void;
|
|
22
|
+
/** Compaction lineage of one model call (gateway headers, `chat_message_send`). */
|
|
23
|
+
export interface ModelCallCompaction {
|
|
24
|
+
/** Completed compactions of the Session when the call is sent. */
|
|
25
|
+
readonly count: number;
|
|
26
|
+
/** Compaction the call's context starts from. */
|
|
27
|
+
readonly id?: string;
|
|
28
|
+
/** Compaction calls: class of the running compaction (`X-Compaction`). */
|
|
29
|
+
readonly kind?: CompactionKind;
|
|
30
|
+
/** First agent-loop call after a compaction: its class (`X-Context-Compacted`) and trigger. */
|
|
31
|
+
readonly contextCompacted?: CompactionKind;
|
|
32
|
+
readonly trigger?: CompactionTrigger;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Compaction lineage for the model call in the current async chain. Only the first
|
|
36
|
+
* agent-loop call after a compaction reports it, like Claude Code's
|
|
37
|
+
* `consumePendingContextCompacted`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function resolveModelCallCompaction(session: LineageSession & Pick<Session, 'agentPurpose' | 'conversationRequestId'>): ModelCallCompaction;
|
package/cli/dist-server/types/workspace/cbc-core/lib/node/context/context-compact-summarizer.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { CompactStrategy, type ContextCompactResult, ContextCompactSummarizeOpti
|
|
|
16
16
|
* 不包含任何具体的压缩逻辑实现。
|
|
17
17
|
*/
|
|
18
18
|
export declare class ContextCompactSummarizerImpl implements ContextCompactSummarizer {
|
|
19
|
+
private activeCompactions?;
|
|
19
20
|
protected readonly productManager: ProductManager;
|
|
20
21
|
protected readonly agentManager: AgentManager;
|
|
21
22
|
protected readonly logger: Logger;
|
|
@@ -25,6 +26,7 @@ export declare class ContextCompactSummarizerImpl implements ContextCompactSumma
|
|
|
25
26
|
protected readonly strategyProvider: Provider<CompactStrategy>;
|
|
26
27
|
compactAndSummarize(session: Session, options?: ContextCompactSummarizeOptions): Promise<boolean>;
|
|
27
28
|
compactWithResult(session: Session, options?: ContextCompactSummarizeOptions): Promise<ContextCompactResult>;
|
|
29
|
+
private compactWithResultOwned;
|
|
28
30
|
/**
|
|
29
31
|
* 按优先级匹配(PreMessage → MaxToken),跳过 Blocking(仅作最终兜底),执行第一个命中的策略;
|
|
30
32
|
* 都不命中则安全网回落到 Blocking。逻辑与压缩 span 化之前完全一致,只是把散落的 `return` 收敛成
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import type { AgentInputItem } from '../../../../cbc-shared/lib/node/index.js';
|
|
2
|
+
import type { CompactionTrigger } from '../../../../telemetry/lib/common/index.js';
|
|
1
3
|
import { Session } from '../session/session-protocol.js';
|
|
2
4
|
export declare const PromptContextProvider: unique symbol;
|
|
3
5
|
export declare const PromptContextInitializer: unique symbol;
|
|
4
6
|
export declare const ContextCompactSummarizer: unique symbol;
|
|
7
|
+
export declare const ManualCompactRequestHandler: unique symbol;
|
|
5
8
|
export declare const PromptRenderer: unique symbol;
|
|
6
9
|
export declare const COMPACT_PROMPT = "compact-prompt";
|
|
7
10
|
export declare const DEFAULT_TOKEN_THRESHOLD = 0.7;
|
|
@@ -190,6 +193,8 @@ export interface ContextCompactSummarizeOptions {
|
|
|
190
193
|
type?: CompactType;
|
|
191
194
|
/** Stable identity shared by live updates and the durable compact boundary. */
|
|
192
195
|
compactionId?: string;
|
|
196
|
+
/** Why this compaction runs; defaults from `type` (manual / pre_message_threshold / emergency_threshold). */
|
|
197
|
+
trigger?: CompactionTrigger;
|
|
193
198
|
}
|
|
194
199
|
export type ContextCompactSkipReason = 'already_compacting' | 'pending_interruption' | 'auto_disabled' | 'empty_history' | 'already_compacted' | 'non_default_agent' | 'below_threshold';
|
|
195
200
|
export type ContextCompactFailureReason = 'strategy_failed' | 'strategy_unavailable';
|
|
@@ -214,6 +219,8 @@ export declare function createCompactionId(): string;
|
|
|
214
219
|
export declare const SESSION_META_COMPACT_TYPE: 'compactType';
|
|
215
220
|
/** Current stable compaction identity, persisted onto the boundary item. */
|
|
216
221
|
export declare const SESSION_META_COMPACTION_ID: 'compactionId';
|
|
222
|
+
/** Trigger of the compaction the summarizer is running; unset for a typed `/compact`. */
|
|
223
|
+
export declare const SESSION_META_COMPACTION_TRIGGER: 'compactionTrigger';
|
|
217
224
|
/**
|
|
218
225
|
* session.meta 上标记当前 compact 成功后会继续执行一次真实 agent run。
|
|
219
226
|
*
|
|
@@ -321,6 +328,16 @@ export interface ContextCompactSummarizer {
|
|
|
321
328
|
/** Compatibility wrapper for existing automatic-compaction callers. */
|
|
322
329
|
compactAndSummarize(session: Session, options?: ContextCompactSummarizeOptions): Promise<boolean>;
|
|
323
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* Host-owned boundary for external `/compact` requests.
|
|
333
|
+
*
|
|
334
|
+
* AgentService invokes this before creating a normal run lifecycle when an
|
|
335
|
+
* interactive host opts in. Implementations must return false for internal compact
|
|
336
|
+
* inputs so strategy-owned internal runs cannot recursively re-enter this boundary.
|
|
337
|
+
*/
|
|
338
|
+
export interface ManualCompactRequestHandler {
|
|
339
|
+
tryHandle(input: string | AgentInputItem[], session: Session): Promise<boolean>;
|
|
340
|
+
}
|
|
324
341
|
export interface PromptRenderer {
|
|
325
342
|
render(template: string, context?: PromptContext): Promise<string>;
|
|
326
343
|
}
|
package/cli/dist-server/types/workspace/cbc-core/lib/node/context/pre-message-compact-strategy.d.ts
CHANGED
|
@@ -4,8 +4,7 @@ import { CompactStrategyContext, ContextCompactSummarizeOptions } from './contex
|
|
|
4
4
|
/**
|
|
5
5
|
* PreMessage 压缩策略:在发送用户消息前触发。
|
|
6
6
|
*
|
|
7
|
-
* 触发条件:PRE_MESSAGE_AUTO 或 WorkBuddy
|
|
8
|
-
* CBC 手动 /compact 不走该策略,继续由 compact agent 路径处理。
|
|
7
|
+
* 触发条件:PRE_MESSAGE_AUTO 或 USER_COMMAND(WorkBuddy / TUI 手动压缩)。
|
|
9
8
|
*
|
|
10
9
|
* 流程:
|
|
11
10
|
* 1. Engineering compact (no LLM call)
|
|
@@ -1,31 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent-trigger payload helper, shared by SessionHookManager and ToolHookManager.
|
|
3
|
-
*
|
|
4
|
-
* Mirrors Claude Code's `createBaseHookInput` (utils/hooks.ts) so that every
|
|
5
|
-
* hook event carries enough context for users to branch on
|
|
6
|
-
* "main thread vs sub-agent" inside their Settings-level hooks.
|
|
7
|
-
*
|
|
8
|
-
* Rules (CC parity):
|
|
9
|
-
* - `agent_type` is the agent's display name; populated from `session.agentName`
|
|
10
|
-
* when set. On the main thread this is the `--agent` flag (when used) or the
|
|
11
|
-
* default agent name. Inside a sub-agent this is the sub-agent's `name`
|
|
12
|
-
* (e.g. "Explore", "Plan", "general-purpose").
|
|
13
|
-
* - `agent_id` is only meaningful inside a sub-agent run — CC leaves it
|
|
14
|
-
* `undefined` on the main thread. We honour the same convention by only
|
|
15
|
-
* emitting it when `session.storeId` is present (sub-agent sessions get a
|
|
16
|
-
* `agent-{8}` storeId; main sessions do not).
|
|
17
|
-
*
|
|
18
|
-
* Kept dependency-free so it can be imported from anywhere — including modules
|
|
19
|
-
* that must avoid pulling the full `../session` barrel (which transitively
|
|
20
|
-
* loads SessionManager / tips and triggers IoC initialisation).
|
|
21
|
-
*/
|
|
22
1
|
export interface AgentTriggerLike {
|
|
23
2
|
id?: string;
|
|
24
3
|
agentName?: string;
|
|
25
4
|
storeId?: string;
|
|
5
|
+
/** 会话 meta:身份标签要读 agentName / teamContext.memberName,parentSessionId 供子会话判定。 */
|
|
26
6
|
meta?: {
|
|
27
7
|
parentSessionId?: string;
|
|
28
|
-
|
|
8
|
+
agentName?: string;
|
|
9
|
+
teamContext?: {
|
|
10
|
+
memberName?: unknown;
|
|
11
|
+
};
|
|
12
|
+
} & Record<string, unknown>;
|
|
29
13
|
}
|
|
30
14
|
export declare function buildAgentTrigger(session: AgentTriggerLike | undefined | null): {
|
|
31
15
|
agent_id?: string;
|
|
@@ -31,7 +31,10 @@ export interface HookInput {
|
|
|
31
31
|
*/
|
|
32
32
|
reason?: SessionEndReason;
|
|
33
33
|
/**
|
|
34
|
-
* User prompt content
|
|
34
|
+
* User prompt content.
|
|
35
|
+
* - UserPromptSubmit: the submitted prompt text.
|
|
36
|
+
* - UserPromptExpansion: Claude Code spec required field, always sent — the
|
|
37
|
+
* raw, pre-expansion text as typed by the user (e.g. "/deploy prod").
|
|
35
38
|
*/
|
|
36
39
|
prompt?: string;
|
|
37
40
|
/**
|