Skip to content

Conversation

@tlongwell-block
Copy link
Collaborator

@tlongwell-block tlongwell-block commented Sep 5, 2025

Adds an analyze tool to the developer MCP extension that provides code structure analysis and symbol tracking capabilities across multiple programming languages.

Changes

  • Add tree-sitter based code analysis for Python, Rust, JavaScript/TypeScript, Go, Swift, and Java
  • Support three analysis modes:
    • Structure: Quick overview of files, functions, and classes
    • Semantic: Detailed analysis including imports and call relationships
    • Focused: Track specific symbols and their call chains across files
  • Include LRU caching to improve performance for repeated analyses
  • Respect .gooseignore and .gitignore patterns for file traversal

Usage

# Analyze a file or directory structure
goose> analyze path/to/code

# Track a specific function and its relationships
goose> analyze path/to/project --focus main --follow-depth 2

# Limit directory traversal depth
goose> analyze large/project --max-depth 2

Implementation Notes

  • Modular architecture with separate modules for parsing, caching, traversal, and formatting
  • Comprehensive test coverage (44 tests)

Testing

Tested with various codebases including Python packages, Rust crates, and mixed-language projects. The tool correctly identifies code structure and tracks cross-file dependencies.

@michaelneale
Copy link
Collaborator

I think this approach has promise, have closed #3389 in favour of this one in the developer MCP which is the right place. Will want to make sure can deal with a tree compute that takes a few minutes without it timing out (so the tool can reply and run in background possibly).

@michaelneale michaelneale self-assigned this Sep 7, 2025
@tlongwell-block tlongwell-block marked this pull request as ready for review September 8, 2025 16:52
Your windows/screen tools can be used for visual debugging. You should not use these tools unless
prompted to, but you can mention they are available if they are relevant.
Always prefer ripgrep (rg -C 3) to grep.
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this best here or closer to where rg is mentioned elsewhere in the prompt (or was that system prompt?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is already in the developer extension prompt in the editor description for some reason. Not sure why there in particular, but it seems like general developer instructions might fit better here in the general developer mcp description

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh I mean in the common shell instructions. it says to use ripgrep - but it doesn't mention -C N at all, which seems to be the thing that hurts it (lacking that), but probably doesn't hurt here.

@michaelneale
Copy link
Collaborator

this seems to work nicely when I try it, a very nice addition. Any measuable improvement on benches @tlongwell-block ?

@tlongwell-block
Copy link
Collaborator Author

tlongwell-block commented Sep 9, 2025

this seems to work nicely when I try it, a very nice addition. Any measuable improvement on benches @tlongwell-block ?

Yes, a fairly consistent 3-6% boost with this change. It gets Sonnet up to our current Opus average.

michaelneale and others added 3 commits September 9, 2025 13:44
* main:
  adding Vercel MCP (#4562)
  docs: reorganizing CLI commands (#4566)
  Desktop import yaml recipes (#4544)
  feat: add auto-compact threshold configuration UI (#4178)
Resolved conflicts:
- crates/goose-mcp/Cargo.toml: Kept all dependencies from both branches (tree-sitter deps + mpatch)
- crates/goose-mcp/src/developer/rmcp_developer.rs: Kept unified diff support and analyze tool changes
Copy link
Collaborator

@michaelneale michaelneale left a comment

Choose a reason for hiding this comment

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

I think this is ok, makes goose smarter with code specifically, helps performance (I also like that it brings sonnet up with opus). Doesn't seem a huge overhead either.

but would love a tick from @jamadeo or @DOsinga to be sure before we ship it - as brings in a few libs, tree sitter etc.

@tlongwell-block
Copy link
Collaborator Author

The tool itself is feature complete. The instructions/prompt need a little tweaking around helping the llm understand the max depth parameter and how it effects analysis

@michaelneale
Copy link
Collaborator

@tlongwell-block I would think a response first/last line (probably both) saying "you will only see X, there is still Y" if possible in the response?

@tlongwell-block
Copy link
Collaborator Author

@tlongwell-block I would think a response first/last line (probably both) saying "you will only see X, there is still Y" if possible in the response?

The tool intentionally does lazy parsing of the codebase (because monorepos are a thing), so we can't really tell it how deep the call graph actually is without the agent electing to parse the entire repo to max_depth=0 (which it totally can do)

It can also surgically search for the calls in subdirectories or individual files to avoid having to parse everything. This works well, too

…0.21

- Add Swift language support with element and call queries
- Replace tree-sitter-kotlin-ng with [email protected] for 0.21 compatibility
- Fix Kotlin queries to match tree-sitter-kotlin node types
- Ensure all tree-sitter dependencies use consistent 0.21 version
- All tests passing for both Swift and Kotlin parsing
@tlongwell-block tlongwell-block merged commit 6970cd8 into main Sep 13, 2025
10 checks passed
@tlongwell-block tlongwell-block deleted the analyze_tool branch September 13, 2025 00:02
michaelneale added a commit that referenced this pull request Sep 15, 2025
* main:
  Soften str_replace instructions for weaker LLMs (#4639)
  docs: changed logo (#4633)
  Add `analyze` tool to Developer extension (#4530)
  Add recipe title in import form (#4625)
  Desktop json recipes upload (#4629)
  Catch errors in node main (#4627)
  chore(deps-dev): bump vite from 7.1.3 to 7.1.5 in /ui/desktop (#4583)
  docs: add Rube extension documentation and server configuration (#4556)
  Always show recipe activities at the top of chat when recipe accepted and active (#4616)
  Add parameter replacement to activities in ui (#4617)
  UI recipes filter invalid, duplicate and unused params (#4615)
  Fix gpt-5 input context limit (#4619)
  [docs] MCP-UI Blog Post (#4578)
  release/1.8.0 (#4577)
  fix: docker build include valid string prior to sha (#4613)
  Run the conversation fixer over messages for recipe create (#4605)
  docs: github copilot config workarounds (#4607)
  Add recipe schema validation to UI (#4602)
@alexhancock alexhancock mentioned this pull request Sep 23, 2025
HikaruEgashira pushed a commit to HikaruEgashira/goose that referenced this pull request Oct 3, 2025
Adds an analyze tool to the developer MCP extension that provides code structure analysis and symbol tracking capabilities across multiple programming languages.

Signed-off-by: HikaruEgashira <[email protected]>
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.

5 participants