CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

feat(init): LLM-powered codebase analysis for AGENTS.md generation

Open punkcanyang opened this issue 5 months ago • 1 comments

Summary

Replace the template-based /init command with deep codebase analysis that generates a customized AGENTS.md tailored to the actual project.

How it works: The command gathers rich project context in Rust, then delegates content generation to the LLM agent via SendMessage — the same pattern used by /change, /relay, and /rlm.

Cost: /init is an explicit user action — users who don't need it won't incur API calls.

Changes

  • gather_project_context() — orchestrates all context gathering
  • parse_cargo_toml() — workspace members, deps, features, workspace.dependencies
  • parse_package_json() — scripts, deps, framework detection
  • gather_git_info() — remote, branch, status (with --untracked-files=no)
  • detect_ci_systems() — GitHub Actions, GitLab CI, CircleCI, Jenkins, Travis, Azure
  • detect_build_systems() — Makefile, Justfile, CMake, Meson, Bazel, scripts/
  • detect_test_frameworks() — Cargo.toml dev-deps (incl. workspace.dev-dependencies), package.json, pytest
  • build_init_prompt() — formats context for the LLM agent
  • read_existing_agents_md() — up to 100KB for in-place updates

Test plan

  • [x] 56 unit tests pass, clippy clean, fmt clean
  • [x] Rebased onto v0.8.53
  • [ ] Manual: run /init to verify agent generates comprehensive AGENTS.md

🤖 Generated with Claude Code

Greptile Summary

This PR replaces the static template-based /init command with a rich context-gathering pipeline that collects Rust/Node.js/git/CI/build-system information, then delegates AGENTS.md authoring to the LLM agent via AppAction::SendMessage — mirroring the /change and /relay pattern.

  • New context helpers: parse_cargo_toml, parse_package_json, gather_git_info (via subprocess), detect_ci_systems, detect_build_systems, detect_test_frameworks, and read_existing_agents_md (100 KB cap) all feed a structured Markdown prompt via build_init_prompt.
  • Behavioral change: /init no longer writes AGENTS.md itself; instead it produces a comprehensive prompt that the agent executes, reading source files and producing a project-tailored guide.
  • Test coverage: 56 unit tests are added covering every new helper, replacing the old template-assertion tests.

Confidence Score: 3/5

Functionally sound rewrite, but the git remote URL is included verbatim in the LLM prompt and can carry embedded HTTP credentials, leaking them to the model provider.

The context-gathering pipeline is well-structured and thoroughly tested. The main concern is in gather_git_info: git remote get-url origin returns the raw URL, including any inline userinfo (username:token), which is appended directly to the prompt sent to the LLM. Repos cloned with an embedded token — common in CI/CD pipelines — would silently exfiltrate that credential. This needs to be addressed before the change ships.

crates/tui/src/commands/init.rs — specifically the gather_git_info function and how the remote URL is handled before being included in the prompt.

Security Review

  • Credential leakage via git remote URL (gather_git_info, line 386): git remote get-url origin can return a URL with embedded HTTP credentials (user + token/password). The raw URL is inserted into the LLM prompt and transmitted to the model provider, exfiltrating any embedded secret without user awareness. The userinfo component should be stripped before embedding the URL in the prompt.

Important Files Changed

Filename Overview
crates/tui/src/commands/init.rs Complete rewrite of /init from a template-based file writer to an LLM-delegated analyzer; introduces context-gathering helpers and a prompt builder — has a credential-leakage path via git remote URL and misses framework detection in devDependencies.

Fix All in Codex Fix All in Claude Code Fix All in Cursor

Reviews (1): Last reviewed commit: "fix(init): satisfy clippy let_chains war..." | Re-trigger Greptile

Greptile also left 3 inline comments on this PR.

punkcanyang avatar Jun 04 '26 08:06 punkcanyang

Thanks @punkcanyang for taking the time to contribute.

This repository is currently observing a maintainer-managed contribution gate in dry-run mode, so this pull request is staying open. When enforcement is enabled, pull requests from contributors who are not listed in .github/APPROVED_CONTRIBUTORS will be closed automatically.

Please read CONTRIBUTING.md for the expected contribution shape. A maintainer can grant PR access by commenting /lgtm on a pull request.

github-actions[bot] avatar Jun 04 '26 08:06 github-actions[bot]

Thanks @punkcanyang. I’m closing this one as superseded by #2759, which carries your three original commits plus follow-up fixes. If the /init lane lands, we should credit your original implementation work.

Hmbown avatar Jun 05 '26 02:06 Hmbown

Follow-up: the /init lane has now landed on the v0.9 integration branch via #2771 (f483544e6).

That harvest includes your original LLM-guided AGENTS.md implementation from this PR, plus #2759’s successor fixes and a final maintainer polish pass for URL sanitizing, nested git workspaces, deterministic context ordering, and SvelteKit detection. I also added the @punkcanyang author-map aliases so the co-author credit is mappable.

Thanks @punkcanyang for the original implementation work that shaped this feature.

Hmbown avatar Jun 05 '26 03:06 Hmbown