fix(mcp): bold labels instead of ATX headings in tool results (#778) (#951)

MCP tool results used Markdown ATX headings (##/###/####) for section
headers — the status summary, each search hit, every file section in an
exploration — which Markdown-rendering clients (e.g. the Claude Code
VSCode extension) blow up to H1–H4 font size, filling the transcript with
oversized lines (worst on search/explore, where the noise scales with
result count). Swap them all for bold labels, which render at body size
while keeping the same structure. CLI/TTY output (ContextBuilder) is
unchanged — the issue notes it's fine.

The format is parse-coupled, so kept in sync:
- The explore truncation boundary and the offload chunker
  (reasoning/reasoner.ts) both key off the per-file header, now a unique
  `**`-prefixed marker emitted via a shared fileSectionHeader() helper.
- Updated the offload strip regexes and switched the opt-in report-style
  prompt off ATX headings (same client, same rendering issue).
- Updated test helpers (sectionFor, sourcedFiles, the callers
  section-boundary scan) that scanned the old markers.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Colby Mchenry
2026-06-22 12:06:35 -05:00
committed by GitHub
co-authored by Claude Opus 4.8
parent ace8d8a0d0
commit 3e1547bbe1
15 changed files with 106 additions and 81 deletions
+7 -6
View File
@@ -35,15 +35,16 @@ import CodeGraph from '../src/index';
// (the steer-to-explore phrasing changed when the Read invitation was removed).
const SKELETON_MARK = '· skeleton (signatures only';
/** Return the `#### <path> ...` section for a file basename, header through the
* line before the next `###`/`####` header (or end of output). */
/** Return the ``**`<path>`** ...`` section for a file basename, header through the
* line before the next bold header (or end of output). Headers are bold labels,
* not ATX headings (issue #778); file sections start with ``**` ``. */
function sectionFor(text: string, basename: string): string {
const lines = text.split('\n');
const start = lines.findIndex((l) => l.startsWith('#### ') && l.includes(basename));
const start = lines.findIndex((l) => l.startsWith('**`') && l.includes(basename));
if (start < 0) return '';
let end = lines.length;
for (let i = start + 1; i < lines.length; i++) {
if (lines[i].startsWith('### ') || lines[i].startsWith('#### ')) {
if (lines[i].startsWith('**')) {
end = i;
break;
}
@@ -284,7 +285,7 @@ export class YamlCodec extends Codec {
const text = result.content?.[0]?.text ?? '';
// Precondition: the spine must have formed, or nothing skeletonizes.
expect(text).toContain('## Flow (call path among the symbols you queried)');
expect(text).toContain('**Flow (call path among the symbols you queried)');
for (const [file, marker] of [
['bridge-interceptor.ts', 'BRIDGE_BODY_MARKER'],
@@ -345,7 +346,7 @@ export class YamlCodec extends Codec {
it('spares an off-spine sibling when the agent NAMED a callable in it (RealCall fix)', async () => {
const result = await handler.execute('codegraph_explore', { query: SPARE_QUERY, maxFiles: 15 });
const text = result.content?.[0]?.text ?? '';
expect(text).toContain('## Flow (call path among the symbols you queried)');
expect(text).toContain('**Flow (call path among the symbols you queried)');
// auth-interceptor.ts is an off-spine Interceptor sibling — would skeletonize —
// but the agent named its method `authenticate`, so it stays FULL.