fix(web): focus failing agent's fields when Configure is clicked from a different agent tab

Address Looper non-blocking review on PR #2022 (commit 6796acc41,
discussion_r3329925123):

When the Settings dialog had Claude selected and the user clicked
"Configure" on a misconfigured CodeBuddy card, `configErrorAgentId`
was added to the cliEnvFields filter — but the result still listed
the *currently selected* agent's fields first. The first-field
focus logic (`index === 0`) then landed on `CLAUDE_CONFIG_DIR`
instead of the CodeBuddy field the user actually came to fix.

When `configErrorAgentId` is set AND it's a different agent than
`cfg.agentId`, partition the matched fields so the failing agent's
fields come first, with the selected agent's fields after. The
auto-focus / scroll target (index === 0) now points at the agent
the user just clicked Configure for.

Verified locally:
- `pnpm --filter @open-design/web typecheck` passes
- `pnpm --filter @open-design/web test tests/components/SettingsDialog.test.ts` 44/45 passed
  (the remaining failure — "still starts a manual Orbit run when saving
  media credentials fails" — is pre-existing on the merge commit
  6796acc41 and is unrelated to the CodeBuddy adapter)
This commit is contained in:
whincwu 2026-05-31 16:41:04 +08:00
parent 6796acc41d
commit 98391a14f5

View file

@ -3223,9 +3223,24 @@ export function SettingsDialog({
users no longer wonder "are these fields I forgot to
fill in?".
*/
const cliEnvFields = AGENT_CLI_ENV_FIELDS.filter(
(field) => field.agentId === cfg.agentId || field.agentId === configErrorAgentId,
);
const cliEnvFields = (() => {
const matches = AGENT_CLI_ENV_FIELDS.filter(
(field) => field.agentId === cfg.agentId || field.agentId === configErrorAgentId,
);
// When the recovery flow is active for an agent OTHER than
// the currently selected one, surface that agent's fields
// first so the auto-focus target (index === 0) is the
// misconfigured field the user just clicked Configure for —
// not the selected agent's first advanced field, which they
// did not ask to edit.
if (configErrorAgentId && configErrorAgentId !== cfg.agentId) {
return [
...matches.filter((f) => f.agentId === configErrorAgentId),
...matches.filter((f) => f.agentId !== configErrorAgentId),
];
}
return matches;
})();
if (cliEnvFields.length === 0) return null;
return (
<details