Skip to main content
Glama

cgis_find_orphans

Find classes nothing constructs, extends, or names—dead-code candidates in production builds, ignoring test-only use and re-exports.

Instructions

Classes nothing in production builds, extends or names — dead-code candidates.

Finds classes that no test, type checker or linter flags, because each is
still imported somewhere: a package re-export keeps a class importable long
after its last real caller is gone. On one mid-sized backend this reported
43 of 1 789 classes, and the hand-written equivalent's findings were all
real and all deleted.

Two filters decide the answer. **Tests are not users** — a class built only
by its own test is exactly the shape being hunted. **A re-export is not a
use** — ``IMPORTS_SYMBOL`` does not count, or nothing is ever reported. What
counts is construction (``CALLS``), inheritance (``EXTENDS``) and being named
(``REFERENCES`` — an annotation, or a class handed to a framework); the last
keeps abstract ports and Protocols off the list.

``prefix`` narrows to one package on a dot boundary. ``include_tests`` counts
test code as a user, turning the report into "unreachable from anywhere".

Machine-generated classes are **hidden by default**, and ``include_generated``
puts them back. The query is right about them — nothing constructs a
betterproto stub — but nobody hand-deletes one either, so they are noise
rather than a finding. Measured on owner-api at b7d02fe6, five of six
reported orphans were generated entities and the sixth a nested pydantic
``Config``: the unfiltered report had no actionable row in it (#432).

Only **module-level** classes are considered by default; ``include_nested``
adds classes defined inside a class or function. Across eight measured
repositories none of the 46 nested rows was dead: most were a ``Meta`` /
``Config`` a metaclass reads, the rest live classes reached as
``self.Nested(...)``, which the resolver does not follow (#432).

Returns JSON ``{orphans, considered, test_sources, generated_excluded,
nested_excluded}``;
each orphan carries ``fqn``/``file``/``line``. **A listing is a candidate for
deletion, not a proof** — a class named only inside a decorator (#429) or
arriving through a star import is invisible here, so the sweep errs towards
reporting a live class rather than hiding a dead one. ``test_sources: 0`` in a
repository that has tests means the graph predates the ``is_test`` column:
re-ingest. ``generated_excluded`` counts every generated class left out of
the population under the same ``prefix``, referenced or not — so ``0`` on a
repository with generated code means the same for ``is_generated``, which has
no backfill: the marker is in the file header, not in the database.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
prefixNoOnly consider classes under this FQN prefix, cut on a dot boundary.
db_pathNoSQLite graph built by cgis_ingest. A relative path resolves against the MCP server's working directory, not the agent's — prefer an absolute path.graph.db
include_testsNoCount test code as a user, so the report means "unreachable from anywhere".
include_nestedNoInclude classes nested in a class or function, which are hidden by default.
include_generatedNoInclude machine-generated classes, which are hidden by default.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.21.9
    • addedInput schema / properties / include_nested
      Added value: +{
      +  "default": false,
      +  "description": "Include classes nested in a class or function, which are hidden by default.",
      +  "title": "Include Nested",
      +  "type": "boolean"
      +}
  2. Changed4 schema fields changedv0.21.1
    • addedInput schema / properties / db_path / description
      Added value: +"SQLite graph built by cgis_ingest. A relative path resolves against the MCP server's working directory, not the agent's — prefer an absolute path."
    • addedInput schema / properties / include_generated / description
      Added value: +"Include machine-generated classes, which are hidden by default."
    • addedInput schema / properties / include_tests / description
      Added value: +"Count test code as a user, so the report means \"unreachable from anywhere\"."
    • addedInput schema / properties / prefix / description
      Added value: +"Only consider classes under this FQN prefix, cut on a dot boundary."
  3. First observedv0.21.0

TDQS

A4.5/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden and delivers: it names the graph relationships that count as a use, discloses the default hiding of generated and nested classes with measured justification, and warns 'a listing is a candidate for deletion, not a proof' with the specific blind spots (decorator-only references, star imports). It even documents staleness signals such as test_sources: 0 meaning a pre-is_test graph that needs re-ingestion.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Purpose is front-loaded correctly, but the description runs several hundred words and includes anecdotal evidence ('43 of 1 789 classes', 'five of six reported orphans were generated entities') and issue citations that read as justification prose rather than invocation guidance. Much of the length is defensible behavioral disclosure, but the anecdotes could be trimmed without losing selection value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 5-parameter analysis tool with subtle semantics, the description covers the detection model, default exclusions, caveats about false negatives, and failure modes in the backing data. An output schema exists, yet the inline description of the returned JSON keys adds interpretive context (what a 0 in generated_excluded implies) that the schema alone would not convey.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3, but the prose adds real meaning beyond the schema: prefix cuts on a dot boundary to one package, include_tests redefines the report as 'unreachable from anywhere', and include_generated/include_nested are given the rationale for their defaults. Only db_path (covered adequately by the schema) is unaddressed.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The opening sentence states a specific verb and resource — 'Classes nothing in production builds, extends or names — dead-code candidates' — and the detail about CALLS/EXTENDS/REFERENCES usage makes the target precise. No sibling tool in the cgis_* family overlaps with orphan detection, so an agent can select this unambiguously.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It gives strong context on when the output is meaningful vs. noise: tests-as-users, re-exports, generated classes, and nested classes are each explained with the interpretation they enable. What it lacks is an explicit routing statement against alternatives (e.g., cgis_analyze_impact or cgis_audit_reachability), so it earns a 4 rather than a 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.