@absol-labs/agent 0.9.1 → 0.11.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 (293) hide show
  1. package/README.md +184 -26
  2. package/dist/capability/invocation-capability.d.ts +18 -6
  3. package/dist/capability/invocation-capability.d.ts.map +1 -1
  4. package/dist/capability/invocation-capability.js.map +1 -1
  5. package/dist/cli/amounts.d.ts +26 -0
  6. package/dist/cli/amounts.d.ts.map +1 -0
  7. package/dist/cli/amounts.js +71 -0
  8. package/dist/cli/amounts.js.map +1 -0
  9. package/dist/cli/args.d.ts +32 -0
  10. package/dist/cli/args.d.ts.map +1 -0
  11. package/dist/cli/args.js +119 -0
  12. package/dist/cli/args.js.map +1 -0
  13. package/dist/cli/attesters.d.ts +51 -0
  14. package/dist/cli/attesters.d.ts.map +1 -0
  15. package/dist/cli/attesters.js +58 -0
  16. package/dist/cli/attesters.js.map +1 -0
  17. package/dist/cli/bin.d.ts +3 -0
  18. package/dist/cli/bin.d.ts.map +1 -0
  19. package/dist/cli/bin.js +5 -0
  20. package/dist/cli/bin.js.map +1 -0
  21. package/dist/cli/commands/claim.d.ts +13 -0
  22. package/dist/cli/commands/claim.d.ts.map +1 -0
  23. package/dist/cli/commands/claim.js +102 -0
  24. package/dist/cli/commands/claim.js.map +1 -0
  25. package/dist/cli/commands/close.d.ts +3 -0
  26. package/dist/cli/commands/close.d.ts.map +1 -0
  27. package/dist/cli/commands/close.js +55 -0
  28. package/dist/cli/commands/close.js.map +1 -0
  29. package/dist/cli/commands/discover.d.ts +3 -0
  30. package/dist/cli/commands/discover.d.ts.map +1 -0
  31. package/dist/cli/commands/discover.js +183 -0
  32. package/dist/cli/commands/discover.js.map +1 -0
  33. package/dist/cli/commands/invoke.d.ts +3 -0
  34. package/dist/cli/commands/invoke.d.ts.map +1 -0
  35. package/dist/cli/commands/invoke.js +142 -0
  36. package/dist/cli/commands/invoke.js.map +1 -0
  37. package/dist/cli/commands/mcp.d.ts +3 -0
  38. package/dist/cli/commands/mcp.d.ts.map +1 -0
  39. package/dist/cli/commands/mcp.js +113 -0
  40. package/dist/cli/commands/mcp.js.map +1 -0
  41. package/dist/cli/commands/open.d.ts +3 -0
  42. package/dist/cli/commands/open.d.ts.map +1 -0
  43. package/dist/cli/commands/open.js +331 -0
  44. package/dist/cli/commands/open.js.map +1 -0
  45. package/dist/cli/commands/reclaim-unverified.d.ts +3 -0
  46. package/dist/cli/commands/reclaim-unverified.d.ts.map +1 -0
  47. package/dist/cli/commands/reclaim-unverified.js +172 -0
  48. package/dist/cli/commands/reclaim-unverified.js.map +1 -0
  49. package/dist/cli/commands/reclaim.d.ts +33 -0
  50. package/dist/cli/commands/reclaim.d.ts.map +1 -0
  51. package/dist/cli/commands/reclaim.js +308 -0
  52. package/dist/cli/commands/reclaim.js.map +1 -0
  53. package/dist/cli/commands/status.d.ts +3 -0
  54. package/dist/cli/commands/status.d.ts.map +1 -0
  55. package/dist/cli/commands/status.js +43 -0
  56. package/dist/cli/commands/status.js.map +1 -0
  57. package/dist/cli/commands/streams.d.ts +3 -0
  58. package/dist/cli/commands/streams.d.ts.map +1 -0
  59. package/dist/cli/commands/streams.js +257 -0
  60. package/dist/cli/commands/streams.js.map +1 -0
  61. package/dist/cli/commands/watch.d.ts +3 -0
  62. package/dist/cli/commands/watch.d.ts.map +1 -0
  63. package/dist/cli/commands/watch.js +55 -0
  64. package/dist/cli/commands/watch.js.map +1 -0
  65. package/dist/cli/config.d.ts +61 -0
  66. package/dist/cli/config.d.ts.map +1 -0
  67. package/dist/cli/config.js +140 -0
  68. package/dist/cli/config.js.map +1 -0
  69. package/dist/cli/context.d.ts +29 -0
  70. package/dist/cli/context.d.ts.map +1 -0
  71. package/dist/cli/context.js +2 -0
  72. package/dist/cli/context.js.map +1 -0
  73. package/dist/cli/deps.d.ts +191 -0
  74. package/dist/cli/deps.d.ts.map +1 -0
  75. package/dist/cli/deps.js +277 -0
  76. package/dist/cli/deps.js.map +1 -0
  77. package/dist/cli/descriptor.d.ts +61 -0
  78. package/dist/cli/descriptor.d.ts.map +1 -0
  79. package/dist/cli/descriptor.js +78 -0
  80. package/dist/cli/descriptor.js.map +1 -0
  81. package/dist/cli/errors.d.ts +48 -0
  82. package/dist/cli/errors.d.ts.map +1 -0
  83. package/dist/cli/errors.js +129 -0
  84. package/dist/cli/errors.js.map +1 -0
  85. package/dist/cli/escape-hatch.d.ts +50 -0
  86. package/dist/cli/escape-hatch.d.ts.map +1 -0
  87. package/dist/cli/escape-hatch.js +45 -0
  88. package/dist/cli/escape-hatch.js.map +1 -0
  89. package/dist/cli/index.d.ts +8 -0
  90. package/dist/cli/index.d.ts.map +1 -0
  91. package/dist/cli/index.js +7 -0
  92. package/dist/cli/index.js.map +1 -0
  93. package/dist/cli/listings.d.ts +15 -0
  94. package/dist/cli/listings.d.ts.map +1 -0
  95. package/dist/cli/listings.js +56 -0
  96. package/dist/cli/listings.js.map +1 -0
  97. package/dist/cli/mandate.d.ts +66 -0
  98. package/dist/cli/mandate.d.ts.map +1 -0
  99. package/dist/cli/mandate.js +61 -0
  100. package/dist/cli/mandate.js.map +1 -0
  101. package/dist/cli/output.d.ts +33 -0
  102. package/dist/cli/output.d.ts.map +1 -0
  103. package/dist/cli/output.js +34 -0
  104. package/dist/cli/output.js.map +1 -0
  105. package/dist/cli/preflight.d.ts +38 -0
  106. package/dist/cli/preflight.d.ts.map +1 -0
  107. package/dist/cli/preflight.js +72 -0
  108. package/dist/cli/preflight.js.map +1 -0
  109. package/dist/cli/privy.d.ts +83 -0
  110. package/dist/cli/privy.d.ts.map +1 -0
  111. package/dist/cli/privy.js +230 -0
  112. package/dist/cli/privy.js.map +1 -0
  113. package/dist/cli/progress.d.ts +36 -0
  114. package/dist/cli/progress.d.ts.map +1 -0
  115. package/dist/cli/progress.js +40 -0
  116. package/dist/cli/progress.js.map +1 -0
  117. package/dist/cli/run.d.ts +25 -0
  118. package/dist/cli/run.d.ts.map +1 -0
  119. package/dist/cli/run.js +173 -0
  120. package/dist/cli/run.js.map +1 -0
  121. package/dist/cli/scan-range.d.ts +55 -0
  122. package/dist/cli/scan-range.d.ts.map +1 -0
  123. package/dist/cli/scan-range.js +57 -0
  124. package/dist/cli/scan-range.js.map +1 -0
  125. package/dist/cli/spend-policy.d.ts +60 -0
  126. package/dist/cli/spend-policy.d.ts.map +1 -0
  127. package/dist/cli/spend-policy.js +65 -0
  128. package/dist/cli/spend-policy.js.map +1 -0
  129. package/dist/cli/status.d.ts +90 -0
  130. package/dist/cli/status.d.ts.map +1 -0
  131. package/dist/cli/status.js +252 -0
  132. package/dist/cli/status.js.map +1 -0
  133. package/dist/cli/timeout.d.ts +30 -0
  134. package/dist/cli/timeout.d.ts.map +1 -0
  135. package/dist/cli/timeout.js +55 -0
  136. package/dist/cli/timeout.js.map +1 -0
  137. package/dist/cli/version.d.ts +12 -0
  138. package/dist/cli/version.d.ts.map +1 -0
  139. package/dist/cli/version.js +22 -0
  140. package/dist/cli/version.js.map +1 -0
  141. package/dist/cli/wallet.d.ts +164 -0
  142. package/dist/cli/wallet.d.ts.map +1 -0
  143. package/dist/cli/wallet.js +234 -0
  144. package/dist/cli/wallet.js.map +1 -0
  145. package/dist/frameworks/crewai.d.ts +10 -0
  146. package/dist/frameworks/crewai.d.ts.map +1 -1
  147. package/dist/frameworks/crewai.js +12 -2
  148. package/dist/frameworks/crewai.js.map +1 -1
  149. package/dist/gateway/caller-auth-gateway.d.ts +38 -3
  150. package/dist/gateway/caller-auth-gateway.d.ts.map +1 -1
  151. package/dist/gateway/caller-auth-gateway.js +25 -1
  152. package/dist/gateway/caller-auth-gateway.js.map +1 -1
  153. package/dist/gateway/http-server.d.ts +53 -0
  154. package/dist/gateway/http-server.d.ts.map +1 -1
  155. package/dist/gateway/http-server.js +189 -4
  156. package/dist/gateway/http-server.js.map +1 -1
  157. package/dist/gateway/server-entry.d.ts +1 -0
  158. package/dist/gateway/server-entry.js +1 -0
  159. package/dist/gateway/server-entry.js.map +1 -1
  160. package/dist/gateway/x402-mode.d.ts +123 -0
  161. package/dist/gateway/x402-mode.d.ts.map +1 -0
  162. package/dist/gateway/x402-mode.js +212 -0
  163. package/dist/gateway/x402-mode.js.map +1 -0
  164. package/dist/index.d.ts +6 -4
  165. package/dist/index.d.ts.map +1 -1
  166. package/dist/index.js +8 -3
  167. package/dist/index.js.map +1 -1
  168. package/dist/mandates/env.d.ts +3 -2
  169. package/dist/mandates/env.d.ts.map +1 -1
  170. package/dist/mandates/env.js +3 -2
  171. package/dist/mandates/env.js.map +1 -1
  172. package/dist/mcp/http-server.d.ts +1 -0
  173. package/dist/mcp/http-server.js +1 -0
  174. package/dist/mcp/http-server.js.map +1 -1
  175. package/dist/mcp/server.d.ts +49 -0
  176. package/dist/mcp/server.d.ts.map +1 -1
  177. package/dist/mcp/server.js +533 -25
  178. package/dist/mcp/server.js.map +1 -1
  179. package/dist/mcp/service-invoker.d.ts +97 -0
  180. package/dist/mcp/service-invoker.d.ts.map +1 -0
  181. package/dist/mcp/service-invoker.js +167 -0
  182. package/dist/mcp/service-invoker.js.map +1 -0
  183. package/dist/mcp/stdio.d.ts +1 -0
  184. package/dist/mcp/stdio.js +1 -0
  185. package/dist/mcp/stdio.js.map +1 -1
  186. package/dist/sdk/client.d.ts +25 -1
  187. package/dist/sdk/client.d.ts.map +1 -1
  188. package/dist/sdk/client.js +20 -1
  189. package/dist/sdk/client.js.map +1 -1
  190. package/dist/sdk/invoke.d.ts +19 -4
  191. package/dist/sdk/invoke.d.ts.map +1 -1
  192. package/dist/sdk/invoke.js +69 -5
  193. package/dist/sdk/invoke.js.map +1 -1
  194. package/dist/x402/delivery-oracle.d.ts +108 -0
  195. package/dist/x402/delivery-oracle.d.ts.map +1 -0
  196. package/dist/x402/delivery-oracle.js +174 -0
  197. package/dist/x402/delivery-oracle.js.map +1 -0
  198. package/dist/x402/facilitator-server-entry.d.ts +3 -0
  199. package/dist/x402/facilitator-server-entry.d.ts.map +1 -0
  200. package/dist/x402/facilitator-server-entry.js +27 -0
  201. package/dist/x402/facilitator-server-entry.js.map +1 -0
  202. package/dist/x402/facilitator-server.d.ts +73 -0
  203. package/dist/x402/facilitator-server.d.ts.map +1 -0
  204. package/dist/x402/facilitator-server.js +305 -0
  205. package/dist/x402/facilitator-server.js.map +1 -0
  206. package/dist/x402/facilitator.d.ts +69 -17
  207. package/dist/x402/facilitator.d.ts.map +1 -1
  208. package/dist/x402/facilitator.js +76 -33
  209. package/dist/x402/facilitator.js.map +1 -1
  210. package/dist/x402/payment-requirements.d.ts +106 -0
  211. package/dist/x402/payment-requirements.d.ts.map +1 -0
  212. package/dist/x402/payment-requirements.js +138 -0
  213. package/dist/x402/payment-requirements.js.map +1 -0
  214. package/dist/x402/relayer.d.ts +41 -0
  215. package/dist/x402/relayer.d.ts.map +1 -0
  216. package/dist/x402/relayer.js +64 -0
  217. package/dist/x402/relayer.js.map +1 -0
  218. package/dist/x402/resource-index.d.ts +75 -0
  219. package/dist/x402/resource-index.d.ts.map +1 -0
  220. package/dist/x402/resource-index.js +126 -0
  221. package/dist/x402/resource-index.js.map +1 -0
  222. package/dist/x402/verified-delivery-facilitator.d.ts +285 -0
  223. package/dist/x402/verified-delivery-facilitator.d.ts.map +1 -0
  224. package/dist/x402/verified-delivery-facilitator.js +423 -0
  225. package/dist/x402/verified-delivery-facilitator.js.map +1 -0
  226. package/dist/zktls/t2-delivery-proof.d.ts +6 -6
  227. package/docs/agent-layer.md +14 -9
  228. package/docs/cli.md +705 -0
  229. package/docs/crewai.md +6 -2
  230. package/docs/eliza.md +6 -1
  231. package/docs/mcp-hosted.md +7 -5
  232. package/docs/mcp-reference.md +175 -0
  233. package/docs/quickstart.md +36 -9
  234. package/docs/threat-model.md +4 -3
  235. package/docs/x402.md +648 -0
  236. package/package.json +33 -10
  237. package/src/capability/invocation-capability.ts +17 -1
  238. package/src/cli/amounts.ts +102 -0
  239. package/src/cli/args.ts +150 -0
  240. package/src/cli/attesters.ts +86 -0
  241. package/src/cli/bin.ts +5 -0
  242. package/src/cli/commands/claim.ts +126 -0
  243. package/src/cli/commands/close.ts +69 -0
  244. package/src/cli/commands/discover.ts +228 -0
  245. package/src/cli/commands/invoke.ts +178 -0
  246. package/src/cli/commands/mcp.ts +135 -0
  247. package/src/cli/commands/open.ts +397 -0
  248. package/src/cli/commands/reclaim-unverified.ts +218 -0
  249. package/src/cli/commands/reclaim.ts +377 -0
  250. package/src/cli/commands/status.ts +56 -0
  251. package/src/cli/commands/streams.ts +344 -0
  252. package/src/cli/commands/watch.ts +70 -0
  253. package/src/cli/config.ts +208 -0
  254. package/src/cli/context.ts +30 -0
  255. package/src/cli/deps.ts +528 -0
  256. package/src/cli/descriptor.ts +133 -0
  257. package/src/cli/errors.ts +162 -0
  258. package/src/cli/escape-hatch.ts +92 -0
  259. package/src/cli/index.ts +27 -0
  260. package/src/cli/listings.ts +77 -0
  261. package/src/cli/mandate.ts +126 -0
  262. package/src/cli/output.ts +63 -0
  263. package/src/cli/preflight.ts +88 -0
  264. package/src/cli/privy.ts +396 -0
  265. package/src/cli/progress.ts +75 -0
  266. package/src/cli/run.ts +209 -0
  267. package/src/cli/scan-range.ts +76 -0
  268. package/src/cli/spend-policy.ts +139 -0
  269. package/src/cli/status.ts +381 -0
  270. package/src/cli/timeout.ts +64 -0
  271. package/src/cli/version.ts +21 -0
  272. package/src/cli/wallet.ts +372 -0
  273. package/src/frameworks/crewai.ts +13 -2
  274. package/src/gateway/caller-auth-gateway.ts +77 -6
  275. package/src/gateway/http-server.ts +280 -6
  276. package/src/gateway/server-entry.ts +1 -0
  277. package/src/gateway/x402-mode.ts +350 -0
  278. package/src/index.ts +40 -5
  279. package/src/mandates/env.ts +3 -2
  280. package/src/mcp/http-server.ts +1 -0
  281. package/src/mcp/server.ts +706 -30
  282. package/src/mcp/service-invoker.ts +285 -0
  283. package/src/mcp/stdio.ts +1 -0
  284. package/src/sdk/client.ts +33 -1
  285. package/src/sdk/invoke.ts +90 -12
  286. package/src/x402/delivery-oracle.ts +285 -0
  287. package/src/x402/facilitator-server-entry.ts +35 -0
  288. package/src/x402/facilitator-server.ts +445 -0
  289. package/src/x402/facilitator.ts +125 -46
  290. package/src/x402/payment-requirements.ts +231 -0
  291. package/src/x402/relayer.ts +122 -0
  292. package/src/x402/resource-index.ts +228 -0
  293. package/src/x402/verified-delivery-facilitator.ts +744 -0
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Pure block-range arithmetic for the escrow log scan behind `metrik streams`.
3
+ * No RPC, no clock, no env — so the coverage rules below are unit-testable
4
+ * without a network, which is the point: they decide when an empty result is
5
+ * allowed to be rendered as "you have no streams".
6
+ *
7
+ * ## Why the anchor is the deploy block
8
+ *
9
+ * A fixed lookback ("the last N blocks") cannot describe coverage: a wallet
10
+ * whose stream predates the window is shown an empty list with nothing to
11
+ * distinguish it from a wallet that never opened one. For a payments tool,
12
+ * telling someone their escrowed funds do not exist is the worst failure we
13
+ * have. The escrow has NO history before its deploy block, so that block is the
14
+ * honest anchor — and whether the budget reached it is then a fact the command
15
+ * can state.
16
+ *
17
+ * ## Why the window is 10 000 blocks
18
+ *
19
+ * `buyer` and `operator` are INDEXED on `StreamOpened`, so a per-wallet scan is
20
+ * a server-side topic filter whose response is tiny regardless of range. What
21
+ * public RPCs cap is the per-call BLOCK RANGE, and a topic filter does not lift
22
+ * it: `sepolia.base.org` answers a wider range with `-32614 "eth_getLogs is
23
+ * limited to a 10,000 range"`. So the page size is the cap, not a guess below
24
+ * it.
25
+ */
26
+ /**
27
+ * getLogs page size. The window is `chunk + 1` blocks (bounds inclusive), so
28
+ * 9 999 is the largest page `sepolia.base.org` accepts.
29
+ */
30
+ export const LOG_SCAN_CHUNK = 9999n;
31
+ /**
32
+ * Window budget for one scan. 400 x 10 000 = 4 000 000 blocks, comfortably more
33
+ * than the live escrow's history (~1.06M blocks on 2026-09-17), so the default
34
+ * scan is complete rather than merely large. It is a CEILING, not a fixed cost:
35
+ * windows are built for the actual anchor-to-head span. Exceeding it is not an
36
+ * error — it is reported as `degraded`.
37
+ */
38
+ export const LOG_SCAN_MAX_WINDOWS = 400;
39
+ /**
40
+ * Page `[anchor, head]` into non-overlapping inclusive windows.
41
+ *
42
+ * An RPC that is behind the deployment yields an empty-but-valid range rather
43
+ * than a negative one, and an anchor past the head is clamped: a node still
44
+ * syncing must not produce a nonsense scan.
45
+ */
46
+ export function escrowScanRange(head, anchorBlock, chunk = LOG_SCAN_CHUNK, maxWindows = LOG_SCAN_MAX_WINDOWS) {
47
+ const anchor = anchorBlock < 0n ? 0n : anchorBlock > head ? head : anchorBlock;
48
+ const maxSpan = (chunk + 1n) * BigInt(maxWindows);
49
+ const degraded = head - anchor > maxSpan;
50
+ const fromBlock = degraded ? head - maxSpan : anchor;
51
+ const windows = [];
52
+ for (let start = fromBlock; start <= head; start += chunk + 1n) {
53
+ windows.push([start, start + chunk > head ? head : start + chunk]);
54
+ }
55
+ return { fromBlock, toBlock: head, windows, degraded };
56
+ }
57
+ //# sourceMappingURL=scan-range.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan-range.js","sourceRoot":"","sources":["../../src/cli/scan-range.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAM,CAAC;AAErC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAWxC;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAY,EACZ,WAAmB,EACnB,QAAgB,cAAc,EAC9B,aAAqB,oBAAoB;IAEzC,MAAM,MAAM,GACV,WAAW,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC;IAClE,MAAM,OAAO,GAAG,CAAC,KAAK,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,IAAI,GAAG,MAAM,GAAG,OAAO,CAAC;IACzC,MAAM,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;IAErD,MAAM,OAAO,GAAkC,EAAE,CAAC;IAClD,KAAK,IAAI,KAAK,GAAG,SAAS,EAAE,KAAK,IAAI,IAAI,EAAE,KAAK,IAAI,KAAK,GAAG,EAAE,EAAE,CAAC;QAC/D,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC;IACrE,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACzD,CAAC"}
@@ -0,0 +1,60 @@
1
+ import type { PrivySpendPolicy } from "./privy.js";
2
+ import type { RequestedSpend } from "./mandate.js";
3
+ import type { ServerMandateCaps } from "../mandates/env.js";
4
+ /**
5
+ * Where a hire's spend ceiling comes from, and who enforces it.
6
+ *
7
+ * The CLI has two kinds of wallet, and they differ in WHO holds the key — which
8
+ * is the whole reason the self-signed spend mandate exists at all:
9
+ *
10
+ * - **Key-holding wallet** (a raw private key, a CDP account). The person
11
+ * typing the command holds the key, so nothing outside this process bounds
12
+ * what that key can spend. `signCliMandate()` makes the agent state its own
13
+ * ceiling, and `checkMandate()` enforces it here. That is the best available
14
+ * guarantee when the client is the last line of defence.
15
+ *
16
+ * - **Policy-enforced wallet** (Privy, either shape). The key lives at Privy
17
+ * and is exercised by the broker, which caps every `openStream` against a
18
+ * policy the client CANNOT reach or raise. Re-signing a local mandate on top
19
+ * of that adds nothing: it is an agent attesting to its own limits when a
20
+ * stronger limit is already enforced somewhere the agent cannot touch. Worse,
21
+ * it cannot even be produced — the broker's typed-data policy allows an
22
+ * `InvocationCapability` and nothing else — so insisting on it would block
23
+ * the wallet whose ceiling is the stronger of the two.
24
+ *
25
+ * So for a policy-enforced wallet the CLI does not self-sign a mandate. It
26
+ * SUBSTITUTES the real ceiling rather than dropping the check: it reads the
27
+ * broker's public `/v1/config` and refuses an over-ceiling hire locally, in the
28
+ * same shape as the gas and USDC preflights — fail early with an actionable
29
+ * message instead of paying gas to learn a knowable fact.
30
+ *
31
+ * **Do not "restore" the mandate here for consistency.** Its premise is
32
+ * key-holding, and that premise is false for these wallets. Reinstating it
33
+ * would weaken the property that makes them non-custodial (the broker would
34
+ * have to be widened to sign `SpendMandate`) while making every fund-moving
35
+ * command fail against the broker as deployed.
36
+ */
37
+ export interface SpendCeiling {
38
+ readonly policy: PrivySpendPolicy;
39
+ }
40
+ /**
41
+ * Refuse a hire the broker will refuse anyway, before any gas is spent.
42
+ *
43
+ * Mirrors the broker's own `openStream` check exactly — `deposit`,
44
+ * `ratePerSecond` and `duration` each against their ceiling — because a
45
+ * divergent copy would either block hires the broker would allow or promise
46
+ * hires it will not.
47
+ */
48
+ export declare function assertWithinSpendPolicy(policy: PrivySpendPolicy, spend: RequestedSpend): void;
49
+ /**
50
+ * Refuse a hire that exceeds an OPERATOR-SET standing ceiling.
51
+ *
52
+ * `METRIK_AGENT_MANDATE_*` is not the self-signed mandate: it is a ceiling the
53
+ * operator deliberately configured, and it can be TIGHTER than the broker
54
+ * policy. A policy-enforced wallet skips the self-signed mandate, so without
55
+ * this the env caps would silently stop applying to exactly the wallets an
56
+ * unattended run is most likely to use. Enforced locally here instead, with the
57
+ * same comparisons `checkMandate()` makes.
58
+ */
59
+ export declare function assertWithinOperatorCaps(caps: ServerMandateCaps, spend: RequestedSpend): void;
60
+ //# sourceMappingURL=spend-policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spend-policy.d.ts","sourceRoot":"","sources":["../../src/cli/spend-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;CACnC;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,cAAc,GACpB,IAAI,CA4BN;AAED;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,iBAAiB,EACvB,KAAK,EAAE,cAAc,GACpB,IAAI,CAyCN"}
@@ -0,0 +1,65 @@
1
+ import { formatUsdc } from "./amounts.js";
2
+ import { CliError } from "./errors.js";
3
+ /**
4
+ * Refuse a hire the broker will refuse anyway, before any gas is spent.
5
+ *
6
+ * Mirrors the broker's own `openStream` check exactly — `deposit`,
7
+ * `ratePerSecond` and `duration` each against their ceiling — because a
8
+ * divergent copy would either block hires the broker would allow or promise
9
+ * hires it will not.
10
+ */
11
+ export function assertWithinSpendPolicy(policy, spend) {
12
+ const over = [];
13
+ if (spend.budgetUsdc > policy.maxTotalUsdc) {
14
+ over.push(`--budget ${formatUsdc(spend.budgetUsdc)} exceeds the policy ceiling of ${formatUsdc(policy.maxTotalUsdc)}`);
15
+ }
16
+ if (spend.ratePerSecondUsdc > policy.maxRatePerSecondUsdc) {
17
+ over.push(`--rate ${spend.ratePerSecondUsdc} atomic/second exceeds the policy ceiling of ${policy.maxRatePerSecondUsdc} atomic/second`);
18
+ }
19
+ if (spend.durationSeconds > policy.maxDurationSeconds) {
20
+ over.push(`--duration ${spend.durationSeconds}s exceeds the policy ceiling of ${policy.maxDurationSeconds}s`);
21
+ }
22
+ if (over.length === 0)
23
+ return;
24
+ throw new CliError(`this hire is outside the spend policy your wallet is capped at: ${over.join("; ")}`, {
25
+ exitCode: 3,
26
+ hint: `the ceiling is enforced by the broker at ${policy.brokerUrl} (GET /v1/config), not by this CLI — you cannot raise it from this side, ` +
27
+ "which is exactly what makes the wallet non-custodial. Size the stream to fit, or use a key-holding wallet.",
28
+ });
29
+ }
30
+ /**
31
+ * Refuse a hire that exceeds an OPERATOR-SET standing ceiling.
32
+ *
33
+ * `METRIK_AGENT_MANDATE_*` is not the self-signed mandate: it is a ceiling the
34
+ * operator deliberately configured, and it can be TIGHTER than the broker
35
+ * policy. A policy-enforced wallet skips the self-signed mandate, so without
36
+ * this the env caps would silently stop applying to exactly the wallets an
37
+ * unattended run is most likely to use. Enforced locally here instead, with the
38
+ * same comparisons `checkMandate()` makes.
39
+ */
40
+ export function assertWithinOperatorCaps(caps, spend) {
41
+ const over = [];
42
+ if (spend.budgetUsdc > caps.maxPerStreamUsdc) {
43
+ over.push(`--budget ${formatUsdc(spend.budgetUsdc)} exceeds METRIK_AGENT_MANDATE max-per-stream ${formatUsdc(caps.maxPerStreamUsdc)}`);
44
+ }
45
+ if (spend.budgetUsdc > caps.maxTotalUsdc) {
46
+ over.push(`--budget ${formatUsdc(spend.budgetUsdc)} exceeds METRIK_AGENT_MANDATE max-total ${formatUsdc(caps.maxTotalUsdc)}`);
47
+ }
48
+ if (spend.ratePerSecondUsdc > caps.maxRatePerSecondUsdc) {
49
+ over.push(`--rate ${spend.ratePerSecondUsdc} atomic/second exceeds METRIK_AGENT_MANDATE max rate ${caps.maxRatePerSecondUsdc} atomic/second`);
50
+ }
51
+ if (spend.durationSeconds > caps.maxDurationSeconds) {
52
+ over.push(`--duration ${spend.durationSeconds}s exceeds METRIK_AGENT_MANDATE max duration ${caps.maxDurationSeconds}s`);
53
+ }
54
+ if (caps.allowedOperators.length > 0 &&
55
+ !caps.allowedOperators.some((operator) => operator.toLowerCase() === spend.operator.toLowerCase())) {
56
+ over.push(`operator ${spend.operator} is not in METRIK_AGENT_MANDATE_ALLOWED_OPERATORS`);
57
+ }
58
+ if (over.length === 0)
59
+ return;
60
+ throw new CliError(`this hire is outside the standing mandate caps in your environment: ${over.join("; ")}`, {
61
+ exitCode: 3,
62
+ hint: "these caps come from METRIK_AGENT_MANDATE_* and are yours to change. They are enforced locally for a policy-enforced wallet, which signs no mandate of its own.",
63
+ });
64
+ }
65
+ //# sourceMappingURL=spend-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spend-policy.js","sourceRoot":"","sources":["../../src/cli/spend-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AA0CvC;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAAwB,EACxB,KAAqB;IAErB,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,IAAI,KAAK,CAAC,UAAU,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC;QAC3C,IAAI,CAAC,IAAI,CACP,YAAY,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,kCAAkC,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAC5G,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,CAAC,iBAAiB,GAAG,MAAM,CAAC,oBAAoB,EAAE,CAAC;QAC1D,IAAI,CAAC,IAAI,CACP,UAAU,KAAK,CAAC,iBAAiB,gDAAgD,MAAM,CAAC,oBAAoB,gBAAgB,CAC7H,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,CAAC,eAAe,GAAG,MAAM,CAAC,kBAAkB,EAAE,CAAC;QACtD,IAAI,CAAC,IAAI,CACP,cAAc,KAAK,CAAC,eAAe,mCAAmC,MAAM,CAAC,kBAAkB,GAAG,CACnG,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAE9B,MAAM,IAAI,QAAQ,CAChB,mEAAmE,IAAI,CAAC,IAAI,CAAC,IA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CAAC,WAAW,EAAE,CACtE,EACD,CAAC;QACD,IAAI,CAAC,IAAI,CACP,YAAY,KAAK,CAAC,QAAQ,mDAAmD,CAC9E,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAE9B,MAAM,IAAI,QAAQ,CAChB,uEAAuE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EACxF;QACE,QAAQ,EAAE,CAAC;QACX,IAAI,EAAE,iKAAiK;KACxK,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,90 @@
1
+ import type { CheckpointProof, StreamV2 } from "@absol-labs/sdk";
2
+ import { type AttesterSet } from "./attesters.js";
3
+ import { type EscapeHatchWindow } from "./escape-hatch.js";
4
+ import type { CliReadClient } from "./deps.js";
5
+ /**
6
+ * Whether the accrual figures on this screen are FINAL.
7
+ *
8
+ * `reclaimableFor` is answered against a checkpoint's cumulative, and the
9
+ * escrow's own `reclaimWithProof` refuses until a checkpoint's `checkedAt`
10
+ * reaches the stream's stop time (`SettlementWindowOpen`). Between closing a
11
+ * stream and the first checkpoint that covers the close, the latest checkpoint
12
+ * therefore describes a SHORTER stream than the one that exists — so the
13
+ * reclaimable figure computed from it is larger than the amount that can
14
+ * actually be reclaimed, and shrinks when the covering checkpoint lands.
15
+ *
16
+ * A live acceptance run read `reclaimable: 1400` immediately after `close`, `0`
17
+ * two minutes later, and got `NothingToReclaim()` from the reclaim in between.
18
+ * Nobody reads "buyer reclaimable 0.0014 USDC" as "a provisional figure that
19
+ * may fall to zero" — they read it as money they have. So while this is
20
+ * pending, the CLI prints no settled-looking number at all.
21
+ */
22
+ export interface SettlementCoverage {
23
+ /**
24
+ * The instant accrual stops: `closedAt`, or `expiresAt` once it has passed.
25
+ * `null` while the stream is still running, where there is nothing to cover.
26
+ */
27
+ readonly stopAt: number | null;
28
+ /** How far the oracle has published. `null` when it could not be read. */
29
+ readonly coveredUpTo: number | null;
30
+ /** True when a stop time exists and no known checkpoint reaches it. */
31
+ readonly pending: boolean;
32
+ }
33
+ /**
34
+ * Coverage from the three facts that decide it. Pure, so the rule is testable
35
+ * without an RPC.
36
+ *
37
+ * Unknown coverage counts as PENDING, not as covered: the buyer-favouring error
38
+ * is to withhold a number we cannot stand behind, never to print one we cannot.
39
+ */
40
+ export declare function settlementCoverage(stream: Pick<StreamV2, "closedAt" | "expiresAt">, latestCheckpointCheckedAt: number | null, nowSeconds: number): SettlementCoverage;
41
+ /**
42
+ * A stream as the CLI reports it.
43
+ *
44
+ * The accrual figures come from the ORACLE's checkpoint proof, not from the
45
+ * stream tuple. `StreamEscrowV2.getStream` reports `claimedCumulative = 0` and
46
+ * `settledCumulative = 0` for a stream's whole active life — `settledCumulative`
47
+ * is written by `reclaim` — so a status built from stream fields would print
48
+ * "earned: 0" for a stream that had been delivering for an hour.
49
+ */
50
+ export interface StreamReport {
51
+ readonly streamId: `0x${string}`;
52
+ readonly stream: StreamV2;
53
+ /** `null` until the oracle has published a checkpoint covering this stream. */
54
+ readonly proof: CheckpointProof | null;
55
+ /** Why there is no proof yet, when applicable. */
56
+ readonly proofUnavailable: string | null;
57
+ readonly claimable: bigint | null;
58
+ readonly reclaimable: bigint | null;
59
+ readonly protocolFeeBps: number | null;
60
+ /**
61
+ * When the buyer's no-proof escape hatch opens, and whether it already has.
62
+ * `null` only when the escrow would not answer.
63
+ *
64
+ * Without this a buyer had no command that could tell them "the proof path is
65
+ * blocked, but the no-proof path opens at T+grace" — the two facts they need
66
+ * together when the oracle has stopped answering.
67
+ */
68
+ readonly escapeHatch: EscapeHatchWindow | null;
69
+ /**
70
+ * How far the oracle has published (`latestCheckpointCheckedAt`). A stale
71
+ * value beside a blocked reclaim IS the explanation for the blocked reclaim.
72
+ */
73
+ readonly latestCheckpointCheckedAt: number | null;
74
+ readonly nowSeconds: number;
75
+ /** `local` when the chain's clock could not be read and the caller's was used. */
76
+ readonly clockSource: "chain" | "local";
77
+ /** Whether `claimable` / `reclaimable` are final. See {@link SettlementCoverage}. */
78
+ readonly settlement: SettlementCoverage;
79
+ /**
80
+ * The escrow's oracle signer set, and therefore whether this stream's
81
+ * operator is also one of the parties attesting to its own delivery.
82
+ * `signers: null` means the set could not be read — which is UNKNOWN, not
83
+ * "no overlap".
84
+ */
85
+ readonly attesters: AttesterSet;
86
+ }
87
+ export declare function readStreamReport(read: CliReadClient, streamId: `0x${string}`, nowSeconds: number): Promise<StreamReport>;
88
+ export declare function streamReportJson(report: StreamReport): unknown;
89
+ export declare function streamReportRows(report: StreamReport): (readonly [string, string])[];
90
+ //# sourceMappingURL=status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/cli/status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGjE,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAKL,KAAK,iBAAiB,EACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,0EAA0E;IAC1E,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,uEAAuE;IACvE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,UAAU,GAAG,WAAW,CAAC,EAChD,yBAAyB,EAAE,MAAM,GAAG,IAAI,EACxC,UAAU,EAAE,MAAM,GACjB,kBAAkB,CAgBpB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,QAAQ,EAAE,KAAK,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,+EAA+E;IAC/E,QAAQ,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC;IACvC,kDAAkD;IAClD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC/C;;;OAGG;IACH,QAAQ,CAAC,yBAAyB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,kFAAkF;IAClF,QAAQ,CAAC,WAAW,EAAE,OAAO,GAAG,OAAO,CAAC;IACxC,qFAAqF;IACrF,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAC;IACxC;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC;CACjC;AAED,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,aAAa,EACnB,QAAQ,EAAE,KAAK,MAAM,EAAE,EACvB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,YAAY,CAAC,CAwEvB;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAgE9D;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,YAAY,GACnB,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAuF/B"}
@@ -0,0 +1,252 @@
1
+ import { formatDuration, formatUsdc } from "./amounts.js";
2
+ import { operatorAttestsOwnDelivery, readAttesterSet, } from "./attesters.js";
3
+ import { describeError } from "./errors.js";
4
+ import { describeEscapeHatch, escapeHatchWindow, formatTimestamp, readChainNow, } from "./escape-hatch.js";
5
+ /**
6
+ * Coverage from the three facts that decide it. Pure, so the rule is testable
7
+ * without an RPC.
8
+ *
9
+ * Unknown coverage counts as PENDING, not as covered: the buyer-favouring error
10
+ * is to withhold a number we cannot stand behind, never to print one we cannot.
11
+ */
12
+ export function settlementCoverage(stream, latestCheckpointCheckedAt, nowSeconds) {
13
+ const stopAt = stream.closedAt > 0
14
+ ? stream.closedAt
15
+ : nowSeconds >= stream.expiresAt
16
+ ? stream.expiresAt
17
+ : null;
18
+ const coveredUpTo = latestCheckpointCheckedAt !== null && latestCheckpointCheckedAt > 0
19
+ ? latestCheckpointCheckedAt
20
+ : null;
21
+ return {
22
+ stopAt,
23
+ coveredUpTo,
24
+ pending: stopAt !== null && (coveredUpTo === null || coveredUpTo < stopAt),
25
+ };
26
+ }
27
+ export async function readStreamReport(read, streamId, nowSeconds) {
28
+ const stream = await read.getStreamV2(streamId);
29
+ // Timing is answered against the chain, because every deadline on this screen
30
+ // — expiry, and the escape hatch in particular — is compared against
31
+ // `block.timestamp` by the escrow, not against this machine's clock.
32
+ const now = await readChainNow(read, nowSeconds);
33
+ let proof = null;
34
+ let proofUnavailable = null;
35
+ try {
36
+ proof = await read.checkpointProof(streamId);
37
+ }
38
+ catch (error) {
39
+ proofUnavailable = describeError(error);
40
+ }
41
+ let claimable = null;
42
+ let reclaimable = null;
43
+ if (proof !== null) {
44
+ [claimable, reclaimable] = await Promise.all([
45
+ read.claimableForV2(streamId, proof.cumulativeAmount),
46
+ read.reclaimableForV2(streamId, proof.cumulativeAmount),
47
+ ]);
48
+ }
49
+ let protocolFeeBps = null;
50
+ try {
51
+ protocolFeeBps = await read.protocolFeeBps();
52
+ }
53
+ catch {
54
+ protocolFeeBps = null;
55
+ }
56
+ let escapeHatch = null;
57
+ try {
58
+ escapeHatch = escapeHatchWindow(stream, await read.escapeGraceSeconds(), now.seconds);
59
+ }
60
+ catch {
61
+ escapeHatch = null;
62
+ }
63
+ let latestCheckpointCheckedAt = null;
64
+ try {
65
+ latestCheckpointCheckedAt = await read.latestCheckpointCheckedAt();
66
+ }
67
+ catch {
68
+ latestCheckpointCheckedAt = null;
69
+ }
70
+ const settlement = settlementCoverage(stream, latestCheckpointCheckedAt, now.seconds);
71
+ const attesters = await readAttesterSet(read);
72
+ return {
73
+ streamId,
74
+ stream,
75
+ proof,
76
+ proofUnavailable,
77
+ claimable,
78
+ reclaimable,
79
+ protocolFeeBps,
80
+ escapeHatch,
81
+ latestCheckpointCheckedAt,
82
+ nowSeconds: now.seconds,
83
+ clockSource: now.source,
84
+ settlement,
85
+ attesters,
86
+ };
87
+ }
88
+ export function streamReportJson(report) {
89
+ const { stream, proof } = report;
90
+ return {
91
+ streamId: report.streamId,
92
+ // StreamEscrowV2 has exactly two states. There is no "paused".
93
+ status: stream.status,
94
+ reclaimed: stream.reclaimed,
95
+ buyer: stream.buyer,
96
+ operator: stream.operator,
97
+ serviceRef: stream.serviceRef,
98
+ deposit: stream.deposit,
99
+ ratePerSecond: stream.ratePerSecond,
100
+ claimedCumulative: stream.claimedCumulative,
101
+ settledCumulative: stream.settledCumulative,
102
+ feesPaid: stream.feesPaid,
103
+ openedAt: stream.openedAt,
104
+ expiresAt: stream.expiresAt,
105
+ closedAt: stream.closedAt,
106
+ protocolFeeBps: report.protocolFeeBps,
107
+ verifiedAccrual: proof === null
108
+ ? null
109
+ : {
110
+ cumulativeAmount: proof.cumulativeAmount,
111
+ checkpointId: proof.checkpointId,
112
+ checkedAt: proof.checkedAt,
113
+ root: proof.root,
114
+ },
115
+ verifiedAccrualUnavailable: report.proofUnavailable,
116
+ // `null` while settlement is pending. A consumer that reads this field gets
117
+ // either an amount that can actually be obtained or nothing — never a
118
+ // settled-looking number derived from a checkpoint that predates the
119
+ // stream's stop time. The superseded figure is still available, explicitly
120
+ // labelled, under `settlement.provisionalReclaimable`.
121
+ claimable: report.claimable,
122
+ reclaimable: report.settlement.pending ? null : report.reclaimable,
123
+ settlement: {
124
+ pending: report.settlement.pending,
125
+ stopAt: report.settlement.stopAt,
126
+ coveredUpTo: report.settlement.coveredUpTo,
127
+ provisionalReclaimable: report.settlement.pending
128
+ ? report.reclaimable
129
+ : null,
130
+ provisionalClaimable: report.settlement.pending ? report.claimable : null,
131
+ },
132
+ // Who attests. `operatorIsOracleSigner: null` means the signer set could
133
+ // not be read — UNKNOWN, never "no overlap".
134
+ oracleSigners: report.attesters.signers,
135
+ oracleSignersUnavailable: report.attesters.unavailable,
136
+ operatorIsOracleSigner: operatorAttestsOwnDelivery(report.attesters, stream.operator),
137
+ latestCheckpointCheckedAt: report.latestCheckpointCheckedAt,
138
+ escapeHatch: report.escapeHatch === null
139
+ ? null
140
+ : {
141
+ escapeGraceSeconds: report.escapeHatch.graceSeconds,
142
+ readyAt: report.escapeHatch.readyAt,
143
+ ready: report.escapeHatch.ready,
144
+ secondsUntilReady: report.escapeHatch.secondsRemaining,
145
+ },
146
+ };
147
+ }
148
+ export function streamReportRows(report) {
149
+ const { stream, proof } = report;
150
+ const rows = [
151
+ [
152
+ "status",
153
+ stream.reclaimed ? `${stream.status} (reclaimed)` : stream.status,
154
+ ],
155
+ ["buyer", stream.buyer],
156
+ ["operator", stream.operator],
157
+ ["serviceRef", stream.serviceRef],
158
+ ["deposit", formatUsdc(stream.deposit)],
159
+ ["rate", `${formatUsdc(stream.ratePerSecond)} / second`],
160
+ ["opened", formatTimestamp(stream.openedAt)],
161
+ ["expires", describeDeadline(stream.expiresAt, report.nowSeconds)],
162
+ ];
163
+ if (stream.closedAt > 0) {
164
+ rows.push(["closed", formatTimestamp(stream.closedAt)]);
165
+ }
166
+ rows.push([
167
+ "verified accrual",
168
+ proof === null
169
+ ? `not checkpointed yet (${report.proofUnavailable ?? "no proof"})`
170
+ : `${formatUsdc(proof.cumulativeAmount)} @ checkpoint ${proof.checkpointId} (${formatTimestamp(Number(proof.checkedAt))})`,
171
+ ]);
172
+ // `claim` accepts ANY retained root, so the operator's balance is obtainable
173
+ // now — it is merely not FINAL until the covering checkpoint lands, and it
174
+ // can only grow. `reclaim` requires the LATEST root to reach the stop time,
175
+ // so the buyer's figure is not obtainable at all while that is pending: it is
176
+ // withheld rather than printed as money the buyer does not have.
177
+ rows.push([
178
+ "operator claimable",
179
+ report.claimable === null
180
+ ? "-"
181
+ : report.settlement.pending
182
+ ? `${formatUsdc(report.claimable)} so far — not final until the checkpoint covering the stop time lands`
183
+ : formatUsdc(report.claimable),
184
+ ]);
185
+ rows.push([
186
+ "buyer reclaimable",
187
+ report.settlement.pending
188
+ ? describePendingSettlement(report.settlement)
189
+ : report.reclaimable === null
190
+ ? "-"
191
+ : formatUsdc(report.reclaimable),
192
+ ]);
193
+ rows.push(["fees paid", formatUsdc(stream.feesPaid)]);
194
+ rows.push([
195
+ "oracle checkpoint",
196
+ report.latestCheckpointCheckedAt === null
197
+ ? "-"
198
+ : report.latestCheckpointCheckedAt <= 0
199
+ ? "none posted yet"
200
+ : `latest covers up to ${formatTimestamp(report.latestCheckpointCheckedAt)}`,
201
+ ]);
202
+ // The no-proof path. Printed for every stream, not only blocked ones: a buyer
203
+ // should learn that this exists before they need it.
204
+ rows.push([
205
+ "escape hatch",
206
+ report.escapeHatch === null
207
+ ? "-"
208
+ : `${describeEscapeHatch(report.escapeHatch)} — no-proof reclaim, forfeits the operator's unclaimed earnings`,
209
+ ]);
210
+ // The same row, read from the seller's side. `reclaimUnverified` pays the
211
+ // buyer the WHOLE remaining deposit with no proof, so an operator who has
212
+ // earned but not claimed loses it the moment that window opens. The window is
213
+ // `expiresAt + escapeGraceSeconds` and the grace is immutable on the live
214
+ // escrow, so the only thing an operator can do about it is claim in time —
215
+ // which they cannot do if nothing tells them the deadline exists.
216
+ if (report.escapeHatch !== null &&
217
+ report.claimable !== null &&
218
+ report.claimable > 0n) {
219
+ rows.push([
220
+ "operator deadline",
221
+ report.escapeHatch.ready
222
+ ? `${formatUsdc(report.claimable)} is unclaimed and the buyer's no-proof reclaim is ALREADY open — it would take this amount from the operator`
223
+ : `${formatUsdc(report.claimable)} is unclaimed; \`metrik claim\` it before ${formatTimestamp(report.escapeHatch.readyAt)}, after which a buyer's no-proof reclaim can take it`,
224
+ ]);
225
+ }
226
+ if (report.protocolFeeBps !== null) {
227
+ rows.push([
228
+ "protocol fee",
229
+ `${report.protocolFeeBps} bps (read from the escrow)`,
230
+ ]);
231
+ }
232
+ return rows;
233
+ }
234
+ /**
235
+ * What is being waited for, in the place a number used to be. Names the two
236
+ * timestamps whose ordering decides it, so the reader can see the wait end.
237
+ */
238
+ function describePendingSettlement(settlement) {
239
+ const stopAt = settlement.stopAt === null ? "unknown" : formatTimestamp(settlement.stopAt);
240
+ const covered = settlement.coveredUpTo === null
241
+ ? "unknown (the escrow would not answer)"
242
+ : formatTimestamp(settlement.coveredUpTo);
243
+ return `pending final checkpoint — the stream stopped at ${stopAt}, the oracle has published only to ${covered}. Reclaim reverts until a checkpoint reaches the stop time (~15-22s apart).`;
244
+ }
245
+ function describeDeadline(expiresAt, nowSeconds) {
246
+ const remaining = expiresAt - nowSeconds;
247
+ const suffix = remaining > 0
248
+ ? `in ${formatDuration(remaining)}`
249
+ : `${formatDuration(-remaining)} ago`;
250
+ return `${formatTimestamp(expiresAt)} — ${suffix}`;
251
+ }
252
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/cli/status.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAEL,0BAA0B,EAC1B,eAAe,GAEhB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,YAAY,GAEb,MAAM,mBAAmB,CAAC;AAgC3B;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAgD,E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,GAAG,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,6CAA6C,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,sDAAsD;SAClL,CAAC,CAAC;IACL,CAAC;IACD,IAAI,MAAM,CAAC,cAAc,KAAK,IAAI,EAAE,CAAC;QACnC,IAAI,CAAC,IAAI,CAAC;YACR,cAAc;YACd,GAAG,MAAM,CAAC,cAAc,6BAA6B;SACtD,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,SAAS,yBAAyB,CAAC,UAA8B;IAC/D,MAAM,MAAM,GACV,UAAU,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAC9E,MAAM,OAAO,GACX,UAAU,CAAC,WAAW,KAAK,IAAI;QAC7B,CAAC,CAAC,uCAAuC;QACzC,CAAC,CAAC,eAAe,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IAC9C,OAAO,oDAAoD,MAAM,sCAAsC,OAAO,6EAA6E,CAAC;AAC9L,CAAC;AAED,SAAS,gBAAgB,CAAC,SAAiB,EAAE,UAAkB;IAC7D,MAAM,SAAS,GAAG,SAAS,GAAG,UAAU,CAAC;IACzC,MAAM,MAAM,GACV,SAAS,GAAG,CAAC;QACX,CAAC,CAAC,MAAM,cAAc,CAAC,SAAS,CAAC,EAAE;QACnC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC;IAC1C,OAAO,GAAG,eAAe,CAAC,SAAS,CAAC,MAAM,MAAM,EAAE,CAAC;AACrD,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * How long any single READ is allowed to take before the CLI gives up on it.
3
+ *
4
+ * A live acceptance run found `status` calls that ran past two minutes with no
5
+ * output, and a `close` that took 8s once and 142s the next time. An unbounded
6
+ * wait is indistinguishable from a wedged command, and the only honest way to
7
+ * tell them apart is to stop waiting and say so.
8
+ *
9
+ * Deliberately generous: Base Sepolia's public endpoint is load-balanced and
10
+ * occasionally slow, and a timeout that fires on a merely-slow node would turn
11
+ * a working command into a spurious failure.
12
+ */
13
+ export declare const READ_TIMEOUT_MS = 20000;
14
+ /**
15
+ * Per-RPC-call budget handed to viem's HTTP transport, with a bounded retry
16
+ * count so one slow endpoint cannot multiply into minutes of silence. viem
17
+ * retries with exponential backoff, so `retryCount` is a multiplier on this.
18
+ */
19
+ export declare const RPC_TIMEOUT_MS = 15000;
20
+ export declare const RPC_RETRY_COUNT = 2;
21
+ /**
22
+ * Bound a read.
23
+ *
24
+ * ONLY safe for reads. A broadcast must never be abandoned on a timer: the
25
+ * transaction may already be in the mempool, and a CLI that walked away from it
26
+ * would report a failure for something that in fact settled. Write paths keep
27
+ * waiting, and the heartbeat (`./progress.ts`) is what makes that wait legible.
28
+ */
29
+ export declare function withReadTimeout<T>(operation: () => Promise<T>, label: string, timeoutMs?: number): Promise<T>;
30
+ //# sourceMappingURL=timeout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../src/cli/timeout.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,QAAS,CAAC;AAEtC;;;;GAIG;AACH,eAAO,MAAM,cAAc,QAAS,CAAC;AACrC,eAAO,MAAM,eAAe,IAAI,CAAC;AAEjC;;;;;;;GAOG;AACH,wBAAsB,eAAe,CAAC,CAAC,EACrC,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,MAAwB,GAClC,OAAO,CAAC,CAAC,CAAC,CA2BZ"}
@@ -0,0 +1,55 @@
1
+ import { CliError } from "./errors.js";
2
+ /**
3
+ * How long any single READ is allowed to take before the CLI gives up on it.
4
+ *
5
+ * A live acceptance run found `status` calls that ran past two minutes with no
6
+ * output, and a `close` that took 8s once and 142s the next time. An unbounded
7
+ * wait is indistinguishable from a wedged command, and the only honest way to
8
+ * tell them apart is to stop waiting and say so.
9
+ *
10
+ * Deliberately generous: Base Sepolia's public endpoint is load-balanced and
11
+ * occasionally slow, and a timeout that fires on a merely-slow node would turn
12
+ * a working command into a spurious failure.
13
+ */
14
+ export const READ_TIMEOUT_MS = 20_000;
15
+ /**
16
+ * Per-RPC-call budget handed to viem's HTTP transport, with a bounded retry
17
+ * count so one slow endpoint cannot multiply into minutes of silence. viem
18
+ * retries with exponential backoff, so `retryCount` is a multiplier on this.
19
+ */
20
+ export const RPC_TIMEOUT_MS = 15_000;
21
+ export const RPC_RETRY_COUNT = 2;
22
+ /**
23
+ * Bound a read.
24
+ *
25
+ * ONLY safe for reads. A broadcast must never be abandoned on a timer: the
26
+ * transaction may already be in the mempool, and a CLI that walked away from it
27
+ * would report a failure for something that in fact settled. Write paths keep
28
+ * waiting, and the heartbeat (`./progress.ts`) is what makes that wait legible.
29
+ */
30
+ export async function withReadTimeout(operation, label, timeoutMs = READ_TIMEOUT_MS) {
31
+ let timer;
32
+ const pending = operation();
33
+ // Attached before the race so an eventual rejection of the abandoned promise
34
+ // is never an unhandled rejection that takes the process down.
35
+ pending.catch(() => { });
36
+ try {
37
+ return await Promise.race([
38
+ pending,
39
+ new Promise((_resolve, reject) => {
40
+ timer = setTimeout(() => {
41
+ reject(new CliError(`${label} did not answer within ${Math.round(timeoutMs / 1000)}s`, {
42
+ exitCode: 4,
43
+ hint: "the endpoint is unreachable or very slow — retry, or point --rpc-url / --oracle-url at a different one.",
44
+ }));
45
+ }, timeoutMs);
46
+ timer.unref?.();
47
+ }),
48
+ ]);
49
+ }
50
+ finally {
51
+ if (timer !== undefined)
52
+ clearTimeout(timer);
53
+ }
54
+ }
55
+ //# sourceMappingURL=timeout.js.map