From fe4d5749769720fb49da4eaa996a295133f7f22b Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Wed, 25 Nov 2026 22:11:42 +1100 Subject: [PATCH] feat(ui): add an isolated UI SDK lab under devtools The lab is a dev-only route and a standalone entry so beta SDK patterns stay out of shipped pages while they are evaluated. --- ui/AGENTS.md | 5 + ui/package.json | 2 + ui/pnpm-lock.yaml | 32 ++ ui/pnpm-workspace.yaml | 3 + ui/src/devtools/ui-sdk/UiSdkLabPage.vue | 480 +++++++++++++++++++ ui/src/devtools/ui-sdk/schedule-rule.ts | 43 ++ ui/src/devtools/ui-sdk/standalone.ts | 6 + ui/src/devtools/ui-sdk/triage-score-parts.ts | 10 + ui/src/devtools/ui-sdk/triage-score.ts | 100 ++++ ui/src/router/routes.ts | 8 + ui/test/schedule-rule.test.ts | 35 ++ ui/ui-sdk-lab.html | 13 + 12 files changed, 737 insertions(+) create mode 100644 ui/src/devtools/ui-sdk/UiSdkLabPage.vue create mode 100644 ui/src/devtools/ui-sdk/schedule-rule.ts create mode 100644 ui/src/devtools/ui-sdk/standalone.ts create mode 100644 ui/src/devtools/ui-sdk/triage-score-parts.ts create mode 100644 ui/src/devtools/ui-sdk/triage-score.ts create mode 100644 ui/test/schedule-rule.test.ts create mode 100644 ui/ui-sdk-lab.html diff --git a/ui/AGENTS.md b/ui/AGENTS.md index 7637d1044..fa0fa0b4a 100644 --- a/ui/AGENTS.md +++ b/ui/AGENTS.md @@ -101,6 +101,11 @@ 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 is an isolated beta experiment in `src/devtools/ui-sdk` and + `ui-sdk-lab.html`. When editing it, read the installed skill at + `node_modules/@ui-sdk/core/skills/ui-sdk/SKILL.md` and matching package docs. + Keep patterns dev-only until the beta terms and package-age exception are + reviewed. ## Tests diff --git a/ui/package.json b/ui/package.json index 861699b43..b6e0a94c7 100644 --- a/ui/package.json +++ b/ui/package.json @@ -42,6 +42,8 @@ "@types/hast": "^3.0.5", "@types/node": "^26.6.4", "@types/qrcode": "^1.5.6", + "@ui-sdk/core": "0.1.0-beta.16", + "@ui-sdk/vue": "0.1.0-beta.16", "@vitejs/plugin-vue": "^6.0.8", "@vue/tsconfig": "^0.9.1", "typescript": "~6.0.3", diff --git a/ui/pnpm-lock.yaml b/ui/pnpm-lock.yaml index 16066b38c..d371fb0fd 100644 --- a/ui/pnpm-lock.yaml +++ b/ui/pnpm-lock.yaml @@ -254,6 +254,12 @@ importers: '@types/qrcode': specifier: ^1.5.6 version: 1.5.6 + '@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)) '@vitejs/plugin-vue': specifier: ^6.0.8 version: 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)) @@ -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/devtools/ui-sdk/UiSdkLabPage.vue b/ui/src/devtools/ui-sdk/UiSdkLabPage.vue new file mode 100644 index 000000000..0b96db135 --- /dev/null +++ b/ui/src/devtools/ui-sdk/UiSdkLabPage.vue @@ -0,0 +1,480 @@ + + + diff --git a/ui/src/devtools/ui-sdk/schedule-rule.ts b/ui/src/devtools/ui-sdk/schedule-rule.ts new file mode 100644 index 000000000..2003837ae --- /dev/null +++ b/ui/src/devtools/ui-sdk/schedule-rule.ts @@ -0,0 +1,43 @@ +export type CronRule = + | { cadence: "daily"; time: string } + | { cadence: "weekly"; time: string; weekdays: readonly number[] } + | { cadence: "monthly"; time: string; day: number }; + +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(","); +} + +export function cronForRule(rule: CronRule): string | null { + if ("cadence" in rule && "time" in rule) { + 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; +} diff --git a/ui/src/devtools/ui-sdk/standalone.ts b/ui/src/devtools/ui-sdk/standalone.ts new file mode 100644 index 000000000..19f41f2bb --- /dev/null +++ b/ui/src/devtools/ui-sdk/standalone.ts @@ -0,0 +1,6 @@ +import { createApp } from "vue"; + +import UiSdkLabPage from "./UiSdkLabPage.vue"; +import "../../style.css"; + +createApp(UiSdkLabPage).mount("#app"); diff --git a/ui/src/devtools/ui-sdk/triage-score-parts.ts b/ui/src/devtools/ui-sdk/triage-score-parts.ts new file mode 100644 index 000000000..d20b294b3 --- /dev/null +++ b/ui/src/devtools/ui-sdk/triage-score-parts.ts @@ -0,0 +1,10 @@ +import { createParts } from "@ui-sdk/vue/primitive"; + +import { triageScore } from "./triage-score"; + +const { Root: TriageScore, Score: TriageScoreOption } = createParts( + triageScore, + { root: "div", score: "button" }, +); + +export { TriageScore, TriageScoreOption }; diff --git a/ui/src/devtools/ui-sdk/triage-score.ts b/ui/src/devtools/ui-sdk/triage-score.ts new file mode 100644 index 000000000..49116e844 --- /dev/null +++ b/ui/src/devtools/ui-sdk/triage-score.ts @@ -0,0 +1,100 @@ +import { + createChange, + createRovingFocus, + definePrimitive, + type ChangeDetails, +} from "@ui-sdk/core"; + +type TriageScoreOptions = { + value?: number; + defaultValue?: number; + onValueChange?: ( + value: number, + details: ChangeDetails<"item-press" | "list-navigation">, + ) => void; +}; + +const scores = [ + { value: 1, label: "Very low" }, + { value: 2, label: "Low" }, + { value: 3, label: "Moderate" }, + { value: 4, label: "High" }, + { value: 5, label: "Very high" }, +]; + +const triageScore = definePrimitive({ + name: "triage-score", + options: { + value: "number", + defaultValue: "number", + onValueChange: "callback", + }, + controlled: ["value"], + state: (options: TriageScoreOptions) => ({ + value: options.value ?? options.defaultValue ?? 0, + focused: null as string | null, + }), + sync: (options) => + options.value === undefined ? {} : { value: options.value }, + api: (context) => { + const change = createChange(context); + const roving = createRovingFocus(context, { + slot: "score", + key: "focused", + remember: false, + preferred: (score) => Number(score.key) === context.store.get().value, + claims: (state, score) => + state.value ? Number(score.key) === state.value : score.key === "1", + orientation: () => "both", + loop: () => true, + }); + + return { + roving, + rate: (value: number, event?: Event) => { + if (!Number.isInteger(value) || value < 1 || value > 5) return; + change("value", value, { reason: "item-press", event }); + }, + keydown(event: KeyboardEvent, el: HTMLElement) { + const moved = roving.keydown(event, el); + if (moved) { + change("value", Number(moved.key), { + reason: "list-navigation", + event, + }); + } + }, + }; + }, + slots: (slot) => ({ + root: slot({ + attrs: () => ({ role: "radiogroup" }), + }), + score: slot<{ value: string }>({ + props: { value: "string" }, + attrs: (state, part) => ({ + type: "button", + role: "radio", + "aria-checked": String(Number(part.key) === state.value), + tabindex: part.api.roving.tabIndex(state, part), + "data-filled": Number(part.key) <= state.value ? "" : undefined, + }), + press: ({ api, key }, event) => api.rate(Number(key), event), + on: { + keydown: (event, { el, api }) => { + if (el) api.keydown(event, el); + }, + }, + bind: (el, part) => part.api.roving.bind(el, part), + }), + }), + agent: { + actions: ["rate"], + items: () => scores.map(({ value, label }) => ({ + value: String(value), + label: `${value} of 5 · ${label} confidence`, + })), + }, +}); + +export { triageScore, type TriageScoreOptions }; diff --git a/ui/src/router/routes.ts b/ui/src/router/routes.ts index 65aa617a3..1a234d844 100644 --- a/ui/src/router/routes.ts +++ b/ui/src/router/routes.ts @@ -498,6 +498,14 @@ export const routes: RouteRecordRaw[] = [ description: "Every instance-wide setting: models, prompts, connections, runtime and status.", }, }, + ...(import.meta.env.DEV + ? [{ + path: "/dev/ui-sdk-lab", + name: "ui-sdk-lab", + component: () => import("@/devtools/ui-sdk/UiSdkLabPage.vue"), + meta: { label: "UI SDK Lab", nav: false }, + }] + : []), { path: "/:pathMatch(.*)*", name: "not-found", diff --git a/ui/test/schedule-rule.test.ts b/ui/test/schedule-rule.test.ts new file mode 100644 index 000000000..a5ff9a329 --- /dev/null +++ b/ui/test/schedule-rule.test.ts @@ -0,0 +1,35 @@ +import assert from "node:assert/strict"; +import test from "node:test"; + +import { cronForRule } from "../src/devtools/ui-sdk/schedule-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)); + } +}); diff --git a/ui/ui-sdk-lab.html b/ui/ui-sdk-lab.html new file mode 100644 index 000000000..9d41d3235 --- /dev/null +++ b/ui/ui-sdk-lab.html @@ -0,0 +1,13 @@ + + + + + + + UI SDK Lab | Archie + + +
+ + +