@jinn-network/client 0.1.5 → 0.1.6-canary.6c3a341c

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 (338) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/dist/adapters/mech/adapter.js +7 -7
  3. package/dist/adapters/mech/adapter.js.map +1 -1
  4. package/dist/adapters/mech/ipfs-pinfile.d.ts +22 -0
  5. package/dist/adapters/mech/ipfs-pinfile.js +54 -0
  6. package/dist/adapters/mech/ipfs-pinfile.js.map +1 -0
  7. package/dist/adapters/mech/ipfs.d.ts +1 -0
  8. package/dist/adapters/mech/ipfs.js +24 -1
  9. package/dist/adapters/mech/ipfs.js.map +1 -1
  10. package/dist/api/bootstrap-endpoint.js +2 -0
  11. package/dist/api/bootstrap-endpoint.js.map +1 -1
  12. package/dist/api/discovery-endpoint.d.ts +18 -0
  13. package/dist/api/discovery-endpoint.js +65 -0
  14. package/dist/api/discovery-endpoint.js.map +1 -0
  15. package/dist/api/fleet-build.d.ts +7 -0
  16. package/dist/api/fleet-build.js +6 -1
  17. package/dist/api/fleet-build.js.map +1 -1
  18. package/dist/api/gather-status.js +9 -2
  19. package/dist/api/gather-status.js.map +1 -1
  20. package/dist/api/harness-readiness-endpoint.d.ts +25 -0
  21. package/dist/api/harness-readiness-endpoint.js +24 -0
  22. package/dist/api/harness-readiness-endpoint.js.map +1 -0
  23. package/dist/api/hermes-doctor-endpoint.d.ts +26 -0
  24. package/dist/api/hermes-doctor-endpoint.js +29 -0
  25. package/dist/api/hermes-doctor-endpoint.js.map +1 -0
  26. package/dist/api/server.d.ts +31 -0
  27. package/dist/api/server.js +28 -0
  28. package/dist/api/server.js.map +1 -1
  29. package/dist/api/setup-endpoints.js +11 -1
  30. package/dist/api/setup-endpoints.js.map +1 -1
  31. package/dist/build-info.json +4 -4
  32. package/dist/build-meta.json +1 -1
  33. package/dist/cli/commands/create.d.ts +5 -3
  34. package/dist/cli/commands/create.js +101 -36
  35. package/dist/cli/commands/create.js.map +1 -1
  36. package/dist/cli/commands/solver-nets.d.ts +19 -0
  37. package/dist/cli/commands/solver-nets.js +140 -2
  38. package/dist/cli/commands/solver-nets.js.map +1 -1
  39. package/dist/cli/commands/solver-plugins-publish.d.ts +31 -0
  40. package/dist/cli/commands/solver-plugins-publish.js +169 -0
  41. package/dist/cli/commands/solver-plugins-publish.js.map +1 -0
  42. package/dist/cli/commands/solver-plugins-revoke.d.ts +15 -0
  43. package/dist/cli/commands/solver-plugins-revoke.js +91 -0
  44. package/dist/cli/commands/solver-plugins-revoke.js.map +1 -0
  45. package/dist/cli/commands/solver-plugins.d.ts +50 -6
  46. package/dist/cli/commands/solver-plugins.js +205 -68
  47. package/dist/cli/commands/solver-plugins.js.map +1 -1
  48. package/dist/config.d.ts +27 -0
  49. package/dist/config.js +24 -0
  50. package/dist/config.js.map +1 -1
  51. package/dist/conformance/checks/hash-signature.js +6 -2
  52. package/dist/conformance/checks/hash-signature.js.map +1 -1
  53. package/dist/conformance/checks/payload.js +4 -2
  54. package/dist/conformance/checks/payload.js.map +1 -1
  55. package/dist/conformance/checks/verdict.d.ts +10 -10
  56. package/dist/conformance/checks/verdict.js +16 -15
  57. package/dist/conformance/checks/verdict.js.map +1 -1
  58. package/dist/conformance/harness.d.ts +1 -1
  59. package/dist/conformance/harness.js +16 -9
  60. package/dist/conformance/harness.js.map +1 -1
  61. package/dist/conformance/types.d.ts +10 -3
  62. package/dist/conformance/types.js.map +1 -1
  63. package/dist/corpus/acquire.d.ts +1 -3
  64. package/dist/corpus/acquire.js.map +1 -1
  65. package/dist/corpus/envelope-projection.d.ts +1 -1
  66. package/dist/corpus/envelope-projection.js +14 -7
  67. package/dist/corpus/envelope-projection.js.map +1 -1
  68. package/dist/corpus/index.d.ts +2 -1
  69. package/dist/corpus/index.js.map +1 -1
  70. package/dist/corpus/prediction-brier-scoreboard-report.js +1 -1
  71. package/dist/corpus/prediction-brier-scoreboard-report.js.map +1 -1
  72. package/dist/corpus/prediction-brier-scoreboard.js +3 -1
  73. package/dist/corpus/prediction-brier-scoreboard.js.map +1 -1
  74. package/dist/corpus/types.d.ts +2 -2
  75. package/dist/daemon/daemon.d.ts +17 -1
  76. package/dist/daemon/daemon.js +15 -0
  77. package/dist/daemon/daemon.js.map +1 -1
  78. package/dist/daemon/freeze-fence.js +6 -3
  79. package/dist/daemon/freeze-fence.js.map +1 -1
  80. package/dist/daemon/readiness-gate.d.ts +30 -0
  81. package/dist/daemon/readiness-gate.js +31 -0
  82. package/dist/daemon/readiness-gate.js.map +1 -0
  83. package/dist/dashboard/assets/{index-D_NMfDfV.css → index-B4sTrvQD.css} +1 -1
  84. package/dist/dashboard/assets/index-BEBclAMv.js +140 -0
  85. package/dist/dashboard/index.html +2 -2
  86. package/dist/discovery/http.js +121 -0
  87. package/dist/discovery/http.js.map +1 -1
  88. package/dist/discovery/onchain.js +11 -0
  89. package/dist/discovery/onchain.js.map +1 -1
  90. package/dist/discovery/types.d.ts +112 -0
  91. package/dist/discovery/types.js.map +1 -1
  92. package/dist/discovery/with-fallback.js +9 -0
  93. package/dist/discovery/with-fallback.js.map +1 -1
  94. package/dist/earning/agent-wallet-binding.d.ts +20 -1
  95. package/dist/earning/agent-wallet-binding.js +54 -16
  96. package/dist/earning/agent-wallet-binding.js.map +1 -1
  97. package/dist/earning/bootstrap.d.ts +63 -0
  98. package/dist/earning/bootstrap.js +393 -22
  99. package/dist/earning/bootstrap.js.map +1 -1
  100. package/dist/earning/funding-plan.js +9 -1
  101. package/dist/earning/funding-plan.js.map +1 -1
  102. package/dist/earning/store.js +48 -1
  103. package/dist/earning/store.js.map +1 -1
  104. package/dist/earning/types.d.ts +30 -0
  105. package/dist/earning/types.js +37 -0
  106. package/dist/earning/types.js.map +1 -1
  107. package/dist/erc8004/abis.d.ts +64 -0
  108. package/dist/erc8004/abis.js +48 -0
  109. package/dist/erc8004/abis.js.map +1 -1
  110. package/dist/erc8004/plugin-registry.d.ts +102 -0
  111. package/dist/erc8004/plugin-registry.js +165 -0
  112. package/dist/erc8004/plugin-registry.js.map +1 -0
  113. package/dist/events/types.d.ts +2 -2
  114. package/dist/harnesses/engine/engine.js +15 -3
  115. package/dist/harnesses/engine/engine.js.map +1 -1
  116. package/dist/harnesses/engine/envelope-assembly.d.ts +2 -2
  117. package/dist/harnesses/engine/envelope-assembly.js +4 -2
  118. package/dist/harnesses/engine/envelope-assembly.js.map +1 -1
  119. package/dist/harnesses/freeze.d.ts +4 -1
  120. package/dist/harnesses/freeze.js +12 -2
  121. package/dist/harnesses/freeze.js.map +1 -1
  122. package/dist/harnesses/impls/claude-mcp-prediction/index.d.ts +4 -1
  123. package/dist/harnesses/impls/claude-mcp-prediction/index.js +7 -2
  124. package/dist/harnesses/impls/claude-mcp-prediction/index.js.map +1 -1
  125. package/dist/harnesses/impls/claude-mcp-prediction-apy/index.d.ts +4 -1
  126. package/dist/harnesses/impls/claude-mcp-prediction-apy/index.js +7 -2
  127. package/dist/harnesses/impls/claude-mcp-prediction-apy/index.js.map +1 -1
  128. package/dist/harnesses/impls/evaluation-context.d.ts +15 -4
  129. package/dist/harnesses/impls/evaluation-context.js +24 -8
  130. package/dist/harnesses/impls/evaluation-context.js.map +1 -1
  131. package/dist/harnesses/impls/hermes-agent/adapter.d.ts +34 -0
  132. package/dist/harnesses/impls/hermes-agent/adapter.js +184 -0
  133. package/dist/harnesses/impls/hermes-agent/adapter.js.map +1 -0
  134. package/dist/harnesses/impls/hermes-agent/bootstrap.d.ts +18 -0
  135. package/dist/harnesses/impls/hermes-agent/bootstrap.js +231 -0
  136. package/dist/harnesses/impls/hermes-agent/bootstrap.js.map +1 -0
  137. package/dist/harnesses/impls/hermes-agent/config-builder.d.ts +49 -0
  138. package/dist/harnesses/impls/hermes-agent/config-builder.js +104 -0
  139. package/dist/harnesses/impls/hermes-agent/config-builder.js.map +1 -0
  140. package/dist/harnesses/impls/hermes-agent/harness.d.ts +30 -0
  141. package/dist/harnesses/impls/hermes-agent/harness.js +52 -0
  142. package/dist/harnesses/impls/hermes-agent/harness.js.map +1 -0
  143. package/dist/harnesses/impls/hermes-agent/index.d.ts +5 -0
  144. package/dist/harnesses/impls/hermes-agent/index.js +7 -0
  145. package/dist/harnesses/impls/hermes-agent/index.js.map +1 -0
  146. package/dist/harnesses/impls/hermes-agent/prompt.d.ts +15 -0
  147. package/dist/harnesses/impls/hermes-agent/prompt.js +37 -0
  148. package/dist/harnesses/impls/hermes-agent/prompt.js.map +1 -0
  149. package/dist/harnesses/impls/index.d.ts +6 -0
  150. package/dist/harnesses/impls/index.js +17 -4
  151. package/dist/harnesses/impls/index.js.map +1 -1
  152. package/dist/harnesses/impls/learner/adapters/claude-code.js.map +1 -0
  153. package/dist/harnesses/impls/{claude-code-learner → learner}/adapters/codex-code.js +13 -34
  154. package/dist/harnesses/impls/learner/adapters/codex-code.js.map +1 -0
  155. package/dist/harnesses/impls/learner/adapters/codex-workspace.js.map +1 -0
  156. package/dist/harnesses/impls/{claude-code-learner → learner}/harness.d.ts +9 -3
  157. package/dist/harnesses/impls/{claude-code-learner → learner}/harness.js +24 -1
  158. package/dist/harnesses/impls/learner/harness.js.map +1 -0
  159. package/dist/harnesses/impls/{claude-code-learner → learner}/harvest.js +15 -3
  160. package/dist/harnesses/impls/learner/harvest.js.map +1 -0
  161. package/dist/harnesses/impls/{claude-code-learner → learner}/index.d.ts +5 -5
  162. package/dist/harnesses/impls/{claude-code-learner → learner}/index.js +4 -4
  163. package/dist/harnesses/impls/learner/index.js.map +1 -0
  164. package/dist/harnesses/impls/{claude-code-learner → learner}/plugin-path.d.ts +4 -4
  165. package/dist/harnesses/impls/{claude-code-learner → learner}/plugin-path.js +7 -7
  166. package/dist/harnesses/impls/learner/plugin-path.js.map +1 -0
  167. package/dist/harnesses/impls/{claude-code-learner → learner}/restoration-patch.js +3 -1
  168. package/dist/harnesses/impls/learner/restoration-patch.js.map +1 -0
  169. package/dist/harnesses/impls/learner/test-utils/fake-plugin-outputs.js.map +1 -0
  170. package/dist/harnesses/impls/learner/test-utils/noop-adapter.js.map +1 -0
  171. package/dist/harnesses/impls/{claude-code-learner → learner}/types.d.ts +12 -2
  172. package/dist/harnesses/impls/learner/types.js.map +1 -0
  173. package/dist/harnesses/impls/portfolio-v0-evaluator/index.js +13 -12
  174. package/dist/harnesses/impls/portfolio-v0-evaluator/index.js.map +1 -1
  175. package/dist/harnesses/impls/prediction-apy-v0-evaluator/index.js +7 -7
  176. package/dist/harnesses/impls/prediction-apy-v0-evaluator/index.js.map +1 -1
  177. package/dist/harnesses/impls/prediction-apy-v0-evaluator/parse-submission.d.ts +3 -3
  178. package/dist/harnesses/impls/prediction-apy-v0-evaluator/parse-submission.js +7 -6
  179. package/dist/harnesses/impls/prediction-apy-v0-evaluator/parse-submission.js.map +1 -1
  180. package/dist/harnesses/impls/prediction-v0-evaluator/checks/integrity.js +1 -1
  181. package/dist/harnesses/impls/prediction-v0-evaluator/checks/integrity.js.map +1 -1
  182. package/dist/harnesses/impls/prediction-v0-evaluator/index.js +11 -10
  183. package/dist/harnesses/impls/prediction-v0-evaluator/index.js.map +1 -1
  184. package/dist/harnesses/impls/prediction-v1-evaluator/index.js +11 -10
  185. package/dist/harnesses/impls/prediction-v1-evaluator/index.js.map +1 -1
  186. package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.d.ts +1 -0
  187. package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.js +10 -2
  188. package/dist/harnesses/impls/swe-rebench-v2-evaluator/eval-runner.js.map +1 -1
  189. package/dist/harnesses/impls/swe-rebench-v2-evaluator/harness.d.ts +24 -5
  190. package/dist/harnesses/impls/swe-rebench-v2-evaluator/harness.js +104 -4
  191. package/dist/harnesses/impls/swe-rebench-v2-evaluator/harness.js.map +1 -1
  192. package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.d.ts +9 -0
  193. package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.js +25 -1
  194. package/dist/harnesses/impls/swe-rebench-v2-evaluator/hf-fetcher.js.map +1 -1
  195. package/dist/harnesses/names.d.ts +1 -0
  196. package/dist/harnesses/names.js +3 -0
  197. package/dist/harnesses/names.js.map +1 -1
  198. package/dist/harnesses/readiness-registry.d.ts +48 -0
  199. package/dist/harnesses/readiness-registry.js +136 -0
  200. package/dist/harnesses/readiness-registry.js.map +1 -0
  201. package/dist/harnesses/types.d.ts +7 -0
  202. package/dist/main.d.ts +14 -0
  203. package/dist/main.js +92 -36
  204. package/dist/main.js.map +1 -1
  205. package/dist/mcp/server.js +14 -13
  206. package/dist/mcp/server.js.map +1 -1
  207. package/dist/operator-errors.js +13 -1
  208. package/dist/operator-errors.js.map +1 -1
  209. package/dist/preflight/claude-auth.d.ts +18 -0
  210. package/dist/preflight/claude-auth.js +38 -0
  211. package/dist/preflight/claude-auth.js.map +1 -1
  212. package/dist/scripts/donation-consumption-acceptance.js +1 -1
  213. package/dist/scripts/donation-consumption-acceptance.js.map +1 -1
  214. package/dist/scripts/swe-rebench-v2-known-bad.json +12 -0
  215. package/dist/scripts/swe-rebench-v2-seed-pool.json +26 -0
  216. package/dist/solver-types/_swe-rebench-v2-substrate.d.ts +52 -0
  217. package/dist/solver-types/_swe-rebench-v2-substrate.js +76 -0
  218. package/dist/solver-types/_swe-rebench-v2-substrate.js.map +1 -0
  219. package/dist/solver-types/_swe-rebench-v2-validated-pool.d.ts +38 -12
  220. package/dist/solver-types/_swe-rebench-v2-validated-pool.js +136 -27
  221. package/dist/solver-types/_swe-rebench-v2-validated-pool.js.map +1 -1
  222. package/dist/solver-types/swe-rebench-v2-auto.d.ts +6 -0
  223. package/dist/solver-types/swe-rebench-v2-auto.js.map +1 -1
  224. package/dist/solver-types/swe-rebench-v2.d.ts +1 -0
  225. package/dist/solver-types/swe-rebench-v2.js +19 -6
  226. package/dist/solver-types/swe-rebench-v2.js.map +1 -1
  227. package/dist/store/store.js +12 -4
  228. package/dist/store/store.js.map +1 -1
  229. package/dist/templates/plugins/runtime-plugin/.mcp.json.tmpl +8 -0
  230. package/dist/templates/plugins/runtime-plugin/README.md.tmpl +30 -0
  231. package/dist/templates/plugins/runtime-plugin/gitignore.tmpl +3 -0
  232. package/dist/templates/plugins/runtime-plugin/jinn.plugin.json.tmpl +21 -0
  233. package/dist/templates/plugins/runtime-plugin/mcp/server.mjs.tmpl +33 -0
  234. package/dist/templates/plugins/runtime-plugin/package.json.tmpl +15 -0
  235. package/dist/templates/plugins/runtime-plugin/test/plugin.test.ts.tmpl +35 -0
  236. package/dist/templates/plugins/runtime-plugin/tsconfig.json.tmpl +11 -0
  237. package/dist/templates/plugins/solver-type-plugin/README.md.tmpl +35 -0
  238. package/dist/templates/plugins/solver-type-plugin/gitignore.tmpl +3 -0
  239. package/dist/templates/plugins/solver-type-plugin/jinn.plugin.json.tmpl +11 -0
  240. package/dist/templates/plugins/solver-type-plugin/package.json.tmpl +15 -0
  241. package/dist/templates/plugins/solver-type-plugin/skills/example/SKILL.md.tmpl +10 -0
  242. package/dist/templates/plugins/solver-type-plugin/test/plugin.test.ts.tmpl +25 -0
  243. package/dist/templates/plugins/solver-type-plugin/tsconfig.json.tmpl +11 -0
  244. package/dist/tx-retry.d.ts +13 -0
  245. package/dist/tx-retry.js +22 -0
  246. package/dist/tx-retry.js.map +1 -1
  247. package/dist/types/envelope.d.ts +28 -21
  248. package/dist/types/envelope.js +8 -3
  249. package/dist/types/envelope.js.map +1 -1
  250. package/dist/types/payloads/index.d.ts +2 -2
  251. package/dist/types/payloads/index.js +13 -12
  252. package/dist/types/payloads/index.js.map +1 -1
  253. package/dist/types/payloads/portfolio-v0.d.ts +60 -10
  254. package/dist/types/payloads/portfolio-v0.js +16 -6
  255. package/dist/types/payloads/portfolio-v0.js.map +1 -1
  256. package/dist/types/payloads/prediction-apy-v0.d.ts +52 -10
  257. package/dist/types/payloads/prediction-apy-v0.js +16 -6
  258. package/dist/types/payloads/prediction-apy-v0.js.map +1 -1
  259. package/dist/types/payloads/prediction-v0.d.ts +49 -10
  260. package/dist/types/payloads/prediction-v0.js +16 -6
  261. package/dist/types/payloads/prediction-v0.js.map +1 -1
  262. package/dist/vendor/@jinn-network/sdk/dist/payloads/prediction-v1.d.ts +45 -6
  263. package/dist/vendor/@jinn-network/sdk/dist/payloads/prediction-v1.js +16 -6
  264. package/dist/x402/handler.js +51 -20
  265. package/dist/x402/handler.js.map +1 -1
  266. package/package.json +11 -3
  267. package/plugins/swe-rebench-v2-diffmin/.claude-plugin/plugin.json +5 -0
  268. package/plugins/swe-rebench-v2-diffmin/.mcp.json +8 -0
  269. package/plugins/swe-rebench-v2-diffmin/README.md +69 -0
  270. package/plugins/swe-rebench-v2-diffmin/jinn.plugin.json +12 -0
  271. package/plugins/swe-rebench-v2-diffmin/mcp/diff-stats-server.mjs +72 -0
  272. package/plugins/swe-rebench-v2-diffmin/mcp/diff-stats.mjs +48 -0
  273. package/plugins/swe-rebench-v2-diffmin/package.json +19 -0
  274. package/plugins/swe-rebench-v2-diffmin/skills/diffmin/SKILL.md +116 -0
  275. package/plugins/swe-rebench-v2-diffmin/skills/test-map/SKILL.md +126 -0
  276. package/plugins/swe-rebench-v2-diffmin/test/diff-stats.test.ts +62 -0
  277. package/plugins/swe-rebench-v2-diffmin/test/manifest.test.ts +53 -0
  278. package/plugins/swe-rebench-v2-diffmin/tsconfig.json +12 -0
  279. package/plugins/swe-rebench-v2-runtime/README.md +13 -0
  280. package/plugins/swe-rebench-v2-runtime/skills/orient/SKILL.md +7 -3
  281. package/plugins/swe-rebench-v2-runtime/skills/plan/SKILL.md +6 -17
  282. package/templates/plugins/runtime-plugin/.mcp.json.tmpl +8 -0
  283. package/templates/plugins/runtime-plugin/README.md.tmpl +30 -0
  284. package/templates/plugins/runtime-plugin/gitignore.tmpl +3 -0
  285. package/templates/plugins/runtime-plugin/jinn.plugin.json.tmpl +21 -0
  286. package/templates/plugins/runtime-plugin/mcp/server.mjs.tmpl +33 -0
  287. package/templates/plugins/runtime-plugin/package.json.tmpl +15 -0
  288. package/templates/plugins/runtime-plugin/test/plugin.test.ts.tmpl +35 -0
  289. package/templates/plugins/runtime-plugin/tsconfig.json.tmpl +11 -0
  290. package/templates/plugins/solver-type-plugin/README.md.tmpl +35 -0
  291. package/templates/plugins/solver-type-plugin/gitignore.tmpl +3 -0
  292. package/templates/plugins/solver-type-plugin/jinn.plugin.json.tmpl +11 -0
  293. package/templates/plugins/solver-type-plugin/package.json.tmpl +15 -0
  294. package/templates/plugins/solver-type-plugin/skills/example/SKILL.md.tmpl +10 -0
  295. package/templates/plugins/solver-type-plugin/test/plugin.test.ts.tmpl +25 -0
  296. package/templates/plugins/solver-type-plugin/tsconfig.json.tmpl +11 -0
  297. package/dist/dashboard/assets/index-BjtltOGc.js +0 -76
  298. package/dist/harnesses/impls/claude-code-learner/adapters/claude-code.js.map +0 -1
  299. package/dist/harnesses/impls/claude-code-learner/adapters/codex-code.js.map +0 -1
  300. package/dist/harnesses/impls/claude-code-learner/adapters/codex-workspace.js.map +0 -1
  301. package/dist/harnesses/impls/claude-code-learner/harness.js.map +0 -1
  302. package/dist/harnesses/impls/claude-code-learner/harvest.js.map +0 -1
  303. package/dist/harnesses/impls/claude-code-learner/index.js.map +0 -1
  304. package/dist/harnesses/impls/claude-code-learner/plugin-path.js.map +0 -1
  305. package/dist/harnesses/impls/claude-code-learner/restoration-patch.js.map +0 -1
  306. package/dist/harnesses/impls/claude-code-learner/test-utils/fake-plugin-outputs.js.map +0 -1
  307. package/dist/harnesses/impls/claude-code-learner/test-utils/noop-adapter.js.map +0 -1
  308. package/dist/harnesses/impls/claude-code-learner/types.js.map +0 -1
  309. package/dist/preflight/claude-required.d.ts +0 -8
  310. package/dist/preflight/claude-required.js +0 -17
  311. package/dist/preflight/claude-required.js.map +0 -1
  312. /package/dist/harnesses/impls/{claude-code-learner → learner}/adapters/claude-code.d.ts +0 -0
  313. /package/dist/harnesses/impls/{claude-code-learner → learner}/adapters/claude-code.js +0 -0
  314. /package/dist/harnesses/impls/{claude-code-learner → learner}/adapters/codex-code.d.ts +0 -0
  315. /package/dist/harnesses/impls/{claude-code-learner → learner}/adapters/codex-workspace.d.ts +0 -0
  316. /package/dist/harnesses/impls/{claude-code-learner → learner}/adapters/codex-workspace.js +0 -0
  317. /package/dist/harnesses/impls/{claude-code-learner → learner}/harvest.d.ts +0 -0
  318. /package/dist/harnesses/impls/{claude-code-learner → learner}/restoration-patch.d.ts +0 -0
  319. /package/dist/harnesses/impls/{claude-code-learner → learner}/test-utils/fake-plugin-outputs.d.ts +0 -0
  320. /package/dist/harnesses/impls/{claude-code-learner → learner}/test-utils/fake-plugin-outputs.js +0 -0
  321. /package/dist/harnesses/impls/{claude-code-learner → learner}/test-utils/noop-adapter.d.ts +0 -0
  322. /package/dist/harnesses/impls/{claude-code-learner → learner}/test-utils/noop-adapter.js +0 -0
  323. /package/dist/harnesses/impls/{claude-code-learner → learner}/types.js +0 -0
  324. /package/plugins/{claude-code-learner → learner}/.claude-plugin/plugin.json +0 -0
  325. /package/plugins/{claude-code-learner → learner}/.codex-plugin/plugin.json +0 -0
  326. /package/plugins/{claude-code-learner → learner}/AGENTS.md +0 -0
  327. /package/plugins/{claude-code-learner → learner}/CLAUDE.md +0 -0
  328. /package/plugins/{claude-code-learner → learner}/README.md +0 -0
  329. /package/plugins/{claude-code-learner → learner}/hooks/hooks.json +0 -0
  330. /package/plugins/{claude-code-learner → learner}/hooks/session-start +0 -0
  331. /package/plugins/{claude-code-learner → learner}/skills/learn/SKILL.md +0 -0
  332. /package/plugins/{claude-code-learner → learner}/skills/learn/analyst-prompt.md +0 -0
  333. /package/plugins/{claude-code-learner → learner}/skills/learn/consolidator-prompt.md +0 -0
  334. /package/plugins/{claude-code-learner → learner}/skills/learn/explorer-prompt.md +0 -0
  335. /package/plugins/{claude-code-learner → learner}/skills/learn/planner-prompt.md +0 -0
  336. /package/plugins/{claude-code-learner → learner}/skills/learn/promoter-prompt.md +0 -0
  337. /package/plugins/{claude-code-learner → learner}/skills/learn/step-worker-prompt.md +0 -0
  338. /package/plugins/{claude-code-learner → learner}/skills/learn/strategist-prompt.md +0 -0
@@ -6,6 +6,14 @@
6
6
  */
7
7
  import type { FleetState, FleetBootstrapResult } from './types.js';
8
8
  import { requestTestnetFunding } from './faucet.js';
9
+ /** Stage 1 master ETH requirement: the agent-funding transfer (STAGE1_AGENT_ETH)
10
+ * plus master's own gas reserve (minEoaGasEth). Centralized so the daemon's
11
+ * ensureStage1 gate, the read-side funding-plan, and gather-status all agree.
12
+ * See jinn-mono-u34i. */
13
+ export declare const STAGE1_AGENT_ETH = 10000000000000000n;
14
+ export declare function stage1MinMasterEth(config: {
15
+ minEoaGasEth: bigint;
16
+ }): bigint;
9
17
  export interface FleetBootstrapperOptions {
10
18
  earningDir?: string;
11
19
  chain?: 'base' | 'base-sepolia';
@@ -45,6 +53,16 @@ export interface FleetBootstrapperOptions {
45
53
  * testnet funding an explicit operator action.
46
54
  */
47
55
  autoTestnetFaucet?: boolean;
56
+ /**
57
+ * Max in-process attempts for the ERC-8004 Safe-binding step (jinn-mono-h74p).
58
+ * Defaults to 3. Tests pass small values to keep retry budgets predictable.
59
+ */
60
+ safeBindingMaxAttempts?: number;
61
+ /**
62
+ * Delay between Safe-binding retries (jinn-mono-h74p). Defaults to 3000 ms
63
+ * (~1.5 Base Sepolia blocks). Tests pass 0 to skip the sleep entirely.
64
+ */
65
+ safeBindingRetryDelayMs?: number;
48
66
  }
49
67
  export declare class FleetBootstrapper {
50
68
  private readonly store;
@@ -60,6 +78,8 @@ export declare class FleetBootstrapper {
60
78
  private readonly faucetLoopTimeoutMs;
61
79
  private readonly now;
62
80
  private readonly autoTestnetFaucet;
81
+ private readonly safeBindingMaxAttempts;
82
+ private readonly safeBindingRetryDelayMs;
63
83
  constructor(options?: FleetBootstrapperOptions);
64
84
  getStatus(): Promise<FleetState>;
65
85
  /**
@@ -83,6 +103,43 @@ export declare class FleetBootstrapper {
83
103
  * IdentityCard's "binding pending" chip on Overview.
84
104
  */
85
105
  retryAgentBindingFor(serviceIndex: number, password: string): Promise<FleetState>;
106
+ /**
107
+ * Stage 1 — Identity (universal). Walks: wallet → predict Safe (from
108
+ * HD-index-1 agent EOA) → ETH funding gate → deploy Safe → mint agentId
109
+ * + setAgentWallet via ERC-1271. Idempotent and re-entrant. Does NOT
110
+ * touch service rows or staking — those belong to Stage 2.
111
+ *
112
+ * Fleet-level fields written:
113
+ * - fleet_safe_address (after predict)
114
+ * - fleet_agent_id, fleet_identity_registry, fleet_stage='stage1'
115
+ * (after mint + bind)
116
+ *
117
+ * Funding gate: requires ETH on the master EOA only (no OLAS). On testnet,
118
+ * the existing CDP faucet loop drains as usual when `autoTestnetFaucet`
119
+ * is enabled.
120
+ *
121
+ * See docs/superpowers/specs/2026-05-13-plug-in-builder-entry-point-design.md §5.1.
122
+ */
123
+ ensureStage1(password: string): Promise<FleetBootstrapResult>;
124
+ /**
125
+ * Stage 1 + Stage 2 — full operator bootstrap. Calls `ensureStage1`
126
+ * first; on success, walks Stage 2 per service. Builder-only users who
127
+ * have completed Stage 1 and call this method later begin Stage 2 from
128
+ * `awaiting_stake` for the first service row (created lazily here).
129
+ *
130
+ * Two-Safe topology in standard mode: `fleet_safe_address !==
131
+ * services[0].safe_address` because Stage 2's `distributor.stake()`
132
+ * creates its own Safe. In self-bond mode the two converge (both
133
+ * derived from HD-index-1).
134
+ *
135
+ * See docs/superpowers/specs/2026-05-13-plug-in-builder-entry-point-design.md §5.1.
136
+ */
137
+ ensureStage1And2(password: string): Promise<FleetBootstrapResult>;
138
+ /**
139
+ * Back-compat alias. Existing call sites in `client/src/cli/commands/bootstrap.ts`
140
+ * and `client/src/cli/commands/fleet-scale.ts` continue to call `bootstrap()`;
141
+ * forwarding to `ensureStage1And2` preserves their semantics without churn.
142
+ */
86
143
  bootstrap(password: string): Promise<FleetBootstrapResult>;
87
144
  /**
88
145
  * If the master is only slightly above the minimum, warn about gas runway (heuristic days).
@@ -90,6 +147,12 @@ export declare class FleetBootstrapper {
90
147
  private warnMasterEthRunway;
91
148
  private ensureMasterWallet;
92
149
  private loadExistingMnemonic;
150
+ /** Deterministic Safe predict from the HD-index-1 agent EOA. */
151
+ private stepFleetSafePredict;
152
+ /** Deploy the predicted fleet Safe. Funds the agent EOA from master if needed. */
153
+ private stepFleetSafeDeploy;
154
+ /** Mint the fleet agentId + bind Safe via setAgentWallet (ERC-1271). */
155
+ private stepFleetIdentityRegister;
93
156
  private bootstrapService;
94
157
  /**
95
158
  * Compare persisted per-service state to registry/staking/Safe bytecode and patch store
@@ -15,7 +15,7 @@ import { formatBootstrapOperatorMessage, isJinnDebug, } from '../operator-errors
15
15
  import { reconcileServiceAgainstChain, } from './reconcile.js';
16
16
  import { previousSafeBeingAbandoned, sweepOrphanedServiceFunds, } from './orphan-sweep.js';
17
17
  import { DEFAULT_FAUCET_LOOP_TIMEOUT_MS, computeFaucetDripCap, requestTestnetFunding, } from './faucet.js';
18
- import { flattenErrorMessage, viemSendTransactionWithRetry, waitForTransactionReceiptWithRetry, } from '../tx-retry.js';
18
+ import { flattenErrorMessage, sleep, viemSendTransactionWithRetry, waitForContractCode, waitForTransactionReceiptWithRetry, } from '../tx-retry.js';
19
19
  import { isUnauthorizedAccountError } from '../errors/unauthorized-account.js';
20
20
  import { createJinnPublicClient, createJinnWalletClient } from './viem-clients.js';
21
21
  import { isTransientEthReadError } from '../chain-read-errors.js';
@@ -25,10 +25,40 @@ import { detectDeprecatedTestnetSetup, migrateDeprecatedTestnetSetup, } from './
25
25
  const addr = (value) => getAddress(value);
26
26
  const SAFE_TOKEN_BOOTSTRAP_MULTIPLIER = 2n;
27
27
  const STANDARD_MASTER_BOOTSTRAP_MULTIPLIER = 2n;
28
+ /** Stage 1 master ETH requirement: the agent-funding transfer (STAGE1_AGENT_ETH)
29
+ * plus master's own gas reserve (minEoaGasEth). Centralized so the daemon's
30
+ * ensureStage1 gate, the read-side funding-plan, and gather-status all agree.
31
+ * See jinn-mono-u34i. */
32
+ export const STAGE1_AGENT_ETH = 10000000000000000n; // 0.01 ETH (moved out of stepFleetSafeDeploy)
33
+ export function stage1MinMasterEth(config) {
34
+ return STAGE1_AGENT_ETH + config.minEoaGasEth;
35
+ }
28
36
  /** Conservative default: ~0.001 ETH/day master gas if not configured. */
29
37
  const DEFAULT_MASTER_ETH_DAILY_WEI = 1000000000000000n;
30
38
  /** Warn when ETH above the minimum would last fewer than this many days at the daily estimate. */
31
39
  const MASTER_ETH_RUNWAY_WARN_DAYS = 7n;
40
+ /**
41
+ * Safe → ERC-8004 agent NFT binding retry (jinn-mono-h74p).
42
+ *
43
+ * Empirical observation against fresh Base Sepolia 1/1 Safes: the first
44
+ * `IdentityRegistry.setAgentWallet` attempt reverts with a generic
45
+ * "Execution reverted for an unknown reason" — but the same Safe + same
46
+ * agentId + a freshly-signed message a few seconds later succeeds. The
47
+ * race window is likely freshly-deployed-Safe state lag on the public RPC
48
+ * (the simulator can't read the Safe's storage yet in the same block /
49
+ * eventual-consistency between sibling RPC nodes). A short bounded retry
50
+ * makes the operator-visible behaviour deterministic instead of relying on
51
+ * the "daemon exits → operator restarts → resume at safe_binding_pending"
52
+ * accidental safety net (which goes away when jinn-mono-vh74.2 removes the
53
+ * Claude-auth post-bootstrap exit gate).
54
+ *
55
+ * Defaults: 3 attempts × 3 s delay = at most ~6 s of in-process retry budget
56
+ * before falling through to the existing `safe_binding_pending` persisted
57
+ * state. Real (non-transient) failures still surface — just with a slightly
58
+ * higher latency tax for the diagnostic.
59
+ */
60
+ const DEFAULT_SAFE_BINDING_MAX_ATTEMPTS = 3;
61
+ const DEFAULT_SAFE_BINDING_RETRY_DELAY_MS = 3_000;
32
62
  export class FleetBootstrapper {
33
63
  store;
34
64
  config;
@@ -43,6 +73,8 @@ export class FleetBootstrapper {
43
73
  faucetLoopTimeoutMs;
44
74
  now;
45
75
  autoTestnetFaucet;
76
+ safeBindingMaxAttempts;
77
+ safeBindingRetryDelayMs;
46
78
  constructor(options = {}) {
47
79
  this.store = new FleetStateStore(options.earningDir);
48
80
  this.chain = options.chain ?? 'base';
@@ -55,6 +87,10 @@ export class FleetBootstrapper {
55
87
  this.now = options.now ?? Date.now;
56
88
  this.autoTestnetFaucet =
57
89
  options.autoTestnetFaucet ?? this.env['JINN_DISABLE_TESTNET_FAUCET'] !== '1';
90
+ this.safeBindingMaxAttempts =
91
+ options.safeBindingMaxAttempts ?? DEFAULT_SAFE_BINDING_MAX_ATTEMPTS;
92
+ this.safeBindingRetryDelayMs =
93
+ options.safeBindingRetryDelayMs ?? DEFAULT_SAFE_BINDING_RETRY_DELAY_MS;
58
94
  const dailyOpt = options.masterEthDailyEstimateWei;
59
95
  this.masterEthDailyEstimateWei =
60
96
  dailyOpt !== undefined
@@ -112,16 +148,149 @@ export class FleetBootstrapper {
112
148
  const mnemonic = await this.loadExistingMnemonic(state, password);
113
149
  return this.stepRegisterAgent(state, mnemonic, serviceIndex);
114
150
  }
115
- async bootstrap(password) {
116
- // Handle legacy keystore migration
151
+ /**
152
+ * Stage 1 — Identity (universal). Walks: wallet → predict Safe (from
153
+ * HD-index-1 agent EOA) → ETH funding gate → deploy Safe → mint agentId
154
+ * + setAgentWallet via ERC-1271. Idempotent and re-entrant. Does NOT
155
+ * touch service rows or staking — those belong to Stage 2.
156
+ *
157
+ * Fleet-level fields written:
158
+ * - fleet_safe_address (after predict)
159
+ * - fleet_agent_id, fleet_identity_registry, fleet_stage='stage1'
160
+ * (after mint + bind)
161
+ *
162
+ * Funding gate: requires ETH on the master EOA only (no OLAS). On testnet,
163
+ * the existing CDP faucet loop drains as usual when `autoTestnetFaucet`
164
+ * is enabled.
165
+ *
166
+ * See docs/superpowers/specs/2026-05-13-plug-in-builder-entry-point-design.md §5.1.
167
+ */
168
+ async ensureStage1(password) {
169
+ // Legacy keystore migration (same as bootstrap()).
117
170
  if (!this.store.hasMnemonicKeystore() && this.store.hasLegacyKeystore()) {
118
171
  await this.store.migrateLegacyFiles();
119
172
  }
120
173
  let state = await this.store.load(this.chain);
174
+ // Short-circuit if Stage 1 is already complete (or beyond).
175
+ if (state.fleet_stage === 'stage1' || state.fleet_stage === 'stage1_and_2') {
176
+ // Even when stage marker says complete, fleet identity may be empty for
177
+ // pre-j07 operators (`stage1_and_2` is set by the migration for
178
+ // services-complete-but-no-agent_id operators). In that case we leave
179
+ // Stage 1 alone — the legacy backfill in main.ts handles those rows
180
+ // and a future ensureStage1 call after backfill will promote.
181
+ return {
182
+ ok: true,
183
+ fleet_state: state,
184
+ message: state.fleet_agent_id !== null
185
+ ? `Stage 1 already complete (fleet_agent_id=${state.fleet_agent_id}, fleet_safe=${state.fleet_safe_address}).`
186
+ : 'Stage 1 marker present but fleet identity is empty (legacy operator). Skipping.',
187
+ };
188
+ }
121
189
  try {
122
- // Phase 1: Master wallet setup
123
190
  state = await this.ensureMasterWallet(state, password);
124
- // Phase 1b: Check master funding
191
+ // Stage 1 funding gate — ETH only (no OLAS). Stage 1 needs
192
+ // STAGE1_AGENT_ETH (0.01) for the master → agent transfer plus
193
+ // minEoaGasEth (0.005) reserved for the master's own gas to send that
194
+ // transfer. The agent EOA then pays for Safe deploy + ERC-8004 register
195
+ // + setAgentWallet out of the funds it just received.
196
+ // See jinn-mono-u34i: pre-fix this gate was 2×minEoaGasEth (= 0.01 ETH),
197
+ // which equaled the transfer amount and left no gas headroom, so a
198
+ // master holding the gate's minimum would fail eth_estimateGas with
199
+ // "gas required exceeds allowance (0)".
200
+ const requiredMasterEth = stage1MinMasterEth(this.config);
201
+ const masterAddress = state.master_address;
202
+ const masterBalance = await this.publicClient.getBalance({
203
+ address: masterAddress,
204
+ });
205
+ if (masterBalance < requiredMasterEth) {
206
+ const shortfall = requiredMasterEth - masterBalance;
207
+ return {
208
+ ok: false,
209
+ fleet_state: state,
210
+ message: `Your master wallet needs more ETH (currently ${formatEther(masterBalance)} ETH, need ${formatEther(shortfall)} ETH more) to complete Stage 1. Please send ETH to: ${masterAddress}`,
211
+ funding: {
212
+ master_address: masterAddress,
213
+ eth_required: shortfall.toString(),
214
+ eth_balance: masterBalance.toString(),
215
+ },
216
+ };
217
+ }
218
+ const mnemonic = await this.loadExistingMnemonic(state, password);
219
+ // Step 1: predict fleet Safe from HD-index-1 agent EOA.
220
+ if (!state.fleet_safe_address) {
221
+ state = await this.stepFleetSafePredict(state, mnemonic);
222
+ }
223
+ // Step 2: deploy fleet Safe if bytecode absent.
224
+ const safeCode = await this.publicClient.getCode({
225
+ address: getAddress(state.fleet_safe_address),
226
+ });
227
+ if (safeCode === undefined || safeCode === '0x') {
228
+ state = await this.stepFleetSafeDeploy(state, mnemonic);
229
+ }
230
+ // Step 3: mint agentId + bind Safe via setAgentWallet.
231
+ if (!state.fleet_agent_id) {
232
+ state = await this.stepFleetIdentityRegister(state, mnemonic);
233
+ }
234
+ else if (state.fleet_stage !== 'stage1' && state.fleet_stage !== 'stage1_and_2') {
235
+ // Identity was minted but stage marker is stale; advance it.
236
+ state = await this.store.patchFleet({ fleet_stage: 'stage1' });
237
+ }
238
+ return {
239
+ ok: true,
240
+ fleet_state: state,
241
+ message: `Stage 1 complete. fleet_agent_id=${state.fleet_agent_id}, fleet_safe=${state.fleet_safe_address}.`,
242
+ };
243
+ }
244
+ catch (error) {
245
+ const { summary, hint, rawMessage } = formatBootstrapOperatorMessage(error);
246
+ const userMessage = hint !== undefined ? `${summary}\nHint: ${hint}` : summary;
247
+ if (this.debug) {
248
+ console.error(`[fleet-bootstrap] ensureStage1 failed:`, error);
249
+ }
250
+ else {
251
+ console.error(`[fleet-bootstrap] ${summary}`);
252
+ if (hint !== undefined)
253
+ console.error(`Hint: ${hint}`);
254
+ if (rawMessage && rawMessage !== summary) {
255
+ console.error(`[fleet-bootstrap] raw: ${rawMessage.split('\n')[0]}`);
256
+ }
257
+ }
258
+ return {
259
+ ok: false,
260
+ fleet_state: state,
261
+ message: userMessage,
262
+ rawErrorMessage: rawMessage,
263
+ };
264
+ }
265
+ }
266
+ /**
267
+ * Stage 1 + Stage 2 — full operator bootstrap. Calls `ensureStage1`
268
+ * first; on success, walks Stage 2 per service. Builder-only users who
269
+ * have completed Stage 1 and call this method later begin Stage 2 from
270
+ * `awaiting_stake` for the first service row (created lazily here).
271
+ *
272
+ * Two-Safe topology in standard mode: `fleet_safe_address !==
273
+ * services[0].safe_address` because Stage 2's `distributor.stake()`
274
+ * creates its own Safe. In self-bond mode the two converge (both
275
+ * derived from HD-index-1).
276
+ *
277
+ * See docs/superpowers/specs/2026-05-13-plug-in-builder-entry-point-design.md §5.1.
278
+ */
279
+ async ensureStage1And2(password) {
280
+ // Stage 1 first — establishes fleet identity. Short-circuits if already done.
281
+ const stage1Result = await this.ensureStage1(password);
282
+ if (!stage1Result.ok) {
283
+ return stage1Result;
284
+ }
285
+ // Original bootstrap body — copied verbatim from the previous bootstrap()
286
+ // method, with two changes:
287
+ // (a) the legacy-keystore migration and master-wallet-ensure are no-ops
288
+ // because ensureStage1 already ran them.
289
+ // (b) at the end, if any service reached `complete`/`safe_binding_pending`
290
+ // we advance `fleet_stage` to `'stage1_and_2'`.
291
+ let state = stage1Result.fleet_state;
292
+ try {
293
+ // Phase 1b: Check master funding for the full operator path.
125
294
  const masterAddress = state.master_address;
126
295
  let masterBalance = await this.publicClient.getBalance({ address: masterAddress });
127
296
  // Self-bond mode needs much more ETH than standard mode because the master
@@ -291,6 +460,11 @@ export class FleetBootstrapper {
291
460
  const nextIndex = nextFleetServiceIndex(state.services);
292
461
  state = await this.bootstrapService(state, mnemonic, nextIndex);
293
462
  }
463
+ // Advance fleet_stage to 'stage1_and_2' if any service is operational.
464
+ const anyOperationalAfter = state.services.some(s => isOperationalServiceStep(s.step));
465
+ if (anyOperationalAfter && state.fleet_stage !== 'stage1_and_2') {
466
+ state = await this.store.patchFleet({ fleet_stage: 'stage1_and_2' });
467
+ }
294
468
  return {
295
469
  ok: true,
296
470
  fleet_state: state,
@@ -322,6 +496,14 @@ export class FleetBootstrapper {
322
496
  };
323
497
  }
324
498
  }
499
+ /**
500
+ * Back-compat alias. Existing call sites in `client/src/cli/commands/bootstrap.ts`
501
+ * and `client/src/cli/commands/fleet-scale.ts` continue to call `bootstrap()`;
502
+ * forwarding to `ensureStage1And2` preserves their semantics without churn.
503
+ */
504
+ async bootstrap(password) {
505
+ return this.ensureStage1And2(password);
506
+ }
325
507
  /**
326
508
  * If the master is only slightly above the minimum, warn about gas runway (heuristic days).
327
509
  */
@@ -382,6 +564,129 @@ export class FleetBootstrapper {
382
564
  return freshMnemonic;
383
565
  }
384
566
  }
567
+ // ── Stage 1: fleet-level identity steps (nghf) ────────────────────────
568
+ /** Deterministic Safe predict from the HD-index-1 agent EOA. */
569
+ async stepFleetSafePredict(state, mnemonic) {
570
+ const agentAddress = deriveAgentAddress(mnemonic, 1);
571
+ const agentKey = walletPrivateKeyAtIndex(mnemonic, 1);
572
+ console.error(`[fleet-bootstrap] Stage 1: predicting fleet Safe (owner=${agentAddress})`);
573
+ const { address } = await initPredictedSafe({
574
+ rpcUrl: this.config.rpcUrl,
575
+ signerKey: agentKey,
576
+ owners: [agentAddress],
577
+ threshold: 1,
578
+ });
579
+ void state;
580
+ return this.store.patchFleet({ fleet_safe_address: getAddress(address) });
581
+ }
582
+ /** Deploy the predicted fleet Safe. Funds the agent EOA from master if needed. */
583
+ async stepFleetSafeDeploy(state, mnemonic) {
584
+ const agentAddress = deriveAgentAddress(mnemonic, 1);
585
+ const agentKey = walletPrivateKeyAtIndex(mnemonic, 1);
586
+ const agentSigner = deriveAgentSigner(mnemonic, 1);
587
+ const fleetSafe = state.fleet_safe_address;
588
+ // Fund agent EOA so it can pay for Safe deploy + setAgentWallet gas.
589
+ // 0.01 ETH covers Safe deploy (~250k gas) + register (~80k) + setAgentWallet
590
+ // (~200k) at testnet gas prices comfortably. STAGE1_AGENT_ETH is the
591
+ // module-level constant used both here and in `stage1MinMasterEth` so the
592
+ // gate and the transfer agree (jinn-mono-u34i).
593
+ const masterAccount = deriveMasterSigner(mnemonic);
594
+ const masterWallet = createJinnWalletClient(this.config.rpcUrl, this.chain, masterAccount);
595
+ const agentBalance = await this.publicClient.getBalance({
596
+ address: getAddress(agentAddress),
597
+ });
598
+ if (agentBalance < STAGE1_AGENT_ETH) {
599
+ const fundAmount = STAGE1_AGENT_ETH - agentBalance;
600
+ console.error(`[fleet-bootstrap] Stage 1: funding fleet agent EOA with ${fundAmount} wei from master`);
601
+ const fundHash = await viemSendTransactionWithRetry(masterWallet, this.publicClient, {
602
+ account: masterAccount,
603
+ to: addr(agentAddress),
604
+ value: fundAmount,
605
+ });
606
+ await waitForTransactionReceiptWithRetry(this.publicClient, fundHash);
607
+ }
608
+ console.error(`[fleet-bootstrap] Stage 1: deploying fleet Safe at ${fleetSafe}`);
609
+ const { safe } = await initPredictedSafe({
610
+ rpcUrl: this.config.rpcUrl,
611
+ signerKey: agentKey,
612
+ owners: [agentAddress],
613
+ threshold: 1,
614
+ });
615
+ const deployTx = await safe.createSafeDeploymentTransaction();
616
+ const agentWallet = createJinnWalletClient(this.config.rpcUrl, this.chain, agentSigner);
617
+ const deployHash = await viemSendTransactionWithRetry(agentWallet, this.publicClient, {
618
+ account: agentSigner,
619
+ to: deployTx.to,
620
+ value: BigInt(deployTx.value),
621
+ data: deployTx.data,
622
+ });
623
+ const receipt = await waitForTransactionReceiptWithRetry(this.publicClient, deployHash);
624
+ if (receipt.status !== 'success') {
625
+ throw new Error(`Fleet Safe deployment tx failed: ${deployHash}`);
626
+ }
627
+ try {
628
+ await waitForContractCode(this.publicClient, getAddress(fleetSafe));
629
+ }
630
+ catch {
631
+ throw new Error(`Fleet Safe deployment succeeded but no code at ${fleetSafe}`);
632
+ }
633
+ console.error(`[fleet-bootstrap] Stage 1: fleet Safe deployed (tx=${deployHash})`);
634
+ return this.store.load(this.chain);
635
+ }
636
+ /** Mint the fleet agentId + bind Safe via setAgentWallet (ERC-1271). */
637
+ async stepFleetIdentityRegister(state, mnemonic) {
638
+ const identityRegistry = this.config.identityRegistry ?? IDENTITY_REGISTRY_ADDRESSES[this.config.chainId];
639
+ if (!identityRegistry) {
640
+ throw new Error(`IdentityRegistry address not configured for chainId=${this.config.chainId}.`);
641
+ }
642
+ const fleetSafe = state.fleet_safe_address;
643
+ const agentSigner = deriveAgentSigner(mnemonic, 1);
644
+ const agentWallet = createJinnWalletClient(this.config.rpcUrl, this.chain, agentSigner);
645
+ // Mint agentId — empty agent URI for v0 (matches stepRegisterAgent §6.1 in spec).
646
+ const registerData = encodeFunctionData({
647
+ abi: IDENTITY_REGISTRY_ABI,
648
+ functionName: 'register',
649
+ args: [''],
650
+ });
651
+ console.error(`[fleet-bootstrap] Stage 1: minting fleet agentId ` +
652
+ `(IdentityRegistry=${identityRegistry}, agentEOA=${agentSigner.address})`);
653
+ const mintTxHash = await viemSendTransactionWithRetry(agentWallet, this.publicClient, {
654
+ account: agentSigner,
655
+ to: addr(identityRegistry),
656
+ data: registerData,
657
+ });
658
+ const mintReceipt = await waitForTransactionReceiptWithRetry(this.publicClient, mintTxHash);
659
+ if (mintReceipt.status !== 'success') {
660
+ throw new Error(`Fleet IdentityRegistry.register() failed: ${mintTxHash}`);
661
+ }
662
+ const fleetAgentId = this.parseAgentIdFromReceipt(mintReceipt, identityRegistry);
663
+ if (fleetAgentId === null) {
664
+ throw new Error(`Fleet IdentityRegistry.register() succeeded but Registered event missing (tx=${mintTxHash})`);
665
+ }
666
+ // Persist agentId IMMEDIATELY so a crash between mint and bind doesn't lose it.
667
+ await this.store.patchFleet({
668
+ fleet_agent_id: fleetAgentId,
669
+ fleet_identity_registry: getAddress(identityRegistry),
670
+ });
671
+ // Bind the Safe via setAgentWallet (ERC-1271).
672
+ console.error(`[fleet-bootstrap] Stage 1: binding fleet Safe ${fleetSafe} to agentId=${fleetAgentId}`);
673
+ const bindResult = await bindAgentWalletToSafe({
674
+ identityRegistryAddress: addr(identityRegistry),
675
+ agentId: BigInt(fleetAgentId),
676
+ safeAddress: addr(fleetSafe),
677
+ agentEoaAccount: agentSigner,
678
+ agentEoaWalletClient: agentWallet,
679
+ publicClient: this.publicClient,
680
+ chainId: this.config.chainId,
681
+ });
682
+ if (!bindResult.ok) {
683
+ const bindErr = bindResult.error;
684
+ throw new Error(`Fleet setAgentWallet failed: ${bindErr.shortMessage}` +
685
+ (bindErr.revertReason ? ` (revert: ${bindErr.revertReason})` : ''));
686
+ }
687
+ console.error(`[fleet-bootstrap] Stage 1: setAgentWallet succeeded (tx=${bindResult.txHash})`);
688
+ return this.store.patchFleet({ fleet_stage: 'stage1' });
689
+ }
385
690
  // ── Phase 2: Per-service bootstrap ───────────────────────────────────
386
691
  async bootstrapService(state, mnemonic, index) {
387
692
  const agentAddress = deriveAgentAddress(mnemonic, index);
@@ -837,6 +1142,7 @@ export class FleetBootstrapper {
837
1142
  let svc = (await this.store.load(this.chain)).services.find(s => s.index === index);
838
1143
  if (!svc)
839
1144
  throw new Error(`Service ${index} not found in state`);
1145
+ const fleetSnapshot = await this.store.load(this.chain);
840
1146
  const identityRegistry = this.config.identityRegistry
841
1147
  ?? IDENTITY_REGISTRY_ADDRESSES[this.config.chainId];
842
1148
  if (!identityRegistry) {
@@ -845,7 +1151,7 @@ export class FleetBootstrapper {
845
1151
  }
846
1152
  const agentSigner = deriveAgentSigner(mnemonic, index);
847
1153
  const agentWallet = createJinnWalletClient(this.config.rpcUrl, this.chain, agentSigner);
848
- // ── Sub-step A: mint NFT (skip if agent_id is already set). ─────────
1154
+ // ── Sub-step A: mint NFT (skip if agent_id is already set OR fleet identity exists). ─
849
1155
  let agentId;
850
1156
  if (svc.agent_id) {
851
1157
  console.error(`[fleet-bootstrap] Service ${index}: ERC-8004 agent already registered ` +
@@ -856,6 +1162,22 @@ export class FleetBootstrapper {
856
1162
  step: svc.step === 'safe_binding_pending' ? 'safe_binding_pending' : 'agent_registered',
857
1163
  });
858
1164
  }
1165
+ else if (fleetSnapshot.fleet_agent_id) {
1166
+ // nghf: reuse the fleet-level agentId minted by ensureStage1 instead of
1167
+ // minting a second one. This collapses the "one agentId per user"
1168
+ // invariant in spec §5.1 for the standard-mode two-Safe topology.
1169
+ console.error(`[fleet-bootstrap] Service ${index}: reusing fleet agentId=${fleetSnapshot.fleet_agent_id} ` +
1170
+ `(no second mint needed).`);
1171
+ agentId = fleetSnapshot.fleet_agent_id;
1172
+ svc = await this.firstServiceUpdate(index, {
1173
+ agent_id: fleetSnapshot.fleet_agent_id,
1174
+ agent_uri: '',
1175
+ identity_registry_address: fleetSnapshot.fleet_identity_registry ?? getAddress(identityRegistry),
1176
+ agent_registered_tx: null,
1177
+ step: 'agent_registered',
1178
+ error: null,
1179
+ });
1180
+ }
859
1181
  else {
860
1182
  // v0: empty agentURI. The richer agent card (per §6 of the spec) is
861
1183
  // future work — operators may later call `setAgentURI`.
@@ -924,32 +1246,79 @@ export class FleetBootstrapper {
924
1246
  step: 'safe_binding_pending',
925
1247
  error: null,
926
1248
  });
927
- try {
928
- const result = await bindAgentWalletToSafe({
929
- identityRegistryAddress: addr(identityRegistry),
930
- agentId: BigInt(agentId),
931
- safeAddress: addr(safeAddress),
932
- agentEoaAccount: agentSigner,
933
- agentEoaWalletClient: agentWallet,
934
- publicClient: this.publicClient,
935
- chainId: this.config.chainId,
936
- });
1249
+ // Combined h74p (retry-on-transient-throw) + hjex.4 (Result-typed
1250
+ // structured errors) policy:
1251
+ // - bindAgentWalletToSafe now returns a BindAgentWalletOutcome
1252
+ // (ok=true | ok=false with structured SafeBindingError).
1253
+ // - A returned Result.ok=false is a deterministic contract revert —
1254
+ // don't retry; record the structured diagnostic.
1255
+ // - A *thrown* exception is the freshly-deployed-Safe RPC race
1256
+ // window h74p targets — retry up to safeBindingMaxAttempts with a
1257
+ // small delay; if every attempt throws we fall through to a plain
1258
+ // reason log (no structured fields available).
1259
+ const maxAttempts = Math.max(1, this.safeBindingMaxAttempts);
1260
+ let bindResult;
1261
+ let lastBindError;
1262
+ for (let attempt = 1; attempt <= maxAttempts; attempt++) {
1263
+ try {
1264
+ bindResult = await bindAgentWalletToSafe({
1265
+ identityRegistryAddress: addr(identityRegistry),
1266
+ agentId: BigInt(agentId),
1267
+ safeAddress: addr(safeAddress),
1268
+ agentEoaAccount: agentSigner,
1269
+ agentEoaWalletClient: agentWallet,
1270
+ publicClient: this.publicClient,
1271
+ chainId: this.config.chainId,
1272
+ });
1273
+ break;
1274
+ }
1275
+ catch (err) {
1276
+ lastBindError = err;
1277
+ if (attempt < maxAttempts) {
1278
+ const reason = err instanceof Error ? err.message : String(err);
1279
+ console.error(`[fleet-bootstrap] Service ${index}: setAgentWallet attempt ` +
1280
+ `${attempt}/${maxAttempts} failed (${reason}); retrying in ` +
1281
+ `${this.safeBindingRetryDelayMs}ms...`);
1282
+ if (this.safeBindingRetryDelayMs > 0) {
1283
+ await sleep(this.safeBindingRetryDelayMs);
1284
+ }
1285
+ }
1286
+ }
1287
+ }
1288
+ if (bindResult?.ok === true) {
937
1289
  console.error(`[fleet-bootstrap] Service ${index}: setAgentWallet succeeded ` +
938
- `(tx=${result.txHash}, safe=${safeAddress}).`);
1290
+ `(tx=${bindResult.txHash}, safe=${safeAddress}).`);
939
1291
  svc = await this.firstServiceUpdate(index, {
940
1292
  safe_bound_to_agent: true,
941
1293
  step: 'complete',
942
1294
  error: null,
1295
+ error_revert_reason: null,
1296
+ error_short_message: null,
943
1297
  });
944
1298
  }
945
- catch (err) {
946
- const reason = err instanceof Error ? err.message : String(err);
1299
+ else if (bindResult && !bindResult.ok) {
1300
+ const bindErr = bindResult.error;
947
1301
  console.error(`[fleet-bootstrap] Service ${index}: setAgentWallet failed; continuing with ` +
948
- `safe_bound_to_agent=false (${reason}).`);
1302
+ `safe_bound_to_agent=false (${bindErr.shortMessage}` +
1303
+ `${bindErr.revertReason ? `, revert: ${bindErr.revertReason}` : ''}).`);
1304
+ svc = await this.firstServiceUpdate(index, {
1305
+ safe_bound_to_agent: false,
1306
+ step: 'safe_binding_pending',
1307
+ error: `safe_binding_failed: ${bindErr.shortMessage}`,
1308
+ error_revert_reason: bindErr.revertReason,
1309
+ error_short_message: bindErr.shortMessage,
1310
+ });
1311
+ }
1312
+ else {
1313
+ const reason = lastBindError instanceof Error ? lastBindError.message : String(lastBindError);
1314
+ console.error(`[fleet-bootstrap] Service ${index}: setAgentWallet failed after ` +
1315
+ `${maxAttempts} attempts; continuing with safe_bound_to_agent=false (${reason}).`);
949
1316
  svc = await this.firstServiceUpdate(index, {
950
1317
  safe_bound_to_agent: false,
951
1318
  step: 'safe_binding_pending',
952
1319
  error: `safe_binding_failed: ${reason}`,
1320
+ error_revert_reason: null,
1321
+ error_short_message: null,
953
1322
  });
954
1323
  }
955
1324
  }
@@ -1066,8 +1435,10 @@ export class FleetBootstrapper {
1066
1435
  if (receipt.status !== 'success') {
1067
1436
  throw new Error(`Safe deployment tx failed for service ${index}: ${deployHash}`);
1068
1437
  }
1069
- const deployedCode = await this.publicClient.getCode({ address: getAddress(safeAddress) });
1070
- if (deployedCode === undefined || deployedCode === '0x') {
1438
+ try {
1439
+ await waitForContractCode(this.publicClient, getAddress(safeAddress));
1440
+ }
1441
+ catch {
1071
1442
  throw new Error(`Safe deployment succeeded but no code at ${safeAddress}`);
1072
1443
  }
1073
1444
  console.error(`[fleet-bootstrap] Service ${index}: Safe deployed (tx: ${deployHash})`);