@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,137 @@
1
+ /**
2
+ * Session orchestrator for claude-mcp-prediction.
3
+ *
4
+ * Single-session (no cadence loop, no market-move triggers). Spawns Claude
5
+ * once with the prediction MCP + prompt, polls a shared "submitted" flag to
6
+ * detect `submit_prediction` tool call, and terminates after a short grace
7
+ * period so Claude's tool response reaches it.
8
+ *
9
+ * Slimmed-down version of:
10
+ * client/src/restorer/impls/claude-mcp-hyperliquid/session-orchestrator.ts:97-209
11
+ */
12
+ import { appendFileSync, mkdirSync, writeFileSync } from 'node:fs';
13
+ import { join } from 'node:path';
14
+ import { spawn } from 'node:child_process';
15
+ const DEFAULT_SESSION_MAX_MS = 180_000;
16
+ const DEFAULT_POLL_INTERVAL_MS = 500;
17
+ const DEFAULT_SUBMISSION_GRACE_MS = 2_000;
18
+ export async function spawnSession(sessionId, prompt, deps) {
19
+ const sessionMaxMs = deps.sessionMaxMs ?? DEFAULT_SESSION_MAX_MS;
20
+ const pollIntervalMs = deps.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
21
+ const submissionGraceMs = deps.submissionGraceMs ?? DEFAULT_SUBMISSION_GRACE_MS;
22
+ const sessionDir = join(deps.workingDir, 'sessions', sessionId);
23
+ mkdirSync(sessionDir, { recursive: true });
24
+ const transcriptPath = join(sessionDir, 'transcript.txt');
25
+ const startedAt = Date.now();
26
+ writeFileSync(transcriptPath, `=== Session ${sessionId} started at ${new Date(startedAt).toISOString()} ===\n\n`);
27
+ const args = [
28
+ '-p', prompt,
29
+ '--mcp-config', deps.mcpConfigPath,
30
+ '--strict-mcp-config',
31
+ '--allowedTools', 'mcp__jinn-prediction__*',
32
+ ];
33
+ if (deps.claudeModel)
34
+ args.push('--model', deps.claudeModel);
35
+ // Minimal env allowlist — same set as the HL orchestrator.
36
+ const agentEnv = {};
37
+ for (const key of [
38
+ 'PATH', 'HOME', 'USER', 'SHELL', 'LANG', 'TERM', 'TMPDIR',
39
+ 'XDG_CONFIG_HOME', 'XDG_DATA_HOME', 'XDG_CACHE_HOME',
40
+ 'NODE_PATH', 'NODE_OPTIONS', 'NPM_CONFIG_PREFIX',
41
+ // Anthropic auth — required for Claude Code to reach the model.
42
+ 'CLAUDE_CODE_OAUTH_TOKEN', 'ANTHROPIC_API_KEY',
43
+ ]) {
44
+ if (process.env[key])
45
+ agentEnv[key] = process.env[key];
46
+ }
47
+ deps.log({ level: 'info', msg: `prediction-session: spawning ${sessionId}`, data: { claudePath: deps.claudePath } });
48
+ const spawnFn = deps._spawnFn ?? spawn;
49
+ return new Promise((resolve) => {
50
+ const child = spawnFn(deps.claudePath, args, {
51
+ stdio: ['ignore', 'pipe', 'pipe'],
52
+ env: agentEnv,
53
+ });
54
+ let stdout = '';
55
+ let aborted = false;
56
+ let terminatedEarly = false;
57
+ child.stdout?.on('data', (d) => {
58
+ const chunk = d.toString();
59
+ stdout += chunk;
60
+ appendFileSync(transcriptPath, chunk);
61
+ });
62
+ child.stderr?.on('data', (d) => {
63
+ appendFileSync(transcriptPath, `[stderr] ${d.toString()}`);
64
+ });
65
+ const sessionTimeout = setTimeout(() => {
66
+ if (!child.killed) {
67
+ deps.log({ level: 'warn', msg: `prediction-session: ${sessionId} reached sessionMaxMs; killing`, data: { sessionMaxMs } });
68
+ child.kill('SIGTERM');
69
+ }
70
+ }, sessionMaxMs);
71
+ // Poll for submit_prediction: once the flag flips, give Claude a short grace
72
+ // window to receive the tool response + close the connection, then SIGTERM.
73
+ let graceTimer = null;
74
+ const pollTimer = setInterval(() => {
75
+ if (graceTimer || child.killed)
76
+ return;
77
+ if (deps.isSubmitted()) {
78
+ deps.log({ level: 'info', msg: `prediction-session: ${sessionId} submit_prediction invoked; scheduling graceful termination` });
79
+ terminatedEarly = true;
80
+ graceTimer = setTimeout(() => {
81
+ if (!child.killed)
82
+ child.kill('SIGTERM');
83
+ }, submissionGraceMs);
84
+ }
85
+ }, pollIntervalMs);
86
+ const onAbort = () => {
87
+ if (aborted)
88
+ return;
89
+ aborted = true;
90
+ deps.log({ level: 'info', msg: `prediction-session: ${sessionId} window abort; killing` });
91
+ child.kill('SIGTERM');
92
+ };
93
+ deps.abort.addEventListener('abort', onAbort);
94
+ const cleanup = () => {
95
+ clearTimeout(sessionTimeout);
96
+ if (graceTimer)
97
+ clearTimeout(graceTimer);
98
+ clearInterval(pollTimer);
99
+ deps.abort.removeEventListener('abort', onAbort);
100
+ };
101
+ child.on('exit', (code, signal) => {
102
+ cleanup();
103
+ const endedAt = Date.now();
104
+ appendFileSync(transcriptPath, `\n\n=== Session ended at ${new Date(endedAt).toISOString()} (code=${code} signal=${signal} submitted=${deps.isSubmitted()} terminatedEarly=${terminatedEarly} aborted=${aborted}) ===\n`);
105
+ deps.log({
106
+ level: 'info',
107
+ msg: `prediction-session: ${sessionId} exited`,
108
+ data: { code, signal, durationMs: endedAt - startedAt, submitted: deps.isSubmitted(), aborted },
109
+ });
110
+ resolve({
111
+ sessionId,
112
+ startedAt,
113
+ endedAt,
114
+ transcriptPath,
115
+ submitted: deps.isSubmitted(),
116
+ stdout,
117
+ aborted: aborted || deps.abort.aborted,
118
+ });
119
+ });
120
+ child.on('error', (err) => {
121
+ cleanup();
122
+ const endedAt = Date.now();
123
+ appendFileSync(transcriptPath, `\n\n=== Session spawn error: ${err.message} ===\n`);
124
+ deps.log({ level: 'error', msg: `prediction-session: ${sessionId} spawn error`, data: { err: err.message } });
125
+ resolve({
126
+ sessionId,
127
+ startedAt,
128
+ endedAt,
129
+ transcriptPath,
130
+ submitted: deps.isSubmitted(),
131
+ stdout,
132
+ aborted: deps.abort.aborted,
133
+ });
134
+ });
135
+ });
136
+ }
137
+ //# sourceMappingURL=session-orchestrator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-orchestrator.js","sourceRoot":"","sources":["../../../../src/restorer/impls/claude-mcp-prediction/session-orchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AAsB9D,MAAM,sBAA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AAI,CAAC,GAAG,EAAE,CAAC;YAC3B,cAAc,CAAC,cAAc,EAAE,gCAAgC,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC;YACpF,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,uBAAuB,SAAS,cAAc,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAC9G,OAAO,CAAC;gBACN,SAAS;gBACT,SAAS;gBACT,OAAO;gBACP,cAAc;gBACd,SAAS,EAAE,IAAI,CAAC,WAAW,EAAE;gBAC7B,MAAM;gBACN,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO;aAC5B,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Types for claude-mcp-prediction — a RestorerImpl that spawns Claude with
3
+ * two MCP tools to decide a prediction.v0 probability.
4
+ */
5
+ import type { PublicClient } from 'viem';
6
+ export interface McpToolContent {
7
+ type: 'text';
8
+ text: string;
9
+ }
10
+ export interface McpToolResult {
11
+ content: McpToolContent[];
12
+ }
13
+ /** Discriminated union for the tool registry. Kept open to add future tools. */
14
+ export interface PredictionToolDefinition {
15
+ name: string;
16
+ description: string;
17
+ /** Zod object schema — registered as the MCP input-schema shape. */
18
+ schema: import('zod').ZodObject<import('zod').ZodRawShape>;
19
+ handler: (args: unknown) => Promise<McpToolResult>;
20
+ }
21
+ export interface SubmissionState {
22
+ probability: string | null;
23
+ rationale: string | null;
24
+ submittedAt: number | null;
25
+ }
26
+ export interface PredictionToolDeps {
27
+ /** Chainlink AggregatorV3 proxy address the intent is anchored to. */
28
+ feed: `0x${string}`;
29
+ /** Human-readable feed description, echoed in tool responses. */
30
+ feedDescription: string;
31
+ /** Venue label — used to sanity-check in the tool response. */
32
+ venue: 'chainlink-base' | 'chainlink-base-sepolia';
33
+ /** viem public client for reading the feed. */
34
+ publicClient: PublicClient;
35
+ /**
36
+ * Called when Claude invokes `submit_prediction`. The impl mutates its own
37
+ * SubmissionState via this callback and signals the orchestrator to terminate.
38
+ */
39
+ onSubmit: (submission: {
40
+ probability: string;
41
+ rationale: string;
42
+ }) => void;
43
+ }
44
+ export interface ClaudeMcpPredictionConfig {
45
+ rpcUrl?: string;
46
+ claudeModel?: string;
47
+ claudePath?: string;
48
+ /** Max wall time for the Claude session (ms). Default 3 min. */
49
+ sessionMaxMs?: number;
50
+ /** Injected deps for test mode — bypasses the real Claude spawn. */
51
+ _testDeps?: TestDeps;
52
+ }
53
+ export interface TestDeps {
54
+ /**
55
+ * Replacement for the real session spawn. Given the MCP config path + prompt,
56
+ * must eventually call the `onSubmit` callback registered on the tools
57
+ * (via in-process MCP, or by writing to the submission state directly).
58
+ *
59
+ * Minimum-viable mock: immediately invoke the submit callback passed in ctx,
60
+ * then return a stub SessionResult.
61
+ */
62
+ runSession?: (args: {
63
+ sessionId: string;
64
+ prompt: string;
65
+ mcpConfigPath: string;
66
+ workingDir: string;
67
+ implStateDir: string;
68
+ timeoutMs: number;
69
+ signalSubmit: (probability: string, rationale: string) => void;
70
+ }) => Promise<SessionResult>;
71
+ }
72
+ export interface SessionResult {
73
+ sessionId: string;
74
+ startedAt: number;
75
+ endedAt: number;
76
+ transcriptPath: string;
77
+ /** True iff `submit_prediction` was called before timeout/abort. */
78
+ submitted: boolean;
79
+ /** Accumulated stdout for post-mortem. */
80
+ stdout: string;
81
+ aborted: boolean;
82
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Types for claude-mcp-prediction — a RestorerImpl that spawns Claude with
3
+ * two MCP tools to decide a prediction.v0 probability.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/restorer/impls/claude-mcp-prediction/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * legacy-claude — RestorerImpl fallback for spec=undefined (health-check) intents.
3
+ *
4
+ * Wraps the existing ClaudeRunner so that intents with no spec.kind continue to
5
+ * work via the RestorationEngine. Registered as the default fallback in the impl
6
+ * registry (supports spec.kind === '').
7
+ *
8
+ * The engine calls findFor({ kind: '' }) for legacy intents because
9
+ * PersistedIntent.specKind is null → coerced to '' in runImpl().
10
+ */
11
+ import { type Runner } from '../../../runner/runner.js';
12
+ import type { RestorerImpl, RestorationContext, RestorationOutput, ReadyStatus, EnableResult, IntentEnableMetadata } from '../../types.js';
13
+ export interface LegacyClaudeConfig {
14
+ runner: Runner;
15
+ /** Passed to RunnerContext. Defaults to /tmp */
16
+ workingDirectory?: string;
17
+ /** Timeout in ms passed to runner. Defaults to 300000 */
18
+ timeoutMs?: number;
19
+ /** Passed to runner for artifact storage */
20
+ storePath?: string;
21
+ /** Daemon API URL for MCP server */
22
+ daemonApiUrl?: string;
23
+ }
24
+ export declare class LegacyClaudeImpl implements RestorerImpl {
25
+ private readonly config;
26
+ readonly name = "legacy-claude";
27
+ readonly version = "1.0.0";
28
+ constructor(config: LegacyClaudeConfig);
29
+ /**
30
+ * Supports the empty-string kind produced by the engine for intents with no spec.
31
+ * Also supports explicitly undefined-kind intents routed by registry default config.
32
+ */
33
+ supports(ctx: {
34
+ kind: string;
35
+ type?: 'restoration' | 'evaluation';
36
+ }): boolean;
37
+ canAttempt(): Promise<{
38
+ ok: true;
39
+ }>;
40
+ isReady(): Promise<ReadyStatus>;
41
+ enableMetadata(): IntentEnableMetadata;
42
+ onEnable(_args: Record<string, string | undefined>): Promise<EnableResult>;
43
+ run(ctx: RestorationContext): Promise<RestorationOutput>;
44
+ }
45
+ export default LegacyClaudeImpl;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * legacy-claude — RestorerImpl fallback for spec=undefined (health-check) intents.
3
+ *
4
+ * Wraps the existing ClaudeRunner so that intents with no spec.kind continue to
5
+ * work via the RestorationEngine. Registered as the default fallback in the impl
6
+ * registry (supports spec.kind === '').
7
+ *
8
+ * The engine calls findFor({ kind: '' }) for legacy intents because
9
+ * PersistedIntent.specKind is null → coerced to '' in runImpl().
10
+ */
11
+ // ── Impl ──────────────────────────────────────────────────────────────────────
12
+ export class LegacyClaudeImpl {
13
+ config;
14
+ name = 'legacy-claude';
15
+ version = '1.0.0';
16
+ constructor(config) {
17
+ this.config = config;
18
+ }
19
+ /**
20
+ * Supports the empty-string kind produced by the engine for intents with no spec.
21
+ * Also supports explicitly undefined-kind intents routed by registry default config.
22
+ */
23
+ supports(ctx) {
24
+ // legacy-claude handles restoration-type health-check intents with no spec.kind.
25
+ // It never runs as an evaluator.
26
+ if (ctx.type === 'evaluation')
27
+ return false;
28
+ return ctx.kind === '' || ctx.kind === 'legacy';
29
+ }
30
+ async canAttempt() {
31
+ return { ok: true };
32
+ }
33
+ async isReady() {
34
+ return { ready: true };
35
+ }
36
+ enableMetadata() {
37
+ return {
38
+ description: 'legacy-claude — handles health-check intents (no spec.kind). Always enabled.',
39
+ };
40
+ }
41
+ async onEnable(_args) {
42
+ return { status: 'ready' };
43
+ }
44
+ async run(ctx) {
45
+ const { intent, workingDir, log } = ctx;
46
+ log({ level: 'info', msg: 'legacy-claude: starting', data: { requestId: intent.id } });
47
+ const runnerCtx = {
48
+ requestId: intent.id,
49
+ workingDirectory: workingDir ?? this.config.workingDirectory ?? '/tmp',
50
+ timeoutMs: this.config.timeoutMs ?? 300_000,
51
+ storePath: this.config.storePath,
52
+ daemonApiUrl: this.config.daemonApiUrl,
53
+ };
54
+ const result = await this.config.runner.run(intent, runnerCtx);
55
+ log({ level: 'info', msg: 'legacy-claude: runner completed', data: { hasData: !!result.data } });
56
+ const output = {
57
+ venueRef: { name: 'legacy' },
58
+ gating: {
59
+ result: result.data,
60
+ },
61
+ informational: {
62
+ runnerResult: result.data,
63
+ artifactCount: result.artifacts?.length ?? 0,
64
+ },
65
+ artifacts: [],
66
+ };
67
+ return output;
68
+ }
69
+ }
70
+ export default LegacyClaudeImpl;
71
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/restorer/impls/legacy-claude/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AA0BH,iFAAiF;AAEjF,MAAM,OAAO,gBAAgB;IAIE;IAHpB,IAAI,GAAG,eAAe,CAAC;IACvB,OAAO,GAAG,OAAO,CAAC;IAE3B,YAA6B,MAA0B;QAA1B,WAAM,GAAN,MAAM,CAAoB;IAAG,CAAC;IAE3D;;;OAGG;IACH,QAAQ,CAAC,GAA0D;QACjE,iFAAiF;QACjF,iCAAiC;QACjC,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY;YAAE,OAAO,KAAK,CAAC;QAC5C,OAAO,GAAG,CAAC,IAAI,KAAK,EAAE,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC;IAClD,CAAC;IAED,KAAK,CAAC,UAAU;QACd,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACzB,CAAC;IAED,cAAc;QACZ,OAAO;YACL,WAAW,EACT,8EAA8E;SACjF,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAyC;QACtD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,GAAuB;QAC/B,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;QAExC,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,yBAAyB,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAEvF,MAAM,SAAS,GAAkB;YAC/B,SAAS,EAAE,MAAM,CAAC,EAAE;YACpB,gBAAgB,EAAE,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,gBAAgB,IAAI,MAAM;YACtE,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,OAAO;YAC3C,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS;YAChC,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY;SACvC,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAE/D,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,iCAAiC,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAEjG,MAAM,MAAM,GAAsB;YAChC,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC5B,MAAM,EAAE;gBACN,MAAM,EAAE,MAAM,CAAC,IAAI;aACpB;YACD,aAAa,EAAE;gBACb,YAAY,EAAE,MAAM,CAAC,IAAI;gBACzB,aAAa,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,IAAI,CAAC;aAC7C;YACD,SAAS,EAAE,EAAE;SACd,CAAC;QAEF,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Canonical metric computation for portfolio.v0 — §7.6.
3
+ *
4
+ * Single source of truth shared by both the restorer and evaluator.
5
+ * Pure functions; no I/O.
6
+ */
7
+ import type { HlFill } from '../../../venues/hyperliquid/types.js';
8
+ /** A single point on the equity curve: [timestamp_ms, accountValue_as_number]. */
9
+ export interface EquityPoint {
10
+ ts: number;
11
+ value: number;
12
+ }
13
+ /**
14
+ * Build an equity curve from the pre/post snapshot values and fills.
15
+ *
16
+ * Per §7.6: the curve is sampled at:
17
+ * - preSnapshot.capturedAt (value = preSnapshot accountValue)
18
+ * - every fill.time (value = inline equity; see note below)
19
+ * - postSnapshot.capturedAt (value = postSnapshot accountValue)
20
+ *
21
+ * Note: HL does not return per-fill equity. The evaluator uses the
22
+ * pre/post accountValues and the fill timestamps as curve shape anchors.
23
+ * For drawdown calculation purposes the curve is:
24
+ * pre-equity → (fills sorted by time but using pre/post values interpolated
25
+ * between them) → post-equity.
26
+ *
27
+ * Actually §7.6 says "sampled at preSnapshot.capturedAt + every fill.time +
28
+ * postSnapshot.capturedAt". Since HL only provides point-in-time equity at
29
+ * pre/post (not at each fill), the canonical approach is to use linear
30
+ * interpolation between the pre and post equity values at each fill timestamp.
31
+ * This matches what the restorer can compute and is deterministic.
32
+ */
33
+ export declare function equityCurve(preTs: number, preValue: number, postTs: number, postValue: number, fillTimes: number[]): EquityPoint[];
34
+ /**
35
+ * Compute max drawdown percentage over an equity curve.
36
+ *
37
+ * Per §7.6:
38
+ * Drawdown at P = 100 * (peak_so_far - equity_P) / peak_so_far
39
+ * maxDrawdownPct = max over all P
40
+ *
41
+ * Returns 0 if the curve has fewer than 2 points or no drawdown.
42
+ */
43
+ export declare function maxDrawdownPct(curve: EquityPoint[]): number;
44
+ /**
45
+ * Compute equity return percentage.
46
+ *
47
+ * Per §7.6: 100 * (postValue - preValue) / preValue
48
+ *
49
+ * Returns 0 if preValue is 0.
50
+ */
51
+ export declare function equityReturnPct(preValue: number, postValue: number): number;
52
+ /**
53
+ * Count fills where closedPnl is non-zero.
54
+ *
55
+ * Per §7.6: count of fills where closedPnl != 0
56
+ *
57
+ * Parses as float to handle "0", "0.0", "0.00", "-0.0", "+0.0" etc.
58
+ * NaN (non-numeric input) and empty string are treated as not-closed (excluded).
59
+ */
60
+ export declare function closedTradesCount(fills: HlFill[]): number;
61
+ /**
62
+ * Compute traded notional multiple.
63
+ *
64
+ * Per §7.6: sum_i(|sz_i * px_i|) / preValue
65
+ *
66
+ * Returns 0 if preValue is 0.
67
+ */
68
+ export declare function tradedNotionalMultiple(fills: HlFill[], preValue: number): number;
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Canonical metric computation for portfolio.v0 — §7.6.
3
+ *
4
+ * Single source of truth shared by both the restorer and evaluator.
5
+ * Pure functions; no I/O.
6
+ */
7
+ /**
8
+ * Build an equity curve from the pre/post snapshot values and fills.
9
+ *
10
+ * Per §7.6: the curve is sampled at:
11
+ * - preSnapshot.capturedAt (value = preSnapshot accountValue)
12
+ * - every fill.time (value = inline equity; see note below)
13
+ * - postSnapshot.capturedAt (value = postSnapshot accountValue)
14
+ *
15
+ * Note: HL does not return per-fill equity. The evaluator uses the
16
+ * pre/post accountValues and the fill timestamps as curve shape anchors.
17
+ * For drawdown calculation purposes the curve is:
18
+ * pre-equity → (fills sorted by time but using pre/post values interpolated
19
+ * between them) → post-equity.
20
+ *
21
+ * Actually §7.6 says "sampled at preSnapshot.capturedAt + every fill.time +
22
+ * postSnapshot.capturedAt". Since HL only provides point-in-time equity at
23
+ * pre/post (not at each fill), the canonical approach is to use linear
24
+ * interpolation between the pre and post equity values at each fill timestamp.
25
+ * This matches what the restorer can compute and is deterministic.
26
+ */
27
+ export function equityCurve(preTs, preValue, postTs, postValue, fillTimes) {
28
+ const points = [];
29
+ // Pre snapshot
30
+ points.push({ ts: preTs, value: preValue });
31
+ // Fill time points — linear interpolation between pre and post
32
+ const duration = postTs - preTs;
33
+ const sorted = [...fillTimes].sort((a, b) => a - b);
34
+ for (const ts of sorted) {
35
+ const clampedTs = Math.max(preTs, Math.min(postTs, ts));
36
+ const frac = duration > 0 ? (clampedTs - preTs) / duration : 0;
37
+ const value = preValue + frac * (postValue - preValue);
38
+ points.push({ ts: clampedTs, value });
39
+ }
40
+ // Post snapshot
41
+ points.push({ ts: postTs, value: postValue });
42
+ return points;
43
+ }
44
+ // ── maxDrawdownPct ────────────────────────────────────────────────────────────
45
+ /**
46
+ * Compute max drawdown percentage over an equity curve.
47
+ *
48
+ * Per §7.6:
49
+ * Drawdown at P = 100 * (peak_so_far - equity_P) / peak_so_far
50
+ * maxDrawdownPct = max over all P
51
+ *
52
+ * Returns 0 if the curve has fewer than 2 points or no drawdown.
53
+ */
54
+ export function maxDrawdownPct(curve) {
55
+ if (curve.length < 2)
56
+ return 0;
57
+ let peakSoFar = curve[0].value;
58
+ let maxDd = 0;
59
+ for (const point of curve) {
60
+ if (point.value > peakSoFar) {
61
+ peakSoFar = point.value;
62
+ }
63
+ if (peakSoFar > 0) {
64
+ const dd = (100 * (peakSoFar - point.value)) / peakSoFar;
65
+ if (dd > maxDd)
66
+ maxDd = dd;
67
+ }
68
+ }
69
+ return maxDd;
70
+ }
71
+ // ── equityReturnPct ───────────────────────────────────────────────────────────
72
+ /**
73
+ * Compute equity return percentage.
74
+ *
75
+ * Per §7.6: 100 * (postValue - preValue) / preValue
76
+ *
77
+ * Returns 0 if preValue is 0.
78
+ */
79
+ export function equityReturnPct(preValue, postValue) {
80
+ if (preValue === 0)
81
+ return 0;
82
+ return (100 * (postValue - preValue)) / preValue;
83
+ }
84
+ // ── closedTradesCount ─────────────────────────────────────────────────────────
85
+ /**
86
+ * Count fills where closedPnl is non-zero.
87
+ *
88
+ * Per §7.6: count of fills where closedPnl != 0
89
+ *
90
+ * Parses as float to handle "0", "0.0", "0.00", "-0.0", "+0.0" etc.
91
+ * NaN (non-numeric input) and empty string are treated as not-closed (excluded).
92
+ */
93
+ export function closedTradesCount(fills) {
94
+ return fills.filter((f) => {
95
+ const v = parseFloat(f.closedPnl);
96
+ return !isNaN(v) && v !== 0;
97
+ }).length;
98
+ }
99
+ // ── tradedNotionalMultiple ────────────────────────────────────────────────────
100
+ /**
101
+ * Compute traded notional multiple.
102
+ *
103
+ * Per §7.6: sum_i(|sz_i * px_i|) / preValue
104
+ *
105
+ * Returns 0 if preValue is 0.
106
+ */
107
+ export function tradedNotionalMultiple(fills, preValue) {
108
+ if (preValue === 0)
109
+ return 0;
110
+ const total = fills.reduce((acc, f) => {
111
+ const sz = parseFloat(f.sz);
112
+ const px = parseFloat(f.px);
113
+ return acc + Math.abs(sz * px);
114
+ }, 0);
115
+ return total / preValue;
116
+ }
117
+ //# sourceMappingURL=canonical-metrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical-metrics.js","sourceRoot":"","sources":["../../../../src/restorer/impls/portfolio-v0-evaluator/canonical-metrics.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,WAAW,CACzB,KAAa,EACb,QAAgB,EAChB,MAAc,EACd,SAAiB,EACjB,SAAmB;IAEnB,MAAM,MAAM,GAAkB,EAAE,CAAC;IAEjC,eAAe;IACf,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;IAE5C,+DAA+D;IAC/D,MAAM,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAC;IAChC,MAAM,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACpD,KAAK,MAAM,EAAE,IAAI,MAAM,EAAE,CAAC;QACxB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;QACxD,MAAM,IAAI,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,KAAK,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/D,MAAM,KAAK,GAAG,QAAQ,GAAG,IAAI,GAAG,CAAC,SAAS,GAAG,QAAQ,CAAC,CAAC;QACvD,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IACxC,CAAC;IAED,gBAAgB;IAChB,MAAM,CAAC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,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC,MAAM,CAAC;AACZ,CAAC;AAED,iFAAiF;AAEjF;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAe,EAAE,QAAgB;IACtE,IAAI,QAAQ,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;QACpC,MAAM,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC5B,MAAM,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC5B,OAAO,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;IACjC,CAAC,EAAE,CAAC,CAAC,CAAC;IACN,OAAO,KAAK,GAAG,QAAQ,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Availability checks for portfolio.v0.eval — §7.4.
3
+ *
4
+ * availability.hyperliquid_reachable
5
+ * availability.hl_pre_snapshot_rederivable
6
+ * availability.hl_fills_rederivable
7
+ *
8
+ * FAIL in any of these → verdict INDETERMINATE per §7.3.
9
+ */
10
+ import type { HlGridPoint } from '../../../../venues/hyperliquid/types.js';
11
+ import type { Check } from '../types.js';
12
+ /**
13
+ * Wraps a HL API call that should succeed if HL is reachable.
14
+ *
15
+ * Returns PASS if the call completes without throwing, FAIL otherwise.
16
+ */
17
+ export declare function checkHlReachable(reachable: boolean, errorMsg?: string): Check;
18
+ /**
19
+ * Check whether the pre-snapshot equity can be rederived from the portfolio
20
+ * grid. A bracket must exist around preTs.
21
+ *
22
+ * Returns PASS if a bracket is found, FAIL if the grid has no bracket.
23
+ */
24
+ export declare function checkPreSnapshotRederivable(grid: HlGridPoint[], preTs: number): Check;
25
+ /**
26
+ * Check whether fills could be fetched without clamping.
27
+ *
28
+ * If startTimeClamped is true, HL silently moved the retention horizon and
29
+ * fills are incomplete — FAIL.
30
+ */
31
+ export declare function checkFillsRederivable(startTimeClamped: boolean): Check;
32
+ /**
33
+ * Check whether the post-snapshot is rederivable (no funding accrual issue).
34
+ *
35
+ * Per §7.5: if postSnapshot.capturedAt > endTs + 60s, emit SKIP and
36
+ * downstream consistency checks should be skipped → INDETERMINATE.
37
+ *
38
+ * This check is named availability.hl_post_snapshot_rederivable and uses
39
+ * SKIP status to propagate INDETERMINATE via the derivation rule (SKIP ≠ FAIL
40
+ * for availability — a FAIL would cause INDETERMINATE, but SKIP means we
41
+ * surface it separately).
42
+ *
43
+ * However, per §7.3 the derivation rule is:
44
+ * if any "availability.*" FAIL → INDETERMINATE
45
+ *
46
+ * A SKIP doesn't trigger INDETERMINATE via the rule, so the eval impl must
47
+ * handle this edge case explicitly by checking for SKIP in downstream checks.
48
+ */
49
+ export declare function checkPostSnapshotFundingAccrual(postCapturedAt: number, endTs: number): Check;