Skip to content

Add self-scan DB tool for token-efficient LLM orientation - #901

Merged
squid-protocol merged 1 commit into
mainfrom
feature/self-scan-db-tool
Jul 31, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
feature/self-scan-db-tool

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

  • Adds tests/tools/self_scan.py, a thin wrapper around galaxyscope . --db-only that regenerates docs/self_scan/gitgalaxy_master.db — a SQLite database of this repo's own structural facts (per-file LOC/complexity/function-class counts, per-function complexity/args/calls_out_to, dependency-network scores).
  • Purpose: an LLM coding session working in this repo often re-derives basic structural facts (file sizes, existing test-file inventories, function counts) via grep or an Explore subagent at the start of a task — real token cost for exactly the kind of question GitGalaxy already answers about any repo it scans, including itself. Querying the DB directly is near-zero-token for that class of orientation question.
  • Explicitly does not replace reading real file content: the DB has no line numbers and doesn't parse dict-literal internals (can't locate where LANGUAGE_DEFINITIONS["scala"] starts inside language_standards.py, for example) — it's for orientation/prioritization, not symbol lookup.
  • The DB itself is gitignored (*.db) and lives at docs/self_scan/ (sibling to docs/gitgalaxy_architecture_brief.md, outside docs/wiki/ so it can't interfere with the mkdocs build — confirmed via mkdocs.yml's docs_dir: "docs/wiki"). Disposable, regenerated in ~6-8s.

Bug found and fixed during manual testing

The native SQLite recorder DELETEs-then-INSERTs keyed on (repo_name, commit_hash), so re-running it only replaces rows from a prior run at the same commit. My first draft of this script passed a replacement (not merged) env= to the galaxyscope subprocess call, which stripped PATH/HOME and silently degraded git's commit-hash resolution to "Unknown" instead of erroring — so the second run's rows never matched the first run's key and just accumulated (179 files → 357, every file duplicated). Fixed by merging the parent env ({**os.environ, ...}) and, as defense in depth, having the script just delete the DB file before every regeneration rather than relying on the keyed replace at all (this DB is meant to reflect current state only, not history).

Test plan

  • ruff check / ruff format --check / mypy — all clean
  • Ran the script twice in a row — confirmed idempotent (179 files, no duplicate file_path rows, single commit_hash value) after the fix
  • Confirmed docs/self_scan/gitgalaxy_master.db does not show up in git status (already covered by the existing *.db gitignore rule)

🤖 Generated with Claude Code

…icient orientation

GitGalaxy already knows how to extract Structural Signatures about any
repo it scans -- including its own. An LLM coding session working in
this repo often re-derives basic structural facts (how big is this
file, how many functions does it have, which files already exist for
language X) via grep or an Explore subagent at the start of a task,
both of which cost real tokens for exactly the kind of question this
engine already answers about itself.

This wraps `galaxyscope . --db-only` to regenerate
docs/self_scan/gitgalaxy_master.db (gitignored, disposable, ~6-8s to
rebuild) so that orientation questions can be answered with a
near-zero-token `sqlite3` query instead. It does not replace reading
actual file content -- the DB has no line numbers and doesn't parse
dict-literal internals (e.g. it can't locate a specific language's
entry inside language_standards.py's LANGUAGE_DEFINITIONS dict) -- it's
for orientation and prioritization (file/function/class inventories,
LOC, complexity, dependency-network scores), not symbol lookup.

Deletes the DB before each regeneration rather than relying on the
recorder's own DELETE-then-INSERT (keyed on repo_name+commit_hash) --
that only replaces rows from a run at the same commit, so rows from a
previous commit would otherwise silently accumulate as HEAD moves.
Also merges (rather than replaces) the subprocess environment when
shelling out, since galaxyscope needs PATH/HOME to resolve git's
commit hash -- a replaced env degrades commit_hash to "Unknown"
instead of erroring, which is what caused the row-accumulation bug in
the first place during manual testing.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit ba93a80 into main Jul 31, 2026
28 checks passed
@squid-protocol
squid-protocol deleted the feature/self-scan-db-tool branch July 31, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant