From 7ffbf0435c64a68a2aa756e83a157d615d5cfc5f Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Thu, 12 Nov 2026 22:46:22 +1100 Subject: [PATCH 1/3] feat(chat): link #N in replies to tasks that exist (#1882) --- ui/src/chat/ChatInline.vue | 2 ++ ui/src/chat/ChatTaskRef.vue | 59 +++++++++++++++++++++++++++++++++++++ ui/src/chat/markdown.ts | 22 ++++++++++++-- ui/src/chat/task-ref.ts | 50 +++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 ui/src/chat/ChatTaskRef.vue create mode 100644 ui/src/chat/task-ref.ts diff --git a/ui/src/chat/ChatInline.vue b/ui/src/chat/ChatInline.vue index ddce3bf48..e67b91be4 100644 --- a/ui/src/chat/ChatInline.vue +++ b/ui/src/chat/ChatInline.vue @@ -1,4 +1,5 @@ + + diff --git a/ui/src/chat/markdown.ts b/ui/src/chat/markdown.ts index 21c7216cf..df990f31c 100644 --- a/ui/src/chat/markdown.ts +++ b/ui/src/chat/markdown.ts @@ -15,6 +15,7 @@ export type ChatInline = | { kind: "del"; text: string } | { kind: "code"; text: string } | { kind: "link"; text: string; href: string } + | { kind: "taskref"; id: number } | { kind: "image"; alt: string; src: string }; /** One block of the document. Lists carry their items as inline runs. */ @@ -27,6 +28,23 @@ export type ChatBlock = const INLINE = /(!\[[^\]]*\]\((?:https?:\/\/[^\s)]+|data:image\/[^\s)]+|\/[^\s)]+)\)|~~[^~]+~~|\*\*[^*]+\*\*|__[^_]+__|`[^`]+`|\[[^\]]+\]\((?:https?:\/\/[^\s)]+|\/[^\s)]+)\)|\*[^*]+\*|_[^_]+_)/g; +// A #N the model wrote about a task. Not part of a word, entity or path. +const TASK_REF = /(? cursor) + out.push({ kind: "text", text: text.slice(cursor, match.index) }); + out.push({ kind: "taskref", id: Number(match[1]) }); + cursor = match.index + match[0].length; + } + if (cursor < text.length) out.push({ kind: "text", text: text.slice(cursor) }); + return out; +} + // inlineMarkdown returns the children of one line: plain text and the element // each matched span becomes, in order. function inlineMarkdown(text: string): ChatInline[] { @@ -34,7 +52,7 @@ function inlineMarkdown(text: string): ChatInline[] { let cursor = 0; for (const match of String(text).matchAll(INLINE)) { if (match.index > cursor) - children.push({ kind: "text", text: text.slice(cursor, match.index) }); + children.push(...plainText(text.slice(cursor, match.index))); const value = match[0]; if (value.startsWith("![")) { const img = value.match(/^!\[([^\]]*)\]\((.+)\)$/); @@ -57,7 +75,7 @@ function inlineMarkdown(text: string): ChatInline[] { cursor = match.index + value.length; } if (cursor < text.length) - children.push({ kind: "text", text: text.slice(cursor) }); + children.push(...plainText(text.slice(cursor))); return children; } diff --git a/ui/src/chat/task-ref.ts b/ui/src/chat/task-ref.ts new file mode 100644 index 000000000..7003d63a0 --- /dev/null +++ b/ui/src/chat/task-ref.ts @@ -0,0 +1,50 @@ +import { api, ApiError } from "@/lib/api"; + +const FOUND_TTL_MS = 10 * 60_000; +const MISSING_TTL_MS = 30_000; + +const lookups = new Map(); +const inflight = new Map>(); + +/** + * Whether task `id` exists, asked of the tasks API. Answers are kept briefly + * so a reply that re-renders every frame asks once. A task that was missing a + * moment ago may have been created since, so that answer expires quickly. A + * failed lookup is null and is not kept: the reference stays plain text. + */ +export function taskExists(id: number): Promise { + const known = lookups.get(id); + if (known && Date.now() - known.at < (known.found ? FOUND_TTL_MS : MISSING_TTL_MS)) + return Promise.resolve(known.found); + let pending = inflight.get(id); + if (!pending) { + pending = api + .task(String(id)) + .then(() => true) + .catch((err) => (err instanceof ApiError && err.status === 404 ? false : null)) + .then((found) => { + if (found !== null) lookups.set(id, { at: Date.now(), found }); + inflight.delete(id); + return found; + }); + inflight.set(id, pending); + } + return pending; +} + +const HIGHLIGHT = ["bg-primary-soft", "motion-safe:transition-colors", "motion-safe:duration-700"]; + +/** + * Scrolls to task `id`'s row when the page lists it and marks it once. + * Returns false when no such row is on screen. + */ +export function revealTaskRow(id: number): boolean { + const row = document.querySelector(`tr[data-row-key="${id}"]`); + if (!row) return false; + const still = window.matchMedia("(prefers-reduced-motion: reduce)").matches; + row.scrollIntoView({ block: "center", behavior: still ? "auto" : "smooth" }); + row.classList.add(...HIGHLIGHT); + window.setTimeout(() => row.classList.remove("bg-primary-soft"), 1600); + window.setTimeout(() => row.classList.remove(...HIGHLIGHT), 2400); + return true; +} From eabd7c8884f546e851f18e2df134995a2413a827 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Thu, 12 Nov 2026 22:47:26 +1100 Subject: [PATCH 2/3] feat(chat): copy a conversation as Markdown from the More menu (#1884) --- ui/src/chat/ChatSessionActions.vue | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/ui/src/chat/ChatSessionActions.vue b/ui/src/chat/ChatSessionActions.vue index 642ec9246..ef071bc69 100644 --- a/ui/src/chat/ChatSessionActions.vue +++ b/ui/src/chat/ChatSessionActions.vue @@ -1,6 +1,7 @@