testsAndMisc/docs/superpowers/evidence/transcribe-diarize-split-2026-08-17.json
Krzysztof kuhy Rudnicki dbf2f29b00 _transcribe_diarize: split 356 -> 164 + 143 + 105
The last Python file over the cap:

  _transcribe_media.py    143  _try_import, both duration probes,
                               get_media_duration, ffmpeg transcode, cleanup
  _transcribe_cluster.py  105  _resample_linear, _kmeans_cosine and its
                               iteration loop
  _transcribe_diarize.py  164  the pipeline: audio loading, the classifier,
                               embedding extraction, diarize_segments

The graph is a tree: _transcribe_media imports nothing local, _cluster takes
only _try_import from it, _diarize imports from both. All 13 top-level
definitions verified AST-identical to HEAD, and an AST scan confirms the
three module constants travelled to the modules that use them.

transcribe_fw.py now imports get_media_duration from _transcribe_media
rather than through _transcribe_diarize. Ruff removed that re-export as
unused and broke the import; running the program is what caught it, and
naming the owning module is the correct fix under the no-barrels rule.

Verified: transcribe_fw.py /nonexistent.wav still exits 2 and --help exits
0; 63 tests pass at 100% line and branch on all three modules; 338 pass in
the directory. Over-cap files 33 -> 32, and no Python file is over the cap
any more - the remaining 32 are 29 shell, 2 kotlin, 1 dart.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011w2Pj4Ek3ZNMQVYcFHgXDY
2026-08-17 13:59:39 +02:00

62 lines
4.3 KiB
JSON

{
"intent": "Split the 356-line _transcribe_diarize.py into media probing, clustering maths, and the diarization pipeline, all under the 250-line cap, moving every definition verbatim.",
"scope": [
"_transcribe_diarize.py 356 -> 164 (audio loading, classifier, embeddings, diarize_segments)",
"New: _transcribe_media.py 143 (duration probing, ffmpeg transcode, temp cleanup)",
"New: _transcribe_cluster.py 105 (linear resampling, cosine k-means)",
"transcribe_fw.py: one import line re-pointed",
"Non-goal: any behaviour change"
],
"changes": [
"Extracted _try_import, both duration probes, get_media_duration, the ffmpeg transcode and _cleanup_temp into _transcribe_media.py; _resample_linear, _kmeans_cosine and _run_kmeans_iterations into _transcribe_cluster.py. What remains in _transcribe_diarize.py is the pipeline: loading audio, loading the classifier, extracting embeddings, and diarize_segments.",
"The dependency graph is a tree: _transcribe_media imports nothing local, _transcribe_cluster imports only _try_import from it, and _transcribe_diarize imports from both.",
"transcribe_fw.py now imports get_media_duration from _transcribe_media rather than through _transcribe_diarize. This was forced by ruff removing the now-unused re-export, and is the correct outcome under the no-barrels rule - import sites should name the owning module.",
"Test modules were re-pointed to the module that owns each function. The audio tests span two modules: _load_audio stayed put and still patches its own namespace, while the direct transcode and cleanup calls now name _transcribe_media."
],
"verification": [
{
"command": "python3 verify_split.py HEAD .../_transcribe_diarize.py <three modules>",
"result": "pass",
"evidence": "IDENTICAL: all 13 top-level definitions moved verbatim. Re-run after ruff's autofixes and the import re-point, and still identical."
},
{
"command": "AST scan for names used but not bound in each of the three modules",
"result": "pass",
"evidence": "All three report no unbound names, confirming the three module-level constants (_NDIM_2D, _SAMPLE_RATE_16K, _MIN_SAMPLES_DIAR) travelled to the modules that use them."
},
{
"command": "pytest linux_configuration/tests/test_transcribe_diarize_*.py --cov of all three modules --cov-branch",
"result": "pass",
"evidence": "63 passed - the same count as before the split. _transcribe_cluster.py 51 statements / 18 branches, _transcribe_diarize.py 81 / 22, _transcribe_media.py 59 / 12, all 100%."
},
{
"command": "python3 transcribe_fw.py /nonexistent.wav; echo $?",
"result": "pass",
"evidence": "Exit 2, the code transcribe.sh branches on, and --help exits 0. This is what caught a real breakage: ruff had removed the get_media_duration re-export as unused, and transcribe_fw.py imported it from there. Only running it (and the full suite) surfaced that."
},
{
"command": "pytest linux_configuration/tests/ -q",
"result": "pass",
"evidence": "338 passed, unchanged from before the split."
},
{
"command": "pre-commit run --files <changed files>",
"result": "pass",
"evidence": "All hooks pass. The shebang-executable hook reads the git index rather than the filesystem, so the new modules' mode change had to be staged with git add --chmod=+x before it would pass."
},
{
"command": "bash ~/utils/scripts/check_file_length.sh --all",
"result": "pass",
"evidence": "32 files over cap, down from 33. The three modules are 164, 143 and 105 lines. No Python file in the repo is now over the cap."
}
],
"risks": [
"A three-way split adds two import edges between sibling modules resolved by bare name on sys.path[0]. That is the existing convention in this directory and the real run confirms it resolves.",
"The get_media_duration re-export is gone, so any out-of-tree caller importing it from _transcribe_diarize would break. Only transcribe_fw.py imported it, and it was updated in the same commit."
],
"rollback": [
"git revert the commit; _transcribe_diarize.py returns to its 356-line form and the two new modules disappear.",
"After rollback, confirm python3 transcribe_fw.py /nonexistent.wav still returns 2 and pytest linux_configuration/tests/ reports 338 passed."
]
}