Simplify: dedup actor label, reuse JSON policy, StrEnum-ify usage window#211
Merged
Conversation
Quality cleanups from a codebase-wide /simplify review (behavior-preserving): - audit: collapse `_actor_label`'s redundant `actor_type == "system"` branch (both arms produced identical output since actor_type already defaults to "system"). - auth/flow: route the `--json` login note through `jsonshape.dumps` so it shares the CLI's single `default=str` serialization policy instead of a raw `json.dumps`. - account: promote `usage --window`'s hand-validated value set to a `choices.UsageWindow` StrEnum, matching every other choice flag — Typer now renders [day|week|month] in --help, validates, and tab-completes for free, dropping the bespoke validation block. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ASaeJJ9LvPiSjcsEqywxwu
The `--llm` map render and `--llm-reduce` orchestration were implemented three
times — in commands/transcripts.py and app/transcribe/{run,batch}.py — each a
copy of the same policy (the `transform` record shape, the per-block reduce
header, the empty-input guard that skips the billable Gateway call, and the
additive `{"type": "reduce", …}` NDJSON schema). The copies were already drifting
and any change to the shapes had to be made in three places.
Promote the delivery policy to a new app-layer module, app/transform.py:
- render_transform_steps (moved out of app/transcribe/run.py)
- emit_transform — the per-transcript map result render (NDJSON-per-id in batch,
else the transcribe JSON/human render)
- emit_reduce — the reduce chain over labeled (id, text) contributions, with the
shared header/empty-guard/NDJSON policy; callers pass only the block label and
the empty-input noun so the exact wording is preserved.
transcripts.py and batch.py now delegate to these; batch._gather_reduce_inputs
returns (source, text) tuples and lets emit_reduce own the header and the
nothing-to-reduce policy. Behavior is unchanged (same output, same messages).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ASaeJJ9LvPiSjcsEqywxwu
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.
Quality cleanups from a codebase-wide /simplify review (behavior-preserving):
_actor_label's redundantactor_type == "system"branch(both arms produced identical output since actor_type already defaults to
"system").
--jsonlogin note throughjsonshape.dumpsso itshares the CLI's single
default=strserialization policy instead of a rawjson.dumps.usage --window's hand-validated value set to achoices.UsageWindowStrEnum, matching every other choice flag — Typer nowrenders [day|week|month] in --help, validates, and tab-completes for free,
dropping the bespoke validation block.
Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01ASaeJJ9LvPiSjcsEqywxwu