Skip to content

Commit 2200f6f

Browse files
OrKoNDevtools-frontend LUCI CQ
authored andcommitted
[AI Assistance] keep track of processed files
Bug: 402034781 Change-Id: I86cd779ec19d39a8c86c1f436aa6f8087715f907 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6348899 Reviewed-by: Ergün Erdoğmuş <[email protected]> Auto-Submit: Alex Rudenko <[email protected]> Commit-Queue: Ergün Erdoğmuş <[email protected]>
1 parent 4319ae5 commit 2200f6f

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

front_end/panels/ai_assistance/AgentProject.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ describeWithEnvironment('AgentProject', () => {
5959
assert.deepEqual(project.readFile('index.html'), 'content');
6060
});
6161

62+
it('can report processed files', async () => {
63+
const {project} = await mockProject();
64+
assert.deepEqual(project.getProcessedFiles(), []);
65+
project.readFile('index.html');
66+
assert.deepEqual(project.getProcessedFiles(), ['index.html']);
67+
});
68+
6269
it('can write files files', async () => {
6370
const {project} = await mockProject();
6471
project.writeFile('index.html', 'updated');

front_end/panels/ai_assistance/AgentProject.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class AgentProject {
2222

2323
readonly #maxFilesChanged: number;
2424
readonly #maxLinesChanged: number;
25+
readonly #processedFiles = new Set<string>();
2526

2627
constructor(project: Workspace.Workspace.Project, options: {
2728
maxFilesChanged: number,
@@ -35,6 +36,14 @@ export class AgentProject {
3536
this.#maxLinesChanged = options.maxLinesChanged;
3637
}
3738

39+
/**
40+
* Returns a list of files from the project that has been used for
41+
* processing.
42+
*/
43+
getProcessedFiles(): string[] {
44+
return Array.from(this.#processedFiles);
45+
}
46+
3847
/**
3948
* Provides file names in the project to the agent.
4049
*/
@@ -52,6 +61,7 @@ export class AgentProject {
5261
if (!uiSourceCode) {
5362
return;
5463
}
64+
this.#processedFiles.add(filepath);
5565
// TODO: needs additional handling for binary files.
5666
return uiSourceCode.workingCopyContentData().text;
5767
}

front_end/panels/ai_assistance/PatchWidget.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,7 @@ export class PatchWidget extends UI.Widget.Widget {
465465
serverSideLoggingEnabled: false,
466466
project: this.#project,
467467
});
468-
const responses =
469-
await Array.fromAsync(agent.applyChanges(changeSummary, {signal: this.#applyPatchAbortController.signal}));
468+
const {responses} = await agent.applyChanges(changeSummary, {signal: this.#applyPatchAbortController.signal});
470469
return responses.at(-1);
471470
}
472471
}

front_end/panels/ai_assistance/agents/PatchAgent.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ describeWithEnvironment('PatchAgent', () => {
3737
})
3838
});
3939

40-
return await Array.fromAsync(agent.applyChanges('summary'));
40+
const {responses} = await agent.applyChanges('summary');
41+
42+
return responses;
4143
}
4244

4345
it('calls listFiles', async () => {

front_end/panels/ai_assistance/agents/PatchAgent.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,10 @@ ${content}
183183
});
184184
}
185185

186-
async *
187-
applyChanges(changeSummary: string, {signal}: {signal?: AbortSignal} = {}):
188-
AsyncGenerator<ResponseData, void, void> {
186+
async applyChanges(changeSummary: string, {signal}: {signal?: AbortSignal} = {}): Promise<{
187+
responses: ResponseData[],
188+
processedFiles: string[],
189+
}> {
189190
this.#changeSummary = changeSummary;
190191
const prompt =
191192
`I have applied the following CSS changes to my page in Chrome DevTools, what are the files in my source code that I need to change to apply the same change?
@@ -203,7 +204,11 @@ CRITICAL: before searching always call listFiles first.
203204
CRITICAL: never call updateFiles with files that do not need updates.
204205
`;
205206

206-
yield* this.run(prompt, {selected: null, signal});
207+
const responses = await Array.fromAsync(this.run(prompt, {selected: null, signal}));
208+
return {
209+
responses,
210+
processedFiles: this.#project.getProcessedFiles(),
211+
};
207212
}
208213
}
209214

0 commit comments

Comments
 (0)