summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorCastor Regex <[email protected]>2025-10-22 05:31:24 -0500
committerJeff Carr <[email protected]>2025-10-22 05:31:24 -0500
commita0c590944ff82d3584a532cd7400689297735757 (patch)
tree60ba1506f7ea2ec2aaa630e2ab4abfa16681f950 /packages
parent1799aac8ae4355bf912238c650856e82da641f6d (diff)
feat: add support for .proto files
Diffstat (limited to 'packages')
-rw-r--r--packages/cli/src/zed-integration/fileSystemService.ts4
-rw-r--r--packages/core/package.json1
-rw-r--r--packages/core/src/services/fileSystemService.ts14
-rw-r--r--packages/core/src/utils/fileUtils.ts15
4 files changed, 33 insertions, 1 deletions
diff --git a/packages/cli/src/zed-integration/fileSystemService.ts b/packages/cli/src/zed-integration/fileSystemService.ts
index deb9857f..8e9bd9a4 100644
--- a/packages/cli/src/zed-integration/fileSystemService.ts
+++ b/packages/cli/src/zed-integration/fileSystemService.ts
@@ -33,6 +33,10 @@ export class AcpFileSystemService implements FileSystemService {
return response.content;
}
+ async readProtoFile(filePath: string): Promise<string> {
+ return this.fallback.readProtoFile(filePath);
+ }
+
async writeTextFile(filePath: string, content: string): Promise<void> {
if (!this.capabilities.writeTextFile) {
return this.fallback.writeTextFile(filePath, content);
diff --git a/packages/core/package.json b/packages/core/package.json
index a694924c..a5ca0fb8 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -54,6 +54,7 @@
"strip-ansi": "^7.1.0",
"undici": "^7.10.0",
"ws": "^8.18.0",
+ "protobufjs": "^7.3.2",
"@xterm/headless": "5.5.0"
},
"optionalDependencies": {
diff --git a/packages/core/src/services/fileSystemService.ts b/packages/core/src/services/fileSystemService.ts
index e2f30cf4..3e4cd30f 100644
--- a/packages/core/src/services/fileSystemService.ts
+++ b/packages/core/src/services/fileSystemService.ts
@@ -5,6 +5,7 @@
*/
import fs from 'fs/promises';
+import protobuf from 'protobufjs';
/**
* Interface for file system operations that may be delegated to different implementations
@@ -19,6 +20,14 @@ export interface FileSystemService {
readTextFile(filePath: string): Promise<string>;
/**
+ * Read and parse a proto file
+ *
+ * @param filePath - The path to the file to read
+ * @returns The file content as a JSON string
+ */
+ readProtoFile(filePath: string): Promise<string>;
+
+ /**
* Write text content to a file
*
* @param filePath - The path to the file to write
@@ -35,6 +44,11 @@ export class StandardFileSystemService implements FileSystemService {
return fs.readFile(filePath, 'utf-8');
}
+ async readProtoFile(filePath: string): Promise<string> {
+ const root = await protobuf.load(filePath);
+ return JSON.stringify(root.toJSON(), null, 2);
+ }
+
async writeTextFile(filePath: string, content: string): Promise<void> {
await fs.writeFile(filePath, content, 'utf-8');
}
diff --git a/packages/core/src/utils/fileUtils.ts b/packages/core/src/utils/fileUtils.ts
index f0b491ed..009a4d72 100644
--- a/packages/core/src/utils/fileUtils.ts
+++ b/packages/core/src/utils/fileUtils.ts
@@ -121,7 +121,9 @@ export async function isBinaryFile(filePath: string): Promise<boolean> {
*/
export async function detectFileType(
filePath: string,
-): Promise<'text' | 'image' | 'pdf' | 'audio' | 'video' | 'binary' | 'svg'> {
+): Promise<
+ 'text' | 'image' | 'pdf' | 'audio' | 'video' | 'binary' | 'svg' | 'proto'
+> {
const ext = path.extname(filePath).toLowerCase();
// The mimetype for various TypeScript extensions (ts, mts, cts, tsx) can be
@@ -135,6 +137,10 @@ export async function detectFileType(
return 'svg';
}
+ if (ext === '.proto') {
+ return 'proto';
+ }
+
const lookedUpMimeType = mime.lookup(filePath); // Returns false if not found, or the mime type string
if (lookedUpMimeType) {
if (lookedUpMimeType.startsWith('image/')) {
@@ -280,6 +286,13 @@ export async function processSingleFileContent(
returnDisplay: `Read SVG as text: ${relativePathForDisplay}`,
};
}
+ case 'proto': {
+ const content = await fileSystemService.readProtoFile(filePath);
+ return {
+ llmContent: content,
+ returnDisplay: `Read proto file: ${relativePathForDisplay}`,
+ };
+ }
case 'text': {
const content = await fileSystemService.readTextFile(filePath);
const lines = content.split('\n');