mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
feat(tui): render todos in the timeline and sidebar (#56948)
This commit is contained in:
parent
89ac09309e
commit
3e0d9ef9f2
16 changed files with 478 additions and 2 deletions
27
packages/tui/src/component/todo-item.tsx
Normal file
27
packages/tui/src/component/todo-item.tsx
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import { TextAttributes } from "@opentui/core"
|
||||
import type { ResolvedTheme } from "@opencode/theme/tui"
|
||||
import { todoMarker, type Todo } from "../util/todo"
|
||||
|
||||
export function TodoItem(props: { theme: ResolvedTheme; todo: Todo }) {
|
||||
const fg = () => {
|
||||
if (props.todo.status === "in_progress") return props.theme.text.feedback.warning.base
|
||||
if (props.todo.status === "cancelled") return props.theme.text.faint
|
||||
return props.theme.text.muted
|
||||
}
|
||||
|
||||
return (
|
||||
<box flexDirection="row" gap={0}>
|
||||
<text flexShrink={0} fg={fg()}>
|
||||
{todoMarker(props.todo.status)}{" "}
|
||||
</text>
|
||||
<text
|
||||
flexGrow={1}
|
||||
wrapMode="word"
|
||||
fg={fg()}
|
||||
attributes={props.todo.status === "cancelled" ? TextAttributes.STRIKETHROUGH : undefined}
|
||||
>
|
||||
{props.todo.content}
|
||||
</text>
|
||||
</box>
|
||||
)
|
||||
}
|
||||
58
packages/tui/src/feature-plugins/sidebar/todo.tsx
Normal file
58
packages/tui/src/feature-plugins/sidebar/todo.tsx
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
import { Plugin } from "@opencode/plugin/tui"
|
||||
import { createMemo, For, Show } from "solid-js"
|
||||
import { TodoItem } from "../../component/todo-item"
|
||||
import { sessionTodos } from "../../util/todo"
|
||||
|
||||
export function SidebarTodo(props: { context: Plugin.Context; sessionID: string }) {
|
||||
const [view, updateView] = props.context.storage.store("view", { initial: { open: true } })
|
||||
const theme = props.context.theme
|
||||
const list = createMemo(() =>
|
||||
sessionTodos(
|
||||
props.context.data.session.message.list(props.sessionID),
|
||||
props.context.data.session.get(props.sessionID)?.revert?.messageID,
|
||||
),
|
||||
)
|
||||
const remaining = createMemo(
|
||||
() => list().filter((item) => item.status === "pending" || item.status === "in_progress").length,
|
||||
)
|
||||
|
||||
return (
|
||||
<Show when={list().length > 0}>
|
||||
<box>
|
||||
<box
|
||||
flexDirection="row"
|
||||
gap={1}
|
||||
onMouseDown={() => {
|
||||
if (list().length <= 2) return
|
||||
void updateView((draft) => {
|
||||
draft.open = !draft.open
|
||||
}).catch((error) => console.error("Failed to persist todo sidebar state", error))
|
||||
}}
|
||||
>
|
||||
<Show when={list().length > 2}>
|
||||
<text fg={theme.text.base}>{view.open ? "▼" : "▶"}</text>
|
||||
</Show>
|
||||
<text fg={theme.text.base}>
|
||||
<b>Todo</b>
|
||||
<Show when={list().length > 2 && !view.open}>
|
||||
<span style={{ fg: theme.text.muted }}> ({remaining()} remaining)</span>
|
||||
</Show>
|
||||
</text>
|
||||
</box>
|
||||
<Show when={list().length <= 2 || view.open}>
|
||||
<For each={list()}>{(item) => <TodoItem theme={theme} todo={item} />}</For>
|
||||
</Show>
|
||||
</box>
|
||||
</Show>
|
||||
)
|
||||
}
|
||||
|
||||
export default Plugin.define({
|
||||
id: "opencode.sidebar.todo",
|
||||
setup(context) {
|
||||
context.ui.slot({
|
||||
append: "sidebar.content",
|
||||
render: (props) => <SidebarTodo context={context} sessionID={props.sessionID} />,
|
||||
})
|
||||
},
|
||||
})
|
||||
|
|
@ -8,6 +8,7 @@ import { sessionLocationMissingStory } from "./session-location-missing"
|
|||
import { oneCellSpinnerStory } from "./one-cell-spinner"
|
||||
import { linkClicksStory } from "./link-clicks"
|
||||
import { highlightsStory } from "./highlights"
|
||||
import { todoStory } from "./todo"
|
||||
|
||||
/**
|
||||
* A story is a full-screen, fixture-driven simulation of a real production component. Stories own
|
||||
|
|
@ -26,6 +27,7 @@ const stories: Story[] = [
|
|||
oneCellSpinnerStory,
|
||||
linkClicksStory,
|
||||
highlightsStory,
|
||||
todoStory,
|
||||
]
|
||||
|
||||
function Commands(props: { context: Plugin.Context }) {
|
||||
|
|
|
|||
166
packages/tui/src/feature-plugins/system/storybook/todo.tsx
Normal file
166
packages/tui/src/feature-plugins/system/storybook/todo.tsx
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
import type { Plugin } from "@opencode/plugin/tui"
|
||||
import type { SessionMessageInfo } from "@opencode/client"
|
||||
import { useTerminalDimensions } from "@opentui/solid"
|
||||
import { createMemo, createSignal, For } from "solid-js"
|
||||
import { SidebarTodo } from "../../sidebar/todo"
|
||||
import type { TodoStatus } from "../../../util/todo"
|
||||
import type { Story } from "./index"
|
||||
import { StoryFooter } from "./footer"
|
||||
|
||||
const statuses: TodoStatus[] = ["pending", "in_progress", "completed", "cancelled"]
|
||||
|
||||
const initial = [
|
||||
{ content: "Read the existing sidebar plugins", status: "completed" as TodoStatus },
|
||||
{ content: "Derive the current list from the latest todowrite call", status: "in_progress" as TodoStatus },
|
||||
{ content: "Render the todowrite tool part like V1", status: "pending" as TodoStatus },
|
||||
{ content: "Add a database table for todos", status: "cancelled" as TodoStatus },
|
||||
]
|
||||
|
||||
function TodoStory(props: { context: Plugin.Context }) {
|
||||
const dimensions = useTerminalDimensions()
|
||||
const theme = props.context.theme
|
||||
const [todos, setTodos] = createSignal(initial)
|
||||
const [selected, setSelected] = createSignal(0)
|
||||
const messages = createMemo((): SessionMessageInfo[] => [
|
||||
{
|
||||
id: "fixture-message",
|
||||
type: "assistant",
|
||||
agent: "build",
|
||||
model: { providerID: "fixture", id: "fixture" },
|
||||
time: { created: 0, completed: 1 },
|
||||
content: [
|
||||
{
|
||||
type: "tool",
|
||||
id: "fixture-todowrite",
|
||||
name: "todowrite",
|
||||
time: { created: 0, completed: 1 },
|
||||
state: {
|
||||
status: "completed",
|
||||
input: { todos: todos().map((todo) => ({ ...todo, priority: "medium" })) },
|
||||
content: [{ type: "text", text: "updated" }],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
const fixture: Plugin.Context = {
|
||||
...props.context,
|
||||
data: {
|
||||
...props.context.data,
|
||||
session: {
|
||||
...props.context.data.session,
|
||||
get: () => undefined,
|
||||
message: { ...props.context.data.session.message, list: () => messages() },
|
||||
},
|
||||
},
|
||||
}
|
||||
const cycle = () =>
|
||||
setTodos((list) =>
|
||||
list.map((todo, index) =>
|
||||
index === selected()
|
||||
? { ...todo, status: statuses[(statuses.indexOf(todo.status) + 1) % statuses.length] }
|
||||
: todo,
|
||||
),
|
||||
)
|
||||
|
||||
props.context.keymap.layer(() => ({
|
||||
commands: [
|
||||
{
|
||||
bind: "escape",
|
||||
title: "Back to storybook",
|
||||
group: "Storybook",
|
||||
run: () => props.context.ui.router.navigate({ type: "plugin", name: "storybook" }),
|
||||
},
|
||||
{
|
||||
bind: "up,k",
|
||||
title: "Previous todo",
|
||||
group: "Storybook",
|
||||
run: () => setSelected((index) => Math.max(0, index - 1)),
|
||||
},
|
||||
{
|
||||
bind: "down,j",
|
||||
title: "Next todo",
|
||||
group: "Storybook",
|
||||
run: () => setSelected((index) => Math.min(todos().length - 1, index + 1)),
|
||||
},
|
||||
{ bind: "s", title: "Cycle status", group: "Storybook", run: cycle },
|
||||
{
|
||||
bind: "a",
|
||||
title: "Add todo",
|
||||
group: "Storybook",
|
||||
run: () =>
|
||||
setTodos((list) => [
|
||||
...list,
|
||||
{ content: `Follow-up task ${list.length + 1} with a longer description that wraps`, status: "pending" },
|
||||
]),
|
||||
},
|
||||
{
|
||||
bind: "c",
|
||||
title: "Complete all",
|
||||
group: "Storybook",
|
||||
run: () => setTodos((list) => list.map((todo) => ({ ...todo, status: "completed" as TodoStatus }))),
|
||||
},
|
||||
{
|
||||
bind: "x",
|
||||
title: "Clear todos",
|
||||
group: "Storybook",
|
||||
run: () => {
|
||||
setTodos([])
|
||||
setSelected(0)
|
||||
},
|
||||
},
|
||||
{
|
||||
bind: "r",
|
||||
title: "Reset",
|
||||
group: "Storybook",
|
||||
run: () => {
|
||||
setTodos(initial)
|
||||
setSelected(0)
|
||||
},
|
||||
},
|
||||
],
|
||||
}))
|
||||
|
||||
return (
|
||||
<box width={dimensions().width} height={dimensions().height} backgroundColor={theme.background.base}>
|
||||
<box flexDirection="row" flexGrow={1} paddingTop={1} paddingLeft={2} paddingRight={2} gap={4}>
|
||||
<box flexGrow={1} flexDirection="column">
|
||||
<text fg={theme.text.base}>Fixture todowrite input</text>
|
||||
<box height={1} />
|
||||
<For each={todos()}>
|
||||
{(todo, index) => (
|
||||
<text fg={index() === selected() ? theme.text.formfield.selected : theme.text.muted}>
|
||||
{index() === selected() ? "› " : " "}
|
||||
{todo.status.padEnd(11)} {todo.content}
|
||||
</text>
|
||||
)}
|
||||
</For>
|
||||
</box>
|
||||
<box width={38} flexShrink={0} backgroundColor={theme.background.raised.base} padding={1}>
|
||||
<SidebarTodo context={fixture} sessionID="fixture-session" />
|
||||
</box>
|
||||
</box>
|
||||
<StoryFooter
|
||||
context={props.context}
|
||||
title="storybook / todo sidebar"
|
||||
details={[`${todos().length} todos`]}
|
||||
message="Hidden when there are no pending or in-progress todos"
|
||||
controls={[
|
||||
{ shortcut: "↑↓", label: "select" },
|
||||
{ shortcut: "s", label: "cycle status" },
|
||||
{ shortcut: "a", label: "add" },
|
||||
{ shortcut: "c", label: "complete all" },
|
||||
{ shortcut: "x", label: "clear" },
|
||||
{ shortcut: "r", label: "reset" },
|
||||
{ shortcut: "esc", label: "back" },
|
||||
]}
|
||||
/>
|
||||
</box>
|
||||
)
|
||||
}
|
||||
|
||||
export const todoStory: Story = {
|
||||
id: "todo",
|
||||
title: "Todo sidebar",
|
||||
render: (context) => <TodoStory context={context} />,
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
// /permission [kind] → triggers a permission request variant
|
||||
// /form [kind] → triggers a canonical Form request variant
|
||||
// /fmt <kind> → emits a specific tool/text type (text, reasoning, shell,
|
||||
// write, edit, patch, subagent, question, error, mix)
|
||||
// write, edit, patch, subagent, todo, question, error, mix)
|
||||
//
|
||||
// Demo mode handles permission and Form replies locally, completing or failing
|
||||
// the synthetic tool parts through the same callbacks used by the live footer.
|
||||
|
|
@ -42,6 +42,7 @@ const KINDS = [
|
|||
"edit",
|
||||
"patch",
|
||||
"subagent",
|
||||
"todo",
|
||||
"question",
|
||||
"error",
|
||||
"mix",
|
||||
|
|
@ -565,6 +566,17 @@ function emitTask(state: State): void {
|
|||
})
|
||||
}
|
||||
|
||||
function emitTodo(state: State): void {
|
||||
const todos = [
|
||||
{ content: "Trigger permission UI", status: "completed" },
|
||||
{ content: "Trigger question UI", status: "in_progress" },
|
||||
{ content: "Tune tool formatting", status: "pending" },
|
||||
{ content: "Rewrite the renderer", status: "cancelled" },
|
||||
]
|
||||
const ref = make(state, "todowrite", { todos })
|
||||
doneTool(state, ref, { output: "1 completed, 1 in progress, 1 pending, 1 cancelled", metadata: { todos } })
|
||||
}
|
||||
|
||||
function emitQuestionTool(state: State): void {
|
||||
const ref = make(state, "question", {
|
||||
questions: [
|
||||
|
|
@ -872,6 +884,11 @@ async function emitFmt(state: State, kind: string, body: string, signal?: AbortS
|
|||
return true
|
||||
}
|
||||
|
||||
if (kind === "todo") {
|
||||
emitTodo(state)
|
||||
return true
|
||||
}
|
||||
|
||||
if (kind === "question") {
|
||||
emitQuestionTool(state)
|
||||
return true
|
||||
|
|
@ -892,6 +909,7 @@ async function emitFmt(state: State, kind: string, body: string, signal?: AbortS
|
|||
emitEdit(state)
|
||||
emitPatch(state)
|
||||
emitTask(state)
|
||||
emitTodo(state)
|
||||
emitQuestionTool(state)
|
||||
emitError(state, "demo mixed scenario error")
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -95,6 +95,8 @@ function monoBody(body: RunEntryBody): RunEntryBody {
|
|||
if (snapshot.kind === "task") {
|
||||
return textBody([snapshot.title, ...snapshot.rows, snapshot.tail].filter(Boolean).join("\n"))
|
||||
}
|
||||
// The writer renders todo cards with ASCII markers in mono so wrapped items keep their indent.
|
||||
if (snapshot.kind === "todo") return body
|
||||
return textBody(
|
||||
["# Questions", ...snapshot.items.flatMap((item) => [item.question, item.answer]), snapshot.tail]
|
||||
.filter(Boolean)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { createScrollbackWriter } from "@opentui/solid"
|
||||
import {
|
||||
MarkdownRenderable,
|
||||
TextAttributes,
|
||||
TextRenderable,
|
||||
type ColorInput,
|
||||
type ScrollbackRenderContext,
|
||||
|
|
@ -13,6 +14,7 @@ import { entryColor, entryLook, entrySyntax } from "./scrollback.shared"
|
|||
import { toolFiletype, toolStructuredFinal } from "./tool"
|
||||
import { RUN_THEME_FALLBACK, transparent, type RunTheme } from "./theme"
|
||||
import type { EntryLayout, RunEntryBody, ScrollbackOptions, StreamCommit, TurnSummary } from "./types"
|
||||
import { todoMarker } from "../util/todo"
|
||||
import { PatchDiff } from "../component/patch-diff"
|
||||
|
||||
export function entryGroupKey(commit: StreamCommit): string | undefined {
|
||||
|
|
@ -118,6 +120,15 @@ export function RunEntryContent(props: {
|
|||
const next = structured()
|
||||
return next?.kind === "task" ? next : undefined
|
||||
})
|
||||
const todo_snapshot = createMemo(() => {
|
||||
const next = structured()
|
||||
return next?.kind === "todo" ? next : undefined
|
||||
})
|
||||
const todoColor = (status: string) => {
|
||||
if (status === "in_progress") return theme().block.warning
|
||||
if (status === "cancelled") return theme().block.faint
|
||||
return theme().block.muted
|
||||
}
|
||||
const question_snapshot = createMemo(() => {
|
||||
const next = structured()
|
||||
return next?.kind === "question" ? next : undefined
|
||||
|
|
@ -229,6 +240,32 @@ export function RunEntryContent(props: {
|
|||
</box>
|
||||
</box>
|
||||
</Match>
|
||||
<Match when={todo_snapshot()}>
|
||||
<box width="100%" flexDirection="column" gap={1}>
|
||||
<text width="100%" wrapMode="word" fg={theme().block.muted}>
|
||||
# Todos
|
||||
</text>
|
||||
<box width="100%" flexDirection="column" gap={0}>
|
||||
{todo_snapshot()!.items.map((item) => (
|
||||
<box width="100%" flexDirection="row" gap={0}>
|
||||
<text flexShrink={0} fg={todoColor(item.status)}>
|
||||
{todoMarker(item.status, props.opts?.mono === true)}{" "}
|
||||
</text>
|
||||
<text
|
||||
flexGrow={1}
|
||||
flexShrink={1}
|
||||
minWidth={0}
|
||||
wrapMode="word"
|
||||
fg={todoColor(item.status)}
|
||||
attributes={item.status === "cancelled" ? TextAttributes.STRIKETHROUGH : undefined}
|
||||
>
|
||||
{item.content}
|
||||
</text>
|
||||
</box>
|
||||
))}
|
||||
</box>
|
||||
</box>
|
||||
</Match>
|
||||
<Match when={question_snapshot()}>
|
||||
<box width="100%" flexDirection="column" gap={1}>
|
||||
<text width="100%" wrapMode="word" fg={theme().block.muted}>
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ export type RunFooterTheme = {
|
|||
export type RunBlockTheme = {
|
||||
text: ColorInput
|
||||
muted: ColorInput
|
||||
faint: ColorInput
|
||||
warning: ColorInput
|
||||
syntax?: SyntaxStyle
|
||||
diffRemoved: ColorInput
|
||||
diffAddedBg: ColorInput
|
||||
|
|
@ -177,6 +179,8 @@ function map(
|
|||
block: {
|
||||
text: scrollback(theme.text.base),
|
||||
muted: scrollback(theme.text.muted),
|
||||
faint: scrollback(theme.text.faint),
|
||||
warning: scrollback(theme.text.feedback.warning.base),
|
||||
syntax,
|
||||
diffRemoved: scrollback(theme.diff.text.removed),
|
||||
diffAddedBg: scrollback(theme.diff.background.added),
|
||||
|
|
@ -241,6 +245,8 @@ function monoTheme(mode: "dark" | "light"): RunTheme {
|
|||
block: {
|
||||
text: foreground,
|
||||
muted: foreground,
|
||||
faint: foreground,
|
||||
warning: foreground,
|
||||
diffRemoved: foreground,
|
||||
diffAddedBg: background,
|
||||
diffRemovedBg: background,
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import {
|
|||
} from "../util/tool-display"
|
||||
import { formatPath } from "../util/path-format"
|
||||
import { isRecord } from "../util/record"
|
||||
import { parseTodos, todoMarker } from "../util/todo"
|
||||
import type { RunEntryBody, StreamCommit, ToolSnapshot } from "./types"
|
||||
|
||||
export { canonicalToolName } from "../util/tool-display"
|
||||
|
|
@ -117,6 +118,7 @@ type ToolName =
|
|||
| "patch"
|
||||
| "batch"
|
||||
| "subagent"
|
||||
| "todowrite"
|
||||
| "question"
|
||||
| "read"
|
||||
| "glob"
|
||||
|
|
@ -457,6 +459,17 @@ function runPatch(p: ToolProps): ToolInline {
|
|||
}
|
||||
}
|
||||
|
||||
function runTodo(p: ToolProps): ToolInline {
|
||||
return {
|
||||
icon: "#",
|
||||
title: "Todos",
|
||||
mode: "block",
|
||||
body: parseTodos(p.frame.input.todos)
|
||||
.map((item) => `${todoMarker(item.status)} ${item.content}`)
|
||||
.join("\n"),
|
||||
}
|
||||
}
|
||||
|
||||
function runQuestion(p: ToolProps): ToolInline {
|
||||
const total = list(p.frame.input.questions).length
|
||||
return {
|
||||
|
|
@ -611,6 +624,13 @@ function snapTask(p: ToolProps): ToolSnapshot {
|
|||
}
|
||||
}
|
||||
|
||||
function snapTodo(p: ToolProps): ToolSnapshot {
|
||||
return {
|
||||
kind: "todo",
|
||||
items: parseTodos(p.frame.input.todos),
|
||||
}
|
||||
}
|
||||
|
||||
function snapQuestion(p: ToolProps): ToolSnapshot {
|
||||
const answers = list<unknown[]>(p.frame.meta.answers)
|
||||
const items = list<{ question?: string }>(p.frame.input.questions).map((item, i) => {
|
||||
|
|
@ -794,6 +814,10 @@ function scrollTaskFinal(p: ToolProps): string {
|
|||
return `# ${kind} Subagent\n${row}`
|
||||
}
|
||||
|
||||
function scrollTodoStart(_: ToolProps): string {
|
||||
return ""
|
||||
}
|
||||
|
||||
function scrollQuestionStart(_: ToolProps): string {
|
||||
return ""
|
||||
}
|
||||
|
|
@ -970,6 +994,18 @@ const TOOL_RULES = {
|
|||
final: scrollTaskFinal,
|
||||
},
|
||||
},
|
||||
todowrite: {
|
||||
view: {
|
||||
output: false,
|
||||
final: true,
|
||||
snap: "structured",
|
||||
},
|
||||
run: runTodo,
|
||||
snap: snapTodo,
|
||||
scroll: {
|
||||
start: scrollTodoStart,
|
||||
},
|
||||
},
|
||||
question: {
|
||||
view: {
|
||||
output: false,
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import type {
|
|||
SessionMessageAssistantTool,
|
||||
} from "@opencode/client/promise"
|
||||
import type { Config } from "../config"
|
||||
import type { Todo } from "../util/todo"
|
||||
import type { CliRenderer } from "@opentui/core"
|
||||
import type { SessionInbox } from "@opencode/schema/session-inbox"
|
||||
|
||||
|
|
@ -222,6 +223,11 @@ type ToolTaskSnapshot = {
|
|||
tail: string
|
||||
}
|
||||
|
||||
type ToolTodoSnapshot = {
|
||||
kind: "todo"
|
||||
items: Todo[]
|
||||
}
|
||||
|
||||
type ToolQuestionSnapshot = {
|
||||
kind: "question"
|
||||
items: Array<{
|
||||
|
|
@ -231,7 +237,12 @@ type ToolQuestionSnapshot = {
|
|||
tail: string
|
||||
}
|
||||
|
||||
export type ToolSnapshot = ToolCodeSnapshot | ToolDiffSnapshot | ToolTaskSnapshot | ToolQuestionSnapshot
|
||||
export type ToolSnapshot =
|
||||
| ToolCodeSnapshot
|
||||
| ToolDiffSnapshot
|
||||
| ToolTaskSnapshot
|
||||
| ToolTodoSnapshot
|
||||
| ToolQuestionSnapshot
|
||||
|
||||
type MiniToolState =
|
||||
| {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import PromptFooter from "../feature-plugins/prompt/footer"
|
|||
import SidebarContext from "../feature-plugins/sidebar/context"
|
||||
import SidebarFooter from "../feature-plugins/sidebar/footer"
|
||||
import SidebarMcp from "../feature-plugins/sidebar/mcp"
|
||||
import SidebarTodo from "../feature-plugins/sidebar/todo"
|
||||
import DiffViewer from "../feature-plugins/system/diff-viewer"
|
||||
import Notifications from "../feature-plugins/system/notifications"
|
||||
import Plugins from "../feature-plugins/system/plugins"
|
||||
|
|
@ -18,6 +19,7 @@ export const builtins = [
|
|||
PromptBtw,
|
||||
SidebarContext,
|
||||
SidebarMcp,
|
||||
SidebarTodo,
|
||||
SidebarFooter,
|
||||
Notifications,
|
||||
Plugins,
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ import { useEditorContext } from "../../context/editor"
|
|||
import { useDialog } from "../../ui/dialog"
|
||||
import { DialogSelect } from "../../ui/dialog-select"
|
||||
import { DialogSessionRename } from "../../component/dialog-session-rename"
|
||||
import { TodoItem } from "../../component/todo-item"
|
||||
import { DialogImagePreview } from "../../component/dialog-image-preview"
|
||||
import { statusLabel } from "../../component/dialog-workspace-file-changes"
|
||||
import { DialogMessage } from "./dialog-message"
|
||||
|
|
@ -120,6 +121,7 @@ import { createSingleFlight } from "../../util/single-flight"
|
|||
import { createDelayedPresence } from "../../util/delayed-presence"
|
||||
import { SessionLocationMissing } from "./location-missing"
|
||||
import { isRecord } from "../../util/record"
|
||||
import { parseTodos } from "../../util/todo"
|
||||
import { createHistoryPrepend } from "./history"
|
||||
import { context, use, type PendingAction } from "./render-context"
|
||||
import { INLINE_TOOL_ICON_WIDTH, InlineToolRow, ReasoningPart, TextPart, toolDisplay } from "./message-parts"
|
||||
|
|
@ -2464,6 +2466,9 @@ function ToolPart(props: { part: SessionMessageAssistantTool; images?: boolean }
|
|||
<Match when={display() === "patch"}>
|
||||
<ApplyPatch {...toolprops} />
|
||||
</Match>
|
||||
<Match when={display() === "todowrite"}>
|
||||
<TodoWrite {...toolprops} />
|
||||
</Match>
|
||||
<Match when={display() === "question"}>
|
||||
<Question {...toolprops} />
|
||||
</Match>
|
||||
|
|
@ -3460,6 +3465,32 @@ function ApplyPatch(props: ToolProps) {
|
|||
)
|
||||
}
|
||||
|
||||
function TodoWrite(props: ToolProps) {
|
||||
const theme = useTheme()
|
||||
const todos = createMemo(() => parseTodos(props.input.todos))
|
||||
return (
|
||||
<Switch>
|
||||
<Match when={props.part.state.status === "completed" && todos().length > 0}>
|
||||
<BlockTool title="# Todos" part={props.part}>
|
||||
<box>
|
||||
<For each={todos()}>{(todo) => <TodoItem theme={theme} todo={todo} />}</For>
|
||||
</box>
|
||||
</BlockTool>
|
||||
</Match>
|
||||
<Match when={true}>
|
||||
<InlineTool
|
||||
icon="⚙"
|
||||
pending="Updating todos…"
|
||||
complete={props.part.state.status === "completed" || props.part.state.status === "error"}
|
||||
part={props.part}
|
||||
>
|
||||
{props.part.state.status === "error" ? "Todo update failed" : "Cleared todos"}
|
||||
</InlineTool>
|
||||
</Match>
|
||||
</Switch>
|
||||
)
|
||||
}
|
||||
|
||||
function Question(props: ToolProps) {
|
||||
const theme = useTheme()
|
||||
const questions = createMemo(() => parseQuestions(props.input.questions))
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ const toolDisplays = new Set([
|
|||
"subagent",
|
||||
"execute",
|
||||
"patch",
|
||||
"todowrite",
|
||||
"question",
|
||||
"skill",
|
||||
])
|
||||
|
|
|
|||
54
packages/tui/src/util/todo.ts
Normal file
54
packages/tui/src/util/todo.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import type {
|
||||
SessionMessageAssistantTool,
|
||||
SessionMessageInfo,
|
||||
SessionMessageToolStateCompleted,
|
||||
} from "@opencode/client"
|
||||
import { isRecord } from "./record"
|
||||
|
||||
export type TodoStatus = "pending" | "in_progress" | "completed" | "cancelled"
|
||||
|
||||
export type Todo = {
|
||||
content: string
|
||||
status: TodoStatus
|
||||
}
|
||||
|
||||
const statuses = new Set<unknown>(["pending", "in_progress", "completed", "cancelled"])
|
||||
|
||||
export function parseTodos(value: unknown): Todo[] {
|
||||
if (!Array.isArray(value)) return []
|
||||
return value.flatMap((item) => {
|
||||
if (!isRecord(item) || typeof item.content !== "string" || !item.content) return []
|
||||
return [{ content: item.content, status: statuses.has(item.status) ? (item.status as TodoStatus) : "pending" }]
|
||||
})
|
||||
}
|
||||
|
||||
export function todoMarker(status: TodoStatus, ascii = false) {
|
||||
if (status === "completed") return ascii ? "[x]" : "[✓]"
|
||||
if (status === "in_progress") return ascii ? "[>]" : "[•]"
|
||||
if (status === "cancelled") return "[-]"
|
||||
return "[ ]"
|
||||
}
|
||||
|
||||
/**
|
||||
* The current list is the latest completed `todowrite` input or post-compaction todo reminder,
|
||||
* after the latest completed compaction and before the revert boundary. An empty list means none.
|
||||
*/
|
||||
export function sessionTodos(messages: ReadonlyArray<SessionMessageInfo>, boundary?: string): Todo[] {
|
||||
const boundaryIndex = boundary ? messages.findIndex((message) => message.id === boundary) : -1
|
||||
const visible = messages.slice(0, boundaryIndex === -1 ? messages.length : boundaryIndex)
|
||||
const compaction = visible.findLastIndex((message) => message.type === "compaction" && message.status === "completed")
|
||||
const source = visible
|
||||
.slice(compaction + 1)
|
||||
.flatMap((message) => {
|
||||
if (message.type === "synthetic" && message.metadata?.kind === "todo.reminder") return [message.metadata.todos]
|
||||
if (message.type !== "assistant") return []
|
||||
return message.content
|
||||
.filter(
|
||||
(item): item is SessionMessageAssistantTool & { state: SessionMessageToolStateCompleted } =>
|
||||
item.type === "tool" && item.name === "todowrite" && item.state.status === "completed",
|
||||
)
|
||||
.map((item) => item.state.input.todos)
|
||||
})
|
||||
.at(-1)
|
||||
return parseTodos(source)
|
||||
}
|
||||
|
|
@ -410,6 +410,20 @@ interval and 30-minute active window.
|
|||
See the [warming guide](/warming) for request behavior, customization,
|
||||
and cost considerations.
|
||||
|
||||
### Experimental
|
||||
|
||||
Experimental features may change or be removed in a future release.
|
||||
|
||||
Set `todo` to `true` to give agents a `todowrite` tool for tracking multi-step work.
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"experimental": {
|
||||
"todo": true,
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
### Skills
|
||||
|
||||
Add directories or URLs that OpenCode should search for agent skills.
|
||||
|
|
|
|||
|
|
@ -123,6 +123,17 @@ V1 groups permission effects by tool. V2 uses one ordered `permissions` array, m
|
|||
Permission actions also changed: `bash` is now `shell`, `task` is now `subagent`, and `write` and `patch` are now `edit`.
|
||||
See [Permissions](/permissions) for the ordered V2 rule format.
|
||||
|
||||
Todos are off by default in V2. To turn them on, use the experimental flag. It may change or be removed in a future
|
||||
release; see [Experimental](/config#experimental).
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"experimental": {
|
||||
"todo": true,
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
<Callout type="warning">
|
||||
V1 asks before accessing paths outside the project. V2 does not: `external_directory` is allowed by default. To keep
|
||||
the V1 behavior, add `{ "action": "external_directory", "resource": "*", "effect": "ask" }` to `permissions`.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue