open-multi-agent-kit 0.90.7 → 0.90.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (331) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +17 -10
  3. package/dist/cli/args.d.ts.map +1 -1
  4. package/dist/cli/args.js +5 -1
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/commands/doctor-provider-cli.d.ts +33 -0
  7. package/dist/commands/doctor-provider-cli.d.ts.map +1 -0
  8. package/dist/commands/doctor-provider-cli.js +215 -0
  9. package/dist/commands/doctor-provider-cli.js.map +1 -0
  10. package/dist/commands/doctor-provider-transport.d.ts +35 -0
  11. package/dist/commands/doctor-provider-transport.d.ts.map +1 -0
  12. package/dist/commands/doctor-provider-transport.js +185 -0
  13. package/dist/commands/doctor-provider-transport.js.map +1 -0
  14. package/dist/commands/doctor-provider.d.ts +121 -7
  15. package/dist/commands/doctor-provider.d.ts.map +1 -1
  16. package/dist/commands/doctor-provider.js +1295 -102
  17. package/dist/commands/doctor-provider.js.map +1 -1
  18. package/dist/commands/session-doctor-cli.d.ts +43 -0
  19. package/dist/commands/session-doctor-cli.d.ts.map +1 -0
  20. package/dist/commands/session-doctor-cli.js +494 -0
  21. package/dist/commands/session-doctor-cli.js.map +1 -0
  22. package/dist/commands/verify-ci.d.ts +21 -0
  23. package/dist/commands/verify-ci.d.ts.map +1 -0
  24. package/dist/commands/verify-ci.js +66 -0
  25. package/dist/commands/verify-ci.js.map +1 -0
  26. package/dist/core/agent-session-services.d.ts +3 -0
  27. package/dist/core/agent-session-services.d.ts.map +1 -1
  28. package/dist/core/agent-session-services.js +3 -0
  29. package/dist/core/agent-session-services.js.map +1 -1
  30. package/dist/core/agent-session.d.ts +116 -2
  31. package/dist/core/agent-session.d.ts.map +1 -1
  32. package/dist/core/agent-session.js +1015 -71
  33. package/dist/core/agent-session.js.map +1 -1
  34. package/dist/core/agent-tool-settings.d.ts +35 -0
  35. package/dist/core/agent-tool-settings.d.ts.map +1 -0
  36. package/dist/core/agent-tool-settings.js +155 -0
  37. package/dist/core/agent-tool-settings.js.map +1 -0
  38. package/dist/core/atomic-session-file.d.ts +14 -0
  39. package/dist/core/atomic-session-file.d.ts.map +1 -0
  40. package/dist/core/atomic-session-file.js +104 -0
  41. package/dist/core/atomic-session-file.js.map +1 -0
  42. package/dist/core/compaction/compaction.d.ts +6 -0
  43. package/dist/core/compaction/compaction.d.ts.map +1 -1
  44. package/dist/core/compaction/compaction.js +12 -1
  45. package/dist/core/compaction/compaction.js.map +1 -1
  46. package/dist/core/compaction/hysteresis.d.ts +27 -0
  47. package/dist/core/compaction/hysteresis.d.ts.map +1 -0
  48. package/dist/core/compaction/hysteresis.js +84 -0
  49. package/dist/core/compaction/hysteresis.js.map +1 -0
  50. package/dist/core/compaction/index.d.ts +2 -0
  51. package/dist/core/compaction/index.d.ts.map +1 -1
  52. package/dist/core/compaction/index.js +2 -0
  53. package/dist/core/compaction/index.js.map +1 -1
  54. package/dist/core/compaction/transaction.d.ts +172 -0
  55. package/dist/core/compaction/transaction.d.ts.map +1 -0
  56. package/dist/core/compaction/transaction.js +824 -0
  57. package/dist/core/compaction/transaction.js.map +1 -0
  58. package/dist/core/context-budget-governor-v2.d.ts +2 -1
  59. package/dist/core/context-budget-governor-v2.d.ts.map +1 -1
  60. package/dist/core/context-budget-governor-v2.js +2 -1
  61. package/dist/core/context-budget-governor-v2.js.map +1 -1
  62. package/dist/core/context-budget-headroom.d.ts.map +1 -1
  63. package/dist/core/context-budget-headroom.js +5 -1
  64. package/dist/core/context-budget-headroom.js.map +1 -1
  65. package/dist/core/context-budget-reserved-tokens.d.ts +110 -0
  66. package/dist/core/context-budget-reserved-tokens.d.ts.map +1 -0
  67. package/dist/core/context-budget-reserved-tokens.js +188 -0
  68. package/dist/core/context-budget-reserved-tokens.js.map +1 -0
  69. package/dist/core/context-budget-v2-cache-invalidation.d.ts +133 -0
  70. package/dist/core/context-budget-v2-cache-invalidation.d.ts.map +1 -0
  71. package/dist/core/context-budget-v2-cache-invalidation.js +452 -0
  72. package/dist/core/context-budget-v2-cache-invalidation.js.map +1 -0
  73. package/dist/core/context-budget-v2-cache-keys.d.ts +3 -0
  74. package/dist/core/context-budget-v2-cache-keys.d.ts.map +1 -1
  75. package/dist/core/context-budget-v2-cache-keys.js +6 -0
  76. package/dist/core/context-budget-v2-cache-keys.js.map +1 -1
  77. package/dist/core/context-budget-v2-cache-provider.d.ts +8 -2
  78. package/dist/core/context-budget-v2-cache-provider.d.ts.map +1 -1
  79. package/dist/core/context-budget-v2-cache-provider.js +28 -5
  80. package/dist/core/context-budget-v2-cache-provider.js.map +1 -1
  81. package/dist/core/context-budget-v2-plan-cache-keys.d.ts.map +1 -1
  82. package/dist/core/context-budget-v2-plan-cache-keys.js +1 -0
  83. package/dist/core/context-budget-v2-plan-cache-keys.js.map +1 -1
  84. package/dist/core/context-budget-v2-planner.d.ts.map +1 -1
  85. package/dist/core/context-budget-v2-planner.js +1 -0
  86. package/dist/core/context-budget-v2-planner.js.map +1 -1
  87. package/dist/core/context-budget-v2-selection.d.ts.map +1 -1
  88. package/dist/core/context-budget-v2-selection.js +9 -0
  89. package/dist/core/context-budget-v2-selection.js.map +1 -1
  90. package/dist/core/context-budget-v2-types.d.ts +4 -0
  91. package/dist/core/context-budget-v2-types.d.ts.map +1 -1
  92. package/dist/core/context-budget-v2-types.js.map +1 -1
  93. package/dist/core/durable-file-directory.d.ts +4 -0
  94. package/dist/core/durable-file-directory.d.ts.map +1 -0
  95. package/dist/core/durable-file-directory.js +76 -0
  96. package/dist/core/durable-file-directory.js.map +1 -0
  97. package/dist/core/durable-file-identity.d.ts +26 -0
  98. package/dist/core/durable-file-identity.d.ts.map +1 -0
  99. package/dist/core/durable-file-identity.js +118 -0
  100. package/dist/core/durable-file-identity.js.map +1 -0
  101. package/dist/core/durable-file-io.d.ts +29 -0
  102. package/dist/core/durable-file-io.d.ts.map +1 -0
  103. package/dist/core/durable-file-io.js +179 -0
  104. package/dist/core/durable-file-io.js.map +1 -0
  105. package/dist/core/durable-file-lock-cleanup.d.ts +12 -0
  106. package/dist/core/durable-file-lock-cleanup.d.ts.map +1 -0
  107. package/dist/core/durable-file-lock-cleanup.js +39 -0
  108. package/dist/core/durable-file-lock-cleanup.js.map +1 -0
  109. package/dist/core/durable-file-lock-owner.d.ts +18 -0
  110. package/dist/core/durable-file-lock-owner.d.ts.map +1 -0
  111. package/dist/core/durable-file-lock-owner.js +78 -0
  112. package/dist/core/durable-file-lock-owner.js.map +1 -0
  113. package/dist/core/durable-file-lock-storage.d.ts +35 -0
  114. package/dist/core/durable-file-lock-storage.d.ts.map +1 -0
  115. package/dist/core/durable-file-lock-storage.js +263 -0
  116. package/dist/core/durable-file-lock-storage.js.map +1 -0
  117. package/dist/core/durable-file-mode.d.ts +8 -0
  118. package/dist/core/durable-file-mode.d.ts.map +1 -0
  119. package/dist/core/durable-file-mode.js +41 -0
  120. package/dist/core/durable-file-mode.js.map +1 -0
  121. package/dist/core/extensions/loader.d.ts +12 -0
  122. package/dist/core/extensions/loader.d.ts.map +1 -1
  123. package/dist/core/extensions/loader.js +50 -37
  124. package/dist/core/extensions/loader.js.map +1 -1
  125. package/dist/core/extensions/types.d.ts +2 -0
  126. package/dist/core/extensions/types.d.ts.map +1 -1
  127. package/dist/core/extensions/types.js.map +1 -1
  128. package/dist/core/index.d.ts +6 -2
  129. package/dist/core/index.d.ts.map +1 -1
  130. package/dist/core/index.js +5 -0
  131. package/dist/core/index.js.map +1 -1
  132. package/dist/core/loop-gates.d.ts.map +1 -1
  133. package/dist/core/loop-gates.js +25 -1
  134. package/dist/core/loop-gates.js.map +1 -1
  135. package/dist/core/model-resolver.d.ts.map +1 -1
  136. package/dist/core/model-resolver.js +1 -1
  137. package/dist/core/model-resolver.js.map +1 -1
  138. package/dist/core/pi-package-intake.d.ts +1 -0
  139. package/dist/core/pi-package-intake.d.ts.map +1 -1
  140. package/dist/core/pi-package-intake.js +7 -0
  141. package/dist/core/pi-package-intake.js.map +1 -1
  142. package/dist/core/redaction.d.ts +8 -0
  143. package/dist/core/redaction.d.ts.map +1 -0
  144. package/dist/core/redaction.js +31 -0
  145. package/dist/core/redaction.js.map +1 -0
  146. package/dist/core/resource-loader.d.ts.map +1 -1
  147. package/dist/core/resource-loader.js +36 -0
  148. package/dist/core/resource-loader.js.map +1 -1
  149. package/dist/core/run-journal-store.d.ts +53 -0
  150. package/dist/core/run-journal-store.d.ts.map +1 -0
  151. package/dist/core/run-journal-store.js +278 -0
  152. package/dist/core/run-journal-store.js.map +1 -0
  153. package/dist/core/run-journal.d.ts +172 -0
  154. package/dist/core/run-journal.d.ts.map +1 -0
  155. package/dist/core/run-journal.js +1053 -0
  156. package/dist/core/run-journal.js.map +1 -0
  157. package/dist/core/sdk.d.ts +7 -0
  158. package/dist/core/sdk.d.ts.map +1 -1
  159. package/dist/core/sdk.js +94 -3
  160. package/dist/core/sdk.js.map +1 -1
  161. package/dist/core/session-doctor-plan.d.ts +128 -0
  162. package/dist/core/session-doctor-plan.d.ts.map +1 -0
  163. package/dist/core/session-doctor-plan.js +833 -0
  164. package/dist/core/session-doctor-plan.js.map +1 -0
  165. package/dist/core/session-file-compaction.d.ts +6 -0
  166. package/dist/core/session-file-compaction.d.ts.map +1 -0
  167. package/dist/core/session-file-compaction.js +169 -0
  168. package/dist/core/session-file-compaction.js.map +1 -0
  169. package/dist/core/session-file-head.d.ts +10 -0
  170. package/dist/core/session-file-head.d.ts.map +1 -0
  171. package/dist/core/session-file-head.js +78 -0
  172. package/dist/core/session-file-head.js.map +1 -0
  173. package/dist/core/session-file-persistence.d.ts +30 -0
  174. package/dist/core/session-file-persistence.d.ts.map +1 -0
  175. package/dist/core/session-file-persistence.js +106 -0
  176. package/dist/core/session-file-persistence.js.map +1 -0
  177. package/dist/core/session-integrity.d.ts +43 -0
  178. package/dist/core/session-integrity.d.ts.map +1 -0
  179. package/dist/core/session-integrity.js +420 -0
  180. package/dist/core/session-integrity.js.map +1 -0
  181. package/dist/core/session-manager.d.ts +24 -4
  182. package/dist/core/session-manager.d.ts.map +1 -1
  183. package/dist/core/session-manager.js +242 -125
  184. package/dist/core/session-manager.js.map +1 -1
  185. package/dist/core/session-owner-lease.d.ts +22 -0
  186. package/dist/core/session-owner-lease.d.ts.map +1 -0
  187. package/dist/core/session-owner-lease.js +176 -0
  188. package/dist/core/session-owner-lease.js.map +1 -0
  189. package/dist/core/session-path-policy.d.ts +132 -0
  190. package/dist/core/session-path-policy.d.ts.map +1 -0
  191. package/dist/core/session-path-policy.js +780 -0
  192. package/dist/core/session-path-policy.js.map +1 -0
  193. package/dist/core/session-repair-plan.d.ts +49 -0
  194. package/dist/core/session-repair-plan.d.ts.map +1 -0
  195. package/dist/core/session-repair-plan.js +202 -0
  196. package/dist/core/session-repair-plan.js.map +1 -0
  197. package/dist/core/session-termination.d.ts +100 -0
  198. package/dist/core/session-termination.d.ts.map +1 -0
  199. package/dist/core/session-termination.js +403 -0
  200. package/dist/core/session-termination.js.map +1 -0
  201. package/dist/core/settings-manager.d.ts +32 -0
  202. package/dist/core/settings-manager.d.ts.map +1 -1
  203. package/dist/core/settings-manager.js +52 -5
  204. package/dist/core/settings-manager.js.map +1 -1
  205. package/dist/core/system-prompt.d.ts.map +1 -1
  206. package/dist/core/system-prompt.js +1 -1
  207. package/dist/core/system-prompt.js.map +1 -1
  208. package/dist/core/verified-bash-adapter.d.ts +36 -0
  209. package/dist/core/verified-bash-adapter.d.ts.map +1 -0
  210. package/dist/core/verified-bash-adapter.js +90 -0
  211. package/dist/core/verified-bash-adapter.js.map +1 -0
  212. package/dist/guardrails/command-redaction.d.ts +32 -0
  213. package/dist/guardrails/command-redaction.d.ts.map +1 -0
  214. package/dist/guardrails/command-redaction.js +776 -0
  215. package/dist/guardrails/command-redaction.js.map +1 -0
  216. package/dist/guardrails/evidence-attestation.d.ts +31 -0
  217. package/dist/guardrails/evidence-attestation.d.ts.map +1 -0
  218. package/dist/guardrails/evidence-attestation.js +178 -0
  219. package/dist/guardrails/evidence-attestation.js.map +1 -0
  220. package/dist/guardrails/evidence-receipt-store.d.ts +33 -0
  221. package/dist/guardrails/evidence-receipt-store.d.ts.map +1 -0
  222. package/dist/guardrails/evidence-receipt-store.js +446 -0
  223. package/dist/guardrails/evidence-receipt-store.js.map +1 -0
  224. package/dist/guardrails/evidence-receipt.d.ts +58 -0
  225. package/dist/guardrails/evidence-receipt.d.ts.map +1 -0
  226. package/dist/guardrails/evidence-receipt.js +389 -0
  227. package/dist/guardrails/evidence-receipt.js.map +1 -0
  228. package/dist/guardrails/evidence-system.d.ts +40 -9
  229. package/dist/guardrails/evidence-system.d.ts.map +1 -1
  230. package/dist/guardrails/evidence-system.js +379 -83
  231. package/dist/guardrails/evidence-system.js.map +1 -1
  232. package/dist/guardrails/replay-ledger-io.d.ts +6 -0
  233. package/dist/guardrails/replay-ledger-io.d.ts.map +1 -0
  234. package/dist/guardrails/replay-ledger-io.js +42 -0
  235. package/dist/guardrails/replay-ledger-io.js.map +1 -0
  236. package/dist/guardrails/replay-ledger-lock-owner.d.ts +32 -0
  237. package/dist/guardrails/replay-ledger-lock-owner.d.ts.map +1 -0
  238. package/dist/guardrails/replay-ledger-lock-owner.js +138 -0
  239. package/dist/guardrails/replay-ledger-lock-owner.js.map +1 -0
  240. package/dist/guardrails/replay-ledger-lock.d.ts +24 -0
  241. package/dist/guardrails/replay-ledger-lock.d.ts.map +1 -0
  242. package/dist/guardrails/replay-ledger-lock.js +135 -0
  243. package/dist/guardrails/replay-ledger-lock.js.map +1 -0
  244. package/dist/guardrails/replay-ledger-mutation-gate.d.ts +24 -0
  245. package/dist/guardrails/replay-ledger-mutation-gate.d.ts.map +1 -0
  246. package/dist/guardrails/replay-ledger-mutation-gate.js +205 -0
  247. package/dist/guardrails/replay-ledger-mutation-gate.js.map +1 -0
  248. package/dist/guardrails/replay-ledger-quarantine.d.ts +2 -0
  249. package/dist/guardrails/replay-ledger-quarantine.d.ts.map +1 -0
  250. package/dist/guardrails/replay-ledger-quarantine.js +19 -0
  251. package/dist/guardrails/replay-ledger-quarantine.js.map +1 -0
  252. package/dist/guardrails/replay-ledger-store.d.ts +32 -0
  253. package/dist/guardrails/replay-ledger-store.d.ts.map +1 -0
  254. package/dist/guardrails/replay-ledger-store.js +211 -0
  255. package/dist/guardrails/replay-ledger-store.js.map +1 -0
  256. package/dist/guardrails/shell-command-name-glob.d.ts +3 -0
  257. package/dist/guardrails/shell-command-name-glob.d.ts.map +1 -0
  258. package/dist/guardrails/shell-command-name-glob.js +233 -0
  259. package/dist/guardrails/shell-command-name-glob.js.map +1 -0
  260. package/dist/guardrails/shell-command-option.d.ts +7 -0
  261. package/dist/guardrails/shell-command-option.d.ts.map +1 -0
  262. package/dist/guardrails/shell-command-option.js +24 -0
  263. package/dist/guardrails/shell-command-option.js.map +1 -0
  264. package/dist/guardrails/shell-command-tokenizer.d.ts +29 -0
  265. package/dist/guardrails/shell-command-tokenizer.d.ts.map +1 -0
  266. package/dist/guardrails/shell-command-tokenizer.js +145 -0
  267. package/dist/guardrails/shell-command-tokenizer.js.map +1 -0
  268. package/dist/guardrails/shell-command-wrapper.d.ts +18 -0
  269. package/dist/guardrails/shell-command-wrapper.d.ts.map +1 -0
  270. package/dist/guardrails/shell-command-wrapper.js +42 -0
  271. package/dist/guardrails/shell-command-wrapper.js.map +1 -0
  272. package/dist/guardrails/verified-executor.d.ts +65 -0
  273. package/dist/guardrails/verified-executor.d.ts.map +1 -0
  274. package/dist/guardrails/verified-executor.js +171 -0
  275. package/dist/guardrails/verified-executor.js.map +1 -0
  276. package/dist/guardrails/workspace-fingerprint.d.ts +23 -0
  277. package/dist/guardrails/workspace-fingerprint.d.ts.map +1 -0
  278. package/dist/guardrails/workspace-fingerprint.js +634 -0
  279. package/dist/guardrails/workspace-fingerprint.js.map +1 -0
  280. package/dist/index.d.ts +15 -3
  281. package/dist/index.d.ts.map +1 -1
  282. package/dist/index.js +13 -1
  283. package/dist/index.js.map +1 -1
  284. package/dist/main.d.ts.map +1 -1
  285. package/dist/main.js +12 -0
  286. package/dist/main.js.map +1 -1
  287. package/dist/modes/interactive/components/control-panel-layout.d.ts.map +1 -1
  288. package/dist/modes/interactive/components/control-panel-layout.js +1 -1
  289. package/dist/modes/interactive/components/control-panel-layout.js.map +1 -1
  290. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  291. package/dist/modes/interactive/components/footer.js +1 -1
  292. package/dist/modes/interactive/components/footer.js.map +1 -1
  293. package/dist/modes/interactive/interactive-mode.d.ts +3 -0
  294. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  295. package/dist/modes/interactive/interactive-mode.js +59 -9
  296. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  297. package/dist/modes/print-mode.d.ts.map +1 -1
  298. package/dist/modes/print-mode.js +43 -2
  299. package/dist/modes/print-mode.js.map +1 -1
  300. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  301. package/dist/modes/rpc/rpc-mode.js +23 -5
  302. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  303. package/dist/modes/rpc/rpc-types.d.ts +3 -0
  304. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  305. package/dist/modes/rpc/rpc-types.js.map +1 -1
  306. package/dist/types/evidence.d.ts +215 -1
  307. package/dist/types/evidence.d.ts.map +1 -1
  308. package/dist/types/evidence.js.map +1 -1
  309. package/dist/verify-ci.d.ts +3 -0
  310. package/dist/verify-ci.d.ts.map +1 -0
  311. package/dist/verify-ci.js +30 -0
  312. package/dist/verify-ci.js.map +1 -0
  313. package/docs/compaction.md +44 -4
  314. package/docs/extensions.md +2 -0
  315. package/docs/providers.md +6 -0
  316. package/docs/sdk.md +238 -1
  317. package/docs/settings.md +67 -4
  318. package/docs/usage.md +38 -0
  319. package/examples/extensions/correctness-wall/README.md +6 -6
  320. package/examples/extensions/correctness-wall/index.ts +37 -11
  321. package/examples/extensions/custom-provider-anthropic/package-lock.json +5 -5
  322. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  323. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  324. package/examples/extensions/gondolin/package-lock.json +2 -2
  325. package/examples/extensions/gondolin/package.json +1 -1
  326. package/examples/extensions/sandbox/package-lock.json +2 -2
  327. package/examples/extensions/sandbox/package.json +1 -1
  328. package/examples/extensions/with-deps/package-lock.json +4 -4
  329. package/examples/extensions/with-deps/package.json +1 -1
  330. package/npm-shrinkwrap.json +12 -12
  331. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"context-budget-v2-types.d.ts","sourceRoot":"","sources":["../../src/core/context-budget-v2-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,mBAAmB,EACnB,mBAAmB,EACnB,oCAAoC,EACpC,gCAAgC,EAChC,2BAA2B,EAC3B,kBAAkB,EAClB,uBAAuB,EACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAE7E,eAAO,MAAM,gCAAgC,sBAAsB,CAAC;AAIpE,MAAM,WAAW,2BAA2B;IAC3C,QAAQ,CAAC,WAAW,EAAE,wBAAwB,CAAC;IAC/C,QAAQ,CAAC,MAAM,EAAE,2BAA2B,CAAC;IAC7C,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,4BAA4B,EAAE,mBAAmB,CAAC;IAC3D,QAAQ,CAAC,iBAAiB,EAAE,IAAI,CAAC;CACjC;AAED,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,CAU5F,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,SAAS,mBAAmB,EAUtD,CAAC;AAEF,MAAM,WAAW,0BAA0B;IAC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AQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,mBAAmB,EAAE,OAAO,CAAC;IACtC,QAAQ,CAAC,eAAe,EAAE,SAAS,sBAAsB,EAAE,CAAC;IAC5D,QAAQ,CAAC,uBAAuB,EAAE,SAAS,wBAAwB,EAAE,CAAC;IACtE,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,QAAQ,CAAC,WAAW,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACrD,QAAQ,CAAC,kBAAkB,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAC3D,QAAQ,CAAC,aAAa,EAAE,kCAAkC,CAAC;CAC3D","sourcesContent":["import type {\n\tContextBudgetItemV2,\n\tContextBudgetTierV2,\n\tContextRepresentationCacheMetadataV2,\n\tContextRepresentationCandidateV2,\n\tContextRepresentationKindV2,\n\tContextSourceRefV2,\n\tHeadroomQualityPolicyV2,\n} from \"./context-budget-headroom.ts\";\nimport type { TokenCounterAdapter } from \"./context-budget-token-counter.ts\";\n\nexport const CONTEXT_BUDGET_POLICY_VERSION_V2 = \"context-budget-v2\";\n\n// Inlined from the deleted token-optimizer.ts (legacy quarantine-compatibility\n// status; legacy-token-optimizer itself no longer exists as a module).\nexport interface TokenOptimizerRuntimeStatus {\n\treadonly optimizerId: \"legacy-token-optimizer\";\n\treadonly status: \"quarantined_compatibility\";\n\treadonly active: false;\n\treadonly activeContextBudgetOptimizer: \"context-budget-v2\";\n\treadonly compatibilityOnly: true;\n}\n\nexport interface TierBudgetPolicyV2 {\n\treadonly floorPct: number;\n\treadonly ceilingPct: number;\n}\n\nexport const DEFAULT_TIER_POLICY_V2: Readonly<Record<ContextBudgetTierV2, TierBudgetPolicyV2>> = {\n\tsystem: { floorPct: 0.25, ceilingPct: 0.45 },\n\t\"active-goal\": { floorPct: 0.1, ceilingPct: 0.25 },\n\t\"current-files\": { floorPct: 0.08, ceilingPct: 0.2 },\n\ttools: { floorPct: 0.04, ceilingPct: 0.12 },\n\tskills: { floorPct: 0.03, ceilingPct: 0.12 },\n\tmcp: { floorPct: 0.02, ceilingPct: 0.08 },\n\thistory: { floorPct: 0.1, ceilingPct: 0.3 },\n\tevidence: { floorPct: 0.08, ceilingPct: 0.25 },\n\tscratch: { floorPct: 0, ceilingPct: 0.05 },\n};\n\nexport const ALL_TIERS_V2: readonly ContextBudgetTierV2[] = [\n\t\"system\",\n\t\"active-goal\",\n\t\"current-files\",\n\t\"tools\",\n\t\"skills\",\n\t\"mcp\",\n\t\"history\",\n\t\"evidence\",\n\t\"scratch\",\n];\n\nexport interface PromptContextBudgetInputV2 {\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens?: number;\n\treadonly safetyMarginTokens?: number;\n\treadonly modelId?: string;\n\treadonly tokenizerId?: string;\n\treadonly policyVersion?: string;\n\treadonly promptHash?: string;\n\treadonly query?: string;\n\treadonly items: readonly ContextBudgetItemV2[];\n\treadonly tokenCounter?: TokenCounterAdapter;\n\treadonly tierPolicy?: Partial<Record<ContextBudgetTierV2, TierBudgetPolicyV2>>;\n\treadonly qualityPolicy?: HeadroomQualityPolicyV2;\n\treadonly cacheProvider?: ContextBudgetCacheProviderV2;\n\treadonly cacheNamespace?: string;\n\treadonly queryIntentHash?: string;\n\treadonly cacheBudgetBucket?: string;\n\treadonly redactionPolicyHash?: string;\n\treadonly safetyProfileHash?: string;\n\treadonly cacheNowEpochMs?: number;\n\treadonly cacheTtlMs?: number;\n}\n\nexport interface SelectedRepresentationV2 {\n\treadonly itemId: string;\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly cache?: ContextRepresentationCacheMetadataV2;\n}\n\nexport interface TierBudgetAllocationV2 {\n\treadonly tier: ContextBudgetTierV2;\n\treadonly floorTokens: number;\n\treadonly ceilingTokens: number;\n\treadonly allocatedTokens: number;\n\treadonly usedTokens: number;\n\treadonly hardTokens: number;\n}\n\nexport type QualityDiagnosticReasonV2 =\n\t| \"omitted_high_priority\"\n\t| \"retrieval_miss_risk\"\n\t| \"restore_on_demand_hint\"\n\t| \"hard_pin_over_capacity\"\n\t| \"coverage_gap\"\n\t| \"tier_ceiling_exceeded\"\n\t| \"invalid_budget\";\n\nexport interface QualityDiagnosticV2 {\n\treadonly reason: QualityDiagnosticReasonV2;\n\treadonly itemId?: string;\n\treadonly detail: string;\n}\n\nexport interface ContextBudgetObservabilityCountsV2 {\n\treadonly selected: number;\n\treadonly omitted: number;\n\treadonly pointer: number;\n\treadonly compressed: number;\n\treadonly full: number;\n\treadonly retrievalFallback: number;\n}\n\nexport interface ContextBudgetObservabilityTokensV2 {\n\treadonly available: number;\n\treadonly used: number;\n\treadonly raw: number;\n\treadonly omitted: number;\n\treadonly tokenSavings: number;\n}\n\nexport type ContextBudgetCacheLayerV2 = \"turn\" | \"session\" | \"workspace\" | \"shared\";\n\nexport type ContextBudgetRepresentationCacheRejectReasonV2 =\n\t| \"fingerprint_mismatch\"\n\t| \"kind_mismatch\"\n\t| \"model_mismatch\"\n\t| \"negative\"\n\t| \"policy_mismatch\"\n\t| \"poisoned\"\n\t| \"source_hash_mismatch\"\n\t| \"stale\"\n\t| \"token_invalid\"\n\t| \"tokenizer_mismatch\";\n\nexport type ContextBudgetRepresentationCacheKeyKindV2 = \"exact\" | \"materialized\";\n\nexport interface ContextBudgetMaterializedVerificationV2 {\n\treadonly queryCoverage?: number;\n\treadonly sourceCoverage?: number;\n\treadonly secretLeakScore?: number;\n\treadonly poisonScore?: number;\n\treadonly validatorVersion?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheEntryV2 {\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceHash: string;\n\treadonly representationFingerprint: string;\n\treadonly keyKind?: ContextBudgetRepresentationCacheKeyKindV2;\n\treadonly modelId: string;\n\treadonly tokenizerId: string;\n\treadonly policyVersion: string;\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly compressorPolicyHash?: string;\n\treadonly qualityPolicyHash?: string;\n\treadonly queryIntentCluster?: string;\n\treadonly outputTextHash?: string;\n\treadonly targetTokenBucket?: number;\n\treadonly verification?: ContextBudgetMaterializedVerificationV2;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetRepresentationCacheReadV2 {\n\treadonly entry: ContextBudgetRepresentationCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetNegativeCacheEntryV2 {\n\treadonly reason: string;\n\treadonly createdAtEpochMs?: number;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetPlanCacheEntryV2 {\n\treadonly plan: PromptContextBudgetPlanV2;\n\treadonly sourceHashes: Readonly<Record<string, string>>;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetPlanCacheReadV2 {\n\treadonly entry: ContextBudgetPlanCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetCacheProviderV2 {\n\treadRepresentation(key: string): ContextBudgetRepresentationCacheReadV2 | undefined;\n\twriteRepresentation(input: { readonly key: string; readonly entry: ContextBudgetRepresentationCacheEntryV2 }): void;\n\treadNegativeRepresentation(key: string): ContextBudgetNegativeCacheEntryV2 | undefined;\n\twriteNegativeRepresentation(input: { readonly key: string; readonly reason: string }): void;\n\treadPlan(key: string): ContextBudgetPlanCacheReadV2 | undefined;\n\twritePlan(input: { readonly key: string; readonly entry: ContextBudgetPlanCacheEntryV2 }): void;\n}\n\nexport interface ContextBudgetPlanCacheTelemetryV2 {\n\treadonly hit: boolean;\n\treadonly key: string;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n\treadonly rejectedReason?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheTelemetryV2 {\n\treadonly exactHits: number;\n\treadonly semanticHits: number;\n\treadonly pointerHits: number;\n\treadonly misses: number;\n\treadonly staleRejects: number;\n\treadonly poisonRejects: number;\n\treadonly negativeHits: number;\n\treadonly writes: number;\n}\n\nexport interface ContextBudgetCacheTokenTelemetryV2 {\n\treadonly raw: number;\n\treadonly rendered: number;\n\treadonly savedByCache: number;\n\treadonly savedByCompression: number;\n\treadonly savedByOmission: number;\n}\n\nexport interface TokenCacheTelemetryV2 {\n\treadonly planCache: ContextBudgetPlanCacheTelemetryV2;\n\treadonly representationCache: ContextBudgetRepresentationCacheTelemetryV2;\n\treadonly tokens: ContextBudgetCacheTokenTelemetryV2;\n}\n\nexport interface PromptContextBudgetObservabilityV2 {\n\treadonly counts: ContextBudgetObservabilityCountsV2;\n\treadonly diagnosticReasons: readonly QualityDiagnosticReasonV2[];\n\treadonly tokens: ContextBudgetObservabilityTokensV2;\n\treadonly planHash: string;\n\treadonly cache: TokenCacheTelemetryV2;\n\treadonly tokenOptimizer: TokenOptimizerRuntimeStatus;\n}\n\nexport interface PromptContextBudgetPlanV2 {\n\treadonly policyVersion: string;\n\treadonly promptHash?: string;\n\treadonly planHash: string;\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens: number;\n\treadonly safetyMarginTokens: number;\n\treadonly availableTokens: number;\n\treadonly usedTokens: number;\n\treadonly omittedTokens: number;\n\treadonly rawTokens: number;\n\treadonly tokenSavingsRatio: number;\n\treadonly emergency: boolean;\n\treadonly omittedHighPriority: boolean;\n\treadonly tierAllocations: readonly TierBudgetAllocationV2[];\n\treadonly selectedRepresentations: readonly SelectedRepresentationV2[];\n\treadonly includedItemIds: readonly string[];\n\treadonly omittedItemIds: readonly string[];\n\treadonly diagnostics: readonly QualityDiagnosticV2[];\n\treadonly retrievalFallbacks: readonly ContextSourceRefV2[];\n\treadonly observability: PromptContextBudgetObservabilityV2;\n}\n"]}
1
+ {"version":3,"file":"context-budget-v2-types.d.ts","sourceRoot":"","sources":["../../src/core/context-budget-v2-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,mBAAmB,EACnB,mBAAmB,EACnB,oCAAoC,EACpC,gCAAgC,EAChC,2BAA2B,EAC3B,kBAAkB,EAClB,uBAAuB,EACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,2CAA2C,CAAC;AAElG,eAAO,MAAM,gCAAgC,sBAAsB,CAAC;AAIpE,MAAM,WAAW,2BAA2B;IAC3C,QAAQ,CAAC,WAAW,EAAE,wBAAwB,CAAC;IAC/C,QAAQ,CAAC,MAAM,EAAE,2BAA2B,CAAC;IAC7C,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,4BAA4B,EAAE,mBAAmB,CAAC;IAC3D,QAAQ,CAAC,iBAAiB,EAAE,IAAI,CAAC;CACjC;AAED,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,CAU5F,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,SAAS,mBAAmB,EAUtD,CAAC;AAEF,MAAM,WAAW,0BAA0B;IAC1C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ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BAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,mBAAmB,EAAE,OAAO,CAAC;IACtC,QAAQ,CAAC,eAAe,EAAE,SAAS,sBAAsB,EAAE,CAAC;IAC5D,QAAQ,CAAC,uBAAuB,EAAE,SAAS,wBAAwB,EAAE,CAAC;IACtE,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,QAAQ,CAAC,WAAW,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACrD,QAAQ,CAAC,kBAAkB,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAC3D,QAAQ,CAAC,aAAa,EAAE,kCAAkC,CAAC;CAC3D","sourcesContent":["import type {\n\tContextBudgetItemV2,\n\tContextBudgetTierV2,\n\tContextRepresentationCacheMetadataV2,\n\tContextRepresentationCandidateV2,\n\tContextRepresentationKindV2,\n\tContextSourceRefV2,\n\tHeadroomQualityPolicyV2,\n} from \"./context-budget-headroom.ts\";\nimport type { TokenCounterAdapter } from \"./context-budget-token-counter.ts\";\nimport type { ContextCacheInvalidationSnapshot } from \"./context-budget-v2-cache-invalidation.ts\";\n\nexport const CONTEXT_BUDGET_POLICY_VERSION_V2 = \"context-budget-v2\";\n\n// Inlined from the deleted token-optimizer.ts (legacy quarantine-compatibility\n// status; legacy-token-optimizer itself no longer exists as a module).\nexport interface TokenOptimizerRuntimeStatus {\n\treadonly optimizerId: \"legacy-token-optimizer\";\n\treadonly status: \"quarantined_compatibility\";\n\treadonly active: false;\n\treadonly activeContextBudgetOptimizer: \"context-budget-v2\";\n\treadonly compatibilityOnly: true;\n}\n\nexport interface TierBudgetPolicyV2 {\n\treadonly floorPct: number;\n\treadonly ceilingPct: number;\n}\n\nexport const DEFAULT_TIER_POLICY_V2: Readonly<Record<ContextBudgetTierV2, TierBudgetPolicyV2>> = {\n\tsystem: { floorPct: 0.25, ceilingPct: 0.45 },\n\t\"active-goal\": { floorPct: 0.1, ceilingPct: 0.25 },\n\t\"current-files\": { floorPct: 0.08, ceilingPct: 0.2 },\n\ttools: { floorPct: 0.04, ceilingPct: 0.12 },\n\tskills: { floorPct: 0.03, ceilingPct: 0.12 },\n\tmcp: { floorPct: 0.02, ceilingPct: 0.08 },\n\thistory: { floorPct: 0.1, ceilingPct: 0.3 },\n\tevidence: { floorPct: 0.08, ceilingPct: 0.25 },\n\tscratch: { floorPct: 0, ceilingPct: 0.05 },\n};\n\nexport const ALL_TIERS_V2: readonly ContextBudgetTierV2[] = [\n\t\"system\",\n\t\"active-goal\",\n\t\"current-files\",\n\t\"tools\",\n\t\"skills\",\n\t\"mcp\",\n\t\"history\",\n\t\"evidence\",\n\t\"scratch\",\n];\n\nexport interface PromptContextBudgetInputV2 {\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens?: number;\n\treadonly safetyMarginTokens?: number;\n\treadonly modelId?: string;\n\treadonly tokenizerId?: string;\n\treadonly policyVersion?: string;\n\treadonly promptHash?: string;\n\treadonly query?: string;\n\treadonly items: readonly ContextBudgetItemV2[];\n\treadonly tokenCounter?: TokenCounterAdapter;\n\treadonly tierPolicy?: Partial<Record<ContextBudgetTierV2, TierBudgetPolicyV2>>;\n\treadonly qualityPolicy?: HeadroomQualityPolicyV2;\n\treadonly cacheProvider?: ContextBudgetCacheProviderV2;\n\treadonly cacheNamespace?: string;\n\treadonly queryIntentHash?: string;\n\treadonly cacheBudgetBucket?: string;\n\treadonly redactionPolicyHash?: string;\n\treadonly safetyProfileHash?: string;\n\treadonly cacheNowEpochMs?: number;\n\treadonly cacheTtlMs?: number;\n\treadonly cacheInvalidationSnapshot?: ContextCacheInvalidationSnapshot;\n}\n\nexport interface SelectedRepresentationV2 {\n\treadonly itemId: string;\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly cache?: ContextRepresentationCacheMetadataV2;\n}\n\nexport interface TierBudgetAllocationV2 {\n\treadonly tier: ContextBudgetTierV2;\n\treadonly floorTokens: number;\n\treadonly ceilingTokens: number;\n\treadonly allocatedTokens: number;\n\treadonly usedTokens: number;\n\treadonly hardTokens: number;\n}\n\nexport type QualityDiagnosticReasonV2 =\n\t| \"omitted_high_priority\"\n\t| \"retrieval_miss_risk\"\n\t| \"restore_on_demand_hint\"\n\t| \"hard_pin_over_capacity\"\n\t| \"coverage_gap\"\n\t| \"tier_ceiling_exceeded\"\n\t| \"invalid_budget\";\n\nexport interface QualityDiagnosticV2 {\n\treadonly reason: QualityDiagnosticReasonV2;\n\treadonly itemId?: string;\n\treadonly detail: string;\n}\n\nexport interface ContextBudgetObservabilityCountsV2 {\n\treadonly selected: number;\n\treadonly omitted: number;\n\treadonly pointer: number;\n\treadonly compressed: number;\n\treadonly full: number;\n\treadonly retrievalFallback: number;\n}\n\nexport interface ContextBudgetObservabilityTokensV2 {\n\treadonly available: number;\n\treadonly used: number;\n\treadonly raw: number;\n\treadonly omitted: number;\n\treadonly tokenSavings: number;\n}\n\nexport type ContextBudgetCacheLayerV2 = \"turn\" | \"session\" | \"workspace\" | \"shared\";\n\nexport type ContextBudgetRepresentationCacheRejectReasonV2 =\n\t| \"fingerprint_mismatch\"\n\t| \"kind_mismatch\"\n\t| \"model_mismatch\"\n\t| \"negative\"\n\t| \"policy_mismatch\"\n\t| \"poisoned\"\n\t| \"source_hash_mismatch\"\n\t| \"stale\"\n\t| \"token_invalid\"\n\t| \"tokenizer_mismatch\";\n\nexport type ContextBudgetRepresentationCacheKeyKindV2 = \"exact\" | \"materialized\";\n\nexport interface ContextBudgetMaterializedVerificationV2 {\n\treadonly queryCoverage?: number;\n\treadonly sourceCoverage?: number;\n\treadonly secretLeakScore?: number;\n\treadonly poisonScore?: number;\n\treadonly validatorVersion?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheEntryV2 {\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceHash: string;\n\treadonly representationFingerprint: string;\n\treadonly keyKind?: ContextBudgetRepresentationCacheKeyKindV2;\n\treadonly modelId: string;\n\treadonly tokenizerId: string;\n\treadonly policyVersion: string;\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly compressorPolicyHash?: string;\n\treadonly qualityPolicyHash?: string;\n\treadonly queryIntentCluster?: string;\n\treadonly outputTextHash?: string;\n\treadonly targetTokenBucket?: number;\n\treadonly verification?: ContextBudgetMaterializedVerificationV2;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetRepresentationCacheReadV2 {\n\treadonly entry: ContextBudgetRepresentationCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetNegativeCacheEntryV2 {\n\treadonly reason: string;\n\treadonly createdAtEpochMs?: number;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetPlanCacheEntryV2 {\n\treadonly plan: PromptContextBudgetPlanV2;\n\treadonly sourceHashes: Readonly<Record<string, string>>;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetPlanCacheReadV2 {\n\treadonly entry: ContextBudgetPlanCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetCacheProviderV2 {\n\tgetInvalidationSnapshot?(): ContextCacheInvalidationSnapshot | undefined;\n\tsetInvalidationSnapshot?(snapshot: ContextCacheInvalidationSnapshot): void;\n\treadRepresentation(key: string): ContextBudgetRepresentationCacheReadV2 | undefined;\n\twriteRepresentation(input: { readonly key: string; readonly entry: ContextBudgetRepresentationCacheEntryV2 }): void;\n\treadNegativeRepresentation(key: string): ContextBudgetNegativeCacheEntryV2 | undefined;\n\twriteNegativeRepresentation(input: { readonly key: string; readonly reason: string }): void;\n\treadPlan(key: string): ContextBudgetPlanCacheReadV2 | undefined;\n\twritePlan(input: { readonly key: string; readonly entry: ContextBudgetPlanCacheEntryV2 }): void;\n}\n\nexport interface ContextBudgetPlanCacheTelemetryV2 {\n\treadonly hit: boolean;\n\treadonly key: string;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n\treadonly rejectedReason?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheTelemetryV2 {\n\treadonly exactHits: number;\n\treadonly semanticHits: number;\n\treadonly pointerHits: number;\n\treadonly misses: number;\n\treadonly staleRejects: number;\n\treadonly poisonRejects: number;\n\treadonly negativeHits: number;\n\treadonly writes: number;\n}\n\nexport interface ContextBudgetCacheTokenTelemetryV2 {\n\treadonly raw: number;\n\treadonly rendered: number;\n\treadonly savedByCache: number;\n\treadonly savedByCompression: number;\n\treadonly savedByOmission: number;\n}\n\nexport interface TokenCacheTelemetryV2 {\n\treadonly planCache: ContextBudgetPlanCacheTelemetryV2;\n\treadonly representationCache: ContextBudgetRepresentationCacheTelemetryV2;\n\treadonly tokens: ContextBudgetCacheTokenTelemetryV2;\n}\n\nexport interface PromptContextBudgetObservabilityV2 {\n\treadonly counts: ContextBudgetObservabilityCountsV2;\n\treadonly diagnosticReasons: readonly QualityDiagnosticReasonV2[];\n\treadonly tokens: ContextBudgetObservabilityTokensV2;\n\treadonly planHash: string;\n\treadonly cache: TokenCacheTelemetryV2;\n\treadonly tokenOptimizer: TokenOptimizerRuntimeStatus;\n}\n\nexport interface PromptContextBudgetPlanV2 {\n\treadonly policyVersion: string;\n\treadonly promptHash?: string;\n\treadonly planHash: string;\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens: number;\n\treadonly safetyMarginTokens: number;\n\treadonly availableTokens: number;\n\treadonly usedTokens: number;\n\treadonly omittedTokens: number;\n\treadonly rawTokens: number;\n\treadonly tokenSavingsRatio: number;\n\treadonly emergency: boolean;\n\treadonly omittedHighPriority: boolean;\n\treadonly tierAllocations: readonly TierBudgetAllocationV2[];\n\treadonly selectedRepresentations: readonly SelectedRepresentationV2[];\n\treadonly includedItemIds: readonly string[];\n\treadonly omittedItemIds: readonly string[];\n\treadonly diagnostics: readonly QualityDiagnosticV2[];\n\treadonly retrievalFallbacks: readonly ContextSourceRefV2[];\n\treadonly observability: PromptContextBudgetObservabilityV2;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"context-budget-v2-types.js","sourceRoot":"","sources":["../../src/core/context-budget-v2-types.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAAmB,CAAC;AAiBpE,MAAM,CAAC,MAAM,sBAAsB,GAA8D;IAChG,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC5C,aAAa,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE;IAClD,eAAe,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE;IACpD,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC3C,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC5C,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IACzC,OAAO,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE;IAC3C,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC9C,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE;CAC1C,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAmC;IAC3D,QAAQ;IACR,aAAa;IACb,eAAe;IACf,OAAO;IACP,QAAQ;IACR,KAAK;IACL,SAAS;IACT,UAAU;IACV,SAAS;CACT,CAAC","sourcesContent":["import type {\n\tContextBudgetItemV2,\n\tContextBudgetTierV2,\n\tContextRepresentationCacheMetadataV2,\n\tContextRepresentationCandidateV2,\n\tContextRepresentationKindV2,\n\tContextSourceRefV2,\n\tHeadroomQualityPolicyV2,\n} from \"./context-budget-headroom.ts\";\nimport type { TokenCounterAdapter } from \"./context-budget-token-counter.ts\";\n\nexport const CONTEXT_BUDGET_POLICY_VERSION_V2 = \"context-budget-v2\";\n\n// Inlined from the deleted token-optimizer.ts (legacy quarantine-compatibility\n// status; legacy-token-optimizer itself no longer exists as a module).\nexport interface TokenOptimizerRuntimeStatus {\n\treadonly optimizerId: \"legacy-token-optimizer\";\n\treadonly status: \"quarantined_compatibility\";\n\treadonly active: false;\n\treadonly activeContextBudgetOptimizer: \"context-budget-v2\";\n\treadonly compatibilityOnly: true;\n}\n\nexport interface TierBudgetPolicyV2 {\n\treadonly floorPct: number;\n\treadonly ceilingPct: number;\n}\n\nexport const DEFAULT_TIER_POLICY_V2: Readonly<Record<ContextBudgetTierV2, TierBudgetPolicyV2>> = {\n\tsystem: { floorPct: 0.25, ceilingPct: 0.45 },\n\t\"active-goal\": { floorPct: 0.1, ceilingPct: 0.25 },\n\t\"current-files\": { floorPct: 0.08, ceilingPct: 0.2 },\n\ttools: { floorPct: 0.04, ceilingPct: 0.12 },\n\tskills: { floorPct: 0.03, ceilingPct: 0.12 },\n\tmcp: { floorPct: 0.02, ceilingPct: 0.08 },\n\thistory: { floorPct: 0.1, ceilingPct: 0.3 },\n\tevidence: { floorPct: 0.08, ceilingPct: 0.25 },\n\tscratch: { floorPct: 0, ceilingPct: 0.05 },\n};\n\nexport const ALL_TIERS_V2: readonly ContextBudgetTierV2[] = [\n\t\"system\",\n\t\"active-goal\",\n\t\"current-files\",\n\t\"tools\",\n\t\"skills\",\n\t\"mcp\",\n\t\"history\",\n\t\"evidence\",\n\t\"scratch\",\n];\n\nexport interface PromptContextBudgetInputV2 {\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens?: number;\n\treadonly safetyMarginTokens?: number;\n\treadonly modelId?: string;\n\treadonly tokenizerId?: string;\n\treadonly policyVersion?: string;\n\treadonly promptHash?: string;\n\treadonly query?: string;\n\treadonly items: readonly ContextBudgetItemV2[];\n\treadonly tokenCounter?: TokenCounterAdapter;\n\treadonly tierPolicy?: Partial<Record<ContextBudgetTierV2, TierBudgetPolicyV2>>;\n\treadonly qualityPolicy?: HeadroomQualityPolicyV2;\n\treadonly cacheProvider?: ContextBudgetCacheProviderV2;\n\treadonly cacheNamespace?: string;\n\treadonly queryIntentHash?: string;\n\treadonly cacheBudgetBucket?: string;\n\treadonly redactionPolicyHash?: string;\n\treadonly safetyProfileHash?: string;\n\treadonly cacheNowEpochMs?: number;\n\treadonly cacheTtlMs?: number;\n}\n\nexport interface SelectedRepresentationV2 {\n\treadonly itemId: string;\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly cache?: ContextRepresentationCacheMetadataV2;\n}\n\nexport interface TierBudgetAllocationV2 {\n\treadonly tier: ContextBudgetTierV2;\n\treadonly floorTokens: number;\n\treadonly ceilingTokens: number;\n\treadonly allocatedTokens: number;\n\treadonly usedTokens: number;\n\treadonly hardTokens: number;\n}\n\nexport type QualityDiagnosticReasonV2 =\n\t| \"omitted_high_priority\"\n\t| \"retrieval_miss_risk\"\n\t| \"restore_on_demand_hint\"\n\t| \"hard_pin_over_capacity\"\n\t| \"coverage_gap\"\n\t| \"tier_ceiling_exceeded\"\n\t| \"invalid_budget\";\n\nexport interface QualityDiagnosticV2 {\n\treadonly reason: QualityDiagnosticReasonV2;\n\treadonly itemId?: string;\n\treadonly detail: string;\n}\n\nexport interface ContextBudgetObservabilityCountsV2 {\n\treadonly selected: number;\n\treadonly omitted: number;\n\treadonly pointer: number;\n\treadonly compressed: number;\n\treadonly full: number;\n\treadonly retrievalFallback: number;\n}\n\nexport interface ContextBudgetObservabilityTokensV2 {\n\treadonly available: number;\n\treadonly used: number;\n\treadonly raw: number;\n\treadonly omitted: number;\n\treadonly tokenSavings: number;\n}\n\nexport type ContextBudgetCacheLayerV2 = \"turn\" | \"session\" | \"workspace\" | \"shared\";\n\nexport type ContextBudgetRepresentationCacheRejectReasonV2 =\n\t| \"fingerprint_mismatch\"\n\t| \"kind_mismatch\"\n\t| \"model_mismatch\"\n\t| \"negative\"\n\t| \"policy_mismatch\"\n\t| \"poisoned\"\n\t| \"source_hash_mismatch\"\n\t| \"stale\"\n\t| \"token_invalid\"\n\t| \"tokenizer_mismatch\";\n\nexport type ContextBudgetRepresentationCacheKeyKindV2 = \"exact\" | \"materialized\";\n\nexport interface ContextBudgetMaterializedVerificationV2 {\n\treadonly queryCoverage?: number;\n\treadonly sourceCoverage?: number;\n\treadonly secretLeakScore?: number;\n\treadonly poisonScore?: number;\n\treadonly validatorVersion?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheEntryV2 {\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceHash: string;\n\treadonly representationFingerprint: string;\n\treadonly keyKind?: ContextBudgetRepresentationCacheKeyKindV2;\n\treadonly modelId: string;\n\treadonly tokenizerId: string;\n\treadonly policyVersion: string;\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly compressorPolicyHash?: string;\n\treadonly qualityPolicyHash?: string;\n\treadonly queryIntentCluster?: string;\n\treadonly outputTextHash?: string;\n\treadonly targetTokenBucket?: number;\n\treadonly verification?: ContextBudgetMaterializedVerificationV2;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetRepresentationCacheReadV2 {\n\treadonly entry: ContextBudgetRepresentationCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetNegativeCacheEntryV2 {\n\treadonly reason: string;\n\treadonly createdAtEpochMs?: number;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetPlanCacheEntryV2 {\n\treadonly plan: PromptContextBudgetPlanV2;\n\treadonly sourceHashes: Readonly<Record<string, string>>;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetPlanCacheReadV2 {\n\treadonly entry: ContextBudgetPlanCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetCacheProviderV2 {\n\treadRepresentation(key: string): ContextBudgetRepresentationCacheReadV2 | undefined;\n\twriteRepresentation(input: { readonly key: string; readonly entry: ContextBudgetRepresentationCacheEntryV2 }): void;\n\treadNegativeRepresentation(key: string): ContextBudgetNegativeCacheEntryV2 | undefined;\n\twriteNegativeRepresentation(input: { readonly key: string; readonly reason: string }): void;\n\treadPlan(key: string): ContextBudgetPlanCacheReadV2 | undefined;\n\twritePlan(input: { readonly key: string; readonly entry: ContextBudgetPlanCacheEntryV2 }): void;\n}\n\nexport interface ContextBudgetPlanCacheTelemetryV2 {\n\treadonly hit: boolean;\n\treadonly key: string;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n\treadonly rejectedReason?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheTelemetryV2 {\n\treadonly exactHits: number;\n\treadonly semanticHits: number;\n\treadonly pointerHits: number;\n\treadonly misses: number;\n\treadonly staleRejects: number;\n\treadonly poisonRejects: number;\n\treadonly negativeHits: number;\n\treadonly writes: number;\n}\n\nexport interface ContextBudgetCacheTokenTelemetryV2 {\n\treadonly raw: number;\n\treadonly rendered: number;\n\treadonly savedByCache: number;\n\treadonly savedByCompression: number;\n\treadonly savedByOmission: number;\n}\n\nexport interface TokenCacheTelemetryV2 {\n\treadonly planCache: ContextBudgetPlanCacheTelemetryV2;\n\treadonly representationCache: ContextBudgetRepresentationCacheTelemetryV2;\n\treadonly tokens: ContextBudgetCacheTokenTelemetryV2;\n}\n\nexport interface PromptContextBudgetObservabilityV2 {\n\treadonly counts: ContextBudgetObservabilityCountsV2;\n\treadonly diagnosticReasons: readonly QualityDiagnosticReasonV2[];\n\treadonly tokens: ContextBudgetObservabilityTokensV2;\n\treadonly planHash: string;\n\treadonly cache: TokenCacheTelemetryV2;\n\treadonly tokenOptimizer: TokenOptimizerRuntimeStatus;\n}\n\nexport interface PromptContextBudgetPlanV2 {\n\treadonly policyVersion: string;\n\treadonly promptHash?: string;\n\treadonly planHash: string;\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens: number;\n\treadonly safetyMarginTokens: number;\n\treadonly availableTokens: number;\n\treadonly usedTokens: number;\n\treadonly omittedTokens: number;\n\treadonly rawTokens: number;\n\treadonly tokenSavingsRatio: number;\n\treadonly emergency: boolean;\n\treadonly omittedHighPriority: boolean;\n\treadonly tierAllocations: readonly TierBudgetAllocationV2[];\n\treadonly selectedRepresentations: readonly SelectedRepresentationV2[];\n\treadonly includedItemIds: readonly string[];\n\treadonly omittedItemIds: readonly string[];\n\treadonly diagnostics: readonly QualityDiagnosticV2[];\n\treadonly retrievalFallbacks: readonly ContextSourceRefV2[];\n\treadonly observability: PromptContextBudgetObservabilityV2;\n}\n"]}
1
+ {"version":3,"file":"context-budget-v2-types.js","sourceRoot":"","sources":["../../src/core/context-budget-v2-types.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAAmB,CAAC;AAiBpE,MAAM,CAAC,MAAM,sBAAsB,GAA8D;IAChG,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC5C,aAAa,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE;IAClD,eAAe,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE;IACpD,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC3C,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC5C,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IACzC,OAAO,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE;IAC3C,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC9C,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE;CAC1C,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAmC;IAC3D,QAAQ;IACR,aAAa;IACb,eAAe;IACf,OAAO;IACP,QAAQ;IACR,KAAK;IACL,SAAS;IACT,UAAU;IACV,SAAS;CACT,CAAC","sourcesContent":["import type {\n\tContextBudgetItemV2,\n\tContextBudgetTierV2,\n\tContextRepresentationCacheMetadataV2,\n\tContextRepresentationCandidateV2,\n\tContextRepresentationKindV2,\n\tContextSourceRefV2,\n\tHeadroomQualityPolicyV2,\n} from \"./context-budget-headroom.ts\";\nimport type { TokenCounterAdapter } from \"./context-budget-token-counter.ts\";\nimport type { ContextCacheInvalidationSnapshot } from \"./context-budget-v2-cache-invalidation.ts\";\n\nexport const CONTEXT_BUDGET_POLICY_VERSION_V2 = \"context-budget-v2\";\n\n// Inlined from the deleted token-optimizer.ts (legacy quarantine-compatibility\n// status; legacy-token-optimizer itself no longer exists as a module).\nexport interface TokenOptimizerRuntimeStatus {\n\treadonly optimizerId: \"legacy-token-optimizer\";\n\treadonly status: \"quarantined_compatibility\";\n\treadonly active: false;\n\treadonly activeContextBudgetOptimizer: \"context-budget-v2\";\n\treadonly compatibilityOnly: true;\n}\n\nexport interface TierBudgetPolicyV2 {\n\treadonly floorPct: number;\n\treadonly ceilingPct: number;\n}\n\nexport const DEFAULT_TIER_POLICY_V2: Readonly<Record<ContextBudgetTierV2, TierBudgetPolicyV2>> = {\n\tsystem: { floorPct: 0.25, ceilingPct: 0.45 },\n\t\"active-goal\": { floorPct: 0.1, ceilingPct: 0.25 },\n\t\"current-files\": { floorPct: 0.08, ceilingPct: 0.2 },\n\ttools: { floorPct: 0.04, ceilingPct: 0.12 },\n\tskills: { floorPct: 0.03, ceilingPct: 0.12 },\n\tmcp: { floorPct: 0.02, ceilingPct: 0.08 },\n\thistory: { floorPct: 0.1, ceilingPct: 0.3 },\n\tevidence: { floorPct: 0.08, ceilingPct: 0.25 },\n\tscratch: { floorPct: 0, ceilingPct: 0.05 },\n};\n\nexport const ALL_TIERS_V2: readonly ContextBudgetTierV2[] = [\n\t\"system\",\n\t\"active-goal\",\n\t\"current-files\",\n\t\"tools\",\n\t\"skills\",\n\t\"mcp\",\n\t\"history\",\n\t\"evidence\",\n\t\"scratch\",\n];\n\nexport interface PromptContextBudgetInputV2 {\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens?: number;\n\treadonly safetyMarginTokens?: number;\n\treadonly modelId?: string;\n\treadonly tokenizerId?: string;\n\treadonly policyVersion?: string;\n\treadonly promptHash?: string;\n\treadonly query?: string;\n\treadonly items: readonly ContextBudgetItemV2[];\n\treadonly tokenCounter?: TokenCounterAdapter;\n\treadonly tierPolicy?: Partial<Record<ContextBudgetTierV2, TierBudgetPolicyV2>>;\n\treadonly qualityPolicy?: HeadroomQualityPolicyV2;\n\treadonly cacheProvider?: ContextBudgetCacheProviderV2;\n\treadonly cacheNamespace?: string;\n\treadonly queryIntentHash?: string;\n\treadonly cacheBudgetBucket?: string;\n\treadonly redactionPolicyHash?: string;\n\treadonly safetyProfileHash?: string;\n\treadonly cacheNowEpochMs?: number;\n\treadonly cacheTtlMs?: number;\n\treadonly cacheInvalidationSnapshot?: ContextCacheInvalidationSnapshot;\n}\n\nexport interface SelectedRepresentationV2 {\n\treadonly itemId: string;\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly cache?: ContextRepresentationCacheMetadataV2;\n}\n\nexport interface TierBudgetAllocationV2 {\n\treadonly tier: ContextBudgetTierV2;\n\treadonly floorTokens: number;\n\treadonly ceilingTokens: number;\n\treadonly allocatedTokens: number;\n\treadonly usedTokens: number;\n\treadonly hardTokens: number;\n}\n\nexport type QualityDiagnosticReasonV2 =\n\t| \"omitted_high_priority\"\n\t| \"retrieval_miss_risk\"\n\t| \"restore_on_demand_hint\"\n\t| \"hard_pin_over_capacity\"\n\t| \"coverage_gap\"\n\t| \"tier_ceiling_exceeded\"\n\t| \"invalid_budget\";\n\nexport interface QualityDiagnosticV2 {\n\treadonly reason: QualityDiagnosticReasonV2;\n\treadonly itemId?: string;\n\treadonly detail: string;\n}\n\nexport interface ContextBudgetObservabilityCountsV2 {\n\treadonly selected: number;\n\treadonly omitted: number;\n\treadonly pointer: number;\n\treadonly compressed: number;\n\treadonly full: number;\n\treadonly retrievalFallback: number;\n}\n\nexport interface ContextBudgetObservabilityTokensV2 {\n\treadonly available: number;\n\treadonly used: number;\n\treadonly raw: number;\n\treadonly omitted: number;\n\treadonly tokenSavings: number;\n}\n\nexport type ContextBudgetCacheLayerV2 = \"turn\" | \"session\" | \"workspace\" | \"shared\";\n\nexport type ContextBudgetRepresentationCacheRejectReasonV2 =\n\t| \"fingerprint_mismatch\"\n\t| \"kind_mismatch\"\n\t| \"model_mismatch\"\n\t| \"negative\"\n\t| \"policy_mismatch\"\n\t| \"poisoned\"\n\t| \"source_hash_mismatch\"\n\t| \"stale\"\n\t| \"token_invalid\"\n\t| \"tokenizer_mismatch\";\n\nexport type ContextBudgetRepresentationCacheKeyKindV2 = \"exact\" | \"materialized\";\n\nexport interface ContextBudgetMaterializedVerificationV2 {\n\treadonly queryCoverage?: number;\n\treadonly sourceCoverage?: number;\n\treadonly secretLeakScore?: number;\n\treadonly poisonScore?: number;\n\treadonly validatorVersion?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheEntryV2 {\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceHash: string;\n\treadonly representationFingerprint: string;\n\treadonly keyKind?: ContextBudgetRepresentationCacheKeyKindV2;\n\treadonly modelId: string;\n\treadonly tokenizerId: string;\n\treadonly policyVersion: string;\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly compressorPolicyHash?: string;\n\treadonly qualityPolicyHash?: string;\n\treadonly queryIntentCluster?: string;\n\treadonly outputTextHash?: string;\n\treadonly targetTokenBucket?: number;\n\treadonly verification?: ContextBudgetMaterializedVerificationV2;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetRepresentationCacheReadV2 {\n\treadonly entry: ContextBudgetRepresentationCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetNegativeCacheEntryV2 {\n\treadonly reason: string;\n\treadonly createdAtEpochMs?: number;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetPlanCacheEntryV2 {\n\treadonly plan: PromptContextBudgetPlanV2;\n\treadonly sourceHashes: Readonly<Record<string, string>>;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetPlanCacheReadV2 {\n\treadonly entry: ContextBudgetPlanCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetCacheProviderV2 {\n\tgetInvalidationSnapshot?(): ContextCacheInvalidationSnapshot | undefined;\n\tsetInvalidationSnapshot?(snapshot: ContextCacheInvalidationSnapshot): void;\n\treadRepresentation(key: string): ContextBudgetRepresentationCacheReadV2 | undefined;\n\twriteRepresentation(input: { readonly key: string; readonly entry: ContextBudgetRepresentationCacheEntryV2 }): void;\n\treadNegativeRepresentation(key: string): ContextBudgetNegativeCacheEntryV2 | undefined;\n\twriteNegativeRepresentation(input: { readonly key: string; readonly reason: string }): void;\n\treadPlan(key: string): ContextBudgetPlanCacheReadV2 | undefined;\n\twritePlan(input: { readonly key: string; readonly entry: ContextBudgetPlanCacheEntryV2 }): void;\n}\n\nexport interface ContextBudgetPlanCacheTelemetryV2 {\n\treadonly hit: boolean;\n\treadonly key: string;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n\treadonly rejectedReason?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheTelemetryV2 {\n\treadonly exactHits: number;\n\treadonly semanticHits: number;\n\treadonly pointerHits: number;\n\treadonly misses: number;\n\treadonly staleRejects: number;\n\treadonly poisonRejects: number;\n\treadonly negativeHits: number;\n\treadonly writes: number;\n}\n\nexport interface ContextBudgetCacheTokenTelemetryV2 {\n\treadonly raw: number;\n\treadonly rendered: number;\n\treadonly savedByCache: number;\n\treadonly savedByCompression: number;\n\treadonly savedByOmission: number;\n}\n\nexport interface TokenCacheTelemetryV2 {\n\treadonly planCache: ContextBudgetPlanCacheTelemetryV2;\n\treadonly representationCache: ContextBudgetRepresentationCacheTelemetryV2;\n\treadonly tokens: ContextBudgetCacheTokenTelemetryV2;\n}\n\nexport interface PromptContextBudgetObservabilityV2 {\n\treadonly counts: ContextBudgetObservabilityCountsV2;\n\treadonly diagnosticReasons: readonly QualityDiagnosticReasonV2[];\n\treadonly tokens: ContextBudgetObservabilityTokensV2;\n\treadonly planHash: string;\n\treadonly cache: TokenCacheTelemetryV2;\n\treadonly tokenOptimizer: TokenOptimizerRuntimeStatus;\n}\n\nexport interface PromptContextBudgetPlanV2 {\n\treadonly policyVersion: string;\n\treadonly promptHash?: string;\n\treadonly planHash: string;\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens: number;\n\treadonly safetyMarginTokens: number;\n\treadonly availableTokens: number;\n\treadonly usedTokens: number;\n\treadonly omittedTokens: number;\n\treadonly rawTokens: number;\n\treadonly tokenSavingsRatio: number;\n\treadonly emergency: boolean;\n\treadonly omittedHighPriority: boolean;\n\treadonly tierAllocations: readonly TierBudgetAllocationV2[];\n\treadonly selectedRepresentations: readonly SelectedRepresentationV2[];\n\treadonly includedItemIds: readonly string[];\n\treadonly omittedItemIds: readonly string[];\n\treadonly diagnostics: readonly QualityDiagnosticV2[];\n\treadonly retrievalFallbacks: readonly ContextSourceRefV2[];\n\treadonly observability: PromptContextBudgetObservabilityV2;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export declare function fsyncDirectorySync(path: string): void;
2
+ export declare function ensureDurableDirectorySync(path: string): void;
3
+ export declare function ensureDurableParentDirectorySync(path: string): void;
4
+ //# sourceMappingURL=durable-file-directory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durable-file-directory.d.ts","sourceRoot":"","sources":["../../src/core/durable-file-directory.ts"],"names":[],"mappings":"AAGA,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAQrD;AA4BD,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAuB7D;AAED,wBAAgB,gCAAgC,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAGnE","sourcesContent":["import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, rmdirSync, statSync } from \"node:fs\";\nimport { dirname } from \"node:path\";\n\nexport function fsyncDirectorySync(path: string): void {\n\tif (process.platform === \"win32\") return;\n\tconst fd = openSync(path, \"r\");\n\ttry {\n\t\tfsyncSync(fd);\n\t} finally {\n\t\tcloseSync(fd);\n\t}\n}\n\nfunction assertDirectorySync(path: string): void {\n\tif (!statSync(path).isDirectory()) throw new Error(`Durable directory path is not a directory: ${path}`);\n}\n\nfunction syncCreatedDirectoryParent(directory: string, created: boolean): void {\n\ttry {\n\t\tfsyncDirectorySync(dirname(directory));\n\t} catch (error) {\n\t\tif (!created) throw error;\n\t\tlet cleanupError: unknown;\n\t\ttry {\n\t\t\trmdirSync(directory);\n\t\t} catch (failure) {\n\t\t\tcleanupError = failure instanceof Error ? failure : new Error(String(failure));\n\t\t}\n\t\ttry {\n\t\t\tfsyncDirectorySync(dirname(directory));\n\t\t} catch (failure) {\n\t\t\tconst syncError = failure instanceof Error ? failure : new Error(String(failure));\n\t\t\tcleanupError = cleanupError ? new AggregateError([cleanupError, syncError]) : syncError;\n\t\t}\n\t\tif (cleanupError) throw new AggregateError([error, cleanupError], \"Durable directory cleanup failed\");\n\t\tthrow error;\n\t}\n}\n\nexport function ensureDurableDirectorySync(path: string): void {\n\tconst missing: string[] = [];\n\tlet cursor = path;\n\twhile (!existsSync(cursor)) {\n\t\tmissing.push(cursor);\n\t\tconst parent = dirname(cursor);\n\t\tif (parent === cursor) break;\n\t\tcursor = parent;\n\t}\n\tassertDirectorySync(cursor);\n\tsyncCreatedDirectoryParent(cursor, false);\n\tfor (const directory of missing.reverse()) {\n\t\tlet created = false;\n\t\ttry {\n\t\t\tmkdirSync(directory, { mode: 0o700 });\n\t\t\tcreated = true;\n\t\t} catch (error) {\n\t\t\tconst code = error instanceof Error && \"code\" in error ? Reflect.get(error, \"code\") : undefined;\n\t\t\tif (code !== \"EEXIST\") throw error;\n\t\t}\n\t\tassertDirectorySync(directory);\n\t\tsyncCreatedDirectoryParent(directory, created);\n\t}\n}\n\nexport function ensureDurableParentDirectorySync(path: string): void {\n\tconst parent = dirname(path);\n\tif (!existsSync(parent)) ensureDurableDirectorySync(parent);\n}\n"]}
@@ -0,0 +1,76 @@
1
+ import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, rmdirSync, statSync } from "node:fs";
2
+ import { dirname } from "node:path";
3
+ export function fsyncDirectorySync(path) {
4
+ if (process.platform === "win32")
5
+ return;
6
+ const fd = openSync(path, "r");
7
+ try {
8
+ fsyncSync(fd);
9
+ }
10
+ finally {
11
+ closeSync(fd);
12
+ }
13
+ }
14
+ function assertDirectorySync(path) {
15
+ if (!statSync(path).isDirectory())
16
+ throw new Error(`Durable directory path is not a directory: ${path}`);
17
+ }
18
+ function syncCreatedDirectoryParent(directory, created) {
19
+ try {
20
+ fsyncDirectorySync(dirname(directory));
21
+ }
22
+ catch (error) {
23
+ if (!created)
24
+ throw error;
25
+ let cleanupError;
26
+ try {
27
+ rmdirSync(directory);
28
+ }
29
+ catch (failure) {
30
+ cleanupError = failure instanceof Error ? failure : new Error(String(failure));
31
+ }
32
+ try {
33
+ fsyncDirectorySync(dirname(directory));
34
+ }
35
+ catch (failure) {
36
+ const syncError = failure instanceof Error ? failure : new Error(String(failure));
37
+ cleanupError = cleanupError ? new AggregateError([cleanupError, syncError]) : syncError;
38
+ }
39
+ if (cleanupError)
40
+ throw new AggregateError([error, cleanupError], "Durable directory cleanup failed");
41
+ throw error;
42
+ }
43
+ }
44
+ export function ensureDurableDirectorySync(path) {
45
+ const missing = [];
46
+ let cursor = path;
47
+ while (!existsSync(cursor)) {
48
+ missing.push(cursor);
49
+ const parent = dirname(cursor);
50
+ if (parent === cursor)
51
+ break;
52
+ cursor = parent;
53
+ }
54
+ assertDirectorySync(cursor);
55
+ syncCreatedDirectoryParent(cursor, false);
56
+ for (const directory of missing.reverse()) {
57
+ let created = false;
58
+ try {
59
+ mkdirSync(directory, { mode: 0o700 });
60
+ created = true;
61
+ }
62
+ catch (error) {
63
+ const code = error instanceof Error && "code" in error ? Reflect.get(error, "code") : undefined;
64
+ if (code !== "EEXIST")
65
+ throw error;
66
+ }
67
+ assertDirectorySync(directory);
68
+ syncCreatedDirectoryParent(directory, created);
69
+ }
70
+ }
71
+ export function ensureDurableParentDirectorySync(path) {
72
+ const parent = dirname(path);
73
+ if (!existsSync(parent))
74
+ ensureDurableDirectorySync(parent);
75
+ }
76
+ //# sourceMappingURL=durable-file-directory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durable-file-directory.js","sourceRoot":"","sources":["../../src/core/durable-file-directory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACrG,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAQ;IACtD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QAAE,OAAO;IACzC,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC/B,IAAI,CAAC;QACJ,SAAS,CAAC,EAAE,CAAC,CAAC;IACf,CAAC;YAAS,CAAC;QACV,SAAS,CAAC,EAAE,CAAC,CAAC;IACf,CAAC;AAAA,CACD;AAED,SAAS,mBAAmB,CAAC,IAAY,EAAQ;IAChD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,IAAI,EAAE,CAAC,CAAC;AAAA,CACzG;AAED,SAAS,0BAA0B,CAAC,SAAiB,EAAE,OAAgB,EAAQ;IAC9E,IAAI,CAAC;QACJ,kBAAkB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IACxC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,CAAC,OAAO;YAAE,MAAM,KAAK,CAAC;QAC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M,EAAE,KAAK,CAAC,CAAC;IAC1C,KAAK,MAAM,SAAS,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;QAC3C,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC;YACJ,SAAS,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;YACtC,OAAO,GAAG,IAAI,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,GAAG,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAChG,IAAI,IAAI,KAAK,QAAQ;gBAAE,MAAM,KAAK,CAAC;QACpC,CAAC;QACD,mBAAmB,CAAC,SAAS,CAAC,CAAC;QAC/B,0BAA0B,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;AAAA,CACD;AAED,MAAM,UAAU,gCAAgC,CAAC,IAAY,EAAQ;IACpE,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;QAAE,0BAA0B,CAAC,MAAM,CAAC,CAAC;AAAA,CAC5D","sourcesContent":["import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, rmdirSync, statSync } from \"node:fs\";\nimport { dirname } from \"node:path\";\n\nexport function fsyncDirectorySync(path: string): void {\n\tif (process.platform === \"win32\") return;\n\tconst fd = openSync(path, \"r\");\n\ttry {\n\t\tfsyncSync(fd);\n\t} finally {\n\t\tcloseSync(fd);\n\t}\n}\n\nfunction assertDirectorySync(path: string): void {\n\tif (!statSync(path).isDirectory()) throw new Error(`Durable directory path is not a directory: ${path}`);\n}\n\nfunction syncCreatedDirectoryParent(directory: string, created: boolean): void {\n\ttry {\n\t\tfsyncDirectorySync(dirname(directory));\n\t} catch (error) {\n\t\tif (!created) throw error;\n\t\tlet cleanupError: unknown;\n\t\ttry {\n\t\t\trmdirSync(directory);\n\t\t} catch (failure) {\n\t\t\tcleanupError = failure instanceof Error ? failure : new Error(String(failure));\n\t\t}\n\t\ttry {\n\t\t\tfsyncDirectorySync(dirname(directory));\n\t\t} catch (failure) {\n\t\t\tconst syncError = failure instanceof Error ? failure : new Error(String(failure));\n\t\t\tcleanupError = cleanupError ? new AggregateError([cleanupError, syncError]) : syncError;\n\t\t}\n\t\tif (cleanupError) throw new AggregateError([error, cleanupError], \"Durable directory cleanup failed\");\n\t\tthrow error;\n\t}\n}\n\nexport function ensureDurableDirectorySync(path: string): void {\n\tconst missing: string[] = [];\n\tlet cursor = path;\n\twhile (!existsSync(cursor)) {\n\t\tmissing.push(cursor);\n\t\tconst parent = dirname(cursor);\n\t\tif (parent === cursor) break;\n\t\tcursor = parent;\n\t}\n\tassertDirectorySync(cursor);\n\tsyncCreatedDirectoryParent(cursor, false);\n\tfor (const directory of missing.reverse()) {\n\t\tlet created = false;\n\t\ttry {\n\t\t\tmkdirSync(directory, { mode: 0o700 });\n\t\t\tcreated = true;\n\t\t} catch (error) {\n\t\t\tconst code = error instanceof Error && \"code\" in error ? Reflect.get(error, \"code\") : undefined;\n\t\t\tif (code !== \"EEXIST\") throw error;\n\t\t}\n\t\tassertDirectorySync(directory);\n\t\tsyncCreatedDirectoryParent(directory, created);\n\t}\n}\n\nexport function ensureDurableParentDirectorySync(path: string): void {\n\tconst parent = dirname(path);\n\tif (!existsSync(parent)) ensureDurableDirectorySync(parent);\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import { type DurableFileGeneration, type DurableFileIdentity, resolveDurableFileIdentity } from "./durable-file-io.ts";
2
+ import { DurableFileLockBusyError, DurableFileLockOwnershipError, getDurableFileLockRoot } from "./durable-file-lock-storage.ts";
3
+ export { DurableFileLockBusyError, DurableFileLockOwnershipError, getDurableFileLockRoot, resolveDurableFileIdentity };
4
+ export type { DurableFileGeneration, DurableFileIdentity };
5
+ export interface DurableFileLockOptions {
6
+ readonly timeoutMs?: number;
7
+ }
8
+ export interface DurableFileLock {
9
+ readonly identity: DurableFileIdentity;
10
+ transfer(path: string, options?: DurableFileLockOptions): void;
11
+ release(): void;
12
+ }
13
+ export type DurableFileLockObservation = {
14
+ readonly status: "absent";
15
+ } | {
16
+ readonly status: "live";
17
+ readonly pid: number;
18
+ readonly host: string;
19
+ } | {
20
+ readonly status: "unknown";
21
+ };
22
+ export declare function inspectDurableFileLockSync(path: string, scope: string): DurableFileLockObservation;
23
+ export declare function acquireDurableFileLockSync(path: string, scope: string, options?: DurableFileLockOptions): DurableFileLock;
24
+ export declare function acquireDurableFileMutationLockSync(path: string, options?: DurableFileLockOptions): DurableFileLock;
25
+ export declare function withDurableFileMutationLockSync<T>(path: string, fn: () => T): T;
26
+ //# sourceMappingURL=durable-file-identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durable-file-identity.d.ts","sourceRoot":"","sources":["../../src/core/durable-file-identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AACxH,OAAO,EAGN,wBAAwB,EACxB,6BAA6B,EAG7B,sBAAsB,EAKtB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,wBAAwB,EAAE,6BAA6B,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,CAAC;AACvH,YAAY,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,CAAC;AAE3D,MAAM,WAAW,sBAAsB;IACtC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,CAAC;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAC/D,OAAO,IAAI,IAAI,CAAC;CAChB;AAED,MAAM,MAAM,0BAA0B,GACnC;IAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAA;CAAE,GAC7B;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACxE;IAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;CAAE,CAAC;AAElC,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,0BAA0B,CAUlG;AA8ED,wBAAgB,0BAA0B,CACzC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,sBAA2B,GAClC,eAAe,CAqBjB;AAED,wBAAgB,kCAAkC,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,eAAe,CAElH;AAED,wBAAgB,+BAA+B,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAO/E","sourcesContent":["import { type DurableFileGeneration, type DurableFileIdentity, resolveDurableFileIdentity } from \"./durable-file-io.ts\";\nimport {\n\tacquireDurableFileLockPathSync,\n\tassertDurableFileLockPathsOwnedSync,\n\tDurableFileLockBusyError,\n\tDurableFileLockOwnershipError,\n\tdrainRetryableDurableFileLocksSync,\n\tdurableFileLockPath,\n\tgetDurableFileLockRoot,\n\ttype HeldDurableFileLock,\n\tinspectDurableFileLockPathSync,\n\treleaseDurableFileLockPathsSync,\n\tretainRetryableDurableFileLocks,\n} from \"./durable-file-lock-storage.ts\";\n\nexport { DurableFileLockBusyError, DurableFileLockOwnershipError, getDurableFileLockRoot, resolveDurableFileIdentity };\nexport type { DurableFileGeneration, DurableFileIdentity };\n\nexport interface DurableFileLockOptions {\n\treadonly timeoutMs?: number;\n}\n\nexport interface DurableFileLock {\n\treadonly identity: DurableFileIdentity;\n\ttransfer(path: string, options?: DurableFileLockOptions): void;\n\trelease(): void;\n}\n\nexport type DurableFileLockObservation =\n\t| { readonly status: \"absent\" }\n\t| { readonly status: \"live\"; readonly pid: number; readonly host: string }\n\t| { readonly status: \"unknown\" };\n\nexport function inspectDurableFileLockSync(path: string, scope: string): DurableFileLockObservation {\n\tdrainRetryableDurableFileLocksSync();\n\tconst deadline = Date.now();\n\tconst observations = resolveDurableFileIdentity(path).lockKeys.map((key) =>\n\t\tinspectDurableFileLockPathSync(durableFileLockPath(scope, key), deadline),\n\t);\n\treturn (\n\t\tobservations.find((value) => value.status === \"live\") ??\n\t\tobservations.find((value) => value.status === \"unknown\") ?? { status: \"absent\" }\n\t);\n}\n\nfunction lockTimeout(options: DurableFileLockOptions): number {\n\tconst timeoutMs = options.timeoutMs ?? 10_000;\n\tif (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0) throw new TypeError(\"Lock timeout must be non-negative\");\n\treturn timeoutMs;\n}\n\nfunction sameLockKeys(left: DurableFileIdentity, right: DurableFileIdentity): boolean {\n\treturn left.lockKeys.join(\"\\0\") === right.lockKeys.join(\"\\0\");\n}\n\nfunction rollbackAddedLocks(\n\theld: HeldDurableFileLock[],\n\tadded: readonly HeldDurableFileLock[],\n\tfailure: unknown,\n): never {\n\ttry {\n\t\treleaseDurableFileLockPathsSync(held, added);\n\t} catch (cleanupError) {\n\t\tretainRetryableDurableFileLocks(added);\n\t\tthrow new AggregateError([failure, cleanupError], \"Durable file lock acquisition cleanup failed\");\n\t}\n\tthrow failure;\n}\n\nfunction createLock(scope: string, identity: DurableFileIdentity, held: HeldDurableFileLock[]): DurableFileLock {\n\tlet currentIdentity = identity;\n\tlet released = false;\n\treturn {\n\t\tget identity() {\n\t\t\treturn currentIdentity;\n\t\t},\n\t\ttransfer(nextPath, options = {}) {\n\t\t\tif (released) throw new TypeError(\"Cannot transfer a released durable file lock\");\n\t\t\tassertDurableFileLockPathsOwnedSync(held);\n\t\t\tconst deadline = Date.now() + lockTimeout(options);\n\t\t\tfor (let attempt = 0; attempt < 4; attempt += 1) {\n\t\t\t\tconst nextIdentity = resolveDurableFileIdentity(nextPath);\n\t\t\t\tconst added: HeldDurableFileLock[] = [];\n\t\t\t\ttry {\n\t\t\t\t\tfor (const key of nextIdentity.lockKeys) {\n\t\t\t\t\t\tif (held.some((lock) => lock.key === key)) continue;\n\t\t\t\t\t\tconst lock = acquireDurableFileLockPathSync(key, durableFileLockPath(scope, key), deadline);\n\t\t\t\t\t\theld.push(lock);\n\t\t\t\t\t\tadded.push(lock);\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\trollbackAddedLocks(held, added, error instanceof Error ? error : new Error(String(error)));\n\t\t\t\t}\n\t\t\t\tconst stable = resolveDurableFileIdentity(nextPath);\n\t\t\t\tif (!sameLockKeys(stable, nextIdentity)) {\n\t\t\t\t\treleaseDurableFileLockPathsSync(held, added);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst retained = new Set(stable.lockKeys);\n\t\t\t\treleaseDurableFileLockPathsSync(\n\t\t\t\t\theld,\n\t\t\t\t\theld.filter((lock) => !retained.has(lock.key)),\n\t\t\t\t);\n\t\t\t\tcurrentIdentity = stable;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow new DurableFileLockBusyError();\n\t\t},\n\t\trelease() {\n\t\t\tif (released) return;\n\t\t\ttry {\n\t\t\t\treleaseDurableFileLockPathsSync(held, held);\n\t\t\t} catch (error) {\n\t\t\t\tretainRetryableDurableFileLocks(held);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treleased = true;\n\t\t},\n\t};\n}\n\nexport function acquireDurableFileLockSync(\n\tpath: string,\n\tscope: string,\n\toptions: DurableFileLockOptions = {},\n): DurableFileLock {\n\tdrainRetryableDurableFileLocksSync();\n\tconst deadline = Date.now() + lockTimeout(options);\n\tfor (let attempt = 0; attempt < 4; attempt += 1) {\n\t\tconst identity = resolveDurableFileIdentity(path);\n\t\tconst held: HeldDurableFileLock[] = [];\n\t\ttry {\n\t\t\tfor (const key of identity.lockKeys) {\n\t\t\t\theld.push(acquireDurableFileLockPathSync(key, durableFileLockPath(scope, key), deadline));\n\t\t\t}\n\t\t\tconst stable = resolveDurableFileIdentity(path);\n\t\t\tif (!sameLockKeys(stable, identity)) {\n\t\t\t\treleaseDurableFileLockPathsSync(held, held);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\treturn createLock(scope, stable, held);\n\t\t} catch (error) {\n\t\t\trollbackAddedLocks(held, held, error instanceof Error ? error : new Error(String(error)));\n\t\t}\n\t}\n\tthrow new DurableFileLockBusyError();\n}\n\nexport function acquireDurableFileMutationLockSync(path: string, options?: DurableFileLockOptions): DurableFileLock {\n\treturn acquireDurableFileLockSync(path, \"mutation\", options);\n}\n\nexport function withDurableFileMutationLockSync<T>(path: string, fn: () => T): T {\n\tconst lock = acquireDurableFileMutationLockSync(path);\n\ttry {\n\t\treturn fn();\n\t} finally {\n\t\tlock.release();\n\t}\n}\n"]}
@@ -0,0 +1,118 @@
1
+ import { resolveDurableFileIdentity } from "./durable-file-io.js";
2
+ import { acquireDurableFileLockPathSync, assertDurableFileLockPathsOwnedSync, DurableFileLockBusyError, DurableFileLockOwnershipError, drainRetryableDurableFileLocksSync, durableFileLockPath, getDurableFileLockRoot, inspectDurableFileLockPathSync, releaseDurableFileLockPathsSync, retainRetryableDurableFileLocks, } from "./durable-file-lock-storage.js";
3
+ export { DurableFileLockBusyError, DurableFileLockOwnershipError, getDurableFileLockRoot, resolveDurableFileIdentity };
4
+ export function inspectDurableFileLockSync(path, scope) {
5
+ drainRetryableDurableFileLocksSync();
6
+ const deadline = Date.now();
7
+ const observations = resolveDurableFileIdentity(path).lockKeys.map((key) => inspectDurableFileLockPathSync(durableFileLockPath(scope, key), deadline));
8
+ return (observations.find((value) => value.status === "live") ??
9
+ observations.find((value) => value.status === "unknown") ?? { status: "absent" });
10
+ }
11
+ function lockTimeout(options) {
12
+ const timeoutMs = options.timeoutMs ?? 10_000;
13
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0)
14
+ throw new TypeError("Lock timeout must be non-negative");
15
+ return timeoutMs;
16
+ }
17
+ function sameLockKeys(left, right) {
18
+ return left.lockKeys.join("\0") === right.lockKeys.join("\0");
19
+ }
20
+ function rollbackAddedLocks(held, added, failure) {
21
+ try {
22
+ releaseDurableFileLockPathsSync(held, added);
23
+ }
24
+ catch (cleanupError) {
25
+ retainRetryableDurableFileLocks(added);
26
+ throw new AggregateError([failure, cleanupError], "Durable file lock acquisition cleanup failed");
27
+ }
28
+ throw failure;
29
+ }
30
+ function createLock(scope, identity, held) {
31
+ let currentIdentity = identity;
32
+ let released = false;
33
+ return {
34
+ get identity() {
35
+ return currentIdentity;
36
+ },
37
+ transfer(nextPath, options = {}) {
38
+ if (released)
39
+ throw new TypeError("Cannot transfer a released durable file lock");
40
+ assertDurableFileLockPathsOwnedSync(held);
41
+ const deadline = Date.now() + lockTimeout(options);
42
+ for (let attempt = 0; attempt < 4; attempt += 1) {
43
+ const nextIdentity = resolveDurableFileIdentity(nextPath);
44
+ const added = [];
45
+ try {
46
+ for (const key of nextIdentity.lockKeys) {
47
+ if (held.some((lock) => lock.key === key))
48
+ continue;
49
+ const lock = acquireDurableFileLockPathSync(key, durableFileLockPath(scope, key), deadline);
50
+ held.push(lock);
51
+ added.push(lock);
52
+ }
53
+ }
54
+ catch (error) {
55
+ rollbackAddedLocks(held, added, error instanceof Error ? error : new Error(String(error)));
56
+ }
57
+ const stable = resolveDurableFileIdentity(nextPath);
58
+ if (!sameLockKeys(stable, nextIdentity)) {
59
+ releaseDurableFileLockPathsSync(held, added);
60
+ continue;
61
+ }
62
+ const retained = new Set(stable.lockKeys);
63
+ releaseDurableFileLockPathsSync(held, held.filter((lock) => !retained.has(lock.key)));
64
+ currentIdentity = stable;
65
+ return;
66
+ }
67
+ throw new DurableFileLockBusyError();
68
+ },
69
+ release() {
70
+ if (released)
71
+ return;
72
+ try {
73
+ releaseDurableFileLockPathsSync(held, held);
74
+ }
75
+ catch (error) {
76
+ retainRetryableDurableFileLocks(held);
77
+ throw error;
78
+ }
79
+ released = true;
80
+ },
81
+ };
82
+ }
83
+ export function acquireDurableFileLockSync(path, scope, options = {}) {
84
+ drainRetryableDurableFileLocksSync();
85
+ const deadline = Date.now() + lockTimeout(options);
86
+ for (let attempt = 0; attempt < 4; attempt += 1) {
87
+ const identity = resolveDurableFileIdentity(path);
88
+ const held = [];
89
+ try {
90
+ for (const key of identity.lockKeys) {
91
+ held.push(acquireDurableFileLockPathSync(key, durableFileLockPath(scope, key), deadline));
92
+ }
93
+ const stable = resolveDurableFileIdentity(path);
94
+ if (!sameLockKeys(stable, identity)) {
95
+ releaseDurableFileLockPathsSync(held, held);
96
+ continue;
97
+ }
98
+ return createLock(scope, stable, held);
99
+ }
100
+ catch (error) {
101
+ rollbackAddedLocks(held, held, error instanceof Error ? error : new Error(String(error)));
102
+ }
103
+ }
104
+ throw new DurableFileLockBusyError();
105
+ }
106
+ export function acquireDurableFileMutationLockSync(path, options) {
107
+ return acquireDurableFileLockSync(path, "mutation", options);
108
+ }
109
+ export function withDurableFileMutationLockSync(path, fn) {
110
+ const lock = acquireDurableFileMutationLockSync(path);
111
+ try {
112
+ return fn();
113
+ }
114
+ finally {
115
+ lock.release();
116
+ }
117
+ }
118
+ //# sourceMappingURL=durable-file-identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durable-file-identity.js","sourceRoot":"","sources":["../../src/core/durable-file-identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwD,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AACxH,OAAO,EACN,8BAA8B,EAC9B,mCAAmC,EACnC,wBAAwB,EACxB,6BAA6B,EAC7B,kCAAkC,EAClC,mBAAmB,EACnB,sBAAsB,EAEtB,8BAA8B,EAC9B,+BAA+B,EAC/B,+BAA+B,GAC/B,MAAM,gCAAgC,CAAC;AA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AAM,UAAU,+BAA+B,CAAI,IAAY,EAAE,EAAW,EAAK;IAChF,MAAM,IAAI,GAAG,kCAAkC,CAAC,IAAI,CAAC,CAAC;IACtD,IAAI,CAAC;QACJ,OAAO,EAAE,EAAE,CAAC;IACb,CAAC;YAAS,CAAC;QACV,IAAI,CAAC,OAAO,EAAE,CAAC;IAChB,CAAC;AAAA,CACD","sourcesContent":["import { type DurableFileGeneration, type DurableFileIdentity, resolveDurableFileIdentity } from \"./durable-file-io.ts\";\nimport {\n\tacquireDurableFileLockPathSync,\n\tassertDurableFileLockPathsOwnedSync,\n\tDurableFileLockBusyError,\n\tDurableFileLockOwnershipError,\n\tdrainRetryableDurableFileLocksSync,\n\tdurableFileLockPath,\n\tgetDurableFileLockRoot,\n\ttype HeldDurableFileLock,\n\tinspectDurableFileLockPathSync,\n\treleaseDurableFileLockPathsSync,\n\tretainRetryableDurableFileLocks,\n} from \"./durable-file-lock-storage.ts\";\n\nexport { DurableFileLockBusyError, DurableFileLockOwnershipError, getDurableFileLockRoot, resolveDurableFileIdentity };\nexport type { DurableFileGeneration, DurableFileIdentity };\n\nexport interface DurableFileLockOptions {\n\treadonly timeoutMs?: number;\n}\n\nexport interface DurableFileLock {\n\treadonly identity: DurableFileIdentity;\n\ttransfer(path: string, options?: DurableFileLockOptions): void;\n\trelease(): void;\n}\n\nexport type DurableFileLockObservation =\n\t| { readonly status: \"absent\" }\n\t| { readonly status: \"live\"; readonly pid: number; readonly host: string }\n\t| { readonly status: \"unknown\" };\n\nexport function inspectDurableFileLockSync(path: string, scope: string): DurableFileLockObservation {\n\tdrainRetryableDurableFileLocksSync();\n\tconst deadline = Date.now();\n\tconst observations = resolveDurableFileIdentity(path).lockKeys.map((key) =>\n\t\tinspectDurableFileLockPathSync(durableFileLockPath(scope, key), deadline),\n\t);\n\treturn (\n\t\tobservations.find((value) => value.status === \"live\") ??\n\t\tobservations.find((value) => value.status === \"unknown\") ?? { status: \"absent\" }\n\t);\n}\n\nfunction lockTimeout(options: DurableFileLockOptions): number {\n\tconst timeoutMs = options.timeoutMs ?? 10_000;\n\tif (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0) throw new TypeError(\"Lock timeout must be non-negative\");\n\treturn timeoutMs;\n}\n\nfunction sameLockKeys(left: DurableFileIdentity, right: DurableFileIdentity): boolean {\n\treturn left.lockKeys.join(\"\\0\") === right.lockKeys.join(\"\\0\");\n}\n\nfunction rollbackAddedLocks(\n\theld: HeldDurableFileLock[],\n\tadded: readonly HeldDurableFileLock[],\n\tfailure: unknown,\n): never {\n\ttry {\n\t\treleaseDurableFileLockPathsSync(held, added);\n\t} catch (cleanupError) {\n\t\tretainRetryableDurableFileLocks(added);\n\t\tthrow new AggregateError([failure, cleanupError], \"Durable file lock acquisition cleanup failed\");\n\t}\n\tthrow failure;\n}\n\nfunction createLock(scope: string, identity: DurableFileIdentity, held: HeldDurableFileLock[]): DurableFileLock {\n\tlet currentIdentity = identity;\n\tlet released = false;\n\treturn {\n\t\tget identity() {\n\t\t\treturn currentIdentity;\n\t\t},\n\t\ttransfer(nextPath, options = {}) {\n\t\t\tif (released) throw new TypeError(\"Cannot transfer a released durable file lock\");\n\t\t\tassertDurableFileLockPathsOwnedSync(held);\n\t\t\tconst deadline = Date.now() + lockTimeout(options);\n\t\t\tfor (let attempt = 0; attempt < 4; attempt += 1) {\n\t\t\t\tconst nextIdentity = resolveDurableFileIdentity(nextPath);\n\t\t\t\tconst added: HeldDurableFileLock[] = [];\n\t\t\t\ttry {\n\t\t\t\t\tfor (const key of nextIdentity.lockKeys) {\n\t\t\t\t\t\tif (held.some((lock) => lock.key === key)) continue;\n\t\t\t\t\t\tconst lock = acquireDurableFileLockPathSync(key, durableFileLockPath(scope, key), deadline);\n\t\t\t\t\t\theld.push(lock);\n\t\t\t\t\t\tadded.push(lock);\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\trollbackAddedLocks(held, added, error instanceof Error ? error : new Error(String(error)));\n\t\t\t\t}\n\t\t\t\tconst stable = resolveDurableFileIdentity(nextPath);\n\t\t\t\tif (!sameLockKeys(stable, nextIdentity)) {\n\t\t\t\t\treleaseDurableFileLockPathsSync(held, added);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst retained = new Set(stable.lockKeys);\n\t\t\t\treleaseDurableFileLockPathsSync(\n\t\t\t\t\theld,\n\t\t\t\t\theld.filter((lock) => !retained.has(lock.key)),\n\t\t\t\t);\n\t\t\t\tcurrentIdentity = stable;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthrow new DurableFileLockBusyError();\n\t\t},\n\t\trelease() {\n\t\t\tif (released) return;\n\t\t\ttry {\n\t\t\t\treleaseDurableFileLockPathsSync(held, held);\n\t\t\t} catch (error) {\n\t\t\t\tretainRetryableDurableFileLocks(held);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treleased = true;\n\t\t},\n\t};\n}\n\nexport function acquireDurableFileLockSync(\n\tpath: string,\n\tscope: string,\n\toptions: DurableFileLockOptions = {},\n): DurableFileLock {\n\tdrainRetryableDurableFileLocksSync();\n\tconst deadline = Date.now() + lockTimeout(options);\n\tfor (let attempt = 0; attempt < 4; attempt += 1) {\n\t\tconst identity = resolveDurableFileIdentity(path);\n\t\tconst held: HeldDurableFileLock[] = [];\n\t\ttry {\n\t\t\tfor (const key of identity.lockKeys) {\n\t\t\t\theld.push(acquireDurableFileLockPathSync(key, durableFileLockPath(scope, key), deadline));\n\t\t\t}\n\t\t\tconst stable = resolveDurableFileIdentity(path);\n\t\t\tif (!sameLockKeys(stable, identity)) {\n\t\t\t\treleaseDurableFileLockPathsSync(held, held);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\treturn createLock(scope, stable, held);\n\t\t} catch (error) {\n\t\t\trollbackAddedLocks(held, held, error instanceof Error ? error : new Error(String(error)));\n\t\t}\n\t}\n\tthrow new DurableFileLockBusyError();\n}\n\nexport function acquireDurableFileMutationLockSync(path: string, options?: DurableFileLockOptions): DurableFileLock {\n\treturn acquireDurableFileLockSync(path, \"mutation\", options);\n}\n\nexport function withDurableFileMutationLockSync<T>(path: string, fn: () => T): T {\n\tconst lock = acquireDurableFileMutationLockSync(path);\n\ttry {\n\t\treturn fn();\n\t} finally {\n\t\tlock.release();\n\t}\n}\n"]}
@@ -0,0 +1,29 @@
1
+ export { ensureDurableDirectorySync, ensureDurableParentDirectorySync, fsyncDirectorySync, } from "./durable-file-directory.ts";
2
+ export interface DurableFileGeneration {
3
+ readonly dev: string;
4
+ readonly ino: string;
5
+ readonly birthtimeNs: string;
6
+ readonly ctimeNs: string;
7
+ }
8
+ export interface DurableFileIdentity {
9
+ readonly canonicalPath: string;
10
+ readonly generation: DurableFileGeneration | null;
11
+ readonly pathKey: string;
12
+ readonly aliasKey: string;
13
+ readonly lockKeys: readonly string[];
14
+ }
15
+ export interface DurableFileSnapshot {
16
+ readonly bytes: Uint8Array;
17
+ readonly generation: DurableFileGeneration;
18
+ }
19
+ export declare class DurableFileReadRaceError extends Error {
20
+ constructor();
21
+ }
22
+ export declare function normalizeDurablePathIdentity(path: string, platform: NodeJS.Platform): string;
23
+ export declare function resolveDurableFileIdentity(path: string): DurableFileIdentity;
24
+ export declare function sameDurableFileGeneration(left: DurableFileGeneration | null, right: DurableFileGeneration | null): boolean;
25
+ export declare function readDurableFileSnapshot(path: string): DurableFileSnapshot | null;
26
+ /** Append without truncation. On an indeterminate fsync failure, visible bytes are retained. */
27
+ export declare function appendFileDurablySync(path: string, bytes: Uint8Array): void;
28
+ export declare function writeExclusiveFileDurablySync(path: string, bytes: Uint8Array): void;
29
+ //# sourceMappingURL=durable-file-io.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"durable-file-io.d.ts","sourceRoot":"","sources":["../../src/core/durable-file-io.ts"],"names":[],"mappings":"AAkBA,OAAO,EACN,0BAA0B,EAC1B,gCAAgC,EAChC,kBAAkB,GAClB,MAAM,6BAA6B,CAAC;AAErC,MAAM,WAAW,qBAAqB;IACrC,QAAQ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IntStats,\n\tcloseSync,\n\texistsSync,\n\tfstatSync,\n\tfsyncSync,\n\topenSync,\n\treadFileSync,\n\trealpathSync,\n\tstatSync,\n\tunlinkSync,\n\twriteSync,\n} from \"node:fs\";\nimport { basename, dirname, resolve } from \"node:path\";\nimport { ensureDurableParentDirectorySync, fsyncDirectorySync } from \"./durable-file-directory.ts\";\nimport { enforcePrivateFileDescriptorModeSync } from \"./durable-file-mode.ts\";\n\nexport {\n\tensureDurableDirectorySync,\n\tensureDurableParentDirectorySync,\n\tfsyncDirectorySync,\n} from \"./durable-file-directory.ts\";\n\nexport interface DurableFileGeneration {\n\treadonly dev: string;\n\treadonly ino: string;\n\treadonly birthtimeNs: string;\n\treadonly ctimeNs: string;\n}\n\nexport interface DurableFileIdentity {\n\treadonly canonicalPath: string;\n\treadonly generation: DurableFileGeneration | null;\n\treadonly pathKey: string;\n\treadonly aliasKey: string;\n\treadonly lockKeys: readonly string[];\n}\n\nexport interface DurableFileSnapshot {\n\treadonly bytes: Uint8Array;\n\treadonly generation: DurableFileGeneration;\n}\n\nexport class DurableFileReadRaceError extends Error {\n\tconstructor() {\n\t\tsuper(\"Durable file identity or bytes changed while being read\");\n\t\tthis.name = \"DurableFileReadRaceError\";\n\t}\n}\n\nfunction generation(stat: BigIntStats): DurableFileGeneration {\n\treturn Object.freeze({\n\t\tdev: stat.dev.toString(),\n\t\tino: stat.ino.toString(),\n\t\tbirthtimeNs: stat.birthtimeNs.toString(),\n\t\tctimeNs: stat.ctimeNs.toString(),\n\t});\n}\n\nexport function normalizeDurablePathIdentity(path: string, platform: NodeJS.Platform): string {\n\tif (platform === \"darwin\") return path.normalize(\"NFD\").toLowerCase();\n\tif (platform === \"win32\") return path.normalize(\"NFC\").toLowerCase();\n\treturn path;\n}\n\nfunction canonicalizePath(path: string): string {\n\tconst requested = resolve(path);\n\tlet cursor = requested;\n\tconst tail: string[] = [];\n\twhile (true) {\n\t\ttry {\n\t\t\treturn resolve(realpathSync.native(cursor), ...tail);\n\t\t} catch (error) {\n\t\t\tconst code = error instanceof Error && \"code\" in error ? Reflect.get(error, \"code\") : undefined;\n\t\t\tif (code !== \"ENOENT\" && code !== \"ENOTDIR\") throw error;\n\t\t\tconst parent = dirname(cursor);\n\t\t\tif (parent === cursor) return requested;\n\t\t\ttail.unshift(basename(cursor));\n\t\t\tcursor = parent;\n\t\t}\n\t}\n}\n\nexport function resolveDurableFileIdentity(path: string): DurableFileIdentity {\n\tconst canonicalPath = canonicalizePath(path);\n\tlet fileGeneration: DurableFileGeneration | null = null;\n\ttry {\n\t\tfileGeneration = generation(statSync(path, { bigint: true }));\n\t} catch (error) {\n\t\tconst code = error instanceof Error && \"code\" in error ? Reflect.get(error, \"code\") : undefined;\n\t\tif (code !== \"ENOENT\" && code !== \"ENOTDIR\") throw error;\n\t}\n\tconst lockPathIdentity = normalizeDurablePathIdentity(canonicalPath, process.platform);\n\tconst pathKey = createHash(\"sha256\").update(`path\\0${lockPathIdentity}`, \"utf8\").digest(\"hex\");\n\tconst aliasKey = fileGeneration\n\t\t? createHash(\"sha256\")\n\t\t\t\t.update(`inode\\0${fileGeneration.dev}\\0${fileGeneration.ino}\\0${fileGeneration.birthtimeNs}`, \"utf8\")\n\t\t\t\t.digest(\"hex\")\n\t\t: pathKey;\n\treturn Object.freeze({\n\t\tcanonicalPath,\n\t\tgeneration: fileGeneration,\n\t\tpathKey,\n\t\taliasKey,\n\t\tlockKeys: Object.freeze([...new Set([pathKey, aliasKey])].sort()),\n\t});\n}\n\nexport function sameDurableFileGeneration(\n\tleft: DurableFileGeneration | null,\n\tright: DurableFileGeneration | null,\n): boolean {\n\tif (left === null || right === null) return left === right;\n\treturn (\n\t\tleft.dev === right.dev &&\n\t\tleft.ino === right.ino &&\n\t\tleft.birthtimeNs === right.birthtimeNs &&\n\t\tleft.ctimeNs === right.ctimeNs\n\t);\n}\n\nexport function readDurableFileSnapshot(path: string): DurableFileSnapshot | null {\n\tlet fd: number;\n\ttry {\n\t\tfd = openSync(path, \"r\");\n\t} catch (error) {\n\t\tif (error instanceof Error && \"code\" in error && Reflect.get(error, \"code\") === \"ENOENT\") return null;\n\t\tthrow error;\n\t}\n\ttry {\n\t\tenforcePrivateFileDescriptorModeSync(fd, path);\n\t\tconst before = fstatSync(fd, { bigint: true });\n\t\tconst bytes: Uint8Array = readFileSync(fd);\n\t\tconst after = fstatSync(fd, { bigint: true });\n\t\tlet current: BigIntStats;\n\t\ttry {\n\t\t\tcurrent = statSync(path, { bigint: true });\n\t\t} catch {\n\t\t\tthrow new DurableFileReadRaceError();\n\t\t}\n\t\tif (\n\t\t\tbefore.dev !== after.dev ||\n\t\t\tbefore.ino !== after.ino ||\n\t\t\tbefore.size !== after.size ||\n\t\t\tbefore.mtimeNs !== after.mtimeNs ||\n\t\t\tbefore.ctimeNs !== after.ctimeNs ||\n\t\t\tbefore.dev !== current.dev ||\n\t\t\tbefore.ino !== current.ino ||\n\t\t\tbefore.size !== current.size ||\n\t\t\tbefore.mtimeNs !== current.mtimeNs ||\n\t\t\tbefore.ctimeNs !== current.ctimeNs ||\n\t\t\tbefore.birthtimeNs !== current.birthtimeNs\n\t\t) {\n\t\t\tthrow new DurableFileReadRaceError();\n\t\t}\n\t\treturn Object.freeze({ bytes, generation: generation(before) });\n\t} finally {\n\t\tcloseSync(fd);\n\t}\n}\n\nfunction writeAll(fd: number, bytes: Uint8Array): void {\n\tlet offset = 0;\n\twhile (offset < bytes.byteLength) {\n\t\toffset += writeSync(fd, bytes, offset, bytes.byteLength - offset);\n\t}\n}\n\n/** Append without truncation. On an indeterminate fsync failure, visible bytes are retained. */\nexport function appendFileDurablySync(path: string, bytes: Uint8Array): void {\n\tensureDurableParentDirectorySync(path);\n\tconst existed = existsSync(path);\n\tconst fd = openSync(path, \"a\", 0o600);\n\ttry {\n\t\tenforcePrivateFileDescriptorModeSync(fd, path);\n\t\twriteAll(fd, bytes);\n\t\tfsyncSync(fd);\n\t} finally {\n\t\tcloseSync(fd);\n\t}\n\tif (!existed) fsyncDirectorySync(dirname(path));\n}\n\nexport function writeExclusiveFileDurablySync(path: string, bytes: Uint8Array): void {\n\tensureDurableParentDirectorySync(path);\n\tconst fd = openSync(path, \"wx\", 0o600);\n\ttry {\n\t\tenforcePrivateFileDescriptorModeSync(fd, path);\n\t\twriteAll(fd, bytes);\n\t\tfsyncSync(fd);\n\t} catch (error) {\n\t\tcloseSync(fd);\n\t\ttry {\n\t\t\tunlinkSync(path);\n\t\t\tfsyncDirectorySync(dirname(path));\n\t\t} catch (cleanupError) {\n\t\t\tthrow new AggregateError([error, cleanupError], \"Exclusive durable file cleanup failed\");\n\t\t}\n\t\tthrow error;\n\t}\n\tcloseSync(fd);\n\ttry {\n\t\tfsyncDirectorySync(dirname(path));\n\t} catch (error) {\n\t\ttry {\n\t\t\tunlinkSync(path);\n\t\t\tfsyncDirectorySync(dirname(path));\n\t\t} catch (cleanupError) {\n\t\t\tthrow new AggregateError([error, cleanupError], \"Exclusive durable file rollback failed\");\n\t\t}\n\t\tthrow error;\n\t}\n}\n"]}