Add todo mode and replace the plan with TODO.md
This commit is contained in:
@@ -123,6 +123,44 @@ export interface paths {
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/api/projects/{projectId}/todo": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
projectId: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
/** @description The items of TODO.md at the root of the project's default branch, in file order. */
|
||||
get: operations["getTodo"];
|
||||
put?: never;
|
||||
post?: never;
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/api/projects/{projectId}/todo/tasks": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
projectId: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
get?: never;
|
||||
put?: never;
|
||||
/** @description Creates a task for a TODO.md item, recording the item as its todo_item, and starts its agent with the item as the first message. Refused while another active task has the same item. */
|
||||
post: operations["startTodoItem"];
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/api/tasks/{taskId}": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
@@ -603,6 +641,26 @@ export interface components {
|
||||
closed_at?: string;
|
||||
/** @description merged: the squash commit on the default branch; empty when there was nothing to merge. */
|
||||
merge_commit?: string;
|
||||
/** @description The title of the TODO.md item the task was started from; absent for other tasks. */
|
||||
todo_item?: string;
|
||||
};
|
||||
Todo: {
|
||||
/** @description Whether the default branch has a TODO.md at its root. */
|
||||
exists: boolean;
|
||||
items: components["schemas"]["TodoItem"][];
|
||||
};
|
||||
TodoItem: {
|
||||
/** @description The item's first line, without its list marker: the item's identity. */
|
||||
title: string;
|
||||
/** @description The item's further lines */
|
||||
body: string;
|
||||
/** @description The text of the nearest heading above the item; empty when there is none. */
|
||||
section: string;
|
||||
};
|
||||
TodoStart: {
|
||||
/** @description The title of the item to start. */
|
||||
title: string;
|
||||
model?: string;
|
||||
};
|
||||
Unmerged: {
|
||||
/** @description Commits on the task branch that aren't on the default branch. */
|
||||
@@ -1142,6 +1200,58 @@ export interface operations {
|
||||
404: components["responses"]["Error"];
|
||||
};
|
||||
};
|
||||
getTodo: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
projectId: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description The items; exists is false when the default branch has no TODO.md. */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Todo"];
|
||||
};
|
||||
};
|
||||
404: components["responses"]["Error"];
|
||||
};
|
||||
};
|
||||
startTodoItem: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
projectId: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": components["schemas"]["TodoStart"];
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description The new task. */
|
||||
201: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Task"];
|
||||
};
|
||||
};
|
||||
400: components["responses"]["Error"];
|
||||
404: components["responses"]["Error"];
|
||||
409: components["responses"]["Error"];
|
||||
};
|
||||
};
|
||||
getTask: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
|
||||
+4
-2
@@ -5,19 +5,21 @@ import { mountInbox } from "./inbox.js";
|
||||
import { mountSettings } from "./settings.js";
|
||||
import { mountTranscript } from "./task.js";
|
||||
import { mountTasks } from "./tasks.js";
|
||||
import { mountTodo } from "./todo.js";
|
||||
|
||||
export type View = "transcript" | "changes" | "tasks" | "inbox" | "admin" | "settings";
|
||||
export type View = "transcript" | "changes" | "tasks" | "todo" | "inbox" | "admin" | "settings";
|
||||
|
||||
const views: Record<View, { label: string; mount: (root: HTMLElement) => () => void }> = {
|
||||
transcript: { label: "Transcript", mount: mountTranscript },
|
||||
changes: { label: "Changes", mount: (root) => mountChanges(root) },
|
||||
tasks: { label: "Tasks", mount: mountTasks },
|
||||
todo: { label: "Todo", mount: mountTodo },
|
||||
inbox: { label: "Inbox", mount: mountInbox },
|
||||
admin: { label: "Admin", mount: mountAdmin },
|
||||
settings: { label: "Settings", mount: mountSettings },
|
||||
};
|
||||
|
||||
const order: View[] = ["transcript", "changes", "tasks", "inbox", "admin", "settings"];
|
||||
const order: View[] = ["transcript", "changes", "tasks", "todo", "inbox", "admin", "settings"];
|
||||
|
||||
const panes: Pane[] = [];
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import { markdown } from "./markdown.js";
|
||||
import { openChanges } from "./panes.js";
|
||||
import { currentSession, findTask, onEach, pinSnapshot, state } from "./state.js";
|
||||
|
||||
const models = ["claude-opus-5-5", "claude-sonnet-5-5", "claude-haiku-5-5", "claude-fable-5-1"];
|
||||
export const models = ["claude-opus-5-5", "claude-sonnet-5-5", "claude-haiku-5-5", "claude-fable-5-1"];
|
||||
|
||||
type Call = { name: string; target: string };
|
||||
|
||||
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
import { get, post, type ByreEvent, type Project, type Schemas } from "./api.js";
|
||||
import { errorText, h, replace, showAlert } from "./dom.js";
|
||||
import { markdown } from "./markdown.js";
|
||||
import { openTranscript } from "./panes.js";
|
||||
import { models } from "./task.js";
|
||||
import { currentSession, on, onEach, state } from "./state.js";
|
||||
|
||||
type Todo = Schemas["Todo"];
|
||||
type TodoItem = Schemas["TodoItem"];
|
||||
|
||||
const refreshKinds = new Set(["task.merged", "project.created"]);
|
||||
|
||||
export function mountTodo(root: HTMLElement): () => void {
|
||||
const todos = new Map<string, Todo | string>();
|
||||
const starting = new Set<string>();
|
||||
let disposed = false;
|
||||
|
||||
const render = () => {
|
||||
const scrollTop = root.querySelector(".todo-view")?.scrollTop ?? 0;
|
||||
replace(root, h("div", { class: "todo-view" }, ...state.projects.map((p) => projectBlock(p, todos.get(p.id), starting, start))));
|
||||
root.querySelector(".todo-view")!.scrollTop = scrollTop;
|
||||
};
|
||||
|
||||
const load = async (projectId: string) => {
|
||||
try {
|
||||
const todo = await get("/api/projects/{projectId}/todo", { path: { projectId } });
|
||||
todos.set(projectId, todo);
|
||||
} catch (err) {
|
||||
todos.set(projectId, `Couldn't read TODO.md: ${errorText(err)}`);
|
||||
}
|
||||
if (!disposed) {
|
||||
render();
|
||||
}
|
||||
};
|
||||
|
||||
const refresh = () => {
|
||||
for (const p of state.projects) {
|
||||
void load(p.id);
|
||||
}
|
||||
};
|
||||
|
||||
const start = async (project: Project, item: TodoItem) => {
|
||||
const key = `${project.id}\n${item.title}`;
|
||||
starting.add(key);
|
||||
render();
|
||||
try {
|
||||
const task = await post("/api/projects/{projectId}/todo/tasks", { path: { projectId: project.id }, body: { title: item.title, model: models[0] } });
|
||||
location.hash = `#/task/${task.id}`;
|
||||
openTranscript();
|
||||
} catch (err) {
|
||||
void showAlert(errorText(err));
|
||||
}
|
||||
starting.delete(key);
|
||||
if (!disposed) {
|
||||
render();
|
||||
}
|
||||
};
|
||||
|
||||
const offs = [
|
||||
on("event", (detail?: unknown) => {
|
||||
const ev = detail as ByreEvent;
|
||||
if (!refreshKinds.has(ev.kind)) {
|
||||
return;
|
||||
}
|
||||
if (ev.project_id) {
|
||||
void load(ev.project_id);
|
||||
}
|
||||
}),
|
||||
on("connection", () => {
|
||||
if (state.connected) {
|
||||
refresh();
|
||||
}
|
||||
}),
|
||||
on("projects", refresh),
|
||||
onEach(["tasks", "sessions", "selection"], render),
|
||||
];
|
||||
|
||||
render();
|
||||
refresh();
|
||||
|
||||
return () => {
|
||||
disposed = true;
|
||||
for (const off of offs) {
|
||||
off();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function projectBlock(project: Project, todo: Todo | string | undefined, starting: Set<string>, start: (p: Project, item: TodoItem) => Promise<void>): HTMLElement {
|
||||
const head = h("h2", {}, project.name, " ", h("span", { class: "repo" }, `TODO.md on ${project.default_branch}`));
|
||||
|
||||
if (todo === undefined) {
|
||||
return h("section", { class: "project" }, head, h("p", { class: "empty-row" }, "Loading…"));
|
||||
}
|
||||
if (typeof todo === "string") {
|
||||
return h("section", { class: "project" }, head, h("p", { class: "empty-row error-text" }, todo));
|
||||
}
|
||||
if (!todo.exists) {
|
||||
return h("section", { class: "project" }, head, h("p", { class: "empty-row" }, `No TODO.md on ${project.default_branch}.`));
|
||||
}
|
||||
if (todo.items.length === 0) {
|
||||
return h("section", { class: "project" }, head, h("p", { class: "empty-row" }, "TODO.md has no items."));
|
||||
}
|
||||
|
||||
const active = (state.tasks.get(project.id) ?? []).filter((t) => t.status === "active" && t.todo_item);
|
||||
const children: HTMLElement[] = [];
|
||||
let section = "";
|
||||
let list: HTMLElement | undefined;
|
||||
for (const item of todo.items) {
|
||||
if (!list || item.section !== section) {
|
||||
section = item.section;
|
||||
if (section) {
|
||||
children.push(h("h3", { class: "todo-section" }, section));
|
||||
}
|
||||
list = h("ul", { class: "todo-list" });
|
||||
children.push(list);
|
||||
}
|
||||
|
||||
const task = active.find((t) => t.todo_item === item.title);
|
||||
let action: HTMLElement;
|
||||
if (task) {
|
||||
const sess = currentSession(task.id);
|
||||
action = h(
|
||||
"a",
|
||||
{ class: "todo-task", href: `#/task/${task.id}`, onclick: openTranscript },
|
||||
h("span", { class: `dot ${sess?.state ?? "none"}`, title: sess?.state ?? "no session" }),
|
||||
sess?.state ?? "no agent",
|
||||
);
|
||||
} else {
|
||||
const busy = starting.has(`${project.id}\n${item.title}`);
|
||||
const button = h("button", { disabled: busy }, busy ? "Starting…" : "Start");
|
||||
button.onclick = () => void start(project, item);
|
||||
action = button;
|
||||
}
|
||||
|
||||
list.append(
|
||||
h(
|
||||
"li",
|
||||
{ class: task && task.id === state.selectedTaskId ? "selected" : "" },
|
||||
h("div", { class: "todo-head" }, h("span", { class: "todo-title" }, item.title), action),
|
||||
item.body && markdown(item.body, "md todo-body"),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return h("section", { class: "project" }, head, ...children);
|
||||
}
|
||||
Reference in New Issue
Block a user