@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
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM 输出完整性保障 —— maxTokens 只是发给 provider 的生成配额,不是业务截断边界。
|
|
3
|
+
*
|
|
4
|
+
* 语义(2026-10-30 拍板):`finish=length`(配额截断)或 parse 失败的输出都**不得**当业务
|
|
5
|
+
* 结果收下(禁止静默半截结果);先放大配额重试一次,仍失败则返回显式失败原因,由调用方
|
|
6
|
+
* 决定如何上报。业务完整性优先于调用成本。
|
|
7
|
+
*
|
|
8
|
+
* @module harness/collaboration/autonomous-subsystem/think/completion-guard
|
|
9
|
+
*/
|
|
10
|
+
import type { LLMMessage } from '@octopi-agent/core/interfaces/model-provider.js';
|
|
11
|
+
import type { SubsystemLLMPort } from './llm-port.js';
|
|
12
|
+
/** 完整性调用的失败原因 */
|
|
13
|
+
export type CompletionGuardFailure = 'llm_error' | 'llm_empty' | 'truncated_output' | 'parse_failed';
|
|
14
|
+
/** 完整性调用结果:成功带解析后的业务结构,失败带显式原因 */
|
|
15
|
+
export type CompletionGuardResult<T> = {
|
|
16
|
+
ok: true;
|
|
17
|
+
parsed: T;
|
|
18
|
+
raw: string;
|
|
19
|
+
} | {
|
|
20
|
+
ok: false;
|
|
21
|
+
reason: CompletionGuardFailure;
|
|
22
|
+
message: string;
|
|
23
|
+
};
|
|
24
|
+
export interface CompletionGuardRequest {
|
|
25
|
+
/** 覆盖认知 prompt;默认使用 port 绑定的 SUBSYSTEM.md 正文 */
|
|
26
|
+
systemPrompt?: string;
|
|
27
|
+
/** 对话消息(不含 system) */
|
|
28
|
+
messages: LLMMessage[];
|
|
29
|
+
/** 生成配额(LLM 传参);截断时重试放大 2 倍,硬上限 {@link RETRY_MAX_TOKENS_CAP} */
|
|
30
|
+
maxTokens: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 带输出完整性保障的单轮 LLM 调用:截断或解析失败时放大配额重试一次。
|
|
34
|
+
*
|
|
35
|
+
* @param llmPort - subsystem LLM 端口
|
|
36
|
+
* @param req - systemPrompt / messages / maxTokens(生成配额,非业务截断)
|
|
37
|
+
* @param parse - 从 LLM 文本解析业务结构;失败返回 null
|
|
38
|
+
* @returns 成功返回 parsed;失败返回 llm_error / truncated_output / parse_failed(至多 2 次 LLM 调用)
|
|
39
|
+
*/
|
|
40
|
+
export declare function chatForCompleteOutput<T>(llmPort: SubsystemLLMPort, req: CompletionGuardRequest, parse: (text: string) => T | null): Promise<CompletionGuardResult<T>>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM 输出完整性保障 —— maxTokens 只是发给 provider 的生成配额,不是业务截断边界。
|
|
3
|
+
*
|
|
4
|
+
* 语义(2026-10-30 拍板):`finish=length`(配额截断)或 parse 失败的输出都**不得**当业务
|
|
5
|
+
* 结果收下(禁止静默半截结果);先放大配额重试一次,仍失败则返回显式失败原因,由调用方
|
|
6
|
+
* 决定如何上报。业务完整性优先于调用成本。
|
|
7
|
+
*
|
|
8
|
+
* @module harness/collaboration/autonomous-subsystem/think/completion-guard
|
|
9
|
+
*/
|
|
10
|
+
/** 重试放大配额的硬上限(防 provider 400;超过此值仍截断按显式失败处理) */
|
|
11
|
+
const RETRY_MAX_TOKENS_CAP = 32768;
|
|
12
|
+
/**
|
|
13
|
+
* 带输出完整性保障的单轮 LLM 调用:截断或解析失败时放大配额重试一次。
|
|
14
|
+
*
|
|
15
|
+
* @param llmPort - subsystem LLM 端口
|
|
16
|
+
* @param req - systemPrompt / messages / maxTokens(生成配额,非业务截断)
|
|
17
|
+
* @param parse - 从 LLM 文本解析业务结构;失败返回 null
|
|
18
|
+
* @returns 成功返回 parsed;失败返回 llm_error / truncated_output / parse_failed(至多 2 次 LLM 调用)
|
|
19
|
+
*/
|
|
20
|
+
export async function chatForCompleteOutput(llmPort, req, parse) {
|
|
21
|
+
let lastFailure = 'parse_failed';
|
|
22
|
+
let lastMessage = 'parse_failed';
|
|
23
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
24
|
+
const maxTokens = attempt === 0 ? req.maxTokens : Math.min(req.maxTokens * 2, RETRY_MAX_TOKENS_CAP);
|
|
25
|
+
let res;
|
|
26
|
+
try {
|
|
27
|
+
res = await llmPort.chat({
|
|
28
|
+
systemPrompt: req.systemPrompt,
|
|
29
|
+
messages: req.messages,
|
|
30
|
+
// 温度留空:由模型配置(ModelInfo.temperature)或服务端默认决定
|
|
31
|
+
maxTokens,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
return { ok: false, reason: 'llm_error', message: err instanceof Error ? err.message : String(err) };
|
|
36
|
+
}
|
|
37
|
+
if (res.finishReason === 'error') {
|
|
38
|
+
return { ok: false, reason: 'llm_error', message: res.content || 'llm chat error' };
|
|
39
|
+
}
|
|
40
|
+
// 配额截断:半截输出不是业务结果,放大配额重试
|
|
41
|
+
if (res.finishReason === 'length') {
|
|
42
|
+
lastFailure = 'truncated_output';
|
|
43
|
+
lastMessage = `truncated_output: completion hit maxTokens=${maxTokens}`;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const raw = res.content ?? '';
|
|
47
|
+
if (!raw.trim()) {
|
|
48
|
+
lastFailure = 'llm_empty';
|
|
49
|
+
lastMessage = 'llm_empty: empty completion content';
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const parsed = parse(raw);
|
|
53
|
+
if (parsed !== null)
|
|
54
|
+
return { ok: true, parsed, raw };
|
|
55
|
+
lastFailure = 'parse_failed';
|
|
56
|
+
lastMessage = 'parse_failed';
|
|
57
|
+
}
|
|
58
|
+
return { ok: false, reason: lastFailure, message: lastMessage };
|
|
59
|
+
}
|
|
@@ -121,7 +121,7 @@ export class ThinkExecutor {
|
|
|
121
121
|
if (event.type === 'assistant_message') {
|
|
122
122
|
lastContent = typeof event.message.content === 'string' ? event.message.content : '';
|
|
123
123
|
}
|
|
124
|
-
if (event.type === '
|
|
124
|
+
if (event.type === 'step_end' && event.usage) {
|
|
125
125
|
const u = event.usage;
|
|
126
126
|
tokenUsage = {
|
|
127
127
|
prompt: u.inputReportedTokens ??
|
|
@@ -4,3 +4,5 @@ export { ModelResolver, resolveProviderInstance } from './model-resolver.js';
|
|
|
4
4
|
export type { ModelResolverConfig, ResolvedModel, ResolvedModelWithFallback } from './model-resolver.js';
|
|
5
5
|
export { createSubsystemLLMPort, shouldFallbackModel, DEP_LLM_PORT, DEP_SUBSYSTEM_PROMPT, DEP_RESOLVED_MODEL, DEP_RESOLVED_MODELS, } from './llm-port.js';
|
|
6
6
|
export type { SubsystemLLMPort, SubsystemLLMPortChatRequest, CreateSubsystemLLMPortOptions, } from './llm-port.js';
|
|
7
|
+
export { chatForCompleteOutput } from './completion-guard.js';
|
|
8
|
+
export type { CompletionGuardFailure, CompletionGuardRequest, CompletionGuardResult, } from './completion-guard.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { ThinkExecutor } from './executor.js';
|
|
2
2
|
export { ModelResolver, resolveProviderInstance } from './model-resolver.js';
|
|
3
3
|
export { createSubsystemLLMPort, shouldFallbackModel, DEP_LLM_PORT, DEP_SUBSYSTEM_PROMPT, DEP_RESOLVED_MODEL, DEP_RESOLVED_MODELS, } from './llm-port.js';
|
|
4
|
+
export { chatForCompleteOutput } from './completion-guard.js';
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* @module autonomous-subsystem/think/model-resolver
|
|
14
14
|
*/
|
|
15
|
-
/** 产品约定的级别名(init/example/docs
|
|
15
|
+
/** 产品约定的级别名(init/example/docs 均定义 mini/standard/pro;summary 为保留别名——历史上曾是摘要档,保留只为把误写的档位名 fail-loud,而不是当模型名发给 provider) */
|
|
16
16
|
const WELLKNOWN_LEVEL_ALIASES = new Set(['summary', 'mini', 'standard', 'pro']);
|
|
17
17
|
/**
|
|
18
18
|
* 按解析结果选择 provider 实例
|
|
@@ -75,10 +75,15 @@ export type ContextField = 'task_summary' | 'tool_calls' | 'tool_results' | 'wor
|
|
|
75
75
|
export interface SenseFilter {
|
|
76
76
|
/** 监听的事件类型(source=eventBus 时) */
|
|
77
77
|
events?: string[];
|
|
78
|
-
/** 声明式条件表达式(如 "
|
|
78
|
+
/** 声明式条件表达式(如 "step.count % 10 === 0") */
|
|
79
79
|
condition?: string;
|
|
80
80
|
/** 代码引用(如 "./handler.ts:shouldExtract"),与 condition 互斥 */
|
|
81
81
|
conditionRef?: string;
|
|
82
|
+
/**
|
|
83
|
+
* 事件累积触发阈值:每收到一个匹配事件计数 +1,累计达到阈值才评估/触发,
|
|
84
|
+
* 触发后清零(缺省 1 = 来一件发一件)。用于「增量 N 条才跑一次」的节流。
|
|
85
|
+
*/
|
|
86
|
+
minEvents?: number;
|
|
82
87
|
/** 该子系统可能产生的事件类型(用于静态循环检测,LLM 子系统建议声明 ['*']) */
|
|
83
88
|
emits?: string[];
|
|
84
89
|
}
|
|
@@ -90,6 +95,10 @@ export interface SenseConfig {
|
|
|
90
95
|
filter?: SenseFilter;
|
|
91
96
|
/** schedule 模式:轮询间隔(毫秒) */
|
|
92
97
|
interval?: number;
|
|
98
|
+
/** schedule 模式:注册后立即补一次首跳(长 interval 跨不过进程生命周期时的保底脉搏) */
|
|
99
|
+
runOnStart?: boolean;
|
|
100
|
+
/** 本子系统的触发冷却(毫秒);缺省用 SenseEngine 全局 defaultCooldownMs */
|
|
101
|
+
cooldownMs?: number;
|
|
93
102
|
isolation: IsolationLevel;
|
|
94
103
|
/** isolation=partial 时,可见的字段列表 */
|
|
95
104
|
fields?: ContextField[];
|
|
@@ -121,7 +130,7 @@ export interface ThinkConfig {
|
|
|
121
130
|
/** 模型级别引用(如 "mini"、"standard"、"pro")或 provider/model 格式 */
|
|
122
131
|
model?: string;
|
|
123
132
|
/** 最大推理轮次(默认 1) */
|
|
124
|
-
|
|
133
|
+
maxSteps?: number;
|
|
125
134
|
/** hybrid 模式的预处理函数 */
|
|
126
135
|
preProcess?: (input: SubsystemInput) => Promise<SubsystemInput>;
|
|
127
136
|
/** hybrid 模式的后处理函数 */
|
|
@@ -297,7 +306,7 @@ export interface SubsystemInput {
|
|
|
297
306
|
sessionMetadata?: {
|
|
298
307
|
agentId: string;
|
|
299
308
|
sessionId: string;
|
|
300
|
-
|
|
309
|
+
stepCount: number;
|
|
301
310
|
} & Record<string, unknown>;
|
|
302
311
|
/** Token 使用量 */
|
|
303
312
|
tokenCount?: {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* 本端口管"目标本地怎么起 Run"。两者不可互相渗透。
|
|
19
19
|
*/
|
|
20
20
|
import type { SessionStore } from '@octopi-agent/core/interfaces/session-store.js';
|
|
21
|
-
import type { TokenUsage } from '@octopi-agent/core/types/
|
|
21
|
+
import type { TokenUsage } from '@octopi-agent/core/types/step.js';
|
|
22
22
|
import type { AgentEvent } from '@octopi-agent/core/primitives/event-bus.js';
|
|
23
23
|
import type { SessionData, SessionSpawnLink } from '../../session/types.js';
|
|
24
24
|
import type { DelegationBudget, DelegationContextMode } from './types.js';
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
* transport 管"怎么把请求送到目标"(进程内 / 将来跨进程);
|
|
18
18
|
* 本端口管"目标本地怎么起 Run"。两者不可互相渗透。
|
|
19
19
|
*/
|
|
20
|
-
import { emptyTokenUsage } from '@octopi-agent/core/types/
|
|
20
|
+
import { emptyTokenUsage } from '@octopi-agent/core/types/step.js';
|
|
21
21
|
/**
|
|
22
|
-
* 累加
|
|
22
|
+
* 累加 step 级 usage 到总账(决策 C2:归集到父的 run 账)
|
|
23
23
|
*
|
|
24
24
|
* @param total - 累计账本(原地更新)
|
|
25
25
|
* @param add - 本轮 usage
|
|
@@ -92,7 +92,7 @@ export class RunnerChildRunPort {
|
|
|
92
92
|
try {
|
|
93
93
|
for await (const event of target.runner.handle(childSessionId, userMessage, runConfig, signal)) {
|
|
94
94
|
switch (event.type) {
|
|
95
|
-
case '
|
|
95
|
+
case 'step.end': {
|
|
96
96
|
const data = event.data;
|
|
97
97
|
// 失败尝试的 content 是中断残句,不是委派结果;error 布尔标记也不是错误文本
|
|
98
98
|
//(String(true)='true' 会占位并挡住后面 engine.error 的真消息)
|
|
@@ -160,7 +160,7 @@ export class RunnerChildRunPort {
|
|
|
160
160
|
status: 'idle',
|
|
161
161
|
},
|
|
162
162
|
messages: [],
|
|
163
|
-
|
|
163
|
+
steps: [],
|
|
164
164
|
metadata: { delegationId: input.delegationId },
|
|
165
165
|
};
|
|
166
166
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* + `AgentHandle`(D2 寻址)+ `DelegateTransport`(唯一分布式缝)。
|
|
9
9
|
*/
|
|
10
10
|
export type { Delegation, DelegationBudget, DelegationContextMode, DelegationEventType, DelegationParentRef, DelegationStatus, DelegationTarget, DelegateRequest, DelegateResult, AgentHandle, } from './types.js';
|
|
11
|
-
export { DELEGATION_SCHEMA_VERSION, DELEGATION_TERMINAL_STATUSES, DELEGATION_ACTIVE_STATUSES, DelegationEvents, isTerminalDelegationStatus, isActiveDelegationStatus, } from './types.js';
|
|
11
|
+
export { DELEGATION_SCHEMA_VERSION, DEFAULT_DELEGATION_OUTPUT_CHARS, normalizeMaxOutputChars, DELEGATION_TERMINAL_STATUSES, DELEGATION_ACTIVE_STATUSES, DelegationEvents, isTerminalDelegationStatus, isActiveDelegationStatus, } from './types.js';
|
|
12
12
|
export type { AgentRegistry, AgentInfo, AgentQuery, AgentRelation, AgentRelationType, AgentDelegationPolicy, } from './registry-types.js';
|
|
13
13
|
export { AgentRegistryEvents } from './registry-types.js';
|
|
14
14
|
export { DefaultAgentRegistry } from './registry.js';
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* L2 委派契约层:`DelegateRequest` / `DelegateResult`(纯 JSON,D1/D5)
|
|
8
8
|
* + `AgentHandle`(D2 寻址)+ `DelegateTransport`(唯一分布式缝)。
|
|
9
9
|
*/
|
|
10
|
-
export { DELEGATION_SCHEMA_VERSION, DELEGATION_TERMINAL_STATUSES, DELEGATION_ACTIVE_STATUSES, DelegationEvents, isTerminalDelegationStatus, isActiveDelegationStatus, } from './types.js';
|
|
10
|
+
export { DELEGATION_SCHEMA_VERSION, DEFAULT_DELEGATION_OUTPUT_CHARS, normalizeMaxOutputChars, DELEGATION_TERMINAL_STATUSES, DELEGATION_ACTIVE_STATUSES, DelegationEvents, isTerminalDelegationStatus, isActiveDelegationStatus, } from './types.js';
|
|
11
11
|
export { AgentRegistryEvents } from './registry-types.js';
|
|
12
12
|
// ── Registry 实现 ──
|
|
13
13
|
export { DefaultAgentRegistry } from './registry.js';
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* 禁止在调用链上 await(`arch/agent-runtime.md` 重入策略)。
|
|
15
15
|
*/
|
|
16
16
|
import type { EventBus } from '@octopi-agent/core/primitives/event-bus.js';
|
|
17
|
-
import type
|
|
17
|
+
import { type Delegation } from './types.js';
|
|
18
18
|
import type { DelegationNotifier } from './service.js';
|
|
19
19
|
/** notify 投递器配置 */
|
|
20
20
|
export interface DelegationNotifierConfig {
|
|
@@ -26,6 +26,11 @@ export interface DelegationNotifierConfig {
|
|
|
26
26
|
/**
|
|
27
27
|
* 渲染委派终态通知(§7.1:`<delegation_completed …/>`)
|
|
28
28
|
*
|
|
29
|
+
* `<output>` 截断上限按委派单 `maxOutputChars`(缺省 {@link DEFAULT_DELEGATION_OUTPUT_CHARS})——
|
|
30
|
+
* 只影响自动送达的 notice;`delegate_get` 全文取回不受此限。上限计量**原始 output 字符**
|
|
31
|
+
* (截断补 `…`,实体最多 max+1 字符);escapeText 后投递文本可因转义膨胀(最坏 5×,
|
|
32
|
+
* 上限约束内容量不约束投递字节——2026-11-09 评审 m5 记债)。
|
|
33
|
+
*
|
|
29
34
|
* @param delegation - 终态委派单
|
|
30
35
|
* @returns 通知文本
|
|
31
36
|
*/
|
|
@@ -13,10 +13,16 @@
|
|
|
13
13
|
* 不打断父 Run:同 session 运行中再来 Trigger 由 Runner FIFO 锁排队,
|
|
14
14
|
* 禁止在调用链上 await(`arch/agent-runtime.md` 重入策略)。
|
|
15
15
|
*/
|
|
16
|
+
import { DEFAULT_DELEGATION_OUTPUT_CHARS } from './types.js';
|
|
16
17
|
import { emitAgentSignal, hasAgentSignalReceiver, } from '../../activation/sources/agent-signal.js';
|
|
17
18
|
/**
|
|
18
19
|
* 渲染委派终态通知(§7.1:`<delegation_completed …/>`)
|
|
19
20
|
*
|
|
21
|
+
* `<output>` 截断上限按委派单 `maxOutputChars`(缺省 {@link DEFAULT_DELEGATION_OUTPUT_CHARS})——
|
|
22
|
+
* 只影响自动送达的 notice;`delegate_get` 全文取回不受此限。上限计量**原始 output 字符**
|
|
23
|
+
* (截断补 `…`,实体最多 max+1 字符);escapeText 后投递文本可因转义膨胀(最坏 5×,
|
|
24
|
+
* 上限约束内容量不约束投递字节——2026-11-09 评审 m5 记债)。
|
|
25
|
+
*
|
|
20
26
|
* @param delegation - 终态委派单
|
|
21
27
|
* @returns 通知文本
|
|
22
28
|
*/
|
|
@@ -31,7 +37,8 @@ export function renderDelegationNotice(delegation) {
|
|
|
31
37
|
];
|
|
32
38
|
const body = [];
|
|
33
39
|
if (delegation.output) {
|
|
34
|
-
|
|
40
|
+
const maxOutputChars = delegation.maxOutputChars ?? DEFAULT_DELEGATION_OUTPUT_CHARS;
|
|
41
|
+
body.push(`<output>${escapeText(truncate(delegation.output, maxOutputChars))}</output>`);
|
|
35
42
|
}
|
|
36
43
|
if (delegation.error) {
|
|
37
44
|
body.push(`<error>${escapeText(truncate(delegation.error, 1000))}</error>`);
|
|
@@ -40,6 +40,8 @@ export interface DispatchDelegationInput {
|
|
|
40
40
|
parentRights?: import('../../governance/session-acl/types.js').SessionRights;
|
|
41
41
|
task: string;
|
|
42
42
|
input: string;
|
|
43
|
+
/** 自动返回通知 `<output>` 截断上限(chars);缺省 = DEFAULT_DELEGATION_OUTPUT_CHARS(B 方案 2026-11-09) */
|
|
44
|
+
maxOutputChars?: number;
|
|
43
45
|
context?: DelegationContextMode;
|
|
44
46
|
/** 父消息历史(仅 context='fork' 时携带) */
|
|
45
47
|
parentMessages?: import('@octopi-agent/core/types.js').Message[];
|
|
@@ -66,7 +66,7 @@ export function intersectBudget(requested, ceiling) {
|
|
|
66
66
|
return Math.min(a, b);
|
|
67
67
|
};
|
|
68
68
|
return {
|
|
69
|
-
|
|
69
|
+
maxSteps: pick(requested?.maxSteps, ceiling?.maxSteps),
|
|
70
70
|
maxTokens: pick(requested?.maxTokens, ceiling?.maxTokens),
|
|
71
71
|
timeoutMs: pick(requested?.timeoutMs, ceiling?.timeoutMs),
|
|
72
72
|
};
|
|
@@ -129,6 +129,7 @@ export class DelegateService {
|
|
|
129
129
|
target: input.target,
|
|
130
130
|
task: input.task,
|
|
131
131
|
input: input.input,
|
|
132
|
+
maxOutputChars: input.maxOutputChars,
|
|
132
133
|
context: input.context,
|
|
133
134
|
budget,
|
|
134
135
|
deadlineAt,
|
|
@@ -24,6 +24,8 @@ export interface CreateDelegationInput {
|
|
|
24
24
|
target: DelegationTarget;
|
|
25
25
|
task: string;
|
|
26
26
|
input: string;
|
|
27
|
+
/** 自动返回通知 `<output>` 截断上限(chars);缺省 = DEFAULT_DELEGATION_OUTPUT_CHARS */
|
|
28
|
+
maxOutputChars?: number;
|
|
27
29
|
context?: DelegationContextMode;
|
|
28
30
|
budget?: DelegationBudget;
|
|
29
31
|
/** 绝对截止时刻(D4);由 budget.timeoutMs 换算或调用方直接给 */
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* 但接口形状按可持久化设计(`Delegation` 全字段可序列化,D1/D5)。
|
|
18
18
|
*/
|
|
19
19
|
import { randomUUID } from 'node:crypto';
|
|
20
|
-
import { DELEGATION_SCHEMA_VERSION, DelegationEvents, isTerminalDelegationStatus, } from './types.js';
|
|
20
|
+
import { DELEGATION_SCHEMA_VERSION, DelegationEvents, isTerminalDelegationStatus, normalizeMaxOutputChars, } from './types.js';
|
|
21
21
|
function now() {
|
|
22
22
|
return Date.now();
|
|
23
23
|
}
|
|
@@ -68,6 +68,7 @@ export class DelegationStore {
|
|
|
68
68
|
target: { ...input.target },
|
|
69
69
|
task: input.task,
|
|
70
70
|
input: input.input,
|
|
71
|
+
maxOutputChars: normalizeMaxOutputChars(input.maxOutputChars),
|
|
71
72
|
context: input.context ?? 'clean',
|
|
72
73
|
status: 'queued',
|
|
73
74
|
depth: input.depth ?? 1,
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* 因此本文件的**所有**类型必须可 `JSON.stringify` 无损往返;
|
|
13
13
|
* 不得出现 `AbortSignal` / `Agent` 实例 / 函数 / class 实例等非序列化值。
|
|
14
14
|
*/
|
|
15
|
-
import type { TokenUsage } from '@octopi-agent/core/types/
|
|
15
|
+
import type { TokenUsage } from '@octopi-agent/core/types/step.js';
|
|
16
16
|
import type { SessionRights } from '../../governance/session-acl/types.js';
|
|
17
17
|
/**
|
|
18
18
|
* 委派消息 schema 版本(D1/⑤:跨进程契约必须版本化)。
|
|
@@ -59,7 +59,7 @@ export interface DelegationTarget {
|
|
|
59
59
|
*/
|
|
60
60
|
export interface DelegationBudget {
|
|
61
61
|
/** 子 Run 最大轮次 */
|
|
62
|
-
|
|
62
|
+
maxSteps?: number;
|
|
63
63
|
/** 子 Run 最大 token */
|
|
64
64
|
maxTokens?: number;
|
|
65
65
|
/** 委派超时(毫秒);换算为 deadlineAt */
|
|
@@ -75,6 +75,21 @@ export interface DelegationParentRef {
|
|
|
75
75
|
}
|
|
76
76
|
/** 结果送达父的状态机(§7.1 送达语义) */
|
|
77
77
|
export type DelegationDeliveryState = 'pending' | 'delivering' | 'surfaced';
|
|
78
|
+
/** 自动返回通知(`<delegation_result>`)`<output>` 默认截断上限(chars)。
|
|
79
|
+
* B 方案(2026-11-09 拍板):默认 16k,可按委派 `max_output_chars` 覆盖;
|
|
80
|
+
* 只影响自动送达 notice,`delegate_get` 全文取回不受此限。 */
|
|
81
|
+
export declare const DEFAULT_DELEGATION_OUTPUT_CHARS = 16000;
|
|
82
|
+
/**
|
|
83
|
+
* 校验/归一化自动返回截断上限(单源;`DelegationStore.create` 唯一写入口消费)。
|
|
84
|
+
*
|
|
85
|
+
* fail loud:非法值(非有限数 / 非正整数)直接抛错,不静默丢结果也不静默禁用截断
|
|
86
|
+
* (NaN 会产出空 `<output>`、负数丢尾部、Infinity 关闭截断——2026-11-09 评审 M2 实测)。
|
|
87
|
+
*
|
|
88
|
+
* @param value - 待校验上限(chars);undefined = 未指定(渲染侧回落默认)
|
|
89
|
+
* @returns 归一化后的上限(undefined = 未指定)
|
|
90
|
+
* @throws 非有限数、非正整数
|
|
91
|
+
*/
|
|
92
|
+
export declare function normalizeMaxOutputChars(value: number | undefined): number | undefined;
|
|
78
93
|
/**
|
|
79
94
|
* 委派单 —— 一次委派的全程记录
|
|
80
95
|
*
|
|
@@ -100,6 +115,12 @@ export interface Delegation {
|
|
|
100
115
|
childRunId?: string;
|
|
101
116
|
/** 子的最后一轮 assistant 文本 = 结论(D5) */
|
|
102
117
|
output?: string;
|
|
118
|
+
/**
|
|
119
|
+
* 自动返回通知(`<delegation_result>`)中 `<output>` 的截断上限(chars)。
|
|
120
|
+
* 只影响 notify 自动送达;`delegate_get` 全文取回不受此限。
|
|
121
|
+
* 缺省 = {@link DEFAULT_DELEGATION_OUTPUT_CHARS}(B 方案 2026-11-09)。
|
|
122
|
+
*/
|
|
123
|
+
maxOutputChars?: number;
|
|
103
124
|
/** 子产出的文件路径(D5/D6:不共享文件系统,显式声明) */
|
|
104
125
|
artifacts?: string[];
|
|
105
126
|
/** 子 Run 的 token 消耗(归集到父的 run 账,决策 C2) */
|
|
@@ -45,6 +45,28 @@ export const DELEGATION_ACTIVE_STATUSES = ['queued', 'running'];
|
|
|
45
45
|
export function isActiveDelegationStatus(status) {
|
|
46
46
|
return DELEGATION_ACTIVE_STATUSES.includes(status);
|
|
47
47
|
}
|
|
48
|
+
/** 自动返回通知(`<delegation_result>`)`<output>` 默认截断上限(chars)。
|
|
49
|
+
* B 方案(2026-11-09 拍板):默认 16k,可按委派 `max_output_chars` 覆盖;
|
|
50
|
+
* 只影响自动送达 notice,`delegate_get` 全文取回不受此限。 */
|
|
51
|
+
export const DEFAULT_DELEGATION_OUTPUT_CHARS = 16_000;
|
|
52
|
+
/**
|
|
53
|
+
* 校验/归一化自动返回截断上限(单源;`DelegationStore.create` 唯一写入口消费)。
|
|
54
|
+
*
|
|
55
|
+
* fail loud:非法值(非有限数 / 非正整数)直接抛错,不静默丢结果也不静默禁用截断
|
|
56
|
+
* (NaN 会产出空 `<output>`、负数丢尾部、Infinity 关闭截断——2026-11-09 评审 M2 实测)。
|
|
57
|
+
*
|
|
58
|
+
* @param value - 待校验上限(chars);undefined = 未指定(渲染侧回落默认)
|
|
59
|
+
* @returns 归一化后的上限(undefined = 未指定)
|
|
60
|
+
* @throws 非有限数、非正整数
|
|
61
|
+
*/
|
|
62
|
+
export function normalizeMaxOutputChars(value) {
|
|
63
|
+
if (value === undefined)
|
|
64
|
+
return undefined;
|
|
65
|
+
if (!Number.isFinite(value) || !Number.isInteger(value) || value <= 0) {
|
|
66
|
+
throw new Error(`maxOutputChars must be a positive integer (got ${value})`);
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
48
70
|
// ── 事件(§7) ──
|
|
49
71
|
/**
|
|
50
72
|
* 委派事件常量。
|
|
@@ -118,8 +118,18 @@ export function createDelegationRuntime(options) {
|
|
|
118
118
|
if (!sessionId)
|
|
119
119
|
return [];
|
|
120
120
|
const hint = service.renderStatusHint(sessionId);
|
|
121
|
+
// B0/引擎提示范式:engineHint 载体(user 形态),不进 provider system 字段——
|
|
122
|
+
// role:'system' 会被适配层拼进 system 前缀,状态翻转即整段重买(§1 烧缓存实锤)。
|
|
121
123
|
return hint
|
|
122
|
-
? [
|
|
124
|
+
? [
|
|
125
|
+
{
|
|
126
|
+
role: 'user',
|
|
127
|
+
content: hint,
|
|
128
|
+
timestamp: Date.now(),
|
|
129
|
+
ephemeral: true,
|
|
130
|
+
metadata: { source: 'engineHint' },
|
|
131
|
+
},
|
|
132
|
+
]
|
|
123
133
|
: [];
|
|
124
134
|
});
|
|
125
135
|
}
|
|
@@ -1,41 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* DefaultBudgetAllocator —
|
|
2
|
+
* DefaultBudgetAllocator — 不变量驱动的预算分配
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* - 系统提示词
|
|
6
|
-
* - 工具定义
|
|
7
|
-
* - 消息历史
|
|
8
|
-
* - 模型输出预留
|
|
4
|
+
* 唯一硬不变量(provider 侧事实):
|
|
9
5
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
6
|
+
* input_tokens + max_tokens ≤ contextWindow
|
|
7
|
+
*
|
|
8
|
+
* 因此分配顺序是「先扣输出,再扣固定开销,剩下的才是消息」:
|
|
9
|
+
*
|
|
10
|
+
* outputReserve = maxOutputTokens(模型能力上限;未知时比例回退)
|
|
11
|
+
* inputLimit = effectiveLimit − outputReserve ← 硬
|
|
12
|
+
* messagesLimit = inputLimit − system − tools − 信封 ← 硬(强制点用它)
|
|
13
|
+
* messagesBudget= messagesLimit ← 软(压缩策略提示)
|
|
14
|
+
*
|
|
15
|
+
* 历史实现的缺陷(本次修正):`outputReserve = clamp(window × 20%, 2k, 8k)`
|
|
16
|
+
* 与请求真实的 `max_tokens` 完全脱节——mimo-v2.6-pro(窗口 1,048,576 /
|
|
17
|
+
* maxTokens 131,072)会算出 1,040,076 的输入上限,加上 131,072 输出共
|
|
18
|
+
* 1,171,148,超出窗口 122,572,且无任何环节察觉。
|
|
14
19
|
*/
|
|
15
20
|
import type { BudgetAllocator, BudgetAllocateParams, BudgetAllocateResult } from './types.js';
|
|
16
21
|
export declare class DefaultBudgetAllocator implements BudgetAllocator {
|
|
17
22
|
private outputRatio;
|
|
18
23
|
private minOutputReserve;
|
|
19
24
|
private maxOutputReserve;
|
|
20
|
-
private
|
|
25
|
+
private requestEnvelopeTokens;
|
|
21
26
|
constructor(options?: {
|
|
22
27
|
outputRatio?: number;
|
|
23
28
|
minOutputReserve?: number;
|
|
24
29
|
maxOutputReserve?: number;
|
|
25
|
-
|
|
30
|
+
requestEnvelopeTokens?: number;
|
|
26
31
|
});
|
|
27
32
|
/**
|
|
28
33
|
* 分配 token 预算
|
|
29
34
|
*
|
|
30
|
-
* @param params -
|
|
31
|
-
* @returns
|
|
35
|
+
* @param params - 分配参数(窗口、模型输出上限、固定开销)
|
|
36
|
+
* @returns 硬上限(inputLimit / messagesLimit)、软目标(messagesBudget)与输出预留
|
|
32
37
|
*/
|
|
33
38
|
allocate(params: BudgetAllocateParams): BudgetAllocateResult;
|
|
34
39
|
/**
|
|
35
|
-
*
|
|
40
|
+
* 解析输出预留
|
|
41
|
+
*
|
|
42
|
+
* 有模型输出上限时按**硬预留**(不变量要求,不得打折);缺失时按窗口比例回退。
|
|
36
43
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
44
|
+
* @param effectiveLimit - 实际可用上限
|
|
45
|
+
* @param maxOutputTokens - 模型单次输出上限(可选)
|
|
46
|
+
* @returns 输出预留 token 数
|
|
39
47
|
*/
|
|
40
|
-
private
|
|
48
|
+
private resolveOutputReserve;
|
|
41
49
|
}
|