Skip to content

Commit 44e6e31

Browse files
committed
Add referenceExample
1 parent 81bbfa1 commit 44e6e31

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

src/__tests__/ConfigService.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ describe("ConfigService", () => {
107107
directoryFirst: true,
108108
excludeDirectories: false,
109109
},
110+
referenceExamples: {}, // Added referenceExamples
110111
};
111112

112113
(fs.existsSync as jest.Mock).mockReturnValue(true);
@@ -154,4 +155,4 @@ describe("ConfigService", () => {
154155
expect(fs.existsSync).toHaveBeenCalledWith(mockConfigPath);
155156
});
156157
});
157-
});
158+
});

src/services/ConfigService.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const configSchema = z.object({
5353
directoryFirst: true,
5454
excludeDirectories: false,
5555
}),
56+
referenceExamples: z.record(z.string(), z.string()).optional().default({}),
5657
});
5758

5859
export type Config = z.infer<typeof configSchema>;
@@ -137,6 +138,12 @@ export class ConfigService {
137138
directoryFirst: true,
138139
excludeDirectories: false,
139140
},
141+
referenceExamples: {
142+
example1: "path/to/example1/file.ts",
143+
example2: "path/to/example2/file.ts",
144+
myService: "src/services/MyService.ts",
145+
anotherKey: "path/to/some/other/example.ts",
146+
},
140147
};
141148
fs.writeFileSync(
142149
this.CONFIG_PATH,

src/services/LLM/LLMContextCreator.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ export class LLMContextCreator {
7777
const runOneTestCmd = config.runOneTestCmd || "yarn test {testPath}";
7878
const runTypeCheckCmd = config.runTypeCheckCmd || "yarn type-check";
7979

80+
// Add flexible reference examples section
81+
const referenceExamplesSection = Object.entries(
82+
config.referenceExamples || {},
83+
)
84+
.map(([key, path]) => `${key}: ${path}`)
85+
.join("\n");
86+
8087
return `# Project Dependencies (from ${info.dependencyFile})
8188
Main Dependencies: ${info.mainDependencies.join(", ")}
8289
@@ -88,7 +95,10 @@ ${Object.entries(info.scripts)
8895
# Test Commands
8996
Run All Tests: ${runAllTestsCmd}
9097
Run Single Test: ${runOneTestCmd}
91-
Run Type Check: ${runTypeCheckCmd}`;
98+
Run Type Check: ${runTypeCheckCmd}
99+
100+
# Reference Examples
101+
${referenceExamplesSection}`;
92102
}
93103

94104
private formatFirstTimeMessage(context: MessageContext): string {

src/services/LLM/__tests__/LLMContextCreator.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,49 @@ describe("LLMContextCreator", () => {
134134
expect(result).toContain(message);
135135
expect(result).not.toContain("file1\nfile2");
136136
});
137+
138+
it("should load config with flexible referenceExamples", async () => {
139+
const mockConfig = {
140+
includeAllFilesOnEnvToContext: true,
141+
referenceExamples: {
142+
serviceA: "src/services/ServiceA.ts",
143+
utilityB: "src/utils/UtilityB.ts",
144+
someOtherKey: "path/to/another/example.ts",
145+
},
146+
};
147+
148+
mocker.spyOnPrototypeAndReturn(ConfigService, "getConfig", mockConfig);
149+
150+
const result = await contextCreator.create(
151+
"test message",
152+
"/test/root",
153+
true,
154+
);
155+
156+
expect(result).toContain("Reference Examples");
157+
expect(result).toContain("serviceA: src/services/ServiceA.ts");
158+
expect(result).toContain("utilityB: src/utils/UtilityB.ts");
159+
expect(result).toContain("someOtherKey: path/to/another/example.ts");
160+
});
161+
162+
it("should use default empty object for referenceExamples when not provided", async () => {
163+
const mockConfig = {
164+
includeAllFilesOnEnvToContext: true,
165+
referenceExamples: {},
166+
};
167+
168+
mocker.spyOnPrototypeAndReturn(ConfigService, "getConfig", mockConfig);
169+
170+
const result = await contextCreator.create(
171+
"test message",
172+
"/test/root",
173+
true,
174+
);
175+
176+
expect(result).toContain("Reference Examples");
177+
expect(result).not.toContain("serviceA:");
178+
expect(result).not.toContain("utilityB:");
179+
});
137180
});
138181

139182
afterEach(() => {

src/services/LLM/__tests__/PhaseManager.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ describe("PhaseManager", () => {
4646
maxGlobalTries: 20,
4747
},
4848
],
49+
referenceExamples: {}, // Added referenceExamples
4950
};
5051

5152
beforeAll(() => {

0 commit comments

Comments
 (0)