feat: remove heuristics, go LLM-only with mocks + restructure

BREAKING: Heuristic fallback removed — LLM client now required

Changes:
- Remove extractFileHeuristic, extractPackageHeuristic, all helpers
- extractFileLLM / extractPackageLLM now throw LLMError when client missing
- Add hybrid binary detection: extension blacklist + content sniffing
- Increase file size limit: 50KB → 500KB (text files only)
- Restructure src/ into subdirectories:
  - src/llm/ — all LLM clients, extract, batch, cache, error
  - src/ast/ — AST extraction
  - src/cli/ — CLI entry point
- Update all imports across codebase and tests
- Add tests/mock-llm.ts helper for deterministic mock clients
- Update all tests to use mock LLM clients (no heuristics dependency)
- All 52 tests passing (including 8 real LLM integration tests)
This commit is contained in:
2026-06-10 17:34:37 +02:00
parent d948d88d0a
commit 2f198ea0d2
23 changed files with 382 additions and 507 deletions
+15 -9
View File
@@ -11,6 +11,7 @@ import { tmpdir } from "os";
import { initProject } from "../src/init.js";
import { patchFile } from "../src/patch.js";
import { validateMaps } from "../src/validate.js";
import { createMockFileClient, createMockPackageClient } from "./mock-llm.js";
describe("integration", () => {
let dir: string;
@@ -26,25 +27,26 @@ describe("integration", () => {
it("init creates .pi-map.md files", async () => {
mkdirSync(join(dir, "src"));
writeFileSync(join(dir, "src", "index.ts"), `export function foo() {}\n`);
await initProject(dir);
const client = createMockFileClient();
await initProject(dir, { llmClient: client, verbose: false });
const map = readFileSync(join(dir, "src", ".pi-map.md"), "utf8");
expect(map).toContain("# src");
expect(map).toContain("foo");
});
it("patch updates a file entry", async () => {
mkdirSync(join(dir, "src"));
writeFileSync(join(dir, "src", "index.ts"), `export function foo() {}\n`);
writeFileSync(join(dir, "src", "utils.ts"), `export const bar = 1;\n`);
await initProject(dir);
const client = createMockFileClient();
await initProject(dir, { llmClient: client, verbose: false });
// Modify a file
writeFileSync(
join(dir, "src", "index.ts"),
`export function foo() {}\nexport function baz() {}\n`,
);
await patchFile(join(dir, "src", "index.ts"));
await patchFile(join(dir, "src", "index.ts"), client, dir);
const map = readFileSync(join(dir, "src", ".pi-map.md"), "utf8");
expect(map).toContain("baz");
@@ -59,14 +61,15 @@ describe("integration", () => {
`export const x${i} = ${i};\n`,
);
}
await initProject(dir);
const client = createMockFileClient();
await initProject(dir, { llmClient: client, verbose: false });
// Modify a file
writeFileSync(
join(dir, "src", "file0.ts"),
`export const x0 = 0;\nexport const y = 99;\n`,
);
await patchFile(join(dir, "src", "file0.ts"));
await patchFile(join(dir, "src", "file0.ts"), client, dir);
const map = readFileSync(join(dir, "src", ".pi-map.md"), "utf8");
expect(map).toContain("y");
@@ -77,7 +80,8 @@ describe("integration", () => {
it("validate detects new files", async () => {
mkdirSync(join(dir, "src"));
writeFileSync(join(dir, "src", "a.ts"), `export const a = 1;\n`);
await initProject(dir);
const client = createMockFileClient();
await initProject(dir, { llmClient: client, verbose: false });
// Add new file
writeFileSync(join(dir, "src", "b.ts"), `export const b = 2;\n`);
@@ -91,7 +95,8 @@ describe("integration", () => {
mkdirSync(join(dir, "src"));
writeFileSync(join(dir, "src", "a.ts"), `export const a = 1;\n`);
writeFileSync(join(dir, "src", "b.ts"), `export const b = 2;\n`);
await initProject(dir);
const client = createMockFileClient();
await initProject(dir, { llmClient: client, verbose: false });
// Delete a file
rmSync(join(dir, "src", "b.ts"));
@@ -104,7 +109,8 @@ describe("integration", () => {
it("validate detects changed signatures", async () => {
mkdirSync(join(dir, "src"));
writeFileSync(join(dir, "src", "a.ts"), `export const a = 1;\n`);
await initProject(dir);
const client = createMockFileClient();
await initProject(dir, { llmClient: client, verbose: false });
// Change exports
writeFileSync(