增加拓展cursor cli 方式调用模型#14
Conversation
There was a problem hiding this comment.
Pull request overview
该 PR 为 wechat-acp 增加通过 Cursor CLI 以 ACP 协议接入的内置 agent preset,并补齐与 Cursor ACP 交互时的一些兼容性与可观测性改进,使用户可以直接通过 --agent cursor 启动并调用 Cursor。
Changes:
- 新增内置
cursoragent preset(cursor agent acp)并在 README 中补充使用说明 - 在创建 ACP session 前,支持按 agent 广播的 auth methods 进行
authenticate(优先cursor_login) - 改进错误日志输出与 permission auto-allow 的 kind 匹配兼容性(snake_case / kebab-case)
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/config.ts | 增加 cursor 内置 preset(command/args) |
| src/bridge.ts | enqueue 失败日志改为结构化错误格式输出 |
| src/acp/client.ts | permission auto-allow 支持更多 kind 命名风格 |
| src/acp/agent-manager.ts | 初始化后新增可选的 ACP authenticate 流程(支持 Cursor) |
| README.md | 文档补充 cursor preset 与登录提示 |
| CHANGELOG.md | 记录 Unreleased 变更点 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const authMethod = pickAuthMethod(initResult.authMethods); | ||
| if (authMethod) { | ||
| log(`Authenticating ACP client via "${authMethod}"...`); | ||
| await connection.authenticate({ methodId: authMethod }); | ||
| log("ACP authentication completed"); | ||
| } |
There was a problem hiding this comment.
If initialization/authentication/session creation throws (e.g., authenticate fails), the spawned agent process is not cleaned up and can be left running. Wrap the init/auth/newSession sequence in a try/catch (or try/finally) that kills the child process on failure before rethrowing so failed sessions don’t leak processes.
| } | ||
| if (typeof err === "string") return err; | ||
| try { | ||
| return JSON.stringify(err); |
There was a problem hiding this comment.
JSON.stringify can return undefined for values like undefined, functions, or symbols. Since formatError is typed to return string, ensure the JSON branch always returns a string (e.g., fall back to String(err) when stringify returns a non-string) so log output is consistent.
| return JSON.stringify(err); | |
| const json = JSON.stringify(err); | |
| return typeof json === "string" ? json : String(err); |
| }); | ||
| log(`ACP initialized (protocol v${initResult.protocolVersion})`); | ||
|
|
||
| const authMethod = pickAuthMethod(initResult.authMethods); |
There was a problem hiding this comment.
Per https://agentclientprotocol.com/protocol/schema#session/new: May return an auth_required error if the agent requires authentication., so only when getting an auth_required, we need to trigger auth flow.
| if (!authMethods || authMethods.length === 0) return null; | ||
|
|
||
| // Prefer cursor_login when available, then fallback to first advertised method. | ||
| const cursorLogin = authMethods.find((method) => method.id === "cursor_login"); |
There was a problem hiding this comment.
A little hacky here, we'd better not have code specific to a certain Agent.
|
|
||
| // Prefer cursor_login when available, then fallback to first advertised method. | ||
| const cursorLogin = authMethods.find((method) => method.id === "cursor_login"); | ||
| return cursorLogin?.id ?? authMethods[0]?.id ?? null; |
There was a problem hiding this comment.
We'd better to allow user to select auth method.
| export const BUILT_IN_AGENTS: Record<string, AgentPreset> = { | ||
| cursor: { | ||
| label: "Cursor Agent (ACP)", | ||
| command: "cursor", |
There was a problem hiding this comment.
From the docs (https://cursor.com/docs/cli/overview), it seems to be agent not cursor?
…ission messages formulahendry#14: daemonize() now detects TypeScript source and replaces the .ts entry with compiled dist/bin/wechat-acp.js for the child process. Prints a clear error if the compiled file doesn't exist (user forgot to run 'npm run build'). formulahendry#15: Add in-memory lastContextToken map updated from handleMessage. handlePermissionRequest reads it and passes it to sendReply instead of hardcoded empty string. Falls back to '' when no message has been received yet.
增加拓展cursor cli 方式调用模型,需要先安装cursor cli脚手架,然后登陆cursor cli,启动项目(node dist/bin/wechat-acp.js --agent cursor
)就可以调用cursor