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; }