@jinn-network/client 0.1.2 → 0.1.3-canary.12cf8b76

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 (1266) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/CONTRIBUTING.md +8 -2
  3. package/README.md +67 -47
  4. package/deployments/deployment-jinn-mvi-l1-sepolia-fast.json +36 -0
  5. package/deployments/deployment-jinn-mvi-l1-sepolia.json +36 -0
  6. package/deployments/deployment-jinn-mvi-l2-baseSepolia.json +12 -0
  7. package/deployments/deployment-phase1b-mech-baseSepolia-fast.json +3 -3
  8. package/deployments/deployment-stolas-l2-baseSepolia-fast.json +1 -1
  9. package/deployments/deployment-task-coordinator-router-v3-baseSepolia-fast.json +38 -0
  10. package/dist/adapters/adapter.d.ts +19 -8
  11. package/dist/adapters/local/adapter.d.ts +10 -9
  12. package/dist/adapters/local/adapter.js +52 -79
  13. package/dist/adapters/local/adapter.js.map +1 -1
  14. package/dist/adapters/mech/adapter.d.ts +33 -15
  15. package/dist/adapters/mech/adapter.js +471 -353
  16. package/dist/adapters/mech/adapter.js.map +1 -1
  17. package/dist/adapters/mech/contracts.d.ts +68 -20
  18. package/dist/adapters/mech/contracts.js +338 -100
  19. package/dist/adapters/mech/contracts.js.map +1 -1
  20. package/dist/adapters/mech/ipfs.d.ts +66 -12
  21. package/dist/adapters/mech/ipfs.js +165 -30
  22. package/dist/adapters/mech/ipfs.js.map +1 -1
  23. package/dist/adapters/mech/safe-revert.d.ts +39 -0
  24. package/dist/adapters/mech/safe-revert.js +124 -0
  25. package/dist/adapters/mech/safe-revert.js.map +1 -0
  26. package/dist/adapters/mech/safe.js +48 -22
  27. package/dist/adapters/mech/safe.js.map +1 -1
  28. package/dist/adapters/mech/types.d.ts +245 -84
  29. package/dist/adapters/mech/types.js +125 -50
  30. package/dist/adapters/mech/types.js.map +1 -1
  31. package/dist/agent/agent-ws.d.ts +57 -0
  32. package/dist/agent/agent-ws.js +301 -0
  33. package/dist/agent/agent-ws.js.map +1 -0
  34. package/dist/agent/auto-mode-detect.d.ts +6 -0
  35. package/dist/agent/auto-mode-detect.js +44 -0
  36. package/dist/agent/auto-mode-detect.js.map +1 -0
  37. package/dist/agent/operator-claude.d.ts +22 -0
  38. package/dist/agent/operator-claude.js +134 -0
  39. package/dist/agent/operator-claude.js.map +1 -0
  40. package/dist/api/admin-endpoint.d.ts +12 -0
  41. package/dist/api/admin-endpoint.js +71 -0
  42. package/dist/api/admin-endpoint.js.map +1 -0
  43. package/dist/api/agent-binding-endpoint.d.ts +26 -0
  44. package/dist/api/agent-binding-endpoint.js +28 -0
  45. package/dist/api/agent-binding-endpoint.js.map +1 -0
  46. package/dist/api/bootstrap-endpoint.d.ts +24 -0
  47. package/dist/api/bootstrap-endpoint.js +103 -0
  48. package/dist/api/bootstrap-endpoint.js.map +1 -0
  49. package/dist/api/events-endpoint.d.ts +9 -0
  50. package/dist/api/events-endpoint.js +46 -0
  51. package/dist/api/events-endpoint.js.map +1 -0
  52. package/dist/api/fleet-build.d.ts +1 -1
  53. package/dist/api/fleet-build.js +17 -8
  54. package/dist/api/fleet-build.js.map +1 -1
  55. package/dist/api/gather-status.d.ts +16 -1
  56. package/dist/api/gather-status.js +163 -3
  57. package/dist/api/gather-status.js.map +1 -1
  58. package/dist/api/handshake.d.ts +17 -0
  59. package/dist/api/handshake.js +28 -0
  60. package/dist/api/handshake.js.map +1 -0
  61. package/dist/api/harness-status-endpoint.d.ts +20 -0
  62. package/dist/api/harness-status-endpoint.js +13 -0
  63. package/dist/api/harness-status-endpoint.js.map +1 -0
  64. package/dist/api/history-build.d.ts +2 -2
  65. package/dist/api/history-build.js +3 -3
  66. package/dist/api/history-build.js.map +1 -1
  67. package/dist/api/launcher-endpoints.d.ts +43 -0
  68. package/dist/api/launcher-endpoints.js +50 -0
  69. package/dist/api/launcher-endpoints.js.map +1 -0
  70. package/dist/api/launcher-status.d.ts +92 -0
  71. package/dist/api/launcher-status.js +82 -0
  72. package/dist/api/launcher-status.js.map +1 -0
  73. package/dist/api/launcher-tasks.d.ts +104 -0
  74. package/dist/api/launcher-tasks.js +83 -0
  75. package/dist/api/launcher-tasks.js.map +1 -0
  76. package/dist/api/leaderboard-api.d.ts +20 -0
  77. package/dist/api/leaderboard-api.js +18 -0
  78. package/dist/api/leaderboard-api.js.map +1 -0
  79. package/dist/api/peers.js +21 -6
  80. package/dist/api/peers.js.map +1 -1
  81. package/dist/api/portfolio-v0-build.d.ts +16 -10
  82. package/dist/api/portfolio-v0-build.js +36 -31
  83. package/dist/api/portfolio-v0-build.js.map +1 -1
  84. package/dist/api/portfolio-v0-doctor.js +1 -1
  85. package/dist/api/portfolio-v0-doctor.js.map +1 -1
  86. package/dist/api/prediction-v1-build.d.ts +65 -0
  87. package/dist/api/prediction-v1-build.js +73 -0
  88. package/dist/api/prediction-v1-build.js.map +1 -0
  89. package/dist/api/rewards-build.js +3 -8
  90. package/dist/api/rewards-build.js.map +1 -1
  91. package/dist/api/server.d.ts +97 -1
  92. package/dist/api/server.js +334 -16
  93. package/dist/api/server.js.map +1 -1
  94. package/dist/api/setup-endpoints.d.ts +62 -0
  95. package/dist/api/setup-endpoints.js +705 -0
  96. package/dist/api/setup-endpoints.js.map +1 -0
  97. package/dist/api/solvernets-catalog-build.d.ts +37 -0
  98. package/dist/api/solvernets-catalog-build.js +19 -0
  99. package/dist/api/solvernets-catalog-build.js.map +1 -0
  100. package/dist/api/solvernets-endpoint.d.ts +15 -0
  101. package/dist/api/solvernets-endpoint.js +5 -0
  102. package/dist/api/solvernets-endpoint.js.map +1 -0
  103. package/dist/api/solvernets-endpoints.d.ts +104 -0
  104. package/dist/api/solvernets-endpoints.js +1023 -0
  105. package/dist/api/solvernets-endpoints.js.map +1 -0
  106. package/dist/api/status-build.d.ts +15 -2
  107. package/dist/api/status-build.js +45 -9
  108. package/dist/api/status-build.js.map +1 -1
  109. package/dist/api/status-rollup-build.d.ts +46 -1
  110. package/dist/api/status-rollup-build.js +168 -5
  111. package/dist/api/status-rollup-build.js.map +1 -1
  112. package/dist/api/ui-token.d.ts +5 -0
  113. package/dist/api/ui-token.js +36 -0
  114. package/dist/api/ui-token.js.map +1 -0
  115. package/dist/build-info.d.ts +32 -0
  116. package/dist/build-info.js +69 -0
  117. package/dist/build-info.js.map +1 -0
  118. package/dist/build-info.json +6 -0
  119. package/dist/build-meta.json +1 -1
  120. package/dist/cli/command.d.ts +9 -0
  121. package/dist/cli/commands/auth.js +6 -3
  122. package/dist/cli/commands/auth.js.map +1 -1
  123. package/dist/cli/commands/balance.d.ts +7 -0
  124. package/dist/cli/commands/balance.js +38 -32
  125. package/dist/cli/commands/balance.js.map +1 -1
  126. package/dist/cli/commands/bootstrap.d.ts +13 -1
  127. package/dist/cli/commands/bootstrap.js +150 -133
  128. package/dist/cli/commands/bootstrap.js.map +1 -1
  129. package/dist/cli/commands/checkpoint.d.ts +85 -0
  130. package/dist/cli/commands/checkpoint.js +75 -0
  131. package/dist/cli/commands/checkpoint.js.map +1 -0
  132. package/dist/cli/commands/claim-rewards.js +14 -2
  133. package/dist/cli/commands/claim-rewards.js.map +1 -1
  134. package/dist/cli/commands/conformance.d.ts +12 -0
  135. package/dist/cli/commands/conformance.js +140 -0
  136. package/dist/cli/commands/conformance.js.map +1 -0
  137. package/dist/cli/commands/create.d.ts +22 -0
  138. package/dist/cli/commands/create.js +226 -0
  139. package/dist/cli/commands/create.js.map +1 -0
  140. package/dist/cli/commands/doctor.d.ts +49 -1
  141. package/dist/cli/commands/doctor.js +162 -134
  142. package/dist/cli/commands/doctor.js.map +1 -1
  143. package/dist/cli/commands/fleet-scale.d.ts +19 -1
  144. package/dist/cli/commands/fleet-scale.js +378 -361
  145. package/dist/cli/commands/fleet-scale.js.map +1 -1
  146. package/dist/cli/commands/fleet.d.ts +7 -0
  147. package/dist/cli/commands/fleet.js +39 -33
  148. package/dist/cli/commands/fleet.js.map +1 -1
  149. package/dist/cli/commands/fund-requirements.d.ts +14 -1
  150. package/dist/cli/commands/fund-requirements.js +182 -174
  151. package/dist/cli/commands/fund-requirements.js.map +1 -1
  152. package/dist/cli/commands/harnesses.d.ts +38 -0
  153. package/dist/cli/commands/harnesses.js +305 -0
  154. package/dist/cli/commands/harnesses.js.map +1 -0
  155. package/dist/cli/commands/history.d.ts +10 -1
  156. package/dist/cli/commands/history.js +68 -59
  157. package/dist/cli/commands/history.js.map +1 -1
  158. package/dist/cli/commands/init.js +4 -1
  159. package/dist/cli/commands/init.js.map +1 -1
  160. package/dist/cli/commands/integrations.d.ts +13 -0
  161. package/dist/cli/commands/integrations.js +1010 -0
  162. package/dist/cli/commands/integrations.js.map +1 -0
  163. package/dist/cli/commands/logs.d.ts +6 -1
  164. package/dist/cli/commands/logs.js +77 -70
  165. package/dist/cli/commands/logs.js.map +1 -1
  166. package/dist/cli/commands/migrate-agent-id.d.ts +26 -0
  167. package/dist/cli/commands/migrate-agent-id.js +164 -0
  168. package/dist/cli/commands/migrate-agent-id.js.map +1 -0
  169. package/dist/cli/commands/prediction-scoreboard.d.ts +10 -0
  170. package/dist/cli/commands/prediction-scoreboard.js +136 -0
  171. package/dist/cli/commands/prediction-scoreboard.js.map +1 -0
  172. package/dist/cli/commands/quickstart.d.ts +51 -1
  173. package/dist/cli/commands/quickstart.js +514 -296
  174. package/dist/cli/commands/quickstart.js.map +1 -1
  175. package/dist/cli/commands/rewards.d.ts +7 -0
  176. package/dist/cli/commands/rewards.js +46 -40
  177. package/dist/cli/commands/rewards.js.map +1 -1
  178. package/dist/cli/commands/run.d.ts +14 -1
  179. package/dist/cli/commands/run.js +243 -91
  180. package/dist/cli/commands/run.js.map +1 -1
  181. package/dist/cli/commands/solver-nets.js +229 -0
  182. package/dist/cli/commands/solver-nets.js.map +1 -0
  183. package/dist/cli/commands/solver-plugins.d.ts +9 -0
  184. package/dist/cli/commands/solver-plugins.js +186 -0
  185. package/dist/cli/commands/solver-plugins.js.map +1 -0
  186. package/dist/cli/commands/status.d.ts +13 -0
  187. package/dist/cli/commands/status.js +105 -34
  188. package/dist/cli/commands/status.js.map +1 -1
  189. package/dist/cli/commands/tasks.js +405 -0
  190. package/dist/cli/commands/tasks.js.map +1 -0
  191. package/dist/cli/commands/ui.d.ts +3 -0
  192. package/dist/cli/commands/ui.js +45 -0
  193. package/dist/cli/commands/ui.js.map +1 -0
  194. package/dist/cli/commands/update.d.ts +12 -0
  195. package/dist/cli/commands/update.js +321 -91
  196. package/dist/cli/commands/update.js.map +1 -1
  197. package/dist/cli/commands/version.js +3 -2
  198. package/dist/cli/commands/version.js.map +1 -1
  199. package/dist/cli/commands/withdraw.d.ts +21 -1
  200. package/dist/cli/commands/withdraw.js +175 -159
  201. package/dist/cli/commands/withdraw.js.map +1 -1
  202. package/dist/cli/deployment-digest.js +0 -5
  203. package/dist/cli/deployment-digest.js.map +1 -1
  204. package/dist/cli/execution-context.d.ts +1 -1
  205. package/dist/cli/execution-context.js +4 -4
  206. package/dist/cli/execution-context.js.map +1 -1
  207. package/dist/cli/help.js +8 -1
  208. package/dist/cli/help.js.map +1 -1
  209. package/dist/cli/index.d.ts +7 -0
  210. package/dist/cli/index.js +26 -6
  211. package/dist/cli/index.js.map +1 -1
  212. package/dist/cli/introspection-context.js +0 -1
  213. package/dist/cli/introspection-context.js.map +1 -1
  214. package/dist/cli/open-browser.d.ts +1 -0
  215. package/dist/cli/open-browser.js +18 -0
  216. package/dist/cli/open-browser.js.map +1 -0
  217. package/dist/cli/password.d.ts +3 -3
  218. package/dist/cli/password.js +6 -6
  219. package/dist/cli/password.js.map +1 -1
  220. package/dist/cli/task-native-readiness.d.ts +27 -0
  221. package/dist/cli/task-native-readiness.js +170 -0
  222. package/dist/cli/task-native-readiness.js.map +1 -0
  223. package/dist/config.d.ts +1771 -57
  224. package/dist/config.js +527 -31
  225. package/dist/config.js.map +1 -1
  226. package/dist/conformance/checks/artifacts.d.ts +37 -0
  227. package/dist/conformance/checks/artifacts.js +110 -0
  228. package/dist/conformance/checks/artifacts.js.map +1 -0
  229. package/dist/conformance/checks/envelope-schema.d.ts +17 -0
  230. package/dist/conformance/checks/envelope-schema.js +36 -0
  231. package/dist/conformance/checks/envelope-schema.js.map +1 -0
  232. package/dist/conformance/checks/hash-signature.d.ts +26 -0
  233. package/dist/conformance/checks/hash-signature.js +70 -0
  234. package/dist/conformance/checks/hash-signature.js.map +1 -0
  235. package/dist/conformance/checks/payload.d.ts +19 -0
  236. package/dist/conformance/checks/payload.js +52 -0
  237. package/dist/conformance/checks/payload.js.map +1 -0
  238. package/dist/conformance/checks/secret-scrub.d.ts +33 -0
  239. package/dist/conformance/checks/secret-scrub.js +118 -0
  240. package/dist/conformance/checks/secret-scrub.js.map +1 -0
  241. package/dist/conformance/checks/source-runtime.d.ts +43 -0
  242. package/dist/conformance/checks/source-runtime.js +68 -0
  243. package/dist/conformance/checks/source-runtime.js.map +1 -0
  244. package/dist/conformance/checks/source-static.d.ts +61 -0
  245. package/dist/conformance/checks/source-static.js +311 -0
  246. package/dist/conformance/checks/source-static.js.map +1 -0
  247. package/dist/conformance/checks/trajectory-chain.d.ts +18 -0
  248. package/dist/conformance/checks/trajectory-chain.js +51 -0
  249. package/dist/conformance/checks/trajectory-chain.js.map +1 -0
  250. package/dist/conformance/checks/trajectory-profile.d.ts +17 -0
  251. package/dist/conformance/checks/trajectory-profile.js +51 -0
  252. package/dist/conformance/checks/trajectory-profile.js.map +1 -0
  253. package/dist/conformance/checks/trajectory-schema.d.ts +20 -0
  254. package/dist/conformance/checks/trajectory-schema.js +40 -0
  255. package/dist/conformance/checks/trajectory-schema.js.map +1 -0
  256. package/dist/conformance/checks/verdict.d.ts +44 -0
  257. package/dist/conformance/checks/verdict.js +122 -0
  258. package/dist/conformance/checks/verdict.js.map +1 -0
  259. package/dist/conformance/harness.d.ts +32 -0
  260. package/dist/conformance/harness.js +227 -0
  261. package/dist/conformance/harness.js.map +1 -0
  262. package/dist/conformance/types.d.ts +88 -0
  263. package/dist/conformance/types.js +31 -0
  264. package/dist/conformance/types.js.map +1 -0
  265. package/dist/corpus/acquire.d.ts +37 -0
  266. package/dist/corpus/acquire.js +155 -0
  267. package/dist/corpus/acquire.js.map +1 -0
  268. package/dist/corpus/cache.d.ts +14 -0
  269. package/dist/corpus/cache.js +18 -0
  270. package/dist/corpus/cache.js.map +1 -0
  271. package/dist/corpus/envelope-projection.d.ts +12 -0
  272. package/dist/corpus/envelope-projection.js +110 -0
  273. package/dist/corpus/envelope-projection.js.map +1 -0
  274. package/dist/corpus/fetch.d.ts +9 -0
  275. package/dist/corpus/fetch.js +24 -0
  276. package/dist/corpus/fetch.js.map +1 -0
  277. package/dist/corpus/index.d.ts +19 -0
  278. package/dist/corpus/index.js +81 -0
  279. package/dist/corpus/index.js.map +1 -0
  280. package/dist/corpus/prediction-brier-scoreboard-report.d.ts +17 -0
  281. package/dist/corpus/prediction-brier-scoreboard-report.js +148 -0
  282. package/dist/corpus/prediction-brier-scoreboard-report.js.map +1 -0
  283. package/dist/corpus/prediction-brier-scoreboard.d.ts +56 -0
  284. package/dist/corpus/prediction-brier-scoreboard.js +269 -0
  285. package/dist/corpus/prediction-brier-scoreboard.js.map +1 -0
  286. package/dist/corpus/prediction-scoreable-verdicts.d.ts +4 -0
  287. package/dist/corpus/prediction-scoreable-verdicts.js +23 -0
  288. package/dist/corpus/prediction-scoreable-verdicts.js.map +1 -0
  289. package/dist/corpus/query.d.ts +17 -0
  290. package/dist/corpus/query.js +108 -0
  291. package/dist/corpus/query.js.map +1 -0
  292. package/dist/corpus/route-resolver.d.ts +16 -0
  293. package/dist/corpus/route-resolver.js +20 -0
  294. package/dist/corpus/route-resolver.js.map +1 -0
  295. package/dist/corpus/types.d.ts +150 -0
  296. package/dist/corpus/types.js +50 -0
  297. package/dist/corpus/types.js.map +1 -0
  298. package/dist/daemon/balance-topup-loop.js +2 -1
  299. package/dist/daemon/balance-topup-loop.js.map +1 -1
  300. package/dist/daemon/creator.d.ts +7 -7
  301. package/dist/daemon/creator.js +11 -14
  302. package/dist/daemon/creator.js.map +1 -1
  303. package/dist/daemon/daemon.d.ts +83 -31
  304. package/dist/daemon/daemon.js +206 -67
  305. package/dist/daemon/daemon.js.map +1 -1
  306. package/dist/daemon/delivery-watcher.js +50 -4
  307. package/dist/daemon/delivery-watcher.js.map +1 -1
  308. package/dist/daemon/freeze-fence.d.ts +42 -0
  309. package/dist/daemon/freeze-fence.js +71 -0
  310. package/dist/daemon/freeze-fence.js.map +1 -0
  311. package/dist/daemon/jinn-claim-loop-canonical.d.ts +207 -0
  312. package/dist/daemon/jinn-claim-loop-canonical.js +296 -0
  313. package/dist/daemon/jinn-claim-loop-canonical.js.map +1 -0
  314. package/dist/daemon/jinn-claim-loop-mock.d.ts +61 -0
  315. package/dist/daemon/jinn-claim-loop-mock.js +122 -0
  316. package/dist/daemon/jinn-claim-loop-mock.js.map +1 -0
  317. package/dist/daemon/jinn-claim-loop.d.ts +123 -0
  318. package/dist/daemon/jinn-claim-loop.js +256 -0
  319. package/dist/daemon/jinn-claim-loop.js.map +1 -0
  320. package/dist/daemon/reward-claim-loop.d.ts +2 -0
  321. package/dist/daemon/reward-claim-loop.js +32 -27
  322. package/dist/daemon/reward-claim-loop.js.map +1 -1
  323. package/dist/dashboard/assets/index-C4Vp0vkW.js +76 -0
  324. package/dist/dashboard/assets/index-a0yafmyT.css +32 -0
  325. package/dist/dashboard/index.html +18 -74
  326. package/dist/earning/agent-wallet-binding.d.ts +133 -0
  327. package/dist/earning/agent-wallet-binding.js +202 -0
  328. package/dist/earning/agent-wallet-binding.js.map +1 -0
  329. package/dist/earning/bootstrap.d.ts +88 -1
  330. package/dist/earning/bootstrap.js +409 -56
  331. package/dist/earning/bootstrap.js.map +1 -1
  332. package/dist/earning/contracts.d.ts +328 -6
  333. package/dist/earning/contracts.js +295 -14
  334. package/dist/earning/contracts.js.map +1 -1
  335. package/dist/earning/evidence-simhash.d.ts +1 -1
  336. package/dist/earning/faucet.d.ts +31 -0
  337. package/dist/earning/faucet.js +37 -0
  338. package/dist/earning/faucet.js.map +1 -1
  339. package/dist/earning/funding-plan.d.ts +89 -0
  340. package/dist/earning/funding-plan.js +202 -0
  341. package/dist/earning/funding-plan.js.map +1 -0
  342. package/dist/earning/migrate-agent-id.d.ts +129 -0
  343. package/dist/earning/migrate-agent-id.js +256 -0
  344. package/dist/earning/migrate-agent-id.js.map +1 -0
  345. package/dist/earning/orphan-sweep.d.ts +14 -0
  346. package/dist/earning/orphan-sweep.js +63 -2
  347. package/dist/earning/orphan-sweep.js.map +1 -1
  348. package/dist/earning/reconcile.d.ts +2 -0
  349. package/dist/earning/reconcile.js +30 -0
  350. package/dist/earning/reconcile.js.map +1 -1
  351. package/dist/earning/safe-adapter.js +45 -3
  352. package/dist/earning/safe-adapter.js.map +1 -1
  353. package/dist/earning/stolas-claim.d.ts +86 -6
  354. package/dist/earning/stolas-claim.js +123 -9
  355. package/dist/earning/stolas-claim.js.map +1 -1
  356. package/dist/earning/store.d.ts +47 -0
  357. package/dist/earning/store.js +113 -1
  358. package/dist/earning/store.js.map +1 -1
  359. package/dist/earning/testnet-setup-migration.d.ts +32 -0
  360. package/dist/earning/testnet-setup-migration.js +214 -0
  361. package/dist/earning/testnet-setup-migration.js.map +1 -0
  362. package/dist/earning/types.d.ts +57 -9
  363. package/dist/earning/types.js +51 -2
  364. package/dist/earning/types.js.map +1 -1
  365. package/dist/earning/viem-clients.d.ts +20 -0
  366. package/dist/earning/viem-clients.js +32 -1
  367. package/dist/earning/viem-clients.js.map +1 -1
  368. package/dist/erc8004/abis.d.ts +423 -0
  369. package/dist/erc8004/abis.js +265 -0
  370. package/dist/erc8004/abis.js.map +1 -0
  371. package/dist/erc8004/addresses.d.ts +40 -0
  372. package/dist/erc8004/addresses.js +64 -0
  373. package/dist/erc8004/addresses.js.map +1 -0
  374. package/dist/erc8004/identity.d.ts +273 -0
  375. package/dist/erc8004/identity.js +405 -0
  376. package/dist/erc8004/identity.js.map +1 -0
  377. package/dist/erc8004/index.d.ts +13 -0
  378. package/dist/erc8004/index.js +20 -0
  379. package/dist/erc8004/index.js.map +1 -0
  380. package/dist/erc8004/reputation.d.ts +349 -0
  381. package/dist/erc8004/reputation.js +464 -0
  382. package/dist/erc8004/reputation.js.map +1 -0
  383. package/dist/erc8004/subgraph.d.ts +46 -0
  384. package/dist/erc8004/subgraph.js +37 -0
  385. package/dist/erc8004/subgraph.js.map +1 -0
  386. package/dist/erc8004/validation.d.ts +145 -0
  387. package/dist/erc8004/validation.js +219 -0
  388. package/dist/erc8004/validation.js.map +1 -0
  389. package/dist/errors/persisted-bootstrap-error.d.ts +4 -0
  390. package/dist/errors/persisted-bootstrap-error.js +50 -0
  391. package/dist/errors/persisted-bootstrap-error.js.map +1 -0
  392. package/dist/events/emitter.d.ts +12 -0
  393. package/dist/events/emitter.js +23 -0
  394. package/dist/events/emitter.js.map +1 -0
  395. package/dist/events/ring-buffer.d.ts +25 -0
  396. package/dist/events/ring-buffer.js +46 -0
  397. package/dist/events/ring-buffer.js.map +1 -0
  398. package/dist/events/types.d.ts +42 -0
  399. package/dist/events/types.js +28 -0
  400. package/dist/events/types.js.map +1 -0
  401. package/dist/harnesses/capability/index.d.ts +82 -0
  402. package/dist/harnesses/capability/index.js +12 -0
  403. package/dist/harnesses/capability/index.js.map +1 -0
  404. package/dist/harnesses/capability/scoped-rpc.d.ts +12 -0
  405. package/dist/harnesses/capability/scoped-rpc.js +34 -0
  406. package/dist/harnesses/capability/scoped-rpc.js.map +1 -0
  407. package/dist/harnesses/capability/scoped-secrets.d.ts +8 -0
  408. package/dist/harnesses/capability/scoped-secrets.js +10 -0
  409. package/dist/harnesses/capability/scoped-secrets.js.map +1 -0
  410. package/dist/harnesses/capability/scoped-signer.d.ts +46 -0
  411. package/dist/harnesses/capability/scoped-signer.js +73 -0
  412. package/dist/harnesses/capability/scoped-signer.js.map +1 -0
  413. package/dist/harnesses/engine/canonical-json.d.ts +1 -0
  414. package/dist/harnesses/engine/canonical-json.js +66 -0
  415. package/dist/harnesses/engine/canonical-json.js.map +1 -0
  416. package/dist/harnesses/engine/delivery.d.ts +58 -0
  417. package/dist/harnesses/engine/delivery.js +67 -0
  418. package/dist/harnesses/engine/delivery.js.map +1 -0
  419. package/dist/harnesses/engine/engine.d.ts +516 -0
  420. package/dist/harnesses/engine/engine.js +1544 -0
  421. package/dist/harnesses/engine/engine.js.map +1 -0
  422. package/dist/harnesses/engine/envelope-assembly.d.ts +73 -0
  423. package/dist/harnesses/engine/envelope-assembly.js +60 -0
  424. package/dist/harnesses/engine/envelope-assembly.js.map +1 -0
  425. package/dist/harnesses/engine/packaging.d.ts +87 -0
  426. package/dist/harnesses/engine/packaging.js +376 -0
  427. package/dist/harnesses/engine/packaging.js.map +1 -0
  428. package/dist/harnesses/engine/persistence.d.ts +193 -0
  429. package/dist/harnesses/engine/persistence.js +421 -0
  430. package/dist/harnesses/engine/persistence.js.map +1 -0
  431. package/dist/harnesses/engine/recovery.d.ts +22 -0
  432. package/dist/harnesses/engine/recovery.js +24 -0
  433. package/dist/harnesses/engine/recovery.js.map +1 -0
  434. package/dist/harnesses/engine/registry.d.ts +55 -0
  435. package/dist/harnesses/engine/registry.js +65 -0
  436. package/dist/harnesses/engine/registry.js.map +1 -0
  437. package/dist/harnesses/engine/signing.d.ts +30 -0
  438. package/dist/harnesses/engine/signing.js +39 -0
  439. package/dist/harnesses/engine/signing.js.map +1 -0
  440. package/dist/harnesses/engine/state.d.ts +42 -0
  441. package/dist/harnesses/engine/state.js +87 -0
  442. package/dist/harnesses/engine/state.js.map +1 -0
  443. package/dist/harnesses/engine/validate-manifest.d.ts +23 -0
  444. package/dist/harnesses/engine/validate-manifest.js +49 -0
  445. package/dist/harnesses/engine/validate-manifest.js.map +1 -0
  446. package/dist/harnesses/engine/verification-stub.d.ts +18 -0
  447. package/dist/harnesses/engine/verification-stub.js +18 -0
  448. package/dist/harnesses/engine/verification-stub.js.map +1 -0
  449. package/dist/harnesses/external-impls/index.d.ts +3 -0
  450. package/dist/harnesses/external-impls/index.js +2 -0
  451. package/dist/harnesses/external-impls/index.js.map +1 -0
  452. package/dist/harnesses/external-impls/loader.d.ts +50 -0
  453. package/dist/harnesses/external-impls/loader.js +139 -0
  454. package/dist/harnesses/external-impls/loader.js.map +1 -0
  455. package/dist/harnesses/external-impls/package-hash.d.ts +26 -0
  456. package/dist/harnesses/external-impls/package-hash.js +102 -0
  457. package/dist/harnesses/external-impls/package-hash.js.map +1 -0
  458. package/dist/harnesses/external-impls/types.d.ts +42 -0
  459. package/dist/harnesses/external-impls/types.js +10 -0
  460. package/dist/harnesses/external-impls/types.js.map +1 -0
  461. package/dist/harnesses/freeze.d.ts +34 -0
  462. package/dist/harnesses/freeze.js +60 -0
  463. package/dist/harnesses/freeze.js.map +1 -0
  464. package/dist/harnesses/impls/claude-code-learner/adapters/claude-code.d.ts +57 -0
  465. package/dist/harnesses/impls/claude-code-learner/adapters/claude-code.js +235 -0
  466. package/dist/harnesses/impls/claude-code-learner/adapters/claude-code.js.map +1 -0
  467. package/dist/harnesses/impls/claude-code-learner/harness.d.ts +22 -0
  468. package/dist/harnesses/impls/claude-code-learner/harness.js +56 -0
  469. package/dist/harnesses/impls/claude-code-learner/harness.js.map +1 -0
  470. package/dist/harnesses/impls/claude-code-learner/harvest.d.ts +20 -0
  471. package/dist/harnesses/impls/claude-code-learner/harvest.js +426 -0
  472. package/dist/harnesses/impls/claude-code-learner/harvest.js.map +1 -0
  473. package/dist/harnesses/impls/claude-code-learner/index.d.ts +14 -0
  474. package/dist/harnesses/impls/claude-code-learner/index.js +13 -0
  475. package/dist/harnesses/impls/claude-code-learner/index.js.map +1 -0
  476. package/dist/harnesses/impls/claude-code-learner/plugin-path.d.ts +14 -0
  477. package/dist/harnesses/impls/claude-code-learner/plugin-path.js +30 -0
  478. package/dist/harnesses/impls/claude-code-learner/plugin-path.js.map +1 -0
  479. package/dist/harnesses/impls/claude-code-learner/test-utils/fake-plugin-outputs.d.ts +50 -0
  480. package/dist/harnesses/impls/claude-code-learner/test-utils/fake-plugin-outputs.js +192 -0
  481. package/dist/harnesses/impls/claude-code-learner/test-utils/fake-plugin-outputs.js.map +1 -0
  482. package/dist/harnesses/impls/claude-code-learner/test-utils/noop-adapter.d.ts +22 -0
  483. package/dist/harnesses/impls/claude-code-learner/test-utils/noop-adapter.js +35 -0
  484. package/dist/harnesses/impls/claude-code-learner/test-utils/noop-adapter.js.map +1 -0
  485. package/dist/harnesses/impls/claude-code-learner/types.d.ts +112 -0
  486. package/dist/harnesses/impls/claude-code-learner/types.js.map +1 -0
  487. package/dist/harnesses/impls/claude-mcp-hyperliquid/api-wallet.d.ts +64 -0
  488. package/dist/harnesses/impls/claude-mcp-hyperliquid/api-wallet.js.map +1 -0
  489. package/dist/harnesses/impls/claude-mcp-hyperliquid/index.d.ts +106 -0
  490. package/dist/harnesses/impls/claude-mcp-hyperliquid/index.js +723 -0
  491. package/dist/harnesses/impls/claude-mcp-hyperliquid/index.js.map +1 -0
  492. package/dist/harnesses/impls/claude-mcp-hyperliquid/mcp-tools.js.map +1 -0
  493. package/dist/harnesses/impls/claude-mcp-hyperliquid/safety-rails.js.map +1 -0
  494. package/dist/harnesses/impls/claude-mcp-hyperliquid/session-orchestrator.d.ts +104 -0
  495. package/dist/harnesses/impls/claude-mcp-hyperliquid/session-orchestrator.js +264 -0
  496. package/dist/harnesses/impls/claude-mcp-hyperliquid/session-orchestrator.js.map +1 -0
  497. package/dist/harnesses/impls/claude-mcp-prediction/index.d.ts +44 -0
  498. package/dist/harnesses/impls/claude-mcp-prediction/index.js +250 -0
  499. package/dist/harnesses/impls/claude-mcp-prediction/index.js.map +1 -0
  500. package/dist/harnesses/impls/claude-mcp-prediction/mcp-tools.js +135 -0
  501. package/dist/harnesses/impls/claude-mcp-prediction/mcp-tools.js.map +1 -0
  502. package/dist/harnesses/impls/claude-mcp-prediction/prompt.d.ts +8 -0
  503. package/dist/harnesses/impls/claude-mcp-prediction/prompt.js +54 -0
  504. package/dist/harnesses/impls/claude-mcp-prediction/prompt.js.map +1 -0
  505. package/dist/harnesses/impls/claude-mcp-prediction/session-orchestrator.d.ts +43 -0
  506. package/dist/harnesses/impls/claude-mcp-prediction/session-orchestrator.js +21 -0
  507. package/dist/harnesses/impls/claude-mcp-prediction/session-orchestrator.js.map +1 -0
  508. package/dist/harnesses/impls/claude-mcp-prediction/types.d.ts +84 -0
  509. package/dist/harnesses/impls/claude-mcp-prediction/types.js +6 -0
  510. package/dist/harnesses/impls/claude-mcp-prediction/types.js.map +1 -0
  511. package/dist/harnesses/impls/claude-mcp-prediction-apy/index.d.ts +36 -0
  512. package/dist/harnesses/impls/claude-mcp-prediction-apy/index.js +241 -0
  513. package/dist/harnesses/impls/claude-mcp-prediction-apy/index.js.map +1 -0
  514. package/dist/harnesses/impls/claude-mcp-prediction-apy/mcp-tools.js +136 -0
  515. package/dist/harnesses/impls/claude-mcp-prediction-apy/mcp-tools.js.map +1 -0
  516. package/dist/harnesses/impls/claude-mcp-prediction-apy/prompt.d.ts +7 -0
  517. package/dist/harnesses/impls/claude-mcp-prediction-apy/prompt.js +46 -0
  518. package/dist/harnesses/impls/claude-mcp-prediction-apy/prompt.js.map +1 -0
  519. package/dist/harnesses/impls/claude-mcp-prediction-apy/session-orchestrator.d.ts +37 -0
  520. package/dist/harnesses/impls/claude-mcp-prediction-apy/session-orchestrator.js +19 -0
  521. package/dist/harnesses/impls/claude-mcp-prediction-apy/session-orchestrator.js.map +1 -0
  522. package/dist/harnesses/impls/claude-mcp-prediction-apy/types.d.ts +64 -0
  523. package/dist/harnesses/impls/claude-mcp-prediction-apy/types.js +6 -0
  524. package/dist/harnesses/impls/claude-mcp-prediction-apy/types.js.map +1 -0
  525. package/dist/harnesses/impls/claude-mcp-shared/single-session-orchestrator.d.ts +84 -0
  526. package/dist/harnesses/impls/claude-mcp-shared/single-session-orchestrator.js +206 -0
  527. package/dist/harnesses/impls/claude-mcp-shared/single-session-orchestrator.js.map +1 -0
  528. package/dist/harnesses/impls/evaluation-context.d.ts +23 -0
  529. package/dist/harnesses/impls/evaluation-context.js +25 -0
  530. package/dist/harnesses/impls/evaluation-context.js.map +1 -0
  531. package/dist/harnesses/impls/index.d.ts +74 -0
  532. package/dist/harnesses/impls/index.js +112 -0
  533. package/dist/harnesses/impls/index.js.map +1 -0
  534. package/dist/harnesses/impls/legacy-claude/index.d.ts +66 -0
  535. package/dist/harnesses/impls/legacy-claude/index.js +168 -0
  536. package/dist/harnesses/impls/legacy-claude/index.js.map +1 -0
  537. package/dist/harnesses/impls/portfolio-v0-evaluator/canonical-metrics.d.ts +68 -0
  538. package/dist/harnesses/impls/portfolio-v0-evaluator/canonical-metrics.js +117 -0
  539. package/dist/harnesses/impls/portfolio-v0-evaluator/canonical-metrics.js.map +1 -0
  540. package/dist/harnesses/impls/portfolio-v0-evaluator/checks/availability.js.map +1 -0
  541. package/dist/harnesses/impls/portfolio-v0-evaluator/checks/consistency.d.ts +78 -0
  542. package/dist/harnesses/impls/portfolio-v0-evaluator/checks/consistency.js +274 -0
  543. package/dist/harnesses/impls/portfolio-v0-evaluator/checks/consistency.js.map +1 -0
  544. package/dist/harnesses/impls/portfolio-v0-evaluator/checks/eligibility.d.ts +23 -0
  545. package/dist/harnesses/impls/portfolio-v0-evaluator/checks/eligibility.js +49 -0
  546. package/dist/harnesses/impls/portfolio-v0-evaluator/checks/eligibility.js.map +1 -0
  547. package/dist/harnesses/impls/portfolio-v0-evaluator/checks/integrity.d.ts +25 -0
  548. package/dist/harnesses/impls/portfolio-v0-evaluator/checks/integrity.js +44 -0
  549. package/dist/harnesses/impls/portfolio-v0-evaluator/checks/integrity.js.map +1 -0
  550. package/dist/harnesses/impls/portfolio-v0-evaluator/checks/spec.d.ts +17 -0
  551. package/dist/harnesses/impls/portfolio-v0-evaluator/checks/spec.js +43 -0
  552. package/dist/harnesses/impls/portfolio-v0-evaluator/checks/spec.js.map +1 -0
  553. package/dist/harnesses/impls/portfolio-v0-evaluator/index.d.ts +44 -0
  554. package/dist/harnesses/impls/portfolio-v0-evaluator/index.js +569 -0
  555. package/dist/harnesses/impls/portfolio-v0-evaluator/index.js.map +1 -0
  556. package/dist/harnesses/impls/portfolio-v0-evaluator/score.js.map +1 -0
  557. package/dist/harnesses/impls/portfolio-v0-evaluator/types.d.ts +34 -0
  558. package/dist/harnesses/impls/portfolio-v0-evaluator/types.js.map +1 -0
  559. package/dist/harnesses/impls/prediction-apy-v0-baseline/index.d.ts +42 -0
  560. package/dist/harnesses/impls/prediction-apy-v0-baseline/index.js +114 -0
  561. package/dist/harnesses/impls/prediction-apy-v0-baseline/index.js.map +1 -0
  562. package/dist/harnesses/impls/prediction-apy-v0-baseline/strategy.js.map +1 -0
  563. package/dist/harnesses/impls/prediction-apy-v0-baseline/types.js.map +1 -0
  564. package/dist/harnesses/impls/prediction-apy-v0-evaluator/canonical-metrics.d.ts +6 -0
  565. package/dist/harnesses/impls/prediction-apy-v0-evaluator/canonical-metrics.js +11 -0
  566. package/dist/harnesses/impls/prediction-apy-v0-evaluator/canonical-metrics.js.map +1 -0
  567. package/dist/harnesses/impls/prediction-apy-v0-evaluator/index.d.ts +42 -0
  568. package/dist/harnesses/impls/prediction-apy-v0-evaluator/index.js +346 -0
  569. package/dist/harnesses/impls/prediction-apy-v0-evaluator/index.js.map +1 -0
  570. package/dist/harnesses/impls/prediction-apy-v0-evaluator/parse-submission.d.ts +16 -0
  571. package/dist/harnesses/impls/prediction-apy-v0-evaluator/parse-submission.js +22 -0
  572. package/dist/harnesses/impls/prediction-apy-v0-evaluator/parse-submission.js.map +1 -0
  573. package/dist/harnesses/impls/prediction-apy-v0-evaluator/score.js.map +1 -0
  574. package/dist/harnesses/impls/prediction-apy-v0-evaluator/types.js.map +1 -0
  575. package/dist/harnesses/impls/prediction-v0-baseline/index.d.ts +33 -0
  576. package/dist/harnesses/impls/prediction-v0-baseline/index.js +109 -0
  577. package/dist/harnesses/impls/prediction-v0-baseline/index.js.map +1 -0
  578. package/dist/harnesses/impls/prediction-v0-baseline/strategy.d.ts +8 -0
  579. package/dist/harnesses/impls/prediction-v0-baseline/strategy.js +41 -0
  580. package/dist/harnesses/impls/prediction-v0-baseline/strategy.js.map +1 -0
  581. package/dist/harnesses/impls/prediction-v0-baseline/types.d.ts +7 -0
  582. package/dist/harnesses/impls/prediction-v0-baseline/types.js.map +1 -0
  583. package/dist/harnesses/impls/prediction-v0-evaluator/canonical-metrics.d.ts +20 -0
  584. package/dist/harnesses/impls/prediction-v0-evaluator/canonical-metrics.js.map +1 -0
  585. package/dist/harnesses/impls/prediction-v0-evaluator/checks/availability.d.ts +9 -0
  586. package/dist/harnesses/impls/prediction-v0-evaluator/checks/availability.js.map +1 -0
  587. package/dist/harnesses/impls/prediction-v0-evaluator/checks/eligibility.d.ts +3 -0
  588. package/dist/harnesses/impls/prediction-v0-evaluator/checks/eligibility.js.map +1 -0
  589. package/dist/harnesses/impls/prediction-v0-evaluator/checks/integrity.d.ts +15 -0
  590. package/dist/harnesses/impls/prediction-v0-evaluator/checks/integrity.js +111 -0
  591. package/dist/harnesses/impls/prediction-v0-evaluator/checks/integrity.js.map +1 -0
  592. package/dist/harnesses/impls/prediction-v0-evaluator/checks/spec.d.ts +5 -0
  593. package/dist/harnesses/impls/prediction-v0-evaluator/checks/spec.js.map +1 -0
  594. package/dist/harnesses/impls/prediction-v0-evaluator/index.d.ts +36 -0
  595. package/dist/harnesses/impls/prediction-v0-evaluator/index.js +342 -0
  596. package/dist/harnesses/impls/prediction-v0-evaluator/index.js.map +1 -0
  597. package/dist/harnesses/impls/prediction-v0-evaluator/score.js.map +1 -0
  598. package/dist/harnesses/impls/prediction-v0-evaluator/types.js +2 -0
  599. package/dist/harnesses/impls/prediction-v0-evaluator/types.js.map +1 -0
  600. package/dist/harnesses/impls/prediction-v1-baseline/index.d.ts +31 -0
  601. package/dist/harnesses/impls/prediction-v1-baseline/index.js +79 -0
  602. package/dist/harnesses/impls/prediction-v1-baseline/index.js.map +1 -0
  603. package/dist/harnesses/impls/prediction-v1-evaluator/index.d.ts +32 -0
  604. package/dist/harnesses/impls/prediction-v1-evaluator/index.js +219 -0
  605. package/dist/harnesses/impls/prediction-v1-evaluator/index.js.map +1 -0
  606. package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.d.ts +20 -0
  607. package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.js +88 -0
  608. package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.js.map +1 -0
  609. package/dist/harnesses/impls/swe-rebench-v2-evaluator/index.d.ts +56 -0
  610. package/dist/harnesses/impls/swe-rebench-v2-evaluator/index.js +40 -0
  611. package/dist/harnesses/impls/swe-rebench-v2-evaluator/index.js.map +1 -0
  612. package/dist/harnesses/manifest/index.d.ts +3 -0
  613. package/dist/harnesses/manifest/index.js +3 -0
  614. package/dist/harnesses/manifest/index.js.map +1 -0
  615. package/dist/harnesses/manifest/load.d.ts +7 -0
  616. package/dist/harnesses/manifest/load.js +49 -0
  617. package/dist/harnesses/manifest/load.js.map +1 -0
  618. package/dist/harnesses/manifest/types.d.ts +75 -0
  619. package/dist/harnesses/manifest/types.js +8 -0
  620. package/dist/harnesses/manifest/types.js.map +1 -0
  621. package/dist/harnesses/manifest/verify.d.ts +15 -0
  622. package/dist/harnesses/manifest/verify.js +53 -0
  623. package/dist/harnesses/manifest/verify.js.map +1 -0
  624. package/dist/harnesses/mode-state.d.ts +7 -0
  625. package/dist/harnesses/mode-state.js +43 -0
  626. package/dist/harnesses/mode-state.js.map +1 -0
  627. package/dist/harnesses/types.d.ts +274 -0
  628. package/dist/harnesses/types.js +28 -0
  629. package/dist/harnesses/types.js.map +1 -0
  630. package/dist/index.d.ts +1 -1
  631. package/dist/main.d.ts +17 -2
  632. package/dist/main.js +1257 -127
  633. package/dist/main.js.map +1 -1
  634. package/dist/mcp/acquire-artifact.d.ts +39 -0
  635. package/dist/mcp/acquire-artifact.js +163 -0
  636. package/dist/mcp/acquire-artifact.js.map +1 -0
  637. package/dist/mcp/operator-server.d.ts +21 -4
  638. package/dist/mcp/operator-server.js +505 -30
  639. package/dist/mcp/operator-server.js.map +1 -1
  640. package/dist/mcp/search-records.d.ts +92 -0
  641. package/dist/mcp/search-records.js +393 -0
  642. package/dist/mcp/search-records.js.map +1 -0
  643. package/dist/mcp/server.d.ts +4 -4
  644. package/dist/mcp/server.js +148 -61
  645. package/dist/mcp/server.js.map +1 -1
  646. package/dist/observability/emit-event.d.ts +2 -2
  647. package/dist/observability/emit-event.js +2 -2
  648. package/dist/observability/emit-event.js.map +1 -1
  649. package/dist/operator-errors.d.ts +14 -0
  650. package/dist/operator-errors.js +39 -10
  651. package/dist/operator-errors.js.map +1 -1
  652. package/dist/plugins/digest.d.ts +1 -0
  653. package/dist/plugins/digest.js +28 -0
  654. package/dist/plugins/digest.js.map +1 -0
  655. package/dist/plugins/index.d.ts +6 -0
  656. package/dist/plugins/index.js +6 -0
  657. package/dist/plugins/index.js.map +1 -0
  658. package/dist/plugins/manifest.d.ts +7 -0
  659. package/dist/plugins/manifest.js +22 -0
  660. package/dist/plugins/manifest.js.map +1 -0
  661. package/dist/plugins/registry.d.ts +9 -0
  662. package/dist/plugins/registry.js +24 -0
  663. package/dist/plugins/registry.js.map +1 -0
  664. package/dist/plugins/resolvers.d.ts +2 -0
  665. package/dist/plugins/resolvers.js +126 -0
  666. package/dist/plugins/resolvers.js.map +1 -0
  667. package/dist/plugins/types.d.ts +35 -0
  668. package/dist/plugins/types.js +2 -0
  669. package/dist/plugins/types.js.map +1 -0
  670. package/dist/plugins/validator.d.ts +3 -0
  671. package/dist/plugins/validator.js +50 -0
  672. package/dist/plugins/validator.js.map +1 -0
  673. package/dist/preflight/claude-auth.d.ts +14 -12
  674. package/dist/preflight/claude-auth.js +23 -37
  675. package/dist/preflight/claude-auth.js.map +1 -1
  676. package/dist/runner/claude.d.ts +3 -3
  677. package/dist/runner/claude.js +62 -26
  678. package/dist/runner/claude.js.map +1 -1
  679. package/dist/runner/runner.d.ts +29 -2
  680. package/dist/runner/simple.d.ts +2 -2
  681. package/dist/runner/simple.js +2 -2
  682. package/dist/runner/simple.js.map +1 -1
  683. package/dist/scripts/fix-node-pty.mjs +62 -0
  684. package/dist/setup/claude-code-install.d.ts +19 -0
  685. package/dist/setup/claude-code-install.js +51 -0
  686. package/dist/setup/claude-code-install.js.map +1 -0
  687. package/dist/setup-mode.d.ts +34 -0
  688. package/dist/setup-mode.js +49 -0
  689. package/dist/setup-mode.js.map +1 -0
  690. package/dist/solver-nets/contracts.d.ts +2 -0
  691. package/dist/solver-nets/contracts.js +2 -0
  692. package/dist/solver-nets/contracts.js.map +1 -0
  693. package/dist/solver-nets/prediction-operator-ux.d.ts +112 -0
  694. package/dist/solver-nets/prediction-operator-ux.js +456 -0
  695. package/dist/solver-nets/prediction-operator-ux.js.map +1 -0
  696. package/dist/solver-nets/registry.d.ts +50 -0
  697. package/dist/solver-nets/registry.js +150 -0
  698. package/dist/solver-nets/registry.js.map +1 -0
  699. package/dist/solver-types/_swe-rebench-v2-aggregate.d.ts +31 -0
  700. package/dist/solver-types/_swe-rebench-v2-aggregate.js +49 -0
  701. package/dist/solver-types/_swe-rebench-v2-aggregate.js.map +1 -0
  702. package/dist/solver-types/_swe-rebench-v2-escrow.d.ts +27 -0
  703. package/dist/solver-types/_swe-rebench-v2-escrow.js +26 -0
  704. package/dist/solver-types/_swe-rebench-v2-escrow.js.map +1 -0
  705. package/dist/solver-types/_swe-rebench-v2-pool.d.ts +39 -0
  706. package/dist/solver-types/_swe-rebench-v2-pool.js +66 -0
  707. package/dist/solver-types/_swe-rebench-v2-pool.js.map +1 -0
  708. package/dist/solver-types/_swe-rebench-v2-state.d.ts +24 -0
  709. package/dist/solver-types/_swe-rebench-v2-state.js +54 -0
  710. package/dist/solver-types/_swe-rebench-v2-state.js.map +1 -0
  711. package/dist/solver-types/constants.d.ts +5 -0
  712. package/dist/solver-types/constants.js +6 -0
  713. package/dist/solver-types/constants.js.map +1 -0
  714. package/dist/solver-types/index.d.ts +10 -0
  715. package/dist/solver-types/index.js +30 -0
  716. package/dist/solver-types/index.js.map +1 -0
  717. package/dist/solver-types/learner-loop-test.d.ts +2 -0
  718. package/dist/solver-types/learner-loop-test.js +39 -0
  719. package/dist/solver-types/learner-loop-test.js.map +1 -0
  720. package/dist/solver-types/portfolio-v0.d.ts +2 -0
  721. package/dist/solver-types/portfolio-v0.js +13 -0
  722. package/dist/solver-types/portfolio-v0.js.map +1 -0
  723. package/dist/solver-types/prediction-apy-v0-auto.d.ts +27 -0
  724. package/dist/solver-types/prediction-apy-v0-auto.js +109 -0
  725. package/dist/solver-types/prediction-apy-v0-auto.js.map +1 -0
  726. package/dist/solver-types/prediction-apy-v0-template.d.ts +8 -0
  727. package/dist/solver-types/prediction-apy-v0-template.js +22 -0
  728. package/dist/solver-types/prediction-apy-v0-template.js.map +1 -0
  729. package/dist/solver-types/prediction-apy-v0.d.ts +3 -0
  730. package/dist/solver-types/prediction-apy-v0.js +25 -0
  731. package/dist/solver-types/prediction-apy-v0.js.map +1 -0
  732. package/dist/solver-types/prediction-v0-auto.d.ts +69 -0
  733. package/dist/solver-types/prediction-v0-auto.js +146 -0
  734. package/dist/solver-types/prediction-v0-auto.js.map +1 -0
  735. package/dist/solver-types/prediction-v0-template.d.ts +70 -0
  736. package/dist/solver-types/prediction-v0-template.js +145 -0
  737. package/dist/solver-types/prediction-v0-template.js.map +1 -0
  738. package/dist/solver-types/prediction-v0.d.ts +13 -0
  739. package/dist/solver-types/prediction-v0.js +31 -0
  740. package/dist/solver-types/prediction-v0.js.map +1 -0
  741. package/dist/solver-types/prediction-v1-auto.d.ts +122 -0
  742. package/dist/solver-types/prediction-v1-auto.js +366 -0
  743. package/dist/solver-types/prediction-v1-auto.js.map +1 -0
  744. package/dist/solver-types/prediction-v1.d.ts +11 -0
  745. package/dist/solver-types/prediction-v1.js +27 -0
  746. package/dist/solver-types/prediction-v1.js.map +1 -0
  747. package/dist/solver-types/solver-type.d.ts +53 -0
  748. package/dist/solver-types/solver-type.js +6 -0
  749. package/dist/solver-types/solver-type.js.map +1 -0
  750. package/dist/solver-types/swe-rebench-v2-auto.d.ts +38 -0
  751. package/dist/solver-types/swe-rebench-v2-auto.js +56 -0
  752. package/dist/solver-types/swe-rebench-v2-auto.js.map +1 -0
  753. package/dist/solver-types/swe-rebench-v2.d.ts +24 -0
  754. package/dist/solver-types/swe-rebench-v2.js +146 -0
  755. package/dist/solver-types/swe-rebench-v2.js.map +1 -0
  756. package/dist/solvernets/daemon-init.d.ts +291 -0
  757. package/dist/solvernets/daemon-init.js +431 -0
  758. package/dist/solvernets/daemon-init.js.map +1 -0
  759. package/dist/solvernets/launch-state-machine.d.ts +165 -0
  760. package/dist/solvernets/launch-state-machine.js +406 -0
  761. package/dist/solvernets/launch-state-machine.js.map +1 -0
  762. package/dist/solvernets/lifecycle-transitions.d.ts +183 -0
  763. package/dist/solvernets/lifecycle-transitions.js +386 -0
  764. package/dist/solvernets/lifecycle-transitions.js.map +1 -0
  765. package/dist/solvernets/manifest.d.ts +120 -0
  766. package/dist/solvernets/manifest.js +166 -0
  767. package/dist/solvernets/manifest.js.map +1 -0
  768. package/dist/solvernets/most-recent-wins.d.ts +77 -0
  769. package/dist/solvernets/most-recent-wins.js +82 -0
  770. package/dist/solvernets/most-recent-wins.js.map +1 -0
  771. package/dist/solvernets/registry-client-erc8004.d.ts +239 -0
  772. package/dist/solvernets/registry-client-erc8004.js +382 -0
  773. package/dist/solvernets/registry-client-erc8004.js.map +1 -0
  774. package/dist/solvernets/registry-client.d.ts +121 -0
  775. package/dist/solvernets/registry-client.js +19 -0
  776. package/dist/solvernets/registry-client.js.map +1 -0
  777. package/dist/solvernets/store.d.ts +298 -0
  778. package/dist/solvernets/store.js +271 -0
  779. package/dist/solvernets/store.js.map +1 -0
  780. package/dist/store/store.d.ts +175 -21
  781. package/dist/store/store.js +711 -46
  782. package/dist/store/store.js.map +1 -1
  783. package/dist/tasks/posting-service.d.ts +25 -0
  784. package/dist/tasks/posting-service.js +149 -0
  785. package/dist/tasks/posting-service.js.map +1 -0
  786. package/dist/tasks/signing.d.ts +4 -0
  787. package/dist/tasks/signing.js +18 -0
  788. package/dist/tasks/signing.js.map +1 -0
  789. package/dist/tasks/sources.d.ts +46 -0
  790. package/dist/tasks/sources.js +45 -0
  791. package/dist/tasks/sources.js.map +1 -0
  792. package/dist/templates/harnesses/alternative-harness/README.md.tmpl +44 -0
  793. package/dist/templates/harnesses/alternative-harness/gitignore.tmpl +3 -0
  794. package/dist/templates/harnesses/alternative-harness/jinn.manifest.json.tmpl +22 -0
  795. package/dist/templates/harnesses/alternative-harness/package.json.tmpl +26 -0
  796. package/dist/templates/harnesses/alternative-harness/src/coordinator.ts.tmpl +50 -0
  797. package/dist/templates/harnesses/alternative-harness/src/harness.ts.tmpl +31 -0
  798. package/dist/templates/harnesses/alternative-harness/src/index.ts.tmpl +44 -0
  799. package/dist/templates/harnesses/alternative-harness/src/mock-harness.ts.tmpl +41 -0
  800. package/dist/templates/harnesses/alternative-harness/src/phases/debrief.ts.tmpl +28 -0
  801. package/dist/templates/harnesses/alternative-harness/src/phases/execute.ts.tmpl +33 -0
  802. package/dist/templates/harnesses/alternative-harness/src/phases/improve.ts.tmpl +31 -0
  803. package/dist/templates/harnesses/alternative-harness/src/phases/memory.ts.tmpl +31 -0
  804. package/dist/templates/harnesses/alternative-harness/src/phases/orient.ts.tmpl +21 -0
  805. package/dist/templates/harnesses/alternative-harness/src/phases/plan.ts.tmpl +25 -0
  806. package/dist/templates/harnesses/alternative-harness/src/phases/strategize.ts.tmpl +29 -0
  807. package/dist/templates/harnesses/alternative-harness/test/coordinator.test.ts.tmpl +53 -0
  808. package/dist/templates/harnesses/alternative-harness/test/unit.test.ts.tmpl +55 -0
  809. package/dist/templates/harnesses/alternative-harness/tsconfig.json.tmpl +16 -0
  810. package/dist/templates/harnesses/evaluator/README.md.tmpl +36 -0
  811. package/dist/templates/harnesses/evaluator/gitignore.tmpl +3 -0
  812. package/dist/templates/harnesses/evaluator/jinn.manifest.json.tmpl +22 -0
  813. package/dist/templates/harnesses/evaluator/package.json.tmpl +26 -0
  814. package/dist/templates/harnesses/evaluator/src/index.ts.tmpl +35 -0
  815. package/dist/templates/harnesses/evaluator/test/unit.test.ts.tmpl +49 -0
  816. package/dist/templates/harnesses/evaluator/tsconfig.json.tmpl +16 -0
  817. package/dist/templates/harnesses/forecaster/README.md.tmpl +25 -0
  818. package/dist/templates/harnesses/forecaster/gitignore.tmpl +5 -0
  819. package/dist/templates/harnesses/forecaster/jinn.manifest.json.tmpl +22 -0
  820. package/dist/templates/harnesses/forecaster/package.json.tmpl +26 -0
  821. package/dist/templates/harnesses/forecaster/src/index.ts.tmpl +33 -0
  822. package/dist/templates/harnesses/forecaster/test/unit.test.ts.tmpl +42 -0
  823. package/dist/templates/harnesses/forecaster/tsconfig.json.tmpl +16 -0
  824. package/dist/trajectory/collector.d.ts +49 -0
  825. package/dist/trajectory/collector.js +86 -0
  826. package/dist/trajectory/collector.js.map +1 -0
  827. package/dist/trajectory/emit.d.ts +27 -0
  828. package/dist/trajectory/emit.js +40 -0
  829. package/dist/trajectory/emit.js.map +1 -0
  830. package/dist/trajectory/hash-chain.d.ts +18 -0
  831. package/dist/trajectory/hash-chain.js +23 -0
  832. package/dist/trajectory/hash-chain.js.map +1 -0
  833. package/dist/trajectory/index.d.ts +22 -0
  834. package/dist/trajectory/index.js +23 -0
  835. package/dist/trajectory/index.js.map +1 -0
  836. package/dist/trajectory/schema.d.ts +14 -14
  837. package/dist/trajectory/secret-scrub.d.ts +32 -0
  838. package/dist/trajectory/secret-scrub.js +51 -0
  839. package/dist/trajectory/secret-scrub.js.map +1 -0
  840. package/dist/trajectory/span-profile.d.ts +27 -0
  841. package/dist/trajectory/span-profile.js +51 -0
  842. package/dist/trajectory/span-profile.js.map +1 -0
  843. package/dist/trajectory/wrappers/http.d.ts +37 -0
  844. package/dist/trajectory/wrappers/http.js +85 -0
  845. package/dist/trajectory/wrappers/http.js.map +1 -0
  846. package/dist/trajectory/wrappers/mcp.d.ts +17 -0
  847. package/dist/trajectory/wrappers/mcp.js +58 -0
  848. package/dist/trajectory/wrappers/mcp.js.map +1 -0
  849. package/dist/trajectory/wrappers/subprocess.d.ts +32 -0
  850. package/dist/trajectory/wrappers/subprocess.js +70 -0
  851. package/dist/trajectory/wrappers/subprocess.js.map +1 -0
  852. package/dist/tx-retry.js +34 -9
  853. package/dist/tx-retry.js.map +1 -1
  854. package/dist/types/envelope.d.ts +1659 -0
  855. package/dist/types/envelope.js +133 -0
  856. package/dist/types/envelope.js.map +1 -0
  857. package/dist/types/index.d.ts +4 -4
  858. package/dist/types/index.js +4 -4
  859. package/dist/types/index.js.map +1 -1
  860. package/dist/types/payloads/index.d.ts +12 -0
  861. package/dist/types/payloads/index.js +60 -0
  862. package/dist/types/payloads/index.js.map +1 -0
  863. package/dist/types/payloads/portfolio-v0.d.ts +481 -0
  864. package/dist/types/payloads/portfolio-v0.js +94 -0
  865. package/dist/types/payloads/portfolio-v0.js.map +1 -0
  866. package/dist/types/payloads/prediction-apy-v0.d.ts +231 -0
  867. package/dist/types/payloads/prediction-apy-v0.js +63 -0
  868. package/dist/types/payloads/prediction-apy-v0.js.map +1 -0
  869. package/dist/types/payloads/prediction-v0.d.ts +262 -0
  870. package/dist/types/payloads/prediction-v0.js +73 -0
  871. package/dist/types/payloads/prediction-v0.js.map +1 -0
  872. package/dist/types/payloads/prediction-v1.d.ts +2 -0
  873. package/dist/types/payloads/prediction-v1.js +2 -0
  874. package/dist/types/payloads/prediction-v1.js.map +1 -0
  875. package/dist/types/portfolio.d.ts +31 -698
  876. package/dist/types/portfolio.js +20 -110
  877. package/dist/types/portfolio.js.map +1 -1
  878. package/dist/types/prediction-apy.d.ts +26 -366
  879. package/dist/types/prediction-apy.js +12 -68
  880. package/dist/types/prediction-apy.js.map +1 -1
  881. package/dist/types/prediction-v1.d.ts +2 -0
  882. package/dist/types/prediction-v1.js +2 -0
  883. package/dist/types/prediction-v1.js.map +1 -0
  884. package/dist/types/prediction.d.ts +546 -382
  885. package/dist/types/prediction.js +16 -87
  886. package/dist/types/prediction.js.map +1 -1
  887. package/dist/types/task-document.d.ts +1121 -0
  888. package/dist/types/task-document.js +99 -0
  889. package/dist/types/task-document.js.map +1 -0
  890. package/dist/types/task.d.ts +805 -0
  891. package/dist/types/task.js +88 -0
  892. package/dist/types/task.js.map +1 -0
  893. package/dist/types/window.d.ts +12 -0
  894. package/dist/types/window.js +6 -0
  895. package/dist/types/window.js.map +1 -0
  896. package/dist/util/path-safety.d.ts +21 -0
  897. package/dist/util/path-safety.js +28 -0
  898. package/dist/util/path-safety.js.map +1 -0
  899. package/dist/util/redact-rpc-urls.d.ts +5 -0
  900. package/dist/util/redact-rpc-urls.js +9 -0
  901. package/dist/util/redact-rpc-urls.js.map +1 -0
  902. package/dist/vendor/@jinn-network/sdk/README.md +89 -0
  903. package/dist/vendor/@jinn-network/sdk/dist/capabilities.d.ts +52 -0
  904. package/dist/vendor/@jinn-network/sdk/dist/capabilities.js +1 -0
  905. package/dist/vendor/@jinn-network/sdk/dist/checkpoint.d.ts +120 -0
  906. package/dist/vendor/@jinn-network/sdk/dist/checkpoint.js +39 -0
  907. package/dist/vendor/@jinn-network/sdk/dist/contracts.d.ts +144 -0
  908. package/dist/vendor/@jinn-network/sdk/dist/contracts.js +248 -0
  909. package/dist/vendor/@jinn-network/sdk/dist/harness.d.ts +120 -0
  910. package/dist/vendor/@jinn-network/sdk/dist/harness.js +31 -0
  911. package/dist/vendor/@jinn-network/sdk/dist/index.d.ts +2 -0
  912. package/dist/vendor/@jinn-network/sdk/dist/index.js +5 -0
  913. package/dist/vendor/@jinn-network/sdk/dist/json-schema.d.ts +32 -0
  914. package/dist/vendor/@jinn-network/sdk/dist/json-schema.js +131 -0
  915. package/dist/vendor/@jinn-network/sdk/dist/manifest.d.ts +69 -0
  916. package/dist/vendor/@jinn-network/sdk/dist/manifest.js +3 -0
  917. package/dist/vendor/@jinn-network/sdk/dist/payloads/prediction-v1.d.ts +223 -0
  918. package/dist/vendor/@jinn-network/sdk/dist/payloads/prediction-v1.js +64 -0
  919. package/dist/vendor/@jinn-network/sdk/dist/payloads/swe-rebench-v2.d.ts +107 -0
  920. package/dist/vendor/@jinn-network/sdk/dist/payloads/swe-rebench-v2.js +51 -0
  921. package/dist/vendor/@jinn-network/sdk/dist/plugins.d.ts +36 -0
  922. package/dist/vendor/@jinn-network/sdk/dist/plugins.js +54 -0
  923. package/dist/vendor/@jinn-network/sdk/dist/prediction-v1.d.ts +870 -0
  924. package/dist/vendor/@jinn-network/sdk/dist/prediction-v1.js +80 -0
  925. package/dist/vendor/@jinn-network/sdk/dist/solvernets/index.d.ts +6 -0
  926. package/dist/vendor/@jinn-network/sdk/dist/solvernets/index.js +8 -0
  927. package/dist/vendor/@jinn-network/sdk/dist/solvernets/manifest-schema.d.ts +559 -0
  928. package/dist/vendor/@jinn-network/sdk/dist/solvernets/manifest-schema.js +126 -0
  929. package/dist/vendor/@jinn-network/sdk/dist/solvernets/prediction-v1.d.ts +6 -0
  930. package/dist/vendor/@jinn-network/sdk/dist/solvernets/prediction-v1.js +3 -0
  931. package/dist/vendor/@jinn-network/sdk/dist/solvernets/swe-rebench-v2.d.ts +4 -0
  932. package/dist/vendor/@jinn-network/sdk/dist/solvernets/swe-rebench-v2.js +2 -0
  933. package/dist/vendor/@jinn-network/sdk/dist/swe-rebench-v2.d.ts +66 -0
  934. package/dist/vendor/@jinn-network/sdk/dist/swe-rebench-v2.js +44 -0
  935. package/dist/vendor/@jinn-network/sdk/dist/types.d.ts +116 -0
  936. package/dist/vendor/@jinn-network/sdk/dist/types.js +21 -0
  937. package/dist/vendor/@jinn-network/sdk/package.json +43 -0
  938. package/dist/venues/hyperliquid/account-value.d.ts +1 -1
  939. package/dist/venues/hyperliquid/account-value.js +1 -1
  940. package/dist/venues/polymarket/client.d.ts +77 -0
  941. package/dist/venues/polymarket/client.js +309 -0
  942. package/dist/venues/polymarket/client.js.map +1 -0
  943. package/dist/withdraw/run-withdraw-plan.js +0 -2
  944. package/dist/withdraw/run-withdraw-plan.js.map +1 -1
  945. package/dist/x402/acquire.d.ts +14 -3
  946. package/dist/x402/acquire.js +28 -11
  947. package/dist/x402/acquire.js.map +1 -1
  948. package/dist/x402/handler.d.ts +15 -3
  949. package/dist/x402/handler.js +67 -24
  950. package/dist/x402/handler.js.map +1 -1
  951. package/package.json +46 -15
  952. package/plugins/claude-code-learner/.claude-plugin/plugin.json +9 -0
  953. package/plugins/claude-code-learner/AGENTS.md +31 -0
  954. package/plugins/claude-code-learner/CLAUDE.md +33 -0
  955. package/plugins/claude-code-learner/README.md +57 -0
  956. package/plugins/claude-code-learner/hooks/hooks.json +16 -0
  957. package/plugins/claude-code-learner/hooks/session-start +38 -0
  958. package/plugins/claude-code-learner/skills/learn/SKILL.md +405 -0
  959. package/plugins/claude-code-learner/skills/learn/analyst-prompt.md +68 -0
  960. package/plugins/claude-code-learner/skills/learn/consolidator-prompt.md +94 -0
  961. package/plugins/claude-code-learner/skills/learn/explorer-prompt.md +53 -0
  962. package/plugins/claude-code-learner/skills/learn/planner-prompt.md +87 -0
  963. package/plugins/claude-code-learner/skills/learn/promoter-prompt.md +113 -0
  964. package/plugins/claude-code-learner/skills/learn/step-worker-prompt.md +47 -0
  965. package/plugins/claude-code-learner/skills/learn/strategist-prompt.md +85 -0
  966. package/plugins/jinn-prediction-plugin/.claude-plugin/plugin.json +19 -0
  967. package/plugins/jinn-prediction-plugin/.mcp.json +8 -0
  968. package/plugins/jinn-prediction-plugin/GEMINI.md +7 -0
  969. package/plugins/jinn-prediction-plugin/gemini-extension.json +13 -0
  970. package/plugins/jinn-prediction-plugin/jinn.plugin.json +26 -0
  971. package/plugins/jinn-prediction-plugin/mcp/polymarket-server.mjs +322 -0
  972. package/plugins/jinn-prediction-plugin/schemas/prediction-v0-solution.schema.json +12 -0
  973. package/plugins/jinn-prediction-plugin/schemas/prediction-v0-task.schema.json +25 -0
  974. package/plugins/jinn-prediction-plugin/schemas/prediction-v0-verdict.schema.json +11 -0
  975. package/plugins/jinn-prediction-plugin/schemas/prediction-v1-solution.schema.json +34 -0
  976. package/plugins/jinn-prediction-plugin/schemas/prediction-v1-task.schema.json +118 -0
  977. package/plugins/jinn-prediction-plugin/schemas/prediction-v1-verdict.schema.json +84 -0
  978. package/plugins/jinn-prediction-plugin/skills/base-rate-forecasting/SKILL.md +3 -0
  979. package/plugins/jinn-prediction-plugin/skills/calibration/SKILL.md +3 -0
  980. package/plugins/jinn-prediction-plugin/skills/common-biases/SKILL.md +3 -0
  981. package/plugins/jinn-prediction-plugin/skills/polymarket-task-handling/SKILL.md +5 -0
  982. package/plugins/jinn-prediction-plugin/skills/prediction-corpus-retrieval/SKILL.md +35 -0
  983. package/plugins/network-tools/.claude-plugin/plugin.json +12 -0
  984. package/plugins/network-tools/jinn.plugin.json +29 -0
  985. package/plugins/network-tools/mcp/jinn-client-server.mjs +110 -0
  986. package/plugins/swe-rebench-v2-runtime/.claude-plugin/plugin.json +9 -0
  987. package/plugins/swe-rebench-v2-runtime/README.md +11 -0
  988. package/plugins/swe-rebench-v2-runtime/jinn.plugin.json +12 -0
  989. package/plugins/swe-rebench-v2-runtime/skills/orient/SKILL.md +25 -0
  990. package/plugins/swe-rebench-v2-runtime/skills/plan/SKILL.md +24 -0
  991. package/skills/jinn-operator/SKILL.md +120 -101
  992. package/templates/harnesses/alternative-harness/README.md.tmpl +44 -0
  993. package/templates/harnesses/alternative-harness/gitignore.tmpl +3 -0
  994. package/templates/harnesses/alternative-harness/jinn.manifest.json.tmpl +22 -0
  995. package/templates/harnesses/alternative-harness/package.json.tmpl +26 -0
  996. package/templates/harnesses/alternative-harness/src/coordinator.ts.tmpl +50 -0
  997. package/templates/harnesses/alternative-harness/src/harness.ts.tmpl +31 -0
  998. package/templates/harnesses/alternative-harness/src/index.ts.tmpl +44 -0
  999. package/templates/harnesses/alternative-harness/src/mock-harness.ts.tmpl +41 -0
  1000. package/templates/harnesses/alternative-harness/src/phases/debrief.ts.tmpl +28 -0
  1001. package/templates/harnesses/alternative-harness/src/phases/execute.ts.tmpl +33 -0
  1002. package/templates/harnesses/alternative-harness/src/phases/improve.ts.tmpl +31 -0
  1003. package/templates/harnesses/alternative-harness/src/phases/memory.ts.tmpl +31 -0
  1004. package/templates/harnesses/alternative-harness/src/phases/orient.ts.tmpl +21 -0
  1005. package/templates/harnesses/alternative-harness/src/phases/plan.ts.tmpl +25 -0
  1006. package/templates/harnesses/alternative-harness/src/phases/strategize.ts.tmpl +29 -0
  1007. package/templates/harnesses/alternative-harness/test/coordinator.test.ts.tmpl +53 -0
  1008. package/templates/harnesses/alternative-harness/test/unit.test.ts.tmpl +55 -0
  1009. package/templates/harnesses/alternative-harness/tsconfig.json.tmpl +16 -0
  1010. package/templates/harnesses/evaluator/README.md.tmpl +36 -0
  1011. package/templates/harnesses/evaluator/gitignore.tmpl +3 -0
  1012. package/templates/harnesses/evaluator/jinn.manifest.json.tmpl +22 -0
  1013. package/templates/harnesses/evaluator/package.json.tmpl +26 -0
  1014. package/templates/harnesses/evaluator/src/index.ts.tmpl +35 -0
  1015. package/templates/harnesses/evaluator/test/unit.test.ts.tmpl +49 -0
  1016. package/templates/harnesses/evaluator/tsconfig.json.tmpl +16 -0
  1017. package/templates/harnesses/forecaster/README.md.tmpl +25 -0
  1018. package/templates/harnesses/forecaster/gitignore.tmpl +5 -0
  1019. package/templates/harnesses/forecaster/jinn.manifest.json.tmpl +22 -0
  1020. package/templates/harnesses/forecaster/package.json.tmpl +26 -0
  1021. package/templates/harnesses/forecaster/src/index.ts.tmpl +33 -0
  1022. package/templates/harnesses/forecaster/test/unit.test.ts.tmpl +42 -0
  1023. package/templates/harnesses/forecaster/tsconfig.json.tmpl +16 -0
  1024. package/dist/adapters/claim-registry/abi.d.ts +0 -127
  1025. package/dist/adapters/claim-registry/abi.js +0 -93
  1026. package/dist/adapters/claim-registry/abi.js.map +0 -1
  1027. package/dist/adapters/claim-registry/client.d.ts +0 -89
  1028. package/dist/adapters/claim-registry/client.js +0 -205
  1029. package/dist/adapters/claim-registry/client.js.map +0 -1
  1030. package/dist/adapters/mech/claim-policy.d.ts +0 -40
  1031. package/dist/adapters/mech/claim-policy.js +0 -104
  1032. package/dist/adapters/mech/claim-policy.js.map +0 -1
  1033. package/dist/bin/jinn-mcp.d.ts +0 -2
  1034. package/dist/bin/jinn-mcp.js +0 -10
  1035. package/dist/bin/jinn-mcp.js.map +0 -1
  1036. package/dist/cli/commands/intents.d.ts +0 -17
  1037. package/dist/cli/commands/intents.js +0 -489
  1038. package/dist/cli/commands/intents.js.map +0 -1
  1039. package/dist/cli/commands/plugin-install.js +0 -803
  1040. package/dist/cli/commands/plugin-install.js.map +0 -1
  1041. package/dist/cli/commands/submit-intent.js +0 -245
  1042. package/dist/cli/commands/submit-intent.js.map +0 -1
  1043. package/dist/cli/intent-registry-access.d.ts +0 -62
  1044. package/dist/cli/intent-registry-access.js +0 -165
  1045. package/dist/cli/intent-registry-access.js.map +0 -1
  1046. package/dist/discovery/registry.d.ts +0 -97
  1047. package/dist/discovery/registry.js +0 -177
  1048. package/dist/discovery/registry.js.map +0 -1
  1049. package/dist/discovery/subgraph.d.ts +0 -37
  1050. package/dist/discovery/subgraph.js +0 -87
  1051. package/dist/discovery/subgraph.js.map +0 -1
  1052. package/dist/intents/kinds/constants.d.ts +0 -5
  1053. package/dist/intents/kinds/constants.js +0 -6
  1054. package/dist/intents/kinds/constants.js.map +0 -1
  1055. package/dist/intents/kinds/index.d.ts +0 -28
  1056. package/dist/intents/kinds/index.js +0 -50
  1057. package/dist/intents/kinds/index.js.map +0 -1
  1058. package/dist/intents/kinds/portfolio-v0.d.ts +0 -2
  1059. package/dist/intents/kinds/portfolio-v0.js +0 -13
  1060. package/dist/intents/kinds/portfolio-v0.js.map +0 -1
  1061. package/dist/intents/kinds/prediction-apy-v0.d.ts +0 -3
  1062. package/dist/intents/kinds/prediction-apy-v0.js +0 -21
  1063. package/dist/intents/kinds/prediction-apy-v0.js.map +0 -1
  1064. package/dist/intents/kinds/prediction-v0.d.ts +0 -3
  1065. package/dist/intents/kinds/prediction-v0.js +0 -32
  1066. package/dist/intents/kinds/prediction-v0.js.map +0 -1
  1067. package/dist/intents/kinds/spec-kind.d.ts +0 -38
  1068. package/dist/intents/kinds/spec-kind.js +0 -6
  1069. package/dist/intents/kinds/spec-kind.js.map +0 -1
  1070. package/dist/intents/posting-service.d.ts +0 -26
  1071. package/dist/intents/posting-service.js +0 -218
  1072. package/dist/intents/posting-service.js.map +0 -1
  1073. package/dist/intents/prediction-apy-v0-auto.d.ts +0 -11
  1074. package/dist/intents/prediction-apy-v0-auto.js +0 -46
  1075. package/dist/intents/prediction-apy-v0-auto.js.map +0 -1
  1076. package/dist/intents/prediction-apy-v0-template.d.ts +0 -8
  1077. package/dist/intents/prediction-apy-v0-template.js +0 -22
  1078. package/dist/intents/prediction-apy-v0-template.js.map +0 -1
  1079. package/dist/intents/prediction-v0-auto.d.ts +0 -53
  1080. package/dist/intents/prediction-v0-auto.js +0 -84
  1081. package/dist/intents/prediction-v0-auto.js.map +0 -1
  1082. package/dist/intents/prediction-v0-template.d.ts +0 -70
  1083. package/dist/intents/prediction-v0-template.js +0 -145
  1084. package/dist/intents/prediction-v0-template.js.map +0 -1
  1085. package/dist/intents/sources.d.ts +0 -39
  1086. package/dist/intents/sources.js +0 -42
  1087. package/dist/intents/sources.js.map +0 -1
  1088. package/dist/restorer/engine/canonical-json.d.ts +0 -18
  1089. package/dist/restorer/engine/canonical-json.js +0 -59
  1090. package/dist/restorer/engine/canonical-json.js.map +0 -1
  1091. package/dist/restorer/engine/claim.d.ts +0 -69
  1092. package/dist/restorer/engine/claim.js +0 -104
  1093. package/dist/restorer/engine/claim.js.map +0 -1
  1094. package/dist/restorer/engine/delivery.d.ts +0 -52
  1095. package/dist/restorer/engine/delivery.js +0 -63
  1096. package/dist/restorer/engine/delivery.js.map +0 -1
  1097. package/dist/restorer/engine/engine.d.ts +0 -213
  1098. package/dist/restorer/engine/engine.js +0 -769
  1099. package/dist/restorer/engine/engine.js.map +0 -1
  1100. package/dist/restorer/engine/manifest-assembly.d.ts +0 -67
  1101. package/dist/restorer/engine/manifest-assembly.js +0 -79
  1102. package/dist/restorer/engine/manifest-assembly.js.map +0 -1
  1103. package/dist/restorer/engine/packaging.d.ts +0 -87
  1104. package/dist/restorer/engine/packaging.js +0 -350
  1105. package/dist/restorer/engine/packaging.js.map +0 -1
  1106. package/dist/restorer/engine/persistence.d.ts +0 -170
  1107. package/dist/restorer/engine/persistence.js +0 -381
  1108. package/dist/restorer/engine/persistence.js.map +0 -1
  1109. package/dist/restorer/engine/recovery.d.ts +0 -22
  1110. package/dist/restorer/engine/recovery.js +0 -24
  1111. package/dist/restorer/engine/recovery.js.map +0 -1
  1112. package/dist/restorer/engine/registry.d.ts +0 -62
  1113. package/dist/restorer/engine/registry.js +0 -73
  1114. package/dist/restorer/engine/registry.js.map +0 -1
  1115. package/dist/restorer/engine/signing.d.ts +0 -30
  1116. package/dist/restorer/engine/signing.js +0 -39
  1117. package/dist/restorer/engine/signing.js.map +0 -1
  1118. package/dist/restorer/engine/state.d.ts +0 -42
  1119. package/dist/restorer/engine/state.js +0 -87
  1120. package/dist/restorer/engine/state.js.map +0 -1
  1121. package/dist/restorer/impls/claude-mcp-hyperliquid/api-wallet.d.ts +0 -64
  1122. package/dist/restorer/impls/claude-mcp-hyperliquid/api-wallet.js.map +0 -1
  1123. package/dist/restorer/impls/claude-mcp-hyperliquid/index.d.ts +0 -104
  1124. package/dist/restorer/impls/claude-mcp-hyperliquid/index.js +0 -721
  1125. package/dist/restorer/impls/claude-mcp-hyperliquid/index.js.map +0 -1
  1126. package/dist/restorer/impls/claude-mcp-hyperliquid/mcp-tools.js.map +0 -1
  1127. package/dist/restorer/impls/claude-mcp-hyperliquid/safety-rails.js.map +0 -1
  1128. package/dist/restorer/impls/claude-mcp-hyperliquid/session-orchestrator.d.ts +0 -97
  1129. package/dist/restorer/impls/claude-mcp-hyperliquid/session-orchestrator.js +0 -226
  1130. package/dist/restorer/impls/claude-mcp-hyperliquid/session-orchestrator.js.map +0 -1
  1131. package/dist/restorer/impls/claude-mcp-prediction/index.d.ts +0 -44
  1132. package/dist/restorer/impls/claude-mcp-prediction/index.js +0 -239
  1133. package/dist/restorer/impls/claude-mcp-prediction/index.js.map +0 -1
  1134. package/dist/restorer/impls/claude-mcp-prediction/mcp-tools.js +0 -135
  1135. package/dist/restorer/impls/claude-mcp-prediction/mcp-tools.js.map +0 -1
  1136. package/dist/restorer/impls/claude-mcp-prediction/prompt.d.ts +0 -8
  1137. package/dist/restorer/impls/claude-mcp-prediction/prompt.js +0 -54
  1138. package/dist/restorer/impls/claude-mcp-prediction/prompt.js.map +0 -1
  1139. package/dist/restorer/impls/claude-mcp-prediction/session-orchestrator.d.ts +0 -36
  1140. package/dist/restorer/impls/claude-mcp-prediction/session-orchestrator.js +0 -137
  1141. package/dist/restorer/impls/claude-mcp-prediction/session-orchestrator.js.map +0 -1
  1142. package/dist/restorer/impls/claude-mcp-prediction/types.d.ts +0 -84
  1143. package/dist/restorer/impls/claude-mcp-prediction/types.js +0 -6
  1144. package/dist/restorer/impls/claude-mcp-prediction/types.js.map +0 -1
  1145. package/dist/restorer/impls/claude-mcp-prediction-apy/index.d.ts +0 -34
  1146. package/dist/restorer/impls/claude-mcp-prediction-apy/index.js +0 -233
  1147. package/dist/restorer/impls/claude-mcp-prediction-apy/index.js.map +0 -1
  1148. package/dist/restorer/impls/claude-mcp-prediction-apy/mcp-tools.js +0 -136
  1149. package/dist/restorer/impls/claude-mcp-prediction-apy/mcp-tools.js.map +0 -1
  1150. package/dist/restorer/impls/claude-mcp-prediction-apy/prompt.d.ts +0 -7
  1151. package/dist/restorer/impls/claude-mcp-prediction-apy/prompt.js +0 -46
  1152. package/dist/restorer/impls/claude-mcp-prediction-apy/prompt.js.map +0 -1
  1153. package/dist/restorer/impls/claude-mcp-prediction-apy/session-orchestrator.d.ts +0 -27
  1154. package/dist/restorer/impls/claude-mcp-prediction-apy/session-orchestrator.js +0 -128
  1155. package/dist/restorer/impls/claude-mcp-prediction-apy/session-orchestrator.js.map +0 -1
  1156. package/dist/restorer/impls/claude-mcp-prediction-apy/types.d.ts +0 -64
  1157. package/dist/restorer/impls/claude-mcp-prediction-apy/types.js +0 -6
  1158. package/dist/restorer/impls/claude-mcp-prediction-apy/types.js.map +0 -1
  1159. package/dist/restorer/impls/evaluation-context.d.ts +0 -16
  1160. package/dist/restorer/impls/evaluation-context.js +0 -18
  1161. package/dist/restorer/impls/evaluation-context.js.map +0 -1
  1162. package/dist/restorer/impls/index.d.ts +0 -46
  1163. package/dist/restorer/impls/index.js +0 -88
  1164. package/dist/restorer/impls/index.js.map +0 -1
  1165. package/dist/restorer/impls/legacy-claude/index.d.ts +0 -52
  1166. package/dist/restorer/impls/legacy-claude/index.js +0 -140
  1167. package/dist/restorer/impls/legacy-claude/index.js.map +0 -1
  1168. package/dist/restorer/impls/portfolio-v0-evaluator/canonical-metrics.d.ts +0 -68
  1169. package/dist/restorer/impls/portfolio-v0-evaluator/canonical-metrics.js +0 -117
  1170. package/dist/restorer/impls/portfolio-v0-evaluator/canonical-metrics.js.map +0 -1
  1171. package/dist/restorer/impls/portfolio-v0-evaluator/checks/availability.js.map +0 -1
  1172. package/dist/restorer/impls/portfolio-v0-evaluator/checks/consistency.d.ts +0 -78
  1173. package/dist/restorer/impls/portfolio-v0-evaluator/checks/consistency.js +0 -274
  1174. package/dist/restorer/impls/portfolio-v0-evaluator/checks/consistency.js.map +0 -1
  1175. package/dist/restorer/impls/portfolio-v0-evaluator/checks/eligibility.d.ts +0 -23
  1176. package/dist/restorer/impls/portfolio-v0-evaluator/checks/eligibility.js +0 -49
  1177. package/dist/restorer/impls/portfolio-v0-evaluator/checks/eligibility.js.map +0 -1
  1178. package/dist/restorer/impls/portfolio-v0-evaluator/checks/integrity.d.ts +0 -25
  1179. package/dist/restorer/impls/portfolio-v0-evaluator/checks/integrity.js +0 -44
  1180. package/dist/restorer/impls/portfolio-v0-evaluator/checks/integrity.js.map +0 -1
  1181. package/dist/restorer/impls/portfolio-v0-evaluator/checks/spec.d.ts +0 -17
  1182. package/dist/restorer/impls/portfolio-v0-evaluator/checks/spec.js +0 -43
  1183. package/dist/restorer/impls/portfolio-v0-evaluator/checks/spec.js.map +0 -1
  1184. package/dist/restorer/impls/portfolio-v0-evaluator/index.d.ts +0 -44
  1185. package/dist/restorer/impls/portfolio-v0-evaluator/index.js +0 -440
  1186. package/dist/restorer/impls/portfolio-v0-evaluator/index.js.map +0 -1
  1187. package/dist/restorer/impls/portfolio-v0-evaluator/score.js.map +0 -1
  1188. package/dist/restorer/impls/portfolio-v0-evaluator/types.d.ts +0 -34
  1189. package/dist/restorer/impls/portfolio-v0-evaluator/types.js.map +0 -1
  1190. package/dist/restorer/impls/prediction-apy-v0-baseline/index.d.ts +0 -40
  1191. package/dist/restorer/impls/prediction-apy-v0-baseline/index.js +0 -107
  1192. package/dist/restorer/impls/prediction-apy-v0-baseline/index.js.map +0 -1
  1193. package/dist/restorer/impls/prediction-apy-v0-baseline/strategy.js.map +0 -1
  1194. package/dist/restorer/impls/prediction-apy-v0-baseline/types.js.map +0 -1
  1195. package/dist/restorer/impls/prediction-apy-v0-evaluator/canonical-metrics.d.ts +0 -6
  1196. package/dist/restorer/impls/prediction-apy-v0-evaluator/canonical-metrics.js +0 -11
  1197. package/dist/restorer/impls/prediction-apy-v0-evaluator/canonical-metrics.js.map +0 -1
  1198. package/dist/restorer/impls/prediction-apy-v0-evaluator/index.d.ts +0 -42
  1199. package/dist/restorer/impls/prediction-apy-v0-evaluator/index.js +0 -208
  1200. package/dist/restorer/impls/prediction-apy-v0-evaluator/index.js.map +0 -1
  1201. package/dist/restorer/impls/prediction-apy-v0-evaluator/parse-submission.d.ts +0 -7
  1202. package/dist/restorer/impls/prediction-apy-v0-evaluator/parse-submission.js +0 -29
  1203. package/dist/restorer/impls/prediction-apy-v0-evaluator/parse-submission.js.map +0 -1
  1204. package/dist/restorer/impls/prediction-apy-v0-evaluator/score.js.map +0 -1
  1205. package/dist/restorer/impls/prediction-apy-v0-evaluator/types.js.map +0 -1
  1206. package/dist/restorer/impls/prediction-v0-baseline/index.d.ts +0 -31
  1207. package/dist/restorer/impls/prediction-v0-baseline/index.js +0 -100
  1208. package/dist/restorer/impls/prediction-v0-baseline/index.js.map +0 -1
  1209. package/dist/restorer/impls/prediction-v0-baseline/strategy.d.ts +0 -8
  1210. package/dist/restorer/impls/prediction-v0-baseline/strategy.js +0 -41
  1211. package/dist/restorer/impls/prediction-v0-baseline/strategy.js.map +0 -1
  1212. package/dist/restorer/impls/prediction-v0-baseline/types.d.ts +0 -7
  1213. package/dist/restorer/impls/prediction-v0-baseline/types.js.map +0 -1
  1214. package/dist/restorer/impls/prediction-v0-evaluator/canonical-metrics.d.ts +0 -20
  1215. package/dist/restorer/impls/prediction-v0-evaluator/canonical-metrics.js.map +0 -1
  1216. package/dist/restorer/impls/prediction-v0-evaluator/checks/availability.d.ts +0 -9
  1217. package/dist/restorer/impls/prediction-v0-evaluator/checks/availability.js.map +0 -1
  1218. package/dist/restorer/impls/prediction-v0-evaluator/checks/eligibility.d.ts +0 -3
  1219. package/dist/restorer/impls/prediction-v0-evaluator/checks/eligibility.js.map +0 -1
  1220. package/dist/restorer/impls/prediction-v0-evaluator/checks/integrity.d.ts +0 -13
  1221. package/dist/restorer/impls/prediction-v0-evaluator/checks/integrity.js +0 -111
  1222. package/dist/restorer/impls/prediction-v0-evaluator/checks/integrity.js.map +0 -1
  1223. package/dist/restorer/impls/prediction-v0-evaluator/checks/spec.d.ts +0 -5
  1224. package/dist/restorer/impls/prediction-v0-evaluator/checks/spec.js.map +0 -1
  1225. package/dist/restorer/impls/prediction-v0-evaluator/index.d.ts +0 -36
  1226. package/dist/restorer/impls/prediction-v0-evaluator/index.js +0 -234
  1227. package/dist/restorer/impls/prediction-v0-evaluator/index.js.map +0 -1
  1228. package/dist/restorer/impls/prediction-v0-evaluator/score.js.map +0 -1
  1229. package/dist/restorer/impls/prediction-v0-evaluator/types.js.map +0 -1
  1230. package/dist/restorer/types.d.ts +0 -194
  1231. package/dist/restorer/types.js +0 -28
  1232. package/dist/restorer/types.js.map +0 -1
  1233. package/dist/types/desired-state.d.ts +0 -94
  1234. package/dist/types/desired-state.js +0 -36
  1235. package/dist/types/desired-state.js.map +0 -1
  1236. /package/dist/cli/commands/{plugin-install.d.ts → solver-nets.d.ts} +0 -0
  1237. /package/dist/cli/commands/{submit-intent.d.ts → tasks.d.ts} +0 -0
  1238. /package/dist/{restorer/impls/prediction-apy-v0-baseline → harnesses/impls/claude-code-learner}/types.js +0 -0
  1239. /package/dist/{restorer → harnesses}/impls/claude-mcp-hyperliquid/api-wallet.js +0 -0
  1240. /package/dist/{restorer → harnesses}/impls/claude-mcp-hyperliquid/mcp-tools.d.ts +0 -0
  1241. /package/dist/{restorer → harnesses}/impls/claude-mcp-hyperliquid/mcp-tools.js +0 -0
  1242. /package/dist/{restorer → harnesses}/impls/claude-mcp-hyperliquid/safety-rails.d.ts +0 -0
  1243. /package/dist/{restorer → harnesses}/impls/claude-mcp-hyperliquid/safety-rails.js +0 -0
  1244. /package/dist/{restorer → harnesses}/impls/claude-mcp-prediction/mcp-tools.d.ts +0 -0
  1245. /package/dist/{restorer → harnesses}/impls/claude-mcp-prediction-apy/mcp-tools.d.ts +0 -0
  1246. /package/dist/{restorer → harnesses}/impls/portfolio-v0-evaluator/checks/availability.d.ts +0 -0
  1247. /package/dist/{restorer → harnesses}/impls/portfolio-v0-evaluator/checks/availability.js +0 -0
  1248. /package/dist/{restorer → harnesses}/impls/portfolio-v0-evaluator/score.d.ts +0 -0
  1249. /package/dist/{restorer → harnesses}/impls/portfolio-v0-evaluator/score.js +0 -0
  1250. /package/dist/{restorer → harnesses}/impls/portfolio-v0-evaluator/types.js +0 -0
  1251. /package/dist/{restorer → harnesses}/impls/prediction-apy-v0-baseline/strategy.d.ts +0 -0
  1252. /package/dist/{restorer → harnesses}/impls/prediction-apy-v0-baseline/strategy.js +0 -0
  1253. /package/dist/{restorer → harnesses}/impls/prediction-apy-v0-baseline/types.d.ts +0 -0
  1254. /package/dist/{restorer/impls/prediction-apy-v0-evaluator → harnesses/impls/prediction-apy-v0-baseline}/types.js +0 -0
  1255. /package/dist/{restorer → harnesses}/impls/prediction-apy-v0-evaluator/score.d.ts +0 -0
  1256. /package/dist/{restorer → harnesses}/impls/prediction-apy-v0-evaluator/score.js +0 -0
  1257. /package/dist/{restorer → harnesses}/impls/prediction-apy-v0-evaluator/types.d.ts +0 -0
  1258. /package/dist/{restorer/impls/prediction-v0-baseline → harnesses/impls/prediction-apy-v0-evaluator}/types.js +0 -0
  1259. /package/dist/{restorer/impls/prediction-v0-evaluator → harnesses/impls/prediction-v0-baseline}/types.js +0 -0
  1260. /package/dist/{restorer → harnesses}/impls/prediction-v0-evaluator/canonical-metrics.js +0 -0
  1261. /package/dist/{restorer → harnesses}/impls/prediction-v0-evaluator/checks/availability.js +0 -0
  1262. /package/dist/{restorer → harnesses}/impls/prediction-v0-evaluator/checks/eligibility.js +0 -0
  1263. /package/dist/{restorer → harnesses}/impls/prediction-v0-evaluator/checks/spec.js +0 -0
  1264. /package/dist/{restorer → harnesses}/impls/prediction-v0-evaluator/score.d.ts +0 -0
  1265. /package/dist/{restorer → harnesses}/impls/prediction-v0-evaluator/score.js +0 -0
  1266. /package/dist/{restorer → harnesses}/impls/prediction-v0-evaluator/types.d.ts +0 -0
@@ -0,0 +1,1544 @@
1
+ /**
2
+ * Harness engine — main TaskEngine class.
3
+ *
4
+ * §6.3, §6.5 of spec/2026-04-17-portfolio-v0-design.md
5
+ *
6
+ * Orchestrates the state machine lifecycle for each observed task.
7
+ * Transition method bodies are stubs; subsequent tasks fill them in.
8
+ */
9
+ import { join } from 'node:path';
10
+ import { createHash, randomUUID } from 'node:crypto';
11
+ import { keccak256, toBytes } from 'viem';
12
+ import { TaskRunPersistence } from './persistence.js';
13
+ import { TaskRunState, MissingEvidenceHashError } from './state.js';
14
+ import { provisionWorkingDir, provisionImplStateDir, walkArtifacts, uploadArtifacts, } from './packaging.js';
15
+ import { assembleAndSignEnvelope, } from './envelope-assembly.js';
16
+ import { deliverAndClaim, } from './delivery.js';
17
+ import { SkippableError } from '../types.js';
18
+ import { submitEvaluatorFeedback, codeDigestSha256ToBytes32, modeStringToFlag, } from '../../erc8004/index.js';
19
+ import { TrajectoryCollector, emitTrajectory } from '../../trajectory/index.js';
20
+ import { buildInfo } from '../../build-info.js';
21
+ import { getSolverNetContract } from '../../vendor/@jinn-network/sdk/dist/solvernets/index.js';
22
+ import { runHarnessWithFreezeFence, } from '../../daemon/freeze-fence.js';
23
+ // ── Sentinel error ────────────────────────────────────────────────────────────
24
+ export class NotImplementedError extends Error {
25
+ transitionName;
26
+ constructor(transitionName) {
27
+ super(`[NotImplemented] ${transitionName} — fill in via subsequent task`);
28
+ this.name = 'NotImplementedError';
29
+ this.transitionName = transitionName;
30
+ }
31
+ }
32
+ /** Map task role to the operator role it requires in `joinedSolverNets`. */
33
+ function joinedRoleForTaskRole(taskRole) {
34
+ return taskRole === 'evaluation' ? 'evaluator' : 'solver';
35
+ }
36
+ /**
37
+ * Build a `JoinedSolverNetsView` from the raw operator-config block.
38
+ *
39
+ * The config carries the full `JoinedSolverNetEntry` shape (manifestCid,
40
+ * name, roles, harness, model, plugins, ...). The engine only needs
41
+ * `roles` and the CID-keyed lookup, so this helper narrows it.
42
+ */
43
+ export function joinedSolverNetsViewFromConfig(joined) {
44
+ if (!joined)
45
+ return undefined;
46
+ const map = new Map();
47
+ for (const [key, entry] of Object.entries(joined)) {
48
+ // The config keys joined nets by `manifestCid`. We accept either the key
49
+ // or the entry's `manifestCid` field; in practice they're identical.
50
+ const cid = entry.manifestCid ?? key;
51
+ map.set(cid, { roles: entry.roles });
52
+ }
53
+ return {
54
+ get: (cid) => map.get(cid),
55
+ manifestCids: () => [...map.keys()],
56
+ };
57
+ }
58
+ // ── TaskEngine ─────────────────────────────────────────────────────────
59
+ export class TaskEngine {
60
+ persistence;
61
+ paths;
62
+ packagingDeps;
63
+ envelopeDeps;
64
+ deliveryDeps;
65
+ implRegistry;
66
+ solverNetRegistry;
67
+ joinedSolverNets;
68
+ manifestResolver;
69
+ identityPublisher;
70
+ reputationFeedback;
71
+ operatorConfig;
72
+ /**
73
+ * Operator-configured harness mode. Defaults to 'train' when absent.
74
+ * Propagated to HarnessContext.mode for each runImpl dispatch.
75
+ */
76
+ harnessMode;
77
+ /** Local SQLite-backed store; used to emit `restoration-result` /
78
+ * `evaluation-verdict` artifact rows when a cycle completes via a
79
+ * deterministic impl (the legacy claude/MCP path writes them itself). */
80
+ store;
81
+ // Transient storage for impl output between runImpl and pack transitions.
82
+ // Keyed by requestId; cleared after successful pack.
83
+ solutionOutputs = new Map();
84
+ // Transient storage for the harness mode used during runImpl.
85
+ // Keyed by requestId; cleared after successful pack.
86
+ modesByRequest = new Map();
87
+ // Transient storage for the codeDigest returned by the freeze-fence.
88
+ // In train mode this is the post-run hash; in frozen mode it's the stable pre-hash.
89
+ // Keyed by requestId; cleared after successful pack.
90
+ codeDigestsByRequest = new Map();
91
+ // Transient storage for trajectory collectors produced in runImpl.
92
+ // emitTrajectory is deferred to pack() so that artifact spans can be added
93
+ // before the trajectory is finalised and uploaded (Task 16 bidirectional linkage).
94
+ // Keyed by requestId; cleared after successful pack.
95
+ // Protected (not private) to allow test subclasses to inject collectors.
96
+ trajectoryCollectors = new Map();
97
+ // Transient storage for trajectory CID+sha256 refs produced by runImpl.
98
+ // Keyed by requestId; cleared after successful pack.
99
+ trajectoryRefs = new Map();
100
+ runtimePluginsByRequest = new Map();
101
+ /** Set by stop(); causes runTickLoop to exit at the next iteration. */
102
+ stopped = false;
103
+ constructor(opts) {
104
+ this.persistence = new TaskRunPersistence(opts.store.db);
105
+ this.store = opts.store;
106
+ this.paths = opts.paths;
107
+ this.packagingDeps = opts.packagingDeps;
108
+ this.envelopeDeps = opts.envelopeDeps;
109
+ this.deliveryDeps = opts.deliveryDeps;
110
+ this.implRegistry = opts.implRegistry;
111
+ this.solverNetRegistry = opts.solverNetRegistry;
112
+ this.joinedSolverNets = opts.joinedSolverNets;
113
+ this.manifestResolver = opts.manifestResolver;
114
+ this.identityPublisher = opts.identityPublisher;
115
+ this.reputationFeedback = opts.reputationFeedback;
116
+ this.operatorConfig = opts.operatorConfig;
117
+ this.harnessMode = opts.harnessMode ?? 'train';
118
+ }
119
+ // ── Public API ──────────────────────────────────────────────────────────────
120
+ /**
121
+ * Called when an task is observed from an on-chain event.
122
+ * Persists a DISCOVERED row. Idempotent: if the row already exists, no-op.
123
+ */
124
+ async observe(input) {
125
+ const existing = this.persistence.getByRequestId(input.requestId);
126
+ if (!existing) {
127
+ this.persistence.insertDiscovered(input);
128
+ console.log(`[harness-engine] observed task ${input.requestId} solverType=${input.solverType ?? 'null'}`);
129
+ }
130
+ }
131
+ async canAcceptTask(input) {
132
+ const reason = await this.runnableFailureReason(input.solverType, input.taskRole ?? 'restoration', input.task);
133
+ return reason ? { ok: false, reason } : { ok: true };
134
+ }
135
+ /**
136
+ * Recover all in-flight tasks from persisted state.
137
+ * Called at daemon startup before beginning normal event processing.
138
+ * Returns a per-task report for each task attempted.
139
+ */
140
+ async recoverInFlight() {
141
+ const inflight = this.persistence.getInFlight();
142
+ const results = await Promise.allSettled(inflight.map((task) => this._recoverOne(task)));
143
+ const reports = results.map((result, i) => {
144
+ const requestId = inflight[i].requestId;
145
+ if (result.status === 'fulfilled') {
146
+ return { requestId, outcome: 'ok' };
147
+ }
148
+ else {
149
+ const error = result.reason instanceof Error
150
+ ? result.reason.message
151
+ : String(result.reason);
152
+ return { requestId, outcome: 'failed', error };
153
+ }
154
+ });
155
+ const okCount = reports.filter((r) => r.outcome === 'ok').length;
156
+ console.log(`[harness-engine] recovery: ${okCount}/${reports.length} tasks resumed`);
157
+ return reports;
158
+ }
159
+ /**
160
+ * Periodic tick: advance every in-flight task by one transition.
161
+ * Called by `runTickLoop` so that tasks which entered a non-event-driven
162
+ * state (e.g. CLAIMED waiting for windowStartTs) get re-driven without
163
+ * waiting for a daemon restart or a fresh marketplace event.
164
+ *
165
+ * Errors from individual tasks are logged but do not stop the loop.
166
+ */
167
+ async tick() {
168
+ const inflight = this.persistence.getInFlight();
169
+ const results = await Promise.allSettled(inflight.map((task) => this.process(task.requestId)));
170
+ for (let i = 0; i < results.length; i++) {
171
+ const r = results[i];
172
+ if (r.status === 'rejected') {
173
+ const requestId = inflight[i].requestId;
174
+ const reason = r.reason instanceof Error ? r.reason.message : String(r.reason);
175
+ console.warn(`[harness-engine] tick: process(${requestId}) failed: ${reason}`);
176
+ }
177
+ }
178
+ }
179
+ /**
180
+ * Drive `tick()` on a fixed interval until `stop()` is called.
181
+ * Errors thrown by tick() itself are logged and do not stop the loop.
182
+ */
183
+ async runTickLoop(intervalMs) {
184
+ while (!this.stopped) {
185
+ try {
186
+ await this.tick();
187
+ }
188
+ catch (err) {
189
+ console.error('[harness-engine] tick loop error (continuing):', err instanceof Error ? err.message : err);
190
+ }
191
+ if (this.stopped)
192
+ break;
193
+ await new Promise((resolve) => setTimeout(resolve, intervalMs));
194
+ }
195
+ }
196
+ /** Signal `runTickLoop` to exit at the next iteration. */
197
+ stop() {
198
+ this.stopped = true;
199
+ }
200
+ /**
201
+ * Process a single task: dispatch by current state to the appropriate
202
+ * transition. Drives one state transition per call.
203
+ *
204
+ * Called both by recovery and by the ongoing event-processing loop.
205
+ */
206
+ async process(requestId) {
207
+ const task = this.persistence.getByRequestId(requestId);
208
+ if (!task) {
209
+ throw new Error(`process: task not found: ${requestId}`);
210
+ }
211
+ switch (task.state) {
212
+ case TaskRunState.DISCOVERED:
213
+ await this._runTransition(task, () => this.claim(task));
214
+ break;
215
+ case TaskRunState.CLAIMED: {
216
+ // Advance to WAITING — persist-before-invoke principle.
217
+ const oldState = task.state;
218
+ this.persistence.transition(task.requestId, TaskRunState.WAITING);
219
+ console.log(`[harness-engine] ${requestId} ${oldState} → ${TaskRunState.WAITING}`);
220
+ break;
221
+ }
222
+ case TaskRunState.WAITING: {
223
+ const advance = this.dataDrivenAdvance(task);
224
+ if (advance !== null) {
225
+ this.persistence.transition(task.requestId, advance);
226
+ console.log(`[harness-engine] ${requestId} ${task.state} → ${advance}`);
227
+ await this._runTransition(this.persistence.getOrThrow(requestId), () => this.takePreSnapshot(this.persistence.getOrThrow(requestId)));
228
+ // takePreSnapshot transitions PRE_SNAPSHOT → RUNNING. Re-dispatch on
229
+ // the post-transition state so RUNNING fires in the same pass (jinn-mono-sae).
230
+ const after = this.persistence.getByRequestId(task.requestId);
231
+ if (after && after.state === TaskRunState.RUNNING) {
232
+ await this.process(task.requestId);
233
+ }
234
+ }
235
+ // else: not yet time — caller is responsible for scheduling retry
236
+ break;
237
+ }
238
+ case TaskRunState.PRE_SNAPSHOT: {
239
+ const advance = this.dataDrivenAdvance(task);
240
+ if (advance !== null) {
241
+ // Snapshot already captured (e.g. recovered from crash mid-transition)
242
+ this.persistence.transition(task.requestId, advance);
243
+ console.log(`[harness-engine] ${requestId} ${task.state} → ${advance}`);
244
+ await this._runTransition(this.persistence.getOrThrow(requestId), () => this.runImpl(this.persistence.getOrThrow(requestId)));
245
+ }
246
+ else {
247
+ await this._runTransition(task, () => this.takePreSnapshot(task));
248
+ // takePreSnapshot transitions PRE_SNAPSHOT → RUNNING internally.
249
+ // Re-dispatch on the post-transition state so the RUNNING case fires
250
+ // in the same pass (jinn-mono-sae fix). Without this, tasks stall
251
+ // at RUNNING until the next tick/restart and runImpl never executes.
252
+ const after = this.persistence.getByRequestId(task.requestId);
253
+ if (after && after.state === TaskRunState.RUNNING) {
254
+ await this.process(task.requestId);
255
+ }
256
+ }
257
+ break;
258
+ }
259
+ case TaskRunState.RUNNING:
260
+ await this._runTransition(task, () => this.runImpl(task));
261
+ break;
262
+ case TaskRunState.POST_SNAPSHOT: {
263
+ const advance = this.dataDrivenAdvance(task);
264
+ if (advance !== null) {
265
+ this.persistence.transition(task.requestId, advance);
266
+ console.log(`[harness-engine] ${requestId} ${task.state} → ${advance}`);
267
+ await this._runTransition(this.persistence.getOrThrow(requestId), () => this.pack(this.persistence.getOrThrow(requestId)));
268
+ }
269
+ else {
270
+ await this._runTransition(task, () => this.takePostSnapshot(task));
271
+ }
272
+ break;
273
+ }
274
+ case TaskRunState.PACKAGING:
275
+ await this._runTransition(task, () => this.pack(task));
276
+ break;
277
+ case TaskRunState.DELIVERING:
278
+ await this._runTransition(task, () => this.deliver(task));
279
+ break;
280
+ case TaskRunState.COMPLETE:
281
+ case TaskRunState.FAILED:
282
+ // Terminal — nothing to do.
283
+ break;
284
+ }
285
+ }
286
+ // ── Transition stubs ────────────────────────────────────────────────────────
287
+ // Stubs throw NotImplementedError. claim() is implemented here; others are
288
+ // filled in by subsequent tasks.
289
+ /**
290
+ * TaskCoordinator clean-break claim transition.
291
+ *
292
+ * The on-chain Task claim happens before observe(), producing the internal
293
+ * Mech requestId stored in this row. The engine's CLAIM step now only verifies
294
+ * the operator has an enabled, ready Harness and advances DISCOVERED → CLAIMED.
295
+ */
296
+ async claim(task) {
297
+ const reason = await this.runnableFailureReason(task.solverType ?? undefined, task.taskRole ?? 'restoration', task.task);
298
+ if (reason) {
299
+ this.persistence.markFailed(task.requestId, reason);
300
+ console.log(`[harness-engine] ${task.requestId}: skipping claimed task — ${reason}`);
301
+ throw new Error(reason);
302
+ }
303
+ // The event path and tick loop can race on the same DISCOVERED row; if
304
+ // another caller already advanced it, treat this as idempotent.
305
+ const current = this.persistence.getByRequestId(task.requestId);
306
+ if (!current) {
307
+ throw new Error(`claim: task not found after claim: ${task.requestId}`);
308
+ }
309
+ if (current.state === TaskRunState.DISCOVERED) {
310
+ this.persistence.transition(task.requestId, TaskRunState.CLAIMED);
311
+ }
312
+ else {
313
+ console.log(`[harness-engine] ${task.requestId}: claim completed but state is already ${current.state}; skipping CLAIMED transition`);
314
+ }
315
+ }
316
+ async releaseClaimedNotStarted() {
317
+ // TaskCoordinator claims are made before observe(), so there is no
318
+ // recoverable "claimed but not started" engine row to release here.
319
+ return [];
320
+ }
321
+ /**
322
+ * Internal routing key alias for the daemon-internal `solverType`-keyed
323
+ * harness map. Per spec §15 (non-goal of
324
+ * `spec/2026-05-05-solvernet-creation-and-launch.md`), the harness
325
+ * dispatch alias is intentionally retained for one cycle past Task 30;
326
+ * the user-facing surface (manifest, SPA, SDK shapes) is `solverType`-
327
+ * free. Prefers the canonical `${contractId}.${contractVersion}` when
328
+ * the task carries them, and falls back to the legacy `task.solverType`
329
+ * field for pre-Task-24 shapes / health-check tasks. Mirrors the SDK's
330
+ * internal `solverTypeAlias` helper but operates on a `Task`.
331
+ */
332
+ routingKeyForTask(task, fallback) {
333
+ if (task?.contractId && task?.contractVersion) {
334
+ return `${task.contractId}.${task.contractVersion}`;
335
+ }
336
+ return task?.solverType ?? fallback;
337
+ }
338
+ /**
339
+ * Resolve the task's `solverNetManifestCid` via the registry, fetch the
340
+ * manifest, and validate the task body against `manifest.contract.schemas.task`.
341
+ *
342
+ * Returns `null` when validation passes (or is skipped because no
343
+ * `manifestResolver` is wired and the task carries no `solverNetManifestCid`),
344
+ * or a human-readable failure reason otherwise.
345
+ *
346
+ * Day-1 compatibility note: this validates via the SDK template's Zod schema
347
+ * looked up by `{contract.id, contract.version}`. The manifest's embedded
348
+ * JSON Schema is the canonical wire format; once external launchers can
349
+ * publish manifests with arbitrary task schemas, this will switch to a JSON
350
+ * Schema validator (or `jsonSchemaToZod`) over the manifest's own schema.
351
+ * See `spec/2026-05-05-solvernet-creation-and-launch.md` §14.
352
+ */
353
+ async manifestBackedValidation(task) {
354
+ const cid = task.solverNetManifestCid;
355
+ if (!cid) {
356
+ // Without a manifest CID, schema validation can't run via the §14
357
+ // pipeline. Production callers (mech adapter) require CIDs at task
358
+ // post-time — this branch is hit only by tests / health-check tasks
359
+ // that don't exercise schema validation. The legacy
360
+ // `solverType`-keyed validation path was retired here.
361
+ return null;
362
+ }
363
+ if (!this.manifestResolver) {
364
+ // Engine wasn't constructed with a registry. Tests that don't exercise
365
+ // manifest resolution leave this unwired; treat schema validation as
366
+ // a no-op rather than failing — the daemon's production wiring always
367
+ // supplies a resolver.
368
+ return null;
369
+ }
370
+ let manifest;
371
+ try {
372
+ manifest = await this.manifestResolver.getManifest({ manifestCid: cid });
373
+ }
374
+ catch (err) {
375
+ const message = err instanceof Error ? err.message : String(err);
376
+ return `manifest resolution failed for cid '${cid}': ${message}`;
377
+ }
378
+ const ref = { id: manifest.contract.id, version: manifest.contract.version };
379
+ // Defense against malformed task documents: if the task carries explicit
380
+ // `contractId`/`contractVersion`, they MUST agree with the manifest.
381
+ if (task.contractId !== undefined && task.contractId !== ref.id) {
382
+ return `task.contractId '${task.contractId}' does not match manifest contract.id '${ref.id}'`;
383
+ }
384
+ if (task.contractVersion !== undefined && task.contractVersion !== ref.version) {
385
+ return `task.contractVersion '${task.contractVersion}' does not match manifest contract.version '${ref.version}'`;
386
+ }
387
+ // Day-1 compatibility: validate via the SDK template's Zod for the
388
+ // resolved contract. Day-N (external launchers) will validate against
389
+ // `manifest.contract.schemas.task` directly via JSON Schema.
390
+ const sdkContract = getSolverNetContract(ref);
391
+ if (!sdkContract) {
392
+ return `unsupported contract '${ref.id}.${ref.version}' from manifest '${cid}'`;
393
+ }
394
+ const parsed = sdkContract.schemas.task.zod.safeParse(task);
395
+ if (!parsed.success) {
396
+ const issues = parsed.error.issues
397
+ .map((issue) => `${issue.path.length > 0 ? issue.path.join('.') : '<root>'}: ${issue.message}`)
398
+ .join('; ');
399
+ return `${ref.id}.${ref.version} task failed validation: ${issues}`;
400
+ }
401
+ return null;
402
+ }
403
+ /**
404
+ * Returns a human-readable failure reason when the task is NOT eligible
405
+ * for this operator under the manifest-bound per-launch attribution
406
+ * model (spec §14, Task 28), or `null` when the task passes the filter.
407
+ *
408
+ * Eligibility logic:
409
+ * - The operator must have an entry in `joinedSolverNets` whose
410
+ * `manifestCid` matches `task.solverNetManifestCid` (or whose
411
+ * `keccak256(manifestCid)` matches the task's on-chain
412
+ * `manifestDigest` when only the digest is available).
413
+ * - The entry's `roles` must include the role required by this task
414
+ * ('solver' for restoration, 'evaluator' for evaluation).
415
+ *
416
+ * Caller must have already guarded `this.joinedSolverNets` non-null and
417
+ * `task` non-null.
418
+ */
419
+ evaluateJoinedEligibility(task, role) {
420
+ const view = this.joinedSolverNets;
421
+ const requiredRole = joinedRoleForTaskRole(role);
422
+ // Preferred path: the task body carries the manifest CID directly.
423
+ const cid = task.solverNetManifestCid;
424
+ if (cid) {
425
+ const entry = view.get(cid);
426
+ if (!entry) {
427
+ return (`task carries solverNetManifestCid '${cid}' but operator has not joined that SolverNet ` +
428
+ `(joinedSolverNets keys: [${view.manifestCids().join(', ') || '<empty>'}])`);
429
+ }
430
+ if (!entry.roles.includes(requiredRole)) {
431
+ return (`operator joined SolverNet '${cid}' but did not opt into role '${requiredRole}' ` +
432
+ `(roles: [${entry.roles.join(', ')}])`);
433
+ }
434
+ return null;
435
+ }
436
+ // Fallback path: task carries an on-chain `manifestDigest` (bytes32
437
+ // hex) without an off-chain CID. Compute keccak256 of every joined CID
438
+ // and compare. Used when the daemon discovers a task via on-chain
439
+ // event before fetching its IPFS body.
440
+ const taskRecord = task;
441
+ const taskDigest = taskRecord.manifestDigest;
442
+ if (taskDigest) {
443
+ const wantHex = taskDigest.toLowerCase();
444
+ for (const joinedCid of view.manifestCids()) {
445
+ const joinedDigest = keccak256(toBytes(joinedCid)).toLowerCase();
446
+ if (joinedDigest === wantHex) {
447
+ const entry = view.get(joinedCid);
448
+ if (!entry.roles.includes(requiredRole)) {
449
+ return (`operator joined SolverNet '${joinedCid}' but did not opt into role '${requiredRole}' ` +
450
+ `(roles: [${entry.roles.join(', ')}])`);
451
+ }
452
+ return null;
453
+ }
454
+ }
455
+ return (`task manifestDigest '${taskDigest}' does not match any joined SolverNet ` +
456
+ `(joinedSolverNets keys: [${view.manifestCids().join(', ') || '<empty>'}])`);
457
+ }
458
+ // Task has neither solverNetManifestCid nor manifestDigest. Per spec §14,
459
+ // post-Task-24 task documents always carry a CID; absence here means a
460
+ // pre-migration / health-check / legacy task. We don't fail those — the
461
+ // legacy solverType-keyed gate downstream still runs.
462
+ return null;
463
+ }
464
+ async runnableFailureReason(solverType, role, task) {
465
+ // Per-launch operator-eligibility filter (Task 28 of
466
+ // `spec/2026-05-05-solvernet-creation-and-launch.md` §14). When the
467
+ // operator has explicitly joined a set of SolverNets — keyed by the
468
+ // launched manifest's `manifestCid` — the engine refuses to accept any
469
+ // task whose on-chain `manifestDigest = keccak256(manifestCid)` doesn't
470
+ // match a joined entry, plus a role gate (restoration → 'solver',
471
+ // evaluation → 'evaluator'). This replaces the old protocol-level
472
+ // solverType filter and disambiguates Launcher A's Prediction from
473
+ // Launcher B's Prediction. The check is skipped when the engine has no
474
+ // `joinedSolverNets` view wired (legacy unit tests, in-memory adapter).
475
+ if (this.joinedSolverNets && task) {
476
+ const eligibility = this.evaluateJoinedEligibility(task, role);
477
+ if (eligibility)
478
+ return eligibility;
479
+ }
480
+ // Prefer the contract-derived routing alias when the task carries
481
+ // `contractId`/`contractVersion` (Task 24); fall back to the explicit
482
+ // `solverType` parameter for legacy pre-migration paths and PersistedTaskRun
483
+ // rows that pre-date `contractId`. See `routingKeyForTask`.
484
+ const routingKey = this.routingKeyForTask(task, solverType);
485
+ const solverNet = this.solverNetRegistry && routingKey
486
+ ? this.solverNetRegistry.forSolverType(routingKey, role)
487
+ : undefined;
488
+ if (this.solverNetRegistry && routingKey && !solverNet) {
489
+ return `no enabled SolverNet for solverType '${routingKey}' and role '${role}'; run \`jinn solver-nets enable <name>\``;
490
+ }
491
+ if (task) {
492
+ // Per spec §14 of `spec/2026-05-05-solvernet-creation-and-launch.md`,
493
+ // task validation resolves manifest → contract → schemas:
494
+ // manifest = registry.getManifest({ manifestCid: task.solverNetManifestCid })
495
+ // contract = manifest.contract
496
+ // validateAgainstSchema(task, contract.schemas.task)
497
+ // The legacy `solverType`-keyed `validateTask(solverType, task)` path
498
+ // is retired here; the routing alias is recovered from
499
+ // `manifest.contract.{id, version}` for the harness map lookup
500
+ // (which still keys on the `<id>.<version>` string until Task 30).
501
+ const validationFailure = await this.manifestBackedValidation(task);
502
+ if (validationFailure)
503
+ return validationFailure;
504
+ }
505
+ if (!this.implRegistry || !routingKey)
506
+ return null;
507
+ const impl = this.implRegistry.findFor({ solverType: routingKey, role });
508
+ if (!impl) {
509
+ const setHarnessHint = solverNet
510
+ ? `jinn solver-nets set-harness ${solverNet.name} <harness>`
511
+ : 'jinn solver-nets set-harness <name> <harness>';
512
+ return `no Harness registered or enabled for solverType '${routingKey}'; run \`${setHarnessHint}\``;
513
+ }
514
+ if (task) {
515
+ if (impl.canAttempt) {
516
+ const attempt = await impl.canAttempt(task);
517
+ if (!attempt.ok) {
518
+ return `impl '${impl.name}' cannot attempt task: ${attempt.reason}`;
519
+ }
520
+ }
521
+ }
522
+ if (impl.isReady) {
523
+ const status = await impl.isReady({ solverType: routingKey, role });
524
+ if (!status.ready) {
525
+ return `impl '${impl.name}' not ready: ${status.reason ?? 'unknown'}${status.nextStep?.cli ? ` — run \`${status.nextStep.cli}\`` : ''}`;
526
+ }
527
+ }
528
+ return null;
529
+ }
530
+ /**
531
+ * PRE_SNAPSHOT transition: provision workingDir + implStateDir, write
532
+ * task.json + env/ files, create sessions/ directory.
533
+ *
534
+ * Requires no external deps beyond filesystem access — always implemented.
535
+ * Advances state PRE_SNAPSHOT with workingDir + implStateDir patch.
536
+ */
537
+ async takePreSnapshot(run) {
538
+ const workingDir = join(this.paths.workingDirRoot, run.requestId);
539
+ // Resolve the impl via registry so implStateDir matches the path runImpl uses
540
+ // (join(implStateDirRoot, impl.name, solverType)). Falls back to solverType then 'default'
541
+ // when no impl is registered — legacy path preserved for health-check tasks.
542
+ const resolvedImpl = run.solverType
543
+ ? this.implRegistry?.findFor({ solverType: run.solverType, role: run.taskRole ?? 'restoration' }) ?? null
544
+ : null;
545
+ const implStateName = run.implName ?? resolvedImpl?.name ?? run.solverType ?? 'default';
546
+ const kindSeg = (run.solverType ?? '').replace(/[.:]/g, '_');
547
+ const implStateDir = kindSeg
548
+ ? join(this.paths.implStateDirRoot, implStateName, kindSeg)
549
+ : join(this.paths.implStateDirRoot, implStateName);
550
+ // Prefer the persisted full Task; fall back to a stub for legacy
551
+ // (pre-migration) rows so the engine still works for health-check tasks.
552
+ const task = run.task ?? {
553
+ id: run.requestId,
554
+ description: '',
555
+ ...(run.solverType ? { solverType: run.solverType, spec: {} } : {}),
556
+ role: run.taskRole ?? 'restoration',
557
+ window: { startTs: run.windowStartTs, endTs: run.windowEndTs },
558
+ };
559
+ provisionWorkingDir(workingDir, task);
560
+ provisionImplStateDir(implStateDir);
561
+ // takePreSnapshot transitions directly to RUNNING with the snapshot payload
562
+ // and workingDir/implStateDir paths set. We cannot transition
563
+ // PRE_SNAPSHOT → PRE_SNAPSHOT (invalid); the snapshot is immediately ready
564
+ // (it's just the provisioned dir context), so we advance to RUNNING in one
565
+ // step. The impl is responsible for capturing real market data.
566
+ this.persistence.transition(run.requestId, TaskRunState.RUNNING, {
567
+ workingDir,
568
+ implStateDir,
569
+ preSnapshotCapturedAt: Date.now(),
570
+ preSnapshotPayload: { provisioned: true, workingDir },
571
+ });
572
+ console.log(`[harness-engine] ${run.requestId} PRE_SNAPSHOT -> RUNNING: workingDir=${workingDir}`);
573
+ }
574
+ /**
575
+ * RUNNING transition: dispatch to a Harness if implRegistry is provided.
576
+ *
577
+ * When no impl is found for the solverType, falls back to NotImplementedError
578
+ * so the engine does not silently swallow the request. In tests that don't
579
+ * exercise the impl path, override this method.
580
+ *
581
+ * Captures impl output in `solutionOutputs` map for pack() to consume. Also
582
+ * records a minimal post-snapshot so data-driven advance can fire.
583
+ */
584
+ async runImpl(task) {
585
+ // The persisted `solver_type` column is authoritative for harness
586
+ // dispatch — it was derived at observation time from the canonical
587
+ // `${contractId}.${contractVersion}` alias (see Task 24's TaskCreated
588
+ // path). Internal routing key only — Task 30 retires the legacy
589
+ // string-keyed harness map.
590
+ const solverType = task.solverType ?? '';
591
+ const role = task.taskRole ?? 'restoration';
592
+ const solverNet = solverType ? this.solverNetRegistry?.forSolverType(solverType, role) : undefined;
593
+ const impl = this.implRegistry?.findFor({ solverType, role });
594
+ if (!impl) {
595
+ throw new NotImplementedError('runImpl');
596
+ }
597
+ const runtimePlugins = solverNet?.runtimePlugins ?? [];
598
+ this.runtimePluginsByRequest.set(task.requestId, runtimePlugins);
599
+ const workingDir = task.workingDir ?? join(this.paths.workingDirRoot, task.requestId);
600
+ const kindSeg = solverType.replace(/[.:]/g, '_');
601
+ const implStateDir = task.implStateDir ?? (kindSeg
602
+ ? join(this.paths.implStateDirRoot, impl.name, kindSeg)
603
+ : join(this.paths.implStateDirRoot, impl.name));
604
+ const windowEndTs = task.windowEndTs;
605
+ const abort = new AbortController();
606
+ const msUntilEndTs = () => Math.max(0, windowEndTs - Date.now());
607
+ const endTimer = setTimeout(() => abort.abort(), msUntilEndTs());
608
+ // Create a trajectory collector for this run.
609
+ const trajectory = new TrajectoryCollector({
610
+ taskCid: task.taskCid ?? '',
611
+ runId: randomUUID(),
612
+ });
613
+ try {
614
+ const ctx = {
615
+ task: (task.task ?? {
616
+ id: task.requestId,
617
+ description: '',
618
+ ...(task.solverType ? { solverType: task.solverType, spec: {} } : {}),
619
+ role,
620
+ window: { startTs: task.windowStartTs, endTs: task.windowEndTs },
621
+ }),
622
+ requestId: task.requestId,
623
+ taskCid: task.taskCid,
624
+ solverNet: solverNet
625
+ ? {
626
+ name: solverNet.name,
627
+ solverType: solverNet.solverType,
628
+ ...(solverNet.model ? { model: solverNet.model } : {}),
629
+ }
630
+ : undefined,
631
+ runtimePlugins,
632
+ solverPluginRoots: runtimePlugins.map((plugin) => plugin.root),
633
+ implStateDir,
634
+ workingDir,
635
+ log: (event) => {
636
+ console.log(`[harness-impl:${impl.name}] [${event.level}] ${event.msg}`, event.data ?? '');
637
+ },
638
+ abort: abort.signal,
639
+ msUntilEndTs,
640
+ trajectory,
641
+ mode: this.harnessMode,
642
+ };
643
+ // Run the harness through the freeze-fence so frozen-mode violations
644
+ // are detected, rolled back, and surfaced as a structured event before
645
+ // envelope assembly (spec §6.3). SkippableError thrown by the harness
646
+ // will bubble out of the fence and be caught below.
647
+ let fence;
648
+ try {
649
+ fence = await runHarnessWithFreezeFence(impl, ctx);
650
+ }
651
+ catch (err) {
652
+ if (err instanceof SkippableError) {
653
+ const skippedAt = Date.now();
654
+ const detail = err.message;
655
+ console.warn(`[harness-engine] ${task.requestId}: impl=${impl.name} skipped (${err.reason}): ${detail}`);
656
+ const skippedOutput = {
657
+ venueRef: { name: 'legacy' },
658
+ gating: {
659
+ skipped: true,
660
+ reason: err.reason,
661
+ skippedAt: String(skippedAt),
662
+ },
663
+ informational: {
664
+ status: 'skipped',
665
+ detail,
666
+ },
667
+ artifacts: [],
668
+ };
669
+ this.solutionOutputs.set(task.requestId, skippedOutput);
670
+ this.modesByRequest.set(task.requestId, ctx.mode);
671
+ // Preserve trajectory for downstream pack() access (Task 6 regression fix).
672
+ this.trajectoryCollectors.set(task.requestId, trajectory);
673
+ // No codeDigest for skipped runs — leave map empty.
674
+ // Fall through to persistence below via goto-equivalent pattern.
675
+ this.persistence.transition(task.requestId, TaskRunState.POST_SNAPSHOT, {
676
+ postSnapshotCapturedAt: Date.now(),
677
+ postSnapshotPayload: { capturedAt: Date.now(), hlTime: 0, payload: null },
678
+ fillsPayload: [],
679
+ gatingClaim: skippedOutput.gating,
680
+ informationalClaim: skippedOutput.informational ?? null,
681
+ solutionOutputsJson: JSON.stringify(skippedOutput),
682
+ implName: impl.name,
683
+ runtimePluginsJson: JSON.stringify(runtimePlugins),
684
+ });
685
+ console.log(`[harness-engine] ${task.requestId} RUNNING → POST_SNAPSHOT via impl=${impl.name} (skipped)`);
686
+ return;
687
+ }
688
+ throw err;
689
+ }
690
+ if (!fence.ok) {
691
+ // Violation: the harness mutated implStateDir in frozen mode.
692
+ // Snapshot already restored by the fence. Emit a structured log,
693
+ // skip envelope assembly, and mark the task FAILED.
694
+ ctx.log({
695
+ level: 'error',
696
+ msg: 'Harness violated frozen-mode contract — envelope rejected',
697
+ data: fence.violation,
698
+ });
699
+ this.persistence.markFailed(task.requestId, `freeze-fence violation: implStateDir mutated in frozen mode (harness=${fence.violation.harnessName}@${fence.violation.harnessVersion})`);
700
+ return;
701
+ }
702
+ // Store the codeDigest from the fence (post-run hash in train mode;
703
+ // stable pre-hash in frozen mode) for use in pack().
704
+ this.codeDigestsByRequest.set(task.requestId, `sha256:${fence.codeDigest}`);
705
+ this.modesByRequest.set(task.requestId, ctx.mode);
706
+ const output = fence.output;
707
+ this.solutionOutputs.set(task.requestId, output);
708
+ // Store the trajectory collector so pack() can:
709
+ // 1. pass it to uploadArtifacts (artifact.emit spans + producedBy metadata)
710
+ // 2. call emitTrajectory AFTER artifact upload so spans are included
711
+ // 3. backfill trajectoryCid on artifacts before envelope assembly
712
+ // emitTrajectory is intentionally deferred to pack() (Task 16).
713
+ this.trajectoryCollectors.set(task.requestId, trajectory);
714
+ // Persist impl output BEFORE the state transition so that a crash after
715
+ // the transition (RUNNING → POST_SNAPSHOT) but before pack() runs will
716
+ // find the serialised output in the DB on restart. pack() will hydrate the
717
+ // in-memory map from solutionOutputsJson if the map entry is absent (#6).
718
+ // Capture post-snapshot from impl output so data-driven advance fires
719
+ this.persistence.transition(task.requestId, TaskRunState.POST_SNAPSHOT, {
720
+ postSnapshotCapturedAt: Date.now(),
721
+ postSnapshotPayload: output.postSnapshot ?? { capturedAt: Date.now(), hlTime: 0, payload: null },
722
+ fillsPayload: output.fills ?? [],
723
+ gatingClaim: output.gating,
724
+ informationalClaim: output.informational ?? null,
725
+ solutionOutputsJson: JSON.stringify(output),
726
+ implName: impl.name,
727
+ runtimePluginsJson: JSON.stringify(runtimePlugins),
728
+ });
729
+ }
730
+ finally {
731
+ clearTimeout(endTimer);
732
+ }
733
+ console.log(`[harness-engine] ${task.requestId} RUNNING → POST_SNAPSHOT via impl=${impl.name}`);
734
+ }
735
+ async takePostSnapshot(_intent) {
736
+ throw new NotImplementedError('takePostSnapshot');
737
+ }
738
+ /**
739
+ * PACKAGING transition: walk workingDir, upload artifacts, assemble + sign
740
+ * envelope, upload envelope, persist envelope CID + artifact CIDs.
741
+ *
742
+ * Requires packagingDeps + envelopeDeps. When absent, falls back to
743
+ * NotImplementedError.
744
+ */
745
+ async pack(task) {
746
+ // Hydrate implOutput from DB if the in-memory map was lost (e.g. process restart
747
+ // after RUNNING → POST_SNAPSHOT but before pack() completed). This must run
748
+ // BEFORE the packagingDeps guard so subclass overrides that call super.pack()
749
+ // can still benefit from hydration even when packagingDeps is absent (#6).
750
+ if (!this.solutionOutputs.has(task.requestId) && task.solutionOutputsJson != null) {
751
+ try {
752
+ const recovered = JSON.parse(task.solutionOutputsJson);
753
+ this.solutionOutputs.set(task.requestId, recovered);
754
+ console.log(`[harness-engine] ${task.requestId}: hydrated solutionOutputs from DB (crash recovery)`);
755
+ }
756
+ catch (err) {
757
+ console.warn(`[harness-engine] ${task.requestId}: failed to hydrate solutionOutputsJson: ${err instanceof Error ? err.message : err}`);
758
+ }
759
+ }
760
+ if (!this.packagingDeps || !this.envelopeDeps) {
761
+ throw new NotImplementedError('pack');
762
+ }
763
+ const workingDir = task.workingDir ?? join(this.paths.workingDirRoot, task.requestId);
764
+ const implOutput = this.solutionOutputs.get(task.requestId);
765
+ const implArtifacts = implOutput?.artifacts ?? [];
766
+ // 1. Walk + upload artifacts (NO registration yet — manifest CID not known).
767
+ // Pass the trajectory collector (if present) so uploadArtifacts can emit
768
+ // jinn.artifact.emit spans and attach producedBy back-refs (Task 16 forward
769
+ // linkage). emitTrajectory is called AFTER upload so artifact spans are included.
770
+ const collector = this.trajectoryCollectors.get(task.requestId);
771
+ const packagingDepsWithReq = {
772
+ ...this.packagingDeps,
773
+ requestId: task.requestId,
774
+ ...(collector ? { collector } : {}),
775
+ };
776
+ const rawArtifacts = await walkArtifacts(workingDir, implArtifacts);
777
+ const uploadedArtifacts = await uploadArtifacts(rawArtifacts, packagingDepsWithReq);
778
+ // 1b. Emit trajectory to IPFS now that all artifact spans have been added.
779
+ // Non-fatal — envelope assembly continues with envelope.trajectory = null if upload fails.
780
+ let trajectoryRef = this.trajectoryRefs.get(task.requestId) ?? null;
781
+ if (!trajectoryRef && collector && this.envelopeDeps) {
782
+ try {
783
+ const { privateKeyToAccount } = await import('viem/accounts');
784
+ const account = privateKeyToAccount(this.envelopeDeps.agentEoaPrivateKey);
785
+ const { cid, sha256 } = await emitTrajectory({
786
+ collector,
787
+ runId: collector.runId,
788
+ signerPrivateKey: this.envelopeDeps.agentEoaPrivateKey,
789
+ signerAddress: account.address,
790
+ ipfsRegistryUrl: this.envelopeDeps.ipfsRegistryUrl,
791
+ });
792
+ trajectoryRef = { cid, sha256 };
793
+ console.log(`[harness-engine] ${task.requestId}: trajectory emitted cid=${cid}`);
794
+ }
795
+ catch (err) {
796
+ console.warn(`[harness-engine] ${task.requestId}: trajectory emit failed (non-fatal):`, err instanceof Error ? err.message : err);
797
+ }
798
+ }
799
+ this.trajectoryRefs.set(task.requestId, trajectoryRef);
800
+ // 1c. Backward linkage: backfill trajectoryCid on all artifacts that have a
801
+ // producedBy back-ref. This must happen BEFORE assembleAndSignEnvelope so the
802
+ // signed envelope carries the complete reference (Task 16).
803
+ if (trajectoryRef) {
804
+ const trajectoryCid = trajectoryRef.cid;
805
+ for (const art of uploadedArtifacts) {
806
+ const pb = art.metadata?.['producedBy'];
807
+ if (pb != null && typeof pb === 'object' && 'spanId' in pb) {
808
+ pb['trajectoryCid'] = trajectoryCid;
809
+ }
810
+ }
811
+ }
812
+ // Map to Artifact shape (strip localPath)
813
+ const artifacts = uploadedArtifacts.map(({ localPath: _localPath, ...art }) => art);
814
+ // 2. Derive agentEoa from private key
815
+ const { privateKeyToAccount } = await import('viem/accounts');
816
+ const account = privateKeyToAccount(this.envelopeDeps.agentEoaPrivateKey);
817
+ const agentEoa = account.address;
818
+ // Safe multisig address — sourced from envelopeDeps (preferred) or deliveryDeps.
819
+ // Hard throw if absent: falling back to agentEoa would produce a
820
+ // protocol-invalid envelope (safeAddress MUST differ from agentEoa, §5.1).
821
+ const safeAddress = this.envelopeDeps.safeAddress ?? this.deliveryDeps?.safeAddress;
822
+ if (!safeAddress) {
823
+ throw new Error('pack: safeAddress not configured in envelopeDeps or deliveryDeps');
824
+ }
825
+ // 3. Build envelope payload from impl output (kind-typed, wrapped into payload field)
826
+ const preSnapshotPayload = task.preSnapshotPayload;
827
+ const postSnapshotPayload = task.postSnapshotPayload;
828
+ // The solverType drives payload schema selection. Fall back to 'legacy.v0'
829
+ // for tasks without a solverType (legacy health-check / daemon-loop-test
830
+ // tasks that use the legacy-claude impl). The legacy.v0 kind accepts any
831
+ // Record payload so validatePayload does not reject the output.
832
+ const solverType = task.solverType ?? 'legacy.v0';
833
+ // Derive role from Task.role. Evaluator tasks produce 'verdict' envelopes;
834
+ // all other tasks produce 'restoration' envelopes.
835
+ const isEvaluation = task.taskRole === 'evaluation';
836
+ const role = isEvaluation ? 'verdict' : 'restoration';
837
+ let envelopePayload;
838
+ if (isEvaluation) {
839
+ // ── Verdict envelope payload ──────────────────────────────────────────────
840
+ // The evaluator impl populates verdictPayload on Solution with a
841
+ // PortfolioV0VerdictPayload-shaped object. Engine passes it through to the
842
+ // envelope assembler, which runs validatePayload('portfolio.v0', 'verdict', ...).
843
+ //
844
+ // If verdictPayload is absent (impl bug / crash recovery), fall back to a
845
+ // minimal INDETERMINATE stub so the envelope assembly does not silently succeed
846
+ // with a wrong shape — validatePayload will catch schema mismatches.
847
+ //
848
+ // verificationOfRestoration: stubbed — Plan D will connect the real SDK.
849
+ // restorationEnvelope.sha256: placeholder — Plan D wires real sha256 derivation.
850
+ const verdictPayload = implOutput?.verdictPayload;
851
+ if (!verdictPayload) {
852
+ throw new Error(`pack: evaluator impl for ${task.requestId} did not produce verdictPayload on Solution; ` +
853
+ `ensure the impl populates output.verdictPayload`);
854
+ }
855
+ // If the (stub) verificationOfRestoration reports 'invalid', downgrade verdict
856
+ // to REJECTED per scope §3.3. For V1 the stub always returns 'valid', so this
857
+ // path does not fire in practice — Plan D makes it real.
858
+ const verif = verdictPayload['verificationOfRestoration'];
859
+ if (verif?.overall === 'invalid') {
860
+ // Override verdict to REJECTED; preserve the rest of the payload.
861
+ envelopePayload = {
862
+ ...verdictPayload,
863
+ verdict: 'REJECTED',
864
+ };
865
+ }
866
+ else {
867
+ envelopePayload = verdictPayload;
868
+ }
869
+ }
870
+ else if (implOutput?.solutionPayload) {
871
+ // ── Non-portfolio restoration envelope payload ────────────────────────────
872
+ // Impls for kinds with a non-portfolio payload schema (e.g. prediction.v1)
873
+ // declare their own fully-formed payload. Engine passes it through directly
874
+ // so validatePayload() can check it against the per-kind schema.
875
+ envelopePayload = implOutput.solutionPayload;
876
+ }
877
+ else {
878
+ // ── Portfolio restoration envelope payload (legacy / portfolio.v0) ─────────
879
+ envelopePayload = {
880
+ preSnapshot: {
881
+ capturedAt: task.preSnapshotCapturedAt ?? Date.now(),
882
+ hlTime: preSnapshotPayload?.hlTime ?? 0,
883
+ // Double-fallback: first tries the structured .payload field (normal shape),
884
+ // then falls back to the whole payload object (handles takePreSnapshot's
885
+ // synthetic shape where the snapshot IS the top-level object, not nested).
886
+ payload: preSnapshotPayload?.payload ?? preSnapshotPayload ?? {},
887
+ },
888
+ postSnapshot: {
889
+ capturedAt: task.postSnapshotCapturedAt ?? Date.now(),
890
+ hlTime: postSnapshotPayload?.hlTime ?? 0,
891
+ // Same double-fallback as above.
892
+ payload: postSnapshotPayload?.payload ?? postSnapshotPayload ?? {},
893
+ },
894
+ fills: task.fillsPayload ?? [],
895
+ gating: task.gatingClaim ?? {},
896
+ ...(task.informationalClaim != null
897
+ ? { informational: task.informationalClaim }
898
+ : {}),
899
+ ...(implOutput?.rationale != null ? { rationale: implOutput.rationale } : {}),
900
+ };
901
+ }
902
+ // 4. Persist generatedAt once (first pack); reuse on retry for CID determinism.
903
+ const generatedAt = task.manifestGeneratedAt ?? Date.now();
904
+ if (!task.manifestGeneratedAt) {
905
+ // Persist before assembling so that a crash after assembly but before
906
+ // transition still gets the same generatedAt on the next attempt.
907
+ this.persistence.setManifestGeneratedAt(task.requestId, generatedAt);
908
+ }
909
+ // 5. Assemble + sign envelope → envelope CID now known.
910
+ // trajectoryRef was computed in step 1b above (emitted after artifact upload).
911
+ // Per the post-gating-fix schema, trajectory references carry sha256 + access
912
+ // (the operator HTTP endpoint that serves the bytes). Phase 3 (jinn-mono-vy37.1.3)
913
+ // sources this from the engine's operatorConfig; absent operatorConfig (e.g. test
914
+ // fixtures) falls back to packagingDeps.operatorEndpoint, then to a localhost
915
+ // sentinel so suites that don't exercise the publish path still pack cleanly.
916
+ const operatorEndpointForTraj = this.operatorConfig?.publicEndpoint
917
+ ?? this.packagingDeps?.operatorEndpoint
918
+ ?? 'http://localhost:7331';
919
+ const envelopeTrajectory = trajectoryRef
920
+ ? {
921
+ sha256: trajectoryRef.sha256,
922
+ access: { endpoint: operatorEndpointForTraj, priceUsdc: '0' },
923
+ }
924
+ : null;
925
+ // evidenceTier reflects the on-chain commitment state at the time of signing.
926
+ // For the V2 claim flow, claimDelivery will write an evidenceHash on-chain,
927
+ // so the envelope should be declared 'committed'. For V1 or unknown flows,
928
+ // 'self-signed' is accurate (no on-chain hash commitment).
929
+ const evidenceTier = this.deliveryDeps?.claimDeliveryVariant === 'v2' || this.deliveryDeps?.claimDeliveryVariant === 'v3'
930
+ ? 'committed'
931
+ : 'self-signed';
932
+ const runtimePlugins = this.runtimePluginsByRequest.get(task.requestId)
933
+ ?? (task.runtimePluginsJson ? JSON.parse(task.runtimePluginsJson) : []);
934
+ const executorPlugins = runtimePlugins
935
+ .map((plugin) => ({
936
+ name: plugin.name,
937
+ version: plugin.version,
938
+ ...(plugin.cid ? { cid: plugin.cid } : {}),
939
+ sha256: plugin.sha256,
940
+ }))
941
+ .sort((a, b) => `${a.name}@${a.version}`.localeCompare(`${b.name}@${b.version}`));
942
+ const implNameForEnvelope = task.implName ?? solverType;
943
+ const solverNet = solverType
944
+ ? this.solverNetRegistry?.forSolverType(solverType, task.taskRole ?? 'restoration')
945
+ : undefined;
946
+ const runtimeBundleDigest = `sha256:${createHash('sha256')
947
+ .update(JSON.stringify({
948
+ harness: {
949
+ name: implNameForEnvelope,
950
+ version: buildInfo.implVersion,
951
+ codeDigest: buildInfo.codeDigest,
952
+ },
953
+ solverNet: solverNet ? { name: solverNet.name, solverType: solverNet.solverType } : null,
954
+ plugins: executorPlugins,
955
+ }))
956
+ .digest('hex')}`;
957
+ // Resolve the mode and codeDigest from the in-memory maps populated by
958
+ // runImpl. Defaults: mode = 'train' (backward compat), codeDigest from
959
+ // buildInfo (fallback when runImpl did not run through the fence, e.g.
960
+ // crash-recovery from solutionOutputsJson without a fresh runImpl).
961
+ const executorMode = this.modesByRequest.get(task.requestId) ?? 'train';
962
+ const fenceCodeDigest = this.codeDigestsByRequest.get(task.requestId) ?? buildInfo.codeDigest;
963
+ const envelopeInputs = {
964
+ solverType,
965
+ role,
966
+ task: {
967
+ cid: task.taskCid,
968
+ onchainCreationTx: task.onchainCreationTx,
969
+ onchainCreationBlock: task.onchainCreationBlock,
970
+ requestId: task.requestId,
971
+ },
972
+ participant: { safeAddress, agentEoa },
973
+ window: { startTs: task.windowStartTs, endTs: task.windowEndTs },
974
+ executor: {
975
+ implName: implNameForEnvelope,
976
+ // buildInfo resolves to real values in production builds; falls back to
977
+ // clearly-labelled placeholders ('dev' / 'sha256:dev-build') when running
978
+ // via tsx without a prior `yarn build` (dev mode).
979
+ implVersion: buildInfo.implVersion,
980
+ clientGitSha: buildInfo.clientGitSha,
981
+ codeDigest: fenceCodeDigest,
982
+ runtimeBundleDigest,
983
+ plugins: executorPlugins,
984
+ signingKey: { kind: 'agent-eoa', pubkey: agentEoa },
985
+ // Propagate the harness execution mode (train | frozen) so the
986
+ // envelope records whether implStateDir was locked during this run.
987
+ mode: executorMode,
988
+ },
989
+ evidenceTier,
990
+ trajectory: envelopeTrajectory,
991
+ artifacts,
992
+ payload: envelopePayload,
993
+ generatedAt,
994
+ };
995
+ const { envelopeCid, envelopeHash } = await assembleAndSignEnvelope(envelopeInputs, this.envelopeDeps);
996
+ const manifestCid = envelopeCid;
997
+ const signatureHash = envelopeHash;
998
+ // 6. ERC-8004 IdentityRegistry per-execution `setMetadata` fires in
999
+ // deliver() AFTER claimDelivery succeeds. 'committed' must mean
1000
+ // "observable on-chain evidenceHash exists" — publishing before claim
1001
+ // would lie during failures. The evidenceHash (signatureHash) is
1002
+ // persisted to DELIVERING state below and reused by deliver().
1003
+ // Operator-rooted entity model: docs/superpowers/specs/2026-04-27-erc-8004-entity-model-design.md.
1004
+ // 7. Build artifact sha256 map for persistence.
1005
+ // Post-gating-fix (spec §1): artifacts no longer have IPFS CIDs — bytes
1006
+ // live in served_artifacts keyed by sha256. We reuse the legacy
1007
+ // `artifactCids` persistence column (key: localPath) but populate it with
1008
+ // sha256 hashes so downstream readers still get a stable identifier.
1009
+ const artifactCids = {};
1010
+ for (const art of uploadedArtifacts) {
1011
+ artifactCids[art.localPath] = art.sha256;
1012
+ }
1013
+ // Backfill envelope_cid (manifestCid) on every served_artifacts row so
1014
+ // the operator can answer manifest-rooted lookups later. Done after the
1015
+ // manifest CID is known.
1016
+ for (const art of uploadedArtifacts) {
1017
+ this.store.setServedArtifactEnvelopeCid(art.sha256, manifestCid);
1018
+ }
1019
+ // 8. Persist DELIVERING with manifest CID + artifact CIDs + evidence hash.
1020
+ // evidenceHash gets its own dedicated column (not stashed in informationalClaim).
1021
+ // executorMode + executorCodeDigest are also persisted so deliver() can
1022
+ // emit a payload v2 setMetadata after the transient maps are cleared.
1023
+ // See `client/src/erc8004/identity.ts` (publishContentV2) and the
1024
+ // payload-v2 ABI tuple in `abis.ts`.
1025
+ this.persistence.transition(task.requestId, TaskRunState.DELIVERING, {
1026
+ manifestCid,
1027
+ artifactCids,
1028
+ evidenceHash: signatureHash,
1029
+ executorMode,
1030
+ executorCodeDigest: fenceCodeDigest,
1031
+ });
1032
+ console.log(`[harness-engine] ${task.requestId} PACKAGING → DELIVERING manifestCid=${manifestCid}`);
1033
+ // Clean up transient state (no longer needed after DELIVERING)
1034
+ this.solutionOutputs.delete(task.requestId);
1035
+ this.trajectoryCollectors.delete(task.requestId);
1036
+ this.trajectoryRefs.delete(task.requestId);
1037
+ this.modesByRequest.delete(task.requestId);
1038
+ this.codeDigestsByRequest.delete(task.requestId);
1039
+ }
1040
+ /**
1041
+ * DELIVERING transition: call mech.deliverToMarketplace + JinnRouter.claimDelivery.
1042
+ *
1043
+ * Requires deliveryDeps. When absent, falls back to NotImplementedError.
1044
+ *
1045
+ * Crash-recovery safe: if `task.deliveryTxHash` is already set (persisted
1046
+ * after a previous deliverToMarketplace call that completed before the process
1047
+ * crashed), we skip the deliver step and go straight to claimDelivery.
1048
+ */
1049
+ async deliver(task) {
1050
+ if (!this.deliveryDeps) {
1051
+ throw new NotImplementedError('deliver');
1052
+ }
1053
+ const manifestCid = task.manifestCid;
1054
+ if (!manifestCid) {
1055
+ throw new Error(`deliver: manifestCid missing for ${task.requestId}`);
1056
+ }
1057
+ // Guard: v2 claimDelivery requires an evidenceHash — a zero fallback would
1058
+ // silently brick staking rewards, so we fail loudly instead.
1059
+ const evidenceHash = task.evidenceHash;
1060
+ if (!evidenceHash && (this.deliveryDeps.claimDeliveryVariant === 'v2' || this.deliveryDeps.claimDeliveryVariant === 'v3')) {
1061
+ throw new MissingEvidenceHashError(task.requestId);
1062
+ }
1063
+ // Capture locals for use in the onDeliveryTxLanded closure.
1064
+ const requestId = task.requestId;
1065
+ const persistence = this.persistence;
1066
+ const { deliveryTxHash, claimTxHash } = await deliverAndClaim(requestId, manifestCid, evidenceHash, this.deliveryDeps,
1067
+ // Recovery: pass existing deliveryTxHash so deliverToMarketplace is skipped.
1068
+ task.deliveryTxHash ?? undefined,
1069
+ // Persist deliveryTxHash before claimDelivery so recovery can resume from here.
1070
+ async (txHash) => {
1071
+ persistence.setDeliveryTxHash(requestId, txHash);
1072
+ }, {
1073
+ kind: task.taskRole === 'evaluation' ? 'verdict' : 'solution',
1074
+ verdictCode: task.taskRole === 'evaluation' ? this.verdictCodeForTask(task) : undefined,
1075
+ });
1076
+ this.persistence.transition(requestId, TaskRunState.COMPLETE, {
1077
+ deliveryTxHash,
1078
+ });
1079
+ console.log(`[harness-engine] ${requestId} DELIVERING → COMPLETE deliveryTx=${deliveryTxHash} claimTx=${claimTxHash}`);
1080
+ // Emit a SQLite artifact row so consumers (release acceptance gate, search
1081
+ // API) see this cycle alongside legacy-claude / MCP-emitted rows. The
1082
+ // legacy claude path writes via the MCP `submit_restoration_result` tool;
1083
+ // deterministic impls (prediction.v1 baseline/evaluator,
1084
+ // …) don't go through MCP, so the engine emits on their behalf here.
1085
+ // Idempotent: skips when a row for this requestId+tag already exists
1086
+ // (legacy path may have already inserted).
1087
+ this.emitCycleArtifact(task, manifestCid, evidenceHash);
1088
+ // ── ERC-8004 setMetadata — fires AFTER claimDelivery succeeds ────────────
1089
+ //
1090
+ // Moved here from pack() per PR#37 review2 must-fix #2. 'committed' means
1091
+ // "observable on-chain evidenceHash exists" — publishing before claim would
1092
+ // lie during failures. evidenceHash comes from task (persisted in
1093
+ // DELIVERING state by pack()); idempotent on retry (setMetadata is a pure
1094
+ // key-value write; re-running with the same payload is safe).
1095
+ //
1096
+ // Restoration-only for now. Evaluator setMetadata lands with jinn-mono-2ff.
1097
+ if (this.identityPublisher) {
1098
+ const taskRoleRaw = task.taskRole ?? 'restoration';
1099
+ if (taskRoleRaw === 'restoration') {
1100
+ const signatureHash = evidenceHash;
1101
+ // v0 tier rule: with an evidenceHash on chain we declare `committed` (tier=1);
1102
+ // higher tiers (`attested`, `proved`) come later when TEE work lands.
1103
+ const tier = signatureHash ? 1 : 0;
1104
+ const manifestHashHex = signatureHash ?? '0x';
1105
+ // Prefer v2 when the harness identity is available — the engine
1106
+ // captures executorMode + executorCodeDigest in pack(). For legacy
1107
+ // rows that completed before payload v2 wiring (or for solver paths
1108
+ // that don't produce a fence digest), executorCodeDigest is null and
1109
+ // we fall back to the v1 encoder so the indexer still sees envelope
1110
+ // metadata, just without harness identity. v1 envelopes are decoded
1111
+ // by the subgraph as mode='train' with empty codeDigest/implName.
1112
+ const harnessImplName = task.implName;
1113
+ const canEmitV2 = !!task.executorMode &&
1114
+ !!task.executorCodeDigest &&
1115
+ !!harnessImplName;
1116
+ try {
1117
+ let pubTxHash;
1118
+ if (canEmitV2) {
1119
+ const v2Payload = {
1120
+ version: 2,
1121
+ tier,
1122
+ manifestHash: manifestHashHex,
1123
+ attestationQuoteCid: '0x',
1124
+ sourceMeasurement: '0x0000000000000000000000000000000000000000000000000000000000000000',
1125
+ codeDigest: codeDigestSha256ToBytes32(task.executorCodeDigest),
1126
+ implName: harnessImplName,
1127
+ modeFlag: modeStringToFlag(task.executorMode),
1128
+ };
1129
+ pubTxHash = await this.identityPublisher.publishContentV2({
1130
+ kind: 'envelope',
1131
+ cid: manifestCid,
1132
+ payload: v2Payload,
1133
+ });
1134
+ console.log(`[harness-engine] ${requestId}: setMetadata envelope:${manifestCid} tx=${pubTxHash} (payload v2 mode=${task.executorMode} impl=${harnessImplName})`);
1135
+ }
1136
+ else {
1137
+ const v1Payload = {
1138
+ version: 1,
1139
+ tier,
1140
+ manifestHash: manifestHashHex,
1141
+ attestationQuoteCid: '0x',
1142
+ sourceMeasurement: '0x0000000000000000000000000000000000000000000000000000000000000000',
1143
+ };
1144
+ pubTxHash = await this.identityPublisher.publishContent({
1145
+ kind: 'envelope',
1146
+ cid: manifestCid,
1147
+ payload: v1Payload,
1148
+ });
1149
+ console.log(`[harness-engine] ${requestId}: setMetadata envelope:${manifestCid} tx=${pubTxHash} (payload v1)`);
1150
+ }
1151
+ }
1152
+ catch (err) {
1153
+ console.warn(`[harness-engine] ${requestId}: setMetadata envelope publish failed (non-fatal): ${err instanceof Error ? err.message : err}`);
1154
+ }
1155
+ }
1156
+ }
1157
+ // ── Reputation feedback hook (jinn-mono-yg4) ─────────────────────────────
1158
+ //
1159
+ // Evaluator-only path: after `claimDelivery` settles the verdict, fire
1160
+ // `ReputationRegistry.giveFeedback(harnessAgentId, ...)` so the
1161
+ // harness's agent NFT accrues a rating (DR §4.3).
1162
+ //
1163
+ // Best-effort: any failure inside the hook is logged but does not
1164
+ // change the COMPLETE state. claimDelivery is already authoritative.
1165
+ if (task.taskRole === 'evaluation' && this.reputationFeedback) {
1166
+ await this._maybePostEvaluatorFeedback(task).catch((err) => {
1167
+ console.warn(`[harness-engine] ${requestId}: reputation feedback hook errored unexpectedly (non-fatal): ${err instanceof Error ? err.message : err}`);
1168
+ });
1169
+ }
1170
+ }
1171
+ /**
1172
+ * Post evaluator feedback on the harness's agent NFT.
1173
+ *
1174
+ * Pulls the verdict from the persisted gating claim (the evaluator impl
1175
+ * writes `{ verdict, score, scoreBasis, ... }` into `output.gating`),
1176
+ * resolves the harness's `agentId` via the configured subgraph
1177
+ * resolver, and submits a single `ReputationRegistry.giveFeedback` tx.
1178
+ *
1179
+ * Skipped silently when:
1180
+ * - No `reputationFeedback` deps wired.
1181
+ * - `gatingClaim` doesn't carry a verdict (impl shape mismatch — log and
1182
+ * return).
1183
+ * - The parent harness's manifest hash isn't reachable from the
1184
+ * persisted state — log and return).
1185
+ * - `resolveAgentId` returns null (subgraph not indexed yet, or no
1186
+ * subgraph URL configured at all — log and return).
1187
+ *
1188
+ * The mapping policy (PASS / FAIL / REJECTED / INDETERMINATE → score) lives
1189
+ * inside `submitEvaluatorFeedback` / `mapVerdictToScore` in the
1190
+ * feedback-hook module; we just hand it the verdict.
1191
+ */
1192
+ /**
1193
+ * Insert a SQLite `artifacts` row for a successfully delivered cycle so the
1194
+ * release acceptance gate (and the search API) can observe completion via
1195
+ * the same surface as the legacy claude / MCP path.
1196
+ *
1197
+ * The legacy `legacy-claude` impl writes via the MCP `submit_restoration_result`
1198
+ * tool when Claude reports success; deterministic impls don't go through MCP.
1199
+ * This emitter closes that gap by writing the row from the engine when the
1200
+ * cycle hits COMPLETE.
1201
+ *
1202
+ * Idempotent: if a row already exists for (requestId, tag) — e.g. the legacy
1203
+ * MCP path got there first — we leave it alone.
1204
+ */
1205
+ emitCycleArtifact(task, manifestCid, evidenceHash) {
1206
+ const taskId = task.task?.id;
1207
+ if (!taskId) {
1208
+ // Rows without task payload cannot be attributed to a Task id. Skip
1209
+ // rather than synthesise provenance.
1210
+ return;
1211
+ }
1212
+ const taskRole = task.taskRole ?? 'restoration';
1213
+ const tag = taskRole === 'evaluation' ? 'evaluation-verdict' : 'restoration-result';
1214
+ const existing = this.store.getArtifactByRequestId(task.requestId, tag);
1215
+ if (existing)
1216
+ return;
1217
+ this.store.insertArtifact({
1218
+ id: randomUUID(),
1219
+ taskId,
1220
+ requestId: task.requestId,
1221
+ title: `${tag}: ${task.solverType ?? 'cycle'} (${task.implName ?? 'engine'})`,
1222
+ content: JSON.stringify({
1223
+ manifestCid,
1224
+ evidenceHash: evidenceHash ?? null,
1225
+ implName: task.implName,
1226
+ }),
1227
+ tags: [tag, 'success'],
1228
+ outcome: 'SUCCESS',
1229
+ });
1230
+ }
1231
+ verdictCodeForTask(task) {
1232
+ const gating = task.gatingClaim;
1233
+ const raw = gating?.verdict;
1234
+ switch (raw) {
1235
+ case 'PASS':
1236
+ case 'SCORED':
1237
+ return 1;
1238
+ case 'FAIL':
1239
+ case 'REJECTED':
1240
+ return 2;
1241
+ case 'INVALID':
1242
+ return 3;
1243
+ case 'INDETERMINATE':
1244
+ case 'UNRESOLVED':
1245
+ return 4;
1246
+ default:
1247
+ return 1;
1248
+ }
1249
+ }
1250
+ async _maybePostEvaluatorFeedback(task) {
1251
+ if (!this.reputationFeedback)
1252
+ return;
1253
+ const gating = task.gatingClaim;
1254
+ const verdictRaw = gating?.['verdict'];
1255
+ if (verdictRaw !== 'PASS' &&
1256
+ verdictRaw !== 'FAIL' &&
1257
+ verdictRaw !== 'REJECTED' &&
1258
+ verdictRaw !== 'INDETERMINATE') {
1259
+ console.warn(`[harness-engine] ${task.requestId}: reputation feedback skipped — gatingClaim has no recognised verdict (got=${String(verdictRaw)})`);
1260
+ return;
1261
+ }
1262
+ const verdict = verdictRaw;
1263
+ // Pull the parent harness's manifest evidence from the inlined eval
1264
+ // payload. The evaluator impl receives the harness's signed manifest
1265
+ // JSON via `task.context.restorationResult`. Its `signature.hash` is
1266
+ // exactly what the harness committed via `claimDelivery(evidenceHash)`.
1267
+ const parent = this._extractHarnessManifestRef(task);
1268
+ if (!parent) {
1269
+ console.warn(`[harness-engine] ${task.requestId}: reputation feedback skipped — could not extract harness manifest hash from inlined evaluation payload`);
1270
+ return;
1271
+ }
1272
+ let resolved;
1273
+ try {
1274
+ resolved = await this.reputationFeedback.resolveAgentId(parent.evidenceHash);
1275
+ }
1276
+ catch (err) {
1277
+ console.warn(`[harness-engine] ${task.requestId}: reputation feedback resolver threw (non-fatal): ${err instanceof Error ? err.message : err}`);
1278
+ return;
1279
+ }
1280
+ if (!resolved) {
1281
+ console.log(`[harness-engine] ${task.requestId}: reputation feedback skipped — no agentId resolved for harness manifestHash=${parent.evidenceHash} (subgraph not indexed yet, or no envelope published)`);
1282
+ return;
1283
+ }
1284
+ // CID resolution priority: subgraph row's `manifestCid` (cheapest, the
1285
+ // operator already published an envelope under it), else the inlined
1286
+ // CID hint when present, else fall back to the bare hash. The subgraph
1287
+ // parses `manifest:<cid>` to a `manifestRef` regardless.
1288
+ const manifestCid = resolved.manifestCid ?? parent.manifestCid ?? '';
1289
+ // The SolverType is the same value used by the restoration —
1290
+ // `task.solverType` is "portfolio.v0" both for the restoration and its
1291
+ // evaluation. Tag1 is indexed on the on-chain event, so cheap to filter.
1292
+ const kind = task.solverType ?? undefined;
1293
+ const verdictArg = kind ? { verdict, solverType: kind } : { verdict };
1294
+ let outcome;
1295
+ try {
1296
+ outcome = await submitEvaluatorFeedback({
1297
+ registry: this.reputationFeedback.client,
1298
+ ref: {
1299
+ harnessAgentId: resolved.agentId,
1300
+ harnessManifestCid: manifestCid,
1301
+ harnessEvidenceHash: parent.evidenceHash,
1302
+ },
1303
+ verdict: verdictArg,
1304
+ });
1305
+ }
1306
+ catch (err) {
1307
+ // submitEvaluatorFeedback already swallows known reverts, but a
1308
+ // truly unexpected throw still must not propagate past delivery.
1309
+ console.warn(`[harness-engine] ${task.requestId}: reputation feedback unexpected throw (non-fatal): ${err instanceof Error ? err.message : err}`);
1310
+ return;
1311
+ }
1312
+ console.log(`[harness-engine] ${task.requestId}: reputation feedback ${outcome.kind} verdict=${verdict} harnessAgentId=${resolved.agentId.toString()}`);
1313
+ }
1314
+ /**
1315
+ * Extract the harness's `evidenceHash` (and best-effort `manifestCid`)
1316
+ * from the persisted evaluation task.
1317
+ *
1318
+ * The evaluator's `task.context.restorationResult` holds the harness's
1319
+ * full signed manifest JSON inlined as a string. We parse it and pull the
1320
+ * `signature.hash`, which is exactly the on-chain `evidenceHash`.
1321
+ *
1322
+ * The CID is not always inlined — the manifest carries its own
1323
+ * `task.cid` field (the *original task* CID), not its self-CID. We
1324
+ * therefore return `manifestCid: null` here and rely on the subgraph
1325
+ * resolver to surface the published manifest CID. Returns `null` when
1326
+ * the inlined payload is missing or malformed.
1327
+ */
1328
+ _extractHarnessManifestRef(task) {
1329
+ const ds = task.task;
1330
+ const inlined = ds?.context?.['restorationResult'];
1331
+ if (typeof inlined !== 'string' || inlined.length === 0) {
1332
+ return null;
1333
+ }
1334
+ let parsed;
1335
+ try {
1336
+ parsed = JSON.parse(inlined);
1337
+ }
1338
+ catch {
1339
+ return null;
1340
+ }
1341
+ if (typeof parsed !== 'object' || parsed === null) {
1342
+ return null;
1343
+ }
1344
+ const sig = parsed['signature'];
1345
+ if (typeof sig !== 'object' || sig === null) {
1346
+ return null;
1347
+ }
1348
+ const hashRaw = sig['hash'];
1349
+ if (typeof hashRaw !== 'string' || !/^0x[0-9a-fA-F]{64}$/.test(hashRaw)) {
1350
+ return null;
1351
+ }
1352
+ return {
1353
+ evidenceHash: hashRaw,
1354
+ manifestCid: null,
1355
+ };
1356
+ }
1357
+ // ── Internal helpers ────────────────────────────────────────────────────────
1358
+ /**
1359
+ * Returns the next state if the current state can be advanced purely from
1360
+ * persisted data (no external work needed), or null if external work is required.
1361
+ *
1362
+ * Used for crash recovery and for collapsing transitions in process()
1363
+ * when a previous run already produced the data.
1364
+ */
1365
+ dataDrivenAdvance(task) {
1366
+ switch (task.state) {
1367
+ case TaskRunState.WAITING:
1368
+ return Date.now() >= task.windowStartTs ? TaskRunState.PRE_SNAPSHOT : null;
1369
+ case TaskRunState.PRE_SNAPSHOT:
1370
+ return task.preSnapshotPayload != null ? TaskRunState.RUNNING : null;
1371
+ case TaskRunState.POST_SNAPSHOT:
1372
+ return task.postSnapshotPayload != null ? TaskRunState.PACKAGING : null;
1373
+ default:
1374
+ return null;
1375
+ }
1376
+ }
1377
+ /**
1378
+ * Wraps a transition method call with error handling: if the transition
1379
+ * throws, the task is marked FAILED with the error message.
1380
+ */
1381
+ async _runTransition(task, fn) {
1382
+ const oldState = task.state;
1383
+ try {
1384
+ await fn();
1385
+ const updated = this.persistence.getByRequestId(task.requestId);
1386
+ if (updated && updated.state !== oldState) {
1387
+ console.log(`[harness-engine] ${task.requestId} ${oldState} → ${updated.state}`);
1388
+ }
1389
+ }
1390
+ catch (err) {
1391
+ const reason = err instanceof Error ? err.message : String(err);
1392
+ this.persistence.markFailed(task.requestId, reason);
1393
+ throw err;
1394
+ }
1395
+ }
1396
+ /**
1397
+ * Recovery handler for a single in-flight task.
1398
+ * Dispatches by state per §6.5.
1399
+ */
1400
+ async _recoverOne(task) {
1401
+ try {
1402
+ await this._recoverDispatch(task);
1403
+ }
1404
+ catch (err) {
1405
+ // If recovery itself throws (e.g. NotImplementedError stub), mark failed.
1406
+ // NotImplementedError is expected during development; don't swallow it in prod.
1407
+ const reason = err instanceof Error ? err.message : String(err);
1408
+ // Only mark failed if the task is still in the same non-terminal state
1409
+ // (another concurrent recovery pass might have already advanced it).
1410
+ const current = this.persistence.getByRequestId(task.requestId);
1411
+ if (current && current.state === task.state) {
1412
+ this.persistence.markFailed(task.requestId, `recovery: ${reason}`);
1413
+ console.error(`[harness-engine] resume failed for ${task.requestId}: ${reason}`);
1414
+ }
1415
+ throw err;
1416
+ }
1417
+ }
1418
+ /**
1419
+ * Per-state recovery dispatch per §6.5.
1420
+ */
1421
+ async _recoverDispatch(task) {
1422
+ switch (task.state) {
1423
+ case TaskRunState.DISCOVERED:
1424
+ // Ready to claim — delegate to claim flow (subsequent task).
1425
+ // Stub: leaves state unchanged; logs task is ready.
1426
+ await this.claim(task);
1427
+ break;
1428
+ case TaskRunState.CLAIMED:
1429
+ // Advance to WAITING — no side effect needed.
1430
+ this.persistence.transition(task.requestId, TaskRunState.WAITING);
1431
+ await this._recoverDispatch(this.persistence.getOrThrow(task.requestId));
1432
+ break;
1433
+ case TaskRunState.WAITING: {
1434
+ const advance = this.dataDrivenAdvance(task);
1435
+ if (advance !== null) {
1436
+ // Window has started — advance immediately.
1437
+ this.persistence.transition(task.requestId, advance);
1438
+ await this._recoverDispatch(this.persistence.getOrThrow(task.requestId));
1439
+ }
1440
+ // else: schedule a timer for startTs — caller handles scheduling.
1441
+ break;
1442
+ }
1443
+ case TaskRunState.PRE_SNAPSHOT: {
1444
+ const advance = this.dataDrivenAdvance(task);
1445
+ if (advance !== null) {
1446
+ // Snapshot already in DB — advance to RUNNING.
1447
+ this.persistence.transition(task.requestId, advance);
1448
+ await this._recoverDispatch(this.persistence.getOrThrow(task.requestId));
1449
+ }
1450
+ else {
1451
+ // Need to (re-)fetch snapshot.
1452
+ await this.takePreSnapshot(task);
1453
+ // takePreSnapshot transitions PRE_SNAPSHOT → RUNNING. Re-dispatch
1454
+ // against the post-transition state so runImpl actually fires for
1455
+ // tasks that were persisted at CLAIMED/WAITING/PRE_SNAPSHOT
1456
+ // before a restart (otherwise recovery stops at RUNNING-but-not-run).
1457
+ const after = this.persistence.getByRequestId(task.requestId);
1458
+ if (after && after.state !== task.state && after.state !== TaskRunState.FAILED) {
1459
+ await this._recoverDispatch(after);
1460
+ }
1461
+ }
1462
+ break;
1463
+ }
1464
+ case TaskRunState.RUNNING:
1465
+ // Re-spawn impl with workingDir + implStateDir intact.
1466
+ await this.runImpl(task);
1467
+ break;
1468
+ case TaskRunState.POST_SNAPSHOT: {
1469
+ const advance = this.dataDrivenAdvance(task);
1470
+ if (advance !== null) {
1471
+ // Snapshot already in DB — advance to PACKAGING.
1472
+ this.persistence.transition(task.requestId, advance);
1473
+ await this._recoverDispatch(this.persistence.getOrThrow(task.requestId));
1474
+ }
1475
+ else {
1476
+ await this.takePostSnapshot(task);
1477
+ }
1478
+ break;
1479
+ }
1480
+ case TaskRunState.PACKAGING:
1481
+ // Re-walk workingDir + Solution; re-upload missing CIDs.
1482
+ await this.pack(task);
1483
+ break;
1484
+ case TaskRunState.DELIVERING:
1485
+ // Chain query — if already delivered → COMPLETE; else retry.
1486
+ await this.deliver(task);
1487
+ break;
1488
+ case TaskRunState.COMPLETE:
1489
+ case TaskRunState.FAILED:
1490
+ // Terminal — nothing to recover.
1491
+ break;
1492
+ }
1493
+ }
1494
+ }
1495
+ // ── runHarnessOnce ────────────────────────────────────────────────────────────
1496
+ /**
1497
+ * Thin, test-friendly entry point for the freeze-fence + mode propagation
1498
+ * path. Runs a single `harness.run(ctx)` call through `runHarnessWithFreezeFence`
1499
+ * and returns either a minimal envelope stub (carrying `executor.mode`) or a
1500
+ * structured violation result — without requiring a full DB-backed TaskEngine
1501
+ * state machine.
1502
+ *
1503
+ * This function is *not* the production dispatch path; it exists so integration
1504
+ * tests can drive the mode-propagation and freeze-fence behaviour in isolation.
1505
+ *
1506
+ * @returns
1507
+ * `{ envelope: { executor: { mode } } }` on success.
1508
+ * `{ violation: FreezeViolation }` when the fence rejects the harness output.
1509
+ *
1510
+ * Spec: docs/superpowers/specs/2026-05-06-agent-harness-solvernet-design.md §6.3
1511
+ */
1512
+ export async function runHarnessOnce(params) {
1513
+ const { harness, implStateDir, mode } = params;
1514
+ const workingDir = params.workingDir ?? implStateDir;
1515
+ const task = params.task ?? {
1516
+ id: 'test-task',
1517
+ description: '',
1518
+ role: 'restoration',
1519
+ window: { startTs: 0, endTs: Date.now() + 3_600_000 },
1520
+ };
1521
+ const ctx = {
1522
+ task,
1523
+ implStateDir,
1524
+ workingDir,
1525
+ log: () => { },
1526
+ abort: new AbortController().signal,
1527
+ msUntilEndTs: () => Math.max(0, (task.window?.endTs ?? Date.now() + 3_600_000) - Date.now()),
1528
+ trajectory: new TrajectoryCollector({ taskCid: '', runId: 'test-run' }),
1529
+ mode,
1530
+ };
1531
+ const fence = await runHarnessWithFreezeFence(harness, ctx);
1532
+ if (!fence.ok) {
1533
+ return { violation: fence.violation };
1534
+ }
1535
+ return {
1536
+ envelope: {
1537
+ executor: {
1538
+ mode,
1539
+ codeDigest: `sha256:${fence.codeDigest}`,
1540
+ },
1541
+ },
1542
+ };
1543
+ }
1544
+ //# sourceMappingURL=engine.js.map