@octopi-agent/engine 0.98.4 → 0.121.10
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/dist/builtin-model-info.js +28 -7
- package/dist/config-admin/agent-presets.d.ts +32 -0
- package/dist/config-admin/agent-presets.js +133 -0
- package/dist/config-admin/discover.d.ts +33 -4
- package/dist/config-admin/discover.js +101 -6
- package/dist/config-admin/env.d.ts +11 -0
- package/dist/config-admin/env.js +41 -0
- package/dist/config-admin/error-copy.d.ts +106 -0
- package/dist/config-admin/error-copy.js +287 -0
- package/dist/config-admin/i18n.d.ts +21 -0
- package/dist/config-admin/i18n.js +19 -0
- package/dist/config-admin/index.d.ts +6 -2
- package/dist/config-admin/index.js +3 -1
- package/dist/config-admin/model-presets.d.ts +14 -0
- package/dist/config-admin/model-presets.js +595 -70
- package/dist/config-admin/onboarding-apply.d.ts +71 -0
- package/dist/config-admin/onboarding-apply.js +235 -0
- package/dist/config-admin/onboarding.d.ts +154 -0
- package/dist/config-admin/onboarding.js +270 -0
- package/dist/config-admin/redact.d.ts +42 -9
- package/dist/config-admin/redact.js +69 -5
- package/dist/config-schema/agent.d.ts +40 -6
- package/dist/config-schema/agent.js +44 -6
- package/dist/config-schema/browser.d.ts +62 -0
- package/dist/config-schema/browser.js +89 -0
- package/dist/config-schema/context.d.ts +12 -37
- package/dist/config-schema/context.js +10 -31
- package/dist/config-schema/engine.d.ts +140 -164
- package/dist/config-schema/engine.js +10 -7
- package/dist/config-schema/governance.d.ts +20 -2
- package/dist/config-schema/governance.js +18 -3
- package/dist/config-schema/models.d.ts +10 -12
- package/dist/config-schema/models.js +16 -3
- package/dist/config-schema/run.d.ts +6 -2
- package/dist/config-schema/run.js +12 -2
- package/dist/config-schema/shared.d.ts +1 -3
- package/dist/config-schema/shared.js +4 -4
- package/dist/config-schema/substrate.d.ts +19 -88
- package/dist/config-schema/substrate.js +30 -107
- package/dist/config.d.ts +161 -123
- package/dist/config.js +109 -7
- package/dist/file-mode.d.ts +67 -0
- package/dist/file-mode.js +182 -0
- package/dist/fork-child.d.ts +82 -0
- package/dist/fork-child.js +123 -0
- package/dist/harness/activation/delegated-run.d.ts +42 -0
- package/dist/harness/activation/delegated-run.js +71 -0
- package/dist/harness/activation/dispatcher.js +11 -0
- package/dist/harness/activation/inbox.d.ts +3 -3
- package/dist/harness/activation/inbox.js +3 -3
- package/dist/harness/activation/index.d.ts +1 -0
- package/dist/harness/activation/run-backend.d.ts +92 -0
- package/dist/harness/activation/run-backend.js +16 -0
- package/dist/harness/activation/run-protocol.d.ts +392 -0
- package/dist/harness/activation/run-protocol.js +19 -0
- package/dist/harness/activation/runtime.d.ts +33 -0
- package/dist/harness/activation/runtime.js +130 -31
- package/dist/harness/activation/types.d.ts +20 -3
- package/dist/harness/agent/builder.d.ts +36 -3
- package/dist/harness/agent/builder.js +206 -46
- package/dist/harness/agent/config-bridge.d.ts +10 -1
- package/dist/harness/agent/config-bridge.js +24 -5
- package/dist/harness/agent/config-integrity.js +19 -2
- package/dist/harness/agent/registered-tool-adapter.d.ts +27 -0
- package/dist/harness/agent/registered-tool-adapter.js +67 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +13 -3
- package/dist/harness/agent/wire-agent-builder.js +35 -9
- package/dist/harness/capabilities/document/backends/plain.js +2 -1
- package/dist/harness/capabilities/document/factory.d.ts +5 -0
- package/dist/harness/capabilities/document/factory.js +1 -0
- package/dist/harness/capabilities/document/legacy/factory.js +3 -2
- package/dist/harness/capabilities/document/port.js +6 -3
- package/dist/harness/capabilities/document/types.d.ts +5 -0
- package/dist/harness/collaboration/autonomous-subsystem/audit/reader.d.ts +17 -0
- package/dist/harness/collaboration/autonomous-subsystem/audit/reader.js +66 -36
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.d.ts +6 -2
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.js +27 -7
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +2 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +11 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +17 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +14 -4
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +50 -41
- package/dist/harness/collaboration/autonomous-subsystem/sense/input-builder.js +4 -4
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.d.ts +6 -0
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.js +25 -4
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +4 -1
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +7 -3
- package/dist/harness/collaboration/delegation/child-run.d.ts +10 -1
- package/dist/harness/collaboration/delegation/child-run.js +38 -6
- package/dist/harness/collaboration/delegation/index.d.ts +1 -1
- package/dist/harness/collaboration/delegation/index.js +1 -1
- package/dist/harness/collaboration/delegation/notifier.d.ts +6 -1
- package/dist/harness/collaboration/delegation/notifier.js +8 -1
- package/dist/harness/collaboration/delegation/registry-types.d.ts +2 -0
- package/dist/harness/collaboration/delegation/service.d.ts +11 -4
- package/dist/harness/collaboration/delegation/service.js +35 -13
- package/dist/harness/collaboration/delegation/store.d.ts +4 -0
- package/dist/harness/collaboration/delegation/store.js +3 -1
- package/dist/harness/collaboration/delegation/types.d.ts +34 -2
- package/dist/harness/collaboration/delegation/types.js +22 -0
- package/dist/harness/collaboration/delegation/wiring.d.ts +2 -0
- package/dist/harness/collaboration/delegation/wiring.js +12 -1
- package/dist/harness/context/budget-allocator.d.ts +26 -18
- package/dist/harness/context/budget-allocator.js +67 -32
- package/dist/harness/context/capabilities/compact/engine.d.ts +44 -11
- package/dist/harness/context/capabilities/compact/engine.js +296 -160
- package/dist/harness/context/capabilities/compact/handover.d.ts +5 -3
- package/dist/harness/context/capabilities/compact/handover.js +7 -5
- package/dist/harness/context/capabilities/compact/index.d.ts +7 -2
- package/dist/harness/context/capabilities/compact/index.js +5 -1
- package/dist/harness/context/capabilities/compact/mechanical.d.ts +130 -0
- package/dist/harness/context/capabilities/compact/mechanical.js +268 -0
- package/dist/harness/context/capabilities/compact/messages.d.ts +60 -0
- package/dist/harness/context/capabilities/compact/messages.js +91 -0
- package/dist/harness/context/capabilities/compact/types.d.ts +134 -19
- package/dist/harness/context/capabilities/compact/types.js +11 -1
- package/dist/harness/context/capabilities/compact/view-split.d.ts +36 -0
- package/dist/harness/context/capabilities/compact/view-split.js +72 -0
- package/dist/harness/context/capabilities/summary/gate.d.ts +19 -2
- package/dist/harness/context/capabilities/summary/gate.js +53 -6
- package/dist/harness/context/capabilities/summary/port.js +0 -1
- package/dist/harness/context/capabilities/summary/registry.js +20 -0
- package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/resolver.js +1 -6
- package/dist/harness/context/capabilities/summary/tool-binding.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/tool-binding.js +16 -12
- package/dist/harness/context/capabilities/summary/tool-bindings.d.ts +13 -0
- package/dist/harness/context/capabilities/summary/tool-bindings.js +22 -0
- package/dist/harness/context/capabilities/summary/types.d.ts +19 -6
- package/dist/harness/context/constitution/default-agents.md +85 -0
- package/dist/harness/context/context-size-ledger.d.ts +143 -0
- package/dist/harness/context/context-size-ledger.js +243 -0
- package/dist/harness/context/default-context-engine.d.ts +290 -120
- package/dist/harness/context/default-context-engine.js +1555 -764
- package/dist/harness/context/index.d.ts +3 -2
- package/dist/harness/context/index.js +2 -1
- package/dist/harness/context/layer-health.d.ts +4 -0
- package/dist/harness/context/layer-health.js +4 -0
- package/dist/harness/context/layer-types.d.ts +72 -0
- package/dist/harness/context/layer-types.js +87 -2
- package/dist/harness/context/layers.d.ts +17 -15
- package/dist/harness/context/layers.js +54 -17
- package/dist/harness/context/message-selector.d.ts +10 -8
- package/dist/harness/context/message-selector.js +49 -27
- package/dist/harness/context/prefix-fingerprint.d.ts +46 -0
- package/dist/harness/context/prefix-fingerprint.js +52 -0
- package/dist/harness/context/summarize.d.ts +2 -2
- package/dist/harness/context/summarize.js +27 -2
- package/dist/harness/context/system-prompt-assembler.d.ts +4 -0
- package/dist/harness/context/system-prompt-assembler.js +7 -3
- package/dist/harness/context/token-constants.d.ts +8 -6
- package/dist/harness/context/token-constants.js +8 -7
- package/dist/harness/context/token-estimate-fns.d.ts +37 -27
- package/dist/harness/context/token-estimate-fns.js +85 -66
- package/dist/harness/context/token-estimator.d.ts +27 -12
- package/dist/harness/context/token-estimator.js +120 -66
- package/dist/harness/context/token-segments.d.ts +88 -0
- package/dist/harness/context/token-segments.js +103 -0
- package/dist/harness/context/tool-result-aging.d.ts +109 -16
- package/dist/harness/context/tool-result-aging.js +220 -55
- package/dist/harness/context/tool-result-body.js +2 -0
- package/dist/harness/context/transform/anchors.d.ts +66 -0
- package/dist/harness/context/transform/anchors.js +125 -0
- package/dist/harness/context/transform/fold.d.ts +56 -0
- package/dist/harness/context/transform/fold.js +135 -0
- package/dist/harness/context/transform/migrate.d.ts +41 -0
- package/dist/harness/context/transform/migrate.js +69 -0
- package/dist/harness/context/transform/types.d.ts +129 -0
- package/dist/harness/context/transform/types.js +19 -0
- package/dist/harness/context/turn-envelope.d.ts +6 -3
- package/dist/harness/context/types.d.ts +196 -119
- package/dist/harness/context/types.js +25 -1
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +4 -3
- package/dist/harness/extension/execution-environment/effect-policy.js +2 -2
- package/dist/harness/extension/execution-environment/ops-audit.d.ts +1 -1
- package/dist/harness/extension/execution-environment/privileged-exec.js +4 -1
- package/dist/harness/extension/execution-environment/resource-limits.d.ts +1 -1
- package/dist/harness/extension/execution-environment/resource-limits.js +1 -1
- package/dist/harness/extension/execution-environment/workspace.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +28 -2
- package/dist/harness/extension/plugin-ecosystem/channel-types.js +11 -2
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +12 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +25 -0
- package/dist/harness/extension/plugin-ecosystem/commands/builtin.js +28 -1
- package/dist/harness/extension/plugin-ecosystem/commands/index.d.ts +3 -1
- package/dist/harness/extension/plugin-ecosystem/commands/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.d.ts +12 -1
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.js +14 -4
- package/dist/harness/extension/plugin-ecosystem/commands/router.d.ts +5 -4
- package/dist/harness/extension/plugin-ecosystem/commands/router.js +23 -14
- package/dist/harness/extension/plugin-ecosystem/commands/types.d.ts +8 -1
- package/dist/harness/extension/plugin-ecosystem/commands/types.js +2 -1
- package/dist/harness/extension/plugin-ecosystem/hooks/adapter.d.ts +54 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/adapter.js +397 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.d.ts +16 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.js +66 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/index.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/index.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.d.ts +11 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.js +54 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/journal.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/journal.js +22 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.d.ts +12 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.js +19 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.d.ts +36 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.js +338 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/services.d.ts +24 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/services.js +139 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/types.d.ts +229 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/types.js +1 -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/plugins/api.d.ts +223 -222
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +218 -203
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.d.ts +95 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.js +170 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.d.ts +178 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.js +314 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +78 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +80 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.js +18 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +7 -85
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +8 -50
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +6 -23
- package/dist/harness/extension/plugin-ecosystem/plugins/index.js +3 -23
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +57 -114
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +279 -282
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +46 -484
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +123 -345
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +50 -223
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +144 -20
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +17 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +15 -0
- package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +6 -1
- package/dist/harness/extension/plugin-ecosystem/skills/manager.js +17 -1
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +3 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +46 -21
- package/dist/harness/extension/plugin-ecosystem/tools/browser-types.d.ts +333 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser-types.js +16 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser.d.ts +64 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser.js +692 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +0 -37
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +108 -4
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +36 -8
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +34 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +0 -6
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +57 -4
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +81 -13
- package/dist/harness/extension/plugin-ecosystem/tools/http.js +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +13 -7
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +126 -14
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +44 -5
- package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.d.ts +11 -0
- package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.js +39 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +19 -24
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +7 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +4 -0
- package/dist/harness/governance/accounting/usage-ledger.d.ts +13 -1
- package/dist/harness/governance/accounting/usage-ledger.js +23 -1
- package/dist/harness/governance/credentials/db.d.ts +9 -0
- package/dist/harness/governance/credentials/db.js +122 -31
- package/dist/harness/governance/credentials/store.d.ts +68 -7
- package/dist/harness/governance/credentials/store.js +177 -64
- package/dist/harness/governance/credentials/types.d.ts +13 -2
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +3 -3
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +2 -2
- package/dist/harness/governance/index.d.ts +1 -0
- package/dist/harness/governance/index.js +1 -0
- package/dist/harness/governance/registry/db.d.ts +32 -0
- package/dist/harness/governance/registry/db.js +142 -0
- package/dist/harness/governance/registry/index.d.ts +9 -0
- package/dist/harness/governance/registry/index.js +9 -0
- package/dist/harness/governance/registry/service.d.ts +381 -0
- package/dist/harness/governance/registry/service.js +825 -0
- package/dist/harness/governance/registry/types.d.ts +77 -0
- package/dist/harness/governance/registry/types.js +7 -0
- package/dist/harness/governance/security/capability-enforcer.js +1 -2
- package/dist/harness/governance/security/default-security-guard.d.ts +3 -0
- package/dist/harness/governance/security/default-security-guard.js +12 -1
- package/dist/harness/governance/security/risk-evaluator.d.ts +13 -3
- package/dist/harness/governance/security/risk-evaluator.js +307 -21
- package/dist/harness/governance/security/shell-parser-treesitter.js +12 -4
- package/dist/harness/governance/session-acl/tool-rights.d.ts +1 -0
- package/dist/harness/index.d.ts +17 -15
- package/dist/harness/index.js +9 -9
- package/dist/harness/knowledge/boot-config.d.ts +57 -0
- package/dist/harness/knowledge/boot-config.js +52 -0
- package/dist/harness/knowledge/catalog-types.d.ts +2 -0
- package/dist/harness/knowledge/client.d.ts +77 -9
- package/dist/harness/knowledge/client.js +95 -24
- package/dist/harness/knowledge/db.d.ts +16 -0
- package/dist/harness/knowledge/db.js +112 -41
- package/dist/harness/knowledge/describe-sample.d.ts +23 -0
- package/dist/harness/knowledge/describe-sample.js +58 -0
- package/dist/harness/knowledge/describe.d.ts +8 -0
- package/dist/harness/knowledge/describe.js +18 -2
- package/dist/harness/knowledge/engine-thread.js +11 -7
- package/dist/harness/knowledge/grounding.js +7 -2
- package/dist/harness/knowledge/http-app.d.ts +15 -0
- package/dist/harness/knowledge/http-app.js +117 -25
- package/dist/harness/knowledge/http-bridge.d.ts +15 -0
- package/dist/harness/knowledge/http-bridge.js +19 -0
- package/dist/harness/knowledge/http-params.d.ts +18 -0
- package/dist/harness/knowledge/http-params.js +24 -0
- package/dist/harness/knowledge/index.d.ts +2 -0
- package/dist/harness/knowledge/index.js +1 -0
- package/dist/harness/knowledge/knowledge-serve-child.js +5 -3
- package/dist/harness/knowledge/purge.js +5 -2
- package/dist/harness/knowledge/query-service.d.ts +25 -4
- package/dist/harness/knowledge/query-service.js +79 -43
- package/dist/harness/knowledge/query-worker-client.d.ts +14 -2
- package/dist/harness/knowledge/query-worker-client.js +8 -3
- package/dist/harness/knowledge/query-worker.js +9 -5
- package/dist/harness/knowledge/read-http.d.ts +2 -0
- package/dist/harness/knowledge/read-http.js +14 -3
- package/dist/harness/knowledge/retriever.d.ts +1 -1
- package/dist/harness/knowledge/retriever.js +1 -2
- package/dist/harness/knowledge/serve.d.ts +14 -8
- package/dist/harness/knowledge/serve.js +14 -6
- package/dist/harness/knowledge/source-store.d.ts +101 -5
- package/dist/harness/knowledge/source-store.js +323 -74
- package/dist/harness/knowledge/start-service-process.d.ts +41 -14
- package/dist/harness/knowledge/start-service-process.js +67 -96
- package/dist/harness/knowledge/tenant-gate.d.ts +81 -0
- package/dist/harness/knowledge/tenant-gate.js +167 -0
- package/dist/harness/knowledge/types.d.ts +7 -0
- package/dist/harness/knowledge/writer-service.d.ts +55 -11
- package/dist/harness/knowledge/writer-service.js +200 -30
- package/dist/harness/knowledge/writer-worker-client.d.ts +19 -11
- package/dist/harness/knowledge/writer-worker-client.js +40 -5
- package/dist/harness/knowledge/writer-worker.js +20 -5
- package/dist/harness/memory/backfill-trigger.d.ts +10 -3
- package/dist/harness/memory/backfill-trigger.js +19 -19
- package/dist/harness/memory/cognition-seeds.d.ts +45 -0
- package/dist/harness/memory/cognition-seeds.js +67 -0
- package/dist/harness/memory/cognition.d.ts +12 -3
- package/dist/harness/memory/cognition.js +55 -35
- package/dist/harness/memory/conceptualizer.d.ts +11 -1
- package/dist/harness/memory/conceptualizer.js +10 -1
- package/dist/harness/memory/context-slice.d.ts +42 -0
- package/dist/harness/memory/context-slice.js +197 -0
- package/dist/harness/memory/health-probe.d.ts +8 -2
- package/dist/harness/memory/health-probe.js +10 -13
- package/dist/harness/memory/index.d.ts +5 -1
- package/dist/harness/memory/index.js +3 -1
- package/dist/harness/memory/sqlite/agent-db.d.ts +1 -0
- package/dist/harness/memory/sqlite/agent-db.js +9 -8
- package/dist/harness/memory/sqlite/cognition-store.d.ts +26 -3
- package/dist/harness/memory/sqlite/cognition-store.js +103 -45
- package/dist/harness/memory/sqlite/memory-store.js +4 -0
- package/dist/harness/memory/sqlite/sqlite-vec.d.ts +24 -1
- package/dist/harness/memory/sqlite/sqlite-vec.js +37 -1
- package/dist/harness/memory/sqlite/wisdom-store.js +35 -10
- package/dist/harness/memory/types.d.ts +24 -6
- package/dist/harness/memory/wisdom-formation.d.ts +14 -3
- package/dist/harness/memory/wisdom-formation.js +85 -22
- package/dist/harness/memory/wisdom-gates.d.ts +14 -0
- package/dist/harness/memory/wisdom-gates.js +59 -19
- package/dist/harness/memory/wisdom.js +9 -0
- package/dist/harness/observability/observer/hub.d.ts +10 -0
- package/dist/harness/observability/observer/hub.js +120 -17
- package/dist/harness/observability/observer/types.d.ts +10 -6
- package/dist/harness/run/agent/agent.d.ts +40 -21
- package/dist/harness/run/agent/agent.js +67 -13
- package/dist/harness/run/agent/index.d.ts +1 -1
- package/dist/harness/run/budget/budget.d.ts +28 -10
- package/dist/harness/run/budget/budget.js +38 -15
- package/dist/harness/run/concurrency/tool-validator.js +4 -3
- package/dist/harness/run/model/index.d.ts +3 -1
- package/dist/harness/run/model/index.js +2 -1
- package/dist/harness/run/model/resolver.d.ts +4 -1
- package/dist/harness/run/model/resolver.js +36 -2
- package/dist/harness/run/model/run-scope.d.ts +2 -0
- package/dist/harness/run/model/run-scope.js +7 -0
- package/dist/harness/run/model/types.d.ts +22 -5
- package/dist/harness/run/model/types.js +3 -2
- package/dist/harness/run/model/window-truth.d.ts +37 -0
- package/dist/harness/run/model/window-truth.js +39 -0
- package/dist/harness/run/reliability/context-length-feedback.d.ts +77 -0
- package/dist/harness/run/reliability/context-length-feedback.js +128 -0
- package/dist/harness/run/reliability/harness-events.d.ts +3 -3
- package/dist/harness/run/reliability/model-error-policy.js +4 -0
- package/dist/harness/run/reliability/run-agent.d.ts +32 -4
- package/dist/harness/run/reliability/run-agent.js +216 -63
- package/dist/harness/run/reliability/run-metrics-collector.d.ts +19 -8
- package/dist/harness/run/reliability/run-metrics-collector.js +38 -23
- package/dist/harness/run/run-guard/default-run-guard.js +8 -8
- package/dist/harness/run/run-host.d.ts +302 -0
- package/dist/harness/run/run-host.js +978 -0
- package/dist/harness/run/run-scope.d.ts +48 -4
- package/dist/harness/run/run-scope.js +19 -1
- package/dist/harness/run/runner.d.ts +181 -39
- package/dist/harness/run/runner.js +654 -119
- package/dist/harness/session/attachments/index.d.ts +1 -0
- package/dist/harness/session/attachments/index.js +1 -0
- package/dist/harness/session/attachments/inject.d.ts +21 -10
- package/dist/harness/session/attachments/inject.js +76 -24
- package/dist/harness/session/attachments/recall-index.d.ts +70 -0
- package/dist/harness/session/attachments/recall-index.js +219 -0
- package/dist/harness/session/attachments/service.d.ts +21 -0
- package/dist/harness/session/attachments/service.js +258 -139
- package/dist/harness/session/attachments/types.d.ts +6 -0
- package/dist/harness/session/in-memory-store.js +13 -1
- package/dist/harness/session/schedules/service.d.ts +10 -2
- package/dist/harness/session/schedules/service.js +13 -2
- package/dist/harness/session/tasks/tools.js +12 -0
- package/dist/harness/session/transform-store.d.ts +136 -0
- package/dist/harness/session/transform-store.js +302 -0
- package/dist/harness/session/types.d.ts +11 -15
- package/dist/harness/shared/events/agent-event-map.d.ts +75 -13
- package/dist/harness/shared/events/agent-event-map.js +3 -2
- package/dist/harness/shared/events/scenario-events.d.ts +6 -6
- package/dist/harness/shared/types/agent-definition.d.ts +7 -2
- package/dist/index.d.ts +16 -18
- package/dist/index.js +9 -10
- package/dist/integration/agent-runtime/channel-message-source.d.ts +3 -1
- package/dist/integration/agent-runtime/channel-message-source.js +4 -3
- package/dist/integration/browser/camoufox.d.ts +40 -0
- package/dist/integration/browser/camoufox.js +80 -0
- package/dist/integration/browser/index.d.ts +91 -0
- package/dist/integration/browser/index.js +110 -0
- package/dist/integration/browser/install.d.ts +47 -0
- package/dist/integration/browser/install.js +214 -0
- package/dist/integration/browser/playwright.d.ts +224 -0
- package/dist/integration/browser/playwright.js +925 -0
- package/dist/integration/browser/service.d.ts +41 -0
- package/dist/integration/browser/service.js +181 -0
- package/dist/integration/browser/stealth.d.ts +42 -0
- package/dist/integration/browser/stealth.js +104 -0
- package/dist/integration/observability/metrics.d.ts +6 -6
- package/dist/integration/observability/metrics.js +13 -13
- package/dist/integration/observability/observer-bridge.js +2 -2
- package/dist/integration/observability/trace-collector.d.ts +5 -5
- package/dist/integration/observability/trace-collector.js +34 -35
- package/dist/integration/observability/trace-events.d.ts +3 -3
- package/dist/integration/observability/trace-events.js +3 -3
- package/dist/integration/providers/anthropic-message-normalize.d.ts +20 -0
- package/dist/integration/providers/anthropic-message-normalize.js +48 -0
- package/dist/integration/providers/anthropic.js +41 -3
- package/dist/integration/providers/fetch-timeout.d.ts +17 -0
- package/dist/integration/providers/fetch-timeout.js +24 -0
- package/dist/integration/providers/openai.d.ts +8 -0
- package/dist/integration/providers/openai.js +48 -2
- package/dist/integration/providers/usage.d.ts +1 -1
- package/dist/integration/providers/wire-dump-diff.js +2 -1
- package/dist/integration/providers/wire-dump.d.ts +57 -3
- package/dist/integration/providers/wire-dump.js +119 -6
- package/dist/integration/storage/archive-manager.d.ts +20 -2
- package/dist/integration/storage/archive-manager.js +34 -8
- package/dist/integration/storage/atomic-tmp.d.ts +12 -0
- package/dist/integration/storage/atomic-tmp.js +36 -0
- package/dist/integration/storage/jsonl.d.ts +10 -1
- package/dist/integration/storage/jsonl.js +155 -54
- package/dist/integration/storage/session-index.d.ts +5 -0
- package/dist/integration/storage/session-index.js +25 -4
- package/dist/integration/tools/assemble.d.ts +50 -0
- package/dist/integration/tools/assemble.js +137 -0
- package/dist/paths.d.ts +18 -0
- package/dist/paths.js +36 -0
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +3 -1
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +74 -5
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +3 -2
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +11 -2
- package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +6 -3
- package/dist/subsystems/cognition-steward/consolidate/handler.js +266 -28
- package/dist/subsystems/memory-steward/backfill/handler.js +3 -2
- package/dist/subsystems/memory-steward/govern/config.yaml +6 -1
- package/dist/subsystems/wisdom-steward/attribute/config.yaml +5 -1
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +8 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +4 -0
- package/dist/subsystems/wisdom-steward/formation/handler.js +27 -5
- package/dist/subsystems/wisdom-steward/govern/config.yaml +6 -1
- package/package.json +14 -15
- package/dist/harness/context/hybrid-compressor.d.ts +0 -41
- package/dist/harness/context/hybrid-compressor.js +0 -159
- package/dist/harness/context/llm-summarizer.d.ts +0 -46
- package/dist/harness/context/llm-summarizer.js +0 -249
- package/dist/harness/context/smart-router.d.ts +0 -75
- package/dist/harness/context/smart-router.js +0 -118
- package/dist/harness/context/truncate-compressor.d.ts +0 -28
- package/dist/harness/context/truncate-compressor.js +0 -107
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -97
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -155
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.d.ts +0 -7
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.js +0 -7
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.d.ts +0 -86
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.js +0 -139
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { getTextContent } from '@octopi-agent/core/types.js';
|
|
2
|
+
import { getRunScope } from '../../../run/run-scope.js';
|
|
3
|
+
import { HookDeniedError } from './adapter.js';
|
|
4
|
+
import { ExtensionTerminalError, shouldAbortWithoutRetry, unwrapExtensionTerminalError } from './policy-error.js';
|
|
5
|
+
/** Per-Run mutable projections shared with Core's existing config callbacks. */
|
|
6
|
+
export class AgentExtensionHookState {
|
|
7
|
+
port;
|
|
8
|
+
scope;
|
|
9
|
+
originalToolParams = new WeakMap();
|
|
10
|
+
iterationSnapshots = new Map();
|
|
11
|
+
originalOnStepComplete;
|
|
12
|
+
originalBeforeStep;
|
|
13
|
+
originalTransformLlmMessages;
|
|
14
|
+
constructor(port, scope, config) {
|
|
15
|
+
this.port = port;
|
|
16
|
+
this.scope = scope;
|
|
17
|
+
this.originalOnStepComplete = config.onStepComplete;
|
|
18
|
+
this.originalBeforeStep = config.beforeStep;
|
|
19
|
+
this.originalTransformLlmMessages = config.transformLlmMessages;
|
|
20
|
+
}
|
|
21
|
+
/** Project only the normalized Provider request, never the Run's message workspace. */
|
|
22
|
+
async transformLlmMessages(messages) {
|
|
23
|
+
const index = Math.max(0, (this.scope().iteration ?? 1) - 1);
|
|
24
|
+
const snapshot = this.iterationSnapshots.get(index);
|
|
25
|
+
const current = this.originalTransformLlmMessages
|
|
26
|
+
? await this.originalTransformLlmMessages(messages)
|
|
27
|
+
: messages;
|
|
28
|
+
if (!snapshot)
|
|
29
|
+
return current;
|
|
30
|
+
const { projectPluginIterationSnapshot } = await import('./iteration-snapshot.js');
|
|
31
|
+
return projectPluginIterationSnapshot(current, snapshot.contributions, snapshot.tokenBudget);
|
|
32
|
+
}
|
|
33
|
+
callbacks() {
|
|
34
|
+
return {
|
|
35
|
+
prepareToolArguments: async (ctx, signal) => this.prepareToolArguments(ctx, signal),
|
|
36
|
+
onToolCallComplete: async (ctx) => this.onToolCallComplete(ctx),
|
|
37
|
+
beforeStep: async (ctx) => this.beforeStep(ctx),
|
|
38
|
+
onStepComplete: async (ctx) => {
|
|
39
|
+
// Finalize first: empty-reply/planning detection, step summaries, events and
|
|
40
|
+
// persistence must all see the finalized reply — not the raw model output.
|
|
41
|
+
await this.onStepComplete(ctx);
|
|
42
|
+
await this.originalOnStepComplete?.(ctx);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
context(signal) {
|
|
47
|
+
const scope = this.scope();
|
|
48
|
+
return {
|
|
49
|
+
sessionId: scope.sessionId,
|
|
50
|
+
agentId: scope.agentId,
|
|
51
|
+
...(scope.runId === undefined ? {} : { runId: scope.runId }),
|
|
52
|
+
...(scope.principal === undefined ? {} : { principal: scope.principal }),
|
|
53
|
+
...(signal === undefined ? {} : { signal }),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async prepareToolArguments(ctx, signal) {
|
|
57
|
+
// No registered handler → nothing to attribute; skip event construction and
|
|
58
|
+
// the Run-identity requirement (direct Agent.run() must keep working idle).
|
|
59
|
+
if (!this.port.hasHooks('before_tool_call'))
|
|
60
|
+
return ctx.args;
|
|
61
|
+
const scope = this.scope();
|
|
62
|
+
if (!scope.runId)
|
|
63
|
+
throw new Error('before_tool_call requires a Host Run identity');
|
|
64
|
+
if (ctx.args === null || typeof ctx.args !== 'object' || Array.isArray(ctx.args))
|
|
65
|
+
return ctx.args;
|
|
66
|
+
const original = ctx.args;
|
|
67
|
+
const result = await this.port.transformBeforeToolCall({
|
|
68
|
+
...this.context(signal),
|
|
69
|
+
runId: scope.runId,
|
|
70
|
+
toolName: ctx.toolCall.name,
|
|
71
|
+
call: ctx.toolCall,
|
|
72
|
+
params: original,
|
|
73
|
+
});
|
|
74
|
+
this.originalToolParams.set(ctx.toolCall, { ...original });
|
|
75
|
+
const value = result.value;
|
|
76
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) {
|
|
77
|
+
// Fail-closed for this call: tool validation, SecurityGuard and audit all
|
|
78
|
+
// inspect a plain parameter record; a non-record transform hides the payload.
|
|
79
|
+
throw new Error('before_tool_call transform must return a plain object of parameters');
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
async onToolCallComplete(ctx) {
|
|
84
|
+
if (!this.port.hasHooks('after_tool_call'))
|
|
85
|
+
return;
|
|
86
|
+
const scope = this.scope();
|
|
87
|
+
if (!scope.runId)
|
|
88
|
+
return;
|
|
89
|
+
const params = (ctx.args ?? {});
|
|
90
|
+
await this.port.observe('after_tool_call', {
|
|
91
|
+
...this.context(),
|
|
92
|
+
runId: scope.runId,
|
|
93
|
+
call: ctx.toolCall,
|
|
94
|
+
originalParams: this.originalToolParams.get(ctx.toolCall) ?? params,
|
|
95
|
+
params,
|
|
96
|
+
result: ctx.result,
|
|
97
|
+
...(ctx.result.isError ? { error: getTextContent(String(ctx.result.content ?? '')) } : {}),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
async beforeStep(ctx) {
|
|
101
|
+
try {
|
|
102
|
+
return await this.prepareStep(ctx);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
throw new ExtensionTerminalError(error);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async prepareStep(ctx) {
|
|
109
|
+
const originalUpdate = await this.originalBeforeStep?.(ctx);
|
|
110
|
+
const scope = this.scope();
|
|
111
|
+
// Iteration bookkeeping also serves after_iteration observations: keep it
|
|
112
|
+
// outside the before_iteration short-circuit or the counter stays at 0.
|
|
113
|
+
scope.iteration = ctx.iteration + 1;
|
|
114
|
+
if (!this.port.hasHooks('before_iteration'))
|
|
115
|
+
return originalUpdate;
|
|
116
|
+
const currentModel = scope.resolvedModel;
|
|
117
|
+
if (!scope.runId || !currentModel)
|
|
118
|
+
throw new Error('before_iteration requires a resolved Host model and Run identity');
|
|
119
|
+
const result = await this.port.beforeIteration({
|
|
120
|
+
...this.context(),
|
|
121
|
+
runId: scope.runId,
|
|
122
|
+
iteration: ctx.iteration,
|
|
123
|
+
messages: ctx.context.messages,
|
|
124
|
+
model: { provider: currentModel.providerName, model: currentModel.modelName },
|
|
125
|
+
thinking: scope.thinkingLevel,
|
|
126
|
+
});
|
|
127
|
+
if (result.vote.decision !== 'allow') {
|
|
128
|
+
throw new HookDeniedError(result.vote, 'before_iteration');
|
|
129
|
+
}
|
|
130
|
+
let resolved = currentModel;
|
|
131
|
+
if (result.transform.model) {
|
|
132
|
+
if (!scope.resolveConfiguredModel) {
|
|
133
|
+
throw new Error('before_iteration model Transform has no Host model resolver');
|
|
134
|
+
}
|
|
135
|
+
const next = await scope.resolveConfiguredModel(result.transform.model);
|
|
136
|
+
if (!next)
|
|
137
|
+
throw new Error(`before_iteration selected an unconfigured model: ${result.transform.model.provider}/${result.transform.model.model}`);
|
|
138
|
+
resolved = next;
|
|
139
|
+
}
|
|
140
|
+
scope.resolvedModel = resolved;
|
|
141
|
+
// Consensus transform: undefined means "no opinion", never "clear".
|
|
142
|
+
if (result.transform.thinking !== undefined)
|
|
143
|
+
scope.thinkingLevel = result.transform.thinking;
|
|
144
|
+
if (resolved !== currentModel) {
|
|
145
|
+
const { updateResolvedModel } = await import('../../../run/model/run-scope.js');
|
|
146
|
+
updateResolvedModel(resolved);
|
|
147
|
+
}
|
|
148
|
+
if (result.transform.snapshot !== undefined) {
|
|
149
|
+
this.iterationSnapshots.set(ctx.iteration, {
|
|
150
|
+
contributions: result.snapshotContributions.map((contribution) => ({
|
|
151
|
+
pluginId: contribution.pluginId,
|
|
152
|
+
text: contribution.value,
|
|
153
|
+
})),
|
|
154
|
+
tokenBudget: Math.max(1, Math.min(scope.extensionSnapshotBudgetTokens ?? 4096, Math.floor((resolved.contextWindow ?? 8192) * 0.1))),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
this.iterationSnapshots.delete(ctx.iteration);
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
...originalUpdate,
|
|
162
|
+
...(resolved === currentModel ? {} : { model: resolved.provider }),
|
|
163
|
+
...(result.transform.thinking === undefined ? {} : { thinkingLevel: result.transform.thinking }),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
async onStepComplete(ctx) {
|
|
167
|
+
const wantsFinalize = this.port.hasHooks('before_agent_finalize');
|
|
168
|
+
const wantsObserve = this.port.hasHooks('after_iteration');
|
|
169
|
+
if (!wantsFinalize && !wantsObserve)
|
|
170
|
+
return;
|
|
171
|
+
const scope = this.scope();
|
|
172
|
+
// Finalize needs only the Run identity; after_iteration additionally reports
|
|
173
|
+
// the resolved model — separate gates so a missing model never silently
|
|
174
|
+
// swallows a registered finalize.
|
|
175
|
+
if (!scope.runId)
|
|
176
|
+
return;
|
|
177
|
+
if (wantsFinalize && !ctx.message.toolCalls?.length) {
|
|
178
|
+
const transformed = await this.port.transform('before_agent_finalize', {
|
|
179
|
+
...this.context(),
|
|
180
|
+
runId: scope.runId,
|
|
181
|
+
reply: ctx.message,
|
|
182
|
+
}, ctx.message);
|
|
183
|
+
const next = transformed.value;
|
|
184
|
+
if (ctx.context.messages.lastIndexOf(ctx.message) < 0) {
|
|
185
|
+
throw new Error('before_agent_finalize candidate is absent from RunScope messages');
|
|
186
|
+
}
|
|
187
|
+
// Mutate in place only: the message store slot, the event copy and the loop's
|
|
188
|
+
// message must stay one identity. Replacing the slot with the plugin's object
|
|
189
|
+
// forks persistence from events and drops timestamp/metadata on the stored side.
|
|
190
|
+
Object.assign(ctx.message, next);
|
|
191
|
+
}
|
|
192
|
+
if (!wantsObserve || !scope.resolvedModel)
|
|
193
|
+
return;
|
|
194
|
+
await this.port.observe('after_iteration', {
|
|
195
|
+
...this.context(),
|
|
196
|
+
runId: scope.runId,
|
|
197
|
+
iteration: Math.max(0, (scope.iteration ?? 1) - 1),
|
|
198
|
+
messages: ctx.context.messages,
|
|
199
|
+
model: { provider: scope.resolvedModel.providerName, model: scope.resolvedModel.modelName },
|
|
200
|
+
...(scope.thinkingLevel === undefined ? {} : { thinking: scope.thinkingLevel }),
|
|
201
|
+
assistantMessage: ctx.context.messages.find((message) => message === ctx.message) ?? ctx.message,
|
|
202
|
+
toolResults: ctx.toolResults,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/** Enriches Loop config with per-Run hook callbacks; no plugin type enters Core. */
|
|
207
|
+
export function integrateAgentHooks(port, config, scope) {
|
|
208
|
+
if (!port)
|
|
209
|
+
return undefined;
|
|
210
|
+
return new AgentExtensionHookState(port, scope, config);
|
|
211
|
+
}
|
|
212
|
+
/** Host Run-level Vote/Override/Observe, outside the reliability loop. */
|
|
213
|
+
export async function* withAgentRunHooks(port, scope, context, signal, gen) {
|
|
214
|
+
if (!port) {
|
|
215
|
+
yield* gen;
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const startedAt = Date.now();
|
|
219
|
+
const runId = scope.runId ?? `unidentified:${scope.sessionId}:${scope.agentId}`;
|
|
220
|
+
const base = {
|
|
221
|
+
sessionId: scope.sessionId,
|
|
222
|
+
agentId: scope.agentId,
|
|
223
|
+
runId,
|
|
224
|
+
...(scope.principal === undefined ? {} : { principal: scope.principal }),
|
|
225
|
+
...(signal === undefined ? {} : { signal }),
|
|
226
|
+
};
|
|
227
|
+
let reason = 'completed';
|
|
228
|
+
let success = true;
|
|
229
|
+
let failure;
|
|
230
|
+
let iterations = 0;
|
|
231
|
+
try {
|
|
232
|
+
const prompt = scope.prompt ?? getTextContent([...context.messages].reverse().find((message) => message.role === 'user')?.content ?? '');
|
|
233
|
+
const runEvent = { ...base, runId, prompt, messages: context.messages };
|
|
234
|
+
const vote = await port.vote('before_agent_run', runEvent);
|
|
235
|
+
if (vote.decision !== 'allow')
|
|
236
|
+
throw new HookDeniedError(vote, 'before_agent_run');
|
|
237
|
+
const override = await port.override('before_agent_reply', runEvent);
|
|
238
|
+
if (override) {
|
|
239
|
+
const finalized = await port.transform('before_agent_finalize', { ...base, runId, reply: override }, override);
|
|
240
|
+
const reply = {
|
|
241
|
+
...finalized.value,
|
|
242
|
+
agentId: finalized.value.agentId ?? scope.agentId,
|
|
243
|
+
timestamp: finalized.value.timestamp ?? Date.now(),
|
|
244
|
+
};
|
|
245
|
+
context.messages.push(reply);
|
|
246
|
+
yield { type: 'agent_start', timestamp: Date.now() };
|
|
247
|
+
yield { type: 'step_start', timestamp: Date.now() };
|
|
248
|
+
yield { type: 'assistant_message', message: reply, timestamp: Date.now() };
|
|
249
|
+
yield { type: 'step_end', hasToolCalls: false, phase: 'final' };
|
|
250
|
+
iterations = 1;
|
|
251
|
+
yield { type: 'agent_end', reason: 'completed', timestamp: Date.now() };
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
for await (const event of gen) {
|
|
255
|
+
if (event.type === 'agent_end') {
|
|
256
|
+
const terminal = shouldAbortWithoutRetry(event.error);
|
|
257
|
+
// failure first: the denied remap below must see the unwrapped cause.
|
|
258
|
+
failure = terminal ? unwrapExtensionTerminalError(event.error) : event.error;
|
|
259
|
+
reason = failure instanceof HookDeniedError && event.reason === 'error' ? 'denied' : event.reason;
|
|
260
|
+
success = isSuccessfulRunEnd(reason);
|
|
261
|
+
if (terminal) {
|
|
262
|
+
yield { ...event, error: failure };
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (event.type === 'step_end')
|
|
267
|
+
iterations += 1;
|
|
268
|
+
yield event;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
failure = unwrapExtensionTerminalError(error);
|
|
274
|
+
reason = failure instanceof HookDeniedError ? 'denied' : 'error';
|
|
275
|
+
success = isSuccessfulRunEnd(reason);
|
|
276
|
+
yield { type: 'agent_end', reason: 'error', timestamp: Date.now(), error: failure };
|
|
277
|
+
}
|
|
278
|
+
finally {
|
|
279
|
+
const messages = context.messages;
|
|
280
|
+
await port.observe('loop_end', {
|
|
281
|
+
...base,
|
|
282
|
+
runId,
|
|
283
|
+
messages,
|
|
284
|
+
durationMs: Date.now() - startedAt,
|
|
285
|
+
reason,
|
|
286
|
+
success,
|
|
287
|
+
...(failure === undefined ? {} : { error: failure instanceof Error ? failure.message : String(failure) }),
|
|
288
|
+
iterations,
|
|
289
|
+
response: getTextContent([...messages].reverse().find((message) => message.role === 'assistant' && !message.toolCalls?.length)?.content ?? ''),
|
|
290
|
+
});
|
|
291
|
+
await observeRunEnd(port, base, messages, startedAt, reason, success, failure instanceof Error ? failure.message : typeof failure === 'string' ? failure : undefined);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Single success formula for loop_end and agent_end observations: clean terminal
|
|
296
|
+
* ends (completed / should_stop) succeed; aborted / error / denied do not. The
|
|
297
|
+
* Runner treats only `error` as a failed Run and `should_stop` as an intentional
|
|
298
|
+
* stop, so a clean stop is not a failure. `reason` always carries the exact cause.
|
|
299
|
+
*/
|
|
300
|
+
function isSuccessfulRunEnd(reason) {
|
|
301
|
+
return reason === 'completed' || reason === 'should_stop';
|
|
302
|
+
}
|
|
303
|
+
async function observeRunEnd(port, base, messages, startedAt, reason, success, error) {
|
|
304
|
+
await port.observe('agent_end', {
|
|
305
|
+
...base,
|
|
306
|
+
runId: base.runId ?? 'unknown',
|
|
307
|
+
messages,
|
|
308
|
+
durationMs: Date.now() - startedAt,
|
|
309
|
+
reason,
|
|
310
|
+
success,
|
|
311
|
+
...(error === undefined ? {} : { error }),
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
/** Build the Host Run tool Vote after SecurityGuard and before raw execution. */
|
|
315
|
+
export async function voteAgentToolCall(port, ctx, originalParams, signal) {
|
|
316
|
+
if (!port || ctx.args === null || typeof ctx.args !== 'object' || Array.isArray(ctx.args))
|
|
317
|
+
return undefined;
|
|
318
|
+
const scope = getRunScope();
|
|
319
|
+
if (!scope?.runId)
|
|
320
|
+
throw new Error('before_tool_call Vote requires a Host Run identity');
|
|
321
|
+
const event = {
|
|
322
|
+
sessionId: scope.sessionId,
|
|
323
|
+
agentId: scope.agentId,
|
|
324
|
+
runId: scope.runId,
|
|
325
|
+
...(scope.principal === undefined ? {} : { principal: scope.principal }),
|
|
326
|
+
...(signal === undefined ? {} : { signal }),
|
|
327
|
+
toolName: ctx.toolCall.name,
|
|
328
|
+
call: ctx.toolCall,
|
|
329
|
+
params: ctx.args,
|
|
330
|
+
};
|
|
331
|
+
const vote = await port.voteBeforeToolCall(event, originalParams.get(ctx.toolCall) ?? event.params);
|
|
332
|
+
if (vote.decision === 'allow')
|
|
333
|
+
return undefined;
|
|
334
|
+
return {
|
|
335
|
+
block: true,
|
|
336
|
+
reason: vote.reason ?? `Plugin hook denied ${ctx.toolCall.name}`,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PluginServiceRecord } from '../plugins/contribution-registry.js';
|
|
2
|
+
import type { HookAuditRecord } from './types.js';
|
|
3
|
+
export interface PluginServiceAudit {
|
|
4
|
+
append(record: HookAuditRecord): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
/** Host-owned service lifecycle. Registration alone has no background side effect. */
|
|
7
|
+
export declare class PluginServiceSupervisor {
|
|
8
|
+
private readonly onFailure;
|
|
9
|
+
private readonly audit?;
|
|
10
|
+
private started;
|
|
11
|
+
private starting;
|
|
12
|
+
private stopping;
|
|
13
|
+
constructor(onFailure: (service: PluginServiceRecord, error: unknown) => void, audit?: PluginServiceAudit | undefined);
|
|
14
|
+
/** Start in registration order; required failures roll back previously started services. */
|
|
15
|
+
start(services: readonly PluginServiceRecord[]): Promise<void>;
|
|
16
|
+
/** Stop only actually-started services, in reverse order; report all failures. */
|
|
17
|
+
stop(services: readonly PluginServiceRecord[]): Promise<void>;
|
|
18
|
+
/** Best-effort cleanup for a service that failed mid-start; never masks the start failure. */
|
|
19
|
+
private stopOne;
|
|
20
|
+
private key;
|
|
21
|
+
private message;
|
|
22
|
+
private record;
|
|
23
|
+
private invoke;
|
|
24
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/** Host-owned service lifecycle. Registration alone has no background side effect. */
|
|
2
|
+
export class PluginServiceSupervisor {
|
|
3
|
+
onFailure;
|
|
4
|
+
audit;
|
|
5
|
+
started = new Set();
|
|
6
|
+
starting = false;
|
|
7
|
+
stopping = false;
|
|
8
|
+
constructor(onFailure, audit) {
|
|
9
|
+
this.onFailure = onFailure;
|
|
10
|
+
this.audit = audit;
|
|
11
|
+
}
|
|
12
|
+
/** Start in registration order; required failures roll back previously started services. */
|
|
13
|
+
async start(services) {
|
|
14
|
+
if (this.starting)
|
|
15
|
+
throw new Error('Plugin service startup is already in progress');
|
|
16
|
+
if (this.stopping)
|
|
17
|
+
throw new Error('Plugin service startup cannot overlap shutdown');
|
|
18
|
+
if (this.started.size > 0)
|
|
19
|
+
return;
|
|
20
|
+
this.starting = true;
|
|
21
|
+
try {
|
|
22
|
+
for (const service of services) {
|
|
23
|
+
if (!service.start)
|
|
24
|
+
continue;
|
|
25
|
+
try {
|
|
26
|
+
await this.invoke(service, 'start');
|
|
27
|
+
this.started.add(this.key(service));
|
|
28
|
+
await this.record(service, 'start', 'ok');
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
await this.record(service, 'start', 'error', error);
|
|
32
|
+
// A failed or timed-out start may already hold ports/timers: release the
|
|
33
|
+
// failing service itself first, or its partial resources leak past rollback.
|
|
34
|
+
await this.stopOne(service);
|
|
35
|
+
if (service.required) {
|
|
36
|
+
await this.stop(services);
|
|
37
|
+
throw new Error(`Required plugin service ${service.pluginId}/${service.serviceId} failed to start: ${this.message(error)}`);
|
|
38
|
+
}
|
|
39
|
+
this.onFailure(service, error);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
this.starting = false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Stop only actually-started services, in reverse order; report all failures. */
|
|
48
|
+
async stop(services) {
|
|
49
|
+
if (this.stopping)
|
|
50
|
+
return;
|
|
51
|
+
this.stopping = true;
|
|
52
|
+
try {
|
|
53
|
+
const started = services.filter((service) => this.started.has(this.key(service))).reverse();
|
|
54
|
+
for (const service of started) {
|
|
55
|
+
this.started.delete(this.key(service));
|
|
56
|
+
try {
|
|
57
|
+
await this.invoke(service, 'stop');
|
|
58
|
+
await this.record(service, 'stop', 'ok');
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
await this.record(service, 'stop', 'error', error);
|
|
62
|
+
this.onFailure(service, error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
this.stopping = false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Best-effort cleanup for a service that failed mid-start; never masks the start failure. */
|
|
71
|
+
async stopOne(service) {
|
|
72
|
+
if (!service.stop)
|
|
73
|
+
return;
|
|
74
|
+
try {
|
|
75
|
+
await this.invoke(service, 'stop');
|
|
76
|
+
await this.record(service, 'stop', 'ok');
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
// Swallowed on purpose: the start failure is the reported cause; cleanup
|
|
80
|
+
// errors only add audit context and must not replace it.
|
|
81
|
+
await this.record(service, 'stop', 'error', error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
key(service) {
|
|
85
|
+
return `${service.pluginId}:${service.serviceId}`;
|
|
86
|
+
}
|
|
87
|
+
message(error) {
|
|
88
|
+
return error instanceof Error ? error.message : String(error);
|
|
89
|
+
}
|
|
90
|
+
async record(service, phase, outcome, error) {
|
|
91
|
+
if (!this.audit)
|
|
92
|
+
return;
|
|
93
|
+
const hookName = phase === 'start' ? 'service_start' : 'service_stop';
|
|
94
|
+
try {
|
|
95
|
+
await this.audit.append({
|
|
96
|
+
pluginId: service.pluginId,
|
|
97
|
+
hookName,
|
|
98
|
+
phase: 'observe',
|
|
99
|
+
outcome,
|
|
100
|
+
sessionId: 'system',
|
|
101
|
+
agentId: 'host',
|
|
102
|
+
...(error === undefined ? {} : { reason: this.message(error) }),
|
|
103
|
+
details: { serviceId: service.serviceId, phase },
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (auditError) {
|
|
107
|
+
this.onFailure(service, new Error(`Service lifecycle audit failed (${phase}/${outcome}): ${this.message(auditError)}`));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async invoke(service, phase) {
|
|
111
|
+
const timeoutMs = service.timeoutMs ?? 30_000;
|
|
112
|
+
const controller = new AbortController();
|
|
113
|
+
let settled = false;
|
|
114
|
+
const timer = setTimeout(() => {
|
|
115
|
+
controller.abort(new Error(`Plugin service ${phase} timed out after ${timeoutMs}ms`));
|
|
116
|
+
}, timeoutMs);
|
|
117
|
+
try {
|
|
118
|
+
await new Promise((resolve, reject) => {
|
|
119
|
+
const finish = (error) => {
|
|
120
|
+
if (settled)
|
|
121
|
+
return;
|
|
122
|
+
settled = true;
|
|
123
|
+
if (error !== undefined)
|
|
124
|
+
reject(error);
|
|
125
|
+
else
|
|
126
|
+
resolve();
|
|
127
|
+
};
|
|
128
|
+
controller.signal.addEventListener('abort', () => finish(controller.signal.reason), { once: true });
|
|
129
|
+
Promise.resolve()
|
|
130
|
+
.then(() => phase === 'start' ? service.start?.(controller.signal) : service.stop?.(controller.signal))
|
|
131
|
+
.then(() => finish(), finish);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
settled = true;
|
|
136
|
+
clearTimeout(timer);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|