@jinn-network/client 0.1.6 → 0.1.7-canary.d4e4e183

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 (288) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/deployments/deployment-jinn-mvi-l1-sepolia-fast.json +23 -4
  3. package/deployments/deployment-jinn-mvi-l1-sepolia.json +23 -4
  4. package/deployments/deployment-jinn-mvi-l2-baseSepolia.json +5 -4
  5. package/dist/adapters/mech/adapter.d.ts +38 -1
  6. package/dist/adapters/mech/adapter.js +241 -54
  7. package/dist/adapters/mech/adapter.js.map +1 -1
  8. package/dist/adapters/mech/contracts.d.ts +17 -4
  9. package/dist/adapters/mech/contracts.js +8 -2
  10. package/dist/adapters/mech/contracts.js.map +1 -1
  11. package/dist/adapters/mech/safe-revert.d.ts +20 -0
  12. package/dist/adapters/mech/safe-revert.js +12 -4
  13. package/dist/adapters/mech/safe-revert.js.map +1 -1
  14. package/dist/adapters/mech/safe.d.ts +5 -1
  15. package/dist/adapters/mech/safe.js +27 -8
  16. package/dist/adapters/mech/safe.js.map +1 -1
  17. package/dist/adapters/mech/verdict-code.d.ts +1 -0
  18. package/dist/adapters/mech/verdict-code.js +18 -0
  19. package/dist/adapters/mech/verdict-code.js.map +1 -1
  20. package/dist/api/admin-endpoint.d.ts +15 -3
  21. package/dist/api/admin-endpoint.js +24 -2
  22. package/dist/api/admin-endpoint.js.map +1 -1
  23. package/dist/api/bootstrap-endpoint.js +49 -0
  24. package/dist/api/bootstrap-endpoint.js.map +1 -1
  25. package/dist/api/codex-doctor-endpoint.d.ts +73 -0
  26. package/dist/api/codex-doctor-endpoint.js +177 -0
  27. package/dist/api/codex-doctor-endpoint.js.map +1 -0
  28. package/dist/api/discovery-endpoint.d.ts +1 -0
  29. package/dist/api/discovery-endpoint.js +26 -0
  30. package/dist/api/discovery-endpoint.js.map +1 -1
  31. package/dist/api/fleet-build.d.ts +1 -0
  32. package/dist/api/fleet-build.js +2 -1
  33. package/dist/api/fleet-build.js.map +1 -1
  34. package/dist/api/gather-status.d.ts +11 -0
  35. package/dist/api/gather-status.js +400 -4
  36. package/dist/api/gather-status.js.map +1 -1
  37. package/dist/api/hermes-doctor-endpoint.d.ts +117 -0
  38. package/dist/api/hermes-doctor-endpoint.js +229 -23
  39. package/dist/api/hermes-doctor-endpoint.js.map +1 -1
  40. package/dist/api/launcher-status.d.ts +21 -16
  41. package/dist/api/launcher-status.js +2 -1
  42. package/dist/api/launcher-status.js.map +1 -1
  43. package/dist/api/portfolio-v0-build.d.ts +10 -0
  44. package/dist/api/portfolio-v0-build.js +24 -5
  45. package/dist/api/portfolio-v0-build.js.map +1 -1
  46. package/dist/api/prediction-v1-build.d.ts +10 -0
  47. package/dist/api/prediction-v1-build.js +7 -1
  48. package/dist/api/prediction-v1-build.js.map +1 -1
  49. package/dist/api/server.d.ts +31 -1
  50. package/dist/api/server.js +68 -1
  51. package/dist/api/server.js.map +1 -1
  52. package/dist/api/setup-endpoints.d.ts +16 -0
  53. package/dist/api/setup-endpoints.js +78 -4
  54. package/dist/api/setup-endpoints.js.map +1 -1
  55. package/dist/api/setup-retry-endpoint.d.ts +19 -0
  56. package/dist/api/setup-retry-endpoint.js +32 -0
  57. package/dist/api/setup-retry-endpoint.js.map +1 -0
  58. package/dist/api/solvernets-endpoints.d.ts +8 -0
  59. package/dist/api/solvernets-endpoints.js +71 -43
  60. package/dist/api/solvernets-endpoints.js.map +1 -1
  61. package/dist/api/status-build.d.ts +72 -0
  62. package/dist/api/status-build.js +73 -18
  63. package/dist/api/status-build.js.map +1 -1
  64. package/dist/api/task-run-routing.d.ts +7 -0
  65. package/dist/api/task-run-routing.js +12 -0
  66. package/dist/api/task-run-routing.js.map +1 -0
  67. package/dist/api/task-runs-build.d.ts +21 -0
  68. package/dist/api/task-runs-build.js +14 -1
  69. package/dist/api/task-runs-build.js.map +1 -1
  70. package/dist/build-info.json +4 -4
  71. package/dist/build-meta.json +1 -1
  72. package/dist/chain-read-errors.d.ts +10 -0
  73. package/dist/chain-read-errors.js +15 -0
  74. package/dist/chain-read-errors.js.map +1 -1
  75. package/dist/cli/commands/auth.js +1 -1
  76. package/dist/cli/commands/auth.js.map +1 -1
  77. package/dist/cli/commands/create.js +3 -2
  78. package/dist/cli/commands/create.js.map +1 -1
  79. package/dist/cli/commands/doctor.d.ts +2 -0
  80. package/dist/cli/commands/doctor.js +2 -0
  81. package/dist/cli/commands/doctor.js.map +1 -1
  82. package/dist/cli/commands/rewards.js +11 -7
  83. package/dist/cli/commands/rewards.js.map +1 -1
  84. package/dist/cli/commands/solver-nets.js +24 -9
  85. package/dist/cli/commands/solver-nets.js.map +1 -1
  86. package/dist/cli/commands/status.js +1 -1
  87. package/dist/cli/commands/status.js.map +1 -1
  88. package/dist/cli/commands/tasks.js +86 -9
  89. package/dist/cli/commands/tasks.js.map +1 -1
  90. package/dist/cli/commands/update.d.ts +10 -0
  91. package/dist/cli/commands/update.js +36 -0
  92. package/dist/cli/commands/update.js.map +1 -1
  93. package/dist/cli/introspection-context.js +5 -0
  94. package/dist/cli/introspection-context.js.map +1 -1
  95. package/dist/cli/task-native-readiness.d.ts +3 -1
  96. package/dist/cli/task-native-readiness.js +28 -6
  97. package/dist/cli/task-native-readiness.js.map +1 -1
  98. package/dist/config.d.ts +106 -5
  99. package/dist/config.js +97 -18
  100. package/dist/config.js.map +1 -1
  101. package/dist/daemon/checkpoint-loop.d.ts +48 -0
  102. package/dist/daemon/checkpoint-loop.js +76 -0
  103. package/dist/daemon/checkpoint-loop.js.map +1 -0
  104. package/dist/daemon/creator.d.ts +1 -1
  105. package/dist/daemon/creator.js +7 -3
  106. package/dist/daemon/creator.js.map +1 -1
  107. package/dist/daemon/daemon.d.ts +19 -0
  108. package/dist/daemon/daemon.js +68 -1
  109. package/dist/daemon/daemon.js.map +1 -1
  110. package/dist/daemon/eviction-loop.d.ts +40 -0
  111. package/dist/daemon/eviction-loop.js +67 -0
  112. package/dist/daemon/eviction-loop.js.map +1 -0
  113. package/dist/daemon/jinn-claim-loop-wiring.d.ts +33 -0
  114. package/dist/daemon/jinn-claim-loop-wiring.js +40 -0
  115. package/dist/daemon/jinn-claim-loop-wiring.js.map +1 -0
  116. package/dist/daemon/jinn-claim-loop.d.ts +24 -17
  117. package/dist/daemon/jinn-claim-loop.js +77 -23
  118. package/dist/daemon/jinn-claim-loop.js.map +1 -1
  119. package/dist/daemon/skip-log-dedup.d.ts +69 -0
  120. package/dist/daemon/skip-log-dedup.js +106 -0
  121. package/dist/daemon/skip-log-dedup.js.map +1 -0
  122. package/dist/dashboard/assets/index-BUlE8F3Y.js +330 -0
  123. package/dist/dashboard/assets/index-blqc7eqq.css +32 -0
  124. package/dist/dashboard/index.html +2 -2
  125. package/dist/discovery/factory.d.ts +17 -5
  126. package/dist/discovery/factory.js +46 -18
  127. package/dist/discovery/factory.js.map +1 -1
  128. package/dist/discovery/http.js +142 -3
  129. package/dist/discovery/http.js.map +1 -1
  130. package/dist/discovery/onchain.d.ts +5 -0
  131. package/dist/discovery/onchain.js +407 -15
  132. package/dist/discovery/onchain.js.map +1 -1
  133. package/dist/discovery/types.d.ts +45 -1
  134. package/dist/discovery/types.js +8 -10
  135. package/dist/discovery/types.js.map +1 -1
  136. package/dist/discovery/with-fallback.d.ts +7 -0
  137. package/dist/discovery/with-fallback.js +10 -0
  138. package/dist/discovery/with-fallback.js.map +1 -1
  139. package/dist/earning/bootstrap.d.ts +92 -1
  140. package/dist/earning/bootstrap.js +203 -63
  141. package/dist/earning/bootstrap.js.map +1 -1
  142. package/dist/earning/contracts.d.ts +14 -0
  143. package/dist/earning/contracts.js +17 -5
  144. package/dist/earning/contracts.js.map +1 -1
  145. package/dist/earning/funding-plan.js +27 -18
  146. package/dist/earning/funding-plan.js.map +1 -1
  147. package/dist/earning/jinn-rewards.d.ts +46 -0
  148. package/dist/earning/jinn-rewards.js +32 -0
  149. package/dist/earning/jinn-rewards.js.map +1 -1
  150. package/dist/earning/safe-adapter.d.ts +2 -0
  151. package/dist/earning/safe-adapter.js +26 -12
  152. package/dist/earning/safe-adapter.js.map +1 -1
  153. package/dist/earning/store.d.ts +8 -0
  154. package/dist/earning/store.js.map +1 -1
  155. package/dist/earning/testnet-setup-migration.d.ts +12 -0
  156. package/dist/earning/testnet-setup-migration.js +27 -1
  157. package/dist/earning/testnet-setup-migration.js.map +1 -1
  158. package/dist/earning/types.d.ts +15 -0
  159. package/dist/erc8004/reputation.d.ts +8 -0
  160. package/dist/erc8004/reputation.js +22 -3
  161. package/dist/erc8004/reputation.js.map +1 -1
  162. package/dist/harnesses/cost-estimates.d.ts +145 -0
  163. package/dist/harnesses/cost-estimates.js +297 -0
  164. package/dist/harnesses/cost-estimates.js.map +1 -0
  165. package/dist/harnesses/engine/engine.d.ts +72 -0
  166. package/dist/harnesses/engine/engine.js +105 -8
  167. package/dist/harnesses/engine/engine.js.map +1 -1
  168. package/dist/harnesses/engine/persistence.d.ts +51 -1
  169. package/dist/harnesses/engine/persistence.js +118 -5
  170. package/dist/harnesses/engine/persistence.js.map +1 -1
  171. package/dist/harnesses/engine/work-dir-reaper.d.ts +65 -0
  172. package/dist/harnesses/engine/work-dir-reaper.js +100 -0
  173. package/dist/harnesses/engine/work-dir-reaper.js.map +1 -0
  174. package/dist/harnesses/impls/hermes-agent/adapter.js +40 -0
  175. package/dist/harnesses/impls/hermes-agent/adapter.js.map +1 -1
  176. package/dist/harnesses/impls/hermes-agent/bootstrap.d.ts +20 -0
  177. package/dist/harnesses/impls/hermes-agent/bootstrap.js +40 -6
  178. package/dist/harnesses/impls/hermes-agent/bootstrap.js.map +1 -1
  179. package/dist/harnesses/impls/hermes-agent/harness.d.ts +59 -1
  180. package/dist/harnesses/impls/hermes-agent/harness.js +104 -0
  181. package/dist/harnesses/impls/hermes-agent/harness.js.map +1 -1
  182. package/dist/harnesses/impls/index.d.ts +7 -0
  183. package/dist/harnesses/impls/index.js +16 -1
  184. package/dist/harnesses/impls/index.js.map +1 -1
  185. package/dist/harnesses/impls/learner/harness.d.ts +38 -4
  186. package/dist/harnesses/impls/learner/harness.js +96 -2
  187. package/dist/harnesses/impls/learner/harness.js.map +1 -1
  188. package/dist/harnesses/impls/learner/plugin-path.d.ts +0 -13
  189. package/dist/harnesses/impls/learner/plugin-path.js +35 -15
  190. package/dist/harnesses/impls/learner/plugin-path.js.map +1 -1
  191. package/dist/harnesses/impls/learner/types.d.ts +11 -0
  192. package/dist/harnesses/impls/stub.d.ts +58 -0
  193. package/dist/harnesses/impls/stub.js +89 -0
  194. package/dist/harnesses/impls/stub.js.map +1 -0
  195. package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.d.ts +69 -50
  196. package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.js +178 -93
  197. package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.js.map +1 -1
  198. package/dist/harnesses/impls/swe-rebench-v2-evaluator/harness.d.ts +12 -1
  199. package/dist/harnesses/impls/swe-rebench-v2-evaluator/harness.js +121 -7
  200. package/dist/harnesses/impls/swe-rebench-v2-evaluator/harness.js.map +1 -1
  201. package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.d.ts +15 -0
  202. package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.js +54 -4
  203. package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.js.map +1 -1
  204. package/dist/harnesses/impls/swe-rebench-v2-evaluator/index.d.ts +6 -0
  205. package/dist/harnesses/impls/swe-rebench-v2-evaluator/index.js +1 -1
  206. package/dist/harnesses/impls/swe-rebench-v2-evaluator/index.js.map +1 -1
  207. package/dist/harnesses/readiness-registry.js +9 -1
  208. package/dist/harnesses/readiness-registry.js.map +1 -1
  209. package/dist/main.js +371 -82
  210. package/dist/main.js.map +1 -1
  211. package/dist/observability/emit-event.d.ts +1 -1
  212. package/dist/observability/emit-event.js.map +1 -1
  213. package/dist/operator-errors.d.ts +7 -0
  214. package/dist/operator-errors.js +13 -1
  215. package/dist/operator-errors.js.map +1 -1
  216. package/dist/plugins/learner/.claude-plugin/plugin.json +9 -0
  217. package/dist/plugins/learner/.codex-plugin/plugin.json +39 -0
  218. package/dist/plugins/learner/AGENTS.md +40 -0
  219. package/dist/plugins/learner/CLAUDE.md +33 -0
  220. package/dist/plugins/learner/README.md +59 -0
  221. package/dist/plugins/learner/hooks/hooks.json +16 -0
  222. package/dist/plugins/learner/hooks/session-start +38 -0
  223. package/dist/plugins/learner/skills/learn/SKILL.md +412 -0
  224. package/dist/plugins/learner/skills/learn/analyst-prompt.md +68 -0
  225. package/dist/plugins/learner/skills/learn/consolidator-prompt.md +94 -0
  226. package/dist/plugins/learner/skills/learn/explorer-prompt.md +53 -0
  227. package/dist/plugins/learner/skills/learn/planner-prompt.md +87 -0
  228. package/dist/plugins/learner/skills/learn/promoter-prompt.md +113 -0
  229. package/dist/plugins/learner/skills/learn/step-worker-prompt.md +47 -0
  230. package/dist/plugins/learner/skills/learn/strategist-prompt.md +85 -0
  231. package/dist/restart-daemon.d.ts +90 -0
  232. package/dist/restart-daemon.js +95 -0
  233. package/dist/restart-daemon.js.map +1 -0
  234. package/dist/setup/halt-mode.d.ts +14 -0
  235. package/dist/setup/halt-mode.js +17 -0
  236. package/dist/setup/halt-mode.js.map +1 -0
  237. package/dist/solver-nets/prediction-operator-ux.js +43 -3
  238. package/dist/solver-nets/prediction-operator-ux.js.map +1 -1
  239. package/dist/solver-nets/registry.d.ts +1 -0
  240. package/dist/solver-nets/registry.js +1 -1
  241. package/dist/solver-nets/registry.js.map +1 -1
  242. package/dist/solver-types/_swe-rebench-v2-pool-cache.d.ts +58 -0
  243. package/dist/solver-types/_swe-rebench-v2-pool-cache.js +87 -0
  244. package/dist/solver-types/_swe-rebench-v2-pool-cache.js.map +1 -0
  245. package/dist/solver-types/_swe-rebench-v2-substrate.d.ts +1 -0
  246. package/dist/solver-types/_swe-rebench-v2-substrate.js +10 -0
  247. package/dist/solver-types/_swe-rebench-v2-substrate.js.map +1 -1
  248. package/dist/solver-types/_swe-rebench-v2-validated-pool.d.ts +65 -0
  249. package/dist/solver-types/_swe-rebench-v2-validated-pool.js +243 -26
  250. package/dist/solver-types/_swe-rebench-v2-validated-pool.js.map +1 -1
  251. package/dist/solver-types/swe-rebench-v2-auto.d.ts +22 -7
  252. package/dist/solver-types/swe-rebench-v2-auto.js +45 -20
  253. package/dist/solver-types/swe-rebench-v2-auto.js.map +1 -1
  254. package/dist/solver-types/swe-rebench-v2.d.ts +13 -2
  255. package/dist/solver-types/swe-rebench-v2.js +233 -94
  256. package/dist/solver-types/swe-rebench-v2.js.map +1 -1
  257. package/dist/solvernets/daemon-init.d.ts +10 -2
  258. package/dist/solvernets/daemon-init.js +22 -2
  259. package/dist/solvernets/daemon-init.js.map +1 -1
  260. package/dist/solvernets/launched-record-dispatcher.js +35 -7
  261. package/dist/solvernets/launched-record-dispatcher.js.map +1 -1
  262. package/dist/solvernets/store.d.ts +5 -0
  263. package/dist/solvernets/store.js +1 -0
  264. package/dist/solvernets/store.js.map +1 -1
  265. package/dist/store/store.d.ts +15 -0
  266. package/dist/store/store.js +118 -3
  267. package/dist/store/store.js.map +1 -1
  268. package/dist/tasks/sources.d.ts +18 -1
  269. package/dist/tasks/sources.js +33 -5
  270. package/dist/tasks/sources.js.map +1 -1
  271. package/dist/tx-retry.d.ts +151 -19
  272. package/dist/tx-retry.js +286 -32
  273. package/dist/tx-retry.js.map +1 -1
  274. package/dist/types/payloads/prediction-apy-v0.d.ts +5 -5
  275. package/dist/types/payloads/prediction-v0.d.ts +5 -5
  276. package/dist/types/task-document.d.ts +392 -0
  277. package/dist/types/task-document.js +10 -0
  278. package/dist/types/task-document.js.map +1 -1
  279. package/dist/types/task.d.ts +28 -0
  280. package/dist/util/extract-tx-hash.d.ts +14 -0
  281. package/dist/util/extract-tx-hash.js +19 -0
  282. package/dist/util/extract-tx-hash.js.map +1 -0
  283. package/dist/vendor/@jinn-network/sdk/dist/contracts.js +1 -1
  284. package/dist/vendor/@jinn-network/sdk/dist/solvernets/manifest-schema.d.ts +3 -0
  285. package/dist/vendor/@jinn-network/sdk/dist/solvernets/manifest-schema.js +1 -0
  286. package/package.json +29 -12
  287. package/dist/dashboard/assets/index-DOlzFN8a.css +0 -32
  288. package/dist/dashboard/assets/index-NkZ7CTAT.js +0 -140
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Per-task cost estimates for paid-API-key harnesses.
3
+ *
4
+ * Background — Issue #331 (Run-mode `feat`, P0 tier under release-feedback
5
+ * umbrella #328). The operator dashboard surfaces a harness/model selection
6
+ * at SolverNet-join time and again in Settings. Operators routing a paid
7
+ * API key (Anthropic, OpenAI, OpenRouter, Nous Portal) through the Hermes
8
+ * harness — or a "raw API key" Claude Code variant if we ever add one —
9
+ * have **no UI nudge** at join-time about per-task cost. The v0.1.6 dogfood
10
+ * surfaced the concrete worry: a first-run operator could pick Opus 4.7 +
11
+ * SWE-rebench v2 and burn $100s/hr before they figure out what Jinn does.
12
+ *
13
+ * This module captures the heuristic the SPA uses to render that estimate
14
+ * and to gate the Save & Join action when the estimate exceeds a
15
+ * configurable per-task threshold (default $1).
16
+ *
17
+ * Heuristic shape per the spec:
18
+ * per-1k-token rate × typical task length, by model id.
19
+ *
20
+ * Subscription harnesses (Claude Code, Codex) are flagged via
21
+ * `subscriptionPath: true` on the harness; in that case the surface shows
22
+ * "Included in subscription, no per-task API cost" and **does not** trigger
23
+ * the confirmation gate, regardless of the model selected.
24
+ *
25
+ * To add a new model: append an entry to `MODEL_COST_TABLE`. The id is the
26
+ * exact `model` string persisted to `joinedSolverNets[<cid>].model`. To
27
+ * shape a new harness: append to `HARNESS_BILLING`. Keep the units
28
+ * consistent: token counts in tokens, rates in USD-per-1k-tokens.
29
+ *
30
+ * Units note: Anthropic + OpenAI publish prices per million tokens; we
31
+ * convert to per-1k-tokens here so the multiplication reads as
32
+ * `(tokens / 1000) * pricePer1k`. Avoids floating-point surprises when the
33
+ * dashboard renders cents.
34
+ *
35
+ * Pricing references captured at the time of this commit (see PR body):
36
+ * - Anthropic Claude Opus 4.7: $15/M input, $75/M output (≈ $0.015 / 1k
37
+ * input, $0.075 / 1k output). Typical SWE-rebench v2 task estimated at
38
+ * ~50k input + 20k output → ~$2.25/task. Anthropic public pricing.
39
+ * - Anthropic Claude Sonnet 4.6: $3/M input, $15/M output.
40
+ * - OpenAI GPT-5.4: $1.25/M input, $10/M output (OpenAI public pricing).
41
+ * - OpenAI GPT-5.4 Mini: $0.25/M input, $2/M output.
42
+ *
43
+ * These are heuristics. Provider-API reconciliation (actual usage) is
44
+ * deferred to the P1 follow-up tracked in #331.
45
+ */
46
+ export type Provider = 'anthropic' | 'openai' | 'openrouter' | 'nous' | 'other';
47
+ export interface ModelCostEntry {
48
+ /** Upstream API provider that owns the billing relationship. */
49
+ provider: Provider;
50
+ /** USD per 1k input tokens. */
51
+ inputPer1kTokens: number;
52
+ /** USD per 1k output tokens. */
53
+ outputPer1kTokens: number;
54
+ /** Typical input-token consumption for a single task. Heuristic. */
55
+ typicalInputTokens: number;
56
+ /** Typical output-token consumption for a single task. Heuristic. */
57
+ typicalOutputTokens: number;
58
+ /**
59
+ * `true` when this model id is only ever reached via a subscription path
60
+ * (e.g. a future "Claude Code subscription" pinned model). The default
61
+ * gate logic prefers the harness-level flag — this exists so an
62
+ * individual model entry can override it on a per-id basis.
63
+ */
64
+ subscriptionPath?: boolean;
65
+ }
66
+ /**
67
+ * Per-model cost entries. Keyed by the exact `model` id persisted to
68
+ * `joinedSolverNets[<cid>].model`. The dashboard model dropdown in
69
+ * `claudeModels.ts` is the source of truth for which ids appear here.
70
+ */
71
+ export declare const MODEL_COST_TABLE: Readonly<Record<string, ModelCostEntry>>;
72
+ /**
73
+ * Harness-level billing classification.
74
+ *
75
+ * `subscriptionPath: true` means the harness shells out to a
76
+ * subscription-billed CLI (Claude Code, Codex) and the operator does NOT
77
+ * incur per-task API charges — the cost surface is suppressed entirely
78
+ * and the confirmation gate is never triggered.
79
+ *
80
+ * `subscriptionPath: false` means the harness routes to a paid API key
81
+ * (Hermes via OpenRouter / Anthropic API / Nous Portal). The cost surface
82
+ * is shown and the gate fires above the configured threshold.
83
+ */
84
+ export declare const HARNESS_BILLING: Readonly<Record<string, {
85
+ subscriptionPath: boolean;
86
+ }>>;
87
+ /** Default per-task USD threshold above which the confirmation gate fires. */
88
+ export declare const DEFAULT_HIGH_COST_THRESHOLD_USD = 1;
89
+ export interface CostEstimate {
90
+ /** Estimated per-task cost in USD. */
91
+ usd: number;
92
+ /** Computed input cost in USD. */
93
+ inputUsd: number;
94
+ /** Computed output cost in USD. */
95
+ outputUsd: number;
96
+ /** Heuristic typical input tokens used. */
97
+ typicalInputTokens: number;
98
+ /** Heuristic typical output tokens used. */
99
+ typicalOutputTokens: number;
100
+ /** Underlying entry consulted. */
101
+ entry: ModelCostEntry;
102
+ }
103
+ /**
104
+ * Compute the per-task cost estimate for a given model id. Returns `null`
105
+ * when the id has no entry in `MODEL_COST_TABLE` — callers should treat
106
+ * that as "unknown, don't surface a number" rather than rendering $0.
107
+ */
108
+ export declare function estimateModelCost(modelId: string): CostEstimate | null;
109
+ /**
110
+ * `true` when the harness routes through a paid API key. Subscription
111
+ * harnesses (Claude Code, Codex) return `false`; unknown harnesses
112
+ * conservatively return `true` so a misnamed harness doesn't silently
113
+ * skip the cost surface.
114
+ */
115
+ export declare function harnessUsesPaidApiKey(harness: string | undefined): boolean;
116
+ export interface CostSurfaceDecision {
117
+ /** Whether to show a numeric cost-per-task estimate at all. */
118
+ showEstimate: boolean;
119
+ /** Resolved estimate (may be `null` even when `showEstimate` is true if the model id is unknown). */
120
+ estimate: CostEstimate | null;
121
+ /** Whether the Save & Join action requires the high-cost confirmation. */
122
+ requiresConfirmation: boolean;
123
+ /**
124
+ * Human-readable reason the surface is suppressed when `showEstimate`
125
+ * is false — e.g. "Included in subscription, no per-task API cost".
126
+ * `null` when the surface is shown.
127
+ */
128
+ suppressedReason: string | null;
129
+ }
130
+ /**
131
+ * Decide what the cost surface should render for a given harness + model
132
+ * combination, plus whether the confirmation gate fires.
133
+ *
134
+ * Defaults:
135
+ * - threshold: $1 / task (see DEFAULT_HIGH_COST_THRESHOLD_USD).
136
+ * - subscription harness → suppress surface + skip gate.
137
+ * - unknown model on a paid harness → show estimate slot (caller may
138
+ * render "estimate unavailable") but DO NOT trigger the gate.
139
+ */
140
+ export declare function decideCostSurface(harness: string | undefined, modelId: string | undefined, thresholdUsd?: number): CostSurfaceDecision;
141
+ /**
142
+ * Format a USD amount for compact display in the dashboard. Picks the
143
+ * smallest fraction count that still distinguishes the value from $0.
144
+ */
145
+ export declare function formatUsd(amount: number): string;
@@ -0,0 +1,297 @@
1
+ /**
2
+ * Per-task cost estimates for paid-API-key harnesses.
3
+ *
4
+ * Background — Issue #331 (Run-mode `feat`, P0 tier under release-feedback
5
+ * umbrella #328). The operator dashboard surfaces a harness/model selection
6
+ * at SolverNet-join time and again in Settings. Operators routing a paid
7
+ * API key (Anthropic, OpenAI, OpenRouter, Nous Portal) through the Hermes
8
+ * harness — or a "raw API key" Claude Code variant if we ever add one —
9
+ * have **no UI nudge** at join-time about per-task cost. The v0.1.6 dogfood
10
+ * surfaced the concrete worry: a first-run operator could pick Opus 4.7 +
11
+ * SWE-rebench v2 and burn $100s/hr before they figure out what Jinn does.
12
+ *
13
+ * This module captures the heuristic the SPA uses to render that estimate
14
+ * and to gate the Save & Join action when the estimate exceeds a
15
+ * configurable per-task threshold (default $1).
16
+ *
17
+ * Heuristic shape per the spec:
18
+ * per-1k-token rate × typical task length, by model id.
19
+ *
20
+ * Subscription harnesses (Claude Code, Codex) are flagged via
21
+ * `subscriptionPath: true` on the harness; in that case the surface shows
22
+ * "Included in subscription, no per-task API cost" and **does not** trigger
23
+ * the confirmation gate, regardless of the model selected.
24
+ *
25
+ * To add a new model: append an entry to `MODEL_COST_TABLE`. The id is the
26
+ * exact `model` string persisted to `joinedSolverNets[<cid>].model`. To
27
+ * shape a new harness: append to `HARNESS_BILLING`. Keep the units
28
+ * consistent: token counts in tokens, rates in USD-per-1k-tokens.
29
+ *
30
+ * Units note: Anthropic + OpenAI publish prices per million tokens; we
31
+ * convert to per-1k-tokens here so the multiplication reads as
32
+ * `(tokens / 1000) * pricePer1k`. Avoids floating-point surprises when the
33
+ * dashboard renders cents.
34
+ *
35
+ * Pricing references captured at the time of this commit (see PR body):
36
+ * - Anthropic Claude Opus 4.7: $15/M input, $75/M output (≈ $0.015 / 1k
37
+ * input, $0.075 / 1k output). Typical SWE-rebench v2 task estimated at
38
+ * ~50k input + 20k output → ~$2.25/task. Anthropic public pricing.
39
+ * - Anthropic Claude Sonnet 4.6: $3/M input, $15/M output.
40
+ * - OpenAI GPT-5.4: $1.25/M input, $10/M output (OpenAI public pricing).
41
+ * - OpenAI GPT-5.4 Mini: $0.25/M input, $2/M output.
42
+ *
43
+ * These are heuristics. Provider-API reconciliation (actual usage) is
44
+ * deferred to the P1 follow-up tracked in #331.
45
+ */
46
+ import { CLAUDE_CODE_HARNESS, CODEX_HARNESS, HERMES_AGENT_HARNESS, canonicalHarnessName, } from './names.js';
47
+ /**
48
+ * Per-model cost entries. Keyed by the exact `model` id persisted to
49
+ * `joinedSolverNets[<cid>].model`. The dashboard model dropdown in
50
+ * `claudeModels.ts` is the source of truth for which ids appear here.
51
+ */
52
+ export const MODEL_COST_TABLE = {
53
+ // ---------- Anthropic family (direct + via OpenRouter) ----------
54
+ 'claude-opus-4-7': {
55
+ provider: 'anthropic',
56
+ inputPer1kTokens: 0.015,
57
+ outputPer1kTokens: 0.075,
58
+ typicalInputTokens: 50_000,
59
+ typicalOutputTokens: 20_000,
60
+ },
61
+ 'claude-sonnet-4-6': {
62
+ provider: 'anthropic',
63
+ inputPer1kTokens: 0.003,
64
+ outputPer1kTokens: 0.015,
65
+ typicalInputTokens: 50_000,
66
+ typicalOutputTokens: 20_000,
67
+ },
68
+ 'claude-haiku-4-5-20251001': {
69
+ provider: 'anthropic',
70
+ inputPer1kTokens: 0.001,
71
+ outputPer1kTokens: 0.005,
72
+ typicalInputTokens: 50_000,
73
+ typicalOutputTokens: 20_000,
74
+ },
75
+ // OpenRouter routing of the same families (Hermes harness uses these).
76
+ 'anthropic/claude-opus-4.7': {
77
+ provider: 'openrouter',
78
+ inputPer1kTokens: 0.015,
79
+ outputPer1kTokens: 0.075,
80
+ typicalInputTokens: 50_000,
81
+ typicalOutputTokens: 20_000,
82
+ },
83
+ 'anthropic/claude-sonnet-4.6': {
84
+ provider: 'openrouter',
85
+ inputPer1kTokens: 0.003,
86
+ outputPer1kTokens: 0.015,
87
+ typicalInputTokens: 50_000,
88
+ typicalOutputTokens: 20_000,
89
+ },
90
+ // ---------- OpenAI family ----------
91
+ 'gpt-5.4': {
92
+ provider: 'openai',
93
+ inputPer1kTokens: 0.00125,
94
+ outputPer1kTokens: 0.01,
95
+ typicalInputTokens: 50_000,
96
+ typicalOutputTokens: 20_000,
97
+ },
98
+ 'gpt-5.4-mini': {
99
+ provider: 'openai',
100
+ inputPer1kTokens: 0.00025,
101
+ outputPer1kTokens: 0.002,
102
+ typicalInputTokens: 50_000,
103
+ typicalOutputTokens: 20_000,
104
+ },
105
+ 'gpt-5.5': {
106
+ provider: 'openai',
107
+ // Newer flagship; public pricing not confirmed at heuristic-capture
108
+ // time, so use Opus-4.7-class rates as a conservative upper bound
109
+ // until we get a verified figure.
110
+ inputPer1kTokens: 0.015,
111
+ outputPer1kTokens: 0.06,
112
+ typicalInputTokens: 50_000,
113
+ typicalOutputTokens: 20_000,
114
+ },
115
+ 'gpt-5.3-codex': {
116
+ provider: 'openai',
117
+ inputPer1kTokens: 0.00125,
118
+ outputPer1kTokens: 0.01,
119
+ typicalInputTokens: 50_000,
120
+ typicalOutputTokens: 20_000,
121
+ },
122
+ 'gpt-5.3-codex-spark': {
123
+ provider: 'openai',
124
+ inputPer1kTokens: 0.00125,
125
+ outputPer1kTokens: 0.01,
126
+ typicalInputTokens: 50_000,
127
+ typicalOutputTokens: 20_000,
128
+ },
129
+ // ---------- OpenRouter long-tail (Hermes) ----------
130
+ // These rates are coarse — OpenRouter's effective price depends on the
131
+ // route picked. We pick the published list-price upper bound so the
132
+ // estimate biases toward over-warning rather than under-warning.
133
+ 'tencent/hy3-preview': {
134
+ provider: 'openrouter',
135
+ inputPer1kTokens: 0.003,
136
+ outputPer1kTokens: 0.015,
137
+ typicalInputTokens: 50_000,
138
+ typicalOutputTokens: 20_000,
139
+ },
140
+ 'deepseek/deepseek-v4-pro': {
141
+ provider: 'openrouter',
142
+ inputPer1kTokens: 0.0014,
143
+ outputPer1kTokens: 0.0028,
144
+ typicalInputTokens: 50_000,
145
+ typicalOutputTokens: 20_000,
146
+ },
147
+ 'deepseek/deepseek-v4-flash': {
148
+ provider: 'openrouter',
149
+ inputPer1kTokens: 0.0001,
150
+ outputPer1kTokens: 0.0004,
151
+ typicalInputTokens: 50_000,
152
+ typicalOutputTokens: 20_000,
153
+ },
154
+ 'google/gemini-3.1-flash-lite': {
155
+ provider: 'openrouter',
156
+ inputPer1kTokens: 0.0001,
157
+ outputPer1kTokens: 0.0004,
158
+ typicalInputTokens: 50_000,
159
+ typicalOutputTokens: 20_000,
160
+ },
161
+ 'moonshotai/kimi-k2.6': {
162
+ provider: 'openrouter',
163
+ inputPer1kTokens: 0.0006,
164
+ outputPer1kTokens: 0.0025,
165
+ typicalInputTokens: 50_000,
166
+ typicalOutputTokens: 20_000,
167
+ },
168
+ 'openrouter/owl-alpha': {
169
+ provider: 'openrouter',
170
+ inputPer1kTokens: 0.002,
171
+ outputPer1kTokens: 0.008,
172
+ typicalInputTokens: 50_000,
173
+ typicalOutputTokens: 20_000,
174
+ },
175
+ 'minimax/minimax-m2.7': {
176
+ provider: 'openrouter',
177
+ inputPer1kTokens: 0.0008,
178
+ outputPer1kTokens: 0.0032,
179
+ typicalInputTokens: 50_000,
180
+ typicalOutputTokens: 20_000,
181
+ },
182
+ 'nousresearch/hermes-4-405b': {
183
+ provider: 'nous',
184
+ inputPer1kTokens: 0.0009,
185
+ outputPer1kTokens: 0.0009,
186
+ typicalInputTokens: 50_000,
187
+ typicalOutputTokens: 20_000,
188
+ },
189
+ };
190
+ /**
191
+ * Harness-level billing classification.
192
+ *
193
+ * `subscriptionPath: true` means the harness shells out to a
194
+ * subscription-billed CLI (Claude Code, Codex) and the operator does NOT
195
+ * incur per-task API charges — the cost surface is suppressed entirely
196
+ * and the confirmation gate is never triggered.
197
+ *
198
+ * `subscriptionPath: false` means the harness routes to a paid API key
199
+ * (Hermes via OpenRouter / Anthropic API / Nous Portal). The cost surface
200
+ * is shown and the gate fires above the configured threshold.
201
+ */
202
+ export const HARNESS_BILLING = {
203
+ [CLAUDE_CODE_HARNESS]: { subscriptionPath: true },
204
+ [CODEX_HARNESS]: { subscriptionPath: true },
205
+ [HERMES_AGENT_HARNESS]: { subscriptionPath: false },
206
+ };
207
+ /** Default per-task USD threshold above which the confirmation gate fires. */
208
+ export const DEFAULT_HIGH_COST_THRESHOLD_USD = 1;
209
+ /**
210
+ * Compute the per-task cost estimate for a given model id. Returns `null`
211
+ * when the id has no entry in `MODEL_COST_TABLE` — callers should treat
212
+ * that as "unknown, don't surface a number" rather than rendering $0.
213
+ */
214
+ export function estimateModelCost(modelId) {
215
+ const entry = MODEL_COST_TABLE[modelId];
216
+ if (!entry)
217
+ return null;
218
+ const inputUsd = (entry.typicalInputTokens / 1000) * entry.inputPer1kTokens;
219
+ const outputUsd = (entry.typicalOutputTokens / 1000) * entry.outputPer1kTokens;
220
+ return {
221
+ usd: inputUsd + outputUsd,
222
+ inputUsd,
223
+ outputUsd,
224
+ typicalInputTokens: entry.typicalInputTokens,
225
+ typicalOutputTokens: entry.typicalOutputTokens,
226
+ entry,
227
+ };
228
+ }
229
+ /**
230
+ * `true` when the harness routes through a paid API key. Subscription
231
+ * harnesses (Claude Code, Codex) return `false`; unknown harnesses
232
+ * conservatively return `true` so a misnamed harness doesn't silently
233
+ * skip the cost surface.
234
+ */
235
+ export function harnessUsesPaidApiKey(harness) {
236
+ if (!harness)
237
+ return false;
238
+ const canonical = canonicalHarnessName(harness);
239
+ const billing = HARNESS_BILLING[canonical];
240
+ if (!billing)
241
+ return true;
242
+ return !billing.subscriptionPath;
243
+ }
244
+ /**
245
+ * Decide what the cost surface should render for a given harness + model
246
+ * combination, plus whether the confirmation gate fires.
247
+ *
248
+ * Defaults:
249
+ * - threshold: $1 / task (see DEFAULT_HIGH_COST_THRESHOLD_USD).
250
+ * - subscription harness → suppress surface + skip gate.
251
+ * - unknown model on a paid harness → show estimate slot (caller may
252
+ * render "estimate unavailable") but DO NOT trigger the gate.
253
+ */
254
+ export function decideCostSurface(harness, modelId, thresholdUsd = DEFAULT_HIGH_COST_THRESHOLD_USD) {
255
+ if (!harnessUsesPaidApiKey(harness)) {
256
+ return {
257
+ showEstimate: false,
258
+ estimate: null,
259
+ requiresConfirmation: false,
260
+ suppressedReason: 'Included in subscription, no per-task API cost.',
261
+ };
262
+ }
263
+ const estimate = modelId ? estimateModelCost(modelId) : null;
264
+ const modelOverridesSubscription = estimate?.entry.subscriptionPath === true;
265
+ if (modelOverridesSubscription) {
266
+ return {
267
+ showEstimate: false,
268
+ estimate: null,
269
+ requiresConfirmation: false,
270
+ suppressedReason: 'Included in subscription, no per-task API cost.',
271
+ };
272
+ }
273
+ return {
274
+ showEstimate: true,
275
+ estimate,
276
+ requiresConfirmation: estimate !== null && estimate.usd > thresholdUsd,
277
+ suppressedReason: null,
278
+ };
279
+ }
280
+ /**
281
+ * Format a USD amount for compact display in the dashboard. Picks the
282
+ * smallest fraction count that still distinguishes the value from $0.
283
+ */
284
+ export function formatUsd(amount) {
285
+ if (!Number.isFinite(amount))
286
+ return '—';
287
+ if (amount === 0)
288
+ return '$0';
289
+ if (amount < 0.01)
290
+ return `<$0.01`;
291
+ if (amount < 1)
292
+ return `$${amount.toFixed(2)}`;
293
+ if (amount < 10)
294
+ return `$${amount.toFixed(2)}`;
295
+ return `$${amount.toFixed(2)}`;
296
+ }
297
+ //# sourceMappingURL=cost-estimates.js.map
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,CAAC;IAC7D,MAAM,0BAA0B,GAC9B,QAAQ,EAAE,KAAK,CAAC,gBAAgB,KAAK,IAAI,CAAC;IAC5C,IAAI,0BAA0B,EAAE,CAAC;QAC/B,OAAO;YACL,YAAY,EAAE,KAAK;YACnB,QAAQ,EAAE,IAAI;YACd,oBAAoB,EAAE,KAAK;YAC3B,gBAAgB,EAAE,iDAAiD;SACpE,CAAC;IACJ,CAAC;IACD,OAAO;QACL,YAAY,EAAE,IAAI;QAClB,QAAQ;QACR,oBAAoB,EAAE,QAAQ,KAAK,IAAI,IAAI,QAAQ,CAAC,GAAG,GAAG,YAAY;QACtE,gBAAgB,EAAE,IAAI;KACvB,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,MAAc;IACtC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,GAAG,CAAC;IACzC,IAAI,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAC9B,IAAI,MAAM,GAAG,IAAI;QAAE,OAAO,QAAQ,CAAC;IACnC,IAAI,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/C,IAAI,MAAM,GAAG,EAAE;QAAE,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAChD,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;AACjC,CAAC"}
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import { TaskRunPersistence, type PersistedTaskRun, type PersistedTaskRunInput } from './persistence.js';
10
10
  import type { Store } from '../../store/store.js';
11
+ import { type ReapWorkDirsReport } from './work-dir-reaper.js';
11
12
  import { type PackagingDeps } from './packaging.js';
12
13
  import { type EnvelopeAssemblyDeps } from './envelope-assembly.js';
13
14
  import { type DeliveryDeps } from './delivery.js';
@@ -240,6 +241,28 @@ export interface TaskEngineOptions {
240
241
  * Spec: docs/superpowers/specs/2026-05-06-agent-harness-solvernet-design.md §6.3
241
242
  */
242
243
  harnessMode?: 'train' | 'frozen';
244
+ /**
245
+ * Working-directory reaper tuning (issue #320). Each task run provisions a
246
+ * heavy scratch directory under `paths.workingDirRoot`; without cleanup an
247
+ * operator accumulates hundreds of dirs / tens of GB. The engine reaps a
248
+ * task's directory once it reaches a terminal state (COMPLETE / FAILED),
249
+ * and periodically sweeps the root for crash-orphaned dirs.
250
+ *
251
+ * Optional — sensible defaults apply when absent.
252
+ */
253
+ workDirReaper?: {
254
+ /**
255
+ * Age above which a directory with no DB row (orphaned by a crash or an
256
+ * older daemon) is removed. Defaults to {@link DEFAULT_ORPHAN_MAX_AGE_MS}
257
+ * (24h). Set to a large value to keep orphans for forensic inspection.
258
+ */
259
+ orphanMaxAgeMs?: number;
260
+ /**
261
+ * Disable the reaper entirely (escape hatch for debugging a stuck task).
262
+ * Defaults to false — the reaper runs.
263
+ */
264
+ disabled?: boolean;
265
+ };
243
266
  }
244
267
  /** Per-task outcome from a recovery pass. */
245
268
  export interface RecoveryReport {
@@ -289,12 +312,38 @@ export declare class TaskEngine {
289
312
  private stopped;
290
313
  private stopResolve?;
291
314
  private readonly stopPromise;
315
+ /** Working-dir reaper tuning (issue #320). */
316
+ protected readonly workDirReaperOpts: {
317
+ orphanMaxAgeMs: number;
318
+ disabled: boolean;
319
+ };
292
320
  constructor(opts: TaskEngineOptions);
293
321
  /**
294
322
  * Called when an task is observed from an on-chain event.
295
323
  * Persists a DISCOVERED row. Idempotent: if the row already exists, no-op.
296
324
  */
297
325
  observe(input: PersistedTaskRunInput): Promise<void>;
326
+ /**
327
+ * Pre-claim acceptance check used by the daemon's engine-watcher loop.
328
+ *
329
+ * Performance contract (issue #398): this runs once per task announcement,
330
+ * on the engine-watcher hot path, for every observed task. It MUST NOT
331
+ * perform per-task blocking I/O. In particular it does not probe
332
+ * `impl.isReady()` — for the Hermes harness that runs two blocking
333
+ * `spawnSync` child processes, so a backlog would pay per-task blocking
334
+ * spawns and starve the daemon event loop.
335
+ *
336
+ * Harness readiness for the claim gate is instead served O(1) from the
337
+ * daemon's cached `HarnessReadinessRegistry` snapshot: the engine-watcher
338
+ * loop calls `gateClaimByReadiness(...)` immediately after `canAcceptTask`
339
+ * returns. A ~tickIntervalMs-stale snapshot is acceptable — harness
340
+ * readiness changes on a minutes scale (auth/config) and the daemon
341
+ * already trusts that cached registry for its post-`canAcceptTask` gate.
342
+ *
343
+ * `claim()` (the DISCOVERED → CLAIMED transition) still probes
344
+ * `impl.isReady()` directly — it runs once per claimed task, not per
345
+ * announcement, and is the authoritative pre-execution gate.
346
+ */
298
347
  canAcceptTask(input: {
299
348
  solverType?: string;
300
349
  taskRole?: 'restoration' | 'evaluation';
@@ -320,6 +369,18 @@ export declare class TaskEngine {
320
369
  * Errors from individual tasks are logged but do not stop the loop.
321
370
  */
322
371
  tick(options?: TickOptions): Promise<void>;
372
+ /**
373
+ * Reap on-disk per-task working directories (issue #320).
374
+ *
375
+ * Removes the scratch directory of every task in a terminal state
376
+ * (COMPLETE / FAILED) and any crash-orphaned directory older than the
377
+ * configured max age. In-flight tasks are never touched. Safe to call at
378
+ * any time; never throws (filesystem errors are collected into the report).
379
+ *
380
+ * Called automatically every `tick()`; also exposed for the one-shot
381
+ * cleanup script and for tests.
382
+ */
383
+ reapWorkDirsNow(): ReapWorkDirsReport;
323
384
  /**
324
385
  * Drive `tick()` on a fixed interval until `stop()` is called.
325
386
  * Errors thrown by tick() itself are logged and do not stop the loop.
@@ -390,6 +451,17 @@ export declare class TaskEngine {
390
451
  * `task` non-null.
391
452
  */
392
453
  private evaluateJoinedEligibility;
454
+ /**
455
+ * Shared eligibility evaluation behind both `canAcceptTask` and `claim`.
456
+ *
457
+ * `opts.skipReadinessProbe` (issue #398): when true, the per-task
458
+ * `impl.isReady()` probe is skipped. The engine-watcher's `canAcceptTask`
459
+ * sets this — it relies on the daemon's cached `HarnessReadinessRegistry`
460
+ * (via `gateClaimByReadiness`) for the readiness gate instead of a
461
+ * blocking per-announcement probe. `claim()` leaves it false so the
462
+ * DISCOVERED → CLAIMED transition still runs the authoritative readiness
463
+ * probe (once per claimed task, not per announcement).
464
+ */
393
465
  private runnableFailureReason;
394
466
  /**
395
467
  * PRE_SNAPSHOT transition: provision workingDir + implStateDir, write