Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/local-agent-acp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
deliverAcpSessionUpdate,
resolveAcpCommand,
selectAcpPermissionOption,
matchAcpSelectValue,
} from "./local-agent-acp.js";
import { GrokPromptCompletionRegistry } from "./local-agent-grok.js";

Expand Down Expand Up @@ -822,3 +823,12 @@ test("a stop requested before the prompt is sent starts no provider work", async
assert.equal(preAbortRequests.includes("session/prompt"), false);
await preAbortRuntime.close();
});

test("an ACP select accepts a plain name when exactly one bracketed variant matches", () => {
const available = ["default[]", "composer-2.5[fast=true]", "grok-4.6[effort=high,fast=true]", "grok-4.6[effort=low]"];

assert.equal(matchAcpSelectValue(available, "composer-2.5[fast=true]"), "composer-2.5[fast=true]");
assert.equal(matchAcpSelectValue(available, "composer-2.5"), "composer-2.5[fast=true]");
assert.equal(matchAcpSelectValue(available, "grok-4.6"), undefined, "ambiguous names match nothing");
assert.equal(matchAcpSelectValue(available, "composer"), undefined);
});
17 changes: 15 additions & 2 deletions src/local-agent-acp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -954,13 +954,26 @@ function resolveAcpSelectConfigUpdate(

if (!configId) throw new Error(`${options.provider} ACP ${options.label} is missing an id.`);
const available = flattenAcpSelectValues(config);
const value = matchAcpSelectValue(available, options.value);

if (!available.includes(options.value)) {
if (!value) {
const suffix = available.length > 0 ? ` Available values: ${available.join(", ")}.` : "";
throw new Error(`${options.provider} ACP ${options.label} does not support '${options.value}'.${suffix}`);
}

return { sessionId, configId, value: options.value };
return { sessionId, configId, value };
}

/**
* Accepts an exact option value, or a plain name such as `composer-2.5` when exactly one option is that name plus
* bracketed settings (Cursor's `composer-2.5[fast=true]`). An ambiguous name matches nothing.
*/
export function matchAcpSelectValue(available: readonly string[], requested: string): string | undefined {
if (available.includes(requested)) return requested;

const variants = available.filter((value) => value.startsWith(`${requested}[`) && value.endsWith("]"));

return variants.length === 1 ? variants[0] : undefined;
}

export function flattenAcpSelectValues(option: JsonObject): string[] {
Expand Down
Loading