@octopi-agent/engine 0.102.10 → 0.121.15
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/dist/builtin-model-info.js +28 -7
- package/dist/config-admin/agent-presets.d.ts +32 -0
- package/dist/config-admin/agent-presets.js +133 -0
- package/dist/config-admin/console-access-key.d.ts +46 -0
- package/dist/config-admin/console-access-key.js +47 -0
- package/dist/config-admin/discover.d.ts +33 -4
- package/dist/config-admin/discover.js +101 -6
- package/dist/config-admin/env.d.ts +11 -0
- package/dist/config-admin/env.js +41 -0
- package/dist/config-admin/error-copy.d.ts +106 -0
- package/dist/config-admin/error-copy.js +287 -0
- package/dist/config-admin/i18n.d.ts +21 -0
- package/dist/config-admin/i18n.js +19 -0
- package/dist/config-admin/index.d.ts +8 -2
- package/dist/config-admin/index.js +4 -1
- package/dist/config-admin/model-presets.d.ts +14 -0
- package/dist/config-admin/model-presets.js +595 -70
- package/dist/config-admin/onboarding-apply.d.ts +83 -0
- package/dist/config-admin/onboarding-apply.js +259 -0
- package/dist/config-admin/onboarding.d.ts +160 -0
- package/dist/config-admin/onboarding.js +298 -0
- package/dist/config-admin/password-policy.d.ts +24 -0
- package/dist/config-admin/password-policy.js +31 -0
- package/dist/config-admin/redact.d.ts +42 -9
- package/dist/config-admin/redact.js +69 -5
- package/dist/config-schema/agent.d.ts +5 -1
- package/dist/config-schema/agent.js +20 -2
- package/dist/config-schema/browser.d.ts +62 -0
- package/dist/config-schema/browser.js +89 -0
- package/dist/config-schema/context.d.ts +7 -2
- package/dist/config-schema/context.js +6 -3
- package/dist/config-schema/engine.d.ts +86 -7
- package/dist/config-schema/engine.js +9 -2
- package/dist/config-schema/governance.d.ts +12 -1
- package/dist/config-schema/governance.js +10 -2
- package/dist/config-schema/models.d.ts +12 -8
- package/dist/config-schema/models.js +16 -1
- package/dist/config-schema/run.d.ts +4 -0
- package/dist/config-schema/run.js +10 -0
- package/dist/config-schema/shared.d.ts +1 -0
- package/dist/config-schema/shared.js +4 -2
- package/dist/config-schema/substrate.d.ts +5 -0
- package/dist/config-schema/substrate.js +8 -0
- package/dist/config.d.ts +116 -10
- package/dist/config.js +109 -13
- package/dist/file-mode.d.ts +67 -0
- package/dist/file-mode.js +182 -0
- package/dist/fork-child.d.ts +82 -0
- package/dist/fork-child.js +123 -0
- package/dist/harness/activation/delegated-run.d.ts +42 -0
- package/dist/harness/activation/delegated-run.js +71 -0
- package/dist/harness/activation/dispatcher.js +4 -0
- package/dist/harness/activation/index.d.ts +1 -0
- package/dist/harness/activation/run-backend.d.ts +92 -0
- package/dist/harness/activation/run-backend.js +16 -0
- package/dist/harness/activation/run-protocol.d.ts +392 -0
- package/dist/harness/activation/run-protocol.js +19 -0
- package/dist/harness/activation/runtime.d.ts +33 -0
- package/dist/harness/activation/runtime.js +119 -28
- package/dist/harness/activation/types.d.ts +19 -2
- package/dist/harness/agent/builder.d.ts +12 -0
- package/dist/harness/agent/builder.js +78 -22
- package/dist/harness/agent/config-bridge.d.ts +10 -1
- package/dist/harness/agent/config-bridge.js +15 -3
- package/dist/harness/agent/registered-tool-adapter.d.ts +27 -0
- package/dist/harness/agent/registered-tool-adapter.js +67 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +2 -0
- package/dist/harness/agent/wire-agent-builder.js +9 -2
- package/dist/harness/capabilities/document/backends/plain.js +2 -1
- package/dist/harness/capabilities/document/legacy/factory.js +3 -2
- package/dist/harness/collaboration/autonomous-subsystem/audit/reader.d.ts +17 -0
- package/dist/harness/collaboration/autonomous-subsystem/audit/reader.js +66 -36
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.d.ts +6 -2
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.js +27 -7
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +1 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +11 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +17 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +13 -3
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +48 -39
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -0
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +4 -0
- package/dist/harness/collaboration/delegation/child-run.d.ts +9 -0
- package/dist/harness/collaboration/delegation/child-run.js +34 -2
- package/dist/harness/collaboration/delegation/registry-types.d.ts +2 -0
- package/dist/harness/collaboration/delegation/service.d.ts +9 -4
- package/dist/harness/collaboration/delegation/service.js +33 -12
- package/dist/harness/collaboration/delegation/store.d.ts +2 -0
- package/dist/harness/collaboration/delegation/store.js +1 -0
- package/dist/harness/collaboration/delegation/types.d.ts +11 -0
- package/dist/harness/collaboration/delegation/wiring.d.ts +2 -0
- package/dist/harness/collaboration/delegation/wiring.js +1 -0
- package/dist/harness/context/capabilities/compact/engine.d.ts +44 -5
- package/dist/harness/context/capabilities/compact/engine.js +127 -39
- package/dist/harness/context/capabilities/compact/index.d.ts +2 -1
- package/dist/harness/context/capabilities/compact/index.js +1 -1
- package/dist/harness/context/capabilities/compact/types.d.ts +59 -9
- package/dist/harness/context/capabilities/summary/gate.d.ts +19 -2
- package/dist/harness/context/capabilities/summary/gate.js +53 -6
- package/dist/harness/context/capabilities/summary/registry.js +20 -0
- package/dist/harness/context/capabilities/summary/tool-binding.js +16 -12
- package/dist/harness/context/capabilities/summary/tool-bindings.d.ts +13 -0
- package/dist/harness/context/capabilities/summary/tool-bindings.js +22 -0
- package/dist/harness/context/capabilities/summary/types.d.ts +16 -0
- package/dist/harness/context/constitution/default-agents.md +85 -0
- package/dist/harness/context/context-size-ledger.js +8 -1
- package/dist/harness/context/default-context-engine.d.ts +100 -6
- package/dist/harness/context/default-context-engine.js +382 -89
- package/dist/harness/context/index.d.ts +2 -1
- package/dist/harness/context/index.js +1 -0
- package/dist/harness/context/layer-health.d.ts +4 -0
- package/dist/harness/context/layer-health.js +4 -0
- package/dist/harness/context/layer-types.d.ts +57 -0
- package/dist/harness/context/layer-types.js +73 -1
- package/dist/harness/context/layers.d.ts +3 -0
- package/dist/harness/context/layers.js +13 -6
- package/dist/harness/context/prefix-fingerprint.d.ts +46 -0
- package/dist/harness/context/prefix-fingerprint.js +52 -0
- package/dist/harness/context/summarize.js +18 -0
- package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
- package/dist/harness/context/system-prompt-assembler.js +5 -2
- package/dist/harness/context/tool-result-aging.d.ts +104 -16
- package/dist/harness/context/tool-result-aging.js +211 -57
- package/dist/harness/context/types.d.ts +71 -4
- package/dist/harness/context/types.js +25 -1
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +4 -3
- package/dist/harness/extension/execution-environment/effect-policy.js +2 -2
- package/dist/harness/extension/execution-environment/privileged-exec.js +4 -1
- package/dist/harness/extension/execution-environment/workspace.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +27 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.js +11 -2
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +12 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +25 -0
- package/dist/harness/extension/plugin-ecosystem/commands/builtin.js +28 -1
- package/dist/harness/extension/plugin-ecosystem/index.d.ts +1 -0
- package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +168 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +156 -15
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.d.ts +95 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.js +170 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.d.ts +178 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.js +314 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +40 -5
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +45 -26
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +11 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +42 -76
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +30 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +46 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +19 -14
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +3 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/browser-types.d.ts +333 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser-types.js +16 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser.d.ts +64 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser.js +692 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +0 -37
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +108 -4
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +34 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +0 -6
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +57 -4
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +81 -13
- package/dist/harness/extension/plugin-ecosystem/tools/http.js +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +13 -7
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +126 -14
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +44 -5
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +10 -24
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +7 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +4 -0
- package/dist/harness/governance/credentials/db.d.ts +9 -0
- package/dist/harness/governance/credentials/db.js +122 -31
- package/dist/harness/governance/credentials/store.d.ts +68 -7
- package/dist/harness/governance/credentials/store.js +177 -64
- package/dist/harness/governance/credentials/types.d.ts +13 -2
- package/dist/harness/governance/index.d.ts +1 -0
- package/dist/harness/governance/index.js +1 -0
- package/dist/harness/governance/registry/db.d.ts +32 -0
- package/dist/harness/governance/registry/db.js +142 -0
- package/dist/harness/governance/registry/index.d.ts +9 -0
- package/dist/harness/governance/registry/index.js +9 -0
- package/dist/harness/governance/registry/service.d.ts +381 -0
- package/dist/harness/governance/registry/service.js +825 -0
- package/dist/harness/governance/registry/types.d.ts +77 -0
- package/dist/harness/governance/registry/types.js +7 -0
- package/dist/harness/governance/security/default-security-guard.d.ts +3 -0
- package/dist/harness/governance/security/default-security-guard.js +12 -1
- package/dist/harness/governance/security/risk-evaluator.d.ts +13 -3
- package/dist/harness/governance/security/risk-evaluator.js +307 -21
- package/dist/harness/governance/security/shell-parser-treesitter.js +12 -4
- package/dist/harness/governance/session-acl/tool-rights.d.ts +1 -0
- package/dist/harness/index.d.ts +5 -3
- package/dist/harness/index.js +2 -2
- package/dist/harness/knowledge/boot-config.d.ts +2 -0
- package/dist/harness/knowledge/boot-config.js +2 -0
- package/dist/harness/knowledge/client.d.ts +53 -7
- package/dist/harness/knowledge/client.js +77 -20
- package/dist/harness/knowledge/db.d.ts +16 -0
- package/dist/harness/knowledge/db.js +107 -41
- package/dist/harness/knowledge/engine-thread.js +5 -7
- package/dist/harness/knowledge/grounding.js +4 -1
- package/dist/harness/knowledge/http-app.d.ts +15 -0
- package/dist/harness/knowledge/http-app.js +82 -21
- package/dist/harness/knowledge/http-bridge.d.ts +15 -0
- package/dist/harness/knowledge/http-bridge.js +19 -0
- package/dist/harness/knowledge/knowledge-serve-child.js +2 -3
- package/dist/harness/knowledge/query-service.d.ts +12 -2
- package/dist/harness/knowledge/query-service.js +75 -41
- package/dist/harness/knowledge/query-worker-client.d.ts +5 -1
- package/dist/harness/knowledge/query-worker-client.js +4 -1
- package/dist/harness/knowledge/query-worker.js +5 -3
- package/dist/harness/knowledge/read-http.d.ts +2 -0
- package/dist/harness/knowledge/read-http.js +9 -2
- package/dist/harness/knowledge/retriever.d.ts +1 -1
- package/dist/harness/knowledge/retriever.js +1 -2
- package/dist/harness/knowledge/serve.d.ts +6 -1
- package/dist/harness/knowledge/serve.js +5 -6
- package/dist/harness/knowledge/source-store.d.ts +101 -5
- package/dist/harness/knowledge/source-store.js +297 -71
- package/dist/harness/knowledge/start-service-process.d.ts +27 -8
- package/dist/harness/knowledge/start-service-process.js +49 -90
- package/dist/harness/knowledge/tenant-gate.d.ts +81 -0
- package/dist/harness/knowledge/tenant-gate.js +167 -0
- package/dist/harness/knowledge/writer-service.d.ts +18 -2
- package/dist/harness/knowledge/writer-service.js +80 -16
- package/dist/harness/knowledge/writer-worker-client.d.ts +9 -2
- package/dist/harness/knowledge/writer-worker-client.js +20 -3
- package/dist/harness/knowledge/writer-worker.js +11 -4
- package/dist/harness/memory/backfill-trigger.d.ts +10 -3
- package/dist/harness/memory/backfill-trigger.js +19 -19
- package/dist/harness/memory/cognition-seeds.d.ts +45 -0
- package/dist/harness/memory/cognition-seeds.js +67 -0
- package/dist/harness/memory/cognition.d.ts +12 -3
- package/dist/harness/memory/cognition.js +55 -35
- package/dist/harness/memory/conceptualizer.d.ts +11 -1
- package/dist/harness/memory/conceptualizer.js +10 -1
- package/dist/harness/memory/context-slice.d.ts +42 -0
- package/dist/harness/memory/context-slice.js +197 -0
- package/dist/harness/memory/health-probe.d.ts +8 -2
- package/dist/harness/memory/health-probe.js +10 -13
- package/dist/harness/memory/index.d.ts +5 -1
- package/dist/harness/memory/index.js +3 -1
- package/dist/harness/memory/sqlite/agent-db.d.ts +1 -0
- package/dist/harness/memory/sqlite/agent-db.js +9 -8
- package/dist/harness/memory/sqlite/cognition-store.d.ts +26 -3
- package/dist/harness/memory/sqlite/cognition-store.js +103 -45
- package/dist/harness/memory/sqlite/memory-store.js +4 -0
- package/dist/harness/memory/sqlite/sqlite-vec.d.ts +24 -1
- package/dist/harness/memory/sqlite/sqlite-vec.js +37 -1
- package/dist/harness/memory/types.d.ts +18 -2
- package/dist/harness/observability/observer/hub.d.ts +10 -0
- package/dist/harness/observability/observer/hub.js +95 -2
- package/dist/harness/run/agent/agent.js +3 -2
- package/dist/harness/run/concurrency/tool-validator.js +4 -3
- package/dist/harness/run/reliability/run-agent.d.ts +22 -0
- package/dist/harness/run/reliability/run-agent.js +79 -10
- package/dist/harness/run/run-host.d.ts +302 -0
- package/dist/harness/run/run-host.js +978 -0
- package/dist/harness/run/run-scope.d.ts +11 -0
- package/dist/harness/run/run-scope.js +19 -1
- package/dist/harness/run/runner.d.ts +149 -22
- package/dist/harness/run/runner.js +352 -35
- package/dist/harness/session/in-memory-store.js +13 -1
- package/dist/harness/session/schedules/service.d.ts +10 -2
- package/dist/harness/session/schedules/service.js +13 -2
- package/dist/harness/session/tasks/tools.js +12 -0
- package/dist/harness/session/types.d.ts +10 -14
- package/dist/harness/shared/events/agent-event-map.d.ts +29 -0
- package/dist/harness/shared/types/agent-definition.d.ts +6 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/integration/agent-runtime/channel-message-source.d.ts +3 -1
- package/dist/integration/agent-runtime/channel-message-source.js +4 -3
- package/dist/integration/browser/camoufox.d.ts +40 -0
- package/dist/integration/browser/camoufox.js +80 -0
- package/dist/integration/browser/index.d.ts +91 -0
- package/dist/integration/browser/index.js +110 -0
- package/dist/integration/browser/install.d.ts +47 -0
- package/dist/integration/browser/install.js +214 -0
- package/dist/integration/browser/playwright.d.ts +224 -0
- package/dist/integration/browser/playwright.js +925 -0
- package/dist/integration/browser/service.d.ts +41 -0
- package/dist/integration/browser/service.js +181 -0
- package/dist/integration/browser/stealth.d.ts +42 -0
- package/dist/integration/browser/stealth.js +104 -0
- package/dist/integration/providers/anthropic-message-normalize.d.ts +20 -0
- package/dist/integration/providers/anthropic-message-normalize.js +48 -0
- package/dist/integration/providers/anthropic.js +27 -2
- package/dist/integration/providers/fetch-timeout.d.ts +17 -0
- package/dist/integration/providers/fetch-timeout.js +24 -0
- package/dist/integration/providers/openai.d.ts +8 -0
- package/dist/integration/providers/openai.js +41 -1
- package/dist/integration/providers/wire-dump-diff.js +2 -1
- package/dist/integration/providers/wire-dump.d.ts +56 -2
- package/dist/integration/providers/wire-dump.js +119 -6
- package/dist/integration/storage/archive-manager.d.ts +14 -2
- package/dist/integration/storage/archive-manager.js +24 -8
- package/dist/integration/storage/atomic-tmp.d.ts +12 -0
- package/dist/integration/storage/atomic-tmp.js +36 -0
- package/dist/integration/storage/jsonl.d.ts +9 -0
- package/dist/integration/storage/jsonl.js +137 -38
- package/dist/integration/storage/session-index.d.ts +5 -0
- package/dist/integration/storage/session-index.js +25 -4
- package/dist/integration/tools/assemble.d.ts +50 -0
- package/dist/integration/tools/assemble.js +137 -0
- package/dist/paths.d.ts +18 -0
- package/dist/paths.js +36 -0
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +3 -1
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +74 -5
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +3 -2
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +11 -2
- package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +6 -3
- package/dist/subsystems/cognition-steward/consolidate/handler.js +266 -28
- package/dist/subsystems/memory-steward/backfill/handler.js +3 -2
- package/dist/subsystems/memory-steward/govern/config.yaml +6 -1
- package/dist/subsystems/wisdom-steward/attribute/config.yaml +5 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +3 -0
- package/dist/subsystems/wisdom-steward/govern/config.yaml +6 -1
- package/package.json +5 -3
|
@@ -49,6 +49,8 @@ export interface AgentDelegationPolicy {
|
|
|
49
49
|
export interface AgentInfo {
|
|
50
50
|
/** Agent 唯一 ID */
|
|
51
51
|
id: string;
|
|
52
|
+
/** Agent 归属租户(arch/multi-tenancy.md §8 委派限本租户);缺省 = DEFAULT 存量域 */
|
|
53
|
+
tenantId?: string;
|
|
52
54
|
/** Agent 名称(人类可读) */
|
|
53
55
|
name: string;
|
|
54
56
|
/** Agent 描述 */
|
|
@@ -39,6 +39,8 @@ export interface DispatchDelegationInput {
|
|
|
39
39
|
*/
|
|
40
40
|
parentRights?: import('../../governance/session-acl/types.js').SessionRights;
|
|
41
41
|
task: string;
|
|
42
|
+
/** 子会话显示标题(工具面必填;写入委派单与子会话标题三键) */
|
|
43
|
+
title?: string;
|
|
42
44
|
input: string;
|
|
43
45
|
/** 自动返回通知 `<output>` 截断上限(chars);缺省 = DEFAULT_DELEGATION_OUTPUT_CHARS(B 方案 2026-11-09) */
|
|
44
46
|
maxOutputChars?: number;
|
|
@@ -103,10 +105,10 @@ export interface ResolutionAvailability {
|
|
|
103
105
|
}>;
|
|
104
106
|
}
|
|
105
107
|
export declare class DelegateResolutionError extends Error {
|
|
106
|
-
readonly reason: 'not_found' | 'not_callable' | 'forbidden' | 'depth_exceeded' | 'too_many_active';
|
|
108
|
+
readonly reason: 'not_found' | 'not_callable' | 'forbidden' | 'depth_exceeded' | 'too_many_active' | 'cross_tenant';
|
|
107
109
|
/** 解析失败时的可用目标(可选;让调用方不必瞎猜) */
|
|
108
110
|
readonly available?: ResolutionAvailability | undefined;
|
|
109
|
-
constructor(message: string, reason: 'not_found' | 'not_callable' | 'forbidden' | 'depth_exceeded' | 'too_many_active',
|
|
111
|
+
constructor(message: string, reason: 'not_found' | 'not_callable' | 'forbidden' | 'depth_exceeded' | 'too_many_active' | 'cross_tenant',
|
|
110
112
|
/** 解析失败时的可用目标(可选;让调用方不必瞎猜) */
|
|
111
113
|
available?: ResolutionAvailability | undefined);
|
|
112
114
|
}
|
|
@@ -185,14 +187,17 @@ export declare class DelegateService {
|
|
|
185
187
|
*
|
|
186
188
|
* @param target - 目标寻址
|
|
187
189
|
* @param callerAgentId - 调用方 agentId(校验 callableBy)
|
|
190
|
+
* @param callerTenantId - 调用方归属租户(§8 委派限本租户;trait 选人先按域过滤——
|
|
191
|
+
* 否则他租户候选会抢走选择或硬拒本可成立的委派,T4b 评审 MAJ-8)
|
|
188
192
|
* @returns 解析出的 AgentHandle
|
|
189
193
|
* @throws 目标不可达 / 不可被委派 / 策略拒绝
|
|
190
194
|
*/
|
|
191
195
|
private resolveTarget;
|
|
192
196
|
/**
|
|
193
|
-
*
|
|
197
|
+
* 列出**可用委派目标**(失败时回传,供调用方自愈)——按调用方租户域收口
|
|
194
198
|
*
|
|
195
|
-
* @
|
|
199
|
+
* @param callerTenant - 调用方归属租户(缺省 = DEFAULT 存量域)
|
|
200
|
+
* @returns 本域可用 traits 与 agent 概要
|
|
196
201
|
*/
|
|
197
202
|
private describeTargets;
|
|
198
203
|
/** 校验委派策略并转 AgentHandle */
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
* **非阻塞**(§7):`dispatch()` 建单后立即返回 `delegationId`,不等子 Run 结束。
|
|
17
17
|
*/
|
|
18
18
|
import { randomUUID } from 'node:crypto';
|
|
19
|
+
import { DEFAULT_TENANT_ID } from '@octopi-agent/core/types.js';
|
|
19
20
|
import { DELEGATION_SCHEMA_VERSION, DelegationEvents, isTerminalDelegationStatus } from './types.js';
|
|
21
|
+
import { delegationSessionTitle } from './child-run.js';
|
|
20
22
|
import { tightenSessionRights } from '../../governance/session-acl/rights.js';
|
|
21
23
|
import { effectiveDelegationPolicy } from './registry-types.js';
|
|
22
24
|
export class DelegateResolutionError extends Error {
|
|
@@ -94,8 +96,15 @@ export class DelegateService {
|
|
|
94
96
|
* @throws 目标不可达 / 不可被委派 / 深度超限 / 未闭合委派过多
|
|
95
97
|
*/
|
|
96
98
|
async dispatch(input) {
|
|
97
|
-
// 1. 解析目标(D2)
|
|
98
|
-
const handle = this.resolveTarget(input.target, input.parent.agentId);
|
|
99
|
+
// 1. 解析目标(D2);trait 选人按父域过滤(MAJ-8)
|
|
100
|
+
const handle = this.resolveTarget(input.target, input.parent.agentId, input.parent.tenantId);
|
|
101
|
+
// 1b. 租户闸(arch/multi-tenancy.md §8,T4b):委派限本租户——跨租户 = 数据外泄 +
|
|
102
|
+
// 目标执行环境不受本租户控制。缺省(config agent / 存量)= DEFAULT 存量域,彼此可派。
|
|
103
|
+
const parentTenant = input.parent.tenantId ?? DEFAULT_TENANT_ID;
|
|
104
|
+
const targetTenant = handle.tenantId ?? DEFAULT_TENANT_ID;
|
|
105
|
+
if (parentTenant !== targetTenant) {
|
|
106
|
+
throw new DelegateResolutionError(`delegate cross-tenant: ${input.parent.agentId} (${parentTenant}) -> ${handle.agentId} (${targetTenant})`, 'cross_tenant');
|
|
107
|
+
}
|
|
99
108
|
// 2. 递归深度闸(§10.4)
|
|
100
109
|
const parentDepth = input.parentDepth ?? this.config.resolveParentDepth?.(input.parent.sessionId) ?? 0;
|
|
101
110
|
const depth = parentDepth + 1;
|
|
@@ -128,6 +137,7 @@ export class DelegateService {
|
|
|
128
137
|
parent: input.parent,
|
|
129
138
|
target: input.target,
|
|
130
139
|
task: input.task,
|
|
140
|
+
title: delegationSessionTitle(input),
|
|
131
141
|
input: input.input,
|
|
132
142
|
maxOutputChars: input.maxOutputChars,
|
|
133
143
|
context: input.context,
|
|
@@ -258,14 +268,17 @@ export class DelegateService {
|
|
|
258
268
|
*
|
|
259
269
|
* @param target - 目标寻址
|
|
260
270
|
* @param callerAgentId - 调用方 agentId(校验 callableBy)
|
|
271
|
+
* @param callerTenantId - 调用方归属租户(§8 委派限本租户;trait 选人先按域过滤——
|
|
272
|
+
* 否则他租户候选会抢走选择或硬拒本可成立的委派,T4b 评审 MAJ-8)
|
|
261
273
|
* @returns 解析出的 AgentHandle
|
|
262
274
|
* @throws 目标不可达 / 不可被委派 / 策略拒绝
|
|
263
275
|
*/
|
|
264
|
-
resolveTarget(target, callerAgentId) {
|
|
276
|
+
resolveTarget(target, callerAgentId, callerTenantId) {
|
|
277
|
+
const callerTenant = callerTenantId ?? DEFAULT_TENANT_ID;
|
|
265
278
|
if (target.agentId) {
|
|
266
279
|
const info = this.registry.get(target.agentId);
|
|
267
280
|
if (!info) {
|
|
268
|
-
throw new DelegateResolutionError(`delegate target not found: ${target.agentId}`, 'not_found', this.describeTargets());
|
|
281
|
+
throw new DelegateResolutionError(`delegate target not found: ${target.agentId}`, 'not_found', this.describeTargets(callerTenant));
|
|
269
282
|
}
|
|
270
283
|
return this.toHandle(info, callerAgentId);
|
|
271
284
|
}
|
|
@@ -274,26 +287,32 @@ export class DelegateService {
|
|
|
274
287
|
//(否则第一个不可委派的命中会让整次委派失败,而不是落到下一个可用候选)
|
|
275
288
|
const candidates = this.registry
|
|
276
289
|
.findByTrait(target.trait)
|
|
290
|
+
.filter((info) => (info.tenantId ?? DEFAULT_TENANT_ID) === callerTenant)
|
|
277
291
|
.filter((info) => effectiveDelegationPolicy(info.delegation).callable)
|
|
278
292
|
.filter((info) => this.isCallableBy(info, callerAgentId));
|
|
279
293
|
const picked = candidates[0];
|
|
280
294
|
if (!picked) {
|
|
281
|
-
//
|
|
282
|
-
|
|
295
|
+
// 失败时回传**本域可用目标**,让调用方(LLM)一次就能改对,而不是瞎猜
|
|
296
|
+
//(跨租户 agent id/traits 不经 available_targets 泄漏,T4b 评审 MIN-1)
|
|
297
|
+
throw new DelegateResolutionError(`no callable agent for trait: ${target.trait}`, 'not_found', this.describeTargets(callerTenant));
|
|
283
298
|
}
|
|
284
299
|
return this.toHandle(picked, callerAgentId);
|
|
285
300
|
}
|
|
286
|
-
throw new DelegateResolutionError('delegate target must set agentId or trait', 'not_found', this.describeTargets());
|
|
301
|
+
throw new DelegateResolutionError('delegate target must set agentId or trait', 'not_found', this.describeTargets(callerTenant));
|
|
287
302
|
}
|
|
288
303
|
/**
|
|
289
|
-
*
|
|
304
|
+
* 列出**可用委派目标**(失败时回传,供调用方自愈)——按调用方租户域收口
|
|
290
305
|
*
|
|
291
|
-
* @
|
|
306
|
+
* @param callerTenant - 调用方归属租户(缺省 = DEFAULT 存量域)
|
|
307
|
+
* @returns 本域可用 traits 与 agent 概要
|
|
292
308
|
*/
|
|
293
|
-
describeTargets() {
|
|
309
|
+
describeTargets(callerTenant = DEFAULT_TENANT_ID) {
|
|
310
|
+
const visible = this.registry
|
|
311
|
+
.list()
|
|
312
|
+
.filter((a) => (a.tenantId ?? DEFAULT_TENANT_ID) === callerTenant);
|
|
294
313
|
return {
|
|
295
|
-
traits: [...new Set(
|
|
296
|
-
agents:
|
|
314
|
+
traits: [...new Set(visible.flatMap((a) => a.traits))].sort(),
|
|
315
|
+
agents: visible.map((a) => ({
|
|
297
316
|
id: a.id,
|
|
298
317
|
traits: [...a.traits],
|
|
299
318
|
callable: effectiveDelegationPolicy(a.delegation).callable,
|
|
@@ -311,6 +330,7 @@ export class DelegateService {
|
|
|
311
330
|
}
|
|
312
331
|
return {
|
|
313
332
|
agentId: info.id,
|
|
333
|
+
tenantId: info.tenantId,
|
|
314
334
|
traits: info.traits,
|
|
315
335
|
rightsCeiling: policy.rightsCeiling,
|
|
316
336
|
budget: policy.budget,
|
|
@@ -340,6 +360,7 @@ export class DelegateService {
|
|
|
340
360
|
childSessionId,
|
|
341
361
|
childRunId,
|
|
342
362
|
task: input.task,
|
|
363
|
+
title: delegationSessionTitle(input),
|
|
343
364
|
input: input.input,
|
|
344
365
|
context: input.context ?? 'clean',
|
|
345
366
|
parentMessages: input.context === 'fork' ? input.parentMessages : undefined,
|
|
@@ -23,6 +23,8 @@ export interface CreateDelegationInput {
|
|
|
23
23
|
parent: DelegationParentRef;
|
|
24
24
|
target: DelegationTarget;
|
|
25
25
|
task: string;
|
|
26
|
+
/** 子会话显示标题(工具面必填;缺省时子 Run 侧退任务派生) */
|
|
27
|
+
title?: string;
|
|
26
28
|
input: string;
|
|
27
29
|
/** 自动返回通知 `<output>` 截断上限(chars);缺省 = DEFAULT_DELEGATION_OUTPUT_CHARS */
|
|
28
30
|
maxOutputChars?: number;
|
|
@@ -67,6 +67,7 @@ export class DelegationStore {
|
|
|
67
67
|
parent: { ...input.parent },
|
|
68
68
|
target: { ...input.target },
|
|
69
69
|
task: input.task,
|
|
70
|
+
title: input.title,
|
|
70
71
|
input: input.input,
|
|
71
72
|
maxOutputChars: normalizeMaxOutputChars(input.maxOutputChars),
|
|
72
73
|
context: input.context ?? 'clean',
|
|
@@ -72,6 +72,8 @@ export interface DelegationParentRef {
|
|
|
72
72
|
agentId: string;
|
|
73
73
|
sessionId: string;
|
|
74
74
|
runId: string;
|
|
75
|
+
/** 父 run 归属租户(§8 委派限本租户);缺省 = DEFAULT 存量域 */
|
|
76
|
+
tenantId?: string;
|
|
75
77
|
}
|
|
76
78
|
/** 结果送达父的状态机(§7.1 送达语义) */
|
|
77
79
|
export type DelegationDeliveryState = 'pending' | 'delivering' | 'surfaced';
|
|
@@ -105,6 +107,11 @@ export interface Delegation {
|
|
|
105
107
|
resolvedAgentId?: string;
|
|
106
108
|
/** 任务描述(进子的 user 消息) */
|
|
107
109
|
task: string;
|
|
110
|
+
/**
|
|
111
|
+
* 子会话显示标题(委派时显式给定,落 child session 标题三键)。
|
|
112
|
+
* 缺省时子 Run 侧退化为任务派生标题(不产生「新会话」)。
|
|
113
|
+
*/
|
|
114
|
+
title?: string;
|
|
108
115
|
/** 显式输入(不传父上下文,D6/⑥) */
|
|
109
116
|
input: string;
|
|
110
117
|
/** 上下文传递模式(默认 clean) */
|
|
@@ -171,6 +178,8 @@ export interface DelegateRequest {
|
|
|
171
178
|
childSessionId: string;
|
|
172
179
|
childRunId: string;
|
|
173
180
|
task: string;
|
|
181
|
+
/** 子会话显示标题(工具面必填;缺省时子 Run 侧退任务派生标题) */
|
|
182
|
+
title?: string;
|
|
174
183
|
input: string;
|
|
175
184
|
/** 上下文传递模式 */
|
|
176
185
|
context: DelegationContextMode;
|
|
@@ -215,6 +224,8 @@ export interface DelegateResult {
|
|
|
215
224
|
export interface AgentHandle {
|
|
216
225
|
/** 解析出的 agentId */
|
|
217
226
|
agentId: string;
|
|
227
|
+
/** 目标 agent 归属租户(§8 委派限本租户的执行点);缺省 = DEFAULT 存量域 */
|
|
228
|
+
tenantId?: string;
|
|
218
229
|
/** 特质标签(供调用方核对是否命中意图) */
|
|
219
230
|
traits: string[];
|
|
220
231
|
/** 被委派时的权利天花板(D3:只能收紧) */
|
|
@@ -101,6 +101,7 @@ export function createDelegationRuntime(options) {
|
|
|
101
101
|
id: agent.agentId,
|
|
102
102
|
name: agent.agentId,
|
|
103
103
|
traits: agent.traits ?? [],
|
|
104
|
+
...(agent.tenantId === undefined ? {} : { tenantId: agent.tenantId }),
|
|
104
105
|
delegation: effectiveDelegationPolicy(agent.delegation),
|
|
105
106
|
status: 'idle',
|
|
106
107
|
});
|
|
@@ -6,18 +6,57 @@
|
|
|
6
6
|
* @module harness/context/capabilities/compact/engine
|
|
7
7
|
*/
|
|
8
8
|
import type { CompactEngine, CreateCompactEngineOptions } from './types.js';
|
|
9
|
-
/**
|
|
9
|
+
/** 回声判据参数(2026-11-13 修正,见 {@link detectSummaryContamination} 的规则三说明) */
|
|
10
|
+
export interface EchoVerdict {
|
|
11
|
+
hits: number;
|
|
12
|
+
hitChars: number;
|
|
13
|
+
textChars: number;
|
|
14
|
+
contaminated: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 判定 `text` 是否构成对 `sourceText` 的逐字复读。
|
|
18
|
+
*
|
|
19
|
+
* 判据是**长度占比**而非行数:复读的失效模式是「输出基本等于输入片段」,而不是
|
|
20
|
+
* 「引用了若干条证据」。四条以上互不相同的证据行如果只占输出很小比例,仍是合法
|
|
21
|
+
* 交接书(模板明确允许引用证据行)。
|
|
22
|
+
*
|
|
23
|
+
* @param text - 模型输出
|
|
24
|
+
* @param sourceText - 回声比对源
|
|
25
|
+
* @returns 命中量与判定
|
|
26
|
+
*/
|
|
27
|
+
export declare function evaluateEcho(text: string, sourceText: string): EchoVerdict;
|
|
28
|
+
/** 污染判定结果(含可观测明细)。`reason` 为 null = 干净通过。 */
|
|
29
|
+
export interface ContaminationResult {
|
|
30
|
+
reason: 'canned_refusal' | 'transcript_shape' | 'verbatim_echo' | null;
|
|
31
|
+
/** 回声明细(已做回声比对时填充,无论是否判污染) */
|
|
32
|
+
echo?: EchoVerdict;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 输出闸门:判定摘要输出是否污染(回声/对话体续写)。
|
|
10
36
|
*
|
|
11
37
|
* 失效模式(2026-10-28 实测):模型把对话样本当语料续写,产出「assistant 半句 + 逐字
|
|
12
|
-
* tool-call
|
|
13
|
-
* 调用方重试或按 onSummarizeFail 降级(不得静默存坏摘要)。
|
|
38
|
+
* tool-call」的原文复读,使折叠掉的中段信息全丢。
|
|
14
39
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
40
|
+
* 三条规则,任一命中即污染:
|
|
41
|
+
* 1. `canned_refusal` —— 正文恰为内容过滤罐头拒答(整段精确匹配,长输出不可能命中)。
|
|
42
|
+
* 2. `transcript_shape` —— 出现对话体/工具调用语法字面量(指令已不含这些,出现即续写)。
|
|
43
|
+
* 3. `verbatim_echo` —— **按长度占比**判复读(见 {@link evaluateEcho})。
|
|
44
|
+
*
|
|
45
|
+
* 规则三的判据在 2026-11-13 由「命中 ≥3 行」改为「命中字符占比 ≥60%」:旧计数分支
|
|
46
|
+
* 与四段式模板的证据行要求结构性冲突——模板要求写文件路径/commit id/测试名,这些行
|
|
47
|
+
* 几乎必然 ≥40 字符且逐字出现在输入里,三条合法证据即触发整包重发。
|
|
17
48
|
*
|
|
18
49
|
* @param text - 模型输出
|
|
19
50
|
* @param sourceText - 「模型实际看到的会话文本」投影(回声比对源;不得含指令本身——
|
|
20
51
|
* 指令的四段式标题会合法出现在输出里)
|
|
52
|
+
* @returns 判定结果(含回声明细,供可观测上报)
|
|
53
|
+
*/
|
|
54
|
+
export declare function inspectSummaryOutput(text: string, sourceText?: string): ContaminationResult;
|
|
55
|
+
/**
|
|
56
|
+
* 输出闸门(字串版):保留旧签名供既有调用方与测试使用。
|
|
57
|
+
*
|
|
58
|
+
* @param text - 模型输出
|
|
59
|
+
* @param sourceText - 回声比对源
|
|
21
60
|
* @returns 命中原因;干净返回 null
|
|
22
61
|
*/
|
|
23
62
|
export declare function detectSummaryContamination(text: string, sourceText?: string): string | null;
|
|
@@ -30,59 +30,109 @@ const STRICT_RETRY_SUFFIX = '\n\nIMPORTANT: your previous attempt replayed input
|
|
|
30
30
|
* 角色行用行首语义(防正文误伤);工具调用语法 anywhere 判定——指令已不含这些
|
|
31
31
|
* 字面量(F15),输出里出现即高概率是续写污染。 */
|
|
32
32
|
const TRANSCRIPT_SHAPE = /<function[=_]|<\/?tool_call|<invoke[ \t]|<\/?tool_use|<parameter[ >]|antml:|Tool Calls:|\[(ASSISTANT|USER|TOOL|SYSTEM)\]|^\s*(Assistant|Human|User|System):/im;
|
|
33
|
-
/**
|
|
33
|
+
/** 单行最短长度:短于此的片段(标题、表头、空行)重复出现不构成复读证据 */
|
|
34
|
+
const ECHO_MIN_LINE_CHARS = 40;
|
|
35
|
+
/** 回声占比阈值:命中的输入字符占输出 ≥ 该比例才判复读。
|
|
36
|
+
*
|
|
37
|
+
* 修正前是「命中 ≥3 行」的计数分支,与四段式模板的「④ Evidence pointers」要求
|
|
38
|
+
* 直接冲突——模板要求写文件路径/commit id/测试名,而这些行几乎必然 ≥40 字符且
|
|
39
|
+
* 逐字出现在输入里。三条合法证据就触发整包重发(2026-11-13 实测:348k token、
|
|
40
|
+
* +59s)。判据改为纯比例:复读的本质是「输出基本就是输入的回声」,与命中几条
|
|
41
|
+
* 无关;引用三条短路径(占比极低)不应与复读整段正文等价。 */
|
|
42
|
+
const ECHO_RATIO_THRESHOLD = 0.6;
|
|
43
|
+
/**
|
|
44
|
+
* 判定 `text` 是否构成对 `sourceText` 的逐字复读。
|
|
45
|
+
*
|
|
46
|
+
* 判据是**长度占比**而非行数:复读的失效模式是「输出基本等于输入片段」,而不是
|
|
47
|
+
* 「引用了若干条证据」。四条以上互不相同的证据行如果只占输出很小比例,仍是合法
|
|
48
|
+
* 交接书(模板明确允许引用证据行)。
|
|
49
|
+
*
|
|
50
|
+
* @param text - 模型输出
|
|
51
|
+
* @param sourceText - 回声比对源
|
|
52
|
+
* @returns 命中量与判定
|
|
53
|
+
*/
|
|
54
|
+
export function evaluateEcho(text, sourceText) {
|
|
55
|
+
let hits = 0;
|
|
56
|
+
let hitChars = 0;
|
|
57
|
+
// 逐行比对:只统计 ≥ ECHO_MIN_LINE_CHARS 的行,且同一行只计一次(split 会产出重复行)
|
|
58
|
+
for (const line of new Set(sourceText.split('\n').map((l) => l.trim()))) {
|
|
59
|
+
if (line.length < ECHO_MIN_LINE_CHARS)
|
|
60
|
+
continue;
|
|
61
|
+
if (!text.includes(line))
|
|
62
|
+
continue;
|
|
63
|
+
hits += 1;
|
|
64
|
+
hitChars += line.length;
|
|
65
|
+
}
|
|
66
|
+
const textChars = text.length;
|
|
67
|
+
const contaminated = hitChars >= ECHO_MIN_LINE_CHARS && hitChars >= textChars * ECHO_RATIO_THRESHOLD;
|
|
68
|
+
return { hits, hitChars, textChars, contaminated };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 输出闸门:判定摘要输出是否污染(回声/对话体续写)。
|
|
34
72
|
*
|
|
35
73
|
* 失效模式(2026-10-28 实测):模型把对话样本当语料续写,产出「assistant 半句 + 逐字
|
|
36
|
-
* tool-call
|
|
37
|
-
*
|
|
74
|
+
* tool-call」的原文复读,使折叠掉的中段信息全丢。
|
|
75
|
+
*
|
|
76
|
+
* 三条规则,任一命中即污染:
|
|
77
|
+
* 1. `canned_refusal` —— 正文恰为内容过滤罐头拒答(整段精确匹配,长输出不可能命中)。
|
|
78
|
+
* 2. `transcript_shape` —— 出现对话体/工具调用语法字面量(指令已不含这些,出现即续写)。
|
|
79
|
+
* 3. `verbatim_echo` —— **按长度占比**判复读(见 {@link evaluateEcho})。
|
|
38
80
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
81
|
+
* 规则三的判据在 2026-11-13 由「命中 ≥3 行」改为「命中字符占比 ≥60%」:旧计数分支
|
|
82
|
+
* 与四段式模板的证据行要求结构性冲突——模板要求写文件路径/commit id/测试名,这些行
|
|
83
|
+
* 几乎必然 ≥40 字符且逐字出现在输入里,三条合法证据即触发整包重发。
|
|
41
84
|
*
|
|
42
85
|
* @param text - 模型输出
|
|
43
86
|
* @param sourceText - 「模型实际看到的会话文本」投影(回声比对源;不得含指令本身——
|
|
44
87
|
* 指令的四段式标题会合法出现在输出里)
|
|
45
|
-
* @returns
|
|
88
|
+
* @returns 判定结果(含回声明细,供可观测上报)
|
|
46
89
|
*/
|
|
47
|
-
export function
|
|
90
|
+
export function inspectSummaryOutput(text, sourceText) {
|
|
48
91
|
// 内容过滤罐头拒答:网关 200 内联拒答(正文被替换成固定英文罐头)不是摘要,
|
|
49
92
|
// 一律判污染——交由既有的「一次加严重试 → 二次抛错降级」链路处理
|
|
50
93
|
if (isCannedRefusalText(text)) {
|
|
51
|
-
return 'canned_refusal';
|
|
94
|
+
return { reason: 'canned_refusal' };
|
|
52
95
|
}
|
|
53
96
|
if (TRANSCRIPT_SHAPE.test(text)) {
|
|
54
|
-
return 'transcript_shape';
|
|
97
|
+
return { reason: 'transcript_shape' };
|
|
55
98
|
}
|
|
56
|
-
if (sourceText) {
|
|
57
|
-
|
|
58
|
-
let hitChars = 0;
|
|
59
|
-
for (const line of sourceText.split('\n')) {
|
|
60
|
-
const trimmed = line.trim();
|
|
61
|
-
if (trimmed.length >= 40 && text.includes(trimmed)) {
|
|
62
|
-
hits += 1;
|
|
63
|
-
hitChars += trimmed.length;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (hits >= 3 || (hitChars >= 40 && hitChars >= text.length * 0.6)) {
|
|
67
|
-
return 'verbatim_echo';
|
|
68
|
-
}
|
|
99
|
+
if (!sourceText) {
|
|
100
|
+
return { reason: null };
|
|
69
101
|
}
|
|
70
|
-
|
|
102
|
+
const echo = evaluateEcho(text, sourceText);
|
|
103
|
+
return echo.contaminated ? { reason: 'verbatim_echo', echo } : { reason: null, echo };
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 输出闸门(字串版):保留旧签名供既有调用方与测试使用。
|
|
107
|
+
*
|
|
108
|
+
* @param text - 模型输出
|
|
109
|
+
* @param sourceText - 回声比对源
|
|
110
|
+
* @returns 命中原因;干净返回 null
|
|
111
|
+
*/
|
|
112
|
+
export function detectSummaryContamination(text, sourceText) {
|
|
113
|
+
return inspectSummaryOutput(text, sourceText).reason;
|
|
71
114
|
}
|
|
72
115
|
/** 带输出闸门的摘要执行:首次污染给一次加严重试,二次污染抛错交 onSummarizeFail 降级。
|
|
116
|
+
*
|
|
117
|
+
* 可观测(2026-11-13):每次闸门判定都通过 `onVerdict` 上报——事故里重发整包
|
|
118
|
+
* 348k token 请求却零事件,UI 只能显示「已等待 Ns」,无法区分「在跑」与「被判污染重试」。
|
|
73
119
|
*
|
|
74
120
|
* @param invoke - 摘要调用(strict=true 时需附加加严指令)
|
|
75
121
|
* @param sourceText - 回声比对源(喂给模型的输入文本)
|
|
122
|
+
* @param onVerdict - 判定回调(尝试序号 + 结论 + 明细)
|
|
76
123
|
* @returns 干净摘要文本
|
|
77
124
|
* @throws provider 错误,或 `contaminated_output:*`(二次污染)
|
|
78
125
|
*/
|
|
79
|
-
async function invokeGuardedSummarize(invoke, sourceText) {
|
|
126
|
+
async function invokeGuardedSummarize(invoke, sourceText, onVerdict) {
|
|
80
127
|
let text = await invoke(false);
|
|
81
|
-
|
|
128
|
+
const first = inspectSummaryOutput(text, sourceText);
|
|
129
|
+
onVerdict?.(1, first);
|
|
130
|
+
if (first.reason) {
|
|
82
131
|
text = await invoke(true);
|
|
83
|
-
const again =
|
|
84
|
-
|
|
85
|
-
|
|
132
|
+
const again = inspectSummaryOutput(text, sourceText);
|
|
133
|
+
onVerdict?.(2, again);
|
|
134
|
+
if (again.reason) {
|
|
135
|
+
throw new Error(`contaminated_output:${again.reason}`);
|
|
86
136
|
}
|
|
87
137
|
}
|
|
88
138
|
return text;
|
|
@@ -182,23 +232,23 @@ export function createCompactEngine(options) {
|
|
|
182
232
|
foldRange: opts.foldRange,
|
|
183
233
|
taskSnapshot: opts.taskSnapshot,
|
|
184
234
|
});
|
|
185
|
-
// 缓存优先:
|
|
235
|
+
// 缓存优先:requestView(会话同形 tools+system+history)+ 尾部 user 指令。
|
|
186
236
|
// 禁止把指令塞进 system 或重排历史——否则打穿前缀缓存。
|
|
187
237
|
const buildPrefixed = () => [
|
|
188
|
-
...opts.
|
|
238
|
+
...opts.requestView?.messages,
|
|
189
239
|
{ role: 'user', content: prompt.tailUser },
|
|
190
240
|
];
|
|
191
|
-
// 无
|
|
241
|
+
// 无 requestView 回退「policy system + 文本化中段」(旁路/旧调用):
|
|
192
242
|
// tool_call-only assistant / 缺 tool_call_id 的 tool 消息会被严格网关 400。
|
|
193
243
|
const buildTextify = () => [
|
|
194
244
|
{ role: 'system', content: prompt.instruction },
|
|
195
245
|
{ role: 'user', content: buildHandoverUserContent(opts, middleText) },
|
|
196
246
|
];
|
|
197
|
-
// 回声比对源 = 模型实际看到的会话文本投影(评审 F2
|
|
247
|
+
// 回声比对源 = 模型实际看到的会话文本投影(评审 F2):前缀分支含 head/middle/tail
|
|
198
248
|
// 全量历史,只比 middleText 会漏掉 head/tail 区回声;指令本身不得进比对源(四段式标题
|
|
199
249
|
// 会合法出现在输出里)。
|
|
200
|
-
const prefixEchoSource = () => (opts.
|
|
201
|
-
let usePrefix = Boolean(opts.
|
|
250
|
+
const prefixEchoSource = () => (opts.requestView?.messages ?? []).map((m) => String(m.content ?? '')).join('\n');
|
|
251
|
+
let usePrefix = Boolean(opts.requestView?.messages?.length);
|
|
202
252
|
let llmMessages = usePrefix ? buildPrefixed() : buildTextify();
|
|
203
253
|
// 回声源:仅前缀分支才用调用方覆盖(前缀含既有摘要占位时,占位正文不得参与判定);
|
|
204
254
|
// textify 分支的比对源必须是它自己发给模型的文本(middleText)
|
|
@@ -207,14 +257,25 @@ export function createCompactEngine(options) {
|
|
|
207
257
|
// provider 多按 input+max_tokens ≤ window 校验,压缩恰在会话最满时触发,保险丝可能把
|
|
208
258
|
// 请求顶出窗口——放不下就改走文本化中段旁路(cache-miss 如实降级),仍放不下则如实失败。
|
|
209
259
|
const hardCap = (opts.maxSummaryTokens ?? maxTokens) * 4;
|
|
210
|
-
|
|
260
|
+
// 工具面也是请求体的一部分(前缀 tools → system → messages):窗口钳制必须把它
|
|
261
|
+
// 算进输入成本,否则「放得下」的判定会漏掉整包 tool schema(几十 k tokens)。
|
|
262
|
+
// 只有 prefix 分支才发 tools——textify 分支 system 指令不同、缓存必 miss,
|
|
263
|
+
// 带工具面是纯成本,还会把旁路本身顶出窗口(2026-11-12 评审 MAJ-1)。
|
|
264
|
+
const prefixTools = opts.requestView?.tools;
|
|
265
|
+
const toolsTokensFor = (withTools) => {
|
|
266
|
+
if (!withTools || !prefixTools?.length)
|
|
267
|
+
return 0;
|
|
268
|
+
const est = opts.estimator;
|
|
269
|
+
return est?.estimateTools?.(prefixTools) ?? new HeuristicTokenEstimator().estimateTools(prefixTools);
|
|
270
|
+
};
|
|
271
|
+
const windowCapOf = (msgs, withTools) => clampSummaryProviderCap({
|
|
211
272
|
hardCap,
|
|
212
273
|
// estimateLLMMessages 口径含 tool_calls/content block/消息开销(tool_calls 全量计入)
|
|
213
|
-
inputTokens: estimateLLMMessages(msgs),
|
|
274
|
+
inputTokens: estimateLLMMessages(msgs) + toolsTokensFor(withTools),
|
|
214
275
|
contextWindow: opts.contextWindow,
|
|
215
276
|
maxOutputTokens: opts.maxOutputTokens,
|
|
216
277
|
});
|
|
217
|
-
let providerMaxTokens = windowCapOf(llmMessages);
|
|
278
|
+
let providerMaxTokens = windowCapOf(llmMessages, usePrefix);
|
|
218
279
|
// F22 可观测:无前缀/被迫旁路 = cache-miss,如实上报,不静默换请求形状
|
|
219
280
|
if (!usePrefix) {
|
|
220
281
|
opts.emit?.({ type: 'compact.summarize_fallback', reason: 'no_prefix', cached: false });
|
|
@@ -223,7 +284,7 @@ export function createCompactEngine(options) {
|
|
|
223
284
|
usePrefix = false;
|
|
224
285
|
llmMessages = buildTextify();
|
|
225
286
|
echoSource = middleText;
|
|
226
|
-
providerMaxTokens = windowCapOf(llmMessages);
|
|
287
|
+
providerMaxTokens = windowCapOf(llmMessages, false);
|
|
227
288
|
opts.emit?.({ type: 'compact.summarize_fallback', reason: 'window_guard', cached: false });
|
|
228
289
|
}
|
|
229
290
|
if (providerMaxTokens < 256) {
|
|
@@ -248,6 +309,18 @@ export function createCompactEngine(options) {
|
|
|
248
309
|
return summarizeFn(msgs, {
|
|
249
310
|
previousSummary: opts.previousSummary,
|
|
250
311
|
maxTokens: providerMaxTokens,
|
|
312
|
+
// 工具面同形(2026-11-12):缓存前缀 = tools → system → messages,缺 tools 时
|
|
313
|
+
// 前缀从第一字节断开,整段历史退化为冷 prefill。
|
|
314
|
+
// 只在 prefix 分支发:textify 分支 system 不同、缓存必 miss,带工具面是纯成本
|
|
315
|
+
// 且会挤占窗口(评审 MAJ-1)。
|
|
316
|
+
//
|
|
317
|
+
// 不传 toolChoice(2026-11-13 实测):'none' 不是对所有 provider 中性的标记。
|
|
318
|
+
// DeepSeek 收到 tool_choice:'none' 会把 tools 整个从 prompt 渲染中剔除
|
|
319
|
+
//(实测 prompt 8117 → 6286 tokens),于是落入「无工具面」那个独立缓存空间,
|
|
320
|
+
// 与会话前缀零重叠(实测 3.7% 命中)。Anthropic 侧才是中性的。
|
|
321
|
+
// 「禁止调用」由指令 + summarize_tool_call_emitted fail-loud 守卫承担——
|
|
322
|
+
// 为了一个 provider-specific 的软提示牺牲整段前缀缓存不划算。
|
|
323
|
+
...(usePrefix && prefixTools && prefixTools.length > 0 ? { tools: prefixTools } : {}),
|
|
251
324
|
...(opts.signal ? { signal: opts.signal } : {}),
|
|
252
325
|
// outputTokens 真值收集(2026-11-08):摘要产物体量以 provider 实测为准
|
|
253
326
|
onUsage: (u) => {
|
|
@@ -255,7 +328,22 @@ export function createCompactEngine(options) {
|
|
|
255
328
|
},
|
|
256
329
|
});
|
|
257
330
|
};
|
|
258
|
-
const text = await invokeGuardedSummarize(invoke, echoSource)
|
|
331
|
+
const text = await invokeGuardedSummarize(invoke, echoSource, (attempt, verdict) => {
|
|
332
|
+
// 闸门判定如实上报(fail-loud):ui 与日志都该看见「被判污染 + 重试」,
|
|
333
|
+
// 而不是只显示「已等待 Ns」
|
|
334
|
+
opts.emit?.({
|
|
335
|
+
type: 'compact.contamination',
|
|
336
|
+
verdict: verdict.reason ?? 'clean',
|
|
337
|
+
attempt,
|
|
338
|
+
...(verdict.echo
|
|
339
|
+
? {
|
|
340
|
+
echoHits: verdict.echo.hits,
|
|
341
|
+
echoHitChars: verdict.echo.hitChars,
|
|
342
|
+
textChars: verdict.echo.textChars,
|
|
343
|
+
}
|
|
344
|
+
: {}),
|
|
345
|
+
});
|
|
346
|
+
});
|
|
259
347
|
// 空白摘要(空串/纯空白)按失败降级(旧 LLMSummaryCompressor 的 trim 守卫在此收口):
|
|
260
348
|
// 空白冒充 fresh 摘要会把 previousSummary 写成空白并推进覆盖点——静默失忆红线
|
|
261
349
|
if (!text.trim()) {
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module harness/context/capabilities/compact
|
|
5
5
|
*/
|
|
6
|
-
export { createCompactEngine, summarySoftTargetTokens, detectSummaryContamination } from './engine.js';
|
|
6
|
+
export { createCompactEngine, summarySoftTargetTokens, detectSummaryContamination, inspectSummaryOutput, evaluateEcho, } from './engine.js';
|
|
7
|
+
export type { ContaminationResult, EchoVerdict } from './engine.js';
|
|
7
8
|
export { asSummaryMessage, wrapSummaryText, isMechanicalNotice, SUMMARY_MARKER, MECHANICAL_NOTICE_TRUNCATED, MECHANICAL_NOTICE_COMPRESSED, MECHANICAL_NOTICE_STRUCTURAL, } from './messages.js';
|
|
8
9
|
export { alignViewSplit, semanticHistory } from './view-split.js';
|
|
9
10
|
export { isToolResultMessage, hasToolCall, } from './messages.js';
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module harness/context/capabilities/compact
|
|
5
5
|
*/
|
|
6
|
-
export { createCompactEngine, summarySoftTargetTokens, detectSummaryContamination } from './engine.js';
|
|
6
|
+
export { createCompactEngine, summarySoftTargetTokens, detectSummaryContamination, inspectSummaryOutput, evaluateEcho, } from './engine.js';
|
|
7
7
|
export { asSummaryMessage, wrapSummaryText, isMechanicalNotice, SUMMARY_MARKER, MECHANICAL_NOTICE_TRUNCATED, MECHANICAL_NOTICE_COMPRESSED, MECHANICAL_NOTICE_STRUCTURAL, } from './messages.js';
|
|
8
8
|
export { alignViewSplit, semanticHistory } from './view-split.js';
|
|
9
9
|
export { isToolResultMessage, hasToolCall, } from './messages.js';
|