Open dustinbyrne opened 1 month ago
Actually, I get it - Navie can't call RPC. So maybe we can reformulate as UI -> RPC "apply" -> calls Navie to get the FileUpdate -> applies file update
. I'll provide an updated proposal.
Title
Implement RPC Command for File Update
Problem
Users need to apply file changes proposed by Navie in their code editor, but since Navie might not be running locally, all file operations must be handled by a separate JSON RPC service. This service must be able to either create new files or update existing files based on the proposed changes received from Navie.
Analysis
To solve this problem, the JSON RPC service (file.update
command) needs to handle:
The file.update
RPC command needs to perform these steps using a defined structure for the incoming request and the response from Navie (formatted with XML tags).
Proposed Changes
New Directory for File Commands:
packages/cli/src/rpc/file
.New File for Update Command:
packages/cli/src/rpc/file/update.ts
to implement the file.update
RPC command.Implementing File Update Logic:
Leverage File-Update Logic:
file-update-service.ts
to apply the proposed changes to the file.File: packages/cli/src/rpc/file/update.ts
fs
for filesystem operations.file.update
which accepts a path
and content
as input arguments.Navie AI @update command
to get the proposed changes, passing the existing content as codeSelection
and proposed change as question
.original
and modified
content sections.original
content is in the file.original
content with the modified
content.This approach makes sure that the file updates are handled correctly even when Navie is running remotely, and all filesystem operations are managed by the JSON RPC service.
flowchart TD
subgraph "Code Editor"
A["User requests file update"]
end
subgraph "RPC Service"
A --> B["RPC file.update"]
B --> C(["Check if file exists"])
C -->|No| D["Create file with provided content"]
C -->|Yes| E["Read existing file content"]
E --> F["Send content to Navie @update command"]
F --> G["Validate original content in file"]
G -->|Valid| H(["Replace original content with modified content"])
G --->|Invalid| I["Error: Original content not found"]
end
subgraph "Navie Service"
F --> J["Process @update command"]
J --> K[/"FileUpdate: { original, modified }"/]
K --> G
end
I generated the plan above using the following prompt (which I edited as an unnamed file in VSCode, then selected all the text and simply typed @plan
)
# Title
AppMap can apply code changes to files.
# Summary
In the course of using Navie AI UI, Navie suggests code changes to files.
The user can choose to apply the change to the actual file on the filesystem.
The file change might be a new file or an update to an existing file.
The JSON RPC service provides a new commands to modify a file: file.update.
RPC file.update accepts the following type as the argument: export type File = {
path: string;
content: string;
};
RPC file.update first checks if the file exists, or not.
If the file does not exist, it creates the file with the provided content.
If the file exists, RPC file.update reads the content of the existing file. It then passes the
proposed change and the existing content to the Navie AI command @update.
THe existing file content is passed as the codeSelection parameter. The proposed change is passed as the
"question".
The Navie AI @update command returns the following type, formatted with XML tags.
export type FileUpdate = {
// Lines from the original content that should be replaced.
original: string;
// Updated content to be applied in place of the original content.
modified: string;
};
An example:
\`\`\`xml
<change>
<original>
// This is the original content that should be replaced.
// It can be multiple lines.
</original>
<modified>
// This is the updated content that should replace the original content.
// It can be multiple lines.
</modified>
</change>
\`\`\`
RPC file.update checks that the `original` content exists in the file. Then in replaces that matching
region with the `modified` content.
# Architecture
The UI runs as an extension in the user's code editor.
The JSON RPC service runs as a separate process on the same machine as the code editor.
The Navie service can either be running in-process with the JSON RPC service, or it can be running
on a remote server.
# Considerations
The Navie project cannot update files directly, because in some deployments it is not running on the
same machine as the user's filesystem. Therefore, all file operations must be performed by the JSON RPC layer.
The RPC layer is implemented in packages/cli/src/rpc. File commands should be located in packages/cli/src/rpc/file.
Each RPC command should be implemented in a separate file, such as packages/cli/src/rpc/file/update.ts.
The file.update method can use logic from the Navie code in file-update-service.ts
Don't try and reuse or refactor the logic in file-update-service.ts.
Problem
The CLI needs a new RPC method that allows for code changes to be applied to a specific file. This method should take in a file path and new code content, and then use the language model (LLM) provided by
packages/navie
to determine the best way to apply these changes to the file's existing content.Analysis
To implement this feature, the following steps need to be taken:
Proposed Changes
Files to be Modified:
Specific changes per file:
rpcHandler.ts
:packages/cli/src/rpcHandler.ts
applyCodeChanges
RPC method.filePath
andnewCode
.fileOperations.ts
:packages/cli/src/fileOperations.ts
filePath
.filePath
.llmIntegration.ts
:packages/cli/src/llmIntegration.ts
newCode
.existingContent
andnewCode
as inputs and return themodifiedContent
.Detailed Implementation Plan
Add RPC Handler:
packages/cli/src/rpcHandler.ts
Method Signature:
Implement File Reading and Writing Operations:
packages/cli/src/fileOperations.ts
Functions to Implement:
async function readFileContent(filePath: string): Promise {
return await readFile(filePath, 'utf-8');
}
Integrate Navie LLM to Identify Code Insertion Points:
packages/cli/src/llmIntegration.ts
Function to Implement:
async function useNavieLLMToInsertCode(existingContent: string, newCode: string): Promise {
// Interface with the Navie LLM service
const response = await analyzeAndInsert(existingContent, newCode);
if (response.success) { return response.modifiedContent; } else { throw new Error('Navie LLM failed to determine code insertion point'); } }
Summary
By adding these changes, the CLI will be able to apply new code to a given file path intelligently using the Navie LLM. This includes reading the current file content, utilizing the Navie LLM to determine how and where to insert the new code, and writing the updated content back to the file. This new RPC method will allow developers to programmatically modify files with the intelligence of Navie LLM to ensure changes are applied correctly and efficiently.
Related to #1894