Skip to content

feat: auto-detect language in init#40

Draft
joshbouncesecurity wants to merge 3 commits intoknostic:masterfrom
joshbouncesecurity:feat/issue16-13-auto-detect-lang
Draft

feat: auto-detect language in init#40
joshbouncesecurity wants to merge 3 commits intoknostic:masterfrom
joshbouncesecurity:feat/issue16-13-auto-detect-lang

Conversation

@joshbouncesecurity
Copy link
Copy Markdown
Contributor

Summary

Makes --language optional in openant init by auto-detecting the project language from file extensions in the target path. Also drops the assumption that the path is a git repository for local-only mode. New users can run openant init <path> and have it just work.

Addresses item 13 from #16 (does not close the issue).

Test plan

  • openant init <python-repo> — language detected as Python.
  • openant init <ts-repo> — language detected as TypeScript.
  • openant init <repo> --language go — explicit flag wins.
  • Path that isn't a git repo: init still proceeds.
  • Unit tests cover detection for Python/JS/TS/Go and explicit-flag override.

joshbouncesecurity and others added 3 commits May 4, 2026 21:10
- Make --language optional in `openant init` (default: auto-detect)
- Make git repository optional for local paths (use "nogit" placeholder)
- Add shared config/languages.json for file extension mappings
- Both Go (init.go) and Python (parser_adapter.py) load from the
  same config file, eliminating duplicated extension lists
- Add .worktrees/ to .gitignore for worktree-based workflow

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add unit tests for ``detect_language`` covering Python, JS/TS, Go,
skip-dir handling, and the empty-directory error path. These tests
build synthetic fixtures with ``tmp_path`` and run without the Go
toolchain, so they execute in every CI matrix configuration.

Add a ``TestInit`` class to ``test_go_cli.py`` that drives the real
binary and verifies:

- auto-detect on the Python and JS fixtures
- auto-detect on synthetic TypeScript and Go trees
- explicit ``-l`` flag overrides auto-detection
- non-git directory is initialized with a ``nogit`` placeholder SHA
- ``--commit`` on a non-git path warns and falls back to ``nogit``
- empty directory fails with a clear "no supported source files"
  message

Item 13 of #16.
Add two tmp_path tests (TS dominant over Python, Python dominant over JS)
that exercise the dominance heuristic without relying on skip_dirs to
mask competing extensions.

Mention Zig in the init -l flag help and in the Go detectLanguage
"no supported source files" error so the Go side matches the Python
detector (which already lists Zig). The .zig extension is already
present in config/languages.json.
@joshbouncesecurity
Copy link
Copy Markdown
Contributor Author

Manual verification

  • openant init <python-repo> (no -l): detected as python.
  • openant init <ts-repo>: detected as javascript (TS dispatched through the JS parser; matches existing semantics).
  • openant init <go-repo>: detected as go.
  • openant init <repo> -l python on a JS repo: explicit flag wins.
  • openant init <non-git-dir>: succeeds (no longer requires .git/); commit_sha reported as nogit.
  • openant init <non-git-dir> --commit <sha>: warning printed, nogit still used.
  • openant init <empty-dir>: clean error message listing supported languages, suggests -l/--language.
  • Mixed-language repo (more .py than .ts at root): detected as python.
  • Repo containing skip_dirs only (e.g. only node_modules/ populated): empty-dir error path.

@joshbouncesecurity
Copy link
Copy Markdown
Contributor Author

Local test results

Built the Go CLI from this branch on Windows and exercised auto-detect on the in-repo fixtures (libs/openant-core/tests/fixtures/sample_python_repo and sample_js_repo).

Commands run:

go build -o openant.exe ./
./openant.exe init <sample_python_repo>
./openant.exe init <sample_js_repo>

Outcome:

  • Python fixture: Auto-detecting language... Detected language: python
  • JS fixture: Auto-detecting language... Detected language: javascript
  • Both succeed against a non-git directory (commit reported as nogit) ✅
  • Did not separately test explicit -l override, mixed-language tie-break, empty-dir error message, or --commit warning on non-git — those are covered by the unit tests in the diff.

Help text reads:

If --language is not specified, the dominant language is auto-detected by
counting source files in the repository.

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