Add Start and Discuss buttons to lead suggestions

This commit is contained in:
Ian Gulliver
2026-10-17 08:10:55 -07:00
parent 62df39c5da
commit f5a495997f
16 changed files with 318 additions and 156 deletions
+32 -14
View File
@@ -1,10 +1,14 @@
import { post } from "./api.js";
import { errorText, h, replace, showAlert } from "./dom.js";
import { currentSession, focusTask, state } from "./state.js";
import { currentLead, currentSession, focusTask, state } from "./state.js";
import { taskStyle } from "./taskcolor.js";
const starting = new Set();
export function todoLink(projectId, title, children) {
return h("span", { class: "todo-link", data: { project: projectId, title } }, h("span", { class: "todo-title" }, ...children), " ", h("span", { class: "todo-action" }));
const busy = new Map();
export function todoLink(projectId, title, children, brief) {
const data = { project: projectId, title };
if (brief !== undefined) {
data["brief"] = brief;
}
return h("span", { class: "todo-link", data }, h("span", { class: "todo-title" }, ...children), " ", h("span", { class: "todo-action" }));
}
export function fillTodoLinks(root, model) {
for (const el of root.querySelectorAll(".todo-link")) {
@@ -14,9 +18,10 @@ export function fillTodoLinks(root, model) {
function fill(el, model) {
const projectId = el.dataset["project"];
const title = el.dataset["title"];
const brief = el.dataset["brief"];
const action = el.querySelector(".todo-action");
const titleEl = el.querySelector(".todo-title");
const task = (state.tasks.get(projectId) ?? []).find((t) => t.status === "active" && t.todo_item === title);
const task = (state.tasks.get(projectId) ?? []).find((t) => t.status === "active" && (brief === undefined ? t.todo_item === title : t.title === title));
if (task) {
const sess = currentSession(task.id);
el.setAttribute("style", taskStyle(task.id));
@@ -34,23 +39,36 @@ function fill(el, model) {
el.removeAttribute("style");
titleEl.classList.remove("task-name");
const key = `${projectId}\n${title}`;
const busy = starting.has(key);
const start = async (discuss) => {
starting.add(key);
const label = busy.get(key);
const run = async (busyLabel, act) => {
busy.set(key, busyLabel);
fill(el, model);
try {
await post("/api/projects/{projectId}/todo/tasks", { path: { projectId }, body: { title, model, discuss } });
await act();
}
catch (err) {
void showAlert(errorText(err));
}
starting.delete(key);
busy.delete(key);
fill(el, model);
};
const startButton = h("button", { disabled: busy, title: "Start a task that gets straight to work" }, busy ? "starting…" : "start");
startButton.onclick = () => void start(false);
const discussButton = h("button", { disabled: busy, title: "Start a task that discusses it with you in chat before building anything" }, "discuss");
discussButton.onclick = () => void start(true);
if (brief === undefined) {
const start = (discuss) => run(discuss ? "discuss" : "start", () => post("/api/projects/{projectId}/todo/tasks", { path: { projectId }, body: { title, model, discuss } }));
const startButton = h("button", { disabled: !!label, title: "Start a task that gets straight to work" }, label === "start" ? "starting…" : "start");
startButton.onclick = () => void start(false);
const discussButton = h("button", { disabled: !!label, title: "Start a task that discusses it with you in chat before building anything" }, label === "discuss" ? "starting…" : "discuss");
discussButton.onclick = () => void start(true);
replace(action, startButton, discussButton);
return;
}
const startButton = h("button", { disabled: !!label, title: "Start a task with the lead's brief" }, label === "start" ? "starting…" : "start");
startButton.onclick = () => void run("start", () => post("/api/projects/{projectId}/tasks", { path: { projectId }, body: { title, prompt: brief, model } }));
const discussButton = h("button", { disabled: !!label, title: "Ask your lead to talk it over in chat" }, label === "discuss" ? "sending…" : "discuss");
discussButton.onclick = () => void run("discuss", () => {
const lead = currentLead();
const live = lead !== undefined && lead.state !== "completed";
return post("/api/me/lead/messages", { body: { text: `Let's discuss your suggestion "${title}" before starting it:\n\n${brief}`, model: live ? undefined : model } });
});
replace(action, startButton, discussButton);
}
//# sourceMappingURL=todolink.js.map