2026-05-18 22:03:59 -05:00
# Stage: trim
## Purpose
2026-05-22 19:05:23 -05:00
Optionally trim the final transcript to session bounds; always produce a durable final-trimmed transcript.
2026-05-18 22:03:59 -05:00
## Inputs and Outputs
Inputs:
2026-05-22 19:05:23 -05:00
- `transcripts/final.json`
2026-05-18 22:03:59 -05:00
Outputs:
2026-05-22 19:05:23 -05:00
- `transcripts/final.trimmed.json` (or configured trim output path)
2026-05-18 22:03:59 -05:00
- when trim enabled: `artifacts/session_bounds.json`
## Boundaries
Owns:
- Trim-enabled switch behavior
- Bounds generation via Scriptorium artifact run
2026-05-22 19:05:23 -05:00
- Bounds validation against final transcript
2026-05-18 22:03:59 -05:00
- Keep-selector derivation and Seriatim trim invocation
- Copy-through behavior when disabled or bounds indicate unchanged transcript
Does not own:
- Upstream normalization
- Downstream artifact analysis
## Config Fields Used
- `session.session_id`
- `session.campaign`
- `pipeline.workspace.root`
- `pipeline.trim.enabled`
- `pipeline.trim.output_path`
- `pipeline.trim.bounds.prompt_id`
- `pipeline.trim.bounds.profile_id`
- `pipeline.trim.bounds.timeout`
- `pipeline.trim.bounds.output_path`
- `pipeline.trim.bounds.transcript_input_name`
- `pipeline.trim.bounds.render_debug`
- `pipeline.trim.bounds.render_output_path`
- `pipeline.seriatim.binary`
- `pipeline.seriatim.timeout`
- `pipeline.scriptorium.binary`
- `pipeline.scriptorium.config_path`
- `pipeline.scriptorium.timeout`
## External Adapters Used
- Scriptorium adapter:
- optional `RenderArtifact` for bounds debug render
- `RunArtifact` for bounds output
- Seriatim adapter:
- `Trim` when bounds indicate trimming is required
## State and Manifest Behavior
2026-05-22 19:05:23 -05:00
- Reads final transcript from normalize manifest outputs when available; falls back to canonical path.
2026-05-18 22:03:59 -05:00
- Uses run-local outputs/logs/reports/config/scratch paths when run layout is enabled.
2026-05-23 04:51:16 +00:00
- Materializes canonical final-trimmed transcript and session bounds when trim is enabled.
2026-05-18 22:03:59 -05:00
- Records bounds diagnostics, trim action, keep selector, and adapter metadata.
## Skip and Resume Behavior
- Runner-level skip applies when already succeeded and not forced.
- Forced reruns can stale downstream succeeded stages.
2026-05-22 19:05:23 -05:00
- When `trim.enabled=false` , stage still succeeds by copying final to final-trimmed output.
2026-05-18 22:03:59 -05:00
## Failure Behavior
2026-05-22 19:05:23 -05:00
- Fails on missing/invalid final transcript.
- With trim enabled, fails on missing adapters/config, bounds generation/validation errors, invalid bounds JSON, invalid range/segment ids, trim adapter failures, or invalid final-trimmed output.
2026-05-18 22:03:59 -05:00
## Tests to Inspect Before Changing
- `internal/stage/trim_test.go`
- `internal/adapters/scriptorium/subprocess_test.go`
- `internal/adapters/seriatim/subprocess_test.go`
## Architectural Invariants
2026-05-22 19:05:23 -05:00
- Trim never falls back to polished transcript; final transcript is required input.
2026-05-18 22:03:59 -05:00
- `session_bounds` output exists only for enabled trim path.
- Render-debug artifacts are diagnostics and not declared stage outputs.