Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/types/repoMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ export interface RepoMapResult {
imports: RepoMapImport[];
routes: RepoMapRoute[];
symbolSummary: string[];
warnings: string[];
}
2 changes: 2 additions & 0 deletions packages/mcp-server/src/utils/compactResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export interface CompactRepoMap {
riskyFileCount: number;
largeFileCount: number;
symbolCount: number;
warnings: string[];
}

export function createCompactRepoMap(map: RepoMapResult): CompactRepoMap {
Expand All @@ -142,6 +143,7 @@ export function createCompactRepoMap(map: RepoMapResult): CompactRepoMap {
riskyFileCount: map.riskyFiles.length,
largeFileCount: map.largeFiles.length,
symbolCount: map.symbols.length,
warnings: map.warnings,
};
}

Expand Down
52 changes: 51 additions & 1 deletion packages/mcp-server/tests/createRepoMapTool.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { describe, it, expect } from "vitest";
import { describe, it, expect, vi } from "vitest";
import type { WorkspaceScanResult } from "@wma/core";
import * as scanner from "@wma/scanner";
import { handleCreateRepoMap } from "../src/tools/createRepoMapTool.js";
import { formatRepoMapMarkdown } from "@wma/repo-map";
import path from "node:path";
Expand Down Expand Up @@ -61,4 +63,52 @@ describe("createRepoMapTool", () => {
const parsed = JSON.parse(result.content[0].text);
expect(parsed.tokenBudget).toBe(10000);
});

it("includes symbol extraction warnings in Markdown and JSON output", async () => {
const scanResult: WorkspaceScanResult = {
rootPath: fixturePath,
scannedAt: new Date().toISOString(),
totalFiles: 1,
includedFiles: 1,
excludedFiles: 0,
totalBytes: 100,
includedBytes: 100,
totalEstimatedTokens: 25,
includedTokens: 25,
files: [{
path: path.join(fixturePath, "missing.ts"),
relativePath: "src/index.ts",
extension: ".ts",
language: "TypeScript",
bytes: 100,
estimatedTokens: 25,
included: true,
riskFlags: [],
}],
folders: [],
languages: [],
warnings: [],
riskFiles: [],
};
const scanSpy = vi.spyOn(scanner, "scanWorkspace").mockResolvedValue(scanResult);

try {
const markdownResult = await handleCreateRepoMap({
rootPath: fixturePath,
format: "markdown",
});
expect(markdownResult.content[0].text).toContain("## Warnings");
expect(markdownResult.content[0].text).toContain("Failed to parse src/index.ts:");

const jsonResult = await handleCreateRepoMap({
rootPath: fixturePath,
format: "json",
});
const parsed = JSON.parse(jsonResult.content[0].text);
expect(parsed.warnings).toHaveLength(1);
expect(parsed.warnings[0]).toContain("Failed to parse src/index.ts:");
} finally {
scanSpy.mockRestore();
}
});
});
1 change: 1 addition & 0 deletions packages/repo-map/src/createRepoMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export function createRepoMap(
imports: symbolResult.imports,
routes: symbolResult.routes,
symbolSummary,
warnings: symbolResult.warnings,
};

result = budgetRepoMap(result, options.tokenBudget);
Expand Down
12 changes: 12 additions & 0 deletions packages/repo-map/src/formatRepoMapMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function formatRepoMapMarkdown(repoMap: RepoMapResult): string {
appendRecommendedAgentContext(lines, repoMap);
appendSuggestedPromptPrefix(lines, repoMap);
appendOverflowNotes(lines, repoMap);
appendWarnings(lines, repoMap);

return lines.join("\n");
}
Expand Down Expand Up @@ -249,6 +250,17 @@ function appendOverflowNotes(lines: string[], repoMap: RepoMapResult): void {
lines.push("");
}

function appendWarnings(lines: string[], repoMap: RepoMapResult): void {
if (repoMap.warnings.length === 0) return;

lines.push("## Warnings");
lines.push("");
for (const warning of repoMap.warnings) {
lines.push(`- ${escapeMarkdownText(warning)}`);
}
lines.push("");
}

function appendKeySymbols(lines: string[], repoMap: RepoMapResult): void {
if (!repoMap.symbols || repoMap.symbols.length === 0) return;

Expand Down
1 change: 1 addition & 0 deletions packages/repo-map/tests/budgetRepoMap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function makeResult(overrides: Partial<RepoMapResult>): RepoMapResult {
imports: [],
routes: [],
symbolSummary: [],
warnings: [],
...overrides,
};
}
Expand Down
60 changes: 59 additions & 1 deletion packages/repo-map/tests/createRepoMap.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { describe, it, expect } from "vitest";
import { describe, it, expect, vi } from "vitest";
import type { WorkspaceScanResult, WorkspaceFileInfo, FolderStats, LanguageBreakdown } from "@wma/core";
import { createRepoMap } from "../src/createRepoMap.js";
import * as typeScriptSymbols from "../src/symbols/parsers/typescriptSymbols.js";
import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";

function makeFile(overrides: Partial<WorkspaceFileInfo> & { relativePath: string }): WorkspaceFileInfo {
return {
Expand Down Expand Up @@ -127,6 +131,60 @@ describe("createRepoMap", () => {
expect(ts).toBeDefined();
});

it("includes failed-read warnings and preserves symbols from successful files", () => {
const tempDir = mkdtempSync(join(tmpdir(), "repo-map-warnings-"));
try {
const scan = makeFixtureScanResult();
const goodPath = join(tempDir, "index.ts");
writeFileSync(goodPath, "export function availableSymbol() {}", "utf-8");
scan.files = [
makeFile({ relativePath: "src/index.ts", path: goodPath }),
makeFile({ relativePath: "src/main.ts", path: join(tempDir, "missing.ts") }),
];

const result = createRepoMap(scan, { tokenBudget: 8000 });

expect(result.warnings).toHaveLength(1);
expect(result.warnings[0]).toContain("Failed to parse src/main.ts:");
expect(result.symbols.some((symbol) => symbol.name === "availableSymbol")).toBe(true);
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
});

it("includes parser-failure warnings and preserves symbols from other files", () => {
const tempDir = mkdtempSync(join(tmpdir(), "repo-map-parser-warnings-"));
const originalParser = typeScriptSymbols.extractTypeScriptSymbols;
const parserSpy = vi.spyOn(typeScriptSymbols, "extractTypeScriptSymbols")
.mockImplementation((content, relativePath, ext) => {
if (relativePath === "src/broken.ts") throw new Error("simulated parser failure");
return originalParser(content, relativePath, ext);
});

try {
const scan = makeFixtureScanResult();
const goodPath = join(tempDir, "index.ts");
const brokenPath = join(tempDir, "broken.ts");
writeFileSync(goodPath, "export function availableSymbol() {}", "utf-8");
writeFileSync(brokenPath, "export function brokenSymbol() {}", "utf-8");
scan.files = [
makeFile({ relativePath: "src/index.ts", path: goodPath }),
makeFile({ relativePath: "src/broken.ts", path: brokenPath }),
];

const result = createRepoMap(scan, { tokenBudget: 8000 });

expect(result.warnings).toEqual([
"Failed to parse src/broken.ts: simulated parser failure",
]);
expect(result.symbols.some((symbol) => symbol.name === "availableSymbol")).toBe(true);
expect(result.symbols.some((symbol) => symbol.name === "brokenSymbol")).toBe(false);
} finally {
parserSpy.mockRestore();
rmSync(tempDir, { recursive: true, force: true });
}
});

it("handles empty scan result gracefully", () => {
const scan: WorkspaceScanResult = {
rootPath: "/empty",
Expand Down
12 changes: 12 additions & 0 deletions packages/repo-map/tests/formatRepoMapMarkdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function makeFixtureRepoMap(): RepoMapResult {
"Exports: 2",
"Functions/Components: 2",
],
warnings: [],
};
}

Expand Down Expand Up @@ -119,6 +120,16 @@ describe("formatRepoMapMarkdown", () => {
expect(sectionCount(md, "Overflow Notes")).toBe(1);
});

it("includes symbol extraction warnings when present", () => {
const repoMap = makeFixtureRepoMap();
repoMap.warnings = ["Failed to parse src/broken.ts: parser failure"];

const md = formatRepoMapMarkdown(repoMap);

expect(sectionCount(md, "Warnings")).toBe(1);
expect(md).toContain("- Failed to parse src/broken.ts: parser failure");
});

it("does not include full source contents", () => {
const repoMap = makeFixtureRepoMap();
const md = formatRepoMapMarkdown(repoMap);
Expand Down Expand Up @@ -162,6 +173,7 @@ describe("formatRepoMapMarkdown", () => {
recommendedExclude: [],
agentInstructions: [],
overflowNotes: [],
warnings: [],
};
const md = formatRepoMapMarkdown(repoMap);

Expand Down
Loading