Merge pull request 'fix: hermes agent empty detail — parse session_id from any line' (#347) from fix/342-parse-session-id into main
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user