refactor: migrate hermes agent from stdout parsing to ACP protocol #401
Reference in New Issue
Block a user
Delete Branch "feat/398-hermes-acp-client"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Replace fragile stdout/stderr parsing with structured ACP (Agent Communication Protocol) for hermes agent communication.
Why
spawnHermeshad a known race condition (#380) — Node.js pipe buffers could be empty on process exit, causing session_id extraction to fail. The root cause was fundamental: mixing structured data with unstructured output.Changes
src/acp-client.ts(new) —HermesAcpClientclass implementing JSON-RPC over stdin/stdout withhermes acpsrc/hermes.ts— replacedspawnHermes/parseSessionIdwith ACP client calls (165→86 lines, -48%)__tests__/acp-client.test.ts(new) — 3 integration tests for connect/prompt/resumesrc/index.ts— exportHermesAcpClientRemoved
spawnHermes,spawnHermesChat,spawnHermesResume,parseSessionId,buildResultFromSessionHow ACP Works
Session ID from protocol response directly — no regex parsing, no race conditions.
Testing
Ref
Fixes #380
Phase 1 #399 + Phase 2 #400 of RFC #398
ACP 迁移方向正确,解决了 stdout race condition。一个设计问题:
continueHermes丢失 session 上下文runHermes在finally里关闭了 ACP client,等 frontmatter retry 调continueHermes时,只能创建全新 session。correction message 说「你上次输出没有正确 frontmatter」,但新 session 没有之前的对话历史,agent 不知道「上次」是什么,retry 等于无效。建议方案:
runHermes不关 client,把HermesAcpClient实例通过闭包或返回值传给continueHermesAgentRunResult里带上 client 引用,retry 循环结束后统一 close另外一个小退步:detail 存储从
storeHermesSessionDetail(结构化 turns)退化成storeHermesRawOutput(纯文本)。可以接受但值得记录为后续 TODO。— 小墨 🖊️
The client is now created once in createHermesAgent() and shared by runHermes and continueHermes closures. This preserves conversation context during frontmatter retry loops — continue() sends a follow-up prompt on the same ACP session instead of starting a new one. Client is cleaned up via process.on('exit'). Ref #398LGTM ✅ session 复用和结构化 detail 都到位了。
— 小墨 🖊️