@nanonets/graft 0.5.0 → 0.6.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.
Files changed (105) hide show
  1. package/README.md +11 -9
  2. package/dist/ai/crux.d.ts +20 -4
  3. package/dist/ai/crux.d.ts.map +1 -1
  4. package/dist/ai/crux.js +39 -41
  5. package/dist/ai/crux.js.map +1 -1
  6. package/dist/ai/llm/anthropic.d.ts +37 -0
  7. package/dist/ai/llm/anthropic.d.ts.map +1 -0
  8. package/dist/ai/llm/anthropic.js +141 -0
  9. package/dist/ai/llm/anthropic.js.map +1 -0
  10. package/dist/ai/llm/factory.d.ts +19 -0
  11. package/dist/ai/llm/factory.d.ts.map +1 -0
  12. package/dist/ai/llm/factory.js +20 -0
  13. package/dist/ai/llm/factory.js.map +1 -0
  14. package/dist/ai/llm/openai.d.ts +33 -0
  15. package/dist/ai/llm/openai.d.ts.map +1 -0
  16. package/dist/ai/llm/openai.js +146 -0
  17. package/dist/ai/llm/openai.js.map +1 -0
  18. package/dist/ai/llm/types.d.ts +113 -0
  19. package/dist/ai/llm/types.d.ts.map +1 -0
  20. package/dist/ai/llm/types.js +22 -0
  21. package/dist/ai/llm/types.js.map +1 -0
  22. package/dist/ai/providers.d.ts +37 -15
  23. package/dist/ai/providers.d.ts.map +1 -1
  24. package/dist/ai/providers.js +30 -5
  25. package/dist/ai/providers.js.map +1 -1
  26. package/dist/ai/summarize.d.ts +4 -4
  27. package/dist/ai/summarize.d.ts.map +1 -1
  28. package/dist/ai/summarize.js +6 -13
  29. package/dist/ai/summarize.js.map +1 -1
  30. package/dist/ai/synthesize.d.ts +12 -4
  31. package/dist/ai/synthesize.d.ts.map +1 -1
  32. package/dist/ai/synthesize.js +18 -34
  33. package/dist/ai/synthesize.js.map +1 -1
  34. package/dist/ask/ask.d.ts +3 -0
  35. package/dist/ask/ask.d.ts.map +1 -1
  36. package/dist/ask/ask.js +20 -18
  37. package/dist/ask/ask.js.map +1 -1
  38. package/dist/ask/fuse.d.ts +96 -0
  39. package/dist/ask/fuse.d.ts.map +1 -0
  40. package/dist/ask/fuse.js +184 -0
  41. package/dist/ask/fuse.js.map +1 -0
  42. package/dist/claude/format.d.ts.map +1 -1
  43. package/dist/claude/format.js +10 -2
  44. package/dist/claude/format.js.map +1 -1
  45. package/dist/claude/init.d.ts +3 -0
  46. package/dist/claude/init.d.ts.map +1 -1
  47. package/dist/claude/init.js +6 -1
  48. package/dist/claude/init.js.map +1 -1
  49. package/dist/claude/skill-template.d.ts.map +1 -1
  50. package/dist/claude/skill-template.js +34 -22
  51. package/dist/claude/skill-template.js.map +1 -1
  52. package/dist/cli.d.ts +3 -2
  53. package/dist/cli.d.ts.map +1 -1
  54. package/dist/cli.js +50 -37
  55. package/dist/cli.js.map +1 -1
  56. package/dist/context/savings.d.ts +34 -0
  57. package/dist/context/savings.d.ts.map +1 -0
  58. package/dist/context/savings.js +49 -0
  59. package/dist/context/savings.js.map +1 -0
  60. package/dist/engine.d.ts +4 -3
  61. package/dist/engine.d.ts.map +1 -1
  62. package/dist/engine.js +30 -19
  63. package/dist/engine.js.map +1 -1
  64. package/dist/graph/map.d.ts +4 -0
  65. package/dist/graph/map.d.ts.map +1 -1
  66. package/dist/graph/map.js +4 -1
  67. package/dist/graph/map.js.map +1 -1
  68. package/dist/graph/scopes.d.ts +30 -0
  69. package/dist/graph/scopes.d.ts.map +1 -0
  70. package/dist/graph/scopes.js +369 -0
  71. package/dist/graph/scopes.js.map +1 -0
  72. package/dist/graph/traverse-cli.d.ts +28 -18
  73. package/dist/graph/traverse-cli.d.ts.map +1 -1
  74. package/dist/graph/traverse-cli.js +68 -43
  75. package/dist/graph/traverse-cli.js.map +1 -1
  76. package/dist/graph/traverse.d.ts +35 -14
  77. package/dist/graph/traverse.d.ts.map +1 -1
  78. package/dist/graph/traverse.js +46 -20
  79. package/dist/graph/traverse.js.map +1 -1
  80. package/dist/graph/workspace.d.ts +136 -0
  81. package/dist/graph/workspace.d.ts.map +1 -0
  82. package/dist/graph/workspace.js +339 -0
  83. package/dist/graph/workspace.js.map +1 -0
  84. package/dist/hosts/instructions.d.ts.map +1 -1
  85. package/dist/hosts/instructions.js +4 -3
  86. package/dist/hosts/instructions.js.map +1 -1
  87. package/dist/hosts/mcp-config.d.ts +5 -0
  88. package/dist/hosts/mcp-config.d.ts.map +1 -1
  89. package/dist/hosts/mcp-config.js +2 -2
  90. package/dist/hosts/mcp-config.js.map +1 -1
  91. package/dist/index.d.ts +9 -3
  92. package/dist/index.d.ts.map +1 -1
  93. package/dist/index.js +8 -4
  94. package/dist/index.js.map +1 -1
  95. package/dist/mcp/tools.d.ts.map +1 -1
  96. package/dist/mcp/tools.js +33 -65
  97. package/dist/mcp/tools.js.map +1 -1
  98. package/dist/search/grep-cli.d.ts.map +1 -1
  99. package/dist/search/grep-cli.js +4 -0
  100. package/dist/search/grep-cli.js.map +1 -1
  101. package/dist/search/grep.d.ts +4 -0
  102. package/dist/search/grep.d.ts.map +1 -1
  103. package/dist/search/grep.js +2 -0
  104. package/dist/search/grep.js.map +1 -1
  105. package/package.json +2 -1
@@ -1,45 +1,56 @@
1
1
  /**
2
- * CLI wiring for `graft callers` / `callees` / `impact`.
2
+ * CLI wiring for `graft callers` and its `--direction` / `--depth` flags.
3
3
  *
4
- * The three commands are one implementation with a direction flag: they all
5
- * resolve a symbol via `resolveSymbol`, walk edges via `callersOf` /
6
- * `calleesOf` / `impactOf`, and share the same resolve-or-die flow, human
7
- * formatter, and --json shape. Kept out of cli.ts so that file stays thin
8
- * (argument wiring only) and this logic stays unit-testable without shelling
9
- * out to the CLI on every case.
4
+ * One command, one implementation: resolve a symbol via `resolveSymbol`, walk
5
+ * edges via `edgeWalk` (incoming or outgoing, depth 1 or a BFS), and share the
6
+ * same resolve-or-die flow, human formatter, and --json shape. Kept out of
7
+ * cli.ts so that file stays thin (argument wiring only) and this logic stays
8
+ * unit-testable without shelling out to the CLI on every case.
9
+ *
10
+ * `--direction out` subsumes the old `graft callees`; `--depth N` subsumes the
11
+ * old `graft impact`. Exported formatters are reused by the MCP `graft_callers`
12
+ * tool (`src/mcp/tools.ts`), so both surfaces render identical reports.
10
13
  */
11
14
  import { resolve } from "node:path";
12
15
  import { contextDirFor } from "../context/node-file.js";
16
+ import { savingsFooter, savingsFor } from "../context/savings.js";
13
17
  import { loadGraphCached } from "./load.js";
14
- import { resolveSymbol, callersOf, calleesOf, impactOf } from "./traverse.js";
15
- const ARROW = { callers: "←", impact: "←", callees: "→" };
16
- const DEFAULT_IMPACT_DEPTH = 2;
17
- function edgesFor(kind, graph, node, depth) {
18
- if (kind === "callers")
19
- return callersOf(graph, node);
20
- if (kind === "callees")
21
- return calleesOf(graph, node);
22
- return impactOf(graph, node, depth);
23
- }
24
- /** Exported so the MCP tools (`graft_callers`/`graft_callees`/`graft_blast_radius`
25
- * in `src/mcp/tools.ts`) can render the same human report format as the CLI,
26
- * rather than re-implementing it — both surfaces walk the same edges via the
27
- * same `resolveSymbol`/`callersOf`/`calleesOf`/`impactOf` core. */
18
+ import { resolveSymbol, edgeWalk } from "./traverse.js";
19
+ const ARROW = { in: "←", out: "→" };
20
+ const DEFAULT_DEPTH = 1;
21
+ /** Exported so the MCP `graft_callers` tool (`src/mcp/tools.ts`) can render the
22
+ * same human report format as the CLI, rather than re-implementing it — both
23
+ * surfaces walk the same edges via the same `resolveSymbol` / `edgeWalk` core. */
28
24
  export function headerOf(n) {
29
25
  return `${n.name} · ${n.kind} · ${n.path}:${n.span}`;
30
26
  }
31
- export function hitLine(kind, hit) {
32
- const arrow = ARROW[kind];
33
- const depthTag = kind === "impact" ? ` [depth ${hit.depth}]` : "";
27
+ /** `showDepth` is set for multi-hop walks (depth > 1), matching the old
28
+ * `graft impact` output which tagged every hit with its BFS depth. */
29
+ export function hitLine(direction, hit, showDepth) {
30
+ const arrow = ARROW[direction];
31
+ const depthTag = showDepth ? ` [depth ${hit.depth}]` : "";
34
32
  const label = hit.node ? `${hit.node.name} (${hit.node.path}:${hit.node.span})` : `${hit.id} (unresolved import)`;
35
33
  return ` ${hit.relation} ${arrow} ${label}${depthTag}`;
36
34
  }
37
- /** Loud, actionable empty-result note — never a bare empty list. `callers` and
38
- * `impact` both walk incoming edges, so they share the "callers" wording. */
39
- export function looseNoteFor(kind, name) {
40
- const label = kind === "callees" ? "callees" : "callers";
41
- const direction = kind === "callees" ? "outgoing" : "incoming";
42
- return ` no indexed ${label} — the graph has no ${direction} call/reference edges for this symbol; try grep -rn "${name}"`;
35
+ /** Tokens-saved baseline for a callers/callees walk: the files of the matched
36
+ * symbols plus every resolved edge endpoint, read whole — the files you'd open
37
+ * to trace these edges by hand. Shared by the CLI and the MCP tool so both
38
+ * surfaces report the same number. */
39
+ export function callersSavings(graph, results) {
40
+ const paths = [];
41
+ for (const { symbol, hits } of results) {
42
+ paths.push(symbol.path);
43
+ for (const h of hits)
44
+ if (h.node)
45
+ paths.push(h.node.path);
46
+ }
47
+ return savingsFor(graph, paths);
48
+ }
49
+ /** Loud, actionable empty-result note — never a bare empty list. */
50
+ export function looseNoteFor(direction, name) {
51
+ const label = direction === "out" ? "callees" : "callers";
52
+ const dir = direction === "out" ? "outgoing" : "incoming";
53
+ return ` no indexed ${label} — the graph has no ${dir} call/reference edges for this symbol; try grep -rn "${name}"`;
43
54
  }
44
55
  function symbolJson(n) {
45
56
  return { id: n.id, name: n.name, kind: n.kind, path: n.path, span: n.span };
@@ -54,13 +65,22 @@ function hitJson(hit) {
54
65
  }
55
66
  return out;
56
67
  }
68
+ /** Parse and validate the raw `--direction` string; exits (code 1) on garbage. */
69
+ function resolveDirection(raw) {
70
+ if (raw === undefined)
71
+ return "in";
72
+ if (raw === "in" || raw === "out")
73
+ return raw;
74
+ console.error(`✗ --direction must be "in" or "out", got "${raw}"`);
75
+ process.exit(1);
76
+ }
57
77
  /**
58
- * Resolve `query` in the graph at `dir` (respecting `--dir`/`--in`), walk
59
- * edges per `kind`, and print either the human report or `--json`. Exits the
60
- * process (code 1) when there's no graph at all or the symbol is unknown —
61
- * both are caller-facing mistakes, not recoverable states.
78
+ * Resolve `query` in the graph at `dir` (respecting `--dir`/`--in`), walk edges
79
+ * per `--direction`/`--depth`, and print either the human report or `--json`.
80
+ * Exits the process (code 1) when there's no graph at all or the symbol is
81
+ * unknown — both are caller-facing mistakes, not recoverable states.
62
82
  */
63
- export function runTraverseCommand(kind, query, dir, opts) {
83
+ export function runCallersCommand(query, dir, opts) {
64
84
  const root = resolve(dir);
65
85
  const contextDir = contextDirFor(root, opts.globalDir);
66
86
  const graph = loadGraphCached(contextDir);
@@ -73,26 +93,30 @@ export function runTraverseCommand(kind, query, dir, opts) {
73
93
  console.error(`✗ no symbol "${query}" in the graph — check spelling or run graft build`);
74
94
  process.exit(1);
75
95
  }
76
- let depth = DEFAULT_IMPACT_DEPTH;
77
- if (kind === "impact" && opts.depth !== undefined) {
96
+ const direction = resolveDirection(opts.direction);
97
+ let depth = DEFAULT_DEPTH;
98
+ if (opts.depth !== undefined) {
78
99
  const d = Number(opts.depth);
79
100
  if (!Number.isFinite(d) || d < 1) {
80
101
  console.error(`✗ --depth must be a positive number, got "${opts.depth}"`);
81
102
  process.exit(1);
82
103
  }
83
- depth = d;
104
+ depth = Math.floor(d);
84
105
  }
85
- const results = matches.map((symbol) => ({ symbol, hits: edgesFor(kind, graph, symbol, depth) }));
106
+ const showDepth = depth > 1;
107
+ const results = matches.map((symbol) => ({ symbol, hits: edgeWalk(graph, symbol, direction, depth) }));
108
+ const saved = callersSavings(graph, results);
86
109
  if (opts.json) {
87
110
  const payload = {
88
111
  query,
89
112
  matches: results.map((r) => {
90
113
  const m = { symbol: symbolJson(r.symbol), hits: r.hits.map(hitJson) };
91
114
  if (r.hits.length === 0) {
92
- m.note = looseNoteFor(kind, r.symbol.name);
115
+ m.note = looseNoteFor(direction, r.symbol.name);
93
116
  }
94
117
  return m;
95
118
  }),
119
+ saved,
96
120
  };
97
121
  console.log(JSON.stringify(payload, null, 2));
98
122
  return;
@@ -101,12 +125,13 @@ export function runTraverseCommand(kind, query, dir, opts) {
101
125
  for (const { symbol, hits } of results) {
102
126
  lines.push(headerOf(symbol));
103
127
  if (hits.length === 0)
104
- lines.push(looseNoteFor(kind, symbol.name));
128
+ lines.push(looseNoteFor(direction, symbol.name));
105
129
  else
106
130
  for (const h of hits)
107
- lines.push(hitLine(kind, h));
131
+ lines.push(hitLine(direction, h, showDepth));
108
132
  lines.push("");
109
133
  }
110
- process.stdout.write(lines.join("\n").replace(/\n+$/, "\n"));
134
+ const body = lines.join("\n").replace(/\n+$/, "\n");
135
+ process.stdout.write(body + savingsFooter(body, saved));
111
136
  }
112
137
  //# sourceMappingURL=traverse-cli.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"traverse-cli.js","sourceRoot":"","sources":["../../src/graph/traverse-cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAgB,MAAM,eAAe,CAAC;AAc5F,MAAM,KAAK,GAAoC,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;AAC3F,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAE/B,SAAS,QAAQ,CAAC,IAAkB,EAAE,KAAc,EAAE,IAAY,EAAE,KAAa;IAC/E,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACtD,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACtD,OAAO,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AACtC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AC;YACX,CAAC,CAAC;YACF,KAAK;SACN,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAC9C,OAAO;IACT,CAAC;IAED,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,OAAO,EAAE,CAAC;QACvC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;QAC7B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;;YACnE,KAAK,MAAM,CAAC,IAAI,IAAI;gBAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;QACxE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC;IACD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACpD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AAC1D,CAAC"}
@@ -1,17 +1,22 @@
1
1
  /**
2
- * Pure graph-traversal core shared by `graft callers` / `callees` / `impact`,
3
- * their MCP equivalents, and `ask`'s structural intent path.
2
+ * Pure graph-traversal core shared by `graft callers` (its `--direction`/
3
+ * `--depth` flags), the MCP `graft_callers` tool, and `ask`'s structural
4
+ * intent path.
4
5
  *
5
6
  * Centralizes the symbol-resolution contract (bare name, qualified id-suffix,
6
- * last-segment fallback, `--in` narrowing) so all three surfaces agree on what
7
- * a query like `Cache.get` or `hashstructure.Hash` means, and the depth-1
8
- * (callers/callees) and BFS (impact) edge walks over the wiring graph.
7
+ * last-segment fallback, `--in` narrowing) so all surfaces agree on what a
8
+ * query like `Cache.get` or `hashstructure.Hash` means, and the direction-aware
9
+ * (incoming/outgoing) depth-1 and BFS edge walks over the wiring graph.
9
10
  *
10
11
  * No I/O here: callers pass in an already-loaded `GraphV1` (via
11
12
  * `loadGraphCached`), which keeps this module trivially unit-testable against
12
13
  * hand-built fixture graphs.
13
14
  */
14
15
  import type { GraphV1, NodeV1, Relation } from "./types.js";
16
+ /** Which way to walk the wiring graph: `in` = incoming edges (who points at
17
+ * the symbol — callers / blast radius), `out` = outgoing edges (what the symbol
18
+ * points at — callees). */
19
+ export type Direction = "in" | "out";
15
20
  /** A resolved symbol-search hit. Reserved for future disambiguation metadata
16
21
  * (e.g. why a query matched); today it wraps the node 1:1. */
17
22
  export interface SymbolMatch {
@@ -62,20 +67,22 @@ export declare function calleesOf(graph: GraphV1, symbol: NodeV1): EdgeHit[];
62
67
  */
63
68
  export declare function impactOf(graph: GraphV1, symbol: NodeV1, maxDepth?: number): EdgeHit[];
64
69
  /**
65
- * BFS over INCOMING walk-relation edges from *multiple* seed nodes at once —
66
- * the multi-seed generalization of {@link impactOf} (`impactOf(g, n, d)` is
67
- * exactly `impactOfMany(g, [n], d)`). Used when one logical unit spans several
68
- * graph node ids — e.g. a file plus every symbol defined in it, since a
69
- * `calls`/`references`/etc. edge from another file always targets the SYMBOL
70
- * id, never the FILE id, so walking the file node alone misses dependents that
71
- * call into it rather than merely importing it.
70
+ * BFS over walk-relation edges from *multiple* seed nodes at once, in the given
71
+ * `direction` (`in` = incoming, the default — "who breaks if this changes";
72
+ * `out` = outgoing — "what this reaches"). The multi-seed generalization of
73
+ * {@link impactOf} (`impactOf(g, n, d)` is exactly `impactOfMany(g, [n], d)`).
74
+ * Used when one logical unit spans several graph node ids — e.g. a file plus
75
+ * every symbol defined in it, since a `calls`/`references`/etc. edge from
76
+ * another file always targets the SYMBOL id, never the FILE id, so walking the
77
+ * file node alone misses dependents that call into it rather than merely
78
+ * importing it.
72
79
  *
73
80
  * Every seed is pre-marked visited (so a seed can never appear as its own
74
81
  * hit, and an edge between two seeds is never reported), then the walk
75
82
  * proceeds exactly like `impactOf`'s: each reached node deduped by id and
76
83
  * reported once, at the depth it was first reached from *any* seed.
77
84
  */
78
- export declare function impactOfMany(graph: GraphV1, seeds: NodeV1[], maxDepth?: number): EdgeHit[];
85
+ export declare function impactOfMany(graph: GraphV1, seeds: NodeV1[], maxDepth?: number, direction?: Direction): EdgeHit[];
79
86
  /**
80
87
  * `impactOf`, generalized for a `kind: 'file'` seed: aggregates the BFS over
81
88
  * the file node AND every symbol node defined in that file (via
@@ -85,5 +92,19 @@ export declare function impactOfMany(graph: GraphV1, seeds: NodeV1[], maxDepth?:
85
92
  * see this module's header and `impactOfMany`'s doc for why. Symbol-kind
86
93
  * queries keep using plain `impactOf`; this is only for file-kind matches.
87
94
  */
88
- export declare function impactOfFile(graph: GraphV1, fileNode: NodeV1, maxDepth?: number): EdgeHit[];
95
+ export declare function impactOfFile(graph: GraphV1, fileNode: NodeV1, maxDepth?: number, direction?: Direction): EdgeHit[];
96
+ /**
97
+ * The single entry point behind `graft callers` and the MCP `graft_callers`
98
+ * tool, covering all of what were once three commands:
99
+ * - `direction:in, depth:1` → callers (who calls/references this)
100
+ * - `direction:out, depth:1` → callees (what this calls/references)
101
+ * - `direction:in, depth>1` → blast radius (transitive dependents)
102
+ * - `direction:out, depth>1` → transitive dependencies
103
+ *
104
+ * Depth 1 uses the plain single-hop scan ({@link callersOf}/{@link calleesOf})
105
+ * so `graft callers <symbol>` output is unchanged. Depth >1 runs the BFS, and
106
+ * for a `kind: 'file'` seed aggregates over the symbols the file defines (see
107
+ * {@link impactOfMany}) so file-level dependents aren't silently dropped.
108
+ */
109
+ export declare function edgeWalk(graph: GraphV1, node: NodeV1, direction: Direction, depth: number): EdgeHit[];
89
110
  //# sourceMappingURL=traverse.d.ts.map
@@ -1 +1 @@
1
- {"version":3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EAAE,QAAQ,SAAI,EAAE,SAAS,GAAE,SAAgB,GAAG,OAAO,EAAE,CAmClH;AAQD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,SAAI,EAAE,SAAS,GAAE,SAAgB,GAAG,OAAO,EAAE,CAEnH;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,CAIrG"}
@@ -82,32 +82,38 @@ export function impactOf(graph, symbol, maxDepth = 2) {
82
82
  return impactOfMany(graph, [symbol], maxDepth);
83
83
  }
84
84
  /**
85
- * BFS over INCOMING walk-relation edges from *multiple* seed nodes at once —
86
- * the multi-seed generalization of {@link impactOf} (`impactOf(g, n, d)` is
87
- * exactly `impactOfMany(g, [n], d)`). Used when one logical unit spans several
88
- * graph node ids — e.g. a file plus every symbol defined in it, since a
89
- * `calls`/`references`/etc. edge from another file always targets the SYMBOL
90
- * id, never the FILE id, so walking the file node alone misses dependents that
91
- * call into it rather than merely importing it.
85
+ * BFS over walk-relation edges from *multiple* seed nodes at once, in the given
86
+ * `direction` (`in` = incoming, the default — "who breaks if this changes";
87
+ * `out` = outgoing — "what this reaches"). The multi-seed generalization of
88
+ * {@link impactOf} (`impactOf(g, n, d)` is exactly `impactOfMany(g, [n], d)`).
89
+ * Used when one logical unit spans several graph node ids — e.g. a file plus
90
+ * every symbol defined in it, since a `calls`/`references`/etc. edge from
91
+ * another file always targets the SYMBOL id, never the FILE id, so walking the
92
+ * file node alone misses dependents that call into it rather than merely
93
+ * importing it.
92
94
  *
93
95
  * Every seed is pre-marked visited (so a seed can never appear as its own
94
96
  * hit, and an edge between two seeds is never reported), then the walk
95
97
  * proceeds exactly like `impactOf`'s: each reached node deduped by id and
96
98
  * reported once, at the depth it was first reached from *any* seed.
97
99
  */
98
- export function impactOfMany(graph, seeds, maxDepth = 2) {
100
+ export function impactOfMany(graph, seeds, maxDepth = 2, direction = "in") {
99
101
  const byId = new Map(graph.nodes.map((n) => [n.id, n]));
100
- // target id → incoming {source, relation} pairs, restricted to walk relations.
101
- const incoming = new Map();
102
+ // Adjacency keyed for the walk direction, restricted to walk relations:
103
+ // 'in' → key = edge.target, neighbour = edge.source (who points AT key)
104
+ // 'out' → key = edge.source, neighbour = edge.target (what key points TO)
105
+ const adj = new Map();
102
106
  for (const e of graph.edges) {
103
107
  if (!WALK_RELATIONS.has(e.relation))
104
108
  continue;
105
- const arr = incoming.get(e.target);
106
- const entry = { source: e.source, relation: e.relation };
109
+ const key = direction === "in" ? e.target : e.source;
110
+ const other = direction === "in" ? e.source : e.target;
111
+ const entry = { other, relation: e.relation };
112
+ const arr = adj.get(key);
107
113
  if (arr)
108
114
  arr.push(entry);
109
115
  else
110
- incoming.set(e.target, [entry]);
116
+ adj.set(key, [entry]);
111
117
  }
112
118
  const visited = new Set(seeds.map((s) => s.id));
113
119
  const hits = [];
@@ -115,12 +121,12 @@ export function impactOfMany(graph, seeds, maxDepth = 2) {
115
121
  for (let depth = 1; depth <= maxDepth && frontier.length > 0; depth++) {
116
122
  const next = [];
117
123
  for (const current of frontier) {
118
- for (const { source, relation } of incoming.get(current) ?? []) {
119
- if (visited.has(source))
124
+ for (const { other, relation } of adj.get(current) ?? []) {
125
+ if (visited.has(other))
120
126
  continue;
121
- visited.add(source);
122
- hits.push({ node: byId.get(source) ?? null, id: source, relation, depth });
123
- next.push(source);
127
+ visited.add(other);
128
+ hits.push({ node: byId.get(other) ?? null, id: other, relation, depth });
129
+ next.push(other);
124
130
  }
125
131
  }
126
132
  frontier = next;
@@ -141,7 +147,27 @@ function symbolsInFile(graph, fileNode) {
141
147
  * see this module's header and `impactOfMany`'s doc for why. Symbol-kind
142
148
  * queries keep using plain `impactOf`; this is only for file-kind matches.
143
149
  */
144
- export function impactOfFile(graph, fileNode, maxDepth = 2) {
145
- return impactOfMany(graph, [fileNode, ...symbolsInFile(graph, fileNode)], maxDepth);
150
+ export function impactOfFile(graph, fileNode, maxDepth = 2, direction = "in") {
151
+ return impactOfMany(graph, [fileNode, ...symbolsInFile(graph, fileNode)], maxDepth, direction);
152
+ }
153
+ /**
154
+ * The single entry point behind `graft callers` and the MCP `graft_callers`
155
+ * tool, covering all of what were once three commands:
156
+ * - `direction:in, depth:1` → callers (who calls/references this)
157
+ * - `direction:out, depth:1` → callees (what this calls/references)
158
+ * - `direction:in, depth>1` → blast radius (transitive dependents)
159
+ * - `direction:out, depth>1` → transitive dependencies
160
+ *
161
+ * Depth 1 uses the plain single-hop scan ({@link callersOf}/{@link calleesOf})
162
+ * so `graft callers <symbol>` output is unchanged. Depth >1 runs the BFS, and
163
+ * for a `kind: 'file'` seed aggregates over the symbols the file defines (see
164
+ * {@link impactOfMany}) so file-level dependents aren't silently dropped.
165
+ */
166
+ export function edgeWalk(graph, node, direction, depth) {
167
+ if (depth <= 1)
168
+ return direction === "in" ? callersOf(graph, node) : calleesOf(graph, node);
169
+ if (node.kind === "file")
170
+ return impactOfFile(graph, node, depth, direction);
171
+ return impactOfMany(graph, [node], depth, direction);
146
172
  }
147
173
  //# sourceMappingURL=traverse.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"traverse.js","sourceRoot":"","sources":["../../src/graph/traverse.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAahD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc,EAAE,KAAa,EAAE,OAA6B,EAAE;IAC1F,MAAM,UAAU,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IACvC,MAAM,iBAAiB,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAEtE,IAAI,OAAO,GAAG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C7E,OAAO,YAAY,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AACvD,CAAC"}
@@ -0,0 +1,136 @@
1
+ import { type AskIndex } from "../ask/index-file.js";
2
+ import { type GraphBuildResult } from "./build.js";
3
+ import { type GraphCheckResult } from "./check.js";
4
+ import { type RepoMap } from "./map.js";
5
+ import type { GraphV1 } from "./types.js";
6
+ /** The parent-side manifest — the ONLY thing a workspace parent's graft/ holds. */
7
+ export interface WorkspaceV1 {
8
+ version: 1;
9
+ /** Immediate child git repos, as dir names, sorted. */
10
+ children: string[];
11
+ }
12
+ export declare const WORKSPACE_FILE = "workspace.json";
13
+ /** `<contextDir>/workspace.json` — sibling of where `.graph/` would live. */
14
+ export declare function workspacePath(outDir: string): string;
15
+ /** Read the workspace manifest for the repo/parent at `root` (respecting the
16
+ * `--dir` override like every other reader). Null when absent or malformed —
17
+ * a non-workspace root costs one `existsSync`. */
18
+ export declare function readWorkspace(root: string, contextDirOverride?: string): WorkspaceV1 | null;
19
+ /** Write the manifest (children sorted; deterministic bytes, like writeGraph). */
20
+ export declare function writeWorkspace(outDir: string, ws: WorkspaceV1): string;
21
+ /** Build-time workspace detection: `root` has NO `.git` of its own and >=2
22
+ * immediate git children (a `.git` FILE — worktree/submodule — counts).
23
+ * Returns the sorted child names, or null when `root` is a normal repo/dir. */
24
+ export declare function isWorkspaceRoot(root: string): string[] | null;
25
+ export interface WorkspaceGraphs {
26
+ /** All children listed in the manifest. */
27
+ children: string[];
28
+ /** Children with a built graph, in manifest order. Each child's graph and
29
+ * sidecar come from ITS OWN `graft/` via the shared caches. */
30
+ built: {
31
+ child: string;
32
+ contextDir: string;
33
+ graph: GraphV1;
34
+ askIndex: AskIndex | null;
35
+ }[];
36
+ /** Children without a built graph — surfaced, never silently skipped. */
37
+ unbuilt: string[];
38
+ /** The surfacing line, set whenever `unbuilt` is non-empty. */
39
+ note?: string;
40
+ }
41
+ /** Load every child's graph via `loadGraphCached` (the only graph loader).
42
+ * Null when `root` is not a workspace (no manifest). */
43
+ export declare function loadWorkspaceGraphs(root: string, contextDirOverride?: string): WorkspaceGraphs | null;
44
+ /** Merge the built children into one virtual graph whose scopes are each
45
+ * child's scopes prefixed `<child>/` (child root scope → `<child>`). With >=2
46
+ * built children this is always multi-scope, so `ask` takes its per-scope
47
+ * RRF path and labels every hit with its repo. Null when nothing is built. */
48
+ export declare function mergeWorkspaceGraphs(built: WorkspaceGraphs["built"]): GraphV1 | null;
49
+ /** Merge the children's build-time ask sidecars to match the merged graph:
50
+ * doc ids prefixed, and each doc's path bag gains the child dir's tokens —
51
+ * exactly what live tokenization of the prefixed path would produce, so the
52
+ * sidecar stays a provably exact cache. `df`/`docCount`/`avgBodyLen` are
53
+ * recomputed over the merged docs. Null (→ live-tokenization fallback, same
54
+ * degradation as any stale sidecar) unless EVERY built child has a sidecar
55
+ * that exactly covers its graph. */
56
+ export declare function mergeWorkspaceAskIndexes(built: WorkspaceGraphs["built"]): AskIndex | null;
57
+ /** One-call federation for graph-consuming commands (grep, callers/callees,
58
+ * impact, MCP): null when `root` is not a workspace; otherwise the merged
59
+ * graph (null when no child is built) plus the unbuilt-children note. */
60
+ export declare function loadFederatedGraph(root: string, contextDirOverride?: string): {
61
+ graph: GraphV1 | null;
62
+ note?: string;
63
+ } | null;
64
+ /** Federation inputs for `ask`: the merged graph + merged sidecar + each built
65
+ * child's context dir (for its concept nodes). `ask` feeds the merged graph to
66
+ * its existing multi-scope pipeline, so `rankScopesAndFuse` does the fair
67
+ * cross-repo fusion with `<child>/`-prefixed scope labels. */
68
+ export declare function federateAsk(root: string, contextDirOverride?: string): {
69
+ graph: GraphV1 | null;
70
+ askIndex: AskIndex | null;
71
+ built: {
72
+ child: string;
73
+ contextDir: string;
74
+ }[];
75
+ note?: string;
76
+ } | null;
77
+ /** EXACT migration wording (asserted by tests) for a parent whose old combined
78
+ * graph is being replaced by the workspace manifest. */
79
+ export declare function migrationNote(children: string[]): string;
80
+ export interface WorkspaceBuildResult {
81
+ children: {
82
+ child: string;
83
+ result: GraphBuildResult;
84
+ }[];
85
+ workspacePath: string;
86
+ /** True when a pre-existing combined graph at the parent was replaced. */
87
+ migrated: boolean;
88
+ /** The exact {@link migrationNote} wording, set only when `migrated`. */
89
+ migrationNote?: string;
90
+ }
91
+ /**
92
+ * `graft build` at a workspace parent: build each child's graph into the child
93
+ * (plain `buildGraph(childDir)` — nothing parent-side touches it, which is what
94
+ * makes the result byte-identical to a standalone build), then write the
95
+ * parent manifest. A pre-existing mega-graph (`graft/.graph/wiring.json` at
96
+ * the parent) is replaced: its `.graph/` and `.cache/` are deleted AFTER the
97
+ * children built successfully, so a failed child build never destroys the old
98
+ * (still-working) graph.
99
+ */
100
+ export declare function buildWorkspace(root: string, opts?: {
101
+ contextDir?: string;
102
+ }): Promise<WorkspaceBuildResult>;
103
+ /** Human report for a workspace build — the migration note (when migrating)
104
+ * first, then one ✓ line per child, then where the manifest went. */
105
+ export declare function formatWorkspaceBuild(r: WorkspaceBuildResult): string;
106
+ export interface WorkspaceCheck {
107
+ children: {
108
+ child: string;
109
+ missing: boolean;
110
+ ok: boolean;
111
+ summary: string;
112
+ result: GraphCheckResult;
113
+ }[];
114
+ /** True when any child that HAS a graph is stale — unbuilt alone never fails. */
115
+ failed: boolean;
116
+ }
117
+ /** Per-child drift check ({@link checkGraph} in each child repo). */
118
+ export declare function checkWorkspace(root: string, contextDirOverride?: string): WorkspaceCheck;
119
+ export declare function formatWorkspaceCheck(c: WorkspaceCheck): string;
120
+ export interface WorkspaceMap {
121
+ children: {
122
+ child: string;
123
+ map: RepoMap;
124
+ }[];
125
+ note?: string;
126
+ }
127
+ /** Per-child repo maps, the directory budget split evenly across the built
128
+ * children. Null when `root` is not a workspace. */
129
+ export declare function buildWorkspaceMap(root: string, opts?: {
130
+ maxDirs?: number;
131
+ contextDir?: string;
132
+ }): WorkspaceMap | null;
133
+ /** One section per child (its own `formatRepoMap` report under a `<child>/`
134
+ * heading), plus the unbuilt-children note when present. */
135
+ export declare function formatWorkspaceMap(m: WorkspaceMap): string;
136
+ //# sourceMappingURL=workspace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../src/graph/workspace.ts"],"names":[],"mappings":"AAgCA,OAAO,EAAoB,KAAK,QAAQ,EAAoB,MAAM,sBAAsB,CAAC;AACzF,OAAO,EAAc,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAc,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE/D,OAAO,EAA+B,KAAK,OAAO,EAAE,MAAM,UAAU,CAAC;AAGrE,OAAO,KAAK,EAAU,OAAO,EAAmB,MAAM,YAAY,CAAC;AAEnE,mFAAmF;AACnF,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,CAAC,CAAC;IACX,uDAAuD;IACvD,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAE/C,6EAA6E;AAC7E,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;kDAEkD;AAClD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,kBAAkB,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAkB3F;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,GAAG,MAAM,CAMtE;AAED;;+EAE+E;AAC/E,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAK7D;AAID,MAAM,WAAW,eAAe;IAC9B,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB;mEAC+D;IAC/D,KAAK,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE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