Skip to content

cli: add --json structured-output mode#885

Draft
kcsongor wants to merge 2 commits into
cs/solana-multi-hostfrom
cs/ntt-json-output
Draft

cli: add --json structured-output mode#885
kcsongor wants to merge 2 commits into
cs/solana-multi-hostfrom
cs/ntt-json-output

Conversation

@kcsongor

Copy link
Copy Markdown
Contributor

Summary

Adds a --json flag (also activated by WL_NTT_JSON=1) to the NTT CLI commands that parent processes / scripts most often need to drive:

  • ntt init
  • ntt add-chain (both the regular and --instance-of multi-tenant paths)
  • ntt push (regular + --dangerously-transfer-ownership-in-one-step)
  • ntt transfer-ownership
  • ntt solana token-authority

In --json mode, every stdout write (including library console.logs and Bun's native console) is redirected to stderr. The only thing that lands on stdout is exactly one final { ok: true, command, data } envelope emitted from the command's success path.

Failure paths intentionally stay unstructured: non-zero exit + stderr message is the contract. Wrappers read the trailing stdout line on exit 0; treat anything else as failure.

Why draft, why this base

This stack technically doesn't depend on #875 — the --json work touches commands that exist independent of the multi-tenant changes. But it's easier to keep the branches stacked while #875 is in flight, since #875 is also under active development and rebasing the JSON work onto main and then again onto #875's eventual merge state is fiddly.

Don't merge this until #875 is merged. Once #875 lands on main, I'll re-target this PR to main and lift draft.

Test plan

  • bun test src/__tests__/ — full suite still passes (160 pass)
  • New src/__tests__/json-output.test.ts covers:
    • JSON envelope shape via --json flag
    • Same via WL_NTT_JSON=1 env var
    • Human mode unchanged
    • stdout / stderr separation under --json
  • Manual smoke: ntt init --json | jq ., ntt solana token-authority ... --json | jq .
  • Manual smoke on ntt add-chain / ntt push / ntt transfer-ownership against a real deployment (deferred until solana: multi-tenant deployment #875 lands)

@kcsongor kcsongor force-pushed the cs/ntt-json-output branch from 7b1c095 to f271ba6 Compare May 20, 2026 15:31
@kcsongor kcsongor force-pushed the cs/solana-multi-host branch from 0ad1b81 to 44239cf Compare June 3, 2026 12:55
@kcsongor kcsongor force-pushed the cs/ntt-json-output branch 2 times, most recently from 76f2c77 to 11bf414 Compare June 3, 2026 13:05
kcsongor added 2 commits June 3, 2026 21:26
…transfer-ownership

Adds a global --json flag (also activated by WL_NTT_JSON=1) that:

- Redirects console.log / .info / .warn / .debug and direct process.stdout
  writes to stderr.
- Emits exactly one { ok, command, data } envelope on stdout from the
  command's success path via emitResult().

Failure paths are intentionally unstructured: non-zero exit + stderr
message is the contract. Wrappers (scripts, parent processes) read the
trailing stdout line on exit code 0; treat anything else as failure.

Bun's console implementation doesn't always route through
process.stdout.write, so we override the console methods directly *and*
hijack process.stdout.write for transitive deps.
Lets parent processes consume the per-instance token_authority PDA without
text-scraping stdout. Same { ok, command, data } envelope shape as the
other --json-aware commands.
@kcsongor kcsongor force-pushed the cs/ntt-json-output branch from 11bf414 to 68ca889 Compare June 3, 2026 19:26
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.

1 participant