Skip to content

feat(integrity): human-readable colored audit output on a terminal#125

Merged
jig merged 1 commit into
developfrom
feat/integrity-log-human
Jul 21, 2026
Merged

feat(integrity): human-readable colored audit output on a terminal#125
jig merged 1 commit into
developfrom
feat/integrity-log-human

Conversation

@jig

@jig jig commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Summary

The integrity audit was a single JSON line to stderr — fine for servers, noisy for interactive use. Now the output adapts to where stderr goes:

  • Interactive terminal → a human-readable block via the term package, one field per line, green when integrity is satisfied, red when not:
    ✓ integrity verified
        ref     v1.4.2
        commit  9fceb02da8f3c1…
        signer  alice
    
    ✗ integrity check failed
        reason  … differs from its committed version at "v1"
    
  • Redirected (pipe/file) → the structured JSON line is kept unchanged, so log ingestion is unaffected. Matches the "JSON for servers, readable for clients" split.

Honors NO_COLOR / CLICOLOR_FORCE. A terminal failure prints the red block and exits non-zero without the old second Error: line.

Implementation

  • lib/term: exported StderrStyle (Go-facing colorizer — stderr TTY + NO_COLOR/CLICOLOR_FORCE aware) and StderrIsTerminal; colorDecision refactored to take an fd (separate stdout/stderr caches).
  • command: reportIntegrity/integrityBlock; ErrIntegrityReported sentinel so main suppresses the duplicate error line.

Test plan

  • TestStderrStyle / TestStderrStylePlain (term): SGR codes under CLICOLOR_FORCE, plain under NO_COLOR.
  • TestIntegrityBlockFormat (command): green success block (header + 3 field lines), no signer line when absent, red failure block with the integrity: prefix stripped.
  • Full suite green with and without -tags debugger; verified end to end under a pty (colored block) and a pipe (JSON).

🤖 Generated with Claude Code

The integrity audit log was one JSON line to stderr — fine for server
log ingestion, noisy for interactive use. Now, when stderr is a
terminal, print a human-readable block using the term package: a green
'✓ integrity verified' with ref/commit/signer each on its own line, or
a red '✗ integrity check failed' with the reason. When stderr is
redirected (pipe/file) the structured JSON line is kept, so machine
consumers are unaffected. Honors NO_COLOR / CLICOLOR_FORCE.

- lib/term: exported StderrStyle (Go-facing colorizer, stderr TTY +
  NO_COLOR/CLICOLOR_FORCE aware) and StderrIsTerminal; colorDecision
  refactored to take an fd.
- command: reportIntegrity/integrityBlock; a terminal failure prints
  the red block and returns ErrIntegrityReported so main exits non-zero
  without a second 'Error:' line.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jig
jig merged commit 2f58d5d into develop Jul 21, 2026
14 checks passed
@jig
jig deleted the feat/integrity-log-human branch July 21, 2026 16:05
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