fix(inventory): fleet packages and root dist/ are not duplication (#174)

The ratchet counted chatkit's own Composer (src + committed dist) as four
chat composers and bip-kit's slug.ts as a slug helper, so extracting a
package read as more duplication. Fleet packages are now skipped the way the
app starter is, read from the derived register so a new package is excluded
the day it is registered; dist/ is excluded at the repo root too.


Claude-Session: https://claude.ai/code/session_01M6u11m24oVkG98wAVbN7nf

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
CatoandClaude authored and GitHub committed 2026-10-14 02:25:39 -07:00
1 parent 92fc62db83
commit 126cf6d07d
2 files changed
+50 -1

No files matched your search

+26 -1
View File
@@ -89,6 +89,26 @@ repos=$(gh repo list "$OWNER" --limit "$LIMIT" --no-archived --source \
--jq '.[] | "\(.name)\t\(.defaultBranchRef.name // "")"' 2>/dev/null)
[ -n "$repos" ] || { echo "could not list repos for $OWNER" >&2; exit 2; }
# Paths that are never a copy somebody wrote: dependencies, build output and
# tests. dist/ is matched at the ROOT too — chatkit commits dist/composer.js,
# and `/dist/` alone counted it as a second chat composer (2026-10-14).
EXCLUDE_PATHS='node_modules|\.next/|(^|/)dist/|__tests__|\.test\.|\.spec\.|\.d\.ts'
# The fleet's packages are excluded the way the app starter is: a kit IS the
# one shared implementation that every copy should become. Counting chatkit's
# Composer as a chat composer, or bip-kit's slug.ts as a slug helper, made
# extracting a package read as MORE duplication — the ratchet punishing the
# exact move it exists to reward. The list is the derived register, so a new
# package is excluded the day it is registered, with no edit here.
REGISTER="$HERE/../../registers/packages.json"
KITS=""
if [ -f "$REGISTER" ]; then
KITS=$(jq -r --arg o "$OWNER" '.packages[].repo // empty
| select(startswith("https://github.com/" + $o + "/"))
| sub("^https://github.com/[^/]+/"; "")' "$REGISTER")
fi
kits_skipped=""
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
truncated=""
@@ -117,6 +137,10 @@ fetch_tree() {
while IFS=$'\t' read -r name branch; do
[ -n "$name" ] || continue
[ -n "$branch" ] || continue
if grep -qx "$name" <<<"$KITS"; then
kits_skipped="$kits_skipped $name"
continue
fi
if ! body=$(fetch_tree "$name" "$branch"); then
unreadable="$unreadable $name"
continue
@@ -132,7 +156,7 @@ while IFS=$'\t' read -r name branch; do
# product — which is the honest number.
printf '%s' "$body" \
| jq -r '.tree[]? | select(.type=="blob") | .path' 2>/dev/null \
| grep -viE 'node_modules|\.next/|/dist/|__tests__|\.test\.|\.spec\.|\.d\.ts' \
| grep -viE "$EXCLUDE_PATHS" \
| grep -vE '^templates/app/|^scripts/site-template/' \
> "$TMP/$name.files"
inspected=$((inspected + 1))
@@ -171,6 +195,7 @@ done
if [ "$MODE" = report ]; then
echo
echo "inspected $inspected repo(s) on their default branches"
[ -n "$kits_skipped" ] && echo "not counted (fleet packages — the shared implementation):$kits_skipped"
[ -n "$truncated" ] && echo "⚠ TRUNCATED trees (undercounted):$truncated"
[ -n "$unreadable" ] && echo "⚠ COULD NOT READ (undercounted):$unreadable"
echo
+24
View File
@@ -140,6 +140,30 @@ for path in src/lib/domain/methods/ballot-updates.ts lib/auto-updates.ts src/com
if matches date-utils "$path"; then no "date-utils ignores $path"; else ok "date-utils ignores $path"; fi
done
# Build output and the packages themselves are not copies.
EXCLUDE=$(grep "^EXCLUDE_PATHS=" "$HERE/shared-inventory.sh" | cut -d"'" -f2)
for path in dist/composer.js dist/react/Composer.js apps/web/dist/x.js node_modules/a/logger.ts; do
if grep -qiE "$EXCLUDE" <<<"$path"; then ok "not counted: $path"; else no "not counted: $path"; fi
done
for path in src/composer.ts src/lib/distance.ts lib/distribution/slug.ts; do
if grep -qiE "$EXCLUDE" <<<"$path"; then no "still counted: $path"; else ok "still counted: $path"; fi
done
KITS_FIXTURE='{"packages":[{"repo":"https://github.com/bitbaum/chatkit"},{"repo":"https://github.com/bitbaum/bip-kit"},{"repo":"https://github.com/someone-else/chatkit"},{}]}'
kits=$(jq -r --arg o bitbaum '.packages[].repo // empty
| select(startswith("https://github.com/" + $o + "/"))
| sub("^https://github.com/[^/]+/"; "")' <<<"$KITS_FIXTURE")
if [ "$kits" = "$(printf 'chatkit\nbip-kit')" ]; then
ok 'fleet packages are read from the register (own org only)'
else
no "fleet packages are read from the register (own org only): got $(tr '\n' ' ' <<<"$kits")"
fi
if grep -q 'registers/packages.json' "$HERE/shared-inventory.sh" && grep -q 'kits_skipped="$kits_skipped' "$HERE/shared-inventory.sh"; then
ok 'the inventory skips the fleet packages'
else
no 'the inventory skips the fleet packages'
fi
if grep -q '\.where"' "$HERE/shared-inventory.sh"; then
ok 'a rise names the files behind it'
else