From a54fe4e34d3ff7a634304924f91d9756526fc333 Mon Sep 17 00:00:00 2001 From: raman325 <7243222+raman325@users.noreply.github.com> Date: Wed, 2 Sep 2026 14:47:39 -0400 Subject: [PATCH] fix(server): select Hermes approval mode by intent, not substring The live `hermes acp` CLI advertises three session modes -- `default` ("Ask before edits."), `accept_edits` ("Auto-allow workspace and /tmp edits; still asks for sensitive paths.") and `dont_ask` ("Don't Ask") -- and every one of them contains the "ask" approval alias somewhere in its id, name, or description. The substring fallback in findModeByAliases therefore returned whichever of the three Hermes listed first, so approval-required resolved to `default` only by accident of ordering. A reorder or a new mode would have silently pointed "approve every edit" at an auto-allow mode. The approval lookup now asks findModeByAliases for a mode that still prompts, rejecting substring candidates whose own text says otherwise ("dont ask", "auto", "accept", "bypass", ...). The filter is opt-in and scoped to approval intent only: an "Accept Edits" mode remains a valid implement-mode candidate, and exact id/name matches are untouched. Model: Claude Opus 5 (1M context). Harness: Claude Code. Co-Authored-By: Claude Opus 5 (1M context) --- .../src/provider/Layers/HermesAdapter.test.ts | 64 +++++++++++++++++++ .../src/provider/Layers/HermesAdapter.ts | 48 +++++++++++++- 2 files changed, 110 insertions(+), 2 deletions(-) diff --git a/apps/server/src/provider/Layers/HermesAdapter.test.ts b/apps/server/src/provider/Layers/HermesAdapter.test.ts index 83559759d8..9fbeb37abb 100644 --- a/apps/server/src/provider/Layers/HermesAdapter.test.ts +++ b/apps/server/src/provider/Layers/HermesAdapter.test.ts @@ -192,6 +192,70 @@ it("resolves approval-required to an approval-shaped mode before implement", () assert.equal(modeId, "ask"); }); +// The exact session modes the live `hermes acp` CLI (v0.21) advertises. All +// three mention "ask", so approval selection cannot lean on substring order. +const liveHermesModes = [ + { id: "default", name: "Default", description: "Ask before edits." }, + { + id: "accept_edits", + name: "Accept Edits", + description: "Auto-allow workspace and /tmp edits; still asks for sensitive paths.", + }, + { + id: "dont_ask", + name: "Don't Ask", + description: "Auto-allow file edits for this session except sensitive paths.", + }, +] as const; + +it("resolves approval-required to the mode that still prompts", () => { + const modeId = resolveRequestedModeId({ + interactionMode: undefined, + runtimeMode: "approval-required", + modeState: { currentModeId: "default", availableModes: liveHermesModes }, + }); + assert.equal(modeId, "default"); +}); + +it("resolves approval-required independently of the order Hermes lists modes in", () => { + const modeId = resolveRequestedModeId({ + interactionMode: undefined, + runtimeMode: "approval-required", + modeState: { + currentModeId: "dont_ask", + availableModes: [liveHermesModes[2], liveHermesModes[1], liveHermesModes[0]], + }, + }); + assert.equal(modeId, "default"); +}); + +it("still resolves the implement mode when approvals are not required", () => { + const modeId = resolveRequestedModeId({ + interactionMode: undefined, + runtimeMode: "full-access", + modeState: { + currentModeId: "dont_ask", + availableModes: [liveHermesModes[2], liveHermesModes[1], liveHermesModes[0]], + }, + }); + assert.equal(modeId, "default"); +}); + +it("resolves approval-required to an asking mode that shares no alias with its id", () => { + const modeId = resolveRequestedModeId({ + interactionMode: undefined, + runtimeMode: "approval-required", + modeState: { + currentModeId: "dont_ask", + availableModes: [ + { id: "dont_ask", name: "Don't Ask", description: "Auto-allow." }, + { id: "confirm_edits", name: "Confirm Edits", description: "Ask before applying edits." }, + ], + }, + }); + assert.equal(modeId, "confirm_edits"); +}); + it("resolves no mode when the agent advertises none", () => { const modeId = resolveRequestedModeId({ interactionMode: undefined, diff --git a/apps/server/src/provider/Layers/HermesAdapter.ts b/apps/server/src/provider/Layers/HermesAdapter.ts index 84ae40cfd4..6ccb138e23 100644 --- a/apps/server/src/provider/Layers/HermesAdapter.ts +++ b/apps/server/src/provider/Layers/HermesAdapter.ts @@ -80,6 +80,25 @@ const HERMES_RESUME_VERSION = 1 as const; const ACP_PLAN_MODE_ALIASES = ["plan", "architect"]; const ACP_IMPLEMENT_MODE_ALIASES = ["code", "agent", "default", "chat", "implement"]; const ACP_APPROVAL_MODE_ALIASES = ["ask"]; +/** + * Normalized text fragments that mark a mode as one which acts without stopping + * to ask. Each entry is unambiguous on its own: bare "always" is not, because + * "always ask" and "always allow" mean opposite things, so only the allowing + * phrasings are listed. + */ +const ACP_PROMPT_SUPPRESSING_SIGNALS = [ + "dont ask", + "don t ask", + "do not ask", + "never ask", + "without asking", + "auto", + "accept", + "always allow", + "allow always", + "skip", + "bypass", +]; function encodeJsonStringForDiagnostics(input: unknown): string | undefined { const result = encodeUnknownJsonStringExit(input); @@ -189,9 +208,29 @@ function normalizeModeSearchText(mode: AcpSessionMode): string { .trim(); } +/** + * Whether a mode's own text says it acts without prompting first. Guards + * approval-intent matching: the live Hermes mode set is `default` + * ("Ask before edits."), `accept_edits` ("Auto-allow workspace and /tmp edits; + * still asks for sensitive paths.") and `dont_ask` ("Don't Ask"), so every one + * of them contains the "ask" alias. Plain substring matching therefore picked + * whichever auto-allowing mode Hermes happened to list first, which silently + * turns "approve every edit" into "approve nothing". + */ +function modeSuppressesPrompts(mode: AcpSessionMode): boolean { + const searchText = normalizeModeSearchText(mode); + return ACP_PROMPT_SUPPRESSING_SIGNALS.some((signal) => searchText.includes(signal)); +} + +/** + * Set `requireProactivePrompting` when the alias expresses "the user wants to be + * asked". It narrows only the substring pass, and only for that intent: an + * "Accept Edits" mode is a perfectly good implement-mode candidate. + */ function findModeByAliases( modes: ReadonlyArray, aliases: ReadonlyArray, + options?: { readonly requireProactivePrompting?: boolean }, ): AcpSessionMode | undefined { const normalizedAliases = aliases.map((alias) => alias.toLowerCase()); for (const alias of normalizedAliases) { @@ -204,8 +243,11 @@ function findModeByAliases( return exact; } } + const partialCandidates = options?.requireProactivePrompting + ? modes.filter((mode) => !modeSuppressesPrompts(mode)) + : modes; for (const alias of normalizedAliases) { - const partial = modes.find((mode) => normalizeModeSearchText(mode).includes(alias)); + const partial = partialCandidates.find((mode) => normalizeModeSearchText(mode).includes(alias)); if (partial) { return partial; } @@ -233,7 +275,9 @@ export function resolveRequestedModeId(input: { if (input.runtimeMode === "approval-required") { return ( - findModeByAliases(modeState.availableModes, ACP_APPROVAL_MODE_ALIASES)?.id ?? + findModeByAliases(modeState.availableModes, ACP_APPROVAL_MODE_ALIASES, { + requireProactivePrompting: true, + })?.id ?? findModeByAliases(modeState.availableModes, ACP_IMPLEMENT_MODE_ALIASES)?.id ?? modeState.availableModes.find((mode) => !isPlanMode(mode))?.id ?? modeState.currentModeId