@octopi-agent/engine 0.70.7 → 0.90.11
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/LICENSE +201 -201
- package/NOTICE +7 -7
- package/README.md +64 -26
- package/dist/config-schema/agent.d.ts +89 -1
- package/dist/config-schema/agent.js +81 -5
- package/dist/config-schema/context.d.ts +24 -5
- package/dist/config-schema/context.js +28 -1
- package/dist/config-schema/engine.d.ts +205 -13
- package/dist/config-schema/engine.js +31 -2
- package/dist/config-schema/governance.d.ts +95 -0
- package/dist/config-schema/governance.js +93 -1
- package/dist/config-schema/models.d.ts +3 -3
- package/dist/config-schema/observability.d.ts +6 -0
- package/dist/config-schema/observability.js +16 -0
- package/dist/config-schema/run.d.ts +10 -0
- package/dist/config-schema/run.js +18 -0
- package/dist/config-schema/shared.d.ts +13 -0
- package/dist/config-schema/shared.js +22 -0
- package/dist/config-schema/substrate.d.ts +2 -2
- package/dist/config-schema/subsystems.d.ts +1 -1
- package/dist/config-schema/subsystems.js +2 -1
- package/dist/config.d.ts +201 -8
- package/dist/config.js +105 -3
- package/dist/harness/activation/compiler.js +3 -0
- package/dist/harness/activation/runtime.d.ts +7 -0
- package/dist/harness/activation/runtime.js +60 -2
- package/dist/harness/activation/sources/agent-signal.d.ts +11 -0
- package/dist/harness/activation/sources/agent-signal.js +33 -0
- package/dist/harness/activation/types.d.ts +6 -1
- package/dist/harness/agent/builder.d.ts +50 -5
- package/dist/harness/agent/builder.js +189 -59
- package/dist/harness/agent/config-bridge.d.ts +33 -25
- package/dist/harness/agent/config-bridge.js +84 -291
- package/dist/harness/agent/index.d.ts +3 -1
- package/dist/harness/agent/index.js +2 -1
- package/dist/harness/agent/tool-purpose.d.ts +46 -0
- package/dist/harness/agent/tool-purpose.js +127 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +133 -0
- package/dist/harness/agent/wire-agent-builder.js +370 -0
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.d.ts +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/loader.d.ts +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +16 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +8 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +17 -9
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +12 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +19 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.d.ts +6 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.js +24 -7
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.d.ts +5 -2
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +11 -3
- package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.d.ts +7 -4
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.js +8 -9
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.d.ts +36 -10
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +60 -7
- package/dist/harness/collaboration/delegation/child-run.d.ts +144 -0
- package/dist/harness/collaboration/delegation/child-run.js +241 -0
- package/dist/harness/collaboration/delegation/index.d.ts +26 -0
- package/dist/harness/collaboration/delegation/index.js +25 -0
- package/dist/harness/collaboration/delegation/notifier.d.ts +46 -0
- package/dist/harness/collaboration/delegation/notifier.js +84 -0
- package/dist/harness/collaboration/delegation/registry-types.d.ts +200 -0
- package/dist/harness/collaboration/delegation/registry-types.js +61 -0
- package/dist/harness/collaboration/delegation/registry.d.ts +110 -0
- package/dist/harness/collaboration/delegation/registry.js +220 -0
- package/dist/harness/collaboration/delegation/service.d.ts +249 -0
- package/dist/harness/collaboration/delegation/service.js +499 -0
- package/dist/harness/collaboration/delegation/store.d.ts +155 -0
- package/dist/harness/collaboration/delegation/store.js +271 -0
- package/dist/harness/collaboration/delegation/transport.d.ts +73 -0
- package/dist/harness/collaboration/delegation/transport.js +61 -0
- package/dist/harness/collaboration/delegation/types.d.ts +231 -0
- package/dist/harness/collaboration/delegation/types.js +70 -0
- package/dist/harness/collaboration/delegation/wiring.d.ts +111 -0
- package/dist/harness/collaboration/delegation/wiring.js +145 -0
- package/dist/harness/collaboration/orchestration/index.d.ts +11 -13
- package/dist/harness/collaboration/orchestration/index.js +11 -11
- package/dist/harness/context/assembler.d.ts +2 -2
- package/dist/harness/context/assembler.js +12 -7
- package/dist/harness/context/capabilities/compact/engine.js +80 -38
- package/dist/harness/context/capabilities/compact/types.d.ts +12 -1
- package/dist/harness/context/capabilities/summary/registry.js +10 -0
- package/dist/harness/context/constitution/default-agents.md +230 -228
- package/dist/harness/context/default-context-engine.d.ts +101 -23
- package/dist/harness/context/default-context-engine.js +483 -172
- package/dist/harness/context/hybrid-compressor.d.ts +3 -3
- package/dist/harness/context/hybrid-compressor.js +18 -23
- package/dist/harness/context/index.d.ts +5 -1
- package/dist/harness/context/index.js +2 -0
- package/dist/harness/context/layer-snapshot.d.ts +4 -0
- package/dist/harness/context/layer-snapshot.js +30 -18
- package/dist/harness/context/layer-types.d.ts +85 -1
- package/dist/harness/context/layer-types.js +110 -4
- package/dist/harness/context/layers.d.ts +5 -2
- package/dist/harness/context/layers.js +11 -5
- package/dist/harness/context/llm-summarizer.d.ts +15 -1
- package/dist/harness/context/llm-summarizer.js +107 -56
- package/dist/harness/context/message-selector.js +6 -2
- package/dist/harness/context/root-instructions.d.ts +72 -0
- package/dist/harness/context/root-instructions.js +227 -0
- package/dist/harness/context/runtime-datetime.d.ts +34 -7
- package/dist/harness/context/runtime-datetime.js +66 -10
- package/dist/harness/context/smart-router.d.ts +1 -1
- package/dist/harness/context/smart-router.js +1 -1
- package/dist/harness/context/system-prompt-assembler.d.ts +30 -0
- package/dist/harness/context/system-prompt-assembler.js +73 -6
- package/dist/harness/context/token-constants.d.ts +2 -2
- package/dist/harness/context/token-constants.js +2 -2
- package/dist/harness/context/token-estimate-fns.d.ts +1 -3
- package/dist/harness/context/token-estimate-fns.js +2 -4
- package/dist/harness/context/token-estimator.d.ts +1 -1
- package/dist/harness/context/token-estimator.js +14 -6
- package/dist/harness/context/tool-result-aging.d.ts +140 -0
- package/dist/harness/context/tool-result-aging.js +331 -0
- package/dist/harness/context/tool-result-body.d.ts +10 -0
- package/dist/harness/context/tool-result-body.js +27 -0
- package/dist/harness/context/turn-envelope.d.ts +123 -0
- package/dist/harness/context/turn-envelope.js +188 -0
- package/dist/harness/context/types.d.ts +35 -47
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +258 -0
- package/dist/harness/extension/execution-environment/effect-policy.js +358 -0
- package/dist/harness/extension/execution-environment/index.d.ts +18 -2
- package/dist/harness/extension/execution-environment/index.js +11 -2
- package/dist/harness/extension/execution-environment/isolation.js +5 -1
- package/dist/harness/extension/execution-environment/memory-undo.d.ts +101 -0
- package/dist/harness/extension/execution-environment/memory-undo.js +192 -0
- package/dist/harness/extension/execution-environment/process-isolation.d.ts +84 -0
- package/dist/harness/extension/execution-environment/process-isolation.js +315 -0
- package/dist/harness/extension/execution-environment/resource-limits.d.ts +36 -0
- package/dist/harness/extension/execution-environment/resource-limits.js +84 -0
- package/dist/harness/extension/execution-environment/sandbox.d.ts +125 -4
- package/dist/harness/extension/execution-environment/sandbox.js +521 -51
- package/dist/harness/extension/execution-environment/shell-journal.d.ts +100 -0
- package/dist/harness/extension/execution-environment/shell-journal.js +299 -0
- package/dist/harness/extension/execution-environment/tool-capabilities.d.ts +45 -0
- package/dist/harness/extension/execution-environment/tool-capabilities.js +126 -0
- package/dist/harness/extension/execution-environment/types.d.ts +67 -39
- package/dist/harness/extension/execution-environment/types.js +2 -2
- package/dist/harness/extension/execution-environment/undo-log.d.ts +203 -0
- package/dist/harness/extension/execution-environment/undo-log.js +627 -0
- package/dist/harness/extension/execution-environment/undo-merge.d.ts +40 -0
- package/dist/harness/extension/execution-environment/undo-merge.js +167 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/index.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/mcp/bridge.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +1 -6
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +3 -8
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +2 -10
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +2 -9
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +1 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/index.js +1 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +2 -4
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +4 -21
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +3 -9
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +4 -8
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +1 -4
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +1 -3
- package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/skills/manager.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.d.ts +51 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +153 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +18 -3
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +277 -81
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.d.ts +31 -0
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +291 -0
- package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +10 -2
- package/dist/harness/extension/plugin-ecosystem/tools/env-info.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/eol.d.ts +35 -0
- package/dist/harness/extension/plugin-ecosystem/tools/eol.js +43 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +40 -9
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.d.ts +33 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +376 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +12 -2
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +241 -70
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.d.ts +31 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.js +104 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.d.ts +111 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.js +197 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.d.ts +27 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +463 -0
- package/dist/harness/extension/plugin-ecosystem/tools/http.d.ts +10 -6
- package/dist/harness/extension/plugin-ecosystem/tools/http.js +41 -47
- package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +6 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/memory.js +25 -1
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.d.ts +13 -0
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +391 -0
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +51 -2
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +151 -12
- package/dist/harness/extension/plugin-ecosystem/tools/session-history.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +10 -1
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +35 -19
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +8 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/web-search.js +1 -0
- package/dist/harness/governance/credentials/index.d.ts +1 -1
- package/dist/harness/governance/credentials/store.d.ts +16 -4
- package/dist/harness/governance/credentials/store.js +33 -6
- package/dist/harness/governance/credentials/types.d.ts +11 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +105 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +184 -0
- package/dist/harness/governance/human-in-the-loop/index.d.ts +5 -5
- package/dist/harness/governance/human-in-the-loop/index.js +3 -3
- package/dist/harness/governance/human-in-the-loop/types.d.ts +7 -62
- package/dist/harness/governance/human-in-the-loop/types.js +6 -2
- package/dist/harness/governance/security/capability-enforcer.d.ts +9 -1
- package/dist/harness/governance/security/capability-enforcer.js +31 -8
- package/dist/harness/governance/security/degradation.js +5 -7
- package/dist/harness/governance/security/risk-evaluator.d.ts +1 -1
- package/dist/harness/governance/security/risk-evaluator.js +4 -82
- package/dist/harness/governance/security/temp-path.d.ts +41 -0
- package/dist/harness/governance/security/temp-path.js +117 -0
- package/dist/harness/governance/session-acl/index.d.ts +1 -0
- package/dist/harness/governance/session-acl/index.js +1 -0
- package/dist/harness/governance/session-acl/rights.d.ts +12 -0
- package/dist/harness/governance/session-acl/rights.js +89 -7
- package/dist/harness/governance/session-acl/seed-roles.js +9 -1
- package/dist/harness/governance/session-acl/service.js +21 -29
- package/dist/harness/governance/session-acl/tool-rights.d.ts +81 -0
- package/dist/harness/governance/session-acl/tool-rights.js +238 -0
- package/dist/harness/governance/session-acl/types.d.ts +22 -0
- package/dist/harness/index.d.ts +16 -12
- package/dist/harness/index.js +10 -6
- package/dist/harness/knowledge/file-identity.d.ts +8 -0
- package/dist/harness/knowledge/file-identity.js +26 -1
- package/dist/harness/knowledge/file-index-store.js +11 -11
- package/dist/harness/knowledge/grounding.d.ts +2 -1
- package/dist/harness/knowledge/grounding.js +8 -5
- package/dist/harness/knowledge/index-store.d.ts +31 -4
- package/dist/harness/knowledge/index-store.js +121 -39
- package/dist/harness/knowledge/index.d.ts +2 -2
- package/dist/harness/knowledge/index.js +1 -1
- package/dist/harness/knowledge/ingest.d.ts +115 -115
- package/dist/harness/knowledge/ingest.js +154 -151
- package/dist/harness/knowledge/job-control-state.js +4 -4
- package/dist/harness/knowledge/job-control.js +11 -11
- package/dist/harness/knowledge/knowledge-serve-child.js +1 -1
- package/dist/harness/knowledge/membership-store.js +11 -11
- package/dist/harness/knowledge/network-guard.d.ts +61 -4
- package/dist/harness/knowledge/network-guard.js +390 -113
- package/dist/harness/knowledge/purge.js +4 -1
- package/dist/harness/knowledge/query-service.js +3 -3
- package/dist/harness/knowledge/writer-service.d.ts +2 -0
- package/dist/harness/knowledge/writer-service.js +14 -13
- package/dist/harness/memory/backfill-coverage.js +3 -1
- package/dist/harness/memory/backfill-trigger.d.ts +2 -2
- package/dist/harness/memory/backfill-trigger.js +4 -4
- package/dist/harness/memory/index.d.ts +1 -0
- package/dist/harness/memory/index.js +1 -0
- package/dist/harness/memory/sqlite/agent-db.js +2 -0
- package/dist/harness/memory/sqlite/memory-store.d.ts +1 -0
- package/dist/harness/memory/sqlite/memory-store.js +14 -4
- package/dist/harness/memory/sqlite/wisdom-store.js +9 -9
- package/dist/harness/memory/store.d.ts +1 -0
- package/dist/harness/memory/store.js +3 -0
- package/dist/harness/memory/time-format.d.ts +28 -0
- package/dist/harness/memory/time-format.js +52 -0
- package/dist/harness/memory/types.d.ts +12 -0
- package/dist/harness/observability/observer/hub.js +53 -2
- package/dist/harness/observability/observer/index.d.ts +2 -2
- package/dist/harness/observability/observer/index.js +1 -1
- package/dist/harness/observability/observer/types.d.ts +80 -0
- package/dist/harness/observability/observer/types.js +118 -9
- package/dist/harness/run/agent/agent.d.ts +18 -0
- package/dist/harness/run/agent/agent.js +26 -0
- package/dist/harness/run/concurrency/tool-loop-detection-core.d.ts +1 -1
- package/dist/harness/run/concurrency/tool-loop-detection-core.js +1 -1
- package/dist/harness/run/reliability/harness-events.d.ts +4 -0
- package/dist/harness/run/reliability/run-agent.js +110 -18
- package/dist/harness/run/reliability/run-metrics-collector.d.ts +28 -2
- package/dist/harness/run/reliability/run-metrics-collector.js +92 -2
- package/dist/harness/run/run-guard/default-run-guard.d.ts +0 -5
- package/dist/harness/run/run-guard/default-run-guard.js +104 -44
- package/dist/harness/run/run-scope.d.ts +52 -0
- package/dist/harness/run/runner.d.ts +117 -16
- package/dist/harness/run/runner.js +668 -157
- package/dist/harness/session/attachments/llm-intent.js +17 -17
- package/dist/harness/session/history/port.js +16 -5
- package/dist/harness/session/in-memory-store.d.ts +6 -0
- package/dist/harness/session/in-memory-store.js +55 -3
- package/dist/harness/session/schedules/index.d.ts +10 -0
- package/dist/harness/session/schedules/index.js +10 -0
- package/dist/harness/session/schedules/render.d.ts +13 -0
- package/dist/harness/session/schedules/render.js +63 -0
- package/dist/harness/session/schedules/service.d.ts +179 -0
- package/dist/harness/session/schedules/service.js +695 -0
- package/dist/harness/session/schedules/store.d.ts +119 -0
- package/dist/harness/session/schedules/store.js +323 -0
- package/dist/harness/session/schedules/tools.d.ts +39 -0
- package/dist/harness/session/schedules/tools.js +442 -0
- package/dist/harness/session/schedules/types.d.ts +104 -0
- package/dist/harness/session/schedules/types.js +97 -0
- package/dist/harness/session/tasks/tools.js +22 -0
- package/dist/harness/session/title.js +25 -9
- package/dist/harness/session/types.d.ts +35 -0
- package/dist/harness/shared/events/agent-event-map.d.ts +39 -0
- package/dist/harness/shared/events/agent-event-map.js +2 -0
- package/dist/harness/shared/types/agent-definition.d.ts +23 -0
- package/dist/index.d.ts +25 -9
- package/dist/index.js +11 -2
- package/dist/integration/observability/run-telemetry.d.ts +8 -0
- package/dist/integration/observability/run-telemetry.js +31 -8
- package/dist/integration/observability/trace-collector.js +26 -4
- package/dist/integration/observability/trace-events.d.ts +1 -0
- package/dist/integration/observability/trace-events.js +2 -0
- package/dist/integration/observability/trace-logger.js +27 -17
- package/dist/integration/providers/anthropic.d.ts +10 -0
- package/dist/integration/providers/anthropic.js +44 -1
- package/dist/integration/providers/openai.d.ts +10 -0
- package/dist/integration/providers/openai.js +58 -2
- package/dist/integration/providers/wire-dump-diff.d.ts +191 -0
- package/dist/integration/providers/wire-dump-diff.js +351 -0
- package/dist/integration/providers/wire-dump.d.ts +178 -0
- package/dist/integration/providers/wire-dump.js +396 -0
- package/dist/integration/storage/jsonl.d.ts +29 -0
- package/dist/integration/storage/jsonl.js +243 -41
- package/dist/integration/storage/session-index.js +63 -8
- package/dist/paths.d.ts +19 -0
- package/dist/paths.js +38 -1
- package/dist/subsystems/cognition-steward/conceptualize/SUBSYSTEM.md +43 -43
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +50 -50
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +6 -6
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +54 -54
- package/dist/subsystems/memory-steward/backfill/handler.js +9 -0
- package/dist/subsystems/safety-guard/config.yaml +3 -1
- package/dist/subsystems/wisdom-steward/evaluate/config.yaml +50 -50
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +42 -42
- package/dist/subsystems/wisdom-steward/formation/config.yaml +54 -54
- package/dist/subsystems/wisdom-steward/govern/config.yaml +55 -55
- package/package.json +115 -115
- package/dist/harness/collaboration/multi-agent/agent-registry-types.d.ts +0 -144
- package/dist/harness/collaboration/multi-agent/agent-registry-types.js +0 -25
- package/dist/harness/collaboration/multi-agent/index.d.ts +0 -17
- package/dist/harness/collaboration/multi-agent/index.js +0 -15
- package/dist/harness/collaboration/multi-agent/process.d.ts +0 -167
- package/dist/harness/collaboration/multi-agent/process.js +0 -256
- package/dist/harness/collaboration/multi-agent/registry.d.ts +0 -36
- package/dist/harness/collaboration/multi-agent/registry.js +0 -137
- package/dist/harness/collaboration/multi-agent/swarm.d.ts +0 -135
- package/dist/harness/collaboration/multi-agent/swarm.js +0 -317
- package/dist/harness/collaboration/multi-agent/types.d.ts +0 -66
- package/dist/harness/collaboration/multi-agent/types.js +0 -15
- package/dist/harness/collaboration/orchestration/async-task-store.d.ts +0 -107
- package/dist/harness/collaboration/orchestration/async-task-store.js +0 -12
- package/dist/harness/collaboration/orchestration/async-task.d.ts +0 -156
- package/dist/harness/collaboration/orchestration/async-task.js +0 -359
- package/dist/harness/collaboration/orchestration/planner/hybrid-planner.d.ts +0 -47
- package/dist/harness/collaboration/orchestration/planner/hybrid-planner.js +0 -61
- package/dist/harness/collaboration/orchestration/planner/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/planner/index.js +0 -6
- package/dist/harness/collaboration/orchestration/planner/llm-planner.d.ts +0 -54
- package/dist/harness/collaboration/orchestration/planner/llm-planner.js +0 -167
- package/dist/harness/collaboration/orchestration/planner/rule-planner.d.ts +0 -85
- package/dist/harness/collaboration/orchestration/planner/rule-planner.js +0 -175
- package/dist/harness/collaboration/orchestration/quality/classifier.d.ts +0 -21
- package/dist/harness/collaboration/orchestration/quality/classifier.js +0 -235
- package/dist/harness/collaboration/orchestration/quality/gate.d.ts +0 -29
- package/dist/harness/collaboration/orchestration/quality/gate.js +0 -409
- package/dist/harness/collaboration/orchestration/quality/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/quality/index.js +0 -8
- package/dist/harness/collaboration/orchestration/quality/types.d.ts +0 -159
- package/dist/harness/collaboration/orchestration/quality/types.js +0 -33
- package/dist/harness/collaboration/orchestration/scheduler/index.d.ts +0 -5
- package/dist/harness/collaboration/orchestration/scheduler/index.js +0 -4
- package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.d.ts +0 -143
- package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.js +0 -297
- package/dist/harness/collaboration/orchestration/strategy/classifier.d.ts +0 -12
- package/dist/harness/collaboration/orchestration/strategy/classifier.js +0 -81
- package/dist/harness/collaboration/orchestration/strategy/index.d.ts +0 -3
- package/dist/harness/collaboration/orchestration/strategy/index.js +0 -2
- package/dist/harness/collaboration/orchestration/strategy/router.d.ts +0 -28
- package/dist/harness/collaboration/orchestration/strategy/router.js +0 -105
- package/dist/harness/collaboration/orchestration/strategy/types.d.ts +0 -49
- package/dist/harness/collaboration/orchestration/strategy/types.js +0 -4
- package/dist/harness/collaboration/orchestration/workflow/engine.d.ts +0 -86
- package/dist/harness/collaboration/orchestration/workflow/engine.js +0 -298
- package/dist/harness/collaboration/orchestration/workflow/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/workflow/index.js +0 -7
- package/dist/harness/collaboration/orchestration/workflow/types.d.ts +0 -143
- package/dist/harness/collaboration/orchestration/workflow/types.js +0 -7
- package/dist/harness/governance/human-in-the-loop/approval-manager.d.ts +0 -32
- package/dist/harness/governance/human-in-the-loop/approval-manager.js +0 -93
- /package/dist/harness/collaboration/{multi-agent → delegation}/message-channel-types.d.ts +0 -0
- /package/dist/harness/collaboration/{multi-agent → delegation}/message-channel-types.js +0 -0
|
@@ -25,6 +25,7 @@ import { BudgetPolicyEngine } from '../budget/budget.js';
|
|
|
25
25
|
import { UsageLedger } from '../../governance/accounting/usage-ledger.js';
|
|
26
26
|
import { nominalTotalTokens } from '@octopi-agent/core/types/turn.js';
|
|
27
27
|
import { getRunScope } from '../run-scope.js';
|
|
28
|
+
import { resolveHitlDecision } from '../../governance/human-in-the-loop/decision-cache.js';
|
|
28
29
|
export const DEFAULT_RELIABILITY_CONFIG = {
|
|
29
30
|
planningRetry: {
|
|
30
31
|
maxAttempts: 2,
|
|
@@ -133,29 +134,30 @@ function hasStructuredPlanningOnlyFormat(text) {
|
|
|
133
134
|
}
|
|
134
135
|
// ── high 风险确认 ──
|
|
135
136
|
/**
|
|
136
|
-
* high
|
|
137
|
+
* high 风险人工确认(SEC-7 单模型)
|
|
137
138
|
*
|
|
138
|
-
* - 有 `harness.confirmHighRisk
|
|
139
|
-
* -
|
|
139
|
+
* - 有 `harness.confirmHighRisk`:查 HitlDecisionCache → 调钩子(返回 HitlDecision)
|
|
140
|
+
* - 无审批通道 / 异常 / deny:回退 reject(false),无人值守不放行
|
|
141
|
+
* - `approve_session` / `approve_always` 由引擎缓存,同 session/进程免再问
|
|
140
142
|
*/
|
|
141
143
|
async function confirmHighRiskDecision(harness, toolCall, reason, severity) {
|
|
142
144
|
const confirm = harness.confirmHighRisk;
|
|
143
145
|
if (!confirm)
|
|
144
146
|
return false;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
147
|
+
const scope = getRunScope();
|
|
148
|
+
return resolveHitlDecision({
|
|
149
|
+
channel: 'high_risk',
|
|
150
|
+
key: toolCall.name,
|
|
151
|
+
sessionId: scope?.sessionId,
|
|
152
|
+
agentId: scope?.agentId,
|
|
153
|
+
ask: async () => await confirm({
|
|
148
154
|
toolCall,
|
|
149
155
|
reason,
|
|
150
156
|
severity,
|
|
151
157
|
sessionId: scope?.sessionId,
|
|
152
158
|
agentId: scope?.agentId,
|
|
153
|
-
})
|
|
154
|
-
}
|
|
155
|
-
catch {
|
|
156
|
-
// 审批通道异常按拒绝处理(fail-safe);此处吞掉仅因异常不改变「不放行」结论
|
|
157
|
-
return false;
|
|
158
|
-
}
|
|
159
|
+
}),
|
|
160
|
+
});
|
|
159
161
|
}
|
|
160
162
|
// ── 核心包装函数 ──
|
|
161
163
|
/**
|
|
@@ -224,13 +226,77 @@ export async function* runAgentWithReliability(context, config, harness, signal)
|
|
|
224
226
|
role: 'user',
|
|
225
227
|
content: state.wrapUp.userMessage,
|
|
226
228
|
timestamp: Date.now(),
|
|
229
|
+
metadata: { source: 'engineHint' },
|
|
227
230
|
});
|
|
228
231
|
}
|
|
229
232
|
// wrap-up 窗口内:允许只读工具,阻止写入工具
|
|
230
233
|
// 简化实现:允许所有工具,让模型自行决策
|
|
231
234
|
// 完整实现应检查工具类型(只读 vs 写入)
|
|
232
235
|
}
|
|
233
|
-
//
|
|
236
|
+
// Tool surface (untrusted degrade): strip egress/exec tools
|
|
237
|
+
if (harness.toolSurface === 'reduced') {
|
|
238
|
+
const { isToolAllowedOnSurface } = await import('../../extension/execution-environment/effect-policy.js');
|
|
239
|
+
if (!isToolAllowedOnSurface(ctx.toolCall.name, 'reduced')) {
|
|
240
|
+
const scope = getRunScope();
|
|
241
|
+
const reason = `tool_surface_reduced: "${ctx.toolCall.name}" is not allowed when untrusted is degraded`;
|
|
242
|
+
state.pendingSecurityEvents.push({
|
|
243
|
+
type: 'security_blocked',
|
|
244
|
+
timestamp: Date.now(),
|
|
245
|
+
data: {
|
|
246
|
+
sessionId: scope?.sessionId,
|
|
247
|
+
agentId: scope?.agentId,
|
|
248
|
+
reason,
|
|
249
|
+
toolName: ctx.toolCall.name,
|
|
250
|
+
action: 'reject',
|
|
251
|
+
severity: 'high',
|
|
252
|
+
violations: [
|
|
253
|
+
{
|
|
254
|
+
type: 'unauthorized_tool',
|
|
255
|
+
severity: 'high',
|
|
256
|
+
description: reason,
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
return { block: true, reason, terminate: false };
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
// SEC-2: session toolRights ∩ agent ToolPolicy (narrow-only, deny wins).
|
|
265
|
+
// Read from RunScope (per-run); harness is shared across concurrent sessions.
|
|
266
|
+
{
|
|
267
|
+
const scope = getRunScope();
|
|
268
|
+
const sessionRights = scope?.toolRuntime?.sessionToolRights;
|
|
269
|
+
const agentPolicy = scope?.toolRuntime?.agentToolPolicy;
|
|
270
|
+
if (sessionRights || agentPolicy) {
|
|
271
|
+
const { isToolPermitted } = await import('../../governance/session-acl/tool-rights.js');
|
|
272
|
+
if (!isToolPermitted(ctx.toolCall.name, undefined, [
|
|
273
|
+
agentPolicy,
|
|
274
|
+
sessionRights,
|
|
275
|
+
])) {
|
|
276
|
+
const reason = `tool_rights_denied: "${ctx.toolCall.name}" is not permitted for this session participant`;
|
|
277
|
+
state.pendingSecurityEvents.push({
|
|
278
|
+
type: 'security_blocked',
|
|
279
|
+
timestamp: Date.now(),
|
|
280
|
+
data: {
|
|
281
|
+
sessionId: scope?.sessionId,
|
|
282
|
+
agentId: scope?.agentId,
|
|
283
|
+
reason,
|
|
284
|
+
toolName: ctx.toolCall.name,
|
|
285
|
+
action: 'reject',
|
|
286
|
+
severity: 'high',
|
|
287
|
+
violations: [
|
|
288
|
+
{
|
|
289
|
+
type: 'unauthorized_tool',
|
|
290
|
+
severity: 'high',
|
|
291
|
+
description: reason,
|
|
292
|
+
},
|
|
293
|
+
],
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
return { block: true, reason, terminate: false };
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
234
300
|
if (harness.security) {
|
|
235
301
|
const toolCheck = harness.security.checkToolCall(ctx.toolCall);
|
|
236
302
|
if (!toolCheck.isClean) {
|
|
@@ -368,6 +434,7 @@ export async function* runAgentWithReliability(context, config, harness, signal)
|
|
|
368
434
|
role: 'user',
|
|
369
435
|
content: `[System: ${relConfig.planningRetry.steerInstruction}]`,
|
|
370
436
|
timestamp: Date.now(),
|
|
437
|
+
metadata: { source: 'engineHint' },
|
|
371
438
|
});
|
|
372
439
|
state.planningOnlySteerInjected = true;
|
|
373
440
|
}
|
|
@@ -386,6 +453,7 @@ export async function* runAgentWithReliability(context, config, harness, signal)
|
|
|
386
453
|
role: 'user',
|
|
387
454
|
content: `[System: ${relConfig.emptyResponseRetry.steerInstruction}]`,
|
|
388
455
|
timestamp: Date.now(),
|
|
456
|
+
metadata: { source: 'engineHint' },
|
|
389
457
|
});
|
|
390
458
|
state.emptyResponseSteerInjected = true;
|
|
391
459
|
}
|
|
@@ -406,12 +474,18 @@ export async function* runAgentWithReliability(context, config, harness, signal)
|
|
|
406
474
|
role: 'user',
|
|
407
475
|
content: '[System: Multiple tool calls produced no result. Please try a different approach.]',
|
|
408
476
|
timestamp: Date.now(),
|
|
477
|
+
metadata: { source: 'engineHint' },
|
|
409
478
|
});
|
|
410
479
|
}
|
|
411
480
|
else {
|
|
412
481
|
// 超过阈值:标记停止 + 立即检查点
|
|
413
482
|
state._noopLoopStop = true;
|
|
414
483
|
state.forceCheckpoint = true;
|
|
484
|
+
// 停止必须可见:只置标志不发声时,用户看到的就是「跑着跑着没了」
|
|
485
|
+
state.runGuardStop = {
|
|
486
|
+
reason: `连续 ${state.consecutiveNoops} 次工具调用无任何返回(no-op 循环)`,
|
|
487
|
+
userMessage: `连续 ${state.consecutiveNoops} 次工具调用没有任何结果,判定为无效循环,本轮已停止。请换个做法或说明当前阻塞点。`,
|
|
488
|
+
};
|
|
415
489
|
state.collector.noteExternalSignal({
|
|
416
490
|
source: 'noop',
|
|
417
491
|
level: 'critical',
|
|
@@ -425,7 +499,19 @@ export async function* runAgentWithReliability(context, config, harness, signal)
|
|
|
425
499
|
state.consecutiveNoops = 0;
|
|
426
500
|
}
|
|
427
501
|
// 4. 工具循环检测
|
|
428
|
-
|
|
502
|
+
const loopDetectionEnabled = relConfig.loopDetection.enabled !== false;
|
|
503
|
+
// 4a. 指标记录与 loopDetection 开关解耦:RunGuard 的 repeated/identical 判据
|
|
504
|
+
// 不能因为关掉 loopDetection 就永远为 0(否则 Guard 静默失效)。
|
|
505
|
+
for (const result of ctx.toolResults) {
|
|
506
|
+
const tc = ctx.message.toolCalls?.find(t => t.id === result.toolCallId);
|
|
507
|
+
state.collector.recordToolResult(result.name, !result.isError, !!result.noop, {
|
|
508
|
+
// 与旁路 loop 检测器同口径:arguments 缺失时归一为 {}
|
|
509
|
+
args: tc?.arguments ?? {},
|
|
510
|
+
result: result.isError ? undefined : result.content,
|
|
511
|
+
error: result.isError ? result.content : undefined,
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
if (hasToolCalls && loopDetectionEnabled) {
|
|
429
515
|
// 记录工具调用
|
|
430
516
|
for (const result of ctx.toolResults) {
|
|
431
517
|
// 从 message.toolCalls 中找到对应的 toolCall
|
|
@@ -450,6 +536,11 @@ export async function* runAgentWithReliability(context, config, harness, signal)
|
|
|
450
536
|
if (state.loopCriticalTriggered) {
|
|
451
537
|
// 二次 critical:通过 shouldStopAfterTurn 停止
|
|
452
538
|
state._loopCriticalTwice = true;
|
|
539
|
+
// 停止必须可见:与 RunGuard 走同一事件通道
|
|
540
|
+
state.runGuardStop = {
|
|
541
|
+
reason: `连续两轮检测到高危循环信号:${loopResult.message}`,
|
|
542
|
+
userMessage: '检测到重复的高危循环迹象,本轮已停止。请换个做法或说明当前阻塞点。',
|
|
543
|
+
};
|
|
453
544
|
}
|
|
454
545
|
else {
|
|
455
546
|
state.loopCriticalTriggered = true;
|
|
@@ -457,6 +548,7 @@ export async function* runAgentWithReliability(context, config, harness, signal)
|
|
|
457
548
|
role: 'user',
|
|
458
549
|
content: `[System: ${loopResult.message} Stop calling tools and provide your final response based on the information gathered so far.]`,
|
|
459
550
|
timestamp: Date.now(),
|
|
551
|
+
metadata: { source: 'engineHint' },
|
|
460
552
|
});
|
|
461
553
|
}
|
|
462
554
|
}
|
|
@@ -465,14 +557,11 @@ export async function* runAgentWithReliability(context, config, harness, signal)
|
|
|
465
557
|
role: 'user',
|
|
466
558
|
content: `[System: ${loopResult.message}]`,
|
|
467
559
|
timestamp: Date.now(),
|
|
560
|
+
metadata: { source: 'engineHint' },
|
|
468
561
|
});
|
|
469
562
|
}
|
|
470
563
|
}
|
|
471
564
|
}
|
|
472
|
-
// 更新追踪指标
|
|
473
|
-
for (const result of ctx.toolResults) {
|
|
474
|
-
state.collector.recordToolResult(result.name, !result.isError, !!result.noop);
|
|
475
|
-
}
|
|
476
565
|
}
|
|
477
566
|
// 5. RunGuard 检查点(周期 + 高危即时)
|
|
478
567
|
if (harness.runGuard) {
|
|
@@ -900,6 +989,7 @@ function executeRecoveryActions(actions, messages) {
|
|
|
900
989
|
role: 'user',
|
|
901
990
|
content: `[System: ${removeCount} earlier messages omitted to fit context window.]`,
|
|
902
991
|
timestamp: Date.now(),
|
|
992
|
+
metadata: { source: 'engineHint' },
|
|
903
993
|
});
|
|
904
994
|
}
|
|
905
995
|
break;
|
|
@@ -920,6 +1010,7 @@ function executeRecoveryActions(actions, messages) {
|
|
|
920
1010
|
role: 'user',
|
|
921
1011
|
content: `[System: ${removed} recent messages cleared to recover from a stuck loop.]`,
|
|
922
1012
|
timestamp: Date.now(),
|
|
1013
|
+
metadata: { source: 'engineHint' },
|
|
923
1014
|
});
|
|
924
1015
|
}
|
|
925
1016
|
break;
|
|
@@ -929,6 +1020,7 @@ function executeRecoveryActions(actions, messages) {
|
|
|
929
1020
|
role: 'user',
|
|
930
1021
|
content: `[System: ${action.hint}]`,
|
|
931
1022
|
timestamp: Date.now(),
|
|
1023
|
+
metadata: { source: 'engineHint' },
|
|
932
1024
|
});
|
|
933
1025
|
break;
|
|
934
1026
|
}
|
|
@@ -21,7 +21,13 @@ export declare class RunMetricsCollector {
|
|
|
21
21
|
private nominalTotalTokens;
|
|
22
22
|
private lastToolName;
|
|
23
23
|
private consecutiveSameTool;
|
|
24
|
+
/** 上一次调用的「名+参数+结果」指纹;用于识别真正无进展的重复 */
|
|
25
|
+
private lastCallFingerprint;
|
|
26
|
+
private consecutiveIdenticalCalls;
|
|
24
27
|
private consecutiveErrors;
|
|
28
|
+
/** 上一次失败调用的「名+参数+错误」指纹;用于识别同一错误反复重试 */
|
|
29
|
+
private lastFailureFingerprint;
|
|
30
|
+
private consecutiveIdenticalFailures;
|
|
25
31
|
private uniqueTools;
|
|
26
32
|
private recentToolCalls;
|
|
27
33
|
private turnSummaries;
|
|
@@ -35,8 +41,26 @@ export declare class RunMetricsCollector {
|
|
|
35
41
|
recordTurn(summary: TurnSummary): void;
|
|
36
42
|
/** 记录本轮 token 消耗(与 Budget 共用 turn_end.usage) */
|
|
37
43
|
recordTokens(delta: number): void;
|
|
38
|
-
/**
|
|
39
|
-
|
|
44
|
+
/**
|
|
45
|
+
* 记录工具结果
|
|
46
|
+
*
|
|
47
|
+
* 两套计数刻意分开:
|
|
48
|
+
* - `consecutiveSameTool`:只看工具名(弱信号,仅观测)
|
|
49
|
+
* - `consecutiveIdenticalCalls`:名 + 参数 + 结果三者一致(无进展的强信号)
|
|
50
|
+
*
|
|
51
|
+
* 编码类 run 会连续调用同一工具但参数各不相同(改一行→跑一次 typecheck),
|
|
52
|
+
* 只看工具名会把它误判成死循环。
|
|
53
|
+
*
|
|
54
|
+
* @param name - 工具名
|
|
55
|
+
* @param success - 是否成功
|
|
56
|
+
* @param isNoop - 是否 no-op(无实际改动)
|
|
57
|
+
* @param trace - 本次调用的参数与结果(用于指纹;缺省则不计入相同调用)
|
|
58
|
+
*/
|
|
59
|
+
recordToolResult(name: string, success: boolean, isNoop?: boolean, trace?: {
|
|
60
|
+
args?: unknown;
|
|
61
|
+
result?: unknown;
|
|
62
|
+
error?: unknown;
|
|
63
|
+
}): void;
|
|
40
64
|
/** 本轮是否实质进展(Budget 续租 + Guard 规则共用) */
|
|
41
65
|
hasProgress(): boolean;
|
|
42
66
|
recordRecovery(attempt: RecoveryAttempt): void;
|
|
@@ -67,7 +91,9 @@ export declare class RunMetricsCollector {
|
|
|
67
91
|
nominalTotalTokens: number;
|
|
68
92
|
elapsedMs: number;
|
|
69
93
|
consecutiveErrors: number;
|
|
94
|
+
consecutiveIdenticalFailures: number;
|
|
70
95
|
consecutiveSameTool: number;
|
|
96
|
+
consecutiveIdenticalCalls: number;
|
|
71
97
|
noopStreak: number;
|
|
72
98
|
hasProgress: boolean;
|
|
73
99
|
uniqueTools: string[];
|
|
@@ -4,6 +4,36 @@
|
|
|
4
4
|
* 归属 reliability(实现);Guard 只依赖 Core 的 CheckpointContext 类型。
|
|
5
5
|
* 禁止:reliability → run-guard 实现包。
|
|
6
6
|
*/
|
|
7
|
+
import { hashToolCall, hashToolOutcome } from '../concurrency/tool-loop-detection-core.js';
|
|
8
|
+
/**
|
|
9
|
+
* 指纹前剥掉「每次必然不同」的元数据字段
|
|
10
|
+
*
|
|
11
|
+
* `shell` 的结果对象带 `durationMs`、`rawStdoutLength`、`isolation`(含随机沙箱 profile
|
|
12
|
+
* 路径与临时目录名)——它们让同一条命令的两次调用结果永远不相等,指纹判据会整体失效。
|
|
13
|
+
* 只用于「无进展重复」判据,不改动工具返回值本身,也不影响既有 loop 检测器的语义。
|
|
14
|
+
*/
|
|
15
|
+
const VOLATILE_OUTCOME_KEYS = new Set([
|
|
16
|
+
'durationMs',
|
|
17
|
+
'elapsedMs',
|
|
18
|
+
'rawStdoutLength',
|
|
19
|
+
'rawLength',
|
|
20
|
+
'isolation',
|
|
21
|
+
'terminated',
|
|
22
|
+
'terminateReason',
|
|
23
|
+
]);
|
|
24
|
+
function stripVolatileOutcome(value, depth = 0) {
|
|
25
|
+
if (depth > 6 || value === null || typeof value !== 'object')
|
|
26
|
+
return value;
|
|
27
|
+
if (Array.isArray(value))
|
|
28
|
+
return value.map((v) => stripVolatileOutcome(v, depth + 1));
|
|
29
|
+
const out = {};
|
|
30
|
+
for (const [k, v] of Object.entries(value)) {
|
|
31
|
+
if (VOLATILE_OUTCOME_KEYS.has(k))
|
|
32
|
+
continue;
|
|
33
|
+
out[k] = stripVolatileOutcome(v, depth + 1);
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
7
37
|
const SUMMARIES_MAX = 8;
|
|
8
38
|
const RECENT_TOOLS_MAX = 10;
|
|
9
39
|
const TOKEN_WINDOW = 10;
|
|
@@ -14,7 +44,13 @@ export class RunMetricsCollector {
|
|
|
14
44
|
nominalTotalTokens = 0;
|
|
15
45
|
lastToolName = '';
|
|
16
46
|
consecutiveSameTool = 0;
|
|
47
|
+
/** 上一次调用的「名+参数+结果」指纹;用于识别真正无进展的重复 */
|
|
48
|
+
lastCallFingerprint = '';
|
|
49
|
+
consecutiveIdenticalCalls = 0;
|
|
17
50
|
consecutiveErrors = 0;
|
|
51
|
+
/** 上一次失败调用的「名+参数+错误」指纹;用于识别同一错误反复重试 */
|
|
52
|
+
lastFailureFingerprint = '';
|
|
53
|
+
consecutiveIdenticalFailures = 0;
|
|
18
54
|
uniqueTools = new Set();
|
|
19
55
|
recentToolCalls = [];
|
|
20
56
|
turnSummaries = [];
|
|
@@ -47,8 +83,22 @@ export class RunMetricsCollector {
|
|
|
47
83
|
if (last)
|
|
48
84
|
last.tokenDelta += delta;
|
|
49
85
|
}
|
|
50
|
-
/**
|
|
51
|
-
|
|
86
|
+
/**
|
|
87
|
+
* 记录工具结果
|
|
88
|
+
*
|
|
89
|
+
* 两套计数刻意分开:
|
|
90
|
+
* - `consecutiveSameTool`:只看工具名(弱信号,仅观测)
|
|
91
|
+
* - `consecutiveIdenticalCalls`:名 + 参数 + 结果三者一致(无进展的强信号)
|
|
92
|
+
*
|
|
93
|
+
* 编码类 run 会连续调用同一工具但参数各不相同(改一行→跑一次 typecheck),
|
|
94
|
+
* 只看工具名会把它误判成死循环。
|
|
95
|
+
*
|
|
96
|
+
* @param name - 工具名
|
|
97
|
+
* @param success - 是否成功
|
|
98
|
+
* @param isNoop - 是否 no-op(无实际改动)
|
|
99
|
+
* @param trace - 本次调用的参数与结果(用于指纹;缺省则不计入相同调用)
|
|
100
|
+
*/
|
|
101
|
+
recordToolResult(name, success, isNoop = false, trace) {
|
|
52
102
|
this.totalToolCalls++;
|
|
53
103
|
if (name === this.lastToolName) {
|
|
54
104
|
this.consecutiveSameTool++;
|
|
@@ -57,12 +107,31 @@ export class RunMetricsCollector {
|
|
|
57
107
|
this.consecutiveSameTool = 1;
|
|
58
108
|
this.lastToolName = name;
|
|
59
109
|
}
|
|
110
|
+
if (trace) {
|
|
111
|
+
const fingerprint = [
|
|
112
|
+
hashToolCall(name, trace.args),
|
|
113
|
+
hashToolOutcome(name, trace.args, stripVolatileOutcome(trace.result), trace.error) ?? '',
|
|
114
|
+
].join('|');
|
|
115
|
+
if (fingerprint === this.lastCallFingerprint) {
|
|
116
|
+
this.consecutiveIdenticalCalls++;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
this.consecutiveIdenticalCalls = 1;
|
|
120
|
+
this.lastCallFingerprint = fingerprint;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
this.consecutiveIdenticalCalls = 0;
|
|
125
|
+
this.lastCallFingerprint = '';
|
|
126
|
+
}
|
|
60
127
|
this.uniqueTools.add(name);
|
|
61
128
|
this.recentToolCalls.push({ name, success });
|
|
62
129
|
if (this.recentToolCalls.length > RECENT_TOOLS_MAX)
|
|
63
130
|
this.recentToolCalls.shift();
|
|
64
131
|
if (success) {
|
|
65
132
|
this.consecutiveErrors = 0;
|
|
133
|
+
this.consecutiveIdenticalFailures = 0;
|
|
134
|
+
this.lastFailureFingerprint = '';
|
|
66
135
|
if (!isNoop) {
|
|
67
136
|
this.lastSuccessAt = this.globalIteration;
|
|
68
137
|
this.noopStreak = 0;
|
|
@@ -70,6 +139,22 @@ export class RunMetricsCollector {
|
|
|
70
139
|
}
|
|
71
140
|
else {
|
|
72
141
|
this.consecutiveErrors++;
|
|
142
|
+
// 错误是否「重复」:同工具 + 同参数 + 同错误内容。
|
|
143
|
+
// 连续失败但每次错误不同(跑测试 A 红 → 修 → 跑测试 B 红)属于探索,
|
|
144
|
+
// 不是卡住;只有同一错误反复出现才说明重试没有换方法。
|
|
145
|
+
const failureFingerprint = trace
|
|
146
|
+
? [
|
|
147
|
+
hashToolCall(name, trace.args),
|
|
148
|
+
hashToolOutcome(name, trace.args, undefined, stripVolatileOutcome(trace.error)) ?? '',
|
|
149
|
+
].join('|')
|
|
150
|
+
: '';
|
|
151
|
+
if (failureFingerprint && failureFingerprint === this.lastFailureFingerprint) {
|
|
152
|
+
this.consecutiveIdenticalFailures++;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
this.consecutiveIdenticalFailures = failureFingerprint ? 1 : 0;
|
|
156
|
+
this.lastFailureFingerprint = failureFingerprint;
|
|
157
|
+
}
|
|
73
158
|
}
|
|
74
159
|
if (isNoop)
|
|
75
160
|
this.noopStreak++;
|
|
@@ -144,9 +229,12 @@ export class RunMetricsCollector {
|
|
|
144
229
|
}
|
|
145
230
|
const metrics = {
|
|
146
231
|
consecutiveErrors: this.consecutiveErrors,
|
|
232
|
+
consecutiveIdenticalFailures: this.consecutiveIdenticalFailures,
|
|
147
233
|
consecutiveSameTool: this.consecutiveSameTool,
|
|
234
|
+
consecutiveIdenticalCalls: this.consecutiveIdenticalCalls,
|
|
148
235
|
tokenGrowthRate,
|
|
149
236
|
toolFailureRate,
|
|
237
|
+
toolCallsInWindow: this.recentToolCalls.length,
|
|
150
238
|
uniqueToolsUsed: this.uniqueTools.size,
|
|
151
239
|
hasProgress: this.hasProgress(),
|
|
152
240
|
noopStreak: this.noopStreak,
|
|
@@ -183,7 +271,9 @@ export class RunMetricsCollector {
|
|
|
183
271
|
nominalTotalTokens: this.nominalTotalTokens,
|
|
184
272
|
elapsedMs: Date.now() - this.startTime,
|
|
185
273
|
consecutiveErrors: this.consecutiveErrors,
|
|
274
|
+
consecutiveIdenticalFailures: this.consecutiveIdenticalFailures,
|
|
186
275
|
consecutiveSameTool: this.consecutiveSameTool,
|
|
276
|
+
consecutiveIdenticalCalls: this.consecutiveIdenticalCalls,
|
|
187
277
|
noopStreak: this.noopStreak,
|
|
188
278
|
hasProgress: this.hasProgress(),
|
|
189
279
|
uniqueTools: [...this.uniqueTools],
|
|
@@ -46,11 +46,6 @@ export interface RunGuardConfig {
|
|
|
46
46
|
/** 每次检查点的回调(可用于日志、监控、用户通知) */
|
|
47
47
|
onCheckpoint?: (ctx: CheckpointContext, verdict: CheckpointVerdict) => void;
|
|
48
48
|
}
|
|
49
|
-
/**
|
|
50
|
-
* DefaultRunGuard
|
|
51
|
-
*
|
|
52
|
-
* 两层智能监督:规则检测 + LLM 审查
|
|
53
|
-
*/
|
|
54
49
|
export declare class DefaultRunGuard implements RunGuard {
|
|
55
50
|
private config;
|
|
56
51
|
private model?;
|
|
@@ -30,6 +30,19 @@ const DEFAULT_CONFIG = {
|
|
|
30
30
|
*
|
|
31
31
|
* 两层智能监督:规则检测 + LLM 审查
|
|
32
32
|
*/
|
|
33
|
+
/** 指标生产者未提供 consecutiveIdenticalCalls 时只告警一次(防日志刷屏) */
|
|
34
|
+
let warnedMissingIdenticalMetric = false;
|
|
35
|
+
/** 指标生产者未提供 toolCallsInWindow 时只告警一次 */
|
|
36
|
+
let warnedMissingWindowMetric = false;
|
|
37
|
+
/** 指标生产者未提供 consecutiveIdenticalFailures 时只告警一次 */
|
|
38
|
+
let warnedMissingFailureMetric = false;
|
|
39
|
+
/**
|
|
40
|
+
* 连续工具失败兜底阈值(错误内容各不相同时)
|
|
41
|
+
*
|
|
42
|
+
* 取高位:正常调试节奏是「跑测试红 → 改 → 再跑」,3~5 次连续失败很常见;
|
|
43
|
+
* 8 次连续失败且一次都没成功,更像是工具/环境整体不可用,而不是在探索。
|
|
44
|
+
*/
|
|
45
|
+
const ERROR_STREAK_SAFETY = 8;
|
|
33
46
|
export class DefaultRunGuard {
|
|
34
47
|
config;
|
|
35
48
|
model;
|
|
@@ -183,78 +196,125 @@ export class DefaultRunGuard {
|
|
|
183
196
|
],
|
|
184
197
|
});
|
|
185
198
|
}
|
|
186
|
-
// 规则 1:
|
|
187
|
-
|
|
199
|
+
// 规则 1: 无进展重复调用
|
|
200
|
+
//
|
|
201
|
+
// 判据只能是「工具名 + 参数 + 结果」三者一致(consecutiveIdenticalCalls):
|
|
202
|
+
// 编码类 run 会连续多次调用 shell / file_edit,但每次参数不同(改一行→跑一次
|
|
203
|
+
// typecheck→再改),这属于正常推进。只看工具名的旧判据会把它误判为死循环,
|
|
204
|
+
// 连续 3 次 recover 后升级为 stop,把正常任务静默掐断。
|
|
205
|
+
//
|
|
206
|
+
// 纯「同名不同参」不再产生规则结果:裁决只消费 high/medium(见 checkpoint),
|
|
207
|
+
// 造一条 low 规则是死代码。需要观测时看 run_guard_metrics 的 consecutiveSameTool。
|
|
208
|
+
const identicalCalls = m.consecutiveIdenticalCalls;
|
|
209
|
+
if (identicalCalls === undefined && !warnedMissingIdenticalMetric) {
|
|
210
|
+
// 指标生产者未升级时判据会静默空转;宁可漏报也不能退回「同名即循环」的误杀。
|
|
211
|
+
warnedMissingIdenticalMetric = true;
|
|
212
|
+
console.warn('[RunGuard] CheckpointMetrics.consecutiveIdenticalCalls 缺失,repeated_identical_call 判据暂不生效');
|
|
213
|
+
}
|
|
214
|
+
if ((identicalCalls ?? 0) >= 5) {
|
|
188
215
|
results.push({
|
|
189
216
|
triggered: true,
|
|
190
217
|
severity: 'high',
|
|
191
|
-
rule: '
|
|
192
|
-
description: `连续 ${
|
|
218
|
+
rule: 'repeated_identical_call',
|
|
219
|
+
description: `连续 ${identicalCalls} 次相同调用(同一工具、同一参数、同一结果),无进展`,
|
|
193
220
|
failureKind: 'loop',
|
|
194
|
-
suggestedRecovery: [{ type: 'inject_hint', hint: '
|
|
221
|
+
suggestedRecovery: [{ type: 'inject_hint', hint: '你的调用参数与结果都没有变化,说明这个方法无法推进。请改变做法,或向用户报告当前阻塞点。' }],
|
|
195
222
|
});
|
|
196
223
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
224
|
+
// 规则 2: 错误循环 —— 判「错误是否重复」,不是「失败了几次」
|
|
225
|
+
//
|
|
226
|
+
// 旧判据 `consecutiveErrors >= 3` 只看连续失败次数:跑测试 A 红 → 改 → 跑测试 B 红
|
|
227
|
+
// → 改 → 跑测试 C 红,三次失败但每次错误都不同,这是正常调试节奏(红-改-绿循环),
|
|
228
|
+
// 却被判 high/blowup → recover,同 kind 连续 3 次后升级 stop。
|
|
229
|
+
//
|
|
230
|
+
// 「卡住」的真实特征是**同一个错误反复出现**:同一工具、同一参数、同一错误内容,
|
|
231
|
+
// 说明重试没有换方法。故判据改为 consecutiveIdenticalFailures。
|
|
232
|
+
//
|
|
233
|
+
// 保留一条兜底:完全不同错误也可能整体失败(例如工具被全局配置坏掉),
|
|
234
|
+
// 用较高的阈值兜住,普通调试节奏(3 个红测试)远达不到。
|
|
235
|
+
const identicalFailures = m.consecutiveIdenticalFailures;
|
|
236
|
+
if (identicalFailures === undefined && !warnedMissingFailureMetric) {
|
|
237
|
+
warnedMissingFailureMetric = true;
|
|
238
|
+
console.warn('[RunGuard] CheckpointMetrics.consecutiveIdenticalFailures 缺失,error_loop 判据退化为连续失败兜底');
|
|
205
239
|
}
|
|
206
|
-
|
|
207
|
-
if (m.consecutiveErrors >= 3) {
|
|
240
|
+
if ((identicalFailures ?? 0) >= 3) {
|
|
208
241
|
results.push({
|
|
209
242
|
triggered: true,
|
|
210
243
|
severity: 'high',
|
|
211
244
|
rule: 'error_loop',
|
|
212
|
-
description:
|
|
245
|
+
description: `同一错误连续 ${identicalFailures} 次(工具、参数、错误内容均未变化),重试没有换方法`,
|
|
213
246
|
failureKind: 'blowup',
|
|
214
|
-
suggestedRecovery: [{ type: 'inject_hint', hint: '
|
|
247
|
+
suggestedRecovery: [{ type: 'inject_hint', hint: '你正在用同样的方式重试同一个失败。请改变做法:读完整错误信息、检查前提假设,或者换个工具/思路;确实解决不了就向用户报告。' }],
|
|
215
248
|
});
|
|
216
249
|
}
|
|
217
|
-
else if (
|
|
250
|
+
else if ((identicalFailures ?? 0) >= 2) {
|
|
218
251
|
results.push({
|
|
219
252
|
triggered: true,
|
|
220
253
|
severity: 'medium',
|
|
221
254
|
rule: 'error_loop',
|
|
222
|
-
description:
|
|
255
|
+
description: `同一错误连续 ${identicalFailures} 次`,
|
|
223
256
|
failureKind: 'blowup',
|
|
224
257
|
});
|
|
225
258
|
}
|
|
226
|
-
|
|
227
|
-
|
|
259
|
+
else if (m.consecutiveErrors >= ERROR_STREAK_SAFETY) {
|
|
260
|
+
// 连续失败但错误各不相同:可能是探索,也可能整体环境坏了。兜底阈值取高位。
|
|
228
261
|
results.push({
|
|
229
262
|
triggered: true,
|
|
230
|
-
severity: '
|
|
231
|
-
rule: '
|
|
232
|
-
description:
|
|
233
|
-
failureKind: '
|
|
234
|
-
suggestedRecovery: [{ type: 'inject_hint', hint: '
|
|
263
|
+
severity: 'high',
|
|
264
|
+
rule: 'error_streak',
|
|
265
|
+
description: `连续 ${m.consecutiveErrors} 次工具调用失败(错误内容各不相同)`,
|
|
266
|
+
failureKind: 'blowup',
|
|
267
|
+
suggestedRecovery: [{ type: 'inject_hint', hint: '你已经连续多次工具调用失败。请先确认工具本身可用(最小示例验证),或向用户报告当前环境问题。' }],
|
|
235
268
|
});
|
|
236
269
|
}
|
|
237
|
-
// 规则
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
270
|
+
// 规则 3: 工具失败率高 —— 只有「高失败率 + 完全无推进」才算 thrash
|
|
271
|
+
//
|
|
272
|
+
// 失败率高本身不是行为异常:编码类 run 里跑测试/编译得红是工作的组成部分
|
|
273
|
+
// (先写失败用例再实现、按错误信息反复调试),失败的调用与成功的编辑交替出现,
|
|
274
|
+
// hasProgress 为 true。旧判据只看 `toolFailureRate > 0.5`,会把这类正常 turn
|
|
275
|
+
// 判成 thrash → recover;同 kind 连续 3 次 recover 时还会 `clear_recent_turns`,
|
|
276
|
+
// 把 agent 刚做完的进度从上下文里抹掉,比直接 stop 更隐蔽。
|
|
277
|
+
//
|
|
278
|
+
// 真正的 thrash 特征是「失败没有换来任何推进」:窗口内失败占比过半,
|
|
279
|
+
// 且最近三轮没有任何成功工具或实质文本。
|
|
280
|
+
//
|
|
281
|
+
// 另需样本量下限:失败率是比值,只调用 2 次且都失败也是 100%,不构成证据。
|
|
282
|
+
const windowCalls = m.toolCallsInWindow;
|
|
283
|
+
if (windowCalls === undefined && !warnedMissingWindowMetric) {
|
|
284
|
+
warnedMissingWindowMetric = true;
|
|
285
|
+
console.warn('[RunGuard] CheckpointMetrics.toolCallsInWindow 缺失,high_failure_rate 判据暂不生效');
|
|
247
286
|
}
|
|
248
|
-
|
|
249
|
-
|
|
287
|
+
if (m.toolFailureRate > 0.5 &&
|
|
288
|
+
(windowCalls ?? 0) >= 5 &&
|
|
289
|
+
!m.hasProgress &&
|
|
290
|
+
ctx.recentSummaries.length >= 3) {
|
|
250
291
|
results.push({
|
|
251
292
|
triggered: true,
|
|
252
|
-
severity:
|
|
253
|
-
rule: '
|
|
254
|
-
description:
|
|
255
|
-
failureKind: '
|
|
293
|
+
severity: 'medium',
|
|
294
|
+
rule: 'high_failure_rate',
|
|
295
|
+
description: `工具失败率 ${(m.toolFailureRate * 100).toFixed(0)}%(窗口 ${windowCalls} 次)且最近无进展`,
|
|
296
|
+
failureKind: 'thrash',
|
|
297
|
+
suggestedRecovery: [{ type: 'inject_hint', hint: '最近的工具调用大量失败,且没有取得任何进展。请停下来定位失败根因(读完整错误信息、确认前提假设是否正确),或向用户报告当前阻塞点。' }],
|
|
256
298
|
});
|
|
257
299
|
}
|
|
300
|
+
// 规则 4(token_growth)与规则 5(no_progress)已移除,原因分别是判据错位与功能重复:
|
|
301
|
+
//
|
|
302
|
+
// - 旧规则 4 用 `tokenGrowthRate > 0.5` 判「上下文膨胀」,但该指标是
|
|
303
|
+
// 「最近半窗 token 消耗 ÷ 前一半 − 1」,衡量的是**消耗增速**而非上下文**绝对大小**。
|
|
304
|
+
// 实测两个长 turn 的上下文分别涨到 10 倍和 2 倍,该值仅 0.08 / 0.03 —— 真正的膨胀
|
|
305
|
+
// 它看不见;对「单轮读了个大文件」这种正常工作反而敏感。
|
|
306
|
+
// 而它想管的事已由 wrap-up 的 context 轴无条件处理(`relConfig.wrapUp.contextRatio`
|
|
307
|
+
// 默认 0.85,动作为进入收尾模式、让 agent 输出结论),比 `truncate_context` 更好:
|
|
308
|
+
// 后者用 `messages.splice()` 整段替换历史中部,会打穿前缀缓存(B0 红线)。
|
|
309
|
+
// `tokenGrowthRate` 指标本身保留,仅作观测(run_guard_metrics),不参与裁决。
|
|
310
|
+
//
|
|
311
|
+
// - 旧规则 5 的两个分支都不生效:`low` 没有任何消费方(裁决只取 high/medium);
|
|
312
|
+
// `medium` 要求 `noopStreak >= 3`,而 run-agent 在 `consecutiveNoops >= noopThreshold`
|
|
313
|
+
// 时已设置 `_noopLoopStop` 并发出可见停止事件,`shouldStopAfterTurn` 直接结束 turn,
|
|
314
|
+
// 本规则只是重复判定,还会多注入一条 hint、污染 recoveryHistory。
|
|
315
|
+
//
|
|
316
|
+
// 结论:真正需要 Guard 的异常只有三类——同参同结果(无进展循环)、同参同错误(没换方法)、
|
|
317
|
+
// 高失败率且无推进(thrash)。上下文压力归 wrap-up / Budget,noop 归 run-agent。
|
|
258
318
|
return results;
|
|
259
319
|
}
|
|
260
320
|
// ── Layer 2: LLM 审查 ──
|
|
@@ -294,8 +354,8 @@ ${summaryText}${taskLine}${recoveryLine}${signalsLine}
|
|
|
294
354
|
当前指标:
|
|
295
355
|
- 迭代次数: ${ctx.iteration}
|
|
296
356
|
- 连续错误: ${ctx.metrics.consecutiveErrors}
|
|
297
|
-
-
|
|
298
|
-
-
|
|
357
|
+
- 连续同一错误: ${ctx.metrics.consecutiveIdenticalFailures ?? '(未提供)'}
|
|
358
|
+
- 工具失败率: ${(ctx.metrics.toolFailureRate * 100).toFixed(0)}%(窗口 ${ctx.metrics.toolCallsInWindow ?? '?'} 次)
|
|
299
359
|
- 是否有进展: ${ctx.metrics.hasProgress ? '是' : '否'}
|
|
300
360
|
- 使用的不同工具数: ${ctx.metrics.uniqueToolsUsed}
|
|
301
361
|
|