Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/chat.md
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,16 @@ moves between a task and any of its chats (`web/src/work/`).
from `GET /api/todos/sheet` already filed: its own filing, else the sheet's default
folder (`docs/task-sheet.md`). Deleting a folder moves its tasks up to its project,
deleting a project makes them Personal, as with its chats.
- **Adding.** The "Add a task…" line at the top ends in a folder button: any project or

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update AGENTS.md with the new add-task behavior

This documents and implements a new Tasks-panel feature, but the Tasks panel entry in the repository operating manual still omits the selectable and remembered quick-add folder behavior. Update that entry in the same change so the repository map remains accurate as explicitly required.

AGENTS.md reference: AGENTS.md:L10-L12

Useful? React with 👍 / 👎.

folder (a new one can be typed into the picker), or Personal, whether or not it has open
tasks and so a group of its own. The line remembers the last one chosen on this device
(`totem.work.addFolder`; a folder deleted since reads as Personal). A group's + opens the
same line starting on that group's folder, without changing the remembered one.
`tomorrow` and `p1` in the title show as chips under the line, with × to keep the word
as text (the Tasks page's parser, `web/src/todos/parse.ts`). A typed `#folder` shows on
the button instead, tinted, and wins for that task; choosing on the button after typing
it keeps the word as text (`web/src/work/AddTask.tsx`). A new task's folder group
unfolds, and a toast says so only when the filter hides the task.
- **The task card** (`web/src/work/TaskCard.tsx`, `card.ts`), T3 Code's thread card for a
task: the check circle and title, then one row per setting with a dropdown (Folder, Due,
Priority, Repeat, Snooze), the description, the chats working on it with New chat, Open
Expand Down
180 changes: 180 additions & 0 deletions web/src/work/AddTask.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
import React, { useLayoutEffect, useMemo, useRef, useState } from 'react'
import { useChat } from '../chat/store'
import { TI } from '../chat/ui'
import { IconCalendar, IconChevronDown, IconFlag, IconPlus, IconX } from '../chat/icons'
import { dueText } from '../todos/format'
import { folderFor, folderLabel, folderNames, PERSONAL } from '../todos/folders'
import { hintKey, parseQuickAdd, type Hint } from '../todos/parse'
import { priorityLabel } from '../todos/types'
import { FolderIcon } from './FolderField'
import { FolderPicker } from './pickers'
import type { WorkTask } from './groups'
import { createTask } from './state'

// The chats panel's "Add a task…" line. The folder button at its end is where the
// task goes: any chat project or folder, a new one typed into the picker, or
// Personal, whether or not that folder has open tasks (and so a group) to add from.
// A "#folder" typed in the title is shown on the button (tinted) and wins for that
// task, unless the button is used after it, which keeps the word as text; "tomorrow"
// and "p1" show as chips under the line, each with × to keep the word as text, as on
// the Tasks page.

interface Props {
/** The folder the button starts on: the one last used (the top line) or the group's. */
folderId: string | null
/** The button was used: the top line remembers it for the next task. */
onFolder?: (folderId: string | null) => void
placeholder?: string
autoFocus?: boolean
/** The task was added (with where it went). */
onAdded?: (task: WorkTask) => void
/** Escape, or focus left an empty line: the group's line closes. */
onDone?: () => void
}

function chipText(hint: Hint, now: Date) {
if (hint.kind === 'due' && hint.dueDate) return dueText(hint.dueDate, now)
if (hint.kind === 'priority' && hint.priority) return priorityLabel(hint.priority)
return hint.text
}

export default function AddTask({ folderId: start, onFolder, placeholder = 'Add a task…', autoFocus = false, onAdded, onDone }: Props) {
const projects = useChat((s) => s.projects)
const names = useMemo(() => folderNames(projects), [projects])
const [text, setText] = useState('')
const [ignore, setIgnore] = useState<string[]>([])
const [saving, setSaving] = useState(false)
const [picking, setPicking] = useState(false)
// The button's folder. A #folder typed in the title wins over it, unless the button is used after.
const [chosen, setChosen] = useState<string | null>(start)
const input = useRef<HTMLTextAreaElement>(null)
const button = useRef<HTMLButtonElement>(null)
const line = useRef<HTMLDivElement>(null)
const current = useRef(text)
current.current = text

const now = new Date()
const parsed = parseQuickAdd(text, { now, folders: names, ignore })
// A folder deleted since it was chosen reads as Personal.
const base = folderFor(chosen, projects)?.id ?? null
const folderId = parsed.folderId ?? base
const typed = !!parsed.folderId && parsed.folderId !== base

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Show recognition when the typed folder matches the selected folder

When the remembered/selected folder is already Acme and the owner types Call #acme, parsed.folderId === base makes typed false. The parser still strips #acme from the saved title, but the folder chip is filtered out and the button is not tinted or labelled “from the title,” so the owner receives no indication that visible text will be removed. Treat any parsed folder hint as typed, even when it resolves to the current folder.

Useful? React with 👍 / 👎.

const project = folderFor(folderId, projects)
// A #folder shows on the button rather than as a chip; choosing on the button keeps the word as text.
const chips = parsed.hints.filter((hint) => hint.kind !== 'folder')
// Grows with a long title (field-sizing is Chromium-only; the desktop app is WebKit). CSS caps it at five lines.
// Measured again when the folder button's width changes too.
useLayoutEffect(() => {
const el = input.current
if (!el) return
el.style.height = 'auto'
el.style.height = `${el.scrollHeight}px`
}, [text, folderId, projects])

async function add() {
const title = parsed.title.trim()
if (saving) return
if (!title) { if (!text.trim()) onDone?.(); return }
setSaving(true)
const submitted = text
const task = await createTask({ title, dueDate: parsed.dueDate, priority: parsed.priority }, folderId)
setSaving(false)
if (!task) return
// Words typed while the bridge answered are the next task's.
setText(current.current.startsWith(submitted) ? current.current.slice(submitted.length).trimStart() : current.current)
setIgnore([])
onAdded?.(task)
input.current?.focus()
}

return (
<div
ref={line} className="wk-add"
onMouseDown={(e) => {
// Only the line's own blank space; the picker's events bubble here through its portal.
if (!line.current?.contains(e.target as Node) || (e.target as HTMLElement).closest('button, textarea')) return
e.preventDefault()
input.current?.focus()
}}
onBlur={(e) => {
// Focus moving to the folder button, its picker or a chip keeps the group's line open.
if (picking || (e.relatedTarget && line.current?.contains(e.relatedTarget as Node))) return
if (!current.current.trim()) onDone?.()
}}
>
<div className="wk-add-line">
<TI icon={IconPlus} size={15} className="wk-add-plus" />
{/* A textarea so a long title wraps in the narrow panel rather than scrolling out of sight. */}
<textarea
ref={input} value={text} placeholder={placeholder} aria-label={placeholder} autoFocus={autoFocus} maxLength={500} rows={1}
aria-busy={saving || undefined}
onChange={(e) => {
const next = e.target.value.replace(/\s*\n\s*/g, ' ')
setText(next)
// A word deleted from the title is read afresh if typed again.
const words = next.toLowerCase().replace(/\s+/g, ' ')
setIgnore((cur) => (cur.every((key) => words.includes(key)) ? cur : cur.filter((key) => words.includes(key))))
}}
onKeyDown={(e) => {
if (e.key === 'Enter' && !e.nativeEvent.isComposing) { e.preventDefault(); void add() }
if (e.key === 'Escape') { e.preventDefault(); setText(''); setIgnore([]); onDone?.() }
}}
/>
<button
ref={button} type="button" className={`wk-add-folder ${project ? '' : 'personal'} ${typed ? 'typed' : ''}`.trim()}
aria-haspopup="dialog" aria-expanded={picking}
aria-label={`Folder: ${folderLabel(folderId, projects)}${typed ? ', from the title' : ''}. Change`}
title={typed ? `${folderLabel(folderId, projects)}, from the title. Choose another` : `Goes in ${folderLabel(folderId, projects)}. Choose another`}
onMouseDown={(e) => e.preventDefault()}
onClick={() => setPicking((v) => !v)}
>
<FolderIcon project={project} size={13} />
<span className="wk-add-folder-name">{project?.name || PERSONAL}</span>
<TI icon={IconChevronDown} size={12} className="wk-add-folder-chev" />
</button>
</div>
{chips.length > 0 && (
<div className="wk-add-chips" aria-label="Recognised in the title">
{chips.map((hint) => (
<span key={`${hint.kind}-${hint.start}`} className={`tk-chip tk-chip-${hint.kind}`}>
<TI icon={hint.kind === 'due' ? IconCalendar : IconFlag} size={12} />
{chipText(hint, now)}
<button
type="button" aria-label={`Keep “${hint.text}” as text`}
onMouseDown={(e) => e.preventDefault()}
onClick={() => setIgnore((cur) => [...cur, hintKey(hint)])}
><TI icon={IconX} size={11} /></button>
</span>
))}
</div>
)}
{picking && (
<FolderPicker
open anchor={button} align="end"
onClose={() => {
setPicking(false)
// Back to the line, unless the click that closed it went to another field.
requestAnimationFrame(() => {
const at = document.activeElement
if (!at || at === document.body) input.current?.focus()
})
Comment on lines +157 to +160

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Wait for a newly created folder before refocusing the task

When the owner creates a new folder from this picker, FolderPicker.make waits for createProject before calling onPick, but ComboPicker.choose closes the picker immediately without awaiting that action. This callback then refocuses the task field while its chosen value is still the previous folder, so pressing Enter promptly after creating the folder submits the task to the old folder; only later does the new folder become selected. Keep the add line pending until folder creation and onPick finish, or otherwise prevent submission during that interval.

Useful? React with 👍 / 👎.

}}
value={folderId} noneLabel={PERSONAL} noneIcon="person" label="Add the task to"
onPick={(id) => {
setChosen(id)
// Chosen over any #folder already typed: those words stay in the title as text.
const keys = [...ignore]
for (let i = 0; i < 20; i++) {
const hint = parseQuickAdd(text, { now: new Date(), folders: names, ignore: keys, kinds: ['folder'] }).hints[0]
if (!hint) break
keys.push(hintKey(hint))
}
setIgnore(keys)
onFolder?.(id)
input.current?.focus()
}}
/>
)}
</div>
)
}
112 changes: 111 additions & 1 deletion web/src/work/TaskCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import TaskCardHost, { PinnedTask } from './TaskCard'
import TaskBar from './TaskBar'
import TasksPanel from './TasksPanel'
import { closeTaskCard, installTaskNav, openTaskCard } from './card'
import { createTask } from './state'
import { createTask, loadWork } from './state'
import { loadProjects } from '../chat/store'

const NOW = new Date(2026, 10, 9, 10, 0, 0)

Expand Down Expand Up @@ -284,3 +285,112 @@ describe('the chats panel’s task rows', () => {
expect(screen.queryByRole('button', { name: /Snooze “Order banner stands”/ })).toBeNull()
})
})

describe('the chats panel’s add line', () => {
async function mountPanel() {
const user = userEvent.setup()
await act(async () => { await loadProjects(); await loadWork() })
render(<><TasksPanel onOpenChat={() => {}} /><ToastHost /></>)
await screen.findByRole('button', { name: 'Snooze “Call the bank”' })
return user
}
const addLine = () => screen.getByRole('textbox', { name: 'Add a task…' })
const folderButton = () => screen.getByRole('button', { name: /^Folder: / })

it('files a new task in any folder, even one with no tasks (and so no group) yet, and keeps it for the next', async () => {
const user = await mountPanel()
expect(folderButton()).toHaveAccessibleName('Folder: Personal. Change')
// Home reno has no open task, so it has no group and no + to add from.
expect(screen.queryByRole('button', { name: 'Add a task to Home reno' })).toBeNull()
await user.click(folderButton())
await user.click(await screen.findByRole('option', { name: /Home reno/ }))
expect(folderButton()).toHaveAccessibleName('Folder: Home reno. Change')
expect(addLine()).toHaveFocus()
await user.type(addLine(), 'Measure the hall tomorrow{Enter}')
await waitFor(() => expect(sent('POST', /\/api\/todos\/board$/)[0]?.body).toEqual({ title: 'Measure the hall', dueDate: '2026-11-10', folderId: 'home' }))
expect(await screen.findByRole('button', { name: 'Add a task to Home reno' })).toBeVisible()
expect(addLine()).toHaveValue('')
expect(addLine()).toHaveFocus()
// The next task goes there too, and so does the next visit.
await user.type(addLine(), 'Buy paint{Enter}')
await waitFor(() => expect(sent('POST', /\/api\/todos\/board$/)[1]?.body).toEqual({ title: 'Buy paint', folderId: 'home' }))
cleanup()
await mountPanel()
expect(folderButton()).toHaveAccessibleName('Folder: Home reno. Change')
})

it('a #folder typed in the title wins for that task, until the button is used again', async () => {
const user = await mountPanel()
await user.type(addLine(), 'Send the invoice #acme')
expect(folderButton()).toHaveAccessibleName('Folder: Acme, from the title. Change')
// The button says it, so no chip repeats it.
expect(screen.queryByLabelText('Recognised in the title')).toBeNull()
await user.click(folderButton())
await user.click(await screen.findByRole('option', { name: /Home reno/ }))
expect(folderButton()).toHaveAccessibleName('Folder: Home reno. Change')
await user.keyboard('{Enter}')
await waitFor(() => expect(sent('POST', /\/api\/todos\/board$/)[0]?.body).toEqual({ title: 'Send the invoice #acme', folderId: 'home' }))
// After that task, a #folder decides again.
await user.type(addLine(), 'Chase the deposit #acme p1{Enter}')
await waitFor(() => expect(sent('POST', /\/api\/todos\/board$/)[1]?.body).toEqual({ title: 'Chase the deposit', priority: 4, folderId: 'acme' }))
expect(folderButton()).toHaveAccessibleName('Folder: Home reno. Change')
})

it('a #folder typed after the button was used still wins, and a filter the new task matches says nothing', async () => {
const user = await mountPanel()
await user.click(folderButton())
await user.click(await screen.findByRole('option', { name: /Home reno/ }))
await user.type(screen.getByRole('textbox', { name: 'Filter tasks and chats' }), 'invoice')
await user.type(addLine(), 'Send the invoice #acme')
expect(folderButton()).toHaveAccessibleName('Folder: Acme, from the title. Change')
await user.keyboard('{Enter}')
await waitFor(() => expect(sent('POST', /\/api\/todos\/board$/)[0]?.body).toEqual({ title: 'Send the invoice', folderId: 'acme' }))
expect(await screen.findByText('Send the invoice')).toBeVisible()
expect(screen.queryByText(/The filter hides it/)).toBeNull()
await user.type(addLine(), 'Water the plants{Enter}')
expect(await screen.findByText(/Added “Water the plants” to Home reno\. The filter hides it\./)).toBeVisible()
})

it('the button keeps every #folder already typed as text, and a #folder deleted and typed again wins', async () => {
const user = await mountPanel()
await user.type(addLine(), 'Call #acme about #home')
await user.click(folderButton())
await user.click(await screen.findByRole('option', { name: /Personal/ }))
expect(folderButton()).toHaveAccessibleName('Folder: Personal. Change')
await user.keyboard('{Enter}')
await waitFor(() => expect(sent('POST', /\/api\/todos\/board$/)[0]?.body).toEqual({ title: 'Call #acme about #home' }))
await user.type(addLine(), 'Call #acme')
expect(folderButton()).toHaveAccessibleName('Folder: Acme, from the title. Change')
await user.clear(addLine())
await user.type(addLine(), 'Call #acme')
expect(folderButton()).toHaveAccessibleName('Folder: Acme, from the title. Change')
await user.keyboard('{Enter}')
await waitFor(() => expect(sent('POST', /\/api\/todos\/board$/)[1]?.body).toEqual({ title: 'Call', folderId: 'acme' }))
})

it('a word kept as text stays in the title, and a folder since deleted reads as Personal', async () => {
localStorage.setItem('totem.work.addFolder', JSON.stringify('gone'))
const user = await mountPanel()
expect(folderButton()).toHaveAccessibleName('Folder: Personal. Change')
await user.type(addLine(), 'Water the plants tomorrow')
await user.click(screen.getByRole('button', { name: 'Keep “tomorrow” as text' }))
await user.keyboard('{Enter}')
await waitFor(() => expect(sent('POST', /\/api\/todos\/board$/)[0]?.body).toEqual({ title: 'Water the plants tomorrow' }))
})

it('a group’s + starts on its folder, can file elsewhere, and stays open while the picker is used', async () => {
const user = await mountPanel()
await user.click(screen.getByRole('button', { name: 'Add a task to Acme' }))
const line = () => screen.getByRole('textbox', { name: 'New task…' })
expect(line()).toHaveFocus()
const buttons = screen.getAllByRole('button', { name: /^Folder: / })
expect(buttons[1]).toHaveAccessibleName('Folder: Acme. Change')
await user.click(buttons[1])
await user.click(await screen.findByRole('option', { name: /Home reno/ }))
expect(line()).toHaveFocus()
await user.type(line(), 'Order tiles{Enter}')
await waitFor(() => expect(sent('POST', /\/api\/todos\/board$/)[0]?.body).toEqual({ title: 'Order tiles', folderId: 'home' }))
// The top line's own folder is untouched.
expect(screen.getAllByRole('button', { name: /^Folder: / })[0]).toHaveAccessibleName('Folder: Personal. Change')
})
})
Loading
Loading