kiokuko-dsh 0.2.7 → 0.2.9

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 (481) hide show
  1. package/PERMISSIONS.md +1 -1
  2. package/README.ja.md +38 -11
  3. package/README.ko.md +34 -3
  4. package/README.md +39 -13
  5. package/README.zh-CN.md +34 -3
  6. package/THIRD_PARTY_NOTICES.md +4 -0
  7. package/dist/db/transaction.d.ts +2 -1
  8. package/dist/db/transaction.d.ts.map +1 -1
  9. package/dist/db/transaction.js +44 -7
  10. package/dist/db/transaction.js.map +1 -1
  11. package/dist/deep-planning-config.d.ts +32 -0
  12. package/dist/deep-planning-config.d.ts.map +1 -0
  13. package/dist/deep-planning-config.js +20 -0
  14. package/dist/deep-planning-config.js.map +1 -0
  15. package/dist/deep-thinker/core/contracts.d.ts +1 -29
  16. package/dist/deep-thinker/core/contracts.d.ts.map +1 -1
  17. package/dist/deep-thinker/core/contracts.js +2 -17
  18. package/dist/deep-thinker/core/contracts.js.map +1 -1
  19. package/dist/deep-thinker/memory-finalizer.d.ts.map +1 -1
  20. package/dist/deep-thinker/memory-finalizer.js +1 -114
  21. package/dist/deep-thinker/memory-finalizer.js.map +1 -1
  22. package/dist/deep-thinker/native-executor.d.ts.map +1 -1
  23. package/dist/deep-thinker/native-executor.js +3 -4
  24. package/dist/deep-thinker/native-executor.js.map +1 -1
  25. package/dist/deep-thinker/store.js +1 -2
  26. package/dist/deep-thinker/store.js.map +1 -1
  27. package/dist/dsh/agenticreplay-event-mapper.d.ts +1 -1
  28. package/dist/dsh/agenticreplay-event-mapper.d.ts.map +1 -1
  29. package/dist/dsh/agenticreplay-event-mapper.js +5 -1
  30. package/dist/dsh/agenticreplay-event-mapper.js.map +1 -1
  31. package/dist/dsh/agenticreplay-files.d.ts +1 -0
  32. package/dist/dsh/agenticreplay-files.d.ts.map +1 -1
  33. package/dist/dsh/agenticreplay-files.js +19 -2
  34. package/dist/dsh/agenticreplay-files.js.map +1 -1
  35. package/dist/dsh/agenticreplay-host.js +3 -3
  36. package/dist/dsh/agenticreplay-host.js.map +1 -1
  37. package/dist/dsh/agenticreplay-read-service.d.ts +20 -0
  38. package/dist/dsh/agenticreplay-read-service.d.ts.map +1 -1
  39. package/dist/dsh/agenticreplay-read-service.js +27 -0
  40. package/dist/dsh/agenticreplay-read-service.js.map +1 -1
  41. package/dist/dsh/agenticreplay-recorder.d.ts +18 -12
  42. package/dist/dsh/agenticreplay-recorder.d.ts.map +1 -1
  43. package/dist/dsh/agenticreplay-recorder.js +43 -13
  44. package/dist/dsh/agenticreplay-recorder.js.map +1 -1
  45. package/dist/dsh/agenticreplay-security.d.ts +1 -0
  46. package/dist/dsh/agenticreplay-security.d.ts.map +1 -1
  47. package/dist/dsh/agenticreplay-security.js +84 -3
  48. package/dist/dsh/agenticreplay-security.js.map +1 -1
  49. package/dist/dsh/answer-review/coordinator.js +2 -1
  50. package/dist/dsh/answer-review/coordinator.js.map +1 -1
  51. package/dist/dsh/auto-memory-review.d.ts.map +1 -1
  52. package/dist/dsh/auto-memory-review.js +10 -193
  53. package/dist/dsh/auto-memory-review.js.map +1 -1
  54. package/dist/dsh/coding-workflow/contracts.d.ts +2 -0
  55. package/dist/dsh/coding-workflow/contracts.d.ts.map +1 -1
  56. package/dist/dsh/coding-workflow/contracts.js.map +1 -1
  57. package/dist/dsh/coding-workflow/intent.d.ts.map +1 -1
  58. package/dist/dsh/coding-workflow/intent.js +12 -4
  59. package/dist/dsh/coding-workflow/intent.js.map +1 -1
  60. package/dist/dsh/coding-workflow/service.d.ts +10 -81
  61. package/dist/dsh/coding-workflow/service.d.ts.map +1 -1
  62. package/dist/dsh/coding-workflow/service.js +52 -1
  63. package/dist/dsh/coding-workflow/service.js.map +1 -1
  64. package/dist/dsh/coding-workflow/store.d.ts +22 -0
  65. package/dist/dsh/coding-workflow/store.d.ts.map +1 -1
  66. package/dist/dsh/coding-workflow/store.js +51 -0
  67. package/dist/dsh/coding-workflow/store.js.map +1 -1
  68. package/dist/dsh/completion-verifiers.d.ts +6 -0
  69. package/dist/dsh/completion-verifiers.d.ts.map +1 -1
  70. package/dist/dsh/completion-verifiers.js.map +1 -1
  71. package/dist/dsh/composition.d.ts +2 -0
  72. package/dist/dsh/composition.d.ts.map +1 -1
  73. package/dist/dsh/composition.js +3 -0
  74. package/dist/dsh/composition.js.map +1 -1
  75. package/dist/dsh/config.d.ts +1 -1
  76. package/dist/dsh/config.d.ts.map +1 -1
  77. package/dist/dsh/config.js +3 -3
  78. package/dist/dsh/config.js.map +1 -1
  79. package/dist/dsh/core/host.d.ts.map +1 -1
  80. package/dist/dsh/core/host.js +159 -34
  81. package/dist/dsh/core/host.js.map +1 -1
  82. package/dist/dsh/core/tasks.d.ts +5 -2
  83. package/dist/dsh/core/tasks.d.ts.map +1 -1
  84. package/dist/dsh/core/tasks.js +124 -93
  85. package/dist/dsh/core/tasks.js.map +1 -1
  86. package/dist/dsh/decisions/request-intent.d.ts +114 -1
  87. package/dist/dsh/decisions/request-intent.d.ts.map +1 -1
  88. package/dist/dsh/decisions/request-intent.js +102 -18
  89. package/dist/dsh/decisions/request-intent.js.map +1 -1
  90. package/dist/dsh/execution-result.d.ts +1 -0
  91. package/dist/dsh/execution-result.d.ts.map +1 -1
  92. package/dist/dsh/execution-support.d.ts +2 -0
  93. package/dist/dsh/execution-support.d.ts.map +1 -1
  94. package/dist/dsh/execution-support.js +39 -4
  95. package/dist/dsh/execution-support.js.map +1 -1
  96. package/dist/dsh/existing-task-intake.d.ts +22 -0
  97. package/dist/dsh/existing-task-intake.d.ts.map +1 -0
  98. package/dist/dsh/existing-task-intake.js +46 -0
  99. package/dist/dsh/existing-task-intake.js.map +1 -0
  100. package/dist/dsh/finalization-request.d.ts +1 -1
  101. package/dist/dsh/finalization-request.d.ts.map +1 -1
  102. package/dist/dsh/finalization-request.js +1 -1
  103. package/dist/dsh/finalization-request.js.map +1 -1
  104. package/dist/dsh/guardrail/contracts.d.ts +85 -0
  105. package/dist/dsh/guardrail/contracts.d.ts.map +1 -0
  106. package/dist/dsh/guardrail/contracts.js +10 -0
  107. package/dist/dsh/guardrail/contracts.js.map +1 -0
  108. package/dist/dsh/guardrail/engine.d.ts +19 -0
  109. package/dist/dsh/guardrail/engine.d.ts.map +1 -0
  110. package/dist/dsh/guardrail/engine.js +178 -0
  111. package/dist/dsh/guardrail/engine.js.map +1 -0
  112. package/dist/dsh/guardrail/evidence.d.ts +16 -0
  113. package/dist/dsh/guardrail/evidence.d.ts.map +1 -0
  114. package/dist/dsh/guardrail/evidence.js +101 -0
  115. package/dist/dsh/guardrail/evidence.js.map +1 -0
  116. package/dist/dsh/guardrail/service.d.ts +27 -0
  117. package/dist/dsh/guardrail/service.d.ts.map +1 -0
  118. package/dist/dsh/guardrail/service.js +253 -0
  119. package/dist/dsh/guardrail/service.js.map +1 -0
  120. package/dist/dsh/host-adapter/admission.d.ts.map +1 -1
  121. package/dist/dsh/host-adapter/admission.js +143 -144
  122. package/dist/dsh/host-adapter/admission.js.map +1 -1
  123. package/dist/dsh/host-adapter/lifecycle.d.ts +1 -0
  124. package/dist/dsh/host-adapter/lifecycle.d.ts.map +1 -1
  125. package/dist/dsh/host-adapter/lifecycle.js +107 -77
  126. package/dist/dsh/host-adapter/lifecycle.js.map +1 -1
  127. package/dist/dsh/host-adapter/routing.d.ts.map +1 -1
  128. package/dist/dsh/host-adapter/routing.js +4 -4
  129. package/dist/dsh/host-adapter/routing.js.map +1 -1
  130. package/dist/dsh/host-adapter/turn-state.d.ts +4 -2
  131. package/dist/dsh/host-adapter/turn-state.d.ts.map +1 -1
  132. package/dist/dsh/host-adapter/turn-state.js +14 -7
  133. package/dist/dsh/host-adapter/turn-state.js.map +1 -1
  134. package/dist/dsh/host-adapter.d.ts.map +1 -1
  135. package/dist/dsh/host-adapter.js +125 -24
  136. package/dist/dsh/host-adapter.js.map +1 -1
  137. package/dist/dsh/intake-clarification.js +2 -2
  138. package/dist/dsh/intake-clarification.js.map +1 -1
  139. package/dist/dsh/intake-gate.js +6 -7
  140. package/dist/dsh/intake-gate.js.map +1 -1
  141. package/dist/dsh/legacy-session-codecs.d.ts +1 -0
  142. package/dist/dsh/legacy-session-codecs.d.ts.map +1 -1
  143. package/dist/dsh/legacy-session-codecs.js +831 -127
  144. package/dist/dsh/legacy-session-codecs.js.map +4 -4
  145. package/dist/dsh/lifecycle-memory.d.ts +66 -0
  146. package/dist/dsh/lifecycle-memory.d.ts.map +1 -0
  147. package/dist/dsh/lifecycle-memory.js +380 -0
  148. package/dist/dsh/lifecycle-memory.js.map +1 -0
  149. package/dist/dsh/lisp/candidate.d.ts +2 -2
  150. package/dist/dsh/lisp/ci.d.ts +2 -1
  151. package/dist/dsh/lisp/ci.d.ts.map +1 -1
  152. package/dist/dsh/lisp/ci.js +15 -2
  153. package/dist/dsh/lisp/ci.js.map +1 -1
  154. package/dist/dsh/lisp/contracts.d.ts +1 -18
  155. package/dist/dsh/lisp/contracts.d.ts.map +1 -1
  156. package/dist/dsh/lisp/contracts.js +1 -10
  157. package/dist/dsh/lisp/contracts.js.map +1 -1
  158. package/dist/dsh/lisp/files.d.ts +1 -1
  159. package/dist/dsh/lisp/files.d.ts.map +1 -1
  160. package/dist/dsh/lisp/files.js +17 -4
  161. package/dist/dsh/lisp/files.js.map +1 -1
  162. package/dist/dsh/lisp/hot-store.d.ts.map +1 -1
  163. package/dist/dsh/lisp/hot-store.js +4 -0
  164. package/dist/dsh/lisp/hot-store.js.map +1 -1
  165. package/dist/dsh/lisp/hot-tools.d.ts +2 -0
  166. package/dist/dsh/lisp/hot-tools.d.ts.map +1 -1
  167. package/dist/dsh/lisp/hot-tools.js +10 -0
  168. package/dist/dsh/lisp/hot-tools.js.map +1 -1
  169. package/dist/dsh/lisp/manager.d.ts +14 -1
  170. package/dist/dsh/lisp/manager.d.ts.map +1 -1
  171. package/dist/dsh/lisp/manager.js +238 -37
  172. package/dist/dsh/lisp/manager.js.map +1 -1
  173. package/dist/dsh/lisp/memory-verification.d.ts +5 -2
  174. package/dist/dsh/lisp/memory-verification.d.ts.map +1 -1
  175. package/dist/dsh/lisp/memory-verification.js +5 -1
  176. package/dist/dsh/lisp/memory-verification.js.map +1 -1
  177. package/dist/dsh/lisp/package-manager.d.ts +1 -1
  178. package/dist/dsh/lisp/package-manager.d.ts.map +1 -1
  179. package/dist/dsh/lisp/package-manager.js +10 -1
  180. package/dist/dsh/lisp/package-manager.js.map +1 -1
  181. package/dist/dsh/lisp/packages.d.ts +1 -1
  182. package/dist/dsh/lisp/packages.d.ts.map +1 -1
  183. package/dist/dsh/lisp/packages.js +15 -5
  184. package/dist/dsh/lisp/packages.js.map +1 -1
  185. package/dist/dsh/lisp/proposal-batch.d.ts +2 -0
  186. package/dist/dsh/lisp/proposal-batch.d.ts.map +1 -1
  187. package/dist/dsh/lisp/proposal-batch.js +17 -3
  188. package/dist/dsh/lisp/proposal-batch.js.map +1 -1
  189. package/dist/dsh/lisp/request-surface.d.ts +12 -0
  190. package/dist/dsh/lisp/request-surface.d.ts.map +1 -1
  191. package/dist/dsh/lisp/store.d.ts +2 -1
  192. package/dist/dsh/lisp/store.d.ts.map +1 -1
  193. package/dist/dsh/lisp/store.js +5 -1
  194. package/dist/dsh/lisp/store.js.map +1 -1
  195. package/dist/dsh/lisp/surface.d.ts.map +1 -1
  196. package/dist/dsh/lisp/surface.js +107 -13
  197. package/dist/dsh/lisp/surface.js.map +1 -1
  198. package/dist/dsh/lisp/task-authority.d.ts +29 -0
  199. package/dist/dsh/lisp/task-authority.d.ts.map +1 -0
  200. package/dist/dsh/lisp/task-authority.js +87 -0
  201. package/dist/dsh/lisp/task-authority.js.map +1 -0
  202. package/dist/dsh/lisp/worker.d.ts +3 -1
  203. package/dist/dsh/lisp/worker.d.ts.map +1 -1
  204. package/dist/dsh/lisp/worker.js +26 -4
  205. package/dist/dsh/lisp/worker.js.map +1 -1
  206. package/dist/dsh/lisp-config.d.ts +21 -0
  207. package/dist/dsh/lisp-config.d.ts.map +1 -0
  208. package/dist/dsh/lisp-config.js +13 -0
  209. package/dist/dsh/lisp-config.js.map +1 -0
  210. package/dist/dsh/memory-application.d.ts +3 -2
  211. package/dist/dsh/memory-application.d.ts.map +1 -1
  212. package/dist/dsh/memory-application.js +31 -22
  213. package/dist/dsh/memory-application.js.map +1 -1
  214. package/dist/dsh/model-handoff.d.ts.map +1 -1
  215. package/dist/dsh/model-handoff.js +2 -1
  216. package/dist/dsh/model-handoff.js.map +1 -1
  217. package/dist/dsh/models/service.d.ts.map +1 -1
  218. package/dist/dsh/models/service.js +13 -2
  219. package/dist/dsh/models/service.js.map +1 -1
  220. package/dist/dsh/models/vendor/opencode-codec.d.ts.map +1 -1
  221. package/dist/dsh/models/vendor/opencode-codec.js +71 -0
  222. package/dist/dsh/models/vendor/opencode-codec.js.map +1 -1
  223. package/dist/dsh/native-cancellation-observer.d.ts +13 -0
  224. package/dist/dsh/native-cancellation-observer.d.ts.map +1 -0
  225. package/dist/dsh/native-cancellation-observer.js +54 -0
  226. package/dist/dsh/native-cancellation-observer.js.map +1 -0
  227. package/dist/dsh/native-execution-ownership.d.ts +6 -0
  228. package/dist/dsh/native-execution-ownership.d.ts.map +1 -0
  229. package/dist/dsh/native-execution-ownership.js +34 -0
  230. package/dist/dsh/native-execution-ownership.js.map +1 -0
  231. package/dist/dsh/native-subagent.d.ts +2 -2
  232. package/dist/dsh/native-subagent.d.ts.map +1 -1
  233. package/dist/dsh/native-subagent.js +2 -3
  234. package/dist/dsh/native-subagent.js.map +1 -1
  235. package/dist/dsh/native-task-authority.d.ts +66 -0
  236. package/dist/dsh/native-task-authority.d.ts.map +1 -0
  237. package/dist/dsh/native-task-authority.js +220 -0
  238. package/dist/dsh/native-task-authority.js.map +1 -0
  239. package/dist/dsh/node-tap-summary.d.ts +1 -2
  240. package/dist/dsh/node-tap-summary.d.ts.map +1 -1
  241. package/dist/dsh/node-tap-summary.js +2 -24
  242. package/dist/dsh/node-tap-summary.js.map +1 -1
  243. package/dist/dsh/observation-pack/policy.d.ts +1 -0
  244. package/dist/dsh/observation-pack/policy.d.ts.map +1 -1
  245. package/dist/dsh/observation-pack/policy.js +3 -0
  246. package/dist/dsh/observation-pack/policy.js.map +1 -1
  247. package/dist/dsh/observation-pack/service.d.ts.map +1 -1
  248. package/dist/dsh/observation-pack/service.js +3 -1
  249. package/dist/dsh/observation-pack/service.js.map +1 -1
  250. package/dist/dsh/on-demand-intake.d.ts +28 -1
  251. package/dist/dsh/on-demand-intake.d.ts.map +1 -1
  252. package/dist/dsh/on-demand-intake.js +171 -10
  253. package/dist/dsh/on-demand-intake.js.map +1 -1
  254. package/dist/dsh/orchestration/execution-owner.js +1 -1
  255. package/dist/dsh/orchestration/execution-owner.js.map +1 -1
  256. package/dist/dsh/orchestration/managed-agent-executor.d.ts +12 -1
  257. package/dist/dsh/orchestration/managed-agent-executor.d.ts.map +1 -1
  258. package/dist/dsh/orchestration/managed-agent-executor.js +28 -2
  259. package/dist/dsh/orchestration/managed-agent-executor.js.map +1 -1
  260. package/dist/dsh/owned-completion-evidence.d.ts +11 -0
  261. package/dist/dsh/owned-completion-evidence.d.ts.map +1 -0
  262. package/dist/dsh/owned-completion-evidence.js +59 -0
  263. package/dist/dsh/owned-completion-evidence.js.map +1 -0
  264. package/dist/dsh/owned-execution.d.ts +28 -1
  265. package/dist/dsh/owned-execution.d.ts.map +1 -1
  266. package/dist/dsh/owned-execution.js +325 -101
  267. package/dist/dsh/owned-execution.js.map +1 -1
  268. package/dist/dsh/owned-read-owner.d.ts +6 -0
  269. package/dist/dsh/owned-read-owner.d.ts.map +1 -0
  270. package/dist/dsh/owned-read-owner.js +22 -0
  271. package/dist/dsh/owned-read-owner.js.map +1 -0
  272. package/dist/dsh/replay-memory-extract.d.ts +36 -0
  273. package/dist/dsh/replay-memory-extract.d.ts.map +1 -0
  274. package/dist/dsh/replay-memory-extract.js +192 -0
  275. package/dist/dsh/replay-memory-extract.js.map +1 -0
  276. package/dist/dsh/semantic-compaction/coordinator.d.ts.map +1 -1
  277. package/dist/dsh/semantic-compaction/coordinator.js +2 -1
  278. package/dist/dsh/semantic-compaction/coordinator.js.map +1 -1
  279. package/dist/dsh/session-bridge.d.ts +3 -0
  280. package/dist/dsh/session-bridge.d.ts.map +1 -1
  281. package/dist/dsh/session-bridge.js +22 -25
  282. package/dist/dsh/session-bridge.js.map +1 -1
  283. package/dist/dsh/session-history-compatibility.d.ts.map +1 -1
  284. package/dist/dsh/session-history-compatibility.js +15 -1
  285. package/dist/dsh/session-history-compatibility.js.map +1 -1
  286. package/dist/dsh/session-history-lookup.d.ts +1 -1
  287. package/dist/dsh/session-history-lookup.d.ts.map +1 -1
  288. package/dist/dsh/session-history-lookup.js +4 -3
  289. package/dist/dsh/session-history-lookup.js.map +1 -1
  290. package/dist/dsh/session-memory-finalizer.d.ts.map +1 -1
  291. package/dist/dsh/session-memory-finalizer.js +129 -117
  292. package/dist/dsh/session-memory-finalizer.js.map +1 -1
  293. package/dist/dsh/setup.d.ts +1 -1
  294. package/dist/dsh/setup.d.ts.map +1 -1
  295. package/dist/dsh/setup.js +1 -1
  296. package/dist/dsh/skill-prompts.json +1 -1
  297. package/dist/dsh/task-authority-context.d.ts +8 -0
  298. package/dist/dsh/task-authority-context.d.ts.map +1 -0
  299. package/dist/dsh/task-authority-context.js +28 -0
  300. package/dist/dsh/task-authority-context.js.map +1 -0
  301. package/dist/dsh/task-completion-host.d.ts +2 -1
  302. package/dist/dsh/task-completion-host.d.ts.map +1 -1
  303. package/dist/dsh/task-completion-host.js +17 -5
  304. package/dist/dsh/task-completion-host.js.map +1 -1
  305. package/dist/dsh/task-completion.d.ts +13 -0
  306. package/dist/dsh/task-completion.d.ts.map +1 -1
  307. package/dist/dsh/task-completion.js +23 -6
  308. package/dist/dsh/task-completion.js.map +1 -1
  309. package/dist/dsh/task-intake.d.ts.map +1 -1
  310. package/dist/dsh/task-intake.js +7 -16
  311. package/dist/dsh/task-intake.js.map +1 -1
  312. package/dist/dsh/task-source-history.d.ts +33 -0
  313. package/dist/dsh/task-source-history.d.ts.map +1 -0
  314. package/dist/dsh/task-source-history.js +62 -0
  315. package/dist/dsh/task-source-history.js.map +1 -0
  316. package/dist/dsh/task-state-host.d.ts +124 -0
  317. package/dist/dsh/task-state-host.d.ts.map +1 -0
  318. package/dist/dsh/task-state-host.js +403 -0
  319. package/dist/dsh/task-state-host.js.map +1 -0
  320. package/dist/dsh/task-state-surface.d.ts +8 -0
  321. package/dist/dsh/task-state-surface.d.ts.map +1 -0
  322. package/dist/dsh/task-state-surface.js +113 -0
  323. package/dist/dsh/task-state-surface.js.map +1 -0
  324. package/dist/dsh/task-state.d.ts +217 -0
  325. package/dist/dsh/task-state.d.ts.map +1 -0
  326. package/dist/dsh/task-state.js +315 -0
  327. package/dist/dsh/task-state.js.map +1 -0
  328. package/dist/dsh/tool-exposure-config.d.ts +12 -0
  329. package/dist/dsh/tool-exposure-config.d.ts.map +1 -0
  330. package/dist/dsh/tool-exposure-config.js +4 -0
  331. package/dist/dsh/tool-exposure-config.js.map +1 -0
  332. package/dist/dsh/tool-exposure.d.ts +2 -11
  333. package/dist/dsh/tool-exposure.d.ts.map +1 -1
  334. package/dist/dsh/tool-exposure.js +2 -2
  335. package/dist/dsh/tool-exposure.js.map +1 -1
  336. package/dist/dsh/tools.d.ts +2 -2
  337. package/dist/dsh/tools.d.ts.map +1 -1
  338. package/dist/dsh/tools.js +3 -2
  339. package/dist/dsh/tools.js.map +1 -1
  340. package/dist/enno-oduno/memory-verification.d.ts +2 -1
  341. package/dist/enno-oduno/memory-verification.d.ts.map +1 -1
  342. package/dist/enno-oduno/memory-verification.js +42 -30
  343. package/dist/enno-oduno/memory-verification.js.map +1 -1
  344. package/dist/enno-oduno/schemas.d.ts +1 -1
  345. package/dist/enno-oduno/store.d.ts +7 -0
  346. package/dist/enno-oduno/store.d.ts.map +1 -1
  347. package/dist/enno-oduno/store.js +42 -0
  348. package/dist/enno-oduno/store.js.map +1 -1
  349. package/dist/ledger/store.d.ts.map +1 -1
  350. package/dist/ledger/store.js +0 -5
  351. package/dist/ledger/store.js.map +1 -1
  352. package/dist/locale/en.json +1 -1
  353. package/dist/locale/ja.json +1 -1
  354. package/dist/locale/ko.json +1 -1
  355. package/dist/locale/zh-CN.json +1 -1
  356. package/dist/memory/application.js +1 -1
  357. package/dist/memory/application.js.map +1 -1
  358. package/dist/memory/auto-globalization.d.ts.map +1 -1
  359. package/dist/memory/auto-globalization.js +4 -82
  360. package/dist/memory/auto-globalization.js.map +1 -1
  361. package/dist/memory/evolution/contracts.d.ts +3 -1
  362. package/dist/memory/evolution/contracts.d.ts.map +1 -1
  363. package/dist/memory/evolution/contracts.js +1 -1
  364. package/dist/memory/evolution/contracts.js.map +1 -1
  365. package/dist/memory/evolution/store.d.ts +2 -1
  366. package/dist/memory/evolution/store.d.ts.map +1 -1
  367. package/dist/memory/evolution/store.js +75 -34
  368. package/dist/memory/evolution/store.js.map +1 -1
  369. package/dist/memory/evolution/worker.d.ts +1 -0
  370. package/dist/memory/evolution/worker.d.ts.map +1 -1
  371. package/dist/memory/evolution/worker.js +6 -18
  372. package/dist/memory/evolution/worker.js.map +1 -1
  373. package/dist/memory/explain.d.ts.map +1 -1
  374. package/dist/memory/explain.js +2 -2
  375. package/dist/memory/explain.js.map +1 -1
  376. package/dist/memory/forget.d.ts.map +1 -1
  377. package/dist/memory/forget.js +12 -3
  378. package/dist/memory/forget.js.map +1 -1
  379. package/dist/memory/hybrid-retrieval.d.ts.map +1 -1
  380. package/dist/memory/hybrid-retrieval.js +3 -0
  381. package/dist/memory/hybrid-retrieval.js.map +1 -1
  382. package/dist/memory/index-reasoning/service.d.ts.map +1 -1
  383. package/dist/memory/index-reasoning/service.js +5 -43
  384. package/dist/memory/index-reasoning/service.js.map +1 -1
  385. package/dist/memory/index-reasoning/worker.d.ts.map +1 -1
  386. package/dist/memory/index-reasoning/worker.js +1 -15
  387. package/dist/memory/index-reasoning/worker.js.map +1 -1
  388. package/dist/memory/lifecycle-cache.d.ts +12 -0
  389. package/dist/memory/lifecycle-cache.d.ts.map +1 -0
  390. package/dist/memory/lifecycle-cache.js +36 -0
  391. package/dist/memory/lifecycle-cache.js.map +1 -0
  392. package/dist/memory/lifecycle-database.d.ts +5 -0
  393. package/dist/memory/lifecycle-database.d.ts.map +1 -0
  394. package/dist/memory/lifecycle-database.js +32 -0
  395. package/dist/memory/lifecycle-database.js.map +1 -0
  396. package/dist/memory/lifecycle-global-state.d.ts +5 -0
  397. package/dist/memory/lifecycle-global-state.d.ts.map +1 -0
  398. package/dist/memory/lifecycle-global-state.js +23 -0
  399. package/dist/memory/lifecycle-global-state.js.map +1 -0
  400. package/dist/memory/lifecycle-global.d.ts +23 -0
  401. package/dist/memory/lifecycle-global.d.ts.map +1 -0
  402. package/dist/memory/lifecycle-global.js +56 -0
  403. package/dist/memory/lifecycle-global.js.map +1 -0
  404. package/dist/memory/lifecycle.d.ts +152 -0
  405. package/dist/memory/lifecycle.d.ts.map +1 -0
  406. package/dist/memory/lifecycle.js +152 -0
  407. package/dist/memory/lifecycle.js.map +1 -0
  408. package/dist/memory/replay-review.d.ts +90 -0
  409. package/dist/memory/replay-review.d.ts.map +1 -0
  410. package/dist/memory/replay-review.js +82 -0
  411. package/dist/memory/replay-review.js.map +1 -0
  412. package/dist/memory/replay-store.d.ts +14 -0
  413. package/dist/memory/replay-store.d.ts.map +1 -0
  414. package/dist/memory/replay-store.js +117 -0
  415. package/dist/memory/replay-store.js.map +1 -0
  416. package/dist/memory/review/adoption.d.ts.map +1 -1
  417. package/dist/memory/review/adoption.js +2 -106
  418. package/dist/memory/review/adoption.js.map +1 -1
  419. package/dist/memory/review/store.d.ts.map +1 -1
  420. package/dist/memory/review/store.js +9 -5
  421. package/dist/memory/review/store.js.map +1 -1
  422. package/dist/memory/review/worker.d.ts.map +1 -1
  423. package/dist/memory/review/worker.js +1 -7
  424. package/dist/memory/review/worker.js.map +1 -1
  425. package/dist/memory/scoped-memory.js +1 -1
  426. package/dist/memory/scoped-memory.js.map +1 -1
  427. package/dist/model-tools/contracts.d.ts +4 -4
  428. package/dist/model-tools/contracts.d.ts.map +1 -1
  429. package/dist/model-tools/contracts.js +1 -11
  430. package/dist/model-tools/contracts.js.map +1 -1
  431. package/dist/model-tools/names.d.ts +4 -0
  432. package/dist/model-tools/names.d.ts.map +1 -0
  433. package/dist/model-tools/names.js +13 -0
  434. package/dist/model-tools/names.js.map +1 -0
  435. package/docs/agenticreplay-recording.md +1 -1
  436. package/docs/code-intelligence.md +54 -119
  437. package/docs/dsh-plugin.md +86 -9
  438. package/docs/getting-started.md +10 -0
  439. package/docs/guardrail-licenses/Apache-2.0.txt +73 -0
  440. package/docs/guardrail-licenses/BSD-2-Clause.txt +9 -0
  441. package/docs/guardrail-licenses/COPYRIGHT-Rust.txt +34 -0
  442. package/docs/guardrail-licenses/COPYRIGHT-library.html +29357 -0
  443. package/docs/guardrail-licenses/ISC.txt +7 -0
  444. package/docs/guardrail-licenses/LICENSE-APACHE +176 -0
  445. package/docs/guardrail-licenses/LICENSE-MIT +25 -0
  446. package/docs/guardrail-licenses/LLVM-exception.txt +15 -0
  447. package/docs/guardrail-licenses/MIT.txt +9 -0
  448. package/docs/guardrail-licenses/NCSA.txt +29 -0
  449. package/docs/guardrail-licenses/README.md +7 -0
  450. package/docs/guardrail-licenses/Unicode-3.0.txt +39 -0
  451. package/docs/guardrail-licenses/libunwind-LICENSE.txt +311 -0
  452. package/docs/guardrail-licenses/manifest.json +71 -0
  453. package/docs/guardrail-licenses/musl-COPYRIGHT.txt +193 -0
  454. package/docs/guardrail.md +33 -0
  455. package/docs/lifecycle-memory.md +25 -0
  456. package/docs/lisp.md +33 -9
  457. package/docs/memory-evolution.md +6 -6
  458. package/docs/owned-execution.md +3 -3
  459. package/docs/replay-memory-review.md +26 -0
  460. package/docs/semantic-compaction.md +2 -0
  461. package/guardrail/aarch64-apple-darwin/kiokuko-guardrail +0 -0
  462. package/guardrail/aarch64-apple-darwin/manifest.json +71 -0
  463. package/guardrail/aarch64-unknown-linux-musl/kiokuko-guardrail +0 -0
  464. package/guardrail/aarch64-unknown-linux-musl/manifest.json +69 -0
  465. package/guardrail/manifest.json +204 -0
  466. package/guardrail/node-runner.mjs +37 -0
  467. package/guardrail/protocols/coding-routine.lisp +33 -0
  468. package/guardrail/x86_64-apple-darwin/kiokuko-guardrail +0 -0
  469. package/guardrail/x86_64-apple-darwin/manifest.json +71 -0
  470. package/guardrail/x86_64-unknown-linux-musl/kiokuko-guardrail +0 -0
  471. package/guardrail/x86_64-unknown-linux-musl/manifest.json +68 -0
  472. package/migrations/038_coding_admission.sql +19 -0
  473. package/migrations/039_memory_lifecycle.sql +336 -0
  474. package/migrations/040_task_state.sql +45 -0
  475. package/migrations/041_task_source_history.sql +88 -0
  476. package/migrations/042_evolution_source_epochs.sql +148 -0
  477. package/package.json +45 -27
  478. package/scripts/guardrail-artifacts.d.mts +13 -0
  479. package/scripts/guardrail-artifacts.mjs +136 -0
  480. package/skills/kiokuko-lisp/SKILL.md +1 -1
  481. package/skills/kiokuko-soul/SKILL.md +6 -6
@@ -17,7 +17,7 @@ import { EvolutionWorker } from '../memory/evolution/worker.js';
17
17
  import { AutoGlobalizationWorker } from '../memory/auto-globalization.js';
18
18
  import { DeepMemoryFinalizer } from '../deep-thinker/memory-finalizer.js';
19
19
  import { DeepStore } from '../deep-thinker/store.js';
20
- import { createHash } from 'node:crypto';
20
+ import { createHash, randomUUID } from 'node:crypto';
21
21
  import { TransactionCommitUncertainError, withImmediateTransaction } from '../db/transaction.js';
22
22
  import { KiokukoError } from '../errors.js';
23
23
  import { recordEntryInTransaction } from '../memory/entries.js';
@@ -705,12 +705,64 @@ function repositoryId(database, workspace) {
705
705
  throw new KiokukoError('INTEGRITY_ERROR', 'DSH finalization workspace has no repository binding');
706
706
  return row.repositoryId;
707
707
  }
708
+ function finalizationIdentity(job) {
709
+ return job.sourceEpoch === 1 ? `finalizer:${job.runId}` : `finalizer:${job.runId}:source:${job.sourceEpoch}`;
710
+ }
711
+ function storedFinalization(database, job) {
712
+ if (job.archived) {
713
+ const row = database.prepare('SELECT job_json FROM dsh_task_source_finalizations WHERE run_id=? AND source_epoch=?')
714
+ .get(job.runId, job.sourceEpoch);
715
+ return row ? JSON.parse(row.job_json) : undefined;
716
+ }
717
+ const row = database.prepare('SELECT * FROM dsh_memory_finalizations WHERE run_id=? AND source_epoch=?')
718
+ .get(job.runId, job.sourceEpoch);
719
+ return row;
720
+ }
721
+ function updateFinalization(database, job, fields) {
722
+ if (job.archived) {
723
+ const row = storedFinalization(database, job);
724
+ if (row)
725
+ database.prepare('UPDATE dsh_task_source_finalizations SET job_json=? WHERE run_id=? AND source_epoch=?')
726
+ .run(JSON.stringify({ ...row, ...fields }), job.runId, job.sourceEpoch);
727
+ }
728
+ else {
729
+ const keys = Object.keys(fields);
730
+ if (keys.some(key => !/^[a-z_]+$/u.test(key)))
731
+ throw new Error('invalid_finalization_field');
732
+ database.prepare(`UPDATE dsh_memory_finalizations SET ${keys.map(key => `${key}=?`).join(',')} WHERE run_id=? AND source_epoch=?`)
733
+ .run(...Object.values(fields), job.runId, job.sourceEpoch);
734
+ }
735
+ }
736
+ function assertFinalizationLease(database, job, now) {
737
+ const current = storedFinalization(database, job);
738
+ if (!current || current.status !== 'processing' || current.claim_nonce !== job.claimNonce || current.source_epoch !== job.sourceEpoch
739
+ || current.dsh_session_id !== job.dshSessionId || typeof current.lease_until !== 'string' || current.lease_until <= now)
740
+ throw new KiokukoError('CONFLICT', 'DSH memory finalization source generation is no longer claimed');
741
+ if (!job.archived) {
742
+ assertMemoryLease(database, job.runId, job.claimNonce, now);
743
+ const run = database.prepare('SELECT COALESCE(task_owner_session_id,dsh_session_id) AS owner FROM ledger_runs WHERE run_id=?').get(job.runId);
744
+ if (run?.owner !== job.dshSessionId)
745
+ throw new KiokukoError('CONFLICT', 'DSH memory finalization source owner changed');
746
+ }
747
+ }
748
+ function archiveJob(row) {
749
+ return { archived: true, runId: String(row.run_id), workspace: String(row.workspace), dshSessionId: String(row.dsh_session_id),
750
+ sourceEpoch: Number(row.source_epoch), sourceGeneration: String(row.source_generation), sourceStartSeq: Number(row.source_start_seq), sourceEndSeq: Number(row.source_end_seq),
751
+ attemptCount: Number(row.attempt_count), scheduledAt: String(row.scheduled_at), inputMode: row.input_mode,
752
+ extractionVersion: row.extraction_version, evidenceSelectionVersion: row.evidence_selection_version,
753
+ memoryAdoptionVersion: row.memory_adoption_version, evidenceContractVersion: row.evidence_contract_version,
754
+ outcome: row.outcome, claimNonce: String(row.claim_nonce), leaseUntil: String(row.lease_until) };
755
+ }
708
756
  export function bindDshRunLogStartInTransaction(database, input, now) {
709
757
  const runId = validateIdentity(input.runId, 'runId');
710
758
  const workspace = validateIdentity(input.workspace, 'workspace');
711
759
  const sessionId = validateIdentity(input.dshSessionId, 'dshSessionId');
712
760
  const sourceStartSeq = validatedSequence(input.sourceStartSeq, 'sourceStartSeq');
713
761
  const sourceStartTurn = validatedTurn(input.sourceStartTurn, 'sourceStartTurn');
762
+ const preceding = database.prepare(`SELECT json_extract(job_json,'$.source_end_seq') AS sourceEndSeq FROM dsh_task_source_finalizations
763
+ WHERE run_id=? AND json_extract(job_json,'$.dsh_session_id')=? ORDER BY source_epoch DESC LIMIT 1`).get(runId, sessionId);
764
+ if (preceding && sourceStartSeq <= preceding.sourceEndSeq)
765
+ throw new KiokukoError('CONFLICT', 'Resumed log source overlaps an earlier finalized source range');
714
766
  const existing = database.prepare(`
715
767
  SELECT workspace, dsh_session_id AS dshSessionId,
716
768
  source_start_seq AS sourceStartSeq, source_start_turn AS sourceStartTurn
@@ -815,14 +867,11 @@ export class DshMemoryFinalizer {
815
867
  catch { /* optional enrichment never vetoes native work */ } }
816
868
  async admitIndex(workspace, sessionId, envelope) { await this.#indexService?.admitIndex(workspace, sessionId, envelope); }
817
869
  async admitConversationIndex(workspace, sessionId, envelope, assertCurrent) { await this.#indexService?.admitConversation(workspace, sessionId, envelope, assertCurrent); }
818
- async indexCommand(sessionId, raw) { await this.start(); return this.#indexService.indexCommand(sessionId, raw); }
870
+ async indexCommand(sessionId, raw) { return { recorded: false, workMayContinue: true, reason: 'post_task_memory_review_required' }; }
819
871
  get lastDrainError() { return this.#lastDrainError; }
820
872
  /** Recover a process-interrupted job once, then drain pending work in background. */
821
873
  async start() {
822
- if (this.#closed)
823
- throw new KiokukoError('SERVICE_UNAVAILABLE', 'DSH memory finalizer is closed');
824
- this.#startup ??= this.#startOnce();
825
- await this.#startup;
874
+ return; // Replaced by post-task native review; old pending jobs are not resumed.
826
875
  }
827
876
  async #startOnce() {
828
877
  this.#configured = true;
@@ -835,6 +884,15 @@ export class DshMemoryFinalizer {
835
884
  WHERE status IN ('processing', 'failed') AND COALESCE(last_error_code,'')<>'MEMORY_FORGOTTEN' AND attempt_count < ? AND capture_admission='ready' AND (claim_nonce IS NULL OR lease_until<=?)
836
885
  `).run(this.#now(), this.#maximumAttempts, this.#now());
837
886
  });
887
+ await this.#runtime.withDatabase(database => withImmediateTransaction(database, () => {
888
+ for (const item of database.prepare('SELECT job_json FROM dsh_task_source_finalizations').all()) {
889
+ const row = JSON.parse(item.job_json);
890
+ if (['processing', 'failed'].includes(String(row.status)) && row.last_error_code !== 'MEMORY_FORGOTTEN'
891
+ && Number(row.attempt_count) < this.#maximumAttempts && row.capture_admission === 'ready'
892
+ && (!row.claim_nonce || String(row.lease_until) <= this.#now()))
893
+ updateFinalization(database, archiveJob(row), { status: 'pending', claim_nonce: null, lease_until: null, updated_at: this.#now() });
894
+ }
895
+ }));
838
896
  await this.#runtime.withDatabase(database => configureEvolution(database, this.#evolutionConfig.mode));
839
897
  if (this.#closed)
840
898
  return;
@@ -849,59 +907,15 @@ export class DshMemoryFinalizer {
849
907
  }
850
908
  /** Persist the first DSH turn boundary for a run before model execution continues. */
851
909
  async bindRunStart(input) {
852
- const now = this.#now();
853
- await this.#runtime.withDatabase((database) => withImmediateTransaction(database, () => {
854
- bindDshRunLogStartInTransaction(database, input, now);
855
- }));
910
+ return; // Optional memory cannot add a task-admission prerequisite.
856
911
  }
857
912
  /** Must be called inside the same transaction that terminalizes the run. */
858
913
  scheduleInTransaction(database, input) {
859
- this.#configured = true;
860
- const runId = validateIdentity(input.runId, 'runId');
861
- const workspace = validateIdentity(input.workspace, 'workspace');
862
- const sessionId = validateIdentity(input.dshSessionId, 'dshSessionId');
863
- const sourceEndSeq = validatedSequence(input.sourceEndSeq, 'sourceEndSeq');
864
- const existing = database.prepare('SELECT status FROM dsh_memory_finalizations WHERE run_id = ?')
865
- .get(runId);
866
- if (existing !== undefined)
867
- return;
868
- const boundary = database.prepare(`
869
- SELECT source_start_seq AS sourceStartSeq
870
- FROM dsh_run_log_boundaries
871
- WHERE run_id = ? AND workspace = ? AND dsh_session_id = ?
872
- `).get(runId, workspace, sessionId);
873
- if (boundary === undefined)
874
- throw new KiokukoError('INTEGRITY_ERROR', 'Completed DSH run has no bound log start');
875
- if (sourceEndSeq < boundary.sourceStartSeq)
876
- throw new KiokukoError('INTEGRITY_ERROR', 'Completed DSH run has a reversed log range');
877
- const now = this.#now();
878
- database.prepare(`
879
- INSERT INTO dsh_memory_finalizations (
880
- run_id, workspace, dsh_session_id, source_start_seq, source_end_seq,
881
- status, attempt_count, input_mode, extraction_version, evidence_selection_version, memory_adoption_version, capture_admission, evidence_contract_version,
882
- scheduled_at, updated_at
883
- ) VALUES (?, ?, ?, ?, ?, 'pending', 0, ?, ?, 2, ?, ?, 4, ?, ?)
884
- `).run(runId, workspace, sessionId, boundary.sourceStartSeq, sourceEndSeq, this.#inputMode, this.#evolutionConfig.mode === 'off' ? 1 : 2, 2, capturePolicy(database, workspace, sessionId).mode === 'allowed' ? 'ready' : capturePolicy(database, workspace, sessionId).mode, now, now);
914
+ return; // No durable draft/finalization job before user review.
885
915
  }
886
916
  /** Schedule a background drain after the enclosing transaction commits. */
887
917
  kick() {
888
- if (this.#closed)
889
- return;
890
- this.#autoGlobalWorker?.kick();
891
- if (this.#drain !== undefined) {
892
- this.#rerunRequested = true;
893
- return;
894
- }
895
- const operation = this.#drainPending();
896
- this.#drain = operation;
897
- void operation.catch((error) => { this.#lastDrainError = error; }).finally(() => {
898
- if (this.#drain === operation)
899
- this.#drain = undefined;
900
- if (this.#rerunRequested && !this.#closed) {
901
- this.#rerunRequested = false;
902
- this.kick();
903
- }
904
- });
918
+ return; // Automatic derived-memory writes were replaced by exact human review.
905
919
  }
906
920
  /** Await currently queued work; intended for orderly shutdown and tests. */
907
921
  async whenIdle() {
@@ -916,23 +930,27 @@ export class DshMemoryFinalizer {
916
930
  }
917
931
  /** Explicitly retry one contained failure without changing DSH session state. */
918
932
  async retryFailed(runId) {
919
- const checked = validateIdentity(runId, 'runId');
920
- await this.#runtime.withDatabase((database) => {
921
- database.prepare(`
922
- UPDATE dsh_memory_finalizations
923
- SET status = 'pending', updated_at = ?
924
- WHERE run_id = ? AND status = 'failed' AND COALESCE(last_error_code,'')<>'MEMORY_FORGOTTEN' AND attempt_count < ? AND capture_admission='ready' AND NOT EXISTS(SELECT 1 FROM memory_capture_exclusions x WHERE x.workspace=dsh_memory_finalizations.workspace AND x.native_session_id=dsh_memory_finalizations.dsh_session_id)
925
- `).run(this.#now(), checked, this.#maximumAttempts);
926
- });
927
- this.kick();
933
+ return; // A historical pending job does not carry approval of a shown revision.
928
934
  }
929
935
  async #claim() {
930
936
  return this.#runtime.withDatabase((database) => withImmediateTransaction(database, () => {
937
+ // Old source segments are durable work, independent of the current task owner.
938
+ for (const item of database.prepare(`SELECT job_json FROM dsh_task_source_finalizations
939
+ WHERE json_extract(job_json,'$.status')='pending' ORDER BY run_id,source_epoch`).all()) {
940
+ const archived = JSON.parse(item.job_json), job = archiveJob(archived);
941
+ if (job.attemptCount >= this.#maximumAttempts || archived.capture_admission !== 'ready'
942
+ || capturePolicy(database, job.workspace, job.dshSessionId).mode !== 'allowed')
943
+ continue;
944
+ const nonce = randomUUID(), until = new Date(Date.parse(this.#now()) + this.#timeoutMs + 30000).toISOString();
945
+ updateFinalization(database, job, { status: 'processing', attempt_count: job.attemptCount + 1, started_at: this.#now(),
946
+ claim_nonce: nonce, lease_until: until, last_error_code: null, last_error_message: null, updated_at: this.#now() });
947
+ return { ...job, attemptCount: job.attemptCount + 1, claimNonce: nonce, leaseUntil: until };
948
+ }
931
949
  const row = database.prepare(`
932
- SELECT run_id AS runId, workspace, dsh_session_id AS dshSessionId,
950
+ SELECT run_id AS runId, workspace, dsh_session_id AS dshSessionId, source_epoch AS sourceEpoch,
933
951
  source_start_seq AS sourceStartSeq, source_end_seq AS sourceEndSeq,
934
952
  attempt_count AS attemptCount, scheduled_at AS scheduledAt, input_mode AS inputMode, extraction_version AS extractionVersion, evidence_selection_version AS evidenceSelectionVersion, memory_adoption_version AS memoryAdoptionVersion, evidence_contract_version AS evidenceContractVersion,
935
- (SELECT status FROM ledger_runs r WHERE r.run_id=dsh_memory_finalizations.run_id) AS outcome
953
+ COALESCE(source_outcome,(SELECT status FROM ledger_runs r WHERE r.run_id=dsh_memory_finalizations.run_id)) AS outcome
936
954
  FROM dsh_memory_finalizations
937
955
  WHERE status = 'pending' AND attempt_count < ? AND capture_admission='ready' AND NOT EXISTS(SELECT 1 FROM memory_capture_exclusions x WHERE x.workspace=dsh_memory_finalizations.workspace AND x.native_session_id=dsh_memory_finalizations.dsh_session_id) AND NOT EXISTS(SELECT 1 FROM memory_review_states m WHERE m.run_id=dsh_memory_finalizations.run_id AND m.lease_nonce IS NOT NULL AND m.lease_until>?)
938
956
  ORDER BY scheduled_at, run_id
@@ -943,7 +961,7 @@ export class DshMemoryFinalizer {
943
961
  const now = this.#now();
944
962
  database.prepare(`INSERT OR IGNORE INTO memory_review_states(run_id,workspace,session_id,source_generation,admitted_after_seq,scanned_through_seq,scheduled_through_seq,reviewed_through_seq,terminal_outcome)
945
963
  VALUES(?,?,?,?,?,?,?,?,?)`).run(row.runId, row.workspace, row.dshSessionId, `legacy:${row.dshSessionId}`, row.sourceStartSeq - 1, row.sourceStartSeq - 1, row.sourceStartSeq - 1, row.sourceStartSeq - 1, row.outcome);
946
- const nonce = acquireMemoryLease(database, row.runId, `finalizer:${row.runId}`, now, this.#timeoutMs + 30000);
964
+ const nonce = acquireMemoryLease(database, row.runId, finalizationIdentity(row), now, this.#timeoutMs + 30000);
947
965
  if (!nonce)
948
966
  return undefined;
949
967
  const until = reviewState(database, row.runId).lease_until;
@@ -973,7 +991,10 @@ export class DshMemoryFinalizer {
973
991
  throw new KiokukoError('SERVICE_UNAVAILABLE', 'DSH LLM service is unavailable for memory finalization');
974
992
  const { envelope } = prepared;
975
993
  const base = buildFinalizationRequest(job, prepared, signal);
976
- const execution = boundedOwnedEvidence(await this.#runtime.withDatabase(db => ownedRunEvidence(db, job.runId, job.dshSessionId)));
994
+ const observed = await this.#runtime.withDatabase(db => ownedRunEvidence(db, job.runId, job.dshSessionId));
995
+ const cited = new Set(reconciliation?.evidence.map(item => item.id) ?? []);
996
+ const execution = boundedOwnedEvidence(observed.filter(receipt => reconciliation ? cited.has(receipt.evidenceRef)
997
+ : prepared.evidence.includes(receipt.operationId)));
977
998
  const built = execution.items.length ? { ...base, request: { ...base.request, messages: [...base.request.messages, { role: 'user', content: [{ type: 'text', text: JSON.stringify({ executionObservations: execution.items, omittedExecutionObservations: execution.omitted, policy: 'Host observations describe execution and source-bound checks. They do not verify generalized lessons. Failed, unknown, stale or previous-generation results are not current success. Preserve conditions and source versions in candidate memories.' }) }] }] } } : base;
978
999
  let request = reconciliation ? { ...built.request, tools: [], system: `${built.request.system ?? ''}
979
1000
  Override the legacy memory output format: return only schemaVersion 3 with memoryOperations and optional episode. Kinds: fact, decision, preference, lesson, reference. Use only the evidence IDs and existing entry IDs below. Operations: add(kind,title,body,evidenceIds), update(targetEntryId,expectedRevision,expectedContentHash,kind,title,body,evidenceIds), unchanged(targetEntryId,evidenceIds), defer(reason: ambiguous|conflict|insufficient_context,evidenceIds). Only editable candidates may be updated. Do not duplicate existing memories; preserve conditions and corrections. Assistant statements, quotes and recalled memory are not new evidence. Empty memoryOperations is valid.`,
@@ -1015,11 +1036,8 @@ Use schemaVersion 4 with memoryOperations and optional episode. Use only supplie
1015
1036
  let finish;
1016
1037
  await this.#runtime.withDatabase(database => withImmediateTransaction(database, () => {
1017
1038
  assertCaptureAllowed(database, job.workspace, job.dshSessionId);
1018
- assertMemoryLease(database, job.runId, job.claimNonce, this.#now());
1019
- database.prepare("UPDATE dsh_memory_finalizations SET dispatched_at=? WHERE run_id=? AND claim_nonce=? AND status='processing' AND capture_admission='ready'").run(this.#now(), job.runId, job.claimNonce);
1020
- const changed = database.prepare('SELECT changes() AS n').get().n;
1021
- if (!changed)
1022
- throw new Error('stale_finalizer_claim');
1039
+ assertFinalizationLease(database, job, this.#now());
1040
+ updateFinalization(database, job, { dispatched_at: this.#now() });
1023
1041
  }));
1024
1042
  for await (const value of abortableStream(this.#llm.stream(request), signal)) {
1025
1043
  const chunk = record(value);
@@ -1105,18 +1123,18 @@ Use schemaVersion 4 with memoryOperations and optional episode. Use only supplie
1105
1123
  if (job.memoryAdoptionVersion === 2) {
1106
1124
  const evidence = await this.#reviewEvidence(job);
1107
1125
  reconciliation = await this.#runtime.withDatabase(database => {
1108
- const state = reviewState(database, job.runId);
1109
- const range = { workspace: job.workspace, sessionId: job.dshSessionId, runId: job.runId, sourceGeneration: state.source_generation, startSeq: job.sourceStartSeq, endSeq: job.sourceEndSeq };
1126
+ const generation = job.archived ? job.sourceGeneration : reviewState(database, job.runId).source_generation;
1127
+ const range = { workspace: job.workspace, sessionId: job.dshSessionId, runId: job.runId, sourceGeneration: generation, startSeq: job.sourceStartSeq, endSeq: job.sourceEndSeq };
1110
1128
  return { range, evidence, ...memorySnapshots(database, range, evidence.map(e => e.text).join('\n'), job.evidenceContractVersion === 4) };
1111
1129
  });
1112
1130
  }
1113
1131
  const extractEpisode = job.extractionVersion === 2 && await this.#runtime.withDatabase(database => evolutionSettings(database).mode !== 'off');
1114
1132
  const requestJob = extractEpisode ? job : { ...job, extractionVersion: 1 };
1115
- const bindingHash = canonicalContentHash({ runId: job.runId, sessionId: job.dshSessionId, digest: prepared.digest,
1133
+ const bindingHash = canonicalContentHash({ runId: job.runId, sourceEpoch: job.sourceEpoch, sessionId: job.dshSessionId, digest: prepared.digest,
1116
1134
  evidence: reconciliation ? reviewManifest(reconciliation.evidence) : null, existing: reconciliation?.existing ?? null });
1117
- const staged = await this.#runtime.withDatabase(db => db.prepare('SELECT staged_capsule_json,staged_binding_hash FROM dsh_memory_finalizations WHERE run_id=?').get(job.runId));
1135
+ const staged = await this.#runtime.withDatabase(db => { assertFinalizationLease(db, job, this.#now()); return storedFinalization(db, job); });
1118
1136
  let result;
1119
- if (staged?.staged_binding_hash === bindingHash && staged.staged_capsule_json) {
1137
+ if (staged?.staged_binding_hash === bindingHash && typeof staged.staged_capsule_json === 'string') {
1120
1138
  const cached = JSON.parse(staged.staged_capsule_json);
1121
1139
  if (reconciliation) {
1122
1140
  const parsed = (job.evidenceContractVersion === 4 ? FinalizerResultV4 : FinalizerResult).parse(JSON.parse(cached.capsuleJson));
@@ -1131,9 +1149,8 @@ Use schemaVersion 4 with memoryOperations and optional episode. Use only supplie
1131
1149
  throw new KiokukoError('VALIDATION_ERROR', 'Memory extraction contains secret-bearing material');
1132
1150
  await this.#runtime.withDatabase(db => withImmediateTransaction(db, () => {
1133
1151
  assertCaptureAllowed(db, job.workspace, job.dshSessionId);
1134
- assertMemoryLease(db, job.runId, job.claimNonce, this.#now());
1135
- db.prepare("UPDATE dsh_memory_finalizations SET staged_capsule_json=?,staged_binding_hash=? WHERE run_id=? AND claim_nonce=? AND status='processing'")
1136
- .run(JSON.stringify({ capsuleJson: result.capsuleJson, usage: result.usage }), bindingHash, job.runId, job.claimNonce);
1152
+ assertFinalizationLease(db, job, this.#now());
1153
+ updateFinalization(db, job, { staged_capsule_json: JSON.stringify({ capsuleJson: result.capsuleJson, usage: result.usage }), staged_binding_hash: bindingHash });
1137
1154
  }));
1138
1155
  }
1139
1156
  if (reconciliation) {
@@ -1154,14 +1171,8 @@ Use schemaVersion 4 with memoryOperations and optional episode. Use only supplie
1154
1171
  const now = this.#now();
1155
1172
  await this.#runtime.withDatabase((database) => withImmediateTransaction(database, () => {
1156
1173
  assertCaptureAllowed(database, job.workspace, job.dshSessionId);
1157
- assertMemoryLease(database, job.runId, job.claimNonce, this.#now());
1174
+ assertFinalizationLease(database, job, this.#now());
1158
1175
  controller.signal.throwIfAborted();
1159
- const current = database.prepare('SELECT status,claim_nonce FROM dsh_memory_finalizations WHERE run_id = ?')
1160
- .get(job.runId);
1161
- if (current?.status === 'completed')
1162
- return;
1163
- if (current?.status !== 'processing' || current.claim_nonce !== job.claimNonce)
1164
- throw new KiokukoError('CONFLICT', 'DSH memory finalization job is no longer claimed');
1165
1176
  const sourceRepositoryId = repositoryId(database, job.workspace);
1166
1177
  const scope = buildStructuredScope({
1167
1178
  visibility: 'project', retrievalScope: 'project-only', repositoryId: sourceRepositoryId,
@@ -1175,7 +1186,7 @@ Use schemaVersion 4 with memoryOperations and optional episode. Use only supplie
1175
1186
  clientKind: 'dsh',
1176
1187
  timestamp: now,
1177
1188
  };
1178
- const adopted = reconciliation && result.memoryOperations ? adoptMemories(database, { id: `finalizer:${job.runId}`, range: reconciliation.range, evidence: reconciliation.evidence, existing: reconciliation.existing, operations: result.memoryOperations, observe: false, now, actor: 'kiokuko-dsh-finalizer' }) : undefined;
1189
+ const adopted = reconciliation && result.memoryOperations ? adoptMemories(database, { id: finalizationIdentity(job), range: reconciliation.range, evidence: reconciliation.evidence, existing: reconciliation.existing, operations: result.memoryOperations, observe: false, now, actor: 'kiokuko-dsh-finalizer' }) : undefined;
1179
1190
  const saved = adopted ? [...new Map(adopted.entries.map(e => [e.id, e])).values()] : result.capsule.memories.map((memory) => recordEntryInTransaction(database, {
1180
1191
  workspace: job.workspace,
1181
1192
  kind: memory.kind,
@@ -1193,29 +1204,32 @@ Use schemaVersion 4 with memoryOperations and optional episode. Use only supplie
1193
1204
  }, { now }));
1194
1205
  const executionReceipts = ownedRunEvidence(database, job.runId, job.dshSessionId);
1195
1206
  for (const effect of database.prepare('SELECT entry_id,revision,operation_index FROM memory_review_effects WHERE job_id=? AND disposition IN (\'added\',\'updated\')')
1196
- .all(`finalizer:${job.runId}`)) {
1207
+ .all(finalizationIdentity(job))) {
1197
1208
  const operation = result.memoryOperations?.[effect.operation_index];
1198
1209
  if (operation)
1199
1210
  linkOwnedMemoryEvidence(database, { id: effect.entry_id, revision: effect.revision }, executionReceipts, operation.evidenceIds, { runId: job.runId, sessionId: job.dshSessionId, workspace: job.workspace });
1200
1211
  }
1201
- const link = database.prepare(`
1202
- INSERT INTO dsh_memory_finalization_entries (run_id, entry_id, ordinal, created_at)
1203
- VALUES (?, ?, ?, ?)
1204
- `);
1205
- saved.forEach((entry, ordinal) => link.run(job.runId, entry.id, ordinal, now));
1212
+ if (job.archived) {
1213
+ const link = database.prepare('INSERT INTO dsh_task_source_entries(run_id,source_epoch,entry_id,ordinal,created_at) VALUES(?,?,?,?,?)');
1214
+ saved.forEach((entry, ordinal) => link.run(job.runId, job.sourceEpoch, entry.id, ordinal, now));
1215
+ }
1216
+ else {
1217
+ const link = database.prepare('INSERT INTO dsh_memory_finalization_entries(run_id,entry_id,ordinal,created_at) VALUES(?,?,?,?)');
1218
+ saved.forEach((entry, ordinal) => link.run(job.runId, entry.id, ordinal, now));
1219
+ }
1206
1220
  if (episode && evolutionSettings(database).mode !== 'off') {
1207
1221
  database.exec('SAVEPOINT evolution_episode');
1208
1222
  try {
1209
1223
  const evidence = [...(prepared.episodeEvidence ?? [])];
1210
1224
  saveEpisode(database, {
1211
- runId: job.runId, workspace: job.workspace, sessionId: job.dshSessionId,
1225
+ runId: job.runId, sourceEpoch: job.sourceEpoch, workspace: job.workspace, sessionId: job.dshSessionId,
1212
1226
  start: job.sourceStartSeq, end: job.sourceEndSeq, logDigest: prepared.digest, outcome: job.outcome,
1213
1227
  evidenceDigest: supportingEvidenceDigest(episode, evidence),
1214
1228
  signature: episodeSignature(job.workspace, episode), draft: episode, evidence: evidenceReferences(evidence),
1215
1229
  sources: saved.map(e => ({ entryId: e.id, revision: e.revision, hash: e.contentHash })),
1216
1230
  ...episodeSignals(episode, evidence),
1217
1231
  }, now, evidence);
1218
- scheduleEvolution(database, job.runId, { ...result.envelope, sessionId: job.dshSessionId }, now);
1232
+ scheduleEvolution(database, job.runId, { ...result.envelope, sessionId: job.dshSessionId }, now, job.sourceEpoch);
1219
1233
  database.exec('RELEASE evolution_episode');
1220
1234
  }
1221
1235
  catch {
@@ -1224,21 +1238,18 @@ Use schemaVersion 4 with memoryOperations and optional episode. Use only supplie
1224
1238
  episodeError = 'episode_persistence_rejected';
1225
1239
  }
1226
1240
  }
1227
- database.prepare("UPDATE memory_review_states SET handoff_status='finalizer_completed',lease_nonce=NULL,lease_until=NULL WHERE run_id=? AND lease_nonce=?").run(job.runId, job.claimNonce);
1241
+ if (!job.archived)
1242
+ database.prepare("UPDATE memory_review_states SET handoff_status='finalizer_completed',lease_nonce=NULL,lease_until=NULL WHERE run_id=? AND lease_nonce=?").run(job.runId, job.claimNonce);
1228
1243
  if (reconciliation && adopted?.held === 0) {
1229
- database.prepare('UPDATE memory_review_jobs SET resolved_by=? WHERE run_id=? AND start_seq>=? AND end_seq<=?').run(`finalizer:${job.runId}`, job.runId, job.sourceStartSeq, job.sourceEndSeq);
1230
- database.prepare('UPDATE memory_review_states SET reviewed_through_seq=max(reviewed_through_seq,?) WHERE run_id=?').run(job.sourceEndSeq, job.runId);
1244
+ database.prepare('UPDATE memory_review_jobs SET resolved_by=? WHERE run_id=? AND session_id=? AND source_generation=? AND start_seq>=? AND end_seq<=?').run(finalizationIdentity(job), job.runId, job.dshSessionId, reconciliation.range.sourceGeneration, job.sourceStartSeq, job.sourceEndSeq);
1245
+ if (!job.archived)
1246
+ database.prepare('UPDATE memory_review_states SET reviewed_through_seq=max(reviewed_through_seq,?) WHERE run_id=?').run(job.sourceEndSeq, job.runId);
1231
1247
  }
1232
- if (episodeError)
1233
- database.prepare('UPDATE dsh_memory_finalizations SET episode_error=? WHERE run_id=?').run(episodeError, job.runId);
1234
- database.prepare(`
1235
- UPDATE dsh_memory_finalizations
1236
- SET status = 'completed', log_event_count = ?,
1237
- log_digest = ?, capsule_hash = ?, capsule_bytes = ?, provider = ?, model = ?,
1238
- input_tokens = ?, output_tokens = ?, cache_read_tokens = ?, cache_write_tokens = ?,
1239
- completed_at = ?, updated_at = ?
1240
- WHERE run_id = ? AND status = 'processing'
1241
- `).run(prepared.eventCount, prepared.digest, canonicalContentHash(JSON.parse(result.capsuleJson)), Buffer.byteLength(result.capsuleJson, 'utf8'), result.envelope.provider, result.envelope.model, result.usage.inputTokens ?? null, result.usage.outputTokens ?? null, result.usage.cacheReadTokens ?? null, result.usage.cacheWriteTokens ?? null, now, now, job.runId);
1248
+ updateFinalization(database, job, { status: 'completed', log_event_count: prepared.eventCount, log_digest: prepared.digest,
1249
+ capsule_hash: canonicalContentHash(JSON.parse(result.capsuleJson)), capsule_bytes: Buffer.byteLength(result.capsuleJson, 'utf8'),
1250
+ provider: result.envelope.provider, model: result.envelope.model, input_tokens: result.usage.inputTokens ?? null,
1251
+ output_tokens: result.usage.outputTokens ?? null, cache_read_tokens: result.usage.cacheReadTokens ?? null,
1252
+ cache_write_tokens: result.usage.cacheWriteTokens ?? null, completed_at: now, updated_at: now, ...(episodeError ? { episode_error: episodeError } : {}) });
1242
1253
  }));
1243
1254
  try {
1244
1255
  await this.admitIndex(job.workspace, job.dshSessionId, prepared.envelope);
@@ -1260,15 +1271,16 @@ Use schemaVersion 4 with memoryOperations and optional episode. Use only supplie
1260
1271
  const failure = boundedError(error);
1261
1272
  try {
1262
1273
  await this.#runtime.withDatabase((database) => {
1263
- database.prepare(`
1264
- UPDATE dsh_memory_finalizations
1265
- SET status = 'failed', claim_nonce=NULL,lease_until=NULL, last_error_code = ?, last_error_message = ?, updated_at = ?
1266
- WHERE run_id = ? AND status = 'processing' AND claim_nonce=?
1267
- `).run(failure.code, failure.code, this.#now(), job.runId, job.claimNonce);
1268
- database.prepare("UPDATE memory_review_states SET handoff_status='finalizer_failed' WHERE run_id=? AND lease_nonce=?").run(job.runId, job.claimNonce);
1269
- database.prepare("UPDATE dsh_memory_finalizations SET input_tokens=?,output_tokens=?,cache_read_tokens=?,cache_write_tokens=? WHERE run_id=? AND last_error_code='MEMORY_FORGOTTEN'")
1270
- .run(attempt.usage.inputTokens ?? null, attempt.usage.outputTokens ?? null, attempt.usage.cacheReadTokens ?? null, attempt.usage.cacheWriteTokens ?? null, job.runId);
1271
- releaseMemoryLease(database, job.runId, job.claimNonce);
1274
+ const current = storedFinalization(database, job);
1275
+ if (current?.status === 'processing' && current.claim_nonce === job.claimNonce)
1276
+ updateFinalization(database, job, { status: 'failed', claim_nonce: null, lease_until: null, last_error_code: failure.code, last_error_message: failure.code, updated_at: this.#now() });
1277
+ if (!job.archived) {
1278
+ database.prepare("UPDATE memory_review_states SET handoff_status='finalizer_failed' WHERE run_id=? AND lease_nonce=?").run(job.runId, job.claimNonce);
1279
+ releaseMemoryLease(database, job.runId, job.claimNonce);
1280
+ }
1281
+ if (current?.last_error_code === 'MEMORY_FORGOTTEN')
1282
+ updateFinalization(database, job, { input_tokens: attempt.usage.inputTokens ?? null,
1283
+ output_tokens: attempt.usage.outputTokens ?? null, cache_read_tokens: attempt.usage.cacheReadTokens ?? null, cache_write_tokens: attempt.usage.cacheWriteTokens ?? null });
1272
1284
  });
1273
1285
  }
1274
1286
  catch (markError) {