# Repeated-take alignment prototype

This reviewed, dependency-free Python asset analyzes Premiere transcript JSON
locally. It supports:

- reference-guided local occurrence matching when `referenceText` is non-empty;
- self-discovered repeated passages when it is empty;
- hard source-clip boundaries;
- fuzzy and partial matches;
- full-take placement around a shared timed-word anchor;
- provisional low-information and conflicting-ending rejection;
- chronological track assignment with the latest take on V1/A1;
- placement rows ordered from the lowest lane upward within each group so
  Premiere can provision missing OVERWRITE tracks sequentially;
- configurable before/after handles, a configurable inter-group safety gap,
  and same-track overlap validation;
- `analysis.json`, flat validated `placements.tsv` and `markers.tsv` control
  streams, a one-row `summary.tsv` for bounded progress, and a flat validated
  `source-markers.tsv` for take-local reference status.

Marker output is split by editorial purpose:

- reference-guided accepted takes receive one source marker each: `EXACT`
  spans the normalized exact take, `WORDING` spans the changed source words,
  and `PARTIAL` spans the accepted partial take;
- source-marker names use the owned `AA-RT · ` prefix and comments use the
  `automation-agent:repeated-takes` ownership tag so reruns can remove only
  their own earlier markers;
- self-discovery keeps group-spanning sequence review markers for accepted
  partial or non-identical stacks because it has no external reference;
- a plausible conflicting candidate that is excluded raises the target to one
  sequence warning marker;
- reference passages without an accepted take receive a short reserved
  timeline slot and one sequence missing marker;
- routine rejects and self-discovered singletons are not marked.

The helper reuses transcript timing and sentence-boundary behavior from the
sibling `srt-caption-toolkit` asset and raw lexical measurements from the
product-neutral `lexical-alignment` asset. A packaged ABSCRIPT must embed all
three reviewed folders.

Run:

```text
python -I repeated_take_alignment.py plan-session \
  --srt-toolkit-dir ../srt-caption-toolkit \
  --lexical-alignment-dir ../lexical-alignment \
  --session-manifest selection-session.json \
  --output session-order.json \
  --output-tsv session-order.tsv

python -I repeated_take_alignment.py analyze \
  --srt-toolkit-dir ../srt-caption-toolkit \
  --lexical-alignment-dir ../lexical-alignment \
  --session-manifest session.json \
  --handle-before 0.2 \
  --handle-after 0.3 \
  --group-gap 0.75 \
  --output-dir output

python -I repeated_take_alignment.py validate-plan \
  --srt-toolkit-dir ../srt-caption-toolkit \
  --lexical-alignment-dir ../lexical-alignment \
  --session-manifest session.json \
  --analysis output/analysis.json \
  --placements output/placements.tsv \
  --markers output/markers.tsv \
  --source-markers output/source-markers.tsv
```

`plan-session` accepts a safe selection-ordered manifest containing local
`sourceId`, zero-based `selectionIndex`, and optional `captureDateRaw` fields.
It uses capture-date order only when the complete selected set has coherent
ISO-8601 dates. Otherwise the complete set remains in Premiere selection-API
order. Exact capture-date ties use selection index and source ID only as stable
tie-breakers and are reported.

Library workflows may pass the same safe session data as a tab-separated table
with the frozen columns `sourceId`, `selectionIndex`, `displayName`,
`captureDateRaw`, `durationSeconds`, and `transcriptPath`. The duration clips
the after-handle at media end. In that form, `analyze` accepts the optional
reference text through `--reference-file`; no Premiere refs enter either file.

This is the Milestone 2 correctness prototype. It uses a bounded rare-word
anchor shortlist before its longest-passage star comparisons and before
reference-window scoring, so unrelated passages do not produce an unbounded
all-pairs token matrix. Its conservativity rules remain provisional until the
natural-session corpus and editor review complete Review Gate 1.
