Skip to content

fix: wallet list routes human-readable summary to stderr, keeps only JSON on stdout - #289

Closed
yodablocks wants to merge 4 commits into
nansen-ai:mainfrom
yodablocks:fix/154-wallet-list-stderr
Closed

fix: wallet list routes human-readable summary to stderr, keeps only JSON on stdout#289
yodablocks wants to merge 4 commits into
nansen-ai:mainfrom
yodablocks:fix/154-wallet-list-stderr

Conversation

@yodablocks

Copy link
Copy Markdown
Contributor

Closes #154

Problem

nansen wallet list was outputting human-readable text only (no JSON),
breaking agent pipelines that rely on | jq .

History

This PR completes that TODO

  • Human-readable wallet summary → stderr (interactive users still see it)
  • Clean JSON → stdout (agent pipelines work: nansen wallet list | jq .)

Changes

  • src/wallet.js — added ttyOutput = console.error dep, switched list handler to use it
  • src/__tests__/wallet.test.js — added ttyOutput mock + explicit stderr/stdout separation test
  • .changeset/fix-wallet-list-stderr.md — patch changeset

Tests

929 tests pass, lint clean.

@nansen-pr-reviewer

nansen-pr-reviewer Bot commented Mar 11, 2026

Copy link
Copy Markdown

pr-reviewer Summary

No issues found

The code review completed successfully with no findings.

Review effort: 2/5 (Simple)

Summary

This PR implements the "Hybrid command" pattern for wallet list: human-readable text is routed to ttyOutput (stderr) so interactive users still see it, while the command now returns structured data so runCLI can emit JSON on stdout. The change is focused, well-tested, and documented in AGENTS.md.

Key changes are correct:

  • src/wallet.jsttyOutput is properly destructured with console.error as the default fallback. Both the empty-wallet path and the populated-wallet path now consistently return result, satisfying the framework's undefined-means-no-output contract (lines 1626–1630 of cli.js).
  • src/cli.jswalletDeps = { ...deps, log: output, ttyOutput: errorOutput } correctly wires the resolved output/errorOutput locals rather than the raw deps object. This is also a silent fix for other wallet subcommands (create, delete, etc.) that previously fell back to console.log even when a custom output was injected into runCLI.
  • All affected tests are updated to assert on ttyLines (stderr) and verify the return value, in line with the AGENTS.md "Hybrid commands" rule.

No bugs, security issues, or AGENTS.md violations found.


Token usage: 837 input, 6,235 output, 178,042 cache read, 29,929 cache write

@yodablocks

Copy link
Copy Markdown
Contributor Author

Note for reviewers: the bot flagged that interactive users will see JSON on stdout alongside human-readable stderr output in a terminal. Happy to add a process.stdout.isTTY guard to suppress JSON in interactive sessions if that matches the intended UX — wanted to check with the team before adding complexity.

@yodablocks
yodablocks force-pushed the fix/154-wallet-list-stderr branch from eb66a40 to 11d18af Compare March 12, 2026 00:14
@Nicolai1205

Copy link
Copy Markdown
Contributor

Fix already landed in main via refactor in #397 (ttyOutput routes human-readable wallet list to stderr). Branch is 0 commits ahead of main.

@erhnysr

erhnysr commented Sep 4, 2026

Copy link
Copy Markdown

Reopening this line of work in #576. This PR was closed on the understanding that the fix had already landed via #397 — but #397's diff only extracted a requireWalletFile() helper for the existence checks in showWallet/exportWallet/setDefaultWallet/deleteWallet; it never touched listWallets or the list handler. A full git log -L :listWallets:src/wallet.js trace confirms no commit ever introduced stderr/stdout separation for it, so the bug is still live on main. #576 is a fresh fix (summary → stderr, structured { wallets } → clean JSON on stdout) with a failing-first regression test and the full suite green.

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.

🟡 [Medium] wallet list writes human-readable text + JSON to stdout simultaneously (breaks piping)

4 participants