@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
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delegation — 委派契约类型(L2 委派契约层)
|
|
3
|
+
*
|
|
4
|
+
* @layer harness/collaboration/delegation — 多 Agent 委派产品契约,非 Core Kernel。
|
|
5
|
+
* 设计权威:`arch/delegation.md`。
|
|
6
|
+
*
|
|
7
|
+
* 设计不变量(`arch/delegation.md` §3):
|
|
8
|
+
* - D1 委派契约是**纯 JSON 消息**,不传 JS 对象引用(跨进程可序列化)
|
|
9
|
+
* - D5 结果只含可序列化字段(output / artifacts / usage / error)
|
|
10
|
+
* - D10 委派单状态机独立,不与 SessionTask / Workflow 共用
|
|
11
|
+
*
|
|
12
|
+
* 因此本文件的**所有**类型必须可 `JSON.stringify` 无损往返;
|
|
13
|
+
* 不得出现 `AbortSignal` / `Agent` 实例 / 函数 / class 实例等非序列化值。
|
|
14
|
+
*/
|
|
15
|
+
// ── 消息 schema 版本 ──
|
|
16
|
+
/**
|
|
17
|
+
* 委派消息 schema 版本(D1/⑤:跨进程契约必须版本化)。
|
|
18
|
+
* 破坏性变更时 +1;transport 与 service 据此做兼容判断。
|
|
19
|
+
*/
|
|
20
|
+
export const DELEGATION_SCHEMA_VERSION = 1;
|
|
21
|
+
/** 终态集合:进入后不可复用(对齐 AgentProcess 旧语义,但状态机独立 D10) */
|
|
22
|
+
export const DELEGATION_TERMINAL_STATUSES = [
|
|
23
|
+
'completed',
|
|
24
|
+
'failed',
|
|
25
|
+
'cancelled',
|
|
26
|
+
'timeout',
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* 判断委派单是否已到终态
|
|
30
|
+
*
|
|
31
|
+
* @param status - 委派单状态
|
|
32
|
+
* @returns 是否终态
|
|
33
|
+
*/
|
|
34
|
+
export function isTerminalDelegationStatus(status) {
|
|
35
|
+
return DELEGATION_TERMINAL_STATUSES.includes(status);
|
|
36
|
+
}
|
|
37
|
+
/** 未闭合状态集合(queued + running) */
|
|
38
|
+
export const DELEGATION_ACTIVE_STATUSES = ['queued', 'running'];
|
|
39
|
+
/**
|
|
40
|
+
* 判断委派单是否仍未闭合
|
|
41
|
+
*
|
|
42
|
+
* @param status - 委派单状态
|
|
43
|
+
* @returns 是否活跃
|
|
44
|
+
*/
|
|
45
|
+
export function isActiveDelegationStatus(status) {
|
|
46
|
+
return DELEGATION_ACTIVE_STATUSES.includes(status);
|
|
47
|
+
}
|
|
48
|
+
// ── 事件(§7) ──
|
|
49
|
+
/**
|
|
50
|
+
* 委派事件常量。
|
|
51
|
+
*
|
|
52
|
+
* notify 通道(§7.1)消费 `COMPLETED` / `FAILED` / `CANCELLED` / `TIMEOUT`,
|
|
53
|
+
* 转 `emitAgentSignal` 唤醒父 AgentRuntime。
|
|
54
|
+
*/
|
|
55
|
+
export const DelegationEvents = {
|
|
56
|
+
/** 委派单创建 */
|
|
57
|
+
CREATED: 'delegation.created',
|
|
58
|
+
/** 子 Run 启动 */
|
|
59
|
+
STARTED: 'delegation.started',
|
|
60
|
+
/** 终态:completed */
|
|
61
|
+
COMPLETED: 'delegation.completed',
|
|
62
|
+
/** 终态:failed */
|
|
63
|
+
FAILED: 'delegation.failed',
|
|
64
|
+
/** 终态:cancelled */
|
|
65
|
+
CANCELLED: 'delegation.cancelled',
|
|
66
|
+
/** 终态:timeout */
|
|
67
|
+
TIMEOUT: 'delegation.timeout',
|
|
68
|
+
/** 送达状态迁移(delivering / surfaced / 回滚 pending) */
|
|
69
|
+
DELIVERY_STATE_CHANGED: 'delegation.delivery_state',
|
|
70
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 委派编排的生产接线
|
|
3
|
+
*
|
|
4
|
+
* @layer harness/collaboration/delegation
|
|
5
|
+
* 设计权威:`arch/delegation.md` §7 / §14。
|
|
6
|
+
*
|
|
7
|
+
* 把 `DelegateService` + 4 个 `delegate_*` 工具 + notify 通道 + 状态提示
|
|
8
|
+
* 接到 agent 上。**显式依赖注入**,不隐式假设共享总线。
|
|
9
|
+
*
|
|
10
|
+
* 两种形态:
|
|
11
|
+
* - {@link createDelegationRuntime} — 可增量 `attach`,适配 Gateway 的**惰性构建**
|
|
12
|
+
* - {@link wireDelegation} — 批量一次接完,适配 `buildFromConfig`
|
|
13
|
+
*
|
|
14
|
+
* 关键依赖约束:
|
|
15
|
+
* - **notify 总线必须与 `AgentSignalSource` 监听的是同一条**
|
|
16
|
+
* (`arch/agent-runtime.md`)。Gateway 路径天然满足(所有 agent 共享
|
|
17
|
+
* `gatewayBus`);库嵌入需自行传共享总线,否则 notify 静默失联(poll 仍可用)。
|
|
18
|
+
* - `RunnerChildRunPort.resolve` 是**惰性**的,因此服务可先建、
|
|
19
|
+
* agent 后 attach,不存在循环依赖。
|
|
20
|
+
*/
|
|
21
|
+
import type { EventBus } from '@octopi-agent/core/primitives/event-bus.js';
|
|
22
|
+
import type { RegisteredTool } from '@octopi-agent/core/types.js';
|
|
23
|
+
import type { SessionStore } from '@octopi-agent/core/interfaces/session-store.js';
|
|
24
|
+
import type { SessionData } from '../../session/types.js';
|
|
25
|
+
import type { Agent } from '../../run/agent/index.js';
|
|
26
|
+
import type { SessionAwareRunner } from '../../run/runner.js';
|
|
27
|
+
import type { AgentDelegationPolicy, AgentRegistry } from './registry-types.js';
|
|
28
|
+
import { DelegationStore } from './store.js';
|
|
29
|
+
import { DelegateService } from './service.js';
|
|
30
|
+
export { DEFAULT_DELEGATION_POLICY, effectiveDelegationPolicy, } from './registry-types.js';
|
|
31
|
+
/** 参与委派的一个 agent 的运行时 */
|
|
32
|
+
export interface DelegatableAgent {
|
|
33
|
+
agentId: string;
|
|
34
|
+
agent: Agent;
|
|
35
|
+
runner: SessionAwareRunner;
|
|
36
|
+
/**
|
|
37
|
+
* 该 agent 的 SessionStore。
|
|
38
|
+
*
|
|
39
|
+
* 必须与 `runner.handle()` 读的是同一个 store,否则预创建的 child session
|
|
40
|
+
* (带 `spawnBy`,D7)对子 Run 不可见。
|
|
41
|
+
*/
|
|
42
|
+
store: SessionStore<SessionData>;
|
|
43
|
+
/** 特质标签(`AgentConfig.traits`) */
|
|
44
|
+
traits?: string[];
|
|
45
|
+
/** 委派策略(`AgentConfig.delegation`) */
|
|
46
|
+
delegation?: AgentDelegationPolicy;
|
|
47
|
+
/** persona(进子的 systemPrompt) */
|
|
48
|
+
persona?: string;
|
|
49
|
+
/**
|
|
50
|
+
* 工具注册入口。
|
|
51
|
+
*
|
|
52
|
+
* `RegisteredTool` 须经 `convertToAgentTool` 转成 `AgentTool` 后注册,
|
|
53
|
+
* 且要同步 SecurityGuard 的未注册工具硬边界名单;故由组装层
|
|
54
|
+
* (`AgentBuildResult.registerTools` / Gateway)注入,本模块不触碰 builder 内部。
|
|
55
|
+
* 缺省 = 不挂工具(服务仍可用,poll 通道不受影响)。
|
|
56
|
+
*/
|
|
57
|
+
registerTools?: (tools: RegisteredTool[]) => void;
|
|
58
|
+
}
|
|
59
|
+
/** `createDelegationRuntime` 配置 */
|
|
60
|
+
export interface DelegationRuntimeOptions {
|
|
61
|
+
/**
|
|
62
|
+
* notify 用事件总线;须与 `AgentSignalSource` 监听的同一条。
|
|
63
|
+
* Gateway 路径天然满足(共享 `gatewayBus`);缺省 = **不接线 notify**(poll 仍可用)。
|
|
64
|
+
*/
|
|
65
|
+
events?: EventBus;
|
|
66
|
+
/**
|
|
67
|
+
* notify 推送开关(缺省 true)。设 `false` 时不安装 notifier(即使有共享总线)——
|
|
68
|
+
* 用于接收端(`AgentSignalSource`)未挂载的部署:宁可退化为 poll + 状态提示,
|
|
69
|
+
* 也不能把发进无人监听总线的通知误标成已送达。
|
|
70
|
+
*/
|
|
71
|
+
notifyPush?: boolean;
|
|
72
|
+
/** 单父 session 未闭合委派上限(失控防护,§8) */
|
|
73
|
+
maxActiveDelegationsPerSession?: number;
|
|
74
|
+
}
|
|
75
|
+
/** 委派编排运行时 */
|
|
76
|
+
export interface DelegationRuntime {
|
|
77
|
+
service: DelegateService;
|
|
78
|
+
registry: AgentRegistry;
|
|
79
|
+
delegationStore: DelegationStore;
|
|
80
|
+
/** 是否已接 notify 通道 */
|
|
81
|
+
notifyWired: boolean;
|
|
82
|
+
/** 已挂载的 agentId */
|
|
83
|
+
readonly attached: readonly string[];
|
|
84
|
+
/**
|
|
85
|
+
* 挂载一个 agent(幂等:同 agentId 重复调用只生效一次)。
|
|
86
|
+
*
|
|
87
|
+
* 只有 `delegation.canDelegate` 的 agent 才挂 `delegate_*` 工具与状态提示;
|
|
88
|
+
* 其余 agent 仅登记进 Registry 供被委派。
|
|
89
|
+
*/
|
|
90
|
+
attach(agent: DelegatableAgent): void;
|
|
91
|
+
/**
|
|
92
|
+
* 释放运行时持有的宿主资源(送达回执订阅)。幂等。
|
|
93
|
+
* Gateway 热重建 / 停机时调用,防止重复 createDelegationRuntime 累积订阅。
|
|
94
|
+
*/
|
|
95
|
+
dispose(): void;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 创建可增量挂载的委派运行时
|
|
99
|
+
*
|
|
100
|
+
* @param options - 总线 / store / 限额
|
|
101
|
+
* @returns 委派运行时
|
|
102
|
+
*/
|
|
103
|
+
export declare function createDelegationRuntime(options: DelegationRuntimeOptions): DelegationRuntime;
|
|
104
|
+
/**
|
|
105
|
+
* 给一组建好的 agent 批量接上委派编排
|
|
106
|
+
*
|
|
107
|
+
* @param agents - 参与委派的 agent
|
|
108
|
+
* @param options - 总线 / store / 限额
|
|
109
|
+
* @returns 委派编排组件;无任何 agent 可委派时返回 undefined
|
|
110
|
+
*/
|
|
111
|
+
export declare function wireDelegation(agents: DelegatableAgent[], options: DelegationRuntimeOptions): DelegationRuntime | undefined;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 委派编排的生产接线
|
|
3
|
+
*
|
|
4
|
+
* @layer harness/collaboration/delegation
|
|
5
|
+
* 设计权威:`arch/delegation.md` §7 / §14。
|
|
6
|
+
*
|
|
7
|
+
* 把 `DelegateService` + 4 个 `delegate_*` 工具 + notify 通道 + 状态提示
|
|
8
|
+
* 接到 agent 上。**显式依赖注入**,不隐式假设共享总线。
|
|
9
|
+
*
|
|
10
|
+
* 两种形态:
|
|
11
|
+
* - {@link createDelegationRuntime} — 可增量 `attach`,适配 Gateway 的**惰性构建**
|
|
12
|
+
* - {@link wireDelegation} — 批量一次接完,适配 `buildFromConfig`
|
|
13
|
+
*
|
|
14
|
+
* 关键依赖约束:
|
|
15
|
+
* - **notify 总线必须与 `AgentSignalSource` 监听的是同一条**
|
|
16
|
+
* (`arch/agent-runtime.md`)。Gateway 路径天然满足(所有 agent 共享
|
|
17
|
+
* `gatewayBus`);库嵌入需自行传共享总线,否则 notify 静默失联(poll 仍可用)。
|
|
18
|
+
* - `RunnerChildRunPort.resolve` 是**惰性**的,因此服务可先建、
|
|
19
|
+
* agent 后 attach,不存在循环依赖。
|
|
20
|
+
*/
|
|
21
|
+
import { effectiveDelegationPolicy } from './registry-types.js';
|
|
22
|
+
import { DefaultAgentRegistry } from './registry.js';
|
|
23
|
+
import { DelegationStore } from './store.js';
|
|
24
|
+
import { DelegateService } from './service.js';
|
|
25
|
+
import { InProcessTransport } from './transport.js';
|
|
26
|
+
import { RunnerChildRunPort, createChildRunExecutor, } from './child-run.js';
|
|
27
|
+
import { createDelegationNotifier } from './notifier.js';
|
|
28
|
+
import { RuntimeEvents } from '../../activation/types.js';
|
|
29
|
+
import { createDelegationTools } from '../../extension/plugin-ecosystem/tools/delegation.js';
|
|
30
|
+
// 供 Gateway / 组装层经同一入口取生效策略
|
|
31
|
+
export { DEFAULT_DELEGATION_POLICY, effectiveDelegationPolicy, } from './registry-types.js';
|
|
32
|
+
/**
|
|
33
|
+
* 创建可增量挂载的委派运行时
|
|
34
|
+
*
|
|
35
|
+
* @param options - 总线 / store / 限额
|
|
36
|
+
* @returns 委派运行时
|
|
37
|
+
*/
|
|
38
|
+
export function createDelegationRuntime(options) {
|
|
39
|
+
const registry = new DefaultAgentRegistry();
|
|
40
|
+
const byId = new Map();
|
|
41
|
+
const childRunPort = new RunnerChildRunPort({
|
|
42
|
+
resolve: (agentId) => {
|
|
43
|
+
const a = byId.get(agentId);
|
|
44
|
+
return a ? { runner: a.runner, store: a.store } : undefined;
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
const personaOf = (agentId) => byId.get(agentId)?.persona ?? '';
|
|
48
|
+
const transport = new InProcessTransport(createChildRunExecutor(childRunPort, { persona: '' }, personaOf));
|
|
49
|
+
const delegationStore = new DelegationStore(options.events);
|
|
50
|
+
// §7.1 送达回执:notify 投递(deliveryState 置位)后 dispatch 被丢
|
|
51
|
+
// (`runtime.trigger.dropped`,事件携带 triggerRef → metadata.delegationId)时
|
|
52
|
+
// 回滚送达标记,让 §7.3 状态提示重新兜底——不能让「推送进了总线但从未
|
|
53
|
+
// 变成父消息」被记成已送达。回滚方向安全:宁可提示多亮一次(父 get 消音)。
|
|
54
|
+
const droppedSubscription = options.events?.on(RuntimeEvents.TRIGGER_DROPPED, (event) => {
|
|
55
|
+
const triggerRef = event.data
|
|
56
|
+
?.triggerRef;
|
|
57
|
+
const delegationId = triggerRef?.metadata?.delegationId;
|
|
58
|
+
if (!delegationId)
|
|
59
|
+
return;
|
|
60
|
+
// fan-out 部分丢弃:有目标已受理(消息已进其上下文)→ 不回滚,
|
|
61
|
+
// 宁可漏提示也不消掉已送达部分(§7 送达语义)
|
|
62
|
+
const reason = event.data?.reason;
|
|
63
|
+
if (reason === 'fanout_partial_failure')
|
|
64
|
+
return;
|
|
65
|
+
// delivering / surfaced 均可回滚 → pending(提示重新兜底);
|
|
66
|
+
// 无送达记录(pending)不动
|
|
67
|
+
if (delegationStore.get(delegationId)?.deliveryState !== 'pending') {
|
|
68
|
+
delegationStore.markUnsurfaced(delegationId);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
const notifier = options.events && options.notifyPush !== false
|
|
72
|
+
? createDelegationNotifier({ events: options.events })
|
|
73
|
+
: undefined;
|
|
74
|
+
const notifyWired = notifier !== undefined;
|
|
75
|
+
const service = new DelegateService(delegationStore, registry, transport, {
|
|
76
|
+
maxActiveDelegationsPerSession: options.maxActiveDelegationsPerSession,
|
|
77
|
+
notifier,
|
|
78
|
+
// 父 session 深度:子 session 的深度 = 创建它的那张委派单的 depth(§10.4,权威查询)
|
|
79
|
+
resolveParentDepth: (sessionId) => delegationStore.findDepthByChildSession(sessionId) ?? 0,
|
|
80
|
+
});
|
|
81
|
+
const delegateTools = createDelegationTools(service);
|
|
82
|
+
const attached = new Set();
|
|
83
|
+
const runtime = {
|
|
84
|
+
service,
|
|
85
|
+
registry,
|
|
86
|
+
delegationStore,
|
|
87
|
+
notifyWired,
|
|
88
|
+
dispose() {
|
|
89
|
+
// 回收送达回执订阅(幂等);service/store 由 GC,不发终止事件
|
|
90
|
+
droppedSubscription?.dispose();
|
|
91
|
+
},
|
|
92
|
+
get attached() {
|
|
93
|
+
return [...attached];
|
|
94
|
+
},
|
|
95
|
+
attach(agent) {
|
|
96
|
+
if (attached.has(agent.agentId))
|
|
97
|
+
return;
|
|
98
|
+
attached.add(agent.agentId);
|
|
99
|
+
byId.set(agent.agentId, agent);
|
|
100
|
+
registry.register({
|
|
101
|
+
id: agent.agentId,
|
|
102
|
+
name: agent.agentId,
|
|
103
|
+
traits: agent.traits ?? [],
|
|
104
|
+
delegation: effectiveDelegationPolicy(agent.delegation),
|
|
105
|
+
status: 'idle',
|
|
106
|
+
});
|
|
107
|
+
// delegate_* 工具只挂给能委派的 agent(§9.3 命名委派)
|
|
108
|
+
if (effectiveDelegationPolicy(agent.delegation).canDelegate) {
|
|
109
|
+
agent.registerTools?.(delegateTools);
|
|
110
|
+
// §7.3:长 Run 每轮可见的委派状态提示。
|
|
111
|
+
// 经 RunScope ALS 取**本 Run** 的 sessionId,避免共享 Agent 实例串味(I1)。
|
|
112
|
+
agent.agent.setSteeringMessages(async () => {
|
|
113
|
+
const { getRunSessionId } = await import('../../run/run-scope.js');
|
|
114
|
+
const sessionId = getRunSessionId(agent.agent.contextSessionId);
|
|
115
|
+
if (!sessionId)
|
|
116
|
+
return [];
|
|
117
|
+
const hint = service.renderStatusHint(sessionId);
|
|
118
|
+
// ephemeral:本轮可见、不落历史。否则「当时的状态」会被固化进 session,
|
|
119
|
+
// 状态过期后仍留在上下文里,且每次状态变化都会打穿前缀缓存。
|
|
120
|
+
return hint
|
|
121
|
+
? [{ role: 'system', content: hint, timestamp: Date.now(), ephemeral: true }]
|
|
122
|
+
: [];
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
return runtime;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* 给一组建好的 agent 批量接上委派编排
|
|
131
|
+
*
|
|
132
|
+
* @param agents - 参与委派的 agent
|
|
133
|
+
* @param options - 总线 / store / 限额
|
|
134
|
+
* @returns 委派编排组件;无任何 agent 可委派时返回 undefined
|
|
135
|
+
*/
|
|
136
|
+
export function wireDelegation(agents, options) {
|
|
137
|
+
// 缺省默认可委派(arch/delegation.md §9.2):只有全部显式关闭才不接线
|
|
138
|
+
const canDelegateAny = agents.some((a) => effectiveDelegationPolicy(a.delegation).canDelegate);
|
|
139
|
+
if (!canDelegateAny)
|
|
140
|
+
return undefined;
|
|
141
|
+
const runtime = createDelegationRuntime(options);
|
|
142
|
+
for (const a of agents)
|
|
143
|
+
runtime.attach(a);
|
|
144
|
+
return runtime;
|
|
145
|
+
}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* orchestration 领域统一导出(experimental)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* 默认不进主路径;经 package 子路径 `octopi/harness/collaboration/orchestration` 访问。
|
|
4
|
+
* @layer harness/collaboration/orchestration
|
|
6
5
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* **范围收窄记录**(`arch/delegation.md` §12.2):
|
|
7
|
+
* workflow / quality / strategy / planner / scheduler / async-task 已删除,
|
|
8
|
+
* 由新的 Delegation 委派契约(`collaboration/delegation`)取代执行语义。
|
|
9
|
+
* 保留:
|
|
10
|
+
* - `reflector/` — LLMReflector(高置信模式改写 Memory `method`,被知识分馏链测试保护)
|
|
11
|
+
* - `cognitive-loop.ts` — Planner/Reflector/ExecutionRecord/AgentState 契约
|
|
12
|
+
*
|
|
13
|
+
* 默认不进主路径;经 package 子路径 `octopi/harness/orchestration` 访问。
|
|
9
14
|
*/
|
|
10
|
-
export * from './workflow/index.js';
|
|
11
|
-
export * from './scheduler/index.js';
|
|
12
|
-
export * from './planner/index.js';
|
|
13
|
-
export * from './strategy/index.js';
|
|
14
|
-
export * from './quality/index.js';
|
|
15
|
-
export * from './reflector/index.js';
|
|
16
|
-
export { AsyncTask, TaskTimeoutError, TaskCancelledError, spawnTask, TaskEvents } from './async-task.js';
|
|
17
|
-
export type { TaskOptions, TaskExecutor } from './async-task.js';
|
|
18
|
-
export type { AsyncTaskStore, AsyncTaskRecord, AsyncTaskStatus, AsyncTaskPriority, AsyncTaskFilter } from './async-task-store.js';
|
|
19
15
|
export type { Planner, Reflector, AgentState, AgentStats, Plan, PlanStep, StepResult, ExecutionRecord, Assessment, Pattern, } from './cognitive-loop.js';
|
|
16
|
+
export { LLMReflector } from './reflector/index.js';
|
|
17
|
+
export type { LLMReflectorConfig } from './reflector/index.js';
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* orchestration 领域统一导出(experimental)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* 默认不进主路径;经 package 子路径 `octopi/harness/collaboration/orchestration` 访问。
|
|
4
|
+
* @layer harness/collaboration/orchestration
|
|
6
5
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* **范围收窄记录**(`arch/delegation.md` §12.2):
|
|
7
|
+
* workflow / quality / strategy / planner / scheduler / async-task 已删除,
|
|
8
|
+
* 由新的 Delegation 委派契约(`collaboration/delegation`)取代执行语义。
|
|
9
|
+
* 保留:
|
|
10
|
+
* - `reflector/` — LLMReflector(高置信模式改写 Memory `method`,被知识分馏链测试保护)
|
|
11
|
+
* - `cognitive-loop.ts` — Planner/Reflector/ExecutionRecord/AgentState 契约
|
|
12
|
+
*
|
|
13
|
+
* 默认不进主路径;经 package 子路径 `octopi/harness/orchestration` 访问。
|
|
9
14
|
*/
|
|
10
|
-
|
|
11
|
-
export
|
|
12
|
-
export * from './planner/index.js';
|
|
13
|
-
export * from './strategy/index.js';
|
|
14
|
-
export * from './quality/index.js';
|
|
15
|
-
export * from './reflector/index.js';
|
|
16
|
-
export { AsyncTask, TaskTimeoutError, TaskCancelledError, spawnTask, TaskEvents } from './async-task.js';
|
|
15
|
+
// ── Reflector ──
|
|
16
|
+
export { LLMReflector } from './reflector/index.js';
|
|
@@ -67,8 +67,8 @@ export declare class DefaultContextAssembler implements ContextAssembler {
|
|
|
67
67
|
private rememberFingerprint;
|
|
68
68
|
/** 会话结束时清理指纹缓存 */
|
|
69
69
|
clearSession(sessionId: string): void;
|
|
70
|
-
/**
|
|
71
|
-
getFingerprint(sessionId: string,
|
|
70
|
+
/** 读取某层最近指纹(调试/测试用);layerKey 形如 `id#system` / `id#snapshot` */
|
|
71
|
+
getFingerprint(sessionId: string, layerKey: string): string | null | undefined;
|
|
72
72
|
}
|
|
73
73
|
/** 默认层顺序常量导出,便于测试断言 */
|
|
74
74
|
export declare const DEFAULT_LAYER_ORDERS: Record<ContextLayerId, number>;
|
|
@@ -97,7 +97,10 @@ export class DefaultContextAssembler {
|
|
|
97
97
|
...this.defaultLayerShares,
|
|
98
98
|
...params.layerShares,
|
|
99
99
|
};
|
|
100
|
-
|
|
100
|
+
// params 显式传入优先(含 '' = 明确不要 preamble,E8 快照组用);缺省回退构造器配置
|
|
101
|
+
const preambleText = (params.constitutionPreamble !== undefined
|
|
102
|
+
? params.constitutionPreamble
|
|
103
|
+
: (this.constitutionPreamble ?? '')).trim();
|
|
101
104
|
if (ordered.length === 0 || systemBudget <= 0) {
|
|
102
105
|
// 宪法 preamble 不可丢:无层时仍返回 preamble
|
|
103
106
|
return {
|
|
@@ -134,8 +137,10 @@ export class DefaultContextAssembler {
|
|
|
134
137
|
// 指纹未变则视为「本层无新内容」的轻量跳过:
|
|
135
138
|
// 当前实现仍每轮调用 assemble(层可能依赖 query),
|
|
136
139
|
// 指纹仅写入 manifest 供观测;缓存复用留给后续层实现。
|
|
140
|
+
// F9:键含 placement——双 RuntimeLayer 实例(system/snapshot)不共享键空间
|
|
141
|
+
const fpKey = `${layer.id}#${layer.placement === 'snapshot' ? 'snapshot' : 'system'}`;
|
|
137
142
|
const fp = layer.fingerprint ? await layer.fingerprint(ctx) : null;
|
|
138
|
-
this.rememberFingerprint(sessionId,
|
|
143
|
+
this.rememberFingerprint(sessionId, fpKey, fp);
|
|
139
144
|
let content = null;
|
|
140
145
|
try {
|
|
141
146
|
content = await layer.assemble(ctx);
|
|
@@ -267,7 +272,7 @@ export class DefaultContextAssembler {
|
|
|
267
272
|
};
|
|
268
273
|
return { systemPrompt, manifest };
|
|
269
274
|
}
|
|
270
|
-
rememberFingerprint(sessionId,
|
|
275
|
+
rememberFingerprint(sessionId, layerKey, fp) {
|
|
271
276
|
if (!this.fingerprints.has(sessionId) && this.fingerprints.size >= MAX_FINGERPRINT_SESSIONS) {
|
|
272
277
|
// 简单 FIFO:丢掉最早插入的 session
|
|
273
278
|
const oldest = this.fingerprints.keys().next().value;
|
|
@@ -279,15 +284,15 @@ export class DefaultContextAssembler {
|
|
|
279
284
|
m = new Map();
|
|
280
285
|
this.fingerprints.set(sessionId, m);
|
|
281
286
|
}
|
|
282
|
-
m.set(
|
|
287
|
+
m.set(layerKey, fp);
|
|
283
288
|
}
|
|
284
289
|
/** 会话结束时清理指纹缓存 */
|
|
285
290
|
clearSession(sessionId) {
|
|
286
291
|
this.fingerprints.delete(sessionId);
|
|
287
292
|
}
|
|
288
|
-
/**
|
|
289
|
-
getFingerprint(sessionId,
|
|
290
|
-
return this.fingerprints.get(sessionId)?.get(
|
|
293
|
+
/** 读取某层最近指纹(调试/测试用);layerKey 形如 `id#system` / `id#snapshot` */
|
|
294
|
+
getFingerprint(sessionId, layerKey) {
|
|
295
|
+
return this.fingerprints.get(sessionId)?.get(layerKey);
|
|
291
296
|
}
|
|
292
297
|
}
|
|
293
298
|
/** 解析各层硬顶:仅已配置 share 的层有值 */
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { getTextContent } from '@octopi-agent/core/types.js';
|
|
9
9
|
import { HeuristicTokenEstimator } from '../../token-estimator.js';
|
|
10
10
|
import { buildPolicyRegistry } from '../summary/resolver.js';
|
|
11
|
+
import { buildSystemPrompt } from '../summary/executor.js';
|
|
11
12
|
function defaultEstimator() {
|
|
12
13
|
const e = new HeuristicTokenEstimator();
|
|
13
14
|
return {
|
|
@@ -15,10 +16,14 @@ function defaultEstimator() {
|
|
|
15
16
|
estimateText: (t) => e.estimateText(t),
|
|
16
17
|
};
|
|
17
18
|
}
|
|
19
|
+
/** 中段摘要任务(summaryPort 与 summarizeFn 两路共用,保持指令对称) */
|
|
20
|
+
const MIDDLE_SEGMENT_TASK = 'Summarize conversation middle segment: goal, progress, decisions, blockers, next steps, key values.';
|
|
18
21
|
function formatMessagesAsText(messages) {
|
|
19
22
|
const parts = [];
|
|
20
23
|
for (const msg of messages) {
|
|
21
|
-
|
|
24
|
+
// 归因保留(模型 2):多 agent 共线的摘要不得张冠李戴
|
|
25
|
+
// (惯例出处 session/history/port.ts renderMessage 的 role(agentId);此处大写+方括号仅排版差异)
|
|
26
|
+
const role = msg.agentId ? `${msg.role.toUpperCase()}(${msg.agentId})` : msg.role.toUpperCase();
|
|
22
27
|
const content = getTextContent(msg.content);
|
|
23
28
|
if (msg.role === 'assistant' && msg.toolCalls?.length) {
|
|
24
29
|
const calls = msg.toolCalls
|
|
@@ -45,12 +50,6 @@ function formatMessagesAsText(messages) {
|
|
|
45
50
|
}
|
|
46
51
|
return parts.join('\n\n---\n\n');
|
|
47
52
|
}
|
|
48
|
-
function toLlmMessages(messages) {
|
|
49
|
-
return messages.map((m) => ({
|
|
50
|
-
role: m.role,
|
|
51
|
-
content: getTextContent(m.content) || '',
|
|
52
|
-
}));
|
|
53
|
-
}
|
|
54
53
|
function asSummaryMessage(summary) {
|
|
55
54
|
const body = summary.includes('[Conversation Summary]')
|
|
56
55
|
? summary
|
|
@@ -86,6 +85,11 @@ export function createCompactEngine(options) {
|
|
|
86
85
|
else if (opts.summarizePolicy && typeof opts.summarizePolicy === 'object') {
|
|
87
86
|
policy = opts.summarizePolicy;
|
|
88
87
|
}
|
|
88
|
+
// 中段文本化为空(消息全无正文无工具):不发空摘要请求——空 user / 空 New content
|
|
89
|
+
// 过不了严格网关,且会让模型凭空产出;按摘要失败降级(onSummarizeFail 接管)
|
|
90
|
+
if (!middleText.trim()) {
|
|
91
|
+
return { error: 'empty_middle' };
|
|
92
|
+
}
|
|
89
93
|
if (port) {
|
|
90
94
|
const unit = {
|
|
91
95
|
text: middleText,
|
|
@@ -94,21 +98,58 @@ export function createCompactEngine(options) {
|
|
|
94
98
|
source: {},
|
|
95
99
|
kind: 'conversation',
|
|
96
100
|
policy: opts.summarizePolicy,
|
|
97
|
-
task:
|
|
101
|
+
task: MIDDLE_SEGMENT_TASK,
|
|
98
102
|
};
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
try {
|
|
104
|
+
const r = await port.extract(unit, {
|
|
105
|
+
signal: opts.signal,
|
|
106
|
+
previousSummary: opts.previousSummary,
|
|
107
|
+
});
|
|
108
|
+
return { summary: r.text, coverage: r.coverage };
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
// 只吞 port.extract 的抛错(摘要器契约外失败:provider 报错/超时)——转 error
|
|
112
|
+
// 通道交给 onSummarizeFail 降级;try 内无其他可抛代码,无其他路径可至此
|
|
113
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
114
|
+
}
|
|
104
115
|
}
|
|
105
116
|
if (summarizeFn) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
117
|
+
// 缓存优先:llmPrefix(会话同形 system+history)+ 尾部 user 指令。
|
|
118
|
+
// 禁止把指令塞进 system 或重排历史——否则打穿前缀缓存。
|
|
119
|
+
// 无 llmPrefix 时回退「policy system + 文本化中段」(旁路/旧调用)。
|
|
120
|
+
let llmMessages;
|
|
121
|
+
if (opts.llmPrefix && opts.llmPrefix.length > 0) {
|
|
122
|
+
const tail = opts.previousSummary
|
|
123
|
+
? `${buildSystemPrompt(policy, MIDDLE_SEGMENT_TASK, maxTokens)}\n\nPrevious summary:\n${opts.previousSummary}`
|
|
124
|
+
: buildSystemPrompt(policy, MIDDLE_SEGMENT_TASK, maxTokens);
|
|
125
|
+
llmMessages = [
|
|
126
|
+
...opts.llmPrefix,
|
|
127
|
+
{ role: 'user', content: tail },
|
|
128
|
+
];
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
// 摘要请求 = policy 指令 + 文本化中段(单条 user),不把原始消息序列当对话发出:
|
|
132
|
+
// tool_call-only assistant / 缺 tool_call_id 的 tool 消息会被严格网关 400。
|
|
133
|
+
const system = buildSystemPrompt(policy, MIDDLE_SEGMENT_TASK, maxTokens);
|
|
134
|
+
const userContent = opts.previousSummary
|
|
135
|
+
? `Previous summary:\n${opts.previousSummary}\n\n---\n\nNew content:\n${middleText}`
|
|
136
|
+
: middleText;
|
|
137
|
+
llmMessages = [
|
|
138
|
+
{ role: 'system', content: system },
|
|
139
|
+
{ role: 'user', content: userContent },
|
|
140
|
+
];
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
const text = await summarizeFn(llmMessages, {
|
|
144
|
+
previousSummary: opts.previousSummary,
|
|
145
|
+
maxTokens: opts.maxSummaryTokens ?? maxTokens,
|
|
146
|
+
});
|
|
147
|
+
return { summary: text, coverage: 'full' };
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
// 只吞 summarizeFn 的抛错(provider 报错/超时)——转 error 通道交给 onSummarizeFail 降级
|
|
151
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
152
|
+
}
|
|
112
153
|
}
|
|
113
154
|
return { error: 'no_summarizer' };
|
|
114
155
|
}
|
|
@@ -184,16 +225,25 @@ export function createCompactEngine(options) {
|
|
|
184
225
|
reason: 'summarize_failed_truncate',
|
|
185
226
|
tokensBefore,
|
|
186
227
|
tokensAfter: estimator.estimateMessages(view),
|
|
228
|
+
// 摘要失败时旧摘要仍有效:summary 字段保留之(与 structure_only 失败兜底同款)
|
|
229
|
+
summary: opts.previousSummary,
|
|
187
230
|
view,
|
|
188
231
|
droppedSummary: 'middle dropped; summarizer unavailable',
|
|
189
232
|
};
|
|
190
233
|
}
|
|
191
234
|
const view = text.slice(0, 500);
|
|
192
|
-
return {
|
|
235
|
+
return {
|
|
236
|
+
ok: true,
|
|
237
|
+
compacted: true,
|
|
238
|
+
reason: 'summarize_failed_truncate',
|
|
239
|
+
tokensBefore,
|
|
240
|
+
summary: opts.previousSummary,
|
|
241
|
+
view,
|
|
242
|
+
};
|
|
193
243
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
244
|
+
// 摘要即完整更新(previousSummary 已随 prompt 交给 summarizeFn 合并;
|
|
245
|
+
// 与 LLMSummaryCompressor / summary executor 同一「迭代式更新」契约),不得再事后拼接
|
|
246
|
+
const summary = summarized.summary;
|
|
197
247
|
if (!isMessages) {
|
|
198
248
|
return {
|
|
199
249
|
ok: true,
|
|
@@ -233,12 +283,13 @@ export function createCompactEngine(options) {
|
|
|
233
283
|
reason: 'structure_truncate',
|
|
234
284
|
tokensBefore,
|
|
235
285
|
tokensAfter: estimator.estimateText(view),
|
|
286
|
+
// 摘要失败时旧摘要仍有效:summary 字段保留之(与 messages 失败兜底同款)
|
|
287
|
+
summary: opts.previousSummary,
|
|
236
288
|
view,
|
|
237
289
|
};
|
|
238
290
|
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
: summarized.summary;
|
|
291
|
+
// 摘要即完整更新(同上:迭代式更新契约,不再事后拼接)
|
|
292
|
+
const summary = summarized.summary;
|
|
242
293
|
const view = `${text.slice(0, 200)}\n\n[Conversation Summary]\n${summary}\n\n${text.slice(-200)}`;
|
|
243
294
|
return {
|
|
244
295
|
ok: true,
|
|
@@ -264,11 +315,11 @@ export function createCompactEngine(options) {
|
|
|
264
315
|
: Math.max(200, Math.floor(tokensBefore * 0.2)));
|
|
265
316
|
const middleText = formatMessagesAsText(middle);
|
|
266
317
|
const summarized = await summarizeMiddle(middleText, middle, opts, maxSummaryTokens);
|
|
318
|
+
// 摘要即完整更新(previousSummary 已随 prompt 交给 summarizeFn 合并);
|
|
319
|
+
// 摘要失败时仍保留旧摘要兜底
|
|
267
320
|
let summary = opts.previousSummary ?? '';
|
|
268
321
|
if (summarized.summary) {
|
|
269
|
-
summary =
|
|
270
|
-
? mergeSummaries(opts.previousSummary, summarized.summary)
|
|
271
|
-
: summarized.summary;
|
|
322
|
+
summary = summarized.summary;
|
|
272
323
|
}
|
|
273
324
|
else if (!summary) {
|
|
274
325
|
const placeholder = `[Structural compact] dropped ${middle.length} middle messages`;
|
|
@@ -309,12 +360,3 @@ export function createCompactEngine(options) {
|
|
|
309
360
|
compactText: (text, opts) => compactCore(text, opts ?? {}),
|
|
310
361
|
};
|
|
311
362
|
}
|
|
312
|
-
function mergeSummaries(previous, next) {
|
|
313
|
-
const a = previous.trim();
|
|
314
|
-
const b = next.trim();
|
|
315
|
-
if (!a)
|
|
316
|
-
return b;
|
|
317
|
-
if (!b)
|
|
318
|
-
return a;
|
|
319
|
-
return `${a}\n\n${b}`;
|
|
320
|
-
}
|