Skip to content

Commit a54fe4e

Browse files
raman325claude
andcommitted
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) <[email protected]>
1 parent f2d2f96 commit a54fe4e

2 files changed

Lines changed: 110 additions & 2 deletions

File tree

‎apps/server/src/provider/Layers/HermesAdapter.test.ts‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,70 @@ it("resolves approval-required to an approval-shaped mode before implement", ()
192192
assert.equal(modeId, "ask");
193193
});
194194

195+
// The exact session modes the live `hermes acp` CLI (v0.21) advertises. All
196+
// three mention "ask", so approval selection cannot lean on substring order.
197+
const liveHermesModes = [
198+
{ id: "default", name: "Default", description: "Ask before edits." },
199+
{
200+
id: "accept_edits",
201+
name: "Accept Edits",
202+
description: "Auto-allow workspace and /tmp edits; still asks for sensitive paths.",
203+
},
204+
{
205+
id: "dont_ask",
206+
name: "Don't Ask",
207+
description: "Auto-allow file edits for this session except sensitive paths.",
208+
},
209+
] as const;
210+
211+
it("resolves approval-required to the mode that still prompts", () => {
212+
const modeId = resolveRequestedModeId({
213+
interactionMode: undefined,
214+
runtimeMode: "approval-required",
215+
modeState: { currentModeId: "default", availableModes: liveHermesModes },
216+
});
217+
assert.equal(modeId, "default");
218+
});
219+
220+
it("resolves approval-required independently of the order Hermes lists modes in", () => {
221+
const modeId = resolveRequestedModeId({
222+
interactionMode: undefined,
223+
runtimeMode: "approval-required",
224+
modeState: {
225+
currentModeId: "dont_ask",
226+
availableModes: [liveHermesModes[2], liveHermesModes[1], liveHermesModes[0]],
227+
},
228+
});
229+
assert.equal(modeId, "default");
230+
});
231+
232+
it("still resolves the implement mode when approvals are not required", () => {
233+
const modeId = resolveRequestedModeId({
234+
interactionMode: undefined,
235+
runtimeMode: "full-access",
236+
modeState: {
237+
currentModeId: "dont_ask",
238+
availableModes: [liveHermesModes[2], liveHermesModes[1], liveHermesModes[0]],
239+
},
240+
});
241+
assert.equal(modeId, "default");
242+
});
243+
244+
it("resolves approval-required to an asking mode that shares no alias with its id", () => {
245+
const modeId = resolveRequestedModeId({
246+
interactionMode: undefined,
247+
runtimeMode: "approval-required",
248+
modeState: {
249+
currentModeId: "dont_ask",
250+
availableModes: [
251+
{ id: "dont_ask", name: "Don't Ask", description: "Auto-allow." },
252+
{ id: "confirm_edits", name: "Confirm Edits", description: "Ask before applying edits." },
253+
],
254+
},
255+
});
256+
assert.equal(modeId, "confirm_edits");
257+
});
258+
195259
it("resolves no mode when the agent advertises none", () => {
196260
const modeId = resolveRequestedModeId({
197261
interactionMode: undefined,

‎apps/server/src/provider/Layers/HermesAdapter.ts‎

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,25 @@ const HERMES_RESUME_VERSION = 1 as const;
8080
const ACP_PLAN_MODE_ALIASES = ["plan", "architect"];
8181
const ACP_IMPLEMENT_MODE_ALIASES = ["code", "agent", "default", "chat", "implement"];
8282
const ACP_APPROVAL_MODE_ALIASES = ["ask"];
83+
/**
84+
* Normalized text fragments that mark a mode as one which acts without stopping
85+
* to ask. Each entry is unambiguous on its own: bare "always" is not, because
86+
* "always ask" and "always allow" mean opposite things, so only the allowing
87+
* phrasings are listed.
88+
*/
89+
const ACP_PROMPT_SUPPRESSING_SIGNALS = [
90+
"dont ask",
91+
"don t ask",
92+
"do not ask",
93+
"never ask",
94+
"without asking",
95+
"auto",
96+
"accept",
97+
"always allow",
98+
"allow always",
99+
"skip",
100+
"bypass",
101+
];
83102

84103
function encodeJsonStringForDiagnostics(input: unknown): string | undefined {
85104
const result = encodeUnknownJsonStringExit(input);
@@ -189,9 +208,29 @@ function normalizeModeSearchText(mode: AcpSessionMode): string {
189208
.trim();
190209
}
191210

211+
/**
212+
* Whether a mode's own text says it acts without prompting first. Guards
213+
* approval-intent matching: the live Hermes mode set is `default`
214+
* ("Ask before edits."), `accept_edits` ("Auto-allow workspace and /tmp edits;
215+
* still asks for sensitive paths.") and `dont_ask` ("Don't Ask"), so every one
216+
* of them contains the "ask" alias. Plain substring matching therefore picked
217+
* whichever auto-allowing mode Hermes happened to list first, which silently
218+
* turns "approve every edit" into "approve nothing".
219+
*/
220+
function modeSuppressesPrompts(mode: AcpSessionMode): boolean {
221+
const searchText = normalizeModeSearchText(mode);
222+
return ACP_PROMPT_SUPPRESSING_SIGNALS.some((signal) => searchText.includes(signal));
223+
}
224+
225+
/**
226+
* Set `requireProactivePrompting` when the alias expresses "the user wants to be
227+
* asked". It narrows only the substring pass, and only for that intent: an
228+
* "Accept Edits" mode is a perfectly good implement-mode candidate.
229+
*/
192230
function findModeByAliases(
193231
modes: ReadonlyArray<AcpSessionMode>,
194232
aliases: ReadonlyArray<string>,
233+
options?: { readonly requireProactivePrompting?: boolean },
195234
): AcpSessionMode | undefined {
196235
const normalizedAliases = aliases.map((alias) => alias.toLowerCase());
197236
for (const alias of normalizedAliases) {
@@ -204,8 +243,11 @@ function findModeByAliases(
204243
return exact;
205244
}
206245
}
246+
const partialCandidates = options?.requireProactivePrompting
247+
? modes.filter((mode) => !modeSuppressesPrompts(mode))
248+
: modes;
207249
for (const alias of normalizedAliases) {
208-
const partial = modes.find((mode) => normalizeModeSearchText(mode).includes(alias));
250+
const partial = partialCandidates.find((mode) => normalizeModeSearchText(mode).includes(alias));
209251
if (partial) {
210252
return partial;
211253
}
@@ -233,7 +275,9 @@ export function resolveRequestedModeId(input: {
233275

234276
if (input.runtimeMode === "approval-required") {
235277
return (
236-
findModeByAliases(modeState.availableModes, ACP_APPROVAL_MODE_ALIASES)?.id ??
278+
findModeByAliases(modeState.availableModes, ACP_APPROVAL_MODE_ALIASES, {
279+
requireProactivePrompting: true,
280+
})?.id ??
237281
findModeByAliases(modeState.availableModes, ACP_IMPLEMENT_MODE_ALIASES)?.id ??
238282
modeState.availableModes.find((mode) => !isPlanMode(mode))?.id ??
239283
modeState.currentModeId

0 commit comments

Comments
 (0)