@deepseek-insight/dsi 0.6.12 → 0.6.14

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 (189) hide show
  1. package/.agents/skills/dsi-thin/SKILL.md +140 -0
  2. package/.agents/skills/dsi-thin/references/ADR-0019-snapshot.md +363 -0
  3. package/.agents/skills/dsi-thin/references/authority-adr.md +28 -0
  4. package/.agents/skills/dsi-thin/references/input-contract.md +42 -0
  5. package/.agents/skills/dsi-thin/references/proven-gates.md +61 -0
  6. package/.agents/skills/dsi-thin/references/two-lane-contract.md +53 -0
  7. package/build/client/_app/immutable/assets/0.B-dIufDc.css +2 -0
  8. package/build/client/_app/immutable/assets/2.B70dfiy3.css +1 -0
  9. package/build/client/_app/immutable/chunks/{B9fOkvHb.js → 0HT0ILkA.js} +1 -1
  10. package/build/client/_app/immutable/chunks/{Dwt_JXeR.js → 2KTqoQH-.js} +1 -1
  11. package/build/client/_app/immutable/chunks/{BIvFR1xA.js → 2M1KS72j.js} +1 -1
  12. package/build/client/_app/immutable/chunks/{a1Hqq5w-.js → 2XtVrxH4.js} +1 -1
  13. package/build/client/_app/immutable/chunks/38H6DLwz.js +1 -0
  14. package/build/client/_app/immutable/chunks/{Cdn_bzx2.js → 3E8jbhSl.js} +1 -1
  15. package/build/client/_app/immutable/chunks/{CmNEu9LM.js → A5Iiq81h.js} +1 -1
  16. package/build/client/_app/immutable/chunks/{C48u-2qp.js → ANnPTMPF.js} +1 -1
  17. package/build/client/_app/immutable/chunks/{BfChGCnE.js → B5S0Wke9.js} +1 -1
  18. package/build/client/_app/immutable/chunks/BBDOLPkB.js +1 -0
  19. package/build/client/_app/immutable/chunks/{DJ36HFmi.js → BImoJlJo.js} +1 -1
  20. package/build/client/_app/immutable/chunks/{DqRXQwgi.js → BJsp4NMH.js} +1 -1
  21. package/build/client/_app/immutable/chunks/{C7a8i7sD.js → BKU5-8Td.js} +1 -1
  22. package/build/client/_app/immutable/chunks/BMgyB-Sy.js +1 -0
  23. package/build/client/_app/immutable/chunks/BYHxHjHc.js +1 -0
  24. package/build/client/_app/immutable/chunks/{BC5nqwvj.js → BZ6uvzU8.js} +1 -1
  25. package/build/client/_app/immutable/chunks/{CvjdFV1E.js → B_Gknb5_.js} +1 -1
  26. package/build/client/_app/immutable/chunks/{CDTTZjYW.js → Bf1I5ROF.js} +1 -1
  27. package/build/client/_app/immutable/chunks/{CaAId7nh.js → Bh_Z0-Fh.js} +1 -1
  28. package/build/client/_app/immutable/chunks/{CLvIgAhR.js → BjafRUyA.js} +1 -1
  29. package/build/client/_app/immutable/chunks/{CG77uzLI.js → Bq4mG8qS.js} +1 -1
  30. package/build/client/_app/immutable/chunks/{CI1tkkzb.js → BqX9BB0G.js} +1 -1
  31. package/build/client/_app/immutable/chunks/BwNsQhd8.js +1 -0
  32. package/build/client/_app/immutable/chunks/{CvWnUnS1.js → Bx68-tOf.js} +1 -1
  33. package/build/client/_app/immutable/chunks/{RIIj2qfU.js → C1dC47iq.js} +1 -1
  34. package/build/client/_app/immutable/chunks/{BNx4_m7U.js → C6zqVyWx.js} +1 -1
  35. package/build/client/_app/immutable/chunks/{GLtnCmfd.js → C8seIiU_.js} +1 -1
  36. package/build/client/_app/immutable/chunks/{B_6pr4k2.js → CCWXLdgd.js} +1 -1
  37. package/build/client/_app/immutable/chunks/{D5ecapQY.js → CHYEvS-6.js} +1 -1
  38. package/build/client/_app/immutable/chunks/{OVDjSnH6.js → CIH5Juz4.js} +1 -1
  39. package/build/client/_app/immutable/chunks/CMByLjfJ.js +1 -0
  40. package/build/client/_app/immutable/chunks/{CnAA0dO8.js → CNJYmM8n.js} +1 -1
  41. package/build/client/_app/immutable/chunks/CP4wchdA.js +2 -0
  42. package/build/client/_app/immutable/chunks/{B2hm1w7K.js → CQTGR8fW.js} +1 -1
  43. package/build/client/_app/immutable/chunks/{Bp4vT1Ke.js → CW2uYEvb.js} +1 -1
  44. package/build/client/_app/immutable/chunks/{BPFR73BS.js → C_Gd0Wor.js} +1 -1
  45. package/build/client/_app/immutable/chunks/{Dn4fSUjR.js → C_MwBDNt.js} +1 -1
  46. package/build/client/_app/immutable/chunks/{Dea0pTfN.js → Ch7rc-L7.js} +4 -4
  47. package/build/client/_app/immutable/chunks/{J3KpJGd_.js → ChC4viXw.js} +1 -1
  48. package/build/client/_app/immutable/chunks/{4pCoNSa4.js → CiLhSVIj.js} +1 -1
  49. package/build/client/_app/immutable/chunks/{C7iYNw8X.js → Cx8YXmgi.js} +1 -1
  50. package/build/client/_app/immutable/chunks/{BRNBFqQ_.js → D4I0Dqwh.js} +1 -1
  51. package/build/client/_app/immutable/chunks/D6mTYwDH.js +6 -0
  52. package/build/client/_app/immutable/chunks/{l5GiMY16.js → D7-uGicP.js} +1 -1
  53. package/build/client/_app/immutable/chunks/{C8wGq5T2.js → D7XrPGMK.js} +1 -1
  54. package/build/client/_app/immutable/chunks/{xRO38jd8.js → D7eKc9ur.js} +1 -1
  55. package/build/client/_app/immutable/chunks/{CEj_BGCY.js → DCmONIPx.js} +1 -1
  56. package/build/client/_app/immutable/chunks/DJWLLhNJ.js +1 -0
  57. package/build/client/_app/immutable/chunks/{qkxAgKjo.js → DNf96C-O.js} +1 -1
  58. package/build/client/_app/immutable/chunks/{D4Ogpdhb.js → DSqRqQNp.js} +1 -1
  59. package/build/client/_app/immutable/chunks/{D4xFb7_b.js → DT1b6JaK.js} +1 -1
  60. package/build/client/_app/immutable/chunks/{D3bC95qg.js → DWYSL4om.js} +1 -1
  61. package/build/client/_app/immutable/chunks/{Bi5NvDds.js → DYfx-RRD.js} +1 -1
  62. package/build/client/_app/immutable/chunks/{Bi25XSWW.js → DfIqw6WM.js} +1 -1
  63. package/build/client/_app/immutable/chunks/{CGux-rdo.js → Dj4_qcIH.js} +4 -4
  64. package/build/client/_app/immutable/chunks/{Cx__ttXF.js → Dk9aRp2m.js} +1 -1
  65. package/build/client/_app/immutable/chunks/{C-58cZAk.js → DmLHHlla.js} +3 -3
  66. package/build/client/_app/immutable/chunks/{GNZHLVjs.js → Do0VAo0_.js} +1 -1
  67. package/build/client/_app/immutable/chunks/{BFsDYOFz.js → DrVddB75.js} +1 -1
  68. package/build/client/_app/immutable/chunks/{CdFbOrCf.js → Dso_gKeU.js} +1 -1
  69. package/build/client/_app/immutable/chunks/{Bl78Sc72.js → DykTZ90H.js} +1 -1
  70. package/build/client/_app/immutable/chunks/{DNlR6G0m.js → GdM4UPkS.js} +1 -1
  71. package/build/client/_app/immutable/chunks/{B52Khb6E.js → IBXFCASw.js} +1 -1
  72. package/build/client/_app/immutable/chunks/{BIUi504d.js → IoX9lmZK.js} +1 -1
  73. package/build/client/_app/immutable/chunks/{Bn64J6A-.js → bpkmZ_Dv.js} +1 -1
  74. package/build/client/_app/immutable/chunks/{iK_uzrhN.js → crRp5OG4.js} +1 -1
  75. package/build/client/_app/immutable/chunks/da2fibLv.js +8 -0
  76. package/build/client/_app/immutable/chunks/{BOKyldQm.js → dcghWWmq.js} +1 -1
  77. package/build/client/_app/immutable/chunks/{CItDRTlN.js → fJBuRi-A.js} +1 -1
  78. package/build/client/_app/immutable/chunks/{CRe9IZg0.js → gXyYVhfn.js} +1 -1
  79. package/build/client/_app/immutable/chunks/{C2vkjTiv.js → j2lJ25s0.js} +1 -1
  80. package/build/client/_app/immutable/chunks/{DypDva7F.js → l3etNtOh.js} +1 -1
  81. package/build/client/_app/immutable/chunks/{BGQXNvll.js → olUfRNXS.js} +1 -1
  82. package/build/client/_app/immutable/chunks/{D3W5wGWM.js → uEyn1Z7p.js} +1 -1
  83. package/build/client/_app/immutable/entry/app.CCuVGpQc.js +2 -0
  84. package/build/client/_app/immutable/entry/start.BtgtnpyB.js +1 -0
  85. package/build/client/_app/immutable/nodes/0.GHtnahSb.js +1 -0
  86. package/build/client/_app/immutable/nodes/1.CaQ_jAq8.js +1 -0
  87. package/build/client/_app/immutable/nodes/2.DxOLlTKc.js +337 -0
  88. package/build/client/_app/version.json +1 -1
  89. package/build/handler.js +7 -6
  90. package/build/index.js +7 -6
  91. package/build/server/chunks/chunks/{app-config.svelte.js-BW7TwbBy.js → app-config.svelte.js-D7wkLUkK.js} +2 -2
  92. package/build/server/chunks/chunks/{db.js-BylhmazO.js → db.js-DRhjT6xK.js} +2 -2
  93. package/build/server/chunks/chunks/{db2.js-Cm8FBINY.js → db2.js-DUta2B-n.js} +207 -222
  94. package/build/server/chunks/chunks/{dsh-connection.js-Lnv7PlHw.js → dsh-connection.js-DRtqPR_j.js} +959 -752
  95. package/build/server/chunks/chunks/{dsh-events.js-D9tSYE7f.js → dsh-events.js-B_E1BU9F.js} +141 -350
  96. package/build/server/chunks/chunks/{git-probe.js-D_H3YQbR.js → git-probe.js-Daf6r7Z9.js} +3 -3
  97. package/build/server/chunks/chunks/index-server.js-CV2lq-ha.js +147 -0
  98. package/build/server/chunks/chunks/{insight-config.js-XUD5BN0g.js → insight-config.js-CA-iT3lB.js} +5 -3
  99. package/build/server/chunks/chunks/{internal2.js-BcS47nI-.js → internal.js-BcS47nI-.js} +1 -1
  100. package/build/server/chunks/chunks/{internal.js-D_QJoxN-.js → internal2.js-DAPn3Vk8.js} +11 -153
  101. package/build/server/chunks/chunks/merge.js-yMwW440S.js +228 -0
  102. package/build/server/chunks/chunks/{server.js-11-pxAWV.js → server.js-DqHGsQU2.js} +2 -2
  103. package/build/server/chunks/chunks/{state.js-DbUk4Hrz.js → state.js-CsIZcr7q.js} +5 -4
  104. package/build/server/chunks/chunks/theme-prefs.svelte.js-8CaWz46g.js +109 -0
  105. package/build/server/chunks/chunks/{watcher.js-DU-MZGLU.js → watcher.js-CoR53lwR.js} +5 -5
  106. package/build/server/chunks/entries/endpoints/api/a2a/_id_/{_server.ts.js-DQenu1Rx.js → _server.ts.js-CpeC2QLb.js} +3 -3
  107. package/build/server/chunks/entries/endpoints/api/a2a/{_server.ts.js-BvEDeAhP.js → _server.ts.js-BKlF4XGH.js} +7 -6
  108. package/build/server/chunks/entries/endpoints/api/a2a/register/{_server.ts.js-DLJ4sQBq.js → _server.ts.js-BpEhlidV.js} +7 -6
  109. package/build/server/chunks/entries/endpoints/api/config/{_server.ts.js-zogZnK_B.js → _server.ts.js-BG78X__J.js} +3 -3
  110. package/build/server/chunks/entries/endpoints/api/dsh/directory/{_server.ts.js-BAfRDeE_.js → _server.ts.js-Dmh7f-hU.js} +3 -3
  111. package/build/server/chunks/entries/endpoints/api/dsh/pick-directory/{_server.ts.js-N21TnqYh.js → _server.ts.js-BEci0ZAx.js} +3 -3
  112. package/build/server/chunks/entries/endpoints/api/dsh/presets/{_server.ts.js-C5ckDTov.js → _server.ts.js-OXFzXBSp.js} +3 -3
  113. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/attachment/{_server.ts.js-CEPz4kVZ.js → _server.ts.js-x44GKy4R.js} +3 -3
  114. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/cancel/{_server.ts.js-CUB5TKnW.js → _server.ts.js-Da5ZqeJ7.js} +3 -3
  115. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/catalog/{_server.ts.js-BfDAa0Vb.js → _server.ts.js-BACv9hW-.js} +3 -3
  116. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/changes/{_server.ts.js-QiLS5yAj.js → _server.ts.js-BtiUS3iD.js} +3 -3
  117. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/command/{_server.ts.js-C5kJrRx-.js → _server.ts.js-BOOyd1LI.js} +3 -3
  118. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/events/{_server.ts.js-vydjdEkJ.js → _server.ts.js-D0GwQbdF.js} +5 -4
  119. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/fork/{_server.ts.js-y5sqH_UC.js → _server.ts.js-Bd0JYMlf.js} +3 -3
  120. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/goal/{_server.ts.js-BoYIpj-f.js → _server.ts.js-DqAV7OOv.js} +3 -3
  121. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/history/{_server.ts.js-SchAEll8.js → _server.ts.js-Cz4P-68E.js} +5 -4
  122. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/models/{_server.ts.js-B8bmQCwT.js → _server.ts.js-C4fXXBIM.js} +3 -3
  123. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/path/{_server.ts.js-DxiKkvE-.js → _server.ts.js-_SIiC8sn.js} +2 -2
  124. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/permission/{_server.ts.js-BBexDstc.js → _server.ts.js-BiqNZiiN.js} +3 -3
  125. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/prompt/{_server.ts.js-fd9StFXw.js → _server.ts.js-Bdx9V4oY.js} +3 -3
  126. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/rename/{_server.ts.js-98HaDusY.js → _server.ts.js-CuBqoV3c.js} +3 -3
  127. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/respond/{_server.ts.js-DN9APffn.js → _server.ts.js-CXPFI_Pn.js} +3 -3
  128. package/build/server/chunks/entries/endpoints/api/dsh/session/_sessionId_/select-model/{_server.ts.js-CeROEmUY.js → _server.ts.js-CRcaw4Yo.js} +3 -3
  129. package/build/server/chunks/entries/endpoints/api/dsh/sessions/{_server.ts.js-DKHmiqIs.js → _server.ts.js-dYrtVHDP.js} +3 -3
  130. package/build/server/chunks/entries/endpoints/api/dsh/workspace-file/{_server.ts.js-S6XZDJmC.js → _server.ts.js-BtlfuMjf.js} +3 -3
  131. package/build/server/chunks/entries/endpoints/api/dsh/workspace-tree/{_server.ts.js-CA4PUERZ.js → _server.ts.js-D12kAP9B.js} +3 -3
  132. package/build/server/chunks/entries/endpoints/api/dsh/workspaces/{_server.ts.js-BObM3Axz.js → _server.ts.js-C9JHp1WU.js} +3 -3
  133. package/build/server/chunks/entries/endpoints/api/dsh/workspaces/_workspaceId_/delete/{_server.ts.js-CA34p4GV.js → _server.ts.js-bLF4Fbgn.js} +3 -3
  134. package/build/server/chunks/entries/endpoints/api/dsh/workspaces/_workspaceId_/rename/{_server.ts.js-DPoRM_7u.js → _server.ts.js-BSw_zD-0.js} +3 -3
  135. package/build/server/chunks/entries/endpoints/api/prompts/_id_/{_server.ts.js-u-regI3R.js → _server.ts.js-bRLZ5TWI.js} +3 -3
  136. package/build/server/chunks/entries/endpoints/api/prompts/{_server.ts.js-YtkQGu7O.js → _server.ts.js-ChzWZoFk.js} +3 -3
  137. package/build/server/chunks/entries/endpoints/api/prompts/use/{_server.ts.js-tv0ivn2x.js → _server.ts.js-DdH5QmPS.js} +3 -3
  138. package/build/server/chunks/entries/endpoints/api/settings/{_server.ts.js-DmU2MBc5.js → _server.ts.js-DwGQj520.js} +2 -2
  139. package/build/server/chunks/entries/endpoints/api/terminal/{_server.ts.js-DHhod6dT.js → _server.ts.js-CwXC6Stk.js} +3 -2
  140. package/build/server/chunks/entries/endpoints/api/workspace/file-write/{_server.ts.js-BmEUPTSa.js → _server.ts.js-CqyKA9g2.js} +6 -5
  141. package/build/server/chunks/entries/endpoints/api/workspace/git-events/{_server.ts.js-_1uYvYEA.js → _server.ts.js-yu695YoE.js} +6 -5
  142. package/build/server/chunks/entries/endpoints/api/workspace/git-file-head/{_server.ts.js-DaXO3et9.js → _server.ts.js-BhDAvM6y.js} +6 -5
  143. package/build/server/chunks/entries/endpoints/api/workspace/git-map/{_server.ts.js-hp85iKSu.js → _server.ts.js-BRUgPrJ2.js} +6 -5
  144. package/build/server/chunks/entries/endpoints/api/workspace/git-status/{_server.ts.js-CPB-9252.js → _server.ts.js-C7VJ2G4_.js} +6 -5
  145. package/build/server/chunks/entries/endpoints/api/workspace/write-gate/{_server.ts.js-DKqzSQBE.js → _server.ts.js-BH5BRA_d.js} +6 -5
  146. package/build/server/chunks/entries/pages/{_error.svelte.js-AsgAVyDR.js → _error.svelte.js-B5TEtccE.js} +10 -9
  147. package/build/server/chunks/entries/pages/_layout.svelte.js-DRfiLzlz.js +20 -0
  148. package/build/server/chunks/entries/pages/{_page.server.ts.js-DTjoTdYK.js → _page.server.ts.js-CityLNBO.js} +3 -3
  149. package/build/server/chunks/entries/pages/{_page.svelte.js-CFdCjELr.js → _page.svelte.js-i6KsWK9O.js} +4654 -2413
  150. package/build/server/chunks/{handler-Bx2fbkEJ.js → handler-XuK3Ihhf.js} +3 -3
  151. package/build/server/chunks/{index.js-BldXQ38P.js → index.js-D2FEiD0I.js} +5 -4
  152. package/build/server/chunks/{manifest.js-Du-9DaEd.js → manifest.js-B_kahcFI.js} +45 -45
  153. package/build/server/chunks/nodes/0.js-C0B2o0le.js +12 -0
  154. package/build/server/chunks/nodes/1.js-C2e7NFqd.js +9 -0
  155. package/build/server/chunks/nodes/{2.js-DGLcInR6.js → 2.js-Bh3kLeYq.js} +9 -8
  156. package/package.json +2 -2
  157. package/skills/dsi-sloc/SKILL.md +117 -0
  158. package/skills/dsi-sloc/references/measurement.md +79 -0
  159. package/skills/dsi-sloc/references/report-skeleton.md +79 -0
  160. package/skills/dsi-thin/SKILL.md +214 -0
  161. package/skills/dsi-thin/references/ADR-0019-snapshot.md +363 -0
  162. package/skills/dsi-thin/references/authority-adr.md +28 -0
  163. package/skills/dsi-thin/references/input-contract.md +42 -0
  164. package/skills/dsi-thin/references/proven-gates.md +61 -0
  165. package/skills/dsi-thin/references/two-lane-contract.md +53 -0
  166. package/template/.dsi/prompts.sqlite +0 -0
  167. package/template/.dsi/prompts.sqlite-shm +0 -0
  168. package/template/.dsi/prompts.sqlite-wal +0 -0
  169. package/template/.dsi/resources/skills-reff.md +5 -4
  170. package/build/client/_app/immutable/assets/0.CRU0GiZX.css +0 -2
  171. package/build/client/_app/immutable/assets/2.Bzy6Q5kl.css +0 -1
  172. package/build/client/_app/immutable/chunks/-BV4MEqr.js +0 -1
  173. package/build/client/_app/immutable/chunks/66qbK5h1.js +0 -2
  174. package/build/client/_app/immutable/chunks/BLxS3bAX.js +0 -6
  175. package/build/client/_app/immutable/chunks/CPhcxli7.js +0 -1
  176. package/build/client/_app/immutable/chunks/CT1m72HM.js +0 -1
  177. package/build/client/_app/immutable/chunks/CxnI-Htc.js +0 -8
  178. package/build/client/_app/immutable/chunks/D0uZseUH.js +0 -1
  179. package/build/client/_app/immutable/chunks/D73RufXg.js +0 -1
  180. package/build/client/_app/immutable/chunks/HwuqC1sa.js +0 -1
  181. package/build/client/_app/immutable/chunks/NtHUheoE.js +0 -1
  182. package/build/client/_app/immutable/entry/app.D8WfdLSe.js +0 -2
  183. package/build/client/_app/immutable/entry/start.CVl0g0cv.js +0 -1
  184. package/build/client/_app/immutable/nodes/0.k1Ikzbp6.js +0 -1
  185. package/build/client/_app/immutable/nodes/1.X0If5xAN.js +0 -1
  186. package/build/client/_app/immutable/nodes/2.CELzu2i6.js +0 -337
  187. package/build/server/chunks/entries/pages/_layout.svelte.js-EFiihTdF.js +0 -18
  188. package/build/server/chunks/nodes/0.js-B0560RI0.js +0 -12
  189. package/build/server/chunks/nodes/1.js-D55AmdZs.js +0 -9
@@ -1 +1 @@
1
- {"version":"1791369987011"}
1
+ {"version":"1791706063586"}
package/build/handler.js CHANGED
@@ -2,9 +2,9 @@ import './shims.js';
2
2
  import 'node:fs';
3
3
  import 'node:path';
4
4
  import 'node:process';
5
- export { h as handler } from './server/chunks/handler-Bx2fbkEJ.js';
6
- import './server/chunks/index.js-BldXQ38P.js';
7
- import './server/chunks/manifest.js-Du-9DaEd.js';
5
+ export { h as handler } from './server/chunks/handler-XuK3Ihhf.js';
6
+ import './server/chunks/index.js-D2FEiD0I.js';
7
+ import './server/chunks/manifest.js-B_kahcFI.js';
8
8
  import './env.js';
9
9
  import 'node:buffer';
10
10
  import 'node:crypto';
@@ -16,8 +16,9 @@ import './server/chunks/chunks/shared.js-HQ0rfhm4.js';
16
16
  import './server/chunks/chunks/uneval.js-BJ9Qq2SF.js';
17
17
  import './server/chunks/chunks/utils.js-CAdNO8Tu.js';
18
18
  import 'node:url';
19
- import './server/chunks/chunks/internal.js-D_QJoxN-.js';
20
- import './server/chunks/chunks/server.js-11-pxAWV.js';
21
- import './server/chunks/chunks/internal2.js-BcS47nI-.js';
19
+ import './server/chunks/chunks/index-server.js-CV2lq-ha.js';
20
+ import './server/chunks/chunks/server.js-DqHGsQU2.js';
21
+ import './server/chunks/chunks/internal.js-BcS47nI-.js';
22
+ import './server/chunks/chunks/internal2.js-DAPn3Vk8.js';
22
23
  import './server/chunks/chunks/exports.js-DH_tjtdv.js';
23
24
  //# sourceMappingURL=handler.js.map
package/build/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import http from 'node:http';
2
2
  import fs__default from 'node:fs';
3
3
  import process from 'node:process';
4
- import { p as polka, h as handler, f as format_listening_address } from './server/chunks/handler-Bx2fbkEJ.js';
4
+ import { p as polka, h as handler, f as format_listening_address } from './server/chunks/handler-XuK3Ihhf.js';
5
5
  import { env, timeout_env } from './env.js';
6
6
  import { rm } from 'node:fs/promises';
7
7
  import './shims.js';
@@ -14,12 +14,13 @@ import 'node:stream';
14
14
  import './server/chunks/chunks/shared.js-HQ0rfhm4.js';
15
15
  import './server/chunks/chunks/uneval.js-BJ9Qq2SF.js';
16
16
  import './server/chunks/chunks/utils.js-CAdNO8Tu.js';
17
- import './server/chunks/index.js-BldXQ38P.js';
18
- import './server/chunks/chunks/internal.js-D_QJoxN-.js';
19
- import './server/chunks/chunks/server.js-11-pxAWV.js';
20
- import './server/chunks/chunks/internal2.js-BcS47nI-.js';
17
+ import './server/chunks/index.js-D2FEiD0I.js';
18
+ import './server/chunks/chunks/index-server.js-CV2lq-ha.js';
19
+ import './server/chunks/chunks/server.js-DqHGsQU2.js';
20
+ import './server/chunks/chunks/internal.js-BcS47nI-.js';
21
+ import './server/chunks/chunks/internal2.js-DAPn3Vk8.js';
21
22
  import './server/chunks/chunks/exports.js-DH_tjtdv.js';
22
- import './server/chunks/manifest.js-Du-9DaEd.js';
23
+ import './server/chunks/manifest.js-B_kahcFI.js';
23
24
  import 'node:url';
24
25
 
25
26
  const path = env('SOCKET_PATH', false);
@@ -328,5 +328,5 @@ function appConfig() {
328
328
  return config;
329
329
  }
330
330
 
331
- export { appConfig as a, textPreviewOf as b, shouldRecordPrompt as c, parseTagWords as d, getTrigger as g, isValidTagWord as i, previewSegments as p, searchKey as s, triggerMode as t };
332
- //# sourceMappingURL=app-config.svelte.js-BW7TwbBy.js.map
331
+ export { appConfig as a, parseTagWords as b, searchKey as c, textPreviewOf as d, getTrigger as g, isValidTagWord as i, previewSegments as p, shouldRecordPrompt as s, triggerMode as t };
332
+ //# sourceMappingURL=app-config.svelte.js-D7wkLUkK.js.map
@@ -1,4 +1,4 @@
1
- import { D as DSI_CONFIG_PATH } from './insight-config.js-XUD5BN0g.js';
1
+ import { D as DSI_CONFIG_PATH } from './insight-config.js-CA-iT3lB.js';
2
2
  import { mkdirSync } from 'node:fs';
3
3
  import { dirname, join } from 'node:path';
4
4
  import { DatabaseSync } from 'node:sqlite';
@@ -117,4 +117,4 @@ function pruneTerminalBefore(cutoffMs, db = openA2aDb()) {
117
117
  }
118
118
 
119
119
  export { listRecent as a, getRow as g, insertWaiting as i, listWaiting as l, openA2aDb as o, pruneTerminalBefore as p, settleRow as s };
120
- //# sourceMappingURL=db.js-BylhmazO.js.map
120
+ //# sourceMappingURL=db.js-DRhjT6xK.js.map
@@ -1,36 +1,21 @@
1
- import { d as readPromptsConfig, D as DSI_CONFIG_PATH, j as joinTagWords, p as parseTagWords } from './insight-config.js-XUD5BN0g.js';
1
+ import { d as readPromptsConfig, D as DSI_CONFIG_PATH, j as joinTagWords, p as parseTagWords } from './insight-config.js-CA-iT3lB.js';
2
2
  import { mkdirSync } from 'node:fs';
3
3
  import { join, dirname } from 'node:path';
4
4
  import { DatabaseSync } from 'node:sqlite';
5
5
  import { homedir } from 'node:os';
6
6
 
7
- //#region src/lib/server/prompts/db.ts
7
+ //#region src/lib/server/prompts/connection.ts
8
8
  /**
9
- * prompts-db (2026-08-28) — the Shelf: one global store of operator prompt
10
- * habits behind the DSI composer's `?` finder. Every admitted ordinary
11
- * send is recorded (first send creates the row, later sends increment);
12
- * search matches label/text prefix (legacy) or contains/fuzzy (`?`,
13
- * tier waterfall); ranking is use_count DESC, last_used_at DESC. Table is
14
- * capped at 5,000 rows — overflow prunes the oldest use_count=1 rows
15
- * (LRU of one-offs; multi-use rows are never pruned). A disposable FTS5
16
- * trigram index (schema v2) shadows the table for `?` search; any FTS
17
- * failure degrades to LIKE — never blocks open, never throws to a route.
9
+ * prompts-db connection (2026-10-10) — lifecycle half of the Shelf, moved
10
+ * WHOLE from db.ts (ADR-0019 standard, ADR-0022 W1). Path resolution
11
+ * (explicit arg -> DSI_PROMPTS_DB env -> settings dbPath -> ~/.dsi default,
12
+ * ~/ expanded), version-gated migrate, the cached default handle, and the
13
+ * close/reset test seams. Degrade contract: never throws to a route —
14
+ * failures are warned and return null/false.
18
15
  *
19
- * Spec: dev/specs/2026-08-28 - DSI Suggest Strip (PRD Module Map
20
- * "prompts-db"; Tasks 1.1). Reference: OCI src/lib/server/prompts/db.ts
21
- * (behavioral reference — semantics ported, names/seams DSI-native).
22
- *
23
- * Storage: node:sqlite DatabaseSync, zero new npm deps. File lives at
24
- * `~/.dsi/prompts.sqlite` by default (DSI_CONFIG_PATH sibling, same trust
25
- * boundary as a2a.sqlite — operator-copied 2026-08-28 with 30 seeded
26
- * rows); `prompts.dbPath` in settings.yaml moves it (~/ expanded), and
27
- * `DSI_PROMPTS_DB` env override is the test seam (each
28
- * node-env-globed test file points it at a tmp path before first open).
29
- *
30
- * Module boundary (PRD communication map): this module imports the
31
- * config layer only (for the directory) — never dsh-connection, never
32
- * dsh-rpc (D10), never the client suggest service (fuzzy math is
33
- * server-local so the client never crosses into $lib/server).
16
+ * Moved verbatim from db.ts by line range; private helpers widened to
17
+ * default-public where siblings import them (sanctioned seam, no signature
18
+ * changes).
34
19
  */
35
20
  /** Library filename under `~/.dsi/`. */
36
21
  var PROMPTS_DB_FILENAME = "prompts.sqlite";
@@ -237,51 +222,167 @@ function migrate(db) {
237
222
  warn("migration failed:", e);
238
223
  }
239
224
  }
225
+ /** The canonical projection of a prompts row (every query selects this). */
240
226
  var SELECT_COLS = "id, label, text, use_count, macro, last_used_at, created_at, tags";
227
+ /** SQL fragment filtering the macro flag — empty when unfiltered (the
228
+ * finder shows macros and ordinary prompts alike; the manager filters). */
229
+ function macroCond(macro) {
230
+ return macro === void 0 ? "" : ` AND macro = ${macro}`;
231
+ }
232
+ /** Dice similarity floor for tier-2 inclusion — PER TERM (min-combine,
233
+ * S3): a row is only as strong as its weakest keyword. Below = noise; the
234
+ * ADR word-share decoy scores 0.174 — excluded. */
235
+ var FUZZY_DICE_FLOOR = .3;
241
236
  /**
242
- * Count-only use recording (The Prompt Tags ADR, 2026-09-14, D7): bump
243
- * use_count + refresh last_used_at for an EXISTING row; unknown text
244
- * returns { counted: false } and inserts NOTHING — the wire's only path
245
- * to a row is an operator save. Null on failure (DB unavailable/empty text).
237
+ * Split a `?`-search key into keyword terms (ADR S1; separator charset
238
+ * widened by ADR-0014 D2): split on `,`, `;`, `+`, or whitespace, trim,
239
+ * drop empties, dedupe (case-insensitive, first spelling wins).
240
+ * `adr, spec + task` → [adr, spec, task]; `load;;skill;` → [load, skill];
241
+ * single term → array of one — the caller decides which path runs.
242
+ * Empty/blank key → []. Pure; exported for tests.
246
243
  */
247
- function countPromptUse(text) {
248
- const trimmed = text.trim();
249
- if (!trimmed) return null;
250
- const db = openPromptsDb();
251
- if (!db) return null;
252
- try {
253
- if (db.prepare(`UPDATE prompts
254
- SET use_count = use_count + 1, last_used_at = datetime('now')
255
- WHERE text = ?`).run(trimmed).changes === 0) return { counted: false };
256
- const row = db.prepare(`SELECT ${SELECT_COLS} FROM prompts WHERE text = ?`).get(trimmed);
257
- return row ? {
258
- counted: true,
259
- record: row
260
- } : null;
261
- } catch (e) {
262
- warn("countPromptUse failed:", e);
263
- return null;
244
+ function splitQueryTerms(key) {
245
+ const seen = /* @__PURE__ */ new Set();
246
+ const terms = [];
247
+ for (const frag of key.split(/[,;+\s]+/)) {
248
+ const raw = frag.trim();
249
+ if (!raw) continue;
250
+ const lower = raw.toLowerCase();
251
+ if (seen.has(lower)) continue;
252
+ seen.add(lower);
253
+ terms.push({
254
+ raw,
255
+ lower
256
+ });
257
+ }
258
+ return terms;
259
+ }
260
+ /** Dice coefficient over character trigrams (case handled by callers). */
261
+ function diceSimilarity(a, b) {
262
+ const grams = /* @__PURE__ */ new Map();
263
+ for (let i = 0; i + 3 <= a.length; i++) {
264
+ const g = a.slice(i, 3 + i);
265
+ grams.set(g, (grams.get(g) ?? 0) + 1);
266
+ }
267
+ if (grams.size === 0) return 0;
268
+ let bCount = 0;
269
+ let shared = 0;
270
+ for (let i = 0; i + 3 <= b.length; i++) {
271
+ bCount++;
272
+ const g = b.slice(i, 3 + i);
273
+ const have = grams.get(g) ?? 0;
274
+ if (have > 0) {
275
+ shared++;
276
+ if (have === 1) grams.delete(g);
277
+ else grams.set(g, have - 1);
278
+ }
264
279
  }
280
+ if (bCount === 0) return 0;
281
+ const aCount = a.length - 2;
282
+ return 2 * shared / (aCount + bCount);
265
283
  }
266
284
  /**
267
- * Cap enforcement (ADR D13): if rows > MAX_ROWS, delete the oldest
268
- * use_count=1 rows until at cap. Multi-use prompts are never pruned.
285
+ * Word-level similarity: max of Dice and normalized edit distance — Dice is
286
+ * meaningless for words shorter than 3 trigrams/chars, edit covers them
287
+ * ("lod" vs "load": Dice 0, edit 0.75 → 0.75). Exported for tests.
269
288
  */
270
- function pruneIfNeeded(db) {
271
- try {
272
- const overflow = db.prepare("SELECT COUNT(*) AS n FROM prompts").get().n - MAX_ROWS;
273
- if (overflow <= 0) return;
274
- db.prepare(`DELETE FROM prompts
275
- WHERE id IN (
276
- SELECT id FROM prompts
277
- WHERE use_count <= 1
278
- ORDER BY last_used_at ASC, id ASC
279
- LIMIT ?
280
- )`).run(overflow);
281
- } catch (e) {
282
- warn("prune failed:", e);
289
+ function wordSimilarity(a, b) {
290
+ const edit = 1 - levenshtein(a, b) / Math.max(a.length, b.length);
291
+ return Math.max(diceSimilarity(a, b), edit);
292
+ }
293
+ /** Wagner–Fischer edit distance (two-row DP), case handled by callers. */
294
+ function levenshtein(a, b) {
295
+ if (a === b) return 0;
296
+ if (!a.length) return b.length;
297
+ if (!b.length) return a.length;
298
+ let prev = Array.from({ length: b.length + 1 }, (_, i) => i);
299
+ for (let i = 1; i <= a.length; i++) {
300
+ const cur = [i];
301
+ for (let j = 1; j <= b.length; j++) cur[j] = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
302
+ prev = cur;
303
+ }
304
+ return prev[b.length];
305
+ }
306
+ /** Lines a row offers to line-level Dice (S3): label counts as the FIRST
307
+ * line — the user-chosen handle deserves line parity with text lines. */
308
+ function rowLines(row) {
309
+ return row.label !== null ? [row.label, ...row.text.split("\n")] : row.text.split("\n");
310
+ }
311
+ /** Best-line score for ONE term (S3): max over the row's lines, where a
312
+ * line's score is the best of whole-line Dice and word-level similarity
313
+ * over the line's words (max of Dice and normalized edit distance — Dice
314
+ * is meaningless for words shorter than 3 trigrams, edit covers them:
315
+ * typo'd "lod" vs "load" clears the floor at word level while line-level
316
+ * trigram dilution would sink it). The word-aware allowance is what keeps
317
+ * typo'd short terms reachable under min-combine as part of a multi-term
318
+ * key. Localizing to the best line kills the body tax: a 400-char body
319
+ * diluting full-text Dice can no longer sink a term that matches its own
320
+ * line cleanly. */
321
+ function termLineScore(term, row) {
322
+ let best = 0;
323
+ for (const line of rowLines(row)) {
324
+ const l = line.toLowerCase();
325
+ if (l.includes(term)) {
326
+ best = 1;
327
+ break;
328
+ }
329
+ let lineScore = diceSimilarity(term, l);
330
+ for (const word of l.split(/\s+/)) {
331
+ if (!word) continue;
332
+ lineScore = Math.max(lineScore, wordSimilarity(term, word));
333
+ }
334
+ best = Math.max(best, lineScore);
335
+ }
336
+ return best;
337
+ }
338
+ /** FTS5 trigram set for a single term (S3): grams of the lowercased term
339
+ * only — never extracted across separators, so no junk grams bridge
340
+ * `;`-split keywords. Deduped; null for <3-char terms (no grams). */
341
+ function termTrigramExpr(term) {
342
+ const k = term.toLowerCase();
343
+ const grams = [];
344
+ for (let i = 0; i + 3 <= k.length && grams.length < 64; i++) {
345
+ const g = k.slice(i, 3 + i);
346
+ if (!grams.includes(g)) grams.push(g);
347
+ }
348
+ return grams.length ? grams.map((g) => `"${g}"`).join(" OR ") : null;
349
+ }
350
+ /** Tier 2 — per-term best-line Dice, min-combine (S3, Semicolon Search).
351
+ * Candidate pool: per-term trigram OR + bm25 cap 50, UNION of per-term
352
+ * pools capped 100 — a row matching ANY term fuzzily enters the pool;
353
+ * per-term scoring then enforces the AND. Row score = MIN over terms of
354
+ * (max Dice over the row's lines, label counts as first line); any term
355
+ * under the 0.3 floor excludes the row entirely. Ordering: score DESC,
356
+ * use_count DESC, last_used_at DESC. Never mixes with tier 1 (only runs
357
+ * when tier 1 returned empty). */
358
+ function fuzzyReRank(db, terms, limit, macro) {
359
+ const pool = /* @__PURE__ */ new Map();
360
+ for (const term of terms) {
361
+ if (term.lower.length < 3) continue;
362
+ const expr = termTrigramExpr(term.lower);
363
+ if (!expr) continue;
364
+ try {
365
+ const rows = db.prepare(`SELECT ${SELECT_COLS} FROM prompts
366
+ WHERE id IN (
367
+ SELECT rowid FROM prompts_fts WHERE prompts_fts MATCH ?
368
+ ORDER BY bm25(prompts_fts) LIMIT 50
369
+ )${macroCond(macro)}`).all(expr);
370
+ for (const r of rows) {
371
+ if (pool.size >= 100) break;
372
+ if (!pool.has(r.id)) pool.set(r.id, r);
373
+ }
374
+ } catch {}
283
375
  }
376
+ if (pool.size === 0) return [];
377
+ return [...pool.values()].map((row) => {
378
+ return {
379
+ row,
380
+ score: terms.reduce((min, t) => Math.min(min, termLineScore(t.lower, row)), 1)
381
+ };
382
+ }).filter((s) => s.score >= FUZZY_DICE_FLOOR).sort((a, b) => b.score - a.score || b.row.use_count - a.row.use_count || (b.row.last_used_at < a.row.last_used_at ? 1 : b.row.last_used_at > a.row.last_used_at ? -1 : 0)).slice(0, limit).map((s) => s.row);
284
383
  }
384
+ //#endregion
385
+ //#region src/lib/server/prompts/search.ts
285
386
  /**
286
387
  * Search prompts. Ranked by use_count DESC, last_used_at DESC.
287
388
  *
@@ -316,48 +417,10 @@ function searchPrompts(prefix, limit = 5, opts) {
316
417
  return [];
317
418
  }
318
419
  }
319
- /** SQL fragment filtering the macro flag — empty when unfiltered (the
320
- * value is a server-internal 0|1, never user text, so inlining is safe). */
321
- function macroCond(macro) {
322
- return macro === void 0 ? "" : ` AND macro = ${macro}`;
323
- }
324
420
  /** Escape LIKE wildcards in user input so the prefix matches literally. */
325
421
  function escLike(s) {
326
422
  return s.replace(/[\\%_]/g, (c) => `\\${c}`);
327
423
  }
328
- /** Trigram index needs ≥3-char keys; below this tier 0 falls back to LIKE. */
329
- var CONTAINS_MIN_FTS = 3;
330
- /** Candidate-pool caps: per-term pool (bm25) and the union budget (S3). */
331
- var FUZZY_CANDIDATE_LIMIT = 50;
332
- var FUZZY_UNION_LIMIT = 100;
333
- /** Dice similarity floor for tier-2 inclusion — PER TERM (min-combine,
334
- * S3): a row is only as strong as its weakest keyword. Below = noise; the
335
- * ADR word-share decoy scores 0.174 — excluded. */
336
- var FUZZY_DICE_FLOOR = .3;
337
- /**
338
- * Split a `?`-search key into keyword terms (ADR S1; separator charset
339
- * widened by ADR-0014 D2): split on `,`, `;`, `+`, or whitespace, trim,
340
- * drop empties, dedupe (case-insensitive, first spelling wins).
341
- * `adr, spec + task` → [adr, spec, task]; `load;;skill;` → [load, skill];
342
- * single term → array of one — the caller decides which path runs.
343
- * Empty/blank key → []. Pure; exported for tests.
344
- */
345
- function splitQueryTerms(key) {
346
- const seen = /* @__PURE__ */ new Set();
347
- const terms = [];
348
- for (const frag of key.split(/[,;+\s]+/)) {
349
- const raw = frag.trim();
350
- if (!raw) continue;
351
- const lower = raw.toLowerCase();
352
- if (seen.has(lower)) continue;
353
- seen.add(lower);
354
- terms.push({
355
- raw,
356
- lower
357
- });
358
- }
359
- return terms;
360
- }
361
424
  /** Build an FTS5 phrase string from one term: `"` doubled per FTS5
362
425
  * phrase quoting. */
363
426
  function ftsPhrase(term) {
@@ -383,7 +446,7 @@ function searchContains(db, key, limit, macro) {
383
446
  const terms = splitQueryTerms(key);
384
447
  if (terms.length > 1) return searchContainsMulti(db, key, terms, limit, macro);
385
448
  const single = terms.length === 1 ? terms[0].raw : key;
386
- if (single.length < CONTAINS_MIN_FTS) return containsLike(db, single, limit, macro);
449
+ if (single.length < 3) return containsLike(db, single, limit, macro);
387
450
  try {
388
451
  const contains = ftsContains(db, single, limit, macro);
389
452
  if (contains.length > 0) return contains;
@@ -411,12 +474,12 @@ function isQueryEcho(text, keyAsSent) {
411
474
  * Any FTS failure degrades to LIKE-AND across all terms — never throws.
412
475
  */
413
476
  function searchContainsMulti(db, key, terms, limit, macro) {
414
- const indexable = terms.filter((t) => t.lower.length >= CONTAINS_MIN_FTS);
477
+ const indexable = terms.filter((t) => t.lower.length >= 3);
415
478
  try {
416
479
  let rows;
417
480
  if (indexable.length > 0) {
418
481
  rows = ftsAndContains(db, indexable, limit, macro);
419
- const shortTerms = terms.filter((t) => t.lower.length < CONTAINS_MIN_FTS);
482
+ const shortTerms = terms.filter((t) => t.lower.length < 3);
420
483
  if (shortTerms.length > 0) rows = rows.filter((row) => shortTerms.every((t) => `${row.label ?? ""}\n${row.text}`.toLowerCase().includes(t.lower)));
421
484
  } else rows = likeAndContains(db, terms, limit, macro);
422
485
  if (rows.length === 1 && isQueryEcho(rows[0].text, key)) rows = [];
@@ -470,129 +533,51 @@ function containsLike(db, key, limit, macro) {
470
533
  ORDER BY use_count DESC, last_used_at DESC
471
534
  LIMIT ?`).all(like, like, limit);
472
535
  }
473
- /** Dice coefficient over character trigrams (case handled by callers). */
474
- function diceSimilarity(a, b) {
475
- const grams = /* @__PURE__ */ new Map();
476
- for (let i = 0; i + 3 <= a.length; i++) {
477
- const g = a.slice(i, 3 + i);
478
- grams.set(g, (grams.get(g) ?? 0) + 1);
479
- }
480
- if (grams.size === 0) return 0;
481
- let bCount = 0;
482
- let shared = 0;
483
- for (let i = 0; i + 3 <= b.length; i++) {
484
- bCount++;
485
- const g = b.slice(i, 3 + i);
486
- const have = grams.get(g) ?? 0;
487
- if (have > 0) {
488
- shared++;
489
- if (have === 1) grams.delete(g);
490
- else grams.set(g, have - 1);
491
- }
492
- }
493
- if (bCount === 0) return 0;
494
- const aCount = a.length - 2;
495
- return 2 * shared / (aCount + bCount);
496
- }
536
+ //#endregion
537
+ //#region src/lib/server/prompts/crud.ts
497
538
  /**
498
- * Word-level similarity: max of Dice and normalized edit distance — Dice is
499
- * meaningless for words shorter than 3 trigrams/chars, edit covers them
500
- * ("lod" vs "load": Dice 0, edit 0.75 → 0.75). Exported for tests.
539
+ * Count-only use recording (The Prompt Tags ADR, 2026-09-14, D7): bump
540
+ * use_count + refresh last_used_at for an EXISTING row; unknown text
541
+ * returns { counted: false } and inserts NOTHING — the wire's only path
542
+ * to a row is an operator save. Null on failure (DB unavailable/empty text).
501
543
  */
502
- function wordSimilarity(a, b) {
503
- const edit = 1 - levenshtein(a, b) / Math.max(a.length, b.length);
504
- return Math.max(diceSimilarity(a, b), edit);
505
- }
506
- /** Wagner–Fischer edit distance (two-row DP), case handled by callers. */
507
- function levenshtein(a, b) {
508
- if (a === b) return 0;
509
- if (!a.length) return b.length;
510
- if (!b.length) return a.length;
511
- let prev = Array.from({ length: b.length + 1 }, (_, i) => i);
512
- for (let i = 1; i <= a.length; i++) {
513
- const cur = [i];
514
- for (let j = 1; j <= b.length; j++) cur[j] = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
515
- prev = cur;
516
- }
517
- return prev[b.length];
518
- }
519
- /** Lines a row offers to line-level Dice (S3): label counts as the FIRST
520
- * line — the user-chosen handle deserves line parity with text lines. */
521
- function rowLines(row) {
522
- return row.label !== null ? [row.label, ...row.text.split("\n")] : row.text.split("\n");
523
- }
524
- /** Best-line score for ONE term (S3): max over the row's lines, where a
525
- * line's score is the best of whole-line Dice and word-level similarity
526
- * over the line's words (max of Dice and normalized edit distance — Dice
527
- * is meaningless for words shorter than 3 trigrams, edit covers them:
528
- * typo'd "lod" vs "load" clears the floor at word level while line-level
529
- * trigram dilution would sink it). The word-aware allowance is what keeps
530
- * typo'd short terms reachable under min-combine as part of a multi-term
531
- * key. Localizing to the best line kills the body tax: a 400-char body
532
- * diluting full-text Dice can no longer sink a term that matches its own
533
- * line cleanly. */
534
- function termLineScore(term, row) {
535
- let best = 0;
536
- for (const line of rowLines(row)) {
537
- const l = line.toLowerCase();
538
- if (l.includes(term)) {
539
- best = 1;
540
- break;
541
- }
542
- let lineScore = diceSimilarity(term, l);
543
- for (const word of l.split(/\s+/)) {
544
- if (!word) continue;
545
- lineScore = Math.max(lineScore, wordSimilarity(term, word));
546
- }
547
- best = Math.max(best, lineScore);
548
- }
549
- return best;
550
- }
551
- /** FTS5 trigram set for a single term (S3): grams of the lowercased term
552
- * only — never extracted across separators, so no junk grams bridge
553
- * `;`-split keywords. Deduped; null for <3-char terms (no grams). */
554
- function termTrigramExpr(term) {
555
- const k = term.toLowerCase();
556
- const grams = [];
557
- for (let i = 0; i + 3 <= k.length && grams.length < 64; i++) {
558
- const g = k.slice(i, 3 + i);
559
- if (!grams.includes(g)) grams.push(g);
544
+ function countPromptUse(text) {
545
+ const trimmed = text.trim();
546
+ if (!trimmed) return null;
547
+ const db = openPromptsDb();
548
+ if (!db) return null;
549
+ try {
550
+ if (db.prepare(`UPDATE prompts
551
+ SET use_count = use_count + 1, last_used_at = datetime('now')
552
+ WHERE text = ?`).run(trimmed).changes === 0) return { counted: false };
553
+ const row = db.prepare(`SELECT ${SELECT_COLS} FROM prompts WHERE text = ?`).get(trimmed);
554
+ return row ? {
555
+ counted: true,
556
+ record: row
557
+ } : null;
558
+ } catch (e) {
559
+ warn("countPromptUse failed:", e);
560
+ return null;
560
561
  }
561
- return grams.length ? grams.map((g) => `"${g}"`).join(" OR ") : null;
562
562
  }
563
- /** Tier 2 — per-term best-line Dice, min-combine (S3, Semicolon Search).
564
- * Candidate pool: per-term trigram OR + bm25 cap 50, UNION of per-term
565
- * pools capped 100 — a row matching ANY term fuzzily enters the pool;
566
- * per-term scoring then enforces the AND. Row score = MIN over terms of
567
- * (max Dice over the row's lines, label counts as first line); any term
568
- * under the 0.3 floor excludes the row entirely. Ordering: score DESC,
569
- * use_count DESC, last_used_at DESC. Never mixes with tier 1 (only runs
570
- * when tier 1 returned empty). */
571
- function fuzzyReRank(db, terms, limit, macro) {
572
- const pool = /* @__PURE__ */ new Map();
573
- for (const term of terms) {
574
- if (term.lower.length < CONTAINS_MIN_FTS) continue;
575
- const expr = termTrigramExpr(term.lower);
576
- if (!expr) continue;
577
- try {
578
- const rows = db.prepare(`SELECT ${SELECT_COLS} FROM prompts
579
- WHERE id IN (
580
- SELECT rowid FROM prompts_fts WHERE prompts_fts MATCH ?
581
- ORDER BY bm25(prompts_fts) LIMIT ${FUZZY_CANDIDATE_LIMIT}
582
- )${macroCond(macro)}`).all(expr);
583
- for (const r of rows) {
584
- if (pool.size >= FUZZY_UNION_LIMIT) break;
585
- if (!pool.has(r.id)) pool.set(r.id, r);
586
- }
587
- } catch {}
563
+ /**
564
+ * Cap enforcement (ADR D13): if rows > MAX_ROWS, delete the oldest
565
+ * use_count=1 rows until at cap. Multi-use prompts are never pruned.
566
+ */
567
+ function pruneIfNeeded(db) {
568
+ try {
569
+ const overflow = db.prepare("SELECT COUNT(*) AS n FROM prompts").get().n - MAX_ROWS;
570
+ if (overflow <= 0) return;
571
+ db.prepare(`DELETE FROM prompts
572
+ WHERE id IN (
573
+ SELECT id FROM prompts
574
+ WHERE use_count <= 1
575
+ ORDER BY last_used_at ASC, id ASC
576
+ LIMIT ?
577
+ )`).run(overflow);
578
+ } catch (e) {
579
+ warn("prune failed:", e);
588
580
  }
589
- if (pool.size === 0) return [];
590
- return [...pool.values()].map((row) => {
591
- return {
592
- row,
593
- score: terms.reduce((min, t) => Math.min(min, termLineScore(t.lower, row)), 1)
594
- };
595
- }).filter((s) => s.score >= FUZZY_DICE_FLOOR).sort((a, b) => b.score - a.score || b.row.use_count - a.row.use_count || (b.row.last_used_at < a.row.last_used_at ? 1 : b.row.last_used_at > a.row.last_used_at ? -1 : 0)).slice(0, limit).map((s) => s.row);
596
581
  }
597
582
  /**
598
583
  * Rename a prompt's label (ADR D3). Label is the one-line handle used for
@@ -777,4 +762,4 @@ function updatePrompt(id, fields) {
777
762
  }
778
763
 
779
764
  export { countPromptUse as a, renamePromptLabel as b, createPrompt as c, deletePrompt as d, listPrompts as l, resolvePromptsDbPath as r, searchPrompts as s, updatePrompt as u };
780
- //# sourceMappingURL=db2.js-Cm8FBINY.js.map
765
+ //# sourceMappingURL=db2.js-DUta2B-n.js.map