testsAndMisc/docs/superpowers/contracts/analyze-repo-split-2026-08-16.json
Krzysztof kuhy Rudnicki 41cc0451c9 Split analyze_repo.sh into an entry script and five libs
869 lines -> 231, with the extracted helpers and per-STEP blocks in
lib/analyze_repo_{scan,tools,separate,report,symbols}.sh (86-228 each).

The seam that mattered was STEP 4, whose two passes share a map of
language -> temp file. Rather than let that cross a file boundary, the
map is passed by nameref and the comments file by parameter, so
separate_code_and_comments fills what report_languages reads with no
global in between.

Two boundaries were one step off on the first pass and produced 23
shellcheck findings: the KEYWORDS_* tables and detect_languages had been
cut away from their only consumers, so every one read as unused (SC2034)
or unassigned (SC2154). Moving each beside its consumer cleared all 23
without a suppression. The nameref also makes shellcheck read a bare
assoc-array subscript on the left of an assignment as arithmetic;
quoting the nine keys is the fix.

The line-set diff against HEAD earned its place here: it caught a
`find ... -printf` call at original line 719 that had fallen into a
one-line gap between two extraction ranges and been dropped. bash -n and
shellcheck both passed on that broken version.

Verified without running the script (decision 6 -- install_missing_tools
calls sudo pacman, cargo and makepkg): shellcheck clean across all six,
the function set matches HEAD plus exactly the six new wrappers, no
executable line lost, and a stubbed run of the entry preamble defines
all fourteen functions, proving the source lines resolve at runtime.

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

20 lines
2.3 KiB
JSON

{
"title": "Split analyze_repo.sh (869 lines) into an entry script and five libs",
"objective": "Bring linux_configuration/scripts/single_use/utils/analyze_repo.sh under the repo-wide 250-line cap by extracting its helper functions and its per-STEP top-level blocks into lib/analyze_repo_*.sh, without changing what the script emits.",
"acceptance_criteria": [
"analyze_repo.sh and every new lib/analyze_repo_*.sh file is at most 250 lines.",
"shellcheck reports zero findings across the entry script and all five libs, at the repo's no-severity-filter setting, with no suppression added.",
"The set of shell functions defined after sourcing is a superset of the original eight, adding only the six wrappers introduced around former top-level blocks: detect_languages, separate_code_and_comments, report_languages, analyze_symbols, analyze_cscope, analyze_clang_ast.",
"Every executable (non-comment, non-blank) line of the original file survives somewhere in the entry or a lib, except for lines deliberately edited to quote an assoc-array subscript, quote $TOP_N, or add a local declaration.",
"A stubbed run of the entry script's preamble defines all fourteen functions, proving each source line resolves at runtime rather than merely parsing.",
"The eight STEP headers the script prints are all still emitted, in the original order.",
"No lib sources another lib; the entry sources all five."
],
"out_of_scope": [
"Executing analyze_repo.sh, whose install_missing_tools calls sudo pacman, cargo install and makepkg; decision 6 forbids running it.",
"Defining KEYWORDS_SHELL and KEYWORDS_JAVA, which the report pass references but which have never existed. The lookup guards on a non-empty value so those two languages are silently skipped; defining them would change output and is a separate fix.",
"Fixing the unguarded cd calls or other pre-existing behaviour in the moved code beyond what shellcheck requires."
],
"verifier": "shellcheck over the entry plus all five libs (expects zero findings), bash -n on each, bash ~/utils/scripts/check_file_length.sh over the six files (expects none listed), a line-set diff of the original against entry+libs showing no unintended loss, and a stubbed run of the entry preamble printing all fourteen function names."
}