Open kgilpin opened 1 month ago
Fix @generate
mode to recognize and use pinned context file names
When using the @generate
command in Navie, the generated code includes generic placeholders like /path/to/your/script.py
instead of recognizing and using the actual pinned file names. This leads to incorrect file references in the output, which can be erroneous and confusing.
The root cause of this issue is that the @generate
mode is currently not configured to handle the file names from the pinned context. When the context is passed to the navie package, it lacks proper handling to identify and use the pinned file names within the @generate
mode.
The main changes needed include:
@generate
mode to use these pinned file names for code generation.To solve this issue, the context should incorporate file names and content, and the @generate
mode should be adapted to observe and use this information.
Update PinFileRequest
class:
export class PinFileRequest {
name: string;
uri?: string;
content?: string;
constructor(arg: PinFileRequest) {
this.name = arg.name;
this.uri = arg.uri;
this.content = arg.content;
}
}
Update ContextItemMixin
in File.vue
to properly handle and pass pinned files in the context.
methods: {
onPin(evt: PinEvent) {
// Ensure pin event passes the file name and content
const pinFileRequest = new PinFileRequest({
name: this.header,
uri: this.location,
content: this.content,
});
this.$root.$emit('pin', pinFileRequest);
},
}
Ensure the AgentSelectionService
class handles and passes the pinned file context correctly when selecting the @generate
mode.
selectAgent(
question: string,
classification: ContextV2.ContextLabel[],
userOptions: UserOptions
): AgentModeResult {
let modifiedQuestion = question;
// Include contextual information with pinned files
const pinnedFileContext = classification.find(label => label.name === ContextV2.ContextLabelName.Generate);
const contextService = new ContextService(
this.history,
this.vectorTermsService,
this.lookupContextService,
this.applyContextService
);
const generateAgent = () => new GenerateAgent(this.history, contextService, this.fileChangeExtractorService);
const buildAgent: { [key in AgentMode]: () => Agent } = {
...
};
Update AgentMode.Generate
logic to make use of the pinned file name and content during code generation.
class GenerateAgent {
...
handleGenerate(question: string, context: ContextV2.ContextLabel[], userContext: UserOptions) {
const pinnedFile = context.find(ctx => ctx.name === ContextV2.ContextLabelName.Generate);
if (pinnedFile) {
question = question.replace('/path/to/your/script.py', pinnedFile.name);
}
...
}
}
By following these changes, the @generate
mode should properly observe and use provided file names in the pinned context, resulting in accurate file references during code generation.
In the first image, no code snippets are found. The instructions referencing a file are included as part of the code snippet prompt description, which will not be included in the absence of code snippets: https://github.com/getappmap/appmap-js/blob/main/packages/navie/src/services/apply-context-service.ts#L103-L110
When using the
@generate
command, Navie doesn't know the name of the pinned file.You can see how, in this screenshot, I have pinned a context file called "official.py".
Then I've asked a typical code generation question. Navie outputs code snippets referring to `/path/to/your/script.py' rather than the pinned file.
It will also propose (correct) changes to the wrong file name:
--
@generate
mode should observe and use the file names provided in the pinned context.