Repository navigation
feat(spike): web client for the durable host (P2) #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bubbleptr
merged 1 commit into
feat/durable-multiview-tui
from
feat/durable-multiview-web
Oct 2, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| // What a graphical client shows for a conversation view, as plain data. The | ||
| // derivations follow pi's durable TUI (packages/coding-agent/src/experimental/durable/tui.ts, | ||
| // MIT, Earendil Works) so every client tells the same story. Type-only imports keep it browser-safe. | ||
| import type { | ||
| ConversationId, | ||
| ConversationView, | ||
| EntryRecord, | ||
| InboxState, | ||
| LiveState, | ||
| TaskGraph, | ||
| TaskGraphNode, | ||
| TaskId, | ||
| } from "@earendil-works/pi-durable"; | ||
|
|
||
| export interface ToolCallView { | ||
| readonly callId: string; | ||
| readonly name: string; | ||
| /** What the call acts on, from its arguments. */ | ||
| readonly target?: string; | ||
| readonly status: "pending" | "running" | "complete" | "error"; | ||
| readonly output?: string; | ||
| /** A subagent's conversation, from the call's running details. */ | ||
| readonly conversationId?: ConversationId; | ||
| } | ||
|
|
||
| export type ChatItem = | ||
| | { readonly kind: "user"; readonly id: string; readonly text: string } | ||
| | { | ||
| readonly kind: "assistant"; | ||
| readonly id: string; | ||
| readonly text: string; | ||
| /** Absent while streaming; `aborted` for a partial an interrupted attempt left behind. */ | ||
| readonly stopReason?: string; | ||
| readonly streaming: boolean; | ||
| readonly tools: readonly ToolCallView[]; | ||
| } | ||
| | { readonly kind: "compaction"; readonly id: string; readonly summary: string } | ||
| | { readonly kind: "reset"; readonly id: string }; | ||
|
|
||
| type Block = { readonly type: string; readonly text?: string; readonly id?: string; readonly name?: string; readonly arguments?: unknown }; | ||
| type Message = { readonly role: string; readonly content: string | readonly Block[]; readonly stopReason?: string; readonly toolCallId?: string; readonly isError?: boolean }; | ||
|
|
||
| function textOf(content: Message["content"]): string { | ||
| if (typeof content === "string") return content; | ||
| return content.flatMap((block) => (block.type === "text" && block.text !== undefined ? [block.text] : [])).join(""); | ||
| } | ||
|
|
||
| function targetOf(args: unknown): string | undefined { | ||
| if (args === null || typeof args !== "object") return undefined; | ||
| const values = Object.values(args as Record<string, unknown>); | ||
| const first = values.find((value) => typeof value === "string") as string | undefined; | ||
| const target = first ?? (values.length === 0 ? undefined : JSON.stringify(args)); | ||
| return target === undefined || target.length <= 80 ? target : `${target.slice(0, 77)}...`; | ||
| } | ||
|
|
||
| function callsOf(message: Message, status: ToolCallView["status"], output?: string): ToolCallView[] { | ||
| if (typeof message.content === "string") return []; | ||
| return message.content.flatMap((block) => { | ||
| if (block.type !== "toolCall" || block.id === undefined || block.name === undefined) return []; | ||
| const target = targetOf(block.arguments); | ||
| return [{ callId: block.id, name: block.name, status, ...(target === undefined ? {} : { target }), ...(output === undefined ? {} : { output }) }]; | ||
| }); | ||
| } | ||
|
|
||
| const liveOf = (view: ConversationView): LiveState => (view.docs["pi.live"] ?? {}) as LiveState; | ||
|
|
||
| export function chatItems(view: ConversationView): ChatItem[] { | ||
| const items: ChatItem[] = []; | ||
| // Where each call ID's newest card sits; provider call IDs may repeat across turns. | ||
| const calls = new Map<string, { item: number; tool: number }>(); | ||
| const updateCall = (callId: string, patch: Partial<ToolCallView>): void => { | ||
| const at = calls.get(callId); | ||
| if (at === undefined) return; | ||
| const item = items[at.item] as Extract<ChatItem, { kind: "assistant" }>; | ||
| const tools = item.tools.map((tool, index) => (index === at.tool ? { ...tool, ...patch } : tool)); | ||
| items[at.item] = { ...item, tools }; | ||
| }; | ||
| const addAssistant = (id: string, message: Message, streaming: boolean): void => { | ||
| // Only a tool-calling answer runs its calls; an aborted, failed, or truncated one never does. | ||
| const ran = streaming || message.stopReason === "toolUse"; | ||
| const tools = ran ? callsOf(message, "pending") : callsOf(message, "error", "Not run: the answer was interrupted."); | ||
| tools.forEach((tool, index) => calls.set(tool.callId, { item: items.length, tool: index })); | ||
| items.push({ | ||
| kind: "assistant", | ||
| id, | ||
| text: textOf(message.content), | ||
| ...(streaming ? {} : { stopReason: message.stopReason ?? "stop" }), | ||
| streaming, | ||
| tools, | ||
| }); | ||
| }; | ||
|
|
||
| for (const entry of view.entries as readonly EntryRecord[]) { | ||
| const message = entry.model?.[0] as Message | undefined; | ||
| const id = String(entry.id); | ||
| if (entry.kind === "pi.user" && message?.role === "user") items.push({ kind: "user", id, text: textOf(message.content) }); | ||
| else if (entry.kind === "pi.assistant" && message?.role === "assistant") addAssistant(id, message, false); | ||
| else if (entry.kind === "pi.tool-result" && message?.role === "toolResult" && message.toolCallId !== undefined) { | ||
| updateCall(message.toolCallId, { status: message.isError ? "error" : "complete", output: textOf(message.content) }); | ||
| } else if (entry.kind === "pi.compaction") items.push({ kind: "compaction", id, summary: message === undefined ? "" : textOf(message.content) }); | ||
| else if (entry.kind === "pi.reset") items.push({ kind: "reset", id }); | ||
| } | ||
|
|
||
| const live = liveOf(view); | ||
| for (const slot of live.tools ?? []) { | ||
| if (slot.status !== "running") continue; | ||
| const child = (slot.details as { conversationId?: ConversationId } | undefined)?.conversationId; | ||
| updateCall(slot.callId, { | ||
| status: "running", | ||
| ...(slot.output === undefined ? {} : { output: slot.output }), | ||
| ...(child === undefined ? {} : { conversationId: child }), | ||
| }); | ||
| } | ||
| const partial = live.generation?.message as Message | undefined; | ||
| if (partial !== undefined) addAssistant("live", partial, true); | ||
| return items; | ||
| } | ||
|
|
||
| /** What the conversation is doing now, most specific first; empty when idle. */ | ||
| export function statusText(view: ConversationView): string { | ||
| const live = liveOf(view); | ||
| const generation = live.generation; | ||
| const compaction = live.compactions?.[0]; | ||
| const runningTool = live.tools?.find((slot) => slot.status === "running"); | ||
| if (generation?.retry !== undefined) return `Retrying (attempt ${generation.attempt + 1}): ${generation.retry.error}`; | ||
| if (generation?.deferred !== undefined) return "Waiting for deferred response..."; | ||
| if (compaction !== undefined) { | ||
| return compaction.retry ? `Retrying ${compaction.reason} compaction (attempt ${compaction.attempt + 1})...` : `Compacting (${compaction.reason})...`; | ||
| } | ||
| if (runningTool !== undefined) return `Running ${runningTool.name}...`; | ||
| if (live.run !== undefined) return "Working..."; | ||
| return ""; | ||
| } | ||
|
|
||
| export interface QueueItem { | ||
| readonly id: number; | ||
| readonly mode: "steer" | "followUp" | "write"; | ||
| readonly text: string; | ||
| } | ||
|
|
||
| export function queueItems(view: ConversationView): QueueItem[] { | ||
| const inbox = (view.docs["pi.inbox"] ?? { items: [] }) as InboxState; | ||
| return inbox.items.map((item) => ({ | ||
| id: item.id as unknown as number, | ||
| mode: item.mode, | ||
| text: item.mode === "write" ? `<${String(item.entry.kind)}>` : textOf(item.content as Message["content"]), | ||
| })); | ||
| } | ||
|
|
||
| export interface TaskRow { | ||
| readonly id: TaskId; | ||
| readonly depth: number; | ||
| readonly label: string; | ||
| } | ||
|
|
||
| function describeTask(node: TaskGraphNode): string { | ||
| const state = node.state; | ||
| const status = | ||
| state.status === "waiting" | ||
| ? `waiting on ${state.on.join(", ")}` | ||
| : state.status === "completing" | ||
| ? `completing (${state.outcome})` | ||
| : `${state.status} ${state.phase}`; | ||
| const flags = [node.background ? "background" : "", node.abortRequested ? "aborting" : ""].filter(Boolean); | ||
| const owned = node.conversations.length > 0 ? ` owns conversation ${node.conversations.join(", ")}` : ""; | ||
| return `${node.kind} #${node.id}: ${status}${flags.length > 0 ? ` [${flags.join(", ")}]` : ""}${owned}`; | ||
| } | ||
|
|
||
| /** Live tasks as an indented tree: owned work under its owner, a subagent's work under the call that owns its conversation. */ | ||
| export function taskRows(graph: TaskGraph): TaskRow[] { | ||
| const nodes = Object.values(graph.tasks); | ||
| const owned = new Set(nodes.flatMap((node) => node.conversations)); | ||
| const children = (node: TaskGraphNode) => | ||
| nodes.filter( | ||
| (candidate) => candidate.owner === node.id || (candidate.owner === undefined && node.conversations.includes(candidate.conversationId)), | ||
| ); | ||
| const rows: TaskRow[] = []; | ||
| const visit = (node: TaskGraphNode, depth: number): void => { | ||
| rows.push({ id: node.id, depth, label: describeTask(node) }); | ||
| for (const child of children(node)) visit(child, depth + 1); | ||
| }; | ||
| for (const node of nodes) if (node.owner === undefined && !owned.has(node.conversationId)) visit(node, 0); | ||
| return rows; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Streaming tools lose live progress
When a streaming answer calls a tool,
chatItemsadds its pending card after applying live tool updates. The running status, output and subagent ID disappear until the tool finishes.Learn more
The live document contains running tool slots and the current partial assistant message. The map of tool cards is populated by
addAssistant, but the partial assistant message is appended only after the running slots are applied. A new call that exists only in the partial cannot be found byupdateCall; even when a committed call shares the ID, the later partial replaces the map entry with a pending card. The TUI rendering order handles the streaming message before running slots.Example: A partial assistant message calls
logswith IDc1, whilepi.live.toolsholds{ callId: 'c1', status: 'running', output: 'fetching' }. The web card remains pending with no output; the TUI shows it running and displaysfetching.Recommended fix: Add the partial assistant with
addAssistantbefore iteratinglive.tools, then patch the current call cards. Add a presentation test with a streaming tool call and a matching running slot.Was this helpful? React with 👍 or 👎 to provide feedback.