From 487c48effaddafecd6c1e6671d57317c6761534b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=A9=98?= Date: Fri, 22 May 2026 09:39:36 +0000 Subject: [PATCH] fix: revert output protocol changes from #385 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Agent CLI outputs plain CAS hash (not JSON), engine parses plain hash. StepOutput no longer carries sessionId — session info is already in CAS detail. Keeps the valuable parts of #385: sessionId in AgentRunResult (process-internal), continue support, and frontmatter retry loop. --- packages/cli-workflow/src/commands/thread.ts | 31 +++----------------- packages/workflow-agent-kit/src/run.ts | 16 +--------- packages/workflow-protocol/src/types.ts | 1 - 3 files changed, 5 insertions(+), 43 deletions(-) diff --git a/packages/cli-workflow/src/commands/thread.ts b/packages/cli-workflow/src/commands/thread.ts index f695e30..e7146be 100644 --- a/packages/cli-workflow/src/commands/thread.ts +++ b/packages/cli-workflow/src/commands/thread.ts @@ -200,7 +200,6 @@ export async function cmdThreadShow(storageRoot: string, threadId: ThreadId): Pr thread: threadId, head: activeHead, done: false, - sessionId: null, }; } @@ -211,7 +210,6 @@ export async function cmdThreadShow(storageRoot: string, threadId: ThreadId): Pr thread: threadId, head: hist.head, done: true, - sessionId: null, }; } @@ -626,12 +624,7 @@ function resolveAgentConfig( return agentConfig; } -type SpawnAgentResult = { - stepHash: CasRef; - sessionId: string | null; -}; - -function spawnAgent(agent: AgentConfig, threadId: ThreadId, role: string): SpawnAgentResult { +function spawnAgent(agent: AgentConfig, threadId: ThreadId, role: string): CasRef { const argv = [...agent.args, threadId, role]; let stdout: string; try { @@ -653,24 +646,10 @@ function spawnAgent(agent: AgentConfig, threadId: ThreadId, role: string): Spawn } const line = stdout.trim().split("\n").pop()?.trim() ?? ""; - - // Try JSON output first (new protocol) - try { - const parsed = JSON.parse(line) as Record; - const stepHash = parsed.stepHash; - const sessionId = parsed.sessionId; - if (typeof stepHash === "string" && isCasRef(stepHash) && typeof sessionId === "string") { - return { stepHash, sessionId }; - } - } catch { - // Not JSON — fall through to legacy CAS hash parsing - } - - // Legacy: plain CAS hash on stdout if (!isCasRef(line)) { - fail(`agent stdout is not a valid CAS hash or JSON: ${line || "(empty)"}`); + fail(`agent stdout is not a valid CAS hash: ${line || "(empty)"}`); } - return { stepHash: line, sessionId: null }; + return line; } async function archiveThread( @@ -719,7 +698,6 @@ export async function cmdThreadStep( thread: threadId, head: headHash, done: true, - sessionId: null, }; } @@ -728,7 +706,7 @@ export async function cmdThreadStep( const agent = resolveAgentConfig(config, workflow, role, agentOverride); loadDotenv({ path: getEnvPath(storageRoot) }); - const { stepHash: newHead, sessionId } = spawnAgent(agent, threadId, role); + const newHead = spawnAgent(agent, threadId, role); // Re-create store to pick up nodes written by the agent subprocess const uwfAfter = await createUwfStore(storageRoot); @@ -759,7 +737,6 @@ export async function cmdThreadStep( thread: threadId, head: newHead, done, - sessionId, }; } diff --git a/packages/workflow-agent-kit/src/run.ts b/packages/workflow-agent-kit/src/run.ts index 0083d21..73f7e58 100644 --- a/packages/workflow-agent-kit/src/run.ts +++ b/packages/workflow-agent-kit/src/run.ts @@ -98,19 +98,6 @@ async function persistStep(options: { }); } -export type AgentCliOutput = { - stepHash: CasRef; - sessionId: string; -}; - -/** - * Create an agent CLI entrypoint. - * Parses argv (` `), runs the agent, extracts structured output, - * writes StepNode to CAS, and prints JSON result to stdout. - * - * If frontmatter extraction fails, retries up to MAX_FRONTMATTER_RETRIES times - * by calling agent.continue() with a correction message. - */ export function createAgent(options: AgentOptions): () => Promise { return async function main(): Promise { const { threadId, role } = parseArgv(process.argv); @@ -161,7 +148,6 @@ export function createAgent(options: AgentOptions): () => Promise { agentName: agentLabel(options.name), }); - const result: AgentCliOutput = { stepHash, sessionId: agentResult.sessionId }; - process.stdout.write(`${JSON.stringify(result)}\n`); + process.stdout.write(`${stepHash}\n`); }; } diff --git a/packages/workflow-protocol/src/types.ts b/packages/workflow-protocol/src/types.ts index ec43431..8960f0c 100644 --- a/packages/workflow-protocol/src/types.ts +++ b/packages/workflow-protocol/src/types.ts @@ -81,7 +81,6 @@ export type StepOutput = { thread: ThreadId; head: CasRef; done: boolean; - sessionId: string | null; }; /** uwf thread steps — single step entry */