Skip to content

refactor(wallet): delegate resolution to @blockrun/core#13

Draft
KillerQueen-Z wants to merge 1 commit into
BlockRunAI:mainfrom
KillerQueen-Z:agent/adopt-core
Draft

refactor(wallet): delegate resolution to @blockrun/core#13
KillerQueen-Z wants to merge 1 commit into
BlockRunAI:mainfrom
KillerQueen-Z:agent/adopt-core

Conversation

@KillerQueen-Z

Copy link
Copy Markdown
Contributor

What

Makes @blockrun/llm the first shared SDK consumer of @blockrun/core.

  • Adds @blockrun/core@^0.0.3.
  • Delegates provider-wallet scanning, file resolution, environment precedence,
    getOrCreateWallet, and getWalletAddress to the shared kernel.
  • Keeps the SDK's public function names and wallet-creation/funding behavior
    unchanged.
  • Adds characterization coverage for the canonical resolution order:
    env → provider wallet.json → ~/.blockrun/.session → legacy wallet.key.

Why

Franklin and MCP already consume this SDK. Once this merges, their wallet
resolution automatically shares the same source of truth as the official
blockrun CLI and clawrouter-codex, without any forced migration for users.

Lockfile note

package-lock.json is regenerated because the upstream lockfile's root package
metadata was already behind the current package.json. The large lockfile diff
aligns it with the declared dependency versions and adds the published core
package; it does not alter the SDK API surface.

Validation

  • npm run build — passed.
  • HOME=/tmp/blockrun-llm-test-home npm test — 200 passed, 12 production
    integration tests skipped by design, TypeScript type checks passed.
  • New wallet characterization tests: 3 passed.

@VickyXAI

Copy link
Copy Markdown
Contributor

审了一遍,这个 PR 不能合 —— 它改了「哪把私钥签支付」,而根因在依赖包 @blockrun/core 里。

行为倒转,不是重构

场景:~/.blockrun/.session(BlockRun 钱包,持有用户已充值的 USDC)+ 更新的 ~/.agentcash/wallet.json(第三方 provider 钱包)。

  • main: loadWallet() → BlockRun 钱包(实测 10/10 测试通过)
  • 此 PR: loadWallet() → 第三方钱包(我在 dist 上实跑验证过)

这是签 x402 支付用哪把私钥的相反答案

根因在 core,不在接线

我先怀疑是 loadWallet 接错了 core 函数(coreResolveFromFiles vs coreResolvePrivateKey),改过去后发现两个都让第三方赢:

// @blockrun/core dist/wallet.js
resolvePrivateKey → resolveFromFiles → scanWallets() 第一个命中就返回
//                                     ↑ provider wallet.json 排在 .session 之前

core 的注释自称「Canonical BlockRun order, matching @blockrun/llm's getOrCreateWallet」,但它把 provider 钱包排在了 .session 前面 —— 恰恰相反。所以委托到 core 之后,无论调哪个解析器,正典都被打破了。修复得在 @blockrun/core 里,把 provider 扫描降到 session/legacy 之后,或者干脆不在默认解析路径里扫 provider。

与既有的刻意修复冲突

这个正典是被专门确立并测试过的:

  • fix: preserve canonical wallet selection (#26)
  • fix(wallet): warn when a new wallet is created beside provider wallets
  • feat(wallet): adopt a discovered wallet deliberately (3.8.0)

另外两个观察

  1. PR 删掉了 test/wallet-selection.test.ts(main 上 10 条全过,覆盖正典选择/导入/备份/迁移提示),换成 3 条 characterization test —— 而后者把倒转后的行为断言成了正确。删掉的正是唯一能抓到这次回退的测试。
  2. 测试若要保留,需要改用 core 支持的 BLOCKRUN_HOME 环境变量来隔离 home:vi.doMock("os") 穿透不进独立编译的 core 包(我验证过 —— 换成 BLOCKRUN_HOME=<home> 后 legacy-key 那条立刻恢复)。

我没有改动这个分支,把判断留给你 —— 因为「默认用哪个钱包付钱」是产品决策,而修复点在另一个仓库。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants