@cleocode/core 2026.6.12 → 2026.6.13

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 (385) hide show
  1. package/dist/conduit/local-transport.d.ts +12 -0
  2. package/dist/conduit/local-transport.d.ts.map +1 -1
  3. package/dist/conduit/local-transport.js +53 -23
  4. package/dist/conduit/local-transport.js.map +1 -1
  5. package/dist/crypto/credentials.d.ts +37 -0
  6. package/dist/crypto/credentials.d.ts.map +1 -1
  7. package/dist/crypto/credentials.js +110 -0
  8. package/dist/crypto/credentials.js.map +1 -1
  9. package/dist/dispatch/contracts/derive-output-contract.d.ts +86 -0
  10. package/dist/dispatch/contracts/derive-output-contract.d.ts.map +1 -0
  11. package/dist/dispatch/contracts/derive-output-contract.js +347 -0
  12. package/dist/dispatch/contracts/derive-output-contract.js.map +1 -0
  13. package/dist/dispatch/contracts/ensures-schema.d.ts +77 -0
  14. package/dist/dispatch/contracts/ensures-schema.d.ts.map +1 -0
  15. package/dist/dispatch/contracts/ensures-schema.js +91 -0
  16. package/dist/dispatch/contracts/ensures-schema.js.map +1 -0
  17. package/dist/dispatch/contracts/output-contracts.d.ts +27 -5
  18. package/dist/dispatch/contracts/output-contracts.d.ts.map +1 -1
  19. package/dist/dispatch/contracts/output-contracts.js +29 -6
  20. package/dist/dispatch/contracts/output-contracts.js.map +1 -1
  21. package/dist/docs/export-document.js +2294 -1250
  22. package/dist/docs/export-document.js.map +3 -3
  23. package/dist/go/driver.d.ts +132 -7
  24. package/dist/go/driver.d.ts.map +1 -1
  25. package/dist/go/driver.js +135 -10
  26. package/dist/go/driver.js.map +1 -1
  27. package/dist/go/index.d.ts +1 -1
  28. package/dist/go/index.d.ts.map +1 -1
  29. package/dist/go/index.js +1 -1
  30. package/dist/go/index.js.map +1 -1
  31. package/dist/index.d.ts +1 -0
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +5 -0
  34. package/dist/index.js.map +1 -1
  35. package/dist/internal.d.ts +13 -10
  36. package/dist/internal.d.ts.map +1 -1
  37. package/dist/internal.js +11 -11
  38. package/dist/internal.js.map +1 -1
  39. package/dist/lifecycle/engine-ops.d.ts.map +1 -1
  40. package/dist/lifecycle/engine-ops.js +7 -4
  41. package/dist/lifecycle/engine-ops.js.map +1 -1
  42. package/dist/lifecycle/ivtr-loop.d.ts +108 -183
  43. package/dist/lifecycle/ivtr-loop.d.ts.map +1 -1
  44. package/dist/lifecycle/ivtr-loop.js +207 -522
  45. package/dist/lifecycle/ivtr-loop.js.map +1 -1
  46. package/dist/llm/auxiliary-fallback.js +1 -1
  47. package/dist/llm/auxiliary-fallback.js.map +1 -1
  48. package/dist/llm/cli-ops.d.ts +14 -1
  49. package/dist/llm/cli-ops.d.ts.map +1 -1
  50. package/dist/llm/cli-ops.js +41 -12
  51. package/dist/llm/cli-ops.js.map +1 -1
  52. package/dist/llm/concrete-session.d.ts.map +1 -1
  53. package/dist/llm/concrete-session.js +4 -0
  54. package/dist/llm/concrete-session.js.map +1 -1
  55. package/dist/llm/credentials.d.ts +35 -0
  56. package/dist/llm/credentials.d.ts.map +1 -1
  57. package/dist/llm/credentials.js +49 -0
  58. package/dist/llm/credentials.js.map +1 -1
  59. package/dist/llm/index.d.ts +4 -0
  60. package/dist/llm/index.d.ts.map +1 -1
  61. package/dist/llm/index.js +4 -0
  62. package/dist/llm/index.js.map +1 -1
  63. package/dist/llm/pi/gondolin-loader.d.ts +241 -0
  64. package/dist/llm/pi/gondolin-loader.d.ts.map +1 -0
  65. package/dist/llm/pi/gondolin-loader.js +195 -0
  66. package/dist/llm/pi/gondolin-loader.js.map +1 -0
  67. package/dist/llm/pi/index.d.ts +28 -0
  68. package/dist/llm/pi/index.d.ts.map +1 -0
  69. package/dist/llm/pi/index.js +27 -0
  70. package/dist/llm/pi/index.js.map +1 -0
  71. package/dist/llm/pi/pi-agent-adapter.d.ts +135 -0
  72. package/dist/llm/pi/pi-agent-adapter.d.ts.map +1 -0
  73. package/dist/llm/pi/pi-agent-adapter.js +329 -0
  74. package/dist/llm/pi/pi-agent-adapter.js.map +1 -0
  75. package/dist/llm/pi/pi-errors.d.ts +161 -0
  76. package/dist/llm/pi/pi-errors.d.ts.map +1 -0
  77. package/dist/llm/pi/pi-errors.js +296 -0
  78. package/dist/llm/pi/pi-errors.js.map +1 -0
  79. package/dist/llm/pi/pi-execution-env.d.ts +286 -0
  80. package/dist/llm/pi/pi-execution-env.d.ts.map +1 -0
  81. package/dist/llm/pi/pi-execution-env.js +406 -0
  82. package/dist/llm/pi/pi-execution-env.js.map +1 -0
  83. package/dist/llm/pi/pi-gondolin-env.d.ts +227 -0
  84. package/dist/llm/pi/pi-gondolin-env.d.ts.map +1 -0
  85. package/dist/llm/pi/pi-gondolin-env.js +541 -0
  86. package/dist/llm/pi/pi-gondolin-env.js.map +1 -0
  87. package/dist/llm/pi/pi-session-storage.d.ts +154 -0
  88. package/dist/llm/pi/pi-session-storage.d.ts.map +1 -0
  89. package/dist/llm/pi/pi-session-storage.js +314 -0
  90. package/dist/llm/pi/pi-session-storage.js.map +1 -0
  91. package/dist/llm/pi/pi-stream-fn.d.ts +124 -0
  92. package/dist/llm/pi/pi-stream-fn.d.ts.map +1 -0
  93. package/dist/llm/pi/pi-stream-fn.js +504 -0
  94. package/dist/llm/pi/pi-stream-fn.js.map +1 -0
  95. package/dist/llm/pi/pi-tool-bridge.d.ts +99 -0
  96. package/dist/llm/pi/pi-tool-bridge.d.ts.map +1 -0
  97. package/dist/llm/pi/pi-tool-bridge.js +117 -0
  98. package/dist/llm/pi/pi-tool-bridge.js.map +1 -0
  99. package/dist/llm/pi/pi-types.d.ts +56 -0
  100. package/dist/llm/pi/pi-types.d.ts.map +1 -0
  101. package/dist/llm/pi/pi-types.js +16 -0
  102. package/dist/llm/pi/pi-types.js.map +1 -0
  103. package/dist/llm/pi/resolve-execution-env.d.ts +194 -0
  104. package/dist/llm/pi/resolve-execution-env.d.ts.map +1 -0
  105. package/dist/llm/pi/resolve-execution-env.js +132 -0
  106. package/dist/llm/pi/resolve-execution-env.js.map +1 -0
  107. package/dist/llm/plugin-facade.js +2253 -1151
  108. package/dist/llm/plugin-facade.js.map +3 -3
  109. package/dist/llm/role-executor.d.ts.map +1 -1
  110. package/dist/llm/role-executor.js +8 -5
  111. package/dist/llm/role-executor.js.map +1 -1
  112. package/dist/llm/role-resolver.d.ts +46 -14
  113. package/dist/llm/role-resolver.d.ts.map +1 -1
  114. package/dist/llm/role-resolver.js +178 -20
  115. package/dist/llm/role-resolver.js.map +1 -1
  116. package/dist/llm/sealed-credential.d.ts +125 -0
  117. package/dist/llm/sealed-credential.d.ts.map +1 -0
  118. package/dist/llm/sealed-credential.js +133 -0
  119. package/dist/llm/sealed-credential.js.map +1 -0
  120. package/dist/llm/session-factory.d.ts.map +1 -1
  121. package/dist/llm/session-factory.js +6 -2
  122. package/dist/llm/session-factory.js.map +1 -1
  123. package/dist/llm/system-key.d.ts +67 -0
  124. package/dist/llm/system-key.d.ts.map +1 -0
  125. package/dist/llm/system-key.js +87 -0
  126. package/dist/llm/system-key.js.map +1 -0
  127. package/dist/llm/system-of-use-registry.d.ts +119 -0
  128. package/dist/llm/system-of-use-registry.d.ts.map +1 -0
  129. package/dist/llm/system-of-use-registry.js +200 -0
  130. package/dist/llm/system-of-use-registry.js.map +1 -0
  131. package/dist/llm/system-resolver.d.ts +32 -10
  132. package/dist/llm/system-resolver.d.ts.map +1 -1
  133. package/dist/llm/system-resolver.js +70 -18
  134. package/dist/llm/system-resolver.js.map +1 -1
  135. package/dist/memory/brain-writer-thread.d.ts.map +1 -1
  136. package/dist/memory/brain-writer-thread.js +116 -11
  137. package/dist/memory/brain-writer-thread.js.map +1 -1
  138. package/dist/memory/claude-mem-migration.d.ts.map +1 -1
  139. package/dist/memory/claude-mem-migration.js +21 -0
  140. package/dist/memory/claude-mem-migration.js.map +1 -1
  141. package/dist/memory/graph-memory-bridge.d.ts.map +1 -1
  142. package/dist/memory/graph-memory-bridge.js +32 -25
  143. package/dist/memory/graph-memory-bridge.js.map +1 -1
  144. package/dist/memory/llm-backend-resolver.js +23 -5
  145. package/dist/memory/llm-backend-resolver.js.map +1 -1
  146. package/dist/nexus/migrations/M-split-graph.d.ts.map +1 -1
  147. package/dist/nexus/migrations/M-split-graph.js +60 -53
  148. package/dist/nexus/migrations/M-split-graph.js.map +1 -1
  149. package/dist/orchestrate/pivot.d.ts.map +1 -1
  150. package/dist/orchestrate/pivot.js +20 -2
  151. package/dist/orchestrate/pivot.js.map +1 -1
  152. package/dist/release/engine-ops.js +2 -2
  153. package/dist/release/engine-ops.js.map +1 -1
  154. package/dist/routing/capability-matrix.d.ts.map +1 -1
  155. package/dist/routing/capability-matrix.js +0 -57
  156. package/dist/routing/capability-matrix.js.map +1 -1
  157. package/dist/selfimprove/budget.d.ts +206 -0
  158. package/dist/selfimprove/budget.d.ts.map +1 -0
  159. package/dist/selfimprove/budget.js +203 -0
  160. package/dist/selfimprove/budget.js.map +1 -0
  161. package/dist/selfimprove/dhq-adapter.d.ts +105 -0
  162. package/dist/selfimprove/dhq-adapter.d.ts.map +1 -0
  163. package/dist/selfimprove/dhq-adapter.js +95 -0
  164. package/dist/selfimprove/dhq-adapter.js.map +1 -0
  165. package/dist/selfimprove/draft-pr.d.ts +129 -0
  166. package/dist/selfimprove/draft-pr.d.ts.map +1 -0
  167. package/dist/selfimprove/draft-pr.js +158 -0
  168. package/dist/selfimprove/draft-pr.js.map +1 -0
  169. package/dist/selfimprove/envelope-diff.d.ts +162 -0
  170. package/dist/selfimprove/envelope-diff.d.ts.map +1 -0
  171. package/dist/selfimprove/envelope-diff.js +321 -0
  172. package/dist/selfimprove/envelope-diff.js.map +1 -0
  173. package/dist/selfimprove/replay.d.ts +121 -0
  174. package/dist/selfimprove/replay.d.ts.map +1 -0
  175. package/dist/selfimprove/replay.js +109 -0
  176. package/dist/selfimprove/replay.js.map +1 -0
  177. package/dist/selfimprove/run-loop.d.ts +148 -0
  178. package/dist/selfimprove/run-loop.d.ts.map +1 -0
  179. package/dist/selfimprove/run-loop.js +240 -0
  180. package/dist/selfimprove/run-loop.js.map +1 -0
  181. package/dist/selfimprove/scenario.d.ts +145 -0
  182. package/dist/selfimprove/scenario.d.ts.map +1 -0
  183. package/dist/selfimprove/scenario.js +243 -0
  184. package/dist/selfimprove/scenario.js.map +1 -0
  185. package/dist/sentient/daemon-entry.js +5 -0
  186. package/dist/sentient/daemon-entry.js.map +1 -1
  187. package/dist/sentient/daemon.d.ts.map +1 -1
  188. package/dist/sentient/daemon.js +19 -0
  189. package/dist/sentient/daemon.js.map +1 -1
  190. package/dist/sentient/hygiene-scan.d.ts.map +1 -1
  191. package/dist/sentient/hygiene-scan.js +14 -6
  192. package/dist/sentient/hygiene-scan.js.map +1 -1
  193. package/dist/sessions/briefing.d.ts.map +1 -1
  194. package/dist/sessions/briefing.js +13 -9
  195. package/dist/sessions/briefing.js.map +1 -1
  196. package/dist/sessions/connection-session-handle.d.ts +161 -0
  197. package/dist/sessions/connection-session-handle.d.ts.map +1 -0
  198. package/dist/sessions/connection-session-handle.js +168 -0
  199. package/dist/sessions/connection-session-handle.js.map +1 -0
  200. package/dist/sessions/handoff.d.ts.map +1 -1
  201. package/dist/sessions/handoff.js +9 -0
  202. package/dist/sessions/handoff.js.map +1 -1
  203. package/dist/sessions/index.d.ts +4 -1
  204. package/dist/sessions/index.d.ts.map +1 -1
  205. package/dist/sessions/index.js +31 -1
  206. package/dist/sessions/index.js.map +1 -1
  207. package/dist/sessions/session-id.d.ts +34 -0
  208. package/dist/sessions/session-id.d.ts.map +1 -1
  209. package/dist/sessions/session-id.js +37 -0
  210. package/dist/sessions/session-id.js.map +1 -1
  211. package/dist/sessions/session-manifest-mirror.d.ts +115 -0
  212. package/dist/sessions/session-manifest-mirror.d.ts.map +1 -0
  213. package/dist/sessions/session-manifest-mirror.js +250 -0
  214. package/dist/sessions/session-manifest-mirror.js.map +1 -0
  215. package/dist/sessions/session-switch.d.ts.map +1 -1
  216. package/dist/sessions/session-switch.js +5 -2
  217. package/dist/sessions/session-switch.js.map +1 -1
  218. package/dist/store/converters.d.ts.map +1 -1
  219. package/dist/store/converters.js +2 -0
  220. package/dist/store/converters.js.map +1 -1
  221. package/dist/store/db-helpers.d.ts.map +1 -1
  222. package/dist/store/db-helpers.js +2 -0
  223. package/dist/store/db-helpers.js.map +1 -1
  224. package/dist/store/dual-scope-db.d.ts.map +1 -1
  225. package/dist/store/dual-scope-db.js +87 -47
  226. package/dist/store/dual-scope-db.js.map +1 -1
  227. package/dist/store/pi-session-store.d.ts +151 -0
  228. package/dist/store/pi-session-store.d.ts.map +1 -0
  229. package/dist/store/pi-session-store.js +166 -0
  230. package/dist/store/pi-session-store.js.map +1 -0
  231. package/dist/store/safety-data-accessor.d.ts +1 -0
  232. package/dist/store/safety-data-accessor.d.ts.map +1 -1
  233. package/dist/store/safety-data-accessor.js +5 -0
  234. package/dist/store/safety-data-accessor.js.map +1 -1
  235. package/dist/store/schema/cleo-global/accounts.d.ts +357 -0
  236. package/dist/store/schema/cleo-global/accounts.d.ts.map +1 -0
  237. package/dist/store/schema/cleo-global/accounts.js +136 -0
  238. package/dist/store/schema/cleo-global/accounts.js.map +1 -0
  239. package/dist/store/schema/cleo-global/index.d.ts +2 -0
  240. package/dist/store/schema/cleo-global/index.d.ts.map +1 -1
  241. package/dist/store/schema/cleo-global/index.js +2 -0
  242. package/dist/store/schema/cleo-global/index.js.map +1 -1
  243. package/dist/store/schema/cleo-global/session-manifest.d.ts +217 -0
  244. package/dist/store/schema/cleo-global/session-manifest.d.ts.map +1 -0
  245. package/dist/store/schema/cleo-global/session-manifest.js +99 -0
  246. package/dist/store/schema/cleo-global/session-manifest.js.map +1 -0
  247. package/dist/store/schema/cleo-project/tasks-core.d.ts +16 -0
  248. package/dist/store/schema/cleo-project/tasks-core.d.ts.map +1 -1
  249. package/dist/store/schema/cleo-project/tasks-core.js +14 -0
  250. package/dist/store/schema/cleo-project/tasks-core.js.map +1 -1
  251. package/dist/store/schema/tasks.d.ts +16 -0
  252. package/dist/store/schema/tasks.d.ts.map +1 -1
  253. package/dist/store/schema/tasks.js +10 -0
  254. package/dist/store/schema/tasks.js.map +1 -1
  255. package/dist/store/selfimprove-dhq-schema.d.ts +284 -0
  256. package/dist/store/selfimprove-dhq-schema.d.ts.map +1 -0
  257. package/dist/store/selfimprove-dhq-schema.js +128 -0
  258. package/dist/store/selfimprove-dhq-schema.js.map +1 -0
  259. package/dist/store/selfimprove-dhq-store.d.ts +175 -0
  260. package/dist/store/selfimprove-dhq-store.d.ts.map +1 -0
  261. package/dist/store/selfimprove-dhq-store.js +182 -0
  262. package/dist/store/selfimprove-dhq-store.js.map +1 -0
  263. package/dist/store/session-store.d.ts +52 -13
  264. package/dist/store/session-store.d.ts.map +1 -1
  265. package/dist/store/session-store.js +71 -13
  266. package/dist/store/session-store.js.map +1 -1
  267. package/dist/store/sqlite-data-accessor.d.ts.map +1 -1
  268. package/dist/store/sqlite-data-accessor.js +7 -0
  269. package/dist/store/sqlite-data-accessor.js.map +1 -1
  270. package/dist/store/umbrella-data-accessor.d.ts +1 -0
  271. package/dist/store/umbrella-data-accessor.d.ts.map +1 -1
  272. package/dist/store/umbrella-data-accessor.js +5 -0
  273. package/dist/store/umbrella-data-accessor.js.map +1 -1
  274. package/dist/store/validation-schemas.d.ts +32 -0
  275. package/dist/store/validation-schemas.d.ts.map +1 -1
  276. package/dist/store/writer-lease-schema.d.ts +392 -0
  277. package/dist/store/writer-lease-schema.d.ts.map +1 -0
  278. package/dist/store/writer-lease-schema.js +142 -0
  279. package/dist/store/writer-lease-schema.js.map +1 -0
  280. package/dist/store/writer-lease.d.ts +368 -0
  281. package/dist/store/writer-lease.d.ts.map +1 -0
  282. package/dist/store/writer-lease.js +1002 -0
  283. package/dist/store/writer-lease.js.map +1 -0
  284. package/dist/tasks/backfill-child-projections.d.ts.map +1 -1
  285. package/dist/tasks/backfill-child-projections.js +14 -9
  286. package/dist/tasks/backfill-child-projections.js.map +1 -1
  287. package/dist/tasks/complete.d.ts.map +1 -1
  288. package/dist/tasks/complete.js +7 -10
  289. package/dist/tasks/complete.js.map +1 -1
  290. package/dist/tasks/duplicate-detector.d.ts.map +1 -1
  291. package/dist/tasks/duplicate-detector.js +14 -7
  292. package/dist/tasks/duplicate-detector.js.map +1 -1
  293. package/dist/telemetry/index.d.ts.map +1 -1
  294. package/dist/telemetry/index.js +10 -4
  295. package/dist/telemetry/index.js.map +1 -1
  296. package/dist/tools/agent-registry.d.ts +250 -0
  297. package/dist/tools/agent-registry.d.ts.map +1 -0
  298. package/dist/tools/agent-registry.js +292 -0
  299. package/dist/tools/agent-registry.js.map +1 -0
  300. package/dist/tools/agent-tool-families.d.ts +107 -0
  301. package/dist/tools/agent-tool-families.d.ts.map +1 -0
  302. package/dist/tools/agent-tool-families.js +527 -0
  303. package/dist/tools/agent-tool-families.js.map +1 -0
  304. package/dist/tools/browser-driver.d.ts +183 -0
  305. package/dist/tools/browser-driver.d.ts.map +1 -0
  306. package/dist/tools/browser-driver.js +242 -0
  307. package/dist/tools/browser-driver.js.map +1 -0
  308. package/dist/tools/builtin-agent-tools.d.ts +36 -0
  309. package/dist/tools/builtin-agent-tools.d.ts.map +1 -0
  310. package/dist/tools/builtin-agent-tools.js +150 -0
  311. package/dist/tools/builtin-agent-tools.js.map +1 -0
  312. package/dist/tools/dispatch.d.ts +370 -0
  313. package/dist/tools/dispatch.d.ts.map +1 -0
  314. package/dist/tools/dispatch.js +505 -0
  315. package/dist/tools/dispatch.js.map +1 -0
  316. package/dist/tools/env-scrub.d.ts +93 -0
  317. package/dist/tools/env-scrub.d.ts.map +1 -0
  318. package/dist/tools/env-scrub.js +176 -0
  319. package/dist/tools/env-scrub.js.map +1 -0
  320. package/dist/tools/fs.d.ts +30 -0
  321. package/dist/tools/fs.d.ts.map +1 -1
  322. package/dist/tools/fs.js +55 -2
  323. package/dist/tools/fs.js.map +1 -1
  324. package/dist/tools/guard.d.ts +15 -0
  325. package/dist/tools/guard.d.ts.map +1 -1
  326. package/dist/tools/guard.js +49 -12
  327. package/dist/tools/guard.js.map +1 -1
  328. package/dist/tools/index.d.ts +10 -0
  329. package/dist/tools/index.d.ts.map +1 -1
  330. package/dist/tools/index.js +37 -0
  331. package/dist/tools/index.js.map +1 -1
  332. package/dist/tools/pty.d.ts +45 -0
  333. package/dist/tools/pty.d.ts.map +1 -0
  334. package/dist/tools/pty.js +166 -0
  335. package/dist/tools/pty.js.map +1 -0
  336. package/dist/tools/schema-gen.d.ts +57 -0
  337. package/dist/tools/schema-gen.d.ts.map +1 -0
  338. package/dist/tools/schema-gen.js +52 -0
  339. package/dist/tools/schema-gen.js.map +1 -0
  340. package/dist/tools/shell.d.ts +12 -0
  341. package/dist/tools/shell.d.ts.map +1 -1
  342. package/dist/tools/shell.js +14 -1
  343. package/dist/tools/shell.js.map +1 -1
  344. package/dist/tools/web-agent-tools.d.ts +72 -0
  345. package/dist/tools/web-agent-tools.d.ts.map +1 -0
  346. package/dist/tools/web-agent-tools.js +393 -0
  347. package/dist/tools/web-agent-tools.js.map +1 -0
  348. package/dist/tools/web-search-backends.d.ts +156 -0
  349. package/dist/tools/web-search-backends.d.ts.map +1 -0
  350. package/dist/tools/web-search-backends.js +290 -0
  351. package/dist/tools/web-search-backends.js.map +1 -0
  352. package/dist/validation/ops.d.ts +1 -15
  353. package/dist/validation/ops.d.ts.map +1 -1
  354. package/dist/validation/ops.js +0 -20
  355. package/dist/validation/ops.js.map +1 -1
  356. package/migrations/drizzle-cleo-global/20260607000000_t11891-writer-leases/migration.sql +55 -0
  357. package/migrations/drizzle-cleo-global/20260607010000_t11639-session-manifest/migration.sql +43 -0
  358. package/migrations/drizzle-cleo-global/20260608000000_t11899-pi-session-tree/migration.sql +52 -0
  359. package/migrations/drizzle-cleo-global/20260608010000_t11709-accounts-credential-pool/migration.sql +72 -0
  360. package/migrations/drizzle-cleo-global/20260608020000_t11889-selfimprove-dhq/migration.sql +64 -0
  361. package/migrations/drizzle-cleo-project/20260607000000_t11891-writer-leases/migration.sql +55 -0
  362. package/migrations/drizzle-cleo-project/20260607010000_t11639-session-parent/migration.sql +22 -0
  363. package/migrations/drizzle-cleo-project/20260608000000_t11899-pi-session-tree/migration.sql +52 -0
  364. package/migrations/drizzle-cleo-project/20260608020000_t11889-selfimprove-dhq/migration.sql +64 -0
  365. package/package.json +15 -13
  366. package/dist/lifecycle/chain-composition.d.ts +0 -30
  367. package/dist/lifecycle/chain-composition.d.ts.map +0 -1
  368. package/dist/lifecycle/chain-composition.js +0 -152
  369. package/dist/lifecycle/chain-composition.js.map +0 -1
  370. package/dist/lifecycle/chain-store.d.ts +0 -70
  371. package/dist/lifecycle/chain-store.d.ts.map +0 -1
  372. package/dist/lifecycle/chain-store.js +0 -246
  373. package/dist/lifecycle/chain-store.js.map +0 -1
  374. package/dist/lifecycle/default-chain.d.ts +0 -39
  375. package/dist/lifecycle/default-chain.d.ts.map +0 -1
  376. package/dist/lifecycle/default-chain.js +0 -176
  377. package/dist/lifecycle/default-chain.js.map +0 -1
  378. package/dist/lifecycle/tessera-engine.d.ts +0 -48
  379. package/dist/lifecycle/tessera-engine.d.ts.map +0 -1
  380. package/dist/lifecycle/tessera-engine.js +0 -249
  381. package/dist/lifecycle/tessera-engine.js.map +0 -1
  382. package/dist/validation/chain-validation.d.ts +0 -43
  383. package/dist/validation/chain-validation.d.ts.map +0 -1
  384. package/dist/validation/chain-validation.js +0 -146
  385. package/dist/validation/chain-validation.js.map +0 -1
@@ -0,0 +1,284 @@
1
+ /**
2
+ * Drizzle ORM schema for the **self-improvement DHQ** table (`selfimprove_dhq`),
3
+ * the durable sink for the P5 self-improvement loop (T11889 · T11889-A · T11911).
4
+ *
5
+ * One row per Dogfood-Harness-Question (DHQ) emitted by `cleo selfimprove run`:
6
+ * the loop replays a canned dogfood scenario, diffs the resulting LAFS envelopes
7
+ * against a golden, and — on regression — UPSERTs exactly ONE row here through the
8
+ * leased Gate-3 accessor ({@link ./selfimprove-dhq-store.ts}). On green it writes
9
+ * nothing. The table is dual-scope: co-located inside EACH scope's consolidated
10
+ * `cleo.db` (project + global) via the `drizzle-cleo-project` / `drizzle-cleo-global`
11
+ * migration sets, exactly like the `_writer_leases` (T11627) and `pi_session_*`
12
+ * (T11899) runtime-infrastructure tables. It is NOT part of the exodus target shape
13
+ * under `schema/cleo-project/`.
14
+ *
15
+ * ## Idempotency invariant — at most ONE open DHQ per `question_hash`
16
+ *
17
+ * A repeated regression must UPSERT the SAME open row rather than spam N duplicates.
18
+ * This is enforced by the **partial UNIQUE index**
19
+ * `ux_selfimprove_dhq_open ON selfimprove_dhq (question_hash) WHERE status = 'open'`.
20
+ * drizzle-orm does **not** surface partial-`WHERE` indexes in its typed schema API
21
+ * (cf. `writer-lease-schema.ts` `_writer_leases.active`, `conduit-schema.ts`
22
+ * `project_agent_refs.enabled`), so the partial index is emitted as **raw SQL in the
23
+ * baseline migration** — this module declares only the full-column table plus the two
24
+ * non-partial indexes drizzle CAN model. The runtime bootstrap asserts the partial
25
+ * index exists via {@link assertSelfimproveDhqOpenIndexPresent} so a missing index
26
+ * (a migration that never ran, or a dropped index) fails loudly instead of silently
27
+ * permitting two open rows for the same `question_hash`.
28
+ *
29
+ * @module
30
+ * @task T11911
31
+ * @task T11889
32
+ * @epic T11889
33
+ * @see ./selfimprove-dhq-store.ts — the Gate-3 accessor over these tables
34
+ * @see ./writer-lease-schema.ts — the partial-UNIQUE-index-via-raw-SQL precedent
35
+ * @see ../../migrations/drizzle-cleo-project — project migration (raw partial index)
36
+ * @see ../../migrations/drizzle-cleo-global — global migration (raw partial index)
37
+ */
38
+ import type { DatabaseSync } from 'node:sqlite';
39
+ /**
40
+ * The physical name of the self-improvement DHQ table. Exported so the engine, the
41
+ * store accessor, the bootstrap assertion, and tests all reference one source of
42
+ * truth.
43
+ */
44
+ export declare const SELFIMPROVE_DHQ_TABLE: "selfimprove_dhq";
45
+ /**
46
+ * The physical name of the partial-UNIQUE active-row index (`WHERE status = 'open'`).
47
+ * Asserted present at bootstrap because drizzle cannot emit it — it lives as raw SQL
48
+ * in the baseline migration.
49
+ */
50
+ export declare const SELFIMPROVE_DHQ_OPEN_INDEX: "ux_selfimprove_dhq_open";
51
+ /**
52
+ * `selfimprove_dhq` — one row per self-improvement-loop DHQ.
53
+ *
54
+ * The at-most-one-open-per-`question_hash` invariant is enforced by the raw-SQL
55
+ * partial-UNIQUE index `ux_selfimprove_dhq_open ON selfimprove_dhq (question_hash)
56
+ * WHERE status = 'open'` (emitted in the baseline migration — drizzle cannot model
57
+ * partial `WHERE`). This declaration intentionally carries only the full-column
58
+ * table plus the two non-partial indexes; do NOT add a `.unique()` on
59
+ * `question_hash` here (it would emit a NON-partial unique that wrongly forbids a
60
+ * second non-open row for the same hash).
61
+ */
62
+ export declare const selfimproveDhq: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
63
+ name: "selfimprove_dhq";
64
+ schema: undefined;
65
+ columns: {
66
+ id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
67
+ name: string;
68
+ tableName: "selfimprove_dhq";
69
+ dataType: "number int53";
70
+ data: number;
71
+ driverParam: number;
72
+ notNull: true;
73
+ hasDefault: true;
74
+ isPrimaryKey: true;
75
+ isAutoincrement: false;
76
+ hasRuntimeDefault: false;
77
+ enumValues: undefined;
78
+ baseColumn: never;
79
+ identity: undefined;
80
+ generated: undefined;
81
+ }, {}>;
82
+ dhqId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
83
+ name: string;
84
+ tableName: "selfimprove_dhq";
85
+ dataType: "string";
86
+ data: string;
87
+ driverParam: string;
88
+ notNull: true;
89
+ hasDefault: false;
90
+ isPrimaryKey: false;
91
+ isAutoincrement: false;
92
+ hasRuntimeDefault: false;
93
+ enumValues: [string, ...string[]];
94
+ baseColumn: never;
95
+ identity: undefined;
96
+ generated: undefined;
97
+ }, {}>;
98
+ scenario: import("drizzle-orm/sqlite-core").SQLiteColumn<{
99
+ name: string;
100
+ tableName: "selfimprove_dhq";
101
+ dataType: "string";
102
+ data: string;
103
+ driverParam: string;
104
+ notNull: true;
105
+ hasDefault: false;
106
+ isPrimaryKey: false;
107
+ isAutoincrement: false;
108
+ hasRuntimeDefault: false;
109
+ enumValues: [string, ...string[]];
110
+ baseColumn: never;
111
+ identity: undefined;
112
+ generated: undefined;
113
+ }, {}>;
114
+ questionHash: import("drizzle-orm/sqlite-core").SQLiteColumn<{
115
+ name: string;
116
+ tableName: "selfimprove_dhq";
117
+ dataType: "string";
118
+ data: string;
119
+ driverParam: string;
120
+ notNull: true;
121
+ hasDefault: false;
122
+ isPrimaryKey: false;
123
+ isAutoincrement: false;
124
+ hasRuntimeDefault: false;
125
+ enumValues: [string, ...string[]];
126
+ baseColumn: never;
127
+ identity: undefined;
128
+ generated: undefined;
129
+ }, {}>;
130
+ title: import("drizzle-orm/sqlite-core").SQLiteColumn<{
131
+ name: string;
132
+ tableName: "selfimprove_dhq";
133
+ dataType: "string";
134
+ data: string;
135
+ driverParam: string;
136
+ notNull: true;
137
+ hasDefault: false;
138
+ isPrimaryKey: false;
139
+ isAutoincrement: false;
140
+ hasRuntimeDefault: false;
141
+ enumValues: [string, ...string[]];
142
+ baseColumn: never;
143
+ identity: undefined;
144
+ generated: undefined;
145
+ }, {}>;
146
+ regressionJson: import("drizzle-orm/sqlite-core").SQLiteColumn<{
147
+ name: string;
148
+ tableName: "selfimprove_dhq";
149
+ dataType: "string";
150
+ data: string;
151
+ driverParam: string;
152
+ notNull: true;
153
+ hasDefault: false;
154
+ isPrimaryKey: false;
155
+ isAutoincrement: false;
156
+ hasRuntimeDefault: false;
157
+ enumValues: [string, ...string[]];
158
+ baseColumn: never;
159
+ identity: undefined;
160
+ generated: undefined;
161
+ }, {}>;
162
+ status: import("drizzle-orm/sqlite-core").SQLiteColumn<{
163
+ name: string;
164
+ tableName: "selfimprove_dhq";
165
+ dataType: "string";
166
+ data: string;
167
+ driverParam: string;
168
+ notNull: true;
169
+ hasDefault: true;
170
+ isPrimaryKey: false;
171
+ isAutoincrement: false;
172
+ hasRuntimeDefault: false;
173
+ enumValues: [string, ...string[]];
174
+ baseColumn: never;
175
+ identity: undefined;
176
+ generated: undefined;
177
+ }, {}>;
178
+ severity: import("drizzle-orm/sqlite-core").SQLiteColumn<{
179
+ name: string;
180
+ tableName: "selfimprove_dhq";
181
+ dataType: "string";
182
+ data: string;
183
+ driverParam: string;
184
+ notNull: false;
185
+ hasDefault: false;
186
+ isPrimaryKey: false;
187
+ isAutoincrement: false;
188
+ hasRuntimeDefault: false;
189
+ enumValues: [string, ...string[]];
190
+ baseColumn: never;
191
+ identity: undefined;
192
+ generated: undefined;
193
+ }, {}>;
194
+ prUrl: import("drizzle-orm/sqlite-core").SQLiteColumn<{
195
+ name: string;
196
+ tableName: "selfimprove_dhq";
197
+ dataType: "string";
198
+ data: string;
199
+ driverParam: string;
200
+ notNull: false;
201
+ hasDefault: false;
202
+ isPrimaryKey: false;
203
+ isAutoincrement: false;
204
+ hasRuntimeDefault: false;
205
+ enumValues: [string, ...string[]];
206
+ baseColumn: never;
207
+ identity: undefined;
208
+ generated: undefined;
209
+ }, {}>;
210
+ runId: import("drizzle-orm/sqlite-core").SQLiteColumn<{
211
+ name: string;
212
+ tableName: "selfimprove_dhq";
213
+ dataType: "string";
214
+ data: string;
215
+ driverParam: string;
216
+ notNull: true;
217
+ hasDefault: false;
218
+ isPrimaryKey: false;
219
+ isAutoincrement: false;
220
+ hasRuntimeDefault: false;
221
+ enumValues: [string, ...string[]];
222
+ baseColumn: never;
223
+ identity: undefined;
224
+ generated: undefined;
225
+ }, {}>;
226
+ createdAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
227
+ name: string;
228
+ tableName: "selfimprove_dhq";
229
+ dataType: "number int53";
230
+ data: number;
231
+ driverParam: number;
232
+ notNull: true;
233
+ hasDefault: false;
234
+ isPrimaryKey: false;
235
+ isAutoincrement: false;
236
+ hasRuntimeDefault: false;
237
+ enumValues: undefined;
238
+ baseColumn: never;
239
+ identity: undefined;
240
+ generated: undefined;
241
+ }, {}>;
242
+ updatedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
243
+ name: string;
244
+ tableName: "selfimprove_dhq";
245
+ dataType: "number int53";
246
+ data: number;
247
+ driverParam: number;
248
+ notNull: true;
249
+ hasDefault: false;
250
+ isPrimaryKey: false;
251
+ isAutoincrement: false;
252
+ hasRuntimeDefault: false;
253
+ enumValues: undefined;
254
+ baseColumn: never;
255
+ identity: undefined;
256
+ generated: undefined;
257
+ }, {}>;
258
+ };
259
+ dialect: "sqlite";
260
+ }>;
261
+ /**
262
+ * Assert that the raw-SQL partial-UNIQUE open-row index is physically present on the
263
+ * given native `cleo.db` handle.
264
+ *
265
+ * Because drizzle cannot emit a partial-`WHERE` index, the at-most-one-open-DHQ
266
+ * invariant depends entirely on the hand-written baseline migration having run. This
267
+ * check makes a missing index a loud, immediate failure at bootstrap rather than a
268
+ * silent loss of the idempotency guarantee (which would let the loop spam duplicate
269
+ * open rows).
270
+ *
271
+ * @param nativeDb - The native `DatabaseSync` handle for a scope's `cleo.db`.
272
+ * @throws {Error} `E_SELFIMPROVE_DHQ_INDEX_MISSING` if `ux_selfimprove_dhq_open` is
273
+ * absent (the migration did not run, or the partial index was dropped).
274
+ *
275
+ * @example
276
+ * ```ts
277
+ * const nativeDb = (handle.db as { $client: DatabaseSync }).$client;
278
+ * assertSelfimproveDhqOpenIndexPresent(nativeDb); // throws if the index is missing
279
+ * ```
280
+ *
281
+ * @task T11911
282
+ */
283
+ export declare function assertSelfimproveDhqOpenIndexPresent(nativeDb: DatabaseSync): void;
284
+ //# sourceMappingURL=selfimprove-dhq-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selfimprove-dhq-schema.d.ts","sourceRoot":"","sources":["../../src/store/selfimprove-dhq-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,EAAG,iBAA0B,CAAC;AAEhE;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAG,yBAAkC,CAAC;AAE7E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmC1B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,oCAAoC,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAajF"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Drizzle ORM schema for the **self-improvement DHQ** table (`selfimprove_dhq`),
3
+ * the durable sink for the P5 self-improvement loop (T11889 · T11889-A · T11911).
4
+ *
5
+ * One row per Dogfood-Harness-Question (DHQ) emitted by `cleo selfimprove run`:
6
+ * the loop replays a canned dogfood scenario, diffs the resulting LAFS envelopes
7
+ * against a golden, and — on regression — UPSERTs exactly ONE row here through the
8
+ * leased Gate-3 accessor ({@link ./selfimprove-dhq-store.ts}). On green it writes
9
+ * nothing. The table is dual-scope: co-located inside EACH scope's consolidated
10
+ * `cleo.db` (project + global) via the `drizzle-cleo-project` / `drizzle-cleo-global`
11
+ * migration sets, exactly like the `_writer_leases` (T11627) and `pi_session_*`
12
+ * (T11899) runtime-infrastructure tables. It is NOT part of the exodus target shape
13
+ * under `schema/cleo-project/`.
14
+ *
15
+ * ## Idempotency invariant — at most ONE open DHQ per `question_hash`
16
+ *
17
+ * A repeated regression must UPSERT the SAME open row rather than spam N duplicates.
18
+ * This is enforced by the **partial UNIQUE index**
19
+ * `ux_selfimprove_dhq_open ON selfimprove_dhq (question_hash) WHERE status = 'open'`.
20
+ * drizzle-orm does **not** surface partial-`WHERE` indexes in its typed schema API
21
+ * (cf. `writer-lease-schema.ts` `_writer_leases.active`, `conduit-schema.ts`
22
+ * `project_agent_refs.enabled`), so the partial index is emitted as **raw SQL in the
23
+ * baseline migration** — this module declares only the full-column table plus the two
24
+ * non-partial indexes drizzle CAN model. The runtime bootstrap asserts the partial
25
+ * index exists via {@link assertSelfimproveDhqOpenIndexPresent} so a missing index
26
+ * (a migration that never ran, or a dropped index) fails loudly instead of silently
27
+ * permitting two open rows for the same `question_hash`.
28
+ *
29
+ * @module
30
+ * @task T11911
31
+ * @task T11889
32
+ * @epic T11889
33
+ * @see ./selfimprove-dhq-store.ts — the Gate-3 accessor over these tables
34
+ * @see ./writer-lease-schema.ts — the partial-UNIQUE-index-via-raw-SQL precedent
35
+ * @see ../../migrations/drizzle-cleo-project — project migration (raw partial index)
36
+ * @see ../../migrations/drizzle-cleo-global — global migration (raw partial index)
37
+ */
38
+ import { index, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
39
+ /**
40
+ * The physical name of the self-improvement DHQ table. Exported so the engine, the
41
+ * store accessor, the bootstrap assertion, and tests all reference one source of
42
+ * truth.
43
+ */
44
+ export const SELFIMPROVE_DHQ_TABLE = 'selfimprove_dhq';
45
+ /**
46
+ * The physical name of the partial-UNIQUE active-row index (`WHERE status = 'open'`).
47
+ * Asserted present at bootstrap because drizzle cannot emit it — it lives as raw SQL
48
+ * in the baseline migration.
49
+ */
50
+ export const SELFIMPROVE_DHQ_OPEN_INDEX = 'ux_selfimprove_dhq_open';
51
+ /**
52
+ * `selfimprove_dhq` — one row per self-improvement-loop DHQ.
53
+ *
54
+ * The at-most-one-open-per-`question_hash` invariant is enforced by the raw-SQL
55
+ * partial-UNIQUE index `ux_selfimprove_dhq_open ON selfimprove_dhq (question_hash)
56
+ * WHERE status = 'open'` (emitted in the baseline migration — drizzle cannot model
57
+ * partial `WHERE`). This declaration intentionally carries only the full-column
58
+ * table plus the two non-partial indexes; do NOT add a `.unique()` on
59
+ * `question_hash` here (it would emit a NON-partial unique that wrongly forbids a
60
+ * second non-open row for the same hash).
61
+ */
62
+ export const selfimproveDhq = sqliteTable(SELFIMPROVE_DHQ_TABLE, {
63
+ /** Surrogate primary key (autoincrement via INTEGER PRIMARY KEY rowid alias). */
64
+ id: integer('id').primaryKey(),
65
+ /** Stable `'DHQ-###'` handle for the question. */
66
+ dhqId: text('dhq_id').notNull(),
67
+ /** The scenario name replayed when this DHQ was raised. */
68
+ scenario: text('scenario').notNull(),
69
+ /** sha256 of the normalized regression signature — the idempotency key. */
70
+ questionHash: text('question_hash').notNull(),
71
+ /** Human-readable DHQ title. */
72
+ title: text('title').notNull(),
73
+ /** The envelope-diff payload (the evidence) as serialized JSON. */
74
+ regressionJson: text('regression_json').notNull(),
75
+ /**
76
+ * Lifecycle status — `open` while the regression is live; advanced to a terminal
77
+ * value as the DHQ is worked. The partial-UNIQUE index keys on `status = 'open'`.
78
+ */
79
+ status: text('status').notNull().default('open'),
80
+ /** Severity classification (nullable until triaged), e.g. `P0`..`P3`. */
81
+ severity: text('severity'),
82
+ /** The draft PR URL once egress fires (nullable until a PR is opened). */
83
+ prUrl: text('pr_url'),
84
+ /** Ties the row to ONE loop run. */
85
+ runId: text('run_id').notNull(),
86
+ /** Creation timestamp (epoch ms). */
87
+ createdAt: integer('created_at').notNull(),
88
+ /** Last-update timestamp (epoch ms). */
89
+ updatedAt: integer('updated_at').notNull(),
90
+ }, (table) => [
91
+ index('ix_selfimprove_dhq_status').on(table.status),
92
+ index('ix_selfimprove_dhq_scenario').on(table.scenario),
93
+ ]);
94
+ /**
95
+ * Assert that the raw-SQL partial-UNIQUE open-row index is physically present on the
96
+ * given native `cleo.db` handle.
97
+ *
98
+ * Because drizzle cannot emit a partial-`WHERE` index, the at-most-one-open-DHQ
99
+ * invariant depends entirely on the hand-written baseline migration having run. This
100
+ * check makes a missing index a loud, immediate failure at bootstrap rather than a
101
+ * silent loss of the idempotency guarantee (which would let the loop spam duplicate
102
+ * open rows).
103
+ *
104
+ * @param nativeDb - The native `DatabaseSync` handle for a scope's `cleo.db`.
105
+ * @throws {Error} `E_SELFIMPROVE_DHQ_INDEX_MISSING` if `ux_selfimprove_dhq_open` is
106
+ * absent (the migration did not run, or the partial index was dropped).
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * const nativeDb = (handle.db as { $client: DatabaseSync }).$client;
111
+ * assertSelfimproveDhqOpenIndexPresent(nativeDb); // throws if the index is missing
112
+ * ```
113
+ *
114
+ * @task T11911
115
+ */
116
+ export function assertSelfimproveDhqOpenIndexPresent(nativeDb) {
117
+ const row = nativeDb
118
+ .prepare(`SELECT name FROM sqlite_master WHERE type = 'index' AND name = ?`)
119
+ .get(SELFIMPROVE_DHQ_OPEN_INDEX);
120
+ if (!row) {
121
+ throw new Error(`E_SELFIMPROVE_DHQ_INDEX_MISSING: partial-unique open-row index ` +
122
+ `"${SELFIMPROVE_DHQ_OPEN_INDEX}" is absent from this cleo.db. The DHQ ` +
123
+ `baseline migration (drizzle-cleo-{project,global}/…_t11889-selfimprove-dhq) ` +
124
+ `did not run, so the at-most-one-open-DHQ-per-question_hash invariant is ` +
125
+ `unenforced.`);
126
+ }
127
+ }
128
+ //# sourceMappingURL=selfimprove-dhq-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selfimprove-dhq-schema.js","sourceRoot":"","sources":["../../src/store/selfimprove-dhq-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAGH,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAE5E;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAA0B,CAAC;AAEhE;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,yBAAkC,CAAC;AAE7E;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CACvC,qBAAqB,EACrB;IACE,iFAAiF;IACjF,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE;IAC9B,kDAAkD;IAClD,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE;IAC/B,2DAA2D;IAC3D,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE;IACpC,2EAA2E;IAC3E,YAAY,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC,OAAO,EAAE;IAC7C,gCAAgC;IAChC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE;IAC9B,mEAAmE;IACnE,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE;IACjD;;;OAGG;IACH,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC;IAChD,yEAAyE;IACzE,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC;IAC1B,0EAA0E;IAC1E,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC;IACrB,oCAAoC;IACpC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE;IAC/B,qCAAqC;IACrC,SAAS,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;IAC1C,wCAAwC;IACxC,SAAS,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;CAC3C,EACD,CAAC,KAAK,EAAE,EAAE,CAAC;IACT,KAAK,CAAC,2BAA2B,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC;IACnD,KAAK,CAAC,6BAA6B,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC;CACxD,CACF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,oCAAoC,CAAC,QAAsB;IACzE,MAAM,GAAG,GAAG,QAAQ;SACjB,OAAO,CAAC,kEAAkE,CAAC;SAC3E,GAAG,CAAC,0BAA0B,CAAiC,CAAC;IACnE,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CACb,iEAAiE;YAC/D,IAAI,0BAA0B,yCAAyC;YACvE,8EAA8E;YAC9E,0EAA0E;YAC1E,aAAa,CAChB,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Store-layer accessor for the self-improvement DHQ table (`selfimprove_dhq`) —
3
+ * T11889 · T11889-A · T11911.
4
+ *
5
+ * This module is the ONLY place that touches the native `cleo.db` handle for the
6
+ * self-improvement loop's DHQ persistence. It lives INSIDE the store chokepoint
7
+ * (`packages/core/src/store/**`), the Gate-3 allowlist, so it may extract the native
8
+ * `DatabaseSync` that {@link openDualScopeDb} already holds (via drizzle's `$client`)
9
+ * and run prepared statements over it — exactly the established `pi-session-store.ts`
10
+ * pattern. It NEVER calls `new DatabaseSync(` itself.
11
+ *
12
+ * The durable adapter (`packages/core/src/selfimprove/dhq-adapter.ts`, T11889-C)
13
+ * sits OUTSIDE the chokepoint, so it must NOT open a raw handle; it calls these
14
+ * accessors and wraps every WRITE in `withWriterLease('project', 'bulk', …)` so the
15
+ * write is serialized against any other writer on the `(project, bulk)` lane. The
16
+ * lease SERIALIZES the write; the "only ever writes `selfimprove_dhq`, never a live
17
+ * `tasks`/`brain` row" guarantee comes from this accessor's prepared statements
18
+ * targeting ONLY `selfimprove_dhq` — adapter discipline, not the lease.
19
+ *
20
+ * Physical model (see the `t11889-selfimprove-dhq` migration):
21
+ * - `selfimprove_dhq(id, dhq_id, scenario, question_hash, title, regression_json,
22
+ * status, severity, pr_url, run_id, created_at, updated_at)` — one row per DHQ.
23
+ * - Idempotency: a raw-SQL partial-UNIQUE index `ux_selfimprove_dhq_open` keys on
24
+ * `question_hash WHERE status = 'open'`, so at most one open row per hash.
25
+ *
26
+ * @module
27
+ * @task T11911
28
+ * @task T11889
29
+ * @epic T11889
30
+ */
31
+ export { assertSelfimproveDhqOpenIndexPresent, SELFIMPROVE_DHQ_OPEN_INDEX, SELFIMPROVE_DHQ_TABLE, } from './selfimprove-dhq-schema.js';
32
+ /** A persisted DHQ row, decoded from `selfimprove_dhq`. */
33
+ export interface SelfimproveDhqRow {
34
+ /** Stable `'DHQ-###'` handle for the question. */
35
+ readonly dhqId: string;
36
+ /** The scenario name replayed when this DHQ was raised. */
37
+ readonly scenario: string;
38
+ /** sha256 of the normalized regression signature — the idempotency key. */
39
+ readonly questionHash: string;
40
+ /** Human-readable DHQ title. */
41
+ readonly title: string;
42
+ /** The envelope-diff payload (the evidence) as serialized JSON. */
43
+ readonly regressionJson: string;
44
+ /** Lifecycle status — `'open'` while the regression is live. */
45
+ readonly status: string;
46
+ /** Severity classification, or `null` until triaged. */
47
+ readonly severity: string | null;
48
+ /** The draft PR URL once egress fires, or `null`. */
49
+ readonly prUrl: string | null;
50
+ /** Ties the row to ONE loop run. */
51
+ readonly runId: string;
52
+ /** Creation timestamp (epoch ms). */
53
+ readonly createdAt: number;
54
+ /** Last-update timestamp (epoch ms). */
55
+ readonly updatedAt: number;
56
+ }
57
+ /**
58
+ * Fields required to UPSERT one open DHQ. `status` is fixed to `'open'` by the
59
+ * accessor (the partial-UNIQUE index keys on it); terminal-status transitions go
60
+ * through {@link updateSelfimproveDhqStatus} instead.
61
+ */
62
+ export interface SelfimproveDhqUpsert {
63
+ /** Stable `'DHQ-###'` handle (used only on first insert for a hash). */
64
+ readonly dhqId: string;
65
+ /** The scenario name replayed. */
66
+ readonly scenario: string;
67
+ /** sha256 of the normalized regression signature — the idempotency key. */
68
+ readonly questionHash: string;
69
+ /** Human-readable DHQ title. */
70
+ readonly title: string;
71
+ /** The envelope-diff payload (the evidence) as serialized JSON. */
72
+ readonly regressionJson: string;
73
+ /** Severity classification, or `null` until triaged. */
74
+ readonly severity: string | null;
75
+ /** Ties the row to ONE loop run. */
76
+ readonly runId: string;
77
+ /** The timestamp to stamp on insert/update (epoch ms). */
78
+ readonly now: number;
79
+ }
80
+ /** Narrow shape of the native handle methods this accessor uses. */
81
+ type NativeRunResult = {
82
+ changes: number | bigint;
83
+ lastInsertRowid: number | bigint;
84
+ };
85
+ interface NativeStatement {
86
+ run(...params: ReadonlyArray<string | number | null>): NativeRunResult;
87
+ get(...params: ReadonlyArray<string | number | null>): Record<string, unknown> | undefined;
88
+ all(...params: ReadonlyArray<string | number | null>): Array<Record<string, unknown>>;
89
+ }
90
+ interface NativeHandle {
91
+ prepare(sql: string): NativeStatement;
92
+ }
93
+ /**
94
+ * Extract the native `DatabaseSync` handle for the PROJECT-scope `cleo.db`.
95
+ *
96
+ * Routes through {@link openDualScopeDb} (the dual-scope chokepoint) — which applies
97
+ * the pragma SSoT, runs the consolidated migrations (creating `selfimprove_dhq`),
98
+ * and manages the singleton cache — then extracts the native handle drizzle holds on
99
+ * `$client`. NEVER opens a raw connection (Gate 3): it reuses the handle the
100
+ * chokepoint already owns.
101
+ *
102
+ * @param cwd - Working directory for project resolution (defaults to `cwd`).
103
+ * @returns The live native handle.
104
+ * @throws When the chokepoint returns a handle without `$client`.
105
+ */
106
+ export declare function getSelfimproveDhqNativeDb(cwd?: string): Promise<NativeHandle>;
107
+ /**
108
+ * Return the open DHQ row for a `question_hash`, or `null` when none is open.
109
+ *
110
+ * @param native - The native project `cleo.db` handle.
111
+ * @param questionHash - The regression-signature hash.
112
+ * @returns The open row or `null`.
113
+ */
114
+ export declare function readOpenSelfimproveDhq(native: NativeHandle, questionHash: string): SelfimproveDhqRow | null;
115
+ /**
116
+ * Return all DHQ rows for a scenario in stable creation order (`created_at ASC`).
117
+ *
118
+ * @param native - The native project `cleo.db` handle.
119
+ * @param scenario - The scenario name.
120
+ * @returns The ordered rows (empty when the scenario has none).
121
+ */
122
+ export declare function readSelfimproveDhqByScenario(native: NativeHandle, scenario: string): SelfimproveDhqRow[];
123
+ /**
124
+ * Insert (or, on a repeated open regression, refresh) exactly ONE open DHQ row for a
125
+ * `question_hash`.
126
+ *
127
+ * The partial-UNIQUE index `ux_selfimprove_dhq_open (question_hash) WHERE status =
128
+ * 'open'` makes this idempotent: a second open regression for the same hash updates
129
+ * the existing open row's `updated_at` / `run_id` / `severity` instead of inserting a
130
+ * duplicate. The caller MUST already hold the PROJECT/`bulk` writer lease — this
131
+ * accessor performs the raw write and does NOT acquire the lease itself (the lease
132
+ * boundary lives in `dhq-adapter.ts`, outside the chokepoint).
133
+ *
134
+ * @param native - The native project `cleo.db` handle (leased section).
135
+ * @param row - The DHQ to upsert.
136
+ */
137
+ export declare function upsertOpenSelfimproveDhq(native: NativeHandle, row: SelfimproveDhqUpsert): void;
138
+ /**
139
+ * Advance an open DHQ to a terminal status (e.g. `'fixed'` / `'dismissed'`) for a
140
+ * `question_hash`. Frees the partial-UNIQUE slot so a future regression of the same
141
+ * hash can open a new row.
142
+ *
143
+ * The caller MUST hold the writer lease.
144
+ *
145
+ * @param native - The native project `cleo.db` handle (leased section).
146
+ * @param questionHash - The regression-signature hash whose open row to advance.
147
+ * @param status - The new (non-open) status.
148
+ * @param now - The update timestamp (epoch ms).
149
+ * @returns The number of rows updated (0 when no open row exists).
150
+ */
151
+ export declare function updateSelfimproveDhqStatus(native: NativeHandle, questionHash: string, status: string, now: number): number;
152
+ /**
153
+ * Record the draft PR URL on the open DHQ row for a `question_hash`.
154
+ *
155
+ * The caller MUST hold the writer lease.
156
+ *
157
+ * @param native - The native project `cleo.db` handle (leased section).
158
+ * @param questionHash - The regression-signature hash whose open row to annotate.
159
+ * @param prUrl - The draft PR URL.
160
+ * @param now - The update timestamp (epoch ms).
161
+ * @returns The number of rows updated (0 when no open row exists).
162
+ */
163
+ export declare function setSelfimproveDhqPrUrl(native: NativeHandle, questionHash: string, prUrl: string, now: number): number;
164
+ /**
165
+ * Bootstrap check: open the project `cleo.db` (running migrations) and assert the
166
+ * partial-UNIQUE open-row index is physically present.
167
+ *
168
+ * Convenience wrapper over {@link getSelfimproveDhqNativeDb} +
169
+ * {@link assertSelfimproveDhqOpenIndexPresent} for callers that only have a `cwd`.
170
+ *
171
+ * @param cwd - Working directory for project resolution.
172
+ * @throws `E_SELFIMPROVE_DHQ_INDEX_MISSING` if the index is absent.
173
+ */
174
+ export declare function assertSelfimproveDhqReady(cwd?: string): Promise<void>;
175
+ //# sourceMappingURL=selfimprove-dhq-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selfimprove-dhq-store.d.ts","sourceRoot":"","sources":["../../src/store/selfimprove-dhq-store.ts"],"names":[],"mappings":"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"}