Skip to content

Commit a4153b1

Browse files
authored
feat(desktop): add custom harness inline from agent dialogs (#3252)
Registering a custom ACP harness works today, but only from Settings → Agents. Anyone whose first touchpoint is "New agent" has no way to discover the custom path — the dropdown just lists the baked-in presets plus whatever was registered earlier. This adds an inline "Add custom harness…" entry to the harness dropdown in all three agent surfaces: create, edit-definition (`AgentDefinitionDialog`), and instance edit (`AgentInstanceEditDialog`). The entry is a sentinel option (`ADD_CUSTOM_HARNESS_VALUE`, NUL-prefixed so it can never collide with a real harness id — backend ids match `[a-z0-9_][a-z0-9_-]*`), mirroring the `CUSTOM_ENTRY_ID` trick already used in `HarnessCatalogDialog`. Picking it never writes into form state; it opens `AddCustomHarnessDialog`, a thin modal wrapper hosting the existing `CustomHarnessForm` in `chromeless` mode. `CustomHarnessForm`'s `onSaved` now carries the saved `definition.id` (the form may rewrite it); the two existing call sites ignore the argument, so their behavior is unchanged. Selection after save is deferred rather than immediate. `usePendingHarnessSelection` holds the saved id until the runtime catalog actually publishes it via discovery, then selects it exactly once — so the dialog never selects an id it cannot render, and back-to-back registrations resolve correctly. The wait is scoped to the owning dialog's `open` state: both host dialogs stay mounted when closed, so an unpublished id is dropped on close rather than selecting into reset form state when discovery later catches up. Selection is routed through each dialog's normal dropdown change handler, so provider/model reset (and command pinning in the instance dialog) behave identically to a hand-picked harness. Dismissing the modal leaves the previous selection untouched. `AgentInstanceEditDialog`'s existing "Custom command" option is a different feature (ad-hoc command override vs. a registered reusable harness) and is untouched. Coverage is 16 unit tests in `addCustomHarness.test.mjs` (real React mount, following the existing `.test.mjs` pattern) plus 4 Playwright specs in `inline-custom-harness.spec.ts` covering all three surfaces end-to-end. Both suites were mutation-verified: treating the sentinel as a real selection, selecting before the catalog publishes, never clearing the pending id, ignoring the dialog's open state, and reversing latest-save-wins each turn the unit tests red; reverting the two dialog diffs turns all four e2e specs red. The `check-file-sizes.mjs` overrides for the two dialogs are ratcheted to their exact new counts (1048 and 1229) — verified tight in both directions, N passes and N−1 fails, so no headroom is introduced. --------- Signed-off-by: Will Pfleger <[email protected]>
1 parent 79223c2 commit a4153b1

9 files changed

Lines changed: 763 additions & 12 deletions

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export default defineConfig({
126126
"**/observer-archive-policy.spec.ts",
127127
"**/harness-management.spec.ts",
128128
"**/harness-catalog-screenshots.spec.ts",
129+
"**/inline-custom-harness.spec.ts",
129130
],
130131
use: {
131132
...devices["Desktop Chrome"],

‎desktop/scripts/check-file-sizes.mjs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,12 +697,18 @@ const overrides = new Map([
697697
// hidden-key projection keeps the top-level secret out of Advanced rows.
698698
// +6 (1195 -> 1201): rebase onto main — this PR's model-source label wiring
699699
// lands on top of main's dialog growth. Queued to split.
700-
["src/features/agents/ui/AgentInstanceEditDialog.tsx", 1201],
700+
// +28 (1201 -> 1229): inline "Add custom harness…" entry — sentinel option,
701+
// modal state, and the AddCustomHarnessDialog mount. The shared routing and
702+
// deferred-selection logic lives in addCustomHarness.ts to keep this minimal.
703+
["src/features/agents/ui/AgentInstanceEditDialog.tsx", 1229],
701704
// AgentDefinitionDialog grew past 1000 with the following load-bearing fixes:
702705
// isRuntimeAutoSeededRef tracking for edit-mode seeding (Fizz shows models);
703706
// runtimeSupportsLlmProviderSelection guard on discovery provider (codex fix);
704707
// hideProviderIds computation for Databricks v1 gate. Queued to split.
705-
["src/features/agents/ui/AgentDefinitionDialog.tsx", 1035],
708+
// +28 (1020 -> 1048): inline "Add custom harness…" entry — sentinel option,
709+
// modal state, and the AddCustomHarnessDialog mount. The shared routing and
710+
// deferred-selection logic lives in addCustomHarness.ts to keep this minimal.
711+
["src/features/agents/ui/AgentDefinitionDialog.tsx", 1048],
706712
// #2630 emoji picker search: the shadow-root search-input autofocus effect
707713
// (rAF retry loop) took this file 999 -> 1026 and landed without this entry,
708714
// so main's Desktop Core went red. Queued to split with the rest of this list.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { CustomHarnessForm } from "@/features/settings/ui/CustomHarnessForm";
2+
import { ChooserDialogContent } from "@/shared/ui/chooser-dialog-content";
3+
import { Dialog } from "@/shared/ui/dialog";
4+
5+
/**
6+
* Registers a custom ACP harness from inside an agent dialog, so "New agent"
7+
* is a complete entry point and not a dead end that sends the user to
8+
* Settings. Hosts the same `CustomHarnessForm` the harness catalog uses.
9+
*/
10+
export function AddCustomHarnessDialog({
11+
onOpenChange,
12+
onSaved,
13+
open,
14+
}: {
15+
onOpenChange: (open: boolean) => void;
16+
/** Called with the id of the harness that was just registered. */
17+
onSaved: (id: string) => void;
18+
open: boolean;
19+
}) {
20+
return (
21+
<Dialog onOpenChange={onOpenChange} open={open}>
22+
<ChooserDialogContent
23+
className="h-[42rem] max-w-2xl"
24+
contentClassName="flex min-h-0 flex-1 p-0"
25+
data-testid="add-custom-harness-dialog"
26+
scrollAreaClassName="flex min-h-0 overflow-hidden px-0"
27+
title="Add custom harness"
28+
>
29+
<CustomHarnessForm
30+
chromeless
31+
header={
32+
<p className="text-sm text-muted-foreground">
33+
Register any ACP-speaking agent tool as a selectable harness.
34+
</p>
35+
}
36+
onCancel={() => onOpenChange(false)}
37+
onSaved={(id) => {
38+
// Dismiss on save as well as cancel — both exits belong to this
39+
// dialog, so callers only handle the resulting selection.
40+
onOpenChange(false);
41+
onSaved(id);
42+
}}
43+
/>
44+
</ChooserDialogContent>
45+
</Dialog>
46+
);
47+
}

‎desktop/src/features/agents/ui/AgentDefinitionDialog.tsx‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ import {
8383
import { useProviderApiKeyFieldState } from "./providerApiKeyFieldState";
8484
import { buildRuntimeModelProviderPayload } from "./agentDefinitionSubmitPayload";
8585
import { AgentDefinitionDialogFooter } from "./AgentDefinitionDialogFooter";
86+
import { AddCustomHarnessDialog } from "./AddCustomHarnessDialog";
87+
import {
88+
ADD_CUSTOM_HARNESS_OPTION,
89+
runtimeDropdownAction,
90+
usePendingHarnessSelection,
91+
} from "./addCustomHarness";
8692

8793
type AgentDefinitionDialogProps = {
8894
open: boolean;
@@ -167,6 +173,7 @@ export function AgentDefinitionDialog({
167173
const [isAvatarUploadPending, setIsAvatarUploadPending] =
168174
React.useState(false);
169175
const [hasUserChanges, setHasUserChanges] = React.useState(false);
176+
const [isAddHarnessOpen, setIsAddHarnessOpen] = React.useState(false);
170177
const {
171178
globalConfig,
172179
inheritedDefaults: {
@@ -308,6 +315,7 @@ export function AgentDefinitionDialog({
308315
setShowAdvancedFields(false);
309316
setIsAvatarUploadPending(false);
310317
setHasUserChanges(false);
318+
setIsAddHarnessOpen(false);
311319
// isRuntimeAutoSeededRef and hasSeededForOpenRef are NOT reset here — the
312320
// [initialValues, open] effect resets both when the dialog re-opens.
313321
}
@@ -578,6 +586,7 @@ export function AgentDefinitionDialog({
578586
runtimes,
579587
runtimesLoading,
580588
});
589+
runtimeDropdownOptions.push(ADD_CUSTOM_HARNESS_OPTION);
581590
const runtimeSummaryLabel = selectedRuntime
582591
? formatRuntimeOptionLabel(selectedRuntime)
583592
: runtime.trim() || "Not configured";
@@ -662,9 +671,13 @@ export function AgentDefinitionDialog({
662671
}
663672

664673
function handleRuntimeDropdownChange(nextValue: string) {
674+
const action = runtimeDropdownAction(nextValue);
675+
if (action.kind === "add-custom-harness") {
676+
setIsAddHarnessOpen(true);
677+
return;
678+
}
665679
setHasUserChanges(true);
666-
const nextRuntime =
667-
nextValue === NO_RUNTIME_DROPDOWN_VALUE ? "" : nextValue;
680+
const nextRuntime = action.runtimeId;
668681
// The user made an explicit choice — no longer auto-seeded.
669682
isRuntimeAutoSeededRef.current = false;
670683
setRuntime(nextRuntime);
@@ -680,6 +693,15 @@ export function AgentDefinitionDialog({
680693
);
681694
}
682695

696+
// Routed through the normal change handler so a harness registered inline
697+
// resets model/provider exactly as a hand-picked one would. Scoped to `open`
698+
// so a pending id can't outlive the dialog that started the registration.
699+
const selectSavedHarness = usePendingHarnessSelection(
700+
runtimes,
701+
handleRuntimeDropdownChange,
702+
open,
703+
);
704+
683705
function handleProviderDropdownChange(nextValue: string) {
684706
setHasUserChanges(true);
685707
const nextProvider =
@@ -944,6 +966,12 @@ export function AgentDefinitionDialog({
944966
returnFocusRef={aiDefaultsTriggerRef}
945967
/>
946968

969+
<AddCustomHarnessDialog
970+
onOpenChange={setIsAddHarnessOpen}
971+
onSaved={selectSavedHarness}
972+
open={isAddHarnessOpen}
973+
/>
974+
947975
{isCreateMode ? createRunSection : null}
948976

949977
<div className="space-y-3">

‎desktop/src/features/agents/ui/AgentInstanceEditDialog.tsx‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ import { useProviderApiKeyFieldState } from "./providerApiKeyFieldState";
8383
import { resolveModelFieldStatusMessage } from "./agentConfigControls";
8484
import { AdvancedRequiredBadge } from "./AdvancedRequiredBadge";
8585
import { showAgentProfileSyncWarning } from "./agentProfileSyncWarning";
86+
import { AddCustomHarnessDialog } from "./AddCustomHarnessDialog";
87+
import {
88+
ADD_CUSTOM_HARNESS_OPTION,
89+
runtimeDropdownAction,
90+
usePendingHarnessSelection,
91+
} from "./addCustomHarness";
8692

8793
const ADVANCED_FIELDS_MOTION_TRANSITION = {
8894
duration: 0.18,
@@ -157,6 +163,7 @@ export function AgentInstanceEditDialog({
157163
const [avatarUrl, setAvatarUrl] = React.useState(agent.avatarUrl ?? "");
158164
const [isAvatarUploadPending, setIsAvatarUploadPending] =
159165
React.useState(false);
166+
const [isAddHarnessOpen, setIsAddHarnessOpen] = React.useState(false);
160167
const shouldReduceMotion = useReducedMotion();
161168

162169
// Runtime selector: defaults to "custom" until the dialog opens and the
@@ -191,6 +198,7 @@ export function AgentInstanceEditDialog({
191198
setAvatarUrl(agent.avatarUrl ?? "");
192199
setShowAdvancedFields(false);
193200
setIsAvatarUploadPending(false);
201+
setIsAddHarnessOpen(false);
194202
runtimeTouched.current = false;
195203
const matched =
196204
runtimes.find((r) => r.command?.trim() === agent.agentCommand.trim()) ??
@@ -244,6 +252,7 @@ export function AgentInstanceEditDialog({
244252
value: selectedRuntimeId,
245253
});
246254
}
255+
options.push(ADD_CUSTOM_HARNESS_OPTION);
247256
return options;
248257
}, [sortedRuntimes, selectedRuntimeId]);
249258

@@ -484,8 +493,12 @@ export function AgentInstanceEditDialog({
484493
}
485494

486495
function handleRuntimeDropdownChange(nextValue: string) {
487-
const nextRuntimeId =
488-
nextValue === NO_RUNTIME_DROPDOWN_VALUE ? "" : nextValue;
496+
const action = runtimeDropdownAction(nextValue);
497+
if (action.kind === "add-custom-harness") {
498+
setIsAddHarnessOpen(true);
499+
return;
500+
}
501+
const nextRuntimeId = action.runtimeId;
489502
const previousRuntimeId = selectedRuntimeId;
490503
const nextRuntime = runtimes.find((r) => r.id === nextRuntimeId);
491504

@@ -532,6 +545,16 @@ export function AgentInstanceEditDialog({
532545
);
533546
}
534547

548+
// Routed through the normal change handler so a harness registered inline
549+
// pins its command and resets model/provider like a hand-picked one. Scoped
550+
// to `open` so a pending id can't outlive the dialog that started the
551+
// registration.
552+
const selectSavedHarness = usePendingHarnessSelection(
553+
runtimes,
554+
handleRuntimeDropdownChange,
555+
open,
556+
);
557+
535558
function handleProviderDropdownChange(nextValue: string) {
536559
const nextProvider =
537560
nextValue === AUTO_PROVIDER_DROPDOWN_VALUE ? "" : nextValue;
@@ -949,6 +972,11 @@ export function AgentInstanceEditDialog({
949972
</span>
950973
</p>
951974
) : null}
975+
<AddCustomHarnessDialog
976+
onOpenChange={setIsAddHarnessOpen}
977+
onSaved={selectSavedHarness}
978+
open={isAddHarnessOpen}
979+
/>
952980
</div>
953981
{selectedRuntimeId === "custom" && !inheritHarness ? (
954982
<div className="space-y-1.5">

0 commit comments

Comments
 (0)