Skip to content

ENH: Add a bool argument index_dependencies to the add_code_to_graph tool #53

Open
yashraj4/CodeGraphContext
#1

Description

@Shashankss1205

When this bool is set to true, start indexing all the Python packages in the import tool. All imports are already traced while parsing each file.
When set to False, perform the same operations as being done now

Activity

  1. yashraj4 commented on Oct 3, 2025

    @yashraj4

    Hi @Shashankss1205 👋,
    I’d like to work on this issue. I will also add/update tests to validate both modes.
    Could you please assign this issue to me so I can start working on it?

  2. Shashankss1205 commented on Oct 3, 2025

    @Shashankss1205
    CollaboratorAuthor

    I want to know both of yours course of action before assigning. This is asked because I was having trouble back when I was starting to implement this. @yashraj4 @Dwid4r

  3. yashraj4 commented on Oct 5, 2025

    @yashraj4

    I will modify the add_code_to_graph tool in two main places within src/codegraphcontext/server.py:

    1. Tool Schema: Update the _init_tools method to let the AI know about the new index_dependencies argument.

    2. Tool Implementation: Update the add_code_to_graph_tool method to add the new logic for finding and indexing dependencies.

  4. eshaanag commented on Jun 3, 2026

    @eshaanag
    Contributor

    I would like to work on this as part of GSSoC 2026 if it is still open for assignment.

    I read through the issue and the earlier maintainer comment asking for a concrete course of action before assigning. I also checked the current code paths:

    • src/codegraphcontext/tool_definitions.py already exposes add_code_to_graph, but only with path and is_dependency.
    • src/codegraphcontext/tools/handlers/indexing_handlers.py has the add_code_to_graph handler and a separate add_package_to_graph flow.
    • src/codegraphcontext/tools/package_resolver.py already has language-specific package lookup helpers, including Python via importlib.util.find_spec.

    My approach would be to keep this scoped to Python first, since the issue specifically mentions Python packages and the resolver support is already present:

    1. Add a new optional index_dependencies: false flag to the add_code_to_graph tool schema, without changing the current default behavior.
    2. During/after the main project indexing job, collect imported Python package names from the parser output and filter out local modules plus stdlib modules.
    3. Resolve remaining top-level packages with the existing package resolver instead of inventing a second discovery path.
    4. Queue those resolved packages as dependency indexing jobs with is_dependency=True, while skipping packages already indexed.
    5. Add tests for both modes: default behavior should not index dependencies, and index_dependencies=True should attempt to resolve/index external imports only.

    The main thing I want to be careful about is avoiding runaway indexing from large virtualenv/site-packages trees, so I would add limits/duplicate checks rather than blindly walking every imported package.

    Please assign this to me if this direction looks reasonable.

  5. Shashankss1205 commented on Aug 2, 2026

    @Shashankss1205
    CollaboratorAuthor

    Cross-reference from #62 (closed into this one): the reported symptom is that a resolved call produces no edge because the callee's package was never added to the graph — use_random → randint resolves in the logs but no CALLS edge is created.

    Two things worth deciding as part of the design here:

    1. stdlib vs third-party may need different handling. ENH: Packages and their methods are not present as nodes #62's example is random, but package_resolver._is_stdlib_module exists specifically to classify and exclude stdlib. "Index all imported packages" probably shouldn't pull in all of CPython's standard library by default — worth an explicit sub-flag or policy.

    2. bug(indexer): add_package_to_graph on a flat module (six, typing_extensions) resolves to the entire site-packages directory and indexes the whole environment #1528 should be fixed first. add_package_to_graph on a flat single-module package (six, typing_extensions) currently resolves to the whole site-packages directory. Turning on automatic dependency indexing on top of that bug would index the entire virtualenv.

  6. moved this from Backlog tasks to In progress in CGC Progress Boardon Sep 6, 2026
  7. Shashankss1205 commented on Oct 15, 2026

    @Shashankss1205
    CollaboratorAuthor

    Maintenance review — 15 October 2026

    Dependency indexing appears in draft #1733 alongside role prompts. Keep it opt-in and scoped separately: test enabled/disabled behavior, dependency cycles, sandbox boundaries and unavailable packages before closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelp wantedExtra attention is needed

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions