@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
package/src/index.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export { VERSION } from './version.js'
|
|
2
|
-
export {
|
|
3
|
-
|
|
2
|
+
export {
|
|
3
|
+
RuntimeConfigSchema,
|
|
4
|
+
TaskRouterConfigSchema,
|
|
5
|
+
CompactionConfigSchema,
|
|
6
|
+
PluginRuntimeConfigSchema,
|
|
7
|
+
RUNTIME_DEFAULTS,
|
|
8
|
+
} from './config/runtime.js'
|
|
9
|
+
export type { RuntimeConfig, CompactionConfig, PluginRuntimeConfig } from './config/runtime.js'
|
|
4
10
|
|
|
5
11
|
export * from './constants/index.js'
|
|
6
12
|
|
|
@@ -27,6 +33,21 @@ export * from './types/connector/index.js'
|
|
|
27
33
|
export * from './types/skills/index.js'
|
|
28
34
|
export * from './types/a2a/index.js'
|
|
29
35
|
export * from './types/conversation/index.js'
|
|
36
|
+
export * from './types/router/index.js'
|
|
37
|
+
export * from './types/advisory/index.js'
|
|
38
|
+
export * from './types/memory/index.js'
|
|
39
|
+
export * from './types/plugin/index.js'
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
AdvisorRegistry,
|
|
43
|
+
AdvisoryExecutor,
|
|
44
|
+
TriggerEvaluator,
|
|
45
|
+
AdvisoryContext,
|
|
46
|
+
} from './advisory/index.js'
|
|
47
|
+
export type {
|
|
48
|
+
AdvisoryCallContext,
|
|
49
|
+
AdvisoryExecutionResult,
|
|
50
|
+
} from './advisory/index.js'
|
|
30
51
|
|
|
31
52
|
export {
|
|
32
53
|
assembleSystemPrompt,
|
|
@@ -45,10 +66,20 @@ export * from './utils/cost.js'
|
|
|
45
66
|
export * from './utils/error.js'
|
|
46
67
|
export * from './utils/logger.js'
|
|
47
68
|
export { hashToolResult, buildToolResultHashes } from './utils/hash.js'
|
|
69
|
+
export {
|
|
70
|
+
compressShellOutput,
|
|
71
|
+
compressShellOutputFull,
|
|
72
|
+
} from './utils/shell-compress.js'
|
|
73
|
+
export type {
|
|
74
|
+
ShellCompressResult,
|
|
75
|
+
ShellCompressOptions,
|
|
76
|
+
} from './utils/shell-compress.js'
|
|
48
77
|
export { createChildAbortController } from './utils/abort.js'
|
|
49
78
|
export { memoizeAsync } from './utils/memoize.js'
|
|
50
79
|
export { extractFinalResponse } from './utils/conversation.js'
|
|
51
80
|
|
|
81
|
+
export { resolveTaskModel } from './router/task-router.js'
|
|
82
|
+
|
|
52
83
|
export { query, drainQuery } from './runtime/query/index.js'
|
|
53
84
|
export type { QueryParams } from './runtime/query/index.js'
|
|
54
85
|
export { ContextCache } from './runtime/query/context-cache.js'
|
|
@@ -71,12 +102,27 @@ export type { DefineAgentOptions } from './agents/index.js'
|
|
|
71
102
|
|
|
72
103
|
export { InMemoryStore } from './store/InMemoryStore.js'
|
|
73
104
|
export type { Identifiable, Timestamped } from './store/InMemoryStore.js'
|
|
105
|
+
export { InMemoryMemoryIndex } from './store/memory/index.js'
|
|
106
|
+
export { InMemoryMemoryStore } from './store/memory/memory.js'
|
|
107
|
+
export { DiskMemoryStore } from './store/memory/disk.js'
|
|
108
|
+
export type { DiskMemoryStoreConfig } from './store/memory/disk.js'
|
|
74
109
|
|
|
75
110
|
export { Registry } from './registry/Registry.js'
|
|
76
111
|
export { ManagedRegistry } from './registry/ManagedRegistry.js'
|
|
77
112
|
export type { ManagedRegistryConfig } from './registry/ManagedRegistry.js'
|
|
78
113
|
export { AgentRegistry } from './registry/agent/definitions.js'
|
|
114
|
+
export { PluginRegistry } from './registry/plugin/index.js'
|
|
115
|
+
|
|
116
|
+
export {
|
|
117
|
+
PluginLifecycleManager,
|
|
118
|
+
PluginResolver,
|
|
119
|
+
discoverPlugins,
|
|
120
|
+
loadPluginManifest,
|
|
121
|
+
discoverAllPluginDirs,
|
|
122
|
+
} from './plugin/index.js'
|
|
123
|
+
export type { PluginLifecycleManagerConfig } from './plugin/lifecycle.js'
|
|
79
124
|
|
|
125
|
+
export { EmergencySaveManager } from './manager/run/emergency.js'
|
|
80
126
|
export { RunPersistence } from './manager/run/persistence.js'
|
|
81
127
|
export { RunDiskStore } from './store/run/disk.js'
|
|
82
128
|
export { SessionStore } from './store/run/disk.js'
|
|
@@ -92,6 +138,9 @@ export {
|
|
|
92
138
|
buildTaskUpdateTool,
|
|
93
139
|
buildTaskListTool,
|
|
94
140
|
} from './tools/task/index.js'
|
|
141
|
+
export { buildAdvisoryTools } from './tools/advisory/index.js'
|
|
142
|
+
export type { AdvisoryToolsOptions } from './tools/advisory/index.js'
|
|
143
|
+
export { buildMemoryTools } from './tools/memory/index.js'
|
|
95
144
|
export { InMemoryConversationStore } from './store/conversation/memory.js'
|
|
96
145
|
export type { InMemoryConversationStoreConfig } from './store/conversation/memory.js'
|
|
97
146
|
export { PlanManager } from './manager/plan/lifecycle.js'
|
|
@@ -223,3 +272,21 @@ export {
|
|
|
223
272
|
} from './telemetry/index.js'
|
|
224
273
|
export type { PlatformMetrics } from './telemetry/index.js'
|
|
225
274
|
export * from './telemetry/attributes.js'
|
|
275
|
+
|
|
276
|
+
export {
|
|
277
|
+
WorkingStateManager,
|
|
278
|
+
serializeState,
|
|
279
|
+
extractFromToolCall,
|
|
280
|
+
extractFromToolResult,
|
|
281
|
+
extractFromUserMessage,
|
|
282
|
+
extractFromAssistantMessage,
|
|
283
|
+
buildVerifiedSummary,
|
|
284
|
+
} from './compaction/index.js'
|
|
285
|
+
export type {
|
|
286
|
+
WorkingState,
|
|
287
|
+
PlanSlot,
|
|
288
|
+
FileSlot,
|
|
289
|
+
FileAction,
|
|
290
|
+
ToolResultSlot,
|
|
291
|
+
CompactionStrategy,
|
|
292
|
+
} from './compaction/index.js'
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mkdirSync,
|
|
3
|
+
readFileSync,
|
|
4
|
+
readdirSync,
|
|
5
|
+
renameSync,
|
|
6
|
+
unlinkSync,
|
|
7
|
+
writeFileSync,
|
|
8
|
+
} from 'node:fs'
|
|
9
|
+
import { join } from 'node:path'
|
|
10
|
+
import {
|
|
11
|
+
EMERGENCY_DIR_NAME,
|
|
12
|
+
EMERGENCY_EVENTS,
|
|
13
|
+
EMERGENCY_SIGNALS,
|
|
14
|
+
} from '../../constants/emergency.js'
|
|
15
|
+
import type { EmergencySaveData } from '../../types/run/emergency.js'
|
|
16
|
+
import type { Logger } from '../../utils/logger.js'
|
|
17
|
+
import type { RunPersistence } from './persistence.js'
|
|
18
|
+
|
|
19
|
+
export class EmergencySaveManager {
|
|
20
|
+
private static _instance: EmergencySaveManager | undefined
|
|
21
|
+
private sessionRef: WeakRef<RunPersistence> | undefined
|
|
22
|
+
private outputDir: string | undefined
|
|
23
|
+
private signalHandlers: Map<string, () => void> = new Map()
|
|
24
|
+
private log: Logger
|
|
25
|
+
|
|
26
|
+
private constructor(log: Logger) {
|
|
27
|
+
this.log = log
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static instance(log?: Logger): EmergencySaveManager {
|
|
31
|
+
if (!EmergencySaveManager._instance) {
|
|
32
|
+
if (!log) {
|
|
33
|
+
throw new Error('EmergencySaveManager requires a logger on first initialization')
|
|
34
|
+
}
|
|
35
|
+
EmergencySaveManager._instance = new EmergencySaveManager(log)
|
|
36
|
+
}
|
|
37
|
+
return EmergencySaveManager._instance
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
attach(sessionMgr: RunPersistence, outputDir: string, log: Logger): void {
|
|
41
|
+
this.detach()
|
|
42
|
+
this.sessionRef = new WeakRef(sessionMgr)
|
|
43
|
+
this.outputDir = outputDir
|
|
44
|
+
this.log = log.child({ component: 'EmergencySaveManager' })
|
|
45
|
+
|
|
46
|
+
for (const signal of EMERGENCY_SIGNALS) {
|
|
47
|
+
const handler = (): void => {
|
|
48
|
+
this.emergencySave(signal)
|
|
49
|
+
}
|
|
50
|
+
this.signalHandlers.set(signal, handler)
|
|
51
|
+
process.on(signal, handler)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
for (const event of EMERGENCY_EVENTS) {
|
|
55
|
+
const handler = (): void => {
|
|
56
|
+
this.emergencySave(event)
|
|
57
|
+
}
|
|
58
|
+
this.signalHandlers.set(event, handler)
|
|
59
|
+
process.on(event, handler)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
this.log.info('Emergency save handlers attached', { outputDir })
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
detach(): void {
|
|
66
|
+
for (const [signal, handler] of this.signalHandlers) {
|
|
67
|
+
process.removeListener(signal, handler)
|
|
68
|
+
}
|
|
69
|
+
this.signalHandlers.clear()
|
|
70
|
+
this.sessionRef = undefined
|
|
71
|
+
this.outputDir = undefined
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
emergencySave(signal: string): void {
|
|
75
|
+
const sessionMgr = this.sessionRef?.deref()
|
|
76
|
+
if (!sessionMgr || !this.outputDir) {
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const snapshot = sessionMgr.toEmergencySnapshot(signal)
|
|
81
|
+
|
|
82
|
+
const emergencyDir = join(this.outputDir, '..', EMERGENCY_DIR_NAME)
|
|
83
|
+
mkdirSync(emergencyDir, { recursive: true })
|
|
84
|
+
|
|
85
|
+
const tmpPath = join(emergencyDir, `${snapshot.runId}.json.tmp`)
|
|
86
|
+
const finalPath = join(emergencyDir, `${snapshot.runId}.json`)
|
|
87
|
+
|
|
88
|
+
writeFileSync(tmpPath, JSON.stringify(snapshot, null, '\t'), 'utf-8')
|
|
89
|
+
renameSync(tmpPath, finalPath)
|
|
90
|
+
|
|
91
|
+
this.log.warn('Emergency save completed', {
|
|
92
|
+
runId: snapshot.runId,
|
|
93
|
+
signal,
|
|
94
|
+
path: finalPath,
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static listSaves(baseDir: string): string[] {
|
|
99
|
+
const emergencyDir = join(baseDir, EMERGENCY_DIR_NAME)
|
|
100
|
+
try {
|
|
101
|
+
return readdirSync(emergencyDir)
|
|
102
|
+
.filter((f) => f.endsWith('.json'))
|
|
103
|
+
.map((f) => join(emergencyDir, f))
|
|
104
|
+
} catch {
|
|
105
|
+
return []
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static loadSave(filePath: string): EmergencySaveData {
|
|
110
|
+
const raw = readFileSync(filePath, 'utf-8')
|
|
111
|
+
return JSON.parse(raw) as EmergencySaveData
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
static clearSave(filePath: string): void {
|
|
115
|
+
unlinkSync(filePath)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -7,9 +7,11 @@ import {
|
|
|
7
7
|
} from '../../types/common/index.js'
|
|
8
8
|
import type { RunId } from '../../types/ids/index.js'
|
|
9
9
|
import type { AssistantMessage, Message } from '../../types/message/index.js'
|
|
10
|
+
import type { EmergencySaveData } from '../../types/run/emergency.js'
|
|
10
11
|
import type { AgentRun, StopReason } from '../../types/run/index.js'
|
|
11
12
|
import type { RunPersistenceConfig } from '../../types/run/index.js'
|
|
12
13
|
import { type ModelPricing, ZERO_COST, accumulateCost } from '../../utils/cost.js'
|
|
14
|
+
import { generateEmergencySaveId } from '../../utils/id.js'
|
|
13
15
|
import type { Logger } from '../../utils/logger.js'
|
|
14
16
|
|
|
15
17
|
export class RunPersistence {
|
|
@@ -156,6 +158,20 @@ export class RunPersistence {
|
|
|
156
158
|
}
|
|
157
159
|
}
|
|
158
160
|
|
|
161
|
+
toEmergencySnapshot(signal: string): EmergencySaveData {
|
|
162
|
+
return {
|
|
163
|
+
id: generateEmergencySaveId(),
|
|
164
|
+
runId: this.run.id,
|
|
165
|
+
messages: this.run.messages,
|
|
166
|
+
tokenUsage: this.run.tokenUsage,
|
|
167
|
+
currentIteration: this.run.currentIteration,
|
|
168
|
+
startedAt: this.run.startedAt,
|
|
169
|
+
savedAt: Date.now(),
|
|
170
|
+
processSignal: signal,
|
|
171
|
+
lastError: this.run.lastError,
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
159
175
|
async persist(): Promise<void> {
|
|
160
176
|
await this.runStore.writeRunMeta(this.run)
|
|
161
177
|
await this.runStore.writeMessages(this.run)
|
package/src/persona/assembler.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentPersona } from '../types/persona/index.js'
|
|
1
|
+
import type { AgentPersona, OutputDiscipline } from '../types/persona/index.js'
|
|
2
2
|
import type { Skill } from '../types/skills/index.js'
|
|
3
3
|
|
|
4
4
|
export function assembleSystemPrompt(persona: AgentPersona, skills?: Skill[]): string {
|
|
@@ -33,6 +33,10 @@ export function assembleSystemPrompt(persona: AgentPersona, skills?: Skill[]): s
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
if (persona.reflexes?.outputDiscipline) {
|
|
37
|
+
sections.push(renderOutputDiscipline(persona.reflexes.outputDiscipline))
|
|
38
|
+
}
|
|
39
|
+
|
|
36
40
|
if (persona.output) {
|
|
37
41
|
sections.push(`## Output Format\n${persona.output.format.trim()}`)
|
|
38
42
|
}
|
|
@@ -44,6 +48,36 @@ export function assembleSystemPrompt(persona: AgentPersona, skills?: Skill[]): s
|
|
|
44
48
|
return sections.join('\n\n')
|
|
45
49
|
}
|
|
46
50
|
|
|
51
|
+
export function renderOutputDiscipline(discipline: OutputDiscipline): string {
|
|
52
|
+
const lines: string[] = []
|
|
53
|
+
|
|
54
|
+
if (discipline.betweenToolCalls === 'silent') {
|
|
55
|
+
lines.push('- Emit zero words between tool calls. Call tools back-to-back with no narration.')
|
|
56
|
+
} else {
|
|
57
|
+
lines.push(
|
|
58
|
+
'- Emit minimal text between tool calls. Keep inter-tool narration to a single short sentence.',
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (discipline.suppressInnerMonologue) {
|
|
63
|
+
lines.push('- Do not output inner monologue, reasoning traces, or planning text between turns.')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (discipline.finalResponse?.singleFileMaxWords) {
|
|
67
|
+
lines.push(
|
|
68
|
+
`- Final response for single-file changes: ${discipline.finalResponse.singleFileMaxWords} words maximum. Describe the why, not the what.`,
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (discipline.finalResponse?.multiFileMaxWords) {
|
|
73
|
+
lines.push(
|
|
74
|
+
`- Final response for multi-file changes: ${discipline.finalResponse.multiFileMaxWords} words maximum. Summarize intent and scope.`,
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return `## Output Discipline\n${lines.join('\n')}`
|
|
79
|
+
}
|
|
80
|
+
|
|
47
81
|
export function mergePersonas(base: AgentPersona, override: Partial<AgentPersona>): AgentPersona {
|
|
48
82
|
return {
|
|
49
83
|
identity: override.identity ?? base.identity,
|
|
@@ -56,6 +90,7 @@ export function mergePersonas(base: AgentPersona, override: Partial<AgentPersona
|
|
|
56
90
|
...(override.reflexes?.constraints ?? []),
|
|
57
91
|
],
|
|
58
92
|
toolGuidance: override.reflexes?.toolGuidance ?? base.reflexes?.toolGuidance,
|
|
93
|
+
outputDiscipline: override.reflexes?.outputDiscipline ?? base.reflexes?.outputDiscipline,
|
|
59
94
|
},
|
|
60
95
|
output: override.output ?? base.output,
|
|
61
96
|
sessionContext: override.sessionContext ?? base.sessionContext,
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { join } from 'node:path'
|
|
2
|
+
import { pathToFileURL } from 'node:url'
|
|
3
|
+
import { HOOK_TIMEOUT_MS, PLUGIN_NAMESPACE_SEPARATOR } from '../constants/plugin/index.js'
|
|
4
|
+
import type { PluginRegistry } from '../registry/plugin/index.js'
|
|
5
|
+
import type { ToolRegistry } from '../registry/tool/execute.js'
|
|
6
|
+
import type { PluginId } from '../types/ids/index.js'
|
|
7
|
+
import type {
|
|
8
|
+
PluginDefinition,
|
|
9
|
+
PluginEventListener,
|
|
10
|
+
PluginHookContext,
|
|
11
|
+
PluginHookDefinition,
|
|
12
|
+
PluginHookEvent,
|
|
13
|
+
PluginHookResult,
|
|
14
|
+
PluginLifecycleEvent,
|
|
15
|
+
PluginScope,
|
|
16
|
+
} from '../types/plugin/index.js'
|
|
17
|
+
import type { ToolDefinition } from '../types/tool/index.js'
|
|
18
|
+
import { toErrorMessage } from '../utils/error.js'
|
|
19
|
+
import { generatePluginId } from '../utils/id.js'
|
|
20
|
+
import type { Logger } from '../utils/logger.js'
|
|
21
|
+
import { loadPluginManifest } from './loader.js'
|
|
22
|
+
|
|
23
|
+
export interface PluginLifecycleManagerConfig {
|
|
24
|
+
pluginRegistry: PluginRegistry
|
|
25
|
+
toolRegistry: ToolRegistry
|
|
26
|
+
log: Logger
|
|
27
|
+
hookTimeoutMs?: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class PluginLifecycleManager {
|
|
31
|
+
private pluginRegistry: PluginRegistry
|
|
32
|
+
private toolRegistry: ToolRegistry
|
|
33
|
+
private listeners: PluginEventListener[] = []
|
|
34
|
+
private hookHandlers: Map<
|
|
35
|
+
PluginHookEvent,
|
|
36
|
+
Array<{ pluginId: PluginId; handler: PluginHookDefinition['handler'] }>
|
|
37
|
+
> = new Map()
|
|
38
|
+
private pluginContributions: Map<PluginId, string[]> = new Map()
|
|
39
|
+
private hookTimeoutMs: number
|
|
40
|
+
private log: Logger
|
|
41
|
+
|
|
42
|
+
constructor(config: PluginLifecycleManagerConfig) {
|
|
43
|
+
this.pluginRegistry = config.pluginRegistry
|
|
44
|
+
this.toolRegistry = config.toolRegistry
|
|
45
|
+
this.hookTimeoutMs = config.hookTimeoutMs ?? HOOK_TIMEOUT_MS
|
|
46
|
+
this.log = config.log.child({ component: 'PluginLifecycleManager' })
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
on(listener: PluginEventListener): void {
|
|
50
|
+
this.listeners.push(listener)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
off(listener: PluginEventListener): void {
|
|
54
|
+
const index = this.listeners.indexOf(listener)
|
|
55
|
+
if (index >= 0) this.listeners.splice(index, 1)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async install(pluginDir: string, scope: PluginScope): Promise<PluginDefinition> {
|
|
59
|
+
const manifest = await loadPluginManifest(pluginDir)
|
|
60
|
+
|
|
61
|
+
const existing = this.pluginRegistry.findByName(manifest.name)
|
|
62
|
+
if (existing) {
|
|
63
|
+
throw new Error(`Plugin "${manifest.name}" is already installed (id: ${existing.id})`)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const pluginId = generatePluginId()
|
|
67
|
+
const definition: PluginDefinition = {
|
|
68
|
+
id: pluginId,
|
|
69
|
+
manifest,
|
|
70
|
+
scope,
|
|
71
|
+
status: 'installed',
|
|
72
|
+
rootDir: pluginDir,
|
|
73
|
+
installedAt: Date.now(),
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this.pluginRegistry.register(definition)
|
|
77
|
+
|
|
78
|
+
this.emit({
|
|
79
|
+
type: 'plugin_installed',
|
|
80
|
+
pluginId,
|
|
81
|
+
name: manifest.name,
|
|
82
|
+
scope,
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
this.log.info(`Plugin installed: ${manifest.name}`, {
|
|
86
|
+
pluginId,
|
|
87
|
+
scope,
|
|
88
|
+
version: manifest.version,
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
return definition
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async enable(pluginId: PluginId): Promise<void> {
|
|
95
|
+
const plugin = this.pluginRegistry.getOrThrow(pluginId)
|
|
96
|
+
|
|
97
|
+
if (plugin.status !== 'installed' && plugin.status !== 'disabled') {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`Cannot enable plugin "${plugin.manifest.name}": status is "${plugin.status}" (expected "installed" or "disabled")`,
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const registeredToolNames: string[] = []
|
|
104
|
+
const { manifest } = plugin
|
|
105
|
+
|
|
106
|
+
// Load tools
|
|
107
|
+
if (manifest.tools && manifest.tools.length > 0) {
|
|
108
|
+
for (const toolPath of manifest.tools) {
|
|
109
|
+
const absolutePath = join(plugin.rootDir, toolPath)
|
|
110
|
+
const fileUrl = pathToFileURL(absolutePath).href
|
|
111
|
+
const mod = (await import(fileUrl)) as { tools?: ToolDefinition[] }
|
|
112
|
+
|
|
113
|
+
if (!mod.tools || !Array.isArray(mod.tools)) {
|
|
114
|
+
throw new Error(
|
|
115
|
+
`Plugin "${manifest.name}": tool module "${toolPath}" must export a "tools" array`,
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
for (const tool of mod.tools) {
|
|
120
|
+
const namespacedName = manifest.name + PLUGIN_NAMESPACE_SEPARATOR + tool.name
|
|
121
|
+
const namespacedTool: ToolDefinition = { ...tool, name: namespacedName }
|
|
122
|
+
this.toolRegistry.register(namespacedTool, 'deferred')
|
|
123
|
+
registeredToolNames.push(namespacedName)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Load hooks
|
|
129
|
+
if (manifest.hooks && manifest.hooks.length > 0) {
|
|
130
|
+
for (const hookPath of manifest.hooks) {
|
|
131
|
+
const absolutePath = join(plugin.rootDir, hookPath)
|
|
132
|
+
const fileUrl = pathToFileURL(absolutePath).href
|
|
133
|
+
const mod = (await import(fileUrl)) as { hooks?: PluginHookDefinition[] }
|
|
134
|
+
|
|
135
|
+
if (!mod.hooks || !Array.isArray(mod.hooks)) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
`Plugin "${manifest.name}": hook module "${hookPath}" must export a "hooks" array`,
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
for (const hook of mod.hooks) {
|
|
142
|
+
const handlers = this.hookHandlers.get(hook.event) ?? []
|
|
143
|
+
handlers.push({ pluginId, handler: hook.handler })
|
|
144
|
+
this.hookHandlers.set(hook.event, handlers)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Log unsupported contribution types
|
|
150
|
+
if (manifest.skills && manifest.skills.length > 0) {
|
|
151
|
+
this.log.info(`Plugin "${manifest.name}": skills contribution not yet supported`)
|
|
152
|
+
}
|
|
153
|
+
if (manifest.mcpServers && manifest.mcpServers.length > 0) {
|
|
154
|
+
this.log.info(`Plugin "${manifest.name}": MCP servers contribution not yet supported`)
|
|
155
|
+
}
|
|
156
|
+
if (manifest.connectors && manifest.connectors.length > 0) {
|
|
157
|
+
this.log.info(`Plugin "${manifest.name}": connectors contribution not yet supported`)
|
|
158
|
+
}
|
|
159
|
+
if (manifest.personas && manifest.personas.length > 0) {
|
|
160
|
+
this.log.info(`Plugin "${manifest.name}": personas contribution not yet supported`)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Track contributions for cleanup
|
|
164
|
+
this.pluginContributions.set(pluginId, registeredToolNames)
|
|
165
|
+
|
|
166
|
+
// Update status to enabled
|
|
167
|
+
const enabled: PluginDefinition = {
|
|
168
|
+
...plugin,
|
|
169
|
+
status: 'enabled',
|
|
170
|
+
enabledAt: Date.now(),
|
|
171
|
+
}
|
|
172
|
+
this.pluginRegistry.register(enabled)
|
|
173
|
+
|
|
174
|
+
this.emit({
|
|
175
|
+
type: 'plugin_enabled',
|
|
176
|
+
pluginId,
|
|
177
|
+
name: manifest.name,
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
this.log.info(`Plugin enabled: ${manifest.name}`, {
|
|
181
|
+
pluginId,
|
|
182
|
+
toolCount: registeredToolNames.length,
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async disable(pluginId: PluginId): Promise<void> {
|
|
187
|
+
const plugin = this.pluginRegistry.getOrThrow(pluginId)
|
|
188
|
+
|
|
189
|
+
if (plugin.status !== 'enabled') {
|
|
190
|
+
throw new Error(
|
|
191
|
+
`Cannot disable plugin "${plugin.manifest.name}": status is "${plugin.status}" (expected "enabled")`,
|
|
192
|
+
)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Unregister contributed tools
|
|
196
|
+
const toolNames = this.pluginContributions.get(pluginId) ?? []
|
|
197
|
+
for (const name of toolNames) {
|
|
198
|
+
this.toolRegistry.unregister(name)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Remove hook handlers for this plugin
|
|
202
|
+
for (const [event, handlers] of this.hookHandlers) {
|
|
203
|
+
const filtered = handlers.filter((h) => h.pluginId !== pluginId)
|
|
204
|
+
if (filtered.length === 0) {
|
|
205
|
+
this.hookHandlers.delete(event)
|
|
206
|
+
} else {
|
|
207
|
+
this.hookHandlers.set(event, filtered)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Clear contributions tracking
|
|
212
|
+
this.pluginContributions.delete(pluginId)
|
|
213
|
+
|
|
214
|
+
// Update status to disabled
|
|
215
|
+
const disabled: PluginDefinition = {
|
|
216
|
+
...plugin,
|
|
217
|
+
status: 'disabled',
|
|
218
|
+
enabledAt: undefined,
|
|
219
|
+
}
|
|
220
|
+
this.pluginRegistry.register(disabled)
|
|
221
|
+
|
|
222
|
+
this.emit({
|
|
223
|
+
type: 'plugin_disabled',
|
|
224
|
+
pluginId,
|
|
225
|
+
name: plugin.manifest.name,
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
this.log.info(`Plugin disabled: ${plugin.manifest.name}`, { pluginId })
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async uninstall(pluginId: PluginId): Promise<void> {
|
|
232
|
+
const plugin = this.pluginRegistry.getOrThrow(pluginId)
|
|
233
|
+
|
|
234
|
+
if (plugin.status === 'enabled') {
|
|
235
|
+
await this.disable(pluginId)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
this.pluginRegistry.unregister(pluginId)
|
|
239
|
+
|
|
240
|
+
this.emit({
|
|
241
|
+
type: 'plugin_uninstalled',
|
|
242
|
+
pluginId,
|
|
243
|
+
name: plugin.manifest.name,
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
this.log.info(`Plugin uninstalled: ${plugin.manifest.name}`, { pluginId })
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async executeHooks(
|
|
250
|
+
event: PluginHookEvent,
|
|
251
|
+
context: Omit<PluginHookContext, 'pluginId' | 'event'>,
|
|
252
|
+
): Promise<PluginHookResult[]> {
|
|
253
|
+
const handlers = this.hookHandlers.get(event)
|
|
254
|
+
if (!handlers || handlers.length === 0) {
|
|
255
|
+
return []
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const results: PluginHookResult[] = []
|
|
259
|
+
|
|
260
|
+
for (const { pluginId, handler } of handlers) {
|
|
261
|
+
const hookContext: PluginHookContext = {
|
|
262
|
+
...context,
|
|
263
|
+
pluginId,
|
|
264
|
+
event,
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const start = performance.now()
|
|
268
|
+
let result: PluginHookResult
|
|
269
|
+
|
|
270
|
+
try {
|
|
271
|
+
result = await Promise.race([
|
|
272
|
+
handler(hookContext),
|
|
273
|
+
new Promise<PluginHookResult>((_, reject) =>
|
|
274
|
+
setTimeout(() => reject(new Error('Hook timeout')), this.hookTimeoutMs),
|
|
275
|
+
),
|
|
276
|
+
])
|
|
277
|
+
} catch (err) {
|
|
278
|
+
const message = toErrorMessage(err)
|
|
279
|
+
result = { action: 'error', message }
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const durationMs = Math.round(performance.now() - start)
|
|
283
|
+
|
|
284
|
+
this.emit({
|
|
285
|
+
type: 'plugin_hook_executed',
|
|
286
|
+
pluginId,
|
|
287
|
+
hookEvent: event,
|
|
288
|
+
durationMs,
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
results.push(result)
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return results
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
private emit(event: PluginLifecycleEvent): void {
|
|
298
|
+
for (const listener of this.listeners) {
|
|
299
|
+
try {
|
|
300
|
+
listener(event)
|
|
301
|
+
} catch (err) {
|
|
302
|
+
this.log.error('Plugin event listener error', {
|
|
303
|
+
error: toErrorMessage(err),
|
|
304
|
+
})
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|