Skip to content

bug(discover): extensionless scripts with valid shebangs are silently skipped #1199

Description

@ibaldr89

Version

v0.9.0 and current main at 7d6cdb23ef5ca2fd51f5d5b7509b33e112ef15f3

Platform

Linux (x64)

Install channel

Built from source

Binary variant

standard

What happened, and what did you expect?

An extensionless executable script is silently excluded from discovery even when its first line unambiguously declares a supported language:

#!/usr/bin/env python3

def extensionless_probe():
    return 42

cbm_language_for_filename("tool") returns CBM_LANG_COUNT, and detect_file_language() returns immediately without inspecting the shebang. The file therefore produces no File or Function nodes, and graph/code searches are indistinguishable from a true negative.

Expected behavior: preserve existing special-filename and extension detection, but when they return unknown, inspect a bounded first line and infer a supported scripting language from a valid shebang.

Reproduction

  1. Create a dummy repository:
mkdir -p /tmp/cbm-shebang-repro/bin
cat >/tmp/cbm-shebang-repro/bin/tool <<'PY'
#!/usr/bin/env python3

def extensionless_probe():
    return 42
PY
chmod +x /tmp/cbm-shebang-repro/bin/tool
  1. Index it:
codebase-memory-mcp cli index_repository '{"repo_path":"/tmp/cbm-shebang-repro","mode":"full"}'
  1. Search for extensionless_probe with search_graph or search_code.

Actual: zero results; the file is absent from discovery. Expected: Python File/Function nodes and a matching search result.

The executable bit is not essential to parsing; the shebang is the language signal and should also work on platforms without POSIX mode bits.

Proposed fix

  • Keep filename/extension mappings authoritative.
  • Only when they return unknown, read at most the first line.
  • Recognize direct interpreter paths plus /usr/bin/env forms, including env -S.
  • Match interpreter basenames exactly (with version suffixes such as python3.12 where applicable).
  • Reject malformed/NUL-containing lines and read failures as unknown.
  • Add reproduce-first discovery tests for direct Python, env python3, env -S python3 -u, precedence, and negative inputs.

Related work checked

Confirmations

  • I searched existing open and closed issues/PRs and found no equivalent fix.
  • The reproduction uses a shareable dummy snippet, not proprietary code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingparsing/qualityGraph extraction bugs, false positives, missing edgespriority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.ux/behaviorDisplay bugs, docs, adoption UX

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions