@octopi-agent/engine 0.98.4 → 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 +35 -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 +57 -160
- package/dist/config-schema/engine.js +1 -5
- package/dist/config-schema/governance.d.ts +8 -1
- package/dist/config-schema/governance.js +8 -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 +24 -3
- package/dist/harness/agent/builder.js +131 -27
- package/dist/harness/agent/config-bridge.js +9 -2
- package/dist/harness/agent/config-integrity.js +19 -2
- package/dist/harness/agent/wire-agent-builder.d.ts +11 -3
- package/dist/harness/agent/wire-agent-builder.js +26 -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/loader.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +2 -2
- 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 +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +3 -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 +1 -6
- package/dist/harness/context/capabilities/summary/tool-binding.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/types.d.ts +3 -6
- 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 +14 -15
- package/dist/harness/context/layers.js +41 -11
- 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 +2 -2
- package/dist/harness/context/summarize.js +9 -2
- package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
- package/dist/harness/context/system-prompt-assembler.js +2 -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/ops-audit.d.ts +1 -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/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/delegation.js +18 -8
- 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/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/sqlite/wisdom-store.js +35 -10
- package/dist/harness/memory/types.d.ts +6 -4
- 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.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 +37 -4
- package/dist/harness/run/runner.d.ts +44 -29
- package/dist/harness/run/runner.js +320 -102
- 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/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/wisdom-steward/formation/SUBSYSTEM.md +8 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +1 -0
- package/dist/subsystems/wisdom-steward/formation/handler.js +27 -5
- package/package.json +11 -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,364 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
* Plugin Manager
|
|
3
|
-
*
|
|
4
|
-
* 这是 plugin 系统的顶层管理器,负责:
|
|
5
|
-
* - 加载和管理所有 plugins
|
|
6
|
-
* - 运行 hooks(支持 priority、timeout、拦截语义)
|
|
7
|
-
* - 能力注册和查询
|
|
8
|
-
*
|
|
9
|
-
* Hook 分类:
|
|
10
|
-
* - 拦截语义:返回值改变执行流程
|
|
11
|
-
* - 观察语义:所有 plugin 都执行
|
|
12
|
-
* - 上下文注入:返回 prependContext / systemPrompt 等
|
|
13
|
-
*/
|
|
1
|
+
import { getOctopiHome } from '../../../../paths.js';
|
|
14
2
|
import { PluginLoader } from './loader.js';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Plugin Manager
|
|
20
|
-
*
|
|
21
|
-
* 负责加载 plugins、运行 hooks、管理能力注册。
|
|
22
|
-
*/
|
|
3
|
+
import { PluginHookAdapter } from '../hooks/adapter.js';
|
|
4
|
+
import { HookAuditJournal } from '../hooks/journal.js';
|
|
5
|
+
import { resolveHitlOutcome } from '../../../governance/human-in-the-loop/decision-cache.js';
|
|
6
|
+
/** Host-owned manager; the author SDK never receives this object. */
|
|
23
7
|
export class PluginManager {
|
|
24
|
-
/** Plugin Loader */
|
|
25
8
|
loader;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
startTime;
|
|
9
|
+
hookJournal;
|
|
10
|
+
hookPort;
|
|
11
|
+
approvalSink;
|
|
30
12
|
constructor(config) {
|
|
31
13
|
this.loader = new PluginLoader(config ?? { loadPaths: [] });
|
|
32
|
-
this.
|
|
14
|
+
this.hookJournal = new HookAuditJournal(() => `${getOctopiHome()}/audit`);
|
|
15
|
+
const host = {
|
|
16
|
+
getHooks: () => this.loader.contributions.getHooks(),
|
|
17
|
+
getPluginConfig: (pluginId) => this.getHookConfig(pluginId),
|
|
18
|
+
recordHook: (record) => this.recordHook(record),
|
|
19
|
+
approveToolCall: (event, request, pluginId) => this.approveToolCall(event, request, pluginId),
|
|
20
|
+
};
|
|
21
|
+
this.hookPort = new PluginHookAdapter(host);
|
|
22
|
+
}
|
|
23
|
+
getDiagnostics() { return this.loader.getDiagnostics(); }
|
|
24
|
+
async discover() { return this.loader.discover(); }
|
|
25
|
+
getAllPlugins() { return this.loader.getAllPlugins(); }
|
|
26
|
+
getRegisteredIds() { return this.loader.getRegisteredIds(); }
|
|
27
|
+
getPlugin(id) { return this.loader.getPlugin(id); }
|
|
28
|
+
/** Narrow interception Port for Harness/Gateway consumers, not the whole Manager. */
|
|
29
|
+
getHookPort() { return this.hookPort; }
|
|
30
|
+
/** Shared append-only audit sink for Host service lifecycle records. */
|
|
31
|
+
getHookAudit() { return this.hookJournal; }
|
|
32
|
+
/** Install the Host's existing high-risk HITL channel; no channel fails closed. */
|
|
33
|
+
setToolApprovalSink(sink) {
|
|
34
|
+
this.approvalSink = sink;
|
|
33
35
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return defaultResult;
|
|
83
|
-
}
|
|
84
|
-
let result = defaultResult;
|
|
85
|
-
for (const entry of entries) {
|
|
86
|
-
// 计算 timeout:plugin config > handler 注册时 > 默认
|
|
87
|
-
const timeoutMs = config?.hooks?.timeouts?.[hookName] ??
|
|
88
|
-
config?.hooks?.timeoutMs ??
|
|
89
|
-
entry.timeoutMs ??
|
|
90
|
-
30_000;
|
|
91
|
-
try {
|
|
92
|
-
const handlerResult = await this.runWithTimeout(() => entry.handler(event), timeoutMs);
|
|
93
|
-
// 拦截语义:非 null/undefined 结果中断链
|
|
94
|
-
if (handlerResult !== null && handlerResult !== undefined) {
|
|
95
|
-
result = handlerResult;
|
|
96
|
-
// block: true 是 terminal
|
|
97
|
-
if (typeof handlerResult === 'object' && 'block' in handlerResult && handlerResult.block) {
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
// cancel: true 是 terminal
|
|
101
|
-
if (typeof handlerResult === 'object' && 'cancel' in handlerResult && handlerResult.cancel) {
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
// outcome: 'block' 是 terminal
|
|
105
|
-
if (typeof handlerResult === 'object' && 'outcome' in handlerResult && handlerResult.outcome === 'block') {
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
36
|
+
getTools(includeOptional = false) {
|
|
37
|
+
return this.loader.contributions.getTools().filter((tool) => includeOptional || !tool.optional);
|
|
38
|
+
}
|
|
39
|
+
getCommands() { return this.loader.contributions.getCommands(); }
|
|
40
|
+
getServices() { return this.loader.contributions.getServices(); }
|
|
41
|
+
getCommandSessionOps(pluginId, name) {
|
|
42
|
+
const command = this.loader.contributions.getCommands().find((candidate) => candidate.pluginId === pluginId &&
|
|
43
|
+
candidate.name.replace(/^\/+/, '').toLowerCase() === name);
|
|
44
|
+
if (!command)
|
|
45
|
+
return undefined;
|
|
46
|
+
const manifest = this.loader.contributions.getPlugin(pluginId)?.manifest;
|
|
47
|
+
const declared = manifest?.contributes?.commands?.find((candidate) => candidate.name === command.name);
|
|
48
|
+
if (!declared)
|
|
49
|
+
return undefined;
|
|
50
|
+
return [...(declared.sessionOps ?? [])];
|
|
51
|
+
}
|
|
52
|
+
getHookConfig(pluginId) {
|
|
53
|
+
return this.loader.getPluginConfig(pluginId);
|
|
54
|
+
}
|
|
55
|
+
async recordHook(record) {
|
|
56
|
+
await this.hookJournal.append(record);
|
|
57
|
+
}
|
|
58
|
+
async approveToolCall(event, request, pluginId) {
|
|
59
|
+
if (!this.approvalSink) {
|
|
60
|
+
return {
|
|
61
|
+
allowed: false,
|
|
62
|
+
decision: 'deny',
|
|
63
|
+
timedOut: false,
|
|
64
|
+
denyReason: 'no_channel',
|
|
65
|
+
denyDetail: 'No Host approval channel is configured for before_tool_call',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const sink = this.approvalSink;
|
|
69
|
+
// SEC-7 single model: the engine remembers approve_session / approve_always
|
|
70
|
+
// (the Host must not cache), so the scope the human chose is actually honored.
|
|
71
|
+
return resolveHitlOutcome({
|
|
72
|
+
channel: 'plugin_hook',
|
|
73
|
+
// Key = asking policy identity + tool name: a session/always grant must never
|
|
74
|
+
// silently satisfy another plugin's approval question for the same tool.
|
|
75
|
+
// Accepted residual semantics: the grant is tool-level, not argument-level —
|
|
76
|
+
// later parameter variants of the same tool+plugin ride the same decision
|
|
77
|
+
// (same contract as the builtin high_risk channel's tool-name key).
|
|
78
|
+
key: `${pluginId}:${event.toolName}`,
|
|
79
|
+
sessionId: event.sessionId,
|
|
80
|
+
agentId: event.agentId,
|
|
81
|
+
ask: async () => {
|
|
82
|
+
try {
|
|
83
|
+
return await sink(event, request);
|
|
108
84
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
break;
|
|
117
|
-
continue;
|
|
85
|
+
catch (error) {
|
|
86
|
+
// Channel failure is a denial source, never a human rejection and never an allow.
|
|
87
|
+
return {
|
|
88
|
+
decision: 'deny',
|
|
89
|
+
denyReason: 'channel_error',
|
|
90
|
+
denyDetail: error instanceof Error ? error.message : String(error),
|
|
91
|
+
};
|
|
118
92
|
}
|
|
119
|
-
|
|
120
|
-
console.error(`[PluginManager] Hook "${hookName}" handler from plugin "${entry.pluginId}" failed:`, err);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return result;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* 执行观察语义的 hook(所有 plugin 都执行,不拦截)
|
|
127
|
-
*/
|
|
128
|
-
async runAllHooks(hookName, event) {
|
|
129
|
-
const entries = this.collectHookEntries(hookName);
|
|
130
|
-
for (const entry of entries) {
|
|
131
|
-
try {
|
|
132
|
-
await entry.handler(event);
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
console.error(`[PluginManager] Hook "${hookName}" from "${entry.pluginId}" error:`, error);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* 收集指定 hook 的所有 handler entries
|
|
141
|
-
*/
|
|
142
|
-
collectHookEntries(hookName) {
|
|
143
|
-
const entries = [];
|
|
144
|
-
for (const plugin of this.loader.getAllPlugins()) {
|
|
145
|
-
if (!plugin.registered)
|
|
146
|
-
continue;
|
|
147
|
-
const hookEntries = plugin.api._hooks.get(hookName);
|
|
148
|
-
if (hookEntries) {
|
|
149
|
-
for (const entry of hookEntries) {
|
|
150
|
-
entries.push({
|
|
151
|
-
pluginId: entry.pluginId,
|
|
152
|
-
handler: entry.handler,
|
|
153
|
-
priority: entry.priority,
|
|
154
|
-
timeoutMs: entry.timeoutMs,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
entries.sort((a, b) => b.priority - a.priority);
|
|
160
|
-
return entries;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* 带超时执行
|
|
164
|
-
*/
|
|
165
|
-
async runWithTimeout(fn, timeoutMs) {
|
|
166
|
-
return new Promise((resolve, reject) => {
|
|
167
|
-
const timer = setTimeout(() => {
|
|
168
|
-
reject(new Error(`Hook handler timed out after ${timeoutMs}ms`));
|
|
169
|
-
}, timeoutMs);
|
|
170
|
-
fn().then((result) => {
|
|
171
|
-
clearTimeout(timer);
|
|
172
|
-
resolve(result);
|
|
173
|
-
}, (err) => {
|
|
174
|
-
clearTimeout(timer);
|
|
175
|
-
reject(err);
|
|
176
|
-
});
|
|
93
|
+
},
|
|
177
94
|
});
|
|
178
95
|
}
|
|
179
|
-
// ================================================================
|
|
180
|
-
// 便捷方法 — 常用 hooks 的快捷调用
|
|
181
|
-
// ================================================================
|
|
182
|
-
/**
|
|
183
|
-
* 获取所有已注册的 providers
|
|
184
|
-
*/
|
|
185
|
-
getProviders() {
|
|
186
|
-
const result = [];
|
|
187
|
-
for (const plugin of this.loader.getAllPlugins()) {
|
|
188
|
-
if (!plugin.registered)
|
|
189
|
-
continue;
|
|
190
|
-
for (const reg of plugin.api._providers) {
|
|
191
|
-
result.push({ pluginId: plugin.id, id: reg.id, provider: reg.provider });
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return result;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* 获取所有已注册的 channels
|
|
198
|
-
*/
|
|
199
|
-
getChannels() {
|
|
200
|
-
const result = [];
|
|
201
|
-
for (const plugin of this.loader.getAllPlugins()) {
|
|
202
|
-
if (!plugin.registered)
|
|
203
|
-
continue;
|
|
204
|
-
for (const reg of plugin.api._channels) {
|
|
205
|
-
result.push({ pluginId: plugin.id, id: reg.id, adapter: reg.adapter });
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return result;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* 获取所有已注册的 tools(过滤 optional)
|
|
212
|
-
*/
|
|
213
|
-
getTools(includeOptional = false) {
|
|
214
|
-
const result = [];
|
|
215
|
-
for (const plugin of this.loader.getAllPlugins()) {
|
|
216
|
-
if (!plugin.registered)
|
|
217
|
-
continue;
|
|
218
|
-
for (const reg of plugin.api._tools) {
|
|
219
|
-
if (!includeOptional && reg.optional)
|
|
220
|
-
continue;
|
|
221
|
-
result.push({
|
|
222
|
-
pluginId: plugin.id,
|
|
223
|
-
definition: reg.definition,
|
|
224
|
-
handler: reg.handler,
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return result;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* 获取所有已注册的 context engines
|
|
232
|
-
*/
|
|
233
|
-
getContextEngines() {
|
|
234
|
-
const result = [];
|
|
235
|
-
for (const plugin of this.loader.getAllPlugins()) {
|
|
236
|
-
if (!plugin.registered)
|
|
237
|
-
continue;
|
|
238
|
-
for (const reg of plugin.api._contextEngines) {
|
|
239
|
-
result.push(reg);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return result;
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* 获取所有已注册的 commands
|
|
246
|
-
*/
|
|
247
|
-
getCommands() {
|
|
248
|
-
const result = [];
|
|
249
|
-
for (const plugin of this.loader.getAllPlugins()) {
|
|
250
|
-
if (!plugin.registered)
|
|
251
|
-
continue;
|
|
252
|
-
for (const cmd of plugin.api._commands) {
|
|
253
|
-
result.push({ pluginId: plugin.id, ...cmd });
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return result;
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* 获取所有已注册的 services
|
|
260
|
-
*/
|
|
261
|
-
getServices() {
|
|
262
|
-
const result = [];
|
|
263
|
-
for (const plugin of this.loader.getAllPlugins()) {
|
|
264
|
-
if (!plugin.registered)
|
|
265
|
-
continue;
|
|
266
|
-
for (const svc of plugin.api._services) {
|
|
267
|
-
result.push({ pluginId: plugin.id, ...svc });
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
return result;
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* 获取所有已注册的 web search providers
|
|
274
|
-
*/
|
|
275
|
-
getWebSearchProviders() {
|
|
276
|
-
const result = [];
|
|
277
|
-
for (const plugin of this.loader.getAllPlugins()) {
|
|
278
|
-
if (!plugin.registered)
|
|
279
|
-
continue;
|
|
280
|
-
for (const reg of plugin.api._webSearchProviders) {
|
|
281
|
-
result.push({ pluginId: plugin.id, provider: reg.provider });
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return result;
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* 获取所有已注册的 media understanding providers
|
|
288
|
-
*/
|
|
289
|
-
getMediaUnderstandingProviders() {
|
|
290
|
-
const result = [];
|
|
291
|
-
for (const plugin of this.loader.getAllPlugins()) {
|
|
292
|
-
if (!plugin.registered)
|
|
293
|
-
continue;
|
|
294
|
-
for (const reg of plugin.api._mediaUnderstandingProviders) {
|
|
295
|
-
result.push({ pluginId: plugin.id, provider: reg.provider });
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
return result;
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* 获取所有已注册的 image generation providers
|
|
302
|
-
*/
|
|
303
|
-
getImageGenerationProviders() {
|
|
304
|
-
const result = [];
|
|
305
|
-
for (const plugin of this.loader.getAllPlugins()) {
|
|
306
|
-
if (!plugin.registered)
|
|
307
|
-
continue;
|
|
308
|
-
for (const reg of plugin.api._imageGenerationProviders) {
|
|
309
|
-
result.push({ pluginId: plugin.id, provider: reg.provider });
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return result;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* 获取所有已注册的 model catalog providers
|
|
316
|
-
*/
|
|
317
|
-
getModelCatalogProviders() {
|
|
318
|
-
const result = [];
|
|
319
|
-
for (const plugin of this.loader.getAllPlugins()) {
|
|
320
|
-
if (!plugin.registered)
|
|
321
|
-
continue;
|
|
322
|
-
for (const reg of plugin.api._modelCatalogProviders) {
|
|
323
|
-
result.push({ pluginId: plugin.id, ...reg });
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return result;
|
|
327
|
-
}
|
|
328
|
-
// ================================================================
|
|
329
|
-
// Gateway Lifecycle
|
|
330
|
-
// ================================================================
|
|
331
|
-
/**
|
|
332
|
-
* 触发 gateway_start hook 并启动所有 plugin 服务
|
|
333
|
-
*/
|
|
334
|
-
async onGatewayStart(config, workspaceDir) {
|
|
335
|
-
this.startTime = Date.now();
|
|
336
|
-
const event = { config, workspaceDir };
|
|
337
|
-
await this.runHook('gateway_start', event, undefined);
|
|
338
|
-
for (const service of this.getServices()) {
|
|
339
|
-
try {
|
|
340
|
-
await service.start();
|
|
341
|
-
console.info(`[PluginManager] Service "${service.id}" started`);
|
|
342
|
-
}
|
|
343
|
-
catch (err) {
|
|
344
|
-
console.error(`[PluginManager] Service "${service.id}" failed to start:`, err);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* 触发 gateway_stop hook 并停止所有 plugin 服务
|
|
350
|
-
*/
|
|
351
|
-
async onGatewayStop() {
|
|
352
|
-
const event = {};
|
|
353
|
-
await this.runHook('gateway_stop', event, undefined);
|
|
354
|
-
for (const service of this.getServices()) {
|
|
355
|
-
try {
|
|
356
|
-
await service.stop();
|
|
357
|
-
console.info(`[PluginManager] Service "${service.id}" stopped`);
|
|
358
|
-
}
|
|
359
|
-
catch (err) {
|
|
360
|
-
console.error(`[PluginManager] Service "${service.id}" failed to stop:`, err);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
96
|
}
|