diff --git a/ui/AGENTS.md b/ui/AGENTS.md
index 7637d1044..bfe89c240 100644
--- a/ui/AGENTS.md
+++ b/ui/AGENTS.md
@@ -101,6 +101,14 @@ state; the UI presents them and submits operator choices.
and table semantics. A hover action must also be reachable by keyboard.
- Keep filtering and pagination consistent with the server. State limitations
such as sorting only loaded rows when they affect the operator's decision.
+- `@ui-sdk/vue` and `@ui-sdk/core` are adopted incrementally alongside
+ `components/ui` (`shadcn-vue` / Reka UI) for high-value interactive
+ components and custom behaviors. Before writing or editing `@ui-sdk` code,
+ read `node_modules/@ui-sdk/core/skills/ui-sdk/SKILL.md` and
+ `node_modules/@ui-sdk/vue/docs/llms.txt` (and `core.md` / `rendering.md` when
+ building a custom primitive). Give every `@ui-sdk` control a clear accessible
+ name, sync state through change callbacks, and mark destructive actions with
+ `data-agent-confirm`.
## Tests
diff --git a/ui/package.json b/ui/package.json
index 861699b43..a030edd43 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -16,6 +16,8 @@
"@lucide/vue": "^1.61.0",
"@tailwindcss/vite": "^4.3.3",
"@tanstack/vue-form": "^1.33.5",
+ "@ui-sdk/core": "0.1.0-beta.16",
+ "@ui-sdk/vue": "0.1.0-beta.16",
"@vue-flow/background": "^1.3.2",
"@vue-flow/core": "^1.48.2",
"@vueuse/core": "^15.0.0",
diff --git a/ui/pnpm-lock.yaml b/ui/pnpm-lock.yaml
index 16066b38c..7abbbb4d0 100644
--- a/ui/pnpm-lock.yaml
+++ b/ui/pnpm-lock.yaml
@@ -181,6 +181,12 @@ importers:
'@tanstack/vue-form':
specifier: ^1.33.5
version: 1.33.5(vue@3.5.44(typescript@6.0.3))
+ '@ui-sdk/core':
+ specifier: 0.1.0-beta.16
+ version: 0.1.0-beta.16
+ '@ui-sdk/vue':
+ specifier: 0.1.0-beta.16
+ version: 0.1.0-beta.16(@ui-sdk/core@0.1.0-beta.16)(vue@3.5.44(typescript@6.0.3))
'@vue-flow/background':
specifier: ^1.3.2
version: 1.3.2(@vue-flow/core@1.48.2(vue@3.5.44(typescript@6.0.3)))(vue@3.5.44(typescript@6.0.3))
@@ -650,6 +656,25 @@ packages:
'@types/web-bluetooth@0.0.21':
resolution: {integrity: sha512-oIQLCGWtcFZy2JW77j9k8nHzAOpqMHLQejDA48XXMWH6tjCQHz5RCFz1bzsmROyL6PUm+LLnUiI4BCn221inxA==}
+ '@ui-sdk/core@0.1.0-beta.16':
+ resolution: {integrity: sha512-I2GMqOviLS/lYfIj2lTqKLbae0V9uSnysK+bSdbhuw2De8zNvrLZiDTc0qzsPNiZvB/bMmUZJS5UDA5Q2Pq4Ng==}
+
+ '@ui-sdk/vue@0.1.0-beta.16':
+ resolution: {integrity: sha512-9Y4aMVrrYrYDNBgiJs1AWW1S6giJQ7wfmyEvN6fU0j3gyO5qmLQ1xLBmZmuCQv1Wt0AIL9VfGpAclW4ZF45IOA==}
+ peerDependencies:
+ '@nuxt/kit': ^4.0.0 || ^5.0.0-0
+ '@nuxt/schema': ^4.0.0 || ^5.0.0-0
+ '@ui-sdk/core': ^0.1.0-beta.16
+ nuxt: ^4.0.0 || ^5.0.0-0
+ vue: '>=3.5'
+ peerDependenciesMeta:
+ '@nuxt/kit':
+ optional: true
+ '@nuxt/schema':
+ optional: true
+ nuxt:
+ optional: true
+
'@ungap/structured-clone@1.4.0':
resolution: {integrity: sha512-1mEZtMKPM09vDmQt5y7YvmN2+DFTP7Tg0EWXdic8/C6VRnpb33e4ghisCIE3WZjsE2N8mf+QV1Zqh7ZFYLWInQ==}
@@ -2016,6 +2041,13 @@ snapshots:
'@types/web-bluetooth@0.0.21': {}
+ '@ui-sdk/core@0.1.0-beta.16': {}
+
+ '@ui-sdk/vue@0.1.0-beta.16(@ui-sdk/core@0.1.0-beta.16)(vue@3.5.44(typescript@6.0.3))':
+ dependencies:
+ '@ui-sdk/core': 0.1.0-beta.16
+ vue: 3.5.44(typescript@6.0.3)
+
'@ungap/structured-clone@1.4.0': {}
'@vitejs/plugin-vue@6.0.10(vite@8.3.5(@types/node@26.6.5)(jiti@2.7.0)(yaml@2.9.1))(vue@3.5.44(typescript@6.0.3))':
diff --git a/ui/pnpm-workspace.yaml b/ui/pnpm-workspace.yaml
index ae1acadb9..2d2558150 100644
--- a/ui/pnpm-workspace.yaml
+++ b/ui/pnpm-workspace.yaml
@@ -1,2 +1,5 @@
allowBuilds:
vue-demi: true
+minimumReleaseAgeExclude:
+ - '@ui-sdk/core@0.1.0-beta.16'
+ - '@ui-sdk/vue@0.1.0-beta.16'
diff --git a/ui/src/chat/ChatComposer.vue b/ui/src/chat/ChatComposer.vue
index abd8a53b4..f2f4e5105 100644
--- a/ui/src/chat/ChatComposer.vue
+++ b/ui/src/chat/ChatComposer.vue
@@ -1,73 +1,65 @@
@@ -247,56 +249,76 @@ function onKeydown(event: KeyboardEvent): void {
/>
-
-
-
-
+
+
+
+
+ {{ menuHeading(state.trigger) }}
+
+ No matches
+
+ {{ item.label }}
+ {{ item.detail }}
+
+
+
+
+
+
+
+ {{ token.type === "workflow" ? `@${token.label}` : token.label }}
+
+
+
+
+
-
-
-
+
-
+
diff --git a/ui/src/chat/ChatSlashPalette.vue b/ui/src/chat/ChatSlashPalette.vue
deleted file mode 100644
index 42f1079c3..000000000
--- a/ui/src/chat/ChatSlashPalette.vue
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
-
-
-
- {{ error }}
-
-
-
-
-
diff --git a/ui/src/chat/commands.ts b/ui/src/chat/commands.ts
deleted file mode 100644
index 559059a5a..000000000
--- a/ui/src/chat/commands.ts
+++ /dev/null
@@ -1,102 +0,0 @@
-import type { ChatCommandSpec, TaskRef } from "./state";
-
-/**
- * The composer palette's arithmetic, kept out of the composer so it is decided
- * in one place rather than reconstructed from DOM positions twice. Two
- * triggers share it: `/` completes a command, `#` picks a task.
- */
-
-export type Trigger = "/" | "#";
-
-/** One row of the palette: what is shown, and the key that identifies it. */
-export interface Completion {
- key: string;
- label: string;
- detail: string;
-}
-
-/** The trigger word the caret sits in: at the start or after whitespace. */
-const OPEN_TOKEN = /(?:^|\s)([/#])([^\s]*)$/;
-
-/** How many matches the palette will show at once. */
-const MAX_MATCHES = 8;
-
-/** detectTrigger returns the trigger and the text typed after it, if any. */
-export function detectTrigger(
- value: string,
- caret: number,
-): { trigger: Trigger; query: string } | null {
- const match = value.slice(0, caret).match(OPEN_TOKEN);
- if (!match) return null;
- return { trigger: match[1] as Trigger, query: match[2].toLowerCase() };
-}
-
-/** Commands matched on the command and its description together. */
-export function commandCompletions(
- specs: ChatCommandSpec[],
- query: string,
-): Completion[] {
- return specs
- .filter((spec) =>
- `${spec.command} ${spec.description ?? ""}`.toLowerCase().includes(query),
- )
- .slice(0, MAX_MATCHES)
- .map((spec) => ({
- key: spec.command,
- label: spec.command,
- detail: spec.description || spec.usage || "",
- }));
-}
-
-/** Tasks matched on id and title, so `#12` and a title word both find one. */
-export function taskCompletions(tasks: TaskRef[], query: string): Completion[] {
- return tasks
- .filter((task) =>
- `${task.id} ${task.title ?? ""}`.toLowerCase().includes(query),
- )
- .slice(0, MAX_MATCHES)
- .map((task) => ({
- key: String(task.id),
- label: `#${task.id}`,
- detail: task.title ?? "",
- }));
-}
-
-/**
- * replaceToken swaps the trigger word the caret sits in for `insert` and
- * returns the caret just after it. A space follows the insert unless one
- * already does, so completing mid-sentence never doubles it. An empty insert
- * removes the token.
- */
-export function replaceToken(
- value: string,
- caret: number,
- insert: string,
-): { text: string; cursor: number } {
- const before = value.slice(0, caret);
- const after = value.slice(caret);
- const start = before.search(/(?:^|\s)[/#][^\s]*$/);
- const tokenStart =
- start < 0 ? before.length : start + (/\s/.test(before[start]) ? 1 : 0);
- const head = before.slice(0, tokenStart);
- const gap = insert === "" || /^\s/.test(after) ? "" : " ";
- // Removing the token must not leave the words either side of it two spaces apart.
- const tail = insert === "" && /\s$/.test(head) ? after.replace(/^[ \t]/, "") : after;
- return {
- text: `${head}${insert}${gap}${tail}`,
- cursor: tokenStart + insert.length + gap.length,
- };
-}
-
-/**
- * isExactCommand reports whether the composer already holds a command and
- * nothing else. Enter then sends it rather than completing it, so a command
- * typed in full is never re-entered by the palette that was offering it.
- */
-export function isExactCommand(
- specs: ChatCommandSpec[],
- value: string,
-): boolean {
- const trimmed = value.trim();
- return specs.some((spec) => spec.command === trimmed);
-}
diff --git a/ui/src/chat/prompt-tokens.ts b/ui/src/chat/prompt-tokens.ts
new file mode 100644
index 000000000..51040e9cf
--- /dev/null
+++ b/ui/src/chat/prompt-tokens.ts
@@ -0,0 +1,16 @@
+import type { TokenInputValue } from "@ui-sdk/core/token-input";
+
+/**
+ * Serializes a TokenInputValue into the plain text sent in a chat turn.
+ * Commands keep their slash label, tasks emit `#`, and workflows emit `@`.
+ */
+export function serializePromptValue(value: TokenInputValue): string {
+ return value
+ .map((segment) => {
+ if (typeof segment === "string") return segment;
+ if (segment.type === "task") return `#${segment.value}`;
+ if (segment.type === "workflow") return `@${segment.label}`;
+ return segment.label;
+ })
+ .join("");
+}
diff --git a/ui/src/chat/state.ts b/ui/src/chat/state.ts
index 14ed90719..66ec9a330 100644
--- a/ui/src/chat/state.ts
+++ b/ui/src/chat/state.ts
@@ -4,8 +4,6 @@ import { errors } from "@/copy/errors";
import { api, describeError, type ChatTurnRecord } from "@/lib/api";
import { router } from "@/router";
import { answerApproval } from "@/runs/answer";
-import { useSessionStore } from "@/stores/session";
-import { commandCompletions, detectTrigger, taskCompletions, type Completion, type Trigger } from "./commands";
import {
resolveTurn,
retryChatTurn,
@@ -291,13 +289,6 @@ export const selectedModel = ref("");
export const chatModelReady = computed(() => !!selectorData.value.active_model);
export const commandSpecs = ref([]);
-export const commandMatches = ref([]);
-/** Which trigger the open menu was opened by. */
-export const menuTrigger = ref("/");
-/** Why the task list could not be read; shown in the menu, with a retry. */
-export const taskLoadError = ref("");
-export const commandSelection = ref(0);
-export const isCommandMenuOpen = ref(false);
/**
* How many layers inside the panel currently own Escape -- an open popover, a
@@ -657,91 +648,6 @@ export function editQueued(index: number): void {
composerText.value = composerText.value.trim() ? `${composerText.value}\n${text}` : text;
}
-let taskChoices: TaskRef[] = [];
-let loadGeneration = 0;
-let lastInput = { value: "", caret: 0 };
-
-async function loadTasks(): Promise {
- const generation = ++loadGeneration;
- try {
- const page = await api.taskPage({ limit: 100 });
- if (generation !== loadGeneration) return;
- taskChoices = page.tasks;
- taskLoadError.value = "";
- } catch (err) {
- if (generation !== loadGeneration) return;
- taskLoadError.value = describeError(err, errors.chat.tasks.load);
- }
- renderMenu();
-}
-
-/** Reads the task list again after a failure, for the menu's Retry. */
-export function retryTasks(): void {
- taskLoadError.value = "";
- void loadTasks();
-}
-
-/** Opens the palette for the trigger word the caret sits in, or closes it. */
-export function syncCommandMenu(value: string, caret: number): void {
- lastInput = { value, caret };
- // The list is read when # is first typed, so it is never older than the
- // moment the operator reached for it.
- if (
- tasksBacked() &&
- detectTrigger(value, caret)?.trigger === "#" &&
- (!isCommandMenuOpen.value || menuTrigger.value !== "#")
- ) {
- taskLoadError.value = "";
- void loadTasks();
- }
- renderMenu();
-}
-
-// # attaches a task, which needs the server's task list; without one the
-// trigger is plain text.
-function tasksBacked(): boolean {
- return useSessionStore().sections?.tasks !== false;
-}
-
-function renderMenu(): void {
- const trigger = detectTrigger(lastInput.value, lastInput.caret);
- const found = trigger?.trigger === "#" && !tasksBacked() ? null : trigger;
- let matches: Completion[] = [];
- if (found?.trigger === "/") {
- matches = commandCompletions(commandSpecs.value, found.query);
- } else if (found?.trigger === "#") {
- matches = taskCompletions(taskChoices, found.query);
- }
- const showsError = found?.trigger === "#" && !!taskLoadError.value;
- if (!found || (!matches.length && !showsError)) {
- isCommandMenuOpen.value = false;
- commandMatches.value = [];
- return;
- }
- if (!isCommandMenuOpen.value || menuTrigger.value !== found.trigger) {
- commandSelection.value = 0;
- }
- menuTrigger.value = found.trigger;
- commandMatches.value = matches;
- commandSelection.value = Math.min(commandSelection.value, Math.max(matches.length - 1, 0));
- isCommandMenuOpen.value = true;
-}
-
-/** The task a menu row stands for. */
-export function taskForKey(key: string): TaskRef | undefined {
- return taskChoices.find((task) => String(task.id) === key);
-}
-
-export function closeCommandMenu(): void {
- isCommandMenuOpen.value = false;
-}
-
-export function moveCommandSelection(delta: number): void {
- const length = commandMatches.value.length;
- if (!length) return;
- commandSelection.value = (commandSelection.value + delta + length) % length;
-}
-
/** The page the operator is on, without the hash the server never sees. */
function currentPage(): string {
return router.currentRoute.value.fullPath.split("#")[0] || "/";
@@ -803,11 +709,9 @@ export async function sendMessage(retryOpts?: RetryOptions): Promise {
}
queuedMessages.value = [...queuedMessages.value, text];
if (explicitText === undefined) clearDraft();
- closeCommandMenu();
return;
}
- closeCommandMenu();
isSending.value = true;
statusText.value = isRetry ? "Retrying…" : "Thinking…";
diff --git a/ui/src/lib/archie-webmcp.ts b/ui/src/lib/archie-webmcp.ts
index bc581c20f..80fc632de 100644
--- a/ui/src/lib/archie-webmcp.ts
+++ b/ui/src/lib/archie-webmcp.ts
@@ -4,10 +4,12 @@
// the UI calls, so the agent and the interface exercise one set of endpoints,
// one CSRF header, and one error shape.
import { api } from "./api";
+import { uiAgent, uiAgentWebMcpTools } from "./ui-agent";
import { createWebMcpRegistrar } from "./webmcp";
import { archieWebMcpTools } from "./webmcp-tools";
-/** Registers the dashboard's tools, replacing any earlier registration. */
-export const registerArchieWebMcpTools = createWebMcpRegistrar(
- archieWebMcpTools(api),
-);
+/** Registers the dashboard's API and @ui-sdk component tools, replacing any earlier registration. */
+export const registerArchieWebMcpTools = createWebMcpRegistrar([
+ ...archieWebMcpTools(api),
+ ...uiAgentWebMcpTools(uiAgent),
+]);
diff --git a/ui/src/lib/ui-agent.ts b/ui/src/lib/ui-agent.ts
new file mode 100644
index 000000000..b79b8ce7c
--- /dev/null
+++ b/ui/src/lib/ui-agent.ts
@@ -0,0 +1,118 @@
+import { agentTools, createAgent, type AgentAction, type AgentStep } from "@ui-sdk/vue/agent";
+
+import type { WebMcpTool } from "./webmcp";
+
+export type UiAgent = ReturnType;
+
+type ConfirmHandler = (
+ step: AgentAction,
+ context: { signal: AbortSignal },
+) => boolean | Promise;
+
+let confirmHandler: ConfirmHandler | null = null;
+
+/** Registers an operator confirmation handler for steps marked with data-agent-confirm. */
+export function setUiAgentConfirmHandler(handler: ConfirmHandler | null): void {
+ confirmHandler = handler;
+}
+
+/** Creates a @ui-sdk agent bridge that refuses unconfirmed data-agent-confirm steps. */
+export function createUiAgent(allowConfirm?: ConfirmHandler): UiAgent {
+ return createAgent({
+ allow: (step, context) => {
+ if (!step.confirm) return true;
+ const handler = allowConfirm ?? confirmHandler;
+ return handler ? handler(step, context) : false;
+ },
+ });
+}
+
+/**
+ * Shared dashboard UI agent bridge. Instantiated at module load before the Vue
+ * app mounts so every @ui-sdk component registers its contract as it mounts.
+ */
+export const uiAgent = createUiAgent();
+
+function jsonEnvelope(value: unknown): { content: Array<{ type: "text"; text: string }> } {
+ return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
+}
+
+/** Exposes @ui-sdk's snapshot, query, and act bridge as WebMCP tools. */
+export function uiAgentWebMcpTools(agent: UiAgent = uiAgent): WebMcpTool[] {
+ const byName = new Map(agentTools.map((tool) => [tool.name, tool]));
+ const snapshotDef = byName.get("snapshot");
+ const queryDef = byName.get("query");
+ const actDef = byName.get("act");
+
+ return [
+ {
+ name: "ui_snapshot",
+ description:
+ snapshotDef?.description ??
+ "List the mounted @ui-sdk dashboard components, their state, and their bounded actions. Read-only.",
+ inputSchema: (snapshotDef?.inputSchema as Record) ?? {
+ type: "object",
+ properties: {},
+ additionalProperties: false,
+ },
+ annotations: { readOnlyHint: true, untrustedContentHint: true },
+ execute: () => jsonEnvelope(agent.snapshot()),
+ },
+ {
+ name: "ui_query",
+ description:
+ queryDef?.description ??
+ "Find mounted @ui-sdk dashboard components or list items by label, text, or kind. Read-only.",
+ inputSchema: (queryDef?.inputSchema as Record) ?? {
+ type: "object",
+ properties: {
+ text: { type: "string" },
+ within: { type: "string" },
+ kind: { type: "string" },
+ },
+ additionalProperties: false,
+ },
+ annotations: { readOnlyHint: true, untrustedContentHint: true },
+ execute: async (input) =>
+ jsonEnvelope(
+ await agent.query({
+ text: typeof input.text === "string" ? input.text : undefined,
+ within: typeof input.within === "string" ? input.within : undefined,
+ kind: typeof input.kind === "string" ? input.kind : undefined,
+ }),
+ ),
+ },
+ {
+ name: "ui_act",
+ description:
+ actDef?.description ??
+ "Run bounded actions on mounted @ui-sdk dashboard components in order. Steps marked for confirmation require operator approval.",
+ inputSchema: (actDef?.inputSchema as Record) ?? {
+ type: "object",
+ properties: {
+ steps: {
+ type: "array",
+ items: {
+ type: "object",
+ properties: {
+ ref: { type: "string" },
+ action: { type: "string" },
+ args: { type: "array" },
+ },
+ required: ["ref", "action"],
+ },
+ },
+ },
+ required: ["steps"],
+ additionalProperties: false,
+ },
+ annotations: { readOnlyHint: false, consequentialHint: true },
+ execute: async (input) => {
+ if (!Array.isArray(input.steps)) {
+ throw new Error("ui_act: steps must be an array");
+ }
+ return jsonEnvelope(await agent.act({ steps: input.steps as AgentStep[] }));
+ },
+ },
+ ];
+}
diff --git a/ui/src/schedules/CronRuleBuilder.vue b/ui/src/schedules/CronRuleBuilder.vue
new file mode 100644
index 000000000..b28d8eb93
--- /dev/null
+++ b/ui/src/schedules/CronRuleBuilder.vue
@@ -0,0 +1,199 @@
+
+
+
+
+
+ Repeats
+
+
+
+
+
+
+
+ Time
+
+
+
+
+ Day of month
+
+
+
+
+
+
+
+
+
+ Days
+
+
+
+
+
+
+ Cron expression
+
+
+
+
+
+ {{ previewWords }}
+ {{ validationHint }}
+
+
+
diff --git a/ui/src/schedules/ScheduleEditor.vue b/ui/src/schedules/ScheduleEditor.vue
index 18ffc8790..f0b3121cd 100644
--- a/ui/src/schedules/ScheduleEditor.vue
+++ b/ui/src/schedules/ScheduleEditor.vue
@@ -11,7 +11,8 @@ import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
import { api, describeError } from "@/lib/api";
import { errors } from "@/copy/errors";
import { useAppearanceStore } from "@/stores/appearance";
-import { cronWords, fromWallTime, toWallTime, type Schedule, type ScheduleTiming } from "./schedule";
+import CronRuleBuilder from "./CronRuleBuilder.vue";
+import { fromWallTime, toWallTime, type Schedule, type ScheduleTiming } from "./schedule";
/**
* Creates or edits one schedule. A built-in schedule keeps its name; only its
@@ -54,10 +55,6 @@ const wallTime = computed({
get: () => toWallTime(timing.value.at, appearance.timeZone),
set: (value: string) => (timing.value.at = fromWallTime(value, appearance.timeZone)),
});
-const cronPreview = computed(() => {
- const words = cronWords(timing.value.cron);
- return words === timing.value.cron ? "" : words;
-});
async function save(): Promise {
if (!props.schedule) return;
@@ -93,10 +90,7 @@ async function save(): Promise {
{{ option.label }}
-
+
diff --git a/ui/src/schedules/cron-rule.ts b/ui/src/schedules/cron-rule.ts
new file mode 100644
index 000000000..c1dece8f4
--- /dev/null
+++ b/ui/src/schedules/cron-rule.ts
@@ -0,0 +1,85 @@
+export type CronRule =
+ | { cadence: "daily"; time: string }
+ | { cadence: "weekly"; time: string; weekdays: readonly number[] }
+ | { cadence: "monthly"; time: string; day: number };
+
+const NUMBER = /^\d+$/;
+
+function clockFields(time: string): [number, number] | null {
+ const match = /^(\d{2}):(\d{2})$/.exec(time);
+ if (!match) return null;
+ const hour = Number(match[1]);
+ const minute = Number(match[2]);
+ if (hour > 23 || minute > 59) return null;
+ return [hour, minute];
+}
+
+function weekdayField(values: readonly number[]): string | null {
+ if (!values.length || values.some((day) => !Number.isInteger(day) || day < 0 || day > 6)) {
+ return null;
+ }
+ const days = [...new Set(values)].sort((a, b) => a - b);
+ if (days.length === 7) return "*";
+ if (days.join(",") === "1,2,3,4,5") return "1-5";
+ if (days.join(",") === "0,6") return "0,6";
+ return days.join(",");
+}
+
+function parseWeekdays(field: string): number[] | null {
+ if (field === "1-5") return [1, 2, 3, 4, 5];
+ const parts = field.split(",");
+ if (!parts.length) return null;
+ const days: number[] = [];
+ for (const part of parts) {
+ if (!NUMBER.test(part)) return null;
+ const value = Number(part);
+ if (value < 0 || value > 7) return null;
+ days.push(value % 7);
+ }
+ return [...new Set(days)].sort((a, b) => a - b);
+}
+
+/** Emits a canonical 5-field cron expression for a guided recurrence rule. */
+export function cronForRule(rule: CronRule): string | null {
+ const clock = clockFields(rule.time);
+ if (!clock) return null;
+ const [hour, minute] = clock;
+ if (rule.cadence === "daily") return `${minute} ${hour} * * *`;
+ if (rule.cadence === "weekly") {
+ const weekdays = weekdayField(rule.weekdays);
+ return weekdays === null ? null : `${minute} ${hour} * * ${weekdays}`;
+ }
+ if (rule.cadence === "monthly") {
+ return Number.isInteger(rule.day) && rule.day >= 1 && rule.day <= 31
+ ? `${minute} ${hour} ${rule.day} * *`
+ : null;
+ }
+ return null;
+}
+
+/** Parses a 5-field cron expression into a guided recurrence rule, or null if custom. */
+export function parseCronRule(expression: string | undefined): CronRule | null {
+ const fields = (expression ?? "").trim().split(/\s+/);
+ if (fields.length !== 5) return null;
+ const [minuteField, hourField, domField, monthField, dowField] = fields as [
+ string,
+ string,
+ string,
+ string,
+ string,
+ ];
+ if (monthField !== "*" || !NUMBER.test(minuteField) || !NUMBER.test(hourField)) return null;
+ const minute = Number(minuteField);
+ const hour = Number(hourField);
+ if (minute > 59 || hour > 23) return null;
+ const time = `${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}`;
+
+ if (domField !== "*") {
+ if (dowField !== "*" || !NUMBER.test(domField)) return null;
+ const day = Number(domField);
+ return day >= 1 && day <= 31 ? { cadence: "monthly", time, day } : null;
+ }
+ if (dowField === "*") return { cadence: "daily", time };
+ const weekdays = parseWeekdays(dowField);
+ return weekdays?.length ? { cadence: "weekly", time, weekdays } : null;
+}
diff --git a/ui/src/style.css b/ui/src/style.css
index 1003bd6dc..e075e3288 100644
--- a/ui/src/style.css
+++ b/ui/src/style.css
@@ -48,6 +48,8 @@
unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
+@layer ui-sdk;
+
@import "tailwindcss";
@import "tw-animate-css";
@import "./shadcn.css";
@@ -350,6 +352,12 @@
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
}
+
+ [data-slot="token-input-editor"][data-empty]::before {
+ content: attr(data-placeholder);
+ color: var(--muted-foreground);
+ pointer-events: none;
+ }
}
/* Widens a control's tap area to 44px on a phone without changing how it looks
diff --git a/ui/test/prompt-tokens.test.ts b/ui/test/prompt-tokens.test.ts
new file mode 100644
index 000000000..689e00daf
--- /dev/null
+++ b/ui/test/prompt-tokens.test.ts
@@ -0,0 +1,27 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { serializePromptValue } from "../src/chat/prompt-tokens.ts";
+
+test("serializePromptValue maps text and tokens into the chat wire format", () => {
+ const cases = [
+ [["Review the retry policy"], "Review the retry policy"],
+ [
+ [
+ "Check ",
+ { id: "1", type: "task", value: "42", label: "#42" },
+ " in ",
+ { id: "2", type: "workflow", value: "wf-1", label: "Event triage" },
+ ],
+ "Check #42 in @Event triage",
+ ],
+ [
+ [{ id: "3", type: "command", value: "/help", label: "/help" }, " schedules"],
+ "/help schedules",
+ ],
+ ] as const;
+
+ for (const [value, expected] of cases) {
+ assert.equal(serializePromptValue([...value]), expected);
+ }
+});
diff --git a/ui/test/schedule-rule.test.ts b/ui/test/schedule-rule.test.ts
new file mode 100644
index 000000000..9adb477a2
--- /dev/null
+++ b/ui/test/schedule-rule.test.ts
@@ -0,0 +1,53 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { cronForRule, parseCronRule } from "../src/schedules/cron-rule.ts";
+
+test("cronForRule emits canonical cron for guided recurrence patterns", () => {
+ const cases = [
+ [{ cadence: "daily", time: "09:05" }, "5 9 * * *"],
+ [{ cadence: "weekly", time: "08:00", weekdays: [1, 2, 3, 4, 5] }, "0 8 * * 1-5"],
+ [{ cadence: "weekly", time: "23:15", weekdays: [0, 6] }, "15 23 * * 0,6"],
+ [{ cadence: "weekly", time: "08:00", weekdays: [6, 0, 2, 2] }, "0 8 * * 0,2,6"],
+ [{ cadence: "weekly", time: "07:30", weekdays: [0, 1, 2, 3, 4, 5, 6] }, "30 7 * * *"],
+ [{ cadence: "monthly", time: "09:30", day: 31 }, "30 9 31 * *"],
+ ] as const;
+
+ for (const [rule, expected] of cases) {
+ assert.equal(cronForRule(rule), expected, JSON.stringify(rule));
+ }
+});
+
+test("cronForRule rejects invalid times and incomplete patterns", () => {
+ const cases = [
+ { cadence: "daily", time: "9:05" },
+ { cadence: "daily", time: "24:00" },
+ { cadence: "daily", time: "09:60" },
+ { cadence: "weekly", time: "09:00", weekdays: [] },
+ { cadence: "weekly", time: "09:00", weekdays: [7] },
+ { cadence: "monthly", time: "09:00", day: 0 },
+ { cadence: "monthly", time: "09:00", day: 32 },
+ ] as const;
+
+ for (const rule of cases) {
+ assert.equal(cronForRule(rule), null, JSON.stringify(rule));
+ }
+});
+
+test("parseCronRule round-trips guided expressions and leaves custom ones untouched", () => {
+ const cases = [
+ ["5 9 * * *", { cadence: "daily", time: "09:05" }],
+ ["0 8 * * 1-5", { cadence: "weekly", time: "08:00", weekdays: [1, 2, 3, 4, 5] }],
+ ["15 23 * * 0,6", { cadence: "weekly", time: "23:15", weekdays: [0, 6] }],
+ ["0 9 * * 7", { cadence: "weekly", time: "09:00", weekdays: [0] }],
+ ["30 9 15 * *", { cadence: "monthly", time: "09:30", day: 15 }],
+ ["*/15 * * * *", null],
+ ["0 9 * 1 *", null],
+ ["0 9 1 * 1", null],
+ ["not-a-cron", null],
+ ] as const;
+
+ for (const [expression, expected] of cases) {
+ assert.deepEqual(parseCronRule(expression), expected, expression);
+ }
+});
diff --git a/ui/test/ui-agent.test.ts b/ui/test/ui-agent.test.ts
new file mode 100644
index 000000000..7e96e39c5
--- /dev/null
+++ b/ui/test/ui-agent.test.ts
@@ -0,0 +1,59 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import { uiAgentWebMcpTools, type UiAgent } from "../src/lib/ui-agent.ts";
+
+function fakeUiAgent(): {
+ calls: Array<{ method: string; args: unknown[] }>;
+ agent: UiAgent;
+} {
+ const calls: Array<{ method: string; args: unknown[] }> = [];
+ const agent = {
+ snapshot: () => {
+ calls.push({ method: "snapshot", args: [] });
+ return [{ ref: "c1", component: "radio-group", label: "Repeats", value: "weekly", actions: ["setValue"] }];
+ },
+ query: async (input: { text?: string; within?: string; kind?: string }) => {
+ calls.push({ method: "query", args: [input] });
+ return [];
+ },
+ act: async (input: { steps: unknown[] }) => {
+ calls.push({ method: "act", args: [input] });
+ return { ok: true, appeared: [], values: {}, steps: [] };
+ },
+ subscribe: () => () => {},
+ } as unknown as UiAgent;
+ return { calls, agent };
+}
+
+test("uiAgentWebMcpTools publishes snapshot, query, and act with expected annotations", async () => {
+ const { calls, agent } = fakeUiAgent();
+ const tools = uiAgentWebMcpTools(agent);
+ assert.deepEqual(
+ tools.map((tool) => tool.name),
+ ["ui_snapshot", "ui_query", "ui_act"],
+ );
+
+ const snapshot = tools[0]!;
+ const query = tools[1]!;
+ const act = tools[2]!;
+
+ assert.equal(snapshot.annotations.readOnlyHint, true);
+ assert.equal(query.annotations.readOnlyHint, true);
+ assert.equal(act.annotations.readOnlyHint, false);
+ assert.equal(act.annotations.consequentialHint, true);
+
+ await snapshot.execute({});
+ await query.execute({ text: "Repeats", kind: "radio-group" });
+ await act.execute({ steps: [{ ref: "Repeats", action: "setValue", args: ["daily"] }] });
+
+ assert.deepEqual(
+ calls.map((c) => c.method),
+ ["snapshot", "query", "act"],
+ );
+
+ await assert.rejects(
+ async () => act.execute({ steps: "not-an-array" }),
+ /steps must be an array/,
+ );
+});