@jinn-network/client 0.1.7 → 0.1.8

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 (319) hide show
  1. package/README.md +67 -1
  2. package/dist/adapters/mech/adapter.d.ts +19 -1
  3. package/dist/adapters/mech/adapter.js +130 -14
  4. package/dist/adapters/mech/adapter.js.map +1 -1
  5. package/dist/adapters/mech/contracts.d.ts +22 -1
  6. package/dist/adapters/mech/contracts.js +34 -24
  7. package/dist/adapters/mech/contracts.js.map +1 -1
  8. package/dist/adapters/mech/safe.d.ts +1 -1
  9. package/dist/adapters/mech/safe.js +5 -3
  10. package/dist/adapters/mech/safe.js.map +1 -1
  11. package/dist/adapters/mech/types.d.ts +6 -1
  12. package/dist/adapters/mech/types.js.map +1 -1
  13. package/dist/agent/operator-claude.js +8 -0
  14. package/dist/agent/operator-claude.js.map +1 -1
  15. package/dist/api/activity-events-endpoint.d.ts +14 -0
  16. package/dist/api/activity-events-endpoint.js +59 -0
  17. package/dist/api/activity-events-endpoint.js.map +1 -0
  18. package/dist/api/bootstrap-endpoint.d.ts +1 -2
  19. package/dist/api/bootstrap-endpoint.js +42 -24
  20. package/dist/api/bootstrap-endpoint.js.map +1 -1
  21. package/dist/api/codex-doctor-endpoint.d.ts +22 -5
  22. package/dist/api/codex-doctor-endpoint.js +136 -17
  23. package/dist/api/codex-doctor-endpoint.js.map +1 -1
  24. package/dist/api/debug-report-endpoint.d.ts +27 -0
  25. package/dist/api/debug-report-endpoint.js +157 -0
  26. package/dist/api/debug-report-endpoint.js.map +1 -0
  27. package/dist/api/gather-status.d.ts +33 -0
  28. package/dist/api/gather-status.js +211 -26
  29. package/dist/api/gather-status.js.map +1 -1
  30. package/dist/api/hermes-doctor-endpoint.d.ts +15 -7
  31. package/dist/api/hermes-doctor-endpoint.js +56 -19
  32. package/dist/api/hermes-doctor-endpoint.js.map +1 -1
  33. package/dist/api/launcher-status.d.ts +4 -2
  34. package/dist/api/launcher-status.js +11 -10
  35. package/dist/api/launcher-status.js.map +1 -1
  36. package/dist/api/launcher-tasks.d.ts +1 -1
  37. package/dist/api/launcher-tasks.js +12 -8
  38. package/dist/api/launcher-tasks.js.map +1 -1
  39. package/dist/api/operator-artifacts-endpoint.js +73 -6
  40. package/dist/api/operator-artifacts-endpoint.js.map +1 -1
  41. package/dist/api/portfolio-v0-build.d.ts +7 -1
  42. package/dist/api/portfolio-v0-build.js +6 -2
  43. package/dist/api/portfolio-v0-build.js.map +1 -1
  44. package/dist/api/prediction-v1-build.d.ts +6 -0
  45. package/dist/api/prediction-v1-build.js +3 -1
  46. package/dist/api/prediction-v1-build.js.map +1 -1
  47. package/dist/api/server.d.ts +17 -0
  48. package/dist/api/server.js +40 -1
  49. package/dist/api/server.js.map +1 -1
  50. package/dist/api/setup-endpoints.d.ts +0 -9
  51. package/dist/api/setup-endpoints.js +11 -153
  52. package/dist/api/setup-endpoints.js.map +1 -1
  53. package/dist/api/solvernets-endpoints.js +30 -63
  54. package/dist/api/solvernets-endpoints.js.map +1 -1
  55. package/dist/api/status-build.d.ts +115 -2
  56. package/dist/api/status-build.js +47 -11
  57. package/dist/api/status-build.js.map +1 -1
  58. package/dist/api/status-harness-rollup.d.ts +35 -0
  59. package/dist/api/status-harness-rollup.js +45 -0
  60. package/dist/api/status-harness-rollup.js.map +1 -0
  61. package/dist/api/task-runs-build.d.ts +8 -0
  62. package/dist/api/task-runs-build.js +5 -1
  63. package/dist/api/task-runs-build.js.map +1 -1
  64. package/dist/build-info.json +4 -4
  65. package/dist/build-meta.json +1 -1
  66. package/dist/captures/live-publisher.js +24 -4
  67. package/dist/captures/live-publisher.js.map +1 -1
  68. package/dist/captures/publish.d.ts +1 -1
  69. package/dist/chain-read-errors.d.ts +12 -0
  70. package/dist/chain-read-errors.js +26 -1
  71. package/dist/chain-read-errors.js.map +1 -1
  72. package/dist/cli/commands/codedigest-revert-check.d.ts +33 -0
  73. package/dist/cli/commands/codedigest-revert-check.js +249 -0
  74. package/dist/cli/commands/codedigest-revert-check.js.map +1 -0
  75. package/dist/cli/commands/solver-nets.d.ts +1 -0
  76. package/dist/cli/commands/solver-nets.js +177 -22
  77. package/dist/cli/commands/solver-nets.js.map +1 -1
  78. package/dist/cli/commands/solver-plugins-block.d.ts +33 -0
  79. package/dist/cli/commands/solver-plugins-block.js +118 -0
  80. package/dist/cli/commands/solver-plugins-block.js.map +1 -0
  81. package/dist/cli/commands/solver-plugins-feedback.d.ts +72 -0
  82. package/dist/cli/commands/solver-plugins-feedback.js +262 -0
  83. package/dist/cli/commands/solver-plugins-feedback.js.map +1 -0
  84. package/dist/cli/commands/solver-plugins-read.d.ts +54 -0
  85. package/dist/cli/commands/solver-plugins-read.js +259 -0
  86. package/dist/cli/commands/solver-plugins-read.js.map +1 -0
  87. package/dist/cli/commands/solver-plugins.d.ts +35 -0
  88. package/dist/cli/commands/solver-plugins.js +399 -2
  89. package/dist/cli/commands/solver-plugins.js.map +1 -1
  90. package/dist/cli/commands/tasks.js +15 -2
  91. package/dist/cli/commands/tasks.js.map +1 -1
  92. package/dist/cli/index.js +2 -0
  93. package/dist/cli/index.js.map +1 -1
  94. package/dist/cli/task-native-readiness.d.ts +7 -0
  95. package/dist/cli/task-native-readiness.js +7 -5
  96. package/dist/cli/task-native-readiness.js.map +1 -1
  97. package/dist/config.d.ts +183 -232
  98. package/dist/config.js +232 -107
  99. package/dist/config.js.map +1 -1
  100. package/dist/daemon/ai-units-gate.d.ts +54 -0
  101. package/dist/daemon/ai-units-gate.js +82 -0
  102. package/dist/daemon/ai-units-gate.js.map +1 -0
  103. package/dist/daemon/creator.js +13 -0
  104. package/dist/daemon/creator.js.map +1 -1
  105. package/dist/daemon/daemon.d.ts +10 -0
  106. package/dist/daemon/daemon.js +203 -30
  107. package/dist/daemon/daemon.js.map +1 -1
  108. package/dist/daemon/gate-logger.d.ts +9 -0
  109. package/dist/daemon/gate-logger.js +2 -0
  110. package/dist/daemon/gate-logger.js.map +1 -0
  111. package/dist/daemon/jinn-claim-loop.js +22 -4
  112. package/dist/daemon/jinn-claim-loop.js.map +1 -1
  113. package/dist/daemon/readiness-gate.d.ts +1 -4
  114. package/dist/daemon/readiness-gate.js.map +1 -1
  115. package/dist/daemon/spend-cap-gate.d.ts +40 -0
  116. package/dist/daemon/spend-cap-gate.js +46 -0
  117. package/dist/daemon/spend-cap-gate.js.map +1 -0
  118. package/dist/dashboard/assets/index-CzKxvMcU.css +32 -0
  119. package/dist/dashboard/assets/index-yVemxHot.js +351 -0
  120. package/dist/dashboard/index.html +2 -2
  121. package/dist/discovery/http.js +328 -1
  122. package/dist/discovery/http.js.map +1 -1
  123. package/dist/discovery/onchain.js +42 -4
  124. package/dist/discovery/onchain.js.map +1 -1
  125. package/dist/discovery/types.d.ts +129 -0
  126. package/dist/discovery/types.js.map +1 -1
  127. package/dist/discovery/with-fallback.js +27 -0
  128. package/dist/discovery/with-fallback.js.map +1 -1
  129. package/dist/earning/bootstrap.d.ts +8 -3
  130. package/dist/earning/bootstrap.js +36 -13
  131. package/dist/earning/bootstrap.js.map +1 -1
  132. package/dist/earning/safe-adapter.js +23 -11
  133. package/dist/earning/safe-adapter.js.map +1 -1
  134. package/dist/earning/types.d.ts +6 -6
  135. package/dist/earning/viem-clients.d.ts +11 -4
  136. package/dist/earning/viem-clients.js +14 -5
  137. package/dist/earning/viem-clients.js.map +1 -1
  138. package/dist/erc8004/identity.d.ts +19 -3
  139. package/dist/erc8004/identity.js +38 -11
  140. package/dist/erc8004/identity.js.map +1 -1
  141. package/dist/erc8004/index.d.ts +1 -1
  142. package/dist/erc8004/index.js.map +1 -1
  143. package/dist/events/types.d.ts +2 -2
  144. package/dist/harnesses/cost-estimates.d.ts +10 -31
  145. package/dist/harnesses/cost-estimates.js +11 -43
  146. package/dist/harnesses/cost-estimates.js.map +1 -1
  147. package/dist/harnesses/engine/engine.d.ts +28 -4
  148. package/dist/harnesses/engine/engine.js +103 -17
  149. package/dist/harnesses/engine/engine.js.map +1 -1
  150. package/dist/harnesses/engine/persistence.d.ts +21 -4
  151. package/dist/harnesses/engine/persistence.js +43 -6
  152. package/dist/harnesses/engine/persistence.js.map +1 -1
  153. package/dist/harnesses/engine/state.d.ts +9 -0
  154. package/dist/harnesses/engine/state.js +23 -10
  155. package/dist/harnesses/engine/state.js.map +1 -1
  156. package/dist/harnesses/impls/hermes-agent/bootstrap.js +4 -2
  157. package/dist/harnesses/impls/hermes-agent/bootstrap.js.map +1 -1
  158. package/dist/harnesses/impls/hermes-agent/config-builder.d.ts +1 -1
  159. package/dist/harnesses/impls/hermes-agent/config-builder.js +4 -2
  160. package/dist/harnesses/impls/hermes-agent/config-builder.js.map +1 -1
  161. package/dist/harnesses/impls/hermes-agent/harness.d.ts +14 -0
  162. package/dist/harnesses/impls/hermes-agent/harness.js +16 -2
  163. package/dist/harnesses/impls/hermes-agent/harness.js.map +1 -1
  164. package/dist/harnesses/impls/hermes-agent/prompt.d.ts +6 -6
  165. package/dist/harnesses/impls/hermes-agent/prompt.js +6 -6
  166. package/dist/harnesses/impls/learner/adapters/claude-code.d.ts +17 -0
  167. package/dist/harnesses/impls/learner/adapters/claude-code.js +113 -14
  168. package/dist/harnesses/impls/learner/adapters/claude-code.js.map +1 -1
  169. package/dist/harnesses/impls/learner/adapters/codex-code.d.ts +9 -0
  170. package/dist/harnesses/impls/learner/adapters/codex-code.js +30 -8
  171. package/dist/harnesses/impls/learner/adapters/codex-code.js.map +1 -1
  172. package/dist/harnesses/impls/learner/harness.d.ts +24 -0
  173. package/dist/harnesses/impls/learner/harness.js +27 -3
  174. package/dist/harnesses/impls/learner/harness.js.map +1 -1
  175. package/dist/harnesses/impls/learner/harvest.d.ts +1 -1
  176. package/dist/harnesses/impls/learner/harvest.js +23 -5
  177. package/dist/harnesses/impls/learner/harvest.js.map +1 -1
  178. package/dist/harnesses/impls/learner/restoration-patch.d.ts +2 -2
  179. package/dist/harnesses/impls/learner/restoration-patch.js +25 -6
  180. package/dist/harnesses/impls/learner/restoration-patch.js.map +1 -1
  181. package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.js +21 -1
  182. package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.js.map +1 -1
  183. package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.d.ts +74 -5
  184. package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.js +103 -32
  185. package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.js.map +1 -1
  186. package/dist/harnesses/readiness-registry.d.ts +7 -0
  187. package/dist/harnesses/readiness-registry.js +9 -0
  188. package/dist/harnesses/readiness-registry.js.map +1 -1
  189. package/dist/learner/revert-decision.d.ts +59 -0
  190. package/dist/learner/revert-decision.js +53 -0
  191. package/dist/learner/revert-decision.js.map +1 -0
  192. package/dist/learner/revert-stats.d.ts +24 -0
  193. package/dist/learner/revert-stats.js +44 -0
  194. package/dist/learner/revert-stats.js.map +1 -0
  195. package/dist/main.js +177 -104
  196. package/dist/main.js.map +1 -1
  197. package/dist/mcp/get-codedigest-reward.d.ts +13 -0
  198. package/dist/mcp/get-codedigest-reward.js +23 -0
  199. package/dist/mcp/get-codedigest-reward.js.map +1 -0
  200. package/dist/mcp/server.js +23 -0
  201. package/dist/mcp/server.js.map +1 -1
  202. package/dist/observability/debug-report-assemble.d.ts +43 -0
  203. package/dist/observability/debug-report-assemble.js +80 -0
  204. package/dist/observability/debug-report-assemble.js.map +1 -0
  205. package/dist/observability/emit-event.d.ts +9 -2
  206. package/dist/observability/emit-event.js +36 -2
  207. package/dist/observability/emit-event.js.map +1 -1
  208. package/dist/observability/file-logger.d.ts +69 -0
  209. package/dist/observability/file-logger.js +177 -0
  210. package/dist/observability/file-logger.js.map +1 -0
  211. package/dist/observability/redact-secrets.d.ts +65 -0
  212. package/dist/observability/redact-secrets.js +300 -0
  213. package/dist/observability/redact-secrets.js.map +1 -0
  214. package/dist/observability/tar.d.ts +30 -0
  215. package/dist/observability/tar.js +102 -0
  216. package/dist/observability/tar.js.map +1 -0
  217. package/dist/plugins/learner/skills/learn/consolidator-prompt.md +18 -1
  218. package/dist/plugins/learner/skills/learn/promoter-prompt.md +72 -1
  219. package/dist/preflight/pidfile-liveness.d.ts +44 -0
  220. package/dist/preflight/pidfile-liveness.js +103 -0
  221. package/dist/preflight/pidfile-liveness.js.map +1 -0
  222. package/dist/preflight/rpc-network.d.ts +40 -0
  223. package/dist/preflight/rpc-network.js +67 -1
  224. package/dist/preflight/rpc-network.js.map +1 -1
  225. package/dist/rpc/transport.d.ts +109 -0
  226. package/dist/rpc/transport.js +220 -0
  227. package/dist/rpc/transport.js.map +1 -0
  228. package/dist/scripts/donation-consumption-acceptance.js +7 -28
  229. package/dist/scripts/donation-consumption-acceptance.js.map +1 -1
  230. package/dist/scripts/swe-rebench-v2-pytest-missing.json +16 -0
  231. package/dist/solver-nets/prediction-operator-ux.d.ts +1 -2
  232. package/dist/solver-nets/prediction-operator-ux.js +56 -53
  233. package/dist/solver-nets/prediction-operator-ux.js.map +1 -1
  234. package/dist/solver-nets/registry.d.ts +19 -1
  235. package/dist/solver-nets/registry.js +37 -24
  236. package/dist/solver-nets/registry.js.map +1 -1
  237. package/dist/solver-types/_swe-rebench-v2-pool.d.ts +9 -2
  238. package/dist/solver-types/_swe-rebench-v2-pool.js +15 -20
  239. package/dist/solver-types/_swe-rebench-v2-pool.js.map +1 -1
  240. package/dist/solver-types/_swe-rebench-v2-state.d.ts +15 -0
  241. package/dist/solver-types/_swe-rebench-v2-state.js +19 -0
  242. package/dist/solver-types/_swe-rebench-v2-state.js.map +1 -1
  243. package/dist/solver-types/_swe-rebench-v2-validated-pool.d.ts +116 -2
  244. package/dist/solver-types/_swe-rebench-v2-validated-pool.js +296 -21
  245. package/dist/solver-types/_swe-rebench-v2-validated-pool.js.map +1 -1
  246. package/dist/solver-types/swe-rebench-v2-auto.d.ts +20 -11
  247. package/dist/solver-types/swe-rebench-v2-auto.js +64 -19
  248. package/dist/solver-types/swe-rebench-v2-auto.js.map +1 -1
  249. package/dist/solver-types/swe-rebench-v2.d.ts +8 -2
  250. package/dist/solver-types/swe-rebench-v2.js +127 -11
  251. package/dist/solver-types/swe-rebench-v2.js.map +1 -1
  252. package/dist/solvernets/daemon-init.d.ts +1 -1
  253. package/dist/solvernets/daemon-init.js +19 -4
  254. package/dist/solvernets/daemon-init.js.map +1 -1
  255. package/dist/solvernets/launched-record-dispatcher.d.ts +4 -0
  256. package/dist/solvernets/launched-record-dispatcher.js +10 -4
  257. package/dist/solvernets/launched-record-dispatcher.js.map +1 -1
  258. package/dist/solvernets/registry-client-erc8004.js +11 -0
  259. package/dist/solvernets/registry-client-erc8004.js.map +1 -1
  260. package/dist/solvernets/store.d.ts +2 -2
  261. package/dist/spend/ai-units-config.d.ts +39 -0
  262. package/dist/spend/ai-units-config.js +28 -0
  263. package/dist/spend/ai-units-config.js.map +1 -0
  264. package/dist/spend/ai-units.d.ts +89 -0
  265. package/dist/spend/ai-units.js +156 -0
  266. package/dist/spend/ai-units.js.map +1 -0
  267. package/dist/spend/cost-surface-status.d.ts +12 -0
  268. package/dist/spend/cost-surface-status.js +24 -0
  269. package/dist/spend/cost-surface-status.js.map +1 -0
  270. package/dist/spend/credential.d.ts +39 -0
  271. package/dist/spend/credential.js +71 -0
  272. package/dist/spend/credential.js.map +1 -0
  273. package/dist/spend/daemon-config.d.ts +13 -0
  274. package/dist/spend/daemon-config.js +24 -0
  275. package/dist/spend/daemon-config.js.map +1 -0
  276. package/dist/spend/pricing.d.ts +16 -0
  277. package/dist/spend/pricing.js +26 -0
  278. package/dist/spend/pricing.js.map +1 -0
  279. package/dist/spend/record.d.ts +13 -0
  280. package/dist/spend/record.js +36 -0
  281. package/dist/spend/record.js.map +1 -0
  282. package/dist/spend/usage.d.ts +27 -0
  283. package/dist/spend/usage.js +113 -0
  284. package/dist/spend/usage.js.map +1 -0
  285. package/dist/store/store.d.ts +101 -0
  286. package/dist/store/store.js +304 -4
  287. package/dist/store/store.js.map +1 -1
  288. package/dist/trajectory/transcript-parsers/codex-session.d.ts +12 -6
  289. package/dist/trajectory/transcript-parsers/codex-session.js +114 -13
  290. package/dist/trajectory/transcript-parsers/codex-session.js.map +1 -1
  291. package/dist/trajectory/transcript-parsers/types.d.ts +8 -8
  292. package/dist/trajectory/transcript-session-dirs.d.ts +18 -0
  293. package/dist/trajectory/transcript-session-dirs.js +85 -0
  294. package/dist/trajectory/transcript-session-dirs.js.map +1 -0
  295. package/dist/trajectory/transcript-watcher.d.ts +20 -1
  296. package/dist/trajectory/transcript-watcher.js +108 -32
  297. package/dist/trajectory/transcript-watcher.js.map +1 -1
  298. package/dist/tx-retry.d.ts +25 -0
  299. package/dist/tx-retry.js +95 -7
  300. package/dist/tx-retry.js.map +1 -1
  301. package/dist/types/payloads/portfolio-v0.d.ts +3 -3
  302. package/dist/types/payloads/prediction-apy-v0.d.ts +3 -3
  303. package/dist/types/payloads/prediction-v0.d.ts +12 -12
  304. package/package.json +11 -3
  305. package/plugins/learner/skills/learn/consolidator-prompt.md +18 -1
  306. package/plugins/learner/skills/learn/promoter-prompt.md +72 -1
  307. package/plugins/swe-rebench-v2-diffmin/README.md +10 -9
  308. package/plugins/swe-rebench-v2-diffmin/jinn.plugin.json +1 -1
  309. package/plugins/swe-rebench-v2-diffmin/skills/diffmin/SKILL.md +15 -10
  310. package/plugins/swe-rebench-v2-diffmin/skills/test-map/SKILL.md +10 -12
  311. package/plugins/swe-rebench-v2-runtime/.claude-plugin/plugin.json +1 -1
  312. package/plugins/swe-rebench-v2-runtime/.codex-plugin/plugin.json +3 -3
  313. package/plugins/swe-rebench-v2-runtime/README.md +6 -6
  314. package/plugins/swe-rebench-v2-runtime/jinn.plugin.json +2 -3
  315. package/plugins/swe-rebench-v2-runtime/skills/task/SKILL.md +81 -0
  316. package/dist/dashboard/assets/index-BUlE8F3Y.js +0 -330
  317. package/dist/dashboard/assets/index-blqc7eqq.css +0 -32
  318. package/plugins/swe-rebench-v2-runtime/skills/orient/SKILL.md +0 -29
  319. package/plugins/swe-rebench-v2-runtime/skills/plan/SKILL.md +0 -53
@@ -0,0 +1,71 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { join } from 'node:path';
4
+ import { CLAUDE_CODE_HARNESS, CODEX_HARNESS, HERMES_AGENT_HARNESS, canonicalHarnessName, } from '../harnesses/names.js';
5
+ /**
6
+ * Does this operator have Claude Code installed and authed via OAuth?
7
+ *
8
+ * The `claude` CLI keeps its OAuth token in the OS keyring on macOS, in
9
+ * platform-equivalent stores elsewhere, and writes per-user state under
10
+ * `~/.claude/`. The cheapest cross-platform "operator has an active
11
+ * Claude Code Pro subscription set up" probe is "does `~/.claude/`
12
+ * exist?" — it's created by `claude` on first run and persists.
13
+ *
14
+ * Injectable for tests via `homeDirOverride`.
15
+ */
16
+ export function hasClaudeCodeOnDisk(homeDirOverride) {
17
+ return existsSync(join(homeDirOverride ?? homedir(), '.claude'));
18
+ }
19
+ /**
20
+ * Does this operator have Codex CLI installed and authed?
21
+ *
22
+ * Codex CLI writes its OAuth to `~/.codex/auth.json`. Presence is the
23
+ * subscription signal.
24
+ */
25
+ export function hasCodexOnDisk(homeDirOverride) {
26
+ return existsSync(join(homeDirOverride ?? homedir(), '.codex', 'auth.json'));
27
+ }
28
+ /**
29
+ * Resolve which authentication credential a harness will bill against.
30
+ *
31
+ * Precedence per provider (preserved from PR #345 / #474):
32
+ * 1. subscription token env var (`*:subscription`) — most explicit
33
+ * subscription marker; the operator has deliberately set it
34
+ * 2. raw-API-key env var (`*:api-key`) — explicit api-key
35
+ * 3. on-disk OAuth (`*:subscription`) — the typical operator who
36
+ * installed `claude` / `codex` CLI and never set an env var
37
+ * 4. null — no credential resolved
38
+ *
39
+ * Returns null when the harness makes no paid LLM call (e.g. prediction
40
+ * harnesses) or no credential is recognisable. Issue #901: disk
41
+ * detection added so stock subscription installs get a credential and
42
+ * the AI-units gate engages by default; precedence above kept stable so
43
+ * the cost-surface UI from #345 / #474 still reads the same.
44
+ */
45
+ export function resolveCredentialId(harness, env, homeDirOverride) {
46
+ if (!harness)
47
+ return null;
48
+ switch (canonicalHarnessName(harness)) {
49
+ case CLAUDE_CODE_HARNESS:
50
+ if (env['CLAUDE_CODE_OAUTH_TOKEN'])
51
+ return 'anthropic:subscription';
52
+ if (env['ANTHROPIC_API_KEY'])
53
+ return 'anthropic:api-key';
54
+ if (hasClaudeCodeOnDisk(homeDirOverride))
55
+ return 'anthropic:subscription';
56
+ return null;
57
+ case CODEX_HARNESS:
58
+ if (env['OPENAI_API_KEY'])
59
+ return 'openai:api-key';
60
+ if (hasCodexOnDisk(homeDirOverride))
61
+ return 'openai:subscription';
62
+ return null;
63
+ case HERMES_AGENT_HARNESS: {
64
+ const provider = (env['JINN_HERMES_PROVIDER'] ?? 'hermes').trim().toLowerCase();
65
+ return `${provider}:api-key`;
66
+ }
67
+ default:
68
+ return null;
69
+ }
70
+ }
71
+ //# sourceMappingURL=credential.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential.js","sourceRoot":"","sources":["../../src/spend/credential.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAK/B;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAC,eAAwB;IAC1D,OAAO,UAAU,CAAC,IAAI,CAAC,eAAe,IAAI,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC;AACnE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,eAAwB;IACrD,OAAO,UAAU,CAAC,IAAI,CAAC,eAAe,IAAI,OAAO,EAAE,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;AAC/E,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,mBAAmB,CACjC,OAA2B,EAC3B,GAAsB,EACtB,eAAwB;IAExB,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAC1B,QAAQ,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC;QACtC,KAAK,mBAAmB;YACtB,IAAI,GAAG,CAAC,yBAAyB,CAAC;gBAAE,OAAO,wBAAwB,CAAC;YACpE,IAAI,GAAG,CAAC,mBAAmB,CAAC;gBAAE,OAAO,mBAAmB,CAAC;YACzD,IAAI,mBAAmB,CAAC,eAAe,CAAC;gBAAE,OAAO,wBAAwB,CAAC;YAC1E,OAAO,IAAI,CAAC;QACd,KAAK,aAAa;YAChB,IAAI,GAAG,CAAC,gBAAgB,CAAC;gBAAE,OAAO,gBAAgB,CAAC;YACnD,IAAI,cAAc,CAAC,eAAe,CAAC;gBAAE,OAAO,qBAAqB,CAAC;YAClE,OAAO,IAAI,CAAC;QACd,KAAK,oBAAoB,CAAC,CAAC,CAAC;YAC1B,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;YAChF,OAAO,GAAG,QAAQ,UAAU,CAAC;QAC/B,CAAC;QACD;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { JinnConfig } from '../config.js';
2
+ import { type CredentialId } from './credential.js';
3
+ export interface SpendCapDaemonConfig {
4
+ /** credentialId -> USD/day cap. */
5
+ caps: Record<CredentialId, number>;
6
+ /** manifest CID -> the credential its harness bills against. */
7
+ manifestCredentials: Record<string, CredentialId>;
8
+ }
9
+ /**
10
+ * Assemble the daemon's spend-cap config from operator config + env. Returns
11
+ * undefined when no credential ends up with a cap (the gate then stays off).
12
+ */
13
+ export declare function buildSpendCapConfig(config: Pick<JinnConfig, 'joinedSolverNets' | 'spendCaps'>, env: NodeJS.ProcessEnv): SpendCapDaemonConfig | undefined;
@@ -0,0 +1,24 @@
1
+ import { resolveCredentialId } from './credential.js';
2
+ /**
3
+ * Assemble the daemon's spend-cap config from operator config + env. Returns
4
+ * undefined when no credential ends up with a cap (the gate then stays off).
5
+ */
6
+ export function buildSpendCapConfig(config, env) {
7
+ const blanketRaw = env['JINN_SPEND_CAP_USD'];
8
+ const blanketNum = blanketRaw != null && blanketRaw.trim() !== '' ? Number(blanketRaw) : NaN;
9
+ const blanket = Number.isFinite(blanketNum) && blanketNum > 0 ? blanketNum : undefined;
10
+ const manifestCredentials = {};
11
+ for (const [manifestCid, entry] of Object.entries(config.joinedSolverNets ?? {})) {
12
+ const credentialId = resolveCredentialId(entry.harness, env);
13
+ if (credentialId)
14
+ manifestCredentials[manifestCid] = credentialId;
15
+ }
16
+ const caps = {};
17
+ for (const credentialId of new Set(Object.values(manifestCredentials))) {
18
+ const cap = config.spendCaps?.[credentialId] ?? blanket;
19
+ if (cap != null)
20
+ caps[credentialId] = cap;
21
+ }
22
+ return Object.keys(caps).length > 0 ? { caps, manifestCredentials } : undefined;
23
+ }
24
+ //# sourceMappingURL=daemon-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"daemon-config.js","sourceRoot":"","sources":["../../src/spend/daemon-config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAqB,MAAM,iBAAiB,CAAC;AASzE;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAA0D,EAC1D,GAAsB;IAEtB,MAAM,UAAU,GAAG,GAAG,CAAC,oBAAoB,CAAC,CAAC;IAC7C,MAAM,UAAU,GAAG,UAAU,IAAI,IAAI,IAAI,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAC7F,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;IAEvF,MAAM,mBAAmB,GAAiC,EAAE,CAAC;IAC7D,KAAK,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,IAAI,EAAE,CAAC,EAAE,CAAC;QACjF,MAAM,YAAY,GAAG,mBAAmB,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAC7D,IAAI,YAAY;YAAE,mBAAmB,CAAC,WAAW,CAAC,GAAG,YAAY,CAAC;IACpE,CAAC;IAED,MAAM,IAAI,GAAiC,EAAE,CAAC;IAC9C,KAAK,MAAM,YAAY,IAAI,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC;QACvE,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC;QACxD,IAAI,GAAG,IAAI,IAAI;YAAE,IAAI,CAAC,YAAY,CAAC,GAAG,GAAG,CAAC;IAC5C,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAClF,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Price a token count in USD for the given model. Returns null when the model
3
+ * is unknown to the catalog (caller falls back to a heuristic).
4
+ *
5
+ * Uses the tokenlens bundled, offline model catalog (models.dev snapshot).
6
+ * The `tokenlens` re-export of `getTokenCosts` accepts an object with
7
+ * `{ modelId, usage }` and injects the default catalog automatically.
8
+ *
9
+ * Note: tokenlens's bundled catalog may lag current model IDs (e.g.
10
+ * `claude-haiku-4-5-20251001` is absent in v1.3.1 and returns null);
11
+ * callers must handle null gracefully.
12
+ */
13
+ export declare function priceTokens(modelId: string, tokens: {
14
+ inputTokens: number;
15
+ outputTokens: number;
16
+ }): number | null;
@@ -0,0 +1,26 @@
1
+ import { getTokenCosts } from 'tokenlens';
2
+ /**
3
+ * Price a token count in USD for the given model. Returns null when the model
4
+ * is unknown to the catalog (caller falls back to a heuristic).
5
+ *
6
+ * Uses the tokenlens bundled, offline model catalog (models.dev snapshot).
7
+ * The `tokenlens` re-export of `getTokenCosts` accepts an object with
8
+ * `{ modelId, usage }` and injects the default catalog automatically.
9
+ *
10
+ * Note: tokenlens's bundled catalog may lag current model IDs (e.g.
11
+ * `claude-haiku-4-5-20251001` is absent in v1.3.1 and returns null);
12
+ * callers must handle null gracefully.
13
+ */
14
+ export function priceTokens(modelId, tokens) {
15
+ try {
16
+ const costs = getTokenCosts({
17
+ modelId,
18
+ usage: { prompt_tokens: tokens.inputTokens, completion_tokens: tokens.outputTokens },
19
+ });
20
+ return typeof costs?.totalUSD === 'number' ? costs.totalUSD : null;
21
+ }
22
+ catch {
23
+ return null;
24
+ }
25
+ }
26
+ //# sourceMappingURL=pricing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pricing.js","sourceRoot":"","sources":["../../src/spend/pricing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CACzB,OAAe,EACf,MAAqD;IAErD,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,aAAa,CAAC;YAC1B,OAAO;YACP,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,CAAC,WAAW,EAAE,iBAAiB,EAAE,MAAM,CAAC,YAAY,EAAE;SACrF,CAAC,CAAC;QACH,OAAO,OAAO,KAAK,EAAE,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IACrE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Store } from '../store/store.js';
2
+ /**
3
+ * Record the cost of one finished harness run as a `task_cost` activity row.
4
+ * Called once per harness run (at the POST_SNAPSHOT transition). Best-effort:
5
+ * never throws — a parse failure must not break task execution.
6
+ */
7
+ export declare function recordTaskCost(store: Store, args: {
8
+ requestId: string;
9
+ harness: string;
10
+ model: string | undefined;
11
+ workingDir: string;
12
+ solverType: string | null;
13
+ }, env?: NodeJS.ProcessEnv): void;
@@ -0,0 +1,36 @@
1
+ import { resolveCredentialId } from './credential.js';
2
+ import { harvestHarnessUsage } from './usage.js';
3
+ /**
4
+ * Record the cost of one finished harness run as a `task_cost` activity row.
5
+ * Called once per harness run (at the POST_SNAPSHOT transition). Best-effort:
6
+ * never throws — a parse failure must not break task execution.
7
+ */
8
+ export function recordTaskCost(store, args, env = process.env) {
9
+ try {
10
+ const credentialId = resolveCredentialId(args.harness, env);
11
+ if (!credentialId)
12
+ return;
13
+ const usage = harvestHarnessUsage(args.harness, args.workingDir, args.model);
14
+ const actualCostUsdMicros = Math.round(usage.costUsd * 1_000_000);
15
+ store.recordActivityEvent({
16
+ ts: new Date().toISOString(),
17
+ kind: 'task_cost',
18
+ requestId: args.requestId,
19
+ solverType: args.solverType,
20
+ credentialId,
21
+ costUsdMicros: actualCostUsdMicros,
22
+ model: usage.model,
23
+ detail: usage.estimated ? 'estimated' : 'observed',
24
+ });
25
+ // Issue #815: fill actual_cost_usd_micros on the per-request claimed
26
+ // row + set claim_status='delivered'. ai_units stays as captured at
27
+ // claim time (estimates are the gate input, never recomputed).
28
+ // Idempotent: no-op when no claimed row exists for this request id.
29
+ store.finalizeClaimDelivered(args.requestId, actualCostUsdMicros);
30
+ }
31
+ catch (err) {
32
+ console.warn(`[spend] failed to record task cost for ${args.requestId}: ` +
33
+ `${err instanceof Error ? err.message : String(err)}`);
34
+ }
35
+ }
36
+ //# sourceMappingURL=record.js.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C1D,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CACxD,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,27 @@
1
+ /** USD attributed to a task whose model has no known price. */
2
+ export declare const UNKNOWN_MODEL_FALLBACK_USD = 1;
3
+ export interface HarnessUsage {
4
+ model: string;
5
+ costUsd: number;
6
+ /** true = derived from an a-priori heuristic; false = from observed usage. */
7
+ estimated: boolean;
8
+ inputTokens?: number;
9
+ outputTokens?: number;
10
+ }
11
+ /** Parse Claude Code `--output-format stream-json` output for the terminal result. */
12
+ export declare function parseClaudeCodeUsage(stdoutJsonl: string): {
13
+ costUsd: number;
14
+ inputTokens?: number;
15
+ outputTokens?: number;
16
+ } | null;
17
+ /** Parse Codex `--json` output for the last turn.completed token usage. */
18
+ export declare function parseCodexUsage(stdoutJsonl: string): {
19
+ inputTokens: number;
20
+ outputTokens: number;
21
+ } | null;
22
+ /**
23
+ * Determine the USD cost of a finished harness run. Reads the harness's own
24
+ * output file for observed usage; falls back to a heuristic on any failure.
25
+ * Always returns a HarnessUsage — never throws.
26
+ */
27
+ export declare function harvestHarnessUsage(harness: string, workingDir: string, model: string | undefined): HarnessUsage;
@@ -0,0 +1,113 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { CLAUDE_CODE_HARNESS, CODEX_HARNESS, canonicalHarnessName } from '../harnesses/names.js';
4
+ import { estimateModelCost } from '../harnesses/cost-estimates.js';
5
+ import { priceTokens } from './pricing.js';
6
+ /** USD attributed to a task whose model has no known price. */
7
+ export const UNKNOWN_MODEL_FALLBACK_USD = 1.0;
8
+ /** Parse Claude Code `--output-format stream-json` output for the terminal result. */
9
+ export function parseClaudeCodeUsage(stdoutJsonl) {
10
+ let result = null;
11
+ for (const line of stdoutJsonl.split('\n')) {
12
+ const trimmed = line.trim();
13
+ if (!trimmed)
14
+ continue;
15
+ let obj;
16
+ try {
17
+ obj = JSON.parse(trimmed);
18
+ }
19
+ catch {
20
+ continue;
21
+ }
22
+ if (obj['type'] === 'result' && typeof obj['total_cost_usd'] === 'number') {
23
+ const usage = obj['usage'];
24
+ result = {
25
+ costUsd: obj['total_cost_usd'],
26
+ inputTokens: typeof usage?.['input_tokens'] === 'number' ? usage['input_tokens'] : undefined,
27
+ outputTokens: typeof usage?.['output_tokens'] === 'number' ? usage['output_tokens'] : undefined,
28
+ };
29
+ }
30
+ }
31
+ return result;
32
+ }
33
+ /** Parse Codex `--json` output for the last turn.completed token usage. */
34
+ export function parseCodexUsage(stdoutJsonl) {
35
+ let result = null;
36
+ for (const line of stdoutJsonl.split('\n')) {
37
+ const trimmed = line.trim();
38
+ if (!trimmed)
39
+ continue;
40
+ let obj;
41
+ try {
42
+ obj = JSON.parse(trimmed);
43
+ }
44
+ catch {
45
+ continue;
46
+ }
47
+ if (obj['type'] === 'turn.completed' && obj['usage']) {
48
+ const usage = obj['usage'];
49
+ const inT = usage['input_tokens'];
50
+ const outT = usage['output_tokens'];
51
+ if (typeof inT === 'number' && typeof outT === 'number') {
52
+ result = { inputTokens: inT, outputTokens: outT };
53
+ }
54
+ }
55
+ }
56
+ return result;
57
+ }
58
+ function heuristicUsage(model) {
59
+ const est = model ? estimateModelCost(model) : null;
60
+ return {
61
+ model: model ?? 'unknown',
62
+ costUsd: est?.usd ?? UNKNOWN_MODEL_FALLBACK_USD,
63
+ estimated: true,
64
+ };
65
+ }
66
+ /**
67
+ * Determine the USD cost of a finished harness run. Reads the harness's own
68
+ * output file for observed usage; falls back to a heuristic on any failure.
69
+ * Always returns a HarnessUsage — never throws.
70
+ */
71
+ export function harvestHarnessUsage(harness, workingDir, model) {
72
+ try {
73
+ const canonical = canonicalHarnessName(harness);
74
+ if (canonical === CLAUDE_CODE_HARNESS) {
75
+ const raw = readFileSync(join(workingDir, '.claude-code', 'stdout.jsonl'), 'utf8');
76
+ const parsed = parseClaudeCodeUsage(raw);
77
+ if (parsed) {
78
+ return {
79
+ model: model ?? 'unknown',
80
+ costUsd: parsed.costUsd,
81
+ estimated: false,
82
+ inputTokens: parsed.inputTokens,
83
+ outputTokens: parsed.outputTokens,
84
+ };
85
+ }
86
+ return heuristicUsage(model);
87
+ }
88
+ if (canonical === CODEX_HARNESS) {
89
+ const raw = readFileSync(join(workingDir, '.codex-code', 'stdout.jsonl'), 'utf8');
90
+ const parsed = parseCodexUsage(raw);
91
+ // When there is no model id, parsed token counts cannot be priced —
92
+ // discard them and fall back to the heuristic (per spec).
93
+ if (parsed && model) {
94
+ const usd = priceTokens(model, parsed);
95
+ if (usd != null) {
96
+ return {
97
+ model,
98
+ costUsd: usd,
99
+ estimated: false,
100
+ inputTokens: parsed.inputTokens,
101
+ outputTokens: parsed.outputTokens,
102
+ };
103
+ }
104
+ }
105
+ return heuristicUsage(model);
106
+ }
107
+ return heuristicUsage(model);
108
+ }
109
+ catch {
110
+ return heuristicUsage(model);
111
+ }
112
+ }
113
+ //# sourceMappingURL=usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/spend/usage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AACjG,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,+DAA+D;AAC/D,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAW9C,sFAAsF;AACtF,MAAM,UAAU,oBAAoB,CAClC,WAAmB;IAEnB,IAAI,MAAM,GAA4E,IAAI,CAAC;IAC3F,KAAK,MAAM,IAAI,IAAI,WAAW,CAAC,KAAK,CAAC,IA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,SAAS;oBACzB,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,SAAS,EAAE,KAAK;oBAChB,WAAW,EAAE,MAAM,CAAC,WAAW;oBAC/B,YAAY,EAAE,MAAM,CAAC,YAAY;iBAClC,CAAC;YACJ,CAAC;YACD,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;QACD,IAAI,SAAS,KAAK,aAAa,EAAE,CAAC;YAChC,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,aAAa,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC;YAClF,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;YACpC,oEAAoE;YACpE,0DAA0D;YAC1D,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;gBACpB,MAAM,GAAG,GAAG,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;gBACvC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;oBAChB,OAAO;wBACL,KAAK;wBACL,OAAO,EAAE,GAAG;wBACZ,SAAS,EAAE,KAAK;wBAChB,WAAW,EAAE,MAAM,CAAC,WAAW;wBAC/B,YAAY,EAAE,MAAM,CAAC,YAAY;qBAClC,CAAC;gBACJ,CAAC;YACH,CAAC;YACD,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC"}
@@ -10,6 +10,17 @@ export interface ActivityEventInput {
10
10
  solverType?: string | null;
11
11
  outcome?: string | null;
12
12
  detail?: string | null;
13
+ credentialId?: string | null;
14
+ costUsdMicros?: number | null;
15
+ model?: string | null;
16
+ /** Projected AI units debited at claim time (issue #815). Estimates are the gate input; never recomputed. */
17
+ aiUnits?: number | null;
18
+ /** Lifecycle stamp on the per-request row: 'claimed' | 'claim_failed' | 'delivered'. */
19
+ claimStatus?: string | null;
20
+ /** USD estimate captured at claim time (micros). Distinct from `actualCostUsdMicros` filled on completion. */
21
+ estimatedCostUsdMicros?: number | null;
22
+ /** USD actually billed (micros) — filled by the completion path; null until then. */
23
+ actualCostUsdMicros?: number | null;
13
24
  }
14
25
  export interface ActivityEventRow {
15
26
  id: number;
@@ -21,6 +32,13 @@ export interface ActivityEventRow {
21
32
  solverType: string | null;
22
33
  outcome: string | null;
23
34
  detail: string | null;
35
+ credentialId: string | null;
36
+ costUsdMicros: number | null;
37
+ model: string | null;
38
+ aiUnits: number | null;
39
+ claimStatus: string | null;
40
+ estimatedCostUsdMicros: number | null;
41
+ actualCostUsdMicros: number | null;
24
42
  }
25
43
  export interface RewardClaimInput {
26
44
  ts: string;
@@ -148,6 +166,22 @@ export interface NetworkArtifactMetadataRow {
148
166
  lastUsedAt: string;
149
167
  peerCatalogId: string | null;
150
168
  }
169
+ export interface Erc8004AnchorInput {
170
+ envelopeId: string;
171
+ envelopeCid: string;
172
+ contentKind: string;
173
+ metadataKey: string;
174
+ agentId: string;
175
+ chainId: number;
176
+ identityRegistryAddress: string;
177
+ txHash: string;
178
+ blockNumber: number | null;
179
+ payloadHex: string;
180
+ anchoredAt: number;
181
+ }
182
+ export interface Erc8004AnchorRow extends Erc8004AnchorInput {
183
+ id: number;
184
+ }
151
185
  export type TaskPostingPolicyType = 'once_per_safe' | 'once_per_bucket' | 'interval';
152
186
  type LauncherTaskProjectionState = 'open' | 'claims-in-flight' | 'fully-claimed' | 'settled' | 'failed';
153
187
  export interface TaskPostRecord {
@@ -185,6 +219,8 @@ export declare class Store {
185
219
  private ensureTaskPostsTaskCoordinatorColumns;
186
220
  /** Older local DBs may have the projection table from before Task grouping fields landed. */
187
221
  private ensureEnvelopeProjectionColumns;
222
+ /** Older local DBs predate the per-credential spend-ledger columns on activity_events. */
223
+ private ensureActivityEventCostColumns;
188
224
  /**
189
225
  * Task-native startup ignores the retired request-first `restoration_intents`
190
226
  * table. Keep a one-time local marker when old in-flight rows are present so
@@ -194,6 +230,14 @@ export declare class Store {
194
230
  /** Idempotent: older DBs before idx_reward_claims_tx may lack the unique index. */
195
231
  private ensureRewardClaimsTxIndex;
196
232
  recordOwnActivity(requestId: string, role: 'created' | 'claimed' | 'delivered' | 'evaluated'): void;
233
+ /**
234
+ * Membership-only variant of `recordOwnActivity`: writes the
235
+ * `own_activity` row but does NOT emit a generic `activity_events`
236
+ * row. Used by paths that emit their own enriched activity event
237
+ * (e.g. issue #815's claim path attaches credentialId / aiUnits /
238
+ * estimatedCostUsdMicros / claimStatus to the row).
239
+ */
240
+ markOwnActivity(requestId: string, role: 'created' | 'claimed' | 'delivered' | 'evaluated'): void;
197
241
  isOwnActivity(requestId: string): boolean;
198
242
  setShutdownState(state: 'clean' | 'running'): void;
199
243
  getShutdownState(): string | null;
@@ -279,8 +323,63 @@ export declare class Store {
279
323
  since?: string;
280
324
  cursor?: string;
281
325
  }): ActivityEventRow[];
326
+ /**
327
+ * Total cost in micro-dollars recorded against a credential since the most
328
+ * recent UTC midnight. Backs the daily spend cap.
329
+ */
330
+ spentTodayMicros(credentialId: string, now?: Date): number;
331
+ /**
332
+ * Sum of `ai_units` for a credential within the current 6h UTC-aligned
333
+ * block (00:00 / 06:00 / 12:00 / 18:00 boundaries). Reads only rows whose
334
+ * `claim_status = 'claimed'` or `'delivered'` so failed-claim rows
335
+ * (`ai_units = 0`, `claim_status = 'claim_failed'`) don't muddy the sum
336
+ * even though their contribution is already zero.
337
+ *
338
+ * Issue #815. Backs the per-block AI-units ceiling gate.
339
+ */
340
+ aiUnitsThisBlock(credentialId: string, now?: Date): number;
341
+ /**
342
+ * Sum of `ai_units` for a credential within the trailing 7-day rolling
343
+ * window from `now`. Backs the per-week AI-units safety-net ceiling.
344
+ * Issue #815.
345
+ */
346
+ aiUnitsThisWeek(credentialId: string, now?: Date): number;
347
+ /**
348
+ * True iff an `ai_units_cap_reached` row exists for the given
349
+ * (credentialId, window, blockId). Used by the daemon to hydrate the
350
+ * AI-units gate's in-memory pause memo across restarts so the
351
+ * "exactly one event per (credential, window, block-id)" guarantee
352
+ * holds across process boundaries (issue #815, finding 1).
353
+ *
354
+ * Lookup is by `credential_id` + `kind` + the `[block=...][window=...]`
355
+ * markers that `daemon.ts` embeds in the row's `detail` string.
356
+ */
357
+ hasAiUnitsCapReachedFor(credentialId: string, window: 'block' | 'week', blockId: string): boolean;
358
+ /**
359
+ * Mark the per-request `claimed` row as `delivered` and record
360
+ * `actual_cost_usd_micros`. The `ai_units` projection captured at
361
+ * claim time is intentionally NOT recomputed — the issue spec says
362
+ * "estimates are the gate input, never recomputed". Idempotent: a
363
+ * no-op when no `claimed` row exists.
364
+ */
365
+ finalizeClaimDelivered(requestId: string, actualCostUsdMicros: number): void;
282
366
  /** Newer events first, then ascending id for `jinn logs --follow` (oldest in batch printed first in caller). */
283
367
  getActivityEventsAfterId(afterId: number, limit: number): ActivityEventRow[];
368
+ /**
369
+ * Filtered, id-cursored page of activity events for the dedicated Events
370
+ * page. Newest-first.
371
+ *
372
+ * Cursors on `id` rather than `ts` so startup/shutdown rows with null
373
+ * timestamps remain reachable.
374
+ */
375
+ getActivityEventsPage(opts?: {
376
+ kinds?: string[];
377
+ outcome?: string;
378
+ requestId?: string;
379
+ beforeId?: number;
380
+ limit?: number;
381
+ }): ActivityEventRow[];
382
+ getActivityEventById(id: number): ActivityEventRow | null;
284
383
  getActivityCountsByKind(): Record<string, number>;
285
384
  getLastEventAtForService(serviceIndex: number): string | null;
286
385
  getActivityCountsForService(serviceIndex: number): Record<string, number>;
@@ -398,6 +497,8 @@ export declare class Store {
398
497
  }>;
399
498
  saveEnvelopeProjection(projection: EnvelopeProjection): void;
400
499
  queryEnvelopeProjections(query?: EnvelopeProjectionQuery): EnvelopeProjection[];
500
+ saveErc8004Anchor(input: Erc8004AnchorInput): void;
501
+ listErc8004AnchorsByEnvelopeCids(envelopeCids: readonly string[]): Erc8004AnchorRow[];
401
502
  close(): void;
402
503
  }
403
504
  export {};