From 19ed5e693661b1696c07c0cef3152f7f9ba78e8f Mon Sep 17 00:00:00 2001 From: Kral <118106297+dashitongzhi@users.noreply.github.com> Date: Sun, 21 Jun 2026 09:06:40 +0800 Subject: [PATCH] fix(memos-local-plugin): detect Hermes chat with global flags --- apps/memos-local-plugin/bridge.cts | 4 +- .../tests/unit/bridge-status.test.ts | 40 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 apps/memos-local-plugin/tests/unit/bridge-status.test.ts diff --git a/apps/memos-local-plugin/bridge.cts b/apps/memos-local-plugin/bridge.cts index 81848acf7..dcd2c3c34 100644 --- a/apps/memos-local-plugin/bridge.cts +++ b/apps/memos-local-plugin/bridge.cts @@ -679,9 +679,11 @@ function createBridgeStatusTracker(statusFile: string, daemon: boolean): { }; } +const HERMES_CHAT_PROCESS_PATTERN = "hermes(?:\\s+\\S+)*\\s+chat\\b"; + function isHermesChatRunning(): boolean { try { - const out = childProcess.execFileSync("pgrep", ["-f", "hermes chat"], { + const out = childProcess.execFileSync("pgrep", ["-f", HERMES_CHAT_PROCESS_PATTERN], { encoding: "utf8", timeout: 1000, }); diff --git a/apps/memos-local-plugin/tests/unit/bridge-status.test.ts b/apps/memos-local-plugin/tests/unit/bridge-status.test.ts new file mode 100644 index 000000000..fc1463086 --- /dev/null +++ b/apps/memos-local-plugin/tests/unit/bridge-status.test.ts @@ -0,0 +1,40 @@ +import fs from "node:fs"; +import path from "node:path"; +import { describe, expect, it } from "vitest"; + +function matchesHermesChatProcess(command: string): boolean { + const bridgePath = path.resolve(__dirname, "../../bridge.cts"); + const bridgeSource = fs.readFileSync(bridgePath, "utf8"); + const match = bridgeSource.match( + /const HERMES_CHAT_PROCESS_PATTERN = "(?.*)";/, + ); + expect(match?.groups?.pattern).toBeTruthy(); + const escapedPattern = match!.groups!.pattern; + const pattern = escapedPattern.replaceAll("\\\\", "\\"); + return new RegExp(pattern).test(command); +} + +describe("Hermes chat process detection", () => { + it("matches the standard Hermes chat command", () => { + expect(matchesHermesChatProcess("hermes chat")).toBe(true); + expect(matchesHermesChatProcess("/usr/local/bin/hermes chat")).toBe(true); + }); + + it("matches global flags before the chat subcommand", () => { + expect( + matchesHermesChatProcess( + "/usr/local/lib/hermes-agent/venv/bin/hermes --skills memory-routing chat", + ), + ).toBe(true); + expect( + matchesHermesChatProcess( + "hermes -m gpt-4.1 --provider openai chat --skills memory-routing", + ), + ).toBe(true); + }); + + it("does not match non-chat Hermes commands", () => { + expect(matchesHermesChatProcess("hermes dashboard")).toBe(false); + expect(matchesHermesChatProcess("hermes --skills memory-routing gateway")).toBe(false); + }); +});