mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-24 21:46:28 +01:00
Compare commits
2 Commits
284aa1e360
...
c54211f112
| Author | SHA1 | Date | |
|---|---|---|---|
| c54211f112 | |||
| c9bf289510 |
208
file_length/SURVEY-2026-08-14.txt
Normal file
208
file_length/SURVEY-2026-08-14.txt
Normal file
@ -0,0 +1,208 @@
|
||||
==============================================================================
|
||||
TOTALS: 4045 readable files (code 2700, prose 580, data 765)
|
||||
code lines total: 471,749
|
||||
==============================================================================
|
||||
|
||||
### LONGEST FILES OVERALL (any readable kind), top 30
|
||||
|
||||
lines kind lang path
|
||||
------ ----- ---------- ---------------------------------------------------------------------------------------------------------
|
||||
174800 prose Text testsAndMisc/linux_configuration/scripts/periodic_background/digital_wellbeing/pacman/words.txt
|
||||
2053 prose Markdown testsAndMisc/docs/superpowers/plans/2026-05-01-phone-focus-recovery.md
|
||||
1838 prose Markdown todo/BACKLOG.md
|
||||
1734 code Shell testsAndMisc/linux_configuration/scripts/periodic_background/digital_wellbeing/setup_midnight_shutdown.sh
|
||||
1570 data JSON testsAndMisc/linux_configuration/scripts/periodic_background/digital_wellbeing/leechblock_defaults.json
|
||||
1475 data JSON macro-cam/assets/testdata/meals.json
|
||||
1437 code TypeScript konbini-67/src/core/shift.test.ts
|
||||
1417 code Dart epopeja_karta/lib/l10n/generated/app_localizations.dart
|
||||
1383 code Shell testsAndMisc/linux_configuration/scripts/single_use/features/setup_nextcloud_raspberry.sh
|
||||
1337 code Shell testsAndMisc/linux_configuration/scripts/periodic_background/check_and_enable_services.sh
|
||||
1325 code Dart home_inventory/test/data/item_repository_test.dart
|
||||
1276 code Shell testsAndMisc/linux_configuration/scripts/single_use/features/raspberry_pi_nextcloud.sh
|
||||
1274 data JSON macro-cam/assets/testdata/model_areas.json
|
||||
1120 code Dart home_inventory/lib/data/item_repository.dart
|
||||
1116 code Shell testsAndMisc/linux_configuration/scripts/single_use/utils/root_bl9000.sh
|
||||
1101 prose Markdown diet-guard/CLAUDE.md
|
||||
1097 code TypeScript konbini-67/src/core/shift.ts
|
||||
1091 data JSON macro-cam/assets/testdata/claude_meal_estimates.json
|
||||
1091 code Shell testsAndMisc/phone_focus_mode/focus_ctl.sh
|
||||
1089 code Dart dufs-cloud/app/test/browser_screen_test.dart
|
||||
1076 code Python steam-backlog-enforcer/steam_backlog_enforcer/main.py
|
||||
1072 code Python steam-backlog-enforcer/steam_backlog_enforcer/tests/test_stats.py
|
||||
1052 code Dart diet-guard/app/lib/screens/history_screen.dart
|
||||
1047 code TypeScript dufs-cloud/web/src/components/gallery.test.tsx
|
||||
1042 code Python steam-backlog-enforcer/steam_backlog_enforcer/tests/test_total_block.py
|
||||
1017 code Dart diet-guard/app/test/screens/history_screen_test.dart
|
||||
1017 code Shell testsAndMisc/linux_configuration/scripts/single_use/utils/generate_study_materials.sh
|
||||
942 code Shell testsAndMisc/linux_configuration/scripts/single_use/utils/lookup_docs.sh
|
||||
929 code Shell testsAndMisc/linux_configuration/scripts/periodic_background/digital_wellbeing/pacman/pacman_wrapper.sh
|
||||
925 prose Markdown todo/CLAUDE.md
|
||||
|
||||
### LONGEST CODE FILES, top 30
|
||||
|
||||
lines lang commits/yr path
|
||||
----- ---------- ---------- ---------------------------------------------------------------------------------------------------------
|
||||
1734 Shell 9 testsAndMisc/linux_configuration/scripts/periodic_background/digital_wellbeing/setup_midnight_shutdown.sh
|
||||
1437 TypeScript 12 konbini-67/src/core/shift.test.ts
|
||||
1417 Dart 2 epopeja_karta/lib/l10n/generated/app_localizations.dart
|
||||
1383 Shell 1 testsAndMisc/linux_configuration/scripts/single_use/features/setup_nextcloud_raspberry.sh
|
||||
1337 Shell 8 testsAndMisc/linux_configuration/scripts/periodic_background/check_and_enable_services.sh
|
||||
1325 Dart 6 home_inventory/test/data/item_repository_test.dart
|
||||
1276 Shell 1 testsAndMisc/linux_configuration/scripts/single_use/features/raspberry_pi_nextcloud.sh
|
||||
1120 Dart 7 home_inventory/lib/data/item_repository.dart
|
||||
1116 Shell 1 testsAndMisc/linux_configuration/scripts/single_use/utils/root_bl9000.sh
|
||||
1097 TypeScript 13 konbini-67/src/core/shift.ts
|
||||
1091 Shell 9 testsAndMisc/phone_focus_mode/focus_ctl.sh
|
||||
1089 Dart 12 dufs-cloud/app/test/browser_screen_test.dart
|
||||
1076 Python 26 steam-backlog-enforcer/steam_backlog_enforcer/main.py
|
||||
1072 Python 4 steam-backlog-enforcer/steam_backlog_enforcer/tests/test_stats.py
|
||||
1052 Dart 6 diet-guard/app/lib/screens/history_screen.dart
|
||||
1047 TypeScript 9 dufs-cloud/web/src/components/gallery.test.tsx
|
||||
1042 Python 2 steam-backlog-enforcer/steam_backlog_enforcer/tests/test_total_block.py
|
||||
1017 Dart 6 diet-guard/app/test/screens/history_screen_test.dart
|
||||
1017 Shell 2 testsAndMisc/linux_configuration/scripts/single_use/utils/generate_study_materials.sh
|
||||
942 Shell 2 testsAndMisc/linux_configuration/scripts/single_use/utils/lookup_docs.sh
|
||||
929 Shell 6 testsAndMisc/linux_configuration/scripts/periodic_background/digital_wellbeing/pacman/pacman_wrapper.sh
|
||||
918 Shell 5 testsAndMisc/linux_configuration/scripts/periodic_background/digital_wellbeing/setup_night_lockdown.sh
|
||||
912 Shell 5 testsAndMisc/linux_configuration/scripts/periodic_background/hosts/install.sh
|
||||
912 Shell 3 testsAndMisc/linux_configuration/scripts/single_use/features/setup_searxng.sh
|
||||
909 Dart 15 dufs-cloud/app/lib/screens/browser_screen.dart
|
||||
897 Dart 8 screen-locker/stronglift_replacement/workout_app/lib/screens/history_screen.dart
|
||||
896 Dart 2 epopeja_karta/test/widget_test.dart
|
||||
870 Shell 2 testsAndMisc/linux_configuration/scripts/single_use/utils/update_android_hosts.sh
|
||||
869 Shell 3 testsAndMisc/linux_configuration/scripts/single_use/utils/analyze_repo.sh
|
||||
850 Python 3 europe-county-map/scripts/extract_ck3_counties.py
|
||||
|
||||
### LONGEST PROSE (md/txt/rst/tex), top 30
|
||||
|
||||
lines lang path
|
||||
------ -------- -----------------------------------------------------------------------------------------------
|
||||
174800 Text testsAndMisc/linux_configuration/scripts/periodic_background/digital_wellbeing/pacman/words.txt
|
||||
2053 Markdown testsAndMisc/docs/superpowers/plans/2026-05-01-phone-focus-recovery.md
|
||||
1838 Markdown todo/BACKLOG.md
|
||||
1101 Markdown diet-guard/CLAUDE.md
|
||||
925 Markdown todo/CLAUDE.md
|
||||
761 Markdown testsAndMisc/linux_configuration/docs/SECURITY_HARDENING_ANALYSIS.md
|
||||
709 Markdown testsAndMisc/docs/superpowers/specs/2026-05-01-phone-focus-recovery-design.md
|
||||
648 Markdown .claude/plans/i-dont-want-to-resilient-teapot.md
|
||||
621 Markdown konbini-67/SPEC-physicality.md
|
||||
592 Markdown .claude/plans/i-added-google-anonymous-elegant-stallman.md
|
||||
578 Markdown .claude/plans/i-am-trying-to-starry-emerson.md
|
||||
564 Markdown .claude/plans/inventory-app-improvements-1-cheeky-mountain.md
|
||||
548 LaTeX CV/magisterskie/cv.tex
|
||||
528 Markdown diet-guard/app/.agents/skills/dart-migrate-to-checks-package/SKILL.md
|
||||
528 Markdown todo/.agents/skills/dart-migrate-to-checks-package/SKILL.md
|
||||
521 Markdown .claude/plans/build-prompt-melodic-mango.md
|
||||
478 Markdown .claude/plans/abundant-cooking-hippo.md
|
||||
461 Markdown .claude/plans/where-the-guard-lives-fluffy-shell.md
|
||||
459 Markdown .claude/plans/changes-to-diet-guard-splendid-spindle.md
|
||||
440 Markdown .claude/plans/japanese-convenience-store-clerk-witty-cocoa.md
|
||||
421 Markdown .claude/plans/all-repos-that-build-cozy-pike.md
|
||||
419 Markdown diet-guard/app/.agents/skills/dart-setup-ffi-assets/SKILL.md
|
||||
419 Markdown todo/.agents/skills/dart-setup-ffi-assets/SKILL.md
|
||||
406 Markdown .claude/plans/grind-leetcode-guard-velvet-engelbart.md
|
||||
402 Markdown .claude/skills/wiki-to-mcp-kb/references/pitfalls.md
|
||||
402 Markdown .claude/plans/inventory-management-for-spicy-cray.md
|
||||
390 Markdown .claude/plans/read-and-fix-incident-2026-08-05-no-way-wiggly-karp.md
|
||||
386 Markdown .claude/plans/take-https-github-com-punkpeye-awesome-m-gentle-swing.md
|
||||
384 Markdown testsAndMisc/.claude/skills/test-driven-development/SKILL.md
|
||||
384 Markdown testsAndMisc/.github/skills/test-driven-development/SKILL.md
|
||||
|
||||
### TOP REFACTOR ROI (lines x commits-last-year), top 30
|
||||
|
||||
roi lines commits/yr lang path
|
||||
----- ----- ---------- ---------- ---------------------------------------------------------------------------------------------------------
|
||||
27976 1076 26 Python steam-backlog-enforcer/steam_backlog_enforcer/main.py
|
||||
22796 556 41 Shell testsAndMisc/phone_focus_mode/config.sh
|
||||
18720 390 48 Python screen-locker/screen_locker/screen_lock.py
|
||||
17244 1437 12 TypeScript konbini-67/src/core/shift.test.ts
|
||||
15606 1734 9 Shell testsAndMisc/linux_configuration/scripts/periodic_background/digital_wellbeing/setup_midnight_shutdown.sh
|
||||
14261 1097 13 TypeScript konbini-67/src/core/shift.ts
|
||||
14041 739 19 Dart todo/lib/ui/capture_screen.dart
|
||||
13635 909 15 Dart dufs-cloud/app/lib/screens/browser_screen.dart
|
||||
13068 1089 12 Dart dufs-cloud/app/test/browser_screen_test.dart
|
||||
12495 833 15 Shell testsAndMisc/phone_focus_mode/deploy.sh
|
||||
11220 660 17 Dart todo/test/capture_screen_test.dart
|
||||
10696 1337 8 Shell testsAndMisc/linux_configuration/scripts/periodic_background/check_and_enable_services.sh
|
||||
9954 553 18 Python steam-backlog-enforcer/steam_backlog_enforcer/game_install.py
|
||||
9819 1091 9 Shell testsAndMisc/phone_focus_mode/focus_ctl.sh
|
||||
9423 1047 9 TypeScript dufs-cloud/web/src/components/gallery.test.tsx
|
||||
9252 771 12 Dart screen-locker/stronglift_replacement/workout_app/lib/screens/settings_screen.dart
|
||||
7950 1325 6 Dart home_inventory/test/data/item_repository_test.dart
|
||||
7840 1120 7 Dart home_inventory/lib/data/item_repository.dart
|
||||
7215 555 13 Python steam-backlog-enforcer/steam_backlog_enforcer/library_hider.py
|
||||
7176 897 8 Dart screen-locker/stronglift_replacement/workout_app/lib/screens/history_screen.dart
|
||||
7170 478 15 Python wake-alarm/wake_alarm/_alarm.py
|
||||
7020 702 10 Dart todo/lib/ui/note_editor.dart
|
||||
6994 538 13 TypeScript konbini-67/src/app.test.tsx
|
||||
6773 521 13 Python steam-backlog-enforcer/steam_backlog_enforcer/scanning.py
|
||||
6768 752 9 Dart screen-locker/stronglift_replacement/workout_app/lib/services/storage_service.dart
|
||||
6699 319 21 Python screen-locker/screen_locker/tests/conftest.py
|
||||
6612 551 12 CSS europe-county-map/src/App.css
|
||||
6600 440 15 Dart diet-guard/app/lib/screens/log_meal_screen.dart
|
||||
6516 543 12 Shell testsAndMisc/phone_focus_mode/focus_daemon.sh
|
||||
6312 1052 6 Dart diet-guard/app/lib/screens/history_screen.dart
|
||||
|
||||
### DISTRIBUTION BY LANGUAGE (code only)
|
||||
|
||||
lang n median mean p75 p90 p95 p99 max
|
||||
---------- --- ------ ----- --- --- --- ---- ----
|
||||
Python 895 179 206.6 294 399 466 652 1076
|
||||
Dart 758 105 160.5 203 351 480 897 1417
|
||||
TypeScript 459 85 125.4 162 266 361 698 1437
|
||||
Shell 363 120 201.1 243 457 663 1276 1734
|
||||
Kotlin 68 26 71.0 69 223 277 564 564
|
||||
HTML 60 402 333.8 548 716 738 843 843
|
||||
C 22 21 70.5 88 229 249 478 478
|
||||
CSS 19 169 261.1 535 768 774 774 774
|
||||
Swift 17 12 12 15 16 16 16 16
|
||||
C++ 16 70 97.8 151 288 288 288 288
|
||||
JavaScript 15 47 65.7 97 134 179 179 179
|
||||
Java 8 40 69.2 101 247 247 247 247
|
||||
|
||||
### DISTRIBUTION BY PROJECT (code only, >=10 files)
|
||||
|
||||
project n median MEAN p90 max total
|
||||
---------------------- --- ------ ----- --- ---- -------
|
||||
steam-backlog-enforcer 114 269 301.3 588 1076 34,352
|
||||
epopeja_karta 37 192 289.4 759 1417 10,708
|
||||
kuhytrack 12 215 240 392 652 2,880
|
||||
screen-locker 211 169 209.8 390 897 44,261
|
||||
steam-game-installer 18 144 198.2 473 765 3,567
|
||||
utils 127 167 193.3 412 525 24,552
|
||||
mcp-servers 27 136 189.1 467 487 5,106
|
||||
testsAndMisc 745 127 187.7 421 1734 139,813
|
||||
europe-county-map 75 138 181.8 374 850 13,637
|
||||
manga_translate 40 144 181.2 417 720 7,250
|
||||
leetcode-guard 117 181 180.4 296 400 21,111
|
||||
wake-alarm 68 150 178.2 405 764 12,118
|
||||
diet-guard 217 128 175.6 379 1052 38,101
|
||||
yay-mcp 16 109 168.3 478 554 2,693
|
||||
todo 99 109 165.9 405 739 16,421
|
||||
i3wm-mcp 12 130 165.8 275 615 1,989
|
||||
home_inventory 113 96 152.6 328 1325 17,249
|
||||
konbini-67 73 96 149.6 209 1437 10,919
|
||||
dufs-cloud 126 99 146.8 257 1089 18,497
|
||||
hotline3d 38 82 136.4 353 736 5,184
|
||||
macro-cam 55 103 133.5 279 574 7,341
|
||||
wiki-kb 31 95 121.3 215 463 3,760
|
||||
atomichabits 15 88 109.8 188 251 1,647
|
||||
octoforge 76 80 104.3 209 510 7,929
|
||||
kuhylog 92 89 94.9 166 301 8,727
|
||||
.claude 17 64 74.5 177 311 1,267
|
||||
iron-and-anvil 40 55 71.7 159 220 2,869
|
||||
habit_stack 54 42 71.7 169 288 3,870
|
||||
personal-website 25 48 65.3 165 303 1,633
|
||||
|
||||
### COUNT OVER CANDIDATE THRESHOLDS (code only)
|
||||
|
||||
threshold files over % of code of those, edited last yr
|
||||
--------- ---------- --------- ------------------------
|
||||
300 474 17.6% 452
|
||||
400 243 9.0% 229
|
||||
500 118 4.4% 114
|
||||
600 82 3.0% 80
|
||||
800 33 1.2% 33
|
||||
1000 19 0.7% 19
|
||||
1500 1 0.0% 1
|
||||
2000 0 0.0% 0
|
||||
5
file_length/__init__.py
Normal file
5
file_length/__init__.py
Normal file
@ -0,0 +1,5 @@
|
||||
"""Shared 250-line file-length cap: config, gate, and survey."""
|
||||
|
||||
from file_length.config import MAX_LINES
|
||||
|
||||
__all__ = ["MAX_LINES"]
|
||||
4606
file_length/baseline-2026-08-14.json
Normal file
4606
file_length/baseline-2026-08-14.json
Normal file
File diff suppressed because it is too large
Load Diff
128
file_length/check.py
Normal file
128
file_length/check.py
Normal file
@ -0,0 +1,128 @@
|
||||
"""Gate: fail if any given file exceeds the 250-line cap.
|
||||
|
||||
Invoked by `scripts/check_file_length.sh`, which pre-commit calls with the
|
||||
staged files. Exits 1 and lists every violation; exits 0 silently otherwise.
|
||||
|
||||
The check is deliberately deterministic code rather than a judgement call --
|
||||
adjudication belongs in an exit code, not in a model.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
if __package__ in (None, ""): # invoked as a plain script
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from file_length.config import ( # noqa: E402
|
||||
CAPPED_EXTENSIONS,
|
||||
EXCLUDED_DIRS,
|
||||
MAX_LINES,
|
||||
is_data_text,
|
||||
is_generated,
|
||||
is_vendored,
|
||||
)
|
||||
|
||||
|
||||
def count_lines(path: Path) -> int | None:
|
||||
"""Number of lines, or None if the file is binary or unreadable."""
|
||||
try:
|
||||
with path.open("rb") as handle:
|
||||
first = handle.read(8192)
|
||||
if b"\x00" in first:
|
||||
return None
|
||||
count = first.count(b"\n")
|
||||
while chunk := handle.read(1 << 20):
|
||||
count += chunk.count(b"\n")
|
||||
if first and not first.endswith(b"\n") and count == 0:
|
||||
count = 1
|
||||
return count
|
||||
except OSError:
|
||||
return None
|
||||
|
||||
|
||||
def exempt_reason(path: Path, lines: int) -> str | None:
|
||||
"""Why this file is not subject to the cap, or None if it is subject."""
|
||||
if path.suffix.lower() not in CAPPED_EXTENSIONS:
|
||||
return "not a capped extension"
|
||||
if is_vendored(path):
|
||||
return "vendored / third-party"
|
||||
if is_generated(path):
|
||||
return "generated"
|
||||
try:
|
||||
size = path.stat().st_size
|
||||
except OSError:
|
||||
return "unreadable"
|
||||
if is_data_text(path, lines, size):
|
||||
return "data-ish text (wordlist)"
|
||||
return None
|
||||
|
||||
|
||||
def iter_all(root: Path):
|
||||
"""Every file under root, skipping excluded directories."""
|
||||
for dirpath, dirnames, filenames in os.walk(root, followlinks=False):
|
||||
dirnames[:] = [d for d in dirnames if d not in EXCLUDED_DIRS]
|
||||
for name in filenames:
|
||||
candidate = Path(dirpath) / name
|
||||
if not candidate.is_symlink():
|
||||
yield candidate
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(
|
||||
description=f"Fail if any file exceeds {MAX_LINES} lines."
|
||||
)
|
||||
parser.add_argument("paths", nargs="*", type=Path)
|
||||
parser.add_argument(
|
||||
"--all",
|
||||
action="store_true",
|
||||
help="check the whole tree under the current directory",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--explain", action="store_true", help="also report why files were skipped"
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.all:
|
||||
targets = list(iter_all(Path.cwd()))
|
||||
elif args.paths:
|
||||
targets = args.paths
|
||||
else:
|
||||
parser.error("give file paths or --all")
|
||||
|
||||
violations: list[tuple[Path, int]] = []
|
||||
for path in targets:
|
||||
if not path.is_file():
|
||||
continue
|
||||
lines = count_lines(path)
|
||||
if lines is None:
|
||||
continue
|
||||
reason = exempt_reason(path, lines)
|
||||
if reason is not None:
|
||||
if args.explain:
|
||||
print(f" skip {path}: {reason}")
|
||||
continue
|
||||
if lines > MAX_LINES:
|
||||
violations.append((path, lines))
|
||||
|
||||
if not violations:
|
||||
return 0
|
||||
|
||||
print(
|
||||
f"File-length gate FAILED: {len(violations)} file(s) over {MAX_LINES} lines\n",
|
||||
file=sys.stderr,
|
||||
)
|
||||
for path, lines in sorted(violations, key=lambda item: -item[1]):
|
||||
over = lines - MAX_LINES
|
||||
print(f" {path}: {lines} lines (over by {over})", file=sys.stderr)
|
||||
print(
|
||||
"\nSplit them, or see refactor_claude_todo.md in this repo.", file=sys.stderr
|
||||
)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
203
file_length/config.py
Normal file
203
file_length/config.py
Normal file
@ -0,0 +1,203 @@
|
||||
"""Shared configuration for the 250-line file-length cap.
|
||||
|
||||
Single source of truth for the cap and its exemptions, imported by both the
|
||||
pre-commit gate (`check.py`) and the survey. Duplicating these lists in shell
|
||||
is what lets a gate and a survey silently disagree.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
#: Hard cap. Files above this fail the gate. Code and prose alike.
|
||||
MAX_LINES = 250
|
||||
|
||||
#: Extensions the cap applies to: real programming languages plus prose.
|
||||
#: Markup (.html/.css/.scss) is deliberately absent -- templates split into
|
||||
#: partials, not functions, so a line cap does not express anything useful.
|
||||
CAPPED_EXTENSIONS = {
|
||||
# code
|
||||
".py",
|
||||
".dart",
|
||||
".ts",
|
||||
".tsx",
|
||||
".js",
|
||||
".jsx",
|
||||
".sh",
|
||||
".bash",
|
||||
".zsh",
|
||||
".c",
|
||||
".h",
|
||||
".cpp",
|
||||
".cc",
|
||||
".hpp",
|
||||
".go",
|
||||
".rs",
|
||||
".java",
|
||||
".kt",
|
||||
".kts",
|
||||
".swift",
|
||||
".rb",
|
||||
".lua",
|
||||
".sql",
|
||||
".vue",
|
||||
".cs",
|
||||
".php",
|
||||
# prose
|
||||
".md",
|
||||
".markdown",
|
||||
".txt",
|
||||
".rst",
|
||||
".tex",
|
||||
".org",
|
||||
}
|
||||
|
||||
#: Generated files: regenerated by a tool, so splitting them is meaningless
|
||||
#: (the tool would just rewrite the original next run).
|
||||
GENERATED_PATTERN = re.compile(
|
||||
r"\.g\.dart$"
|
||||
r"|\.freezed\.dart$"
|
||||
r"|\.gr\.dart$"
|
||||
r"|\.config\.dart$"
|
||||
r"|\.mocks\.dart$"
|
||||
r"|\.min\.(js|css)$"
|
||||
r"|\.pb\.(go|py)$"
|
||||
r"|_pb2(_grpc)?\.py$"
|
||||
r"|\.generated\.ts$"
|
||||
r"|\.d\.ts$"
|
||||
r"|/l10n/generated/"
|
||||
r"|/generated/"
|
||||
)
|
||||
|
||||
#: A marker in the first few lines also marks a file generated. Covers tools
|
||||
#: that do not use a distinguishing extension.
|
||||
GENERATED_MARKERS = (
|
||||
"GENERATED CODE - DO NOT MODIFY",
|
||||
"@generated",
|
||||
"DO NOT EDIT",
|
||||
"Autogenerated",
|
||||
"AUTOGENERATED",
|
||||
"generated by",
|
||||
)
|
||||
|
||||
#: Directory names never descended into: dependencies, build output, caches.
|
||||
EXCLUDED_DIRS = frozenset(
|
||||
{
|
||||
".git",
|
||||
"node_modules",
|
||||
".dart_tool",
|
||||
"build",
|
||||
".venv",
|
||||
"venv",
|
||||
"env",
|
||||
"site-packages",
|
||||
"target",
|
||||
"ephemeral",
|
||||
"__pycache__",
|
||||
".mypy_cache",
|
||||
".pytest_cache",
|
||||
".ruff_cache",
|
||||
"dist",
|
||||
".next",
|
||||
"vendor",
|
||||
"third_party",
|
||||
"Pods",
|
||||
".gradle",
|
||||
".idea",
|
||||
".cxx",
|
||||
"coverage",
|
||||
"htmlcov",
|
||||
".tox",
|
||||
"Library",
|
||||
"Temp",
|
||||
"obj",
|
||||
".terraform",
|
||||
".fvm",
|
||||
".angular",
|
||||
".cache",
|
||||
".svelte-kit",
|
||||
"migrations",
|
||||
".ci-mirror-venv",
|
||||
".hippo",
|
||||
".build-deps",
|
||||
}
|
||||
)
|
||||
|
||||
#: Third-party content living *inside* a repo you own, keyed by repo dir name.
|
||||
#: Verified by git remote / vendor manifest, not guessed.
|
||||
VENDORED_SUBPATHS = {
|
||||
"mcp-servers": ("servers",),
|
||||
"dufs-cloud": ("app/assets/pdfjs", "web/assets/pdfjs"),
|
||||
".claude": (
|
||||
"projects",
|
||||
"shell-snapshots",
|
||||
"cache",
|
||||
"backups",
|
||||
"todos",
|
||||
"statsig",
|
||||
"history",
|
||||
"chrome",
|
||||
"downloads",
|
||||
"plugins",
|
||||
"ide",
|
||||
),
|
||||
}
|
||||
|
||||
#: Whole repos under ~ that are third-party clones, not kuhy's work.
|
||||
#: Verified 2026-08-14 by `git remote get-url origin` + commit authors.
|
||||
THIRD_PARTY_REPOS = frozenset(
|
||||
{
|
||||
"StringTheory", # github.com/AnthonySf/TheStringTheory
|
||||
"reaper-mcp", # github.com/TwelveTake-Studios/reaper-mcp
|
||||
"freesound-mcp", # github.com/timjrobinson/FreesoundMCPServer
|
||||
"llama_cpp_dart_local", # generated FFI bindings
|
||||
"aseprite-mcp",
|
||||
"aur",
|
||||
"build-your-own-x",
|
||||
"build_your_x",
|
||||
"byox-ladder",
|
||||
"warriorjs",
|
||||
"untools",
|
||||
"awesome-mcp-explorer",
|
||||
"runnerup",
|
||||
"depotdownloader",
|
||||
"actions-runner",
|
||||
}
|
||||
)
|
||||
|
||||
#: A `.txt` whose mean line is shorter than this is data (a wordlist, a
|
||||
#: coordinate dump), not prose, so the cap does not apply.
|
||||
DATA_TXT_MAX_MEAN_LINE = 25
|
||||
|
||||
|
||||
def is_generated(path: Path) -> bool:
|
||||
"""True if the file is tool-generated and must not be split by hand."""
|
||||
if GENERATED_PATTERN.search(path.as_posix()):
|
||||
return True
|
||||
try:
|
||||
with path.open("r", encoding="utf-8", errors="replace") as handle:
|
||||
head = "".join(next(handle, "") for _ in range(5))
|
||||
except OSError:
|
||||
return False
|
||||
return any(marker in head for marker in GENERATED_MARKERS)
|
||||
|
||||
|
||||
def is_data_text(path: Path, lines: int, size: int) -> bool:
|
||||
"""True for wordlist-style .txt: many lines, very short ones."""
|
||||
if path.suffix.lower() != ".txt" or lines <= 0:
|
||||
return False
|
||||
return (size / lines) < DATA_TXT_MAX_MEAN_LINE
|
||||
|
||||
|
||||
def is_vendored(path: Path) -> bool:
|
||||
"""True if the path sits under a known vendored subtree or excluded dir."""
|
||||
parts = path.parts
|
||||
if any(part in EXCLUDED_DIRS for part in parts):
|
||||
return True
|
||||
posix = path.as_posix()
|
||||
for repo, subs in VENDORED_SUBPATHS.items():
|
||||
for sub in subs:
|
||||
if f"/{repo}/{sub}/" in posix or posix.startswith(f"{repo}/{sub}/"):
|
||||
return True
|
||||
return any(f"/{repo}/" in posix for repo in THIRD_PARTY_REPOS)
|
||||
96
refactor_claude_todo.md
Normal file
96
refactor_claude_todo.md
Normal file
@ -0,0 +1,96 @@
|
||||
# Refactor TODO — enforce the 250-line file cap
|
||||
|
||||
> **This file is a ready-to-use prompt.** Paste it to Claude, or open this repo
|
||||
> and say "do refactor_claude_todo". It is self-contained: everything needed to
|
||||
> execute is below. Generated 2026-08-14 from a measured survey of every repo.
|
||||
|
||||
## Goal
|
||||
|
||||
Every file in this repo must be **at most 250 lines** — source, tests, and
|
||||
prose (`.md`/`.txt`/`.rst`/`.tex`) alike — and must **stay** that way forever,
|
||||
enforced by a gate that fails the commit, not by a note anyone can ignore.
|
||||
|
||||
Why: a file that cannot be read in one piece forces re-reads and partial edits,
|
||||
which is the single largest avoidable cost in an LLM-assisted workflow. Aim by
|
||||
churn, not size alone — refactoring pays where code is read and changed often
|
||||
(Fowler, *refactoring economic benefit*).
|
||||
|
||||
## Scope in this repo
|
||||
|
||||
- **39 files** currently exceed 250 lines (of 139 eligible files).
|
||||
- **14,348 lines** sit in violation; longest file is **525 lines**.
|
||||
|
||||
Exempt (do NOT split these):
|
||||
- generated files — `*.g.dart`, `*.freezed.dart`, `*.gr.dart`, `**/l10n/generated/**`,
|
||||
anything with a `GENERATED` header
|
||||
- markup — `.html`, `.css`, `.scss`
|
||||
- data files — `.json`, `.yaml`, `.csv`, wordlists and other data-ish `.txt`
|
||||
(mean line length under 25 chars)
|
||||
|
||||
## Violations, highest ROI first
|
||||
|
||||
ROI = lines x commits in the last year. Work top-down; a long file nobody edits
|
||||
has near-zero payoff and should not be first.
|
||||
|
||||
| lines | commits/yr | kind | file |
|
||||
|------:|-----------:|:-----|:-----|
|
||||
| 515 | 6 | code | `gatelock/gatelock/_window.py` |
|
||||
| 477 | 3 | code | `gatelock/gatelock/tests/test_recovery.py` |
|
||||
| 259 | 5 | code | `crdt_sync_dart/lib/src/sync.dart` |
|
||||
| 406 | 3 | code | `crdt-sync/crdt_sync/_firebase_auth.py` |
|
||||
| 393 | 3 | code | `crdt-sync/crdt_sync/tests/test_firebase_auth.py` |
|
||||
| 363 | 3 | code | `crdt-sync/crdt_sync/_sync.py` |
|
||||
| 525 | 2 | code | `crdt_sync_dart/test/firebase_auth_rest_test.dart` |
|
||||
| 483 | 2 | code | `gatelock/gatelock/_scrollable.py` |
|
||||
| 321 | 3 | code | `gatelock/gatelock/_recovery.py` |
|
||||
| 457 | 2 | code | `sync_settings_ui/test/sync_settings_screen_test.dart` |
|
||||
| 452 | 2 | code | `crdt_sync_dart/test/mirror_store_test.dart` |
|
||||
| 451 | 2 | code | `crdt_sync_dart/test/sync_revisions_test.dart` |
|
||||
| 439 | 2 | code | `aur-publish/publish.sh` |
|
||||
| 291 | 3 | code | `crdt_sync_dart/test/github_client_test.dart` |
|
||||
| 418 | 2 | code | `gatelock/gatelock/tests/test_outputs.py` |
|
||||
|
||||
_(24 further files over 250 lines not listed — re-run the survey for the full set.)_
|
||||
|
||||
## How to split
|
||||
|
||||
- **Python** — extract cohesive helpers into sibling modules; keep the public
|
||||
API and imports stable.
|
||||
- **Shell** — split into `lib/*.sh` sourced by a thin entry script. Keep
|
||||
`set -euo pipefail` in each.
|
||||
- **Dart / TypeScript** — extract widgets/components into their own files.
|
||||
- **Tests** — split by test-group into sibling files
|
||||
(`foo.test.ts` -> `foo.parsing.test.ts`, `foo.render.test.ts`). Coverage must
|
||||
not drop.
|
||||
- **Docs** — split into topic files under `docs/` with an index. For an
|
||||
oversized `CLAUDE.md`, move detail into referenced docs so the
|
||||
always-loaded part shrinks.
|
||||
|
||||
**Do not** game the cap: no one-lining, no deleting tests, no moving code into
|
||||
an exempt extension, no `# noqa`-style suppressions.
|
||||
|
||||
## Make it permanent (required — this is the point)
|
||||
|
||||
A refactor without a gate silently regrows. Before this task is done:
|
||||
|
||||
1. Wire the shared gate `~/utils/scripts/check_file_length.sh` into this repo's
|
||||
`.pre-commit-config.yaml` as a local hook. If the repo has no pre-commit
|
||||
config, add a minimal one.
|
||||
2. The hook checks **files in the commit** (not the whole tree), so unrelated
|
||||
commits never break, and it **fails** — exit 1, not a warning.
|
||||
3. No baseline file and no allowlist. Those are suppressions.
|
||||
4. If this repo has CI (`.github/workflows`), add the same check there so it
|
||||
also fails on push.
|
||||
|
||||
## Done condition
|
||||
|
||||
- `bash ~/utils/scripts/check_file_length.sh --all` from this repo root exits 0.
|
||||
- The repo's own test suite and coverage bar are still green.
|
||||
- `pre-commit run --files <changed files>` passes.
|
||||
- A deliberately over-250-line test file, staged, makes `git commit` **fail**.
|
||||
- For a deployed daemon/app: the entry point still actually runs.
|
||||
|
||||
## Verify
|
||||
|
||||
Run the repo's own suite, then run the program itself and confirm the
|
||||
behaviour is unchanged. Testing is the last step, never the first.
|
||||
38
scripts/check_file_length.sh
Executable file
38
scripts/check_file_length.sh
Executable file
@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ============================================================================
|
||||
# Fail if any file exceeds the shared 250-line cap.
|
||||
#
|
||||
# A file that cannot be read in one piece forces re-reads and partial edits,
|
||||
# which is the largest avoidable cost in an LLM-assisted workflow. The cap
|
||||
# applies to code AND prose; generated files, markup and data are exempt.
|
||||
#
|
||||
# The real check lives in Python (file_length/check.py) so that the gate and
|
||||
# the survey share one exemption list -- see rules/shell.instructions.md on
|
||||
# never embedding another language's logic inline.
|
||||
#
|
||||
# Usage:
|
||||
# scripts/check_file_length.sh <file> [<file> ...] # pre-commit passes these
|
||||
# scripts/check_file_length.sh --all # whole tree, from cwd
|
||||
# ============================================================================
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
readonly UTILS_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
readonly CHECKER="$UTILS_ROOT/file_length/check.py"
|
||||
|
||||
main() {
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "Usage: $(basename "$0") <file>... | --all" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -f "$CHECKER" ]]; then
|
||||
echo "Error: checker not found at $CHECKER" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PYTHONPATH="$UTILS_ROOT${PYTHONPATH:+:$PYTHONPATH}" \
|
||||
python3 "$CHECKER" "$@"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Loading…
Reference in New Issue
Block a user