Skip to content

refactor(cli): resolve runtime config once and thread ui.IO - #122

Merged
jmgilman merged 1 commit into
masterfrom
feat/cli-ux-p1-merge-context
Jun 8, 2026
Merged

jmgilman merged 1 commit into
masterfrom
feat/cli-ux-p1-merge-context

Conversation

@jmgilman

@jmgilman jmgilman commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

P1 / PR-1.4 of the CLI UX overhaul — the merge pass that makes the foundation real. No user-visible behavior change: the resolved values and output bytes are identical; resolution simply happens once.

What's here

  • Resolve-once: the root PersistentPreRunE resolves the full RuntimeConfig and caches it, the single ui.IO, the logger, and outputExplicit on commandContext. The ten per-command loadRuntimeConfig re-calls (up/down/exec/info/install/list/run/connect/wallet/target) become cc.runtimeConfig.
  • loadRuntimeConfig(cmd, vp): precedence values from viper; the flag-only session knobs (-v/-q/--non-interactive/--color/--no-color) straight off cmd.Flags() (env-immune); -v raises the resolved --log-level; --color/--no-color fold into a ui.ColorMode. The signature change is atomic with the re-call deletions because resolveWallet/rejectExplicitTarget have no cmd in scope (deviation from the 063 plan, which mistakenly put the signature change in PR-1.2).
  • resolveUX: turns the requested color policy + interactivity into final verdicts from the raw injected streams — NO_COLOR supreme, the non-interactive latch one-way.
  • ui.IO seam: ctx.io.NewSlogLogger (DiscardHandler under -q) replaces newLogger; list/info/wallet read cc.io.JSON() instead of the viper-backed outputJSON() helper. Both removed.
  • addGlobalFlags extracts the persistent-flag registration so tests drive loadRuntimeConfig directly; ui gains an exported IsTerminalReader for the latch.
  • ConfigFromRuntime takes a ui-local RuntimeView (via a RuntimeConfig.view() adapter) so ui never imports cli (no cycle; keeps charm-banned deps out of ui's graph).

Testing

  • gofmt/go vet/go build clean; golangci-lint 0 issues; moon run root:check + moon run root:test (full envtest gate) green; git diff --check clean.
  • New: slogLevel, resolveColorMode (incl. --no-color/explicit-color precedence), resolveUX (non-TTY → plain + non-interactive; --color=always forces color off-TTY), loadRuntimeConfig flag resolution (-vv raise, -q, --non-interactive, viper output) + unknown-color rejection. Existing per-command tests pass unchanged through the new single resolution (the byte-neutrality net); the newLogger/outputJSON unit tests are dropped (their behavior moved to ui and is covered there).

Part of the P1 foundation series (1.1 #119, 1.2 #120, 1.3 #121 merged → 1.4 → 1.5 → 1.6).

🤖 Generated with Claude Code

P1 foundation (PR-1.4) of the CLI UX overhaul — the merge pass. Resolve the
full runtime config exactly once in the root PersistentPreRunE and cache it,
the single ui.IO, the logger, and outputExplicit on commandContext. Delete the
ten per-command loadRuntimeConfig re-calls (up/down/exec/info/install/list/run/
connect/wallet/target) in favour of cc.runtimeConfig.

loadRuntimeConfig now takes (cmd, vp): precedence values come from viper, the
flag-only session knobs (-v/-q/--non-interactive/--color/--no-color) come
straight off cmd.Flags(), -v raises the resolved --log-level, and --color/
--no-color fold into a ui.ColorMode. resolveUX turns the requested policy into
final color/non-interactive verdicts from the raw injected streams (NO_COLOR
supreme; the latch one-way). The signature change is atomic with the re-call
deletions because resolveWallet and rejectExplicitTarget have no cmd in scope.

The ui.IO seam replaces the ad-hoc logger and JSON toggle: ctx.io.NewSlogLogger
(DiscardHandler under -q) supersedes newLogger, and list/info/wallet read
cc.io.JSON() instead of the viper-backed outputJSON() helper (both removed). The
global flags are extracted into addGlobalFlags so tests can drive
loadRuntimeConfig directly. ui gains an exported IsTerminalReader for the latch.

No user-visible behaviour change: the resolved values and output bytes are
identical; resolution simply happens once.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jmgilman
jmgilman force-pushed the feat/cli-ux-p1-merge-context branch from 67cbd42 to cc50a75 Compare June 8, 2026 14:50
@jmgilman
jmgilman merged commit 915bf7d into master Jun 8, 2026
14 of 15 checks passed
@jmgilman
jmgilman deleted the feat/cli-ux-p1-merge-context branch June 8, 2026 15:00
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