Skip to content

feat: support custom file extensions via GRAPHIFY_EXTENSION_ALIASES - #666

Open
lowrycito wants to merge 4 commits into
Graphify-Labs:v6from
lowrycito:feat/extension-aliases-env
Open

lowrycito wants to merge 4 commits into
Graphify-Labs:v6from
lowrycito:feat/extension-aliases-env

Conversation

@lowrycito

Copy link
Copy Markdown

Summary

Adds an opt-in mechanism for projects whose source files use non-standard extensions for languages graphify already supports. The motivating case is a codebase that uses .pic for files that are valid PHP — today those files are silently dropped at every stage (detection, collection, AST dispatch).

This PR introduces:

  • graphify.detect.register_extension_alias(custom, canonical) — public helper that adds the custom extension to CODE_EXTENSIONS (or DOC_EXTENSIONS) and records the mapping in a new EXTENSION_ALIASES dict. Validates that both arguments start with . and that the canonical extension is already known.
  • GRAPHIFY_EXTENSION_ALIASES env var — comma-separated custom:canonical pairs applied automatically when graphify.detect is imported. Malformed pairs and unknown canonicals are skipped silently so a bad config never crashes the pipeline.
  • _get_extractor() and collect_files() consult the alias map, so aliased files are routed to the canonical extractor and discovered during file walks. Routing the alias lookup through _get_extractor (rather than mutating a local dispatch dict in extract()) keeps a single source of truth and means both the sequential and ProcessPoolExecutor parallel paths pick up aliases consistently — a runtime call to register_extension_alias() takes effect immediately without re-running setup.

Example

# Treat .pic as PHP and .foo as Python for this run
export GRAPHIFY_EXTENSION_ALIASES=".pic:.php,.foo:.py"
/graphify .

Or programmatically:

from graphify.detect import register_extension_alias
register_extension_alias(".pic", ".php")

Why an env var

Same pattern as GRAPHIFY_WHISPER_MODEL — keeps the slash-command invocation untouched while allowing per-project configuration. Drop-in from prep scripts and CI without rewriting any of the skill flow.

Tests

Added to tests/test_detect.py:

  • Code-extension and doc-extension aliasing
  • Case normalization
  • Validation: missing leading dot, unknown canonical
  • Env-var parsing: single, multiple, malformed, empty
  • End-to-end through collect_files and extract using a tiny .pic file with PHP content

Test plan

  • pytest tests/test_detect.py -v — 40 pass (29 existing + 11 new)
  • pytest tests/ --ignore=tests/test_install.py --ignore=tests/test_transcribe.py --ignore=tests/test_claude_md.py — 454 pass; the 5 pre-existing SQL failures on v6 reproduce on a clean checkout and are unrelated to this change.
  • Manual smoke: GRAPHIFY_EXTENSION_ALIASES=".pic:.php" python -c "from graphify.detect import classify_file; from pathlib import Path; print(classify_file(Path('foo.pic')))" returns FileType.CODE

Notes

  • Backward-compatible: zero behavior change unless the env var is set or the helper is called.
  • README updated under "Excluding paths" with a short usage example.
  • EXTENSION_ALIASES is exported as a public name on graphify.detect so downstream tooling can introspect what's registered.

Some projects use non-standard file extensions for languages graphify
already supports — for example, a codebase that uses ``.pic`` for PHP
sources. Today those files are silently dropped: detect classifies them
as ``None``, collect_files won't pick them up, and the AST dispatch
in extract has no entry for the suffix.

This adds a small alias mechanism so users can teach graphify to treat
one extension as another:

  - ``register_extension_alias(custom, canonical)`` — public helper in
    graphify.detect that updates CODE_EXTENSIONS / DOC_EXTENSIONS and
    records the mapping in EXTENSION_ALIASES. Validates that both
    extensions start with a dot and that the canonical is known.

  - ``GRAPHIFY_EXTENSION_ALIASES`` env var — comma-separated
    ``custom:canonical`` pairs (e.g. ``.pic:.php,.foo:.py``) applied
    automatically at module import. Malformed pairs and unknown
    canonicals are skipped silently so a bad config never crashes the
    pipeline.

  - ``_get_extractor()`` and ``collect_files()`` consult
    EXTENSION_ALIASES so aliased files are routed to the canonical
    extractor and discovered during file walks. Routing the alias
    lookup through ``_get_extractor`` covers both the sequential and
    parallel (ProcessPoolExecutor) extraction paths.

Tests added for the registrar (validation, case normalization, code
and doc extensions), env-var parsing (single, multiple, malformed,
empty), and end-to-end flow through ``collect_files`` and ``extract``
using a tiny ``.pic`` file containing PHP.

Backward-compatible: zero behavior change unless the env var is set or
the helper is called.
@Qodo-Free-For-OSS

Copy link
Copy Markdown

Hi, Programmatic aliases registered via register_extension_alias() are stored only in the parent process, but extract() can run per-file extraction in subprocesses, where EXTENSION_ALIASES will be empty unless the env var was set. This makes aliased files silently skip extraction when parallel mode is used.

Severity: action required | Category: correctness

How to fix: Propagate aliases to workers

Agent prompt to fix - you can give this to your LLM of choice:

Issue description

register_extension_alias() mutates graphify.detect.EXTENSION_ALIASES only in the current process. When extract() runs in parallel, _extract_single_file() executes in subprocess workers that import graphify.detect fresh, so programmatic aliases are not present and aliased files can be treated as unsupported.

Issue Context

  • Parallel extraction is enabled by default and is used when len(uncached_work) >= _PARALLEL_THRESHOLD.
  • Workers will inherit environment variables, but not mutated in-memory Python module state.

Fix Focus Areas

  • graphify/extract.py[3711-3770]
  • graphify/extract.py[3817-3886]
  • graphify/detect.py[35-65]

Implementation notes

Choose one robust propagation strategy:

  1. Worker initializer: Add an initializer to ProcessPoolExecutor that applies a serialized alias map (e.g., list of (custom, canonical) pairs) by calling register_extension_alias() in each worker before processing files.
  2. Pass aliases in args: Include the alias pairs in the args tuple passed to _extract_single_file, and apply them at the start of _extract_single_file (idempotently).
  3. Env-based propagation: Before starting the process pool, merge programmatic aliases into os.environ["GRAPHIFY_EXTENSION_ALIASES"] (preserving existing pairs), so workers will pick them up on import.

Also add/adjust a test to force parallel mode (e.g., create >= _PARALLEL_THRESHOLD aliased files or set threshold lower via a test hook) and assert extraction happens for aliased extensions in parallel.

We noticed a couple of other issues in this PR as well - happy to share if helpful.


Found by Qodo code review

@lowrycito

Copy link
Copy Markdown
Author

Resolved in 8598553. _extract_parallel() now snapshots EXTENSION_ALIASES and passes the pairs to a ProcessPoolExecutor initializer, which re-registers them in every spawned worker.

I added a regression test that forces the spawn multiprocessing context, lowers the parallel threshold, and verifies both aliased PHP files are extracted in worker processes. I also covered canonical TypeScript parser selection, case-insensitive alias discovery, and canonical Python/Java cross-file handling.

Validation: 462 passed with the project SQL extra enabled (excluding the three environment-dependent tests documented in the PR submission).

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

Formal verification. 1 change(s) tested, no difference found (not proven).


Graphify review — findings

This PR adds support for user-defined custom file extension aliases, letting projects map non-standard extensions to canonical ones graphify already supports (e.g. treating .pic as .php). Aliases can be configured via the GRAPHIFY_EXTENSION_ALIASES environment variable or the new register_extension_alias() function, and the changes thread alias resolution through file classification (detect.py), file discovery (collect_files), and AST extractor dispatch (extract.py), including propagation to parallel worker processes. The surface area also includes a refactor of collect_files to iterate once over all files and filter by suffix rather than globbing per-extension, plus new README documentation and a test suite covering alias registration, case normalization, and classification behavior.

Worth a look

  • collect_files case-normalization changes collected set for uppercase suffixes — graphify/extract.py:4071 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review Execution auto-disposal is off for this run; enable it (with sandbox isolation) to have Graphify try to confirm or refute this automatically.
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 495 functions depend on the 297 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 17 callers, 10 callees
  • worse: collect_files() — 12 callers, 4 callees

Verification — 495 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 492 function(s) in the blast radius were not formally verified this run

Formal verification

Could not verify: Could not verify collect\_files.

The verifier did not have enough to check collect\_files, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `target` is annotated `Path` — outside the synthesizable primitive/collection set

No difference found (not proven): No behavior difference found in extract (not a proof).

The verifier ran both versions of extract on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

Could not verify: Could not verify extract\_js.

The verifier did not have enough to check extract\_js, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_extract\_parallel.

The verifier did not have enough to check \_extract\_parallel, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `effective_root` is annotated `Path` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_get\_extractor.

The verifier did not have enough to check \_get\_extractor, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set

· 1 grounded finding(s) anchored inline below; 1 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/extract.py Resolved

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Formal verification. 1 change(s) tested, no difference found (not proven).


Graphify review — findings

This PR adds support for user-defined custom file extension aliases, letting non-standard extensions (e.g. .pic) be treated as a known canonical extension (e.g. .php). Aliases can be registered via a new register_extension_alias() function or the GRAPHIFY_EXTENSION_ALIASES env var, which is parsed at module import in detect.py. The extract.py changes wire aliases into the extractor dispatch, file collection, and the Python/Java cross-file resolution filters via a _canonical_suffix() helper, and propagate aliases to parallel-processing workers through a pool initializer. The change also adds README documentation and new tests covering alias registration, classification, discovery, and env-var parsing.

No blocking issues surfaced. 5 lower-confidence candidates did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 495 functions depend on the 297 functions this change touches.

Health — this change adds coupling hotspots:

  • new: detect() — 22 callers, 11 callees
  • new: extract() — 17 callers, 10 callees
  • new: main() — 3 callers, 42 callees
  • new: run_pipeline() — 8 callers, 13 callees
  • new: _extract_generic() — 12 callers, 5 callees
  • new: extract_go() — 12 callers, 5 callees
  • new: extract_julia() — 12 callers, 5 callees
  • new: collect_files() — 12 callers, 4 callees
  • …and 7 more

Verification — 495 functions in the blast radius were not formally verified this run (proofs are advisory here).

Health delta baseline: last indexed commit 7281f27 (diverged from this PR's base — delta is approximate).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 492 function(s) in the blast radius were not formally verified this run

Formal verification

Could not verify: Could not verify collect\_files.

The verifier did not have enough to check collect\_files, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `target` is annotated `Path` — outside the synthesizable primitive/collection set

No difference found (not proven): No behavior difference found in extract (not a proof).

The verifier ran both versions of extract on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

Could not verify: Could not verify extract\_js.

The verifier did not have enough to check extract\_js, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_extract\_parallel.

The verifier did not have enough to check \_extract\_parallel, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `effective_root` is annotated `Path` — outside the synthesizable primitive/collection set

Could not verify: Could not verify \_get\_extractor.

The verifier did not have enough to check \_get\_extractor, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: parameter `path` is annotated `Path` — outside the synthesizable primitive/collection set

· 1 grounded finding(s) anchored inline below; 14 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/extract.py Resolved

This branch has not been deployed

No deployments
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.

2 participants