fix(inject): honor user_projects.agent_pref when caller omits adapter

POST /api/inject defaulted to "claude" whenever the body didn't pin an
adapter, so every project ran Claude regardless of agent_pref — a Gemini
project got Claude, a Cursor project got Claude. The per-row agent
preference is the SSOT exposed by /api/control and used everywhere in
the UI for the agent dropdown; the inject path was the one place
ignoring it.

After we resolve dbMatch (the user's project row), check agent_pref and
upgrade the provisional "claude" default only when the column is set
AND valid against ORCHESTRATION_ADAPTER_IDS. Caller-supplied adapter
still wins; agent_pref is just the fallback.

Daemon side already prefers payload_adapter (from d6215fe) before
defaulting to "claude" in execute_inject, so this commit closes the gap
end to end: web UI → /api/inject reads agent_pref → payload carries it
→ daemon launches the right agent in the right tab.
This commit is contained in:
g-but committed 2026-05-31 00:27:24 +02:00
1 parent 14e4a08f7a
commit 16d21c28e7
1 file changed
+16 -1
+16 -1
View File
@@ -22,7 +22,10 @@ export async function POST(req: NextRequest) {
const dataOrResp = await readJsonBody(req, InjectBody);
if (dataOrResp instanceof NextResponse) return dataOrResp;
const { tab, promptKey, customPrompt, adapter } = dataOrResp;
const eventAdapter: AgentOption = adapter ?? "claude";
// Provisional adapter for early-return logging; the real resolution happens
// after we've looked up dbMatch and can honor user_projects.agent_pref below.
type ResolvedAdapter = (typeof ORCHESTRATION_ADAPTER_IDS)[number];
let eventAdapter: ResolvedAdapter = adapter ?? "claude";
const userId = await getApiUserId();
if (!userId) {
@@ -72,6 +75,18 @@ export async function POST(req: NextRequest) {
const projectPath: string | null = dbMatch.dirPath ?? null;
const projectId: string | null = dbMatch.entityProjectId ?? null;
// Honor the project's per-row agent preference when the caller didn't pin one.
// Without this the daemon defaults to "claude" for every project regardless
// of agent_pref, so a Gemini project gets a Claude launch and a Cursor
// project gets Claude too. The DB column is text, so validate it's still a
// supported adapter before trusting it.
if (!adapter && dbMatch.agentPref) {
const ids = ORCHESTRATION_ADAPTER_IDS as readonly string[];
if (ids.includes(dbMatch.agentPref)) {
eventAdapter = dbMatch.agentPref as ResolvedAdapter;
}
}
let prompt: string;
let promptLabel = "Custom";
let effectiveTab = canonical;