@octopi-agent/engine 0.97.15 → 0.102.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/config-schema/agent.d.ts +37 -5
- package/dist/config-schema/agent.js +24 -4
- package/dist/config-schema/context.d.ts +6 -36
- package/dist/config-schema/context.js +4 -28
- package/dist/config-schema/engine.d.ts +61 -160
- package/dist/config-schema/engine.js +1 -5
- package/dist/config-schema/governance.d.ts +10 -1
- package/dist/config-schema/governance.js +38 -1
- package/dist/config-schema/models.d.ts +2 -8
- package/dist/config-schema/models.js +0 -2
- package/dist/config-schema/run.d.ts +2 -2
- package/dist/config-schema/run.js +2 -2
- package/dist/config-schema/shared.d.ts +0 -3
- package/dist/config-schema/shared.js +0 -2
- package/dist/config-schema/substrate.d.ts +14 -88
- package/dist/config-schema/substrate.js +22 -107
- package/dist/config.d.ts +45 -113
- package/dist/config.js +8 -2
- package/dist/harness/activation/dispatcher.js +7 -0
- package/dist/harness/activation/inbox.d.ts +3 -3
- package/dist/harness/activation/inbox.js +3 -3
- package/dist/harness/activation/runtime.js +13 -5
- package/dist/harness/activation/types.d.ts +2 -2
- package/dist/harness/agent/builder.d.ts +34 -2
- package/dist/harness/agent/builder.js +189 -58
- package/dist/harness/agent/config-bridge.js +9 -2
- package/dist/harness/agent/config-integrity.d.ts +66 -0
- package/dist/harness/agent/config-integrity.js +108 -2
- package/dist/harness/agent/wire-agent-builder.d.ts +11 -3
- package/dist/harness/agent/wire-agent-builder.js +31 -7
- package/dist/harness/capabilities/document/factory.d.ts +5 -0
- package/dist/harness/capabilities/document/factory.js +1 -0
- 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/index.d.ts +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/index.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +4 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +21 -4
- 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/completion-guard.d.ts +40 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.js +59 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +2 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +12 -3
- package/dist/harness/collaboration/delegation/child-run.d.ts +1 -1
- package/dist/harness/collaboration/delegation/child-run.js +4 -4
- 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/service.d.ts +2 -0
- package/dist/harness/collaboration/delegation/service.js +2 -1
- package/dist/harness/collaboration/delegation/store.d.ts +2 -0
- package/dist/harness/collaboration/delegation/store.js +2 -1
- package/dist/harness/collaboration/delegation/types.d.ts +23 -2
- package/dist/harness/collaboration/delegation/types.js +22 -0
- package/dist/harness/collaboration/delegation/wiring.js +11 -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 +0 -6
- package/dist/harness/context/capabilities/compact/engine.js +169 -121
- 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 +5 -1
- package/dist/harness/context/capabilities/compact/index.js +4 -0
- 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 +76 -11
- 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/port.js +0 -1
- package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/resolver.js +4 -9
- package/dist/harness/context/capabilities/summary/tool-binding.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/types.d.ts +4 -7
- package/dist/harness/context/context-size-ledger.d.ts +143 -0
- package/dist/harness/context/context-size-ledger.js +236 -0
- package/dist/harness/context/default-context-engine.d.ts +195 -119
- package/dist/harness/context/default-context-engine.js +1241 -743
- package/dist/harness/context/index.d.ts +2 -2
- package/dist/harness/context/index.js +1 -1
- package/dist/harness/context/layer-types.d.ts +15 -0
- package/dist/harness/context/layer-types.js +14 -1
- package/dist/harness/context/layers.d.ts +16 -19
- package/dist/harness/context/layers.js +42 -14
- package/dist/harness/context/message-selector.d.ts +10 -8
- package/dist/harness/context/message-selector.js +49 -27
- package/dist/harness/context/summarize.d.ts +3 -3
- package/dist/harness/context/summarize.js +11 -4
- package/dist/harness/context/system-prompt-assembler.d.ts +4 -0
- package/dist/harness/context/system-prompt-assembler.js +3 -1
- 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 +6 -1
- package/dist/harness/context/tool-result-aging.js +16 -5
- 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 +127 -117
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +24 -2
- package/dist/harness/extension/execution-environment/effect-policy.js +30 -0
- package/dist/harness/extension/execution-environment/ops-audit.d.ts +7 -3
- package/dist/harness/extension/execution-environment/ops-audit.js +11 -12
- 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/undo-log.d.ts +6 -2
- package/dist/harness/extension/execution-environment/undo-log.js +31 -10
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +1 -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/plugins/api.d.ts +83 -249
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +88 -214
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +43 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +61 -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 +50 -117
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +316 -285
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +23 -490
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +85 -353
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +41 -223
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +138 -19
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +15 -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/builtin.js +17 -24
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -8
- package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +3 -9
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +3 -6
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +9 -5
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +9 -130
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +122 -14
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +4 -13
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +25 -11
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +168 -62
- 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 +11 -2
- 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/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/security/capability-enforcer.js +1 -2
- package/dist/harness/governance/security/default-risk-policy.d.ts +1 -0
- package/dist/harness/governance/security/default-risk-policy.js +1 -0
- package/dist/harness/governance/security/default-security-guard.js +9 -0
- package/dist/harness/governance/security/index.d.ts +1 -0
- package/dist/harness/governance/security/index.js +2 -0
- package/dist/harness/governance/security/risk-evaluator.js +13 -0
- package/dist/harness/governance/security/risk-types.d.ts +12 -0
- package/dist/harness/governance/security/shell-parser-fallback.d.ts +29 -0
- package/dist/harness/governance/security/shell-parser-fallback.js +410 -0
- package/dist/harness/governance/security/shell-parser-shared.d.ts +83 -0
- package/dist/harness/governance/security/shell-parser-shared.js +188 -0
- package/dist/harness/governance/security/shell-parser-treesitter.d.ts +52 -0
- package/dist/harness/governance/security/shell-parser-treesitter.js +370 -0
- package/dist/harness/governance/security/shell-parser.d.ts +23 -10
- package/dist/harness/governance/security/shell-parser.js +37 -496
- package/dist/harness/governance/security/vendor/README.md +24 -0
- package/dist/harness/governance/security/vendor/tree-sitter-bash.LICENSE.txt +21 -0
- package/dist/harness/governance/security/vendor/tree-sitter-bash.wasm +0 -0
- package/dist/harness/index.d.ts +12 -12
- package/dist/harness/index.js +7 -7
- package/dist/harness/knowledge/boot-config.d.ts +55 -0
- package/dist/harness/knowledge/boot-config.js +50 -0
- package/dist/harness/knowledge/catalog-types.d.ts +2 -0
- package/dist/harness/knowledge/client.d.ts +24 -2
- package/dist/harness/knowledge/client.js +19 -5
- package/dist/harness/knowledge/db.js +5 -0
- 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 +6 -0
- package/dist/harness/knowledge/grounding.js +3 -1
- package/dist/harness/knowledge/http-app.js +35 -4
- 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 +3 -0
- package/dist/harness/knowledge/purge.js +5 -2
- package/dist/harness/knowledge/query-service.d.ts +13 -2
- package/dist/harness/knowledge/query-service.js +4 -2
- package/dist/harness/knowledge/query-worker-client.d.ts +9 -1
- package/dist/harness/knowledge/query-worker-client.js +4 -2
- package/dist/harness/knowledge/query-worker.js +4 -2
- package/dist/harness/knowledge/read-http.js +5 -1
- package/dist/harness/knowledge/serve.d.ts +8 -7
- package/dist/harness/knowledge/serve.js +9 -0
- package/dist/harness/knowledge/source-store.js +26 -3
- package/dist/harness/knowledge/start-service-process.d.ts +15 -7
- package/dist/harness/knowledge/start-service-process.js +21 -9
- package/dist/harness/knowledge/types.d.ts +7 -0
- package/dist/harness/knowledge/writer-service.d.ts +37 -9
- package/dist/harness/knowledge/writer-service.js +120 -14
- package/dist/harness/knowledge/writer-worker-client.d.ts +10 -9
- package/dist/harness/knowledge/writer-worker-client.js +20 -2
- package/dist/harness/knowledge/writer-worker.js +9 -1
- package/dist/harness/memory/index.d.ts +6 -2
- package/dist/harness/memory/index.js +4 -1
- package/dist/harness/memory/memory-events.d.ts +25 -0
- package/dist/harness/memory/memory-events.js +38 -0
- package/dist/harness/memory/sqlite/agent-db.js +15 -0
- package/dist/harness/memory/sqlite/wisdom-store.d.ts +7 -2
- package/dist/harness/memory/sqlite/wisdom-store.js +86 -12
- package/dist/harness/memory/steward-policy.d.ts +3 -0
- package/dist/harness/memory/steward-policy.js +1 -1
- package/dist/harness/memory/types.d.ts +47 -7
- package/dist/harness/memory/wisdom-attribution.d.ts +136 -0
- package/dist/harness/memory/wisdom-attribution.js +287 -0
- package/dist/harness/memory/wisdom-events.d.ts +37 -0
- package/dist/harness/memory/wisdom-events.js +61 -0
- package/dist/harness/memory/wisdom-formation.d.ts +31 -1
- package/dist/harness/memory/wisdom-formation.js +130 -33
- package/dist/harness/memory/wisdom-gates.d.ts +14 -0
- package/dist/harness/memory/wisdom-gates.js +59 -19
- package/dist/harness/memory/wisdom.d.ts +7 -2
- package/dist/harness/memory/wisdom.js +49 -2
- package/dist/harness/observability/observer/hub.js +25 -15
- 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 +66 -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/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 +10 -4
- package/dist/harness/run/reliability/run-agent.js +137 -53
- 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-scope.d.ts +41 -4
- package/dist/harness/run/runner.d.ts +71 -31
- package/dist/harness/run/runner.js +368 -106
- 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/transform-store.d.ts +136 -0
- package/dist/harness/session/transform-store.js +302 -0
- package/dist/harness/session/types.d.ts +2 -2
- package/dist/harness/shared/events/agent-event-map.d.ts +46 -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/paths/glob.d.ts +52 -0
- package/dist/harness/shared/paths/glob.js +218 -0
- package/dist/harness/shared/paths/index.d.ts +84 -0
- package/dist/harness/shared/paths/index.js +179 -0
- package/dist/harness/shared/types/agent-definition.d.ts +1 -2
- package/dist/index.d.ts +14 -17
- package/dist/index.js +7 -9
- 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.js +14 -1
- package/dist/integration/providers/openai.js +7 -1
- package/dist/integration/providers/usage.d.ts +1 -1
- package/dist/integration/providers/wire-dump.d.ts +1 -1
- package/dist/integration/storage/archive-manager.d.ts +6 -0
- package/dist/integration/storage/archive-manager.js +10 -0
- package/dist/integration/storage/jsonl.d.ts +1 -1
- package/dist/integration/storage/jsonl.js +18 -16
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +4 -2
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +12 -20
- package/dist/subsystems/memory-steward/backfill/config.yaml +4 -2
- package/dist/subsystems/memory-steward/backfill/handler.js +44 -52
- package/dist/subsystems/wisdom-steward/attribute/SUBSYSTEM.md +24 -0
- package/dist/subsystems/wisdom-steward/attribute/config.yaml +60 -0
- package/dist/subsystems/wisdom-steward/attribute/handler.d.ts +23 -0
- package/dist/subsystems/wisdom-steward/attribute/handler.js +167 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.js +3 -1
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +8 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +13 -5
- package/dist/subsystems/wisdom-steward/formation/handler.js +39 -23
- package/dist/subsystems/wisdom-steward/govern/config.yaml +1 -1
- package/dist/subsystems/wisdom-steward/govern/handler.js +4 -0
- package/package.json +16 -14
- 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
|
@@ -1,336 +1,367 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import * as fs from 'node:fs/promises';
|
|
12
|
-
import { existsSync } from 'node:fs';
|
|
13
|
-
import { validateManifest } from './manifest.js';
|
|
14
|
-
import { PluginApi as PluginApiClass } from './api.js';
|
|
15
|
-
import { CapabilityRegistry, registerManifestCapabilities } from './capability.js';
|
|
16
|
-
/**
|
|
17
|
-
* Plugin Loader
|
|
18
|
-
*
|
|
19
|
-
* 负责从文件系统发现和加载 plugins。
|
|
20
|
-
*/
|
|
1
|
+
/** Manifest-first discovery: no plugin code runs before eligibility and config validation. */
|
|
2
|
+
import { existsSync, readdirSync, readFileSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { join, relative, resolve, sep } from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
import { PluginApi } from './api.js';
|
|
6
|
+
import { parseManifest, validatePluginConfig, } from './manifest.js';
|
|
7
|
+
import { PluginContributionRegistry, } from './contribution-registry.js';
|
|
8
|
+
import { getEngineVersion, satisfiesEngineRange } from './engine-compatibility.js';
|
|
9
|
+
import { readStaging } from './staging.js';
|
|
10
|
+
const PLUGIN_MANIFEST_FILENAME = 'octopi.plugin.json';
|
|
21
11
|
export class PluginLoader {
|
|
22
|
-
|
|
23
|
-
plugins = new Map();
|
|
24
|
-
/** Capability Registry */
|
|
25
|
-
capabilities = new CapabilityRegistry();
|
|
26
|
-
/** 配置 */
|
|
12
|
+
contributions = new PluginContributionRegistry();
|
|
27
13
|
config;
|
|
14
|
+
plugins = new Map();
|
|
15
|
+
diagnostics = [];
|
|
28
16
|
constructor(config) {
|
|
29
17
|
this.config = config;
|
|
30
18
|
}
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
19
|
+
/** Resolve a loaded plugin's configured hook policy, including legacy aliases. */
|
|
20
|
+
getPluginConfig(id) {
|
|
21
|
+
const plugin = this.plugins.get(id);
|
|
22
|
+
if (!plugin)
|
|
23
|
+
return undefined;
|
|
24
|
+
const ids = [plugin.id, ...(plugin.manifest.legacyPluginIds ?? [])];
|
|
25
|
+
return ids.map((key) => this.config.entries?.[key]).find((entry) => entry !== undefined);
|
|
26
|
+
}
|
|
27
|
+
/** Discover, validate and atomically publish the successful plugin set. */
|
|
38
28
|
async discover() {
|
|
39
|
-
|
|
29
|
+
// Keep the previous effective snapshot until the next complete set validates.
|
|
30
|
+
this.diagnostics = [];
|
|
31
|
+
const candidates = new Map();
|
|
32
|
+
const aliases = new Map();
|
|
33
|
+
const rejectedIds = new Set();
|
|
40
34
|
for (const loadPath of this.config.loadPaths) {
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
catch (err) {
|
|
46
|
-
console.warn(`[PluginLoader] Failed to scan "${loadPath}":`, err);
|
|
35
|
+
for (const rootDir of this.scanDirectories(loadPath)) {
|
|
36
|
+
const candidate = this.readCandidate(rootDir);
|
|
37
|
+
if (candidate)
|
|
38
|
+
this.addCandidate(candidate, candidates, aliases, rejectedIds);
|
|
47
39
|
}
|
|
48
40
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// 依赖解析:按 requiresPlugins 拓扑排序
|
|
52
|
-
const ordered = this.resolveDependencyOrder(filtered);
|
|
53
|
-
// 检查缺失的依赖
|
|
54
|
-
const ids = new Set(ordered.map(p => p.manifest.id));
|
|
55
|
-
const disabled = new Set();
|
|
56
|
-
for (const plugin of ordered) {
|
|
57
|
-
const deps = plugin.manifest.requiresPlugins ?? [];
|
|
58
|
-
for (const dep of deps) {
|
|
59
|
-
if (!ids.has(dep)) {
|
|
60
|
-
console.warn(`[PluginLoader] Plugin "${plugin.manifest.id}" requires "${dep}", but it was not found. Skipping.`);
|
|
61
|
-
disabled.add(plugin.manifest.id);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
41
|
+
for (const candidate of candidates.values()) {
|
|
42
|
+
candidate.config = this.config.entries?.[candidate.id];
|
|
64
43
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
await this.registerPlugin(plugin);
|
|
44
|
+
for (const id of rejectedIds) {
|
|
45
|
+
const candidate = candidates.get(id);
|
|
46
|
+
if (candidate)
|
|
47
|
+
candidate.rejected = true;
|
|
70
48
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
49
|
+
this.applyAliases(candidates);
|
|
50
|
+
for (const candidate of candidates.values()) {
|
|
51
|
+
candidate.eligible = this.isEligible(candidate);
|
|
52
|
+
}
|
|
53
|
+
for (const candidate of candidates.values()) {
|
|
54
|
+
if (candidate.eligible)
|
|
55
|
+
this.prepareCandidate(candidate);
|
|
56
|
+
}
|
|
57
|
+
// Configuration, entry, conflict and dependency failures must settle before any import.
|
|
58
|
+
let changed = true;
|
|
59
|
+
while (changed) {
|
|
60
|
+
const before = [...candidates.values()].filter((candidate) => candidate.eligible).length;
|
|
61
|
+
this.markDependencyFailures(candidates, aliases);
|
|
62
|
+
this.checkDeclaredConflicts(candidates);
|
|
63
|
+
changed = before !== [...candidates.values()].filter((candidate) => candidate.eligible).length;
|
|
64
|
+
}
|
|
65
|
+
const staged = [];
|
|
66
|
+
for (const candidate of candidates.values()) {
|
|
67
|
+
if (!candidate.eligible)
|
|
88
68
|
continue;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
69
|
+
const plugin = await this.importAndRegister(candidate);
|
|
70
|
+
if (plugin)
|
|
71
|
+
staged.push(plugin);
|
|
72
|
+
else
|
|
73
|
+
candidate.eligible = false;
|
|
74
|
+
}
|
|
75
|
+
this.markDependencyFailures(candidates, aliases);
|
|
76
|
+
const publishable = staged.filter((plugin) => candidates.get(plugin.manifest.id)?.eligible);
|
|
77
|
+
for (const plugin of staged) {
|
|
78
|
+
if (!candidates.get(plugin.manifest.id)?.eligible) {
|
|
79
|
+
this.fail(plugin.manifest.id, 'dependency', new Error('A required plugin failed to register'), plugin.path);
|
|
94
80
|
}
|
|
95
|
-
|
|
96
|
-
|
|
81
|
+
}
|
|
82
|
+
const nextDiscoveryFailed = this.diagnostics.some((item) => item.status === 'failed');
|
|
83
|
+
if (publishable.length === 0 && nextDiscoveryFailed && this.plugins.size > 0) {
|
|
84
|
+
const reason = 'New discovery has no publishable plugins; last complete snapshot retained for diagnosis';
|
|
85
|
+
this.fail('discovery', 'publish', new Error(reason));
|
|
86
|
+
throw new Error(`Plugin discovery failed: ${reason}`);
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
const nextPlugins = new Map();
|
|
90
|
+
for (const plugin of publishable) {
|
|
91
|
+
const loaded = {
|
|
92
|
+
...plugin,
|
|
93
|
+
id: plugin.manifest.id,
|
|
94
|
+
name: plugin.manifest.name,
|
|
95
|
+
version: plugin.manifest.version,
|
|
96
|
+
...(plugin.manifest.description === undefined ? {} : { description: plugin.manifest.description }),
|
|
97
|
+
source: 'local',
|
|
98
|
+
registered: true,
|
|
99
|
+
};
|
|
100
|
+
nextPlugins.set(loaded.id, loaded);
|
|
97
101
|
}
|
|
102
|
+
this.contributions.publish(publishable);
|
|
103
|
+
this.plugins = nextPlugins;
|
|
104
|
+
for (const plugin of nextPlugins.values()) {
|
|
105
|
+
this.diagnostics.push({ id: plugin.id, status: 'registered', stage: 'publish', reason: 'registered', path: plugin.path });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
// publish constructs a replacement set before assignment; a conflict cannot leave a partial new set.
|
|
110
|
+
this.fail('unknown', 'publish', error);
|
|
98
111
|
}
|
|
99
|
-
return plugins;
|
|
112
|
+
return this.getRegisteredIds().map((id) => this.plugins.get(id));
|
|
100
113
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
*/
|
|
104
|
-
async loadPluginFromDir(pluginDir, manifestPath) {
|
|
105
|
-
// 1. 读取和验证 manifest
|
|
106
|
-
const manifestJson = await fs.readFile(manifestPath, 'utf-8');
|
|
107
|
-
let manifest;
|
|
114
|
+
scanDirectories(loadPath) {
|
|
115
|
+
const root = resolve(loadPath);
|
|
108
116
|
try {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
117
|
+
const stat = readdirSync(root, { withFileTypes: true });
|
|
118
|
+
if (existsSync(join(root, PLUGIN_MANIFEST_FILENAME)))
|
|
119
|
+
return [root];
|
|
120
|
+
return stat
|
|
121
|
+
.filter((entry) => entry.isDirectory() && existsSync(join(root, entry.name, PLUGIN_MANIFEST_FILENAME)))
|
|
122
|
+
.map((entry) => join(root, entry.name));
|
|
114
123
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
console.warn(`[PluginLoader] No entry point found in "${pluginDir}"`);
|
|
119
|
-
return null;
|
|
124
|
+
catch (error) {
|
|
125
|
+
this.diagnostics.push({ id: root, status: 'failed', stage: 'manifest', reason: errorMessage(error), path: root });
|
|
126
|
+
return [];
|
|
120
127
|
}
|
|
121
|
-
|
|
122
|
-
|
|
128
|
+
}
|
|
129
|
+
readCandidate(rootDir) {
|
|
123
130
|
try {
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
if (!definition?.id || !definition?.register) {
|
|
127
|
-
console.warn(`[PluginLoader] Invalid plugin definition in "${entryPoint}": missing id or register`);
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
131
|
+
const manifest = parseManifest(readFileSync(join(rootDir, PLUGIN_MANIFEST_FILENAME), 'utf8'));
|
|
132
|
+
return { id: manifest.id, rootDir, manifest, eligible: false, rejected: false };
|
|
130
133
|
}
|
|
131
|
-
catch (
|
|
132
|
-
|
|
134
|
+
catch (error) {
|
|
135
|
+
this.fail(rootDir, 'manifest', error, rootDir);
|
|
133
136
|
return null;
|
|
134
137
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
source: entryPoint,
|
|
143
|
-
rootDir: pluginDir,
|
|
144
|
-
pluginConfig: entryConfig?.config,
|
|
145
|
-
});
|
|
146
|
-
// 5. 注册 manifest 中声明的能力
|
|
147
|
-
try {
|
|
148
|
-
registerManifestCapabilities(manifest, this.capabilities);
|
|
138
|
+
}
|
|
139
|
+
addCandidate(candidate, candidates, aliases, rejectedIds) {
|
|
140
|
+
const previous = candidates.get(candidate.id);
|
|
141
|
+
if (previous) {
|
|
142
|
+
this.fail(candidate.id, 'manifest', new Error(`Duplicate plugin id at ${candidate.rootDir} and ${previous.rootDir}`), candidate.rootDir);
|
|
143
|
+
rejectedIds.add(candidate.id);
|
|
144
|
+
return;
|
|
149
145
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
146
|
+
const ids = [candidate.id, ...(candidate.manifest.legacyPluginIds ?? [])];
|
|
147
|
+
for (const id of ids) {
|
|
148
|
+
const owner = aliases.get(id);
|
|
149
|
+
if (owner && owner !== candidate.id) {
|
|
150
|
+
this.fail(candidate.id, 'manifest', new Error(`Plugin id or legacy alias "${id}" conflicts with "${owner}"`), candidate.rootDir);
|
|
151
|
+
this.fail(owner, 'manifest', new Error(`Plugin id or legacy alias "${id}" conflicts with "${candidate.id}"`));
|
|
152
|
+
rejectedIds.add(candidate.id).add(owner);
|
|
153
|
+
}
|
|
153
154
|
}
|
|
154
|
-
const
|
|
155
|
-
id
|
|
156
|
-
|
|
157
|
-
definition,
|
|
158
|
-
api,
|
|
159
|
-
source: entryPoint,
|
|
160
|
-
rootDir: pluginDir,
|
|
161
|
-
registered: false,
|
|
162
|
-
};
|
|
163
|
-
this.plugins.set(manifest.id, plugin);
|
|
164
|
-
return plugin;
|
|
155
|
+
for (const id of ids)
|
|
156
|
+
aliases.set(id, candidate.id);
|
|
157
|
+
candidates.set(candidate.id, candidate);
|
|
165
158
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
*/
|
|
174
|
-
async resolveEntryPoint(pluginDir) {
|
|
175
|
-
// 检查 package.json
|
|
176
|
-
const pkgPath = path.join(pluginDir, 'package.json');
|
|
177
|
-
if (existsSync(pkgPath)) {
|
|
178
|
-
try {
|
|
179
|
-
const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf-8'));
|
|
180
|
-
// main 字段
|
|
181
|
-
if (pkg.main) {
|
|
182
|
-
const main = path.resolve(pluginDir, pkg.main);
|
|
183
|
-
if (existsSync(main))
|
|
184
|
-
return main;
|
|
185
|
-
}
|
|
159
|
+
applyAliases(candidates) {
|
|
160
|
+
for (const candidate of candidates.values()) {
|
|
161
|
+
const spellings = [candidate.id, ...(candidate.manifest.legacyPluginIds ?? [])];
|
|
162
|
+
const configured = spellings.filter((id) => this.config.entries?.[id] !== undefined);
|
|
163
|
+
if (configured.length > 1) {
|
|
164
|
+
this.fail(candidate.id, 'policy', new Error(`Plugin is configured under multiple identities: ${configured.join(', ')}`), candidate.rootDir);
|
|
165
|
+
candidate.rejected = true;
|
|
186
166
|
}
|
|
187
|
-
|
|
188
|
-
|
|
167
|
+
else if (configured.length === 1) {
|
|
168
|
+
candidate.config = this.config.entries?.[configured[0]];
|
|
189
169
|
}
|
|
190
170
|
}
|
|
191
|
-
// 尝试常见入口文件
|
|
192
|
-
const candidates = [
|
|
193
|
-
'index.ts', 'index.js', 'index.mjs',
|
|
194
|
-
'src/index.ts', 'src/index.js', 'src/index.mjs',
|
|
195
|
-
'dist/index.js', 'dist/index.mjs',
|
|
196
|
-
];
|
|
197
|
-
for (const candidate of candidates) {
|
|
198
|
-
const fullPath = path.join(pluginDir, candidate);
|
|
199
|
-
if (existsSync(fullPath))
|
|
200
|
-
return fullPath;
|
|
201
|
-
}
|
|
202
|
-
return null;
|
|
203
171
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
172
|
+
isEligible(candidate) {
|
|
173
|
+
if (candidate.rejected)
|
|
174
|
+
return false;
|
|
175
|
+
const ids = [candidate.id, ...(candidate.manifest.legacyPluginIds ?? [])];
|
|
176
|
+
if (this.config.blockList?.some((id) => ids.includes(id))) {
|
|
177
|
+
this.disabled(candidate, 'blocklisted');
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
if (this.config.allowList && !ids.some((id) => this.config.allowList.includes(id))) {
|
|
181
|
+
this.disabled(candidate, 'not in allowList');
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
const enabled = candidate.config?.enabled ?? candidate.manifest.enabledByDefault ?? true;
|
|
185
|
+
if (!enabled) {
|
|
186
|
+
this.disabled(candidate, 'disabled by configuration or manifest default');
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
prepareCandidate(candidate) {
|
|
192
|
+
try {
|
|
193
|
+
candidate.entryPoint = this.resolveEntry(candidate.rootDir, candidate.manifest.entry);
|
|
194
|
+
candidate.pluginConfig = validatePluginConfig(candidate.manifest, candidate.config?.config);
|
|
195
|
+
const engineVersion = this.config.engineVersion ?? getEngineVersion();
|
|
196
|
+
if (!satisfiesEngineRange(engineVersion, candidate.manifest.engine.octopi)) {
|
|
197
|
+
throw new Error(`Requires Octopi ${candidate.manifest.engine.octopi}; host is ${engineVersion}`);
|
|
220
198
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
this.fail(candidate.id, 'config', error, candidate.rootDir);
|
|
202
|
+
candidate.eligible = false;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
markDependencyFailures(candidates, aliases) {
|
|
206
|
+
const visiting = new Set();
|
|
207
|
+
const failed = new Set();
|
|
208
|
+
const visit = (id) => {
|
|
209
|
+
const candidate = candidates.get(id);
|
|
210
|
+
if (!candidate || !candidate.eligible)
|
|
211
|
+
return false;
|
|
212
|
+
if (visiting.has(id)) {
|
|
213
|
+
this.fail(id, 'dependency', new Error('Circular plugin dependency'), candidate.rootDir);
|
|
214
|
+
candidate.eligible = false;
|
|
215
|
+
failed.add(id);
|
|
225
216
|
return false;
|
|
226
217
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
return false;
|
|
218
|
+
if (failed.has(id))
|
|
219
|
+
return false;
|
|
220
|
+
visiting.add(id);
|
|
221
|
+
for (const dependencyName of candidate.manifest.requiresPlugins ?? []) {
|
|
222
|
+
const dependency = aliases.get(dependencyName) ?? dependencyName;
|
|
223
|
+
if (!visit(dependency)) {
|
|
224
|
+
this.fail(id, 'dependency', new Error(`Missing or ineligible dependency "${dependencyName}" (resolved to "${dependency}")`), candidate.rootDir);
|
|
225
|
+
candidate.eligible = false;
|
|
226
|
+
failed.add(id);
|
|
227
|
+
break;
|
|
238
228
|
}
|
|
239
229
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
230
|
+
visiting.delete(id);
|
|
231
|
+
return candidate.eligible;
|
|
232
|
+
};
|
|
233
|
+
for (const id of candidates.keys())
|
|
234
|
+
visit(id);
|
|
235
|
+
}
|
|
236
|
+
checkDeclaredConflicts(candidates) {
|
|
237
|
+
const claims = new Map();
|
|
238
|
+
for (const candidate of candidates.values()) {
|
|
239
|
+
if (!candidate.eligible)
|
|
240
|
+
continue;
|
|
241
|
+
const entries = [
|
|
242
|
+
...(candidate.manifest.contributes?.tools ?? []).map((name) => `tool:${name}`),
|
|
243
|
+
...(candidate.manifest.contributes?.commands ?? []).map((command) => `command:${command.name}`),
|
|
244
|
+
...(candidate.manifest.contributes?.services ?? []).map((name) => `service:${name}`),
|
|
245
|
+
];
|
|
246
|
+
for (const claim of entries) {
|
|
247
|
+
const owner = claims.get(claim);
|
|
248
|
+
if (owner) {
|
|
249
|
+
this.fail(candidate.id, 'register', new Error(`Declared ${claim} conflicts with "${owner}"`), candidate.rootDir);
|
|
250
|
+
candidate.eligible = false;
|
|
251
|
+
const first = candidates.get(owner);
|
|
252
|
+
if (first) {
|
|
253
|
+
first.eligible = false;
|
|
254
|
+
this.fail(owner, 'register', new Error(`Declared ${claim} conflicts with "${candidate.id}"`), first.rootDir);
|
|
246
255
|
}
|
|
247
256
|
}
|
|
257
|
+
else
|
|
258
|
+
claims.set(claim, candidate.id);
|
|
248
259
|
}
|
|
249
|
-
|
|
250
|
-
});
|
|
260
|
+
}
|
|
251
261
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
*/
|
|
258
|
-
resolveDependencyOrder(plugins) {
|
|
259
|
-
const idToPlugin = new Map();
|
|
260
|
-
for (const p of plugins) {
|
|
261
|
-
idToPlugin.set(p.id, p);
|
|
262
|
-
}
|
|
263
|
-
// 计算入度(有多少 plugin 依赖它)
|
|
264
|
-
const inDegree = new Map();
|
|
265
|
-
const dependents = new Map(); // dep → [plugins that depend on it]
|
|
266
|
-
for (const p of plugins) {
|
|
267
|
-
if (!inDegree.has(p.id))
|
|
268
|
-
inDegree.set(p.id, 0);
|
|
269
|
-
const deps = (p.manifest.requiresPlugins ?? []).filter(d => idToPlugin.has(d));
|
|
270
|
-
for (const dep of deps) {
|
|
271
|
-
inDegree.set(p.id, (inDegree.get(p.id) ?? 0) + 1);
|
|
272
|
-
if (!dependents.has(dep))
|
|
273
|
-
dependents.set(dep, []);
|
|
274
|
-
dependents.get(dep).push(p.id);
|
|
275
|
-
}
|
|
262
|
+
async importAndRegister(candidate) {
|
|
263
|
+
const { manifest, rootDir, entryPoint, pluginConfig } = candidate;
|
|
264
|
+
if (!entryPoint || !pluginConfig) {
|
|
265
|
+
this.fail(manifest.id, 'config', new Error('Candidate has not completed pre-import validation'), rootDir);
|
|
266
|
+
return null;
|
|
276
267
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
if (
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
const result = [];
|
|
284
|
-
while (queue.length > 0) {
|
|
285
|
-
const id = queue.shift();
|
|
286
|
-
result.push(idToPlugin.get(id));
|
|
287
|
-
for (const dep of (dependents.get(id) ?? [])) {
|
|
288
|
-
const newDeg = (inDegree.get(dep) ?? 1) - 1;
|
|
289
|
-
inDegree.set(dep, newDeg);
|
|
290
|
-
if (newDeg === 0)
|
|
291
|
-
queue.push(dep);
|
|
268
|
+
try {
|
|
269
|
+
const module = await import(pathToFileURL(entryPoint).href);
|
|
270
|
+
const definition = module.default;
|
|
271
|
+
if (!definition || definition.id !== manifest.id || typeof definition.register !== 'function') {
|
|
272
|
+
throw new Error(`Default entry must be definePlugin({ id: "${manifest.id}", register })`);
|
|
292
273
|
}
|
|
274
|
+
const api = new PluginApi({
|
|
275
|
+
id: manifest.id,
|
|
276
|
+
name: manifest.name,
|
|
277
|
+
version: manifest.version,
|
|
278
|
+
...(manifest.description === undefined ? {} : { description: manifest.description }),
|
|
279
|
+
source: rootDir,
|
|
280
|
+
rootDir,
|
|
281
|
+
pluginConfig,
|
|
282
|
+
});
|
|
283
|
+
await definition.register(api);
|
|
284
|
+
this.assertActualContributions(manifest, api);
|
|
285
|
+
return { manifest, definition, api, path: rootDir };
|
|
293
286
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
if (remaining.length > 0) {
|
|
298
|
-
console.warn(`[PluginLoader] Circular dependency detected among: ${remaining.map(p => p.id).join(', ')}. Appending in original order.`);
|
|
299
|
-
result.push(...remaining);
|
|
287
|
+
catch (error) {
|
|
288
|
+
this.fail(manifest.id, 'register', error, rootDir);
|
|
289
|
+
return null;
|
|
300
290
|
}
|
|
301
|
-
return result;
|
|
302
291
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
return;
|
|
309
|
-
try {
|
|
310
|
-
await plugin.definition.register(plugin.api);
|
|
311
|
-
plugin.registered = true;
|
|
312
|
-
console.info(`[PluginLoader] Plugin "${plugin.id}" registered successfully`);
|
|
292
|
+
resolveEntry(rootDir, entry) {
|
|
293
|
+
const root = realpathSync(rootDir);
|
|
294
|
+
const candidate = resolve(root, entry);
|
|
295
|
+
if (relative(root, candidate).startsWith(`..${sep}`) || relative(root, candidate) === '..') {
|
|
296
|
+
throw new Error(`Plugin entry escapes its root: ${entry}`);
|
|
313
297
|
}
|
|
314
|
-
|
|
315
|
-
|
|
298
|
+
const real = realpathSync(candidate);
|
|
299
|
+
const rel = relative(root, real);
|
|
300
|
+
if (rel === '..' || rel.startsWith(`..${sep}`)) {
|
|
301
|
+
throw new Error(`Plugin entry realpath escapes its root: ${entry}`);
|
|
316
302
|
}
|
|
303
|
+
return real;
|
|
317
304
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
305
|
+
assertActualContributions(manifest, api) {
|
|
306
|
+
const staged = readStaging(api);
|
|
307
|
+
const declaredTools = new Set(manifest.contributes?.tools ?? []);
|
|
308
|
+
const actualTools = new Set(staged.tools.map((tool) => tool.definition.name));
|
|
309
|
+
const declaredCommands = new Map((manifest.contributes?.commands ?? []).map((command) => [command.name, command.sessionOps ?? []]));
|
|
310
|
+
for (const tool of actualTools) {
|
|
311
|
+
if (!declaredTools.has(tool))
|
|
312
|
+
throw new Error(`Tool "${tool}" is not declared in manifest`);
|
|
313
|
+
}
|
|
314
|
+
for (const tool of declaredTools) {
|
|
315
|
+
if (!actualTools.has(tool))
|
|
316
|
+
throw new Error(`Declared tool "${tool}" was not registered`);
|
|
317
|
+
}
|
|
318
|
+
const actualCommands = new Set(staged.commands.map((command) => command.name));
|
|
319
|
+
for (const command of actualCommands) {
|
|
320
|
+
if (!declaredCommands.has(command))
|
|
321
|
+
throw new Error(`Command "${command}" is not declared in manifest`);
|
|
322
|
+
}
|
|
323
|
+
for (const command of declaredCommands.keys()) {
|
|
324
|
+
if (!actualCommands.has(command))
|
|
325
|
+
throw new Error(`Declared command "${command}" was not registered`);
|
|
326
|
+
}
|
|
327
|
+
for (const command of staged.commands) {
|
|
328
|
+
const declared = declaredCommands.get(command.name) ?? [];
|
|
329
|
+
const actual = command.sessionOps ?? [];
|
|
330
|
+
if (JSON.stringify([...declared].sort()) !== JSON.stringify([...actual].sort())) {
|
|
331
|
+
throw new Error(`Command "${command.name}" sessionOps differ from manifest`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
const declaredHooks = new Set(manifest.contributes?.hooks ?? []);
|
|
335
|
+
for (const hook of staged.hooks.keys()) {
|
|
336
|
+
if (!declaredHooks.has(hook))
|
|
337
|
+
throw new Error(`Hook "${hook}" is not declared in manifest`);
|
|
338
|
+
}
|
|
339
|
+
for (const hook of declaredHooks) {
|
|
340
|
+
if (!staged.hooks.has(hook))
|
|
341
|
+
throw new Error(`Declared hook "${hook}" was not registered`);
|
|
342
|
+
}
|
|
343
|
+
const declaredServices = new Set(manifest.contributes?.services ?? []);
|
|
344
|
+
const actualServices = new Set(staged.services.map((service) => service.serviceId));
|
|
345
|
+
for (const service of actualServices) {
|
|
346
|
+
if (!declaredServices.has(service))
|
|
347
|
+
throw new Error(`Service "${service}" is not declared in manifest`);
|
|
348
|
+
}
|
|
349
|
+
for (const service of declaredServices) {
|
|
350
|
+
if (!actualServices.has(service))
|
|
351
|
+
throw new Error(`Declared service "${service}" was not registered`);
|
|
352
|
+
}
|
|
323
353
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
*/
|
|
327
|
-
getAllPlugins() {
|
|
328
|
-
return [...this.plugins.values()];
|
|
354
|
+
disabled(candidate, reason) {
|
|
355
|
+
this.diagnostics.push({ id: candidate.id, status: 'disabled', stage: 'policy', reason, path: candidate.rootDir });
|
|
329
356
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
*/
|
|
333
|
-
getRegisteredIds() {
|
|
334
|
-
return [...this.plugins.values()].filter((p) => p.registered).map((p) => p.id);
|
|
357
|
+
fail(id, stage, error, path) {
|
|
358
|
+
this.diagnostics.push({ id, status: 'failed', stage, reason: errorMessage(error), ...(path === undefined ? {} : { path }) });
|
|
335
359
|
}
|
|
360
|
+
getDiagnostics() { return this.diagnostics.map((item) => ({ ...item })); }
|
|
361
|
+
getRegisteredIds() { return [...this.plugins.keys()]; }
|
|
362
|
+
getPlugin(id) { return this.plugins.get(id); }
|
|
363
|
+
getAllPlugins() { return [...this.plugins.values()]; }
|
|
364
|
+
}
|
|
365
|
+
function errorMessage(error) {
|
|
366
|
+
return error instanceof Error ? error.message : String(error);
|
|
336
367
|
}
|