Просмотр исходного кода

feat(mcp): line-number codegraph_node + codegraph_trace source output

node's code block and trace's inlined hop/destination bodies now carry cat -n line numbers (reusing numberSourceLines, matching codegraph_explore and Read), so the agent can cite or edit exact lines without re-Reading the file just to get them. Consistency across the code-returning tools + edit-workflow sufficiency.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Colby McHenry 1 месяц назад
Родитель
Сommit
bde8c195f6
2 измененных файлов с 8 добавлено и 2 удалено
  1. 3 0
      CHANGELOG.md
  2. 5 2
      src/mcp/tools.ts

+ 3 - 0
CHANGELOG.md

@@ -25,6 +25,9 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
   `codegraph_explore`/`codegraph_node`/Read. Measured across real repos: fewer
   tool calls and lower cost than the prior path-only output, with no wall-clock
   regression.
+- **`codegraph_node` and `codegraph_trace` now emit line-numbered source**
+  (`cat -n` style, matching `codegraph_explore` and Read), so an agent can cite
+  or edit exact lines without re-reading the file just to recover line numbers.
 
 ## [0.9.4] - 2026-05-22
 

+ 5 - 2
src/mcp/tools.ts

@@ -1241,7 +1241,7 @@ export class ToolHandler {
     if (slice.length > maxLines) { omitted = slice.length - maxLines; slice = slice.slice(0, maxLines); }
     const nonBlank = slice.filter(l => l.trim().length > 0);
     const dedent = nonBlank.length ? Math.min(...nonBlank.map(l => l.length - l.trimStart().length)) : 0;
-    let text = slice.map(l => `      ${l.slice(dedent)}`).join('\n');
+    let text = slice.map((l, i) => `      ${startLine + i}\t${l.slice(dedent)}`).join('\n');
     if (text.length > maxChars) {
       text = text.slice(0, maxChars).replace(/\n[^\n]*$/, '');
       omitted = Math.max(omitted, 1);
@@ -2340,7 +2340,10 @@ export class ToolHandler {
       lines.push('', outline, '',
         `> Structural outline only. Read \`${node.filePath}\` or call codegraph_node on a specific member for its body.`);
     } else if (code) {
-      lines.push('', '```' + node.language, code, '```');
+      // Line-numbered (cat -n style, like codegraph_explore and Read) so the
+      // agent can cite/edit exact lines without re-Reading the file for them.
+      const numbered = node.startLine ? numberSourceLines(code, node.startLine) : code;
+      lines.push('', '```' + node.language, numbered, '```');
     }
 
     return lines.join('\n');