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
@@ -1,3 +1,8 @@
1
+ import { renameSync, openSync, closeSync, writeFileSync, fsyncSync, fchmodSync, rmSync, statSync } from 'node:fs';
2
+ import { assertProtocolRoute, reserveProtocolFile, applyProtocolFile, withProtocolEffect, reserveProtocolTest, authorizeProtocolTest, finishProtocolTest } from './guardrail/service.js';
3
+ import { runProtocolTests } from './guardrail/engine.js';
4
+ import { retainProtocolResult, protocolReceiptUncertain } from './guardrail/evidence.js';
5
+ import { recordOwnedCompletionObservation } from './owned-completion-evidence.js';
1
6
  import { spawn } from 'node:child_process';
2
7
  import { createHash, randomUUID } from 'node:crypto';
3
8
  import { readFile, open, rename, mkdir, rm, realpath, stat } from 'node:fs/promises';
@@ -17,14 +22,43 @@ import { shellArguments } from './execution-command.js';
17
22
  import { assertCodingDispatch, assertCodingCommandRetry } from './coding-workflow/service.js';
18
23
  import { readCodingWorkflow } from './coding-workflow/store.js';
19
24
  import { executionRequestAction } from './coding-workflow/intent.js';
25
+ import { withImmediateTransaction } from '../db/transaction.js';
26
+ import { TASK_AUTHORITY, authorizeTaskLease, readTaskSnapshot } from './task-state.js';
27
+ import { captureExecutionTaskLease, withTaskAuthority, currentTaskAuthority, hasNoTaskAuthority, withNoTaskAuthority } from './task-authority-context.js';
20
28
  const hash = (data) => createHash('sha256').update(data).digest('hex');
21
29
  const within = (root, target) => { const relative = path.relative(root, target); return relative === '' || !relative.startsWith('..' + path.sep) && relative !== '..' && !path.isAbsolute(relative); };
22
30
  const safeText = (text) => findSecret(text) ? '[redacted secret-bearing text]' : text;
23
31
  const ownedCalls = new WeakSet();
24
32
  export const isOwnedExecutionCall = (execution) => ownedCalls.has(execution);
33
+ /** Known effect surfaces. Composite Lisp/PTC programs guard their inner calls;
34
+ * reading, cancellation and pure evaluation do not acquire execution authority. */
35
+ export function taskEffectTool(name, args) {
36
+ if (name === 'str_replace_editor')
37
+ return args?.command !== 'view';
38
+ return ['kioku_write', 'kioku_edit', 'kioku_remove', 'kioku_exec', 'write', 'edit', 'bash', 'spawn', 'fork', 'subagent', 'enno_delegate', 'task_operation'].includes(name);
39
+ }
25
40
  const fileInput = z.object({ path: z.string().min(1), content: z.string().optional(), expectedHash: z.string().nullable().optional(), oldText: z.string().optional(), newText: z.string().optional() }).strict();
26
41
  const commandInput = z.object({ command: z.string().min(1), cwd: z.string().optional(), shell: z.enum(['bash', 'zsh']).default('bash'), background: z.boolean().default(false), timeoutMs: z.number().int().min(1).max(3600000).default(300000), destructiveTargets: z.array(z.string()).optional() }).strict();
27
42
  const resultInput = z.object({ operationId: z.string().min(1), cancel: z.boolean().default(false) }).strict();
43
+ const runtimeServices = new WeakMap();
44
+ /** Host-only stop observation. A crash receipt is not proof of a stopped child. */
45
+ export async function stopTaskOwnedExecutions(runtime, identity, signal) {
46
+ signal?.throwIfAborted();
47
+ await Promise.all([...runtimeServices.get(runtime) ?? []].map(service => service.stopTask(identity, signal)));
48
+ signal?.throwIfAborted();
49
+ try {
50
+ return await runtime.withDatabase(db => db.prepare('SELECT receipt_json FROM dsh_owned_operations WHERE run_id=?')
51
+ .all(identity.taskId).every(row => {
52
+ const receipt = JSON.parse(row.receipt_json);
53
+ if (receipt.repositoryRoot !== identity.repositoryRoot || receipt.state === 'started')
54
+ return false;
55
+ return receipt.kind !== 'kioku_exec' || receipt.state === 'completed' && receipt.processStopped === true;
56
+ }));
57
+ }
58
+ catch {
59
+ return false;
60
+ }
61
+ }
28
62
  /** One owner for effects and observed evidence. Saved-result reads never execute an effect. */
29
63
  export class OwnedExecutionService {
30
64
  host;
@@ -32,13 +66,62 @@ export class OwnedExecutionService {
32
66
  #legacyRuns = new Set();
33
67
  constructor(host) {
34
68
  this.host = host;
69
+ const services = runtimeServices.get(host.runtime) ?? new Set();
70
+ services.add(this);
71
+ runtimeServices.set(host.runtime, services);
35
72
  }
36
73
  current(execution) {
37
74
  execution.signal.throwIfAborted();
38
75
  const identity = this.host.resolve(execution);
39
76
  if (!identity)
40
77
  throw new Error('No current admitted execution owner');
41
- return identity;
78
+ return Object.freeze({ ...identity });
79
+ }
80
+ assertAuthority(identity, lease, database) {
81
+ const current = this.host.resolve({ agent: identity.agent, callId: 'task-authority', name: 'kioku_exec', signal: new AbortController().signal });
82
+ if (!current || current.runId !== identity.runId || current.sessionId !== identity.sessionId
83
+ || current.repositoryRoot !== identity.repositoryRoot || current.generation !== identity.generation
84
+ || lease.taskId !== identity.runId || lease.sessionId !== (identity.workflowSessionId ?? identity.sessionId)
85
+ || lease.repositoryRoot !== identity.repositoryRoot)
86
+ throw new KiokukoError('CONFLICT', 'Task execution owner changed');
87
+ authorizeTaskLease(database, lease);
88
+ }
89
+ async checkAuthority(identity, lease) {
90
+ await this.host.runtime.withDatabase(db => this.assertAuthority(identity, lease, db));
91
+ }
92
+ /** The caller may carry an earlier lease (for example an asynchronous Lisp job).
93
+ * Never replace it with the current task after a stop/resume or owner change. */
94
+ async captureAuthority(execution, identity = this.current(execution)) {
95
+ return this.host.runtime.withDatabase(db => {
96
+ const lease = captureExecutionTaskLease(db, {
97
+ taskId: identity.runId, sessionId: identity.workflowSessionId ?? identity.sessionId, repositoryRoot: identity.repositoryRoot,
98
+ }, execution);
99
+ this.assertAuthority(identity, lease, db);
100
+ execution[TASK_AUTHORITY] = lease;
101
+ return lease;
102
+ });
103
+ }
104
+ /** A pure composite may run in any state, but its later inner effects must
105
+ * retain the task (or absence of one) observed when the composite began. */
106
+ async composite(execution, next) {
107
+ if (hasNoTaskAuthority())
108
+ return withNoTaskAuthority(next);
109
+ const inherited = execution[TASK_AUTHORITY] ?? currentTaskAuthority();
110
+ if (inherited)
111
+ return withTaskAuthority(inherited, next);
112
+ let lease;
113
+ try {
114
+ const identity = this.host.resolve(execution) ?? await this.host.resolveRead?.(execution);
115
+ if (execution[TASK_AUTHORITY])
116
+ return withTaskAuthority(execution[TASK_AUTHORITY], next);
117
+ if (identity)
118
+ lease = await this.host.runtime.withDatabase(db => {
119
+ const task = readTaskSnapshot(db, { taskId: identity.runId, sessionId: identity.workflowSessionId ?? identity.sessionId, repositoryRoot: identity.repositoryRoot });
120
+ return { taskId: task.taskId, sessionId: task.sessionId, repositoryRoot: task.repositoryRoot, revision: task.revision, generation: task.generation };
121
+ });
122
+ }
123
+ catch { /* Pure calculations remain available; inner effects fail closed. */ }
124
+ return lease ? withTaskAuthority(lease, next) : withNoTaskAuthority(next);
42
125
  }
43
126
  async persist(receipt, digest) {
44
127
  const journal = this.journal(receipt.repositoryRoot);
@@ -82,6 +165,8 @@ export class OwnedExecutionService {
82
165
  return;
83
166
  try {
84
167
  await this.host.runtime.withDatabase(db => {
168
+ const lease = captureExecutionTaskLease(db, { taskId: identity.runId, sessionId: identity.workflowSessionId ?? identity.sessionId, repositoryRoot: identity.repositoryRoot }, execution);
169
+ this.assertAuthority(identity, lease, db);
85
170
  // Coding checks carry source/config/artifact dependencies. Assessment
86
171
  // invalidates the affected checks instead of discarding unrelated items.
87
172
  if (readCodingWorkflow(db, identity.runId)) {
@@ -94,11 +179,13 @@ export class OwnedExecutionService {
94
179
  }
95
180
  catch { /* Missing auxiliary evidence never rejects development. */ }
96
181
  }
97
- async evidence(identity, receipt, command, execute) {
182
+ async evidence(identity, receipt, command, lease, execute) {
98
183
  let completion = false, memory = false;
99
184
  let sourcePaths = [];
185
+ await this.checkAuthority(identity, lease);
100
186
  try {
101
187
  await this.host.runtime.withDatabase(db => {
188
+ this.assertAuthority(identity, lease, db);
102
189
  completion = beginTaskCompletionExecution(db, { runId: identity.runId, callId: receipt.operationId, command, repositoryRoot: identity.repositoryRoot, cwd: receipt.cwd });
103
190
  if (completion) {
104
191
  const method = db.prepare(`SELECT b.method_json FROM dsh_completion_executions e JOIN dsh_completion_bindings b
@@ -110,7 +197,7 @@ export class OwnedExecutionService {
110
197
  }
111
198
  catch { /* Evidence failure is exposed as unknown; effects continue. */ }
112
199
  try {
113
- memory = await this.host.runtime.withDatabase(db => beginMemoryExecution(db, identity, receipt.operationId, command, receipt.cwd));
200
+ memory = await this.host.runtime.withDatabase(db => { this.assertAuthority(identity, lease, db); return beginMemoryExecution(db, identity, receipt.operationId, command, receipt.cwd); });
114
201
  }
115
202
  catch { /* Memory bookkeeping cannot suppress completion observations. */ }
116
203
  for (const source of sourcePaths) {
@@ -130,7 +217,8 @@ export class OwnedExecutionService {
130
217
  const argv = shellArguments(command);
131
218
  const readOnly = argv && ['cat', 'head', 'tail', 'ls', 'pwd', 'wc', 'stat', 'readlink'].includes(path.basename(argv[0] ?? ''));
132
219
  if (!completion && !readOnly)
133
- await this.unknownEffects({ agent: identity.agent, callId: receipt.operationId, name: 'kioku_exec', signal: new AbortController().signal });
220
+ await this.unknownEffects({ agent: identity.agent, callId: receipt.operationId, name: 'kioku_exec', signal: new AbortController().signal, [TASK_AUTHORITY]: lease });
221
+ await this.checkAuthority(identity, lease);
134
222
  const result = await execute();
135
223
  for (const target of receipt.targets) {
136
224
  try {
@@ -145,36 +233,41 @@ export class OwnedExecutionService {
145
233
  }
146
234
  }
147
235
  }
148
- if (this.host.resolve({ agent: identity.agent, callId: receipt.operationId, name: 'kioku_exec', signal: new AbortController().signal })?.generation === identity.generation) {
149
- try {
150
- await this.host.runtime.withDatabase(db => {
151
- if (completion) {
152
- finishTaskCompletionExecution(db, { runId: identity.runId, callId: receipt.operationId, result });
153
- saveTaskCompletionReceipt(db, identity.runId);
154
- const row = db.prepare(`SELECT e.source_digest,e.outcome,b.method_json FROM dsh_completion_executions e
236
+ try {
237
+ await this.host.runtime.withDatabase(db => withImmediateTransaction(db, () => {
238
+ this.assertAuthority(identity, lease, db);
239
+ if (completion) {
240
+ finishTaskCompletionExecution(db, { runId: identity.runId, callId: receipt.operationId, result });
241
+ saveTaskCompletionReceipt(db, identity.runId);
242
+ const row = db.prepare(`SELECT e.source_digest,e.outcome,b.method_json FROM dsh_completion_executions e
155
243
  JOIN dsh_completion_bindings b ON b.run_id=e.run_id AND b.method_digest=e.method_digest WHERE e.run_id=? AND e.call_id=? LIMIT 1`)
156
- .get(identity.runId, receipt.operationId);
157
- if (row) {
158
- const method = JSON.parse(row.method_json);
159
- let postSourceDigest;
160
- try {
161
- postSourceDigest = completionSourceDigest(db, identity.runId, identity.repositoryRoot, method.sourcePaths);
162
- }
163
- catch { /* Missing inputs remain unknown. */ }
164
- receipt.checks = [{ sourcePaths: method.sourcePaths, sourceDigest: row.source_digest, ...(postSourceDigest ? { postSourceDigest } : {}), outcome: row.outcome, assertion: method.assertion }];
165
- receipt.verification = row.outcome === 'passed' ? 'passed' : row.outcome === 'failed' ? 'failed' : 'unknown';
244
+ .get(identity.runId, receipt.operationId);
245
+ if (row) {
246
+ const method = JSON.parse(row.method_json);
247
+ let postSourceDigest;
248
+ try {
249
+ postSourceDigest = completionSourceDigest(db, identity.runId, identity.repositoryRoot, method.sourcePaths);
166
250
  }
251
+ catch { /* Missing inputs remain unknown. */ }
252
+ receipt.checks = [{ sourcePaths: method.sourcePaths, sourceDigest: row.source_digest, ...(postSourceDigest ? { postSourceDigest } : {}), outcome: row.outcome, assertion: method.assertion }];
253
+ receipt.verification = row.outcome === 'passed' ? 'passed' : row.outcome === 'failed' ? 'failed' : 'unknown';
167
254
  }
168
- if (memory)
169
- completeMemoryExecution(db, identity, receipt.operationId, result);
170
- });
255
+ }
256
+ if (memory)
257
+ completeMemoryExecution(db, identity, receipt.operationId, result);
258
+ }));
259
+ receipt.authority = 'current';
260
+ }
261
+ catch (error) {
262
+ receipt.verification = 'unknown';
263
+ try {
264
+ await this.checkAuthority(identity, lease);
171
265
  }
172
266
  catch {
173
- receipt.verification = 'unknown';
267
+ receipt.authority = 'stale';
268
+ receipt.error = safeText(error instanceof Error ? error.message : String(error));
174
269
  }
175
270
  }
176
- else
177
- receipt.verification = 'unknown';
178
271
  return result;
179
272
  }
180
273
  async approve(identity, detail, signal) {
@@ -191,7 +284,13 @@ export class OwnedExecutionService {
191
284
  return { ...value, receipt, ...(replayed ? { replayed: true } : {}), status: { work: receipt.state, verification: receipt.verification ?? 'unknown', receiptPersistence: receipt.persistence, memoryStorage } };
192
285
  }
193
286
  async execute(name, raw, execution) {
194
- const identity = this.current(execution);
287
+ const identity = (name === 'kioku_read' || name === 'kioku_result') && this.host.resolveRead
288
+ ? await this.host.resolveRead(execution).then(value => {
289
+ execution.signal.throwIfAborted();
290
+ if (!value)
291
+ throw new Error('No current execution result owner');
292
+ return Object.freeze({ ...value });
293
+ }) : this.current(execution);
195
294
  const action = executionRequestAction(identity.requestIntent, identity.requestIntentContext, name);
196
295
  ownedCalls.add(execution);
197
296
  if (name === 'kioku_read' || name === 'kioku_result') {
@@ -205,6 +304,7 @@ export class OwnedExecutionService {
205
304
  if (name === 'kioku_result')
206
305
  return this.result(identity, resultInput.parse(raw));
207
306
  const input = name === 'kioku_exec' ? commandInput.parse(raw) : fileInput.parse(raw);
307
+ const lease = name === 'kioku_read' ? await this.captureAuthority(execution, identity).catch(() => undefined) : await this.captureAuthority(execution, identity);
208
308
  if (name !== 'kioku_read') {
209
309
  try {
210
310
  await this.host.runtime.withDatabase(db => {
@@ -264,7 +364,7 @@ export class OwnedExecutionService {
264
364
  await this.persist(prior, digest);
265
365
  return this.reply(prior, {}, true);
266
366
  }
267
- const receipt = { version: 1, operationId, runId: identity.runId, sessionId: identity.sessionId, generation: identity.generation, kind: name, repositoryRoot: identity.repositoryRoot, cwd: identity.repositoryRoot, targets: [], state: 'started', evidenceRef: `owned:${operationId}`, persistence: 'pending' };
367
+ const receipt = { version: 1, operationId, runId: identity.runId, sessionId: identity.sessionId, generation: identity.generation, kind: name, repositoryRoot: identity.repositoryRoot, cwd: identity.repositoryRoot, targets: [], state: 'started', evidenceRef: `owned:${operationId}`, persistence: 'pending', ...(lease ? { taskAuthority: Object.freeze({ ...lease }) } : {}) };
268
368
  const controller = new AbortController();
269
369
  const operation = { digest, receipt, controller };
270
370
  // A second concurrent call may have completed the database lookup too.
@@ -304,8 +404,8 @@ export class OwnedExecutionService {
304
404
  await this.persist(receipt, digest);
305
405
  const done = (async () => {
306
406
  try {
307
- operation.value = name === 'kioku_exec' ? await this.command(identity, receipt, input, signal)
308
- : await this.file(identity, receipt, name, input, signal);
407
+ operation.value = name === 'kioku_exec' ? await this.command(identity, receipt, input, signal, lease)
408
+ : await this.file(identity, receipt, name, input, signal, lease);
309
409
  receipt.state = 'completed';
310
410
  }
311
411
  catch (error) {
@@ -315,6 +415,18 @@ export class OwnedExecutionService {
315
415
  receipt.verification = 'unknown';
316
416
  }
317
417
  await this.persist(receipt, digest);
418
+ if (name === 'kioku_exec') {
419
+ try {
420
+ await finishProtocolTest(action => this.host.runtime.withDatabase(action), receipt);
421
+ await this.host.runtime.withDatabase(db => saveTaskCompletionReceipt(db, identity.runId));
422
+ }
423
+ catch (error) {
424
+ receipt.verification = 'unknown';
425
+ receipt.error = safeText(error instanceof Error ? error.message : String(error));
426
+ await this.persist(receipt, digest);
427
+ }
428
+ }
429
+ await this.host.runtime.withDatabase(db => withImmediateTransaction(db, () => recordOwnedCompletionObservation(db, receipt))).catch(() => { });
318
430
  return this.reply(receipt, operation.value);
319
431
  })();
320
432
  operation.done = done;
@@ -322,7 +434,7 @@ export class OwnedExecutionService {
322
434
  return this.reply(receipt);
323
435
  return done;
324
436
  }
325
- async file(identity, receipt, name, input, signal) {
437
+ async file(identity, receipt, name, input, signal, lease) {
326
438
  const target = path.resolve(identity.repositoryRoot, input.path);
327
439
  // Resolve the parent as well as existing target to identify symlink exits.
328
440
  let actual;
@@ -351,8 +463,20 @@ export class OwnedExecutionService {
351
463
  await this.persist(receipt, this.#operations.get(receipt.operationId).digest);
352
464
  if (input.expectedHash !== undefined && input.expectedHash !== before)
353
465
  throw new Error('File changed before the operation');
354
- if (name === 'kioku_read')
355
- return { content: (await readFile(actual, 'utf8')), hash: before };
466
+ if (name === 'kioku_read') {
467
+ const content = await readFile(actual, 'utf8'), observedHash = hash(content);
468
+ if (lease && observedHash === before) {
469
+ try {
470
+ await this.checkAuthority(identity, lease);
471
+ receipt.authority = 'current';
472
+ receipt.verification = 'passed';
473
+ }
474
+ catch {
475
+ receipt.authority = 'stale';
476
+ }
477
+ }
478
+ return { content, hash: observedHash };
479
+ }
356
480
  const disposable = await this.disposable(identity, actual);
357
481
  const database = before !== null && (/\.(?:db|sqlite3?)(?:-(?:wal|shm|journal))?$/iu.test(actual) || (await readFile(actual)).subarray(0, 16).equals(Buffer.from('SQLite format 3\0')));
358
482
  if (!disposable && (!within(identity.repositoryRoot, actual) || name === 'kioku_remove' || database))
@@ -360,8 +484,11 @@ export class OwnedExecutionService {
360
484
  signal.throwIfAborted();
361
485
  if (await this.snapshot(actual) !== before)
362
486
  throw new Error('File changed during operation approval');
363
- if (name === 'kioku_remove')
487
+ const protocol = await this.host.runtime.withDatabase(db => reserveProtocolFile(db, lease, receipt.operationId, name, actual, this.#operations.get(receipt.operationId).digest));
488
+ if (name === 'kioku_remove') {
489
+ await this.checkAuthority(identity, lease);
364
490
  await rm(actual, { recursive: false, force: false });
491
+ }
365
492
  else {
366
493
  const existing = before === null ? '' : await readFile(actual, 'utf8');
367
494
  let content = input.content;
@@ -372,30 +499,61 @@ export class OwnedExecutionService {
372
499
  }
373
500
  if (content === undefined)
374
501
  throw new Error('Write content is required');
375
- await mkdir(path.dirname(actual), { recursive: true });
376
- const mode = before === null ? 0o644 : (await stat(actual)).mode;
377
- const temporary = path.join(path.dirname(actual), `.kioku-${randomUUID()}.tmp`);
378
- try {
379
- const file = await open(temporary, 'wx', mode);
502
+ if (protocol && Buffer.byteLength(content) > 8 * 1024 * 1024)
503
+ throw new Error('Protocol file byte limit');
504
+ if (protocol) {
505
+ // Existing parents were bound at enrollment. Stage and commit inside the same final
506
+ // synchronous authority boundary; cancellation committed before it prevents all writes.
507
+ await this.host.runtime.withDatabase(db => applyProtocolFile(db, lease, receipt.operationId, signal, () => {
508
+ const mode = before === null ? 0o644 : statSync(actual).mode & 0o7777;
509
+ const temporary = path.join(path.dirname(actual), `.kioku-${randomUUID()}.tmp`);
510
+ try {
511
+ const file = openSync(temporary, 'wx', mode);
512
+ try {
513
+ fchmodSync(file, mode);
514
+ writeFileSync(file, content);
515
+ fsyncSync(file);
516
+ }
517
+ finally {
518
+ closeSync(file);
519
+ }
520
+ renameSync(temporary, actual);
521
+ }
522
+ finally {
523
+ rmSync(temporary, { force: true });
524
+ }
525
+ }));
526
+ }
527
+ else {
528
+ await this.checkAuthority(identity, lease);
529
+ await mkdir(path.dirname(actual), { recursive: true });
530
+ const mode = before === null ? 0o644 : (await stat(actual)).mode;
531
+ const temporary = path.join(path.dirname(actual), `.kioku-${randomUUID()}.tmp`);
380
532
  try {
381
- await file.chmod(mode & 0o7777);
382
- await file.writeFile(content);
383
- await file.sync();
533
+ const file = await open(temporary, 'wx', mode);
534
+ try {
535
+ await file.chmod(mode & 0o7777);
536
+ await file.writeFile(content);
537
+ await file.sync();
538
+ }
539
+ finally {
540
+ await file.close();
541
+ }
542
+ signal.throwIfAborted();
543
+ await this.checkAuthority(identity, lease);
544
+ await rename(temporary, actual);
384
545
  }
385
546
  finally {
386
- await file.close();
547
+ await rm(temporary, { force: true });
387
548
  }
388
- signal.throwIfAborted();
389
- await rename(temporary, actual);
390
- }
391
- finally {
392
- await rm(temporary, { force: true });
393
549
  }
394
550
  if (await this.snapshot(actual) !== hash(content))
395
551
  throw new Error('Written content differs from requested content');
396
552
  }
397
553
  receipt.targets[0].after = await this.snapshot(actual);
554
+ await this.checkAuthority(identity, lease);
398
555
  receipt.verification = 'passed';
556
+ receipt.authority = 'current';
399
557
  return { applied: true };
400
558
  }
401
559
  async disposable(identity, target) {
@@ -403,50 +561,78 @@ export class OwnedExecutionService {
403
561
  return /^(?:dist|build|target|node_modules)(?:[/\\]|$)/u.test(path.relative(identity.repositoryRoot, target));
404
562
  return within(await realpath(tmpdir()), target);
405
563
  }
406
- async command(identity, receipt, input, signal) {
407
- receipt.cwd = await realpath(path.resolve(identity.repositoryRoot, input.cwd ?? '.'));
408
- receipt.command = safeText(input.command);
409
- receipt.commandDigest = hash(input.command);
410
- await this.persist(receipt, this.#operations.get(receipt.operationId).digest);
411
- // Known destructive intent gets a concrete review. Unknown arbitrary code
412
- // is executed without pretending that static analysis can prove its effects.
413
- const argv = shellArguments(input.command);
414
- const removals = argv && path.basename(argv[0] ?? '') === 'rm' ? argv.slice(1).filter(arg => arg !== '--' && !arg.startsWith('-')) : undefined;
415
- const disposableRemoval = removals?.length && (await Promise.all(removals.map(async (target) => {
416
- const absolute = path.resolve(receipt.cwd, target);
417
- try {
418
- return this.disposable(identity, await realpath(absolute));
419
- }
420
- catch {
421
- return false;
564
+ async command(identity, receipt, input, signal, lease) {
565
+ let launchAttempted = false;
566
+ try {
567
+ receipt.cwd = await realpath(path.resolve(identity.repositoryRoot, input.cwd ?? '.'));
568
+ receipt.command = safeText(input.command);
569
+ receipt.commandDigest = hash(input.command);
570
+ await this.persist(receipt, this.#operations.get(receipt.operationId).digest);
571
+ // Known destructive intent gets a concrete review. Unknown arbitrary code
572
+ // is executed without pretending that static analysis can prove its effects.
573
+ const argv = shellArguments(input.command);
574
+ const removals = argv && path.basename(argv[0] ?? '') === 'rm' ? argv.slice(1).filter(arg => arg !== '--' && !arg.startsWith('-')) : undefined;
575
+ const disposableRemoval = removals?.length && (await Promise.all(removals.map(async (target) => {
576
+ const absolute = path.resolve(receipt.cwd, target);
577
+ try {
578
+ return this.disposable(identity, await realpath(absolute));
579
+ }
580
+ catch {
581
+ return false;
582
+ }
583
+ }))).every(Boolean);
584
+ let durableSql = !!(argv && ['sqlite3', 'psql', 'mysql'].includes(path.basename(argv[0] ?? '')) && /\b(?:insert|update|delete|replace|drop|alter|truncate|create)\b/iu.test(argv.slice(1).join(' ')));
585
+ if (durableSql && path.basename(argv[0]) === 'sqlite3' && argv[1] && !argv[1].startsWith('-')) {
586
+ const database = path.resolve(receipt.cwd, argv[1]);
587
+ durableSql = argv[1] !== ':memory:' && await this.snapshot(database) !== null && !await this.disposable(identity, database);
422
588
  }
423
- }))).every(Boolean);
424
- let durableSql = !!(argv && ['sqlite3', 'psql', 'mysql'].includes(path.basename(argv[0] ?? '')) && /\b(?:insert|update|delete|replace|drop|alter|truncate|create)\b/iu.test(argv.slice(1).join(' ')));
425
- if (durableSql && path.basename(argv[0]) === 'sqlite3' && argv[1] && !argv[1].startsWith('-')) {
426
- const database = path.resolve(receipt.cwd, argv[1]);
427
- durableSql = argv[1] !== ':memory:' && await this.snapshot(database) !== null && !await this.disposable(identity, database);
428
- }
429
- if (input.destructiveTargets?.length || durableSql || removals?.length && !disposableRemoval || !disposableRemoval && /(?:^|[;&|]\s*)(?:rm\s|git\s+(?:reset\s+--hard|clean\s+-[a-z]*f)|(?:drop\s+(?:table|database)|truncate\s+table)\b)/iu.test(input.command))
430
- await this.approve(identity, `Command: ${safeText(input.command)}\nCwd: ${receipt.cwd}\nTargets: ${input.destructiveTargets?.join(', ') ?? 'see command'}`, signal);
431
- return this.evidence(identity, receipt, input.command, async () => {
432
- const result = await runOwnedProcess(input.command, receipt.cwd, input.shell, signal, input.timeoutMs, () => { receipt.processStarted = true; });
433
- const output = result.content[0].text;
434
- receipt.exitCode = result.value.exitCode;
435
- receipt.signal = result.value.signal;
436
- receipt.cancelled = result.value.aborted;
437
- receipt.timedOut = result.value.timedOut;
438
- receipt.processStarted = result.value.processStarted === true;
439
- receipt.outputComplete = result.value.outputComplete === true;
440
- receipt.observedBytes = Buffer.byteLength(output);
441
- receipt.outputDigest = hash(output);
442
- if (result.value.summary)
443
- receipt.summary = result.value.summary;
444
- receipt.verification = result.isError ? 'failed' : 'unknown';
445
- const preview = safeText(output).slice(-24000);
446
- receipt.displayedBytes = Buffer.byteLength(preview);
447
- // Evidence consumes the full output here, before the public preview.
448
- return result;
449
- }).then(result => ({ exitCode: receipt.exitCode, output: safeText(result.content[0].text).slice(-24000) }));
589
+ if (input.destructiveTargets?.length || durableSql || removals?.length && !disposableRemoval || !disposableRemoval && /(?:^|[;&|]\s*)(?:rm\s|git\s+(?:reset\s+--hard|clean\s+-[a-z]*f)|(?:drop\s+(?:table|database)|truncate\s+table)\b)/iu.test(input.command))
590
+ await this.approve(identity, `Command: ${safeText(input.command)}\nCwd: ${receipt.cwd}\nTargets: ${input.destructiveTargets?.join(', ') ?? 'see command'}`, signal);
591
+ const protocol = await this.host.runtime.withDatabase(db => reserveProtocolTest(db, lease, receipt.operationId, input.command, receipt.cwd));
592
+ return await this.evidence(identity, receipt, input.command, lease, async () => {
593
+ signal.throwIfAborted();
594
+ await this.checkAuthority(identity, lease);
595
+ launchAttempted = true;
596
+ const result = protocol
597
+ ? await this.host.runtime.withDatabase(db => { const current = authorizeProtocolTest(db, lease, receipt.operationId, signal); return runProtocolTests(current, receipt.operationId, signal, input.timeoutMs, () => { receipt.processStarted = true; }, launch => withProtocolEffect(db, () => { authorizeProtocolTest(db, lease, receipt.operationId, signal); return launch(); })); })
598
+ : await runOwnedProcess(input.command, receipt.cwd, input.shell, signal, input.timeoutMs, () => { receipt.processStarted = true; });
599
+ if (protocol)
600
+ retainProtocolResult(receipt, result);
601
+ const output = result.content[0].text;
602
+ receipt.exitCode = result.value.exitCode;
603
+ receipt.signal = result.value.signal;
604
+ receipt.cancelled = result.value.aborted;
605
+ receipt.timedOut = result.value.timedOut;
606
+ receipt.processStarted = result.value.processStarted === true;
607
+ receipt.processStopped = result.value.processStopped === true;
608
+ receipt.outputComplete = result.value.outputComplete === true;
609
+ receipt.observedBytes = Buffer.byteLength(output);
610
+ receipt.outputDigest = hash(output);
611
+ if (protocol && protocolReceiptUncertain(receipt))
612
+ throw Error('Protocol launch transaction outcome is uncertain; reconcile the pending operation before explicit resume/rebind');
613
+ if (result.value.summary)
614
+ receipt.summary = result.value.summary;
615
+ receipt.verification = result.isError ? 'failed' : 'unknown';
616
+ const preview = safeText(output).slice(-24000);
617
+ receipt.displayedBytes = Buffer.byteLength(preview);
618
+ // Evidence consumes the full output here, before the public preview.
619
+ return result;
620
+ }).then(result => ({ exitCode: receipt.exitCode, output: safeText(result.content[0].text).slice(-24000) }));
621
+ }
622
+ catch (error) {
623
+ // Before the only launch boundary, cancellation proves that no child ran.
624
+ // Once launch was attempted, preserve unknown outcomes and reconcile them.
625
+ if (!signal.aborted || launchAttempted)
626
+ throw error;
627
+ receipt.processStarted = false;
628
+ receipt.processStopped = true;
629
+ receipt.cancelled = true;
630
+ receipt.exitCode = null;
631
+ receipt.signal = null;
632
+ receipt.outputComplete = false;
633
+ receipt.verification = 'failed';
634
+ return { exitCode: null, output: '' };
635
+ }
450
636
  }
451
637
  async result(identity, input) {
452
638
  const operation = this.#operations.get(input.operationId);
@@ -470,13 +656,24 @@ export class OwnedExecutionService {
470
656
  await this.persist(receipt, journal.digest);
471
657
  return this.reply(receipt.state === 'started' ? { ...receipt, state: 'unknown', error: 'Host restarted before final process result was saved; effects will not be replayed.' } : receipt);
472
658
  }
473
- async close() { for (const op of this.#operations.values())
474
- op.controller.abort(); await Promise.allSettled([...this.#operations.values()].map(op => op.done)); }
659
+ async stopTask(identity, signal) {
660
+ const operations = [...this.#operations.values()].filter(op => op.receipt.runId === identity.taskId && op.receipt.repositoryRoot === identity.repositoryRoot);
661
+ for (const operation of operations)
662
+ operation.controller.abort();
663
+ await Promise.allSettled(operations.map(operation => operation.done));
664
+ signal?.throwIfAborted();
665
+ }
666
+ async close() {
667
+ for (const op of this.#operations.values())
668
+ op.controller.abort();
669
+ await Promise.allSettled([...this.#operations.values()].map(op => op.done));
670
+ runtimeServices.get(this.host.runtime)?.delete(this);
671
+ }
475
672
  }
476
673
  /** Normal user environment, process group cancellation, bounded complete output. */
477
674
  export function runOwnedProcess(command, cwd, shell, signal, timeoutMs, onStarted) {
478
675
  if (signal.aborted)
479
- return Promise.resolve(observeProcessResult({ isError: true, value: { exitCode: null, signal: null, timedOut: false, aborted: true, processStarted: false, outputComplete: false }, content: [{ type: 'text', text: '' }] }));
676
+ return Promise.resolve(observeProcessResult({ isError: true, value: { exitCode: null, signal: null, timedOut: false, aborted: true, processStarted: false, processStopped: true, outputComplete: false }, content: [{ type: 'text', text: '' }] }));
480
677
  return new Promise(resolve => {
481
678
  const env = { ...process.env };
482
679
  delete env.NODE_TEST_CONTEXT;
@@ -519,12 +716,14 @@ export function runOwnedProcess(command, cwd, shell, signal, timeoutMs, onStarte
519
716
  clearTimeout(timer);
520
717
  signal.removeEventListener('abort', abort);
521
718
  const output = Buffer.concat(chunks).toString('utf8') + (error ? `\n${error}` : '');
719
+ let processStopped = false;
522
720
  try {
523
721
  const reported = terminal.trim().split('\n').map(line => JSON.parse(line)).find(item => item.kind === 'completed' || item.kind === undefined);
524
- if (!reported)
722
+ if (!reported || reported.processStarted !== true || !(reported.exitCode === null || Number.isInteger(reported.exitCode)) || !(reported.signal === null || typeof reported.signal === 'string'))
525
723
  throw new Error('Missing completion');
526
724
  exitCode = reported.exitCode;
527
725
  termSignal = reported.signal;
726
+ processStopped = true;
528
727
  }
529
728
  catch {
530
729
  error ||= 'Missing final process report';
@@ -532,7 +731,7 @@ export function runOwnedProcess(command, cwd, shell, signal, timeoutMs, onStarte
532
731
  const outputComplete = !capped && !error && !timedOut && !signal.aborted && !termSignal;
533
732
  const summary = outputComplete ? parseTestSummary(output, true) : undefined;
534
733
  resolve(observeProcessResult({ isError: exitCode !== 0 || !!termSignal || timedOut || signal.aborted || capped || !!error,
535
- value: { exitCode, signal: termSignal, timedOut, aborted: signal.aborted, processStarted, outputComplete, ...(summary ? { summary } : {}) }, content: [{ type: 'text', text: output }] }));
734
+ value: { exitCode, signal: termSignal, timedOut, aborted: signal.aborted, processStarted, processStopped, outputComplete, ...(summary ? { summary } : {}) }, content: [{ type: 'text', text: output }] }));
536
735
  });
537
736
  });
538
737
  }
@@ -547,12 +746,37 @@ export function mountOwnedExecution(ctx, host) {
547
746
  parameters: JSON.parse(JSON.stringify(z.toJSONSchema(name === 'kioku_exec' ? commandInput : name === 'kioku_result' ? resultInput : fileInput))),
548
747
  output: { schema: {}, render: (_, value) => [{ type: 'text', text: JSON.stringify(value) }] }, execute }));
549
748
  }
550
- if (ctx.on && ctx.tools.get)
551
- disposers.push(ctx.on('tools/pre-execute', (execution, next) => {
552
- if (implementations.has(ctx.tools.get(execution.name, execution.agent)?.execute))
749
+ if (ctx.on)
750
+ disposers.push(ctx.on('tools/pre-execute', async (execution, next) => {
751
+ if (implementations.has(ctx.tools.get?.(execution.name, execution.agent)?.execute))
553
752
  ownedCalls.add(execution);
554
- return next();
753
+ const effect = taskEffectTool(execution.name, execution.arguments) && host.isTaskControl?.(execution) !== true;
754
+ // Pin an admitted owner before an approval can await a human. On-demand
755
+ // admission without a task is allowed to finish before the first capture.
756
+ if (effect && host.resolve(execution))
757
+ await service.captureAuthority(execution);
758
+ const decision = await next();
759
+ if (decision?.kind === 'deny')
760
+ return decision;
761
+ if (effect && host.isTaskControl?.(execution) !== true && host.unownedNative?.(execution) !== true)
762
+ await service.captureAuthority(execution);
763
+ return decision;
555
764
  }, { prepend: true }));
765
+ if (ctx.on)
766
+ disposers.push(ctx.on('tools/execute', async (execution, next) => {
767
+ if (host.isTaskControl?.(execution) === true)
768
+ return next();
769
+ if (execution.name === 'bash' && host.unownedNative?.(execution) === true)
770
+ return withNoTaskAuthority(next);
771
+ if (execution.name === 'run_code')
772
+ return service.composite(execution, next);
773
+ if (!taskEffectTool(execution.name, execution.arguments))
774
+ return next();
775
+ const lease = await service.captureAuthority(execution);
776
+ await host.runtime.withDatabase(db => assertProtocolRoute(db, lease, execution.name, isOwnedExecutionCall(execution)));
777
+ execution.signal.throwIfAborted();
778
+ return withTaskAuthority(lease, next);
779
+ }));
556
780
  if (ctx.on)
557
781
  disposers.push(ctx.on('tools/pre-execute', async (execution, next) => {
558
782
  if (['lisp_eval', 'lisp_call', 'lisp_define', 'lisp_hot_install', 'lisp_hot_call'].includes(execution.name))