@smeltjs/core 0.2.0 → 0.4.0

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 (348) hide show
  1. package/README.md +3 -3
  2. package/dist/agents/guide.d.ts +68 -0
  3. package/dist/agents/guide.d.ts.map +1 -0
  4. package/dist/agents/guide.js +72 -0
  5. package/dist/agents/guide.js.map +1 -0
  6. package/dist/agents/instructions.d.ts +133 -0
  7. package/dist/agents/instructions.d.ts.map +1 -0
  8. package/dist/agents/instructions.js +212 -0
  9. package/dist/agents/instructions.js.map +1 -0
  10. package/dist/agents/lint.d.ts +154 -0
  11. package/dist/agents/lint.d.ts.map +1 -0
  12. package/dist/agents/lint.js +761 -0
  13. package/dist/agents/lint.js.map +1 -0
  14. package/dist/agents/split.d.ts +113 -0
  15. package/dist/agents/split.d.ts.map +1 -0
  16. package/dist/agents/split.js +234 -0
  17. package/dist/agents/split.js.map +1 -0
  18. package/dist/apply.d.ts.map +1 -1
  19. package/dist/apply.js.map +1 -1
  20. package/dist/cache/prefix.d.ts.map +1 -1
  21. package/dist/cache/prefix.js.map +1 -1
  22. package/dist/cli/agents.d.ts +39 -0
  23. package/dist/cli/agents.d.ts.map +1 -0
  24. package/dist/cli/agents.js +121 -0
  25. package/dist/cli/agents.js.map +1 -0
  26. package/dist/cli/args.d.ts +17 -70
  27. package/dist/cli/args.d.ts.map +1 -1
  28. package/dist/cli/args.js +18 -338
  29. package/dist/cli/args.js.map +1 -1
  30. package/dist/cli/bin.d.ts.map +1 -1
  31. package/dist/cli/bin.js.map +1 -1
  32. package/dist/cli/config.d.ts +60 -0
  33. package/dist/cli/config.d.ts.map +1 -1
  34. package/dist/cli/config.js +89 -2
  35. package/dist/cli/config.js.map +1 -1
  36. package/dist/cli/hooks.d.ts +55 -51
  37. package/dist/cli/hooks.d.ts.map +1 -1
  38. package/dist/cli/hooks.js +206 -658
  39. package/dist/cli/hooks.js.map +1 -1
  40. package/dist/cli/init.d.ts +30 -15
  41. package/dist/cli/init.d.ts.map +1 -1
  42. package/dist/cli/init.js +167 -38
  43. package/dist/cli/init.js.map +1 -1
  44. package/dist/cli/report.d.ts +23 -0
  45. package/dist/cli/report.d.ts.map +1 -1
  46. package/dist/cli/report.js +142 -4
  47. package/dist/cli/report.js.map +1 -1
  48. package/dist/cli/run.d.ts +29 -90
  49. package/dist/cli/run.d.ts.map +1 -1
  50. package/dist/cli/run.js +34 -342
  51. package/dist/cli/run.js.map +1 -1
  52. package/dist/cli/shell.d.ts +106 -0
  53. package/dist/cli/shell.d.ts.map +1 -0
  54. package/dist/cli/shell.js +100 -0
  55. package/dist/cli/shell.js.map +1 -0
  56. package/dist/cli/subcommands/agents.d.ts +72 -0
  57. package/dist/cli/subcommands/agents.d.ts.map +1 -0
  58. package/dist/cli/subcommands/agents.js +162 -0
  59. package/dist/cli/subcommands/agents.js.map +1 -0
  60. package/dist/cli/subcommands/flags.d.ts +144 -0
  61. package/dist/cli/subcommands/flags.d.ts.map +1 -0
  62. package/dist/cli/subcommands/flags.js +220 -0
  63. package/dist/cli/subcommands/flags.js.map +1 -0
  64. package/dist/cli/subcommands/hooks.d.ts +18 -0
  65. package/dist/cli/subcommands/hooks.d.ts.map +1 -0
  66. package/dist/cli/subcommands/hooks.js +80 -0
  67. package/dist/cli/subcommands/hooks.js.map +1 -0
  68. package/dist/cli/subcommands/init.d.ts +19 -0
  69. package/dist/cli/subcommands/init.d.ts.map +1 -0
  70. package/dist/cli/subcommands/init.js +44 -0
  71. package/dist/cli/subcommands/init.js.map +1 -0
  72. package/dist/cli/subcommands/map.d.ts +75 -0
  73. package/dist/cli/subcommands/map.d.ts.map +1 -0
  74. package/dist/cli/subcommands/map.js +132 -0
  75. package/dist/cli/subcommands/map.js.map +1 -0
  76. package/dist/cli/subcommands/registry.d.ts +81 -0
  77. package/dist/cli/subcommands/registry.d.ts.map +1 -0
  78. package/dist/cli/subcommands/registry.js +141 -0
  79. package/dist/cli/subcommands/registry.js.map +1 -0
  80. package/dist/cli/subcommands/retrieve.d.ts +74 -0
  81. package/dist/cli/subcommands/retrieve.d.ts.map +1 -0
  82. package/dist/cli/subcommands/retrieve.js +84 -0
  83. package/dist/cli/subcommands/retrieve.js.map +1 -0
  84. package/dist/cli/subcommands/smelt.d.ts +107 -0
  85. package/dist/cli/subcommands/smelt.d.ts.map +1 -0
  86. package/dist/cli/subcommands/smelt.js +304 -0
  87. package/dist/cli/subcommands/smelt.js.map +1 -0
  88. package/dist/cli/subcommands/stats.d.ts +43 -0
  89. package/dist/cli/subcommands/stats.d.ts.map +1 -0
  90. package/dist/cli/subcommands/stats.js +62 -0
  91. package/dist/cli/subcommands/stats.js.map +1 -0
  92. package/dist/cli/subcommands/subcommand.d.ts +113 -0
  93. package/dist/cli/subcommands/subcommand.d.ts.map +1 -0
  94. package/dist/cli/subcommands/subcommand.js +3 -0
  95. package/dist/cli/subcommands/subcommand.js.map +1 -0
  96. package/dist/cli/usage.d.ts +3 -0
  97. package/dist/cli/usage.d.ts.map +1 -0
  98. package/dist/cli/usage.js +95 -0
  99. package/dist/cli/usage.js.map +1 -0
  100. package/dist/detect.d.ts.map +1 -1
  101. package/dist/detect.js.map +1 -1
  102. package/dist/errors.d.ts +21 -1
  103. package/dist/errors.d.ts.map +1 -1
  104. package/dist/errors.js +33 -1
  105. package/dist/errors.js.map +1 -1
  106. package/dist/harness/aider.d.ts +10 -0
  107. package/dist/harness/aider.d.ts.map +1 -0
  108. package/dist/harness/aider.js +21 -0
  109. package/dist/harness/aider.js.map +1 -0
  110. package/dist/harness/claude-code.d.ts +3 -0
  111. package/dist/harness/claude-code.d.ts.map +1 -0
  112. package/dist/harness/claude-code.js +68 -0
  113. package/dist/harness/claude-code.js.map +1 -0
  114. package/dist/harness/cline.d.ts +3 -0
  115. package/dist/harness/cline.d.ts.map +1 -0
  116. package/dist/harness/cline.js +54 -0
  117. package/dist/harness/cline.js.map +1 -0
  118. package/dist/harness/codex.d.ts +3 -0
  119. package/dist/harness/codex.d.ts.map +1 -0
  120. package/dist/harness/codex.js +92 -0
  121. package/dist/harness/codex.js.map +1 -0
  122. package/dist/harness/cursor.d.ts +3 -0
  123. package/dist/harness/cursor.d.ts.map +1 -0
  124. package/dist/harness/cursor.js +54 -0
  125. package/dist/harness/cursor.js.map +1 -0
  126. package/dist/harness/gemini.d.ts +3 -0
  127. package/dist/harness/gemini.d.ts.map +1 -0
  128. package/dist/harness/gemini.js +60 -0
  129. package/dist/harness/gemini.js.map +1 -0
  130. package/dist/harness/grok.d.ts +3 -0
  131. package/dist/harness/grok.d.ts.map +1 -0
  132. package/dist/harness/grok.js +47 -0
  133. package/dist/harness/grok.js.map +1 -0
  134. package/dist/harness/hermes.d.ts +3 -0
  135. package/dist/harness/hermes.d.ts.map +1 -0
  136. package/dist/harness/hermes.js +72 -0
  137. package/dist/harness/hermes.js.map +1 -0
  138. package/dist/harness/kilocode.d.ts +3 -0
  139. package/dist/harness/kilocode.d.ts.map +1 -0
  140. package/dist/harness/kilocode.js +35 -0
  141. package/dist/harness/kilocode.js.map +1 -0
  142. package/dist/harness/opencode.d.ts +3 -0
  143. package/dist/harness/opencode.d.ts.map +1 -0
  144. package/dist/harness/opencode.js +97 -0
  145. package/dist/harness/opencode.js.map +1 -0
  146. package/dist/harness/paths.d.ts +17 -0
  147. package/dist/harness/paths.d.ts.map +1 -0
  148. package/dist/harness/paths.js +45 -0
  149. package/dist/harness/paths.js.map +1 -0
  150. package/dist/harness/profile.d.ts +209 -0
  151. package/dist/harness/profile.d.ts.map +1 -0
  152. package/dist/harness/profile.js +41 -0
  153. package/dist/harness/profile.js.map +1 -0
  154. package/dist/harness/registry.d.ts +100 -0
  155. package/dist/harness/registry.d.ts.map +1 -0
  156. package/dist/harness/registry.js +144 -0
  157. package/dist/harness/registry.js.map +1 -0
  158. package/dist/harness/snippet.d.ts +19 -0
  159. package/dist/harness/snippet.d.ts.map +1 -0
  160. package/dist/harness/snippet.js +41 -0
  161. package/dist/harness/snippet.js.map +1 -0
  162. package/dist/hash.d.ts.map +1 -1
  163. package/dist/hash.js.map +1 -1
  164. package/dist/hooks/guard-core.d.ts +14 -14
  165. package/dist/hooks/guard-core.d.ts.map +1 -1
  166. package/dist/hooks/guard-core.js +15 -37
  167. package/dist/hooks/guard-core.js.map +1 -1
  168. package/dist/hooks/shim.d.ts +95 -4
  169. package/dist/hooks/shim.d.ts.map +1 -1
  170. package/dist/hooks/shim.js +87 -2
  171. package/dist/hooks/shim.js.map +1 -1
  172. package/dist/hooks/shims/claude-code.d.ts +5 -18
  173. package/dist/hooks/shims/claude-code.d.ts.map +1 -1
  174. package/dist/hooks/shims/claude-code.js +9 -56
  175. package/dist/hooks/shims/claude-code.js.map +1 -1
  176. package/dist/hooks/shims/cline.d.ts +5 -12
  177. package/dist/hooks/shims/cline.d.ts.map +1 -1
  178. package/dist/hooks/shims/cline.js +9 -34
  179. package/dist/hooks/shims/cline.js.map +1 -1
  180. package/dist/hooks/shims/codex.d.ts +5 -18
  181. package/dist/hooks/shims/codex.d.ts.map +1 -1
  182. package/dist/hooks/shims/codex.js +9 -51
  183. package/dist/hooks/shims/codex.js.map +1 -1
  184. package/dist/hooks/shims/cursor.d.ts +5 -14
  185. package/dist/hooks/shims/cursor.d.ts.map +1 -1
  186. package/dist/hooks/shims/cursor.js +9 -42
  187. package/dist/hooks/shims/cursor.js.map +1 -1
  188. package/dist/hooks/shims/gemini.d.ts +5 -18
  189. package/dist/hooks/shims/gemini.d.ts.map +1 -1
  190. package/dist/hooks/shims/gemini.js +9 -48
  191. package/dist/hooks/shims/gemini.js.map +1 -1
  192. package/dist/hooks/shims/grok.d.ts +5 -13
  193. package/dist/hooks/shims/grok.d.ts.map +1 -1
  194. package/dist/hooks/shims/grok.js +9 -32
  195. package/dist/hooks/shims/grok.js.map +1 -1
  196. package/dist/hooks/shims/hermes.d.ts +5 -17
  197. package/dist/hooks/shims/hermes.d.ts.map +1 -1
  198. package/dist/hooks/shims/hermes.js +9 -45
  199. package/dist/hooks/shims/hermes.js.map +1 -1
  200. package/dist/index.d.ts +43 -76
  201. package/dist/index.d.ts.map +1 -1
  202. package/dist/index.js +21 -67
  203. package/dist/index.js.map +1 -1
  204. package/dist/lang/bash.d.ts.map +1 -1
  205. package/dist/lang/bash.js.map +1 -1
  206. package/dist/lang/c.d.ts.map +1 -1
  207. package/dist/lang/c.js.map +1 -1
  208. package/dist/lang/c_sharp.d.ts.map +1 -1
  209. package/dist/lang/c_sharp.js.map +1 -1
  210. package/dist/lang/cpp.d.ts.map +1 -1
  211. package/dist/lang/cpp.js.map +1 -1
  212. package/dist/lang/go.d.ts.map +1 -1
  213. package/dist/lang/go.js.map +1 -1
  214. package/dist/lang/java.d.ts.map +1 -1
  215. package/dist/lang/java.js.map +1 -1
  216. package/dist/lang/javascript.d.ts.map +1 -1
  217. package/dist/lang/javascript.js.map +1 -1
  218. package/dist/lang/kotlin.d.ts.map +1 -1
  219. package/dist/lang/kotlin.js.map +1 -1
  220. package/dist/lang/php.d.ts.map +1 -1
  221. package/dist/lang/php.js.map +1 -1
  222. package/dist/lang/profile.d.ts.map +1 -1
  223. package/dist/lang/profile.js.map +1 -1
  224. package/dist/lang/python.d.ts.map +1 -1
  225. package/dist/lang/python.js.map +1 -1
  226. package/dist/lang/registry.d.ts.map +1 -1
  227. package/dist/lang/registry.js.map +1 -1
  228. package/dist/lang/ruby.d.ts.map +1 -1
  229. package/dist/lang/ruby.js.map +1 -1
  230. package/dist/lang/rust.d.ts.map +1 -1
  231. package/dist/lang/rust.js.map +1 -1
  232. package/dist/lang/swift.d.ts.map +1 -1
  233. package/dist/lang/swift.js.map +1 -1
  234. package/dist/lang/tsx.d.ts.map +1 -1
  235. package/dist/lang/tsx.js.map +1 -1
  236. package/dist/lang/typescript.d.ts.map +1 -1
  237. package/dist/lang/typescript.js.map +1 -1
  238. package/dist/net/policy.d.ts +18 -1
  239. package/dist/net/policy.d.ts.map +1 -1
  240. package/dist/net/policy.js +6 -4
  241. package/dist/net/policy.js.map +1 -1
  242. package/dist/ops/index.d.ts +39 -0
  243. package/dist/ops/index.d.ts.map +1 -0
  244. package/dist/ops/index.js +37 -0
  245. package/dist/ops/index.js.map +1 -0
  246. package/dist/ops/inputs.d.ts +170 -0
  247. package/dist/ops/inputs.d.ts.map +1 -0
  248. package/dist/ops/inputs.js +142 -0
  249. package/dist/ops/inputs.js.map +1 -0
  250. package/dist/ops/verbs.d.ts +136 -0
  251. package/dist/ops/verbs.d.ts.map +1 -0
  252. package/dist/ops/verbs.js +76 -0
  253. package/dist/ops/verbs.js.map +1 -0
  254. package/dist/plan/auto.d.ts +69 -0
  255. package/dist/plan/auto.d.ts.map +1 -0
  256. package/dist/plan/auto.js +70 -0
  257. package/dist/plan/auto.js.map +1 -0
  258. package/dist/plan/budget.d.ts +21 -0
  259. package/dist/plan/budget.d.ts.map +1 -0
  260. package/dist/plan/budget.js +26 -0
  261. package/dist/plan/budget.js.map +1 -0
  262. package/dist/plan/grammar.d.ts +14 -0
  263. package/dist/plan/grammar.d.ts.map +1 -1
  264. package/dist/plan/grammar.js +47 -6
  265. package/dist/plan/grammar.js.map +1 -1
  266. package/dist/plan/lexical.d.ts.map +1 -1
  267. package/dist/plan/lexical.js +1 -7
  268. package/dist/plan/lexical.js.map +1 -1
  269. package/dist/plan/planners.d.ts +35 -2
  270. package/dist/plan/planners.d.ts.map +1 -1
  271. package/dist/plan/planners.js +35 -2
  272. package/dist/plan/planners.js.map +1 -1
  273. package/dist/plan/structural.d.ts +19 -5
  274. package/dist/plan/structural.d.ts.map +1 -1
  275. package/dist/plan/structural.js +180 -33
  276. package/dist/plan/structural.js.map +1 -1
  277. package/dist/repomap/cache.d.ts +48 -0
  278. package/dist/repomap/cache.d.ts.map +1 -1
  279. package/dist/repomap/cache.js +112 -13
  280. package/dist/repomap/cache.js.map +1 -1
  281. package/dist/repomap/io.d.ts +24 -0
  282. package/dist/repomap/io.d.ts.map +1 -0
  283. package/dist/repomap/io.js +34 -0
  284. package/dist/repomap/io.js.map +1 -0
  285. package/dist/repomap/map.d.ts +69 -6
  286. package/dist/repomap/map.d.ts.map +1 -1
  287. package/dist/repomap/map.js +104 -22
  288. package/dist/repomap/map.js.map +1 -1
  289. package/dist/repomap/rank.d.ts +26 -2
  290. package/dist/repomap/rank.d.ts.map +1 -1
  291. package/dist/repomap/rank.js +20 -0
  292. package/dist/repomap/rank.js.map +1 -1
  293. package/dist/repomap/reader.d.ts +73 -0
  294. package/dist/repomap/reader.d.ts.map +1 -0
  295. package/dist/repomap/reader.js +30 -0
  296. package/dist/repomap/reader.js.map +1 -0
  297. package/dist/repomap/tags.d.ts.map +1 -1
  298. package/dist/repomap/tags.js.map +1 -1
  299. package/dist/retrieve.d.ts +8 -0
  300. package/dist/retrieve.d.ts.map +1 -1
  301. package/dist/retrieve.js +12 -1
  302. package/dist/retrieve.js.map +1 -1
  303. package/dist/smelter.d.ts +79 -0
  304. package/dist/smelter.d.ts.map +1 -0
  305. package/dist/smelter.js +65 -0
  306. package/dist/smelter.js.map +1 -0
  307. package/dist/stages.d.ts.map +1 -1
  308. package/dist/stages.js +2 -2
  309. package/dist/stages.js.map +1 -1
  310. package/dist/stats.d.ts +2 -1
  311. package/dist/stats.d.ts.map +1 -1
  312. package/dist/stats.js +2 -1
  313. package/dist/stats.js.map +1 -1
  314. package/dist/store-dir.d.ts +43 -4
  315. package/dist/store-dir.d.ts.map +1 -1
  316. package/dist/store-dir.js +48 -5
  317. package/dist/store-dir.js.map +1 -1
  318. package/dist/store.d.ts +6 -0
  319. package/dist/store.d.ts.map +1 -1
  320. package/dist/store.js +6 -0
  321. package/dist/store.js.map +1 -1
  322. package/dist/text/json-edit.d.ts +71 -0
  323. package/dist/text/json-edit.d.ts.map +1 -0
  324. package/dist/text/json-edit.js +219 -0
  325. package/dist/text/json-edit.js.map +1 -0
  326. package/dist/types.d.ts +35 -14
  327. package/dist/types.d.ts.map +1 -1
  328. package/dist/types.js.map +1 -1
  329. package/grammars/tree-sitter-bash.wasm +0 -0
  330. package/grammars/tree-sitter-c.wasm +0 -0
  331. package/grammars/tree-sitter-c_sharp.wasm +0 -0
  332. package/grammars/tree-sitter-cpp.wasm +0 -0
  333. package/grammars/tree-sitter-go.wasm +0 -0
  334. package/grammars/tree-sitter-java.wasm +0 -0
  335. package/grammars/tree-sitter-javascript.wasm +0 -0
  336. package/grammars/tree-sitter-kotlin.wasm +0 -0
  337. package/grammars/tree-sitter-php.wasm +0 -0
  338. package/grammars/tree-sitter-python.wasm +0 -0
  339. package/grammars/tree-sitter-ruby.wasm +0 -0
  340. package/grammars/tree-sitter-rust.wasm +0 -0
  341. package/grammars/tree-sitter-swift.wasm +0 -0
  342. package/grammars/tree-sitter-tsx.wasm +0 -0
  343. package/grammars/tree-sitter-typescript.wasm +0 -0
  344. package/package.json +11 -11
  345. package/dist/cli/resolve.d.ts +0 -103
  346. package/dist/cli/resolve.d.ts.map +0 -1
  347. package/dist/cli/resolve.js +0 -106
  348. package/dist/cli/resolve.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"store-dir.js","sourceRoot":"","sources":["../src/store-dir.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,SAAS,EACT,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,UAAU,EACV,SAAS,GACV,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EACL,kBAAkB,EAClB,UAAU,EACV,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAI3C;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,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EAAsE;IAChF,CAAC;IACD,IAAI,CAAC;QACH,SAAS,CAAC,EAAE,CAAC,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,GAAI,KAA2B,CAAC,IAAI,CAAC;QAC/C,kFAAkF;QAClF,yEAAyE;QACzE,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;YACpF,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;YAAS,CAAC;QACT,SAAS,CAAC,EAAE,CAAC,CAAC;IAChB,CAAC;AACH,CAAC","sourcesContent":["import {\n closeSync,\n fsyncSync,\n linkSync,\n mkdirSync,\n openSync,\n readdirSync,\n readFileSync,\n statSync,\n unlinkSync,\n writeSync,\n} from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport { randomBytes } from 'node:crypto';\nimport process from 'node:process';\n\nimport {\n HashCollisionError,\n SmeltError,\n StoreCorruptionError,\n StoreFormatError,\n UnknownHashError,\n} from './errors.ts';\nimport { contentHash } from './hash.ts';\nimport { retrieveStats } from './stats.ts';\nimport type { RawRetrieveCounters } from './stats.ts';\nimport type { ElisionStore, RetrieveStats } from './types.ts';\n\n/**\n * The format marker every store directory carries, and the one version this code\n * understands. A future layout is a new version, refused loudly by old code — never a\n * quiet reinterpretation of someone's stored bytes.\n */\nexport const DIRECTORY_STORE_FORMAT = 'smelt-elision-store';\nexport const DIRECTORY_STORE_VERSION = 1;\n\n/**\n * What a storage key may look like. `contentHash` produces 16 lowercase hex characters;\n * the pattern is wider so an injected test hash still works, and strict enough that a\n * key can never traverse out of `blobs/` or collide with `format.json`.\n */\nconst KEY_PATTERN = /^[0-9a-f]{4,128}$/;\n\n/** One journal line: a kind, a space, and the hash as a JSON string literal. */\nconst LOG_LINE = /^(hit|miss|corrupt) (\"(?:[^\"\\\\]|\\\\.)*\")$/;\n\n/** See {@link MemoryElisionStoreOptions} in `store.ts` — same escape hatch, same reason. */\nexport interface DirectoryElisionStoreOptions {\n /**\n * Override the hash function, so the collision branch — unreachable with sha256 —\n * can be tested. Production has no reason to pass this.\n */\n readonly hash?: (content: string) => string;\n}\n\n/**\n * A persistent {@link ElisionStore} over a content-addressed directory. `node:fs` only —\n * no SQLite, no new dependency, nothing that phones home. Elisions put here outlive the\n * process, so a long-lived agent session can `retrieve()` across restarts.\n *\n * ## Storage layout\n *\n * ```text\n * <root>/\n * format.json { \"format\": \"smelt-elision-store\", \"version\": 1 } — refused if unknown\n * blobs/<hash> one file per elision: the exact UTF-8 bytes, named by their content hash\n * tmp/ staging for atomic writes; never read, safe to sweep\n * retrievals.log append-only journal: `hit \"<hash>\"` | `miss \"<hash>\"` | `corrupt \"<hash>\"`\n * ```\n *\n * **Nothing lives in memory.** Every read — `stats()` included — comes off the disk, so\n * two instances over the same directory (two processes, or one process before and after\n * a restart) always agree. `stats()` is a scan; elision counts per session are small and\n * retrieval is the model asking for material back, which is rare by design.\n *\n * ## Durability\n *\n * - **Writes are crash-safe.** A blob is written to `tmp/`, `fsync`ed, then `link(2)`ed\n * into `blobs/` — an atomic, no-clobber publish. A torn write dies in `tmp/`, where\n * nothing looks; a name in `blobs/` always refers to a fully written file.\n * - **`fsync` is only as strong as the platform makes it.** Every flush here is Node's\n * `fsyncSync`, which is libuv's `uv_fs_fsync`, and what that reaches the hardware with\n * differs by platform. On Apple it is strong: libuv knows macOS's own `fsync(2)` only\n * hands the write to the drive, so its `__APPLE__` branch issues\n * `fcntl(fd, F_FULLFSYNC)` — a real drive-cache flush — before falling back to\n * `F_BARRIERFSYNC` and then plain `fsync(2)`. Measured here (Node 26, libuv 1.52,\n * internal APFS SSD): an 11-byte append costs 0.01 ms unflushed, 5.5 ms through\n * `fsyncSync`, and 0.10 ms through a raw `fsync(2)` against 4.8 ms through a raw\n * `F_FULLFSYNC` — the cost says which syscall is being made. Everywhere else libuv\n * calls plain `fsync(2)`, which is as durable as the drive's honesty about its own\n * write cache. So a **power loss** can lose a blob or a journal line this code has\n * already `fsync`ed and reported as written on any non-Apple platform whose drive\n * lies, and on Apple only where `F_FULLFSYNC` itself fails and libuv degrades\n * silently — some non-APFS and network mounts. A **process** crash cannot lose one\n * anywhere: the bytes are in the page cache and the publish is still atomic. Nothing\n * is ever handed back unverified either way, so the worst a lost blob can produce is\n * {@link UnknownHashError} — never wrong bytes presented as right ones. \"Crash-safe\"\n * is the claim, deliberately not \"power-loss-proof\": the durability is real, it is\n * just not unconditional.\n * - **Reads verify.** `retrieve()`, `peek()` and `has()` re-hash the bytes and refuse a\n * mismatch with {@link StoreCorruptionError} — a damaged blob is never handed back as\n * a retrieval nor reported as present, and \"we hold damaged bytes\" is distinct from\n * {@link UnknownHashError}'s \"never existed\". The guard in\n * `test/guards/persistent-store.test.ts` watches this.\n * - **Counters survive a restart.** Every `retrieve()` appends one `fsync`ed line to\n * `retrievals.log`, and `stats()` is a fold over it — so `expansionRate` stays\n * meaningful across a whole session, not just one process. A crash in the middle of\n * an append can tear at most that one line; a torn tail is skipped, costing at most\n * the single count that was being written when the process died.\n * - **Concurrent writers are safe.** `link(2)` refuses to clobber, so two processes\n * putting at once race to publish and the loser verifies byte-for-byte agreement with\n * the winner — identical content dedupes, different content under one hash is a\n * {@link HashCollisionError}. Journal appends use `O_APPEND`. Tested with two real\n * processes in `test/store-dir.test.ts`.\n *\n * ## No eviction\n *\n * Same rule as {@link MemoryElisionStore}: no cap, no LRU, no `clear()`. A store that\n * can forget turns Law 3 into \"reversible, usually\". Elided text is smaller than the\n * session that produced it; if disk pressure ever forces a cap, retrieval of an evicted\n * hash must throw a distinct \"evicted\" error — never {@link UnknownHashError} — so the\n * model can tell \"we lost it\" from \"never existed\". Today there is no such error because\n * there is no such cap.\n *\n * ## Two deliberate choices around the edges\n *\n * - **The root is resolved to an absolute path at construction.** Every later path is\n * joined from that, so a `process.chdir()` after construction cannot silently\n * re-target the store — the bytes a relative-rooted store put before a chdir would\n * otherwise be unreachable after it, which reads exactly like data loss.\n * - **A failed journal append never withholds intact bytes.** `retrieve()`'s order of\n * business is: read, verify, count, return. When the *count* cannot be written (a\n * read-only journal, a full disk), the bytes are still returned — they are verified\n * and the caller asked for them; refusing would turn a bookkeeping failure into\n * Law 3 breaking. The failure is surfaced distinctly instead: a\n * `process.emitWarning` with name `SmeltCounterWriteFailure`, so \"your retrieval\n * worked\" and \"your counters just went quiet\" stay two separate facts. The same\n * applies to the `miss`/`corrupt` journal lines: the store's own error for the\n * lookup still wins over the journal's I/O error.\n */\nexport class DirectoryElisionStore implements ElisionStore {\n readonly #blobsDir: string;\n readonly #tmpDir: string;\n readonly #logPath: string;\n readonly #hash: (content: string) => string;\n\n constructor(root: string, options: DirectoryElisionStoreOptions = {}) {\n this.#hash = options.hash ?? contentHash;\n // Resolve NOW, against the working directory the caller constructed with — a\n // later chdir must never re-point an already-constructed store. See the class doc.\n const absoluteRoot = resolve(root);\n this.#blobsDir = join(absoluteRoot, 'blobs');\n this.#tmpDir = join(absoluteRoot, 'tmp');\n this.#logPath = join(absoluteRoot, 'retrievals.log');\n const markerPath = join(absoluteRoot, 'format.json');\n // Validate before mutating: a directory carrying a marker this code does not\n // understand is refused with the directory exactly as it was found — no blobs/,\n // no tmp/, no staged temp file created inside someone else's layout.\n const existing = this.#readMarker(markerPath);\n if (existing !== undefined) this.#verifyMarker(markerPath, existing);\n mkdirSync(this.#blobsDir, { recursive: true });\n mkdirSync(this.#tmpDir, { recursive: true });\n this.#claimFormat(markerPath);\n }\n\n put(content: string): string {\n const hash = this.#hash(content);\n if (!KEY_PATTERN.test(hash)) {\n throw new SmeltError(\n `smelt: hash \"${hash}\" is not usable as a storage key — it must match ` +\n `${String(KEY_PATTERN)} so it can name a file inside blobs/ and nothing else.`,\n );\n }\n const existing = this.#readBlob(hash);\n if (existing !== undefined) {\n // Verify the stored bytes before comparing: a damaged blob is corruption, not a\n // collision. Only intact bytes that still differ earn HashCollisionError.\n if (this.#hash(existing) !== hash) throw new StoreCorruptionError(hash);\n if (existing !== content) throw new HashCollisionError(hash);\n return hash;\n }\n const tmpPath = this.#writeTemp(content);\n try {\n // link(2) is the atomic, no-clobber publish: it fails with EEXIST rather than\n // overwrite, so a concurrent writer can never silently replace someone's bytes.\n linkSync(tmpPath, join(this.#blobsDir, hash));\n } catch (error) {\n if ((error as { code?: string }).code !== 'EEXIST') throw error;\n // Another writer published this hash between our existence check and our link.\n // Same bytes: idempotent put, done. Damaged or vanished bytes: corruption — the\n // store was torn or edited outside smelt. Intact different bytes: a collision.\n const winner = this.#readBlob(hash);\n if (winner === undefined || this.#hash(winner) !== hash) {\n throw new StoreCorruptionError(hash);\n }\n if (winner !== content) throw new HashCollisionError(hash);\n } finally {\n unlinkSync(tmpPath);\n }\n fsyncDirBestEffort(this.#blobsDir);\n return hash;\n }\n\n peek(hash: string): string | undefined {\n const content = this.#readBlob(hash);\n if (content === undefined) return undefined;\n if (this.#hash(content) !== hash) throw new StoreCorruptionError(hash);\n return content;\n }\n\n retrieve(hash: string): string {\n const content = this.#readBlob(hash);\n if (content === undefined) {\n this.#appendLogCounting('miss', hash);\n throw new UnknownHashError(hash);\n }\n if (this.#hash(content) !== hash) {\n this.#appendLogCounting('corrupt', hash);\n throw new StoreCorruptionError(hash);\n }\n this.#appendLogCounting('hit', hash);\n return content;\n }\n\n /**\n * Whether this hash can be **retrieved** — verified, exactly as {@link peek} and\n * {@link retrieve} verify, because it is `peek()`.\n *\n * `has()` used to be the one read that skipped verification: a damaged blob answered\n * `true` and then threw {@link StoreCorruptionError} on the very next line, so a\n * consumer that checked before retrieving was told a lie by the cheaper call. The two\n * answers now come from one place and cannot drift: `true` means the bytes are there\n * and hash to their name, `false` means this store never held them, and damage is\n * raised rather than hidden behind a boolean — the same distinction `peek()` draws\n * between \"we hold damaged bytes\" and \"never existed\".\n *\n * It stays uncounted: a check is not the model asking for material back, and counting\n * one would inflate `retrieveCalls` and with it the expansion rate, which is the one\n * number this library exists to keep honest. So no journal line is written here, not\n * even for the corrupt case — `retrieve()` journals that when the model asks.\n *\n * @throws {StoreCorruptionError} when the stored bytes do not hash to their name.\n */\n has(hash: string): boolean {\n return this.peek(hash) !== undefined;\n }\n\n /**\n * The five directly-observed counts, every one read off the disk — a scan of\n * `blobs/` plus a fold over `retrievals.log`. See {@link RawRetrieveCounters}; the\n * derived half of the stats comes from the shared `retrieveStats()`, never here.\n */\n rawCounters(): RawRetrieveCounters {\n let elisionsStored = 0;\n let bytesStored = 0;\n for (const entry of readdirSync(this.#blobsDir)) {\n if (!KEY_PATTERN.test(entry)) continue; // `.DS_Store` and friends are not blobs\n elisionsStored += 1;\n bytesStored += statSync(join(this.#blobsDir, entry)).size;\n }\n\n let retrieveCalls = 0;\n let misses = 0;\n const hits = new Set<string>();\n for (const line of this.#readLog().split('\\n')) {\n const match = LOG_LINE.exec(line);\n if (match === null) continue; // a torn tail from a crash mid-append, or blank\n retrieveCalls += 1;\n if (match[1] === 'miss') misses += 1;\n else if (match[1] === 'hit') hits.add(JSON.parse(match[2]!) as string);\n }\n\n return { elisionsStored, bytesStored, retrieveCalls, uniqueRetrieved: hits.size, misses };\n }\n\n stats(): RetrieveStats {\n return retrieveStats(this.rawCounters());\n }\n\n /** The blob's exact content, or `undefined` when no such blob is stored. */\n #readBlob(hash: string): string | undefined {\n if (!KEY_PATTERN.test(hash)) return undefined; // never a path component\n try {\n return readFileSync(join(this.#blobsDir, hash), 'utf8');\n } catch (error) {\n if ((error as { code?: string }).code === 'ENOENT') return undefined;\n throw error;\n }\n }\n\n /** Write content to a unique file in `tmp/`, fsynced, and return its path. */\n #writeTemp(content: string): string {\n const tmpPath = join(this.#tmpDir, `${String(process.pid)}-${randomBytes(8).toString('hex')}`);\n const fd = openSync(tmpPath, 'wx');\n try {\n // writeSync may write fewer bytes than asked; loop, or a short write would be\n // fsynced and published under the full content's hash as a torn blob.\n const bytes = Buffer.from(content, 'utf8');\n let written = 0;\n while (written < bytes.length) {\n written += writeSync(fd, bytes, written);\n }\n fsyncSync(fd);\n } finally {\n closeSync(fd);\n }\n return tmpPath;\n }\n\n /**\n * A journal append on the `retrieve()` path — counting, not custody. A failure here\n * must never decide whether the caller gets its verified bytes (or its true error),\n * so it is caught and surfaced as a distinct `process.emitWarning` — see the class\n * doc, and the read-only-journal case in `test/store-dir.test.ts`.\n */\n #appendLogCounting(kind: 'hit' | 'miss' | 'corrupt', hash: string): void {\n try {\n this.#appendLog(kind, hash);\n } catch (error) {\n process.emitWarning(\n `smelt: could not journal a \"${kind}\" for hash \"${hash}\" in ${this.#logPath} ` +\n `(${error instanceof Error ? error.message : String(error)}). The retrieval ` +\n `itself is unaffected, but this count is lost — retrieveCalls and ` +\n `expansionRate now UNDER-report until the journal is writable again.`,\n 'SmeltCounterWriteFailure',\n );\n }\n }\n\n /**\n * One durable journal line. The hash is JSON-encoded because `retrieve()` takes it\n * from the model verbatim — a hash containing a newline must not forge a second line.\n * The record starts with its own newline so a torn tail from an earlier crash — a\n * partial record with no trailing newline — can never bleed into this one: the tear\n * stays on its own line and is skipped by `stats()`, as blank lines are.\n */\n #appendLog(kind: 'hit' | 'miss' | 'corrupt', hash: string): void {\n const fd = openSync(this.#logPath, 'a');\n try {\n const record = Buffer.from(`\\n${kind} ${JSON.stringify(hash)}\\n`, 'utf8');\n let written = 0;\n while (written < record.length) {\n written += writeSync(fd, record, written);\n }\n fsyncSync(fd);\n } finally {\n closeSync(fd);\n }\n }\n\n #readLog(): string {\n try {\n return readFileSync(this.#logPath, 'utf8');\n } catch (error) {\n if ((error as { code?: string }).code === 'ENOENT') return '';\n throw error;\n }\n }\n\n /**\n * Write the format marker if this directory has none, or verify the one it has.\n * Creation is atomic (write to `tmp/`, then `link`), so a concurrent creator never\n * observes a half-written marker. The constructor pre-verified any pre-existing\n * marker; the verify here catches only a concurrent creator's claim.\n */\n #claimFormat(markerPath: string): void {\n const claim = (): string | undefined => {\n const body = `${JSON.stringify({\n format: DIRECTORY_STORE_FORMAT,\n version: DIRECTORY_STORE_VERSION,\n })}\\n`;\n const tmpPath = this.#writeTemp(body);\n try {\n linkSync(tmpPath, markerPath);\n return undefined; // claimed by us; nothing to verify\n } catch (error) {\n if ((error as { code?: string }).code !== 'EEXIST') throw error;\n return readFileSync(markerPath, 'utf8');\n } finally {\n unlinkSync(tmpPath);\n }\n };\n\n const existing = claim();\n if (existing === undefined) return;\n this.#verifyMarker(markerPath, existing);\n }\n\n /** The marker's body, or `undefined` when the directory carries none. */\n #readMarker(markerPath: string): string | undefined {\n try {\n return readFileSync(markerPath, 'utf8');\n } catch (error) {\n if ((error as { code?: string }).code === 'ENOENT') return undefined;\n throw error;\n }\n }\n\n /** Refuse a marker this version of smelt does not understand. */\n #verifyMarker(markerPath: string, existing: string): void {\n let parsed: { format?: unknown; version?: unknown };\n try {\n parsed = JSON.parse(existing) as { format?: unknown; version?: unknown };\n } catch {\n throw new StoreFormatError(\n `smelt: \"${markerPath}\" is not parseable JSON, so this directory cannot be ` +\n `trusted as an elision store. Refusing to read or write it.`,\n );\n }\n if (parsed.format !== DIRECTORY_STORE_FORMAT || parsed.version !== DIRECTORY_STORE_VERSION) {\n throw new StoreFormatError(\n `smelt: \"${markerPath}\" declares format ${JSON.stringify(parsed.format)} ` +\n `version ${JSON.stringify(parsed.version)}; this code understands ` +\n `\"${DIRECTORY_STORE_FORMAT}\" version ${String(DIRECTORY_STORE_VERSION)}. ` +\n `Refusing to reinterpret someone else's layout.`,\n );\n }\n }\n}\n\n/**\n * Flush the directory entry after a publish, so the *name* survives a crash as well as\n * the bytes. Where the platform refuses to fsync a directory (Windows does), the publish\n * is still atomic — only the durability of the directory entry falls back to the OS's\n * own schedule. Only that refusal is swallowed: a real I/O failure (`EIO`) propagates,\n * because \"the disk could not flush\" must never be reported as a successful put.\n *\n * Where it does work it is the same `fsyncSync` the blob's own flush uses, and so is\n * exactly as strong as that — see the durability note on {@link DirectoryElisionStore}\n * for what that means per platform.\n */\nfunction fsyncDirBestEffort(path: string): void {\n let fd: number;\n try {\n fd = openSync(path, 'r');\n } catch {\n return; // the platform refuses to even open a directory for reading (Windows)\n }\n try {\n fsyncSync(fd);\n } catch (error) {\n const code = (error as { code?: string }).code;\n // EINVAL/ENOTSUP/EPERM/EBADF: the platform refuses to fsync a directory — see the\n // doc comment. Anything else (EIO above all) is a genuine write failure.\n if (code !== 'EINVAL' && code !== 'ENOTSUP' && code !== 'EPERM' && code !== 'EBADF') {\n throw error;\n }\n } finally {\n closeSync(fd);\n }\n}\n"]}
package/dist/store.d.ts CHANGED
@@ -28,6 +28,12 @@ export declare class MemoryElisionStore implements ElisionStore {
28
28
  put(content: string): string;
29
29
  peek(hash: string): string | undefined;
30
30
  retrieve(hash: string): string;
31
+ /**
32
+ * True exactly when `retrieve(hash)` would return bytes. Nothing to verify: `put`
33
+ * hashed the content itself and no one else can reach the map, so a key here cannot
34
+ * name bytes that stopped matching it — unlike a directory on someone's disk, where
35
+ * {@link DirectoryElisionStore.has} re-hashes for this same promise.
36
+ */
31
37
  has(hash: string): boolean;
32
38
  /** The five directly-observed counts. See {@link RawRetrieveCounters} — no derivation here. */
33
39
  rawCounters(): RawRetrieveCounters;
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE9D;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CAC7C;AAED,qBAAa,kBAAmB,YAAW,YAAY;;IAQrD,YAAY,OAAO,GAAE,yBAA8B,EAElD;IAED,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAU3B;IAED,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAErC;IAED,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAS7B;IAED,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzB;IAED,+FAA+F;IAC/F,WAAW,IAAI,mBAAmB,CAQjC;IAED,KAAK,IAAI,aAAa,CAErB;CACF"}
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE9D;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CAC7C;AAED,qBAAa,kBAAmB,YAAW,YAAY;;IAQrD,YAAY,OAAO,GAAE,yBAA8B,EAElD;IAED,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAU3B;IAED,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAErC;IAED,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAS7B;IAED;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzB;IAED,+FAA+F;IAC/F,WAAW,IAAI,mBAAmB,CAQjC;IAED,KAAK,IAAI,aAAa,CAErB;CACF","sourcesContent":["import { HashCollisionError, UnknownHashError } from './errors.ts';\nimport { contentHash } from './hash.ts';\nimport { retrieveStats } from './stats.ts';\nimport type { RawRetrieveCounters } from './stats.ts';\nimport type { ElisionStore, RetrieveStats } from './types.ts';\n\n/**\n * The default store: in-process, content-addressed, no eviction.\n *\n * In-process is the right default because it is the only one with no failure modes to\n * explain. A consumer that needs elisions to survive a process restart (a long-lived\n * agent session, say) hands `createSmelter()` a {@link DirectoryElisionStore} — or\n * implements {@link ElisionStore} over storage of its own; the interface is five\n * methods wide for exactly that reason.\n *\n * There is no `clear()` and no LRU. A store that can forget turns Law 3 into\n * \"reversible, usually\", and a `retrieve()` that fails after an eviction is\n * indistinguishable to the model from a hallucinated hash.\n */\nexport interface MemoryElisionStoreOptions {\n /**\n * Override the hash function. The only reason this exists: the collision branch in\n * {@link MemoryElisionStore.put} is unreachable with sha256, and an untestable branch\n * is a branch nobody knows works. A test injects a colliding hash and watches it\n * throw. Production has no reason to pass this.\n */\n readonly hash?: (content: string) => string;\n}\n\nexport class MemoryElisionStore implements ElisionStore {\n readonly #blobs = new Map<string, string>();\n readonly #hash: (content: string) => string;\n #bytesStored = 0;\n #retrieveCalls = 0;\n #misses = 0;\n readonly #retrievedHashes = new Set<string>();\n\n constructor(options: MemoryElisionStoreOptions = {}) {\n this.#hash = options.hash ?? contentHash;\n }\n\n put(content: string): string {\n const hash = this.#hash(content);\n const existing = this.#blobs.get(hash);\n if (existing !== undefined) {\n if (existing !== content) throw new HashCollisionError(hash);\n return hash;\n }\n this.#blobs.set(hash, content);\n this.#bytesStored += Buffer.byteLength(content, 'utf8');\n return hash;\n }\n\n peek(hash: string): string | undefined {\n return this.#blobs.get(hash);\n }\n\n retrieve(hash: string): string {\n this.#retrieveCalls += 1;\n const content = this.#blobs.get(hash);\n if (content === undefined) {\n this.#misses += 1;\n throw new UnknownHashError(hash);\n }\n this.#retrievedHashes.add(hash);\n return content;\n }\n\n /**\n * True exactly when `retrieve(hash)` would return bytes. Nothing to verify: `put`\n * hashed the content itself and no one else can reach the map, so a key here cannot\n * name bytes that stopped matching it — unlike a directory on someone's disk, where\n * {@link DirectoryElisionStore.has} re-hashes for this same promise.\n */\n has(hash: string): boolean {\n return this.#blobs.has(hash);\n }\n\n /** The five directly-observed counts. See {@link RawRetrieveCounters} — no derivation here. */\n rawCounters(): RawRetrieveCounters {\n return {\n elisionsStored: this.#blobs.size,\n bytesStored: this.#bytesStored,\n retrieveCalls: this.#retrieveCalls,\n uniqueRetrieved: this.#retrievedHashes.size,\n misses: this.#misses,\n };\n }\n\n stats(): RetrieveStats {\n return retrieveStats(this.rawCounters());\n }\n}\n"]}
package/dist/store.js CHANGED
@@ -36,6 +36,12 @@ export class MemoryElisionStore {
36
36
  this.#retrievedHashes.add(hash);
37
37
  return content;
38
38
  }
39
+ /**
40
+ * True exactly when `retrieve(hash)` would return bytes. Nothing to verify: `put`
41
+ * hashed the content itself and no one else can reach the map, so a key here cannot
42
+ * name bytes that stopped matching it — unlike a directory on someone's disk, where
43
+ * {@link DirectoryElisionStore.has} re-hashes for this same promise.
44
+ */
39
45
  has(hash) {
40
46
  return this.#blobs.has(hash);
41
47
  }
package/dist/store.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AA2B3C,MAAM,OAAO,kBAAkB;IACpB,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACnC,KAAK,CAA8B;IAC5C,YAAY,GAAG,CAAC,CAAC;IACjB,cAAc,GAAG,CAAC,CAAC;IACnB,OAAO,GAAG,CAAC,CAAC;IACH,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;IAE9C,YAAY,OAAO,GAA8B,EAAE;QACjD,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,IAAI,WAAW,CAAC;IAC3C,CAAC;IAED,GAAG,CAAC,OAAe;QACjB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,QAAQ,KAAK,SA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IAED,QAAQ,CAAC,IAAY;QACnB,IAAI,CAAC,cAAc,IAAI,CAAC,CAAC;QACzB,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;YAClB,MAAM,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACnC,CAAC;QACD,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,+FAA+F;IAC/F,WAAW;QACT,OAAO;YACL,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;YAChC,WAAW,EAAE,IAAI,CAAC,YAAY;YAC9B,aAAa,EAAE,IAAI,CAAC,cAAc;YAClC,eAAe,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI;YAC3C,MAAM,EAAE,IAAI,CAAC,OAAO;SACrB,CAAC;IACJ,CAAC;IAED,KAAK;QACH,OAAO,aAAa,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF","sourcesContent":["import { HashCollisionError, UnknownHashError } from './errors.ts';\nimport { contentHash } from './hash.ts';\nimport { retrieveStats } from './stats.ts';\nimport type { RawRetrieveCounters } from './stats.ts';\nimport type { ElisionStore, RetrieveStats } from './types.ts';\n\n/**\n * The default store: in-process, content-addressed, no eviction.\n *\n * In-process is the right default because it is the only one with no failure modes to\n * explain. A consumer that needs elisions to survive a process restart (a long-lived\n * agent session, say) hands `createSmelter()` a {@link DirectoryElisionStore} — or\n * implements {@link ElisionStore} over storage of its own; the interface is five\n * methods wide for exactly that reason.\n *\n * There is no `clear()` and no LRU. A store that can forget turns Law 3 into\n * \"reversible, usually\", and a `retrieve()` that fails after an eviction is\n * indistinguishable to the model from a hallucinated hash.\n */\nexport interface MemoryElisionStoreOptions {\n /**\n * Override the hash function. The only reason this exists: the collision branch in\n * {@link MemoryElisionStore.put} is unreachable with sha256, and an untestable branch\n * is a branch nobody knows works. A test injects a colliding hash and watches it\n * throw. Production has no reason to pass this.\n */\n readonly hash?: (content: string) => string;\n}\n\nexport class MemoryElisionStore implements ElisionStore {\n readonly #blobs = new Map<string, string>();\n readonly #hash: (content: string) => string;\n #bytesStored = 0;\n #retrieveCalls = 0;\n #misses = 0;\n readonly #retrievedHashes = new Set<string>();\n\n constructor(options: MemoryElisionStoreOptions = {}) {\n this.#hash = options.hash ?? contentHash;\n }\n\n put(content: string): string {\n const hash = this.#hash(content);\n const existing = this.#blobs.get(hash);\n if (existing !== undefined) {\n if (existing !== content) throw new HashCollisionError(hash);\n return hash;\n }\n this.#blobs.set(hash, content);\n this.#bytesStored += Buffer.byteLength(content, 'utf8');\n return hash;\n }\n\n peek(hash: string): string | undefined {\n return this.#blobs.get(hash);\n }\n\n retrieve(hash: string): string {\n this.#retrieveCalls += 1;\n const content = this.#blobs.get(hash);\n if (content === undefined) {\n this.#misses += 1;\n throw new UnknownHashError(hash);\n }\n this.#retrievedHashes.add(hash);\n return content;\n }\n\n /**\n * True exactly when `retrieve(hash)` would return bytes. Nothing to verify: `put`\n * hashed the content itself and no one else can reach the map, so a key here cannot\n * name bytes that stopped matching it — unlike a directory on someone's disk, where\n * {@link DirectoryElisionStore.has} re-hashes for this same promise.\n */\n has(hash: string): boolean {\n return this.#blobs.has(hash);\n }\n\n /** The five directly-observed counts. See {@link RawRetrieveCounters} — no derivation here. */\n rawCounters(): RawRetrieveCounters {\n return {\n elisionsStored: this.#blobs.size,\n bytesStored: this.#bytesStored,\n retrieveCalls: this.#retrieveCalls,\n uniqueRetrieved: this.#retrievedHashes.size,\n misses: this.#misses,\n };\n }\n\n stats(): RetrieveStats {\n return retrieveStats(this.rawCounters());\n }\n}\n"]}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Byte-faithful edits to somebody else's text file.
3
+ *
4
+ * Two editors, one contract: **change the one thing you were asked to change and
5
+ * leave every other byte alone.** An installer that reformats a settings file has
6
+ * edited what it was never asked to — key order, indentation, string escapes, number
7
+ * spellings and unknown keys are all somebody's choices, and `JSON.parse` →
8
+ * `JSON.stringify` erases every one of them.
9
+ *
10
+ * - {@link editTopLevelProperty}: replace, insert or remove **one top-level property**
11
+ * of a JSON object, in its source text. The value is rendered fresh; nothing
12
+ * outside its bytes moves. Callers have already `JSON.parse`d the text and decided
13
+ * what the new value is; this module holds only the tokenising.
14
+ * - {@link upsertMarkerBlock} / {@link stripMarkerBlock}: the same idea over a
15
+ * delimited block in a plain-text file (an instruction file, a Markdown snippet
16
+ * between two marker lines).
17
+ *
18
+ * Neither knows what a harness or a hook is. `cli/hooks.ts` is the consumer today; the
19
+ * module lives under `src/text/` rather than `cli/` because its whole interface is
20
+ * strings in, strings out — it reads no argv, prints nothing and imports nothing from
21
+ * the CLI, and the next byte-faithful editor (an instruction-file rewrite) wants a
22
+ * sibling here, not a CLI import.
23
+ */
24
+ /** How a JSON file is laid out — what a rendered value must match to blend in. */
25
+ export interface JsonStyle {
26
+ /** The indentation unit — the whitespace before a top-level key. */
27
+ readonly indent: string;
28
+ /** `'\r\n'` when the file uses it anywhere, `'\n'` otherwise. */
29
+ readonly newline: string;
30
+ }
31
+ /**
32
+ * The layout an existing file uses: its first indented key's leading whitespace (two
33
+ * spaces when nothing is indented) and its newline convention. Detected once, before
34
+ * any edit, so a sequence of edits renders consistently even after an earlier one has
35
+ * changed the first indented line.
36
+ */
37
+ export declare function jsonStyle(text: string): JsonStyle;
38
+ /**
39
+ * Replace, insert or remove one top-level property of the JSON object in `text`,
40
+ * leaving every other byte verbatim.
41
+ *
42
+ * - `value` defined: the property's value is replaced in place when the key exists,
43
+ * otherwise the property is appended after the last one (or into an empty object).
44
+ * - `value === undefined`: the property is removed, with its separating comma and
45
+ * whitespace; a key that is not there is a no-op and the text comes back unchanged.
46
+ *
47
+ * The rendered value is `JSON.stringify(value, null, indent)`, re-indented to sit at
48
+ * top level. `style` defaults to {@link jsonStyle} of `text`; pass it explicitly when
49
+ * making several edits to one file.
50
+ *
51
+ * Returns `undefined` when `text` is not a JSON object the scanner can walk — an
52
+ * array, a scalar, or something that is not JSON at all. Callers should have
53
+ * `JSON.parse`d first and refused; this is belt and braces, not a validator.
54
+ */
55
+ export declare function editTopLevelProperty(text: string, key: string, value: unknown, style?: JsonStyle): string | undefined;
56
+ /**
57
+ * Replace the block delimited by `start` … `end` in `existingText`, or append it.
58
+ *
59
+ * An absent or blank file becomes exactly `block`. A file that carries the block has
60
+ * it replaced in place (one newline after `end` is absorbed, so a block that ends in
61
+ * its own newline does not grow a blank line per re-run). A file without it gets the
62
+ * block appended after exactly one blank line, whatever trailing newlines it had.
63
+ */
64
+ export declare function upsertMarkerBlock(existingText: string | undefined, block: string, start: string, end: string): string;
65
+ /**
66
+ * Remove the block delimited by `start` … `end`. The text comes back unchanged when
67
+ * the block is not there; `undefined` when nothing (or only whitespace) remains — the
68
+ * file was entirely the block, and the caller decides whether to delete it.
69
+ */
70
+ export declare function stripMarkerBlock(existingText: string, start: string, end: string): string | undefined;
71
+ //# sourceMappingURL=json-edit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-edit.d.ts","sourceRoot":"","sources":["../../src/text/json-edit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,kFAAkF;AAClF,MAAM,WAAW,SAAS;IACxB,oEAAoE;IACpE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAKjD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,EACd,KAAK,GAAE,SAA2B,GACjC,MAAM,GAAG,SAAS,CAWpB;AA+ID;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,GACV,MAAM,CAUR;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,GACV,MAAM,GAAG,SAAS,CAQpB","sourcesContent":["/**\n * Byte-faithful edits to somebody else's text file.\n *\n * Two editors, one contract: **change the one thing you were asked to change and\n * leave every other byte alone.** An installer that reformats a settings file has\n * edited what it was never asked to — key order, indentation, string escapes, number\n * spellings and unknown keys are all somebody's choices, and `JSON.parse` →\n * `JSON.stringify` erases every one of them.\n *\n * - {@link editTopLevelProperty}: replace, insert or remove **one top-level property**\n * of a JSON object, in its source text. The value is rendered fresh; nothing\n * outside its bytes moves. Callers have already `JSON.parse`d the text and decided\n * what the new value is; this module holds only the tokenising.\n * - {@link upsertMarkerBlock} / {@link stripMarkerBlock}: the same idea over a\n * delimited block in a plain-text file (an instruction file, a Markdown snippet\n * between two marker lines).\n *\n * Neither knows what a harness or a hook is. `cli/hooks.ts` is the consumer today; the\n * module lives under `src/text/` rather than `cli/` because its whole interface is\n * strings in, strings out — it reads no argv, prints nothing and imports nothing from\n * the CLI, and the next byte-faithful editor (an instruction-file rewrite) wants a\n * sibling here, not a CLI import.\n */\n\n/** How a JSON file is laid out — what a rendered value must match to blend in. */\nexport interface JsonStyle {\n /** The indentation unit — the whitespace before a top-level key. */\n readonly indent: string;\n /** `'\\r\\n'` when the file uses it anywhere, `'\\n'` otherwise. */\n readonly newline: string;\n}\n\n/**\n * The layout an existing file uses: its first indented key's leading whitespace (two\n * spaces when nothing is indented) and its newline convention. Detected once, before\n * any edit, so a sequence of edits renders consistently even after an earlier one has\n * changed the first indented line.\n */\nexport function jsonStyle(text: string): JsonStyle {\n return {\n newline: text.includes('\\r\\n') ? '\\r\\n' : '\\n',\n indent: /\\n([ \\t]+)\"/.exec(text)?.[1] ?? ' ',\n };\n}\n\n/**\n * Replace, insert or remove one top-level property of the JSON object in `text`,\n * leaving every other byte verbatim.\n *\n * - `value` defined: the property's value is replaced in place when the key exists,\n * otherwise the property is appended after the last one (or into an empty object).\n * - `value === undefined`: the property is removed, with its separating comma and\n * whitespace; a key that is not there is a no-op and the text comes back unchanged.\n *\n * The rendered value is `JSON.stringify(value, null, indent)`, re-indented to sit at\n * top level. `style` defaults to {@link jsonStyle} of `text`; pass it explicitly when\n * making several edits to one file.\n *\n * Returns `undefined` when `text` is not a JSON object the scanner can walk — an\n * array, a scalar, or something that is not JSON at all. Callers should have\n * `JSON.parse`d first and refused; this is belt and braces, not a validator.\n */\nexport function editTopLevelProperty(\n text: string,\n key: string,\n value: unknown,\n style: JsonStyle = jsonStyle(text),\n): string | undefined {\n const scan = scanJsonTopLevel(text);\n if (scan === undefined) return undefined;\n const property = scan.properties.find((candidate) => candidate.key === key);\n if (value === undefined) {\n return property === undefined ? text : removeJsonProperty(text, scan, property);\n }\n const rendered = renderJsonValue(value, style.indent, style.newline);\n return property !== undefined\n ? `${text.slice(0, property.valueStart)}${rendered}${text.slice(property.valueEnd)}`\n : insertJsonProperty(text, scan, key, rendered, style.indent, style.newline);\n}\n\n/** One top-level property of a JSON object, located by offsets in its source text. */\ninterface JsonTopLevelProperty {\n readonly key: string;\n /** Offset of the key's opening quote. */\n readonly keyStart: number;\n /** Offset of the value's first byte. */\n readonly valueStart: number;\n /** Offset one past the value's last byte. */\n readonly valueEnd: number;\n}\n\ninterface JsonTopLevelScan {\n /** Offset of the root object's `{`. */\n readonly open: number;\n /** Offset of the root object's `}`. */\n readonly close: number;\n readonly properties: readonly JsonTopLevelProperty[];\n}\n\n/**\n * Locate the top-level properties of a JSON object *in its source text*, so one\n * property can be replaced, inserted or removed while every other byte of the file\n * rides through verbatim. `undefined` when the text is not an object.\n */\nfunction scanJsonTopLevel(text: string): JsonTopLevelScan | undefined {\n let i = skipJsonWhitespace(text, 0);\n if (text[i] !== '{') return undefined;\n const open = i;\n i = skipJsonWhitespace(text, i + 1);\n const properties: JsonTopLevelProperty[] = [];\n if (text[i] === '}') return { open, close: i, properties };\n for (;;) {\n if (text[i] !== '\"') return undefined;\n const keyStart = i;\n const keyEnd = skipJsonString(text, i);\n if (keyEnd === undefined) return undefined;\n const key = JSON.parse(text.slice(keyStart, keyEnd)) as string;\n i = skipJsonWhitespace(text, keyEnd);\n if (text[i] !== ':') return undefined;\n const valueStart = skipJsonWhitespace(text, i + 1);\n const valueEnd = skipJsonValue(text, valueStart);\n if (valueEnd === undefined) return undefined;\n properties.push({ key, keyStart, valueStart, valueEnd });\n i = skipJsonWhitespace(text, valueEnd);\n if (text[i] === ',') {\n i = skipJsonWhitespace(text, i + 1);\n continue;\n }\n if (text[i] === '}') return { open, close: i, properties };\n return undefined;\n }\n}\n\nfunction skipJsonWhitespace(text: string, from: number): number {\n let i = from;\n while (i < text.length && ' \\t\\r\\n'.includes(text[i]!)) i += 1;\n return i;\n}\n\n/** `from` points at `\"`; returns the offset one past the closing quote. */\nfunction skipJsonString(text: string, from: number): number | undefined {\n let i = from + 1;\n while (i < text.length) {\n if (text[i] === '\\\\') i += 2;\n else if (text[i] === '\"') return i + 1;\n else i += 1;\n }\n return undefined;\n}\n\nfunction skipJsonValue(text: string, from: number): number | undefined {\n const first = text[from];\n if (first === '\"') return skipJsonString(text, from);\n if (first === '{' || first === '[') {\n let depth = 0;\n let i = from;\n while (i < text.length) {\n const ch = text[i]!;\n if (ch === '\"') {\n const end = skipJsonString(text, i);\n if (end === undefined) return undefined;\n i = end;\n continue;\n }\n if (ch === '{' || ch === '[') depth += 1;\n else if (ch === '}' || ch === ']') {\n depth -= 1;\n if (depth === 0) return i + 1;\n }\n i += 1;\n }\n return undefined;\n }\n // number / true / false / null\n let i = from;\n while (i < text.length && !',}] \\t\\r\\n'.includes(text[i]!)) i += 1;\n return i > from ? i : undefined;\n}\n\n/** A JSON value indented for embedding at a top-level property position. */\nfunction renderJsonValue(value: unknown, indent: string, newline: string): string {\n return JSON.stringify(value, null, indent).split('\\n').join(`${newline}${indent}`);\n}\n\nfunction removeJsonProperty(\n text: string,\n scan: JsonTopLevelScan,\n property: JsonTopLevelProperty,\n): string {\n const index = scan.properties.indexOf(property);\n const next = scan.properties[index + 1];\n if (next !== undefined) {\n // Delete through the separating comma and whitespace, up to the next key.\n return text.slice(0, property.keyStart) + text.slice(next.keyStart);\n }\n const previous = scan.properties[index - 1];\n // Last (or only) property: delete the preceding comma (if any) with it.\n const from = previous !== undefined ? previous.valueEnd : scan.open + 1;\n return text.slice(0, from) + text.slice(property.valueEnd);\n}\n\nfunction insertJsonProperty(\n text: string,\n scan: JsonTopLevelScan,\n key: string,\n renderedValue: string,\n indent: string,\n newline: string,\n): string {\n const entry = `${JSON.stringify(key)}: ${renderedValue}`;\n if (scan.properties.length === 0) {\n return `${text.slice(0, scan.open + 1)}${newline}${indent}${entry}${newline}${text.slice(scan.close)}`;\n }\n const last = scan.properties[scan.properties.length - 1]!;\n return `${text.slice(0, last.valueEnd)},${newline}${indent}${entry}${text.slice(last.valueEnd)}`;\n}\n\n/* ------------------------------------------------------------------------------------\n * Marker blocks\n * ---------------------------------------------------------------------------------- */\n\n/**\n * Replace the block delimited by `start` … `end` in `existingText`, or append it.\n *\n * An absent or blank file becomes exactly `block`. A file that carries the block has\n * it replaced in place (one newline after `end` is absorbed, so a block that ends in\n * its own newline does not grow a blank line per re-run). A file without it gets the\n * block appended after exactly one blank line, whatever trailing newlines it had.\n */\nexport function upsertMarkerBlock(\n existingText: string | undefined,\n block: string,\n start: string,\n end: string,\n): string {\n if (existingText === undefined || existingText.trim() === '') return block;\n const startIndex = existingText.indexOf(start);\n const endIndex = existingText.indexOf(end);\n if (startIndex !== -1 && endIndex !== -1 && endIndex > startIndex) {\n const before = existingText.slice(0, startIndex);\n const after = existingText.slice(endIndex + end.length).replace(/^\\n/, '');\n return `${before}${block}${after}`;\n }\n return `${existingText.replace(/\\n*$/, '\\n\\n')}${block}`;\n}\n\n/**\n * Remove the block delimited by `start` … `end`. The text comes back unchanged when\n * the block is not there; `undefined` when nothing (or only whitespace) remains — the\n * file was entirely the block, and the caller decides whether to delete it.\n */\nexport function stripMarkerBlock(\n existingText: string,\n start: string,\n end: string,\n): string | undefined {\n const startIndex = existingText.indexOf(start);\n const endIndex = existingText.indexOf(end);\n if (startIndex === -1 || endIndex === -1 || endIndex <= startIndex) return existingText;\n const stripped =\n existingText.slice(0, startIndex).replace(/\\n+$/, '\\n') +\n existingText.slice(endIndex + end.length).replace(/^\\n+/, '');\n return stripped.trim() === '' ? undefined : stripped;\n}\n"]}
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Byte-faithful edits to somebody else's text file.
3
+ *
4
+ * Two editors, one contract: **change the one thing you were asked to change and
5
+ * leave every other byte alone.** An installer that reformats a settings file has
6
+ * edited what it was never asked to — key order, indentation, string escapes, number
7
+ * spellings and unknown keys are all somebody's choices, and `JSON.parse` →
8
+ * `JSON.stringify` erases every one of them.
9
+ *
10
+ * - {@link editTopLevelProperty}: replace, insert or remove **one top-level property**
11
+ * of a JSON object, in its source text. The value is rendered fresh; nothing
12
+ * outside its bytes moves. Callers have already `JSON.parse`d the text and decided
13
+ * what the new value is; this module holds only the tokenising.
14
+ * - {@link upsertMarkerBlock} / {@link stripMarkerBlock}: the same idea over a
15
+ * delimited block in a plain-text file (an instruction file, a Markdown snippet
16
+ * between two marker lines).
17
+ *
18
+ * Neither knows what a harness or a hook is. `cli/hooks.ts` is the consumer today; the
19
+ * module lives under `src/text/` rather than `cli/` because its whole interface is
20
+ * strings in, strings out — it reads no argv, prints nothing and imports nothing from
21
+ * the CLI, and the next byte-faithful editor (an instruction-file rewrite) wants a
22
+ * sibling here, not a CLI import.
23
+ */
24
+ /**
25
+ * The layout an existing file uses: its first indented key's leading whitespace (two
26
+ * spaces when nothing is indented) and its newline convention. Detected once, before
27
+ * any edit, so a sequence of edits renders consistently even after an earlier one has
28
+ * changed the first indented line.
29
+ */
30
+ export function jsonStyle(text) {
31
+ return {
32
+ newline: text.includes('\r\n') ? '\r\n' : '\n',
33
+ indent: /\n([ \t]+)"/.exec(text)?.[1] ?? ' ',
34
+ };
35
+ }
36
+ /**
37
+ * Replace, insert or remove one top-level property of the JSON object in `text`,
38
+ * leaving every other byte verbatim.
39
+ *
40
+ * - `value` defined: the property's value is replaced in place when the key exists,
41
+ * otherwise the property is appended after the last one (or into an empty object).
42
+ * - `value === undefined`: the property is removed, with its separating comma and
43
+ * whitespace; a key that is not there is a no-op and the text comes back unchanged.
44
+ *
45
+ * The rendered value is `JSON.stringify(value, null, indent)`, re-indented to sit at
46
+ * top level. `style` defaults to {@link jsonStyle} of `text`; pass it explicitly when
47
+ * making several edits to one file.
48
+ *
49
+ * Returns `undefined` when `text` is not a JSON object the scanner can walk — an
50
+ * array, a scalar, or something that is not JSON at all. Callers should have
51
+ * `JSON.parse`d first and refused; this is belt and braces, not a validator.
52
+ */
53
+ export function editTopLevelProperty(text, key, value, style = jsonStyle(text)) {
54
+ const scan = scanJsonTopLevel(text);
55
+ if (scan === undefined)
56
+ return undefined;
57
+ const property = scan.properties.find((candidate) => candidate.key === key);
58
+ if (value === undefined) {
59
+ return property === undefined ? text : removeJsonProperty(text, scan, property);
60
+ }
61
+ const rendered = renderJsonValue(value, style.indent, style.newline);
62
+ return property !== undefined
63
+ ? `${text.slice(0, property.valueStart)}${rendered}${text.slice(property.valueEnd)}`
64
+ : insertJsonProperty(text, scan, key, rendered, style.indent, style.newline);
65
+ }
66
+ /**
67
+ * Locate the top-level properties of a JSON object *in its source text*, so one
68
+ * property can be replaced, inserted or removed while every other byte of the file
69
+ * rides through verbatim. `undefined` when the text is not an object.
70
+ */
71
+ function scanJsonTopLevel(text) {
72
+ let i = skipJsonWhitespace(text, 0);
73
+ if (text[i] !== '{')
74
+ return undefined;
75
+ const open = i;
76
+ i = skipJsonWhitespace(text, i + 1);
77
+ const properties = [];
78
+ if (text[i] === '}')
79
+ return { open, close: i, properties };
80
+ for (;;) {
81
+ if (text[i] !== '"')
82
+ return undefined;
83
+ const keyStart = i;
84
+ const keyEnd = skipJsonString(text, i);
85
+ if (keyEnd === undefined)
86
+ return undefined;
87
+ const key = JSON.parse(text.slice(keyStart, keyEnd));
88
+ i = skipJsonWhitespace(text, keyEnd);
89
+ if (text[i] !== ':')
90
+ return undefined;
91
+ const valueStart = skipJsonWhitespace(text, i + 1);
92
+ const valueEnd = skipJsonValue(text, valueStart);
93
+ if (valueEnd === undefined)
94
+ return undefined;
95
+ properties.push({ key, keyStart, valueStart, valueEnd });
96
+ i = skipJsonWhitespace(text, valueEnd);
97
+ if (text[i] === ',') {
98
+ i = skipJsonWhitespace(text, i + 1);
99
+ continue;
100
+ }
101
+ if (text[i] === '}')
102
+ return { open, close: i, properties };
103
+ return undefined;
104
+ }
105
+ }
106
+ function skipJsonWhitespace(text, from) {
107
+ let i = from;
108
+ while (i < text.length && ' \t\r\n'.includes(text[i]))
109
+ i += 1;
110
+ return i;
111
+ }
112
+ /** `from` points at `"`; returns the offset one past the closing quote. */
113
+ function skipJsonString(text, from) {
114
+ let i = from + 1;
115
+ while (i < text.length) {
116
+ if (text[i] === '\\')
117
+ i += 2;
118
+ else if (text[i] === '"')
119
+ return i + 1;
120
+ else
121
+ i += 1;
122
+ }
123
+ return undefined;
124
+ }
125
+ function skipJsonValue(text, from) {
126
+ const first = text[from];
127
+ if (first === '"')
128
+ return skipJsonString(text, from);
129
+ if (first === '{' || first === '[') {
130
+ let depth = 0;
131
+ let i = from;
132
+ while (i < text.length) {
133
+ const ch = text[i];
134
+ if (ch === '"') {
135
+ const end = skipJsonString(text, i);
136
+ if (end === undefined)
137
+ return undefined;
138
+ i = end;
139
+ continue;
140
+ }
141
+ if (ch === '{' || ch === '[')
142
+ depth += 1;
143
+ else if (ch === '}' || ch === ']') {
144
+ depth -= 1;
145
+ if (depth === 0)
146
+ return i + 1;
147
+ }
148
+ i += 1;
149
+ }
150
+ return undefined;
151
+ }
152
+ // number / true / false / null
153
+ let i = from;
154
+ while (i < text.length && !',}] \t\r\n'.includes(text[i]))
155
+ i += 1;
156
+ return i > from ? i : undefined;
157
+ }
158
+ /** A JSON value indented for embedding at a top-level property position. */
159
+ function renderJsonValue(value, indent, newline) {
160
+ return JSON.stringify(value, null, indent).split('\n').join(`${newline}${indent}`);
161
+ }
162
+ function removeJsonProperty(text, scan, property) {
163
+ const index = scan.properties.indexOf(property);
164
+ const next = scan.properties[index + 1];
165
+ if (next !== undefined) {
166
+ // Delete through the separating comma and whitespace, up to the next key.
167
+ return text.slice(0, property.keyStart) + text.slice(next.keyStart);
168
+ }
169
+ const previous = scan.properties[index - 1];
170
+ // Last (or only) property: delete the preceding comma (if any) with it.
171
+ const from = previous !== undefined ? previous.valueEnd : scan.open + 1;
172
+ return text.slice(0, from) + text.slice(property.valueEnd);
173
+ }
174
+ function insertJsonProperty(text, scan, key, renderedValue, indent, newline) {
175
+ const entry = `${JSON.stringify(key)}: ${renderedValue}`;
176
+ if (scan.properties.length === 0) {
177
+ return `${text.slice(0, scan.open + 1)}${newline}${indent}${entry}${newline}${text.slice(scan.close)}`;
178
+ }
179
+ const last = scan.properties[scan.properties.length - 1];
180
+ return `${text.slice(0, last.valueEnd)},${newline}${indent}${entry}${text.slice(last.valueEnd)}`;
181
+ }
182
+ /* ------------------------------------------------------------------------------------
183
+ * Marker blocks
184
+ * ---------------------------------------------------------------------------------- */
185
+ /**
186
+ * Replace the block delimited by `start` … `end` in `existingText`, or append it.
187
+ *
188
+ * An absent or blank file becomes exactly `block`. A file that carries the block has
189
+ * it replaced in place (one newline after `end` is absorbed, so a block that ends in
190
+ * its own newline does not grow a blank line per re-run). A file without it gets the
191
+ * block appended after exactly one blank line, whatever trailing newlines it had.
192
+ */
193
+ export function upsertMarkerBlock(existingText, block, start, end) {
194
+ if (existingText === undefined || existingText.trim() === '')
195
+ return block;
196
+ const startIndex = existingText.indexOf(start);
197
+ const endIndex = existingText.indexOf(end);
198
+ if (startIndex !== -1 && endIndex !== -1 && endIndex > startIndex) {
199
+ const before = existingText.slice(0, startIndex);
200
+ const after = existingText.slice(endIndex + end.length).replace(/^\n/, '');
201
+ return `${before}${block}${after}`;
202
+ }
203
+ return `${existingText.replace(/\n*$/, '\n\n')}${block}`;
204
+ }
205
+ /**
206
+ * Remove the block delimited by `start` … `end`. The text comes back unchanged when
207
+ * the block is not there; `undefined` when nothing (or only whitespace) remains — the
208
+ * file was entirely the block, and the caller decides whether to delete it.
209
+ */
210
+ export function stripMarkerBlock(existingText, start, end) {
211
+ const startIndex = existingText.indexOf(start);
212
+ const endIndex = existingText.indexOf(end);
213
+ if (startIndex === -1 || endIndex === -1 || endIndex <= startIndex)
214
+ return existingText;
215
+ const stripped = existingText.slice(0, startIndex).replace(/\n+$/, '\n') +
216
+ existingText.slice(endIndex + end.length).replace(/^\n+/, '');
217
+ return stripped.trim() === '' ? undefined : stripped;
218
+ }
219
+ //# sourceMappingURL=json-edit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-edit.js","sourceRoot":"","sources":["../../src/text/json-edit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAUH;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI;QAC9C,MAAM,EAAE,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI;KAC9C,CAAC;AACJ,CAAC;AAED;;;;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C3C,IAAI,UAAU,KAAK,CAAC,CAAC,IAAI,QAAQ,KAAK,CAAC,CAAC,IAAI,QAAQ,IAAI,UAAU;QAAE,OAAO,YAAY,CAAC;IACxF,MAAM,QAAQ,GACZ,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC;QACvD,YAAY,CAAC,KAAK,CAAC,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAChE,OAAO,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC;AACvD,CAAC","sourcesContent":["/**\n * Byte-faithful edits to somebody else's text file.\n *\n * Two editors, one contract: **change the one thing you were asked to change and\n * leave every other byte alone.** An installer that reformats a settings file has\n * edited what it was never asked to — key order, indentation, string escapes, number\n * spellings and unknown keys are all somebody's choices, and `JSON.parse` →\n * `JSON.stringify` erases every one of them.\n *\n * - {@link editTopLevelProperty}: replace, insert or remove **one top-level property**\n * of a JSON object, in its source text. The value is rendered fresh; nothing\n * outside its bytes moves. Callers have already `JSON.parse`d the text and decided\n * what the new value is; this module holds only the tokenising.\n * - {@link upsertMarkerBlock} / {@link stripMarkerBlock}: the same idea over a\n * delimited block in a plain-text file (an instruction file, a Markdown snippet\n * between two marker lines).\n *\n * Neither knows what a harness or a hook is. `cli/hooks.ts` is the consumer today; the\n * module lives under `src/text/` rather than `cli/` because its whole interface is\n * strings in, strings out — it reads no argv, prints nothing and imports nothing from\n * the CLI, and the next byte-faithful editor (an instruction-file rewrite) wants a\n * sibling here, not a CLI import.\n */\n\n/** How a JSON file is laid out — what a rendered value must match to blend in. */\nexport interface JsonStyle {\n /** The indentation unit — the whitespace before a top-level key. */\n readonly indent: string;\n /** `'\\r\\n'` when the file uses it anywhere, `'\\n'` otherwise. */\n readonly newline: string;\n}\n\n/**\n * The layout an existing file uses: its first indented key's leading whitespace (two\n * spaces when nothing is indented) and its newline convention. Detected once, before\n * any edit, so a sequence of edits renders consistently even after an earlier one has\n * changed the first indented line.\n */\nexport function jsonStyle(text: string): JsonStyle {\n return {\n newline: text.includes('\\r\\n') ? '\\r\\n' : '\\n',\n indent: /\\n([ \\t]+)\"/.exec(text)?.[1] ?? ' ',\n };\n}\n\n/**\n * Replace, insert or remove one top-level property of the JSON object in `text`,\n * leaving every other byte verbatim.\n *\n * - `value` defined: the property's value is replaced in place when the key exists,\n * otherwise the property is appended after the last one (or into an empty object).\n * - `value === undefined`: the property is removed, with its separating comma and\n * whitespace; a key that is not there is a no-op and the text comes back unchanged.\n *\n * The rendered value is `JSON.stringify(value, null, indent)`, re-indented to sit at\n * top level. `style` defaults to {@link jsonStyle} of `text`; pass it explicitly when\n * making several edits to one file.\n *\n * Returns `undefined` when `text` is not a JSON object the scanner can walk — an\n * array, a scalar, or something that is not JSON at all. Callers should have\n * `JSON.parse`d first and refused; this is belt and braces, not a validator.\n */\nexport function editTopLevelProperty(\n text: string,\n key: string,\n value: unknown,\n style: JsonStyle = jsonStyle(text),\n): string | undefined {\n const scan = scanJsonTopLevel(text);\n if (scan === undefined) return undefined;\n const property = scan.properties.find((candidate) => candidate.key === key);\n if (value === undefined) {\n return property === undefined ? text : removeJsonProperty(text, scan, property);\n }\n const rendered = renderJsonValue(value, style.indent, style.newline);\n return property !== undefined\n ? `${text.slice(0, property.valueStart)}${rendered}${text.slice(property.valueEnd)}`\n : insertJsonProperty(text, scan, key, rendered, style.indent, style.newline);\n}\n\n/** One top-level property of a JSON object, located by offsets in its source text. */\ninterface JsonTopLevelProperty {\n readonly key: string;\n /** Offset of the key's opening quote. */\n readonly keyStart: number;\n /** Offset of the value's first byte. */\n readonly valueStart: number;\n /** Offset one past the value's last byte. */\n readonly valueEnd: number;\n}\n\ninterface JsonTopLevelScan {\n /** Offset of the root object's `{`. */\n readonly open: number;\n /** Offset of the root object's `}`. */\n readonly close: number;\n readonly properties: readonly JsonTopLevelProperty[];\n}\n\n/**\n * Locate the top-level properties of a JSON object *in its source text*, so one\n * property can be replaced, inserted or removed while every other byte of the file\n * rides through verbatim. `undefined` when the text is not an object.\n */\nfunction scanJsonTopLevel(text: string): JsonTopLevelScan | undefined {\n let i = skipJsonWhitespace(text, 0);\n if (text[i] !== '{') return undefined;\n const open = i;\n i = skipJsonWhitespace(text, i + 1);\n const properties: JsonTopLevelProperty[] = [];\n if (text[i] === '}') return { open, close: i, properties };\n for (;;) {\n if (text[i] !== '\"') return undefined;\n const keyStart = i;\n const keyEnd = skipJsonString(text, i);\n if (keyEnd === undefined) return undefined;\n const key = JSON.parse(text.slice(keyStart, keyEnd)) as string;\n i = skipJsonWhitespace(text, keyEnd);\n if (text[i] !== ':') return undefined;\n const valueStart = skipJsonWhitespace(text, i + 1);\n const valueEnd = skipJsonValue(text, valueStart);\n if (valueEnd === undefined) return undefined;\n properties.push({ key, keyStart, valueStart, valueEnd });\n i = skipJsonWhitespace(text, valueEnd);\n if (text[i] === ',') {\n i = skipJsonWhitespace(text, i + 1);\n continue;\n }\n if (text[i] === '}') return { open, close: i, properties };\n return undefined;\n }\n}\n\nfunction skipJsonWhitespace(text: string, from: number): number {\n let i = from;\n while (i < text.length && ' \\t\\r\\n'.includes(text[i]!)) i += 1;\n return i;\n}\n\n/** `from` points at `\"`; returns the offset one past the closing quote. */\nfunction skipJsonString(text: string, from: number): number | undefined {\n let i = from + 1;\n while (i < text.length) {\n if (text[i] === '\\\\') i += 2;\n else if (text[i] === '\"') return i + 1;\n else i += 1;\n }\n return undefined;\n}\n\nfunction skipJsonValue(text: string, from: number): number | undefined {\n const first = text[from];\n if (first === '\"') return skipJsonString(text, from);\n if (first === '{' || first === '[') {\n let depth = 0;\n let i = from;\n while (i < text.length) {\n const ch = text[i]!;\n if (ch === '\"') {\n const end = skipJsonString(text, i);\n if (end === undefined) return undefined;\n i = end;\n continue;\n }\n if (ch === '{' || ch === '[') depth += 1;\n else if (ch === '}' || ch === ']') {\n depth -= 1;\n if (depth === 0) return i + 1;\n }\n i += 1;\n }\n return undefined;\n }\n // number / true / false / null\n let i = from;\n while (i < text.length && !',}] \\t\\r\\n'.includes(text[i]!)) i += 1;\n return i > from ? i : undefined;\n}\n\n/** A JSON value indented for embedding at a top-level property position. */\nfunction renderJsonValue(value: unknown, indent: string, newline: string): string {\n return JSON.stringify(value, null, indent).split('\\n').join(`${newline}${indent}`);\n}\n\nfunction removeJsonProperty(\n text: string,\n scan: JsonTopLevelScan,\n property: JsonTopLevelProperty,\n): string {\n const index = scan.properties.indexOf(property);\n const next = scan.properties[index + 1];\n if (next !== undefined) {\n // Delete through the separating comma and whitespace, up to the next key.\n return text.slice(0, property.keyStart) + text.slice(next.keyStart);\n }\n const previous = scan.properties[index - 1];\n // Last (or only) property: delete the preceding comma (if any) with it.\n const from = previous !== undefined ? previous.valueEnd : scan.open + 1;\n return text.slice(0, from) + text.slice(property.valueEnd);\n}\n\nfunction insertJsonProperty(\n text: string,\n scan: JsonTopLevelScan,\n key: string,\n renderedValue: string,\n indent: string,\n newline: string,\n): string {\n const entry = `${JSON.stringify(key)}: ${renderedValue}`;\n if (scan.properties.length === 0) {\n return `${text.slice(0, scan.open + 1)}${newline}${indent}${entry}${newline}${text.slice(scan.close)}`;\n }\n const last = scan.properties[scan.properties.length - 1]!;\n return `${text.slice(0, last.valueEnd)},${newline}${indent}${entry}${text.slice(last.valueEnd)}`;\n}\n\n/* ------------------------------------------------------------------------------------\n * Marker blocks\n * ---------------------------------------------------------------------------------- */\n\n/**\n * Replace the block delimited by `start` … `end` in `existingText`, or append it.\n *\n * An absent or blank file becomes exactly `block`. A file that carries the block has\n * it replaced in place (one newline after `end` is absorbed, so a block that ends in\n * its own newline does not grow a blank line per re-run). A file without it gets the\n * block appended after exactly one blank line, whatever trailing newlines it had.\n */\nexport function upsertMarkerBlock(\n existingText: string | undefined,\n block: string,\n start: string,\n end: string,\n): string {\n if (existingText === undefined || existingText.trim() === '') return block;\n const startIndex = existingText.indexOf(start);\n const endIndex = existingText.indexOf(end);\n if (startIndex !== -1 && endIndex !== -1 && endIndex > startIndex) {\n const before = existingText.slice(0, startIndex);\n const after = existingText.slice(endIndex + end.length).replace(/^\\n/, '');\n return `${before}${block}${after}`;\n }\n return `${existingText.replace(/\\n*$/, '\\n\\n')}${block}`;\n}\n\n/**\n * Remove the block delimited by `start` … `end`. The text comes back unchanged when\n * the block is not there; `undefined` when nothing (or only whitespace) remains — the\n * file was entirely the block, and the caller decides whether to delete it.\n */\nexport function stripMarkerBlock(\n existingText: string,\n start: string,\n end: string,\n): string | undefined {\n const startIndex = existingText.indexOf(start);\n const endIndex = existingText.indexOf(end);\n if (startIndex === -1 || endIndex === -1 || endIndex <= startIndex) return existingText;\n const stripped =\n existingText.slice(0, startIndex).replace(/\\n+$/, '\\n') +\n existingText.slice(endIndex + end.length).replace(/^\\n+/, '');\n return stripped.trim() === '' ? undefined : stripped;\n}\n"]}
package/dist/types.d.ts CHANGED
@@ -111,7 +111,7 @@ export interface AppliedElision {
111
111
  *
112
112
  * Budgets in smelt's core are UTF-8 bytes, permanently — bytes are the only unit that
113
113
  * is computable locally for every model, and they mean the same thing in five years.
114
- * See `docs/HANDOFF.md` § "Decision 1". This hook does not change that: it adds a
114
+ * See `docs/ARCHITECTURE.md` § "Decision 1". This hook does not change that: it adds a
115
115
  * second, labelled number to the result. The plan is still made in bytes.
116
116
  *
117
117
  * Both `id` and `unit` are required, and that is a Law 4 decision rather than
@@ -154,17 +154,6 @@ export interface SmeltResult {
154
154
  /** Present only when the caller supplied a {@link Measure}. Never invented. */
155
155
  readonly measured?: MeasuredSize;
156
156
  }
157
- /** Options for a single `smelt()` call. */
158
- export interface SmeltOptions {
159
- /** Soft ceiling for the emitted output, in UTF-8 bytes. */
160
- readonly budgetBytes: number;
161
- /** Filename or path, used to detect the language. Optional; detection falls back to `'unknown'`. */
162
- readonly path?: string;
163
- /** Override language detection entirely. */
164
- readonly language?: DetectedLanguage;
165
- /** What the caller was looking for. See {@link PlanInput.focus}. */
166
- readonly focus?: readonly string[];
167
- }
168
157
  /**
169
158
  * Reversibility, as a callable. Takes a {@link SmeltResult} and the store that holds its
170
159
  * elided bytes, and returns the original text — byte for byte.
@@ -227,9 +216,28 @@ export interface ElisionStore {
227
216
  peek(hash: string): string | undefined;
228
217
  /**
229
218
  * The stored content, *counted* as a retrieval. This is what the model's tool calls.
219
+ *
230
220
  * @throws {UnknownHashError} when the hash is unknown.
221
+ * @throws {StoreCorruptionError} — {@link DirectoryElisionStore} only — when the
222
+ * bytes on disk no longer hash to their own name. Distinct from
223
+ * `UnknownHashError` on purpose: "we hold damaged bytes" and "it never existed"
224
+ * are different answers, and a caller that conflates them will report the wrong
225
+ * one to its user.
226
+ *
227
+ * A {@link DirectoryElisionStore} whose journal cannot be written (a read-only
228
+ * store directory, a full disk) still returns the bytes — verified bytes are never
229
+ * withheld over a bookkeeping failure — and surfaces the lost count as a
230
+ * `process.emitWarning` named `SmeltCounterWriteFailure` instead of throwing. Its
231
+ * stats go quiet from that point; the retrieval itself succeeded.
231
232
  */
232
233
  retrieve(hash: string): string;
234
+ /**
235
+ * Whether this hash can be retrieved — **not** merely whether a slot bearing it
236
+ * exists. `true` must mean the very next `retrieve(hash)` returns bytes, so a store
237
+ * that verifies content on read verifies here too and raises its corruption error
238
+ * rather than answering `true` for bytes it would then refuse. Uncounted: a check is
239
+ * not the model asking for material back.
240
+ */
233
241
  has(hash: string): boolean;
234
242
  /** A snapshot of the counters. See {@link RetrieveStats}. */
235
243
  stats(): RetrieveStats;
@@ -244,17 +252,30 @@ export interface RetrieveTool {
244
252
  readonly name: string;
245
253
  /** Prose the consumer can put straight into a tool description. */
246
254
  readonly description: string;
247
- /** JSON-Schema-shaped parameter description, for consumers that want one. */
255
+ /**
256
+ * JSON-Schema-shaped parameter description, for consumers that want one.
257
+ *
258
+ * Strict-mode shaped: `additionalProperties: false` and a `required` naming every
259
+ * property, so a consumer registering this under OpenAI's structured-outputs strict
260
+ * mode is not refused at registration. See {@link createRetrieveTool}.
261
+ */
248
262
  readonly inputSchema: {
249
263
  readonly type: 'object';
250
264
  readonly properties: {
251
265
  readonly hash: {
252
266
  readonly type: 'string';
267
+ readonly description: string;
253
268
  };
254
269
  };
255
270
  readonly required: readonly ['hash'];
271
+ readonly additionalProperties: false;
256
272
  };
257
- /** @throws {UnknownHashError} when the hash is unknown. */
273
+ /**
274
+ * @throws {UnknownHashError} when the hash is unknown.
275
+ * @throws {StoreCorruptionError} when the backing store holds damaged bytes for
276
+ * that hash — see {@link ElisionStore.retrieve}, whose contract this forwards
277
+ * verbatim. Surface either to the model as a tool error, never as empty text.
278
+ */
258
279
  invoke(input: {
259
280
  readonly hash: string;
260
281
  }): string;