diff options
| author | Adam Malczewski <[email protected]> | 2026-06-21 14:21:53 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-06-21 14:21:53 +0900 |
| commit | 1b09eea04911d73cdf3f979d4f19dcf5dc20c461 (patch) | |
| tree | 979da96aa142fababc5c5f2d1ac019bb0d1c61db /src/features/surface-host/logic/todo.ts | |
| parent | d98a63ce17519983dcf58c27432723e2f4b96e75 (diff) | |
| download | dispatch-web-1b09eea04911d73cdf3f979d4f19dcf5dc20c461.tar.gz dispatch-web-1b09eea04911d73cdf3f979d4f19dcf5dc20c461.zip | |
feat(surfaces): todo task list sidebar view
Add a dedicated "Tasks" sidebar view for the per-conversation todo surface
(model-maintained via todo_write tool; read-only, conversation-scoped).
- parseTodoPayload: pure parser for the rendererId: "todo" custom field
(TodoItem { content, status, priority } — types defined FE-side, not in wire)
- TodoList.svelte: renders the task list with status indicators (spinner for
in_progress, checkmark for completed, X for cancelled, empty circle for
pending) + priority dots (red/yellow/gray)
- SurfaceView dispatches rendererId: "todo" to TodoList
- App.svelte: "Tasks" view kind (always visible; "No tasks yet" empty state),
todo surface pulled out of the generic Extensions list, re-mounts per
conversation via {#key}
681 tests green.
Diffstat (limited to 'src/features/surface-host/logic/todo.ts')
| -rw-r--r-- | src/features/surface-host/logic/todo.ts | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/features/surface-host/logic/todo.ts b/src/features/surface-host/logic/todo.ts new file mode 100644 index 0000000..b8e027b --- /dev/null +++ b/src/features/surface-host/logic/todo.ts @@ -0,0 +1,58 @@ +/** + * Pure parser for the `rendererId: "todo"` custom-field payload. + * + * The `todo` backend extension maintains a per-conversation task list (written + * by the model via a `todo_write` tool) and exposes it as a read-only + * conversation-scoped surface with one `custom` field + * (`rendererId: "todo"`, `payload: TodoPayload`). This parser validates the + * untyped `payload: unknown` at the network seam so a hostile/partial payload + * can never crash the renderer (graceful skip → null). + * + * The `TodoItem` type is NOT in `@dispatch/wire` — it is defined by the `todo` + * extension and carried in the surface payload, so we define it here (the FE's + * rendering contract for the shape). Empty `todos` is a valid, parseable state + * (the model hasn't created a list / cleared it); the caller hides the panel. + */ +export type TodoStatus = "pending" | "in_progress" | "completed" | "cancelled"; +export type TodoPriority = "high" | "medium" | "low"; + +export interface TodoItem { + readonly content: string; + readonly status: TodoStatus; + readonly priority: TodoPriority; +} + +export interface TodoData { + readonly todos: readonly TodoItem[]; +} + +const STATUSES = new Set<string>(["pending", "in_progress", "completed", "cancelled"]); +const PRIORITIES = new Set<string>(["high", "medium", "low"]); + +function isTodoItem(v: unknown): v is TodoItem { + if (typeof v !== "object" || v === null) return false; + const o = v as Record<string, unknown>; + return ( + typeof o.content === "string" && + typeof o.status === "string" && + STATUSES.has(o.status) && + typeof o.priority === "string" && + PRIORITIES.has(o.priority) + ); +} + +export function parseTodoPayload(payload: unknown): TodoData | null { + if (typeof payload !== "object" || payload === null) return null; + const obj = payload as Record<string, unknown>; + const raw = obj.todos; + if (!Array.isArray(raw)) return null; + const todos: TodoItem[] = []; + for (const entry of raw) { + if (!isTodoItem(entry)) return null; + todos.push(entry); + } + return { todos }; +} + +/** The `rendererId` the `todo` extension's `custom` surface field uses. */ +export const TODO_RENDERER_ID = "todo"; |
