Skip to content

Commit 0b18d91

Browse files
committed
fix: context files in prompts not working
Fixes that the macro for `contextFiles` stopped working.
1 parent 3b40bba commit 0b18d91

File tree

4 files changed

+12
-28
lines changed

4 files changed

+12
-28
lines changed

runner/configuration/environment.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import {
77
RootPromptDefinition,
88
} from '../shared-interfaces.js';
99
import { Rating } from '../ratings/rating-types.js';
10-
import {
11-
extractPromptContextFilePatterns,
12-
renderHandlebarsTemplate,
13-
} from './prompt-templating.js';
10+
import { renderHandlebarsTemplate } from './prompt-templating.js';
1411
import { McpServerOptions } from '../codegen/llm-runner.js';
1512
import { lazy } from '../utils/lazy-creation.js';
1613
import { EnvironmentConfig } from './environment-config.js';
@@ -120,21 +117,21 @@ export class Environment {
120117
}
121118

122119
systemPromptGeneration = lazy(() => {
123-
return this.renderRelativePrompt(this.config.generationSystemPrompt);
120+
return this.renderRelativePrompt(this.config.generationSystemPrompt).result;
124121
});
125122

126123
systemPromptRepair = lazy(() => {
127124
if (!this.config.repairSystemPrompt) {
128125
return 'Please fix the given errors and return the corrected code.';
129126
}
130-
return this.renderRelativePrompt(this.config.repairSystemPrompt);
127+
return this.renderRelativePrompt(this.config.repairSystemPrompt).result;
131128
});
132129

133130
systemPromptEditing = lazy(() => {
134131
if (!this.config.editingSystemPrompt) {
135132
return this.systemPromptGeneration();
136133
}
137-
return this.renderRelativePrompt(this.config.editingSystemPrompt);
134+
return this.renderRelativePrompt(this.config.editingSystemPrompt).result;
138135
});
139136

140137
/**
@@ -275,14 +272,12 @@ export class Environment {
275272
ratings: Rating[],
276273
isEditing: boolean
277274
): PromptDefinition {
278-
const { promptText, contextFiles } = extractPromptContextFilePatterns(
279-
this.renderRelativePrompt(relativePath)
280-
);
275+
const { result, contextFiles } = this.renderRelativePrompt(relativePath);
281276

282277
return {
283278
name: name,
284279
kind: 'single',
285-
prompt: promptText,
280+
prompt: result,
286281
ratings,
287282
systemPromptType: isEditing ? 'editing' : 'generation',
288283
contextFilePatterns: contextFiles,
@@ -387,7 +382,7 @@ export class Environment {
387382
}
388383

389384
/** Renders a prompt from a path relative to the environment config. */
390-
private renderRelativePrompt(relativePath: string): string {
385+
private renderRelativePrompt(relativePath: string) {
391386
const path = resolve(this.rootPath, relativePath);
392387
return this.renderPrompt(readFileSync(path, 'utf8'), path);
393388
}

runner/configuration/prompt-templating.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,10 @@ initializeHandlebars();
3535
export function renderHandlebarsTemplate<T extends { rootDir: string | null }>(
3636
content: string,
3737
ctx: T
38-
): string {
38+
) {
3939
const template = Handlebars.compile(content, { strict: true });
40-
return template(ctx);
41-
}
42-
43-
/**
44-
* Extracts the context file patterns from a prompt's text. Returns the prompt's text without
45-
* any special context file syntax and the context file patterns.
46-
* @param initialPromptText Initial text of the prompt.
47-
*/
48-
export function extractPromptContextFilePatterns(initialPromptText: string) {
4940
const contextFiles: string[] = [];
50-
const promptText = Handlebars.compile(initialPromptText, {
51-
strict: true,
52-
})(null, {
41+
const result = template(ctx, {
5342
partials: {
5443
contextFiles: (ctx) => {
5544
if (typeof ctx !== 'string') {
@@ -84,7 +73,7 @@ export function extractPromptContextFilePatterns(initialPromptText: string) {
8473
});
8574

8675
return {
87-
promptText,
76+
result,
8877
contextFiles,
8978
};
9079
}

runner/ratings/autoraters/code-rater.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export async function autoRateCode(
6464
const prompt = environment.renderPrompt(promptText, null, {
6565
APP_PROMPT: appPrompt,
6666
FRAMEWORK_SPECIFIC_HINTS: FW_HINTS[environment.fullStackFramework.id] ?? '',
67-
});
67+
}).result;
6868

6969
const result = await llm.generateConstrained({
7070
abortSignal,

runner/ratings/autoraters/visuals-rater.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function autoRateAppearance(
3131
): Promise<AutoRateResult> {
3232
const prompt = environment.renderPrompt(defaultVisualRaterPrompt, null, {
3333
APP_PROMPT: appPrompt,
34-
});
34+
}).result;
3535

3636
const messages: PromptDataMessage[] = [
3737
{

0 commit comments

Comments
 (0)