Skip to content

Commit 21cb345

Browse files
committed
fix: correct handling of files to modify/create during analysis
1 parent 0bc11a7 commit 21cb345

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

src/helpers/xml.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const allowedAttributes = [
44
"path",
55
"required",
66
"type",
7+
"why",
78
"dependencies",
89
"description",
910
"name",

src/scripts/file-modifier.ts

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,10 @@ export async function executeProjectFilesAnalysis({
148148
tokenCount: currentBatchTokens,
149149
});
150150

151-
const {
152-
object: partialProjectAnalysis,
153-
usage,
154-
experimental_providerMetadata,
155-
} = await generateObject({
156-
model: anthropic("claude-3-5-sonnet-latest", {
157-
cacheControl: true,
158-
}),
159-
schema: projectFilesAnalysisSchema,
160-
messages: [
161-
{
162-
role: "system",
163-
content: dedent`
151+
const messages = [
152+
{
153+
role: "system" as const,
154+
content: dedent`
164155
You are an experienced software developer specialized in Next.js ecosystem working as assistant that analyzes which source code files need modifications, which ones needs to be created and which needs to be deleted.
165156
166157
Base on user request specified in <request> section. You follow strict rules, defined in the <rules> section. There are also <good> and <bad> examples and a way of thinking defined in <thinking> and <examples> sections.
@@ -171,7 +162,7 @@ export async function executeProjectFilesAnalysis({
171162
rules: {
172163
rule: [
173164
"Focus on code and configuration files",
174-
"Do not mark files not present in the <files> section as modifications, all files that are meant to be created must not be included in the <files> section",
165+
"Does the file exist in <files>? If YES -> MUST use `files_to_modify`, If NO -> MUST use `files_to_create` in output",
175166
"Include files that need both direct and indirect modifications",
176167
"Analyze the coupling between various modules",
177168
"Include related configuration files",
@@ -265,15 +256,15 @@ export async function executeProjectFilesAnalysis({
265256
},
266257
})}
267258
`,
268-
},
269-
{
270-
role: "user",
271-
content: dedent`
259+
},
260+
{
261+
role: "user" as const,
262+
content: dedent`
272263
Files that you need to work on:
273264
274265
${xml.build({
275266
files: {
276-
file: Object.entries(projectFiles).map(
267+
file: Object.entries(currentBatchProjectFiles).map(
277268
([projectFilePath, projectFileContent]) => ({
278269
"@_path": projectFilePath,
279270
"#text": projectFileContent,
@@ -283,15 +274,15 @@ export async function executeProjectFilesAnalysis({
283274
})}
284275
`,
285276

286-
experimental_providerMetadata: {
287-
anthropic: {
288-
cacheControl: { type: "ephemeral" },
289-
},
277+
experimental_providerMetadata: {
278+
anthropic: {
279+
cacheControl: { type: "ephemeral" },
290280
},
291281
},
292-
{
293-
role: "user",
294-
content: dedent`
282+
},
283+
{
284+
role: "user" as const,
285+
content: dedent`
295286
User request for you:
296287
297288
${xml.build({
@@ -300,8 +291,21 @@ export async function executeProjectFilesAnalysis({
300291
},
301292
})}
302293
`,
303-
},
304-
],
294+
},
295+
];
296+
297+
detailedLogger.verboseLog("Project analysis prompt:", messages)
298+
299+
const {
300+
object: partialProjectAnalysis,
301+
usage,
302+
experimental_providerMetadata,
303+
} = await generateObject({
304+
model: anthropic("claude-3-5-sonnet-latest", {
305+
cacheControl: true,
306+
}),
307+
schema: projectFilesAnalysisSchema,
308+
messages,
305309
});
306310

307311
detailedLogger.usageLog("Analysis generation usage metrics", {
@@ -358,7 +362,7 @@ export async function executeSingleFileModifications({
358362
path: projectFileModification.path,
359363
operation: projectFileModification.operation,
360364
why: projectFileModification.why,
361-
originalContent: projectFileModification.content
365+
originalContent: projectFileModification.content,
362366
});
363367

364368
if (projectFileModification.operation === "create") {

0 commit comments

Comments
 (0)