@octopi-agent/engine 0.65.0 → 0.86.38
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 +69 -0
- package/dist/config-schema/context.d.ts +23 -4
- package/dist/config-schema/context.js +28 -1
- package/dist/config-schema/engine.d.ts +285 -9
- package/dist/config-schema/engine.js +35 -3
- package/dist/config-schema/governance.d.ts +95 -0
- package/dist/config-schema/governance.js +91 -0
- package/dist/config-schema/models.d.ts +1 -1
- 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 +10 -0
- package/dist/config-schema/shared.js +10 -0
- package/dist/config-schema/substrate.d.ts +87 -1
- package/dist/config-schema/substrate.js +114 -0
- package/dist/config-schema/subsystems.d.ts +1 -1
- package/dist/config-schema/subsystems.js +2 -1
- package/dist/config.d.ts +249 -7
- package/dist/config.js +113 -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 +48 -4
- package/dist/harness/agent/builder.js +206 -55
- package/dist/harness/agent/config-bridge.d.ts +33 -25
- package/dist/harness/agent/config-bridge.js +83 -280
- 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 +38 -0
- package/dist/harness/agent/tool-purpose.js +118 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +133 -0
- package/dist/harness/agent/wire-agent-builder.js +363 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +4 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +14 -8
- 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/gate.js +2 -2
- package/dist/harness/context/capabilities/summary/policies.js +5 -5
- package/dist/harness/context/capabilities/summary/registry.js +39 -24
- 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-health.js +3 -2
- 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 +49 -1
- package/dist/harness/context/layer-types.js +72 -4
- package/dist/harness/context/layers.d.ts +32 -15
- package/dist/harness/context/layers.js +87 -71
- 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 +33 -0
- package/dist/harness/context/system-prompt-assembler.js +78 -7
- 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 +248 -0
- package/dist/harness/extension/execution-environment/effect-policy.js +334 -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/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 +493 -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 +4 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/index.js +3 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.d.ts +56 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.js +281 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +98 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +250 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/stream.d.ts +124 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/stream.js +372 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.d.ts +118 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.js +8 -0
- 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/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 +45 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +136 -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 +278 -82
- 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 +239 -61
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.d.ts +27 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +554 -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 +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/memory.d.ts +11 -1
- package/dist/harness/extension/plugin-ecosystem/tools/memory.js +39 -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 +18 -15
- package/dist/harness/index.js +11 -7
- 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 +6 -3
- package/dist/harness/knowledge/index.d.ts +2 -2
- package/dist/harness/knowledge/index.js +1 -1
- package/dist/harness/knowledge/ingest.js +4 -1
- package/dist/harness/knowledge/job-control-state.js +4 -4
- package/dist/harness/knowledge/job-control.js +11 -11
- 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/query-service.js +8 -8
- package/dist/harness/knowledge/retriever.js +1 -1
- package/dist/harness/knowledge/source-store.d.ts +17 -2
- package/dist/harness/knowledge/source-store.js +6 -5
- package/dist/harness/knowledge/writer-service.d.ts +2 -0
- package/dist/harness/knowledge/writer-service.js +14 -13
- package/dist/harness/memory/backfill-trigger.d.ts +2 -2
- package/dist/harness/memory/backfill-trigger.js +4 -4
- package/dist/harness/memory/cognition-decay.d.ts +36 -0
- package/dist/harness/memory/cognition-decay.js +55 -0
- package/dist/harness/memory/cognition-gates.d.ts +60 -0
- package/dist/harness/memory/cognition-gates.js +191 -0
- package/dist/harness/memory/cognition-trigger.d.ts +30 -0
- package/dist/harness/memory/cognition-trigger.js +41 -0
- package/dist/harness/memory/cognition-types.d.ts +1 -1
- package/dist/harness/memory/cognition.d.ts +40 -8
- package/dist/harness/memory/cognition.js +432 -79
- package/dist/harness/memory/conceptualizer.d.ts +66 -0
- package/dist/harness/memory/conceptualizer.js +246 -0
- package/dist/harness/memory/index.d.ts +17 -2
- package/dist/harness/memory/index.js +12 -1
- package/dist/harness/memory/sqlite/agent-db.d.ts +9 -0
- package/dist/harness/memory/sqlite/agent-db.js +120 -15
- package/dist/harness/memory/sqlite/cognition-store.d.ts +55 -16
- package/dist/harness/memory/sqlite/cognition-store.js +591 -144
- 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.d.ts +33 -14
- package/dist/harness/memory/sqlite/wisdom-store.js +257 -44
- 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 +343 -16
- package/dist/harness/memory/types.js +49 -0
- package/dist/harness/memory/wisdom-formation.d.ts +101 -0
- package/dist/harness/memory/wisdom-formation.js +304 -0
- package/dist/harness/memory/wisdom-gates.d.ts +50 -0
- package/dist/harness/memory/wisdom-gates.js +204 -0
- package/dist/harness/memory/wisdom-policy.d.ts +107 -0
- package/dist/harness/memory/wisdom-policy.js +220 -0
- package/dist/harness/memory/wisdom-types.d.ts +3 -2
- package/dist/harness/memory/wisdom-types.js +2 -2
- package/dist/harness/memory/wisdom.d.ts +27 -0
- package/dist/harness/memory/wisdom.js +181 -0
- package/dist/harness/observability/observer/hub.js +23 -1
- 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 +57 -0
- package/dist/harness/observability/observer/types.js +118 -9
- package/dist/harness/run/agent/agent.d.ts +27 -0
- package/dist/harness/run/agent/agent.js +45 -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 +116 -20
- 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 +101 -16
- package/dist/harness/run/runner.js +557 -158
- package/dist/harness/session/attachments/llm-intent.js +17 -17
- package/dist/harness/session/history/port.js +1 -0
- package/dist/harness/session/in-memory-store.d.ts +1 -0
- package/dist/harness/session/in-memory-store.js +22 -1
- package/dist/harness/session/index.d.ts +1 -0
- package/dist/harness/session/index.js +1 -0
- 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.d.ts +86 -0
- package/dist/harness/session/title.js +268 -0
- package/dist/harness/session/types.d.ts +35 -0
- package/dist/harness/shared/events/agent-event-map.d.ts +21 -0
- package/dist/harness/shared/events/agent-event-map.js +1 -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/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 +11 -0
- package/dist/integration/storage/jsonl.js +148 -39
- package/dist/integration/storage/session-index.js +63 -8
- package/dist/subsystems/cognition-steward/conceptualize/SUBSYSTEM.md +43 -0
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +50 -0
- package/dist/subsystems/cognition-steward/conceptualize/handler.d.ts +9 -0
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +125 -0
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +6 -0
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +54 -0
- package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +12 -0
- package/dist/subsystems/cognition-steward/consolidate/handler.js +93 -0
- package/dist/subsystems/memory-steward/backfill/handler.js +9 -0
- package/dist/subsystems/wisdom-steward/evaluate/config.yaml +50 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.d.ts +18 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.js +91 -0
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +42 -0
- package/dist/subsystems/wisdom-steward/formation/config.yaml +54 -0
- package/dist/subsystems/wisdom-steward/formation/handler.d.ts +18 -0
- package/dist/subsystems/wisdom-steward/formation/handler.js +212 -0
- package/dist/subsystems/wisdom-steward/govern/config.yaml +55 -0
- package/dist/subsystems/wisdom-steward/govern/handler.d.ts +17 -0
- package/dist/subsystems/wisdom-steward/govern/handler.js +68 -0
- 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
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* 总开关 = `level`:off(**生产/嵌入缺省**)=关;summary/full=开。
|
|
8
8
|
* message 全文只认 payload.messageFullText && retention.messagesPerRun==='full'。
|
|
9
9
|
*/
|
|
10
|
+
import { isChatReplayHidden } from '../../context/layer-types.js';
|
|
11
|
+
import { isTurnStartContent, messageText, parseTurnEnvelope, parseTurnIdFromContent, } from '../../context/turn-envelope.js';
|
|
10
12
|
/**
|
|
11
13
|
* 未写 observer 时的解析结果 = level 预设 `off`
|
|
12
14
|
* (生产/嵌入缺省不采集;开发在 octopi.json 显式 summary/full)
|
|
@@ -182,10 +184,92 @@ export function shouldCaptureMessageFullText(cfg) {
|
|
|
182
184
|
cfg.payload.messageFullText === true &&
|
|
183
185
|
cfg.retention.messagesPerRun === 'full');
|
|
184
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Run message 归因(G2/G4 唯一判定处)。
|
|
189
|
+
*
|
|
190
|
+
* 判定次序:**source 优先、内容兜底**——
|
|
191
|
+
* ① role 二值(assistant/tool)→ ② 引擎载体 source(turnEnd / 载体插槽 / contextSummary / engineHint,
|
|
192
|
+
* 语义真源 `harness/context/layer-types.ts` ENGINE_CARRIER_SOURCES)→ ③ system role →
|
|
193
|
+
* ④ 无 source + user role + 正文以信封开标签起头 = turn_envelope → ⑤ 其余 user_speech。
|
|
194
|
+
*
|
|
195
|
+
* source 优先是审计面的可靠性要求:载体消息正文来自不可信语料(知识/grounding/附件),
|
|
196
|
+
* 含信封字面量也不得被内容嗅探抢走归因(否则机器插槽挂上「用户发言」徽章)。
|
|
197
|
+
* turn_end 的内容兜底仅作 legacy 降级:无 source 且整条正文就是闭标形状才认。
|
|
198
|
+
*
|
|
199
|
+
* @param msg - 消息(role/content/metadata)
|
|
200
|
+
* @returns 归因
|
|
201
|
+
*/
|
|
202
|
+
export function attributeRunMessage(msg) {
|
|
203
|
+
const role = (msg.role ?? 'user');
|
|
204
|
+
const source = msg.metadata?.source;
|
|
205
|
+
const base = source !== undefined ? { source } : {};
|
|
206
|
+
// ① 模型/工具输出
|
|
207
|
+
if (role === 'assistant')
|
|
208
|
+
return { speaker: 'llm', kind: 'assistant', ...base };
|
|
209
|
+
if (role === 'tool')
|
|
210
|
+
return { speaker: 'tool', kind: 'tool', ...base };
|
|
211
|
+
// ② 引擎载体语义(source 是机器插槽的一等标识,先于一切内容嗅探)
|
|
212
|
+
if (source === 'turnEnd') {
|
|
213
|
+
return {
|
|
214
|
+
speaker: 'engine',
|
|
215
|
+
kind: 'turn_end',
|
|
216
|
+
turnId: parseTurnIdFromContent(msg.content),
|
|
217
|
+
...base,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
if (source === 'runtimeSnapshot' ||
|
|
221
|
+
source === 'knowledgeGrounding' ||
|
|
222
|
+
source === 'sessionAttachment') {
|
|
223
|
+
return { speaker: 'engine', kind: 'carrier', ...base };
|
|
224
|
+
}
|
|
225
|
+
if (source === 'contextSummary')
|
|
226
|
+
return { speaker: 'engine', kind: 'context_summary', ...base };
|
|
227
|
+
if (source === 'engineHint')
|
|
228
|
+
return { speaker: 'engine', kind: 'engine_hint', ...base };
|
|
229
|
+
// ③ system 消息
|
|
230
|
+
if (role === 'system') {
|
|
231
|
+
return {
|
|
232
|
+
speaker: 'engine',
|
|
233
|
+
kind: source === 'systemPrompt' ? 'hosted_system' : 'system',
|
|
234
|
+
...base,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
// ④ 内容兜底(仅无 source 的 user 消息):正文以信封开标签起头 = 已定形 turn 信封
|
|
238
|
+
if (isTurnStartContent(msg.content)) {
|
|
239
|
+
const env = parseTurnEnvelope(msg.content);
|
|
240
|
+
return {
|
|
241
|
+
speaker: 'human',
|
|
242
|
+
kind: 'turn_envelope',
|
|
243
|
+
turnId: env?.turnId,
|
|
244
|
+
...base,
|
|
245
|
+
slots: env?.slots.map((s) => ({ tag: s.tag, chars: s.body.length })),
|
|
246
|
+
userChars: env && env.hasUserMessage ? env.userText.length : 0,
|
|
247
|
+
hasUserMessage: env?.hasUserMessage,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
// legacy 降级:无 source 且整条正文就是闭标形状(用户发言中途回显闭标不算)
|
|
251
|
+
if (source === undefined && isTurnEndShape(msg.content)) {
|
|
252
|
+
return {
|
|
253
|
+
speaker: 'engine',
|
|
254
|
+
kind: 'turn_end',
|
|
255
|
+
turnId: parseTurnIdFromContent(msg.content),
|
|
256
|
+
...base,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
// ⑤ 其余 user 发言(未知 role 落 engine/system,不冒充用户)
|
|
260
|
+
if (role === 'user')
|
|
261
|
+
return { speaker: 'human', kind: 'user_speech', ...base };
|
|
262
|
+
return { speaker: 'engine', kind: 'system', ...base };
|
|
263
|
+
}
|
|
264
|
+
/** 整条正文就是 turn_end 闭标形状(legacy 降级用;用户发言中途回显不命中) */
|
|
265
|
+
function isTurnEndShape(content) {
|
|
266
|
+
return /^\s*<turn_end[\s/>][^<]*\/?>\s*$/.test(messageText(content));
|
|
267
|
+
}
|
|
185
268
|
/** message 摘要统计 */
|
|
186
269
|
export function summarizeMessages(messages, opts) {
|
|
187
270
|
const maxPreview = opts?.maxPreviewChars ?? 200;
|
|
188
271
|
const byRole = {};
|
|
272
|
+
const byKind = {};
|
|
189
273
|
const agentIds = new Set();
|
|
190
274
|
let systemPromptCount = 0;
|
|
191
275
|
let contextSummaryCount = 0;
|
|
@@ -204,6 +288,8 @@ export function summarizeMessages(messages, opts) {
|
|
|
204
288
|
const hidden = isHiddenFromChat(m);
|
|
205
289
|
if (hidden)
|
|
206
290
|
hiddenFromChatCount += 1;
|
|
291
|
+
const attribution = attributeRunMessage(m);
|
|
292
|
+
byKind[attribution.kind] = (byKind[attribution.kind] ?? 0) + 1;
|
|
207
293
|
const text = extractMessageText(m.content);
|
|
208
294
|
chars += text.length;
|
|
209
295
|
return {
|
|
@@ -215,6 +301,7 @@ export function summarizeMessages(messages, opts) {
|
|
|
215
301
|
toolCalls: m.toolCalls,
|
|
216
302
|
toolResults: m.toolResults,
|
|
217
303
|
hiddenFromChat: hidden,
|
|
304
|
+
attribution,
|
|
218
305
|
contentChars: text.length,
|
|
219
306
|
contentPreview: text.slice(0, maxPreview),
|
|
220
307
|
};
|
|
@@ -223,6 +310,7 @@ export function summarizeMessages(messages, opts) {
|
|
|
223
310
|
summary: {
|
|
224
311
|
count: messages.length,
|
|
225
312
|
byRole,
|
|
313
|
+
byKind,
|
|
226
314
|
systemPromptCount,
|
|
227
315
|
contextSummaryCount,
|
|
228
316
|
hiddenFromChatCount,
|
|
@@ -239,14 +327,13 @@ export function summarizeMessages(messages, opts) {
|
|
|
239
327
|
* @returns 是否隐藏
|
|
240
328
|
*/
|
|
241
329
|
export function isHiddenFromChat(msg) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
/AGENTS\.md|Session Startup|Operating Instructions|Agent Persona/i.test(text));
|
|
330
|
+
// D9:判定委托共享谓词 isChatReplayHidden(layer-types),
|
|
331
|
+
// 与 ConversationAdapter.isHiddenSystemHistory 同源,清单不再两份手抄
|
|
332
|
+
return isChatReplayHidden({
|
|
333
|
+
role: msg.role,
|
|
334
|
+
source: msg.metadata?.source,
|
|
335
|
+
text: extractMessageText(msg.content),
|
|
336
|
+
});
|
|
250
337
|
}
|
|
251
338
|
function extractMessageText(content) {
|
|
252
339
|
if (typeof content === 'string')
|
|
@@ -278,7 +365,19 @@ export function attachFullContent(views, messages) {
|
|
|
278
365
|
const m = messages[v.index];
|
|
279
366
|
if (!m)
|
|
280
367
|
return v;
|
|
281
|
-
|
|
368
|
+
const next = { ...v, content: m.content };
|
|
369
|
+
// full 模式补 turn 信封槽位正文(审计入口:这轮模型看到了什么)
|
|
370
|
+
if (v.attribution?.kind === 'turn_envelope') {
|
|
371
|
+
const env = parseTurnEnvelope(m.content);
|
|
372
|
+
if (env) {
|
|
373
|
+
// 整组按解析顺序重建(不用 tag 当查找键:同 tag 双槽位会串正文)
|
|
374
|
+
next.attribution = {
|
|
375
|
+
...v.attribution,
|
|
376
|
+
slots: env.slots.map((s) => ({ tag: s.tag, chars: s.body.length, body: s.body })),
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return next;
|
|
282
381
|
});
|
|
283
382
|
}
|
|
284
383
|
function cloneUnknown(value) {
|
|
@@ -320,15 +419,25 @@ export function cloneMessages(messages) {
|
|
|
320
419
|
*/
|
|
321
420
|
export function summarizeLlmMessages(messages) {
|
|
322
421
|
const byRole = {};
|
|
422
|
+
const byKind = {};
|
|
323
423
|
let chars = 0;
|
|
324
424
|
for (const m of messages) {
|
|
325
425
|
const role = m.role || 'unknown';
|
|
326
426
|
byRole[role] = (byRole[role] ?? 0) + 1;
|
|
427
|
+
// 归因与 workspace 视图同源(LLM 出口消息无 metadata,信封/角色仍可判定)。
|
|
428
|
+
// 已知局限(F10):source 型机器插槽(contextSummary/engineHint)在 LLM 出口丢失 metadata,
|
|
429
|
+
// 只能落 user_speech——byKind 与逐条 attribution 同用本函数,两侧口径一致不互斥
|
|
430
|
+
const attribution = attributeRunMessage({
|
|
431
|
+
role: m.role,
|
|
432
|
+
content: m.content,
|
|
433
|
+
});
|
|
434
|
+
byKind[attribution.kind] = (byKind[attribution.kind] ?? 0) + 1;
|
|
327
435
|
chars += extractMessageText(m.content).length;
|
|
328
436
|
}
|
|
329
437
|
return {
|
|
330
438
|
count: messages.length,
|
|
331
439
|
byRole,
|
|
440
|
+
byKind,
|
|
332
441
|
systemPromptCount: byRole.system ?? 0,
|
|
333
442
|
contextSummaryCount: 0,
|
|
334
443
|
// LLM 出口视图无「对话 UI 隐藏」语义;不把 system 条数冒充 hidden
|
|
@@ -54,6 +54,8 @@ export declare class Agent {
|
|
|
54
54
|
/** sessionId → 压缩状态快照;Runner 从 Session 播种,assemble 后回写 Session */
|
|
55
55
|
private _sessionCompactStates;
|
|
56
56
|
private _onAfterTurn?;
|
|
57
|
+
/** Client Tool 会话可见性;undefined = 全部可见 */
|
|
58
|
+
private _toolVisibilityFilter?;
|
|
57
59
|
constructor(options: AgentOptions);
|
|
58
60
|
get context(): AgentContext;
|
|
59
61
|
get messages(): Message[];
|
|
@@ -65,8 +67,21 @@ export declare class Agent {
|
|
|
65
67
|
*/
|
|
66
68
|
get config(): Readonly<AgentLoopConfig>;
|
|
67
69
|
get harness(): ReliabilityHarness | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* 同步 SecurityGuard 未注册工具硬边界名单。
|
|
72
|
+
* Client Tool 等动态注册会经 setTools 进入 tool 面;若不同步,会被
|
|
73
|
+
* DefaultSecurityGuard 以 unauthorized_tool 拦截。
|
|
74
|
+
*/
|
|
75
|
+
private syncSecurityRegisteredTools;
|
|
68
76
|
registerTool(tool: AgentTool): void;
|
|
69
77
|
setTools(tools: AgentTool[]): void;
|
|
78
|
+
/**
|
|
79
|
+
* 会话级 tool 面可见性(Client Tool:无 live client 则不进 LLM tool 面)。
|
|
80
|
+
* 返回 false 的 tool 对该 session 的 run 隐藏;server tool 不受影响。
|
|
81
|
+
*/
|
|
82
|
+
setToolVisibilityFilter(filter: ((sessionId: string, toolName: string) => boolean) | undefined): void;
|
|
83
|
+
/** 本 session 的 tool 列表(含可见性过滤) */
|
|
84
|
+
toolsForSession(sessionId: string): AgentTool[];
|
|
70
85
|
setModel(model: ModelProvider): void;
|
|
71
86
|
setSystemPrompt(prompt: string): void;
|
|
72
87
|
setHarness(harness: ReliabilityHarness): void;
|
|
@@ -86,6 +101,7 @@ export declare class Agent {
|
|
|
86
101
|
setSessionCompactState(sessionId: string, agentId: string, state: {
|
|
87
102
|
summary?: string;
|
|
88
103
|
lastProactiveMessageCount?: number;
|
|
104
|
+
lastProactiveCoverEnd?: number;
|
|
89
105
|
lastProactiveTokens?: number;
|
|
90
106
|
} | undefined): void;
|
|
91
107
|
/**
|
|
@@ -98,6 +114,7 @@ export declare class Agent {
|
|
|
98
114
|
getSessionCompactState(sessionId: string, agentId: string): {
|
|
99
115
|
summary?: string;
|
|
100
116
|
lastProactiveMessageCount?: number;
|
|
117
|
+
lastProactiveCoverEnd?: number;
|
|
101
118
|
lastProactiveTokens?: number;
|
|
102
119
|
} | undefined;
|
|
103
120
|
/** 每轮结束后通知 ContextEngine(afterTurn 校准等);turn 为本轮增量消息 */
|
|
@@ -106,6 +123,16 @@ export declare class Agent {
|
|
|
106
123
|
notifyAfterTurn(usage?: import('@octopi-agent/core/types/turn.js').TokenUsage, turn?: Message[]): Promise<void>;
|
|
107
124
|
/** 动态替换 convertToLlm(ContextEngine 接线等) */
|
|
108
125
|
setConvertToLlm(fn?: AgentLoopConfig['convertToLlm']): void;
|
|
126
|
+
/**
|
|
127
|
+
* 动态替换 getSteeringMessages(当前 turn 结束后注入的提示)
|
|
128
|
+
*
|
|
129
|
+
* 晚绑定入口:一个 Agent 实例服务多 session,回调必须经
|
|
130
|
+
* `getRunScope()` / `getRunSessionId()` 取**本 Run** 的身份,
|
|
131
|
+
* 不得直接闭包某个 sessionId(否则并发 session 串味,违反 I1)。
|
|
132
|
+
*
|
|
133
|
+
* @param fn - steering 消息提供者;undefined 清除
|
|
134
|
+
*/
|
|
135
|
+
setSteeringMessages(fn?: AgentLoopConfig['getSteeringMessages']): void;
|
|
109
136
|
/** 动态替换 transformContext */
|
|
110
137
|
setTransformContext(fn?: AgentLoopConfig['transformContext']): void;
|
|
111
138
|
/**
|
|
@@ -26,6 +26,8 @@ export class Agent {
|
|
|
26
26
|
/** sessionId → 压缩状态快照;Runner 从 Session 播种,assemble 后回写 Session */
|
|
27
27
|
_sessionCompactStates = new Map();
|
|
28
28
|
_onAfterTurn;
|
|
29
|
+
/** Client Tool 会话可见性;undefined = 全部可见 */
|
|
30
|
+
_toolVisibilityFilter;
|
|
29
31
|
constructor(options) {
|
|
30
32
|
this._context = {
|
|
31
33
|
systemPrompt: options.systemPrompt ?? '',
|
|
@@ -65,11 +67,39 @@ export class Agent {
|
|
|
65
67
|
}
|
|
66
68
|
get harness() { return this._harness; }
|
|
67
69
|
// ── 工具管理 ──
|
|
70
|
+
/**
|
|
71
|
+
* 同步 SecurityGuard 未注册工具硬边界名单。
|
|
72
|
+
* Client Tool 等动态注册会经 setTools 进入 tool 面;若不同步,会被
|
|
73
|
+
* DefaultSecurityGuard 以 unauthorized_tool 拦截。
|
|
74
|
+
*/
|
|
75
|
+
syncSecurityRegisteredTools() {
|
|
76
|
+
const security = this._harness?.security;
|
|
77
|
+
if (!security?.setRegisteredTools)
|
|
78
|
+
return;
|
|
79
|
+
security.setRegisteredTools(new Set(this.tools.map((t) => t.name)));
|
|
80
|
+
}
|
|
68
81
|
registerTool(tool) {
|
|
69
82
|
this._context.tools = [...(this._context.tools ?? []), tool];
|
|
83
|
+
this.syncSecurityRegisteredTools();
|
|
70
84
|
}
|
|
71
85
|
setTools(tools) {
|
|
72
86
|
this._context.tools = [...tools];
|
|
87
|
+
this.syncSecurityRegisteredTools();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 会话级 tool 面可见性(Client Tool:无 live client 则不进 LLM tool 面)。
|
|
91
|
+
* 返回 false 的 tool 对该 session 的 run 隐藏;server tool 不受影响。
|
|
92
|
+
*/
|
|
93
|
+
setToolVisibilityFilter(filter) {
|
|
94
|
+
this._toolVisibilityFilter = filter;
|
|
95
|
+
}
|
|
96
|
+
/** 本 session 的 tool 列表(含可见性过滤) */
|
|
97
|
+
toolsForSession(sessionId) {
|
|
98
|
+
const tools = this.tools;
|
|
99
|
+
const filter = this._toolVisibilityFilter;
|
|
100
|
+
if (!filter)
|
|
101
|
+
return tools;
|
|
102
|
+
return tools.filter((t) => filter(sessionId, t.name));
|
|
73
103
|
}
|
|
74
104
|
// ── 动态配置 ──
|
|
75
105
|
setModel(model) {
|
|
@@ -80,6 +110,7 @@ export class Agent {
|
|
|
80
110
|
}
|
|
81
111
|
setHarness(harness) {
|
|
82
112
|
this._harness = harness;
|
|
113
|
+
this.syncSecurityRegisteredTools();
|
|
83
114
|
}
|
|
84
115
|
/** 当前 ContextEngine 会话键(多 Session 时由 Runner 注入) */
|
|
85
116
|
get contextSessionId() {
|
|
@@ -131,6 +162,18 @@ export class Agent {
|
|
|
131
162
|
setConvertToLlm(fn) {
|
|
132
163
|
this._config = { ...this._config, convertToLlm: fn };
|
|
133
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* 动态替换 getSteeringMessages(当前 turn 结束后注入的提示)
|
|
167
|
+
*
|
|
168
|
+
* 晚绑定入口:一个 Agent 实例服务多 session,回调必须经
|
|
169
|
+
* `getRunScope()` / `getRunSessionId()` 取**本 Run** 的身份,
|
|
170
|
+
* 不得直接闭包某个 sessionId(否则并发 session 串味,违反 I1)。
|
|
171
|
+
*
|
|
172
|
+
* @param fn - steering 消息提供者;undefined 清除
|
|
173
|
+
*/
|
|
174
|
+
setSteeringMessages(fn) {
|
|
175
|
+
this._config = { ...this._config, getSteeringMessages: fn };
|
|
176
|
+
}
|
|
134
177
|
/** 动态替换 transformContext */
|
|
135
178
|
setTransformContext(fn) {
|
|
136
179
|
this._config = { ...this._config, transformContext: fn };
|
|
@@ -164,7 +207,9 @@ export class Agent {
|
|
|
164
207
|
const runScope = {
|
|
165
208
|
sessionId: options?.runScope?.sessionId ?? this._contextSessionId,
|
|
166
209
|
agentId: options?.runScope?.agentId ?? harness.agentId ?? 'default',
|
|
210
|
+
runId: options?.runScope?.runId,
|
|
167
211
|
systemPrompt: options?.runScope?.systemPrompt ?? context.systemPrompt,
|
|
212
|
+
grounding: options?.runScope?.grounding,
|
|
168
213
|
toolRuntime: options?.runScope?.toolRuntime,
|
|
169
214
|
agentRevision: options?.runScope?.agentRevision,
|
|
170
215
|
};
|
|
@@ -70,7 +70,11 @@ export type RunGuardMetricsEvent = {
|
|
|
70
70
|
nominalTotalTokens: number;
|
|
71
71
|
elapsedMs: number;
|
|
72
72
|
consecutiveErrors: number;
|
|
73
|
+
/** 连续同一错误(名+参数+错误内容一致)——「卡住」的强信号 */
|
|
74
|
+
consecutiveIdenticalFailures?: number;
|
|
73
75
|
consecutiveSameTool: number;
|
|
76
|
+
/** 连续相同调用(名+参数+结果一致)——无进展循环的强信号 */
|
|
77
|
+
consecutiveIdenticalCalls?: number;
|
|
74
78
|
noopStreak: number;
|
|
75
79
|
hasProgress: boolean;
|
|
76
80
|
uniqueTools: string[];
|
|
@@ -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) {
|
|
@@ -576,8 +665,12 @@ export async function* runAgentWithReliability(context, config, harness, signal)
|
|
|
576
665
|
}
|
|
577
666
|
return 'abort';
|
|
578
667
|
}
|
|
579
|
-
// 默认:重试 rate_limit / timeout / server(最多 3 次,避免无界重试)
|
|
580
|
-
|
|
668
|
+
// 默认:重试 rate_limit / timeout / network / server(最多 3 次,避免无界重试)
|
|
669
|
+
// network 含对端断连(undici terminated / socket hang up),重试常可自愈
|
|
670
|
+
if (classified.reason === 'rate_limit' ||
|
|
671
|
+
classified.reason === 'timeout' ||
|
|
672
|
+
classified.reason === 'network' ||
|
|
673
|
+
classified.reason === 'server') {
|
|
581
674
|
if (attempt < 3) {
|
|
582
675
|
const delayMs = classified.retryAfterMs ?? (attempt + 1) * 1000;
|
|
583
676
|
if (delayMs > 0) {
|
|
@@ -896,6 +989,7 @@ function executeRecoveryActions(actions, messages) {
|
|
|
896
989
|
role: 'user',
|
|
897
990
|
content: `[System: ${removeCount} earlier messages omitted to fit context window.]`,
|
|
898
991
|
timestamp: Date.now(),
|
|
992
|
+
metadata: { source: 'engineHint' },
|
|
899
993
|
});
|
|
900
994
|
}
|
|
901
995
|
break;
|
|
@@ -916,6 +1010,7 @@ function executeRecoveryActions(actions, messages) {
|
|
|
916
1010
|
role: 'user',
|
|
917
1011
|
content: `[System: ${removed} recent messages cleared to recover from a stuck loop.]`,
|
|
918
1012
|
timestamp: Date.now(),
|
|
1013
|
+
metadata: { source: 'engineHint' },
|
|
919
1014
|
});
|
|
920
1015
|
}
|
|
921
1016
|
break;
|
|
@@ -925,6 +1020,7 @@ function executeRecoveryActions(actions, messages) {
|
|
|
925
1020
|
role: 'user',
|
|
926
1021
|
content: `[System: ${action.hint}]`,
|
|
927
1022
|
timestamp: Date.now(),
|
|
1023
|
+
metadata: { source: 'engineHint' },
|
|
928
1024
|
});
|
|
929
1025
|
break;
|
|
930
1026
|
}
|