Every weapon in the Hunter's arsenal
Phantom.js is not an LLM that greps your code. It's a two-agent pipeline with a vetted, read-only tool surface, sandboxed verification, and a FinOps line item on every PR. Here's what's under the hood β and why each piece exists.
Detection & Analysis
AST Zombie Detection
Whole-repo, comment-aware AST reachability β not grep.
how it works
The Hunter Agent parses every file with the TypeScript compiler API and flags functions with zero static references. Matches inside comments are ignored, so a symbol mentioned only in a comment never becomes a false positive. A per-file parse cache turns the scan O(files), not O(functions Γ files).
Vampire Dependency FinOps
Dead code and bloated deps β bundle KB β cold-start Ξ β $/mo.
how it works
estimate_finops_impact converts removed lines into a bundle-size delta, a cold-start delta (~50 KB β 1 ms), compute-seconds saved per month, and projected $/mo at a tunable price-per-GB-second. Production reconciles these against FOCUS billing exports instead of estimates.
The Haunted Call Graph
An interactive React Flow graph of your codebase.
how it works
Nodes are functions, colored by verdict (terminal green = alive, neon purple = zombie, amber = uncertain), grouped into columns so dead code visually clusters. Edges are callerβcallee. Click any node to inspect the Hunter and Skeptic Chain-of-Thought before approving a removal.
Public + Local Scanning
Paste a GitHub URL or a local path β same engine.
how it works
A RepoSource abstraction backs both: LocalDiskRepo reads the filesystem; InMemoryRepo holds a fetched GitHub tarball (gunzipped + untarred in memory β no git clone, no disk writes). Supports owner/repo, /tree/ref, and /tree/ref/subpath URLs. Tarball capped at 50 MB / 2500 files to protect the function.
Verification & Safety
Multi-Agent Skeptic Verification
A second agent tries to disprove every flag.
how it works
The Skeptic runs a veto checklist β dynamic imports, barrel re-exports, string-literal reflection, test-only usage, and computed/private-key names. Any hit forces ALIVE. Computed/private members ([Symbol.x], #x) can't be referenced by plain name, so they route to UNCERTAIN (human review) instead of being false-flagged dead. The model cannot override these checks.
Sandboxed Build Testing
No PR unless the build still compiles.
how it works
run_sandbox_check verifies that removing a set of functions leaves no reference from surviving code (a transitive safety net). Production applies the edits in an isolated sandbox (Docker/E2B) and runs tsc --noEmit + the test suite; on any compiler error the agent self-corrects and drops the offending removal from the batch.
Three-Tier Verdicts + Confidence
dead / uncertain / alive, never auto-delete the unsure.
how it works
Each suspect gets a confidence score. β₯0.7 and the Skeptic found nothing β dead. Otherwise β uncertain, which is routed to human review and never deleted automatically. Exported-but-unreferenced functions land in uncertain (they could be intended public API).
Read-Only by Construction
There is no write/exec tool. Mutation only via an approved PR.
how it works
The MCP server exposes 8 read-only tools and nothing that mutates. A prompt-injection hidden in scanned source can, at worst, produce a read-only tool call. The only write path is branch + PR, gated behind a human approval, and fully reversible (close the PR, delete the branch).
Platform & Operations
MCP Decoupling
Transport-agnostic: stdio locally, in-memory on serverless.
how it works
Reasoning lives in the agent; tool execution lives in the sandboxed server. The same createPhantomServer factory runs over stdio when launched standalone, or linked in-process via InMemoryTransport on Vercel β no subprocess on the function. Swap to Streamable HTTP for a fully network-decoupled deploy; the tool surface and agent loop are unchanged.
Continuous GitHub Haunting
A GitHub Action comments on every PR before merge.
how it works
.github/workflows/phantom-haunt.yml triggers on pull requests touching source, runs the agent against the checked-out repo, and posts a Markdown report (zombie candidates + FinOps delta) as a PR comment and the job summary. Read-only β it never pushes. Add an approval label to promote a report into an actual exorcism PR.
AI Cost Observability
Track token spend vs. cloud savings β ROI per scan.
how it works
Every scan reports the projected savings against the agent's own LLM token cost, so FinOps can see whether the agent paid for itself. Production feeds real cloud spend via a FOCUS (FinOps Open Cost & Usage Specification) MCP server and persists the trend to Supabase.
Redis AST Caching
Unchanged files skip re-parse across runs and hosts.
how it works
The in-process parse cache makes a single scan O(files). The stretch Redis layer keys parsed ASTs by file-content hash so repeated scans of a repo (or the same file across PRs) skip parsing entirely β critical for the GitHub Action, which re-scans on every PR.
The Trial β two agents, one verdict
- flags zero-reference
- candidates
- dynamic imports
- barrels, reflection
- tests, computed keys
- dead / uncertain
- alive
The Skeptic can only upgrade a candidate toward ALIVE or uncertain β never toward dead. A human approves before anything is removed, and a sandbox confirms the build still compiles.
The MCP tool surface β finite & read-only
This is the complete set of operations the agent can perform. Note what's missing: there is nowrite_file,exec, orgit tool. That's the security boundary.
list_source_filesEnumerate the scannable file setrun_ast_parserParse a file β function declarationsfind_referencesWhole-repo, comment-aware reference scanlist_exportsExported symbols + barrel re-exportsget_callsCall sites per file (call-graph edges)get_importsImport declarations (cross-file edges)run_sandbox_checkTransitive reference safety before PRestimate_finops_impactBundle / cold-start / $ projectionVerified, not assumed
From a real scan of anthropics/anthropic-sdk-typescript (src). Build and type-check pass; the local sample repo resolves the dynamic-import and barrel-re-export edge cases correctly.
Want to see it hunt?
π» Summon the Hunter