From 546237db85fc1aea14f8bf48a73b3bb28cacde3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=A9=98?= Date: Mon, 18 May 2026 16:57:24 +0000 Subject: [PATCH] fix: parseSessionIdFromStdout scans all lines, not just last --quiet mode outputs session_id on the first line, not the last. The old code only checked the last non-empty line and broke immediately if it didn't match, causing session detail to always be empty. Fixes the empty detail bug when hermes agent runs in quiet mode. --- .../__tests__/session-detail.test.ts | 7 ++++++- packages/uwf-agent-hermes/src/session-detail.ts | 13 ++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/uwf-agent-hermes/__tests__/session-detail.test.ts b/packages/uwf-agent-hermes/__tests__/session-detail.test.ts index 311b098..b1dfb00 100644 --- a/packages/uwf-agent-hermes/__tests__/session-detail.test.ts +++ b/packages/uwf-agent-hermes/__tests__/session-detail.test.ts @@ -16,7 +16,12 @@ describe("parseSessionIdFromStdout", () => { expect(parseSessionIdFromStdout(stdout)).toBe("20260518_223724_45ab80"); }); - test("returns null when trailing line is not session_id", () => { + test("reads session_id from the first line (quiet mode)", () => { + const stdout = "session_id: 20260518_165315_3467a1\nHello world\n"; + expect(parseSessionIdFromStdout(stdout)).toBe("20260518_165315_3467a1"); + }); + + test("returns null when no session_id line present", () => { expect(parseSessionIdFromStdout("only assistant text\n")).toBeNull(); }); }); diff --git a/packages/uwf-agent-hermes/src/session-detail.ts b/packages/uwf-agent-hermes/src/session-detail.ts index 3e29f6d..e95487e 100644 --- a/packages/uwf-agent-hermes/src/session-detail.ts +++ b/packages/uwf-agent-hermes/src/session-detail.ts @@ -24,19 +24,14 @@ export function getHermesSessionPath(sessionId: string): string { return join(getHermesSessionsDir(), `session_${sessionId}.json`); } -/** Parse `session_id: …` from the last non-empty line of Hermes stdout. */ +/** Parse `session_id: …` from any line of Hermes stdout. */ export function parseSessionIdFromStdout(stdout: string): string | null { - const lines = stdout.split(/\r?\n/).map((line) => line.trim()); - for (let i = lines.length - 1; i >= 0; i--) { - const line = lines[i]; - if (line === undefined || line === "") { - continue; - } - const match = SESSION_ID_LINE.exec(line); + const lines = stdout.split(/\r?\n/); + for (const line of lines) { + const match = SESSION_ID_LINE.exec(line.trim()); if (match?.[1] !== undefined) { return match[1]; } - break; } return null; } -- 2.43.0