@namzu/sdk 0.1.3 → 0.1.4-rc.2
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/CHANGELOG.md +45 -29
- package/README.md +14 -2
- package/dist/advisory/context.d.ts +23 -0
- package/dist/advisory/context.d.ts.map +1 -0
- package/dist/advisory/context.js +33 -0
- package/dist/advisory/context.js.map +1 -0
- package/dist/advisory/evaluator.d.ts +14 -0
- package/dist/advisory/evaluator.d.ts.map +1 -0
- package/dist/advisory/evaluator.js +87 -0
- package/dist/advisory/evaluator.js.map +1 -0
- package/dist/advisory/executor.d.ts +40 -0
- package/dist/advisory/executor.d.ts.map +1 -0
- package/dist/advisory/executor.js +132 -0
- package/dist/advisory/executor.js.map +1 -0
- package/dist/advisory/index.d.ts +6 -0
- package/dist/advisory/index.d.ts.map +1 -0
- package/dist/advisory/index.js +5 -0
- package/dist/advisory/index.js.map +1 -0
- package/dist/advisory/registry.d.ts +14 -0
- package/dist/advisory/registry.d.ts.map +1 -0
- package/dist/advisory/registry.js +36 -0
- package/dist/advisory/registry.js.map +1 -0
- package/dist/agents/ReactiveAgent.d.ts.map +1 -1
- package/dist/agents/ReactiveAgent.js +1 -0
- package/dist/agents/ReactiveAgent.js.map +1 -1
- package/dist/agents/SupervisorAgent.d.ts.map +1 -1
- package/dist/agents/SupervisorAgent.js +12 -1
- package/dist/agents/SupervisorAgent.js.map +1 -1
- package/dist/bridge/a2a/mapper.d.ts.map +1 -1
- package/dist/bridge/a2a/mapper.js +2 -0
- package/dist/bridge/a2a/mapper.js.map +1 -1
- package/dist/bridge/sse/mapper.d.ts.map +1 -1
- package/dist/bridge/sse/mapper.js +17 -0
- package/dist/bridge/sse/mapper.js.map +1 -1
- package/dist/bus/breaker.d.ts +18 -0
- package/dist/bus/breaker.d.ts.map +1 -0
- package/dist/bus/breaker.js +158 -0
- package/dist/bus/breaker.js.map +1 -0
- package/dist/bus/index.d.ts +33 -0
- package/dist/bus/index.d.ts.map +1 -0
- package/dist/bus/index.js +72 -0
- package/dist/bus/index.js.map +1 -0
- package/dist/bus/lock.d.ts +27 -0
- package/dist/bus/lock.d.ts.map +1 -0
- package/dist/bus/lock.js +194 -0
- package/dist/bus/lock.js.map +1 -0
- package/dist/bus/ownership.d.ts +18 -0
- package/dist/bus/ownership.d.ts.map +1 -0
- package/dist/bus/ownership.js +111 -0
- package/dist/bus/ownership.js.map +1 -0
- package/dist/compaction/extractor.d.ts +7 -0
- package/dist/compaction/extractor.d.ts.map +1 -0
- package/dist/compaction/extractor.js +131 -0
- package/dist/compaction/extractor.js.map +1 -0
- package/dist/compaction/index.d.ts +6 -0
- package/dist/compaction/index.d.ts.map +1 -0
- package/dist/compaction/index.js +5 -0
- package/dist/compaction/index.js.map +1 -0
- package/dist/compaction/manager.d.ts +22 -0
- package/dist/compaction/manager.d.ts.map +1 -0
- package/dist/compaction/manager.js +91 -0
- package/dist/compaction/manager.js.map +1 -0
- package/dist/compaction/serializer.d.ts +3 -0
- package/dist/compaction/serializer.d.ts.map +1 -0
- package/dist/compaction/serializer.js +67 -0
- package/dist/compaction/serializer.js.map +1 -0
- package/dist/compaction/types.d.ts +40 -0
- package/dist/compaction/types.d.ts.map +1 -0
- package/dist/compaction/types.js +2 -0
- package/dist/compaction/types.js.map +1 -0
- package/dist/compaction/verifier.d.ts +6 -0
- package/dist/compaction/verifier.d.ts.map +1 -0
- package/dist/compaction/verifier.js +68 -0
- package/dist/compaction/verifier.js.map +1 -0
- package/dist/config/runtime.d.ts +328 -0
- package/dist/config/runtime.d.ts.map +1 -1
- package/dist/config/runtime.js +51 -0
- package/dist/config/runtime.js.map +1 -1
- package/dist/constants/advisory/index.d.ts +8 -0
- package/dist/constants/advisory/index.d.ts.map +1 -0
- package/dist/constants/advisory/index.js +8 -0
- package/dist/constants/advisory/index.js.map +1 -0
- package/dist/constants/bus/index.d.ts +7 -0
- package/dist/constants/bus/index.d.ts.map +1 -0
- package/dist/constants/bus/index.js +7 -0
- package/dist/constants/bus/index.js.map +1 -0
- package/dist/constants/compaction/index.d.ts +17 -0
- package/dist/constants/compaction/index.d.ts.map +1 -0
- package/dist/constants/compaction/index.js +17 -0
- package/dist/constants/compaction/index.js.map +1 -0
- package/dist/constants/emergency.d.ts +4 -0
- package/dist/constants/emergency.d.ts.map +1 -0
- package/dist/constants/emergency.js +4 -0
- package/dist/constants/emergency.js.map +1 -0
- package/dist/constants/index.d.ts +6 -0
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +6 -0
- package/dist/constants/index.js.map +1 -1
- package/dist/constants/limits.d.ts +1 -0
- package/dist/constants/limits.d.ts.map +1 -1
- package/dist/constants/limits.js +1 -0
- package/dist/constants/limits.js.map +1 -1
- package/dist/constants/plugin/index.d.ts +21 -0
- package/dist/constants/plugin/index.d.ts.map +1 -0
- package/dist/constants/plugin/index.js +21 -0
- package/dist/constants/plugin/index.js.map +1 -0
- package/dist/constants/verification/index.d.ts +2 -0
- package/dist/constants/verification/index.d.ts.map +1 -0
- package/dist/constants/verification/index.js +2 -0
- package/dist/constants/verification/index.js.map +1 -0
- package/dist/contracts/api.d.ts +1 -1
- package/dist/contracts/api.d.ts.map +1 -1
- package/dist/contracts/schemas.d.ts +20 -20
- package/dist/index.d.ts +24 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -1
- package/dist/manager/run/emergency.d.ts +19 -0
- package/dist/manager/run/emergency.d.ts.map +1 -0
- package/dist/manager/run/emergency.js +88 -0
- package/dist/manager/run/emergency.js.map +1 -0
- package/dist/manager/run/persistence.d.ts +2 -0
- package/dist/manager/run/persistence.d.ts.map +1 -1
- package/dist/manager/run/persistence.js +14 -0
- package/dist/manager/run/persistence.js.map +1 -1
- package/dist/persona/assembler.d.ts +2 -1
- package/dist/persona/assembler.d.ts.map +1 -1
- package/dist/persona/assembler.js +23 -0
- package/dist/persona/assembler.js.map +1 -1
- package/dist/plugin/index.d.ts +4 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +4 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/lifecycle.d.ts +30 -0
- package/dist/plugin/lifecycle.d.ts.map +1 -0
- package/dist/plugin/lifecycle.js +227 -0
- package/dist/plugin/lifecycle.js.map +1 -0
- package/dist/plugin/loader.d.ts +25 -0
- package/dist/plugin/loader.d.ts.map +1 -0
- package/dist/plugin/loader.js +76 -0
- package/dist/plugin/loader.js.map +1 -0
- package/dist/plugin/resolver.d.ts +36 -0
- package/dist/plugin/resolver.d.ts.map +1 -0
- package/dist/plugin/resolver.js +80 -0
- package/dist/plugin/resolver.js.map +1 -0
- package/dist/registry/plugin/index.d.ts +9 -0
- package/dist/registry/plugin/index.d.ts.map +1 -0
- package/dist/registry/plugin/index.js +16 -0
- package/dist/registry/plugin/index.js.map +1 -0
- package/dist/registry/tool/execute.d.ts +3 -0
- package/dist/registry/tool/execute.d.ts.map +1 -1
- package/dist/registry/tool/execute.js +45 -11
- package/dist/registry/tool/execute.js.map +1 -1
- package/dist/router/index.d.ts +2 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +2 -0
- package/dist/router/index.js.map +1 -0
- package/dist/router/task-router.d.ts +8 -0
- package/dist/router/task-router.d.ts.map +1 -0
- package/dist/router/task-router.js +19 -0
- package/dist/router/task-router.js.map +1 -0
- package/dist/run/reporter.d.ts.map +1 -1
- package/dist/run/reporter.js +15 -0
- package/dist/run/reporter.js.map +1 -1
- package/dist/runtime/query/context-cache.d.ts +6 -0
- package/dist/runtime/query/context-cache.d.ts.map +1 -1
- package/dist/runtime/query/context-cache.js +36 -0
- package/dist/runtime/query/context-cache.js.map +1 -1
- package/dist/runtime/query/executor.d.ts +4 -0
- package/dist/runtime/query/executor.d.ts.map +1 -1
- package/dist/runtime/query/executor.js +30 -1
- package/dist/runtime/query/executor.js.map +1 -1
- package/dist/runtime/query/index.d.ts +10 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +77 -12
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts +9 -0
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +40 -0
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/advisory.d.ts +4 -0
- package/dist/runtime/query/iteration/phases/advisory.d.ts.map +1 -0
- package/dist/runtime/query/iteration/phases/advisory.js +150 -0
- package/dist/runtime/query/iteration/phases/advisory.js.map +1 -0
- package/dist/runtime/query/iteration/phases/compaction.d.ts +3 -0
- package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -0
- package/dist/runtime/query/iteration/phases/compaction.js +87 -0
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -0
- package/dist/runtime/query/iteration/phases/context.d.ts +10 -0
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/runtime/query/iteration/phases/index.d.ts +2 -0
- package/dist/runtime/query/iteration/phases/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/index.js +2 -0
- package/dist/runtime/query/iteration/phases/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts +6 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +39 -0
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/prompt.d.ts +7 -0
- package/dist/runtime/query/prompt.d.ts.map +1 -1
- package/dist/runtime/query/prompt.js +44 -0
- package/dist/runtime/query/prompt.js.map +1 -1
- package/dist/store/memory/disk.d.ts +30 -0
- package/dist/store/memory/disk.d.ts.map +1 -0
- package/dist/store/memory/disk.js +154 -0
- package/dist/store/memory/disk.js.map +1 -0
- package/dist/store/memory/index.d.ts +13 -0
- package/dist/store/memory/index.d.ts.map +1 -0
- package/dist/store/memory/index.js +46 -0
- package/dist/store/memory/index.js.map +1 -0
- package/dist/store/memory/memory.d.ts +17 -0
- package/dist/store/memory/memory.d.ts.map +1 -0
- package/dist/store/memory/memory.js +72 -0
- package/dist/store/memory/memory.js.map +1 -0
- package/dist/tools/advisory/index.d.ts +7 -0
- package/dist/tools/advisory/index.d.ts.map +1 -0
- package/dist/tools/advisory/index.js +125 -0
- package/dist/tools/advisory/index.js.map +1 -0
- package/dist/tools/defineTool.d.ts +1 -0
- package/dist/tools/defineTool.d.ts.map +1 -1
- package/dist/tools/defineTool.js +1 -0
- package/dist/tools/defineTool.js.map +1 -1
- package/dist/tools/memory/index.d.ts +7 -0
- package/dist/tools/memory/index.d.ts.map +1 -0
- package/dist/tools/memory/index.js +10 -0
- package/dist/tools/memory/index.js.map +1 -0
- package/dist/tools/memory/read.d.ts +4 -0
- package/dist/tools/memory/read.d.ts.map +1 -0
- package/dist/tools/memory/read.js +37 -0
- package/dist/tools/memory/read.js.map +1 -0
- package/dist/tools/memory/save.d.ts +4 -0
- package/dist/tools/memory/save.d.ts.map +1 -0
- package/dist/tools/memory/save.js +37 -0
- package/dist/tools/memory/save.js.map +1 -0
- package/dist/tools/memory/search.d.ts +4 -0
- package/dist/tools/memory/search.d.ts.map +1 -0
- package/dist/tools/memory/search.js +41 -0
- package/dist/tools/memory/search.js.map +1 -0
- package/dist/types/advisory/config.d.ts +33 -0
- package/dist/types/advisory/config.d.ts.map +1 -0
- package/dist/types/advisory/config.js +2 -0
- package/dist/types/advisory/config.js.map +1 -0
- package/dist/types/advisory/index.d.ts +4 -0
- package/dist/types/advisory/index.d.ts.map +1 -0
- package/dist/types/advisory/index.js +2 -0
- package/dist/types/advisory/index.js.map +1 -0
- package/dist/types/advisory/result.d.ts +35 -0
- package/dist/types/advisory/result.d.ts.map +1 -0
- package/dist/types/advisory/result.js +2 -0
- package/dist/types/advisory/result.js.map +1 -0
- package/dist/types/advisory/trigger.d.ts +44 -0
- package/dist/types/advisory/trigger.d.ts.map +1 -0
- package/dist/types/advisory/trigger.js +2 -0
- package/dist/types/advisory/trigger.js.map +1 -0
- package/dist/types/agent/factory.d.ts +2 -0
- package/dist/types/agent/factory.d.ts.map +1 -1
- package/dist/types/agent/reactive.d.ts +2 -0
- package/dist/types/agent/reactive.d.ts.map +1 -1
- package/dist/types/agent/supervisor.d.ts +4 -0
- package/dist/types/agent/supervisor.d.ts.map +1 -1
- package/dist/types/bus/index.d.ts +96 -0
- package/dist/types/bus/index.d.ts.map +1 -0
- package/dist/types/bus/index.js +2 -0
- package/dist/types/bus/index.js.map +1 -0
- package/dist/types/ids/index.d.ts +6 -0
- package/dist/types/ids/index.d.ts.map +1 -1
- package/dist/types/memory/index.d.ts +54 -0
- package/dist/types/memory/index.d.ts.map +1 -0
- package/dist/types/memory/index.js +12 -0
- package/dist/types/memory/index.js.map +1 -0
- package/dist/types/message/index.d.ts +3 -1
- package/dist/types/message/index.d.ts.map +1 -1
- package/dist/types/message/index.js +7 -2
- package/dist/types/message/index.js.map +1 -1
- package/dist/types/persona/index.d.ts +9 -0
- package/dist/types/persona/index.d.ts.map +1 -1
- package/dist/types/plugin/index.d.ts +186 -0
- package/dist/types/plugin/index.d.ts.map +1 -0
- package/dist/types/plugin/index.js +90 -0
- package/dist/types/plugin/index.js.map +1 -0
- package/dist/types/router/index.d.ts +2 -0
- package/dist/types/router/index.d.ts.map +1 -0
- package/dist/types/router/index.js +2 -0
- package/dist/types/router/index.js.map +1 -0
- package/dist/types/router/task-router.d.ts +12 -0
- package/dist/types/router/task-router.d.ts.map +1 -0
- package/dist/types/router/task-router.js +2 -0
- package/dist/types/router/task-router.js.map +1 -0
- package/dist/types/run/emergency.d.ts +27 -0
- package/dist/types/run/emergency.d.ts.map +1 -0
- package/dist/types/run/emergency.js +6 -0
- package/dist/types/run/emergency.js.map +1 -0
- package/dist/types/run/events.d.ts +13 -1
- package/dist/types/run/events.d.ts.map +1 -1
- package/dist/types/run/index.d.ts +1 -0
- package/dist/types/run/index.d.ts.map +1 -1
- package/dist/types/run/index.js +1 -0
- package/dist/types/run/index.js.map +1 -1
- package/dist/types/tool/index.d.ts +13 -0
- package/dist/types/tool/index.d.ts.map +1 -1
- package/dist/types/verification/index.d.ts +219 -0
- package/dist/types/verification/index.d.ts.map +1 -0
- package/dist/types/verification/index.js +43 -0
- package/dist/types/verification/index.js.map +1 -0
- package/dist/utils/id.d.ts +7 -1
- package/dist/utils/id.d.ts.map +1 -1
- package/dist/utils/id.js +18 -0
- package/dist/utils/id.js.map +1 -1
- package/dist/utils/shell-compress.d.ts +13 -0
- package/dist/utils/shell-compress.d.ts.map +1 -0
- package/dist/utils/shell-compress.js +97 -0
- package/dist/utils/shell-compress.js.map +1 -0
- package/dist/verification/gate.d.ts +19 -0
- package/dist/verification/gate.d.ts.map +1 -0
- package/dist/verification/gate.js +103 -0
- package/dist/verification/gate.js.map +1 -0
- package/dist/verification/index.d.ts +3 -0
- package/dist/verification/index.d.ts.map +1 -0
- package/dist/verification/index.js +3 -0
- package/dist/verification/index.js.map +1 -0
- package/dist/verification/rules.d.ts +4 -0
- package/dist/verification/rules.d.ts.map +1 -0
- package/dist/verification/rules.js +61 -0
- package/dist/verification/rules.js.map +1 -0
- package/package.json +5 -1
- package/src/advisory/context.ts +47 -0
- package/src/advisory/evaluator.ts +98 -0
- package/src/advisory/executor.ts +187 -0
- package/src/advisory/index.ts +5 -0
- package/src/advisory/registry.ts +42 -0
- package/src/agents/ReactiveAgent.ts +1 -0
- package/src/agents/SupervisorAgent.ts +13 -1
- package/src/bridge/a2a/mapper.ts +3 -0
- package/src/bridge/sse/mapper.ts +19 -0
- package/src/bus/breaker.ts +192 -0
- package/src/bus/index.ts +120 -0
- package/src/bus/lock.ts +233 -0
- package/src/bus/ownership.ts +133 -0
- package/src/compaction/extractor.ts +149 -0
- package/src/compaction/index.ts +21 -0
- package/src/compaction/manager.ts +107 -0
- package/src/compaction/serializer.ts +88 -0
- package/src/compaction/types.ts +37 -0
- package/src/compaction/verifier.ts +91 -0
- package/src/config/runtime.ts +64 -0
- package/src/constants/advisory/index.ts +7 -0
- package/src/constants/bus/index.ts +6 -0
- package/src/constants/compaction/index.ts +20 -0
- package/src/constants/emergency.ts +3 -0
- package/src/constants/index.ts +6 -0
- package/src/constants/limits.ts +2 -0
- package/src/constants/plugin/index.ts +25 -0
- package/src/constants/verification/index.ts +1 -0
- package/src/contracts/api.ts +2 -0
- package/src/index.ts +69 -2
- package/src/manager/run/emergency.ts +117 -0
- package/src/manager/run/persistence.ts +16 -0
- package/src/persona/assembler.ts +36 -1
- package/src/plugin/index.ts +3 -0
- package/src/plugin/lifecycle.ts +308 -0
- package/src/plugin/loader.ts +91 -0
- package/src/plugin/resolver.ts +95 -0
- package/src/registry/plugin/index.ts +20 -0
- package/src/registry/tool/execute.ts +51 -11
- package/src/router/index.ts +1 -0
- package/src/router/task-router.ts +24 -0
- package/src/run/reporter.ts +17 -0
- package/src/runtime/query/context-cache.ts +50 -0
- package/src/runtime/query/executor.ts +37 -1
- package/src/runtime/query/index.ts +125 -12
- package/src/runtime/query/iteration/index.ts +60 -0
- package/src/runtime/query/iteration/phases/advisory.ts +185 -0
- package/src/runtime/query/iteration/phases/compaction.ts +98 -0
- package/src/runtime/query/iteration/phases/context.ts +16 -0
- package/src/runtime/query/iteration/phases/index.ts +2 -0
- package/src/runtime/query/iteration/phases/tool-review.ts +52 -1
- package/src/runtime/query/prompt.ts +64 -0
- package/src/store/memory/disk.ts +205 -0
- package/src/store/memory/index.ts +68 -0
- package/src/store/memory/memory.ts +103 -0
- package/src/tools/advisory/index.ts +157 -0
- package/src/tools/defineTool.ts +2 -0
- package/src/tools/memory/index.ts +13 -0
- package/src/tools/memory/read.ts +42 -0
- package/src/tools/memory/save.ts +40 -0
- package/src/tools/memory/search.ts +52 -0
- package/src/types/advisory/config.ts +35 -0
- package/src/types/advisory/index.ts +18 -0
- package/src/types/advisory/result.ts +34 -0
- package/src/types/advisory/trigger.ts +39 -0
- package/src/types/agent/factory.ts +3 -0
- package/src/types/agent/reactive.ts +3 -0
- package/src/types/agent/supervisor.ts +6 -0
- package/src/types/bus/index.ts +53 -0
- package/src/types/ids/index.ts +6 -0
- package/src/types/memory/index.ts +69 -0
- package/src/types/message/index.ts +10 -2
- package/src/types/persona/index.ts +11 -0
- package/src/types/plugin/index.ts +231 -0
- package/src/types/router/index.ts +1 -0
- package/src/types/router/task-router.ts +20 -0
- package/src/types/run/emergency.ts +23 -0
- package/src/types/run/events.ts +15 -1
- package/src/types/run/index.ts +1 -0
- package/src/types/tool/index.ts +15 -0
- package/src/types/verification/index.ts +69 -0
- package/src/utils/id.ts +28 -0
- package/src/utils/shell-compress.ts +137 -0
- package/src/verification/gate.ts +136 -0
- package/src/verification/index.ts +2 -0
- package/src/verification/rules.ts +78 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { readFile, readdir, stat } from 'node:fs/promises'
|
|
2
|
+
import { homedir } from 'node:os'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import {
|
|
5
|
+
PLUGIN_MANIFEST_FILENAME,
|
|
6
|
+
PLUGIN_NAME_PATTERN,
|
|
7
|
+
PROJECT_PLUGIN_DIR,
|
|
8
|
+
USER_PLUGIN_DIR,
|
|
9
|
+
} from '../constants/plugin/index.js'
|
|
10
|
+
import { type PluginManifest, PluginManifestSchema } from '../types/plugin/index.js'
|
|
11
|
+
import { getRootLogger } from '../utils/logger.js'
|
|
12
|
+
|
|
13
|
+
const logger = getRootLogger().child({ component: 'PluginLoader' })
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Scans a directory for subdirectories containing a plugin manifest.
|
|
17
|
+
* Returns an array of absolute paths to plugin directories.
|
|
18
|
+
*/
|
|
19
|
+
export async function discoverPlugins(parentDir: string): Promise<string[]> {
|
|
20
|
+
const dirs: string[] = []
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const entries = await readdir(parentDir)
|
|
24
|
+
for (const entry of entries) {
|
|
25
|
+
if (entry.startsWith('.') || entry.startsWith('_')) continue
|
|
26
|
+
const fullPath = join(parentDir, entry)
|
|
27
|
+
const s = await stat(fullPath)
|
|
28
|
+
if (!s.isDirectory()) continue
|
|
29
|
+
|
|
30
|
+
const manifestPath = join(fullPath, PLUGIN_MANIFEST_FILENAME)
|
|
31
|
+
try {
|
|
32
|
+
await stat(manifestPath)
|
|
33
|
+
dirs.push(fullPath)
|
|
34
|
+
} catch {
|
|
35
|
+
// No manifest in this directory — skip
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} catch {
|
|
39
|
+
logger.debug('Plugins directory not found', { parentDir })
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return dirs
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Reads and validates a plugin manifest from a plugin directory.
|
|
47
|
+
* Throws on invalid manifest (fail fast).
|
|
48
|
+
*/
|
|
49
|
+
export async function loadPluginManifest(pluginDir: string): Promise<PluginManifest> {
|
|
50
|
+
const manifestPath = join(pluginDir, PLUGIN_MANIFEST_FILENAME)
|
|
51
|
+
const raw = await readFile(manifestPath, 'utf-8')
|
|
52
|
+
const parsed: unknown = JSON.parse(raw)
|
|
53
|
+
return PluginManifestSchema.parse(parsed)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Validates that the plugin name matches the directory name
|
|
58
|
+
* and conforms to the plugin name pattern.
|
|
59
|
+
*/
|
|
60
|
+
export function validatePluginName(name: string, dirName: string): void {
|
|
61
|
+
if (!PLUGIN_NAME_PATTERN.test(name)) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`Plugin name "${name}" is invalid. Must be lowercase alphanumeric with hyphens (pattern: ${PLUGIN_NAME_PATTERN.source})`,
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
if (name !== dirName) {
|
|
67
|
+
throw new Error(`Plugin name "${name}" must match directory name "${dirName}"`)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Discovers plugin directories from both project-level and user-level locations.
|
|
73
|
+
* Returns categorized arrays of absolute paths.
|
|
74
|
+
*/
|
|
75
|
+
export async function discoverAllPluginDirs(
|
|
76
|
+
workingDirectory?: string,
|
|
77
|
+
): Promise<{ project: string[]; user: string[] }> {
|
|
78
|
+
const projectDir = workingDirectory
|
|
79
|
+
? join(workingDirectory, PROJECT_PLUGIN_DIR)
|
|
80
|
+
: join(process.cwd(), PROJECT_PLUGIN_DIR)
|
|
81
|
+
const userDir = join(homedir(), USER_PLUGIN_DIR)
|
|
82
|
+
|
|
83
|
+
const [project, user] = await Promise.all([discoverPlugins(projectDir), discoverPlugins(userDir)])
|
|
84
|
+
|
|
85
|
+
logger.debug('Plugin discovery complete', {
|
|
86
|
+
projectCount: project.length,
|
|
87
|
+
userCount: user.length,
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
return { project, user }
|
|
91
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { PLUGIN_NAMESPACE_SEPARATOR } from '../constants/plugin/index.js'
|
|
2
|
+
import type { PluginRegistry } from '../registry/plugin/index.js'
|
|
3
|
+
import type { ToolRegistry } from '../registry/tool/execute.js'
|
|
4
|
+
import type { PluginId } from '../types/ids/index.js'
|
|
5
|
+
import type { PluginContributionType } from '../types/plugin/index.js'
|
|
6
|
+
|
|
7
|
+
export class PluginResolver {
|
|
8
|
+
private pluginRegistry: PluginRegistry
|
|
9
|
+
private toolRegistry: ToolRegistry
|
|
10
|
+
|
|
11
|
+
constructor(pluginRegistry: PluginRegistry, toolRegistry: ToolRegistry) {
|
|
12
|
+
this.pluginRegistry = pluginRegistry
|
|
13
|
+
this.toolRegistry = toolRegistry
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Parses a qualified tool name in `pluginName:toolName` format.
|
|
18
|
+
* Returns null if the name is not namespaced.
|
|
19
|
+
*/
|
|
20
|
+
resolveToolName(qualifiedName: string): { pluginName: string; toolName: string } | null {
|
|
21
|
+
const sepIndex = qualifiedName.indexOf(PLUGIN_NAMESPACE_SEPARATOR)
|
|
22
|
+
if (sepIndex === -1) return null
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
pluginName: qualifiedName.slice(0, sepIndex),
|
|
26
|
+
toolName: qualifiedName.slice(sepIndex + PLUGIN_NAMESPACE_SEPARATOR.length),
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Lists all tool names contributed by a specific plugin.
|
|
32
|
+
* Matches tools whose name starts with `manifest.name:`.
|
|
33
|
+
*/
|
|
34
|
+
getPluginTools(pluginId: PluginId): string[] {
|
|
35
|
+
const definition = this.pluginRegistry.getOrThrow(pluginId)
|
|
36
|
+
const prefix = definition.manifest.name + PLUGIN_NAMESPACE_SEPARATOR
|
|
37
|
+
return this.toolRegistry.listNames().filter((name) => name.startsWith(prefix))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Resolves a fully qualified component name to its plugin, contribution type, and local name.
|
|
42
|
+
*/
|
|
43
|
+
resolveComponent(
|
|
44
|
+
qualifiedName: string,
|
|
45
|
+
):
|
|
46
|
+
| { pluginId: PluginId; contributionType: PluginContributionType; componentName: string }
|
|
47
|
+
| undefined {
|
|
48
|
+
const sepIndex = qualifiedName.indexOf(PLUGIN_NAMESPACE_SEPARATOR)
|
|
49
|
+
if (sepIndex === -1) return undefined
|
|
50
|
+
|
|
51
|
+
const pluginName = qualifiedName.slice(0, sepIndex)
|
|
52
|
+
const componentName = qualifiedName.slice(sepIndex + PLUGIN_NAMESPACE_SEPARATOR.length)
|
|
53
|
+
|
|
54
|
+
const definition = this.pluginRegistry.findByName(pluginName)
|
|
55
|
+
if (!definition) return undefined
|
|
56
|
+
|
|
57
|
+
const contributionType = this.inferContributionType(definition.id, pluginName, componentName)
|
|
58
|
+
if (!contributionType) return undefined
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
pluginId: definition.id,
|
|
62
|
+
contributionType,
|
|
63
|
+
componentName,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Returns a namespaced name in `pluginName:componentName` format.
|
|
69
|
+
*/
|
|
70
|
+
namespaceName(pluginName: string, componentName: string): string {
|
|
71
|
+
return pluginName + PLUGIN_NAMESPACE_SEPARATOR + componentName
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private inferContributionType(
|
|
75
|
+
pluginId: PluginId,
|
|
76
|
+
pluginName: string,
|
|
77
|
+
componentName: string,
|
|
78
|
+
): PluginContributionType | undefined {
|
|
79
|
+
const definition = this.pluginRegistry.getOrThrow(pluginId)
|
|
80
|
+
const manifest = definition.manifest
|
|
81
|
+
|
|
82
|
+
if (manifest.tools?.includes(componentName)) return 'tool'
|
|
83
|
+
if (manifest.skills?.includes(componentName)) return 'skill'
|
|
84
|
+
if (manifest.hooks?.includes(componentName)) return 'hook'
|
|
85
|
+
if (manifest.connectors?.includes(componentName)) return 'connector'
|
|
86
|
+
if (manifest.personas?.includes(componentName)) return 'persona'
|
|
87
|
+
if (manifest.mcpServers?.some((s) => s.name === componentName)) return 'mcp_server'
|
|
88
|
+
|
|
89
|
+
// Check if it exists as a registered tool (runtime registration)
|
|
90
|
+
const namespacedToolName = pluginName + PLUGIN_NAMESPACE_SEPARATOR + componentName
|
|
91
|
+
if (this.toolRegistry.has(namespacedToolName)) return 'tool'
|
|
92
|
+
|
|
93
|
+
return undefined
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PluginDefinition, PluginScope, PluginStatus } from '../../types/plugin/index.js'
|
|
2
|
+
import { ManagedRegistry } from '../ManagedRegistry.js'
|
|
3
|
+
|
|
4
|
+
export class PluginRegistry extends ManagedRegistry<PluginDefinition> {
|
|
5
|
+
constructor() {
|
|
6
|
+
super({ componentName: 'PluginRegistry', idField: 'id' })
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
listByScope(scope: PluginScope): PluginDefinition[] {
|
|
10
|
+
return this.getAll().filter((def) => def.scope === scope)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
listByStatus(status: PluginStatus): PluginDefinition[] {
|
|
14
|
+
return this.getAll().filter((def) => def.status === status)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
findByName(name: string): PluginDefinition | undefined {
|
|
18
|
+
return this.getAll().find((def) => def.manifest.name === name)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
ToolDefinition,
|
|
10
10
|
ToolRegistryConfig,
|
|
11
11
|
ToolResult,
|
|
12
|
+
ToolTierConfig,
|
|
12
13
|
} from '../../types/tool/index.js'
|
|
13
14
|
import { toErrorMessage } from '../../utils/error.js'
|
|
14
15
|
import { type Logger, getRootLogger } from '../../utils/logger.js'
|
|
@@ -22,12 +23,14 @@ export interface ToolExecutionResult extends ToolResult {
|
|
|
22
23
|
export class ToolRegistry extends Registry<ToolDefinition> {
|
|
23
24
|
private log: Logger
|
|
24
25
|
private availability: Map<string, ToolAvailability> = new Map()
|
|
26
|
+
private tierConfig?: ToolTierConfig
|
|
25
27
|
|
|
26
28
|
constructor(config?: ToolRegistryConfig) {
|
|
27
29
|
super()
|
|
28
30
|
this.log = (config?.logger ?? getRootLogger()).child({
|
|
29
31
|
component: 'ToolRegistry',
|
|
30
32
|
})
|
|
33
|
+
this.tierConfig = config?.tierConfig
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
override register(id: string, tool: ToolDefinition): void
|
|
@@ -61,6 +64,14 @@ export class ToolRegistry extends Registry<ToolDefinition> {
|
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
private registerOne(id: string, tool: ToolDefinition, state: ToolAvailability): void {
|
|
67
|
+
if (tool.tier && this.tierConfig) {
|
|
68
|
+
const validIds = this.tierConfig.tiers.map((t) => t.id)
|
|
69
|
+
if (!validIds.includes(tool.tier)) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
`Tool "${id}" has tier "${tool.tier}" which is not defined. Valid tiers: ${validIds.join(', ')}`,
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
64
75
|
if (this.has(id)) {
|
|
65
76
|
this.log.warn(`Tool "${id}" is already registered, overwriting.`)
|
|
66
77
|
}
|
|
@@ -122,6 +133,26 @@ export class ToolRegistry extends Registry<ToolDefinition> {
|
|
|
122
133
|
)
|
|
123
134
|
}
|
|
124
135
|
|
|
136
|
+
assignTiers(mapping: Record<string, string>): void {
|
|
137
|
+
for (const [toolName, tierId] of Object.entries(mapping)) {
|
|
138
|
+
const tool = this.getOrThrow(toolName)
|
|
139
|
+
if (this.tierConfig) {
|
|
140
|
+
const validIds = this.tierConfig.tiers.map((t) => t.id)
|
|
141
|
+
if (!validIds.includes(tierId)) {
|
|
142
|
+
throw new Error(
|
|
143
|
+
`Tier "${tierId}" for tool "${toolName}" is not defined. Valid tiers: ${validIds.join(', ')}`,
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
tool.tier = tierId
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
toTierGuidance(): string | null {
|
|
152
|
+
if (!this.tierConfig?.guidanceTemplate) return null
|
|
153
|
+
return this.tierConfig.guidanceTemplate(this.tierConfig.tiers)
|
|
154
|
+
}
|
|
155
|
+
|
|
125
156
|
getOrThrow(name: string): ToolDefinition {
|
|
126
157
|
const tool = this.get(name)
|
|
127
158
|
if (!tool) {
|
|
@@ -159,17 +190,26 @@ export class ToolRegistry extends Registry<ToolDefinition> {
|
|
|
159
190
|
toLLMTools(toolNames?: string[]): LLMToolSchema[] {
|
|
160
191
|
const toolsToConvert = this.getByAvailability(['active', 'suspended'], toolNames)
|
|
161
192
|
|
|
162
|
-
return toolsToConvert.map((tool) =>
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
193
|
+
return toolsToConvert.map((tool) => {
|
|
194
|
+
let description = tool.description
|
|
195
|
+
if (this.tierConfig?.labelInDescription && tool.tier) {
|
|
196
|
+
const tierDef = this.tierConfig.tiers.find((t) => t.id === tool.tier)
|
|
197
|
+
if (tierDef) {
|
|
198
|
+
description = `[${tierDef.label}] ${description}`
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
type: 'function' as const,
|
|
203
|
+
function: {
|
|
204
|
+
name: tool.name,
|
|
205
|
+
description,
|
|
206
|
+
parameters: zodToJsonSchema(tool.inputSchema, {
|
|
207
|
+
target: 'jsonSchema7',
|
|
208
|
+
$refStrategy: 'none',
|
|
209
|
+
}) as Record<string, unknown>,
|
|
210
|
+
},
|
|
211
|
+
}
|
|
212
|
+
})
|
|
173
213
|
}
|
|
174
214
|
|
|
175
215
|
getCallableTools(toolNames?: string[]): ToolDefinition[] {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { resolveTaskModel } from './task-router.js'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { TaskRouterConfig, TaskType } from '../types/router/index.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the model ID for a given task type using the router config.
|
|
5
|
+
*
|
|
6
|
+
* Fallback chain: `router[taskType]` -> `router.default` -> `primaryModel`
|
|
7
|
+
*/
|
|
8
|
+
export function resolveTaskModel(
|
|
9
|
+
taskType: TaskType,
|
|
10
|
+
router: TaskRouterConfig | undefined,
|
|
11
|
+
primaryModel: string,
|
|
12
|
+
): string {
|
|
13
|
+
if (!router) return primaryModel
|
|
14
|
+
|
|
15
|
+
const specific = router[taskType]
|
|
16
|
+
if (specific) return specific
|
|
17
|
+
|
|
18
|
+
if (taskType !== 'default') {
|
|
19
|
+
const fallback = router.default
|
|
20
|
+
if (fallback) return fallback
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return primaryModel
|
|
24
|
+
}
|
package/src/run/reporter.ts
CHANGED
|
@@ -154,6 +154,23 @@ export function createRunReporter(parentLogger?: Logger): RunReporter {
|
|
|
154
154
|
})
|
|
155
155
|
break
|
|
156
156
|
|
|
157
|
+
case 'plugin_hook_executing':
|
|
158
|
+
log.debug('Plugin hook executing', {
|
|
159
|
+
runId: event.runId,
|
|
160
|
+
pluginId: event.pluginId,
|
|
161
|
+
hookEvent: event.hookEvent,
|
|
162
|
+
})
|
|
163
|
+
break
|
|
164
|
+
|
|
165
|
+
case 'plugin_hook_completed':
|
|
166
|
+
log.debug('Plugin hook completed', {
|
|
167
|
+
runId: event.runId,
|
|
168
|
+
pluginId: event.pluginId,
|
|
169
|
+
hookEvent: event.hookEvent,
|
|
170
|
+
action: event.result.action,
|
|
171
|
+
})
|
|
172
|
+
break
|
|
173
|
+
|
|
157
174
|
default: {
|
|
158
175
|
const _exhaustive: never = event
|
|
159
176
|
throw new Error(`Unhandled run event type: ${(_exhaustive as RunEvent).type}`)
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto'
|
|
2
2
|
import type { ToolRegistry } from '../../registry/tool/execute.js'
|
|
3
|
+
import type { AgentContextLevel } from '../../types/agent/factory.js'
|
|
3
4
|
import type { ThreadId } from '../../types/ids/index.js'
|
|
4
5
|
import type { AgentPersona } from '../../types/persona/index.js'
|
|
5
6
|
import type { Skill } from '../../types/skills/index.js'
|
|
6
7
|
import { PromptBuilder } from './prompt.js'
|
|
8
|
+
import type { PromptSegments } from './prompt.js'
|
|
7
9
|
|
|
8
10
|
export interface ContextCacheConfig {
|
|
9
11
|
agentId: string
|
|
@@ -25,6 +27,8 @@ export class ContextCache {
|
|
|
25
27
|
|
|
26
28
|
private cachedPrompt: string | undefined
|
|
27
29
|
private cachedConfigHash: string | undefined
|
|
30
|
+
private cachedStaticSegment: string | undefined
|
|
31
|
+
private cachedStaticHash: string | undefined
|
|
28
32
|
|
|
29
33
|
constructor(config: ContextCacheConfig) {
|
|
30
34
|
this.threadId = config.threadId
|
|
@@ -61,9 +65,55 @@ export class ContextCache {
|
|
|
61
65
|
return this.computeConfigHash(input) !== this.cachedConfigHash
|
|
62
66
|
}
|
|
63
67
|
|
|
68
|
+
getSystemPromptSegmented(
|
|
69
|
+
input: PromptCacheInput,
|
|
70
|
+
contextLevel: AgentContextLevel = 'full',
|
|
71
|
+
workingDirectory?: string,
|
|
72
|
+
): PromptSegments {
|
|
73
|
+
const staticHash = this.computeStaticHash(input)
|
|
74
|
+
|
|
75
|
+
const builder = new PromptBuilder({
|
|
76
|
+
systemPrompt: input.systemPrompt,
|
|
77
|
+
persona: input.persona,
|
|
78
|
+
skills: input.skills,
|
|
79
|
+
basePrompt: input.basePrompt,
|
|
80
|
+
tools: input.tools,
|
|
81
|
+
allowedTools: input.allowedTools,
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const segments = builder.buildSegmented(contextLevel, workingDirectory)
|
|
85
|
+
|
|
86
|
+
if (this.cachedStaticHash === staticHash && this.cachedStaticSegment !== undefined) {
|
|
87
|
+
return {
|
|
88
|
+
static: this.cachedStaticSegment,
|
|
89
|
+
dynamic: segments.dynamic,
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
this.cachedStaticSegment = segments.static
|
|
94
|
+
this.cachedStaticHash = staticHash
|
|
95
|
+
|
|
96
|
+
return segments
|
|
97
|
+
}
|
|
98
|
+
|
|
64
99
|
invalidate(): void {
|
|
65
100
|
this.cachedPrompt = undefined
|
|
66
101
|
this.cachedConfigHash = undefined
|
|
102
|
+
this.cachedStaticSegment = undefined
|
|
103
|
+
this.cachedStaticHash = undefined
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private computeStaticHash(input: PromptCacheInput): string {
|
|
107
|
+
const parts: string[] = [
|
|
108
|
+
this.agentId,
|
|
109
|
+
input.systemPrompt ?? '',
|
|
110
|
+
input.persona?.identity?.role ?? '',
|
|
111
|
+
input.persona?.identity?.description ?? '',
|
|
112
|
+
input.basePrompt ?? '',
|
|
113
|
+
...(input.skills?.map((s) => s.metadata.name) ?? []),
|
|
114
|
+
]
|
|
115
|
+
|
|
116
|
+
return createHash('sha256').update(parts.join('\0')).digest('hex').slice(0, 16)
|
|
67
117
|
}
|
|
68
118
|
|
|
69
119
|
private computeConfigHash(input: PromptCacheInput): string {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { extractFromToolCall, extractFromToolResult } from '../../compaction/extractor.js'
|
|
2
|
+
import type { WorkingStateManager } from '../../compaction/manager.js'
|
|
1
3
|
import type { ToolRegistry } from '../../registry/tool/execute.js'
|
|
2
4
|
import type { ActivityStore } from '../../store/activity/memory.js'
|
|
3
5
|
import type { RunId } from '../../types/ids/index.js'
|
|
@@ -7,6 +9,7 @@ import type { ChatCompletionResponse } from '../../types/provider/index.js'
|
|
|
7
9
|
import type { RunEvent } from '../../types/run/index.js'
|
|
8
10
|
import type { ToolContext } from '../../types/tool/index.js'
|
|
9
11
|
import type { Logger } from '../../utils/logger.js'
|
|
12
|
+
import { compressShellOutput } from '../../utils/shell-compress.js'
|
|
10
13
|
|
|
11
14
|
export type EmitEvent = (event: RunEvent) => Promise<void>
|
|
12
15
|
|
|
@@ -29,6 +32,7 @@ export class ToolExecutor {
|
|
|
29
32
|
private activityStore: ActivityStore
|
|
30
33
|
private emitEvent: EmitEvent
|
|
31
34
|
private log: Logger
|
|
35
|
+
private workingStateManager?: WorkingStateManager
|
|
32
36
|
|
|
33
37
|
constructor(
|
|
34
38
|
config: ToolExecutorConfig,
|
|
@@ -42,6 +46,10 @@ export class ToolExecutor {
|
|
|
42
46
|
this.log = log
|
|
43
47
|
}
|
|
44
48
|
|
|
49
|
+
setWorkingStateManager(manager: WorkingStateManager): void {
|
|
50
|
+
this.workingStateManager = manager
|
|
51
|
+
}
|
|
52
|
+
|
|
45
53
|
async executeBatch(response: ChatCompletionResponse): Promise<ToolExecutionBatch> {
|
|
46
54
|
const toolCalls = response.message.toolCalls
|
|
47
55
|
if (!toolCalls) {
|
|
@@ -119,14 +127,24 @@ export class ToolExecutor {
|
|
|
119
127
|
input,
|
|
120
128
|
})
|
|
121
129
|
|
|
130
|
+
if (this.workingStateManager) {
|
|
131
|
+
extractFromToolCall(this.workingStateManager, toolName, toolCall.function.arguments)
|
|
132
|
+
}
|
|
133
|
+
|
|
122
134
|
const startMs = Date.now()
|
|
123
135
|
const result = await this.config.tools.execute(toolName, input, toolContext)
|
|
124
136
|
const durationMs = Date.now() - startMs
|
|
125
137
|
|
|
126
|
-
const
|
|
138
|
+
const rawOutput = result.success
|
|
127
139
|
? result.output
|
|
128
140
|
: `Error: ${result.error ?? 'Tool execution failed'}`
|
|
129
141
|
|
|
142
|
+
const output = result.success ? this.maybeCompress(toolName, rawOutput) : rawOutput
|
|
143
|
+
|
|
144
|
+
if (this.workingStateManager) {
|
|
145
|
+
extractFromToolResult(this.workingStateManager, toolName, output, !result.success)
|
|
146
|
+
}
|
|
147
|
+
|
|
130
148
|
if (result.success) {
|
|
131
149
|
this.log.debug('Tool executed successfully', {
|
|
132
150
|
runId: this.config.runId,
|
|
@@ -160,4 +178,22 @@ export class ToolExecutor {
|
|
|
160
178
|
|
|
161
179
|
return { toolCallId: toolCall.id, output }
|
|
162
180
|
}
|
|
181
|
+
|
|
182
|
+
private maybeCompress(toolName: string, output: string): string {
|
|
183
|
+
const tool = this.config.tools.get(toolName)
|
|
184
|
+
if (!tool || tool.category !== 'shell') {
|
|
185
|
+
return output
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const compressed = compressShellOutput(output)
|
|
189
|
+
if (compressed.length < output.length) {
|
|
190
|
+
this.log.debug('Shell output compressed', {
|
|
191
|
+
tool: toolName,
|
|
192
|
+
originalLength: output.length,
|
|
193
|
+
compressedLength: compressed.length,
|
|
194
|
+
reductionPercent: Math.round((1 - compressed.length / output.length) * 100),
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
return compressed
|
|
198
|
+
}
|
|
163
199
|
}
|