@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,499 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DelegateService — 委派编排
|
|
3
|
+
*
|
|
4
|
+
* @layer harness/collaboration/delegation
|
|
5
|
+
* 设计权威:`arch/delegation.md` §7 / §8 / §10。
|
|
6
|
+
*
|
|
7
|
+
* 职责:
|
|
8
|
+
* - 建单(`DelegationStore.create`,唯一写入口)
|
|
9
|
+
* - 解析目标(`AgentRegistry`:agentId 优先,capability 兜底,D2)
|
|
10
|
+
* - 递归深度闸(§10.4)
|
|
11
|
+
* - 失控防护 `maxActiveDelegationsPerSession`(§8:**不是并发闸**,并发硬闸只在 SessionGate 一处,D9)
|
|
12
|
+
* - 经 `DelegateTransport` 起子 Run、收结果(D1/D5)
|
|
13
|
+
* - 归集 usage 到父的 run 账(决策 C2)
|
|
14
|
+
* - 终态投递 notify(§7.1,投递由 P3 的 notifier 实现,本层只负责触发)
|
|
15
|
+
*
|
|
16
|
+
* **非阻塞**(§7):`dispatch()` 建单后立即返回 `delegationId`,不等子 Run 结束。
|
|
17
|
+
*/
|
|
18
|
+
import { randomUUID } from 'node:crypto';
|
|
19
|
+
import { DELEGATION_SCHEMA_VERSION, DelegationEvents, isTerminalDelegationStatus } from './types.js';
|
|
20
|
+
import { tightenSessionRights } from '../../governance/session-acl/rights.js';
|
|
21
|
+
import { effectiveDelegationPolicy } from './registry-types.js';
|
|
22
|
+
export class DelegateResolutionError extends Error {
|
|
23
|
+
reason;
|
|
24
|
+
available;
|
|
25
|
+
constructor(message, reason,
|
|
26
|
+
/** 解析失败时的可用目标(可选;让调用方不必瞎猜) */
|
|
27
|
+
available) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.reason = reason;
|
|
30
|
+
this.available = available;
|
|
31
|
+
this.name = 'DelegateResolutionError';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** 缺省失控防护:单父 session 同时挂载的未闭合委派上限 */
|
|
35
|
+
export const DEFAULT_MAX_ACTIVE_DELEGATIONS = 8;
|
|
36
|
+
function now() {
|
|
37
|
+
return Date.now();
|
|
38
|
+
}
|
|
39
|
+
/** 日志用的短摘要 */
|
|
40
|
+
function truncateForLog(text) {
|
|
41
|
+
return text.length <= 200 ? text : `${text.slice(0, 200)}…`;
|
|
42
|
+
}
|
|
43
|
+
/** 生成子 Session ID(D7;格式稳定可读,便于检索与审计) */
|
|
44
|
+
function makeChildSessionId(delegationId, agentId) {
|
|
45
|
+
return `cs-${delegationId.replace(/^del-/, '')}-${agentId}-${randomUUID().slice(0, 6)}`;
|
|
46
|
+
}
|
|
47
|
+
/** 生成子 Run ID */
|
|
48
|
+
function makeChildRunId() {
|
|
49
|
+
return `run-${randomUUID().slice(0, 8)}`;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 合并预算:请求预算 ∩ agent 上限(取更严的一侧)
|
|
53
|
+
*
|
|
54
|
+
* @param requested - 请求里的预算
|
|
55
|
+
* @param ceiling - agent 声明的预算上限
|
|
56
|
+
* @returns 生效预算
|
|
57
|
+
*/
|
|
58
|
+
export function intersectBudget(requested, ceiling) {
|
|
59
|
+
if (!requested && !ceiling)
|
|
60
|
+
return undefined;
|
|
61
|
+
const pick = (a, b) => {
|
|
62
|
+
if (a == null)
|
|
63
|
+
return b;
|
|
64
|
+
if (b == null)
|
|
65
|
+
return a;
|
|
66
|
+
return Math.min(a, b);
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
maxTurns: pick(requested?.maxTurns, ceiling?.maxTurns),
|
|
70
|
+
maxTokens: pick(requested?.maxTokens, ceiling?.maxTokens),
|
|
71
|
+
timeoutMs: pick(requested?.timeoutMs, ceiling?.timeoutMs),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* DelegateService — 委派编排
|
|
76
|
+
*/
|
|
77
|
+
export class DelegateService {
|
|
78
|
+
store;
|
|
79
|
+
registry;
|
|
80
|
+
transport;
|
|
81
|
+
config;
|
|
82
|
+
inflight = new Map();
|
|
83
|
+
constructor(store, registry, transport, config = {}) {
|
|
84
|
+
this.store = store;
|
|
85
|
+
this.registry = registry;
|
|
86
|
+
this.transport = transport;
|
|
87
|
+
this.config = config;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 非阻塞派发:建单并起子 Run,立即返回(§7)
|
|
91
|
+
*
|
|
92
|
+
* @param input - 派发入参
|
|
93
|
+
* @returns 委派单(status = queued 或 running)与解析出的目标
|
|
94
|
+
* @throws 目标不可达 / 不可被委派 / 深度超限 / 未闭合委派过多
|
|
95
|
+
*/
|
|
96
|
+
async dispatch(input) {
|
|
97
|
+
// 1. 解析目标(D2)
|
|
98
|
+
const handle = this.resolveTarget(input.target, input.parent.agentId);
|
|
99
|
+
// 2. 递归深度闸(§10.4)
|
|
100
|
+
const parentDepth = input.parentDepth ?? this.config.resolveParentDepth?.(input.parent.sessionId) ?? 0;
|
|
101
|
+
const depth = parentDepth + 1;
|
|
102
|
+
const maxDepth = handle.maxDepth ?? 1;
|
|
103
|
+
if (depth > maxDepth) {
|
|
104
|
+
throw new DelegateResolutionError(`delegation depth exceeded: ${depth} > ${maxDepth} (${handle.agentId})`, 'depth_exceeded');
|
|
105
|
+
}
|
|
106
|
+
// 3. 失控防护(§8);缺省有上限(委派默认开启,不能不限)
|
|
107
|
+
const limit = this.config.maxActiveDelegationsPerSession ?? DEFAULT_MAX_ACTIVE_DELEGATIONS;
|
|
108
|
+
if (limit != null) {
|
|
109
|
+
const active = this.store.list({
|
|
110
|
+
parentSessionId: input.parent.sessionId,
|
|
111
|
+
activeOnly: true,
|
|
112
|
+
}).length;
|
|
113
|
+
if (active >= limit) {
|
|
114
|
+
throw new DelegateResolutionError(`too many active delegations for session ${input.parent.sessionId}: ${active} >= ${limit}`, 'too_many_active');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// 4. 预算:请求 ∩ agent 上限(D3 只收紧)
|
|
118
|
+
const budget = intersectBudget(input.budget, handle.budget);
|
|
119
|
+
// 4b. 权利天花板:父有效权限 ∩ 目标自身天花板(D3 只收紧,不得借委派提权)
|
|
120
|
+
const rightsCeiling = tightenSessionRights(input.parentRights, handle.rightsCeiling);
|
|
121
|
+
// 5. deadlineAt(D4:数据化)
|
|
122
|
+
// `input.timeoutMs` 与 `budget.timeoutMs` 都要生效——任选其一,前者优先。
|
|
123
|
+
const deadlineAt = input.deadlineAt ??
|
|
124
|
+
this.deadlineFromBudget(budget) ??
|
|
125
|
+
(input.timeoutMs != null ? now() + input.timeoutMs : undefined);
|
|
126
|
+
// 6. 建单(唯一写入口)
|
|
127
|
+
const delegation = this.store.create({
|
|
128
|
+
parent: input.parent,
|
|
129
|
+
target: input.target,
|
|
130
|
+
task: input.task,
|
|
131
|
+
input: input.input,
|
|
132
|
+
context: input.context,
|
|
133
|
+
budget,
|
|
134
|
+
deadlineAt,
|
|
135
|
+
cancelable: input.cancelable,
|
|
136
|
+
cascade: input.cascade,
|
|
137
|
+
depth,
|
|
138
|
+
});
|
|
139
|
+
// 6b. 子身份在起 Run **之前**生成并落库(D7):
|
|
140
|
+
// 子 Run 期间发起的孙代委派要能经 findDepthByChildSession 查到深度(§10.4)。
|
|
141
|
+
const childSessionId = makeChildSessionId(delegation.id, handle.agentId);
|
|
142
|
+
const childRunId = makeChildRunId();
|
|
143
|
+
this.store.update(delegation.id, {
|
|
144
|
+
resolvedAgentId: handle.agentId,
|
|
145
|
+
childSessionId,
|
|
146
|
+
childRunId,
|
|
147
|
+
});
|
|
148
|
+
// 7. 起子 Run(非阻塞:不 await 终态)
|
|
149
|
+
const controller = new AbortController();
|
|
150
|
+
this.inflight.set(delegation.id, controller);
|
|
151
|
+
void this.runChild(delegation.id, handle, input, budget, rightsCeiling, deadlineAt, controller, childSessionId, childRunId);
|
|
152
|
+
return { delegation: this.store.get(delegation.id), resolvedAgentId: handle.agentId };
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* 读取委派单
|
|
156
|
+
*
|
|
157
|
+
* @param delegationId - 委派单 ID
|
|
158
|
+
* @returns 委派单;不存在返回 undefined
|
|
159
|
+
*/
|
|
160
|
+
get(delegationId) {
|
|
161
|
+
return this.store.get(delegationId);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* 列出委派单(poll 通道,§7)
|
|
165
|
+
*
|
|
166
|
+
* @param filter - 过滤条件
|
|
167
|
+
* @returns 匹配的委派单
|
|
168
|
+
*/
|
|
169
|
+
list(filter) {
|
|
170
|
+
return this.store.list(filter);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* 取消委派(D4)
|
|
174
|
+
*
|
|
175
|
+
* @param delegationId - 委派单 ID
|
|
176
|
+
* @returns 取消后的委派单
|
|
177
|
+
* @throws 委派单不存在,或已终态 / 不可取消
|
|
178
|
+
*/
|
|
179
|
+
cancel(delegationId, reason = 'cancelled by parent') {
|
|
180
|
+
const record = this.store.get(delegationId);
|
|
181
|
+
if (!record) {
|
|
182
|
+
throw new Error(`Delegation not found: ${delegationId}`);
|
|
183
|
+
}
|
|
184
|
+
if (isTerminalDelegationStatus(record.status)) {
|
|
185
|
+
throw new Error(`Delegation already terminal: ${record.status} (${delegationId})`);
|
|
186
|
+
}
|
|
187
|
+
if (!record.cancelable) {
|
|
188
|
+
throw new Error(`Delegation not cancelable: ${delegationId}`);
|
|
189
|
+
}
|
|
190
|
+
this.inflight.get(delegationId)?.abort();
|
|
191
|
+
this.inflight.delete(delegationId);
|
|
192
|
+
return this.store.update(delegationId, {
|
|
193
|
+
status: 'cancelled',
|
|
194
|
+
error: reason,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* 级联中止:父 session 消亡时中止其所有 `cascade: true` 的在途委派(决策 C1)
|
|
199
|
+
*
|
|
200
|
+
* 默认(`cascade: false`)子 Run **继续跑**,父结束不影响;
|
|
201
|
+
* 只有父显式声明 `cascade: true` 的委派会被中止。
|
|
202
|
+
*
|
|
203
|
+
* 调用时机由宿主决定(Gateway / 嵌入方在父 run 或父 session 终止时调用)。
|
|
204
|
+
*
|
|
205
|
+
* @param parentSessionId - 父 session ID
|
|
206
|
+
* @param reason - 中止原因(写入 error 字段)
|
|
207
|
+
* @returns 被中止的委派单 ID 列表
|
|
208
|
+
*/
|
|
209
|
+
abortChildren(parentSessionId, reason = 'parent terminated (cascade)') {
|
|
210
|
+
const aborted = [];
|
|
211
|
+
const active = this.store.list({ parentSessionId, activeOnly: true });
|
|
212
|
+
for (const record of active) {
|
|
213
|
+
if (!record.cascade)
|
|
214
|
+
continue;
|
|
215
|
+
try {
|
|
216
|
+
this.cancel(record.id, reason);
|
|
217
|
+
aborted.push(record.id);
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
// 并发下可能已被其他路径落到终态;跳过即可,状态机已保证不重复迁移
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return aborted;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* 渲染父 session 的委派状态提示(§7.3,供 `getSteeringMessages` 用)
|
|
227
|
+
*
|
|
228
|
+
* @param parentSessionId - 父 session ID
|
|
229
|
+
* @returns 状态提示文本;无未闭合且无未读终态时返回空串
|
|
230
|
+
*/
|
|
231
|
+
renderStatusHint(parentSessionId) {
|
|
232
|
+
const counts = this.store.countByStatus(parentSessionId);
|
|
233
|
+
const active = counts.queued + counts.running;
|
|
234
|
+
const doneUnsurfaced = this.store
|
|
235
|
+
.list({ parentSessionId, unsurfacedOnly: true })
|
|
236
|
+
.filter((d) => isTerminalDelegationStatus(d.status));
|
|
237
|
+
if (active === 0 && doneUnsurfaced.length === 0)
|
|
238
|
+
return '';
|
|
239
|
+
const parts = [];
|
|
240
|
+
if (counts.completed > 0)
|
|
241
|
+
parts.push(`${counts.completed} completed`);
|
|
242
|
+
if (counts.failed > 0)
|
|
243
|
+
parts.push(`${counts.failed} failed`);
|
|
244
|
+
if (counts.timeout > 0)
|
|
245
|
+
parts.push(`${counts.timeout} timeout`);
|
|
246
|
+
if (counts.cancelled > 0)
|
|
247
|
+
parts.push(`${counts.cancelled} cancelled`);
|
|
248
|
+
if (counts.queued > 0)
|
|
249
|
+
parts.push(`${counts.queued} queued`);
|
|
250
|
+
if (counts.running > 0)
|
|
251
|
+
parts.push(`${counts.running} running`);
|
|
252
|
+
return `<delegation_status>${parts.join(', ')}</delegation_status>`;
|
|
253
|
+
}
|
|
254
|
+
// ── 内部 ──
|
|
255
|
+
/**
|
|
256
|
+
* 解析目标(D2):agentId 优先,capability 兜底
|
|
257
|
+
*
|
|
258
|
+
* @param target - 目标寻址
|
|
259
|
+
* @param callerAgentId - 调用方 agentId(校验 callableBy)
|
|
260
|
+
* @returns 解析出的 AgentHandle
|
|
261
|
+
* @throws 目标不可达 / 不可被委派 / 策略拒绝
|
|
262
|
+
*/
|
|
263
|
+
resolveTarget(target, callerAgentId) {
|
|
264
|
+
if (target.agentId) {
|
|
265
|
+
const info = this.registry.get(target.agentId);
|
|
266
|
+
if (!info) {
|
|
267
|
+
throw new DelegateResolutionError(`delegate target not found: ${target.agentId}`, 'not_found', this.describeTargets());
|
|
268
|
+
}
|
|
269
|
+
return this.toHandle(info, callerAgentId);
|
|
270
|
+
}
|
|
271
|
+
if (target.trait) {
|
|
272
|
+
// 先验后挑:不可委派的候选要过滤掉,而不是挑中再抛错
|
|
273
|
+
//(否则第一个不可委派的命中会让整次委派失败,而不是落到下一个可用候选)
|
|
274
|
+
const candidates = this.registry
|
|
275
|
+
.findByTrait(target.trait)
|
|
276
|
+
.filter((info) => effectiveDelegationPolicy(info.delegation).callable)
|
|
277
|
+
.filter((info) => this.isCallableBy(info, callerAgentId));
|
|
278
|
+
const picked = candidates[0];
|
|
279
|
+
if (!picked) {
|
|
280
|
+
// 失败时回传**可用目标**,让调用方(LLM)一次就能改对,而不是瞎猜
|
|
281
|
+
throw new DelegateResolutionError(`no callable agent for trait: ${target.trait}`, 'not_found', this.describeTargets());
|
|
282
|
+
}
|
|
283
|
+
return this.toHandle(picked, callerAgentId);
|
|
284
|
+
}
|
|
285
|
+
throw new DelegateResolutionError('delegate target must set agentId or trait', 'not_found', this.describeTargets());
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* 列出**可用委派目标**(失败时回传,供调用方自愈)
|
|
289
|
+
*
|
|
290
|
+
* @returns 可用 traits 与 agent 概要
|
|
291
|
+
*/
|
|
292
|
+
describeTargets() {
|
|
293
|
+
return {
|
|
294
|
+
traits: [...new Set(this.registry.list().flatMap((a) => a.traits))].sort(),
|
|
295
|
+
agents: this.registry.list().map((a) => ({
|
|
296
|
+
id: a.id,
|
|
297
|
+
traits: [...a.traits],
|
|
298
|
+
callable: effectiveDelegationPolicy(a.delegation).callable,
|
|
299
|
+
})),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
/** 校验委派策略并转 AgentHandle */
|
|
303
|
+
toHandle(info, callerAgentId) {
|
|
304
|
+
const policy = effectiveDelegationPolicy(info.delegation);
|
|
305
|
+
if (!policy.callable) {
|
|
306
|
+
throw new DelegateResolutionError(`agent not callable for delegation: ${info.id}`, 'not_callable');
|
|
307
|
+
}
|
|
308
|
+
if (!this.isCallableBy(info, callerAgentId)) {
|
|
309
|
+
throw new DelegateResolutionError(`agent ${info.id} forbids delegation from ${callerAgentId}`, 'forbidden');
|
|
310
|
+
}
|
|
311
|
+
return {
|
|
312
|
+
agentId: info.id,
|
|
313
|
+
traits: info.traits,
|
|
314
|
+
rightsCeiling: policy.rightsCeiling,
|
|
315
|
+
budget: policy.budget,
|
|
316
|
+
maxDepth: policy.maxDepth,
|
|
317
|
+
callable: true,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
/** callableBy 白名单校验(缺省 = 任意) */
|
|
321
|
+
isCallableBy(info, callerAgentId) {
|
|
322
|
+
const allowed = effectiveDelegationPolicy(info.delegation).callableBy;
|
|
323
|
+
if (!allowed || allowed.length === 0)
|
|
324
|
+
return true;
|
|
325
|
+
return allowed.includes(callerAgentId);
|
|
326
|
+
}
|
|
327
|
+
/** budget.timeoutMs → deadlineAt */
|
|
328
|
+
deadlineFromBudget(budget) {
|
|
329
|
+
if (budget?.timeoutMs == null)
|
|
330
|
+
return undefined;
|
|
331
|
+
return now() + budget.timeoutMs;
|
|
332
|
+
}
|
|
333
|
+
/** 起子 Run、收结果、落终态(非阻塞入口) */
|
|
334
|
+
async runChild(delegationId, handle, input, budget, rightsCeiling, deadlineAt, controller, childSessionId, childRunId) {
|
|
335
|
+
const request = {
|
|
336
|
+
delegationId,
|
|
337
|
+
from: input.parent,
|
|
338
|
+
to: input.target,
|
|
339
|
+
childSessionId,
|
|
340
|
+
childRunId,
|
|
341
|
+
task: input.task,
|
|
342
|
+
input: input.input,
|
|
343
|
+
context: input.context ?? 'clean',
|
|
344
|
+
parentMessages: input.context === 'fork' ? input.parentMessages : undefined,
|
|
345
|
+
rightsCeiling,
|
|
346
|
+
budget,
|
|
347
|
+
deadlineAt,
|
|
348
|
+
cancelable: input.cancelable ?? true,
|
|
349
|
+
schemaVersion: DELEGATION_SCHEMA_VERSION,
|
|
350
|
+
};
|
|
351
|
+
// deadline 定时器(D4):到点中止本地执行并落 timeout 终态
|
|
352
|
+
let deadlineTimer;
|
|
353
|
+
if (deadlineAt != null) {
|
|
354
|
+
const delay = Math.max(0, deadlineAt - now());
|
|
355
|
+
deadlineTimer = setTimeout(() => {
|
|
356
|
+
controller.abort();
|
|
357
|
+
if (!isTerminalDelegationStatus(this.store.get(delegationId)?.status ?? 'queued')) {
|
|
358
|
+
this.store.update(delegationId, {
|
|
359
|
+
status: 'timeout',
|
|
360
|
+
error: `delegation timeout at deadline ${deadlineAt}`,
|
|
361
|
+
});
|
|
362
|
+
void this.notify(delegationId);
|
|
363
|
+
}
|
|
364
|
+
}, delay);
|
|
365
|
+
}
|
|
366
|
+
try {
|
|
367
|
+
this.store.update(delegationId, { status: 'running', startedAt: now() });
|
|
368
|
+
const result = await this.transport.call(request, controller.signal);
|
|
369
|
+
this.settleWithResult(delegationId, result);
|
|
370
|
+
}
|
|
371
|
+
catch (err) {
|
|
372
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
373
|
+
this.settleWithFailure(delegationId, controller.signal.aborted, message);
|
|
374
|
+
}
|
|
375
|
+
finally {
|
|
376
|
+
if (deadlineTimer)
|
|
377
|
+
clearTimeout(deadlineTimer);
|
|
378
|
+
this.inflight.delete(delegationId);
|
|
379
|
+
void this.notify(delegationId);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* 落成功终态。
|
|
384
|
+
*
|
|
385
|
+
* 若委派单已被 deadline / cancel 抢先落到终态,**不得覆盖**,但必须留痕——
|
|
386
|
+
* 否则子跑完的结果会无声无息消失(审查 P1-2)。
|
|
387
|
+
*/
|
|
388
|
+
settleWithResult(delegationId, result) {
|
|
389
|
+
const record = this.store.get(delegationId);
|
|
390
|
+
const current = record?.status;
|
|
391
|
+
if (current && isTerminalDelegationStatus(current)) {
|
|
392
|
+
this.noteLateOutcome(delegationId, current, result.output, undefined);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
// 归集 usage 到父的 run 账(决策 C2):写入委派单,由调用方/Runner 汇总
|
|
396
|
+
this.store.update(delegationId, {
|
|
397
|
+
status: result.status,
|
|
398
|
+
childSessionId: result.childSessionId,
|
|
399
|
+
childRunId: result.childRunId,
|
|
400
|
+
output: result.output,
|
|
401
|
+
artifacts: result.artifacts,
|
|
402
|
+
usage: result.usage,
|
|
403
|
+
error: result.error,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* 落失败终态。
|
|
408
|
+
*
|
|
409
|
+
* 已终态时**保留原 error**(如用户的取消原因),绝不让状态机内部文案
|
|
410
|
+
* 「Invalid delegation transition: …」污染对外可见面(审查 P1-2)。
|
|
411
|
+
*/
|
|
412
|
+
settleWithFailure(delegationId, aborted, message) {
|
|
413
|
+
const record = this.store.get(delegationId);
|
|
414
|
+
const current = record?.status;
|
|
415
|
+
if (current && isTerminalDelegationStatus(current)) {
|
|
416
|
+
this.noteLateOutcome(delegationId, current, undefined, message);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
this.store.update(delegationId, {
|
|
420
|
+
status: aborted ? 'cancelled' : 'failed',
|
|
421
|
+
error: message,
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* 迟到结果/失败留痕:保留原 error,追加一行说明,并打 warn。
|
|
426
|
+
*
|
|
427
|
+
* @param delegationId - 委派单 ID
|
|
428
|
+
* @param current - 已落入的终态
|
|
429
|
+
* @param lateOutput - 迟到的子产出(若有)
|
|
430
|
+
* @param lateError - 迟到的失败原因(若有)
|
|
431
|
+
*/
|
|
432
|
+
noteLateOutcome(delegationId, current, lateOutput, lateError) {
|
|
433
|
+
const detail = lateError ?? (lateOutput ? `output=${truncateForLog(lateOutput)}` : '(no output)');
|
|
434
|
+
const note = `late result dropped (delegation already ${current}): ${detail}`;
|
|
435
|
+
console.warn(`[Delegation] ${delegationId}: ${note}`);
|
|
436
|
+
const existing = this.store.get(delegationId)?.error;
|
|
437
|
+
this.store.update(delegationId, {
|
|
438
|
+
error: existing ? `${existing} | ${note}` : note,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* notify 通道触发点(§7.1)。
|
|
443
|
+
*
|
|
444
|
+
* `deliveryState` 只在**结果真正送达父**时为 `surfaced`:notify 投递成功
|
|
445
|
+
* (投递器自带接收端校验,发进空总线会抛错按失败处理),或父经
|
|
446
|
+
* {@link markSurfaced}(delegate_get)取回。投递期间为 `delivering`
|
|
447
|
+
* (乐观占位,提示保持点亮);投递器缺省 / 失败 / 被丢回滚时 `pending`,
|
|
448
|
+
* 让 §7.3 状态提示兜底——否则通知会无声消失。
|
|
449
|
+
*/
|
|
450
|
+
async notify(delegationId) {
|
|
451
|
+
const record = this.store.get(delegationId);
|
|
452
|
+
if (!record || !isTerminalDelegationStatus(record.status))
|
|
453
|
+
return;
|
|
454
|
+
// 去重:仅 pending 可投递(delivering = 投递进行中占位,surfaced = 已送达)
|
|
455
|
+
if (record.deliveryState !== 'pending')
|
|
456
|
+
return;
|
|
457
|
+
const notifier = this.config.notifier;
|
|
458
|
+
if (!notifier)
|
|
459
|
+
return;
|
|
460
|
+
// delivering 占位兼并发去重(替代旧 notifying Set)。dropped 事件在投递的
|
|
461
|
+
// 同步微任务链内先于本 await 续体到达(no_agent 等早期丢弃):wiring 回滚
|
|
462
|
+
// delivering → pending 后,续体的条件置位自然跳过——无需 generation 即时序自洽。
|
|
463
|
+
this.store.markDelivering(delegationId);
|
|
464
|
+
try {
|
|
465
|
+
await notifier(record);
|
|
466
|
+
// 条件置位:仅当投递期间未被回滚(仍 delivering)才记已送达。
|
|
467
|
+
// 若 dropped 已回滚成 pending,或父已 get 先行 surfaced,均不得覆盖
|
|
468
|
+
//(catch 的条件回滚同理——两个方向都只动 delivering 自己的占位)。
|
|
469
|
+
if (this.store.get(delegationId)?.deliveryState === 'delivering') {
|
|
470
|
+
this.store.markSurfaced(delegationId);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
catch (err) {
|
|
474
|
+
// 投递失败条件回滚(仅 delivering,与成功路径的条件置位对称):
|
|
475
|
+
// 不覆盖父 get 先行的 surfaced——否则已拿到结果的单会重新亮提示
|
|
476
|
+
if (this.store.get(delegationId)?.deliveryState === 'delivering') {
|
|
477
|
+
this.store.markUnsurfaced(delegationId);
|
|
478
|
+
}
|
|
479
|
+
// notify 失败不得影响委派单终态(poll + 状态提示兜底)。
|
|
480
|
+
// 吞掉投递异常但必须留痕——否则「没配投递器」与「每单都投递失败」无法区分;
|
|
481
|
+
// 委派单已是终态,未送达留待提示兜底,重试交由上层/分布式议题(§11)。
|
|
482
|
+
console.warn(`[Delegation] ${delegationId}: notify not delivered, un-surfaced kept for hint fallback: ${err instanceof Error ? err.message : String(err)}`);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* 标记委派单结果已送达父(§7.3 状态提示据此消音)。
|
|
487
|
+
*
|
|
488
|
+
* 送达途径之二:父经 `delegate_get` 主动取回终态结果(工具面在返回结果前
|
|
489
|
+
* 调用)。`delegate_list` 是只读概览,不置位——列表结果可能被截断,
|
|
490
|
+
* 只有明确取回单条全文才算送达。途径之一是 notify 投递成功(服务内部置位)。
|
|
491
|
+
*
|
|
492
|
+
* @param delegationId - 委派单 ID
|
|
493
|
+
* @returns 更新后的委派单
|
|
494
|
+
*/
|
|
495
|
+
markSurfaced(delegationId) {
|
|
496
|
+
return this.store.markSurfaced(delegationId);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
export { DelegationEvents };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DelegationStore — 委派单唯一写入口
|
|
3
|
+
*
|
|
4
|
+
* @layer harness/collaboration/delegation
|
|
5
|
+
* 设计权威:`arch/delegation.md` §4 / §6.2 / D10。
|
|
6
|
+
*
|
|
7
|
+
* 职责:
|
|
8
|
+
* - 读写 `Delegation`(委派单)
|
|
9
|
+
* - **状态机校验**(D10:独立状态机,不与 SessionTask / Workflow 共用)
|
|
10
|
+
* - 发射 `delegation.*` 事件(notify 通道的共同数据源,§7.1)
|
|
11
|
+
*
|
|
12
|
+
* 与 `SessionTaskService` 同构但**独立**:
|
|
13
|
+
* `docs/task-system.md` A2 明令 SessionTask 不做执行原语、不与执行件共状态机,
|
|
14
|
+
* 委派单不塞进 SessionTask。
|
|
15
|
+
*
|
|
16
|
+
* 持久化:v1 提供内存实现;跨进程持久化留待分布式议题(`arch/delegation.md` O5)。
|
|
17
|
+
* 但接口形状按可持久化设计(`Delegation` 全字段可序列化,D1/D5)。
|
|
18
|
+
*/
|
|
19
|
+
import type { EventBus } from '@octopi-agent/core/primitives/event-bus.js';
|
|
20
|
+
import type { Delegation, DelegationBudget, DelegationContextMode, DelegationParentRef, DelegationStatus, DelegationTarget, DelegationDeliveryState } from './types.js';
|
|
21
|
+
/** 建单入参(服务端生成 id / 时间戳 / 初始状态) */
|
|
22
|
+
export interface CreateDelegationInput {
|
|
23
|
+
parent: DelegationParentRef;
|
|
24
|
+
target: DelegationTarget;
|
|
25
|
+
task: string;
|
|
26
|
+
input: string;
|
|
27
|
+
context?: DelegationContextMode;
|
|
28
|
+
budget?: DelegationBudget;
|
|
29
|
+
/** 绝对截止时刻(D4);由 budget.timeoutMs 换算或调用方直接给 */
|
|
30
|
+
deadlineAt?: number;
|
|
31
|
+
cancelable?: boolean;
|
|
32
|
+
cascade?: boolean;
|
|
33
|
+
/** 委派深度(根委派 = 1) */
|
|
34
|
+
depth?: number;
|
|
35
|
+
}
|
|
36
|
+
/** 可更新字段(不含 id / parent / createdAt 等不可变字段) */
|
|
37
|
+
export interface UpdateDelegationPatch {
|
|
38
|
+
resolvedAgentId?: string;
|
|
39
|
+
status?: DelegationStatus;
|
|
40
|
+
childSessionId?: string;
|
|
41
|
+
childRunId?: string;
|
|
42
|
+
output?: string;
|
|
43
|
+
artifacts?: string[];
|
|
44
|
+
usage?: Delegation['usage'];
|
|
45
|
+
error?: string;
|
|
46
|
+
startedAt?: number;
|
|
47
|
+
completedAt?: number;
|
|
48
|
+
deadlineAt?: number;
|
|
49
|
+
deliveryState?: DelegationDeliveryState;
|
|
50
|
+
}
|
|
51
|
+
/** list 过滤 */
|
|
52
|
+
export interface DelegationListFilter {
|
|
53
|
+
parentSessionId?: string;
|
|
54
|
+
parentAgentId?: string;
|
|
55
|
+
status?: DelegationStatus | DelegationStatus[];
|
|
56
|
+
/** 仅未闭合(queued + running) */
|
|
57
|
+
activeOnly?: boolean;
|
|
58
|
+
/** 仅结果未送达的(§7.3 状态提示去重;delivering 视为未送达) */
|
|
59
|
+
unsurfacedOnly?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 校验状态迁移是否合法(D10 独立状态机)
|
|
63
|
+
*
|
|
64
|
+
* 合法迁移:
|
|
65
|
+
* - queued → running | failed | cancelled | timeout
|
|
66
|
+
* - running → completed | failed | cancelled | timeout
|
|
67
|
+
* - 终态 → 不可再迁(不可复用)
|
|
68
|
+
*
|
|
69
|
+
* @param from - 当前状态
|
|
70
|
+
* @param to - 目标状态
|
|
71
|
+
* @returns 是否合法
|
|
72
|
+
*/
|
|
73
|
+
export declare function canTransitionDelegation(from: DelegationStatus, to: DelegationStatus): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* DelegationStore — 委派单唯一写入口
|
|
76
|
+
*/
|
|
77
|
+
export declare class DelegationStore {
|
|
78
|
+
private readonly events?;
|
|
79
|
+
private readonly records;
|
|
80
|
+
constructor(events?: EventBus | undefined);
|
|
81
|
+
/**
|
|
82
|
+
* 建单(status 固定为 `queued`)
|
|
83
|
+
*
|
|
84
|
+
* @param input - 委派单入参
|
|
85
|
+
* @returns 新建的委派单
|
|
86
|
+
*/
|
|
87
|
+
create(input: CreateDelegationInput): Delegation;
|
|
88
|
+
/**
|
|
89
|
+
* 读取委派单
|
|
90
|
+
*
|
|
91
|
+
* @param delegationId - 委派单 ID
|
|
92
|
+
* @returns 委派单;不存在返回 undefined
|
|
93
|
+
*/
|
|
94
|
+
get(delegationId: string): Delegation | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* 更新委派单(含状态机校验)
|
|
97
|
+
*
|
|
98
|
+
* @param delegationId - 委派单 ID
|
|
99
|
+
* @param patch - 变更字段
|
|
100
|
+
* @returns 更新后的委派单
|
|
101
|
+
* @throws 委派单不存在,或状态迁移非法
|
|
102
|
+
*/
|
|
103
|
+
update(delegationId: string, patch: UpdateDelegationPatch): Delegation;
|
|
104
|
+
/**
|
|
105
|
+
* 列出委派单
|
|
106
|
+
*
|
|
107
|
+
* @param filter - 过滤条件
|
|
108
|
+
* @returns 匹配的委派单(按 createdAt 升序)
|
|
109
|
+
*/
|
|
110
|
+
list(filter?: DelegationListFilter): Delegation[];
|
|
111
|
+
/**
|
|
112
|
+
* 统计父 session 下各状态数量(§7.3 状态提示渲染用)
|
|
113
|
+
*
|
|
114
|
+
* @param parentSessionId - 父 session ID
|
|
115
|
+
* @returns 状态 → 数量
|
|
116
|
+
*/
|
|
117
|
+
countByStatus(parentSessionId: string): Record<DelegationStatus, number>;
|
|
118
|
+
/**
|
|
119
|
+
* 查子 session 所在的委派链深度(§10.4 递归深度闸)
|
|
120
|
+
*
|
|
121
|
+
* 子 session 的深度 = 创建它的那张委派单的 `depth`。
|
|
122
|
+
* 查不到表示该 session 非委派产生,视作根(返回 undefined,调用方按 0 处理)。
|
|
123
|
+
*
|
|
124
|
+
* @param childSessionId - 子 session ID
|
|
125
|
+
* @returns 委派链深度;非委派 session 返回 undefined
|
|
126
|
+
*/
|
|
127
|
+
findDepthByChildSession(childSessionId: string): number | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* 标记投递进行中(§7.1 乐观占位,pending → delivering)。
|
|
130
|
+
* 兼作并发去重位:投递期间同单的重复 notify 入口直接返回。
|
|
131
|
+
*
|
|
132
|
+
* @param delegationId - 委派单 ID
|
|
133
|
+
* @returns 更新后的委派单
|
|
134
|
+
*/
|
|
135
|
+
markDelivering(delegationId: string): Delegation;
|
|
136
|
+
/**
|
|
137
|
+
* 标记结果已送达父(→ surfaced,§7.3 去重):notify 投递成功
|
|
138
|
+
* 或父经 delegate_get 全文取回。
|
|
139
|
+
*
|
|
140
|
+
* @param delegationId - 委派单 ID
|
|
141
|
+
* @returns 更新后的委派单
|
|
142
|
+
*/
|
|
143
|
+
markSurfaced(delegationId: string): Delegation;
|
|
144
|
+
/**
|
|
145
|
+
* 回滚送达标记(→ pending,§7.1 送达回执)——投递失败或 dispatch 被丢
|
|
146
|
+
* (`runtime.trigger.dropped`)时调用,让 §7.3 提示重新兜底。
|
|
147
|
+
* 回滚只在推断安全方向上发生:宁可提示多亮一次(父 get 消音),不可丢结果。
|
|
148
|
+
*
|
|
149
|
+
* @param delegationId - 委派单 ID
|
|
150
|
+
* @returns 更新后的委派单
|
|
151
|
+
*/
|
|
152
|
+
markUnsurfaced(delegationId: string): Delegation;
|
|
153
|
+
private eventForStatus;
|
|
154
|
+
private emit;
|
|
155
|
+
}
|