Skip to content

Add Bash script support#1217

Open
Omar-Elwazeery wants to merge 1 commit into
colbymchenry:mainfrom
Omar-Elwazeery:feat/bash-script-support
Open

Add Bash script support#1217
Omar-Elwazeery wants to merge 1 commit into
colbymchenry:mainfrom
Omar-Elwazeery:feat/bash-script-support

Conversation

@Omar-Elwazeery

Copy link
Copy Markdown

Summary

Fixes #1203.

  • Register Bash/shell as a supported Tree-sitter language using the existing WASM grammar pipeline.
  • Add Bash detection for .sh, .bash, .bats, and extensionless scripts with Bash/POSIX shell shebangs.
  • Add a Bash extractor for shell functions, assignments, exported/readonly variables, command calls, and static source/script imports.
  • Include extensionless Bash shebang scripts in scan/sync flows and add Bash import resolution for shell/Bats files.
  • Add regression coverage for detection, extraction, scanning, sync, and .bats import resolution.

Testing

  • npm test -- __tests__/extraction.test.ts __tests__/resolution.test.ts __tests__/sync.test.ts -t Bash
  • npm run build
  • ⚠️ npm test currently times out in the full-suite parallel run at __tests__/mcp-daemon.test.ts > proxy survives the daemon dying mid-session and keeps serving (#662). I confirmed the same full-suite timeout occurs on a clean base after stashing this branch, and the exact test passes when run isolated both before and after this change.

@Adam0120

Copy link
Copy Markdown

I tested this PR against a deployment repository with 101 Bash scripts and found a reproducible grammar ABI failure on common case ... esac statements (resolved is not a function), plus two accuracy issues around shell path semantics and canonical script-directory variables.

I opened a focused patch against the author's branch: Omar-Elwazeery#1

The patch vendors the official ABI-15 tree-sitter-bash 0.25.1 WASM with its MIT notice, keeps Bash imports exact-path, conservatively folds only a root-level deterministic script-directory idiom, and adds regressions. On a main-based integration branch it indexed all 101/101 .sh files and recovered the real cross-file source/call chains. Build and Bash-focused tests pass on the PR branch; full extraction + sync suites pass 615/615 on the main-based integration branch.

@Omar-Elwazeery Omar-Elwazeery force-pushed the feat/bash-script-support branch from 1745053 to c8a48a2 Compare July 11, 2026 18:29
@Omar-Elwazeery

Copy link
Copy Markdown
Author

Rebased onto the latest main and force-pushed (c8a48a2). Bash support is still verified with targeted Bash tests and a successful build. The PR is mergeable; the only remaining blocker is review approval.

@colbymchenry colbymchenry left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

CodeGraph review

@Omar-Elwazeery — 1 finding on this change.

Overall risk: 🟠 Medium

This change adds Bash language support, including shebang detection, grammar loading, and a new extractor. The most important risk is that extensionless files are unconditionally classified as Bash for grammar loading, which could cause parsing failures for non‑Bash files.

Findings

Severity Finding Where
🟠 Medium Overbroad language detection for extensionless files src/extraction/index.ts:150 — see inline comment

Worth double-checking

  • detectLanguageForGrammarLoad — Verify that treating any extensionless file as Bash (line 150) does not cause incorrect grammar loading for non‑Bash files.
  • collectIncludedFiles — Note that collectIncludedFiles has no test coverage; consider adding tests to ensure it correctly filters files, especially with the new Bash shebang logic.

Business rules (2 honored · 2 not applicable)

No rules violated or at risk.

QA checklist — 3 things to verify in the running product
  • cli — Run codegraph sync on a repository containing a Bash script with a proper shebang and confirm the script is indexed and appears in the language list. (Ensures the new Bash extraction and shebang detection work end‑to‑end.)
  • cli — Run codegraph sync on a repository without any Bash scripts and verify the sync completes without errors. (Confirms that the added Bash support does not break existing sync behavior for other languages.)
  • api — Query getSupportedLanguages() after sync and check that 'bash' is listed. (Validates that the language registry correctly includes Bash.)
Blast radius: 53 files affected beyond the diff · 161 symbols · 42 test files selected

Tests to run:

  • __tests__/adaptive-explore-sizing.test.ts
  • __tests__/android-res-exclusion.test.ts
  • __tests__/concurrent-locking.test.ts
  • __tests__/config-secret-redaction.test.ts
  • __tests__/context-ranking.test.ts
  • __tests__/context.test.ts
  • __tests__/db-reopen-on-replace.test.ts
  • __tests__/dynamic-boundaries.test.ts
  • __tests__/exclude-config.test.ts
  • __tests__/explore-blast-radius.test.ts
  • __tests__/explore-corroboration-ranking.test.ts
  • __tests__/explore-nl-stopword-collision.test.ts
  • __tests__/explore-output-budget.test.ts
  • __tests__/explore-result-count.test.ts
  • __tests__/explore-synth-constant-endpoints.test.ts
  • __tests__/extension-mapping.test.ts
  • __tests__/extraction.test.ts
  • __tests__/frameworks.test.ts
  • __tests__/frontload-hook.test.ts
  • __tests__/grammar-wasm-bytes.test.ts

Comment thread src/extraction/index.ts
function detectLanguageForGrammarLoad(filePath: string, overrides?: Record<string, Language>): Language {
const lang = detectLanguage(filePath, undefined, overrides);
return lang === 'unknown' && isPotentialBashShebangPath(filePath) ? 'bash' : lang;
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

🟠 Medium — Overbroad language detection for extensionless files

detectLanguageForGrammarLoad treats any extensionless file as Bash, potentially loading the Bash grammar for non‑Bash files and causing parse errors (src/extraction/index.ts line 150).

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.

Feature Request: Bash Script Support for Code Graph Analysis

3 participants