Skip to content

Reduce LOC with shared media-source, JSON-emit, and omit-None helpers#151

Merged
alexkroman merged 2 commits into
mainfrom
claude/code-reducing-helpers-4ga1im
Jun 13, 2026
Merged

Reduce LOC with shared media-source, JSON-emit, and omit-None helpers#151
alexkroman merged 2 commits into
mainfrom
claude/code-reducing-helpers-4ga1im

Conversation

@alexkroman

Copy link
Copy Markdown
Collaborator

Factor three repeated patterns into helpers, collapsing duplication across
the media commands and the JSON emission paths:

  1. mediafile.resolve_media_source — the ~25-line URL-classify → download →
    reject block was copy-pasted in caption/clip/dub (and had already drifted:
    clip lacked the bare scheme:// reject). Now one context manager owns it,
    yielding (local_path, downloaded); callers keep only their per-command
    output-path logic (also shared via mediafile.default_output). clip now
    rejects scheme:// like caption/dub, and dub checks ffmpeg before the URL
    branch (matching caption).

  2. jsonshape.compact — replaces the build-then-"if x is not None" idiom in
    CLIError.to_dict and the streaming turn payload.

  3. jsonshape.dumps — centralizes json.dumps(..., default=str), the one
    serialization policy every emit path shared (output, BaseRenderer, the
    --out / -o json field renderers).

https://claude.ai/code/session_01P9Yeo2YLTWUPou2yvqR7wa

Factor three repeated patterns into helpers, collapsing duplication across
the media commands and the JSON emission paths:

1. mediafile.resolve_media_source — the ~25-line URL-classify → download →
   reject block was copy-pasted in caption/clip/dub (and had already drifted:
   clip lacked the bare scheme:// reject). Now one context manager owns it,
   yielding (local_path, downloaded); callers keep only their per-command
   output-path logic (also shared via mediafile.default_output). clip now
   rejects scheme:// like caption/dub, and dub checks ffmpeg before the URL
   branch (matching caption).

2. jsonshape.compact — replaces the build-then-"if x is not None" idiom in
   CLIError.to_dict and the streaming turn payload.

3. jsonshape.dumps — centralizes json.dumps(..., default=str), the one
   serialization policy every emit path shared (output, BaseRenderer, the
   --out / -o json field renderers).

https://claude.ai/code/session_01P9Yeo2YLTWUPou2yvqR7wa
@alexkroman alexkroman enabled auto-merge June 13, 2026 15:24
@alexkroman alexkroman added this pull request to the merge queue Jun 13, 2026
Merged via the queue into main with commit cac4a82 Jun 13, 2026
16 checks passed
@alexkroman alexkroman deleted the claude/code-reducing-helpers-4ga1im branch June 13, 2026 15:31
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.

2 participants