Repository navigation
output: add a notice level, distinct from warning - #423
Merged
Merged
Conversation
The formatter had one non-fatal level, Warn, and both its callers mean "you
should change something": a degraded auth-status result, and a deprecated flag.
An informational message routed through it would dilute that, and the next thing
to use this path is a recurring "a newer version exists" on commands that
worked fine.
Notice takes a stable code alongside the prose, because a consumer branching on
an informational message needs a key and the wording is not a contract. JSON
mode renders {"notice": {"code", "message"}} beside the existing warning and
error envelopes; --human renders a "Note:" line and drops the code, which has no
place in human output. cli_telemetry_notice is registered in cliPrefixedCodes
even though it is not an error code: the reservation guarantee is about the
identifier never colliding with an API code, which applies to a notice too.
The telemetry disclosure moves onto it, since it was the one formatter-adjacent
path writing bare prose. Interactive flows (auth login, the confirmation prompt)
keep writing prose to stderr by design, so the documented guarantee covers
formatter diagnostics rather than the whole stream, and says so.
Two fixes the documentation forced out. The PostHog SDK's Logger defaults to
log.New(os.Stderr, ...), so a failed upload printed "posthog <time> WARN:
sending request ..." as bare prose; analytics is opt-in and best-effort and its
enqueue errors were already swallowed, so it now gets a discarding logger, with
posthogEndpoint a var so a test can point at an always-rejecting server and
prove the silence. And stderr diagnostics are newline-delimited rather than one
document, which a first-run notice followed by an error demonstrates, so that
boundary is documented and pinned.
Test hygiene, found while writing the above: newWithCapture resolves
distinctID(), which reads and writes ~/.hyperframes/config.json, and 8 of the
18 tests constructing a client had no HOME isolation. TestMain now sandboxes the
package.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
terencechotai2-commits
left a comment
There was a problem hiding this comment.
Reviewed at eaddf060. No findings.
What I checked:
Notice(code, message)is a separate method onFormatter. Human mode rendersNote: <message>to stderr and drops the code. JSON mode writes one compact{"notice":{"code","message"}}line to stderr. Neither touches stdout. The one-envelope-per-line test pins the framing when a notice, warning and error all appear in one run.- The telemetry disclosure now goes through the formatter. I built the binary and ran it with a fresh config dir: in JSON mode the disclosure is a parseable
{"notice":{"code":"cli_telemetry_notice",...}}line on stderr instead of bare prose. discardLoggerstops PostHog transport failures from printing bare prose between the JSON envelopes. The test proves an upload was actually attempted, so it can't pass vacuously.- CI is green on ubuntu, macos and windows.
Consumer note (not a defect): JSON-mode stderr can now carry more than one line, e.g. a notice before an error envelope. Anything that runs json.loads(stderr) on the whole stream should parse line by line instead. The PR's docs already say this; worth calling out in the release notes.
— tai2
jrusso1020
approved these changes
Oct 7, 2026
jrusso1020
left a comment
Collaborator
There was a problem hiding this comment.
Approving at eaddf060. No findings that need a change. tai2's review covers the main behaviour; I add the reuse check and the mutation results.
- Reuse and size.
Noticesits next toWarnin both formatters with the same stderr-only shape, and nothing new is invented around it. The test fake inauth_login_oauth_test.gois the only otherFormatter, and it gains the one method. This is the smallest change that keepsWarnmeaning "act on this". - The telemetry disclosure through the formatter. In JSON mode it is now an envelope rather than bare prose, so a caller parsing stderr line by line no longer has to skip one free-text line on the first run.
TestJSONFormatter_DiagnosticsAreOnePerLinepins that framing.JSONFormatter.Errorwas already compactjson.Marshal, so the per-line claim also holds for existing error envelopes. cli_telemetry_noticeincliPrefixedCodes. That list exists only forcodes_test.go's namespace scan, so registering a notice code there reserves the identifier with no other effect. The comment says why.- Silencing PostHog's logger.
discardLoggerdrops only the SDK's transport chatter, and enqueue errors were already swallowed. The new test uses an always-500 server and asserts that an upload actually ran, so it can't pass vacuously.
Mutations: 3 of 4 caught.
- Caught: removing
discardLogger, emitting the envelope underwarning, and sending the telemetry disclosure back to bareos.Stderr. - Survived: appending a different code string to the human
Note:line. The test checks for the specific code, so this is a mutation artifact, not a gap.
go build, go vet and go test ./... pass locally, and CI's test job is green on Linux, macOS and Windows.
— Rames
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope
Surfaces: CLI | Module: Output / diagnostics
Part of PRINFRA-1328
Summary
The formatter had one non-fatal level,
Warn, and every caller uses it to mean "you should change something": a degradedauth statusresult, or a deprecated flag. The staleness notice in PRINFRA-1328 ("a newer version exists") is informational and will fire on commands that worked fine, so routing it throughWarnwould dilute what a warning means. This adds a separateNoticelevel, moves the telemetry disclosure onto it, and lands on its own so the staleness check can build on it.How it works
Every diagnostic the CLI emits through the formatter goes to stderr, never stdout, so a piped response stays clean. There are now three levels, chosen by what the caller should do:
--humanError{"error": {...}}Error: ...(plusHint:)Warn{"warning": {"message"}}Warning: ...Notice{"notice": {"code", "message"}}Note: ...A notice carries a stable
codebecause a consumer that branches on an informational message needs a key, and the prose is not a contract. Human output drops the code. The first notice is the telemetry disclosure (cli_telemetry_notice); the staleness check will addcli_update_available.A single run can emit several diagnostics (a first-run notice followed by an error is the common case), so stderr is one compact JSON object per line, not one document. README and SKILL.md now say so, and a test pins it.
Design decisions
A new level rather than reusing
Warn.Warnis useful only while it keeps meaning "act on this".ghmakes the same split: its update check prints an "upgrade notice", not a warning.Notice codes register in
cliPrefixedCodeseven though they are not errors. The reservation guarantees acli_identifier never collides with an API code, and that applies regardless of severity.The stderr guarantee is scoped to formatter diagnostics. Interactive flows (
auth loginprompts, the y/N confirmation) still write prose to stderr by design, so the docs promise JSON envelopes for formatter diagnostics, not for the whole stream.PostHog's SDK logger is silenced. It defaults to
log.New(os.Stderr, ...), so a failed telemetry upload printedposthog ... WARN: sending request ...as bare prose among the JSON envelopes. Telemetry is opt-in and best-effort and its enqueue errors were already swallowed, so its transport failures are now silenced too.The analytics test package sandboxes HOME. Constructing an analytics client resolves an anonymous ID from
~/.hyperframes/config.json, and 8 of the 18 tests that construct one had no HOME isolation, so running them on a machine without an ID wrote one into the developer's real config.TestMainnow isolates the whole package.Testing
Five new tests: the
Noticerendering in both formatters, the one-envelope-per-line framing, the silent analytics transport failure (against an always-rejecting server, so the upload path really runs), and the package-wide HOME sandbox. The telemetry notice test now asserts the envelope and its code rather than a substring. The transport-failure and JSON notice tests were checked by deliberately breaking the line each protects (removing the discarding logger; emitting the envelope underwarning) and watching them fail.make lintandmake testpass.🤖 Generated with Claude Code