Переглянути джерело

Merge pull request #873 from shixi-li/fix/acp-client-info-version

fix: send ACP client version during initialization
Alvin 1 тиждень тому
батько
коміт
1f5b256d5c
2 змінених файлів з 32 додано та 8 видалено
  1. 19 0
      src/tools/acp-run.test.ts
  2. 13 8
      src/tools/acp-run.ts

+ 19 - 0
src/tools/acp-run.test.ts

@@ -0,0 +1,19 @@
+import { describe, expect, test } from 'bun:test';
+import packageJson from '../../package.json' with { type: 'json' };
+import { createAcpInitializeParams } from './acp-run';
+
+describe('ACP initialize payload', () => {
+  test('sends protocol-compliant client implementation information', () => {
+    const params = createAcpInitializeParams();
+
+    expect(params).toEqual({
+      protocolVersion: 1,
+      clientCapabilities: {},
+      clientInfo: {
+        name: 'oh-my-opencode-slim',
+        version: packageJson.version,
+      },
+    });
+    expect(params.clientInfo).not.toHaveProperty('title');
+  });
+});

+ 13 - 8
src/tools/acp-run.ts

@@ -1,6 +1,7 @@
 import { type ChildProcessWithoutNullStreams, spawn } from 'node:child_process';
 import { createInterface } from 'node:readline';
 import { type ToolDefinition, tool } from '@opencode-ai/plugin';
+import packageJson from '../../package.json' with { type: 'json' };
 import {
   type AcpAgentConfig,
   type AcpAgentsConfig,
@@ -33,6 +34,17 @@ type Pending = {
   reject: (error: Error) => void;
 };
 
+export function createAcpInitializeParams() {
+  return {
+    protocolVersion: 1,
+    clientCapabilities: {},
+    clientInfo: {
+      name: 'oh-my-opencode-slim',
+      version: packageJson.version,
+    },
+  };
+}
+
 class AcpClient {
   private child: ChildProcessWithoutNullStreams;
   private next = 1;
@@ -86,14 +98,7 @@ class AcpClient {
   }
 
   async run(prompt: string): Promise<string> {
-    const init = await this.request('initialize', {
-      protocolVersion: 1,
-      clientCapabilities: {},
-      clientInfo: {
-        name: 'oh-my-opencode-slim',
-        title: 'oh-my-opencode-slim ACP bridge',
-      },
-    });
+    const init = await this.request('initialize', createAcpInitializeParams());
     this.authMethods = readAuthMethods(init);
     const created = await this.newSession();
     const sessionId = readSessionId(created);