feat(tasks): task search across REST, tool, and TUI

Ranked exact/substring search: TaskSearch (all terms AND, ranked title >
key > goal > criteria > notes) over one project or the whole board via
TaskService.search. Surfaced as GET /tasks?q=, a read-only task_search tool
for agents, and a `/` filter in the TUI board.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-23 22:08:11 +00:00
parent 1d7fab4ee4
commit 99f781687f
11 changed files with 357 additions and 28 deletions
+88 -20
View File
@@ -85,10 +85,28 @@ func (m *Model) openTasks() tea.Cmd {
m.taskListErr = ""
m.taskDetail = false
m.taskDetailScroll = 0
m.taskFilter = ""
m.taskFilterTyping = false
m.taskListLoading = true
return fetchTasks(m.client.HTTPBase())
}
// filteredTasks narrows the board by the `/` query — a case-insensitive substring over
// id/title/goal. An empty query returns the whole list.
func (m Model) filteredTasks() []TaskSummary {
if strings.TrimSpace(m.taskFilter) == "" {
return m.taskList
}
q := strings.ToLower(m.taskFilter)
var out []TaskSummary
for _, tk := range m.taskList {
if strings.Contains(strings.ToLower(tk.ID+" "+tk.Title+" "+tk.Goal), q) {
out = append(out, tk)
}
}
return out
}
// applyTasksLoaded folds a GET /tasks result into the board, clamping the cursor and
// surfacing any fetch error in place of a crash.
func (m *Model) applyTasksLoaded(msg tasksLoadedMsg) {
@@ -107,10 +125,11 @@ func (m *Model) applyTasksLoaded(msg tasksLoadedMsg) {
// selectedTask returns the highlighted task, or false when the list is empty / the
// cursor is out of range.
func (m Model) selectedTask() (TaskSummary, bool) {
if m.taskListIndex < 0 || m.taskListIndex >= len(m.taskList) {
f := m.filteredTasks()
if m.taskListIndex < 0 || m.taskListIndex >= len(f) {
return TaskSummary{}, false
}
return m.taskList[m.taskListIndex], true
return f[m.taskListIndex], true
}
// handleTasksKey owns every key while the board is open. In list mode: navigate, r
@@ -136,15 +155,36 @@ func (m Model) handleTasksKey(k keyMsg) (tea.Model, tea.Cmd) {
}
return m, nil
}
// While editing the `/` filter, keys feed the query (esc/enter stop editing, keeping it).
if m.taskFilterTyping {
switch {
case k.Type == keyEnter || k.Type == keyEsc:
m.taskFilterTyping = false
case k.Type == keyBackspace:
if n := len(m.taskFilter); n > 0 {
m.taskFilter = m.taskFilter[:n-1]
m.taskListIndex = 0
}
case k.Type == keyRunes || k.Type == keySpace:
m.taskFilter += string(k.Runes)
m.taskListIndex = 0
}
return m, nil
}
switch {
case k.Type == keyEsc || runeIs(k, "T"):
m.overlay = OverlayNone
case runeIs(k, "/"):
m.taskFilterTyping = true
case runeIs(k, "c"):
m.taskFilter = ""
m.taskListIndex = 0
case k.Type == keyUp || runeIs(k, "k"):
if m.taskListIndex > 0 {
m.taskListIndex--
}
case k.Type == keyDown || runeIs(k, "j"):
if m.taskListIndex < len(m.taskList)-1 {
if m.taskListIndex < len(m.filteredTasks())-1 {
m.taskListIndex++
}
case runeIs(k, "r"):
@@ -195,11 +235,12 @@ func (m Model) tasksModal() string {
}
t := m.theme
w := m.modalWidth()
tasks := m.filteredTasks()
var b strings.Builder
b.WriteString(m.titleLine("tasks"))
if len(m.taskList) > 0 {
b.WriteString(mbg(t, " ("+itoa(m.taskListIndex+1)+"/"+itoa(len(m.taskList))+")", t.P.Faint))
if len(tasks) > 0 {
b.WriteString(mbg(t, " ("+itoa(m.taskListIndex+1)+"/"+itoa(len(tasks))+")", t.P.Faint))
}
b.WriteString("\n\n")
@@ -213,9 +254,19 @@ func (m Model) tasksModal() string {
b.WriteString("\n" + modalHints(t, [][2]string{{"T/esc", "close"}}))
return t.Overlay.Width(w).Render(b.String())
}
if len(m.taskList) == 0 {
b.WriteString(mbg(t, " no tasks", t.P.Faint) + "\n")
b.WriteString("\n" + modalHints(t, [][2]string{{"r", "refresh"}, {"T/esc", "close"}}))
// Filter prompt: shown while editing the `/` query or whenever one is set.
if m.taskFilterTyping || m.taskFilter != "" {
b.WriteString(m.taskFilterLine() + "\n\n")
}
if len(tasks) == 0 {
msg := " no tasks"
if m.taskFilter != "" {
msg = " no tasks match \"" + m.taskFilter + "\""
}
b.WriteString(mbg(t, msg, t.P.Faint) + "\n")
b.WriteString("\n" + modalHints(t, m.taskListHints()))
return t.Overlay.Width(w).Render(b.String())
}
@@ -225,33 +276,50 @@ func (m Model) tasksModal() string {
bodyH = 4
}
off := 0
if len(m.taskList) > bodyH {
if len(tasks) > bodyH {
off = m.taskListIndex - bodyH/2
if off < 0 {
off = 0
}
if off > len(m.taskList)-bodyH {
off = len(m.taskList) - bodyH
if off > len(tasks)-bodyH {
off = len(tasks) - bodyH
}
}
end := off + bodyH
if end > len(m.taskList) {
end = len(m.taskList)
if end > len(tasks) {
end = len(tasks)
}
for i := off; i < end; i++ {
b.WriteString(m.taskListRow(i) + "\n")
b.WriteString(m.taskListRow(tasks, i) + "\n")
}
b.WriteString("\n" + modalHints(t, [][2]string{
{"↑↓", "select"}, {"enter", "detail"}, {"r", "refresh"}, {"T/esc", "close"},
}))
b.WriteString("\n" + modalHints(t, m.taskListHints()))
return t.Overlay.Width(w).Render(b.String())
}
// taskListRow renders one board line: marker, id, status, title, and claimant.
func (m Model) taskListRow(i int) string {
// taskListHints is the list-mode footer (shared by the populated and empty-filter views).
func (m Model) taskListHints() [][2]string {
return [][2]string{{"↑↓", "select"}, {"enter", "detail"}, {"/", "filter"}, {"r", "refresh"}, {"T/esc", "close"}}
}
// taskFilterLine renders the `/` filter prompt over the current query, with a caret while editing.
func (m Model) taskFilterLine() string {
t := m.theme
tk := m.taskList[i]
prompt := lipgloss.NewStyle().Foreground(t.P.Accent).Background(t.P.BgPanel).Render("/ ")
caret := mbg(t, "", t.P.BgPanel)
if m.taskFilterTyping && m.caretVisible() {
caret = lipgloss.NewStyle().Foreground(t.P.Accent).Background(t.P.BgPanel).Render("▏")
}
if m.taskFilter == "" {
return prompt + caret + mbg(t, "type to filter tasks…", t.P.Faint)
}
return prompt + mbg(t, m.taskFilter, t.P.FgStrong) + caret
}
// taskListRow renders one board line: marker, id, status, title, and claimant.
func (m Model) taskListRow(tasks []TaskSummary, i int) string {
t := m.theme
tk := tasks[i]
marker := mbg(t, " ", t.P.BgPanel)
idFg := t.P.Fg