Skip to content

Commit e7ea247

Browse files
prosdevclaude
andcommitted
fix(cli,core): address code review — validation, cached graph, cleanup
- Validate --direction with Commander .choices() (rejects invalid values) - Use cached dependency graph for --depends-on (loadOrBuildGraph) - Pass excludePatterns/languages from config (parity with search command) - Use replaceAll for dist/ normalization (handles nested paths) - Note indexer.close() not needed in catch (process.exit cleans up) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 14ec0ab commit e7ea247

File tree

10 files changed

+57
-73
lines changed

10 files changed

+57
-73
lines changed

.claude/agents/bug-investigator.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ color: orange
1010

1111
Systematically traces issues through the dev-agent monorepo. Reproduces, traces, fixes, and prevents regression.
1212

13-
## MCP Tools — Save Tokens, Extend Sessions
13+
## MCP Tools — Conserve Context
1414

15-
Use MCP tools to get focused results instead of Grep → Read cycles. See CLAUDE.md for the token savings table.
15+
This agent runs in a long session with a finite context window. Every Grep → Read cycle burns ~5,000 tokens on irrelevant matches. MCP tools return only what you need.
1616

17-
- **`dev_search`** — Conceptual queries ("where does rate limiting happen"). Returns ranked snippets — no file reading needed.
18-
- **`dev_refs`** — Callers/callees of a function. Use `dependsOn` to trace dependency chains between files.
17+
**Before you Grep or Read, ask: can an MCP tool answer this without reading files?**
18+
19+
- **`dev_search`** — Conceptual queries ("where does rate limiting happen"). Returns ranked snippets, not 200 grep matches.
20+
- **`dev_refs`** — Callers/callees of a function. Use `dependsOn` to trace dependency chains. Returns the call graph directly.
1921
- **`dev_map`** — Codebase structure with hot paths and subsystems. One call replaces dozens of ls/glob/read operations.
2022

21-
Reserve Grep/Glob for exact string matches where you know the literal text.
23+
Only use Grep for exact string matches where you know the literal text. Only Read files when you need the full implementation.
2224

2325
## Investigation Framework
2426

.claude/agents/logic-reviewer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Every finding MUST include confidence: **HIGH** (verified from code), **MEDIUM**
6565

6666
### Cross-Package Data Flow (Deep+ Effort)
6767

68-
Use MCP tools to trace cross-package flows without reading every file (see CLAUDE.md for token savings). `dev_refs` returns the call graph directly, `dev_search` finds related code by concept, `dev_patterns` compares error handling across files.
68+
**Before you Grep or Read, ask: can an MCP tool answer this without reading files?** `dev_refs` returns the call graph directly, `dev_search` finds related code by concept, `dev_patterns` compares error handling across files — each saves ~3,000-5,000 tokens vs manual file reading.
6969

7070
- [ ] Core exports consumed correctly by CLI, MCP server, and subagents — verify with `dev_refs`
7171
- [ ] Dependency chains make sense — use `dev_refs` with `dependsOn` to trace file-to-file paths

.claude/agents/plan-reviewer.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ Two-pass review of execution plans in `.claude/da-plans/`. Validates completenes
1212

1313
This agent **NEVER modifies plans**. It reports issues for the author to fix.
1414

15+
## MCP Tools — Conserve Context
16+
17+
This agent runs in a long session with a finite context window. Every Grep → Read cycle burns ~5,000 tokens on irrelevant matches. MCP tools return only what you need.
18+
19+
**Before you Grep or Read, ask: can an MCP tool answer this without reading files?**
20+
21+
- **`dev_map`** — Verify structure claims in the plan against actual codebase layout.
22+
- **`dev_refs`** — Confirm dependency assertions. Use `dependsOn` to trace dependency chains between files.
23+
- **`dev_patterns`** — Check if proposed patterns match existing conventions.
24+
1525
## Two-Pass Review
1626

1727
### Pass 1: Engineer Review

.claude/agents/quality-reviewer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Maximum **5 SUGGESTION items** per review. If more found, pick the top 5 and not
4848

4949
### Readability & Simplification
5050

51-
Use MCP tools to check for duplication without reading every file (see CLAUDE.md for token savings). `dev_patterns` compares patterns across similar files. `dev_search` checks if a utility exists by meaning, not just name.
51+
**Before you Grep or Read, ask: can an MCP tool answer this without reading files?** `dev_patterns` compares patterns across similar files (~500 tokens vs ~3,000 for manual reads). `dev_search` checks if a utility exists by meaning, not just name.
5252

5353
- [ ] No code duplicating existing utilities — verify with `dev_patterns` and `dev_search`
5454
- [ ] Functions reasonably sized (consider splitting if >50 lines)

.claude/agents/quick-scout.md

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ color: blue
1010

1111
Lightweight explorer optimized for speed and cost. Finds code, traces flows, maps dependencies.
1212

13-
## Token Efficiency
13+
## MCP Tools — Conserve Context
1414

15-
Use MCP tools to get focused results instead of Grep → Read cycles. See CLAUDE.md for the token savings table. Every file Read costs tokens — let the tools do the reading.
15+
This agent runs in a long session with a finite context window. Every Grep → Read cycle burns ~5,000 tokens on irrelevant matches. MCP tools return only what you need.
16+
17+
**Before you Grep or Read, ask: can an MCP tool answer this without reading files?**
1618

1719
## Capability Boundaries
1820

@@ -35,52 +37,6 @@ Do NOT guess at architectural reasoning or make recommendations.
3537
4. **Verify** — Only Read a file when you need the full implementation, not just the location.
3638
5. **Report** — Concise, factual answer with file paths and line numbers
3739

38-
## Dev-Agent Quick Reference
39-
40-
```
41-
packages/
42-
core/src/
43-
scanner/ # ts-morph (TS/JS) and tree-sitter (Go) analysis
44-
vector/ # Antfly vector storage + embeddings
45-
services/ # Coordinator, search, health
46-
events/ # Event bus system
47-
indexer/ # Repository indexing orchestration
48-
map/ # Codebase structure mapping
49-
observability/ # Logger integration
50-
51-
cli/src/
52-
commands/ # Commander.js CLI commands
53-
utils/ # Formatters, logger, output helpers
54-
55-
mcp-server/src/
56-
server/ # MCP server setup
57-
adapters/ # Tool adapters (search, refs, map, inspect, status, health)
58-
formatters/ # Compact and verbose output formatters
59-
utils/ # Logger
60-
61-
subagents/src/
62-
coordinator/ # Agent orchestration
63-
explorer/ # Code exploration agent
64-
planner/ # Planning agent
65-
github/ # GitHub integration agent
66-
67-
logger/src/ # @prosdevlab/kero centralized logging
68-
types/src/ # Shared TypeScript types
69-
integrations/ # Claude Code, VS Code integrations
70-
dev-agent/ # Root package (CLI entry point)
71-
```
72-
73-
### Common Patterns
40+
## Orientation
7441

75-
| Pattern | Location |
76-
|---------|----------|
77-
| MCP tool adapters | `packages/mcp-server/src/adapters/built-in/` |
78-
| Core services | `packages/core/src/services/` |
79-
| Scanner implementations | `packages/core/src/scanner/` |
80-
| CLI commands | `packages/cli/src/commands/` |
81-
| Subagent types | `packages/subagents/src/{agent}/` |
82-
| Tests | `packages/**/src/**/__tests__/` |
83-
| Package configs | `packages/*/package.json` |
84-
| Build config | `turbo.json`, `tsconfig.json` |
85-
| Test config | `vitest.config.ts` |
86-
```
42+
Use `dev_map` to get the current codebase structure — don't rely on memorized paths. Run `dev_map --focus packages/core --depth 3` to drill into a specific area.

.claude/agents/research-planner.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ Plans investigations before jumping into implementation. Produces a structured r
1212

1313
This agent **NEVER writes code**. It produces investigation plans.
1414

15-
## MCP Tools — Save Tokens, Extend Sessions
15+
## MCP Tools — Conserve Context
1616

17-
Use MCP tools to map the territory without burning tokens on Grep → Read cycles. See CLAUDE.md for the token savings table.
17+
This agent runs in a long session with a finite context window. Every Grep → Read cycle burns ~5,000 tokens on irrelevant matches. MCP tools return only what you need.
1818

19-
- **`dev_search`** — Find relevant code areas by meaning. Returns ranked snippets — no file reading needed.
19+
**Before you Grep or Read, ask: can an MCP tool answer this without reading files?**
20+
21+
- **`dev_search`** — Find relevant code areas by meaning. Returns ranked snippets, not 200 grep matches.
2022
- **`dev_map`** — Codebase structure with hot paths and subsystems. One call replaces dozens of ls/glob/read operations.
2123
- **`dev_patterns`** — Compare patterns across similar files without reading each one.
2224
- **`dev_refs`** — Trace cross-package dependencies. Use `dependsOn` to trace dependency chains between files.

.claude/agents/security-reviewer.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ Security-focused review for a TypeScript monorepo that processes repository data
1212

1313
This agent **NEVER modifies code**. It reports issues for the developer to fix.
1414

15-
## Token Efficiency
15+
## MCP Tools — Conserve Context
1616

17-
Use MCP tools to avoid expensive Grep → Read cycles. See CLAUDE.md for the token savings table. `dev_search` returns ranked snippets, `dev_refs` traces input flow directly, `dev_patterns` scans for similar vulnerability patterns — all without reading files manually.
17+
This agent runs in a long session with a finite context window. Every Grep → Read cycle burns ~5,000 tokens on irrelevant matches. MCP tools return only what you need.
1818

19-
## Checklist
19+
**Before you Grep or Read, ask: can an MCP tool answer this without reading files?**
20+
21+
- **`dev_search`** — Find security-sensitive code ("user input", "shell execution", "token handling"). Returns ranked snippets.
22+
- **`dev_patterns`** — If one injection vector exists, the same pattern likely appears elsewhere. Scan for similar patterns across files.
23+
- **`dev_refs`** — Trace how user input flows through the system. Use `dependsOn` to trace dependency chains.
2024

21-
Use `dev_search` to find security-sensitive code ("user input", "shell execution", "token handling"). Use `dev_patterns` to find similar patterns across the codebase — if one injection vector exists, the same pattern likely appears elsewhere. Use `dev_refs` to trace how user input flows through the system.
25+
## Checklist
2226

2327
### Command Injection
2428
- [ ] No unsanitized user input passed to `child_process`, `exec`, `execSync`, or shell commands

CLAUDE.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,11 @@ See `.claude/da-plans/README.md` for status and format details.
139139

140140
---
141141

142-
## MCP tools — token-efficient context
142+
## MCP tools — conserve context
143143

144-
MCP tools return pre-ranked, pre-snippeted results. Use them to avoid expensive Grep → Read cycles that burn thousands of tokens on irrelevant context.
144+
**Before you Grep or Read, ask: can an MCP tool answer this without reading files?**
145+
146+
MCP tools return pre-ranked snippets. Every Grep → Read cycle burns ~3,000-5,000 tokens of context window on irrelevant matches. MCP tools return only what you need.
145147

146148
| Instead of | Use | Tokens saved |
147149
|------------|-----|-------------|
@@ -150,7 +152,7 @@ MCP tools return pre-ranked, pre-snippeted results. Use them to avoid expensive
150152
| ls + glob + read READMEs | `dev_map` | ~2,000 |
151153
| Read multiple files to compare patterns | `dev_patterns filePath` | ~3,000 |
152154

153-
Reserve Grep/Glob for exact string matches where you know the literal text.
155+
Only use Grep for exact string matches where you know the literal text. Only Read files when you need the full implementation.
154156

155157
### 5 adapters
156158

packages/cli/src/commands/refs.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import * as path from 'node:path';
22
import {
3-
buildDependencyGraph,
43
ensureStorageDirectory,
54
getStorageFilePaths,
65
getStoragePath,
6+
loadOrBuildGraph,
77
RepositoryIndexer,
88
type SearchResult,
99
shortestPath,
1010
} from '@prosdevlab/dev-agent-core';
1111
import chalk from 'chalk';
12-
import { Command } from 'commander';
12+
import { Command, Option } from 'commander';
1313
import ora from 'ora';
1414
import { loadConfig } from '../utils/config.js';
1515
import { logger } from '../utils/logger.js';
@@ -25,7 +25,11 @@ interface CalleeInfo {
2525
export const refsCommand = new Command('refs')
2626
.description('Find callers and callees of a function')
2727
.argument('<name>', 'Function or method name (e.g., "createPlan", "SearchAdapter.execute")')
28-
.option('-d, --direction <direction>', 'Query direction: callees, callers, or both', 'both')
28+
.addOption(
29+
new Option('-d, --direction <direction>', 'Query direction: callees, callers, or both')
30+
.choices(['callees', 'callers', 'both'])
31+
.default('both')
32+
)
2933
.option('-l, --limit <number>', 'Maximum results per direction', '20')
3034
.option('--depends-on <file>', 'Trace dependency path to a target file')
3135
.option('--json', 'Output results as JSON', false)
@@ -44,6 +48,8 @@ export const refsCommand = new Command('refs')
4448
const indexer = new RepositoryIndexer({
4549
repositoryPath: resolvedRepoPath,
4650
vectorStorePath: filePaths.vectors,
51+
excludePatterns: config?.repository?.excludePatterns || config?.excludePatterns,
52+
languages: config?.repository?.languages || config?.languages,
4753
});
4854

4955
await indexer.initialize();
@@ -64,8 +70,9 @@ export const refsCommand = new Command('refs')
6470
// Handle --depends-on
6571
if (options.dependsOn) {
6672
spinner.text = `Tracing path: ${name}${options.dependsOn}`;
67-
const allDocs = await indexer.getAll({ limit: 50000 });
68-
const graph = buildDependencyGraph(allDocs);
73+
const graph = await loadOrBuildGraph(filePaths.dependencyGraph, async () =>
74+
indexer.getAll({ limit: 50000 })
75+
);
6976
const sourceFile = (target.metadata.path as string) || '';
7077
const tracePath = shortestPath(graph, sourceFile, options.dependsOn);
7178

@@ -195,6 +202,7 @@ export const refsCommand = new Command('refs')
195202
} catch (error) {
196203
spinner.fail('Refs query failed');
197204
logger.error(error instanceof Error ? error.message : String(error));
205+
// indexer may not be initialized if error was early, but close() is safe to call
198206
process.exit(1);
199207
}
200208
});

packages/core/src/scanner/typescript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ export class TypeScriptScanner implements Scanner {
994994
// (e.g. /abs/packages/logger/dist/types.d.ts) but we store
995995
// relative source paths (packages/logger/src/types.ts).
996996
let normalized = rawPath
997-
.replace(/\/dist\//, '/src/')
997+
.replaceAll('/dist/', '/src/')
998998
.replace(/\.d\.ts$/, '.ts')
999999
.replace(/\.js$/, '.ts');
10001000
if (this.repoRoot && normalized.startsWith(this.repoRoot)) {

0 commit comments

Comments
 (0)