summaryrefslogtreecommitdiffhomepage
path: root/packages/todo/src/extension.ts
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-21 14:34:22 +0900
committerAdam Malczewski <[email protected]>2026-06-21 14:34:22 +0900
commitd56fe9cf64719bb330c17b2daee58c0bafa057c9 (patch)
treeb80a25aaee57f959454d468e03f100c38e224b82 /packages/todo/src/extension.ts
parent8a4a624d16422467a8e85434c674bb591877e8ea (diff)
downloaddispatch-d56fe9cf64719bb330c17b2daee58c0bafa057c9.tar.gz
dispatch-d56fe9cf64719bb330c17b2daee58c0bafa057c9.zip
feat(todo): per-conversation task list tool + surface
New standard tool extension with a single todo_write tool (opencode todowrite pattern: full-list replace, returns JSON, no business-rule enforcement — the description guides the model). Per-conversation in-memory state + per-conversation surface (rendererId: todo, scope: conversation) via subscriber-notify (message-queue pattern). Wave 0 (kernel contract): added conversationId?: string to ToolExecuteContext (additive, backward-compatible). Wired in dispatch.ts — the kernel already had it but wasn't passing it through to tools. Wave 1 (todo extension): pure core (validateTodos — shape only; getTodos/ setTodos/clearTodos; buildTodoSpec; formatTodoResult). Shell: createTodoWriteTool + surface provider. Tool description matches opencode's todowrite.txt depth (when-to-use, examples, task states). Priority field removed (bloats the tool with little value). 25 tests. Wave 2 (host-bin): registered todo in CORE_EXTENSIONS + dep + root tsconfig ref. Verified: tsc EXIT 0, 1123 vitest, biome clean (314 files). Boot smoke clean. FE handoff: frontend-todo-handoff.md.
Diffstat (limited to 'packages/todo/src/extension.ts')
-rw-r--r--packages/todo/src/extension.ts81
1 files changed, 81 insertions, 0 deletions
diff --git a/packages/todo/src/extension.ts b/packages/todo/src/extension.ts
new file mode 100644
index 0000000..80af7aa
--- /dev/null
+++ b/packages/todo/src/extension.ts
@@ -0,0 +1,81 @@
+/**
+ * todo extension — owns the per-conversation task list (state + surface + the
+ * `todo_write` tool). Plugs into the kernel host via a manifest +
+ * `activate(host)`; the model maintains the list via the tool, and the surface
+ * renders the live list for the frontend (subscriber-notify, same pattern as
+ * message-queue). State is in-memory (per-process, per-conversation) — no
+ * persistence, mirroring message-queue.
+ */
+
+import type { Extension, HostAPI, Manifest } from "@dispatch/kernel";
+import type { SurfaceContext, SurfaceProvider } from "@dispatch/surface-registry";
+import { surfaceRegistryHandle } from "@dispatch/surface-registry";
+import type { SurfaceSpec } from "@dispatch/ui-contract";
+import { buildTodoSpec, getTodos, TODO_SURFACE_ID, type TodoState } from "./pure.js";
+import { createTodoWriteTool } from "./tool.js";
+
+export const manifest: Manifest = {
+ id: "todo",
+ name: "Todo Tool",
+ version: "0.0.0",
+ apiVersion: "^0.1.0",
+ trust: "bundled",
+ activation: "eager",
+ dependsOn: ["surface-registry"],
+ capabilities: {},
+ contributes: {
+ tools: ["todo_write"],
+ },
+};
+
+export function activate(host: HostAPI): void {
+ const registry = host.getService(surfaceRegistryHandle);
+
+ const state: TodoState = new Map();
+ const subscribers = new Set<() => void>();
+
+ function notify(): void {
+ for (const sub of subscribers) {
+ sub();
+ }
+ }
+
+ host.defineTool(createTodoWriteTool({ state, notify }));
+
+ function getSpec(context?: SurfaceContext): SurfaceSpec {
+ const convId = context?.conversationId;
+ const todos = convId === undefined ? [] : getTodos(state, convId);
+ return buildTodoSpec(todos);
+ }
+
+ function invoke(_actionId: string, _payload?: unknown, _context?: SurfaceContext): void {
+ // The todo surface is read-only: the model mutates the list via the
+ // `todo_write` tool; no client-facing surface actions.
+ }
+
+ const provider: SurfaceProvider = {
+ catalogEntry: {
+ id: TODO_SURFACE_ID,
+ region: "side",
+ title: "Tasks",
+ scope: "conversation",
+ },
+ getSpec,
+ invoke,
+ subscribe(onChange) {
+ subscribers.add(onChange);
+ return () => {
+ subscribers.delete(onChange);
+ };
+ },
+ };
+
+ registry.register(provider);
+
+ host.logger.info("todo: registered");
+}
+
+export const extension: Extension = {
+ manifest,
+ activate,
+};