Skip to content

fix(input): accept null version, cost, workspace and output_style - #684

Open
eric-engberg wants to merge 1 commit into
sirmalloc:mainfrom
eric-engberg:fix/payload-null-fields
Open

eric-engberg wants to merge 1 commit into
sirmalloc:mainfrom
eric-engberg:fix/payload-null-fields

Conversation

@eric-engberg

Copy link
Copy Markdown
Contributor

What

A status payload with version, cost, workspace or output_style set to null now renders. Before, it was rejected as a whole: no status line, exit 1.

Why

The payload schema already accepts null for context_window, effort, vim, worktree and rate_limits, but not for these four. One null in any of them failed validation for the whole payload, even when no widget on the line reads that field:

$ echo '{"model":{"id":"x"},"cwd":"/tmp","cost":null}' | ccstatusline
Invalid status JSON format: [
  {
    "expected": "object",
    "code": "invalid_type",
    "path": [
      "cost"
    ],
    "message": "Invalid input: expected object, received null"
  }
]

version: null, workspace: null and output_style: null fail the same way.

How

The four fields become .nullable().optional(), as the other five already are. Nothing else changes:

  • Every reader already handles null: Version and Output Style check the value for truthiness, Session Cost, Session Clock and the session-duration check read cost?.…, and the git and Claude-settings lookups read workspace?.… among their candidate directories. A null field renders exactly like a missing one.
  • The type change surfaces any reader that couldn't take null, and bun run lint passes with no other edits.
  • Wrong types are still rejected, as the existing "keeps invalid numeric strings rejected" tests expect. Fields inside these objects, and the identifiers Claude Code always sends (session_id, transcript_path, cwd, model), are unchanged. Making those nullable would need null handling at about a dozen call sites.

Demo

A sample payload with the four fields set to null, piped through the CLI (first output line and exit code), then the same payload with values for comparison. The line has Model, Context Length, Version, Session Cost and Output Style.

Powerline: before

Null payload fields before the fix, Powerline mode

Powerline: after

Null payload fields after the fix, Powerline mode

Plain: before

Null payload fields before the fix, plain mode

Plain: after

Null payload fields after the fix, plain mode

Testing

  • New test: a payload with all four fields null parses and keeps them as null. It fails on main.
  • bun test: 2783 pass, 0 fail. bun run lint passes.
  • StatusJSON.test.ts under Node (Vitest): 8 pass (7 existing, 1 new).
  • Built CLI under Bun 1.4.2 and Node 26.10.0:
    • With the baseline payload, both runtimes give identical output in plain and Powerline mode, the same as main.
    • With the four fields null and a line using Version, Session Cost and Output Style, main exits 1 under both runtimes. This branch renders the line, and both runtimes agree.
    • The TUI opens and exits cleanly under both.

The status payload schema accepted null for context_window, effort, vim,
worktree and rate_limits, but not for version, cost, workspace or
output_style. A payload with any of those four set to null failed
validation as a whole: the CLI printed "Invalid status JSON format" and
exited 1, so no status line rendered, even when no widget on the line
reads that field.

Mark the four fields nullable like the others. Every reader already
goes through optional chaining or a truthiness check (Version, Session
Cost, Session Clock, Output Style, and the git and Claude settings
lookups that fall back from workspace to cwd), so a null field renders
the same as a missing one. Wrong types are still rejected.
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