Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

feat(gui): /ultracode toggle picker (#79) + fix segmented button borders (#74)

Rach Pradhanb3dd7bfa4e0f
diff --git a/gui/src/components/PromptInputCard.tsx b/gui/src/components/PromptInputCard.tsx
index 057bd258..7a399e62 100644
--- a/gui/src/components/PromptInputCard.tsx
+++ b/gui/src/components/PromptInputCard.tsx
@@ -33,6 +33,7 @@ import { CommandAutocomplete } from "@/components/CommandAutocomplete";
import { AttachmentTray } from "@/components/attachments/AttachmentTray";
import { DropOverlay } from "@/components/attachments/DropOverlay";
import { classifyPath } from "@/components/attachments/attachmentTypes";
+import { parseChoiceCommand } from "@/components/commandChoices";
import { useAutosizeTextarea } from "@/hooks/useAutosizeTextarea";
import { useAttachments } from "@/hooks/useSession";
import { useCommandAutocomplete } from "@/hooks/useCommandAutocomplete";
@@ -169,6 +170,14 @@ export function PromptInputCard({
handleModelMenuOpenChange(true);
return;
}
+ // `/ultracode` expands into on/off choice rows; selecting one flips the same
+ // ultra toggle the footer button uses (a GUI-only mode, not a backend cmd).
+ const choice = parseChoiceCommand(command.name);
+ if (choice != null && choice.name === "ultracode") {
+ setUltraMode(choice.arg === "on");
+ setPromptDraft("");
+ return;
+ }
onCommandSelect(command);
}
@@ -177,6 +186,7 @@ export function PromptInputCard({
setPromptDraft,
workspacePath,
enabled: canCompose && !isInputDisabled,
+ ultracodeEnabled: isUltraMode,
onSelect: handleAutocompleteSelect,
});
diff --git a/gui/src/components/commandChoices.test.ts b/gui/src/components/commandChoices.test.ts
new file mode 100644
index 00000000..6d5f491c
--- /dev/null
+++ b/gui/src/components/commandChoices.test.ts
@@ -0,0 +1,49 @@
+import { describe, expect, test } from "bun:test";
+
+import {
+ ULTRACODE_COMMAND,
+ getCommandChoices,
+ parseChoiceCommand,
+} from "./commandChoices";
+
+describe("getCommandChoices", () => {
+ test("ultracode lists `on` first when currently off", () => {
+ const choices = getCommandChoices("ultracode", { ultracodeEnabled: false });
+ expect(choices?.map((c) => c.name)).toEqual([
+ "ultracode on",
+ "ultracode off",
+ ]);
+ });
+
+ test("ultracode lists `off` first when currently on", () => {
+ const choices = getCommandChoices("ultracode", { ultracodeEnabled: true });
+ expect(choices?.map((c) => c.name)).toEqual([
+ "ultracode off",
+ "ultracode on",
+ ]);
+ });
+
+ test("returns null for non-choice commands", () => {
+ expect(getCommandChoices("help", { ultracodeEnabled: false })).toBeNull();
+ });
+});
+
+describe("parseChoiceCommand", () => {
+ test("splits a choice descriptor name into command + arg", () => {
+ expect(parseChoiceCommand("ultracode on")).toEqual({
+ name: "ultracode",
+ arg: "on",
+ });
+ });
+
+ test("returns null for a plain command name", () => {
+ expect(parseChoiceCommand("ultracode")).toBeNull();
+ });
+});
+
+describe("ULTRACODE_COMMAND", () => {
+ test("is a discoverable builtin descriptor", () => {
+ expect(ULTRACODE_COMMAND.name).toBe("ultracode");
+ expect(ULTRACODE_COMMAND.kind).toBe("builtin");
+ });
+});
diff --git a/gui/src/components/commandChoices.ts b/gui/src/components/commandChoices.ts
new file mode 100644
index 00000000..b031d15f
--- /dev/null
+++ b/gui/src/components/commandChoices.ts
@@ -0,0 +1,64 @@
+import type { CommandDescriptor } from "@/services/desktop/types/contracts";
+
+/**
+ * `/ultracode` is a GUI-only toggle (it flips the same per-prompt ultra mode the
+ * Ultra footer button uses) rather than a backend slash command, so we surface a
+ * synthetic descriptor for it in autocomplete.
+ */
+export const ULTRACODE_COMMAND: CommandDescriptor = {
+ name: "ultracode",
+ usage: "Toggle ultracode (multi-agent) mode for your next prompt.",
+ aliases: [],
+ kind: "builtin",
+ value: null,
+ isAgentSwitch: false,
+ executionKind: "runnable",
+ requiresWorkspace: false,
+ requiresConversation: false,
+ argumentHint: "<on|off>",
+ resultKind: "text",
+};
+
+function ultracodeChoice(on: boolean): CommandDescriptor {
+ return {
+ ...ULTRACODE_COMMAND,
+ name: on ? "ultracode on" : "ultracode off",
+ usage: on ? "Enable ultracode for your next prompt." : "Disable ultracode.",
+ argumentHint: null,
+ };
+}
+
+export interface CommandChoiceContext {
+ ultracodeEnabled: boolean;
+}
+
+/**
+ * Expands a choice-command into its selectable rows, or returns null when `name`
+ * is not a choice-command. The opposite of the current state is listed first so
+ * the default highlight (index 0) flips the mode when the user presses Enter.
+ */
+export function getCommandChoices(
+ name: string,
+ ctx: CommandChoiceContext,
+): CommandDescriptor[] | null {
+ if (name === ULTRACODE_COMMAND.name) {
+ const on = ultracodeChoice(true);
+ const off = ultracodeChoice(false);
+ return ctx.ultracodeEnabled ? [off, on] : [on, off];
+ }
+ return null;
+}
+
+/**
+ * Parses a choice descriptor name such as `"ultracode on"` into its command name
+ * and argument. Returns null for plain (single-token) command names.
+ */
+export function parseChoiceCommand(
+ name: string,
+): { name: string; arg: string } | null {
+ const match = /^(\S+)\s+(\S+)$/.exec(name);
+ if (match == null) {
+ return null;
+ }
+ return { name: match[1], arg: match[2] };
+}
diff --git a/gui/src/components/ui/ButtonGroup.tsx b/gui/src/components/ui/ButtonGroup.tsx
index 9f29050b..ff189027 100644
--- a/gui/src/components/ui/ButtonGroup.tsx
+++ b/gui/src/components/ui/ButtonGroup.tsx
@@ -11,9 +11,9 @@ const buttonGroupVariants = cva(
variants: {
orientation: {
horizontal:
- "*:data-slot:rounded-r-none [&>[data-slot]:not(:has(~[data-slot]))]:rounded-r-md! [&>[data-slot]~[data-slot]]:rounded-l-none [&>[data-slot]~[data-slot]]:border-l-0",
+ "*:data-slot:relative *:data-slot:rounded-r-none [&>[data-slot]:not(:has(~[data-slot]))]:rounded-r-md! [&>[data-slot]~[data-slot]]:rounded-l-none [&>[data-slot]~[data-slot]]:-ml-px *:hover:z-10 [&>[data-slot][aria-expanded=true]]:z-10",
vertical:
- "flex-col *:data-slot:rounded-b-none [&>[data-slot]:not(:has(~[data-slot]))]:rounded-b-md! [&>[data-slot]~[data-slot]]:rounded-t-none [&>[data-slot]~[data-slot]]:border-t-0",
+ "flex-col *:data-slot:relative *:data-slot:rounded-b-none [&>[data-slot]:not(:has(~[data-slot]))]:rounded-b-md! [&>[data-slot]~[data-slot]]:rounded-t-none [&>[data-slot]~[data-slot]]:-mt-px *:hover:z-10 [&>[data-slot][aria-expanded=true]]:z-10",
},
},
defaultVariants: {
diff --git a/gui/src/hooks/useCommandAutocomplete.ts b/gui/src/hooks/useCommandAutocomplete.ts
index 86fd738b..cda47597 100644
--- a/gui/src/hooks/useCommandAutocomplete.ts
+++ b/gui/src/hooks/useCommandAutocomplete.ts
@@ -2,6 +2,10 @@ import { useCallback, useEffect, useMemo, useState } from "react";
import * as desktopClient from "@/services/desktop/client";
import type { CommandDescriptor } from "@/services/desktop/types/contracts";
+import {
+ ULTRACODE_COMMAND,
+ getCommandChoices,
+} from "@/components/commandChoices";
/** Matches a slash-command being typed at the very start of the draft. */
const SLASH_QUERY = /^\/([\w-]*)$/;
@@ -30,6 +34,8 @@ interface Options {
setPromptDraft: (value: string) => void;
workspacePath?: string | null;
enabled: boolean;
+ /** Current ultracode state, used to order the `/ultracode` choice rows. */
+ ultracodeEnabled?: boolean;
onSelect: (command: CommandDescriptor) => void;
}
@@ -74,6 +80,7 @@ export function useCommandAutocomplete({
setPromptDraft,
workspacePath,
enabled,
+ ultracodeEnabled = false,
onSelect,
}: Options): CommandAutocompleteState {
const [commands, setCommands] = useState<CommandDescriptor[]>([]);
@@ -104,18 +111,46 @@ export function useCommandAutocomplete({
const slashMatch = SLASH_QUERY.exec(promptDraft);
const query = slashMatch?.[1] ?? null;
- const items = useMemo(() => {
+ // Surface the GUI-only `/ultracode` toggle in autocomplete even though it has
+ // no backend command descriptor.
+ const allCommands = useMemo(() => {
+ if (commands.some((command) => command.name === ULTRACODE_COMMAND.name)) {
+ return commands;
+ }
+ return [...commands, ULTRACODE_COMMAND];
+ }, [commands]);
+
+ const normalItems = useMemo(() => {
if (query == null) {
return [];
}
- return commands
+ return allCommands
.filter((command) => matches(command, query))
.sort((a, b) => {
const byRank = rank(a, query) - rank(b, query);
return byRank !== 0 ? byRank : a.name.localeCompare(b.name);
})
.slice(0, MAX_VISIBLE);
- }, [commands, query]);
+ }, [allCommands, query]);
+
+ // When the full name of a choice-command is typed (e.g. `/ultracode`), expand
+ // into its on/off choice rows instead of the normal completion list.
+ const exactCommand =
+ query == null
+ ? null
+ : (allCommands.find(
+ (command) =>
+ command.name === query || command.aliases.includes(query),
+ ) ?? null);
+ const choices = useMemo(
+ () =>
+ exactCommand == null
+ ? null
+ : getCommandChoices(exactCommand.name, { ultracodeEnabled }),
+ [exactCommand, ultracodeEnabled],
+ );
+ const inChoiceMode = choices != null && choices.length > 0;
+ const items = inChoiceMode ? choices : normalItems;
// Reset the highlight whenever the query changes (adjust state during render
// rather than in an effect — the React-recommended pattern).
@@ -172,9 +207,19 @@ export function useCommandAutocomplete({
);
return true;
case "Enter":
+ if (event.metaKey || event.ctrlKey) {
+ return false;
+ }
+ // In choice mode (e.g. `/ultracode`), Enter selects the highlighted
+ // on/off row rather than autofilling or submitting.
+ if (inChoiceMode) {
+ event.preventDefault();
+ pick();
+ return true;
+ }
// Plain Enter autofills partial commands, but exact commands should
// fall through to the composer submit path so `/help` runs directly.
- if (event.metaKey || event.ctrlKey || hasExactCommandMatch) {
+ if (hasExactCommandMatch) {
return false;
}
event.preventDefault();
@@ -182,7 +227,11 @@ export function useCommandAutocomplete({
return true;
case "Tab":
event.preventDefault();
- complete();
+ if (inChoiceMode) {
+ pick();
+ } else {
+ complete();
+ }
return true;
case "Escape":
event.preventDefault();
@@ -192,7 +241,15 @@ export function useCommandAutocomplete({
return false;
}
},
- [isOpen, items.length, complete, query, hasExactCommandMatch],
+ [
+ isOpen,
+ items.length,
+ complete,
+ pick,
+ inChoiceMode,
+ query,
+ hasExactCommandMatch,
+ ],
);
return {