@namzu/sdk 0.1.4 → 0.1.5-rc.1

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.
Files changed (324) hide show
  1. package/dist/advisory/executor.d.ts +2 -2
  2. package/dist/advisory/executor.d.ts.map +1 -1
  3. package/dist/advisory/executor.js.map +1 -1
  4. package/dist/agents/AbstractAgent.d.ts +20 -2
  5. package/dist/agents/AbstractAgent.d.ts.map +1 -1
  6. package/dist/agents/AbstractAgent.js +23 -1
  7. package/dist/agents/AbstractAgent.js.map +1 -1
  8. package/dist/agents/PipelineAgent.d.ts.map +1 -1
  9. package/dist/agents/PipelineAgent.js +1 -1
  10. package/dist/agents/PipelineAgent.js.map +1 -1
  11. package/dist/agents/ReactiveAgent.d.ts.map +1 -1
  12. package/dist/agents/ReactiveAgent.js +1 -0
  13. package/dist/agents/ReactiveAgent.js.map +1 -1
  14. package/dist/agents/RouterAgent.d.ts.map +1 -1
  15. package/dist/agents/RouterAgent.js +4 -2
  16. package/dist/agents/RouterAgent.js.map +1 -1
  17. package/dist/agents/SupervisorAgent.d.ts.map +1 -1
  18. package/dist/agents/SupervisorAgent.js +4 -1
  19. package/dist/agents/SupervisorAgent.js.map +1 -1
  20. package/dist/agents/__tests__/lock.test.d.ts +2 -0
  21. package/dist/agents/__tests__/lock.test.d.ts.map +1 -0
  22. package/dist/agents/__tests__/lock.test.js +131 -0
  23. package/dist/agents/__tests__/lock.test.js.map +1 -0
  24. package/dist/agents/index.d.ts +2 -0
  25. package/dist/agents/index.d.ts.map +1 -1
  26. package/dist/agents/index.js +1 -0
  27. package/dist/agents/index.js.map +1 -1
  28. package/dist/agents/lock.d.ts +42 -0
  29. package/dist/agents/lock.d.ts.map +1 -0
  30. package/dist/agents/lock.js +54 -0
  31. package/dist/agents/lock.js.map +1 -0
  32. package/dist/bridge/a2a/message.d.ts.map +1 -1
  33. package/dist/bridge/a2a/message.js.map +1 -1
  34. package/dist/bridge/tools/connector/router.d.ts +4 -5
  35. package/dist/bridge/tools/connector/router.d.ts.map +1 -1
  36. package/dist/bridge/tools/connector/router.js.map +1 -1
  37. package/dist/compaction/__tests__/SlidingWindowManager.test.d.ts +2 -0
  38. package/dist/compaction/__tests__/SlidingWindowManager.test.d.ts.map +1 -0
  39. package/dist/compaction/__tests__/SlidingWindowManager.test.js +113 -0
  40. package/dist/compaction/__tests__/SlidingWindowManager.test.js.map +1 -0
  41. package/dist/compaction/__tests__/dangling.test.d.ts +2 -0
  42. package/dist/compaction/__tests__/dangling.test.d.ts.map +1 -0
  43. package/dist/compaction/__tests__/dangling.test.js +356 -0
  44. package/dist/compaction/__tests__/dangling.test.js.map +1 -0
  45. package/dist/compaction/__tests__/factory.test.d.ts +2 -0
  46. package/dist/compaction/__tests__/factory.test.d.ts.map +1 -0
  47. package/dist/compaction/__tests__/factory.test.js +43 -0
  48. package/dist/compaction/__tests__/factory.test.js.map +1 -0
  49. package/dist/compaction/dangling.d.ts +96 -0
  50. package/dist/compaction/dangling.d.ts.map +1 -0
  51. package/dist/compaction/dangling.js +274 -0
  52. package/dist/compaction/dangling.js.map +1 -0
  53. package/dist/compaction/factory.d.ts +20 -0
  54. package/dist/compaction/factory.d.ts.map +1 -0
  55. package/dist/compaction/factory.js +35 -0
  56. package/dist/compaction/factory.js.map +1 -0
  57. package/dist/compaction/index.d.ts +5 -0
  58. package/dist/compaction/index.d.ts.map +1 -1
  59. package/dist/compaction/index.js +3 -0
  60. package/dist/compaction/index.js.map +1 -1
  61. package/dist/compaction/interface.d.ts +33 -0
  62. package/dist/compaction/interface.d.ts.map +1 -0
  63. package/dist/compaction/interface.js +2 -0
  64. package/dist/compaction/interface.js.map +1 -0
  65. package/dist/compaction/managers/index.d.ts +4 -0
  66. package/dist/compaction/managers/index.d.ts.map +1 -0
  67. package/dist/compaction/managers/index.js +4 -0
  68. package/dist/compaction/managers/index.js.map +1 -0
  69. package/dist/compaction/managers/null.d.ts +12 -0
  70. package/dist/compaction/managers/null.d.ts.map +1 -0
  71. package/dist/compaction/managers/null.js +15 -0
  72. package/dist/compaction/managers/null.js.map +1 -0
  73. package/dist/compaction/managers/slidingWindow.d.ts +27 -0
  74. package/dist/compaction/managers/slidingWindow.d.ts.map +1 -0
  75. package/dist/compaction/managers/slidingWindow.js +41 -0
  76. package/dist/compaction/managers/slidingWindow.js.map +1 -0
  77. package/dist/compaction/managers/structured.d.ts +23 -0
  78. package/dist/compaction/managers/structured.d.ts.map +1 -0
  79. package/dist/compaction/managers/structured.js +144 -0
  80. package/dist/compaction/managers/structured.js.map +1 -0
  81. package/dist/compaction/types.d.ts +1 -1
  82. package/dist/compaction/types.d.ts.map +1 -1
  83. package/dist/config/runtime.d.ts +16 -16
  84. package/dist/config/runtime.js +1 -1
  85. package/dist/config/runtime.js.map +1 -1
  86. package/dist/constants/agent/index.d.ts +1 -1
  87. package/dist/constants/agent/index.d.ts.map +1 -1
  88. package/dist/gateway/local.d.ts +2 -2
  89. package/dist/gateway/local.d.ts.map +1 -1
  90. package/dist/gateway/local.js +10 -1
  91. package/dist/gateway/local.js.map +1 -1
  92. package/dist/index.d.ts +18 -4
  93. package/dist/index.d.ts.map +1 -1
  94. package/dist/index.js +12 -2
  95. package/dist/index.js.map +1 -1
  96. package/dist/manager/agent/lifecycle.d.ts.map +1 -1
  97. package/dist/manager/agent/lifecycle.js +3 -2
  98. package/dist/manager/agent/lifecycle.js.map +1 -1
  99. package/dist/manager/run/persistence.d.ts +1 -2
  100. package/dist/manager/run/persistence.d.ts.map +1 -1
  101. package/dist/manager/run/persistence.js +2 -1
  102. package/dist/manager/run/persistence.js.map +1 -1
  103. package/dist/plugin/__tests__/lifecycle.test.d.ts +2 -0
  104. package/dist/plugin/__tests__/lifecycle.test.d.ts.map +1 -0
  105. package/dist/plugin/__tests__/lifecycle.test.js +332 -0
  106. package/dist/plugin/__tests__/lifecycle.test.js.map +1 -0
  107. package/dist/plugin/lifecycle.d.ts +2 -2
  108. package/dist/plugin/lifecycle.d.ts.map +1 -1
  109. package/dist/plugin/lifecycle.js +28 -2
  110. package/dist/plugin/lifecycle.js.map +1 -1
  111. package/dist/plugin/resolver.d.ts +2 -2
  112. package/dist/plugin/resolver.d.ts.map +1 -1
  113. package/dist/plugin/resolver.js.map +1 -1
  114. package/dist/registry/agent/definitions.d.ts +3 -2
  115. package/dist/registry/agent/definitions.d.ts.map +1 -1
  116. package/dist/registry/agent/definitions.js.map +1 -1
  117. package/dist/registry/tool/execute.d.ts +2 -5
  118. package/dist/registry/tool/execute.d.ts.map +1 -1
  119. package/dist/registry/tool/execute.js.map +1 -1
  120. package/dist/runtime/decision/parser.d.ts.map +1 -1
  121. package/dist/runtime/decision/parser.js +15 -40
  122. package/dist/runtime/decision/parser.js.map +1 -1
  123. package/dist/runtime/query/context-cache.d.ts +3 -3
  124. package/dist/runtime/query/context-cache.d.ts.map +1 -1
  125. package/dist/runtime/query/context-cache.js.map +1 -1
  126. package/dist/runtime/query/context.d.ts +1 -1
  127. package/dist/runtime/query/context.d.ts.map +1 -1
  128. package/dist/runtime/query/context.js.map +1 -1
  129. package/dist/runtime/query/events.js +11 -11
  130. package/dist/runtime/query/events.js.map +1 -1
  131. package/dist/runtime/query/executor.d.ts +4 -2
  132. package/dist/runtime/query/executor.d.ts.map +1 -1
  133. package/dist/runtime/query/executor.js +1 -0
  134. package/dist/runtime/query/executor.js.map +1 -1
  135. package/dist/runtime/query/index.d.ts +5 -3
  136. package/dist/runtime/query/index.d.ts.map +1 -1
  137. package/dist/runtime/query/index.js +2 -1
  138. package/dist/runtime/query/index.js.map +1 -1
  139. package/dist/runtime/query/iteration/index.d.ts +2 -2
  140. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  141. package/dist/runtime/query/iteration/index.js.map +1 -1
  142. package/dist/runtime/query/iteration/phases/advisory.d.ts.map +1 -1
  143. package/dist/runtime/query/iteration/phases/advisory.js.map +1 -1
  144. package/dist/runtime/query/iteration/phases/checkpoint.d.ts +1 -1
  145. package/dist/runtime/query/iteration/phases/checkpoint.d.ts.map +1 -1
  146. package/dist/runtime/query/iteration/phases/checkpoint.js.map +1 -1
  147. package/dist/runtime/query/iteration/phases/context.d.ts +2 -2
  148. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  149. package/dist/runtime/query/iteration/phases/plan.d.ts +1 -1
  150. package/dist/runtime/query/iteration/phases/plan.d.ts.map +1 -1
  151. package/dist/runtime/query/iteration/phases/plan.js.map +1 -1
  152. package/dist/runtime/query/prompt.d.ts +2 -2
  153. package/dist/runtime/query/prompt.d.ts.map +1 -1
  154. package/dist/runtime/query/prompt.js.map +1 -1
  155. package/dist/runtime/query/result.d.ts +1 -1
  156. package/dist/runtime/query/result.d.ts.map +1 -1
  157. package/dist/runtime/query/result.js.map +1 -1
  158. package/dist/runtime/query/tooling.d.ts +4 -2
  159. package/dist/runtime/query/tooling.d.ts.map +1 -1
  160. package/dist/runtime/query/tooling.js +1 -0
  161. package/dist/runtime/query/tooling.js.map +1 -1
  162. package/dist/store/conversation/memory.d.ts +1 -1
  163. package/dist/store/conversation/memory.d.ts.map +1 -1
  164. package/dist/store/conversation/memory.js +15 -3
  165. package/dist/store/conversation/memory.js.map +1 -1
  166. package/dist/store/run/disk.d.ts +1 -2
  167. package/dist/store/run/disk.d.ts.map +1 -1
  168. package/dist/store/run/disk.js +21 -13
  169. package/dist/store/run/disk.js.map +1 -1
  170. package/dist/tools/builtins/__tests__/structuredOutput.example.d.ts +140 -0
  171. package/dist/tools/builtins/__tests__/structuredOutput.example.d.ts.map +1 -0
  172. package/dist/tools/builtins/__tests__/structuredOutput.example.js +183 -0
  173. package/dist/tools/builtins/__tests__/structuredOutput.example.js.map +1 -0
  174. package/dist/tools/builtins/__tests__/structuredOutput.test.d.ts +2 -0
  175. package/dist/tools/builtins/__tests__/structuredOutput.test.d.ts.map +1 -0
  176. package/dist/tools/builtins/__tests__/structuredOutput.test.js +224 -0
  177. package/dist/tools/builtins/__tests__/structuredOutput.test.js.map +1 -0
  178. package/dist/tools/builtins/grep.d.ts.map +1 -1
  179. package/dist/tools/builtins/grep.js +1 -2
  180. package/dist/tools/builtins/grep.js.map +1 -1
  181. package/dist/tools/builtins/index.d.ts +1 -0
  182. package/dist/tools/builtins/index.d.ts.map +1 -1
  183. package/dist/tools/builtins/index.js +3 -0
  184. package/dist/tools/builtins/index.js.map +1 -1
  185. package/dist/tools/builtins/ls.d.ts +1 -1
  186. package/dist/tools/builtins/structuredOutput.d.ts +27 -0
  187. package/dist/tools/builtins/structuredOutput.d.ts.map +1 -0
  188. package/dist/tools/builtins/structuredOutput.js +46 -0
  189. package/dist/tools/builtins/structuredOutput.js.map +1 -0
  190. package/dist/tools/task/list.d.ts +1 -1
  191. package/dist/tools/task/list.d.ts.map +1 -1
  192. package/dist/tools/task/list.js.map +1 -1
  193. package/dist/types/agent/base.d.ts +4 -1
  194. package/dist/types/agent/base.d.ts.map +1 -1
  195. package/dist/types/agent/index.d.ts +1 -0
  196. package/dist/types/agent/index.d.ts.map +1 -1
  197. package/dist/types/agent/index.js +1 -0
  198. package/dist/types/agent/index.js.map +1 -1
  199. package/dist/types/agent/manager.d.ts +27 -0
  200. package/dist/types/agent/manager.d.ts.map +1 -0
  201. package/dist/types/agent/manager.js +2 -0
  202. package/dist/types/agent/manager.js.map +1 -0
  203. package/dist/types/agent/reactive.d.ts +2 -2
  204. package/dist/types/agent/reactive.d.ts.map +1 -1
  205. package/dist/types/agent/supervisor.d.ts +2 -2
  206. package/dist/types/agent/supervisor.d.ts.map +1 -1
  207. package/dist/types/agent/task.d.ts +0 -2
  208. package/dist/types/agent/task.d.ts.map +1 -1
  209. package/dist/types/agent/task.js +0 -2
  210. package/dist/types/agent/task.js.map +1 -1
  211. package/dist/types/common/index.d.ts +0 -1
  212. package/dist/types/common/index.d.ts.map +1 -1
  213. package/dist/types/common/index.js +0 -1
  214. package/dist/types/common/index.js.map +1 -1
  215. package/dist/types/hitl/index.d.ts +1 -2
  216. package/dist/types/hitl/index.d.ts.map +1 -1
  217. package/dist/types/hitl/index.js.map +1 -1
  218. package/dist/types/invocation/__tests__/state.test.d.ts +2 -0
  219. package/dist/types/invocation/__tests__/state.test.d.ts.map +1 -0
  220. package/dist/types/invocation/__tests__/state.test.js +167 -0
  221. package/dist/types/invocation/__tests__/state.test.js.map +1 -0
  222. package/dist/types/invocation/index.d.ts +37 -0
  223. package/dist/types/invocation/index.d.ts.map +1 -0
  224. package/dist/types/invocation/index.js +23 -0
  225. package/dist/types/invocation/index.js.map +1 -0
  226. package/dist/types/plugin/index.d.ts +6 -0
  227. package/dist/types/plugin/index.d.ts.map +1 -1
  228. package/dist/types/plugin/index.js +16 -0
  229. package/dist/types/plugin/index.js.map +1 -1
  230. package/dist/types/run/events.d.ts +1 -1
  231. package/dist/types/run/events.d.ts.map +1 -1
  232. package/dist/types/run/index.d.ts +1 -0
  233. package/dist/types/run/index.d.ts.map +1 -1
  234. package/dist/types/run/index.js +1 -0
  235. package/dist/types/run/index.js.map +1 -1
  236. package/dist/types/run/metadata.d.ts +1 -1
  237. package/dist/types/run/metadata.d.ts.map +1 -1
  238. package/dist/types/run/state.d.ts +1 -1
  239. package/dist/types/run/state.d.ts.map +1 -1
  240. package/dist/types/run/stop-reason.d.ts +2 -0
  241. package/dist/types/run/stop-reason.d.ts.map +1 -0
  242. package/dist/types/run/stop-reason.js +2 -0
  243. package/dist/types/run/stop-reason.js.map +1 -0
  244. package/dist/types/structured-output/index.d.ts +51 -0
  245. package/dist/types/structured-output/index.d.ts.map +1 -0
  246. package/dist/types/structured-output/index.js +2 -0
  247. package/dist/types/structured-output/index.js.map +1 -0
  248. package/dist/types/tool/index.d.ts +36 -0
  249. package/dist/types/tool/index.d.ts.map +1 -1
  250. package/package.json +1 -1
  251. package/src/advisory/executor.ts +2 -4
  252. package/src/agents/AbstractAgent.ts +26 -3
  253. package/src/agents/PipelineAgent.ts +1 -1
  254. package/src/agents/ReactiveAgent.ts +1 -0
  255. package/src/agents/RouterAgent.ts +8 -2
  256. package/src/agents/SupervisorAgent.ts +5 -1
  257. package/src/agents/__tests__/lock.test.ts +158 -0
  258. package/src/agents/index.ts +2 -0
  259. package/src/agents/lock.ts +66 -0
  260. package/src/bridge/a2a/message.ts +1 -2
  261. package/src/bridge/tools/connector/router.ts +4 -5
  262. package/src/compaction/__tests__/SlidingWindowManager.test.ts +139 -0
  263. package/src/compaction/__tests__/dangling.test.ts +447 -0
  264. package/src/compaction/__tests__/factory.test.ts +53 -0
  265. package/src/compaction/dangling.ts +321 -0
  266. package/src/compaction/factory.ts +41 -0
  267. package/src/compaction/index.ts +14 -0
  268. package/src/compaction/interface.ts +35 -0
  269. package/src/compaction/managers/index.ts +3 -0
  270. package/src/compaction/managers/null.ts +19 -0
  271. package/src/compaction/managers/slidingWindow.ts +57 -0
  272. package/src/compaction/managers/structured.ts +169 -0
  273. package/src/compaction/types.ts +1 -1
  274. package/src/config/runtime.ts +1 -1
  275. package/src/constants/agent/index.ts +1 -1
  276. package/src/gateway/local.ts +13 -4
  277. package/src/index.ts +38 -1
  278. package/src/manager/agent/lifecycle.ts +3 -2
  279. package/src/manager/run/persistence.ts +3 -8
  280. package/src/plugin/__tests__/lifecycle.test.ts +430 -0
  281. package/src/plugin/lifecycle.ts +32 -6
  282. package/src/plugin/resolver.ts +3 -3
  283. package/src/registry/agent/definitions.ts +3 -2
  284. package/src/registry/tool/execute.ts +2 -5
  285. package/src/runtime/decision/parser.ts +15 -40
  286. package/src/runtime/query/context-cache.ts +3 -4
  287. package/src/runtime/query/context.ts +1 -2
  288. package/src/runtime/query/events.ts +11 -11
  289. package/src/runtime/query/executor.ts +5 -3
  290. package/src/runtime/query/index.ts +11 -4
  291. package/src/runtime/query/iteration/index.ts +2 -2
  292. package/src/runtime/query/iteration/phases/advisory.ts +1 -2
  293. package/src/runtime/query/iteration/phases/checkpoint.ts +1 -2
  294. package/src/runtime/query/iteration/phases/context.ts +2 -2
  295. package/src/runtime/query/iteration/phases/plan.ts +1 -2
  296. package/src/runtime/query/prompt.ts +3 -3
  297. package/src/runtime/query/result.ts +1 -2
  298. package/src/runtime/query/tooling.ts +5 -2
  299. package/src/store/conversation/memory.ts +21 -5
  300. package/src/store/run/disk.ts +18 -16
  301. package/src/tools/builtins/__tests__/structuredOutput.example.ts +221 -0
  302. package/src/tools/builtins/__tests__/structuredOutput.test.ts +275 -0
  303. package/src/tools/builtins/grep.ts +1 -2
  304. package/src/tools/builtins/index.ts +3 -0
  305. package/src/tools/builtins/structuredOutput.ts +55 -0
  306. package/src/tools/task/list.ts +1 -2
  307. package/src/types/agent/base.ts +5 -1
  308. package/src/types/agent/index.ts +1 -0
  309. package/src/types/agent/manager.ts +36 -0
  310. package/src/types/agent/reactive.ts +2 -2
  311. package/src/types/agent/supervisor.ts +2 -2
  312. package/src/types/agent/task.ts +0 -4
  313. package/src/types/common/index.ts +0 -2
  314. package/src/types/hitl/index.ts +1 -2
  315. package/src/types/invocation/__tests__/state.test.ts +210 -0
  316. package/src/types/invocation/index.ts +55 -0
  317. package/src/types/plugin/index.ts +19 -0
  318. package/src/types/run/events.ts +1 -10
  319. package/src/types/run/index.ts +1 -0
  320. package/src/types/run/metadata.ts +1 -1
  321. package/src/types/run/state.ts +1 -1
  322. package/src/types/run/stop-reason.ts +10 -0
  323. package/src/types/structured-output/index.ts +56 -0
  324. package/src/types/tool/index.ts +45 -0
@@ -1,14 +1,14 @@
1
1
  import { PLUGIN_NAMESPACE_SEPARATOR } from '../constants/plugin/index.js'
2
2
  import type { PluginRegistry } from '../registry/plugin/index.js'
3
- import type { ToolRegistry } from '../registry/tool/execute.js'
4
3
  import type { PluginId } from '../types/ids/index.js'
5
4
  import type { PluginContributionType } from '../types/plugin/index.js'
5
+ import type { ToolRegistryContract } from '../types/tool/index.js'
6
6
 
7
7
  export class PluginResolver {
8
8
  private pluginRegistry: PluginRegistry
9
- private toolRegistry: ToolRegistry
9
+ private toolRegistry: ToolRegistryContract
10
10
 
11
- constructor(pluginRegistry: PluginRegistry, toolRegistry: ToolRegistry) {
11
+ constructor(pluginRegistry: PluginRegistry, toolRegistry: ToolRegistryContract) {
12
12
  this.pluginRegistry = pluginRegistry
13
13
  this.toolRegistry = toolRegistry
14
14
  }
@@ -1,5 +1,6 @@
1
- import type { AgentDefinition, AgentType } from '../../types/agent/index.js'
2
- import type { Agent, BaseAgentConfig, BaseAgentResult } from '../../types/agent/index.js'
1
+ import type { AgentType, BaseAgentConfig, BaseAgentResult } from '../../types/agent/base.js'
2
+ import type { Agent } from '../../types/agent/core.js'
3
+ import type { AgentDefinition } from '../../types/agent/factory.js'
3
4
  import { type Logger, getRootLogger } from '../../utils/logger.js'
4
5
  import { Registry } from '../Registry.js'
5
6
 
@@ -7,18 +7,15 @@ import type {
7
7
  ToolAvailability,
8
8
  ToolContext,
9
9
  ToolDefinition,
10
+ ToolExecutionResult,
10
11
  ToolRegistryConfig,
11
- ToolResult,
12
12
  ToolTierConfig,
13
13
  } from '../../types/tool/index.js'
14
14
  import { toErrorMessage } from '../../utils/error.js'
15
15
  import { type Logger, getRootLogger } from '../../utils/logger.js'
16
16
  import { Registry } from '../Registry.js'
17
17
 
18
- export interface ToolExecutionResult extends ToolResult {
19
- permissionDenied?: boolean
20
- permissionMessage?: string
21
- }
18
+ export type { ToolExecutionResult }
22
19
 
23
20
  export class ToolRegistry extends Registry<ToolDefinition> {
24
21
  private log: Logger
@@ -17,14 +17,9 @@ export class DecisionParser {
17
17
  parse(rawContent: string | null): DecisionParseResult {
18
18
  if (!rawContent || rawContent.trim().length === 0) {
19
19
  return {
20
- ok: true,
21
- decision: {
22
- agentId: this.config.fallbackAgentId,
23
- confidence: 0,
24
- reasoning: 'Empty LLM response',
25
- },
26
- source: 'fallback',
27
- reason: 'empty_response',
20
+ ok: false,
21
+ error: 'Empty LLM response',
22
+ rawContent: rawContent ?? '',
28
23
  }
29
24
  }
30
25
 
@@ -34,14 +29,9 @@ export class DecisionParser {
34
29
  contentPreview: rawContent.slice(0, 200),
35
30
  })
36
31
  return {
37
- ok: true,
38
- decision: {
39
- agentId: this.config.fallbackAgentId,
40
- confidence: 0,
41
- reasoning: 'Could not extract JSON from response',
42
- },
43
- source: 'fallback',
44
- reason: 'json_extraction_failed',
32
+ ok: false,
33
+ error: 'Could not extract JSON from response',
34
+ rawContent,
45
35
  }
46
36
  }
47
37
 
@@ -54,14 +44,9 @@ export class DecisionParser {
54
44
  contentPreview: jsonStr.slice(0, 200),
55
45
  })
56
46
  return {
57
- ok: true,
58
- decision: {
59
- agentId: this.config.fallbackAgentId,
60
- confidence: 0,
61
- reasoning: `JSON parse failed: ${String(err)}`,
62
- },
63
- source: 'fallback',
64
- reason: 'json_parse_failed',
47
+ ok: false,
48
+ error: `JSON parse failed: ${String(err)}`,
49
+ rawContent: jsonStr,
65
50
  }
66
51
  }
67
52
 
@@ -74,14 +59,9 @@ export class DecisionParser {
74
59
  this.log.warn('Routing response failed schema validation', { errors })
75
60
 
76
61
  return {
77
- ok: true,
78
- decision: {
79
- agentId: this.config.fallbackAgentId,
80
- confidence: 0,
81
- reasoning: `Schema validation failed: ${errors}`,
82
- },
83
- source: 'fallback',
84
- reason: 'schema_validation_failed',
62
+ ok: false,
63
+ error: `Schema validation failed: ${errors}`,
64
+ rawContent: jsonStr,
85
65
  }
86
66
  }
87
67
 
@@ -94,14 +74,9 @@ export class DecisionParser {
94
74
  })
95
75
 
96
76
  return {
97
- ok: true,
98
- decision: {
99
- agentId: this.config.fallbackAgentId,
100
- confidence: 0,
101
- reasoning: `Unknown agentId "${response.agentId}", falling back`,
102
- },
103
- source: 'fallback',
104
- reason: 'unknown_agent_id',
77
+ ok: false,
78
+ error: `Unknown agentId "${response.agentId}"`,
79
+ rawContent: jsonStr,
105
80
  }
106
81
  }
107
82
 
@@ -1,11 +1,10 @@
1
1
  import { createHash } from 'node:crypto'
2
- import type { ToolRegistry } from '../../registry/tool/execute.js'
3
2
  import type { AgentContextLevel } from '../../types/agent/factory.js'
4
3
  import type { ThreadId } from '../../types/ids/index.js'
5
4
  import type { AgentPersona } from '../../types/persona/index.js'
6
5
  import type { Skill } from '../../types/skills/index.js'
7
- import { PromptBuilder } from './prompt.js'
8
- import type { PromptSegments } from './prompt.js'
6
+ import type { ToolRegistryContract } from '../../types/tool/index.js'
7
+ import { PromptBuilder, type PromptSegments } from './prompt.js'
9
8
 
10
9
  export interface ContextCacheConfig {
11
10
  agentId: string
@@ -17,7 +16,7 @@ export interface PromptCacheInput {
17
16
  persona?: AgentPersona
18
17
  skills?: Skill[]
19
18
  basePrompt?: string
20
- tools: ToolRegistry
19
+ tools: ToolRegistryContract
21
20
  allowedTools?: string[]
22
21
  }
23
22
 
@@ -10,8 +10,7 @@ import type { LLMProvider } from '../../types/provider/index.js'
10
10
  import type { AgentRunConfig } from '../../types/run/index.js'
11
11
  import type { ModelPricing } from '../../utils/cost.js'
12
12
  import { generateRunId } from '../../utils/id.js'
13
- import type { Logger } from '../../utils/logger.js'
14
- import { getRootLogger } from '../../utils/logger.js'
13
+ import { type Logger, getRootLogger } from '../../utils/logger.js'
15
14
 
16
15
  export interface RunContextConfig {
17
16
  agentId: string
@@ -29,10 +29,10 @@ export class EventTranslator {
29
29
  }
30
30
 
31
31
  wireActivityStore(activityStore: ActivityStore, runId: RunId): void {
32
- activityStore.on((event: ActivityEvent) => {
32
+ activityStore.on(async (event: ActivityEvent) => {
33
33
  const activity = event.activity
34
34
  if (event.type === 'activity.created') {
35
- this.emitEvent({
35
+ await this.emitEvent({
36
36
  type: 'activity_created',
37
37
  runId,
38
38
  activityId: activity.id,
@@ -40,7 +40,7 @@ export class EventTranslator {
40
40
  description: activity.description,
41
41
  })
42
42
  } else {
43
- this.emitEvent({
43
+ await this.emitEvent({
44
44
  type: 'activity_updated',
45
45
  runId,
46
46
  activityId: activity.id,
@@ -53,13 +53,13 @@ export class EventTranslator {
53
53
  }
54
54
 
55
55
  wireTaskStore(taskStore: TaskStore, runId: RunId): () => void {
56
- const unsubscribe = taskStore.on((event: TaskEvent) => {
56
+ const unsubscribe = taskStore.on(async (event: TaskEvent) => {
57
57
  const task = event.task
58
58
 
59
59
  if (task.runId !== runId) return
60
60
  switch (event.type) {
61
61
  case 'task.created':
62
- this.emitEvent({
62
+ await this.emitEvent({
63
63
  type: 'task_created',
64
64
  runId,
65
65
  taskId: task.id,
@@ -70,7 +70,7 @@ export class EventTranslator {
70
70
  case 'task.updated':
71
71
  case 'task.claimed':
72
72
  case 'task.deleted':
73
- this.emitEvent({
73
+ await this.emitEvent({
74
74
  type: 'task_updated',
75
75
  runId,
76
76
  taskId: task.id,
@@ -89,11 +89,11 @@ export class EventTranslator {
89
89
  }
90
90
 
91
91
  wirePlanManager(planManager: PlanManager, runId: RunId): void {
92
- planManager.on((event: PlanEvent) => {
92
+ planManager.on(async (event: PlanEvent) => {
93
93
  const plan = event.plan
94
94
  switch (event.type) {
95
95
  case 'plan.ready':
96
- this.emitEvent({
96
+ await this.emitEvent({
97
97
  type: 'plan_ready',
98
98
  runId,
99
99
  planId: plan.id,
@@ -103,14 +103,14 @@ export class EventTranslator {
103
103
  })
104
104
  break
105
105
  case 'plan.approved':
106
- this.emitEvent({
106
+ await this.emitEvent({
107
107
  type: 'plan_approved',
108
108
  runId,
109
109
  planId: plan.id,
110
110
  })
111
111
  break
112
112
  case 'plan.rejected':
113
- this.emitEvent({
113
+ await this.emitEvent({
114
114
  type: 'plan_rejected',
115
115
  runId,
116
116
  planId: plan.id,
@@ -119,7 +119,7 @@ export class EventTranslator {
119
119
  break
120
120
  case 'plan.step_updated':
121
121
  if (event.step) {
122
- this.emitEvent({
122
+ await this.emitEvent({
123
123
  type: 'plan_step_updated',
124
124
  runId,
125
125
  planId: plan.id,
@@ -1,27 +1,28 @@
1
1
  import { extractFromToolCall, extractFromToolResult } from '../../compaction/extractor.js'
2
2
  import type { WorkingStateManager } from '../../compaction/manager.js'
3
- import type { ToolRegistry } from '../../registry/tool/execute.js'
4
3
  import type { ActivityStore } from '../../store/activity/memory.js'
5
4
  import type { RunId } from '../../types/ids/index.js'
5
+ import type { InvocationState } from '../../types/invocation/index.js'
6
6
  import { type Message, createToolMessage } from '../../types/message/index.js'
7
7
  import type { PermissionMode } from '../../types/permission/index.js'
8
8
  import type { ChatCompletionResponse } from '../../types/provider/index.js'
9
9
  import type { RunEvent } from '../../types/run/index.js'
10
10
  import type { Sandbox } from '../../types/sandbox/index.js'
11
- import type { ToolContext } from '../../types/tool/index.js'
11
+ import type { ToolContext, ToolRegistryContract } from '../../types/tool/index.js'
12
12
  import type { Logger } from '../../utils/logger.js'
13
13
  import { compressShellOutput } from '../../utils/shell-compress.js'
14
14
 
15
15
  export type EmitEvent = (event: RunEvent) => Promise<void>
16
16
 
17
17
  export interface ToolExecutorConfig {
18
- tools: ToolRegistry
18
+ tools: ToolRegistryContract
19
19
  runId: RunId
20
20
  workingDirectory: string
21
21
  permissionMode: PermissionMode
22
22
  env: Record<string, string>
23
23
  abortSignal: AbortSignal
24
24
  sandbox?: Sandbox
25
+ invocationState?: InvocationState
25
26
  }
26
27
 
27
28
  export interface ToolExecutionBatch {
@@ -91,6 +92,7 @@ export class ToolExecutor {
91
92
  runId: this.config.runId,
92
93
  workingDirectory: this.config.workingDirectory,
93
94
  },
95
+ invocationState: this.config.invocationState,
94
96
  toolRegistry: this.config.tools,
95
97
  sandbox: this.config.sandbox,
96
98
  }
@@ -8,7 +8,6 @@ import { extractFromUserMessage } from '../../compaction/extractor.js'
8
8
  import { WorkingStateManager } from '../../compaction/manager.js'
9
9
  import type { CompactionConfig } from '../../config/runtime.js'
10
10
  import { getTracer } from '../../provider/telemetry/setup.js'
11
- import type { ToolRegistry } from '../../registry/tool/execute.js'
12
11
  import { GENAI, NAMZU, agentRunSpanName } from '../../telemetry/attributes.js'
13
12
  import { buildAdvisoryTools } from '../../tools/advisory/index.js'
14
13
  import { SearchToolsTool } from '../../tools/builtins/search-tools.js'
@@ -16,9 +15,13 @@ import { buildTaskTools } from '../../tools/task/index.js'
16
15
  import type { AdvisoryConfig } from '../../types/advisory/index.js'
17
16
  import type { RuntimeToolOverrides } from '../../types/agent/base.js'
18
17
  import type { AgentContextLevel } from '../../types/agent/factory.js'
19
- import type { CheckpointId, ResumeHandler } from '../../types/hitl/index.js'
20
- import { autoApproveHandler } from '../../types/hitl/index.js'
18
+ import {
19
+ type CheckpointId,
20
+ type ResumeHandler,
21
+ autoApproveHandler,
22
+ } from '../../types/hitl/index.js'
21
23
  import type { RunId, ThreadId } from '../../types/ids/index.js'
24
+ import type { InvocationState } from '../../types/invocation/index.js'
22
25
  import { type Message, createSystemMessage } from '../../types/message/index.js'
23
26
  import type { AgentPersona } from '../../types/persona/index.js'
24
27
  import type { LLMProvider } from '../../types/provider/index.js'
@@ -27,6 +30,7 @@ import type { AgentRun, AgentRunConfig, RunEvent, RunEventListener } from '../..
27
30
  import type { Sandbox, SandboxProvider } from '../../types/sandbox/index.js'
28
31
  import type { Skill } from '../../types/skills/index.js'
29
32
  import type { TaskStore } from '../../types/task/index.js'
33
+ import type { ToolRegistryContract } from '../../types/tool/index.js'
30
34
  import type { VerificationGateConfig } from '../../types/verification/index.js'
31
35
  import type { ModelPricing } from '../../utils/cost.js'
32
36
  import { VerificationGate } from '../../verification/gate.js'
@@ -47,7 +51,7 @@ export interface QueryParams {
47
51
  skills?: Skill[]
48
52
  basePrompt?: string
49
53
  provider: LLMProvider
50
- tools: ToolRegistry
54
+ tools: ToolRegistryContract
51
55
  runConfig: AgentRunConfig
52
56
  allowedTools?: string[]
53
57
  agentId: string
@@ -102,6 +106,8 @@ export interface QueryParams {
102
106
  pluginManager?: import('../../plugin/lifecycle.js').PluginLifecycleManager
103
107
 
104
108
  sandboxProvider?: SandboxProvider
109
+
110
+ invocationState?: InvocationState
105
111
  }
106
112
 
107
113
  export async function* query(params: QueryParams): AsyncGenerator<RunEvent, AgentRun> {
@@ -186,6 +192,7 @@ export async function* query(params: QueryParams): AsyncGenerator<RunEvent, Agen
186
192
  permissionMode: ctx.permissionMode,
187
193
  env: params.runConfig.env ?? {},
188
194
  abortSignal: ctx.abortController.signal,
195
+ invocationState: params.invocationState,
189
196
  },
190
197
  ctx.activityStore,
191
198
  eventTranslator.emitEvent,
@@ -6,13 +6,13 @@ import type { CompactionConfig } from '../../../config/runtime.js'
6
6
  import type { PlanManager } from '../../../manager/plan/lifecycle.js'
7
7
  import type { RunPersistence } from '../../../manager/run/persistence.js'
8
8
  import { getTracer } from '../../../provider/telemetry/setup.js'
9
- import type { ToolRegistry } from '../../../registry/tool/execute.js'
10
9
  import type { ActivityStore } from '../../../store/activity/memory.js'
11
10
  import { GENAI, NAMZU, agentIterationSpanName } from '../../../telemetry/attributes.js'
12
11
  import type { ResumeHandler } from '../../../types/hitl/index.js'
13
12
  import { createAssistantMessage, createUserMessage } from '../../../types/message/index.js'
14
13
  import type { LLMProvider } from '../../../types/provider/index.js'
15
14
  import type { AgentRunConfig, RunEvent, StopReason } from '../../../types/run/index.js'
15
+ import type { ToolRegistryContract } from '../../../types/tool/index.js'
16
16
  import { toErrorMessage } from '../../../utils/error.js'
17
17
  import type { Logger } from '../../../utils/logger.js'
18
18
  import type { CheckpointManager } from '../checkpoint.js'
@@ -33,7 +33,7 @@ export type { ToolReviewOutcome } from './phases/index.js'
33
33
  export interface IterationConfig {
34
34
  provider: LLMProvider
35
35
  runConfig: AgentRunConfig
36
- tools: ToolRegistry
36
+ tools: ToolRegistryContract
37
37
  allowedTools?: string[]
38
38
  taskGateway?: import('../../../types/agent/gateway.js').TaskGateway
39
39
  taskStore?: import('../../../types/task/index.js').TaskStore
@@ -1,6 +1,5 @@
1
1
  import { serializeState } from '../../../../compaction/serializer.js'
2
- import type { AdvisoryRequest } from '../../../../types/advisory/index.js'
3
- import type { TriggerEvaluationState } from '../../../../types/advisory/index.js'
2
+ import type { AdvisoryRequest, TriggerEvaluationState } from '../../../../types/advisory/index.js'
4
3
  import { createUserMessage } from '../../../../types/message/index.js'
5
4
  import type { ChatCompletionResponse } from '../../../../types/provider/index.js'
6
5
  import { toErrorMessage } from '../../../../utils/error.js'
@@ -1,7 +1,6 @@
1
1
  import type { RunEvent } from '../../../../types/run/index.js'
2
2
  import { CheckpointManager } from '../../checkpoint.js'
3
- import type { IterationContext, PhaseSignal } from './context.js'
4
- import { handleHITLDecision } from './context.js'
3
+ import { type IterationContext, type PhaseSignal, handleHITLDecision } from './context.js'
5
4
 
6
5
  export async function* runIterationCheckpoint(
7
6
  ctx: IterationContext,
@@ -4,7 +4,6 @@ import type { WorkingStateManager } from '../../../../compaction/manager.js'
4
4
  import type { CompactionConfig } from '../../../../config/runtime.js'
5
5
  import type { PlanManager } from '../../../../manager/plan/lifecycle.js'
6
6
  import type { RunPersistence } from '../../../../manager/run/persistence.js'
7
- import type { ToolRegistry } from '../../../../registry/tool/execute.js'
8
7
  import type { ActivityStore } from '../../../../store/activity/memory.js'
9
8
  import type { TaskGateway, TaskHandle } from '../../../../types/agent/gateway.js'
10
9
  import type { HITLResumeDecision, ResumeHandler } from '../../../../types/hitl/index.js'
@@ -12,6 +11,7 @@ import type { TaskId } from '../../../../types/ids/index.js'
12
11
  import type { LLMProvider } from '../../../../types/provider/index.js'
13
12
  import type { AgentRunConfig, RunEvent } from '../../../../types/run/index.js'
14
13
  import type { TaskStore } from '../../../../types/task/index.js'
14
+ import type { ToolRegistryContract } from '../../../../types/tool/index.js'
15
15
  import type { Logger } from '../../../../utils/logger.js'
16
16
  import type { CheckpointManager } from '../../checkpoint.js'
17
17
  import type { EmitEvent } from '../../events.js'
@@ -27,7 +27,7 @@ export interface LaunchedTaskMeta {
27
27
  export interface IterationContext {
28
28
  readonly provider: LLMProvider
29
29
  readonly runConfig: AgentRunConfig
30
- readonly tools: ToolRegistry
30
+ readonly tools: ToolRegistryContract
31
31
  readonly allowedTools?: string[]
32
32
  readonly runMgr: RunPersistence
33
33
  readonly toolExecutor: ToolExecutor
@@ -1,6 +1,5 @@
1
1
  import type { RunEvent } from '../../../../types/run/index.js'
2
- import type { IterationContext, PhaseSignal } from './context.js'
3
- import { handleHITLDecision } from './context.js'
2
+ import { type IterationContext, type PhaseSignal, handleHITLDecision } from './context.js'
4
3
 
5
4
  export async function* runPlanGate(ctx: IterationContext): AsyncGenerator<RunEvent, PhaseSignal> {
6
5
  if (!ctx.planManager.active || ctx.planManager.active.status !== 'ready') {
@@ -1,9 +1,9 @@
1
1
  import { FILESYSTEM_TOOLS } from '../../constants/tools/index.js'
2
2
  import { assembleSystemPrompt } from '../../persona/assembler.js'
3
- import type { ToolRegistry } from '../../registry/tool/execute.js'
4
3
  import type { AgentContextLevel } from '../../types/agent/factory.js'
5
4
  import type { AgentPersona } from '../../types/persona/index.js'
6
5
  import type { Skill } from '../../types/skills/index.js'
6
+ import type { ToolRegistryContract } from '../../types/tool/index.js'
7
7
 
8
8
  export interface PromptSegments {
9
9
  /** Layers 1-6: basePrompt, persona identity/expertise/reflexes/skills/outputDiscipline. Stable within a run. */
@@ -21,7 +21,7 @@ export interface PromptBuilderConfig {
21
21
 
22
22
  basePrompt?: string
23
23
 
24
- tools: ToolRegistry
24
+ tools: ToolRegistryContract
25
25
  allowedTools?: string[]
26
26
  }
27
27
 
@@ -34,7 +34,7 @@ Platform: ${process.platform}
34
34
  IMPORTANT: Always use absolute paths based on the working directory above. Before reading a file, use the glob tool to discover actual file paths — never guess or hallucinate paths.`
35
35
  }
36
36
 
37
- function hasFilesystemTools(tools: ToolRegistry, allowedTools?: string[]): boolean {
37
+ function hasFilesystemTools(tools: ToolRegistryContract, allowedTools?: string[]): boolean {
38
38
  const activeTools = allowedTools ?? tools.listNames()
39
39
  return activeTools.some((name) => FILESYSTEM_TOOLS.has(name))
40
40
  }
@@ -1,5 +1,4 @@
1
- import { SpanStatusCode } from '@opentelemetry/api'
2
- import type { Span } from '@opentelemetry/api'
1
+ import { type Span, SpanStatusCode } from '@opentelemetry/api'
3
2
  import type { PlanManager } from '../../manager/plan/lifecycle.js'
4
3
  import type { RunPersistence } from '../../manager/run/persistence.js'
5
4
  import type { ActivityStore } from '../../store/activity/memory.js'
@@ -1,20 +1,22 @@
1
- import type { ToolRegistry } from '../../registry/tool/execute.js'
2
1
  import type { ActivityStore } from '../../store/activity/memory.js'
3
2
  import type { RunId } from '../../types/ids/index.js'
3
+ import type { InvocationState } from '../../types/invocation/index.js'
4
4
  import type { PermissionMode } from '../../types/permission/index.js'
5
5
  import type { RunEvent } from '../../types/run/index.js'
6
+ import type { ToolRegistryContract } from '../../types/tool/index.js'
6
7
  import type { Logger } from '../../utils/logger.js'
7
8
  import { ToolExecutor } from './executor.js'
8
9
 
9
10
  export type EmitEvent = (event: RunEvent) => Promise<void>
10
11
 
11
12
  export interface ToolingBootstrapConfig {
12
- tools: ToolRegistry
13
+ tools: ToolRegistryContract
13
14
  runId: RunId
14
15
  workingDirectory: string
15
16
  permissionMode: PermissionMode
16
17
  env: Record<string, string>
17
18
  abortSignal: AbortSignal
19
+ invocationState?: InvocationState
18
20
  }
19
21
 
20
22
  export class ToolingBootstrap {
@@ -32,6 +34,7 @@ export class ToolingBootstrap {
32
34
  permissionMode: config.permissionMode,
33
35
  env: config.env,
34
36
  abortSignal: config.abortSignal,
37
+ invocationState: config.invocationState,
35
38
  },
36
39
  activityStore,
37
40
  emitEvent,
@@ -1,7 +1,11 @@
1
+ import { findSafeTrimIndex } from '../../compaction/dangling.js'
1
2
  import type { ConversationStore } from '../../types/conversation/index.js'
2
3
  import type { MessageId, RunId, ThreadId } from '../../types/ids/index.js'
3
- import type { Message } from '../../types/message/index.js'
4
- import { createAssistantMessage, createUserMessage } from '../../types/message/index.js'
4
+ import {
5
+ type Message,
6
+ createAssistantMessage,
7
+ createUserMessage,
8
+ } from '../../types/message/index.js'
5
9
  import { extractFinalResponse } from '../../utils/conversation.js'
6
10
  import { generateMessageId } from '../../utils/id.js'
7
11
 
@@ -35,16 +39,28 @@ export class InMemoryConversationStore implements ConversationStore {
35
39
  const messages = this.threads.get(threadId)
36
40
  if (!messages) return []
37
41
 
38
- const slice = messages.length > this.maxMessages ? messages.slice(-this.maxMessages) : messages
39
-
40
- return slice.map((m) => {
42
+ // Convert to Message type for trim safety check
43
+ const convertedMessages: Message[] = messages.map((m) => {
41
44
  switch (m.role) {
42
45
  case 'user':
43
46
  return createUserMessage(m.content)
44
47
  case 'assistant':
45
48
  return createAssistantMessage(m.content)
49
+ default: {
50
+ const _exhaustive: never = m.role
51
+ throw new Error(`Unhandled message role: ${_exhaustive}`)
52
+ }
46
53
  }
47
54
  })
55
+
56
+ // Apply safe trimming to preserve tool call/result atomicity
57
+ let trimStartIdx = 0
58
+ if (convertedMessages.length > this.maxMessages) {
59
+ const desiredTrimPoint = convertedMessages.length - this.maxMessages
60
+ trimStartIdx = findSafeTrimIndex(convertedMessages, desiredTrimPoint)
61
+ }
62
+
63
+ return convertedMessages.slice(trimStartIdx)
48
64
  }
49
65
 
50
66
  persistRunResult(threadId: ThreadId, runId: RunId, messages: Message[]): void {
@@ -1,8 +1,7 @@
1
1
  import { appendFile, mkdir, readFile, readdir, rename, unlink, writeFile } from 'node:fs/promises'
2
2
  import { join } from 'node:path'
3
3
  import type { CheckpointId, IterationCheckpoint } from '../../types/hitl/index.js'
4
- import type { AgentRun, RunEvent } from '../../types/run/index.js'
5
- import type { RunStoreConfig } from '../../types/run/index.js'
4
+ import type { AgentRun, RunEvent, RunStoreConfig } from '../../types/run/index.js'
6
5
  import { type Logger, getRootLogger } from '../../utils/logger.js'
7
6
 
8
7
  export class RunDiskStore {
@@ -96,8 +95,9 @@ export class RunDiskStore {
96
95
  try {
97
96
  const content = await readFile(join(dir, 'checkpoints', `${checkpointId}.json`), 'utf-8')
98
97
  return JSON.parse(content) as IterationCheckpoint
99
- } catch {
100
- return null
98
+ } catch (err) {
99
+ if (isFileNotFound(err)) return null
100
+ throw err
101
101
  }
102
102
  }
103
103
 
@@ -117,8 +117,9 @@ export class RunDiskStore {
117
117
  }
118
118
  }
119
119
  return checkpoints.sort((a, b) => a.createdAt - b.createdAt)
120
- } catch {
121
- return []
120
+ } catch (err) {
121
+ if (isFileNotFound(err)) return []
122
+ throw err
122
123
  }
123
124
  }
124
125
 
@@ -126,7 +127,9 @@ export class RunDiskStore {
126
127
  const dir = this.requireInit()
127
128
  try {
128
129
  await unlink(join(dir, 'checkpoints', `${checkpointId}.json`))
129
- } catch {}
130
+ } catch (err) {
131
+ if (!isFileNotFound(err)) throw err
132
+ }
130
133
  }
131
134
 
132
135
  static async listRuns(baseDir: string): Promise<
@@ -142,8 +145,9 @@ export class RunDiskStore {
142
145
  const indexPath = join(baseDir, 'index.json')
143
146
  const content = await readFile(indexPath, 'utf-8')
144
147
  return JSON.parse(content)
145
- } catch {
146
- return []
148
+ } catch (err) {
149
+ if (isFileNotFound(err)) return []
150
+ throw err
147
151
  }
148
152
  }
149
153
 
@@ -166,13 +170,7 @@ export class RunDiskStore {
166
170
  const content = await readFile(indexPath, 'utf-8')
167
171
  index = JSON.parse(content)
168
172
  } catch (err) {
169
- const isNotFound =
170
- typeof err === 'object' &&
171
- err !== null &&
172
- (err as NodeJS.ErrnoException).code === 'ENOENT'
173
- if (!isNotFound) {
174
- this.log.warn('Failed to read run index — starting fresh', { error: String(err) })
175
- }
173
+ if (!isFileNotFound(err)) throw err
176
174
  }
177
175
 
178
176
  const entry = {
@@ -216,6 +214,10 @@ async function atomicWriteJson(filePath: string, value: unknown): Promise<void>
216
214
  await atomicWriteFile(filePath, JSON.stringify(value, null, 2))
217
215
  }
218
216
 
217
+ function isFileNotFound(err: unknown): boolean {
218
+ return typeof err === 'object' && err !== null && (err as NodeJS.ErrnoException).code === 'ENOENT'
219
+ }
220
+
219
221
  export const SessionStore = RunDiskStore
220
222
 
221
223
  export type SessionStore = RunDiskStore