agentfootprint 7.16.0 → 7.18.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 (295) hide show
  1. package/AGENTS.md +1 -1
  2. package/CLAUDE.md +2 -2
  3. package/ai-instructions/claude-code/SKILL.md +1 -1
  4. package/dist/conventions.js +8 -6
  5. package/dist/conventions.js.map +1 -1
  6. package/dist/core/Agent.js +81 -27
  7. package/dist/core/Agent.js.map +1 -1
  8. package/dist/core/RunnerBase.js +16 -1
  9. package/dist/core/RunnerBase.js.map +1 -1
  10. package/dist/core/agent/AgentBuilder.js +209 -43
  11. package/dist/core/agent/AgentBuilder.js.map +1 -1
  12. package/dist/core/agent/buildAgentChart.js +8 -8
  13. package/dist/core/agent/buildAgentChart.js.map +1 -1
  14. package/dist/core/agent/buildDynamicAgentChart.js +6 -6
  15. package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
  16. package/dist/core/agent/middleware/errors.js +54 -0
  17. package/dist/core/agent/middleware/errors.js.map +1 -0
  18. package/dist/core/agent/middleware/index.js +23 -0
  19. package/dist/core/agent/middleware/index.js.map +1 -0
  20. package/dist/core/agent/middleware/ledger.js +61 -0
  21. package/dist/core/agent/middleware/ledger.js.map +1 -0
  22. package/dist/core/agent/middleware/outcomes.js +66 -0
  23. package/dist/core/agent/middleware/outcomes.js.map +1 -0
  24. package/dist/core/agent/middleware/runChain.js +144 -0
  25. package/dist/core/agent/middleware/runChain.js.map +1 -0
  26. package/dist/core/agent/middleware/types.js +41 -0
  27. package/dist/core/agent/middleware/types.js.map +1 -0
  28. package/dist/core/agent/stages/prepareFinal.js +10 -0
  29. package/dist/core/agent/stages/prepareFinal.js.map +1 -1
  30. package/dist/core/agent/stages/route.js +62 -1
  31. package/dist/core/agent/stages/route.js.map +1 -1
  32. package/dist/core/agent/stages/seed.js +130 -85
  33. package/dist/core/agent/stages/seed.js.map +1 -1
  34. package/dist/core/agent/stages/toolCalls.js +195 -8
  35. package/dist/core/agent/stages/toolCalls.js.map +1 -1
  36. package/dist/core/agent/stages/window.js +141 -0
  37. package/dist/core/agent/stages/window.js.map +1 -0
  38. package/dist/core/agent/window/errors.js.map +1 -0
  39. package/dist/core/agent/window/index.js +36 -0
  40. package/dist/core/agent/window/index.js.map +1 -0
  41. package/dist/core/agent/window/notice.js +57 -0
  42. package/dist/core/agent/window/notice.js.map +1 -0
  43. package/dist/core/agent/window/options.js +93 -0
  44. package/dist/core/agent/window/options.js.map +1 -0
  45. package/dist/core/agent/window/removal.js +45 -0
  46. package/dist/core/agent/window/removal.js.map +1 -0
  47. package/dist/core/agent/window/strategies/drop.js +106 -0
  48. package/dist/core/agent/window/strategies/drop.js.map +1 -0
  49. package/dist/core/agent/window/strategies/slidingWindow.js +87 -0
  50. package/dist/core/agent/window/strategies/slidingWindow.js.map +1 -0
  51. package/dist/core/agent/window/strategies/summarizeOldest.js +178 -0
  52. package/dist/core/agent/window/strategies/summarizeOldest.js.map +1 -0
  53. package/dist/core/agent/window/strategies/tokenBudget.js +95 -0
  54. package/dist/core/agent/window/strategies/tokenBudget.js.map +1 -0
  55. package/dist/core/agent/window/strategy.js +42 -0
  56. package/dist/core/agent/window/strategy.js.map +1 -0
  57. package/dist/core/agent/window/summarize.js.map +1 -0
  58. package/dist/core/agent/{compaction → window}/turns.js +50 -28
  59. package/dist/core/agent/window/turns.js.map +1 -0
  60. package/dist/core/agent/window/types.js +23 -0
  61. package/dist/core/agent/window/types.js.map +1 -0
  62. package/dist/core/pause.js +19 -1
  63. package/dist/core/pause.js.map +1 -1
  64. package/dist/esm/conventions.d.ts +8 -6
  65. package/dist/esm/conventions.js +8 -6
  66. package/dist/esm/conventions.js.map +1 -1
  67. package/dist/esm/core/Agent.d.ts +14 -6
  68. package/dist/esm/core/Agent.js +82 -28
  69. package/dist/esm/core/Agent.js.map +1 -1
  70. package/dist/esm/core/RunnerBase.js +16 -1
  71. package/dist/esm/core/RunnerBase.js.map +1 -1
  72. package/dist/esm/core/agent/AgentBuilder.d.ts +157 -4
  73. package/dist/esm/core/agent/AgentBuilder.js +209 -43
  74. package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
  75. package/dist/esm/core/agent/buildAgentChart.d.ts +16 -9
  76. package/dist/esm/core/agent/buildAgentChart.js +8 -8
  77. package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
  78. package/dist/esm/core/agent/buildDynamicAgentChart.js +6 -6
  79. package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
  80. package/dist/esm/core/agent/middleware/errors.d.ts +51 -0
  81. package/dist/esm/core/agent/middleware/errors.js +50 -0
  82. package/dist/esm/core/agent/middleware/errors.js.map +1 -0
  83. package/dist/esm/core/agent/middleware/index.d.ts +16 -0
  84. package/dist/esm/core/agent/middleware/index.js +16 -0
  85. package/dist/esm/core/agent/middleware/index.js.map +1 -0
  86. package/dist/esm/core/agent/middleware/ledger.d.ts +40 -0
  87. package/dist/esm/core/agent/middleware/ledger.js +57 -0
  88. package/dist/esm/core/agent/middleware/ledger.js.map +1 -0
  89. package/dist/esm/core/agent/middleware/outcomes.d.ts +45 -0
  90. package/dist/esm/core/agent/middleware/outcomes.js +60 -0
  91. package/dist/esm/core/agent/middleware/outcomes.js.map +1 -0
  92. package/dist/esm/core/agent/middleware/runChain.d.ts +104 -0
  93. package/dist/esm/core/agent/middleware/runChain.js +139 -0
  94. package/dist/esm/core/agent/middleware/runChain.js.map +1 -0
  95. package/dist/esm/core/agent/middleware/types.d.ts +191 -0
  96. package/dist/esm/core/agent/middleware/types.js +40 -0
  97. package/dist/esm/core/agent/middleware/types.js.map +1 -0
  98. package/dist/esm/core/agent/stages/prepareFinal.d.ts +10 -0
  99. package/dist/esm/core/agent/stages/prepareFinal.js +10 -0
  100. package/dist/esm/core/agent/stages/prepareFinal.js.map +1 -1
  101. package/dist/esm/core/agent/stages/route.d.ts +29 -0
  102. package/dist/esm/core/agent/stages/route.js +60 -0
  103. package/dist/esm/core/agent/stages/route.js.map +1 -1
  104. package/dist/esm/core/agent/stages/seed.d.ts +16 -1
  105. package/dist/esm/core/agent/stages/seed.js +130 -85
  106. package/dist/esm/core/agent/stages/seed.js.map +1 -1
  107. package/dist/esm/core/agent/stages/toolCalls.d.ts +23 -0
  108. package/dist/esm/core/agent/stages/toolCalls.js +195 -8
  109. package/dist/esm/core/agent/stages/toolCalls.js.map +1 -1
  110. package/dist/esm/core/agent/stages/window.d.ts +63 -0
  111. package/dist/esm/core/agent/stages/window.js +137 -0
  112. package/dist/esm/core/agent/stages/window.js.map +1 -0
  113. package/dist/esm/core/agent/types.d.ts +33 -8
  114. package/dist/esm/core/agent/window/errors.js.map +1 -0
  115. package/dist/esm/core/agent/window/index.d.ts +27 -0
  116. package/dist/esm/core/agent/window/index.js +25 -0
  117. package/dist/esm/core/agent/window/index.js.map +1 -0
  118. package/dist/esm/core/agent/window/notice.d.ts +46 -0
  119. package/dist/esm/core/agent/window/notice.js +52 -0
  120. package/dist/esm/core/agent/window/notice.js.map +1 -0
  121. package/dist/esm/core/agent/window/options.d.ts +33 -0
  122. package/dist/esm/core/agent/window/options.js +87 -0
  123. package/dist/esm/core/agent/window/options.js.map +1 -0
  124. package/dist/esm/core/agent/window/removal.d.ts +22 -0
  125. package/dist/esm/core/agent/window/removal.js +40 -0
  126. package/dist/esm/core/agent/window/removal.js.map +1 -0
  127. package/dist/esm/core/agent/window/strategies/drop.d.ts +54 -0
  128. package/dist/esm/core/agent/window/strategies/drop.js +102 -0
  129. package/dist/esm/core/agent/window/strategies/drop.js.map +1 -0
  130. package/dist/esm/core/agent/window/strategies/slidingWindow.d.ts +48 -0
  131. package/dist/esm/core/agent/window/strategies/slidingWindow.js +83 -0
  132. package/dist/esm/core/agent/window/strategies/slidingWindow.js.map +1 -0
  133. package/dist/esm/core/agent/window/strategies/summarizeOldest.d.ts +42 -0
  134. package/dist/esm/core/agent/window/strategies/summarizeOldest.js +174 -0
  135. package/dist/esm/core/agent/window/strategies/summarizeOldest.js.map +1 -0
  136. package/dist/esm/core/agent/window/strategies/tokenBudget.d.ts +47 -0
  137. package/dist/esm/core/agent/window/strategies/tokenBudget.js +91 -0
  138. package/dist/esm/core/agent/window/strategies/tokenBudget.js.map +1 -0
  139. package/dist/esm/core/agent/window/strategy.d.ts +181 -0
  140. package/dist/esm/core/agent/window/strategy.js +41 -0
  141. package/dist/esm/core/agent/window/strategy.js.map +1 -0
  142. package/dist/esm/core/agent/window/summarize.js.map +1 -0
  143. package/dist/esm/core/agent/window/turns.d.ts +108 -0
  144. package/dist/esm/core/agent/{compaction → window}/turns.js +48 -26
  145. package/dist/esm/core/agent/window/turns.js.map +1 -0
  146. package/dist/esm/core/agent/window/types.d.ts +263 -0
  147. package/dist/esm/core/agent/window/types.js +22 -0
  148. package/dist/esm/core/agent/window/types.js.map +1 -0
  149. package/dist/esm/core/pause.d.ts +42 -0
  150. package/dist/esm/core/pause.js +17 -0
  151. package/dist/esm/core/pause.js.map +1 -1
  152. package/dist/esm/events/dispatcher.d.ts +1 -1
  153. package/dist/esm/events/dispatcher.js.map +1 -1
  154. package/dist/esm/events/payloads.d.ts +26 -0
  155. package/dist/esm/events/registry.d.ts +5 -1
  156. package/dist/esm/events/registry.js +4 -0
  157. package/dist/esm/events/registry.js.map +1 -1
  158. package/dist/esm/index.d.ts +3 -2
  159. package/dist/esm/index.js +23 -6
  160. package/dist/esm/index.js.map +1 -1
  161. package/dist/esm/lib/mcp/mcpServe.js +39 -6
  162. package/dist/esm/lib/mcp/mcpServe.js.map +1 -1
  163. package/dist/esm/lib/mcp/types.d.ts +16 -0
  164. package/dist/esm/recorders/core/CompactionMeter.d.ts +25 -19
  165. package/dist/esm/recorders/core/CompactionMeter.js +27 -19
  166. package/dist/esm/recorders/core/CompactionMeter.js.map +1 -1
  167. package/dist/events/dispatcher.js.map +1 -1
  168. package/dist/events/registry.js +4 -0
  169. package/dist/events/registry.js.map +1 -1
  170. package/dist/index.js +40 -13
  171. package/dist/index.js.map +1 -1
  172. package/dist/lib/mcp/mcpServe.js +39 -6
  173. package/dist/lib/mcp/mcpServe.js.map +1 -1
  174. package/dist/recorders/core/CompactionMeter.js +27 -19
  175. package/dist/recorders/core/CompactionMeter.js.map +1 -1
  176. package/dist/types/conventions.d.ts +8 -6
  177. package/dist/types/conventions.d.ts.map +1 -1
  178. package/dist/types/core/Agent.d.ts +14 -6
  179. package/dist/types/core/Agent.d.ts.map +1 -1
  180. package/dist/types/core/RunnerBase.d.ts.map +1 -1
  181. package/dist/types/core/agent/AgentBuilder.d.ts +157 -4
  182. package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
  183. package/dist/types/core/agent/buildAgentChart.d.ts +16 -9
  184. package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
  185. package/dist/types/core/agent/middleware/errors.d.ts +52 -0
  186. package/dist/types/core/agent/middleware/errors.d.ts.map +1 -0
  187. package/dist/types/core/agent/middleware/index.d.ts +17 -0
  188. package/dist/types/core/agent/middleware/index.d.ts.map +1 -0
  189. package/dist/types/core/agent/middleware/ledger.d.ts +41 -0
  190. package/dist/types/core/agent/middleware/ledger.d.ts.map +1 -0
  191. package/dist/types/core/agent/middleware/outcomes.d.ts +46 -0
  192. package/dist/types/core/agent/middleware/outcomes.d.ts.map +1 -0
  193. package/dist/types/core/agent/middleware/runChain.d.ts +105 -0
  194. package/dist/types/core/agent/middleware/runChain.d.ts.map +1 -0
  195. package/dist/types/core/agent/middleware/types.d.ts +192 -0
  196. package/dist/types/core/agent/middleware/types.d.ts.map +1 -0
  197. package/dist/types/core/agent/stages/prepareFinal.d.ts +10 -0
  198. package/dist/types/core/agent/stages/prepareFinal.d.ts.map +1 -1
  199. package/dist/types/core/agent/stages/route.d.ts +29 -0
  200. package/dist/types/core/agent/stages/route.d.ts.map +1 -1
  201. package/dist/types/core/agent/stages/seed.d.ts +16 -1
  202. package/dist/types/core/agent/stages/seed.d.ts.map +1 -1
  203. package/dist/types/core/agent/stages/toolCalls.d.ts +23 -0
  204. package/dist/types/core/agent/stages/toolCalls.d.ts.map +1 -1
  205. package/dist/types/core/agent/stages/window.d.ts +64 -0
  206. package/dist/types/core/agent/stages/window.d.ts.map +1 -0
  207. package/dist/types/core/agent/types.d.ts +33 -8
  208. package/dist/types/core/agent/types.d.ts.map +1 -1
  209. package/dist/types/core/agent/window/errors.d.ts.map +1 -0
  210. package/dist/types/core/agent/window/index.d.ts +28 -0
  211. package/dist/types/core/agent/window/index.d.ts.map +1 -0
  212. package/dist/types/core/agent/window/notice.d.ts +47 -0
  213. package/dist/types/core/agent/window/notice.d.ts.map +1 -0
  214. package/dist/types/core/agent/window/options.d.ts +34 -0
  215. package/dist/types/core/agent/window/options.d.ts.map +1 -0
  216. package/dist/types/core/agent/window/removal.d.ts +23 -0
  217. package/dist/types/core/agent/window/removal.d.ts.map +1 -0
  218. package/dist/types/core/agent/window/strategies/drop.d.ts +55 -0
  219. package/dist/types/core/agent/window/strategies/drop.d.ts.map +1 -0
  220. package/dist/types/core/agent/window/strategies/slidingWindow.d.ts +49 -0
  221. package/dist/types/core/agent/window/strategies/slidingWindow.d.ts.map +1 -0
  222. package/dist/types/core/agent/window/strategies/summarizeOldest.d.ts +43 -0
  223. package/dist/types/core/agent/window/strategies/summarizeOldest.d.ts.map +1 -0
  224. package/dist/types/core/agent/window/strategies/tokenBudget.d.ts +48 -0
  225. package/dist/types/core/agent/window/strategies/tokenBudget.d.ts.map +1 -0
  226. package/dist/types/core/agent/window/strategy.d.ts +182 -0
  227. package/dist/types/core/agent/window/strategy.d.ts.map +1 -0
  228. package/dist/types/core/agent/window/summarize.d.ts.map +1 -0
  229. package/dist/types/core/agent/window/turns.d.ts +109 -0
  230. package/dist/types/core/agent/window/turns.d.ts.map +1 -0
  231. package/dist/types/core/agent/window/types.d.ts +264 -0
  232. package/dist/types/core/agent/window/types.d.ts.map +1 -0
  233. package/dist/types/core/pause.d.ts +42 -0
  234. package/dist/types/core/pause.d.ts.map +1 -1
  235. package/dist/types/events/dispatcher.d.ts +1 -1
  236. package/dist/types/events/dispatcher.d.ts.map +1 -1
  237. package/dist/types/events/payloads.d.ts +26 -0
  238. package/dist/types/events/payloads.d.ts.map +1 -1
  239. package/dist/types/events/registry.d.ts +5 -1
  240. package/dist/types/events/registry.d.ts.map +1 -1
  241. package/dist/types/index.d.ts +3 -2
  242. package/dist/types/index.d.ts.map +1 -1
  243. package/dist/types/lib/mcp/mcpServe.d.ts.map +1 -1
  244. package/dist/types/lib/mcp/types.d.ts +16 -0
  245. package/dist/types/lib/mcp/types.d.ts.map +1 -1
  246. package/dist/types/recorders/core/CompactionMeter.d.ts +25 -19
  247. package/dist/types/recorders/core/CompactionMeter.d.ts.map +1 -1
  248. package/package.json +1 -1
  249. package/dist/core/agent/compaction/errors.js.map +0 -1
  250. package/dist/core/agent/compaction/index.js +0 -24
  251. package/dist/core/agent/compaction/index.js.map +0 -1
  252. package/dist/core/agent/compaction/strategy.js +0 -152
  253. package/dist/core/agent/compaction/strategy.js.map +0 -1
  254. package/dist/core/agent/compaction/summarize.js.map +0 -1
  255. package/dist/core/agent/compaction/turns.js.map +0 -1
  256. package/dist/core/agent/compaction/types.js +0 -21
  257. package/dist/core/agent/compaction/types.js.map +0 -1
  258. package/dist/core/agent/stages/compact.js +0 -130
  259. package/dist/core/agent/stages/compact.js.map +0 -1
  260. package/dist/esm/core/agent/compaction/errors.js.map +0 -1
  261. package/dist/esm/core/agent/compaction/index.d.ts +0 -18
  262. package/dist/esm/core/agent/compaction/index.js +0 -18
  263. package/dist/esm/core/agent/compaction/index.js.map +0 -1
  264. package/dist/esm/core/agent/compaction/strategy.d.ts +0 -103
  265. package/dist/esm/core/agent/compaction/strategy.js +0 -148
  266. package/dist/esm/core/agent/compaction/strategy.js.map +0 -1
  267. package/dist/esm/core/agent/compaction/summarize.js.map +0 -1
  268. package/dist/esm/core/agent/compaction/turns.d.ts +0 -85
  269. package/dist/esm/core/agent/compaction/turns.js.map +0 -1
  270. package/dist/esm/core/agent/compaction/types.d.ts +0 -148
  271. package/dist/esm/core/agent/compaction/types.js +0 -20
  272. package/dist/esm/core/agent/compaction/types.js.map +0 -1
  273. package/dist/esm/core/agent/stages/compact.d.ts +0 -59
  274. package/dist/esm/core/agent/stages/compact.js +0 -126
  275. package/dist/esm/core/agent/stages/compact.js.map +0 -1
  276. package/dist/types/core/agent/compaction/errors.d.ts.map +0 -1
  277. package/dist/types/core/agent/compaction/index.d.ts +0 -19
  278. package/dist/types/core/agent/compaction/index.d.ts.map +0 -1
  279. package/dist/types/core/agent/compaction/strategy.d.ts +0 -104
  280. package/dist/types/core/agent/compaction/strategy.d.ts.map +0 -1
  281. package/dist/types/core/agent/compaction/summarize.d.ts.map +0 -1
  282. package/dist/types/core/agent/compaction/turns.d.ts +0 -86
  283. package/dist/types/core/agent/compaction/turns.d.ts.map +0 -1
  284. package/dist/types/core/agent/compaction/types.d.ts +0 -149
  285. package/dist/types/core/agent/compaction/types.d.ts.map +0 -1
  286. package/dist/types/core/agent/stages/compact.d.ts +0 -60
  287. package/dist/types/core/agent/stages/compact.d.ts.map +0 -1
  288. /package/dist/core/agent/{compaction → window}/errors.js +0 -0
  289. /package/dist/core/agent/{compaction → window}/summarize.js +0 -0
  290. /package/dist/esm/core/agent/{compaction → window}/errors.d.ts +0 -0
  291. /package/dist/esm/core/agent/{compaction → window}/errors.js +0 -0
  292. /package/dist/esm/core/agent/{compaction → window}/summarize.d.ts +0 -0
  293. /package/dist/esm/core/agent/{compaction → window}/summarize.js +0 -0
  294. /package/dist/types/core/agent/{compaction → window}/errors.d.ts +0 -0
  295. /package/dist/types/core/agent/{compaction → window}/summarize.d.ts +0 -0
@@ -0,0 +1,192 @@
1
+ /**
2
+ * middleware/types — PUBLIC. The shape of a governance chain.
3
+ *
4
+ * Pattern: Chain of Responsibility (GoF), with the one dangerous answer
5
+ * removed at the type level.
6
+ * Role: core/ layer. Two chains, one vocabulary:
7
+ *
8
+ * `toolMiddleware` wraps every tool dispatch
9
+ * `messageMiddleware` wraps the message boundary — the input
10
+ * before the model sees it, the output
11
+ * before the caller receives it
12
+ *
13
+ * Emits: N/A. A middleware is a pure decision. It never touches scope,
14
+ * never emits and never writes — the stage does all of that, so
15
+ * "record everything that happened" lives in ONE place rather
16
+ * than being re-implemented per middleware.
17
+ *
18
+ * ## The law that shapes these types
19
+ *
20
+ * **A middleware cannot answer for the tool.** The outcome union has three
21
+ * arms — allow, deny, ask — and no `result` arm. There is no spelling of
22
+ * "here is what the tool would have returned". Whatever the chain decides,
23
+ * the answer the model finally reads is the real tool's output or a
24
+ * refusal. That is not a convention a reviewer has to enforce; it is the
25
+ * absence of a field.
26
+ *
27
+ * **A transform declares itself.** `allow(value, why)` requires a reason
28
+ * whenever it changes something, and the stage commits BOTH the original
29
+ * and the transformed value into the run's ledger. A prompt scrubbed by a
30
+ * middleware that hid its own scrubbing would poison every slice taken
31
+ * afterwards: the trace would show text nobody ever sent.
32
+ *
33
+ * **`ask` exists only where a pause exists.** `ToolOutcome` has it because
34
+ * tool dispatch runs inside a footprintjs pausable stage — the same door
35
+ * `checkIn` and `askHuman` already go through. `MessageOutcome` does not,
36
+ * because the message boundary is a plain stage, and inventing a second
37
+ * pause to give it one would be a worse answer than not offering it.
38
+ */
39
+ import type { LLMMessage } from '../../../adapters/types.js';
40
+ import type { MemoryIdentity } from '../../../memory/identity/types.js';
41
+ /**
42
+ * Let the call through — optionally with a replacement for what the chain
43
+ * carries forward.
44
+ *
45
+ * `allow()` passes the value along untouched. `allow(value, why)` replaces
46
+ * it and says why; the `why` is not decoration, it is the row the ledger
47
+ * shows a person asking "who changed this, and what did it look like
48
+ * before?".
49
+ */
50
+ export interface AllowOutcome<T> {
51
+ readonly kind: 'allow';
52
+ /** The replacement value. Absent = pass through unchanged. */
53
+ readonly value?: T;
54
+ /** Why the value changed. Present whenever `value` is. */
55
+ readonly why?: string;
56
+ }
57
+ /**
58
+ * Refuse the call. For a tool, `reason` reaches the model verbatim as the
59
+ * tool result and the run continues — a denial is data the agent can adapt
60
+ * to, not a crash. For a message, `reason` surfaces as a
61
+ * `MessageDeniedError` at the API boundary.
62
+ */
63
+ export interface DenyOutcome {
64
+ readonly kind: 'deny';
65
+ readonly reason: string;
66
+ }
67
+ /** Suspend the run and put the question to a person. Tool dispatch only. */
68
+ export interface AskOutcome {
69
+ readonly kind: 'ask';
70
+ readonly payload: AskPayload;
71
+ }
72
+ /** What a person is being asked. Carried verbatim to the checkpoint. */
73
+ export interface AskPayload {
74
+ /** The question, in your own words. Shown to whoever answers. */
75
+ readonly question: string;
76
+ /** Anything else the answering UI should render. Never interpreted here. */
77
+ readonly detail?: unknown;
78
+ }
79
+ /**
80
+ * Everything a tool middleware may answer. Closed, and every arm has a
81
+ * home in this codebase: allow rides the normal dispatch, deny rides the
82
+ * synthetic tool result every other gate already uses, ask rides the
83
+ * pausable-stage checkpoint that `checkIn` rides.
84
+ */
85
+ export type ToolOutcome = AllowOutcome<Readonly<Record<string, unknown>>> | DenyOutcome | AskOutcome;
86
+ /** Everything a message middleware may answer. No `ask` — see the header. */
87
+ export type MessageOutcome = AllowOutcome<string> | DenyOutcome;
88
+ /** The call a tool middleware is deciding about. */
89
+ export interface ToolMiddlewareContext {
90
+ readonly toolName: string;
91
+ /** Matches `stream.tool_start.toolCallId` for this dispatch. */
92
+ readonly toolCallId: string;
93
+ /** ReAct iteration this call belongs to. */
94
+ readonly iteration: number;
95
+ /**
96
+ * The args as THIS middleware sees them — every earlier transform in the
97
+ * chain already applied. The first middleware sees what the model asked
98
+ * for; the last sees what the tool is about to receive.
99
+ */
100
+ readonly args: Readonly<Record<string, unknown>>;
101
+ /** Conversation so far, including the assistant turn that made this call. */
102
+ readonly history: readonly LLMMessage[];
103
+ /** Multi-tenant run identity, when the run carried one. */
104
+ readonly identity?: MemoryIdentity;
105
+ /** Abort signal from `run({ env: { signal } })`. */
106
+ readonly signal?: AbortSignal;
107
+ }
108
+ /** The message a message middleware is deciding about. */
109
+ export interface MessageMiddlewareContext {
110
+ /**
111
+ * `'input'` runs at the very top of the run, BEFORE the user's message is
112
+ * committed — so the window strategies, the injections, the slots, the
113
+ * request bytes and every later slice all see the transformed text and
114
+ * agree with each other. `'output'` runs where the final answer is
115
+ * captured, so the record and the caller receive the same string.
116
+ */
117
+ readonly phase: 'input' | 'output';
118
+ /** The content as THIS middleware sees it — earlier transforms applied. */
119
+ readonly content: string;
120
+ /** Conversation so far. Empty at `'input'`. */
121
+ readonly history: readonly LLMMessage[];
122
+ readonly identity?: MemoryIdentity;
123
+ readonly signal?: AbortSignal;
124
+ }
125
+ /**
126
+ * One link in the tool-dispatch chain.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * const noProdWrites: ToolMiddleware = {
131
+ * name: 'no-prod-writes',
132
+ * onToolCall: (call) =>
133
+ * call.args.env === 'prod' ? deny('writes to prod need a change ticket') : allow(),
134
+ * };
135
+ * ```
136
+ */
137
+ export interface ToolMiddleware {
138
+ /** Identifies this middleware in every ledger row and event it produces. */
139
+ readonly name: string;
140
+ onToolCall(call: ToolMiddlewareContext): ToolOutcome | Promise<ToolOutcome>;
141
+ }
142
+ /**
143
+ * One link in the message chain. Runs at both phases unless it decides
144
+ * otherwise by reading `msg.phase`.
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * const scrubSSNs: MessageMiddleware = {
149
+ * name: 'scrub-ssns',
150
+ * onMessage: (msg) => {
151
+ * const clean = msg.content.replace(/\b\d{3}-\d{2}-\d{4}\b/g, '[ssn]');
152
+ * return clean === msg.content ? allow() : allow(clean, 'masked a US SSN');
153
+ * },
154
+ * };
155
+ * ```
156
+ */
157
+ export interface MessageMiddleware {
158
+ readonly name: string;
159
+ onMessage(msg: MessageMiddlewareContext): MessageOutcome | Promise<MessageOutcome>;
160
+ }
161
+ /**
162
+ * One row per middleware decision, committed to `scope.middlewareDecisions`.
163
+ *
164
+ * Every decision files a row, including the pass-throughs. A chain that
165
+ * only recorded its refusals would leave you unable to tell "the middleware
166
+ * looked and was fine with it" apart from "the middleware never ran" — and
167
+ * those are different facts about a run.
168
+ */
169
+ export interface MiddlewareDecision {
170
+ /** The middleware's `name`. */
171
+ readonly middleware: string;
172
+ /** Which chain this row came from. */
173
+ readonly at: 'tool' | 'message';
174
+ /** Message chain only. */
175
+ readonly phase?: 'input' | 'output';
176
+ /** Tool chain only. */
177
+ readonly toolName?: string;
178
+ /** Tool chain only. */
179
+ readonly toolCallId?: string;
180
+ /** ReAct iteration. `0` for the `'input'` phase, which runs before iter 1. */
181
+ readonly iteration: number;
182
+ readonly outcome: 'allow' | 'deny' | 'ask';
183
+ /** True when this row changed the value the chain carries forward. */
184
+ readonly changed: boolean;
185
+ /** The transform's `why`, the denial's `reason`, or the ask's `question`. */
186
+ readonly why?: string;
187
+ /** The value before this middleware. Present only when `changed`. */
188
+ readonly before?: unknown;
189
+ /** The value after this middleware. Present only when `changed`. */
190
+ readonly after?: unknown;
191
+ }
192
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/core/agent/middleware/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAIxE;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,8DAA8D;IAC9D,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACnB,0DAA0D;IAC1D,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,4EAA4E;AAC5E,MAAM,WAAW,UAAU;IACzB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AAoE;IACpE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B"}
@@ -13,6 +13,16 @@
13
13
  *
14
14
  * Pure function — no closure over Agent class state. Imported and
15
15
  * passed directly to `flowChart(...)` in buildAgentChart.
16
+ *
17
+ * NOT the seam for `messageMiddleware`'s `'output'` half, deliberately.
18
+ * This stage runs inside the Final BRANCH subflow, whose state does not
19
+ * merge back into the run (a branch mount hands its outputMapper the
20
+ * branch's RESULT, not its scope). Rows filed here would land in an
21
+ * isolated commit log and never reach `snapshot.sharedState`, splitting
22
+ * one ledger across two places. The chain runs one stage earlier instead
23
+ * — in the Route decider, in the main chart — and rewrites
24
+ * `llmLatestContent`, which is the value this stage copies. See
25
+ * `stages/route.ts`.
16
26
  */
17
27
  import type { TypedScope } from 'footprintjs';
18
28
  import type { AgentState } from '../types.js';
@@ -1 +1 @@
1
- {"version":3,"file":"prepareFinal.d.ts","sourceRoot":"","sources":["../../../../../src/core/agent/stages/prepareFinal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,eAAO,MAAM,iBAAiB,UAAW,WAAW,UAAU,CAAC,KAAG,IAkCjE,CAAC"}
1
+ {"version":3,"file":"prepareFinal.d.ts","sourceRoot":"","sources":["../../../../../src/core/agent/stages/prepareFinal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,eAAO,MAAM,iBAAiB,UAAW,WAAW,UAAU,CAAC,KAAG,IAkCjE,CAAC"}
@@ -14,6 +14,35 @@
14
14
  */
15
15
  import type { TypedScope } from 'footprintjs';
16
16
  import type { AgentState } from '../types.js';
17
+ import type { MessageMiddleware } from '../middleware/types.js';
17
18
  export type RouteBranch = 'tool-calls' | 'final';
18
19
  export declare const routeDeciderStage: (scope: TypedScope<AgentState>) => RouteBranch;
20
+ /**
21
+ * Build the Route decider, optionally carrying the `'output'` half of the
22
+ * message chain.
23
+ *
24
+ * ## Why the chain runs HERE and not in PrepareFinal
25
+ *
26
+ * PrepareFinal is where `finalContent` is set, which makes it look like the
27
+ * output seam. It is not, for one structural reason: it lives inside the Final
28
+ * BRANCH subflow, and a branch mount hands its `outputMapper` the branch's
29
+ * RESULT, not its scope — so nothing that stage writes reaches the run's
30
+ * shared state. Ledger rows filed there would sit in an isolated commit log,
31
+ * and one ledger would be split across two places a reader has to know about.
32
+ *
33
+ * The decider is one stage earlier, in the main chart, and it is the first
34
+ * moment the run KNOWS this turn is the final answer. Its writes commit before
35
+ * the branch resolves (footprintjs commits a decider stage ahead of matching
36
+ * the branch), and the value it rewrites — `llmLatestContent` — is exactly
37
+ * what PrepareFinal copies into `finalContent`. So the caller, the committed
38
+ * record, the `newMessages` the memory writes persist, and the ledger row all
39
+ * carry the same string. One seam, one answer.
40
+ *
41
+ * The `'tool-calls'` path is untouched: a turn that is still calling tools has
42
+ * not produced an answer, and running an output rule over a half-finished turn
43
+ * would be running it over something that is not the output.
44
+ *
45
+ * Empty chain → the exact synchronous decider this file has always exported.
46
+ */
47
+ export declare function buildRouteDeciderStage(messageMiddleware?: readonly MessageMiddleware[]): (scope: TypedScope<AgentState>) => RouteBranch | Promise<RouteBranch>;
19
48
  //# sourceMappingURL=route.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../src/core/agent/stages/route.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,OAAO,CAAC;AAEjD,eAAO,MAAM,iBAAiB,UAAW,WAAW,UAAU,CAAC,KAAG,WAmBjE,CAAC"}
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../../../src/core/agent/stages/route.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAIhE,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,OAAO,CAAC;AAEjD,eAAO,MAAM,iBAAiB,UAAW,WAAW,UAAU,CAAC,KAAG,WAmBjE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,sBAAsB,CACpC,iBAAiB,CAAC,EAAE,SAAS,iBAAiB,EAAE,GAC/C,CAAC,KAAK,EAAE,UAAU,CAAC,UAAU,CAAC,KAAK,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CA6BvE"}
@@ -19,6 +19,7 @@
19
19
  import type { TypedScope } from 'footprintjs';
20
20
  import type { LLMMessage, LLMToolSchema } from '../../../adapters/types.js';
21
21
  import type { AgentInput, AgentState, RunConfig } from '../types.js';
22
+ import type { MessageMiddleware } from '../middleware/types.js';
22
23
  export interface SeedStageDeps {
23
24
  /** Resolved `clampIterations(opts.maxIterations ?? 10)`. Frozen at
24
25
  * chart-build time. */
@@ -53,11 +54,25 @@ export interface SeedStageDeps {
53
54
  * written, so the commit log is byte-identical to earlier releases.
54
55
  */
55
56
  readonly resolveRunConfig?: (input: AgentInput) => RunConfig | undefined;
57
+ /**
58
+ * The message chain (`.messageMiddleware(...)`), walked here at the
59
+ * `'input'` phase — BEFORE `userMessage` and `history` are written.
60
+ *
61
+ * This is the only placement that keeps the run honest. Everything
62
+ * downstream reads `scope.history`: the window strategies, the injection
63
+ * engine, all three slots, the request that goes on the wire, and every
64
+ * slice taken afterwards. Transform later than this and those components
65
+ * disagree about what the user actually said — the trace would show one
66
+ * message and the model would have answered another.
67
+ *
68
+ * Empty / undefined → seed stays the synchronous stage it always was.
69
+ */
70
+ readonly messageMiddleware?: readonly MessageMiddleware[];
56
71
  }
57
72
  /**
58
73
  * Build the seed stage function for an Agent instance. Captures both
59
74
  * the chart-build-time constants and the per-run mutable accessors
60
75
  * via the deps object.
61
76
  */
62
- export declare function buildSeedStage(deps: SeedStageDeps): (scope: TypedScope<AgentState>) => void;
77
+ export declare function buildSeedStage(deps: SeedStageDeps): (scope: TypedScope<AgentState>) => void | Promise<void>;
63
78
  //# sourceMappingURL=seed.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../../../../../src/core/agent/stages/seed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE5E,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAErE,MAAM,WAAW,aAAa;IAC5B;4BACwB;IACxB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,0EAA0E;IAC1E,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC;;iEAE6D;IAC7D,QAAQ,CAAC,WAAW,EAAE,SAAS,aAAa,EAAE,CAAC;IAC/C;;;;;;OAMG;IACH,QAAQ,CAAC,2BAA2B,EAAE,MAAM,SAAS,UAAU,EAAE,GAAG,SAAS,CAAC;IAC9E;;;;;OAKG;IACH,QAAQ,CAAC,eAAe,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IACnD;;;;;;;OAOG;IACH,QAAQ,CAAC,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AAE,aAAa,GAClB,CAAC,KAAK,EAAE,UAAU,CAAC,UAAU,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAsCzD"}
@@ -20,6 +20,19 @@
20
20
  * `tool.execute`. Deny → tool not executed; result is a synthetic
21
21
  * denial string. Allow / gate_open → execution proceeds.
22
22
  *
23
+ * Gate order for one call, and why it is this order:
24
+ *
25
+ * permission → MIDDLEWARE CHAIN → arg validation → check-in →
26
+ * credentials → execute
27
+ *
28
+ * The chain sits after the permission gate so an existing checker still
29
+ * decides first (a denial there means no middleware runs), and before arg
30
+ * validation so validation judges the args that will actually be sent —
31
+ * a middleware that transformed args into something the tool's schema
32
+ * rejects must be caught, not forwarded. A middleware answering `ask`
33
+ * pauses on the SAME wire `checkIn` uses; the human's answer is a
34
+ * decision, not a result, so the chain resumes and the REAL tool runs.
35
+ *
23
36
  * `read_skill` is the auto-attached activation tool — when the LLM
24
37
  * calls it with a valid Skill id, the next InjectionEngine pass
25
38
  * activates that Skill (lifetime: turn).
@@ -31,6 +44,7 @@ import type { CredentialProvider } from '../../../identity/types.js';
31
44
  import { type ResolvedCheckInConfig } from '../../checkin.js';
32
45
  import type { ProviderToolCache } from '../../slots/buildToolsSlot.js';
33
46
  import type { Tool } from '../../tools.js';
47
+ import type { ToolMiddleware } from '../middleware/types.js';
34
48
  import { type ToolArgValidationMode } from '../toolArgsValidation.js';
35
49
  import type { AgentState } from '../types.js';
36
50
  export interface ToolCallsHandlerDeps {
@@ -78,6 +92,15 @@ export interface ToolCallsHandlerDeps {
78
92
  * Agent (no check-in). The gate fires ONLY for tools that declared `checkIn`.
79
93
  */
80
94
  readonly checkIn?: ResolvedCheckInConfig;
95
+ /**
96
+ * The tool-dispatch governance chain (`.toolMiddleware(...)`), in
97
+ * declaration order. Walked AFTER the permission gate — so an existing
98
+ * `PermissionChecker` still decides first and a denial there means no
99
+ * middleware runs at all — and BEFORE arg validation, so validation judges
100
+ * the args that will actually be sent rather than the ones the model
101
+ * proposed. Empty / undefined → not walked, no ledger key, no events.
102
+ */
103
+ readonly toolMiddleware?: readonly ToolMiddleware[];
81
104
  }
82
105
  /**
83
106
  * Build the pausable tool-call handler for the agent's chart.
@@ -1 +1 @@
1
- {"version":3,"file":"toolCalls.d.ts","sourceRoot":"","sources":["../../../../../src/core/agent/stages/toolCalls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,KAAK,EAAc,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAIhF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,KAAK,EAAc,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAGjF,OAAO,EAIL,KAAK,qBAAqB,EAG3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,WAAW,oBAAoB;IACnC;;4DAEwD;IACxD,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACnD;;qDAEiD;IACjD,QAAQ,CAAC,oBAAoB,CAAC,EAAE,YAAY,CAAC;IAC7C;;;;;OAKG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IAC/C;;4DAEwD;IACxD,QAAQ,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IAC/C;;kEAE8D;IAC9D,QAAQ,CAAC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACjD;;;8EAG0E;IAC1E,QA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ACjD,QAAQ,CAAC,oBAAoB,CAAC,EAAE,YAAY,CAAC;IAC7C;;;;;OAKG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IAC/C;;4DAEwD;IACxD,QAAQ,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IAC/C;;kEAE8D;IAC9D,QAAQ,CAAC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACjD;;;8EAG0E;IAC1E,QAAQ,CAAC,iBAAiB,CAAC,EAAE,qBAAqB,CAAC;IACnD;;;;;;OAMG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,cAAc,CAAC,EAAE,MAAM,KAAK,SAAS,MAAM,EAAE,CAAC;IAC1E;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,qBAAqB,CAAC;IACzC;;;;;;;OAOG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,cAAc,EAAE,CAAC;CACrD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,oBAAoB,GACzB,eAAe,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CA60BzC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * window — the loop-head stage that applies the agent's window strategy.
3
+ *
4
+ * Runs once per ReAct iteration boundary, as the loop target, so everything
5
+ * downstream in the turn — the injection engine's triggers, all three context
6
+ * slots, and the wire itself — sees ONE window. No component gets a different
7
+ * past than the model does.
8
+ *
9
+ * The law: **it edits the window, never the ledger.** The turns a strategy
10
+ * removes were committed by `seed#0` / `tool-calls#N` before this stage ran
11
+ * and stay in those bundles byte-identical; footprintjs's commit log is
12
+ * append-only, so a removal cannot erase history even in principle. What it
13
+ * can do is stop re-sending it — and say so, in its own commit, naming every
14
+ * runtimeStageId whose messages left. A compacted (or trimmed) run is still a
15
+ * provable run.
16
+ *
17
+ * This file is deliberately all WIRING. The decision — what the window should
18
+ * become — lives behind `WindowStrategy` (window/strategy.ts, public since
19
+ * 7.17), so the duty to record, emit and cost what happened stays in exactly
20
+ * one place instead of being re-implemented per strategy. The TRIGGER lives
21
+ * in the strategy too: `plan()` is called at every boundary and answers
22
+ * `undefined` when it did not engage, which is what lets `slidingWindow`
23
+ * trigger on turn count while the token-triggered strategies refuse by name
24
+ * on a provider that reports no usage.
25
+ *
26
+ * Emits (existing vocabulary only — no new event types):
27
+ * agentfootprint.context.evicted — one per message leaving the window
28
+ * agentfootprint.context.budget_pressure — one per visit that HAS a budget
29
+ * (omitted by strategies that do
30
+ * not, rather than reporting a cap
31
+ * nobody configured)
32
+ * agentfootprint.cost.tick — when a pricingTable is set: a
33
+ * summarizer call is a real billed
34
+ * call and counts
35
+ *
36
+ * A summarizer call is deliberately NOT bracketed with `stream.llm_start` /
37
+ * `llm_end`: those carry an `iteration` and every consumer pairs them by it,
38
+ * so a second bracket inside one iteration would corrupt the pairing. Its
39
+ * cost rides the cost channel and its tokens are recorded in the commit.
40
+ */
41
+ import type { TypedScope } from 'footprintjs';
42
+ import type { PricingTable } from '../../../adapters/types.js';
43
+ import type { CompactionMeterHandle } from '../../../recorders/core/CompactionMeter.js';
44
+ import type { WindowStrategy } from '../window/strategy.js';
45
+ import type { AgentState } from '../types.js';
46
+ export interface WindowStageDeps {
47
+ /** The agent's one window strategy. */
48
+ readonly strategy: WindowStrategy;
49
+ /** The meter this stage reads. Attached inline by `Agent.createExecutor`. */
50
+ readonly meter: CompactionMeterHandle;
51
+ /** The agent's own model — a billing strategy's default. */
52
+ readonly agentModel: string;
53
+ /** The MAIN provider's name, for a refusal that names it. */
54
+ readonly providerName: string;
55
+ /** Optional pricing adapter, so a summarizer call is costed like any other. */
56
+ readonly pricingTable?: PricingTable;
57
+ /** Optional cumulative USD cap per run. */
58
+ readonly costBudget?: number;
59
+ /** Injectable clock (tests pin survivalMs). */
60
+ readonly now?: () => number;
61
+ }
62
+ /** Build the window stage. */
63
+ export declare function buildWindowStage(deps: WindowStageDeps): (scope: TypedScope<AgentState>) => Promise<void>;
64
+ //# sourceMappingURL=window.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../../../../../src/core/agent/stages/window.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAc,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AAKxF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,WAAW,eAAe;IAC9B,uCAAuC;IACvC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,EAAE,qBAAqB,CAAC;IACtC,4DAA4D;IAC5D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,6DAA6D;IAC7D,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,+EAA+E;IAC/E,QAAQ,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC;IACrC,2CAA2C;IAC3C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,+CAA+C;IAC/C,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CAC7B;AAED,8BAA8B;AAC9B,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,eAAe,GACpB,CAAC,KAAK,EAAE,UAAU,CAAC,UAAU,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CA4GlD"}
@@ -18,7 +18,8 @@ import type { CredentialProvider } from '../../identity/types.js';
18
18
  import type { ToolArgValidationMode } from './toolArgsValidation.js';
19
19
  import type { ThinkingBlock } from '../../thinking/types.js';
20
20
  import type { ReliabilityScope } from '../../reliability/types.js';
21
- import type { CompactionRecord } from './compaction/types.js';
21
+ import type { WindowRecord } from './window/types.js';
22
+ import type { MiddlewareDecision } from './middleware/types.js';
22
23
  /**
23
24
  * Dials for the deferred observer queue (RFC-001) — only meaningful with
24
25
  * `observerDelivery: 'deferred'` (passing them without it throws at
@@ -347,6 +348,23 @@ export interface AgentState {
347
348
  pausedToolStartMs: number;
348
349
  pausedCheckIn?: boolean;
349
350
  pausedCheckInArgs?: Readonly<Record<string, unknown>>;
351
+ pausedAsk?: boolean;
352
+ pausedAskArgs?: Readonly<Record<string, unknown>>;
353
+ pausedAskIndex?: number;
354
+ pausedAskMiddleware?: string;
355
+ /** One row per middleware decision, in the order they were decided —
356
+ * including the pass-throughs, because "the rule looked and was fine with
357
+ * it" and "the rule never ran" are different facts about a run. A transform
358
+ * files both the value it received and the value it produced, so a slice
359
+ * taken later can find the moment the text changed and who changed it.
360
+ * Written only by an agent that configured a chain; absent otherwise. */
361
+ middlewareDecisions?: readonly MiddlewareDecision[];
362
+ /** Set by the seed / prepare-final stage when a `messageMiddleware` returned
363
+ * `deny`. Read at the API boundary, where it becomes a `MessageDeniedError`.
364
+ * Never carries the refused content — see MessageDeniedError. */
365
+ messageDeniedReason?: string;
366
+ messageDeniedPhase?: 'input' | 'output';
367
+ messageDeniedBy?: string;
350
368
  cumTokensInput: number;
351
369
  cumTokensOutput: number;
352
370
  cumEstimatedUsd: number;
@@ -408,16 +426,23 @@ export interface AgentState {
408
426
  /** The base system prompt `.configure()` resolved for THIS run, replacing
409
427
  * `.system(...)`. Same rule: absent unless a resolver returned one. */
410
428
  resolvedInstructions?: string;
411
- /** One record per OVER-BUDGET visit to the compaction stage — including the
412
- * visits that folded nothing, which are the interesting ones. Written only
413
- * by an agent built with `.compaction()`; absent otherwise, so an agent
414
- * without it commits exactly the keys it always did.
429
+ /** One record per visit to the window stage that ENGAGED — including the
430
+ * visits that removed nothing, which are the interesting ones. Written
431
+ * only by an agent built with `.window()` or `.compaction()`; absent
432
+ * otherwise, so an agent without one commits exactly the keys it always
433
+ * did.
415
434
  *
416
- * This array is the fold's half of the law: the window shrank, and the
435
+ * This array is the strategy's half of the law: the window shrank, and the
417
436
  * ledger says which stages' messages left it, how many, and what the last
418
437
  * call actually measured. The messages themselves are untouched in the
419
- * commit bundles that wrote them. */
420
- compactions?: readonly CompactionRecord[];
438
+ * commit bundles that wrote them.
439
+ *
440
+ * The key is `compactions` because that is what it shipped as in 7.16,
441
+ * when compaction was the family's only member. It is committed state —
442
+ * public surface for anyone reading a run — so it keeps its name rather
443
+ * than break every reader for a better word. Narrow a record by its
444
+ * `strategy` field, not by the key it lives under. */
445
+ compactions?: readonly WindowRecord[];
421
446
  /** Set when a `PermissionChecker` returns `{ result: 'halt', ... }`.
422
447
  * `Agent.run()` reads these at the API boundary and throws a typed
423
448
  * `PolicyHaltError` carrying the same context — the chart $break's
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/core/agent/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,qBAAqB,EACrB,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,YAAY,EACb,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,y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CAAC,CAAC,CAAC;IACnD,yCAAyC;IACzC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,kEAAkE;IAClE,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAG7B;;;6EAGyE;IACzE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;0CAIsC;IACtC,cAAc,EAAE,SAAS,aAAa,EAAE,CAAC;IAGzC;;;;;;iFAM6E;IAC7E,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sBAAsB,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;IACzD,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B;kEAC8D;IAC9D,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,wBAAwB,CAAC,EAAE,MAAM,CAAC;CACnC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../../src/core/agent/window/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;GAYG;AACH,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,SAAkB,IAAI,iCAAiC;IACvD,4DAA4D;IAC5D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBAEd,QAAQ,EAAE,MAAM;CAY7B"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * window — the window-strategy family: keep the live context window inside
3
+ * its budget without ever losing the record.
4
+ *
5
+ * The one sentence: **a window strategy edits the WINDOW, never the LEDGER.**
6
+ * Removed turns stay in the commit log verbatim; the strategy files its own
7
+ * recorded step naming every `runtimeStageId` whose messages left. A summary
8
+ * is a claim about the past, so this library files it as a claim — not as the
9
+ * past. A drop is an absence, and it is named the same way.
10
+ *
11
+ * Three strategies ship, all sharing one turn segmentation and one refusal
12
+ * engine:
13
+ * `summarizeOldest` fold the oldest span into a summary (`.compaction()`)
14
+ * `slidingWindow` keep the last N turns, drop older ones
15
+ * `tokenBudget` counted-token trigger, drop instead of summarize
16
+ *
17
+ * Public surface (re-exported from the package root).
18
+ */
19
+ export { CompactionUnmeasurableError } from './errors.js';
20
+ export type { CompactionOptions, CompactionRecord, FoldRefusal, FoldRefusalReason, ResolvedCompaction, SlidingWindowOptions, SlidingWindowRecord, TokenBudgetOptions, TokenBudgetRecord, WindowRecord, WindowRefusal, WindowRefusalReason, } from './types.js';
21
+ export type { RemovalFacts, WindowEviction, WindowStrategy, WindowStrategyInput, WindowStrategyResult, } from './strategy.js';
22
+ export type { RemovalPlan, Turn } from './turns.js';
23
+ export { COMPACTED_FRAME_PREFIX, isCompactedSummary } from './summarize.js';
24
+ export { DROP_NOTICE_PREFIX, isDropNotice } from './notice.js';
25
+ export { summarizeOldest } from './strategies/summarizeOldest.js';
26
+ export { slidingWindow } from './strategies/slidingWindow.js';
27
+ export { tokenBudget } from './strategies/tokenBudget.js';
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/core/agent/window/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAC1D,YAAY,EACV,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,mBAAmB,GACpB,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,YAAY,EACZ,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * window/notice — the authored message a DROP leaves behind, and why it has
3
+ * to exist at all.
4
+ *
5
+ * Pattern: Authored envelope with no untrusted payload whatsoever.
6
+ * Role: core/ layer. Shared by both drop strategies.
7
+ * Emits: N/A.
8
+ *
9
+ * The first reason for this message is the WIRE, not the prose. An agent
10
+ * window looks like `user, assistant+tool, assistant+tool, …`, so dropping
11
+ * the oldest turns leaves an ASSISTANT message at the head — and the
12
+ * providers that care (Anthropic) require the window to open on a user turn.
13
+ * A silent drop of the window's head therefore produces a request the vendor
14
+ * rejects. Something must occupy that position.
15
+ *
16
+ * Given that we have to author a message there anyway, it should say what
17
+ * happened rather than be filler. So it does: how many messages left, at
18
+ * which iteration, by which strategy, and where they still are. Unlike the
19
+ * compaction frame there is no model output involved at ALL — every character
20
+ * below is written by this library, which is why a drop has no prompt-
21
+ * injection surface to speak of.
22
+ *
23
+ * It appears ONLY when the removal reaches the window's head. A removal in
24
+ * the middle leaves the original opening turn in place, so there is no wire
25
+ * problem to solve — and splicing a lone `user` message between two assistant
26
+ * turns is its own risk. The ledger names that removal either way.
27
+ *
28
+ * It does not accumulate: the notice is an ordinary oldest turn next time
29
+ * round, so the next drop absorbs it and files a fresh one.
30
+ */
31
+ import type { LLMMessage } from '../../../adapters/types.js';
32
+ /** Opening of the authored notice. Stable — tests and readers match on it. */
33
+ export declare const DROP_NOTICE_PREFIX = "[dropped history";
34
+ /**
35
+ * Build the message that takes the head position after a drop.
36
+ *
37
+ * `role: 'user'` for the same reason the compaction frame is: it is the head
38
+ * of the window, and the head of the window must be a user turn.
39
+ */
40
+ export declare function buildDropNotice(facts: {
41
+ readonly droppedMessageCount: number;
42
+ readonly iteration: number;
43
+ readonly strategy: string;
44
+ }): LLMMessage;
45
+ /** True when this message is a notice a previous drop wrote. */
46
+ export declare function isDropNotice(msg: LLMMessage | undefined): boolean;
47
+ //# sourceMappingURL=notice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notice.d.ts","sourceRoot":"","sources":["../../../../../src/core/agent/window/notice.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D,8EAA8E;AAC9E,eAAO,MAAM,kBAAkB,qBAAqB,CAAC;AAErD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE;IACrC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,GAAG,UAAU,CASb;AAED,gEAAgE;AAChE,wBAAgB,YAAY,CAAC,GAAG,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAEjE"}