Skip to content

gitgalaxy libsurface: which libraries a repository leans on, which files lean hardest, how the surface changes (Part of #8534) - #8535

Merged
squid-protocol merged 4 commits into
mainfrom
sensors/libsurface
Nov 16, 2026
Merged

squid-protocol merged 4 commits into
mainfrom
sensors/libsurface

Conversation

@squid-protocol

@squid-protocol squid-protocol commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

New read-only command gitgalaxy libsurface SCAN_DB [SCAN_DB_AFTER] [--lib NAME] [--libs FILE] [--src ROOT] [--top N] [--json FILE] (gitgalaxy/tools/sensors/libsurface.py, wired into gitgalaxy/cli.py beside assess and reach). From a finished scan's file_data (imports, lines) and fcall_external (#8530) it gives three views: the external libraries in use (files, sites, distinct API names); the files coupled to one library, most coupled first (where work on the library lands); and, for two scans, the API names added and dropped and the files newly or no longer coupled. A site is a matching import or include plus a call to one of the library's API names; density is sites per line. Counts and lists only, no score, no risk claim. Databases are opened read-only; no column is added and no scan output changes. Part of #8534.

Who defines a library (three layers, later wins by name; disable = true removes an entry): (1) discovery with no list, every external import root: first dotted component (Python), host/owner/repo (Go), package prefix (Java), first :: component (Rust), package name (JS/TS), include directory or header name (C-family), after the engine's own is_stdlib_module / is_system_header lists and the repository's own packages are set aside; (2) a shipped table (library_table.py, Python data so no packaging change) of glob patterns for the API names of 20 C-family libraries, needed because a library reached through a wrapper header is invisible to includes alone; (3) TOML files: $XDG_CONFIG_HOME/gitgalaxy/libraries.toml, ROOT/.gitgalaxy/libraries.toml, --libs FILE. Patterns are globs, never regexes, so a pattern a user writes cannot hang the matcher; a malformed file is refused with a message (exit 2), patterns are length-bounded.

Type of change

  • New feature (a post-scan command; no parsing or engine logic change)

Measured

On curl, prometheus, sphinx, commons-lang and ripgrep scans the discovery lists are sensible; curl OpenSSL matches the research prototype exactly (19 files, 452 sites, 231 API names). The research test (coupling to a library vs where its work lands, recall@20, 19 pairs in curl, libarchive and harfbuzz) was re-run through this module with the glob table: +0.389 over a size ranking (99.7% lower bound +0.344), -0.018 against the registered regexes (non-inferior at -0.05), and +0.000 against the regex prototype on every one of the 19 pairs: the glob table loses nothing. Includes alone gave +0.253 and lost to the full measure by -0.136, which is why the table has API names. Outside C (import coupling only, registered before running): +0.241 over size on 11 evaluable pairs (Go +0.395 on 5, Python +0.102 on 5, Java one library; Rust not evaluable). Surface change, curl OpenSSL 2020-06 to 2022-12: 31 API names added, 15 dropped; 90% of the added names were absent from the earlier source and 80% of the dropped names gone from the later one, which checks the diff's accuracy about what appeared and disappeared, not that each name is the library's: at least three dropped names (SSL_IS_PROXY, SSL_CONN_CONFIG, SSL_SET_OPTION) are curl's own macros that share the SSL_ prefix, so the loose SSL_* pattern counts them (documented as a limitation on the wiki page); the added names include the OpenSSL 1.1 object API. All exploratory; the research is in the temporal-crucible repository (docs/sensor-overhaul/sensors/library_surface.md).

Class / Sibling gaps

Class: questions about a repository's dependencies answerable from the imports, includes and external calls a scan already stores, for any language that writes them. Handled here: library discovery in C-family, Python, Go, Java, Rust and JS/TS; coupled-file ranking; surface change between two scans; API-name matching for the 20 shipped C-family libraries; user and project overrides. Sibling gaps: (1) API names for Go, Python, Java, Rust and JS libraries: the scan records external calls there as bare names with no package, so names cannot be attributed; those languages use imports only (resolver work, not this command); (2) C++, Objective-C and Fortran probably have the same wrapper-header problem as C, untested; (3) discovery lists Rust workspace crates and unrecognised platform headers (in.h) as libraries: disable = true removes them, parsing Cargo.toml / go.mod would not need a guess but is a different input; (4) a prefix pattern also matches a repository's own macros or functions with that prefix (curl's SSL_* macros): excluding names the repository defines needs the scan to store macro definitions, not done here; the weak units in the research (c-ares, glib, libarchive zlib) are reported, not tuned; (5) the navigation entries for wiki page 08-25 are in this PR (docs/wiki/index.md, mkdocs.yml).

CI checklist

  • python tests/tools/audit_check.py passes
  • tests/tools/test_libsurface.py (37 tests; breaking the JDK-package skip or the call-matching logic on purpose fails 1 and 3 of them), tree-wide guards (289 passed, 1 skipped), tests/tools plus test_assess.py (4,810 passed; 1 failure, test_l5_speedups::test_javac_session_compiles_live_and_rejects_stillborn, fails identically on unmodified main: this box's JDK has no javac), time ratchet (4,890 tests, none over the limit)
  • Scan output unchanged: no recorder, parser or engine file touched, so no golden master moves

Files (hand-written, 7): gitgalaxy/tools/sensors/libsurface.py, gitgalaxy/tools/sensors/library_table.py, gitgalaxy/cli.py, tests/tools/test_libsurface.py, docs/wiki/08-25-library-surface.md, docs/wiki/index.md, mkdocs.yml.

Remaining slices

More table entries; Rust and the other wrapper-header languages need their own evidence first.

Lessons for agents

  • A string-literal key read from a user-supplied file or an environment variable trips the dead-key audit (no writer inside gitgalaxy/): name it as a module constant (XDG_CONFIG_ENV, DISABLE_KEY) as chronometer does for its env vars.
  • A bare cat > file with no heredoc hangs the shell on stdin: write scratch files with the Write tool (.claude/rules/python-test-traps.md).

🤖 Generated with Claude Code

https://claude.ai/code/session_018srRveGdV73aUiuqkipAic

…les lean hardest, how the surface changes (read-only)

New post-scan command 'gitgalaxy libsurface SCAN_DB [SCAN_DB_AFTER] [--lib NAME]' (gitgalaxy/tools/sensors/libsurface.py): from file_data
imports and fcall_external it discovers every external library (engine's own stdlib and system-header lists; the repository's own packages
set aside), ranks the files coupled to one library by sites per line, and shows the API names and files added or dropped between two scans.
Library definitions are three layers, later wins by name: discovery (no list), a shipped table of glob patterns for 20 C-family libraries
(library_table.py), and user TOML files (XDG config, ROOT/.gitgalaxy/libraries.toml, --libs). Globs, not regexes. Opens the databases
read-only; adds no column and changes no scan output. Wiki page 08-25.

Part of #8534.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018srRveGdV73aUiuqkipAic
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

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