forge
Explore
Log in

Don't you dare go Hollow

Kb-sync post hook greps only the edited file

Browse files at this commit

4a9b76be12ade166dd5dbf1f3e0cc2a3ecdd5a19Ahmet Kaan GümüşParent: bf8046e
  • chore
    • kb-sync post hook greps only the edited file
Show full message
⚡ chore: kb-sync post hook greps only the edited file

Domain edits: 227 README greps -> 1 (0.392s -> 0.003s); route sweep
only for src/web + lib.rs edits; session sweep unchanged.
.claude/kb-sync.shmodified+18 -9
@@ -19,23 +19,32 @@ ingest() {
19 }19 }
20 20
21 check() {21 check() {
22+ # $2 = the single edited src file (post); empty = full sweep (session)
22 # corner-cut: substring match on "<name>.rs" anywhere in README — a module23 # corner-cut: substring match on "<name>.rs" anywhere in README — a module
23 # mentioned outside ## Layout also counts; tighten to the section if it lies24 # mentioned outside ## Layout also counts; tighten to the section if it lies
25+ mods="${2:-src/domain/*.rs src/web/*.rs}"
26+ # only domain/web files are ## Layout modules (lib.rs, config.rs, ... are not)
27+ case "$mods" in *src/domain/*.rs|*src/web/*.rs) ;; *) mods="" ;; esac
24 missing=""28 missing=""
25- for f in src/domain/*.rs src/web/*.rs; do29+ for f in $mods; do
26 b=$(basename "$f" .rs)30 b=$(basename "$f" .rs)
27 [ "$b" = mod ] && continue31 [ "$b" = mod ] && continue
28 grep -q "$b\.rs" README.md || missing="$missing $b"32 grep -q "$b\.rs" README.md || missing="$missing $b"
29 done33 done
30 # Route drift: every utoipa path under a lib.rs nest prefix must appear34 # Route drift: every utoipa path under a lib.rs nest prefix must appear
31- # backticked in the README ## Endpoints table.35+ # backticked in the README ## Endpoints table. Only web/ and lib.rs edits can
36+ # introduce drift, so a domain-file edit skips this sweep.
32 routes=""37 routes=""
33- while read -r prefix mod; do38+ case "${2:-src/lib.rs}" in
34- while read -r p; do39+ *src/web/*.rs|*src/lib.rs)
35- full="$prefix$p"; full="${full%/}"40+ while read -r prefix mod; do
36- grep -qF "\`$full\`" README.md || routes="$routes $full"41+ while read -r p; do
37- done < <(grep -oP 'path = "\K[^"]*' "src/web/$mod.rs" 2>/dev/null)42+ full="$prefix$p"; full="${full%/}"
38- done < <(grep -oP '\.nest\("\K[^"]+", web::\w+' src/lib.rs | sed 's/", web::/ /')43+ grep -qF "\`$full\`" README.md || routes="$routes $full"
44+ done < <(grep -oP 'path = "\K[^"]*' "src/web/$mod.rs" 2>/dev/null)
45+ done < <(grep -oP '\.nest\("\K[^"]+", web::\w+' src/lib.rs | sed 's/", web::/ /')
46+ ;;
47+ esac
39 msg=""48 msg=""
40 [ -n "$missing" ] && msg="README.md ## Layout is missing src modules:$missing."49 [ -n "$missing" ] && msg="README.md ## Layout is missing src modules:$missing."
41 [ -n "$routes" ] && msg="$msg README.md ## Endpoints is missing routes:$routes."50 [ -n "$routes" ] && msg="$msg README.md ## Endpoints is missing routes:$routes."
@@ -53,7 +62,7 @@ case "$1" in
53 fp=$(jq -r '.tool_input.file_path // empty' 2>/dev/null)62 fp=$(jq -r '.tool_input.file_path // empty' 2>/dev/null)
54 case "$fp" in63 case "$fp" in
55 */README.md) ingest ;;64 */README.md) ingest ;;
56- */src/*.rs) check PostToolUse ;;65+ */src/*.rs) check PostToolUse "$fp" ;;
57 esac66 esac
58 ;;67 ;;
59 esac68 esac