@octopi-agent/engine 0.70.7 → 0.90.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -201
- package/NOTICE +7 -7
- package/README.md +64 -26
- package/dist/config-schema/agent.d.ts +89 -1
- package/dist/config-schema/agent.js +81 -5
- package/dist/config-schema/context.d.ts +24 -5
- package/dist/config-schema/context.js +28 -1
- package/dist/config-schema/engine.d.ts +205 -13
- package/dist/config-schema/engine.js +31 -2
- package/dist/config-schema/governance.d.ts +95 -0
- package/dist/config-schema/governance.js +93 -1
- package/dist/config-schema/models.d.ts +3 -3
- package/dist/config-schema/observability.d.ts +6 -0
- package/dist/config-schema/observability.js +16 -0
- package/dist/config-schema/run.d.ts +10 -0
- package/dist/config-schema/run.js +18 -0
- package/dist/config-schema/shared.d.ts +13 -0
- package/dist/config-schema/shared.js +22 -0
- package/dist/config-schema/substrate.d.ts +2 -2
- package/dist/config-schema/subsystems.d.ts +1 -1
- package/dist/config-schema/subsystems.js +2 -1
- package/dist/config.d.ts +201 -8
- package/dist/config.js +105 -3
- package/dist/harness/activation/compiler.js +3 -0
- package/dist/harness/activation/runtime.d.ts +7 -0
- package/dist/harness/activation/runtime.js +60 -2
- package/dist/harness/activation/sources/agent-signal.d.ts +11 -0
- package/dist/harness/activation/sources/agent-signal.js +33 -0
- package/dist/harness/activation/types.d.ts +6 -1
- package/dist/harness/agent/builder.d.ts +50 -5
- package/dist/harness/agent/builder.js +189 -59
- package/dist/harness/agent/config-bridge.d.ts +33 -25
- package/dist/harness/agent/config-bridge.js +84 -291
- package/dist/harness/agent/index.d.ts +3 -1
- package/dist/harness/agent/index.js +2 -1
- package/dist/harness/agent/tool-purpose.d.ts +46 -0
- package/dist/harness/agent/tool-purpose.js +127 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +133 -0
- package/dist/harness/agent/wire-agent-builder.js +370 -0
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.d.ts +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/loader.d.ts +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +16 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +8 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +17 -9
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +12 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +19 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.d.ts +6 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/session-lifecycle-bridge.js +24 -7
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.d.ts +5 -2
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +11 -3
- package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.d.ts +7 -4
- package/dist/harness/collaboration/autonomous-subsystem/think/llm-port.js +8 -9
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.d.ts +36 -10
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +60 -7
- package/dist/harness/collaboration/delegation/child-run.d.ts +144 -0
- package/dist/harness/collaboration/delegation/child-run.js +241 -0
- package/dist/harness/collaboration/delegation/index.d.ts +26 -0
- package/dist/harness/collaboration/delegation/index.js +25 -0
- package/dist/harness/collaboration/delegation/notifier.d.ts +46 -0
- package/dist/harness/collaboration/delegation/notifier.js +84 -0
- package/dist/harness/collaboration/delegation/registry-types.d.ts +200 -0
- package/dist/harness/collaboration/delegation/registry-types.js +61 -0
- package/dist/harness/collaboration/delegation/registry.d.ts +110 -0
- package/dist/harness/collaboration/delegation/registry.js +220 -0
- package/dist/harness/collaboration/delegation/service.d.ts +249 -0
- package/dist/harness/collaboration/delegation/service.js +499 -0
- package/dist/harness/collaboration/delegation/store.d.ts +155 -0
- package/dist/harness/collaboration/delegation/store.js +271 -0
- package/dist/harness/collaboration/delegation/transport.d.ts +73 -0
- package/dist/harness/collaboration/delegation/transport.js +61 -0
- package/dist/harness/collaboration/delegation/types.d.ts +231 -0
- package/dist/harness/collaboration/delegation/types.js +70 -0
- package/dist/harness/collaboration/delegation/wiring.d.ts +111 -0
- package/dist/harness/collaboration/delegation/wiring.js +145 -0
- package/dist/harness/collaboration/orchestration/index.d.ts +11 -13
- package/dist/harness/collaboration/orchestration/index.js +11 -11
- package/dist/harness/context/assembler.d.ts +2 -2
- package/dist/harness/context/assembler.js +12 -7
- package/dist/harness/context/capabilities/compact/engine.js +80 -38
- package/dist/harness/context/capabilities/compact/types.d.ts +12 -1
- package/dist/harness/context/capabilities/summary/registry.js +10 -0
- package/dist/harness/context/constitution/default-agents.md +230 -228
- package/dist/harness/context/default-context-engine.d.ts +101 -23
- package/dist/harness/context/default-context-engine.js +483 -172
- package/dist/harness/context/hybrid-compressor.d.ts +3 -3
- package/dist/harness/context/hybrid-compressor.js +18 -23
- package/dist/harness/context/index.d.ts +5 -1
- package/dist/harness/context/index.js +2 -0
- package/dist/harness/context/layer-snapshot.d.ts +4 -0
- package/dist/harness/context/layer-snapshot.js +30 -18
- package/dist/harness/context/layer-types.d.ts +85 -1
- package/dist/harness/context/layer-types.js +110 -4
- package/dist/harness/context/layers.d.ts +5 -2
- package/dist/harness/context/layers.js +11 -5
- package/dist/harness/context/llm-summarizer.d.ts +15 -1
- package/dist/harness/context/llm-summarizer.js +107 -56
- package/dist/harness/context/message-selector.js +6 -2
- package/dist/harness/context/root-instructions.d.ts +72 -0
- package/dist/harness/context/root-instructions.js +227 -0
- package/dist/harness/context/runtime-datetime.d.ts +34 -7
- package/dist/harness/context/runtime-datetime.js +66 -10
- package/dist/harness/context/smart-router.d.ts +1 -1
- package/dist/harness/context/smart-router.js +1 -1
- package/dist/harness/context/system-prompt-assembler.d.ts +30 -0
- package/dist/harness/context/system-prompt-assembler.js +73 -6
- package/dist/harness/context/token-constants.d.ts +2 -2
- package/dist/harness/context/token-constants.js +2 -2
- package/dist/harness/context/token-estimate-fns.d.ts +1 -3
- package/dist/harness/context/token-estimate-fns.js +2 -4
- package/dist/harness/context/token-estimator.d.ts +1 -1
- package/dist/harness/context/token-estimator.js +14 -6
- package/dist/harness/context/tool-result-aging.d.ts +140 -0
- package/dist/harness/context/tool-result-aging.js +331 -0
- package/dist/harness/context/tool-result-body.d.ts +10 -0
- package/dist/harness/context/tool-result-body.js +27 -0
- package/dist/harness/context/turn-envelope.d.ts +123 -0
- package/dist/harness/context/turn-envelope.js +188 -0
- package/dist/harness/context/types.d.ts +35 -47
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +258 -0
- package/dist/harness/extension/execution-environment/effect-policy.js +358 -0
- package/dist/harness/extension/execution-environment/index.d.ts +18 -2
- package/dist/harness/extension/execution-environment/index.js +11 -2
- package/dist/harness/extension/execution-environment/isolation.js +5 -1
- package/dist/harness/extension/execution-environment/memory-undo.d.ts +101 -0
- package/dist/harness/extension/execution-environment/memory-undo.js +192 -0
- package/dist/harness/extension/execution-environment/process-isolation.d.ts +84 -0
- package/dist/harness/extension/execution-environment/process-isolation.js +315 -0
- package/dist/harness/extension/execution-environment/resource-limits.d.ts +36 -0
- package/dist/harness/extension/execution-environment/resource-limits.js +84 -0
- package/dist/harness/extension/execution-environment/sandbox.d.ts +125 -4
- package/dist/harness/extension/execution-environment/sandbox.js +521 -51
- package/dist/harness/extension/execution-environment/shell-journal.d.ts +100 -0
- package/dist/harness/extension/execution-environment/shell-journal.js +299 -0
- package/dist/harness/extension/execution-environment/tool-capabilities.d.ts +45 -0
- package/dist/harness/extension/execution-environment/tool-capabilities.js +126 -0
- package/dist/harness/extension/execution-environment/types.d.ts +67 -39
- package/dist/harness/extension/execution-environment/types.js +2 -2
- package/dist/harness/extension/execution-environment/undo-log.d.ts +203 -0
- package/dist/harness/extension/execution-environment/undo-log.js +627 -0
- package/dist/harness/extension/execution-environment/undo-merge.d.ts +40 -0
- package/dist/harness/extension/execution-environment/undo-merge.js +167 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/index.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/mcp/bridge.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +1 -6
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +3 -8
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +2 -10
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +2 -9
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +1 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/index.js +1 -3
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +2 -4
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +4 -21
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +3 -9
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +4 -8
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +1 -4
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +1 -3
- package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/skills/manager.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.d.ts +51 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +153 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +18 -3
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +277 -81
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.d.ts +31 -0
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +291 -0
- package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +10 -2
- package/dist/harness/extension/plugin-ecosystem/tools/env-info.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/eol.d.ts +35 -0
- package/dist/harness/extension/plugin-ecosystem/tools/eol.js +43 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +40 -9
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.d.ts +33 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +376 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +12 -2
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +241 -70
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.d.ts +31 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.js +104 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.d.ts +111 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.js +197 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.d.ts +27 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +463 -0
- package/dist/harness/extension/plugin-ecosystem/tools/http.d.ts +10 -6
- package/dist/harness/extension/plugin-ecosystem/tools/http.js +41 -47
- package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +6 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/memory.js +25 -1
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.d.ts +13 -0
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +391 -0
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +51 -2
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +151 -12
- package/dist/harness/extension/plugin-ecosystem/tools/session-history.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +10 -1
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +35 -19
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +8 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/web-search.js +1 -0
- package/dist/harness/governance/credentials/index.d.ts +1 -1
- package/dist/harness/governance/credentials/store.d.ts +16 -4
- package/dist/harness/governance/credentials/store.js +33 -6
- package/dist/harness/governance/credentials/types.d.ts +11 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +105 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +184 -0
- package/dist/harness/governance/human-in-the-loop/index.d.ts +5 -5
- package/dist/harness/governance/human-in-the-loop/index.js +3 -3
- package/dist/harness/governance/human-in-the-loop/types.d.ts +7 -62
- package/dist/harness/governance/human-in-the-loop/types.js +6 -2
- package/dist/harness/governance/security/capability-enforcer.d.ts +9 -1
- package/dist/harness/governance/security/capability-enforcer.js +31 -8
- package/dist/harness/governance/security/degradation.js +5 -7
- package/dist/harness/governance/security/risk-evaluator.d.ts +1 -1
- package/dist/harness/governance/security/risk-evaluator.js +4 -82
- package/dist/harness/governance/security/temp-path.d.ts +41 -0
- package/dist/harness/governance/security/temp-path.js +117 -0
- package/dist/harness/governance/session-acl/index.d.ts +1 -0
- package/dist/harness/governance/session-acl/index.js +1 -0
- package/dist/harness/governance/session-acl/rights.d.ts +12 -0
- package/dist/harness/governance/session-acl/rights.js +89 -7
- package/dist/harness/governance/session-acl/seed-roles.js +9 -1
- package/dist/harness/governance/session-acl/service.js +21 -29
- package/dist/harness/governance/session-acl/tool-rights.d.ts +81 -0
- package/dist/harness/governance/session-acl/tool-rights.js +238 -0
- package/dist/harness/governance/session-acl/types.d.ts +22 -0
- package/dist/harness/index.d.ts +16 -12
- package/dist/harness/index.js +10 -6
- package/dist/harness/knowledge/file-identity.d.ts +8 -0
- package/dist/harness/knowledge/file-identity.js +26 -1
- package/dist/harness/knowledge/file-index-store.js +11 -11
- package/dist/harness/knowledge/grounding.d.ts +2 -1
- package/dist/harness/knowledge/grounding.js +8 -5
- package/dist/harness/knowledge/index-store.d.ts +31 -4
- package/dist/harness/knowledge/index-store.js +121 -39
- package/dist/harness/knowledge/index.d.ts +2 -2
- package/dist/harness/knowledge/index.js +1 -1
- package/dist/harness/knowledge/ingest.d.ts +115 -115
- package/dist/harness/knowledge/ingest.js +154 -151
- package/dist/harness/knowledge/job-control-state.js +4 -4
- package/dist/harness/knowledge/job-control.js +11 -11
- package/dist/harness/knowledge/knowledge-serve-child.js +1 -1
- package/dist/harness/knowledge/membership-store.js +11 -11
- package/dist/harness/knowledge/network-guard.d.ts +61 -4
- package/dist/harness/knowledge/network-guard.js +390 -113
- package/dist/harness/knowledge/purge.js +4 -1
- package/dist/harness/knowledge/query-service.js +3 -3
- package/dist/harness/knowledge/writer-service.d.ts +2 -0
- package/dist/harness/knowledge/writer-service.js +14 -13
- package/dist/harness/memory/backfill-coverage.js +3 -1
- package/dist/harness/memory/backfill-trigger.d.ts +2 -2
- package/dist/harness/memory/backfill-trigger.js +4 -4
- package/dist/harness/memory/index.d.ts +1 -0
- package/dist/harness/memory/index.js +1 -0
- package/dist/harness/memory/sqlite/agent-db.js +2 -0
- package/dist/harness/memory/sqlite/memory-store.d.ts +1 -0
- package/dist/harness/memory/sqlite/memory-store.js +14 -4
- package/dist/harness/memory/sqlite/wisdom-store.js +9 -9
- package/dist/harness/memory/store.d.ts +1 -0
- package/dist/harness/memory/store.js +3 -0
- package/dist/harness/memory/time-format.d.ts +28 -0
- package/dist/harness/memory/time-format.js +52 -0
- package/dist/harness/memory/types.d.ts +12 -0
- package/dist/harness/observability/observer/hub.js +53 -2
- package/dist/harness/observability/observer/index.d.ts +2 -2
- package/dist/harness/observability/observer/index.js +1 -1
- package/dist/harness/observability/observer/types.d.ts +80 -0
- package/dist/harness/observability/observer/types.js +118 -9
- package/dist/harness/run/agent/agent.d.ts +18 -0
- package/dist/harness/run/agent/agent.js +26 -0
- package/dist/harness/run/concurrency/tool-loop-detection-core.d.ts +1 -1
- package/dist/harness/run/concurrency/tool-loop-detection-core.js +1 -1
- package/dist/harness/run/reliability/harness-events.d.ts +4 -0
- package/dist/harness/run/reliability/run-agent.js +110 -18
- package/dist/harness/run/reliability/run-metrics-collector.d.ts +28 -2
- package/dist/harness/run/reliability/run-metrics-collector.js +92 -2
- package/dist/harness/run/run-guard/default-run-guard.d.ts +0 -5
- package/dist/harness/run/run-guard/default-run-guard.js +104 -44
- package/dist/harness/run/run-scope.d.ts +52 -0
- package/dist/harness/run/runner.d.ts +117 -16
- package/dist/harness/run/runner.js +668 -157
- package/dist/harness/session/attachments/llm-intent.js +17 -17
- package/dist/harness/session/history/port.js +16 -5
- package/dist/harness/session/in-memory-store.d.ts +6 -0
- package/dist/harness/session/in-memory-store.js +55 -3
- package/dist/harness/session/schedules/index.d.ts +10 -0
- package/dist/harness/session/schedules/index.js +10 -0
- package/dist/harness/session/schedules/render.d.ts +13 -0
- package/dist/harness/session/schedules/render.js +63 -0
- package/dist/harness/session/schedules/service.d.ts +179 -0
- package/dist/harness/session/schedules/service.js +695 -0
- package/dist/harness/session/schedules/store.d.ts +119 -0
- package/dist/harness/session/schedules/store.js +323 -0
- package/dist/harness/session/schedules/tools.d.ts +39 -0
- package/dist/harness/session/schedules/tools.js +442 -0
- package/dist/harness/session/schedules/types.d.ts +104 -0
- package/dist/harness/session/schedules/types.js +97 -0
- package/dist/harness/session/tasks/tools.js +22 -0
- package/dist/harness/session/title.js +25 -9
- package/dist/harness/session/types.d.ts +35 -0
- package/dist/harness/shared/events/agent-event-map.d.ts +39 -0
- package/dist/harness/shared/events/agent-event-map.js +2 -0
- package/dist/harness/shared/types/agent-definition.d.ts +23 -0
- package/dist/index.d.ts +25 -9
- package/dist/index.js +11 -2
- package/dist/integration/observability/run-telemetry.d.ts +8 -0
- package/dist/integration/observability/run-telemetry.js +31 -8
- package/dist/integration/observability/trace-collector.js +26 -4
- package/dist/integration/observability/trace-events.d.ts +1 -0
- package/dist/integration/observability/trace-events.js +2 -0
- package/dist/integration/observability/trace-logger.js +27 -17
- package/dist/integration/providers/anthropic.d.ts +10 -0
- package/dist/integration/providers/anthropic.js +44 -1
- package/dist/integration/providers/openai.d.ts +10 -0
- package/dist/integration/providers/openai.js +58 -2
- package/dist/integration/providers/wire-dump-diff.d.ts +191 -0
- package/dist/integration/providers/wire-dump-diff.js +351 -0
- package/dist/integration/providers/wire-dump.d.ts +178 -0
- package/dist/integration/providers/wire-dump.js +396 -0
- package/dist/integration/storage/jsonl.d.ts +29 -0
- package/dist/integration/storage/jsonl.js +243 -41
- package/dist/integration/storage/session-index.js +63 -8
- package/dist/paths.d.ts +19 -0
- package/dist/paths.js +38 -1
- package/dist/subsystems/cognition-steward/conceptualize/SUBSYSTEM.md +43 -43
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +50 -50
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +6 -6
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +54 -54
- package/dist/subsystems/memory-steward/backfill/handler.js +9 -0
- package/dist/subsystems/safety-guard/config.yaml +3 -1
- package/dist/subsystems/wisdom-steward/evaluate/config.yaml +50 -50
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +42 -42
- package/dist/subsystems/wisdom-steward/formation/config.yaml +54 -54
- package/dist/subsystems/wisdom-steward/govern/config.yaml +55 -55
- package/package.json +115 -115
- package/dist/harness/collaboration/multi-agent/agent-registry-types.d.ts +0 -144
- package/dist/harness/collaboration/multi-agent/agent-registry-types.js +0 -25
- package/dist/harness/collaboration/multi-agent/index.d.ts +0 -17
- package/dist/harness/collaboration/multi-agent/index.js +0 -15
- package/dist/harness/collaboration/multi-agent/process.d.ts +0 -167
- package/dist/harness/collaboration/multi-agent/process.js +0 -256
- package/dist/harness/collaboration/multi-agent/registry.d.ts +0 -36
- package/dist/harness/collaboration/multi-agent/registry.js +0 -137
- package/dist/harness/collaboration/multi-agent/swarm.d.ts +0 -135
- package/dist/harness/collaboration/multi-agent/swarm.js +0 -317
- package/dist/harness/collaboration/multi-agent/types.d.ts +0 -66
- package/dist/harness/collaboration/multi-agent/types.js +0 -15
- package/dist/harness/collaboration/orchestration/async-task-store.d.ts +0 -107
- package/dist/harness/collaboration/orchestration/async-task-store.js +0 -12
- package/dist/harness/collaboration/orchestration/async-task.d.ts +0 -156
- package/dist/harness/collaboration/orchestration/async-task.js +0 -359
- package/dist/harness/collaboration/orchestration/planner/hybrid-planner.d.ts +0 -47
- package/dist/harness/collaboration/orchestration/planner/hybrid-planner.js +0 -61
- package/dist/harness/collaboration/orchestration/planner/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/planner/index.js +0 -6
- package/dist/harness/collaboration/orchestration/planner/llm-planner.d.ts +0 -54
- package/dist/harness/collaboration/orchestration/planner/llm-planner.js +0 -167
- package/dist/harness/collaboration/orchestration/planner/rule-planner.d.ts +0 -85
- package/dist/harness/collaboration/orchestration/planner/rule-planner.js +0 -175
- package/dist/harness/collaboration/orchestration/quality/classifier.d.ts +0 -21
- package/dist/harness/collaboration/orchestration/quality/classifier.js +0 -235
- package/dist/harness/collaboration/orchestration/quality/gate.d.ts +0 -29
- package/dist/harness/collaboration/orchestration/quality/gate.js +0 -409
- package/dist/harness/collaboration/orchestration/quality/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/quality/index.js +0 -8
- package/dist/harness/collaboration/orchestration/quality/types.d.ts +0 -159
- package/dist/harness/collaboration/orchestration/quality/types.js +0 -33
- package/dist/harness/collaboration/orchestration/scheduler/index.d.ts +0 -5
- package/dist/harness/collaboration/orchestration/scheduler/index.js +0 -4
- package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.d.ts +0 -143
- package/dist/harness/collaboration/orchestration/scheduler/task-scheduler.js +0 -297
- package/dist/harness/collaboration/orchestration/strategy/classifier.d.ts +0 -12
- package/dist/harness/collaboration/orchestration/strategy/classifier.js +0 -81
- package/dist/harness/collaboration/orchestration/strategy/index.d.ts +0 -3
- package/dist/harness/collaboration/orchestration/strategy/index.js +0 -2
- package/dist/harness/collaboration/orchestration/strategy/router.d.ts +0 -28
- package/dist/harness/collaboration/orchestration/strategy/router.js +0 -105
- package/dist/harness/collaboration/orchestration/strategy/types.d.ts +0 -49
- package/dist/harness/collaboration/orchestration/strategy/types.js +0 -4
- package/dist/harness/collaboration/orchestration/workflow/engine.d.ts +0 -86
- package/dist/harness/collaboration/orchestration/workflow/engine.js +0 -298
- package/dist/harness/collaboration/orchestration/workflow/index.d.ts +0 -9
- package/dist/harness/collaboration/orchestration/workflow/index.js +0 -7
- package/dist/harness/collaboration/orchestration/workflow/types.d.ts +0 -143
- package/dist/harness/collaboration/orchestration/workflow/types.js +0 -7
- package/dist/harness/governance/human-in-the-loop/approval-manager.d.ts +0 -32
- package/dist/harness/governance/human-in-the-loop/approval-manager.js +0 -93
- /package/dist/harness/collaboration/{multi-agent → delegation}/message-channel-types.d.ts +0 -0
- /package/dist/harness/collaboration/{multi-agent → delegation}/message-channel-types.js +0 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChildRunPort — 子 Run 执行端口
|
|
3
|
+
*
|
|
4
|
+
* @layer harness/collaboration/delegation
|
|
5
|
+
* 设计权威:`arch/delegation.md` §10。
|
|
6
|
+
*
|
|
7
|
+
* 职责:把一个 `DelegateRequest` 变成一次**真实受监督的子 Run**,产出 `ChildRunOutput`。
|
|
8
|
+
*
|
|
9
|
+
* 不变量落点:
|
|
10
|
+
* - **D7** 子 Run 落**独立 Session**,带 `spawnBy` 父子关联(`SessionSpawnLink`)
|
|
11
|
+
* - **D8** 子 Run 走 `SessionAwareRunner.handle()` —— 该入口自带
|
|
12
|
+
* per-run `AgentContext` + `RunScope` + session 锁 + SessionGate + ACL,
|
|
13
|
+
* 因此**绝不写 `agent.context.messages`**(旧 multi-agent 路径的 I1 违规)
|
|
14
|
+
* - **D9** 并发硬闸仍只在 SessionGate 一处(委派层不建第二把闸)
|
|
15
|
+
*
|
|
16
|
+
* 与 transport 的分工:
|
|
17
|
+
* transport 管"怎么把请求送到目标"(进程内 / 将来跨进程);
|
|
18
|
+
* 本端口管"目标本地怎么起 Run"。两者不可互相渗透。
|
|
19
|
+
*/
|
|
20
|
+
import type { SessionStore } from '@octopi-agent/core/interfaces/session-store.js';
|
|
21
|
+
import type { TokenUsage } from '@octopi-agent/core/types/turn.js';
|
|
22
|
+
import type { AgentEvent } from '@octopi-agent/core/primitives/event-bus.js';
|
|
23
|
+
import type { SessionData, SessionSpawnLink } from '../../session/types.js';
|
|
24
|
+
import type { DelegationBudget, DelegationContextMode } from './types.js';
|
|
25
|
+
/** 子 Run 入参 */
|
|
26
|
+
export interface ChildRunInput {
|
|
27
|
+
delegationId: string;
|
|
28
|
+
/** 目标 agentId(已解析) */
|
|
29
|
+
childAgentId: string;
|
|
30
|
+
task: string;
|
|
31
|
+
input: string;
|
|
32
|
+
/** 上下文传递模式 */
|
|
33
|
+
context: DelegationContextMode;
|
|
34
|
+
/** 父消息历史(仅 context='fork' 时携带);调用方传快照 */
|
|
35
|
+
parentMessages?: import('@octopi-agent/core/types.js').Message[];
|
|
36
|
+
/** 父子关联(写入 child session 的 `spawnBy`,D7) */
|
|
37
|
+
spawnBy: SessionSpawnLink;
|
|
38
|
+
/**
|
|
39
|
+
* 子 Session / Run ID(D7)。
|
|
40
|
+
*
|
|
41
|
+
* 由服务方在起子 Run **之前**生成并落库——否则子 Run 期间发起的孙代委派
|
|
42
|
+
* 查不到 `childSessionId`,递归深度闸(§10.4)会失效。
|
|
43
|
+
*/
|
|
44
|
+
childSessionId: string;
|
|
45
|
+
childRunId: string;
|
|
46
|
+
/** 子的 systemPrompt(模板 persona + 编排指令,§9.4) */
|
|
47
|
+
systemPrompt: string;
|
|
48
|
+
budget?: DelegationBudget;
|
|
49
|
+
/** 权利天花板(D3:只能收紧不能放宽);进 `RunConfig.rightsCeiling` */
|
|
50
|
+
rightsCeiling?: import('../../governance/session-acl/types.js').SessionRights;
|
|
51
|
+
}
|
|
52
|
+
/** 子 Run 产出(D5:可序列化) */
|
|
53
|
+
export interface ChildRunOutput {
|
|
54
|
+
childSessionId: string;
|
|
55
|
+
childRunId: string;
|
|
56
|
+
output?: string;
|
|
57
|
+
/** 产物路径;未产出时**省略**(不写假空数组) */
|
|
58
|
+
artifacts?: string[];
|
|
59
|
+
usage?: TokenUsage;
|
|
60
|
+
error?: string;
|
|
61
|
+
/** 是否被中止(cascade / cancel)——用于把结果映射为 `cancelled` 而非 `failed` */
|
|
62
|
+
aborted?: boolean;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 子 Run 执行端口
|
|
66
|
+
*/
|
|
67
|
+
export interface ChildRunPort {
|
|
68
|
+
/**
|
|
69
|
+
* 起一次受监督的子 Run
|
|
70
|
+
*
|
|
71
|
+
* @param input - 子 Run 入参
|
|
72
|
+
* @param signal - 中止信号(D4 的本地投影)
|
|
73
|
+
* @returns 子 Run 产出
|
|
74
|
+
*/
|
|
75
|
+
run(input: ChildRunInput, signal?: AbortSignal): Promise<ChildRunOutput>;
|
|
76
|
+
}
|
|
77
|
+
/** 目标 agent 的运行时句柄 */
|
|
78
|
+
export interface ChildRunTarget {
|
|
79
|
+
/** 该 agent 的 SessionAwareRunner(自带 harness / ACL / SessionGate) */
|
|
80
|
+
runner: {
|
|
81
|
+
handle(sessionId: string, input: import('@octopi-agent/core/types.js').Message, runConfig: import('../../run/runner.js').RunConfig, signal?: AbortSignal): AsyncGenerator<AgentEvent>;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* 该 agent 的 SessionStore。
|
|
85
|
+
*
|
|
86
|
+
* 必须与 `runner.handle()` 读的是**同一个** store,否则预创建的 child session
|
|
87
|
+
* (带 `spawnBy`,D7)对子 Run 不可见。
|
|
88
|
+
*/
|
|
89
|
+
store: SessionStore<SessionData>;
|
|
90
|
+
}
|
|
91
|
+
/** RunnerChildRunPort 配置 */
|
|
92
|
+
export interface RunnerChildRunPortConfig {
|
|
93
|
+
/** 解析 agentId → 运行时句柄;返回 undefined 表示目标不可运行 */
|
|
94
|
+
resolve(agentId: string): ChildRunTarget | undefined;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* RunnerChildRunPort — 以 `SessionAwareRunner.handle()` 起子 Run
|
|
98
|
+
*
|
|
99
|
+
* 保证 D7/D8/D9:独立 session、per-run 上下文、并发闸仍只在 SessionGate。
|
|
100
|
+
*/
|
|
101
|
+
export declare class RunnerChildRunPort implements ChildRunPort {
|
|
102
|
+
private readonly config;
|
|
103
|
+
/**
|
|
104
|
+
* @param config - 目标解析与 session 存储
|
|
105
|
+
*/
|
|
106
|
+
constructor(config: RunnerChildRunPortConfig);
|
|
107
|
+
/**
|
|
108
|
+
* 起一次受监督的子 Run
|
|
109
|
+
*
|
|
110
|
+
* @param input - 子 Run 入参
|
|
111
|
+
* @param signal - 中止信号
|
|
112
|
+
* @returns 子 Run 产出
|
|
113
|
+
* @throws 目标不可运行,或 session 预创建失败
|
|
114
|
+
*/
|
|
115
|
+
run(input: ChildRunInput, signal?: AbortSignal): Promise<ChildRunOutput>;
|
|
116
|
+
/** 构造带 `spawnBy` 的 child session 骨架 */
|
|
117
|
+
private newChildSession;
|
|
118
|
+
}
|
|
119
|
+
/** 委派指令片段(§9.4:模板 persona + 编排指令) */
|
|
120
|
+
export interface DelegationPromptOptions {
|
|
121
|
+
/** 子 agent 的 persona(来自 `AgentConfig.persona`) */
|
|
122
|
+
persona: string;
|
|
123
|
+
/** 附加编排指令(缺省用 `DEFAULT_DELEGATION_DIRECTIVE`) */
|
|
124
|
+
directive?: string;
|
|
125
|
+
}
|
|
126
|
+
/** 缺省编排指令 */
|
|
127
|
+
export declare const DEFAULT_DELEGATION_DIRECTIVE: string;
|
|
128
|
+
/**
|
|
129
|
+
* 构造子的 systemPrompt(§9.4)
|
|
130
|
+
*
|
|
131
|
+
* @param options - persona 与编排指令
|
|
132
|
+
* @param parentAgentId - 父 agentId(进指令文本)
|
|
133
|
+
* @returns systemPrompt 文本
|
|
134
|
+
*/
|
|
135
|
+
export declare function buildChildSystemPrompt(options: DelegationPromptOptions, parentAgentId: string): string;
|
|
136
|
+
/**
|
|
137
|
+
* 把 `ChildRunPort` 适配成 `LocalDelegateExecutor`(供 `InProcessTransport` 使用)
|
|
138
|
+
*
|
|
139
|
+
* @param port - 子 Run 执行端口
|
|
140
|
+
* @param options - systemPrompt 构造选项
|
|
141
|
+
* @param resolvePersona - 从 childAgentId 取 persona(缺省取空串)
|
|
142
|
+
* @returns transport 可用的执行器
|
|
143
|
+
*/
|
|
144
|
+
export declare function createChildRunExecutor(port: ChildRunPort, options: DelegationPromptOptions, resolvePersona?: (childAgentId: string) => string): import('./transport.js').LocalDelegateExecutor;
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChildRunPort — 子 Run 执行端口
|
|
3
|
+
*
|
|
4
|
+
* @layer harness/collaboration/delegation
|
|
5
|
+
* 设计权威:`arch/delegation.md` §10。
|
|
6
|
+
*
|
|
7
|
+
* 职责:把一个 `DelegateRequest` 变成一次**真实受监督的子 Run**,产出 `ChildRunOutput`。
|
|
8
|
+
*
|
|
9
|
+
* 不变量落点:
|
|
10
|
+
* - **D7** 子 Run 落**独立 Session**,带 `spawnBy` 父子关联(`SessionSpawnLink`)
|
|
11
|
+
* - **D8** 子 Run 走 `SessionAwareRunner.handle()` —— 该入口自带
|
|
12
|
+
* per-run `AgentContext` + `RunScope` + session 锁 + SessionGate + ACL,
|
|
13
|
+
* 因此**绝不写 `agent.context.messages`**(旧 multi-agent 路径的 I1 违规)
|
|
14
|
+
* - **D9** 并发硬闸仍只在 SessionGate 一处(委派层不建第二把闸)
|
|
15
|
+
*
|
|
16
|
+
* 与 transport 的分工:
|
|
17
|
+
* transport 管"怎么把请求送到目标"(进程内 / 将来跨进程);
|
|
18
|
+
* 本端口管"目标本地怎么起 Run"。两者不可互相渗透。
|
|
19
|
+
*/
|
|
20
|
+
import { emptyTokenUsage } from '@octopi-agent/core/types/turn.js';
|
|
21
|
+
/**
|
|
22
|
+
* 累加 turn 级 usage 到总账(决策 C2:归集到父的 run 账)
|
|
23
|
+
*
|
|
24
|
+
* @param total - 累计账本(原地更新)
|
|
25
|
+
* @param add - 本轮 usage
|
|
26
|
+
*/
|
|
27
|
+
function addUsage(total, add) {
|
|
28
|
+
if (!add)
|
|
29
|
+
return;
|
|
30
|
+
total.outputTokens += add.outputTokens ?? 0;
|
|
31
|
+
total.inputUncachedTokens += add.inputUncachedTokens ?? 0;
|
|
32
|
+
total.inputCachedTokens += add.inputCachedTokens ?? 0;
|
|
33
|
+
total.inputCacheWriteTokens += add.inputCacheWriteTokens ?? 0;
|
|
34
|
+
if (add.inputReportedTokens != null) {
|
|
35
|
+
total.inputReportedTokens = (total.inputReportedTokens ?? 0) + add.inputReportedTokens;
|
|
36
|
+
}
|
|
37
|
+
if (add.cacheAware)
|
|
38
|
+
total.cacheAware = true;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* RunnerChildRunPort — 以 `SessionAwareRunner.handle()` 起子 Run
|
|
42
|
+
*
|
|
43
|
+
* 保证 D7/D8/D9:独立 session、per-run 上下文、并发闸仍只在 SessionGate。
|
|
44
|
+
*/
|
|
45
|
+
export class RunnerChildRunPort {
|
|
46
|
+
config;
|
|
47
|
+
/**
|
|
48
|
+
* @param config - 目标解析与 session 存储
|
|
49
|
+
*/
|
|
50
|
+
constructor(config) {
|
|
51
|
+
this.config = config;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 起一次受监督的子 Run
|
|
55
|
+
*
|
|
56
|
+
* @param input - 子 Run 入参
|
|
57
|
+
* @param signal - 中止信号
|
|
58
|
+
* @returns 子 Run 产出
|
|
59
|
+
* @throws 目标不可运行,或 session 预创建失败
|
|
60
|
+
*/
|
|
61
|
+
async run(input, signal) {
|
|
62
|
+
const target = this.config.resolve(input.childAgentId);
|
|
63
|
+
if (!target) {
|
|
64
|
+
throw new Error(`delegate target not runnable: ${input.childAgentId}`);
|
|
65
|
+
}
|
|
66
|
+
// id 由服务方在起 Run 前生成并落库(D7);此处只消费,不生成
|
|
67
|
+
const childSessionId = input.childSessionId;
|
|
68
|
+
const childRunId = input.childRunId;
|
|
69
|
+
// D7:预创建 child session 并写入父子关联。
|
|
70
|
+
// 随后 `handle()` 会 load 到本 session(而非 createSession),spawnBy 得以保留。
|
|
71
|
+
await target.store.save(childSessionId, this.newChildSession(childSessionId, input));
|
|
72
|
+
const userText = input.context === 'fork' && input.parentMessages?.length
|
|
73
|
+
? `${renderForkHeader(input.parentMessages)}\n\n${input.task}\n\n${input.input}`
|
|
74
|
+
: `${input.task}\n\n${input.input}`;
|
|
75
|
+
const userMessage = {
|
|
76
|
+
role: 'user',
|
|
77
|
+
content: userText,
|
|
78
|
+
timestamp: Date.now(),
|
|
79
|
+
};
|
|
80
|
+
const runConfig = {
|
|
81
|
+
systemPrompt: input.systemPrompt,
|
|
82
|
+
agentId: input.childAgentId,
|
|
83
|
+
sessionId: childSessionId,
|
|
84
|
+
// D3:委派权利天花板,Runner 会与模板天花板取交集
|
|
85
|
+
rightsCeiling: input.rightsCeiling,
|
|
86
|
+
};
|
|
87
|
+
const usage = emptyTokenUsage();
|
|
88
|
+
let output;
|
|
89
|
+
let error;
|
|
90
|
+
let aborted = false;
|
|
91
|
+
const artifacts = [];
|
|
92
|
+
try {
|
|
93
|
+
for await (const event of target.runner.handle(childSessionId, userMessage, runConfig, signal)) {
|
|
94
|
+
switch (event.type) {
|
|
95
|
+
case 'turn.end': {
|
|
96
|
+
const data = event.data;
|
|
97
|
+
if (typeof data.content === 'string' && data.content.length > 0) {
|
|
98
|
+
output = data.content;
|
|
99
|
+
}
|
|
100
|
+
addUsage(usage, data.usage);
|
|
101
|
+
if (data.error != null && error == null) {
|
|
102
|
+
error = data.error instanceof Error ? data.error.message : String(data.error);
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
case 'engine.error': {
|
|
107
|
+
const data = event.data;
|
|
108
|
+
const message = data.error instanceof Error ? data.error.message : String(data.error ?? 'unknown error');
|
|
109
|
+
error = message;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
default:
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
error = err instanceof Error ? err.message : String(err);
|
|
119
|
+
}
|
|
120
|
+
if (signal?.aborted)
|
|
121
|
+
aborted = true;
|
|
122
|
+
return {
|
|
123
|
+
childSessionId,
|
|
124
|
+
childRunId,
|
|
125
|
+
output,
|
|
126
|
+
...(artifacts.length > 0 ? { artifacts } : {}),
|
|
127
|
+
usage,
|
|
128
|
+
error: aborted ? (error ?? 'aborted') : error,
|
|
129
|
+
aborted,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/** 构造带 `spawnBy` 的 child session 骨架 */
|
|
133
|
+
newChildSession(sessionId, input) {
|
|
134
|
+
const timestamp = Date.now();
|
|
135
|
+
return {
|
|
136
|
+
id: sessionId,
|
|
137
|
+
agentId: input.childAgentId,
|
|
138
|
+
primaryAgentId: input.childAgentId,
|
|
139
|
+
spawnBy: { ...input.spawnBy },
|
|
140
|
+
meta: {
|
|
141
|
+
title: `delegation: ${input.task}`.slice(0, 120),
|
|
142
|
+
createdAt: timestamp,
|
|
143
|
+
updatedAt: timestamp,
|
|
144
|
+
status: 'idle',
|
|
145
|
+
},
|
|
146
|
+
messages: [],
|
|
147
|
+
turns: [],
|
|
148
|
+
metadata: { delegationId: input.delegationId },
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 渲染 fork 模式的父历史前缀(§9.4:显式 `context: 'fork'` 才继承)
|
|
154
|
+
*
|
|
155
|
+
* @param parentMessages - 父消息历史(只取可序列化文本)
|
|
156
|
+
* @returns 前缀文本
|
|
157
|
+
*/
|
|
158
|
+
function renderForkHeader(parentMessages) {
|
|
159
|
+
const lines = parentMessages.map((m) => {
|
|
160
|
+
const msg = m;
|
|
161
|
+
const role = typeof msg?.role === 'string' ? msg.role : 'unknown';
|
|
162
|
+
const content = typeof msg?.content === 'string' ? msg.content : JSON.stringify(msg?.content ?? '');
|
|
163
|
+
return `- [${role}] ${content}`;
|
|
164
|
+
});
|
|
165
|
+
return [
|
|
166
|
+
'[Context Fork] 以下是从父会话分叉的上下文,供你理解任务背景:',
|
|
167
|
+
...lines,
|
|
168
|
+
].join('\n');
|
|
169
|
+
}
|
|
170
|
+
/** 缺省编排指令 */
|
|
171
|
+
export const DEFAULT_DELEGATION_DIRECTIVE = 'You are being delegated a task by a parent agent. ' +
|
|
172
|
+
'Work the task independently and end your run with a concise conclusion as your final message. ' +
|
|
173
|
+
'Do not wait for further instructions.';
|
|
174
|
+
/**
|
|
175
|
+
* 构造子的 systemPrompt(§9.4)
|
|
176
|
+
*
|
|
177
|
+
* @param options - persona 与编排指令
|
|
178
|
+
* @param parentAgentId - 父 agentId(进指令文本)
|
|
179
|
+
* @returns systemPrompt 文本
|
|
180
|
+
*/
|
|
181
|
+
export function buildChildSystemPrompt(options, parentAgentId) {
|
|
182
|
+
const directive = options.directive ?? DEFAULT_DELEGATION_DIRECTIVE;
|
|
183
|
+
return [options.persona, directive, `Delegating parent: ${parentAgentId}`]
|
|
184
|
+
.filter((s) => s && s.length > 0)
|
|
185
|
+
.join('\n\n');
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* 把 `ChildRunPort` 适配成 `LocalDelegateExecutor`(供 `InProcessTransport` 使用)
|
|
189
|
+
*
|
|
190
|
+
* @param port - 子 Run 执行端口
|
|
191
|
+
* @param options - systemPrompt 构造选项
|
|
192
|
+
* @param resolvePersona - 从 childAgentId 取 persona(缺省取空串)
|
|
193
|
+
* @returns transport 可用的执行器
|
|
194
|
+
*/
|
|
195
|
+
export function createChildRunExecutor(port, options, resolvePersona) {
|
|
196
|
+
return async (request, signal) => {
|
|
197
|
+
const childAgentId = request.to.agentId;
|
|
198
|
+
if (!childAgentId) {
|
|
199
|
+
return {
|
|
200
|
+
delegationId: request.delegationId,
|
|
201
|
+
status: 'failed',
|
|
202
|
+
error: 'delegate_request: unresolved target agentId',
|
|
203
|
+
schemaVersion: request.schemaVersion,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
const persona = resolvePersona?.(childAgentId) ?? options.persona;
|
|
207
|
+
const systemPrompt = buildChildSystemPrompt({ persona, directive: options.directive }, request.from.agentId);
|
|
208
|
+
const output = await port.run({
|
|
209
|
+
delegationId: request.delegationId,
|
|
210
|
+
childAgentId,
|
|
211
|
+
// D7:id 由服务方在起 Run 前生成并落库,此处透传
|
|
212
|
+
childSessionId: request.childSessionId,
|
|
213
|
+
childRunId: request.childRunId,
|
|
214
|
+
task: request.task,
|
|
215
|
+
input: request.input,
|
|
216
|
+
context: request.context,
|
|
217
|
+
parentMessages: request.parentMessages,
|
|
218
|
+
spawnBy: {
|
|
219
|
+
delegationId: request.delegationId,
|
|
220
|
+
parentAgentId: request.from.agentId,
|
|
221
|
+
parentSessionId: request.from.sessionId,
|
|
222
|
+
parentRunId: request.from.runId,
|
|
223
|
+
},
|
|
224
|
+
systemPrompt,
|
|
225
|
+
budget: request.budget,
|
|
226
|
+
rightsCeiling: request.rightsCeiling,
|
|
227
|
+
}, signal);
|
|
228
|
+
return {
|
|
229
|
+
delegationId: request.delegationId,
|
|
230
|
+
// 中止 ≠ 失败:cascade / cancel 落 cancelled,其余失败落 failed(补-2)
|
|
231
|
+
status: output.aborted ? 'cancelled' : output.error ? 'failed' : 'completed',
|
|
232
|
+
childSessionId: output.childSessionId,
|
|
233
|
+
childRunId: output.childRunId,
|
|
234
|
+
output: output.output,
|
|
235
|
+
artifacts: output.artifacts,
|
|
236
|
+
usage: output.usage,
|
|
237
|
+
error: output.error,
|
|
238
|
+
schemaVersion: request.schemaVersion,
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delegation 模块统一导出
|
|
3
|
+
*
|
|
4
|
+
* @layer harness/collaboration/delegation
|
|
5
|
+
* 设计权威:`arch/delegation.md`。
|
|
6
|
+
*
|
|
7
|
+
* L2 委派契约层:`DelegateRequest` / `DelegateResult`(纯 JSON,D1/D5)
|
|
8
|
+
* + `AgentHandle`(D2 寻址)+ `DelegateTransport`(唯一分布式缝)。
|
|
9
|
+
*/
|
|
10
|
+
export type { Delegation, DelegationBudget, DelegationContextMode, DelegationEventType, DelegationParentRef, DelegationStatus, DelegationTarget, DelegateRequest, DelegateResult, AgentHandle, } from './types.js';
|
|
11
|
+
export { DELEGATION_SCHEMA_VERSION, DELEGATION_TERMINAL_STATUSES, DELEGATION_ACTIVE_STATUSES, DelegationEvents, isTerminalDelegationStatus, isActiveDelegationStatus, } from './types.js';
|
|
12
|
+
export type { AgentRegistry, AgentInfo, AgentQuery, AgentRelation, AgentRelationType, AgentDelegationPolicy, } from './registry-types.js';
|
|
13
|
+
export { AgentRegistryEvents } from './registry-types.js';
|
|
14
|
+
export { DefaultAgentRegistry } from './registry.js';
|
|
15
|
+
export { DelegationStore, canTransitionDelegation } from './store.js';
|
|
16
|
+
export type { CreateDelegationInput, UpdateDelegationPatch, DelegationListFilter, } from './store.js';
|
|
17
|
+
export { InProcessTransport, assertCompatibleSchema } from './transport.js';
|
|
18
|
+
export type { DelegateTransport, LocalDelegateExecutor } from './transport.js';
|
|
19
|
+
export { RunnerChildRunPort, createChildRunExecutor, buildChildSystemPrompt, DEFAULT_DELEGATION_DIRECTIVE, } from './child-run.js';
|
|
20
|
+
export type { ChildRunPort, ChildRunInput, ChildRunOutput, ChildRunTarget, RunnerChildRunPortConfig, DelegationPromptOptions, } from './child-run.js';
|
|
21
|
+
export { DelegateService, DelegateResolutionError, intersectBudget } from './service.js';
|
|
22
|
+
export type { DispatchDelegationInput, DispatchResult, DelegateServiceConfig, DelegationNotifier, } from './service.js';
|
|
23
|
+
export { createDelegationNotifier, renderDelegationNotice, delegationReason, } from './notifier.js';
|
|
24
|
+
export type { DelegationNotifierConfig } from './notifier.js';
|
|
25
|
+
export { wireDelegation, createDelegationRuntime } from './wiring.js';
|
|
26
|
+
export type { DelegatableAgent, DelegationRuntimeOptions, DelegationRuntime, } from './wiring.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delegation 模块统一导出
|
|
3
|
+
*
|
|
4
|
+
* @layer harness/collaboration/delegation
|
|
5
|
+
* 设计权威:`arch/delegation.md`。
|
|
6
|
+
*
|
|
7
|
+
* L2 委派契约层:`DelegateRequest` / `DelegateResult`(纯 JSON,D1/D5)
|
|
8
|
+
* + `AgentHandle`(D2 寻址)+ `DelegateTransport`(唯一分布式缝)。
|
|
9
|
+
*/
|
|
10
|
+
export { DELEGATION_SCHEMA_VERSION, DELEGATION_TERMINAL_STATUSES, DELEGATION_ACTIVE_STATUSES, DelegationEvents, isTerminalDelegationStatus, isActiveDelegationStatus, } from './types.js';
|
|
11
|
+
export { AgentRegistryEvents } from './registry-types.js';
|
|
12
|
+
// ── Registry 实现 ──
|
|
13
|
+
export { DefaultAgentRegistry } from './registry.js';
|
|
14
|
+
// ── Store ──
|
|
15
|
+
export { DelegationStore, canTransitionDelegation } from './store.js';
|
|
16
|
+
// ── Transport ──
|
|
17
|
+
export { InProcessTransport, assertCompatibleSchema } from './transport.js';
|
|
18
|
+
// ── Child Run(子 Run 执行端口,D7/D8/D9) ──
|
|
19
|
+
export { RunnerChildRunPort, createChildRunExecutor, buildChildSystemPrompt, DEFAULT_DELEGATION_DIRECTIVE, } from './child-run.js';
|
|
20
|
+
// ── Service ──
|
|
21
|
+
export { DelegateService, DelegateResolutionError, intersectBudget } from './service.js';
|
|
22
|
+
// ── notify 通道(§7.1) ──
|
|
23
|
+
export { createDelegationNotifier, renderDelegationNotice, delegationReason, } from './notifier.js';
|
|
24
|
+
// ── 生产接线 ──
|
|
25
|
+
export { wireDelegation, createDelegationRuntime } from './wiring.js';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DelegationNotifier — notify 通道投递器
|
|
3
|
+
*
|
|
4
|
+
* @layer harness/collaboration/delegation
|
|
5
|
+
* 设计权威:`arch/delegation.md` §7.1。
|
|
6
|
+
*
|
|
7
|
+
* 子 Run 终态 → 写 `DelegationStore`(已由 service 完成)→ **本模块投递**
|
|
8
|
+
* → `emitAgentSignal` → `AgentSignalSource` → `AgentRuntime.dispatch`
|
|
9
|
+
* → Compiler 编译成 user 消息进父 session 队列。
|
|
10
|
+
*
|
|
11
|
+
* **复用既有 Trigger 模型,不新造父子通道**(`arch/agent-runtime.md`)。
|
|
12
|
+
*
|
|
13
|
+
* 不打断父 Run:同 session 运行中再来 Trigger 由 Runner FIFO 锁排队,
|
|
14
|
+
* 禁止在调用链上 await(`arch/agent-runtime.md` 重入策略)。
|
|
15
|
+
*/
|
|
16
|
+
import type { EventBus } from '@octopi-agent/core/primitives/event-bus.js';
|
|
17
|
+
import type { Delegation } from './types.js';
|
|
18
|
+
import type { DelegationNotifier } from './service.js';
|
|
19
|
+
/** notify 投递器配置 */
|
|
20
|
+
export interface DelegationNotifierConfig {
|
|
21
|
+
/** 事件总线(须与挂载 `AgentSignalSource` 的总线同一条) */
|
|
22
|
+
events: EventBus;
|
|
23
|
+
/** 自定义内容渲染(缺省用 `renderDelegationNotice`) */
|
|
24
|
+
render?: (delegation: Delegation) => string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 渲染委派终态通知(§7.1:`<delegation_completed …/>`)
|
|
28
|
+
*
|
|
29
|
+
* @param delegation - 终态委派单
|
|
30
|
+
* @returns 通知文本
|
|
31
|
+
*/
|
|
32
|
+
export declare function renderDelegationNotice(delegation: Delegation): string;
|
|
33
|
+
/** 委派终态 → notify 通道 reason */
|
|
34
|
+
export declare function delegationReason(delegation: Delegation): string;
|
|
35
|
+
/**
|
|
36
|
+
* 创建 notify 投递器
|
|
37
|
+
*
|
|
38
|
+
* 投递前提:总线上有存活的 `AgentSignalSource` 接收端。`bus.emit` 对有无监听者
|
|
39
|
+
* 零反馈,不校验就会把发进空总线的通知误标已送达(2026-10-22 断链根因)。
|
|
40
|
+
* 无接收端时抛出,由 `DelegateService.notify` 按投递失败处理(留 `deliveryState` 为 pending
|
|
41
|
+
* 给状态提示兜底并打 warn)。
|
|
42
|
+
*
|
|
43
|
+
* @param config - 事件总线与渲染器
|
|
44
|
+
* @returns 可注入 `DelegateServiceConfig.notifier` 的投递器
|
|
45
|
+
*/
|
|
46
|
+
export declare function createDelegationNotifier(config: DelegationNotifierConfig): DelegationNotifier;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DelegationNotifier — notify 通道投递器
|
|
3
|
+
*
|
|
4
|
+
* @layer harness/collaboration/delegation
|
|
5
|
+
* 设计权威:`arch/delegation.md` §7.1。
|
|
6
|
+
*
|
|
7
|
+
* 子 Run 终态 → 写 `DelegationStore`(已由 service 完成)→ **本模块投递**
|
|
8
|
+
* → `emitAgentSignal` → `AgentSignalSource` → `AgentRuntime.dispatch`
|
|
9
|
+
* → Compiler 编译成 user 消息进父 session 队列。
|
|
10
|
+
*
|
|
11
|
+
* **复用既有 Trigger 模型,不新造父子通道**(`arch/agent-runtime.md`)。
|
|
12
|
+
*
|
|
13
|
+
* 不打断父 Run:同 session 运行中再来 Trigger 由 Runner FIFO 锁排队,
|
|
14
|
+
* 禁止在调用链上 await(`arch/agent-runtime.md` 重入策略)。
|
|
15
|
+
*/
|
|
16
|
+
import { emitAgentSignal, hasAgentSignalReceiver, } from '../../activation/sources/agent-signal.js';
|
|
17
|
+
/**
|
|
18
|
+
* 渲染委派终态通知(§7.1:`<delegation_completed …/>`)
|
|
19
|
+
*
|
|
20
|
+
* @param delegation - 终态委派单
|
|
21
|
+
* @returns 通知文本
|
|
22
|
+
*/
|
|
23
|
+
export function renderDelegationNotice(delegation) {
|
|
24
|
+
const attrs = [
|
|
25
|
+
`id="${escapeAttr(delegation.id)}"`,
|
|
26
|
+
`status="${delegation.status}"`,
|
|
27
|
+
`agent="${escapeAttr(delegation.resolvedAgentId ?? delegation.target.agentId ?? '')}"`,
|
|
28
|
+
`task="${escapeAttr(truncate(delegation.task, 120))}"`,
|
|
29
|
+
];
|
|
30
|
+
const body = [];
|
|
31
|
+
if (delegation.output) {
|
|
32
|
+
body.push(`<output>${escapeText(truncate(delegation.output, 4000))}</output>`);
|
|
33
|
+
}
|
|
34
|
+
if (delegation.error) {
|
|
35
|
+
body.push(`<error>${escapeText(truncate(delegation.error, 1000))}</error>`);
|
|
36
|
+
}
|
|
37
|
+
if (delegation.artifacts?.length) {
|
|
38
|
+
body.push(`<artifacts>${delegation.artifacts.map((a) => escapeText(a)).join(', ')}</artifacts>`);
|
|
39
|
+
}
|
|
40
|
+
const tag = delegation.status === 'completed' ? 'delegation_completed' : 'delegation_failed';
|
|
41
|
+
return body.length > 0
|
|
42
|
+
? `<${tag} ${attrs.join(' ')}>${body.join('')}</${tag}>`
|
|
43
|
+
: `<${tag} ${attrs.join(' ')}/>`;
|
|
44
|
+
}
|
|
45
|
+
/** 委派终态 → notify 通道 reason */
|
|
46
|
+
export function delegationReason(delegation) {
|
|
47
|
+
return delegation.status === 'completed' ? 'delegation_completed' : `delegation_${delegation.status}`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 创建 notify 投递器
|
|
51
|
+
*
|
|
52
|
+
* 投递前提:总线上有存活的 `AgentSignalSource` 接收端。`bus.emit` 对有无监听者
|
|
53
|
+
* 零反馈,不校验就会把发进空总线的通知误标已送达(2026-10-22 断链根因)。
|
|
54
|
+
* 无接收端时抛出,由 `DelegateService.notify` 按投递失败处理(留 `deliveryState` 为 pending
|
|
55
|
+
* 给状态提示兜底并打 warn)。
|
|
56
|
+
*
|
|
57
|
+
* @param config - 事件总线与渲染器
|
|
58
|
+
* @returns 可注入 `DelegateServiceConfig.notifier` 的投递器
|
|
59
|
+
*/
|
|
60
|
+
export function createDelegationNotifier(config) {
|
|
61
|
+
const render = config.render ?? renderDelegationNotice;
|
|
62
|
+
return (delegation) => {
|
|
63
|
+
if (!hasAgentSignalReceiver(config.events)) {
|
|
64
|
+
throw new Error('delegation notify not delivered: no AgentSignalSource receiver on the bus');
|
|
65
|
+
}
|
|
66
|
+
emitAgentSignal(config.events, {
|
|
67
|
+
fromAgentId: delegation.resolvedAgentId ?? delegation.target.agentId ?? 'child',
|
|
68
|
+
toAgentId: delegation.parent.agentId,
|
|
69
|
+
sessionId: delegation.parent.sessionId,
|
|
70
|
+
payload: { kind: 'system_note', content: render(delegation) },
|
|
71
|
+
reason: delegationReason(delegation),
|
|
72
|
+
delegationId: delegation.id,
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function truncate(text, max) {
|
|
77
|
+
return text.length <= max ? text : `${text.slice(0, max)}…`;
|
|
78
|
+
}
|
|
79
|
+
function escapeAttr(value) {
|
|
80
|
+
return value.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<');
|
|
81
|
+
}
|
|
82
|
+
function escapeText(value) {
|
|
83
|
+
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
84
|
+
}
|