Human-facing task state

This commit is contained in:
Ian Gulliver
2026-10-16 10:59:46 -07:00
parent 07780b8701
commit db58d76837
12 changed files with 78 additions and 54 deletions
+8 -9
View File
@@ -2,7 +2,7 @@ import { get, post } from "./api.js";
import { errorText, h, replace, showAlert } from "./dom.js";
import { markdown } from "./markdown.js";
import { models } from "./task.js";
import { currentSession, findTask, focusedProject, focusTask, on, onEach, state, taskState } from "./state.js";
import { findTask, focusedProject, focusTask, on, onEach, state, taskState } from "./state.js";
import { taskStyle } from "./taskcolor.js";
const refreshKinds = new Set(["task.merged", "project.created"]);
export function mountProject(root) {
@@ -100,12 +100,11 @@ function nested(active) {
}
return out;
}
const busyStates = new Set(["running", "reviewing", "merging", "discarding"]);
function stateMark(s) {
if (s !== undefined && busyStates.has(s)) {
return h("span", { class: "spinner", title: s });
function stateMark(ts) {
if (ts.kind === "working" || ts.kind === "merging") {
return h("span", { class: "spinner", title: ts.title });
}
return h("span", { class: `dot ${s ?? "none"}`, title: s ?? "no session" });
return h("span", { class: `dot ${ts.kind}`, title: ts.title });
}
function tasksBlock(active) {
if (active.length === 0) {
@@ -121,7 +120,7 @@ function tasksBlock(active) {
e.preventDefault();
focusTask(task.id);
},
}, task.parent_task_id !== undefined && h("span", { class: "subtask-mark", title: `Subtask of ${findTask(task.parent_task_id)?.title ?? task.parent_task_id}` }, "↳"), stateMark(ts), h("span", { class: "task-title task-name" }, task.title), count > 0 && h("span", { class: "badge", title: "inbox items" }, count), task.merge_queued_at !== undefined && h("span", { class: "task-state warn", title: "Waiting for the merge in progress in this project to finish" }, "merge held"), task.merging_into_parent && h("span", { class: "task-state warn", title: "Waiting for the parent task's agent to merge it" }, "merging into parent"), h("span", { class: "task-state" }, ts ?? "no agent")));
}, task.parent_task_id !== undefined && h("span", { class: "subtask-mark", title: `Subtask of ${findTask(task.parent_task_id)?.title ?? task.parent_task_id}` }, "↳"), stateMark(ts), h("span", { class: "task-title task-name" }, task.title), count > 0 && h("span", { class: "badge", title: "inbox items" }, count), h("span", { class: `task-state ${ts.kind}`, title: ts.title }, ts.label)));
}));
}
function todoBlock(project, todo, active, starting, start) {
@@ -152,7 +151,7 @@ function todoBlock(project, todo, active, starting, start) {
const task = active.find((t) => t.todo_item === item.title);
let action;
if (task) {
const sess = currentSession(task.id);
const ts = taskState(task);
action = h("a", {
class: "todo-task",
href: `#/task/${task.id}`,
@@ -160,7 +159,7 @@ function todoBlock(project, todo, active, starting, start) {
e.preventDefault();
focusTask(task.id);
},
}, stateMark(sess?.state), sess?.state ?? "no agent");
}, stateMark(ts), ts.label);
}
else {
const busy = starting.has(`${project.id}\n${item.title}`);
+1 -1
View File
File diff suppressed because one or more lines are too long
+17 -5
View File
@@ -55,14 +55,26 @@ export function currentSession(taskId) {
return state.sessions.get(taskId)?.findLast((s) => s.state !== "completed") ?? state.sessions.get(taskId)?.at(-1);
}
export function taskState(task) {
if (task.discarding) {
return "discarding";
const open = state.inbox.filter((item) => item.task_id === task.id);
if (open.some((item) => item.kind === "question")) {
return { kind: "answer", label: "Needs your answer", title: "The agent asked a question in the inbox" };
}
if (task.merging) {
return "merging";
return { kind: "merging", label: "Merging", title: "The merge turn is running" };
}
const s = currentSession(task.id)?.state;
return s === "idle" && task.reviewing ? "reviewing" : s;
if (task.merging_into_parent) {
return { kind: "merging", label: "Merging", title: "Waiting for the parent task's agent to merge it" };
}
if (task.merge_queued_at !== undefined) {
return { kind: "held", label: "Merge held", title: "Waiting for the merge in progress in this project to finish" };
}
if (open.length > 0) {
return { kind: "error", label: "Error", title: "The agent's session failed or hit a rate limit; see the inbox" };
}
if (task.discarding || task.reviewing || currentSession(task.id)?.state === "running") {
return { kind: "working", label: "Working", title: task.discarding ? "Discarding" : task.reviewing ? "A review is running" : "The agent is mid-turn" };
}
return { kind: "idle", label: "Idle", title: "Waiting for a message" };
}
export function currentLead() {
return state.leadSessions.findLast((s) => s.state !== "completed") ?? state.leadSessions.at(-1);
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -132,7 +132,7 @@ export function openSwitcher() {
.sort((a, b) => Number(b.count > 0) - Number(a.count > 0) || a.visited - b.visited);
rows = matches.map(({ project, task, count }) => {
const ts = taskState(task);
const el = h("li", { style: taskStyle(task.id) }, h("span", { class: `dot ${ts ?? "none"}`, title: ts ?? "no session" }), h("span", { class: "task-title" }, h("span", { class: "project-name" }, project.name), " ", task.parent_task_id !== undefined && h("span", { class: "subtask-mark" }, `${findTask(task.parent_task_id)?.title ?? task.parent_task_id} ↳ `), h("span", { class: "task-name" }, task.title)), count > 0 && h("span", { class: "badge", title: "inbox items" }, count), task.merge_queued_at !== undefined && h("span", { class: "task-state warn", title: "Waiting for the merge in progress in this project to finish" }, "merge held"), task.merging_into_parent && h("span", { class: "task-state warn", title: "Waiting for the parent task's agent to merge it" }, "merging into parent"), h("span", { class: "task-state" }, ts ?? "no agent"));
const el = h("li", { style: taskStyle(task.id) }, h("span", { class: `dot ${ts.kind}`, title: ts.title }), h("span", { class: "task-title" }, h("span", { class: "project-name" }, project.name), " ", task.parent_task_id !== undefined && h("span", { class: "subtask-mark" }, `${findTask(task.parent_task_id)?.title ?? task.parent_task_id} ↳ `), h("span", { class: "task-name" }, task.title)), count > 0 && h("span", { class: "badge", title: "inbox items" }, count), h("span", { class: `task-state ${ts.kind}`, title: ts.title }, ts.label));
return { el, pick: () => go(task.id) };
});
for (const p of (targets ?? state.projects).filter((p) => `${p.name} project`.toLowerCase().includes(q))) {
+1 -1
View File
File diff suppressed because one or more lines are too long