Pick project and model when creating a task

This commit is contained in:
Ian Gulliver
2026-10-16 09:13:28 -07:00
parent 2bb7833de3
commit 1a2710f7c8
5 changed files with 33 additions and 19 deletions
+12 -7
View File
@@ -2,7 +2,7 @@ import { post } from "./api.js";
import { errorText, h, replace, showAlert } from "./dom.js";
import { focusLead } from "./panes.js";
import { activeTasks, focusedProject, focusProject, focusTab, focusTask, lastVisits, onEach, state, taskState } from "./state.js";
import { confirmMerge } from "./task.js";
import { confirmMerge, models } from "./task.js";
import { taskStyle } from "./taskcolor.js";
export function bindShortcuts() {
addEventListener("keydown", (e) => {
@@ -50,6 +50,7 @@ const shortcuts = [
[
["↑ ↓", "Move the highlight"],
["Enter", "Pick the highlighted row"],
["name: title", "Create the task in the project whose name starts with name"],
],
],
[
@@ -117,12 +118,16 @@ export function openSwitcher() {
}
};
const render = () => {
const title = input.value.trim();
const typed = input.value.trim();
const prefix = /^([^:\s]+):\s*(.*)$/.exec(typed);
const named = prefix ? state.projects.filter((p) => p.name.toLowerCase().startsWith(prefix[1].toLowerCase())) : [];
const targets = named.length > 0 ? named : undefined;
const title = targets ? prefix[2] : typed;
const q = title.toLowerCase();
const inbox = (taskId) => state.inbox.filter((item) => item.task_id === taskId).length;
const visits = lastVisits();
const matches = activeTasks()
.filter(({ project, task }) => `${project.name} ${task.title}`.toLowerCase().includes(q))
.filter(({ project, task }) => targets ? targets.some((p) => p.id === project.id) && task.title.toLowerCase().includes(q) : `${project.name} ${task.title}`.toLowerCase().includes(q))
.map((m) => ({ ...m, count: inbox(m.task.id), visited: visits[m.task.id] ?? 0 }))
.sort((a, b) => Number(b.count > 0) - Number(a.count > 0) || a.visited - b.visited);
rows = matches.map(({ project, task, count }) => {
@@ -130,7 +135,7 @@ export function openSwitcher() {
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), " ", 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"), h("span", { class: "task-state" }, ts ?? "no agent"));
return { el, pick: () => go(task.id) };
});
for (const p of state.projects.filter((p) => `${p.name} project`.toLowerCase().includes(q))) {
for (const p of (targets ?? state.projects).filter((p) => `${p.name} project`.toLowerCase().includes(q))) {
const el = h("li", {}, h("span", { class: "dot none" }), h("span", { class: "task-title" }, h("span", { class: "project-name" }, p.name)), h("span", { class: "task-state" }, "project"));
rows.push({
el,
@@ -140,9 +145,9 @@ export function openSwitcher() {
},
});
}
const project = focusedProject() ?? state.projects[0];
if (title && project) {
const el = h("li", { class: "new-task" }, h("span", { class: "task-title" }, "New task in ", h("span", { class: "project-name" }, project.name), ": ", title));
const fallback = focusedProject() ?? state.projects[0];
for (const project of title ? (targets ?? (fallback ? [fallback] : [])) : []) {
const el = h("li", { class: "new-task" }, h("span", { class: "task-title" }, "New task in ", h("span", { class: "project-name" }, project.name), ": ", title), h("span", { class: "task-state", title: "Model for the first message" }, models[0]));
rows.push({ el, pick: () => void create(project.id, title) });
}
selected = Math.min(selected, Math.max(rows.length - 1, 0));