Skip to content

feat(cli): add signet link with a --json machine-readable output mode - #342

Merged
blockchain-maxis merged 4 commits into
blockchain-maxis:mainfrom
ibochielizabeth-spec:feat/cli-json-output
Sep 2, 2026
Merged

feat(cli): add signet link with a --json machine-readable output mode#342
blockchain-maxis merged 4 commits into
blockchain-maxis:mainfrom
ibochielizabeth-spec:feat/cli-json-output

Conversation

@ibochielizabeth-spec

Copy link
Copy Markdown
Contributor

closes #264

Stacked on #335 and #336 (feat: scaffold the cli/ Go module closing #251, and feat: read a config file... closing #262) — there was no signet link command, or any cli/ module at all, to add --json to before those. This branch cherry-picks both commits (authorship preserved — they're @ibochivincent-lang's work) so it builds cleanly; the commit to actually review here is the top one (c85277c).

Summary

CI pipelines that link a deploy wallet need to parse the result. Without structured output, automation scrapes human-formatted text that's free to change between releases.

Changes

  • cli/internal/link/link.go (new): Link(handle, publicKey, network) (Result, error). Validates handle (mirroring HANDLE_PATTERN from packages/types/src/handle.ts: lowercase/digits/_/-, 1-32 chars) and publicKey (Stellar G... charset/length — not a full StrKey checksum, since real key handling is still internal/keys' job, not yet implemented). Returns Result{Handle, PublicKey, Network, Status}. This does not yet perform a real on-chain claim or call a deployment's HTTP API — internal/keys and internal/spec, which it would need for that, are themselves still scaffolded — but the output shape is the real, stable contract --json commits to now.
  • cli/internal/cmd/link.go (new): wires it up as signet link <handle> --public-key ... [--network] [--json] (--network defaults to testnet). Without --json, prints a human summary to stdout. With --json, encodes exactly one JSON object to stdout via encoding/json and nothing else. On a validation error, stdout stays empty in both modes — the error reaches the user through stderr, via main.go's existing top-level error handling, never through stdout.
  • cli/internal/cmd/link_test.go (new): asserts --json's stdout decodes as the expected link.Result and is exactly one line (no decorative text before/after), that non---json output does not parse as JSON, and that an invalid public key leaves stdout empty with a non-zero exit.
  • cli/internal/link/link_test.go (new): the validation logic in isolation (valid input, invalid handle, invalid public key).
  • cli/README.md: documents the new command, its flags, and the --json output contract.

Verification

  • go build ./... / go vet ./... / go test ./... — all pass (28/28 tests across internal/cmd, internal/config, internal/link).
  • golangci-lint run ./... — 0 issues.
  • node scripts/check-docs.mjs — passes.
  • Manually exercised the built binary:
    • signet link aquawolf --public-key G... --json{"handle":"aquawolf","publicKey":"G...","network":"testnet","status":"ok"} on stdout, nothing on stderr.
    • Same command without --jsonLinked aquawolf to G... (testnet).
    • signet link aquawolf --public-key nope --json → empty stdout, invalid public key "nope": expected a Stellar G... address on stderr, exit code 1.
  • Cross-compiled with CGO_ENABLED=0 for linux/amd64 — still clean, no cgo crept in.

ibochivincent-lang and others added 3 commits August 30, 2026 16:30
Every CLI issue is blocked on this module existing. Add cli/ as a
standalone Go module (go 1.25, no cgo) alongside the pnpm workspace,
building a signet binary via cobra: cmd/signet/main.go is the
entrypoint, internal/cmd holds the command tree, and internal/link,
internal/keys, internal/spec are placeholder packages for the
wallet-linking, key-management, and API-spec work that follows.

signet --version carries a version and commit string injected via
ldflags. signet --help and a bare `signet` invocation both print real
usage text — cobra only renders the Usage: section when a command is
Runnable() or has subcommands, so the root command needed an explicit
RunE (falling through to cmd.Help()) to show it before any subcommand
exists. golangci-lint is configured via cli/.golangci.yml, and a new
CI job builds, vets, tests, and lints the module.

Verified go build/go vet/go test all pass, and the binary
cross-compiles with CGO_ENABLED=0 for linux/amd64 and darwin/arm64.
…entity

Self-hosters and testnet users need to point the CLI at a deployment
other than the default, and repeat runs shouldn't re-ask which identity
to use. Every invocation needing --url and --source made self-hosted
deployments second-class.

Add internal/config: Load/Save a JSON file under os.UserConfigDir()/
signet (baseUrl, source), and Resolve combines flag > env (SIGNET_URL,
baseUrl only) > config file > built-in default per field. Wire --url/
--source as persistent flags on the root command, resolved in
PersistentPreRunE and attached to the command context via
config.WithResolved/FromContext for subcommands to read once they
exist. An explicit --source is saved back to the config file
(RememberSource) so the next run without it picks the same identity
back up. No config file is required for the default deployment.

Document the precedence and file location in cli/README.md, and add
SIGNET_URL to check-docs.mjs's ENV_ALLOW list — it's the cli/ module's
own shell env, not part of the pnpm workspace's .env.
CI pipelines that link a deploy wallet need to parse the result, and
without structured output automation scrapes human-formatted text
that's free to change between releases.

Add internal/link.Link(handle, publicKey, network), validating the
handle (mirroring HANDLE_PATTERN from packages/types) and the public
key's charset/length, returning a Result{Handle, PublicKey, Network,
Status}. This doesn't yet perform a real on-chain claim or call a
deployment's HTTP API — internal/keys and internal/spec, which it
would need for that, are themselves still scaffolded — but the output
contract is real and stable now.

Wire it up as `signet link <handle> --public-key ... [--network]
[--json]`. Without --json, prints a human summary to stdout. With
--json, encodes exactly one JSON object to stdout via encoding/json
and nothing else; on a validation error, stdout stays empty in both
modes and the error reaches the user via stderr (main.go's existing
error handling), never stdout.

Covered by cmd/link_test.go (asserting --json's stdout decodes as the
expected JSON and is exactly one line, non-json output is not JSON,
and an invalid input leaves stdout empty) and link/link_test.go (the
validation logic in isolation).
@drips-wave

drips-wave Bot commented Aug 30, 2026

Copy link
Copy Markdown

@ibochielizabeth-spec Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@vercel

vercel Bot commented Aug 30, 2026

Copy link
Copy Markdown

@ibochielizabeth-spec is attempting to deploy a commit to the blockchainmaxis-8449's projects Team on Vercel.

A member of the Team first needs to authorize it.

@netlify

netlify Bot commented Aug 30, 2026

Copy link
Copy Markdown

Deploy Preview for stellar-signet ready!

Name Link
🔨 Latest commit a7411e7
🔍 Latest deploy log https://app.netlify.com/projects/stellar-signet/deploys/6a98064ad923970008bc16bd
😎 Deploy Preview https://deploy-preview-342--stellar-signet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

blockchain-maxis#335 and blockchain-maxis#336 landed as squashes, so their files came back as add/add
conflicts against this branch's cherry-picks of the same work:
- .github/workflows/ci.yml, README.md: take main's (carries the golangci
  action/version fixes and the packages/ui removal).
- cli/internal/cmd/root.go: main's version is blockchain-maxis#336's fuller one (config
  resolution in PersistentPreRunE); this branch only adds AddCommand(newLinkCmd()).
- cli/README.md: take this branch's, which documents the link command.

Also made the non-JSON output stop claiming a link that did not happen.
internal/keys and internal/spec are still scaffolds, so 'Linked aquawolf to
G… (testnet)' reported a success for a no-op. It now reads 'Validated … Not
yet submitted — the on-chain claim is not implemented.' The --json contract is
untouched, which is what issue blockchain-maxis#264 and the downstream stack depend on.

Verified: go build/vet/test, gofmt -l, golangci-lint v2.13.2 (0 issues), plus
a manual run of all three paths — --json emits exactly one JSON line on
stdout, the human path writes the honest summary, and an invalid handle leaves
stdout empty with the error on stderr and exit 1.
@blockchain-maxis
blockchain-maxis merged commit 6040164 into blockchain-maxis:main Sep 2, 2026
10 of 11 checks passed
blockchain-maxis added a commit to Mamavee001/signet that referenced this pull request Sep 2, 2026
…error

Conflict resolution against the squashed blockchain-maxis#335/blockchain-maxis#336/blockchain-maxis#342:
- .github/workflows/ci.yml, README.md: main's.
- cli/cmd/signet/main.go: this branch's exit-code mapping (the point of the PR).
- cli/internal/cmd/link.go, cli/README.md: main's honest 'Validated … not yet
  submitted' wording rather than this branch's older 'Linked …'.
- cli/internal/link/link.go: this branch's ValidationError and public-key
  redaction.

The secret-hygiene test only inspected cobra's output buffers. The command tree
runs with SilenceErrors, so a returned error never reaches those buffers —
cmd/signet/main.go prints it to the process's real stderr. The test therefore
could not fail no matter what an error message said, which is the half of the
acceptance criterion ('stdout, stderr, or an error string') that most needed
covering. Now asserts the error string too.

That immediately caught a real leak. The public-key path was already careful
not to echo its input, but the handle path was not:

  $ signet link SASAAEJC6P5U…UUEMCD --public-key GASAAEJC…
  invalid handle "SASAAEJC6P5U…UUEMCD": expected 1-32 lowercase letters…

Reproduced with the built binary, not just in a test — a seed put in the wrong
argument slot was read straight back into shell history and any CI log. Errors
now pass the value through redactSecrets, so an ordinary typo is still echoed
('invalid handle "Bad Handle"') while a secret-shaped value becomes
'[redacted: secret-shaped value]'.

Verified: go build, go vet, gofmt -l, golangci-lint v2.13.2 (0 issues) and
go test -race ./... all clean, plus the built binary — redaction confirmed,
typo feedback intact, and exit codes 2 for invalid input / 0 for success.
blockchain-maxis added a commit to Mamavee001/signet that referenced this pull request Sep 2, 2026
Conflict resolution against the squashed blockchain-maxis#335/blockchain-maxis#336/blockchain-maxis#342:
- .github/workflows/ci.yml, README.md: main's.
- cli/cmd/signet/main.go, cli/internal/link/link.go, cli/internal/cmd/link.go:
  this branch's, which carry blockchain-maxis#345's exit-code mapping that this PR is stacked
  on. Taking main's first silently dropped it — caught because the shim then
  forwarded exit 1 instead of 2 in the end-to-end check below.
- cli/README.md: this branch's, with the stale 'Linked …' example updated to
  main's honest 'Validated … not yet submitted' wording.
- scripts/check-docs.mjs: keep the CLI_RELEASE_ENABLED / NPM_TOKEN allowlist
  entries (GitHub repo variable and Actions secret, not app env).

Reapplied the handle-error secret redaction from blockchain-maxis#345, which this branch
predates.

Verified the release path end to end rather than by reading it — built a
linux/amd64 binary with the workflow's own ldflags, staged it through
scripts/release/stage-platform-package.mjs, pinned with pin-shim-version.mjs,
laid the two packages out as npm would under node_modules/@signet, and ran the
shim:

  --version              -> signet version 9.9.9-test (commit deadbeef)
  link --json            -> one JSON object, nothing else
  invalid handle, $? -> 2   (the shim forwards the binary's real exit code)

Then reverted the staged binary and the 9.9.9-test version pins.

Publishing stays inert on merge: release-cli.yml triggers only on a cli-v*
tag (none exist) and the npm publish step is additionally gated on
vars.CLI_RELEASE_ENABLED, which is not set.

go build/vet/test -race, gofmt, golangci-lint v2.13.2 (0 issues) and
check-docs all clean.
blockchain-maxis added a commit to Otfrugger/signet that referenced this pull request Sep 2, 2026
This PR's only real change is the cross-compile smoke build; everything else in
the diff is cherry-picked blockchain-maxis#335/blockchain-maxis#336/blockchain-maxis#342/blockchain-maxis#345, all now squashed onto main. Took
main's version of every one of those files.

ci.yml keeps all three improvements rather than either side:
- `go test -race ./...` from this branch (issue blockchain-maxis#252 asks for -race; main
  still had a plain `go test`),
- the golangci-lint action v8 + pinned v2.13.2 from main,
- the four-target cross-compile smoke build this PR adds. Noted in the comment
  that the target set matches what release-cli.yml publishes, so the two
  cannot silently diverge.

Verified locally: all four targets build with CGO_ENABLED=0, and
go test -race ./... is clean across all 7 packages.
blockchain-maxis added a commit to Otfrugger/signet that referenced this pull request Sep 2, 2026
Everything except cli/internal/browser/ and its docs was a cherry-pick of
blockchain-maxis#335/blockchain-maxis#336/blockchain-maxis#342/blockchain-maxis#345/blockchain-maxis#356/blockchain-maxis#357/blockchain-maxis#358, all now on main — took main's for all of
those. scripts/check-docs.mjs keeps all three allowlist entries rather than
either side's pair (WAYLAND_DISPLAY from this branch, CLI_RELEASE_ENABLED and
NPM_TOKEN from blockchain-maxis#346).

Verified the fallback behaves as issue blockchain-maxis#257 requires, by driving OpenOrPrint
with DISPLAY and WAYLAND_DISPLAY unset:

  headless, browser allowed -> prints 'Open this URL to continue: <url>', returns nil
  --no-browser              -> same

so the opener's failure is absorbed rather than propagated, and both paths
reach the developer at the same URL.

Left unwired deliberately, unlike blockchain-maxis#357's CheckStellarCLI: there is no call site
to attach it to yet — `signet link` performs no approval flow (that lands with
the loopback server and the pairing endpoints), so wiring it now would mean
inventing the flow rather than connecting to one. Both the package doc and
cli/README say so plainly.

go build/vet, gofmt, golangci-lint v2.13.2 (0 issues), go test -race ./... and
check-docs all clean.
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.

CLI has no machine-readable output mode

3 participants