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
@@ -6,6 +6,7 @@ import { createHash, randomUUID } from 'node:crypto';
6
6
  import { fileURLToPath } from 'node:url';
7
7
  import { z } from 'zod';
8
8
  import { EvalInput, LispError, digest, fail, failure, identifier } from './contracts.js';
9
+ import { LispStore } from './store.js';
9
10
  import { sessionCodingWorkflow } from '../coding-workflow/store.js';
10
11
  import { LispWorker } from './worker.js';
11
12
  import { prepareLayout } from './sandbox.js';
@@ -21,9 +22,41 @@ import { detectRepositoryRoot } from '../../repository/detect-root.js';
21
22
  import { HotToolRuntime } from './hot-tools.js';
22
23
  import { CallInput, DefineInput, TaskToolCatalog, selectFields, validateValue } from './task-tools.js';
23
24
  import { ApplyInput, CompareInput, StageInput, VerifyInput, candidateFromResult, compareCandidates, loadCandidate, loadVerification, materializeCandidate, stageCandidate } from './candidate.js';
25
+ import { LispTaskAuthority } from './task-authority.js';
26
+ /** Confirm the exact owned operation stopped; an abort acknowledgement is not completion. */
27
+ export async function confirmOwnedJobStop(operationId, read) {
28
+ const abort = new AbortController();
29
+ const unconfirmed = () => new LispError('STOP_UNCONFIRMED', '管理中のプロセスの停止をまだ確認できません。記録を確認してから再開してください。');
30
+ let timer;
31
+ const deadline = new Promise((_resolve, reject) => {
32
+ timer = setTimeout(() => { abort.abort(); reject(unconfirmed()); }, 5000);
33
+ });
34
+ let identity;
35
+ try {
36
+ for (let first = true;; first = false) {
37
+ const result = await Promise.race([read(first, abort.signal), deadline]);
38
+ const receipt = result?.receipt;
39
+ if (receipt?.operationId !== operationId)
40
+ throw unconfirmed();
41
+ const current = JSON.stringify([receipt.runId, receipt.sessionId, receipt.generation]);
42
+ if (identity !== undefined && current !== identity)
43
+ throw unconfirmed();
44
+ identity = current;
45
+ if ((receipt.state === 'completed' || receipt.state === 'cancelled') && receipt.processStopped === true)
46
+ return;
47
+ if (receipt.state !== 'started')
48
+ throw unconfirmed();
49
+ await Promise.race([new Promise(resolve => setTimeout(resolve, 25)), deadline]);
50
+ }
51
+ }
52
+ finally {
53
+ clearTimeout(timer);
54
+ }
55
+ }
24
56
  /** Host-owned authority. Worker frames never grant permissions or choose identities. */
25
57
  export class LispManager {
26
58
  options;
59
+ taskAuthority;
27
60
  enabled = new Map();
28
61
  #agents = new Map();
29
62
  #proposals;
@@ -42,13 +75,16 @@ export class LispManager {
42
75
  constructor(options) {
43
76
  this.options = options;
44
77
  this.#config = options.config;
45
- this.#store = options.store;
46
- this.#proposals = new LispProposalBatch({ store: options.store, backupRoot: join(options.dataRoot, 'backups'), protectedRoots: () => this.protectedRoots(), ...(options.questions ? { questions: options.questions } : {}), stopped: () => this.#closed,
47
- ...(options.config.executionMode === 'development' && options.toolCall ? { execute: options.toolCall } : {}) });
78
+ this.taskAuthority = new LispTaskAuthority(options.store.database);
79
+ this.#store = new LispStore(options.store.database, (db, owner) => this.taskAuthority.authorizePublication(db, owner));
80
+ this.#proposals = new LispProposalBatch({ store: this.#store, backupRoot: join(options.dataRoot, 'backups'), protectedRoots: () => this.protectedRoots(), ...(options.questions ? { questions: options.questions } : {}), stopped: () => this.#closed,
81
+ authorizeEffect: async (owner) => { await this.taskAuthority.authorizeEffect(owner); },
82
+ ...(options.config.executionMode === 'development' && options.toolCall ? { execute: async (owner, name, args, signal, callId) => options.toolCall(owner, name, args, signal, callId, await this.taskAuthority.authorizeEffect(owner, 'owned')) } : {}) });
48
83
  this.#library = options.library ?? fileURLToPath(new URL('../../../lisp/', import.meta.url));
49
84
  this.#compiled = new CompiledLispCache(join(options.dataRoot, 'compiled'), this.#library, this.#config);
50
- this.#taskTools = new TaskToolCatalog(options.store);
51
- this.#hot = new HotToolRuntime({ store: options.store, ...(options.questions ? { questions: options.questions } : {}),
85
+ this.#taskTools = new TaskToolCatalog(this.#store);
86
+ this.#hot = new HotToolRuntime({ store: this.#store, ...(options.questions ? { questions: options.questions } : {}),
87
+ authorizeEffect: async (owner) => { await this.taskAuthority.authorizeEffect(owner); },
52
88
  projectRoot: async (owner) => detectRepositoryRoot({ cwd: owner.root, allowDirectory: true }).root,
53
89
  authorize: async (owner) => {
54
90
  const state = this.entry(owner);
@@ -127,6 +163,8 @@ export class LispManager {
127
163
  protectedRoots() { return [this.options.dataRoot, dirname(this.#library), ...this.options.protectedRoots ?? []]; }
128
164
  async authorizeCodingTask(owner) {
129
165
  const workflow = await this.#store.database(db => sessionCodingWorkflow(db, owner.sessionId));
166
+ if (workflow?.protocol && this.#config.executionMode !== 'protected')
167
+ fail('PROTOCOL_PROTECTED_REQUIRED', 'This bounded protocol requires protected Lisp computation. Disable the existing Lisp session before binding, then select protected mode; use owned file/test tools for effects.');
130
168
  if (workflow && (workflow.repositoryRoot !== owner.root || workflow.choice.state !== 'yes' || !workflow.definition || ['cancelled', 'superseded', 'completed'].includes(workflow.state)))
131
169
  fail('CODING_CHOICE_PENDING', 'このタスクの Goal と条件を定め、Lisp の選択に回答してから実行してください。');
132
170
  }
@@ -191,8 +229,16 @@ export class LispManager {
191
229
  const active = [...this.#agents].filter(([key, state]) => state.owner.sessionId === sessionId && JSON.parse(key)[2] === 'task');
192
230
  const stopped = await Promise.allSettled(active.map(async ([key, state]) => {
193
231
  state.state = 'STOPPING';
232
+ for (const abort of state.active)
233
+ abort.abort(new LispError('CANCELLED', '作業用 Lisp の処理を取り消しました。'));
194
234
  try {
195
235
  await state.worker?.stop();
236
+ // A task can still be preparing its compiled runtime without a worker.
237
+ // Keep its admission visible until its own cleanup has settled.
238
+ await state.taskSettlement;
239
+ await this.stopOwned(state);
240
+ if (state.error?.code === 'STOP_UNCONFIRMED')
241
+ fail('STOP_UNCONFIRMED', '作業用 Lisp の停止を確認できません。');
196
242
  this.#agents.delete(key);
197
243
  }
198
244
  catch (error) {
@@ -210,14 +256,24 @@ export class LispManager {
210
256
  await this.authorizeCodingTask(owner);
211
257
  if ([...this.#agents.values()].some(s => s.owner.sessionId === owner.sessionId && s.state === 'STOP_UNCONFIRMED'))
212
258
  fail('STOP_UNCONFIRMED', '停止未確認の Lisp worker があります。新しい実行を開始できません。');
213
- const state = { owner, state: 'PREFLIGHT', active: new Set(), hostBusy: true };
259
+ const abort = new AbortController();
260
+ const combined = signal ? AbortSignal.any([signal, abort.signal]) : abort.signal;
261
+ const state = { owner, state: 'PREFLIGHT', active: new Set([abort]), hostBusy: true, execution: this.taskAuthority.current() };
262
+ let settled;
263
+ state.taskSettlement = new Promise(resolve => { settled = resolve; });
214
264
  const key = JSON.stringify([owner.sessionId, owner.agentId, 'task', randomUUID()]);
215
265
  this.#agents.set(key, state);
266
+ const assertCurrent = () => {
267
+ combined.throwIfAborted();
268
+ if (this.#closed || state.disposed || this.#agents.get(key) !== state || !['PREFLIGHT', 'EVALUATING'].includes(state.state))
269
+ fail('CANCELLED', '作業用 Lisp の実行は取り消されています。');
270
+ };
216
271
  let worker;
217
272
  try {
273
+ assertCurrent();
218
274
  await this.reserveSlot(state);
219
- const compiled = await this.#compiled.ensure(signal ?? new AbortController().signal, () => { });
220
- signal?.throwIfAborted();
275
+ const compiled = await this.#compiled.ensure(combined, () => { });
276
+ assertCurrent();
221
277
  const base = await mkdtemp(join(this.options.dataRoot, 'w-'));
222
278
  const layout = await prepareLayout(base, this.#library);
223
279
  layout.compiled = compiled.path;
@@ -225,23 +281,28 @@ export class LispManager {
225
281
  layout.protected = this.#config.executionMode === 'protected';
226
282
  worker = this.#config.executionMode === 'protected' ? new LispWorker(layout, this.#config, undefined, () => false) : new LispWorker(layout, this.#config, (method, args, context) => this.bridge(state, method, args, context));
227
283
  state.worker = worker;
284
+ assertCurrent();
228
285
  await worker.start();
286
+ assertCurrent();
229
287
  if (this.#config.executionMode === 'protected') {
230
288
  const canary = join(base, 'host-canary');
231
289
  await writeFile(canary, 'protected', { mode: 0o600 });
232
- const probe = await worker.request('eval', { inputs: [], code: `(let ((read-denied (handler-case (progn (with-open-file (s ${JSON.stringify(canary)}) (read-char s)) nil) (file-error () t))) (delete-denied (handler-case (progn (delete-file ${JSON.stringify(canary)}) nil) (file-error () t)))) (unless (and read-denied delete-denied) (error "ISOLATION_FAILED")) :protected)` }, this.#config.startupTimeoutMs, signal);
290
+ const probe = await worker.request('eval', { inputs: [], code: `(let ((read-denied (handler-case (progn (with-open-file (s ${JSON.stringify(canary)}) (read-char s)) nil) (file-error () t))) (delete-denied (handler-case (progn (delete-file ${JSON.stringify(canary)}) nil) (file-error () t)))) (unless (and read-denied delete-denied) (error "ISOLATION_FAILED")) :protected)` }, this.#config.startupTimeoutMs, combined);
233
291
  if (!probe.ok || await readFile(canary, 'utf8') !== 'protected')
234
292
  fail('ISOLATION_FAILED', 'OS によるファイル保護を確認できません。');
235
293
  }
294
+ assertCurrent();
236
295
  state.state = 'EVALUATING';
237
296
  if (mode === 'compile') {
238
- const checked = await worker.request('task-compile', { code }, this.#config.timeoutMs, signal);
297
+ const checked = await worker.request('task-compile', { code }, this.#config.timeoutMs, combined);
298
+ assertCurrent();
239
299
  if (!checked.ok || checked.proposals.length)
240
300
  fail('TASK_COMPILE_FAILED', String(checked.value).slice(0, 1000));
241
301
  return { value: null, output: worker.output(), generation: worker.generation };
242
302
  }
243
303
  if (mode === 'eval') {
244
- const evaluated = await worker.request('eval', { code, inputs: [] }, this.#config.timeoutMs, signal);
304
+ const evaluated = await worker.request('eval', { code, inputs: [] }, this.#config.timeoutMs, combined);
305
+ assertCurrent();
245
306
  if (!evaluated.ok || evaluated.proposals.length)
246
307
  fail('TASK_EVAL_FAILED', String(evaluated.value).slice(0, 1000));
247
308
  const value = evaluated.value;
@@ -252,28 +313,42 @@ export class LispManager {
252
313
  fail('TASK_INPUT_LIMIT', 'Task input is too large.');
253
314
  const inputPath = join(layout.inputs, randomUUID());
254
315
  await writeFile(inputPath, encoded, { flag: 'wx', mode: 0o400 });
316
+ assertCurrent();
255
317
  state.state = 'EVALUATING';
256
- const response = await worker.request('task', { code, input: inputPath }, this.#config.timeoutMs, signal);
318
+ const response = await worker.request('task', { code, input: inputPath }, this.#config.timeoutMs, combined);
257
319
  if (!response.ok || response.proposals.length)
258
320
  fail('TASK_EXECUTION_FAILED', String(response.value).slice(0, 1000));
259
321
  const result = await snapshot(layout.scratch, 'task-result.json', []);
260
322
  if (!result.exists)
261
323
  fail('TASK_RESULT_MISSING', 'Task result was not saved.');
262
324
  const bytes = await checkedBytes(result);
325
+ assertCurrent();
263
326
  return { value: JSON.parse(bytes.toString('utf8')), output: worker.output(), generation: worker.generation };
264
327
  }
265
328
  finally {
266
- if (worker) {
267
- try {
268
- await worker.stop();
269
- }
270
- catch (error) {
271
- state.state = 'STOP_UNCONFIRMED';
272
- state.error = failure(error);
273
- throw error;
329
+ try {
330
+ if (worker) {
331
+ try {
332
+ await worker.stop();
333
+ }
334
+ catch (error) {
335
+ state.state = 'STOP_UNCONFIRMED';
336
+ state.error = failure(error);
337
+ throw error;
338
+ }
274
339
  }
340
+ await this.stopOwned(state);
341
+ this.#agents.delete(key);
342
+ }
343
+ catch (error) {
344
+ state.state = 'STOP_UNCONFIRMED';
345
+ state.error = failure(error);
346
+ throw error;
347
+ }
348
+ finally {
349
+ state.active.delete(abort);
350
+ settled();
275
351
  }
276
- this.#agents.delete(key);
277
352
  }
278
353
  }
279
354
  async startWorker(state) {
@@ -299,7 +374,7 @@ export class LispManager {
299
374
  layout.compiled = compiled.path;
300
375
  layout.workspace = state.owner.root;
301
376
  layout.protected = this.#config.executionMode === 'protected';
302
- worker = new LispWorker(layout, this.#config, (method, args, context) => this.bridge(state, method, args, context));
377
+ worker = new LispWorker(layout, this.#config, (method, args, context) => this.bridge(state, method, args, context), undefined, () => this.taskAuthority.bound(state.execution, async () => { await this.taskAuthority.authorizeEffect(state.owner, this.#config.executionMode === 'protected' ? 'protected' : 'direct'); }));
303
378
  state.worker = worker;
304
379
  if (this.#closed || state.state !== 'PREFLIGHT' || abort.signal.aborted)
305
380
  fail('CANCELLED', '起動は取り消されています。');
@@ -374,7 +449,7 @@ export class LispManager {
374
449
  }
375
450
  canSuspend(state) {
376
451
  return !this.#closed && !state.disposed && state.state === 'READY' && !state.hostBusy && !state.admission && state.active.size === 0
377
- && Boolean(state.worker?.healthy) && !state.worker?.hasRunningJobs;
452
+ && !state.ownedJobs?.size && !state.ownedCalls?.size && Boolean(state.worker?.healthy) && !state.worker?.hasRunningJobs;
378
453
  }
379
454
  scheduleIdle(state) {
380
455
  clearTimeout(state.idleTimer);
@@ -479,7 +554,62 @@ export class LispManager {
479
554
  }
480
555
  catch { /* independent status/commands still expose the durable recovery state */ }
481
556
  }
482
- async bridge(state, method, args, context) {
557
+ retainOwned(state, value) {
558
+ const receipt = value?.receipt;
559
+ if (receipt && typeof receipt.operationId === 'string' && !(receipt.processStopped === true && ['completed', 'cancelled'].includes(receipt.state ?? '')))
560
+ (state.ownedJobs ??= new Set()).add(receipt.operationId);
561
+ }
562
+ async ownedDispatch(state, action) {
563
+ const abort = new AbortController();
564
+ (state.ownedDispatches ??= new Set()).add(abort);
565
+ try {
566
+ return await action(abort.signal);
567
+ }
568
+ finally {
569
+ state.ownedDispatches?.delete(abort);
570
+ }
571
+ }
572
+ stopOwned(state) {
573
+ if (state.ownedStop)
574
+ return state.ownedStop;
575
+ const stopping = (async () => {
576
+ for (const abort of state.ownedDispatches ?? [])
577
+ abort.abort();
578
+ let timer;
579
+ try {
580
+ await Promise.race([Promise.allSettled([...state.ownedCalls ?? []]), new Promise((_resolve, reject) => {
581
+ timer = setTimeout(() => reject(new LispError('STOP_UNCONFIRMED', 'Owned process admission is unresolved; reconcile before resuming.')), 5000);
582
+ })]);
583
+ }
584
+ finally {
585
+ clearTimeout(timer);
586
+ }
587
+ let failure;
588
+ for (const operationId of state.ownedJobs ?? []) {
589
+ try {
590
+ await confirmOwnedJobStop(operationId, async (cancel, signal) => this.options.toolCall?.(state.owner, 'kioku_result', { operationId, cancel }, signal));
591
+ state.ownedJobs?.delete(operationId);
592
+ }
593
+ catch (error) {
594
+ failure ??= error;
595
+ }
596
+ }
597
+ if (failure)
598
+ throw failure;
599
+ })();
600
+ state.ownedStop = stopping.finally(() => { delete state.ownedStop; });
601
+ return state.ownedStop;
602
+ }
603
+ bridge(state, method, args, context) {
604
+ const pending = this.taskAuthority.bound(state.execution, () => this.bridgeBound(state, method, args, context));
605
+ if (['run', 'start-job', 'tool-call', 'ci-verify'].includes(method)) {
606
+ (state.ownedCalls ??= new Set()).add(pending);
607
+ const settled = () => { state.ownedCalls?.delete(pending); };
608
+ void pending.then(settled, settled);
609
+ }
610
+ return pending;
611
+ }
612
+ async bridgeBound(state, method, args, context) {
483
613
  if (state.state !== 'EVALUATING' || !state.worker?.healthy || this.#closed)
484
614
  fail('STALE_RPC', '現在の評価に属さない要求です。');
485
615
  if (context.generation !== state.worker.generation || context.signal.aborted)
@@ -514,9 +644,13 @@ export class LispManager {
514
644
  if (!this.options.packagesCall)
515
645
  fail('PACKAGES_UNAVAILABLE', 'Package host adapter is unavailable.');
516
646
  const request = PackageRequest.parse(args);
647
+ if (request.kind === 'update')
648
+ await this.taskAuthority.authorizeEffect(state.owner);
517
649
  if (request.kind === 'update' && (!state.currentVerification || state.packageBase))
518
650
  fail('PACKAGES_UPDATE_SCOPE', 'Use exactly one update-lockfiles call in a persistent lisp_eval; task calls cannot propose workspace updates.');
519
651
  const result = await this.options.packagesCall(state.owner, request, context.signal);
652
+ if (request.kind === 'update')
653
+ await this.taskAuthority.authorizeEffect(state.owner);
520
654
  if (this.#closed || state.state !== 'EVALUATING' || state.worker.generation !== context.generation || context.signal.aborted)
521
655
  fail('STALE_RPC', 'Package operation is no longer current.');
522
656
  if (result.base)
@@ -539,18 +673,22 @@ export class LispManager {
539
673
  if (method === 'job-status' || method === 'cancel-job') {
540
674
  const request = z.object({ id: z.string().min(1) }).strict().parse(args);
541
675
  const value = await this.options.toolCall(state.owner, 'kioku_result', { operationId: request.id, cancel: method === 'cancel-job' }, context.signal);
542
- if (value.receipt?.state !== 'started')
676
+ if (value.receipt?.processStopped === true && ['completed', 'cancelled'].includes(value.receipt.state))
543
677
  state.ownedJobs?.delete(request.id);
544
678
  return value;
545
679
  }
546
680
  const input = z.object({ program: z.string().min(1), argv: z.array(z.string()), timeoutMs: z.number().int().positive(), directory: z.string().optional() }).strict().parse(args);
547
681
  const quote = (value) => "'" + value.replaceAll("'", "'\\''") + "'";
548
682
  const directory = input.directory ?? '.';
549
- const value = await this.options.toolCall(state.owner, 'kioku_exec', { command: [input.program, ...input.argv].map(quote).join(' '), cwd: isAbsolute(directory) ? directory : join(state.owner.root, directory), timeoutMs: input.timeoutMs, background: method === 'start-job' }, method === 'start-job' ? undefined : context.signal, `lisp-rpc:${context.generation}:${context.evaluationId}:${context.rpcId}`);
550
- if (method === 'start-job') {
551
- (state.ownedJobs ??= new Set()).add(value.receipt.operationId);
683
+ const lease = await this.taskAuthority.authorizeEffect(state.owner, 'owned');
684
+ context.signal.throwIfAborted();
685
+ const value = await this.ownedDispatch(state, signal => this.options.toolCall(state.owner, 'kioku_exec', { command: [input.program, ...input.argv].map(quote).join(' '), cwd: isAbsolute(directory) ? directory : join(state.owner.root, directory), timeoutMs: input.timeoutMs, background: method === 'start-job' }, method === 'start-job' ? signal : AbortSignal.any([signal, context.signal]), `lisp-rpc:${context.generation}:${context.evaluationId}:${context.rpcId}`, lease));
686
+ // A launched job must remain cancellable even if task authority changed
687
+ // while its start acknowledgement was in flight.
688
+ this.retainOwned(state, value);
689
+ await this.taskAuthority.authorizeEffect(state.owner, 'owned');
690
+ if (method === 'start-job')
552
691
  return value.receipt.operationId;
553
- }
554
692
  return { code: value.exitCode, stdout: value.output ?? '', stderr: '', receipt: value.receipt };
555
693
  }
556
694
  if (method === 'tools-list')
@@ -559,7 +697,15 @@ export class LispManager {
559
697
  const parsed = z.object({ name: z.enum(['lisp_status', 'kioku_read', 'kioku_write', 'kioku_edit', 'kioku_remove', 'kioku_exec', 'kioku_result']), args: z.record(z.string(), z.unknown()) }).strict().parse(args);
560
698
  if (!this.options.toolCall)
561
699
  fail('HOST_ADAPTER_UNAVAILABLE', 'このホストには監査済みアダプターがありません。');
562
- return this.options.toolCall(state.owner, parsed.name, parsed.args, context.signal, `lisp-rpc:${context.generation}:${context.evaluationId}:${context.rpcId}`);
700
+ const lease = ['kioku_write', 'kioku_edit', 'kioku_remove', 'kioku_exec'].includes(parsed.name)
701
+ ? await this.taskAuthority.authorizeEffect(state.owner, 'owned') : undefined;
702
+ context.signal.throwIfAborted();
703
+ const result = await this.ownedDispatch(state, signal => this.options.toolCall(state.owner, parsed.name, parsed.args, parsed.name === 'kioku_exec' && parsed.args.background === true ? signal : AbortSignal.any([signal, context.signal]), `lisp-rpc:${context.generation}:${context.evaluationId}:${context.rpcId}`, lease));
704
+ if (parsed.name === 'kioku_exec')
705
+ this.retainOwned(state, result);
706
+ if (lease)
707
+ await this.taskAuthority.authorizeEffect(state.owner, 'owned');
708
+ return result;
563
709
  }
564
710
  if (method === 'ci-list-runs' || method === 'ci-failed-log' || method === 'ci-verify') {
565
711
  if (!this.options.ciCall)
@@ -573,7 +719,14 @@ export class LispManager {
573
719
  const active = [...state.active];
574
720
  if (active.length !== 1)
575
721
  fail('HOST_STATE', 'CI 呼び出しの実行主体を一意に確認できません。');
722
+ if (request.kind === 'verify')
723
+ await this.taskAuthority.authorizeEffect(state.owner);
724
+ context.signal.throwIfAborted();
576
725
  const result = await this.options.ciCall(state.owner, request, active[0].signal, state.worker.layout.scratch);
726
+ if (request.kind === 'verify')
727
+ this.retainOwned(state, result);
728
+ if (request.kind === 'verify')
729
+ await this.taskAuthority.authorizeEffect(state.owner);
577
730
  if (request.kind === 'verify' && state.currentVerification?.generation === context.generation) {
578
731
  state.currentVerification.results.push({ request, result });
579
732
  }
@@ -593,10 +746,14 @@ export class LispManager {
593
746
  if (await this.#store.countByKind(state.owner.sessionId, 'artifact') >= 1000)
594
747
  fail('ARTIFACT_LIMIT', 'このセッションの成果物数が上限です。');
595
748
  const id = `artifact-${randomUUID()}`, target = join(root, id);
749
+ await this.taskAuthority.authorizeEffect(state.owner);
596
750
  await this.#store.reserve(state.owner, id, 'artifact', digest(source), state.worker.generation, { source, target });
751
+ const bytes = await checkedBytes(source);
752
+ await this.taskAuthority.authorizeEffect(state.owner);
597
753
  const file = await open(target, 'wx', 0o600);
598
754
  try {
599
- await file.writeFile(await checkedBytes(source));
755
+ await this.taskAuthority.authorizeEffect(state.owner);
756
+ await file.writeFile(bytes);
600
757
  await file.sync();
601
758
  }
602
759
  finally {
@@ -612,6 +769,25 @@ export class LispManager {
612
769
  }
613
770
  fail('UNKNOWN_ADAPTER', 'このホスト要求には対応していません。');
614
771
  }
772
+ /** Session-local process evidence only; observing it never creates or wakes a worker. */
773
+ taskJobsIdle(owner) {
774
+ if (this.#closed)
775
+ return false;
776
+ const root = this.enabled.get(owner.sessionId);
777
+ if (root !== undefined && root !== owner.root)
778
+ return false;
779
+ for (const state of this.#agents.values()) {
780
+ if (state.owner.sessionId !== owner.sessionId)
781
+ continue;
782
+ if (state.owner.root !== owner.root || state.state === 'STOPPING' || state.state === 'STOP_UNCONFIRMED')
783
+ return false;
784
+ if (state.ownedJobs?.size || state.ownedCalls?.size)
785
+ return false;
786
+ if (state.worker && (!state.worker.jobsIdle || (!state.worker.healthy && !state.worker.stopped)))
787
+ return false;
788
+ }
789
+ return true;
790
+ }
615
791
  async status(owner, offset) {
616
792
  const policy = this.options.questions?.approvalPolicy;
617
793
  const approval = { mode: policy?.mode() ?? this.#config.approvalMode, scope: 'profile', writable: policy?.writable() ?? false };
@@ -658,7 +834,7 @@ export class LispManager {
658
834
  return Promise.resolve(pending === hash ? { replay: true, code: 'IN_PROGRESS', state: 'RUNNING' } : failure(new LispError('ID_CONFLICT', '実行中の操作 ID に異なる入力があります。')));
659
835
  if (key)
660
836
  this.#inflight.set(key, hash);
661
- const result = this.dispatch(owner, tool, input, signal);
837
+ const result = this.taskAuthority.run(owner, () => this.dispatch(owner, tool, input, signal)).catch(error => failure(error));
662
838
  this.#executions.set(result, owner.sessionId);
663
839
  const finished = () => {
664
840
  this.#executions.delete(result);
@@ -905,7 +1081,9 @@ export class LispManager {
905
1081
  await this.#store.reserve(owner, id, tool, hash, 'host', { ...request, candidateDigest: digest(candidate) });
906
1082
  let scratchRoot;
907
1083
  try {
1084
+ await this.taskAuthority.authorizeEffect(owner);
908
1085
  scratchRoot = await materializeCandidate(owner, this.#store, candidate, this.options.dataRoot);
1086
+ await this.taskAuthority.authorizeEffect(owner);
909
1087
  const execution = await this.options.ciCall(owner, { kind: 'verify', target: request.target,
910
1088
  ...(request.script ? { script: request.script } : {}), location: 'scratch', directory: '.' }, signal ?? new AbortController().signal, scratchRoot);
911
1089
  const recorded = { candidateRef: request.candidateRef, candidateDigest: digest(candidate), execution,
@@ -986,6 +1164,7 @@ export class LispManager {
986
1164
  message: '休止中の Lisp を自動起動しました。以前の変数・関数・参照は失われています。必要な定義を作り直してから実行してください。この要求のコードは実行していません。過去の副作用を再実行しないでください。' };
987
1165
  }
988
1166
  if (tool === 'lisp_reset') {
1167
+ await this.taskAuthority.authorizeEffect(owner);
989
1168
  if (state.state !== 'READY')
990
1169
  fail('RECOVERY_REQUIRED', '異常停止からの再開には /kioku-lisp recover を使ってください。');
991
1170
  await this.#store.reserve(owner, id, tool, hash, state.worker?.generation ?? '', input);
@@ -1006,6 +1185,7 @@ export class LispManager {
1006
1185
  fail(state.state === 'EVALUATING' ? 'BUSY' : 'RECOVERY_REQUIRED', 'Lisp は実行可能な状態ではありません。/kioku-lisp status で確認してください。');
1007
1186
  const worker = state.worker;
1008
1187
  state.state = 'EVALUATING'; // reserve the slot before the first await
1188
+ state.execution = this.taskAuthority.current();
1009
1189
  const abort = new AbortController();
1010
1190
  state.active.add(abort);
1011
1191
  const combined = signal ? AbortSignal.any([signal, abort.signal]) : abort.signal;
@@ -1156,9 +1336,13 @@ export class LispManager {
1156
1336
  for (const abort of state.active)
1157
1337
  abort.abort(new LispError('CANCELLED', 'Lisp の処理を取り消しました。'));
1158
1338
  try {
1159
- for (const operationId of state.ownedJobs ?? [])
1160
- await this.options.toolCall?.(state.owner, 'kioku_result', { operationId, cancel: true });
1161
- state.ownedJobs?.clear();
1339
+ let ownedStopFailure;
1340
+ try {
1341
+ await this.stopOwned(state);
1342
+ }
1343
+ catch (error) {
1344
+ ownedStopFailure = new LispError('STOP_UNCONFIRMED', `管理中のプロセスの停止を確認できません。${failure(error).message}`);
1345
+ }
1162
1346
  await state.worker?.stop();
1163
1347
  if (state.admission) {
1164
1348
  try {
@@ -1170,6 +1354,8 @@ export class LispManager {
1170
1354
  }
1171
1355
  }
1172
1356
  this.#compiled.assertStopped();
1357
+ if (ownedStopFailure)
1358
+ throw ownedStopFailure;
1173
1359
  state.state = 'RECOVERY_REQUIRED';
1174
1360
  }
1175
1361
  catch (error) {
@@ -1177,7 +1363,14 @@ export class LispManager {
1177
1363
  throw error;
1178
1364
  }
1179
1365
  }
1180
- async recover(owner, signal) {
1366
+ recover(owner, signal) {
1367
+ return this.taskAuthority.run(owner, async () => {
1368
+ this.entry(owner);
1369
+ await this.taskAuthority.authorizeEffect(owner);
1370
+ return this.recoverBound(owner, signal);
1371
+ });
1372
+ }
1373
+ async recoverBound(owner, signal) {
1181
1374
  if (await this.isTaskMode(owner)) {
1182
1375
  await this.stopTaskWorkers(owner.sessionId);
1183
1376
  await Promise.allSettled([...this.#executions].filter(([, session]) => session === owner.sessionId).map(([promise]) => promise));
@@ -1202,6 +1395,7 @@ export class LispManager {
1202
1395
  await this.#store.transition(boundOwner, op.operation_id, [op.state], 'ABANDONED', { ...await recordedResult(this.#store, boundOwner, op), ok: false, state: 'ABANDONED', humanRecovery: true });
1203
1396
  }
1204
1397
  signal?.throwIfAborted();
1398
+ await this.taskAuthority.authorizeEffect(owner);
1205
1399
  await this.startWorker(state);
1206
1400
  return this.status(owner);
1207
1401
  }
@@ -1216,7 +1410,14 @@ export class LispManager {
1216
1410
  await this.#store.transition(owner, id, [op.state], 'ABANDONED', { ...await recordedResult(this.#store, owner, op), ok: false, state: 'ABANDONED', humanAbandoned: true, reapply: false });
1217
1411
  return { ok: true, recovery: '/kioku-lisp recover で新しい Lisp を起動できます。ファイルを自動復元・再適用しません。' };
1218
1412
  }
1219
- async restore(owner, id, signal) {
1413
+ restore(owner, id, signal) {
1414
+ return this.taskAuthority.run(owner, async () => {
1415
+ this.entry(owner);
1416
+ await this.taskAuthority.authorizeEffect(owner);
1417
+ return this.restoreBound(owner, id, signal);
1418
+ });
1419
+ }
1420
+ async restoreBound(owner, id, signal) {
1220
1421
  const state = this.entry(owner);
1221
1422
  await this.cancel(state);
1222
1423
  await Promise.allSettled([...this.#executions].filter(([, session]) => session === owner.sessionId).map(([promise]) => promise));