Skip to content

output: add a notice level, distinct from warning - #423

Merged
somanshreddy merged 1 commit into
mainfrom
09-18-notice_output_level
Oct 7, 2026
Merged

somanshreddy merged 1 commit into
mainfrom
09-18-notice_output_level

Conversation

@somanshreddy

Copy link
Copy Markdown
Collaborator

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 degraded auth status result, 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 through Warn would dilute what a warning means. This adds a separate Notice level, 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:

Level Means JSON mode (default) --human
Error the command failed; exit code is non-zero {"error": {...}} Error: ... (plus Hint:)
Warn the command ran, but you should change something {"warning": {"message"}} Warning: ...
Notice something you may want to know; nothing is wrong {"notice": {"code", "message"}} Note: ...

A notice carries a stable code because 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 add cli_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. Warn is useful only while it keeps meaning "act on this". gh makes the same split: its update check prints an "upgrade notice", not a warning.

Notice codes register in cliPrefixedCodes even though they are not errors. The reservation guarantees a cli_ identifier never collides with an API code, and that applies regardless of severity.

The stderr guarantee is scoped to formatter diagnostics. Interactive flows (auth login prompts, 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 printed posthog ... 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. TestMain now isolates the whole package.

Testing

Five new tests: the Notice rendering 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 under warning) and watching them fail. make lint and make test pass.

🤖 Generated with Claude Code

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 terencechotai2-commits left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at eaddf060. No findings.

What I checked:

  • Notice(code, message) is a separate method on Formatter. Human mode renders Note: <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.
  • discardLogger stops 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 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. Notice sits next to Warn in both formatters with the same stderr-only shape, and nothing new is invented around it. The test fake in auth_login_oauth_test.go is the only other Formatter, and it gains the one method. This is the smallest change that keeps Warn meaning "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_DiagnosticsAreOnePerLine pins that framing. JSONFormatter.Error was already compact json.Marshal, so the per-line claim also holds for existing error envelopes.
  • cli_telemetry_notice in cliPrefixedCodes. That list exists only for codes_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. discardLogger drops 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 under warning, and sending the telemetry disclosure back to bare os.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

@somanshreddy
somanshreddy merged commit 02d9074 into main Oct 7, 2026
10 checks passed
@somanshreddy
somanshreddy deleted the 09-18-notice_output_level branch October 7, 2026 07:11
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.

3 participants