agentfootprint 19.0.0 → 20.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (576) hide show
  1. package/CAPABILITIES.md +3 -0
  2. package/README.md +3 -10
  3. package/dist/adapters/observability/auditShapes/events/decisions.js +26 -0
  4. package/dist/adapters/observability/auditShapes/events/decisions.js.map +1 -1
  5. package/dist/answer-account/facts/calls.js +26 -7
  6. package/dist/answer-account/facts/calls.js.map +1 -1
  7. package/dist/answer-account/facts/understood.js +3 -1
  8. package/dist/answer-account/facts/understood.js.map +1 -1
  9. package/dist/core/agent/assessment/gather/stage.js +1 -1
  10. package/dist/core/agent/assessment/gather/stage.js.map +1 -1
  11. package/dist/core/agent/assessment/periodRows.js +7 -11
  12. package/dist/core/agent/assessment/periodRows.js.map +1 -1
  13. package/dist/core/agent/assessment/reasonClasses.js +28 -1
  14. package/dist/core/agent/assessment/reasonClasses.js.map +1 -1
  15. package/dist/core/agent/assessment/resultEvidence.js +8 -5
  16. package/dist/core/agent/assessment/resultEvidence.js.map +1 -1
  17. package/dist/core/agent/assessment/results/coverage/declarations.js +28 -0
  18. package/dist/core/agent/assessment/results/coverage/declarations.js.map +1 -0
  19. package/dist/core/agent/assessment/results/stage.js +1 -1
  20. package/dist/core/agent/assessment/results/stage.js.map +1 -1
  21. package/dist/core/agent/assessment/settledResults.js +4 -2
  22. package/dist/core/agent/assessment/settledResults.js.map +1 -1
  23. package/dist/core/agent/assessment/standingAdmission.js +14 -2
  24. package/dist/core/agent/assessment/standingAdmission.js.map +1 -1
  25. package/dist/core/agent/assistantReplay.js +10 -6
  26. package/dist/core/agent/assistantReplay.js.map +1 -1
  27. package/dist/core/agent/buildToolRegistry.js +21 -2
  28. package/dist/core/agent/buildToolRegistry.js.map +1 -1
  29. package/dist/core/agent/emptiness.js +6 -1
  30. package/dist/core/agent/emptiness.js.map +1 -1
  31. package/dist/core/agent/recordedCalls/resultDispositions.js +9 -1
  32. package/dist/core/agent/recordedCalls/resultDispositions.js.map +1 -1
  33. package/dist/core/agent/recordedCalls/resultRewriteIndex.js +40 -0
  34. package/dist/core/agent/recordedCalls/resultRewriteIndex.js.map +1 -0
  35. package/dist/core/agent/recordedCalls.js +3 -1
  36. package/dist/core/agent/recordedCalls.js.map +1 -1
  37. package/dist/core/agent/runtime/catalog/buildCatalog.js +6 -1
  38. package/dist/core/agent/runtime/catalog/buildCatalog.js.map +1 -1
  39. package/dist/core/agent/runtime/chart/chartDependencies.js +1 -0
  40. package/dist/core/agent/runtime/chart/chartDependencies.js.map +1 -1
  41. package/dist/core/agent/runtime/chart/owner.js +7 -1
  42. package/dist/core/agent/runtime/chart/owner.js.map +1 -1
  43. package/dist/core/agent/runtime/configuration/configure.js +2 -0
  44. package/dist/core/agent/runtime/configuration/configure.js.map +1 -1
  45. package/dist/core/agent/runtime/configuration/values.js.map +1 -1
  46. package/dist/core/agent/runtime/conversation/owner.js +2 -1
  47. package/dist/core/agent/runtime/conversation/owner.js.map +1 -1
  48. package/dist/core/agent/runtime/request/factory.js +4 -0
  49. package/dist/core/agent/runtime/request/factory.js.map +1 -1
  50. package/dist/core/agent/runtime/skills/owner.js +14 -5
  51. package/dist/core/agent/runtime/skills/owner.js.map +1 -1
  52. package/dist/core/agent/runtime/slots/buildSlots.js +9 -0
  53. package/dist/core/agent/runtime/slots/buildSlots.js.map +1 -1
  54. package/dist/core/agent/runtime/toolCalls/factory.js +4 -0
  55. package/dist/core/agent/runtime/toolCalls/factory.js.map +1 -1
  56. package/dist/core/agent/skillContext/apply.js +45 -0
  57. package/dist/core/agent/skillContext/apply.js.map +1 -0
  58. package/dist/core/agent/skillContext/bodies.js +42 -0
  59. package/dist/core/agent/skillContext/bodies.js.map +1 -0
  60. package/dist/core/agent/skillContext/decide.js +88 -0
  61. package/dist/core/agent/skillContext/decide.js.map +1 -0
  62. package/dist/core/agent/skillContext/gate.js +42 -0
  63. package/dist/core/agent/skillContext/gate.js.map +1 -0
  64. package/dist/core/agent/skillContext/honestyView.js +37 -0
  65. package/dist/core/agent/skillContext/honestyView.js.map +1 -0
  66. package/dist/core/agent/stages/callLLM/prepareCall.js +2 -0
  67. package/dist/core/agent/stages/callLLM/prepareCall.js.map +1 -1
  68. package/dist/core/agent/stages/prepareFinal.js +35 -33
  69. package/dist/core/agent/stages/prepareFinal.js.map +1 -1
  70. package/dist/core/agent/stages/route.js +2 -2
  71. package/dist/core/agent/stages/route.js.map +1 -1
  72. package/dist/core/agent/stages/toolCalls/evidence/towers.js +5 -1
  73. package/dist/core/agent/stages/toolCalls/evidence/towers.js.map +1 -1
  74. package/dist/core/agent/stages/toolCalls/execution/callStart.js +7 -1
  75. package/dist/core/agent/stages/toolCalls/execution/callStart.js.map +1 -1
  76. package/dist/core/agent/stages/toolCalls/execution/catalogOperations.js +1 -4
  77. package/dist/core/agent/stages/toolCalls/execution/catalogOperations.js.map +1 -1
  78. package/dist/core/agent/stages/toolCalls/execution/dispatchCall.js +2 -0
  79. package/dist/core/agent/stages/toolCalls/execution/dispatchCall.js.map +1 -1
  80. package/dist/core/agent/stages/toolCalls/execution/finalizeCallResult.js +28 -2
  81. package/dist/core/agent/stages/toolCalls/execution/finalizeCallResult.js.map +1 -1
  82. package/dist/core/agent/stages/window.js +9 -0
  83. package/dist/core/agent/stages/window.js.map +1 -1
  84. package/dist/core/agent/types/skillContext.js +7 -0
  85. package/dist/core/agent/types/skillContext.js.map +1 -0
  86. package/dist/core/agent/types.js +0 -1
  87. package/dist/core/agent/types.js.map +1 -1
  88. package/dist/core/agent/window/turns.js +3 -0
  89. package/dist/core/agent/window/turns.js.map +1 -1
  90. package/dist/core/slots/buildMessagesSlot.js +11 -1
  91. package/dist/core/slots/buildMessagesSlot.js.map +1 -1
  92. package/dist/core/slots/buildToolsSlot.js +1 -4
  93. package/dist/core/slots/buildToolsSlot.js.map +1 -1
  94. package/dist/core/slots/composeSkillCatalog.js +23 -1
  95. package/dist/core/slots/composeSkillCatalog.js.map +1 -1
  96. package/dist/esm/adapters/observability/auditShapes/events/decisions.js +26 -0
  97. package/dist/esm/adapters/observability/auditShapes/events/decisions.js.map +1 -1
  98. package/dist/esm/answer-account/facts/calls.js +27 -8
  99. package/dist/esm/answer-account/facts/calls.js.map +1 -1
  100. package/dist/esm/answer-account/facts/understood.js +3 -1
  101. package/dist/esm/answer-account/facts/understood.js.map +1 -1
  102. package/dist/esm/answer-account/types.d.ts +6 -0
  103. package/dist/esm/core/agent/assessment/gather/stage.js +1 -1
  104. package/dist/esm/core/agent/assessment/gather/stage.js.map +1 -1
  105. package/dist/esm/core/agent/assessment/periodRows.d.ts +1 -3
  106. package/dist/esm/core/agent/assessment/periodRows.js +4 -9
  107. package/dist/esm/core/agent/assessment/periodRows.js.map +1 -1
  108. package/dist/esm/core/agent/assessment/reasonClasses.d.ts +9 -0
  109. package/dist/esm/core/agent/assessment/reasonClasses.js +25 -0
  110. package/dist/esm/core/agent/assessment/reasonClasses.js.map +1 -1
  111. package/dist/esm/core/agent/assessment/resultEvidence.d.ts +1 -0
  112. package/dist/esm/core/agent/assessment/resultEvidence.js +9 -6
  113. package/dist/esm/core/agent/assessment/resultEvidence.js.map +1 -1
  114. package/dist/esm/core/agent/assessment/results/coverage/declarations.d.ts +16 -0
  115. package/dist/esm/core/agent/assessment/results/coverage/declarations.js +22 -0
  116. package/dist/esm/core/agent/assessment/results/coverage/declarations.js.map +1 -0
  117. package/dist/esm/core/agent/assessment/results/stage.js +1 -1
  118. package/dist/esm/core/agent/assessment/results/stage.js.map +1 -1
  119. package/dist/esm/core/agent/assessment/settledResults.js +4 -2
  120. package/dist/esm/core/agent/assessment/settledResults.js.map +1 -1
  121. package/dist/esm/core/agent/assessment/standingAdmission.d.ts +1 -0
  122. package/dist/esm/core/agent/assessment/standingAdmission.js +15 -3
  123. package/dist/esm/core/agent/assessment/standingAdmission.js.map +1 -1
  124. package/dist/esm/core/agent/assistantReplay.d.ts +8 -4
  125. package/dist/esm/core/agent/assistantReplay.js +10 -6
  126. package/dist/esm/core/agent/assistantReplay.js.map +1 -1
  127. package/dist/esm/core/agent/buildToolRegistry.d.ts +13 -0
  128. package/dist/esm/core/agent/buildToolRegistry.js +21 -2
  129. package/dist/esm/core/agent/buildToolRegistry.js.map +1 -1
  130. package/dist/esm/core/agent/chartContract.d.ts +2 -0
  131. package/dist/esm/core/agent/emptiness.d.ts +2 -0
  132. package/dist/esm/core/agent/emptiness.js +4 -0
  133. package/dist/esm/core/agent/emptiness.js.map +1 -1
  134. package/dist/esm/core/agent/evidence/types.d.ts +8 -0
  135. package/dist/esm/core/agent/recordedCalls/resultDispositions.d.ts +2 -0
  136. package/dist/esm/core/agent/recordedCalls/resultDispositions.js +7 -0
  137. package/dist/esm/core/agent/recordedCalls/resultDispositions.js.map +1 -1
  138. package/dist/esm/core/agent/recordedCalls/resultRewriteIndex.d.ts +11 -0
  139. package/dist/esm/core/agent/recordedCalls/resultRewriteIndex.js +36 -0
  140. package/dist/esm/core/agent/recordedCalls/resultRewriteIndex.js.map +1 -0
  141. package/dist/esm/core/agent/recordedCalls.d.ts +1 -0
  142. package/dist/esm/core/agent/recordedCalls.js +1 -0
  143. package/dist/esm/core/agent/recordedCalls.js.map +1 -1
  144. package/dist/esm/core/agent/runtime/catalog/buildCatalog.d.ts +1 -0
  145. package/dist/esm/core/agent/runtime/catalog/buildCatalog.js +6 -1
  146. package/dist/esm/core/agent/runtime/catalog/buildCatalog.js.map +1 -1
  147. package/dist/esm/core/agent/runtime/chart/chartDependencies.d.ts +1 -0
  148. package/dist/esm/core/agent/runtime/chart/chartDependencies.js +1 -0
  149. package/dist/esm/core/agent/runtime/chart/chartDependencies.js.map +1 -1
  150. package/dist/esm/core/agent/runtime/chart/owner.js +7 -1
  151. package/dist/esm/core/agent/runtime/chart/owner.js.map +1 -1
  152. package/dist/esm/core/agent/runtime/configuration/configure.js +2 -0
  153. package/dist/esm/core/agent/runtime/configuration/configure.js.map +1 -1
  154. package/dist/esm/core/agent/runtime/configuration/model.d.ts +2 -0
  155. package/dist/esm/core/agent/runtime/configuration/values.d.ts +1 -0
  156. package/dist/esm/core/agent/runtime/configuration/values.js.map +1 -1
  157. package/dist/esm/core/agent/runtime/conversation/owner.js +2 -1
  158. package/dist/esm/core/agent/runtime/conversation/owner.js.map +1 -1
  159. package/dist/esm/core/agent/runtime/request/factory.js +4 -0
  160. package/dist/esm/core/agent/runtime/request/factory.js.map +1 -1
  161. package/dist/esm/core/agent/runtime/skills/owner.js +14 -5
  162. package/dist/esm/core/agent/runtime/skills/owner.js.map +1 -1
  163. package/dist/esm/core/agent/runtime/slots/buildSlots.js +9 -0
  164. package/dist/esm/core/agent/runtime/slots/buildSlots.js.map +1 -1
  165. package/dist/esm/core/agent/runtime/toolCalls/factory.d.ts +1 -0
  166. package/dist/esm/core/agent/runtime/toolCalls/factory.js +4 -0
  167. package/dist/esm/core/agent/runtime/toolCalls/factory.js.map +1 -1
  168. package/dist/esm/core/agent/skillContext/apply.d.ts +39 -0
  169. package/dist/esm/core/agent/skillContext/apply.js +40 -0
  170. package/dist/esm/core/agent/skillContext/apply.js.map +1 -0
  171. package/dist/esm/core/agent/skillContext/bodies.d.ts +25 -0
  172. package/dist/esm/core/agent/skillContext/bodies.js +36 -0
  173. package/dist/esm/core/agent/skillContext/bodies.js.map +1 -0
  174. package/dist/esm/core/agent/skillContext/decide.d.ts +33 -0
  175. package/dist/esm/core/agent/skillContext/decide.js +84 -0
  176. package/dist/esm/core/agent/skillContext/decide.js.map +1 -0
  177. package/dist/esm/core/agent/skillContext/gate.d.ts +32 -0
  178. package/dist/esm/core/agent/skillContext/gate.js +37 -0
  179. package/dist/esm/core/agent/skillContext/gate.js.map +1 -0
  180. package/dist/esm/core/agent/skillContext/honestyView.d.ts +6 -0
  181. package/dist/esm/core/agent/skillContext/honestyView.js +33 -0
  182. package/dist/esm/core/agent/skillContext/honestyView.js.map +1 -0
  183. package/dist/esm/core/agent/stages/callLLM/prepareCall.js +2 -0
  184. package/dist/esm/core/agent/stages/callLLM/prepareCall.js.map +1 -1
  185. package/dist/esm/core/agent/stages/callLLM/types.d.ts +7 -0
  186. package/dist/esm/core/agent/stages/finalStageContract.d.ts +14 -0
  187. package/dist/esm/core/agent/stages/prepareFinal.d.ts +3 -9
  188. package/dist/esm/core/agent/stages/prepareFinal.js +35 -33
  189. package/dist/esm/core/agent/stages/prepareFinal.js.map +1 -1
  190. package/dist/esm/core/agent/stages/route.js +2 -2
  191. package/dist/esm/core/agent/stages/route.js.map +1 -1
  192. package/dist/esm/core/agent/stages/toolCalls/contracts/catalog.d.ts +9 -0
  193. package/dist/esm/core/agent/stages/toolCalls/evidence/towers.js +5 -1
  194. package/dist/esm/core/agent/stages/toolCalls/evidence/towers.js.map +1 -1
  195. package/dist/esm/core/agent/stages/toolCalls/execution/callStart.d.ts +1 -1
  196. package/dist/esm/core/agent/stages/toolCalls/execution/callStart.js +7 -1
  197. package/dist/esm/core/agent/stages/toolCalls/execution/callStart.js.map +1 -1
  198. package/dist/esm/core/agent/stages/toolCalls/execution/catalogOperations.js +2 -5
  199. package/dist/esm/core/agent/stages/toolCalls/execution/catalogOperations.js.map +1 -1
  200. package/dist/esm/core/agent/stages/toolCalls/execution/dispatchCall.js +2 -0
  201. package/dist/esm/core/agent/stages/toolCalls/execution/dispatchCall.js.map +1 -1
  202. package/dist/esm/core/agent/stages/toolCalls/execution/finalizeCallResult.d.ts +7 -0
  203. package/dist/esm/core/agent/stages/toolCalls/execution/finalizeCallResult.js +28 -2
  204. package/dist/esm/core/agent/stages/toolCalls/execution/finalizeCallResult.js.map +1 -1
  205. package/dist/esm/core/agent/stages/window.d.ts +6 -0
  206. package/dist/esm/core/agent/stages/window.js +9 -0
  207. package/dist/esm/core/agent/stages/window.js.map +1 -1
  208. package/dist/esm/core/agent/types/skillContext.d.ts +31 -0
  209. package/dist/esm/core/agent/types/skillContext.js +6 -0
  210. package/dist/esm/core/agent/types/skillContext.js.map +1 -0
  211. package/dist/esm/core/agent/types.d.ts +2 -2
  212. package/dist/esm/core/agent/types.js +0 -1
  213. package/dist/esm/core/agent/types.js.map +1 -1
  214. package/dist/esm/core/agent/window/turns.d.ts +6 -0
  215. package/dist/esm/core/agent/window/turns.js +3 -0
  216. package/dist/esm/core/agent/window/turns.js.map +1 -1
  217. package/dist/esm/core/agent/window/types.d.ts +7 -0
  218. package/dist/esm/core/slots/buildMessagesSlot.d.ts +7 -0
  219. package/dist/esm/core/slots/buildMessagesSlot.js +11 -1
  220. package/dist/esm/core/slots/buildMessagesSlot.js.map +1 -1
  221. package/dist/esm/core/slots/buildToolsSlot.d.ts +2 -0
  222. package/dist/esm/core/slots/buildToolsSlot.js +1 -4
  223. package/dist/esm/core/slots/buildToolsSlot.js.map +1 -1
  224. package/dist/esm/core/slots/composeSkillCatalog.d.ts +10 -1
  225. package/dist/esm/core/slots/composeSkillCatalog.js +23 -1
  226. package/dist/esm/core/slots/composeSkillCatalog.js.map +1 -1
  227. package/dist/esm/events/payloads/skillContext.d.ts +39 -0
  228. package/dist/esm/events/payloads/skillContext.js +8 -0
  229. package/dist/esm/events/payloads/skillContext.js.map +1 -0
  230. package/dist/esm/events/payloads/stream.d.ts +9 -0
  231. package/dist/esm/events/payloads.d.ts +1 -0
  232. package/dist/esm/injection-engine/skillContext.d.ts +92 -0
  233. package/dist/esm/injection-engine/skillContext.js +90 -0
  234. package/dist/esm/injection-engine/skillContext.js.map +1 -0
  235. package/dist/esm/injection-engine/skillToolDescriptors.js +9 -3
  236. package/dist/esm/injection-engine/skillToolDescriptors.js.map +1 -1
  237. package/dist/esm/injection-engine/skillTools.d.ts +7 -0
  238. package/dist/esm/injection-engine/skillTools.js +14 -1
  239. package/dist/esm/injection-engine/skillTools.js.map +1 -1
  240. package/dist/esm/injection-engine/types.d.ts +1 -1
  241. package/dist/esm/injection-engine/types.js +6 -6
  242. package/dist/esm/injection-engine/types.js.map +1 -1
  243. package/dist/esm/lib/spokenIds.d.ts +11 -0
  244. package/dist/esm/lib/spokenIds.js +13 -0
  245. package/dist/esm/lib/spokenIds.js.map +1 -1
  246. package/dist/esm/llm-ledger/build.d.ts +77 -0
  247. package/dist/esm/llm-ledger/build.js +344 -0
  248. package/dist/esm/llm-ledger/build.js.map +1 -0
  249. package/dist/esm/llm-ledger/calls.d.ts +30 -0
  250. package/dist/esm/llm-ledger/calls.js +244 -0
  251. package/dist/esm/llm-ledger/calls.js.map +1 -0
  252. package/dist/esm/llm-ledger/digest.d.ts +24 -0
  253. package/dist/esm/llm-ledger/digest.js +22 -0
  254. package/dist/esm/llm-ledger/digest.js.map +1 -0
  255. package/dist/esm/llm-ledger/entries.d.ts +37 -0
  256. package/dist/esm/llm-ledger/entries.js +291 -0
  257. package/dist/esm/llm-ledger/entries.js.map +1 -0
  258. package/dist/esm/llm-ledger/fileStore.d.ts +12 -0
  259. package/dist/esm/llm-ledger/fileStore.js +571 -0
  260. package/dist/esm/llm-ledger/fileStore.js.map +1 -0
  261. package/dist/esm/llm-ledger/ledger.d.ts +61 -0
  262. package/dist/esm/llm-ledger/ledger.js +48 -0
  263. package/dist/esm/llm-ledger/ledger.js.map +1 -0
  264. package/dist/esm/llm-ledger/limits.d.ts +77 -0
  265. package/dist/esm/llm-ledger/limits.js +76 -0
  266. package/dist/esm/llm-ledger/limits.js.map +1 -0
  267. package/dist/esm/llm-ledger/memoryStore.d.ts +3 -0
  268. package/dist/esm/llm-ledger/memoryStore.js +44 -0
  269. package/dist/esm/llm-ledger/memoryStore.js.map +1 -0
  270. package/dist/esm/llm-ledger/queue.d.ts +7 -0
  271. package/dist/esm/llm-ledger/queue.js +36 -0
  272. package/dist/esm/llm-ledger/queue.js.map +1 -0
  273. package/dist/esm/llm-ledger/reader.d.ts +29 -0
  274. package/dist/esm/llm-ledger/reader.js +47 -0
  275. package/dist/esm/llm-ledger/reader.js.map +1 -0
  276. package/dist/esm/llm-ledger/report.d.ts +82 -0
  277. package/dist/esm/llm-ledger/report.js +162 -0
  278. package/dist/esm/llm-ledger/report.js.map +1 -0
  279. package/dist/esm/llm-ledger/rules/cited.d.ts +10 -0
  280. package/dist/esm/llm-ledger/rules/cited.js +12 -0
  281. package/dist/esm/llm-ledger/rules/cited.js.map +1 -0
  282. package/dist/esm/llm-ledger/rules/port.d.ts +98 -0
  283. package/dist/esm/llm-ledger/rules/port.js +252 -0
  284. package/dist/esm/llm-ledger/rules/port.js.map +1 -0
  285. package/dist/esm/llm-ledger/rules/timeWindow.d.ts +2 -0
  286. package/dist/esm/llm-ledger/rules/timeWindow.js +94 -0
  287. package/dist/esm/llm-ledger/rules/timeWindow.js.map +1 -0
  288. package/dist/esm/llm-ledger/rules/traceableValues.d.ts +6 -0
  289. package/dist/esm/llm-ledger/rules/traceableValues.js +103 -0
  290. package/dist/esm/llm-ledger/rules/traceableValues.js.map +1 -0
  291. package/dist/esm/llm-ledger/serve.d.ts +21 -0
  292. package/dist/esm/llm-ledger/serve.js +105 -0
  293. package/dist/esm/llm-ledger/serve.js.map +1 -0
  294. package/dist/esm/llm-ledger/session.d.ts +6 -0
  295. package/dist/esm/llm-ledger/session.js +43 -0
  296. package/dist/esm/llm-ledger/session.js.map +1 -0
  297. package/dist/esm/llm-ledger/stages.d.ts +134 -0
  298. package/dist/esm/llm-ledger/stages.js +479 -0
  299. package/dist/esm/llm-ledger/stages.js.map +1 -0
  300. package/dist/esm/llm-ledger/store.d.ts +97 -0
  301. package/dist/esm/llm-ledger/store.js +208 -0
  302. package/dist/esm/llm-ledger/store.js.map +1 -0
  303. package/dist/esm/llm-ledger/tokens.d.ts +30 -0
  304. package/dist/esm/llm-ledger/tokens.js +319 -0
  305. package/dist/esm/llm-ledger/tokens.js.map +1 -0
  306. package/dist/esm/llm-ledger/types.d.ts +173 -0
  307. package/dist/esm/llm-ledger/types.js +2 -0
  308. package/dist/esm/llm-ledger/types.js.map +1 -0
  309. package/dist/esm/llm-ledger/window.d.ts +40 -0
  310. package/dist/esm/llm-ledger/window.js +66 -0
  311. package/dist/esm/llm-ledger/window.js.map +1 -0
  312. package/dist/esm/redaction/knownStrings/fields-0.d.ts +1 -1
  313. package/dist/esm/redaction/knownStrings/fields-0.js +1 -1
  314. package/dist/esm/redaction/knownStrings/fields-0.js.map +1 -1
  315. package/dist/esm/redaction/knownStrings/fields-1.d.ts +6 -6
  316. package/dist/esm/redaction/knownStrings/fields-1.js +6 -6
  317. package/dist/esm/redaction/knownStrings/fields-1.js.map +1 -1
  318. package/dist/esm/redaction/knownStrings/fields-2.d.ts +7 -0
  319. package/dist/esm/redaction/knownStrings/fields-2.js +7 -0
  320. package/dist/esm/redaction/knownStrings/fields-2.js.map +1 -1
  321. package/dist/esm/redaction/knownStrings/words-0.d.ts +1 -1
  322. package/dist/esm/redaction/knownStrings/words-0.js +1 -1
  323. package/dist/esm/redaction/knownStrings/words-0.js.map +1 -1
  324. package/dist/esm/redaction/knownStrings/words-1.d.ts +2 -2
  325. package/dist/esm/redaction/knownStrings/words-1.js +2 -2
  326. package/dist/esm/redaction/knownStrings/words-1.js.map +1 -1
  327. package/dist/esm/redaction/knownStrings/words-2.d.ts +3 -0
  328. package/dist/esm/redaction/knownStrings/words-2.js +3 -0
  329. package/dist/esm/redaction/knownStrings/words-2.js.map +1 -1
  330. package/dist/esm/trace-toolpack/traceToolpack/resultRewrite.d.ts +3 -0
  331. package/dist/esm/trace-toolpack/traceToolpack/resultRewrite.js +14 -0
  332. package/dist/esm/trace-toolpack/traceToolpack/resultRewrite.js.map +1 -0
  333. package/dist/esm/trace-toolpack/traceToolpack/toolCallJournal.d.ts +6 -5
  334. package/dist/esm/trace-toolpack/traceToolpack/toolCallJournal.js +12 -17
  335. package/dist/esm/trace-toolpack/traceToolpack/toolCallJournal.js.map +1 -1
  336. package/dist/esm/trace-toolpack/traceToolpack/toolCallOccurrence.d.ts +7 -0
  337. package/dist/esm/trace-toolpack/traceToolpack/toolCallOccurrence.js +19 -0
  338. package/dist/esm/trace-toolpack/traceToolpack/toolCallOccurrence.js.map +1 -1
  339. package/dist/events/payloads/skillContext.js +9 -0
  340. package/dist/events/payloads/skillContext.js.map +1 -0
  341. package/dist/injection-engine/skillContext.js +96 -0
  342. package/dist/injection-engine/skillContext.js.map +1 -0
  343. package/dist/injection-engine/skillToolDescriptors.js +9 -3
  344. package/dist/injection-engine/skillToolDescriptors.js.map +1 -1
  345. package/dist/injection-engine/skillTools.js +16 -2
  346. package/dist/injection-engine/skillTools.js.map +1 -1
  347. package/dist/injection-engine/types.js +6 -6
  348. package/dist/injection-engine/types.js.map +1 -1
  349. package/dist/lib/spokenIds.js +15 -1
  350. package/dist/lib/spokenIds.js.map +1 -1
  351. package/dist/llm-ledger/build.js +354 -0
  352. package/dist/llm-ledger/build.js.map +1 -0
  353. package/dist/llm-ledger/calls.js +248 -0
  354. package/dist/llm-ledger/calls.js.map +1 -0
  355. package/dist/llm-ledger/digest.js +28 -0
  356. package/dist/llm-ledger/digest.js.map +1 -0
  357. package/dist/llm-ledger/entries.js +308 -0
  358. package/dist/llm-ledger/entries.js.map +1 -0
  359. package/dist/llm-ledger/fileStore.js +575 -0
  360. package/dist/llm-ledger/fileStore.js.map +1 -0
  361. package/dist/llm-ledger/ledger.js +52 -0
  362. package/dist/llm-ledger/ledger.js.map +1 -0
  363. package/dist/llm-ledger/limits.js +79 -0
  364. package/dist/llm-ledger/limits.js.map +1 -0
  365. package/dist/llm-ledger/memoryStore.js +48 -0
  366. package/dist/llm-ledger/memoryStore.js.map +1 -0
  367. package/dist/llm-ledger/queue.js +40 -0
  368. package/dist/llm-ledger/queue.js.map +1 -0
  369. package/dist/llm-ledger/reader.js +51 -0
  370. package/dist/llm-ledger/reader.js.map +1 -0
  371. package/dist/llm-ledger/report.js +166 -0
  372. package/dist/llm-ledger/report.js.map +1 -0
  373. package/dist/llm-ledger/rules/cited.js +15 -0
  374. package/dist/llm-ledger/rules/cited.js.map +1 -0
  375. package/dist/llm-ledger/rules/port.js +261 -0
  376. package/dist/llm-ledger/rules/port.js.map +1 -0
  377. package/dist/llm-ledger/rules/timeWindow.js +97 -0
  378. package/dist/llm-ledger/rules/timeWindow.js.map +1 -0
  379. package/dist/llm-ledger/rules/traceableValues.js +107 -0
  380. package/dist/llm-ledger/rules/traceableValues.js.map +1 -0
  381. package/dist/llm-ledger/serve.js +111 -0
  382. package/dist/llm-ledger/serve.js.map +1 -0
  383. package/dist/llm-ledger/session.js +49 -0
  384. package/dist/llm-ledger/session.js.map +1 -0
  385. package/dist/llm-ledger/stages.js +497 -0
  386. package/dist/llm-ledger/stages.js.map +1 -0
  387. package/dist/llm-ledger/store.js +220 -0
  388. package/dist/llm-ledger/store.js.map +1 -0
  389. package/dist/llm-ledger/tokens.js +327 -0
  390. package/dist/llm-ledger/tokens.js.map +1 -0
  391. package/dist/llm-ledger/types.js +3 -0
  392. package/dist/llm-ledger/types.js.map +1 -0
  393. package/dist/llm-ledger/window.js +72 -0
  394. package/dist/llm-ledger/window.js.map +1 -0
  395. package/dist/redaction/knownStrings/fields-0.js +1 -1
  396. package/dist/redaction/knownStrings/fields-0.js.map +1 -1
  397. package/dist/redaction/knownStrings/fields-1.js +6 -6
  398. package/dist/redaction/knownStrings/fields-1.js.map +1 -1
  399. package/dist/redaction/knownStrings/fields-2.js +7 -0
  400. package/dist/redaction/knownStrings/fields-2.js.map +1 -1
  401. package/dist/redaction/knownStrings/words-0.js +1 -1
  402. package/dist/redaction/knownStrings/words-0.js.map +1 -1
  403. package/dist/redaction/knownStrings/words-1.js +2 -2
  404. package/dist/redaction/knownStrings/words-1.js.map +1 -1
  405. package/dist/redaction/knownStrings/words-2.js +3 -0
  406. package/dist/redaction/knownStrings/words-2.js.map +1 -1
  407. package/dist/trace-toolpack/traceToolpack/resultRewrite.js +18 -0
  408. package/dist/trace-toolpack/traceToolpack/resultRewrite.js.map +1 -0
  409. package/dist/trace-toolpack/traceToolpack/toolCallJournal.js +14 -19
  410. package/dist/trace-toolpack/traceToolpack/toolCallJournal.js.map +1 -1
  411. package/dist/trace-toolpack/traceToolpack/toolCallOccurrence.js +22 -1
  412. package/dist/trace-toolpack/traceToolpack/toolCallOccurrence.js.map +1 -1
  413. package/dist/types/adapters/observability/auditShapes/events/decisions.d.ts.map +1 -1
  414. package/dist/types/answer-account/facts/calls.d.ts.map +1 -1
  415. package/dist/types/answer-account/types.d.ts +6 -0
  416. package/dist/types/answer-account/types.d.ts.map +1 -1
  417. package/dist/types/core/agent/assessment/periodRows.d.ts +1 -3
  418. package/dist/types/core/agent/assessment/periodRows.d.ts.map +1 -1
  419. package/dist/types/core/agent/assessment/reasonClasses.d.ts +9 -0
  420. package/dist/types/core/agent/assessment/reasonClasses.d.ts.map +1 -1
  421. package/dist/types/core/agent/assessment/resultEvidence.d.ts +1 -0
  422. package/dist/types/core/agent/assessment/resultEvidence.d.ts.map +1 -1
  423. package/dist/types/core/agent/assessment/results/coverage/declarations.d.ts +17 -0
  424. package/dist/types/core/agent/assessment/results/coverage/declarations.d.ts.map +1 -0
  425. package/dist/types/core/agent/assessment/settledResults.d.ts.map +1 -1
  426. package/dist/types/core/agent/assessment/standingAdmission.d.ts +1 -0
  427. package/dist/types/core/agent/assessment/standingAdmission.d.ts.map +1 -1
  428. package/dist/types/core/agent/assistantReplay.d.ts +8 -4
  429. package/dist/types/core/agent/assistantReplay.d.ts.map +1 -1
  430. package/dist/types/core/agent/buildToolRegistry.d.ts +13 -0
  431. package/dist/types/core/agent/buildToolRegistry.d.ts.map +1 -1
  432. package/dist/types/core/agent/chartContract.d.ts +2 -0
  433. package/dist/types/core/agent/chartContract.d.ts.map +1 -1
  434. package/dist/types/core/agent/emptiness.d.ts +2 -0
  435. package/dist/types/core/agent/emptiness.d.ts.map +1 -1
  436. package/dist/types/core/agent/evidence/types.d.ts +8 -0
  437. package/dist/types/core/agent/evidence/types.d.ts.map +1 -1
  438. package/dist/types/core/agent/recordedCalls/resultDispositions.d.ts +2 -0
  439. package/dist/types/core/agent/recordedCalls/resultDispositions.d.ts.map +1 -1
  440. package/dist/types/core/agent/recordedCalls/resultRewriteIndex.d.ts +12 -0
  441. package/dist/types/core/agent/recordedCalls/resultRewriteIndex.d.ts.map +1 -0
  442. package/dist/types/core/agent/recordedCalls.d.ts +1 -0
  443. package/dist/types/core/agent/recordedCalls.d.ts.map +1 -1
  444. package/dist/types/core/agent/runtime/catalog/buildCatalog.d.ts +1 -0
  445. package/dist/types/core/agent/runtime/catalog/buildCatalog.d.ts.map +1 -1
  446. package/dist/types/core/agent/runtime/chart/chartDependencies.d.ts +1 -0
  447. package/dist/types/core/agent/runtime/chart/chartDependencies.d.ts.map +1 -1
  448. package/dist/types/core/agent/runtime/chart/owner.d.ts.map +1 -1
  449. package/dist/types/core/agent/runtime/configuration/configure.d.ts.map +1 -1
  450. package/dist/types/core/agent/runtime/configuration/model.d.ts +2 -0
  451. package/dist/types/core/agent/runtime/configuration/model.d.ts.map +1 -1
  452. package/dist/types/core/agent/runtime/configuration/values.d.ts +1 -0
  453. package/dist/types/core/agent/runtime/configuration/values.d.ts.map +1 -1
  454. package/dist/types/core/agent/runtime/conversation/owner.d.ts.map +1 -1
  455. package/dist/types/core/agent/runtime/request/factory.d.ts.map +1 -1
  456. package/dist/types/core/agent/runtime/skills/owner.d.ts.map +1 -1
  457. package/dist/types/core/agent/runtime/slots/buildSlots.d.ts.map +1 -1
  458. package/dist/types/core/agent/runtime/toolCalls/factory.d.ts +1 -0
  459. package/dist/types/core/agent/runtime/toolCalls/factory.d.ts.map +1 -1
  460. package/dist/types/core/agent/skillContext/apply.d.ts +40 -0
  461. package/dist/types/core/agent/skillContext/apply.d.ts.map +1 -0
  462. package/dist/types/core/agent/skillContext/bodies.d.ts +26 -0
  463. package/dist/types/core/agent/skillContext/bodies.d.ts.map +1 -0
  464. package/dist/types/core/agent/skillContext/decide.d.ts +34 -0
  465. package/dist/types/core/agent/skillContext/decide.d.ts.map +1 -0
  466. package/dist/types/core/agent/skillContext/gate.d.ts +33 -0
  467. package/dist/types/core/agent/skillContext/gate.d.ts.map +1 -0
  468. package/dist/types/core/agent/skillContext/honestyView.d.ts +7 -0
  469. package/dist/types/core/agent/skillContext/honestyView.d.ts.map +1 -0
  470. package/dist/types/core/agent/stages/callLLM/prepareCall.d.ts.map +1 -1
  471. package/dist/types/core/agent/stages/callLLM/types.d.ts +7 -0
  472. package/dist/types/core/agent/stages/callLLM/types.d.ts.map +1 -1
  473. package/dist/types/core/agent/stages/finalStageContract.d.ts +14 -0
  474. package/dist/types/core/agent/stages/finalStageContract.d.ts.map +1 -1
  475. package/dist/types/core/agent/stages/prepareFinal.d.ts +3 -9
  476. package/dist/types/core/agent/stages/prepareFinal.d.ts.map +1 -1
  477. package/dist/types/core/agent/stages/route.d.ts.map +1 -1
  478. package/dist/types/core/agent/stages/toolCalls/contracts/catalog.d.ts +9 -0
  479. package/dist/types/core/agent/stages/toolCalls/contracts/catalog.d.ts.map +1 -1
  480. package/dist/types/core/agent/stages/toolCalls/evidence/towers.d.ts.map +1 -1
  481. package/dist/types/core/agent/stages/toolCalls/execution/callStart.d.ts +1 -1
  482. package/dist/types/core/agent/stages/toolCalls/execution/callStart.d.ts.map +1 -1
  483. package/dist/types/core/agent/stages/toolCalls/execution/catalogOperations.d.ts.map +1 -1
  484. package/dist/types/core/agent/stages/toolCalls/execution/dispatchCall.d.ts.map +1 -1
  485. package/dist/types/core/agent/stages/toolCalls/execution/finalizeCallResult.d.ts +7 -0
  486. package/dist/types/core/agent/stages/toolCalls/execution/finalizeCallResult.d.ts.map +1 -1
  487. package/dist/types/core/agent/stages/window.d.ts +6 -0
  488. package/dist/types/core/agent/stages/window.d.ts.map +1 -1
  489. package/dist/types/core/agent/types/skillContext.d.ts +32 -0
  490. package/dist/types/core/agent/types/skillContext.d.ts.map +1 -0
  491. package/dist/types/core/agent/types.d.ts +2 -2
  492. package/dist/types/core/agent/types.d.ts.map +1 -1
  493. package/dist/types/core/agent/window/turns.d.ts +6 -0
  494. package/dist/types/core/agent/window/turns.d.ts.map +1 -1
  495. package/dist/types/core/agent/window/types.d.ts +7 -0
  496. package/dist/types/core/agent/window/types.d.ts.map +1 -1
  497. package/dist/types/core/slots/buildMessagesSlot.d.ts +7 -0
  498. package/dist/types/core/slots/buildMessagesSlot.d.ts.map +1 -1
  499. package/dist/types/core/slots/buildToolsSlot.d.ts +2 -0
  500. package/dist/types/core/slots/buildToolsSlot.d.ts.map +1 -1
  501. package/dist/types/core/slots/composeSkillCatalog.d.ts +10 -1
  502. package/dist/types/core/slots/composeSkillCatalog.d.ts.map +1 -1
  503. package/dist/types/events/payloads/skillContext.d.ts +40 -0
  504. package/dist/types/events/payloads/skillContext.d.ts.map +1 -0
  505. package/dist/types/events/payloads/stream.d.ts +9 -0
  506. package/dist/types/events/payloads/stream.d.ts.map +1 -1
  507. package/dist/types/events/payloads.d.ts +1 -0
  508. package/dist/types/events/payloads.d.ts.map +1 -1
  509. package/dist/types/injection-engine/skillContext.d.ts +93 -0
  510. package/dist/types/injection-engine/skillContext.d.ts.map +1 -0
  511. package/dist/types/injection-engine/skillToolDescriptors.d.ts.map +1 -1
  512. package/dist/types/injection-engine/skillTools.d.ts +7 -0
  513. package/dist/types/injection-engine/skillTools.d.ts.map +1 -1
  514. package/dist/types/injection-engine/types.d.ts +1 -1
  515. package/dist/types/injection-engine/types.d.ts.map +1 -1
  516. package/dist/types/lib/spokenIds.d.ts +11 -0
  517. package/dist/types/lib/spokenIds.d.ts.map +1 -1
  518. package/dist/types/llm-ledger/build.d.ts +78 -0
  519. package/dist/types/llm-ledger/build.d.ts.map +1 -0
  520. package/dist/types/llm-ledger/calls.d.ts +31 -0
  521. package/dist/types/llm-ledger/calls.d.ts.map +1 -0
  522. package/dist/types/llm-ledger/digest.d.ts +25 -0
  523. package/dist/types/llm-ledger/digest.d.ts.map +1 -0
  524. package/dist/types/llm-ledger/entries.d.ts +38 -0
  525. package/dist/types/llm-ledger/entries.d.ts.map +1 -0
  526. package/dist/types/llm-ledger/fileStore.d.ts +13 -0
  527. package/dist/types/llm-ledger/fileStore.d.ts.map +1 -0
  528. package/dist/types/llm-ledger/ledger.d.ts +62 -0
  529. package/dist/types/llm-ledger/ledger.d.ts.map +1 -0
  530. package/dist/types/llm-ledger/limits.d.ts +78 -0
  531. package/dist/types/llm-ledger/limits.d.ts.map +1 -0
  532. package/dist/types/llm-ledger/memoryStore.d.ts +4 -0
  533. package/dist/types/llm-ledger/memoryStore.d.ts.map +1 -0
  534. package/dist/types/llm-ledger/queue.d.ts +8 -0
  535. package/dist/types/llm-ledger/queue.d.ts.map +1 -0
  536. package/dist/types/llm-ledger/reader.d.ts +30 -0
  537. package/dist/types/llm-ledger/reader.d.ts.map +1 -0
  538. package/dist/types/llm-ledger/report.d.ts +83 -0
  539. package/dist/types/llm-ledger/report.d.ts.map +1 -0
  540. package/dist/types/llm-ledger/rules/cited.d.ts +11 -0
  541. package/dist/types/llm-ledger/rules/cited.d.ts.map +1 -0
  542. package/dist/types/llm-ledger/rules/port.d.ts +99 -0
  543. package/dist/types/llm-ledger/rules/port.d.ts.map +1 -0
  544. package/dist/types/llm-ledger/rules/timeWindow.d.ts +3 -0
  545. package/dist/types/llm-ledger/rules/timeWindow.d.ts.map +1 -0
  546. package/dist/types/llm-ledger/rules/traceableValues.d.ts +7 -0
  547. package/dist/types/llm-ledger/rules/traceableValues.d.ts.map +1 -0
  548. package/dist/types/llm-ledger/serve.d.ts +22 -0
  549. package/dist/types/llm-ledger/serve.d.ts.map +1 -0
  550. package/dist/types/llm-ledger/session.d.ts +7 -0
  551. package/dist/types/llm-ledger/session.d.ts.map +1 -0
  552. package/dist/types/llm-ledger/stages.d.ts +135 -0
  553. package/dist/types/llm-ledger/stages.d.ts.map +1 -0
  554. package/dist/types/llm-ledger/store.d.ts +98 -0
  555. package/dist/types/llm-ledger/store.d.ts.map +1 -0
  556. package/dist/types/llm-ledger/tokens.d.ts +31 -0
  557. package/dist/types/llm-ledger/tokens.d.ts.map +1 -0
  558. package/dist/types/llm-ledger/types.d.ts +174 -0
  559. package/dist/types/llm-ledger/types.d.ts.map +1 -0
  560. package/dist/types/llm-ledger/window.d.ts +41 -0
  561. package/dist/types/llm-ledger/window.d.ts.map +1 -0
  562. package/dist/types/redaction/knownStrings/fields-0.d.ts +1 -1
  563. package/dist/types/redaction/knownStrings/fields-1.d.ts +6 -6
  564. package/dist/types/redaction/knownStrings/fields-2.d.ts +7 -0
  565. package/dist/types/redaction/knownStrings/fields-2.d.ts.map +1 -1
  566. package/dist/types/redaction/knownStrings/words-0.d.ts +1 -1
  567. package/dist/types/redaction/knownStrings/words-1.d.ts +2 -2
  568. package/dist/types/redaction/knownStrings/words-2.d.ts +3 -0
  569. package/dist/types/redaction/knownStrings/words-2.d.ts.map +1 -1
  570. package/dist/types/trace-toolpack/traceToolpack/resultRewrite.d.ts +4 -0
  571. package/dist/types/trace-toolpack/traceToolpack/resultRewrite.d.ts.map +1 -0
  572. package/dist/types/trace-toolpack/traceToolpack/toolCallJournal.d.ts +6 -5
  573. package/dist/types/trace-toolpack/traceToolpack/toolCallJournal.d.ts.map +1 -1
  574. package/dist/types/trace-toolpack/traceToolpack/toolCallOccurrence.d.ts +7 -0
  575. package/dist/types/trace-toolpack/traceToolpack/toolCallOccurrence.d.ts.map +1 -1
  576. package/package.json +3 -3
@@ -0,0 +1,61 @@
1
+ /**
2
+ * llm-ledger/ledger — `createLedger`: the host's side and the agent's side of one ledger.
3
+ *
4
+ * Pattern: a facade. Every call is one short run (`calls.ts`), queued per session (`queue.ts`).
5
+ * The agent's calls are bound to one session and take no session argument.
6
+ * Role: the one entry point this folder offers; the doors (MCP, the command line) are a later
7
+ * pull request and call only this.
8
+ * Emits: N/A.
9
+ *
10
+ * Every reply is `{ ok: true, … }` or `{ ok: false, refused: <word> }` (`store` beside
11
+ * `store-refused`). Rules are registered once, here: the three built-ins and the host's
12
+ * (`rules/port.ts`); a rule that cannot be registered throws `LedgerRuleError`. A session opened
13
+ * without `rules` runs the built-ins (chosen here).
14
+ */
15
+ import type { RedactionPolicy } from 'footprintjs';
16
+ import type { LedgerConfirm } from './calls.js';
17
+ import type { LedgerCallKind } from './stages.js';
18
+ import type { LedgerRule } from './rules/port.js';
19
+ import type { LedgerServed } from './serve.js';
20
+ import type { LedgerStore } from './store.js';
21
+ /** What `createLedger` takes. */
22
+ export interface LedgerOptions {
23
+ readonly store: LedgerStore;
24
+ /** Host rules, beside the built-ins. */
25
+ readonly rules?: readonly LedgerRule[];
26
+ /** Given: every executor gets it, and every served string is masked unless it is a known kind. */
27
+ readonly redaction?: RedactionPolicy;
28
+ /** The person channel for sessions opened with `confirm: true`. */
29
+ readonly confirm?: LedgerConfirm;
30
+ /** The host's clock, RFC 3339 UTC. */
31
+ readonly clock?: () => string;
32
+ /** Each run's snapshot, for audits. */
33
+ readonly runs?: (record: {
34
+ readonly call: LedgerCallKind;
35
+ readonly snapshot: unknown;
36
+ }) => void;
37
+ }
38
+ /** The host's calls. */
39
+ export interface LedgerHost {
40
+ open(input?: unknown): Promise<LedgerServed>;
41
+ record(session: string, input: unknown): Promise<LedgerServed>;
42
+ supply(session: string, input: unknown): Promise<LedgerServed>;
43
+ deliver(session: string, input: unknown): Promise<LedgerServed>;
44
+ report(session: string): Promise<LedgerServed>;
45
+ }
46
+ /** The agent's calls, bound to one session. */
47
+ export interface LedgerAgent {
48
+ note(input: unknown): Promise<LedgerServed>;
49
+ withdraw(input: unknown): Promise<LedgerServed>;
50
+ ask(input?: unknown): Promise<LedgerServed>;
51
+ submit(input: unknown): Promise<LedgerServed>;
52
+ }
53
+ /** One ledger. */
54
+ export interface Ledger {
55
+ readonly host: LedgerHost;
56
+ agentFor(session: string): LedgerAgent;
57
+ }
58
+ /** The built-in rules, in the order a session runs them. */
59
+ export declare const BUILT_IN_RULES: readonly LedgerRule[];
60
+ /** A ledger over `options.store`. */
61
+ export declare function createLedger(options: LedgerOptions): Ledger;
@@ -0,0 +1,48 @@
1
+ import { runCall } from './calls.js';
2
+ import { cited } from './rules/cited.js';
3
+ import { registerRules, ruleKey } from './rules/port.js';
4
+ import { timeWindow } from './rules/timeWindow.js';
5
+ import { traceableValues } from './rules/traceableValues.js';
6
+ import { sessionQueue } from './queue.js';
7
+ import { mintSessionId } from './session.js';
8
+ /** The built-in rules, in the order a session runs them. */
9
+ export const BUILT_IN_RULES = Object.freeze([
10
+ cited,
11
+ traceableValues,
12
+ timeWindow,
13
+ ]);
14
+ /** A ledger over `options.store`. */
15
+ export function createLedger(options) {
16
+ const rules = registerRules(BUILT_IN_RULES, options.rules ?? []);
17
+ const ctx = {
18
+ store: options.store,
19
+ rules,
20
+ builtInKeys: BUILT_IN_RULES.map(ruleKey),
21
+ ...(options.redaction === undefined ? {} : { redaction: options.redaction }),
22
+ ...(options.confirm === undefined ? {} : { confirm: options.confirm }),
23
+ clock: options.clock ?? (() => new Date().toISOString()),
24
+ ...(options.runs === undefined ? {} : { runs: options.runs }),
25
+ };
26
+ const queue = sessionQueue();
27
+ const busy = () => ({ ok: false, refused: 'busy' });
28
+ const call = (kind, session, input) => queue.run(session, () => runCall(ctx, kind, session, input), busy);
29
+ return Object.freeze({
30
+ host: Object.freeze({
31
+ open: (input = {}) => {
32
+ const session = mintSessionId();
33
+ return call('open', session, input);
34
+ },
35
+ record: (session, input) => call('record', session, input),
36
+ supply: (session, input) => call('supply', session, input),
37
+ deliver: (session, input) => call('deliver', session, input),
38
+ report: (session) => call('report', session, {}),
39
+ }),
40
+ agentFor: (session) => Object.freeze({
41
+ note: (input) => call('note', session, input),
42
+ withdraw: (input) => call('withdraw', session, input),
43
+ ask: (input = {}) => call('ask', session, input),
44
+ submit: (input) => call('submit', session, input),
45
+ }),
46
+ });
47
+ }
48
+ //# sourceMappingURL=ledger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../../src/llm-ledger/ledger.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * llm-ledger/limits — every cap the ledger holds, in ONE frozen table.
3
+ *
4
+ * Pattern: one table, read by every check. A cap written as a number anywhere
5
+ * else in the folder is a second owner, so the builders, the entry
6
+ * checks and both stores read `LEDGER_LIMITS` and nothing else.
7
+ * Role: the closed leaf's own vocabulary. Imports nothing.
8
+ * Emits: N/A.
9
+ *
10
+ * Characters are counted as Unicode code points (what a JSON Schema
11
+ * `maxLength` counts), bytes as UTF-8. A line is one stored entry as the file
12
+ * store writes it (`store.ts` · `lineBytesOf`); the memory store measures the
13
+ * same line, so both stores hold the same caps.
14
+ */
15
+ export declare const LEDGER_LIMITS: Readonly<{
16
+ /** Entries in one session, all kinds counted. */
17
+ readonly maxEntries: 10000;
18
+ /** Bytes of one session's log: the sum of its lines. */
19
+ readonly maxLogBytes: number;
20
+ /** Bytes of one line. */
21
+ readonly maxLineBytes: number;
22
+ /** A receipt's `source`: 1–128 characters, no control characters. */
23
+ readonly minSourceChars: 1;
24
+ readonly maxSourceChars: 128;
25
+ /** A receipt's `query`. */
26
+ readonly maxQueryChars: 1024;
27
+ /** Distinct tokens one receipt or supplied entry keeps. */
28
+ readonly maxTokens: 2048;
29
+ /** A token's length. */
30
+ readonly minTokenChars: 4;
31
+ readonly maxTokenChars: 64;
32
+ /** Bytes of the host's text read for tokens; the rest is counted, never read. */
33
+ readonly maxTextBytes: 1048576;
34
+ /** A receipt's `ref.uri`. */
35
+ readonly maxRefUriChars: 512;
36
+ /** A receipt's `externalId`. */
37
+ readonly maxExternalIdChars: 256;
38
+ /** A note's `text`. */
39
+ readonly maxNoteChars: 2000;
40
+ /** A note's `values`: how many, and each one's length. */
41
+ readonly maxValues: 32;
42
+ readonly maxValueChars: 64;
43
+ /** A note's `cites`. */
44
+ readonly maxCites: 32;
45
+ /** A withdrawal's `why`. */
46
+ readonly maxWhyChars: 500;
47
+ /** A submit's `claims`. */
48
+ readonly maxClaims: 64;
49
+ /** Bytes of a draft (and of a delivered text). */
50
+ readonly maxDraftBytes: number;
51
+ /** Tokens a check lists as `missing`; the rest are counted. */
52
+ readonly maxMissing: 32;
53
+ /** Rules one session runs (`opened.rules`). */
54
+ readonly maxRules: 16;
55
+ /** The file store's key, in bytes. */
56
+ readonly minKeyBytes: 32;
57
+ /** How long an append waits for another writer's lock. */
58
+ readonly lockWaitMs: 2000;
59
+ /** A lock older than this was left by a writer that died; it is taken over. */
60
+ readonly lockStaleMs: 30000;
61
+ /** Sessions one high-water mark remembers; the least recently used is forgotten past it. */
62
+ readonly maxHighWaterSessions: 10000;
63
+ /** Rules one ledger registers, built-ins included. */
64
+ readonly maxRegisteredRules: 16;
65
+ /** Distinct fact names one rule's table may read. */
66
+ readonly maxRuleFacts: 32;
67
+ /** How long a rule may run before its check is `unreachable` (`rule-timeout`). */
68
+ readonly ruleTimeoutMs: 1000;
69
+ /** Attempts one call makes when another writer appended first; then `busy`. */
70
+ readonly maxAttempts: 3;
71
+ /** Calls one session may have waiting in a ledger's queue; then `busy`. */
72
+ readonly maxQueued: 8;
73
+ /** Receipts `ask` lists, newest first. */
74
+ readonly askReceipts: 64;
75
+ }>;
76
+ /** The cap table's type: every value a literal. */
77
+ export type LedgerLimits = typeof LEDGER_LIMITS;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * llm-ledger/limits — every cap the ledger holds, in ONE frozen table.
3
+ *
4
+ * Pattern: one table, read by every check. A cap written as a number anywhere
5
+ * else in the folder is a second owner, so the builders, the entry
6
+ * checks and both stores read `LEDGER_LIMITS` and nothing else.
7
+ * Role: the closed leaf's own vocabulary. Imports nothing.
8
+ * Emits: N/A.
9
+ *
10
+ * Characters are counted as Unicode code points (what a JSON Schema
11
+ * `maxLength` counts), bytes as UTF-8. A line is one stored entry as the file
12
+ * store writes it (`store.ts` · `lineBytesOf`); the memory store measures the
13
+ * same line, so both stores hold the same caps.
14
+ */
15
+ export const LEDGER_LIMITS = Object.freeze({
16
+ /** Entries in one session, all kinds counted. */
17
+ maxEntries: 10_000,
18
+ /** Bytes of one session's log: the sum of its lines. */
19
+ maxLogBytes: 32 * 1024 * 1024,
20
+ /** Bytes of one line. */
21
+ maxLineBytes: 256 * 1024,
22
+ /** A receipt's `source`: 1–128 characters, no control characters. */
23
+ minSourceChars: 1,
24
+ maxSourceChars: 128,
25
+ /** A receipt's `query`. */
26
+ maxQueryChars: 1_024,
27
+ /** Distinct tokens one receipt or supplied entry keeps. */
28
+ maxTokens: 2_048,
29
+ /** A token's length. */
30
+ minTokenChars: 4,
31
+ maxTokenChars: 64,
32
+ /** Bytes of the host's text read for tokens; the rest is counted, never read. */
33
+ maxTextBytes: 1_048_576,
34
+ /** A receipt's `ref.uri`. */
35
+ maxRefUriChars: 512,
36
+ /** A receipt's `externalId`. */
37
+ maxExternalIdChars: 256,
38
+ /** A note's `text`. */
39
+ maxNoteChars: 2_000,
40
+ /** A note's `values`: how many, and each one's length. */
41
+ maxValues: 32,
42
+ maxValueChars: 64,
43
+ /** A note's `cites`. */
44
+ maxCites: 32,
45
+ /** A withdrawal's `why`. */
46
+ maxWhyChars: 500,
47
+ /** A submit's `claims`. */
48
+ maxClaims: 64,
49
+ /** Bytes of a draft (and of a delivered text). */
50
+ maxDraftBytes: 64 * 1024,
51
+ /** Tokens a check lists as `missing`; the rest are counted. */
52
+ maxMissing: 32,
53
+ /** Rules one session runs (`opened.rules`). */
54
+ maxRules: 16,
55
+ /** The file store's key, in bytes. */
56
+ minKeyBytes: 32,
57
+ /** How long an append waits for another writer's lock. */
58
+ lockWaitMs: 2_000,
59
+ /** A lock older than this was left by a writer that died; it is taken over. */
60
+ lockStaleMs: 30_000,
61
+ /** Sessions one high-water mark remembers; the least recently used is forgotten past it. */
62
+ maxHighWaterSessions: 10_000,
63
+ /** Rules one ledger registers, built-ins included. */
64
+ maxRegisteredRules: 16,
65
+ /** Distinct fact names one rule's table may read. */
66
+ maxRuleFacts: 32,
67
+ /** How long a rule may run before its check is `unreachable` (`rule-timeout`). */
68
+ ruleTimeoutMs: 1_000,
69
+ /** Attempts one call makes when another writer appended first; then `busy`. */
70
+ maxAttempts: 3,
71
+ /** Calls one session may have waiting in a ledger's queue; then `busy`. */
72
+ maxQueued: 8,
73
+ /** Receipts `ask` lists, newest first. */
74
+ askReceipts: 64,
75
+ });
76
+ //# sourceMappingURL=limits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limits.js","sourceRoot":"","sources":["../../../src/llm-ledger/limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IACzC,iDAAiD;IACjD,UAAU,EAAE,MAAM;IAClB,wDAAwD;IACxD,WAAW,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;IAC7B,yBAAyB;IACzB,YAAY,EAAE,GAAG,GAAG,IAAI;IAExB,qEAAqE;IACrE,cAAc,EAAE,CAAC;IACjB,cAAc,EAAE,GAAG;IACnB,2BAA2B;IAC3B,aAAa,EAAE,KAAK;IACpB,2DAA2D;IAC3D,SAAS,EAAE,KAAK;IAChB,wBAAwB;IACxB,aAAa,EAAE,CAAC;IAChB,aAAa,EAAE,EAAE;IACjB,iFAAiF;IACjF,YAAY,EAAE,SAAS;IACvB,6BAA6B;IAC7B,cAAc,EAAE,GAAG;IACnB,gCAAgC;IAChC,kBAAkB,EAAE,GAAG;IAEvB,uBAAuB;IACvB,YAAY,EAAE,KAAK;IACnB,0DAA0D;IAC1D,SAAS,EAAE,EAAE;IACb,aAAa,EAAE,EAAE;IACjB,wBAAwB;IACxB,QAAQ,EAAE,EAAE;IACZ,4BAA4B;IAC5B,WAAW,EAAE,GAAG;IAChB,2BAA2B;IAC3B,SAAS,EAAE,EAAE;IACb,kDAAkD;IAClD,aAAa,EAAE,EAAE,GAAG,IAAI;IACxB,+DAA+D;IAC/D,UAAU,EAAE,EAAE;IACd,+CAA+C;IAC/C,QAAQ,EAAE,EAAE;IAEZ,sCAAsC;IACtC,WAAW,EAAE,EAAE;IACf,0DAA0D;IAC1D,UAAU,EAAE,KAAK;IACjB,+EAA+E;IAC/E,WAAW,EAAE,MAAM;IACnB,4FAA4F;IAC5F,oBAAoB,EAAE,MAAM;IAE5B,sDAAsD;IACtD,kBAAkB,EAAE,EAAE;IACtB,qDAAqD;IACrD,YAAY,EAAE,EAAE;IAChB,kFAAkF;IAClF,aAAa,EAAE,KAAK;IACpB,+EAA+E;IAC/E,WAAW,EAAE,CAAC;IACd,2EAA2E;IAC3E,SAAS,EAAE,CAAC;IACZ,0CAA0C;IAC1C,WAAW,EAAE,EAAE;CACP,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { LedgerStore } from './store.js';
2
+ /** A new, empty in-memory store. */
3
+ export declare function memoryLedgerStore(): LedgerStore;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * llm-ledger/memoryStore — the in-process adapter: for tests and a host that keeps the log in memory.
3
+ *
4
+ * Pattern: the port's second adapter, under the file store's caps and the
5
+ * same admission (`store.ts` · `admitBatch`), so one contract suite
6
+ * runs on both and gives the same answers.
7
+ * Role: each session is an array of entries in a `Map`. An entry is kept as
8
+ * the copy admission parsed from its canonical JSON (a clone that
9
+ * also refuses what JSON cannot hold), deep-frozen; a load hands out
10
+ * a frozen array of those entries.
11
+ * Emits: N/A.
12
+ *
13
+ * Nothing survives the process, and there is no MAC: a memory store is as
14
+ * trustworthy as the process that holds it. One `append` runs to completion
15
+ * before the next starts (it awaits nothing between its compare and its
16
+ * write), which is the compare-and-swap within one process.
17
+ */
18
+ import { LedgerStoreError, admitBatch, checkRoom } from './store.js';
19
+ import { isSessionId } from './session.js';
20
+ /** A new, empty in-memory store. */
21
+ export function memoryLedgerStore() {
22
+ const sessions = new Map();
23
+ return {
24
+ async load(session) {
25
+ if (!isSessionId(session))
26
+ throw new LedgerStoreError('malformed', 'session');
27
+ const held = sessions.get(session);
28
+ const entries = held === undefined ? [] : [...held.entries];
29
+ return Object.freeze({ seq: entries.length, entries: Object.freeze(entries) });
30
+ },
31
+ async append(session, expectedSeq, entries) {
32
+ const batch = admitBatch(session, expectedSeq, entries);
33
+ const held = sessions.get(session) ?? { entries: [], bytes: 0 };
34
+ if (held.entries.length !== expectedSeq)
35
+ return 'conflict';
36
+ checkRoom(held.entries.length, held.bytes, batch);
37
+ held.entries.push(...batch.entries);
38
+ held.bytes += batch.bytes;
39
+ sessions.set(session, held);
40
+ return held.entries.length;
41
+ },
42
+ };
43
+ }
44
+ //# sourceMappingURL=memoryStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoryStore.js","sourceRoot":"","sources":["../../../src/llm-ledger/memoryStore.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3C,oCAAoC;AACpC,MAAM,UAAU,iBAAiB;IAC/B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAqD,CAAC;IAC9E,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,OAAe;YACxB,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;gBAAE,MAAM,IAAI,gBAAgB,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;YAC9E,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACnC,MAAM,OAAO,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;YAC5D,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACjF,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO;YACxC,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;YACxD,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;YAChE,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,WAAW;gBAAE,OAAO,UAAU,CAAC;YAC3D,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAClD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;YACpC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC;YAC1B,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QAC7B,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ /** A per-session FIFO. */
2
+ export interface LedgerQueue {
3
+ /** Runs `work` after every earlier call of `session`; `busy` when too many wait. */
4
+ run<T>(session: string, work: () => Promise<T>, busy: () => T): Promise<T>;
5
+ }
6
+ /** A new, empty queue. */
7
+ export declare function sessionQueue(maxQueued?: number): LedgerQueue;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * llm-ledger/queue — one FIFO per session, in one process.
3
+ *
4
+ * Pattern: a promise chain per session key. A call waits for the calls of its session queued
5
+ * before it; calls of other sessions do not wait for it. Across processes the store's seq
6
+ * decides (`conflict`), not this queue.
7
+ * Role: why two calls of one ledger never race each other's appends: the second loads the log
8
+ * the first left.
9
+ * Emits: N/A.
10
+ *
11
+ * At most `maxQueued` calls of one session wait at once; one more is answered `busy` at once,
12
+ * without running. A call that fails does not stop the queue.
13
+ */
14
+ import { LEDGER_LIMITS as L } from './limits.js';
15
+ /** A new, empty queue. */
16
+ export function sessionQueue(maxQueued = L.maxQueued) {
17
+ const tails = new Map();
18
+ return {
19
+ run(session, work, busy) {
20
+ const lane = tails.get(session) ?? { tail: Promise.resolve(), waiting: 0 };
21
+ if (lane.waiting >= maxQueued)
22
+ return Promise.resolve(busy());
23
+ lane.waiting++;
24
+ const result = lane.tail.then(work, work);
25
+ lane.tail = result.then(() => undefined, () => undefined);
26
+ tails.set(session, lane);
27
+ void lane.tail.then(() => {
28
+ lane.waiting--;
29
+ if (lane.waiting === 0 && tails.get(session) === lane)
30
+ tails.delete(session);
31
+ });
32
+ return result;
33
+ },
34
+ };
35
+ }
36
+ //# sourceMappingURL=queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../src/llm-ledger/queue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,aAAa,IAAI,CAAC,EAAE,MAAM,aAAa,CAAC;AAQjD,0BAA0B;AAC1B,MAAM,UAAU,YAAY,CAAC,YAAoB,CAAC,CAAC,SAAS;IAC1D,MAAM,KAAK,GAAG,IAAI,GAAG,EAAuD,CAAC;IAC7E,OAAO;QACL,GAAG,CAAI,OAAe,EAAE,IAAsB,EAAE,IAAa;YAC3D,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;YAC3E,IAAI,IAAI,CAAC,OAAO,IAAI,SAAS;gBAAE,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;YAC9D,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC1C,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CACrB,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CAChB,CAAC;YACF,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACzB,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;gBACvB,IAAI,CAAC,OAAO,EAAE,CAAC;gBACf,IAAI,IAAI,CAAC,OAAO,KAAK,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,IAAI;oBAAE,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC/E,CAAC,CAAC,CAAC;YACH,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { LedgerLog } from './store.js';
2
+ import type { LedgerCheck, LedgerDelivered, LedgerEntry, LedgerNote, LedgerOpened, LedgerReceipt, LedgerReleased, LedgerSubmit, LedgerSupplied, LedgerWithdrawal } from './types.js';
3
+ /** What one log says, indexed. */
4
+ export interface LedgerReader {
5
+ /** The last entry's seq: 0 for a session that does not exist. */
6
+ readonly seq: number;
7
+ /** The session's `opened` entry, when its first entry is one. */
8
+ readonly opened: LedgerOpened | undefined;
9
+ /** At the entry cap: every append is refused (`ledger-full`). */
10
+ readonly full: boolean;
11
+ entry(seq: number): LedgerEntry | undefined;
12
+ receipt(seq: number): LedgerReceipt | undefined;
13
+ note(seq: number): LedgerNote | undefined;
14
+ /** The withdrawal of `note`, when there is one. */
15
+ withdrawalOf(note: number): LedgerWithdrawal | undefined;
16
+ readonly receipts: readonly LedgerReceipt[];
17
+ readonly supplied: readonly LedgerSupplied[];
18
+ readonly notes: readonly LedgerNote[];
19
+ /** The last `submit`, when there is one. */
20
+ readonly lastSubmit: LedgerSubmit | undefined;
21
+ /** The `check` entries of `submit`, in log order. */
22
+ checksOf(submit: number): readonly LedgerCheck[];
23
+ /** The `released` entry of `submit`, when there is one. */
24
+ releasedOf(submit: number): LedgerReleased | undefined;
25
+ /** The last `delivered` entry, when there is one. */
26
+ readonly lastDelivered: LedgerDelivered | undefined;
27
+ }
28
+ /** The reader of `log`. */
29
+ export declare function readerOf(log: LedgerLog): LedgerReader;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * llm-ledger/reader — one loaded log, read by seq and by kind.
3
+ *
4
+ * Pattern: a read-only index over one `LedgerStore.load` (one per attempt of a call). Stages hold
5
+ * it in their closure; it never enters a run's scope, so no entry's content reaches a run
6
+ * record.
7
+ * Role: the one place that answers "what does the log say" for the facts, the rules and the
8
+ * fold. It never writes and never loads.
9
+ * Emits: N/A.
10
+ */
11
+ import { LEDGER_LIMITS as L } from './limits.js';
12
+ /** The reader of `log`. */
13
+ export function readerOf(log) {
14
+ const entries = log.entries;
15
+ const byKind = (kind) => entries.filter((e) => e.kind === kind);
16
+ const receipts = byKind('receipt');
17
+ const withdrawals = new Map(byKind('withdrawal').map((w) => [w.note, w]));
18
+ const checks = new Map();
19
+ for (const c of byKind('check'))
20
+ checks.set(c.submit, [...(checks.get(c.submit) ?? []), c]);
21
+ const released = new Map(byKind('released').map((r) => [r.submit, r]));
22
+ const submits = byKind('submit');
23
+ const delivered = byKind('delivered');
24
+ const first = entries[0];
25
+ const entry = (seq) => Number.isSafeInteger(seq) && seq >= 1 ? entries[seq - 1] : undefined;
26
+ const as = (kind) => (seq) => {
27
+ const e = entry(seq);
28
+ return e?.kind === kind ? e : undefined;
29
+ };
30
+ return Object.freeze({
31
+ seq: log.seq,
32
+ opened: first?.kind === 'opened' ? first : undefined,
33
+ full: log.seq >= L.maxEntries,
34
+ entry,
35
+ receipt: as('receipt'),
36
+ note: as('note'),
37
+ withdrawalOf: (note) => withdrawals.get(note),
38
+ receipts,
39
+ supplied: byKind('supplied'),
40
+ notes: byKind('note'),
41
+ lastSubmit: submits[submits.length - 1],
42
+ checksOf: (submit) => checks.get(submit) ?? [],
43
+ releasedOf: (submit) => released.get(submit),
44
+ lastDelivered: delivered[delivered.length - 1],
45
+ });
46
+ }
47
+ //# sourceMappingURL=reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reader.js","sourceRoot":"","sources":["../../../src/llm-ledger/reader.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,82 @@
1
+ import type { LedgerReader } from './reader.js';
2
+ import type { LedgerCheckCounts } from './rules/port.js';
3
+ import type { LedgerCheckWhy, LedgerDisposition, LedgerVerdict } from './types.js';
4
+ /** The report's standing, in AgentFootprint's words. */
5
+ export type LedgerStanding = 'ask' | 'not-sure' | 'consistent' | 'not-assessed';
6
+ /** Why a standing is not `consistent`. `report-withheld` and `delivery-differs` are new (§10.1). */
7
+ export type LedgerReason = 'asked' | 'value-unsupported' | 'claim-unsettled' | 'check-unreachable' | 'report-withheld' | 'delivery-differs';
8
+ /** One check as the fold reads it: a stored `check` entry, or a dry run's finding. */
9
+ export interface LedgerCheckView {
10
+ readonly subject: {
11
+ readonly note: number;
12
+ } | {
13
+ readonly draft: true;
14
+ };
15
+ readonly rule: string;
16
+ readonly disposition: LedgerDisposition;
17
+ readonly verdict?: LedgerVerdict;
18
+ readonly restsOn: readonly number[];
19
+ readonly counts: LedgerCheckCounts;
20
+ readonly missing?: readonly string[];
21
+ readonly why?: LedgerCheckWhy;
22
+ }
23
+ /** One subject's line in the report. */
24
+ export interface LedgerSubjectReport {
25
+ readonly verdict?: LedgerVerdict;
26
+ readonly reason?: 'claim-unsettled' | 'check-unreachable';
27
+ readonly checks: readonly LedgerCheckView[];
28
+ /** Tokens no receipt holds, the first ones each check kept. */
29
+ readonly missing: readonly string[];
30
+ /** Whether what it rests on was observed, only reported, or nothing. */
31
+ readonly restsOn: 'observed' | 'reported' | 'nothing';
32
+ }
33
+ /** A named claim (or ruled-out note) in the report. */
34
+ export interface LedgerClaimReport extends LedgerSubjectReport {
35
+ readonly note: number;
36
+ readonly kind: 'claim' | 'ruled-out';
37
+ /** The agent's own words: served only through `serve.ts`. */
38
+ readonly text: string;
39
+ }
40
+ /** The fold's result. Holds real values: serve it through `serve.ts` only. */
41
+ export interface LedgerReport {
42
+ readonly standing: LedgerStanding;
43
+ readonly reasons: readonly LedgerReason[];
44
+ readonly submit: number | null;
45
+ readonly draftDigest?: string;
46
+ readonly preview: boolean;
47
+ readonly claims: readonly LedgerClaimReport[];
48
+ readonly draft?: LedgerSubjectReport;
49
+ /** Kept apart, never summed. */
50
+ readonly counts: {
51
+ readonly verified: number;
52
+ readonly consistentWithReported: number;
53
+ readonly unsupported: number;
54
+ readonly open: number;
55
+ readonly notAssessed: number;
56
+ };
57
+ readonly receipts: {
58
+ readonly observed: number;
59
+ readonly reported: number;
60
+ readonly incomplete: readonly number[];
61
+ };
62
+ readonly withdrawnAfterCheck: readonly {
63
+ readonly note: number;
64
+ readonly verdict?: LedgerVerdict;
65
+ }[];
66
+ /** Live claim and ruled-out notes the last submit did not name. */
67
+ readonly notChecked: readonly number[];
68
+ readonly openQuestions: readonly number[];
69
+ readonly delivery: 'not-compared' | 'matches' | 'differs';
70
+ readonly release: 'not-asked' | 'waiting' | 'released' | 'withheld' | 'no-person-channel';
71
+ readonly full: boolean;
72
+ }
73
+ /** The two sentences every report carries. */
74
+ export declare const REPORT_SENTENCES: readonly string[];
75
+ /**
76
+ * The report of `reader`'s last submit. `preview` gives the findings of a dry run over `claims`
77
+ * instead (nothing appended): the report then reads them, and says `preview: true`.
78
+ */
79
+ export declare function foldReport(reader: LedgerReader, preview?: {
80
+ readonly claims: readonly number[];
81
+ readonly checks: readonly LedgerCheckView[];
82
+ }): LedgerReport;