@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
|
@@ -9,11 +9,12 @@
|
|
|
9
9
|
* .model('gpt-5.5')
|
|
10
10
|
* .persona('./personas/my-agent')
|
|
11
11
|
* .tool(myTool)
|
|
12
|
-
* .budget({
|
|
12
|
+
* .budget({ maxSteps: 15 })
|
|
13
13
|
* .build();
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
import { DefaultToolBus } from '../extension/plugin-ecosystem/tools/tool-bus.js';
|
|
17
|
+
import * as pluginToolAdapter from '../extension/plugin-ecosystem/tools/plugin-tool.js';
|
|
17
18
|
import { expandHomePath } from '../../paths.js';
|
|
18
19
|
import { createUnconfiguredFileEffects, createUnconfiguredMemoryEffects, } from '../extension/execution-environment/undo-log.js';
|
|
19
20
|
import { JournaledMemoryStore } from '../extension/execution-environment/memory-undo.js';
|
|
@@ -62,9 +63,19 @@ export class DefaultErrorStrategy {
|
|
|
62
63
|
if (error.reason === 'content_filter' && attempt < maxAttempts) {
|
|
63
64
|
return { action: 'retry', delayMs: (attempt + 1) * 1000 };
|
|
64
65
|
}
|
|
65
|
-
// ── context_length
|
|
66
|
+
// ── context_length(F 类,arch/overflow-redesign.md T2):重发前 onError 已
|
|
67
|
+
// 回填真值/收缩上界,重装配会砍量后重发;限 2 次防「砍不给力」连环 400。
|
|
68
|
+
// 耗尽后如实收口换 session/model(L3 语义),不再伪装可恢复 ──
|
|
66
69
|
if (error.reason === 'context_length') {
|
|
67
|
-
|
|
70
|
+
if (attempt < maxAttempts) {
|
|
71
|
+
return { action: 'retry', delayMs: (attempt + 1) * 1000 };
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
action: 'abort',
|
|
75
|
+
reason: 'Context length exceeded after shrink-and-resend: ' +
|
|
76
|
+
`${error.message}. ` +
|
|
77
|
+
'This session is no longer suitable for continued work, or the current model does not fit the task scale — start a new session or switch to a model with a larger context window.',
|
|
78
|
+
};
|
|
68
79
|
}
|
|
69
80
|
// ── 不可重试错误:认证、计费 ──
|
|
70
81
|
if (error.reason === 'auth') {
|
|
@@ -159,11 +170,16 @@ function convertToAgentTool(tool, contextProvider) {
|
|
|
159
170
|
name: tool.definition.name,
|
|
160
171
|
description: tool.definition.description,
|
|
161
172
|
executionMode: tool.executionMode,
|
|
173
|
+
...(tool.source === undefined ? {} : { source: tool.source }),
|
|
162
174
|
parameters: buildToolLlmParameters(tool.definition.parameters),
|
|
163
175
|
execute: async (toolCallId, args, signal, onUpdate) => {
|
|
164
176
|
const startTime = Date.now();
|
|
165
177
|
try {
|
|
166
178
|
const context = contextProvider.get();
|
|
179
|
+
const { isPluginToolPermitted } = await import('../extension/plugin-ecosystem/tools/plugin-tool.js');
|
|
180
|
+
if (!isPluginToolPermitted(tool, context.agentToolPolicy)) {
|
|
181
|
+
throw new Error(`Plugin tool "${tool.definition.name}" is not allowed for this agent`);
|
|
182
|
+
}
|
|
167
183
|
const rawArgs = (args ?? {});
|
|
168
184
|
// schema 已 required purpose;模型漏填时推导,不中断调用
|
|
169
185
|
const purpose = resolveToolCallPurpose(tool.definition.name, rawArgs);
|
|
@@ -188,6 +204,7 @@ function convertToAgentTool(tool, contextProvider) {
|
|
|
188
204
|
name: tool.definition.name,
|
|
189
205
|
content: result,
|
|
190
206
|
purpose,
|
|
207
|
+
...(tool.source === undefined ? {} : { source: tool.source }),
|
|
191
208
|
durationMs: Date.now() - startTime,
|
|
192
209
|
};
|
|
193
210
|
}
|
|
@@ -200,6 +217,7 @@ function convertToAgentTool(tool, contextProvider) {
|
|
|
200
217
|
purpose: typeof args?.purpose === 'string'
|
|
201
218
|
? String(args.purpose)
|
|
202
219
|
: '',
|
|
220
|
+
...(tool.source === undefined ? {} : { source: tool.source }),
|
|
203
221
|
durationMs: Date.now() - startTime,
|
|
204
222
|
};
|
|
205
223
|
}
|
|
@@ -335,7 +353,9 @@ export class AgentBuilder {
|
|
|
335
353
|
_toolBus = new DefaultToolBus();
|
|
336
354
|
_contextEngine;
|
|
337
355
|
_summarize;
|
|
338
|
-
/**
|
|
356
|
+
/** 按 session 键控的 context 压力(由 convertToLlm 更新;共享 Agent 下并发会话不串号) */
|
|
357
|
+
_contextPressureBySession = new Map();
|
|
358
|
+
/** 兜底:无 sessionId 的调用方(仅 advisory 用途;并发下可能串号,不得用于持久化) */
|
|
339
359
|
_lastContextPressure;
|
|
340
360
|
/** 为 true 时禁止自动挂默认 summarize(测试/特殊场景) */
|
|
341
361
|
_disableAutoSummarize = false;
|
|
@@ -357,6 +377,8 @@ export class AgentBuilder {
|
|
|
357
377
|
_systemPrompt;
|
|
358
378
|
/** Skill 目录(SKILL.md);build 时 discover 并注入 system prompt 索引 */
|
|
359
379
|
_skillDirectory;
|
|
380
|
+
/** Skill id allowlist(agents[].skills);未设置 = 全部启用 */
|
|
381
|
+
_skillAllowlist;
|
|
360
382
|
_skillManager;
|
|
361
383
|
/** 记忆检索(注入 system prompt MemoryLayer) */
|
|
362
384
|
_memoryStore;
|
|
@@ -376,7 +398,7 @@ export class AgentBuilder {
|
|
|
376
398
|
_knowledgeGrounding;
|
|
377
399
|
/** 智慧(注入 system prompt WisdomLayer) */
|
|
378
400
|
_wisdomStore;
|
|
379
|
-
/** Wisdom 注入策略(wisdom.injection:core/scenario 上限 + trialVisible) */
|
|
401
|
+
/** Wisdom 注入策略(wisdom.injection:core/scenario/trial 上限 + trialVisible) */
|
|
380
402
|
_wisdomInjection;
|
|
381
403
|
/** 认知图谱(注入 system prompt CognitionLayer) */
|
|
382
404
|
_cognitionStore;
|
|
@@ -423,6 +445,8 @@ export class AgentBuilder {
|
|
|
423
445
|
_agentHome;
|
|
424
446
|
/** 逻辑 agentId(观测 / 子系统审计用) */
|
|
425
447
|
_agentId;
|
|
448
|
+
/** Deferred until build so .pluginTools() and .agentId() order is immaterial. */
|
|
449
|
+
_pluginToolRecords = [];
|
|
426
450
|
model(providerOrName) {
|
|
427
451
|
if (typeof providerOrName === 'string') {
|
|
428
452
|
// 字符串形式:创建一个简单的 wrapper(需要外部注册实际 provider)
|
|
@@ -452,6 +476,14 @@ export class AgentBuilder {
|
|
|
452
476
|
this._toolBus.register(tool, { replace: true });
|
|
453
477
|
return this;
|
|
454
478
|
}
|
|
479
|
+
/**
|
|
480
|
+
* Mount host-owned plugin contributions into this Agent's ToolBus projection.
|
|
481
|
+
* Authorization is applied by ToolBus/RunScope; mounting is not Tool exposure.
|
|
482
|
+
*/
|
|
483
|
+
pluginTools(records) {
|
|
484
|
+
this._pluginToolRecords = [...this._pluginToolRecords, ...records];
|
|
485
|
+
return this;
|
|
486
|
+
}
|
|
455
487
|
/** 批量注册:逐个 try/catch,避免一个工具失败拖垮整表 */
|
|
456
488
|
tools(...tools) {
|
|
457
489
|
for (const t of tools) {
|
|
@@ -554,6 +586,17 @@ export class AgentBuilder {
|
|
|
554
586
|
this._skillDirectory = expandHomePath(dir.trim());
|
|
555
587
|
return this;
|
|
556
588
|
}
|
|
589
|
+
/**
|
|
590
|
+
* Skill 启用清单(agents[].skills):discover 只保留列出的 skill id。
|
|
591
|
+
* 不调用或传 undefined = 目录内全部启用。
|
|
592
|
+
*
|
|
593
|
+
* @param ids - 允许的 skill id 列表(SKILL.md 目录名)
|
|
594
|
+
* @returns this
|
|
595
|
+
*/
|
|
596
|
+
skillAllowlist(ids) {
|
|
597
|
+
this._skillAllowlist = ids;
|
|
598
|
+
return this;
|
|
599
|
+
}
|
|
557
600
|
/** 直接注入 SkillManager(跳过目录 discover) */
|
|
558
601
|
skills(manager) {
|
|
559
602
|
this._skillManager = manager;
|
|
@@ -981,6 +1024,7 @@ export class AgentBuilder {
|
|
|
981
1024
|
}
|
|
982
1025
|
const runner = new SessionAwareRunner(agent, harness, store, {
|
|
983
1026
|
...this._runnerConfig,
|
|
1027
|
+
defaultIntentProvider: this._model,
|
|
984
1028
|
toolIsolation: this._toolIsolation ?? this._runnerConfig?.toolIsolation,
|
|
985
1029
|
effectPolicy: this._effectPolicy ?? this._runnerConfig?.effectPolicy,
|
|
986
1030
|
confirmEffect: this._confirmEffect ?? this._runnerConfig?.confirmEffect,
|
|
@@ -993,9 +1037,16 @@ export class AgentBuilder {
|
|
|
993
1037
|
sessionTaskService,
|
|
994
1038
|
sessionScheduleService,
|
|
995
1039
|
events,
|
|
996
|
-
eventSink:
|
|
997
|
-
|
|
998
|
-
|
|
1040
|
+
eventSink: (event, ctx) => {
|
|
1041
|
+
// 适配事件上 EventBus:子系统 trigger(filter.events)与总线消费方按事件名
|
|
1042
|
+
// 匹配的通路(2026-11-04 拍板 A)。llm_stream_delta 高频流片不上总线。
|
|
1043
|
+
if (event.type !== 'llm_stream_delta')
|
|
1044
|
+
events.emit(event);
|
|
1045
|
+
if (this._telemetry?.onEvent)
|
|
1046
|
+
this._telemetry.onEvent(event, ctx);
|
|
1047
|
+
else
|
|
1048
|
+
this._runnerConfig?.eventSink?.(event, ctx);
|
|
1049
|
+
},
|
|
999
1050
|
});
|
|
1000
1051
|
runner.setToolContextProvider(this._contextProvider);
|
|
1001
1052
|
if (this._personaResolver) {
|
|
@@ -1022,6 +1073,7 @@ export class AgentBuilder {
|
|
|
1022
1073
|
wisdomStore,
|
|
1023
1074
|
wisdomCoreMaxItems: this._wisdomInjection?.coreMaxItems,
|
|
1024
1075
|
wisdomScenarioMaxItems: this._wisdomInjection?.scenarioMaxItems,
|
|
1076
|
+
wisdomTrialMaxItems: this._wisdomInjection?.trialMaxItems,
|
|
1025
1077
|
wisdomIncludeTrial: this._wisdomInjection?.trialVisible,
|
|
1026
1078
|
cognitionStore,
|
|
1027
1079
|
systemBudgetRatio: assemblerCfg?.systemBudgetRatio,
|
|
@@ -1333,7 +1385,7 @@ export class AgentBuilder {
|
|
|
1333
1385
|
// Skill:目录 discover(或外部注入的 manager)
|
|
1334
1386
|
if (!this._skillManager && this._skillDirectory) {
|
|
1335
1387
|
const { DefaultSkillManager } = await import('../extension/plugin-ecosystem/skills/manager.js');
|
|
1336
|
-
const mgr = new DefaultSkillManager(this._skillDirectory);
|
|
1388
|
+
const mgr = new DefaultSkillManager(this._skillDirectory, this._skillAllowlist ? { only: this._skillAllowlist } : undefined);
|
|
1337
1389
|
try {
|
|
1338
1390
|
await mgr.discover(this._skillDirectory);
|
|
1339
1391
|
this._skillManager = mgr;
|
|
@@ -1349,6 +1401,9 @@ export class AgentBuilder {
|
|
|
1349
1401
|
cwd: this._workspace?.trim() ? this._workspace : undefined,
|
|
1350
1402
|
});
|
|
1351
1403
|
const busAgentId = this._agentId ?? 'default';
|
|
1404
|
+
for (const record of this._pluginToolRecords) {
|
|
1405
|
+
this._toolBus.registerForAgent(busAgentId, pluginToolAdapter.pluginToolToRegisteredTool(record));
|
|
1406
|
+
}
|
|
1352
1407
|
const agentTools = this._toolBus.listForAgent(busAgentId).map(t => convertToAgentTool(t, this._contextProvider));
|
|
1353
1408
|
console.log(`[AgentBuilder] agent tools (${agentTools.length}): ${agentTools.map((t) => t.name).join(', ')}`);
|
|
1354
1409
|
// 创建 Agent
|
|
@@ -1358,6 +1413,7 @@ export class AgentBuilder {
|
|
|
1358
1413
|
model: this._model,
|
|
1359
1414
|
systemPrompt,
|
|
1360
1415
|
tools: agentTools,
|
|
1416
|
+
extensionHooks: this._runnerConfig?.extensionHooks,
|
|
1361
1417
|
observer: loopObserver ?? (this._observer ? {
|
|
1362
1418
|
onLLMStart: (p) => this._observer?.log('info', 'llm.start', p),
|
|
1363
1419
|
onLLMEnd: (p) => this._observer?.log('info', 'llm.end', p),
|
|
@@ -1368,7 +1424,19 @@ export class AgentBuilder {
|
|
|
1368
1424
|
const agent = new Agent(agentOptions);
|
|
1369
1425
|
// ContextEngine 接线:经 convertToLlm 调用 assemble
|
|
1370
1426
|
// 模型快照只读 ALS(Runner 每 run resolve 一次);无 snapshot 时才回退 agent.model
|
|
1371
|
-
const contextEngine = this._contextEngine ?? new DefaultContextEngine(
|
|
1427
|
+
const contextEngine = this._contextEngine ?? new DefaultContextEngine({
|
|
1428
|
+
...(this._runnerConfig?.sessionsDir
|
|
1429
|
+
? {
|
|
1430
|
+
transformStore: new (await import('../session/transform-store.js')).JsonlTransformStore({
|
|
1431
|
+
sessionsDir: this._runnerConfig.sessionsDir,
|
|
1432
|
+
}),
|
|
1433
|
+
}
|
|
1434
|
+
: {}),
|
|
1435
|
+
...(this._runnerConfig?.extensionHooks === undefined ? {} : {
|
|
1436
|
+
extensionHooks: this._runnerConfig.extensionHooks,
|
|
1437
|
+
extensionIdentity: { sessionId: 'default', agentId: busAgentId },
|
|
1438
|
+
}),
|
|
1439
|
+
});
|
|
1372
1440
|
const { getResolvedModel } = await import('../run/model/run-scope.js');
|
|
1373
1441
|
const summarizeFn = this._summarize ??
|
|
1374
1442
|
(!this._disableAutoSummarize && this._model
|
|
@@ -1384,13 +1452,18 @@ export class AgentBuilder {
|
|
|
1384
1452
|
})(messages, opts);
|
|
1385
1453
|
}
|
|
1386
1454
|
: undefined);
|
|
1387
|
-
agent.setConvertToLlm(async (messages) => {
|
|
1455
|
+
agent.setConvertToLlm(async (messages, signal) => {
|
|
1388
1456
|
// I1:身份与 systemPrompt 优先读 RunScope ALS,避免共享 Agent 单例竞态
|
|
1389
1457
|
const scope = getRunScope();
|
|
1390
1458
|
const sessionId = scope?.sessionId ?? agent.contextSessionId;
|
|
1391
1459
|
const agentId = scope?.agentId ?? 'default';
|
|
1392
1460
|
const systemPrompt = scope?.systemPrompt ?? agent.context.systemPrompt;
|
|
1393
|
-
|
|
1461
|
+
// 工具口径与请求同源(2026-11-07):run 级 tools = loop 实际发送的 toolDefs。
|
|
1462
|
+
// M-6:回退止于 []——run context 未带 tools 时 loop 发送的就是 0 个工具,估算也
|
|
1463
|
+
// 必须是 0;回落实例工具面(agent.context.tools)会让估算多算整包 tools(毒样本)。
|
|
1464
|
+
// 实例面只在 run context 本身就是实例 context 时经 scope.tools 自然成立。
|
|
1465
|
+
const toolSource = scope?.tools ?? [];
|
|
1466
|
+
const tools = toolSource.map((t) => ({
|
|
1394
1467
|
type: 'function',
|
|
1395
1468
|
function: {
|
|
1396
1469
|
name: t.name,
|
|
@@ -1408,6 +1481,7 @@ export class AgentBuilder {
|
|
|
1408
1481
|
const result = await contextEngine.assemble({
|
|
1409
1482
|
sessionId,
|
|
1410
1483
|
agentId,
|
|
1484
|
+
modelKey: snapshot?.ref,
|
|
1411
1485
|
messages,
|
|
1412
1486
|
systemPrompt,
|
|
1413
1487
|
tools,
|
|
@@ -1416,7 +1490,12 @@ export class AgentBuilder {
|
|
|
1416
1490
|
maxOutputTokens: snapshot?.maxOutputTokens,
|
|
1417
1491
|
compactTargetTokens: this._contextAssemblerConfig?.compactTargetTokens,
|
|
1418
1492
|
summarize: summarizeFn,
|
|
1493
|
+
// 交接式摘要素材(F8R-05):自动压缩路径也随摘要请求带上活任务快照;
|
|
1494
|
+
// 空串归一为 undefined——引擎口径「无素材」只有一种形状(评审 L3)
|
|
1495
|
+
taskSnapshot: scope?.taskSnapshot?.() || undefined,
|
|
1419
1496
|
loadCompactState: () => agent.getSessionCompactState(sessionId, agentId),
|
|
1497
|
+
// P3:run 中止信号 —— 摘要调用(provider.chat)随之取消;无此透传时 abort 只能干等
|
|
1498
|
+
signal,
|
|
1420
1499
|
// 惰性读 bus:覆盖 buildAgent 之后才 setEvents 的场景
|
|
1421
1500
|
// Observer:ContextEngine 侧事件(context.compact.* 等)不经过 Runner emitObserved,
|
|
1422
1501
|
// 必须在此直采 Hub,否则 timeline 永远看不到 compact。
|
|
@@ -1440,10 +1519,8 @@ export class AgentBuilder {
|
|
|
1440
1519
|
bus.emit(event);
|
|
1441
1520
|
},
|
|
1442
1521
|
});
|
|
1443
|
-
//
|
|
1444
|
-
|
|
1445
|
-
agent.setSessionCompactState(sessionId, agentId, result.compactState);
|
|
1446
|
-
}
|
|
1522
|
+
// 压缩覆盖/摘要正文由转换记录账本持久(记录先落盘后发视图);
|
|
1523
|
+
// 旧 compactState 快照回写已随记录模型退役(迁移读口仍在 run 起点)。
|
|
1447
1524
|
// Observer P1:LLM 实际输入视图(ContextEngine 出口)
|
|
1448
1525
|
// 真源 = hub.recordLlmMessages;事件只带 summarizeLlmMessages,避免双套统计/覆盖全文
|
|
1449
1526
|
if (this._observerHub?.isEnabled() && this._observerHub.getConfig().channels['context.llm']) {
|
|
@@ -1470,23 +1547,29 @@ export class AgentBuilder {
|
|
|
1470
1547
|
},
|
|
1471
1548
|
});
|
|
1472
1549
|
}
|
|
1473
|
-
//
|
|
1474
|
-
|
|
1550
|
+
// 保存 context 压力(供 harness.getContextPressure(sessionId) 使用):
|
|
1551
|
+
// 按 session 键控——共享 Agent 单例下并发会话各取自己的估算,不串号。
|
|
1552
|
+
// readingSource(评审 F5):读数是校准/实测锚定/裸估算——生产日志可判定读数可信度
|
|
1553
|
+
const pressure = {
|
|
1475
1554
|
estimatedTokens: result.estimatedTokens,
|
|
1476
1555
|
contextWindow,
|
|
1556
|
+
readingSource: result.readingSource,
|
|
1477
1557
|
};
|
|
1558
|
+
this._contextPressureBySession.set(sessionId, pressure);
|
|
1559
|
+
this._lastContextPressure = pressure;
|
|
1478
1560
|
// droppedSummary 不得进 system(动态注记打穿前缀缓存)。
|
|
1479
1561
|
// 本轮直接不投递;压缩语义由消息侧 contextSummary 承载。
|
|
1480
1562
|
return result.messages;
|
|
1481
1563
|
});
|
|
1482
|
-
agent.
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1564
|
+
agent.setOnAfterStep(async (identity, usage, step) => {
|
|
1565
|
+
// 身份只信调用方显式传入(40-engineering #8 单源):runner 事件循环跑在 run 的
|
|
1566
|
+
// ALS 窗口外,getRunScope() 会拿到泄漏的外层 scope,agent.contextSessionId 是
|
|
1567
|
+
// 共享可变字段——并发委派子 run 下两者双向串味,错位样本毒化 ratio 校准
|
|
1568
|
+
// (2026-11-09 事故:视图估算 160k vs 实测 314k)。
|
|
1569
|
+
await contextEngine.afterStep?.({
|
|
1570
|
+
sessionId: identity.sessionId,
|
|
1571
|
+
agentId: identity.agentId,
|
|
1572
|
+
step: step ?? [],
|
|
1490
1573
|
usage: usage,
|
|
1491
1574
|
});
|
|
1492
1575
|
});
|
|
@@ -1533,9 +1616,30 @@ export class AgentBuilder {
|
|
|
1533
1616
|
runGuard,
|
|
1534
1617
|
budget,
|
|
1535
1618
|
// P5: Context 压力回调(从 ContextEngine assemble 获取)
|
|
1536
|
-
getContextPressure: () =>
|
|
1619
|
+
getContextPressure: (sessionId) => sessionId !== undefined
|
|
1620
|
+
? builderRef._contextPressureBySession.get(sessionId)
|
|
1621
|
+
: builderRef._lastContextPressure,
|
|
1622
|
+
// 校准状态通道(持久化配套):export 写进 session metadata、restore 时 import——
|
|
1623
|
+
// 重启后第一轮即 anchored/calibrated,消除「跑几轮才校准」冷启动过渡
|
|
1624
|
+
exportCalibration: () => contextEngine.exportCalibration?.(),
|
|
1625
|
+
importCalibration: (data) => {
|
|
1626
|
+
contextEngine.importCalibration?.(data);
|
|
1627
|
+
},
|
|
1537
1628
|
// high 风险确认:有则走人工审批,无则 run-agent 回退 reject
|
|
1538
1629
|
confirmHighRisk: this._confirmHighRisk,
|
|
1630
|
+
// P3 告警通道:F 类反馈环(T2)的症状告警,与 ContextEngine emit 同路(Hub + EventBus)
|
|
1631
|
+
// data 形状与 emit 闭包同源(剥 type/sessionId,其余入 data)
|
|
1632
|
+
onOverflowAlert: (alert) => {
|
|
1633
|
+
const { type, sessionId: sid, ...data } = alert;
|
|
1634
|
+
const event = { type, timestamp: Date.now(), sessionId: sid, data };
|
|
1635
|
+
try {
|
|
1636
|
+
this._observerHub?.ingestEvent(event);
|
|
1637
|
+
}
|
|
1638
|
+
catch {
|
|
1639
|
+
// 观测 fail-open
|
|
1640
|
+
}
|
|
1641
|
+
this._events?.emit(event);
|
|
1642
|
+
},
|
|
1539
1643
|
};
|
|
1540
1644
|
// Agent.run() 需要 harness;Builder 组装期绑定
|
|
1541
1645
|
agent.setHarness(harness);
|
|
@@ -100,8 +100,8 @@ export async function buildFromConfig(config, options) {
|
|
|
100
100
|
const budgetConfig = config.budgetPolicy;
|
|
101
101
|
const runGuardConfig = config.runGuard;
|
|
102
102
|
const contextEngineConfig = config.contextEngine;
|
|
103
|
-
const contextAssemblerConfig = config.context?.contextAssembler
|
|
104
|
-
const constitutionConfig = config.context?.constitution
|
|
103
|
+
const contextAssemblerConfig = config.context?.contextAssembler;
|
|
104
|
+
const constitutionConfig = config.context?.constitution;
|
|
105
105
|
// 2. 加载子系统(三级搜索路径)
|
|
106
106
|
const subsystemSpecs = await resolveSubsystemSpecs();
|
|
107
107
|
// 3. 为每个 agent 构建
|
|
@@ -127,6 +127,7 @@ export async function buildFromConfig(config, options) {
|
|
|
127
127
|
subsystemAllowlist: config.subsystems?.allowlist,
|
|
128
128
|
subsystemDenylist: config.subsystems?.denylist,
|
|
129
129
|
toolIsolation: config.toolIsolation,
|
|
130
|
+
effectPolicy: config.effectPolicy,
|
|
130
131
|
sessionIdleExpiryMs: config.session?.idleExpiryMs,
|
|
131
132
|
modelCallConfig: config.modelCall,
|
|
132
133
|
concurrencyConfig: config.concurrency,
|
|
@@ -184,12 +185,18 @@ async function buildAgent(agentConfig, shared) {
|
|
|
184
185
|
await wireAgentBuilder(builder, {
|
|
185
186
|
model: provider,
|
|
186
187
|
agentId: agentConfig.id,
|
|
188
|
+
// 转换记录账本持久面(评审 F4):sessionsDir 穿到引擎工厂;缺省时引擎为
|
|
189
|
+
// 进程内存 store(首条记录有一次性告警,不静默)
|
|
190
|
+
extraRunnerConfig: shared.runnerConfig?.sessionsDir
|
|
191
|
+
? { sessionsDir: shared.runnerConfig.sessionsDir }
|
|
192
|
+
: undefined,
|
|
187
193
|
workspace: agentConfig.workspace,
|
|
188
194
|
// legacy:string persona 等价 home(config-bridge 显式决定,不进 wire 隐式规则)
|
|
189
195
|
home: agentConfig.home ??
|
|
190
196
|
(typeof agentConfig.persona === 'string' ? agentConfig.persona : undefined),
|
|
191
197
|
persona: agentConfig.persona,
|
|
192
198
|
skillDirectory: agentConfig.skillDirectory,
|
|
199
|
+
skills: agentConfig.skills,
|
|
193
200
|
tools: agentConfig.tools,
|
|
194
201
|
maxSessionRights: agentConfig.maxSessionRights,
|
|
195
202
|
effectPolicy: agentConfig.effectPolicy ?? shared.effectPolicy,
|
|
@@ -89,11 +89,28 @@ export function computeSecurityConfigFingerprint(config) {
|
|
|
89
89
|
...pickFields(config.effectPolicy ?? {}, EFFECT_POLICY_SECURITY_KEYS, 'effectPolicy.'),
|
|
90
90
|
...pickFields(config.security ?? {}, SECURITY_CONFIG_SECURITY_KEYS, 'security.'),
|
|
91
91
|
};
|
|
92
|
-
// per-agent
|
|
92
|
+
// per-agent 覆盖与工具面/插件加载授权都是安全面。
|
|
93
93
|
if (config.agents !== undefined)
|
|
94
94
|
fields['agents'] = config.agents;
|
|
95
95
|
if (config.plugins !== undefined && Object.keys(config.plugins).length > 0) {
|
|
96
|
-
|
|
96
|
+
const pluginFields = pickFields(config.plugins, ['loadPaths', 'allowList', 'blockList'], 'plugins.');
|
|
97
|
+
const entries = config.plugins.entries;
|
|
98
|
+
if (typeof entries === 'object' && entries !== null && !Array.isArray(entries)) {
|
|
99
|
+
const enabled = {};
|
|
100
|
+
for (const [id, entry] of Object.entries(entries)) {
|
|
101
|
+
if (typeof entry === 'object' && entry !== null && !Array.isArray(entry)) {
|
|
102
|
+
const value = entry.enabled;
|
|
103
|
+
if (value !== undefined)
|
|
104
|
+
enabled[id] = value;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
pluginFields['plugins.entries.enabled'] = enabled;
|
|
108
|
+
}
|
|
109
|
+
// Business config is hashed, never copied into the diagnostic field projection.
|
|
110
|
+
if (config.plugins.configs !== undefined) {
|
|
111
|
+
pluginFields['plugins.legacyConfigsHash'] = createHash('sha256').update(stableStringify(config.plugins.configs)).digest('hex');
|
|
112
|
+
}
|
|
113
|
+
fields['plugins'] = pluginFields;
|
|
97
114
|
}
|
|
98
115
|
return {
|
|
99
116
|
fingerprint: createHash('sha256').update(stableStringify(fields)).digest('hex'),
|
|
@@ -49,9 +49,15 @@ export declare function resolveSecurityConfig(config: {
|
|
|
49
49
|
* 从配置中创建 ContextEngine 实例
|
|
50
50
|
*
|
|
51
51
|
* @param config - contextEngine 配置(可空)
|
|
52
|
+
* @param extension - hooks / agentId / sessionsDir(有 sessionsDir 时转换记录落
|
|
53
|
+
* `sessions/<sid>/transform/`;否则进程内账本)
|
|
52
54
|
* @returns ContextEngine
|
|
53
55
|
*/
|
|
54
|
-
export declare function resolveContextEngine(config: ContextEngineConfig | undefined
|
|
56
|
+
export declare function resolveContextEngine(config: ContextEngineConfig | undefined, extension?: {
|
|
57
|
+
hooks?: SessionAwareRunnerConfig['extensionHooks'];
|
|
58
|
+
agentId: string;
|
|
59
|
+
sessionsDir?: string;
|
|
60
|
+
}): ContextEngine;
|
|
55
61
|
/**
|
|
56
62
|
* 从配置中解析 RunGuard
|
|
57
63
|
*
|
|
@@ -80,6 +86,8 @@ export interface AgentWireSpec {
|
|
|
80
86
|
systemPrompt?: string;
|
|
81
87
|
};
|
|
82
88
|
skillDirectory?: string;
|
|
89
|
+
/** Skill 启用清单(agents[].skills,按 skill id);缺省 = 目录内全部启用 */
|
|
90
|
+
skills?: string[];
|
|
83
91
|
/** SEC-2 / E6 工具策略与会话权利天花板 */
|
|
84
92
|
tools?: import('@octopi-agent/core/types.js').ToolPolicy;
|
|
85
93
|
maxSessionRights?: SessionAwareRunnerConfig['agentMaxSessionRights'];
|
|
@@ -95,8 +103,8 @@ export interface AgentWireSpec {
|
|
|
95
103
|
embedding?: ModelsConfig['embedding'];
|
|
96
104
|
};
|
|
97
105
|
contextEngineConfig?: ContextEngineConfig;
|
|
98
|
-
contextAssemblerConfig?: HarnessConfig['contextAssembler'];
|
|
99
|
-
constitutionConfig?: HarnessConfig['constitution'];
|
|
106
|
+
contextAssemblerConfig?: NonNullable<HarnessConfig['context']>['contextAssembler'];
|
|
107
|
+
constitutionConfig?: NonNullable<HarnessConfig['context']>['constitution'];
|
|
100
108
|
memoryConfig?: HarnessConfig['memory'];
|
|
101
109
|
cognitionConfig?: HarnessConfig['cognition'];
|
|
102
110
|
wisdomConfig?: HarnessConfig['wisdom'];
|
|
@@ -18,6 +18,7 @@ import { getOctopiHome } from '../../paths.js';
|
|
|
18
18
|
import { DefaultRunGuard, } from '../run/run-guard/default-run-guard.js';
|
|
19
19
|
import { DefaultContextEngine } from '../context/default-context-engine.js';
|
|
20
20
|
import { DefaultBudgetAllocator } from '../context/budget-allocator.js';
|
|
21
|
+
import { JsonlTransformStore } from '../session/transform-store.js';
|
|
21
22
|
import { initShellParser } from '../governance/security/shell-parser.js';
|
|
22
23
|
// ── 配置解析(唯一实现;供 wire 与公开导出共用) ──
|
|
23
24
|
/**
|
|
@@ -56,20 +57,33 @@ export function resolveSecurityConfig(config) {
|
|
|
56
57
|
* 从配置中创建 ContextEngine 实例
|
|
57
58
|
*
|
|
58
59
|
* @param config - contextEngine 配置(可空)
|
|
60
|
+
* @param extension - hooks / agentId / sessionsDir(有 sessionsDir 时转换记录落
|
|
61
|
+
* `sessions/<sid>/transform/`;否则进程内账本)
|
|
59
62
|
* @returns ContextEngine
|
|
60
63
|
*/
|
|
61
|
-
export function resolveContextEngine(config) {
|
|
64
|
+
export function resolveContextEngine(config, extension) {
|
|
62
65
|
// 缺省 type = default:只给旋钮(如 proactiveCompactRatio)也必须落到默认引擎
|
|
63
66
|
if (!config || config.type == null || config.type === 'default') {
|
|
64
67
|
return new DefaultContextEngine({
|
|
65
68
|
protectFirstN: config?.protectFirstN ?? 5,
|
|
66
69
|
protectLastN: config?.protectLastN ?? 20,
|
|
70
|
+
midTurnProtectLastN: config?.midTurnProtectLastN,
|
|
67
71
|
summaryBudget: config?.summaryBudget,
|
|
68
72
|
proactiveCompactRatio: config?.proactiveCompactRatio ?? 0.6,
|
|
69
73
|
proactiveCooldownMs: config?.proactiveCooldownMs ?? 30_000,
|
|
74
|
+
summarizeTimeoutMs: config?.summarizeTimeoutMs,
|
|
70
75
|
historyAging: config?.historyAging,
|
|
71
76
|
targetTokens: config?.targetTokens,
|
|
72
77
|
compactFallbackRatio: config?.compactFallbackRatio,
|
|
78
|
+
...(extension?.sessionsDir
|
|
79
|
+
? {
|
|
80
|
+
transformStore: new JsonlTransformStore({ sessionsDir: extension.sessionsDir }),
|
|
81
|
+
}
|
|
82
|
+
: {}),
|
|
83
|
+
...(extension?.hooks === undefined ? {} : {
|
|
84
|
+
extensionHooks: extension.hooks,
|
|
85
|
+
extensionIdentity: { sessionId: 'default', agentId: extension.agentId },
|
|
86
|
+
}),
|
|
73
87
|
budgetAllocator: new DefaultBudgetAllocator({
|
|
74
88
|
outputRatio: config?.outputRatio ?? 0.20,
|
|
75
89
|
minOutputReserve: config?.minOutputReserve ?? 2000,
|
|
@@ -197,7 +211,7 @@ export async function wireAgentBuilder(builder, spec) {
|
|
|
197
211
|
if (skillDir && existsSync(skillDir)) {
|
|
198
212
|
try {
|
|
199
213
|
const { DefaultSkillManager } = await import('../extension/plugin-ecosystem/skills/manager.js');
|
|
200
|
-
skillManager = new DefaultSkillManager();
|
|
214
|
+
skillManager = new DefaultSkillManager(undefined, spec.skills ? { only: spec.skills } : undefined);
|
|
201
215
|
await skillManager.discover(skillDir);
|
|
202
216
|
builder.skills(skillManager);
|
|
203
217
|
}
|
|
@@ -205,7 +219,8 @@ export async function wireAgentBuilder(builder, spec) {
|
|
|
205
219
|
console.warn(`[AgentWire] skill discover failed for ${skillDir}: ${err instanceof Error ? err.message : String(err)}`);
|
|
206
220
|
skillManager = undefined;
|
|
207
221
|
}
|
|
208
|
-
// 无 manager 时 builder
|
|
222
|
+
// 无 manager 时 builder 仍可用目录兜底(allowlist 同样生效)
|
|
223
|
+
builder.skillAllowlist(spec.skills);
|
|
209
224
|
builder.skillDirectory(skillDir);
|
|
210
225
|
}
|
|
211
226
|
// ── Memory / Wisdom / Cognition(agent home 下 AgentDatabase) ──
|
|
@@ -229,7 +244,11 @@ export async function wireAgentBuilder(builder, spec) {
|
|
|
229
244
|
wireBudget(builder, spec.budgetConfig);
|
|
230
245
|
}
|
|
231
246
|
// ── Context Engine(缺省也接线:配置面必须有唯一出口) ──
|
|
232
|
-
builder.contextEngine(resolveContextEngine(spec.contextEngineConfig
|
|
247
|
+
builder.contextEngine(resolveContextEngine(spec.contextEngineConfig, {
|
|
248
|
+
hooks: spec.extraRunnerConfig?.extensionHooks,
|
|
249
|
+
agentId: spec.agentId,
|
|
250
|
+
sessionsDir: spec.extraRunnerConfig?.sessionsDir,
|
|
251
|
+
}));
|
|
233
252
|
// ── Context Assembler / Constitution / Memory policy ──
|
|
234
253
|
if (spec.contextAssemblerConfig) {
|
|
235
254
|
builder.contextAssembler(spec.contextAssemblerConfig);
|
|
@@ -284,13 +303,13 @@ export function shouldAutoLoadSubsystems(spec) {
|
|
|
284
303
|
function wireBudget(builder, budgetConfig) {
|
|
285
304
|
const engineConfig = {
|
|
286
305
|
maxWallClockMs: budgetConfig.maxWallClockMs,
|
|
287
|
-
|
|
306
|
+
maxSteps: budgetConfig.maxSteps,
|
|
288
307
|
maxToolCalls: budgetConfig.maxToolCalls,
|
|
289
308
|
};
|
|
290
309
|
builder.budget(engineConfig);
|
|
291
310
|
const wrapUpConfig = {};
|
|
292
|
-
if ('
|
|
293
|
-
wrapUpConfig.
|
|
311
|
+
if ('wrapUpSteps' in budgetConfig && budgetConfig.wrapUpSteps !== undefined) {
|
|
312
|
+
wrapUpConfig.steps = budgetConfig.wrapUpSteps;
|
|
294
313
|
}
|
|
295
314
|
if ('onPolicyHit' in budgetConfig && budgetConfig.onPolicyHit !== undefined) {
|
|
296
315
|
wrapUpConfig.onPolicyHit = budgetConfig.onPolicyHit;
|
|
@@ -11,6 +11,11 @@ import type { DocumentPort } from './types.js';
|
|
|
11
11
|
export interface DocumentCapabilityConfig {
|
|
12
12
|
extract?: {
|
|
13
13
|
enabled?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* 档位路由部署缺省(per-call extractOptions.tier 覆盖):
|
|
16
|
+
* `auto`(缺省)= t0→t1→t2 逐档降级;`t0-only` = 钉死本地抽取,不外发增强/云
|
|
17
|
+
*/
|
|
18
|
+
backend?: 'auto' | 't0-only';
|
|
14
19
|
timeoutMs?: number;
|
|
15
20
|
maxFileBytes?: number;
|
|
16
21
|
allowedRoots?: string[];
|
|
@@ -18,6 +18,7 @@ export function createDocumentPortFromConfig(cfg) {
|
|
|
18
18
|
const extract = cfg?.extract;
|
|
19
19
|
const config = {
|
|
20
20
|
enabled: extract?.enabled !== false,
|
|
21
|
+
...(extract?.backend ? { backend: extract.backend } : {}),
|
|
21
22
|
...(extract?.timeoutMs != null ? { timeoutMs: extract.timeoutMs } : {}),
|
|
22
23
|
...(extract?.maxFileBytes != null ? { maxFileBytes: extract.maxFileBytes } : {}),
|
|
23
24
|
...(extract?.allowedRoots?.length ? { allowedRoots: extract.allowedRoots } : {}),
|
|
@@ -111,6 +111,8 @@ export function createDefaultDocumentPort(options = {}) {
|
|
|
111
111
|
const backends = options.backends ?? createDefaultBackends();
|
|
112
112
|
const legacy = options.legacyConverter ?? null;
|
|
113
113
|
const capsTtl = options.capabilitiesTtlMs ?? 5 * 60_000;
|
|
114
|
+
/** 部署缺省档位(documents.extract.backend):t0-only 钉死本地档;probe / hasBackendFor / extract 同判 */
|
|
115
|
+
const defaultTier = config.backend === 't0-only' ? 't0' : undefined;
|
|
114
116
|
let capsCache = null;
|
|
115
117
|
async function availableBackendIds() {
|
|
116
118
|
const ids = new Set();
|
|
@@ -230,7 +232,7 @@ export function createDefaultDocumentPort(options = {}) {
|
|
|
230
232
|
if (LEGACY_FORMATS.has(format) && format !== 'xls') {
|
|
231
233
|
return { format, level: caps.formats[format]?.level ?? 'none' };
|
|
232
234
|
}
|
|
233
|
-
const candidates = pickBackends(format, available,
|
|
235
|
+
const candidates = pickBackends(format, available, tierOrder(defaultTier));
|
|
234
236
|
const first = candidates[0];
|
|
235
237
|
return {
|
|
236
238
|
format,
|
|
@@ -296,11 +298,12 @@ export function createDefaultDocumentPort(options = {}) {
|
|
|
296
298
|
});
|
|
297
299
|
async function hasBackendFor(fmt) {
|
|
298
300
|
const { available } = await loadCapabilities();
|
|
299
|
-
return pickBackends(fmt, available,
|
|
301
|
+
return pickBackends(fmt, available, tierOrder(defaultTier)).length > 0;
|
|
300
302
|
}
|
|
301
303
|
async function runExtract(args) {
|
|
302
304
|
const { available } = await loadCapabilities();
|
|
303
|
-
|
|
305
|
+
// 档位路由:per-call tier > documents.extract.backend 部署缺省(t0-only 钉死不外发)> auto 全档
|
|
306
|
+
const tiers = tierOrder(args.extractOptions.tier ?? defaultTier);
|
|
304
307
|
const candidates = pickBackends(args.formatHint, available, tiers);
|
|
305
308
|
if (candidates.length === 0 && args.formatHint === 'unknown') {
|
|
306
309
|
throw new DocumentExtractError('UNSUPPORTED_FORMAT', 'unable to detect document format');
|
|
@@ -145,6 +145,11 @@ export interface ResolvedExtractSource {
|
|
|
145
145
|
}
|
|
146
146
|
export interface DocumentPortConfig {
|
|
147
147
|
enabled?: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* 档位路由部署缺省(per-call ExtractOptions.tier 覆盖):
|
|
150
|
+
* `auto`(缺省)= t0→t1→t2 逐档降级;`t0-only` = 钉死本地抽取(内容不外发)
|
|
151
|
+
*/
|
|
152
|
+
backend?: 'auto' | 't0-only';
|
|
148
153
|
timeoutMs?: number;
|
|
149
154
|
maxFileBytes?: number;
|
|
150
155
|
/** 路径允许根;未设置则不限制(由调用方约束) */
|
|
@@ -291,7 +291,7 @@ async function buildSpec(config, systemPrompt, source, dirPath) {
|
|
|
291
291
|
implementation: impl,
|
|
292
292
|
systemPrompt: thinkRaw.systemPrompt ?? systemPrompt,
|
|
293
293
|
model: thinkRaw.model ?? config.model,
|
|
294
|
-
|
|
294
|
+
maxSteps: thinkRaw.maxSteps ?? config.maxSteps,
|
|
295
295
|
handler,
|
|
296
296
|
preProcess,
|
|
297
297
|
postProcess,
|
|
@@ -105,7 +105,7 @@ export declare class SenseEngine {
|
|
|
105
105
|
* - 字符串字面量原样保留(不再把 `'recent'` 误识别为变量)
|
|
106
106
|
* - SenseContext 顶层字段(sessionLifecycle / eventData / …)→ `ctx.<field>`
|
|
107
107
|
* - `eventData.x` → `ctx.eventData.x`;`metrics.x` → `ctx.metrics['x']`
|
|
108
|
-
* - 其余标识符 → `ctx.metrics['id']`(兼容 `
|
|
108
|
+
* - 其余标识符 → `ctx.metrics['id']`(兼容 `step.count` 等指标键)
|
|
109
109
|
*/
|
|
110
110
|
private compileConditionExpression;
|
|
111
111
|
}
|
|
@@ -434,7 +434,7 @@ export class SenseEngine {
|
|
|
434
434
|
* - 字符串字面量原样保留(不再把 `'recent'` 误识别为变量)
|
|
435
435
|
* - SenseContext 顶层字段(sessionLifecycle / eventData / …)→ `ctx.<field>`
|
|
436
436
|
* - `eventData.x` → `ctx.eventData.x`;`metrics.x` → `ctx.metrics['x']`
|
|
437
|
-
* - 其余标识符 → `ctx.metrics['id']`(兼容 `
|
|
437
|
+
* - 其余标识符 → `ctx.metrics['id']`(兼容 `step.count` 等指标键)
|
|
438
438
|
*/
|
|
439
439
|
compileConditionExpression(expr) {
|
|
440
440
|
const body = rewriteConditionExpression(expr);
|
|
@@ -544,7 +544,7 @@ export function rewriteConditionExpression(expr) {
|
|
|
544
544
|
i = rest;
|
|
545
545
|
continue;
|
|
546
546
|
}
|
|
547
|
-
// 其余标识符:整段 dotted name 作为 metrics key(
|
|
547
|
+
// 其余标识符:整段 dotted name 作为 metrics key(step.count)
|
|
548
548
|
let name = base;
|
|
549
549
|
let rest = j;
|
|
550
550
|
while (rest < expr.length &&
|