@jinn-network/client 0.1.1 → 0.1.2-canary.d6e72dfd

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 (317) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/CONTRIBUTING.md +123 -0
  3. package/README.md +210 -37
  4. package/deployments/deployment-claim-registry-baseSepolia.json +13 -0
  5. package/deployments/deployment-jinn-testnet-faucet-baseSepolia-fast.json +15 -0
  6. package/dist/adapters/claim-registry/abi.d.ts +127 -0
  7. package/dist/adapters/claim-registry/abi.js +93 -0
  8. package/dist/adapters/claim-registry/abi.js.map +1 -0
  9. package/dist/adapters/claim-registry/client.d.ts +89 -0
  10. package/dist/adapters/claim-registry/client.js +205 -0
  11. package/dist/adapters/claim-registry/client.js.map +1 -0
  12. package/dist/adapters/mech/adapter.d.ts +1 -0
  13. package/dist/adapters/mech/adapter.js +75 -41
  14. package/dist/adapters/mech/adapter.js.map +1 -1
  15. package/dist/adapters/mech/contracts.d.ts +2 -0
  16. package/dist/adapters/mech/contracts.js +57 -7
  17. package/dist/adapters/mech/contracts.js.map +1 -1
  18. package/dist/adapters/mech/ipfs.d.ts +8 -0
  19. package/dist/adapters/mech/ipfs.js +12 -0
  20. package/dist/adapters/mech/ipfs.js.map +1 -1
  21. package/dist/adapters/mech/types.d.ts +20 -46
  22. package/dist/adapters/mech/types.js +16 -35
  23. package/dist/adapters/mech/types.js.map +1 -1
  24. package/dist/api/gather-status.d.ts +1 -0
  25. package/dist/api/gather-status.js +33 -1
  26. package/dist/api/gather-status.js.map +1 -1
  27. package/dist/api/portfolio-v0-build.d.ts +81 -0
  28. package/dist/api/portfolio-v0-build.js +141 -0
  29. package/dist/api/portfolio-v0-build.js.map +1 -0
  30. package/dist/api/portfolio-v0-doctor.d.ts +37 -0
  31. package/dist/api/portfolio-v0-doctor.js +123 -0
  32. package/dist/api/portfolio-v0-doctor.js.map +1 -0
  33. package/dist/api/rewards-build.js +1 -1
  34. package/dist/api/rewards-build.js.map +1 -1
  35. package/dist/api/status-build.d.ts +7 -0
  36. package/dist/api/status-build.js +1 -0
  37. package/dist/api/status-build.js.map +1 -1
  38. package/dist/bin/jinn-mcp.d.ts +0 -12
  39. package/dist/bin/jinn-mcp.js +5 -14
  40. package/dist/bin/jinn-mcp.js.map +1 -1
  41. package/dist/build-meta.json +1 -1
  42. package/dist/cli/commands/auth.js +115 -25
  43. package/dist/cli/commands/auth.js.map +1 -1
  44. package/dist/cli/commands/bootstrap.js +1 -0
  45. package/dist/cli/commands/bootstrap.js.map +1 -1
  46. package/dist/cli/commands/doctor.js +130 -14
  47. package/dist/cli/commands/doctor.js.map +1 -1
  48. package/dist/cli/commands/fleet-scale.js +1 -0
  49. package/dist/cli/commands/fleet-scale.js.map +1 -1
  50. package/dist/cli/commands/fund-requirements.js +2 -0
  51. package/dist/cli/commands/fund-requirements.js.map +1 -1
  52. package/dist/cli/commands/intents.d.ts +17 -0
  53. package/dist/cli/commands/intents.js +489 -0
  54. package/dist/cli/commands/intents.js.map +1 -0
  55. package/dist/cli/commands/keys-backup.js +13 -11
  56. package/dist/cli/commands/keys-backup.js.map +1 -1
  57. package/dist/cli/commands/mcp.d.ts +3 -0
  58. package/dist/cli/commands/mcp.js +19 -0
  59. package/dist/cli/commands/mcp.js.map +1 -0
  60. package/dist/cli/commands/plugin-install.js +8 -4
  61. package/dist/cli/commands/plugin-install.js.map +1 -1
  62. package/dist/cli/commands/quickstart.js +60 -4
  63. package/dist/cli/commands/quickstart.js.map +1 -1
  64. package/dist/cli/commands/rewards.js +27 -1
  65. package/dist/cli/commands/rewards.js.map +1 -1
  66. package/dist/cli/commands/submit-intent.js +108 -5
  67. package/dist/cli/commands/submit-intent.js.map +1 -1
  68. package/dist/cli/commands/version.js +1 -0
  69. package/dist/cli/commands/version.js.map +1 -1
  70. package/dist/cli/deployment-digest.js +5 -0
  71. package/dist/cli/deployment-digest.js.map +1 -1
  72. package/dist/cli/execution-context.js +1 -0
  73. package/dist/cli/execution-context.js.map +1 -1
  74. package/dist/cli/index.js +4 -0
  75. package/dist/cli/index.js.map +1 -1
  76. package/dist/cli/intent-registry-access.d.ts +64 -0
  77. package/dist/cli/intent-registry-access.js +187 -0
  78. package/dist/cli/intent-registry-access.js.map +1 -0
  79. package/dist/cli/introspection-context.js +1 -0
  80. package/dist/cli/introspection-context.js.map +1 -1
  81. package/dist/cli/password.d.ts +21 -9
  82. package/dist/cli/password.js +45 -24
  83. package/dist/cli/password.js.map +1 -1
  84. package/dist/config.d.ts +110 -8
  85. package/dist/config.js +41 -12
  86. package/dist/config.js.map +1 -1
  87. package/dist/daemon/creator.d.ts +7 -1
  88. package/dist/daemon/creator.js +38 -3
  89. package/dist/daemon/creator.js.map +1 -1
  90. package/dist/daemon/daemon.d.ts +43 -0
  91. package/dist/daemon/daemon.js +87 -2
  92. package/dist/daemon/daemon.js.map +1 -1
  93. package/dist/earning/bootstrap.d.ts +2 -1
  94. package/dist/earning/bootstrap.js +72 -4
  95. package/dist/earning/bootstrap.js.map +1 -1
  96. package/dist/earning/contracts.d.ts +10 -0
  97. package/dist/earning/contracts.js +24 -0
  98. package/dist/earning/contracts.js.map +1 -1
  99. package/dist/earning/jinn-rewards.d.ts +9 -0
  100. package/dist/earning/jinn-rewards.js +7 -0
  101. package/dist/earning/jinn-rewards.js.map +1 -1
  102. package/dist/intents/prediction-apy-v0-auto.d.ts +11 -0
  103. package/dist/intents/prediction-apy-v0-auto.js +46 -0
  104. package/dist/intents/prediction-apy-v0-auto.js.map +1 -0
  105. package/dist/intents/prediction-apy-v0-template.d.ts +8 -0
  106. package/dist/intents/prediction-apy-v0-template.js +22 -0
  107. package/dist/intents/prediction-apy-v0-template.js.map +1 -0
  108. package/dist/intents/prediction-v0-auto.d.ts +53 -0
  109. package/dist/intents/prediction-v0-auto.js +84 -0
  110. package/dist/intents/prediction-v0-auto.js.map +1 -0
  111. package/dist/intents/prediction-v0-template.d.ts +65 -0
  112. package/dist/intents/prediction-v0-template.js +125 -0
  113. package/dist/intents/prediction-v0-template.js.map +1 -0
  114. package/dist/main.js +149 -1
  115. package/dist/main.js.map +1 -1
  116. package/dist/mcp/operator-server.d.ts +1 -1
  117. package/dist/mcp/operator-server.js +1 -1
  118. package/dist/preflight/claude-auth.d.ts +12 -1
  119. package/dist/preflight/claude-auth.js +21 -3
  120. package/dist/preflight/claude-auth.js.map +1 -1
  121. package/dist/restorer/engine/canonical-json.d.ts +18 -0
  122. package/dist/restorer/engine/canonical-json.js +59 -0
  123. package/dist/restorer/engine/canonical-json.js.map +1 -0
  124. package/dist/restorer/engine/claim.d.ts +69 -0
  125. package/dist/restorer/engine/claim.js +104 -0
  126. package/dist/restorer/engine/claim.js.map +1 -0
  127. package/dist/restorer/engine/delivery.d.ts +52 -0
  128. package/dist/restorer/engine/delivery.js +63 -0
  129. package/dist/restorer/engine/delivery.js.map +1 -0
  130. package/dist/restorer/engine/engine.d.ts +203 -0
  131. package/dist/restorer/engine/engine.js +753 -0
  132. package/dist/restorer/engine/engine.js.map +1 -0
  133. package/dist/restorer/engine/manifest-assembly.d.ts +67 -0
  134. package/dist/restorer/engine/manifest-assembly.js +79 -0
  135. package/dist/restorer/engine/manifest-assembly.js.map +1 -0
  136. package/dist/restorer/engine/packaging.d.ts +87 -0
  137. package/dist/restorer/engine/packaging.js +350 -0
  138. package/dist/restorer/engine/packaging.js.map +1 -0
  139. package/dist/restorer/engine/persistence.d.ts +170 -0
  140. package/dist/restorer/engine/persistence.js +381 -0
  141. package/dist/restorer/engine/persistence.js.map +1 -0
  142. package/dist/restorer/engine/recovery.d.ts +22 -0
  143. package/dist/restorer/engine/recovery.js +24 -0
  144. package/dist/restorer/engine/recovery.js.map +1 -0
  145. package/dist/restorer/engine/registry.d.ts +62 -0
  146. package/dist/restorer/engine/registry.js +73 -0
  147. package/dist/restorer/engine/registry.js.map +1 -0
  148. package/dist/restorer/engine/signing.d.ts +30 -0
  149. package/dist/restorer/engine/signing.js +39 -0
  150. package/dist/restorer/engine/signing.js.map +1 -0
  151. package/dist/restorer/engine/state.d.ts +42 -0
  152. package/dist/restorer/engine/state.js +87 -0
  153. package/dist/restorer/engine/state.js.map +1 -0
  154. package/dist/restorer/impls/claude-mcp-hyperliquid/api-wallet.d.ts +64 -0
  155. package/dist/restorer/impls/claude-mcp-hyperliquid/api-wallet.js +96 -0
  156. package/dist/restorer/impls/claude-mcp-hyperliquid/api-wallet.js.map +1 -0
  157. package/dist/restorer/impls/claude-mcp-hyperliquid/index.d.ts +101 -0
  158. package/dist/restorer/impls/claude-mcp-hyperliquid/index.js +710 -0
  159. package/dist/restorer/impls/claude-mcp-hyperliquid/index.js.map +1 -0
  160. package/dist/restorer/impls/claude-mcp-hyperliquid/mcp-tools.d.ts +137 -0
  161. package/dist/restorer/impls/claude-mcp-hyperliquid/mcp-tools.js +865 -0
  162. package/dist/restorer/impls/claude-mcp-hyperliquid/mcp-tools.js.map +1 -0
  163. package/dist/restorer/impls/claude-mcp-hyperliquid/safety-rails.d.ts +74 -0
  164. package/dist/restorer/impls/claude-mcp-hyperliquid/safety-rails.js +74 -0
  165. package/dist/restorer/impls/claude-mcp-hyperliquid/safety-rails.js.map +1 -0
  166. package/dist/restorer/impls/claude-mcp-hyperliquid/session-orchestrator.d.ts +97 -0
  167. package/dist/restorer/impls/claude-mcp-hyperliquid/session-orchestrator.js +226 -0
  168. package/dist/restorer/impls/claude-mcp-hyperliquid/session-orchestrator.js.map +1 -0
  169. package/dist/restorer/impls/claude-mcp-prediction/index.d.ts +43 -0
  170. package/dist/restorer/impls/claude-mcp-prediction/index.js +230 -0
  171. package/dist/restorer/impls/claude-mcp-prediction/index.js.map +1 -0
  172. package/dist/restorer/impls/claude-mcp-prediction/mcp-tools.d.ts +38 -0
  173. package/dist/restorer/impls/claude-mcp-prediction/mcp-tools.js +135 -0
  174. package/dist/restorer/impls/claude-mcp-prediction/mcp-tools.js.map +1 -0
  175. package/dist/restorer/impls/claude-mcp-prediction/prompt.d.ts +8 -0
  176. package/dist/restorer/impls/claude-mcp-prediction/prompt.js +54 -0
  177. package/dist/restorer/impls/claude-mcp-prediction/prompt.js.map +1 -0
  178. package/dist/restorer/impls/claude-mcp-prediction/session-orchestrator.d.ts +36 -0
  179. package/dist/restorer/impls/claude-mcp-prediction/session-orchestrator.js +137 -0
  180. package/dist/restorer/impls/claude-mcp-prediction/session-orchestrator.js.map +1 -0
  181. package/dist/restorer/impls/claude-mcp-prediction/types.d.ts +82 -0
  182. package/dist/restorer/impls/claude-mcp-prediction/types.js +6 -0
  183. package/dist/restorer/impls/claude-mcp-prediction/types.js.map +1 -0
  184. package/dist/restorer/impls/legacy-claude/index.d.ts +45 -0
  185. package/dist/restorer/impls/legacy-claude/index.js +71 -0
  186. package/dist/restorer/impls/legacy-claude/index.js.map +1 -0
  187. package/dist/restorer/impls/portfolio-v0-evaluator/canonical-metrics.d.ts +68 -0
  188. package/dist/restorer/impls/portfolio-v0-evaluator/canonical-metrics.js +117 -0
  189. package/dist/restorer/impls/portfolio-v0-evaluator/canonical-metrics.js.map +1 -0
  190. package/dist/restorer/impls/portfolio-v0-evaluator/checks/availability.d.ts +49 -0
  191. package/dist/restorer/impls/portfolio-v0-evaluator/checks/availability.js +91 -0
  192. package/dist/restorer/impls/portfolio-v0-evaluator/checks/availability.js.map +1 -0
  193. package/dist/restorer/impls/portfolio-v0-evaluator/checks/consistency.d.ts +78 -0
  194. package/dist/restorer/impls/portfolio-v0-evaluator/checks/consistency.js +274 -0
  195. package/dist/restorer/impls/portfolio-v0-evaluator/checks/consistency.js.map +1 -0
  196. package/dist/restorer/impls/portfolio-v0-evaluator/checks/eligibility.d.ts +23 -0
  197. package/dist/restorer/impls/portfolio-v0-evaluator/checks/eligibility.js +49 -0
  198. package/dist/restorer/impls/portfolio-v0-evaluator/checks/eligibility.js.map +1 -0
  199. package/dist/restorer/impls/portfolio-v0-evaluator/checks/integrity.d.ts +25 -0
  200. package/dist/restorer/impls/portfolio-v0-evaluator/checks/integrity.js +44 -0
  201. package/dist/restorer/impls/portfolio-v0-evaluator/checks/integrity.js.map +1 -0
  202. package/dist/restorer/impls/portfolio-v0-evaluator/checks/spec.d.ts +17 -0
  203. package/dist/restorer/impls/portfolio-v0-evaluator/checks/spec.js +43 -0
  204. package/dist/restorer/impls/portfolio-v0-evaluator/checks/spec.js.map +1 -0
  205. package/dist/restorer/impls/portfolio-v0-evaluator/index.d.ts +43 -0
  206. package/dist/restorer/impls/portfolio-v0-evaluator/index.js +431 -0
  207. package/dist/restorer/impls/portfolio-v0-evaluator/index.js.map +1 -0
  208. package/dist/restorer/impls/portfolio-v0-evaluator/score.d.ts +21 -0
  209. package/dist/restorer/impls/portfolio-v0-evaluator/score.js +32 -0
  210. package/dist/restorer/impls/portfolio-v0-evaluator/score.js.map +1 -0
  211. package/dist/restorer/impls/portfolio-v0-evaluator/types.d.ts +32 -0
  212. package/dist/restorer/impls/portfolio-v0-evaluator/types.js +8 -0
  213. package/dist/restorer/impls/portfolio-v0-evaluator/types.js.map +1 -0
  214. package/dist/restorer/impls/prediction-apy-v0-baseline/index.d.ts +39 -0
  215. package/dist/restorer/impls/prediction-apy-v0-baseline/index.js +98 -0
  216. package/dist/restorer/impls/prediction-apy-v0-baseline/index.js.map +1 -0
  217. package/dist/restorer/impls/prediction-apy-v0-baseline/strategy.d.ts +2 -0
  218. package/dist/restorer/impls/prediction-apy-v0-baseline/strategy.js +7 -0
  219. package/dist/restorer/impls/prediction-apy-v0-baseline/strategy.js.map +1 -0
  220. package/dist/restorer/impls/prediction-apy-v0-baseline/types.d.ts +4 -0
  221. package/dist/restorer/impls/prediction-apy-v0-baseline/types.js +2 -0
  222. package/dist/restorer/impls/prediction-apy-v0-baseline/types.js.map +1 -0
  223. package/dist/restorer/impls/prediction-apy-v0-evaluator/canonical-metrics.d.ts +2 -0
  224. package/dist/restorer/impls/prediction-apy-v0-evaluator/canonical-metrics.js +7 -0
  225. package/dist/restorer/impls/prediction-apy-v0-evaluator/canonical-metrics.js.map +1 -0
  226. package/dist/restorer/impls/prediction-apy-v0-evaluator/index.d.ts +39 -0
  227. package/dist/restorer/impls/prediction-apy-v0-evaluator/index.js +186 -0
  228. package/dist/restorer/impls/prediction-apy-v0-evaluator/index.js.map +1 -0
  229. package/dist/restorer/impls/prediction-apy-v0-evaluator/score.d.ts +9 -0
  230. package/dist/restorer/impls/prediction-apy-v0-evaluator/score.js +20 -0
  231. package/dist/restorer/impls/prediction-apy-v0-evaluator/score.js.map +1 -0
  232. package/dist/restorer/impls/prediction-apy-v0-evaluator/types.d.ts +7 -0
  233. package/dist/restorer/impls/prediction-apy-v0-evaluator/types.js +2 -0
  234. package/dist/restorer/impls/prediction-apy-v0-evaluator/types.js.map +1 -0
  235. package/dist/restorer/impls/prediction-v0-baseline/index.d.ts +29 -0
  236. package/dist/restorer/impls/prediction-v0-baseline/index.js +94 -0
  237. package/dist/restorer/impls/prediction-v0-baseline/index.js.map +1 -0
  238. package/dist/restorer/impls/prediction-v0-baseline/strategy.d.ts +8 -0
  239. package/dist/restorer/impls/prediction-v0-baseline/strategy.js +41 -0
  240. package/dist/restorer/impls/prediction-v0-baseline/strategy.js.map +1 -0
  241. package/dist/restorer/impls/prediction-v0-baseline/types.d.ts +7 -0
  242. package/dist/restorer/impls/prediction-v0-baseline/types.js +2 -0
  243. package/dist/restorer/impls/prediction-v0-baseline/types.js.map +1 -0
  244. package/dist/restorer/impls/prediction-v0-evaluator/canonical-metrics.d.ts +20 -0
  245. package/dist/restorer/impls/prediction-v0-evaluator/canonical-metrics.js +66 -0
  246. package/dist/restorer/impls/prediction-v0-evaluator/canonical-metrics.js.map +1 -0
  247. package/dist/restorer/impls/prediction-v0-evaluator/checks/availability.d.ts +9 -0
  248. package/dist/restorer/impls/prediction-v0-evaluator/checks/availability.js +23 -0
  249. package/dist/restorer/impls/prediction-v0-evaluator/checks/availability.js.map +1 -0
  250. package/dist/restorer/impls/prediction-v0-evaluator/checks/eligibility.d.ts +3 -0
  251. package/dist/restorer/impls/prediction-v0-evaluator/checks/eligibility.js +13 -0
  252. package/dist/restorer/impls/prediction-v0-evaluator/checks/eligibility.js.map +1 -0
  253. package/dist/restorer/impls/prediction-v0-evaluator/checks/integrity.d.ts +7 -0
  254. package/dist/restorer/impls/prediction-v0-evaluator/checks/integrity.js +93 -0
  255. package/dist/restorer/impls/prediction-v0-evaluator/checks/integrity.js.map +1 -0
  256. package/dist/restorer/impls/prediction-v0-evaluator/checks/spec.d.ts +5 -0
  257. package/dist/restorer/impls/prediction-v0-evaluator/checks/spec.js +20 -0
  258. package/dist/restorer/impls/prediction-v0-evaluator/checks/spec.js.map +1 -0
  259. package/dist/restorer/impls/prediction-v0-evaluator/index.d.ts +33 -0
  260. package/dist/restorer/impls/prediction-v0-evaluator/index.js +208 -0
  261. package/dist/restorer/impls/prediction-v0-evaluator/index.js.map +1 -0
  262. package/dist/restorer/impls/prediction-v0-evaluator/score.d.ts +8 -0
  263. package/dist/restorer/impls/prediction-v0-evaluator/score.js +15 -0
  264. package/dist/restorer/impls/prediction-v0-evaluator/score.js.map +1 -0
  265. package/dist/restorer/impls/prediction-v0-evaluator/types.d.ts +7 -0
  266. package/dist/restorer/impls/prediction-v0-evaluator/types.js +2 -0
  267. package/dist/restorer/impls/prediction-v0-evaluator/types.js.map +1 -0
  268. package/dist/restorer/types.d.ts +177 -0
  269. package/dist/restorer/types.js +7 -0
  270. package/dist/restorer/types.js.map +1 -0
  271. package/dist/store/store.d.ts +3 -1
  272. package/dist/store/store.js +3 -0
  273. package/dist/store/store.js.map +1 -1
  274. package/dist/types/desired-state.d.ts +53 -0
  275. package/dist/types/desired-state.js +20 -0
  276. package/dist/types/desired-state.js.map +1 -1
  277. package/dist/types/index.d.ts +4 -1
  278. package/dist/types/index.js +4 -1
  279. package/dist/types/index.js.map +1 -1
  280. package/dist/types/portfolio.d.ts +1000 -0
  281. package/dist/types/portfolio.js +168 -0
  282. package/dist/types/portfolio.js.map +1 -0
  283. package/dist/types/prediction-apy.d.ts +919 -0
  284. package/dist/types/prediction-apy.js +121 -0
  285. package/dist/types/prediction-apy.js.map +1 -0
  286. package/dist/types/prediction.d.ts +925 -0
  287. package/dist/types/prediction.js +140 -0
  288. package/dist/types/prediction.js.map +1 -0
  289. package/dist/venues/aave-v3/addresses.d.ts +6 -0
  290. package/dist/venues/aave-v3/addresses.js +19 -0
  291. package/dist/venues/aave-v3/addresses.js.map +1 -0
  292. package/dist/venues/aave-v3/client.d.ts +81 -0
  293. package/dist/venues/aave-v3/client.js +97 -0
  294. package/dist/venues/aave-v3/client.js.map +1 -0
  295. package/dist/venues/chainlink/client.d.ts +99 -0
  296. package/dist/venues/chainlink/client.js +130 -0
  297. package/dist/venues/chainlink/client.js.map +1 -0
  298. package/dist/venues/chainlink/feeds.d.ts +8 -0
  299. package/dist/venues/chainlink/feeds.js +9 -0
  300. package/dist/venues/chainlink/feeds.js.map +1 -0
  301. package/dist/venues/hyperliquid/account-value.d.ts +30 -0
  302. package/dist/venues/hyperliquid/account-value.js +30 -0
  303. package/dist/venues/hyperliquid/account-value.js.map +1 -0
  304. package/dist/venues/hyperliquid/client.d.ts +63 -0
  305. package/dist/venues/hyperliquid/client.js +135 -0
  306. package/dist/venues/hyperliquid/client.js.map +1 -0
  307. package/dist/venues/hyperliquid/grid.d.ts +36 -0
  308. package/dist/venues/hyperliquid/grid.js +61 -0
  309. package/dist/venues/hyperliquid/grid.js.map +1 -0
  310. package/dist/venues/hyperliquid/types.d.ts +81 -0
  311. package/dist/venues/hyperliquid/types.js +8 -0
  312. package/dist/venues/hyperliquid/types.js.map +1 -0
  313. package/dist/withdraw/run-withdraw-plan.js +2 -0
  314. package/dist/withdraw/run-withdraw-plan.js.map +1 -1
  315. package/docker-compose.yml +44 -0
  316. package/package.json +12 -1
  317. package/skills/jinn-operator/SKILL.md +85 -0
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Restorer engine — mech delivery + JinnRouter.claimDelivery.
3
+ *
4
+ * §6.1 DELIVERING phase.
5
+ *
6
+ * Steps:
7
+ * 1. Encode manifest CID as bytes32 digest (cidToDigestHex).
8
+ * 2. Call mech.deliverToMarketplace(requestId, deliveryDigest) via the Safe.
9
+ * 3. Call JinnRouter.claimDelivery(requestId, evidenceHash) where evidenceHash
10
+ * is the keccak256 hash of the signed manifest (from manifest assembly).
11
+ */
12
+ import type { Hex, PublicClient, WalletClient, Address } from 'viem';
13
+ export interface DeliveryDeps {
14
+ publicClient: PublicClient;
15
+ walletClient: WalletClient;
16
+ safeAddress: Address;
17
+ mechContractAddress: Address;
18
+ routerAddress: Address;
19
+ /** v1 or v2 claimDelivery encoding — matches chain config */
20
+ claimDeliveryVariant: 'v1' | 'v2';
21
+ }
22
+ /**
23
+ * Callback invoked after deliverToMarketplace lands on-chain but BEFORE
24
+ * claimDelivery is called. Callers use this to durably persist the tx hash so
25
+ * that a crash between the two steps can be recovered without re-submitting the
26
+ * deliver transaction.
27
+ */
28
+ export type OnDeliveryTxLanded = (deliveryTxHash: Hex) => void | Promise<void>;
29
+ export interface DeliveryResult {
30
+ deliveryTxHash: Hex;
31
+ claimTxHash: Hex;
32
+ }
33
+ /**
34
+ * Deliver the manifest to the marketplace and claim the delivery on JinnRouter.
35
+ *
36
+ * Crash-recovery safe: if `preExistingDeliveryTxHash` is provided, the
37
+ * deliverToMarketplace step is skipped entirely — the function resumes from
38
+ * the claimDelivery step only. This handles the case where the process crashed
39
+ * after deliver landed on-chain but before the COMPLETE transition was persisted.
40
+ *
41
+ * @param requestId The on-chain request ID (bytes32 hex).
42
+ * @param manifestCid IPFS CID of the signed manifest.
43
+ * @param evidenceHash keccak256 hash of the canonical manifest JSON
44
+ * (from manifest assembly) — used as evidenceHash in claimDelivery V2.
45
+ * @param deps Viem clients + contract addresses.
46
+ * @param preExistingDeliveryTxHash If set, skip deliverToMarketplace and use
47
+ * this as the deliveryTxHash in the result.
48
+ * @param onDeliveryTxLanded Optional callback invoked after
49
+ * deliverToMarketplace succeeds, before claimDelivery. Use this to persist the
50
+ * tx hash so recovery can skip the deliver step on restart.
51
+ */
52
+ export declare function deliverAndClaim(requestId: Hex, manifestCid: string, evidenceHash: Hex, deps: DeliveryDeps, preExistingDeliveryTxHash?: Hex, onDeliveryTxLanded?: OnDeliveryTxLanded): Promise<DeliveryResult>;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Restorer engine — mech delivery + JinnRouter.claimDelivery.
3
+ *
4
+ * §6.1 DELIVERING phase.
5
+ *
6
+ * Steps:
7
+ * 1. Encode manifest CID as bytes32 digest (cidToDigestHex).
8
+ * 2. Call mech.deliverToMarketplace(requestId, deliveryDigest) via the Safe.
9
+ * 3. Call JinnRouter.claimDelivery(requestId, evidenceHash) where evidenceHash
10
+ * is the keccak256 hash of the signed manifest (from manifest assembly).
11
+ */
12
+ import { cidToDigestHex, } from '../../adapters/mech/ipfs.js';
13
+ import { callDeliverToMarketplace, claimDelivery, } from '../../adapters/mech/contracts.js';
14
+ /**
15
+ * Deliver the manifest to the marketplace and claim the delivery on JinnRouter.
16
+ *
17
+ * Crash-recovery safe: if `preExistingDeliveryTxHash` is provided, the
18
+ * deliverToMarketplace step is skipped entirely — the function resumes from
19
+ * the claimDelivery step only. This handles the case where the process crashed
20
+ * after deliver landed on-chain but before the COMPLETE transition was persisted.
21
+ *
22
+ * @param requestId The on-chain request ID (bytes32 hex).
23
+ * @param manifestCid IPFS CID of the signed manifest.
24
+ * @param evidenceHash keccak256 hash of the canonical manifest JSON
25
+ * (from manifest assembly) — used as evidenceHash in claimDelivery V2.
26
+ * @param deps Viem clients + contract addresses.
27
+ * @param preExistingDeliveryTxHash If set, skip deliverToMarketplace and use
28
+ * this as the deliveryTxHash in the result.
29
+ * @param onDeliveryTxLanded Optional callback invoked after
30
+ * deliverToMarketplace succeeds, before claimDelivery. Use this to persist the
31
+ * tx hash so recovery can skip the deliver step on restart.
32
+ */
33
+ export async function deliverAndClaim(requestId, manifestCid, evidenceHash, deps, preExistingDeliveryTxHash, onDeliveryTxLanded) {
34
+ let deliveryTxHash;
35
+ if (preExistingDeliveryTxHash) {
36
+ // Recovery path: deliverToMarketplace already landed on a previous run.
37
+ console.log(`[restorer-engine] deliverToMarketplace already done (recovery), tx=${preExistingDeliveryTxHash}`);
38
+ deliveryTxHash = preExistingDeliveryTxHash;
39
+ }
40
+ else {
41
+ // 1. Convert manifest CID to 32-byte digest for on-chain delivery data
42
+ const deliveryDigest = cidToDigestHex(manifestCid);
43
+ // 2. deliverToMarketplace via Safe
44
+ console.log(`[restorer-engine] deliverToMarketplace requestId=${requestId}`);
45
+ deliveryTxHash = await callDeliverToMarketplace(deps.publicClient, deps.walletClient, deps.safeAddress, deps.mechContractAddress, [requestId], [deliveryDigest]);
46
+ console.log(`[restorer-engine] deliverToMarketplace tx=${deliveryTxHash}`);
47
+ // Persist the tx hash before proceeding to claimDelivery. If the process
48
+ // crashes between here and the COMPLETE transition, recovery will read this
49
+ // hash and skip the deliver step.
50
+ if (onDeliveryTxLanded) {
51
+ await onDeliveryTxLanded(deliveryTxHash);
52
+ }
53
+ }
54
+ // 3. claimDelivery on JinnRouter
55
+ console.log(`[restorer-engine] claimDelivery requestId=${requestId}`);
56
+ const claimTxHash = await claimDelivery(deps.publicClient, deps.walletClient, deps.safeAddress, deps.routerAddress, requestId, {
57
+ variant: deps.claimDeliveryVariant,
58
+ evidenceHash: deps.claimDeliveryVariant === 'v2' ? evidenceHash : undefined,
59
+ });
60
+ console.log(`[restorer-engine] claimDelivery tx=${claimTxHash}`);
61
+ return { deliveryTxHash, claimTxHash };
62
+ }
63
+ //# sourceMappingURL=delivery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delivery.js","sourceRoot":"","sources":["../../../src/restorer/engine/delivery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EACL,cAAc,GACf,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,wBAAwB,EACxB,aAAa,GACd,MAAM,kCAAkC,CAAC;AA6B1C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,SAAc,EACd,WAAmB,EACnB,YAAiB,EACjB,IAAkB,EAClB,yBAA+B,EAC/B,kBAAuC;IAEvC,IAAI,cAAmB,CAAC;IAExB,IAAI,yBAAyB,EAAE,CAAC;QAC9B,wEAAwE;QACxE,OAAO,CAAC,GAAG,CAAC,sEAAsE,yBAAyB,EAAE,CAAC,CAAC;QAC/G,cAAc,GAAG,yBAAyB,CAAC;IAC7C,CAAC;SAAM,CAAC;QACN,uEAAuE;QACvE,MAAM,cAAc,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;QAEnD,mCAAmC;QACnC,OAAO,CAAC,GAAG,CAAC,oDAAoD,SAAS,EAAE,CAAC,CAAC;QAC7E,cAAc,GAAG,MAAM,wBAAwB,CAC7C,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,mBAAmB,EACxB,CAAC,SAAS,CAAC,EACX,CAAC,cAAc,CAAC,CACjB,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,6CAA6C,cAAc,EAAE,CAAC,CAAC;QAE3E,yEAAyE;QACzE,4EAA4E;QAC5E,kCAAkC;QAClC,IAAI,kBAAkB,EAAE,CAAC;YACvB,MAAM,kBAAkB,CAAC,cAAc,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAED,iCAAiC;IACjC,OAAO,CAAC,GAAG,CAAC,6CAA6C,SAAS,EAAE,CAAC,CAAC;IACtE,MAAM,WAAW,GAAG,MAAM,aAAa,CACrC,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,aAAa,EAClB,SAAS,EACT;QACE,OAAO,EAAE,IAAI,CAAC,oBAAoB;QAClC,YAAY,EAAE,IAAI,CAAC,oBAAoB,KAAK,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;KAC5E,CACF,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,sCAAsC,WAAW,EAAE,CAAC,CAAC;IAEjE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC;AACzC,CAAC"}
@@ -0,0 +1,203 @@
1
+ /**
2
+ * Restorer engine — main RestorationEngine 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 intent.
7
+ * Transition method bodies are stubs; subsequent tasks fill them in.
8
+ */
9
+ import { IntentPersistence, type PersistedIntent, type PersistedIntentInput } from './persistence.js';
10
+ import type { Store } from '../../store/store.js';
11
+ import { type MarketplaceClaimer } from './claim.js';
12
+ import type { ClaimRegistryClient } from '../../adapters/claim-registry/client.js';
13
+ import { type PackagingDeps } from './packaging.js';
14
+ import { type ManifestAssemblyDeps } from './manifest-assembly.js';
15
+ import { type DeliveryDeps } from './delivery.js';
16
+ import type { RestorerImpl } from '../types.js';
17
+ export declare class NotImplementedError extends Error {
18
+ readonly transitionName: string;
19
+ constructor(transitionName: string);
20
+ }
21
+ export interface RestorerImplRegistry {
22
+ /** Returns the impl name for a given spec kind (and optional type), or null if none registered. */
23
+ resolveImplName(ctx: {
24
+ kind: string | null;
25
+ type?: 'restoration' | 'evaluation';
26
+ }): string | null;
27
+ }
28
+ export interface RestorationEngineOptions {
29
+ store: Store;
30
+ registry: RestorerImplRegistry;
31
+ paths: {
32
+ workingDirRoot: string;
33
+ implStateDirRoot: string;
34
+ };
35
+ /**
36
+ * Injected claim dependencies. When provided, engine.claim() is functional.
37
+ * When absent, claim() falls back to NotImplementedError (useful for tests
38
+ * that don't exercise the claim path).
39
+ */
40
+ claimDeps?: {
41
+ registryClient: ClaimRegistryClient;
42
+ marketplaceClaimer: MarketplaceClaimer;
43
+ };
44
+ /**
45
+ * Packaging dependencies. When provided, pack() is functional.
46
+ * When absent, pack() falls back to NotImplementedError.
47
+ */
48
+ packagingDeps?: PackagingDeps;
49
+ /**
50
+ * Manifest assembly dependencies. When provided, pack() can assemble + sign.
51
+ * When absent, pack() falls back to NotImplementedError.
52
+ */
53
+ manifestDeps?: ManifestAssemblyDeps;
54
+ /**
55
+ * Delivery dependencies. When provided, deliver() is functional.
56
+ * When absent, deliver() falls back to NotImplementedError.
57
+ */
58
+ deliveryDeps?: DeliveryDeps;
59
+ /**
60
+ * Impl registry for resolving which RestorerImpl to run.
61
+ * When provided and findFor() returns an impl, runImpl() dispatches to it.
62
+ */
63
+ implRegistry?: {
64
+ findFor(ctx: {
65
+ kind: string;
66
+ type?: 'restoration' | 'evaluation';
67
+ }): RestorerImpl | undefined;
68
+ };
69
+ }
70
+ /** Per-intent outcome from a recovery pass. */
71
+ export interface RecoveryReport {
72
+ requestId: string;
73
+ outcome: 'ok' | 'failed';
74
+ error?: string;
75
+ }
76
+ export declare class RestorationEngine {
77
+ protected readonly persistence: IntentPersistence;
78
+ protected readonly registry: RestorerImplRegistry;
79
+ protected readonly paths: RestorationEngineOptions['paths'];
80
+ protected readonly claimDeps: RestorationEngineOptions['claimDeps'];
81
+ protected readonly packagingDeps: RestorationEngineOptions['packagingDeps'];
82
+ protected readonly manifestDeps: RestorationEngineOptions['manifestDeps'];
83
+ protected readonly deliveryDeps: RestorationEngineOptions['deliveryDeps'];
84
+ protected readonly implRegistry: RestorationEngineOptions['implRegistry'];
85
+ private readonly implOutputs;
86
+ /** Set by stop(); causes runTickLoop to exit at the next iteration. */
87
+ private stopped;
88
+ constructor(opts: RestorationEngineOptions);
89
+ /**
90
+ * Called when an intent is observed from an on-chain event.
91
+ * Persists a DISCOVERED row. Idempotent: if the row already exists, no-op.
92
+ */
93
+ observe(input: PersistedIntentInput): Promise<void>;
94
+ /**
95
+ * Recover all in-flight intents from persisted state.
96
+ * Called at daemon startup before beginning normal event processing.
97
+ * Returns a per-intent report for each intent attempted.
98
+ */
99
+ recoverInFlight(): Promise<RecoveryReport[]>;
100
+ /**
101
+ * Periodic tick: advance every in-flight intent by one transition.
102
+ * Called by `runTickLoop` so that intents which entered a non-event-driven
103
+ * state (e.g. CLAIMED waiting for windowStartTs) get re-driven without
104
+ * waiting for a daemon restart or a fresh marketplace event.
105
+ *
106
+ * Errors from individual intents are logged but do not stop the loop.
107
+ */
108
+ tick(): Promise<void>;
109
+ /**
110
+ * Drive `tick()` on a fixed interval until `stop()` is called.
111
+ * Errors thrown by tick() itself are logged and do not stop the loop.
112
+ */
113
+ runTickLoop(intervalMs: number): Promise<void>;
114
+ /** Signal `runTickLoop` to exit at the next iteration. */
115
+ stop(): void;
116
+ /**
117
+ * Process a single intent: dispatch by current state to the appropriate
118
+ * transition. Drives one state transition per call.
119
+ *
120
+ * Called both by recovery and by the ongoing event-processing loop.
121
+ */
122
+ process(requestId: string): Promise<void>;
123
+ /**
124
+ * Two-layer claim: ClaimRegistry + Marketplace.
125
+ *
126
+ * Idempotent on resume: checks ClaimRegistry for a pre-existing claim before
127
+ * sending any on-chain transaction.
128
+ *
129
+ * Advances state DISCOVERED → CLAIMED on success.
130
+ * Marks FAILED if either layer cannot be claimed.
131
+ *
132
+ * Requires claimDeps to be injected via constructor options. Falls back to
133
+ * NotImplementedError if claimDeps is absent (development / test mode).
134
+ */
135
+ protected claim(intent: PersistedIntent): Promise<void>;
136
+ /**
137
+ * Release ClaimRegistry claims for all CLAIMED intents whose work window has
138
+ * not yet started. Called on graceful engine shutdown.
139
+ *
140
+ * Returns the list of requestIds that were successfully released.
141
+ */
142
+ releaseClaimedNotStarted(): Promise<string[]>;
143
+ /**
144
+ * PRE_SNAPSHOT transition: provision workingDir + implStateDir, write
145
+ * intent.json + env/ files, create sessions/ directory.
146
+ *
147
+ * Requires no external deps beyond filesystem access — always implemented.
148
+ * Advances state PRE_SNAPSHOT with workingDir + implStateDir patch.
149
+ */
150
+ protected takePreSnapshot(intent: PersistedIntent): Promise<void>;
151
+ /**
152
+ * RUNNING transition: dispatch to a RestorerImpl if implRegistry is provided.
153
+ *
154
+ * When no impl is found for the spec kind, falls back to NotImplementedError
155
+ * so the engine does not silently swallow the request. In tests that don't
156
+ * exercise the impl path, override this method.
157
+ *
158
+ * Captures impl output in `implOutputs` map for pack() to consume. Also
159
+ * records a minimal post-snapshot so data-driven advance can fire.
160
+ */
161
+ protected runImpl(intent: PersistedIntent): Promise<void>;
162
+ protected takePostSnapshot(_intent: PersistedIntent): Promise<void>;
163
+ /**
164
+ * PACKAGING transition: walk workingDir, upload artifacts, assemble + sign
165
+ * manifest, upload manifest, persist manifest CID + artifact CIDs.
166
+ *
167
+ * Requires packagingDeps + manifestDeps. When absent, falls back to
168
+ * NotImplementedError.
169
+ */
170
+ protected pack(intent: PersistedIntent): Promise<void>;
171
+ /**
172
+ * DELIVERING transition: call mech.deliverToMarketplace + JinnRouter.claimDelivery.
173
+ *
174
+ * Requires deliveryDeps. When absent, falls back to NotImplementedError.
175
+ *
176
+ * Crash-recovery safe: if `intent.deliveryTxHash` is already set (persisted
177
+ * after a previous deliverToMarketplace call that completed before the process
178
+ * crashed), we skip the deliver step and go straight to claimDelivery.
179
+ */
180
+ protected deliver(intent: PersistedIntent): Promise<void>;
181
+ /**
182
+ * Returns the next state if the current state can be advanced purely from
183
+ * persisted data (no external work needed), or null if external work is required.
184
+ *
185
+ * Used for crash recovery and for collapsing transitions in process()
186
+ * when a previous run already produced the data.
187
+ */
188
+ private dataDrivenAdvance;
189
+ /**
190
+ * Wraps a transition method call with error handling: if the transition
191
+ * throws, the intent is marked FAILED with the error message.
192
+ */
193
+ private _runTransition;
194
+ /**
195
+ * Recovery handler for a single in-flight intent.
196
+ * Dispatches by state per §6.5.
197
+ */
198
+ private _recoverOne;
199
+ /**
200
+ * Per-state recovery dispatch per §6.5.
201
+ */
202
+ private _recoverDispatch;
203
+ }