@abdulmunimjemal/codescope 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -93,6 +93,20 @@ interface Neighborhood {
93
93
  /** Names referenced in the graph that have no definition in the index. */
94
94
  unresolved: string[];
95
95
  }
96
+ /** A symbol in a blast-radius result, with its hop distance from the root. */
97
+ type ImpactRow = SymbolRow & {
98
+ distance: number;
99
+ };
100
+ /** A token-budgeted task-context map: seed matches + ranked neighbours + edges. */
101
+ interface ContextBundle {
102
+ query: string;
103
+ seeds: SymbolRow[];
104
+ related: SymbolRow[];
105
+ edges: Array<{
106
+ from: string;
107
+ to: string;
108
+ }>;
109
+ }
96
110
  interface IndexStats {
97
111
  files: number;
98
112
  symbols: number;
@@ -149,15 +163,50 @@ declare class GraphStore {
149
163
  getSymbol(name: string, opts?: {
150
164
  limit?: number;
151
165
  }): SymbolRow[];
152
- /** Symbols that call a given name (both bare `foo()` and `x.foo()`). */
166
+ /**
167
+ * Distinct callers of a name (both bare `foo()` and `x.foo()`). Multiple call
168
+ * sites from the same caller in the same file collapse to one row — fewer
169
+ * tokens and a more useful "who depends on this" answer.
170
+ */
153
171
  findCallers(name: string, opts?: {
154
172
  limit?: number;
155
173
  }): RefRow[];
174
+ /** The definitions that a symbol calls, resolved kind-aware to project symbols. */
175
+ findCallees(name: string, opts?: {
176
+ limit?: number;
177
+ }): SymbolRow[];
178
+ /** How many call sites reference this name (popularity / centrality signal). */
179
+ callerCount(name: string): number;
180
+ /**
181
+ * The blast radius of changing a symbol: its transitive callers, breadth-first,
182
+ * annotated with hop distance and ordered nearest-first. Answers "what could
183
+ * break if I change this?" without reading the codebase.
184
+ */
185
+ impact(name: string, opts?: {
186
+ depth?: number;
187
+ limit?: number;
188
+ }): ImpactRow[];
189
+ /**
190
+ * A token-budgeted relevance map for a task: the symbols matching `query` plus
191
+ * their immediate call neighbourhood, ranked by call-site centrality, capped at
192
+ * `maxSymbols`. This is the slice of the codebase an agent needs to start a
193
+ * change — delivered as graph facts, not file dumps.
194
+ */
195
+ context(query: string, opts?: {
196
+ maxSymbols?: number;
197
+ }): ContextBundle;
156
198
  /** All references (calls + imports) to a name. */
157
199
  findReferences(name: string, opts?: {
158
200
  kind?: "call" | "method" | "import";
159
201
  limit?: number;
160
202
  }): RefRow[];
203
+ /**
204
+ * Files whose imports reference a module basename (e.g. `store` for
205
+ * `src/store.ts`). Matches `import … from "./store"`, `"../src/store.js"`,
206
+ * etc. Used by affected-test analysis to follow import edges, which — unlike
207
+ * call edges — reliably reach test files (tests import the module under test).
208
+ */
209
+ findImporters(moduleBasename: string): string[];
161
210
  /** The symbols defined in a file, in source order. */
162
211
  fileOutline(path: string): SymbolRow[];
163
212
  /** Distinct (callee, callKind) pairs invoked from inside symbols named `from`. */
@@ -256,11 +305,15 @@ declare function parseSource(langId: string, source: string): Promise<ParseResul
256
305
  * "member access" node — so definitions, calls, and imports are all described
257
306
  * declaratively here and interpreted by a single generic walker.
258
307
  */
259
- type NameStrategy = "field" | "c_declarator";
308
+ type NameStrategy = "field" | "c_declarator" | "first_typed";
260
309
  interface DefRule {
261
310
  kind: SymbolKind;
262
- /** How to read the definition's name (default: the `name` field). */
311
+ /** How to read the definition's name (default: `field` on `name`). */
263
312
  name?: NameStrategy;
313
+ /** For the `field` strategy: which field holds the name (default `name`). */
314
+ nameField?: string;
315
+ /** For the `first_typed` strategy: pick the first named child of these types. */
316
+ nameTypes?: string[];
264
317
  }
265
318
  interface CallRule {
266
319
  /** AST node type for this kind of call. */
@@ -318,20 +371,72 @@ declare function createServer(store: GraphStore): McpServer;
318
371
  /** Connect a codescope server to stdio (the transport coding agents speak). */
319
372
  declare function runStdioServer(store: GraphStore): Promise<void>;
320
373
 
374
+ /** Whether a repo-relative path looks like a test file. */
375
+ declare function isTestFile(path: string): boolean;
376
+ interface AffectedResult {
377
+ changed: string[];
378
+ /** Every file that defines a symbol transitively affected by the changes. */
379
+ impactedFiles: string[];
380
+ /** The impacted files that look like tests — the suite worth re-running. */
381
+ tests: string[];
382
+ }
383
+ declare function affected(store: GraphStore, changedPaths: string[], opts?: {
384
+ depth?: number;
385
+ }): AffectedResult;
386
+
387
+ /** Agents whose config is plain JSON with an `mcpServers` map (auto-wirable). */
388
+ type AgentId = "claude" | "cursor";
389
+ declare const SUPPORTED_AGENTS: readonly AgentId[];
390
+ interface ServerEntry {
391
+ command: string;
392
+ args: string[];
393
+ }
394
+ /** The MCP server entry agents need to launch codescope over stdio. */
395
+ declare function serverEntry(serveTarget?: string): ServerEntry;
396
+ /** The config file codescope writes for a given agent. */
397
+ declare function configPath(agent: AgentId, root: string, global?: boolean): string;
398
+ interface InstallOutcome {
399
+ agent: AgentId;
400
+ path: string;
401
+ action: "added" | "updated";
402
+ }
403
+ /**
404
+ * Idempotently wire codescope into an agent's MCP config. Preserves any other
405
+ * servers already configured and overwrites only the `codescope` entry.
406
+ */
407
+ declare function installInto(agent: AgentId, root: string, opts?: {
408
+ global?: boolean;
409
+ serveTarget?: string;
410
+ }): InstallOutcome;
411
+ /** Wire codescope into one or more agents. */
412
+ declare function install(root: string, opts?: {
413
+ agents?: AgentId[];
414
+ global?: boolean;
415
+ serveTarget?: string;
416
+ }): InstallOutcome[];
417
+ /** Copy-paste config for agents whose config isn't plain JSON (e.g. Codex, TOML). */
418
+ declare function codexSnippet(serveTarget?: string): string;
419
+
321
420
  declare function formatSymbols(rows: SymbolRow[]): string;
322
421
  declare function formatRefs(rows: RefRow[]): string;
323
422
  declare function formatNeighborhood(n: Neighborhood): string;
423
+ declare function formatImpact(rows: ImpactRow[]): string;
424
+ declare function formatContext(b: ContextBundle): string;
425
+ declare function formatAffected(r: AffectedResult): string;
324
426
  declare function formatStats(s: IndexStats): string;
325
427
 
428
+ declare const format_formatAffected: typeof formatAffected;
429
+ declare const format_formatContext: typeof formatContext;
430
+ declare const format_formatImpact: typeof formatImpact;
326
431
  declare const format_formatNeighborhood: typeof formatNeighborhood;
327
432
  declare const format_formatRefs: typeof formatRefs;
328
433
  declare const format_formatStats: typeof formatStats;
329
434
  declare const format_formatSymbols: typeof formatSymbols;
330
435
  declare namespace format {
331
- export { format_formatNeighborhood as formatNeighborhood, format_formatRefs as formatRefs, format_formatStats as formatStats, format_formatSymbols as formatSymbols };
436
+ export { format_formatAffected as formatAffected, format_formatContext as formatContext, format_formatImpact as formatImpact, format_formatNeighborhood as formatNeighborhood, format_formatRefs as formatRefs, format_formatStats as formatStats, format_formatSymbols as formatSymbols };
332
437
  }
333
438
 
334
439
  /** The codescope version. Kept in sync with package.json at release time. */
335
- declare const VERSION = "0.1.0";
440
+ declare const VERSION = "0.3.0";
336
441
 
337
- export { type FileIndexOutcome, type FileMeta, GraphStore, type IndexOptions, type IndexRunResult, type IndexStats, Indexer, LANGUAGES, type LanguageConfig, type Neighborhood, type ParseResult, type ParsedRef, type ParsedSymbol, type RefKind, type RefRow, SUPPORTED_EXTENSIONS, type SymbolKind, type SymbolRow, VERSION, type WatchEvents, type WatchHandle, type WatchOptions, createServer, format, languageForPath, parseSource, runStdioServer, watch };
442
+ export { type AffectedResult, type AgentId, type ContextBundle, type FileIndexOutcome, type FileMeta, GraphStore, type ImpactRow, type IndexOptions, type IndexRunResult, type IndexStats, Indexer, type InstallOutcome, LANGUAGES, type LanguageConfig, type Neighborhood, type ParseResult, type ParsedRef, type ParsedSymbol, type RefKind, type RefRow, SUPPORTED_AGENTS, SUPPORTED_EXTENSIONS, type SymbolKind, type SymbolRow, VERSION, type WatchEvents, type WatchHandle, type WatchOptions, affected, codexSnippet, configPath, createServer, format, install, installInto, isTestFile, languageForPath, parseSource, runStdioServer, serverEntry, watch };