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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ SCREEN_ENABLED=false

# The chat project or folder each task is filed under (the chats panel's Tasks face).
# TASK_FOLDERS_FILE=data/task-folders.json
# Shared sheet rows the owner marked done or snoozed in Totem (never written to the sheet).
# SHEET_MARKS_FILE=data/sheet-marks.json

# --- Source health (docs/source-health.md): the run log every connector writes ---
# SOURCE_RUNS_DB=data/source-runs.db
Expand Down
4 changes: 2 additions & 2 deletions AGENTS.md

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion bridge.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import { fetchFavicon } from './chat/favicon.mjs'
import { createConnectionIconStore, validConnectionId } from './connections/icons.mjs'
import { createProjectStore, moveMemoryEntries, validProjectId } from './chat/projects.mjs'
import { createTaskFolderStore } from './chat/task-folders.mjs'
import { createSheetMarkStore } from './todos/sheet-marks.mjs'
import { fileSheetItems as fileSheetFolders, folderAdoption, folderPath, resolveFolder, SHEET_UNFILED } from './todos/folders.mjs'
import { linkedTaskBlock, findSheetItem } from './chat/task-link.mjs'
import { createChatRuns } from './chat/runs.mjs'
Expand Down Expand Up @@ -17117,7 +17118,19 @@ const todoCommands = createTodoCommands({
// keeps it out of Settings -> Connections.
sourceRuns.forget('github-tasks')
const todoIssueStates = createIssueStates({ links: (o) => todoService.issueLinks(o), run: ghCapture })
todoHttpHandler = createTodoHttpHandler({ service: todoService, commands: todoCommands, sheetFeed: taskSheetFeed, issueStates: todoIssueStates, sheetFolders: fileSheetItems })
// The owner's own done and snoozed marks on sheet rows: kept here, never written
// to the sheet (todos/sheet-marks.mjs).
const sheetMarks = createSheetMarkStore({ file: process.env.SHEET_MARKS_FILE || join(HERE, 'data', 'sheet-marks.json') })
todoHttpHandler = createTodoHttpHandler({ service: todoService, commands: todoCommands, sheetFeed: taskSheetFeed, issueStates: todoIssueStates, sheetFolders: fileSheetItems, sheetMarks,
onSheetMark: ({ ref, state, until, title }) => actionLog.record({
action: state ? `sheet.${state}` : 'sheet.unmark',
actor: 'http',
channel: 'http',
target: ref,
status: 'ok',
summary: `${state === 'done' ? 'Marked done in Totem' : state === 'snoozed' ? `Snoozed until ${until}` : 'Back in the list'}: ${title || ref} (the sheet is unchanged)`,
}),
})
todoMcpTools = createTodoMcpTools({ service: todoService, commands: todoCommands, folders: taskFolderContext })
adoptTaskFolders().catch((e) => log(`task folders: the move from areas to folders failed (${e.message}); it runs again at the next start`))

Expand Down
33 changes: 32 additions & 1 deletion docs/task-sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,43 @@ that is set up with nothing assigned says so once at the foot of the list; one t
up adds nothing to the list, and Filter › Show lists it greyed as not set up. The feed is not
ETag-cached, so offline the app keeps the rows it last read in memory.

## Done and snooze, for you only

A row you have finished, or want out of sight for a while, can leave your list without the
sheet changing: nobody else sees anything. The mark is kept in Totem
(`data/sheet-marks.json`, `SHEET_MARKS_FILE`; `todos/sheet-marks.mjs`):

- **Done for you** hides the row until you put it back, or until the row leaves the feed
(marked Done in the sheet, given to someone else, deleted), when the mark goes with it.
- **Snoozed** hides it until the time you picked (the same presets as a task's snooze, at
most a year out), then it comes back on its own and the mark is dropped.

`POST /api/todos/sheet/mark` with `{ "id": "<row id>", "state": "done" | "snoozed" | null,
"until": "<ISO time, for a snooze>" }` answers the feed as `GET` does. The row must be open
for you on the current read (`404 SHEET_ROW_NOT_FOUND` otherwise); `null` takes a mark off.
Each change is one action-log line (`sheet.done`, `sheet.snoozed`, `sheet.unmark`). Like the
task routes, it takes the bearer as well as a session: an agent holding `BRIDGE_SECRET` could
hide a row from the owner's list, as it could finish a task, but never change the sheet.

In `GET /api/todos/sheet`, a marked row moves from `items` to `hidden`, carrying its `mark`
(`{ state, at, until? }`); every list draws `items`, so a client that predates marks simply
stops showing marked rows. A mark follows its row when a row above it is inserted or deleted
(it finds the row again by tab and title and is re-keyed, but only if the row still has the
due date and Who it had when marked, so a new row that reuses a title, a weekly "Send the
update", is not hidden by last week's mark); a done row re-dated or reassigned in place loses its
mark the same way and comes back; with two rows of the same title it applies only to the exact id. Marks of rows gone from a good read are dropped; a stale or
failed read keeps them all. A chat linked to a marked row still gets its `LINKED TASK` block.

Where: the web's Tasks page (the row's mark, `x`, `s`, the pane; the Snoozed and Completed
folds hold marked rows), the chats panel's Tasks face and its task card (check, Snooze,
"Mark done for me" in the row menu), and the iPhone app's Tasks list and row page.

## What "read-only" covers

**The task feed never writes to the sheet.** It is handed only Drive's read calls (`sheetInfo`,
`sheetRead`; see `taskSheetFeed` in `bridge.mjs`), and only a GET reaches it. Tests check that
every request it makes to Google is a GET to the Sheets API. Nothing in the task list (completing,
snoozing, editing, sharing) changes a sheet row.
snoozing, editing, sharing) changes a sheet row: done and snooze on a row are kept in Totem (above).

**The Drive tools are a separate feature and can still edit the sheet.** An agent asked to add a
note to a row, or to fill in a cell, does it with the `drive__sheet_*` tools (`docs/drive.md`), as
Expand Down
15 changes: 10 additions & 5 deletions docs/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ mirrored byte for byte to `mobile/src/lib/todos/`.
buttons appear on hover and on keyboard focus. At phone width the marks drop under the
title, as the app draws them.
- **Sheet rows** (the read-only task sheet, `docs/task-sheet.md`) sit in the same groups,
with the sheet's mark (its name, the feed's `title` or "Task sheet", is the mark's
tooltip), no check circle, and an open-in-sheet button. Their flag keeps the
with the sheet's mark where a task has its check circle (its name, the feed's `title`
or "Task sheet", is in the mark's tooltip), and snooze and open-in-sheet buttons. The
mark turns into a check on hover: pressing it, `x` or Space marks the row done **for the
owner only**, and `s` snoozes it; both are kept in Totem and never written to the sheet
(`docs/task-sheet.md` → Done and snooze, for you only). A snoozed row waits in the
Snoozed fold and a done one in Completed, where its check puts it back. Their flag keeps the
sheet's word and takes the colour of what it means beside a task's: one mapping,
`sheetAsTaskPriority` in `board.ts`, ranks, filters and colours them on the web and
in the app: High as P2 (amber), Medium as P3 (blue), Low in the P3 band but muted. Their "In Progress" shows only
Expand Down Expand Up @@ -84,7 +88,8 @@ mirrored byte for byte to `mobile/src/lib/todos/`.
chats linked to the task with New chat, related tasks, and Chat about this. Esc in the title
or description puts the saved text back and saves nothing. A refused change puts back
only the fields it touched, names them in the toast, and never draws over a later edit. A sheet row opens
read-only with Open in sheet, except its Folder, which files it (`PUT /api/chat/task-folders/<row id>`). With nothing selected the pane is today's summary and the
read-only with Open in sheet, except its Folder, which files it (`PUT /api/chat/task-folders/<row id>`), and its
check and Snooze, which are the owner's own (`POST /api/todos/sheet/mark`). With nothing selected the pane is today's summary and the
keys. Below ~1100 px the pane slides over the list; at phone width it fills the screen.
- **Archive and recycle bin** open in the pane from the "…" menu and are read only then;
a task opened from either is shown read-only there, with Unarchive or Restore;
Expand Down Expand Up @@ -113,8 +118,8 @@ The list is one tab stop (a roving focus over its rows).
| Key | Does |
|---|---|
| `j` / `k`, ↓ / ↑, Home / End | Move between rows (the pane follows when open) |
| `x`, Space | Complete or reopen (select mode: select) |
| `s` / `d` / `p` | Snooze / due date / priority menu |
| `x`, Space | Complete or reopen (select mode: select); on a sheet row, done for you or back |
| `s` / `d` / `p` | Snooze / due date / priority menu (a sheet row: snooze only) |
| `n` | The quick-add line (New task), from anywhere on the page |
| `m` | Open the row with the note composer focused |
| `g t t` | The quick-add line, from anywhere in the dashboard |
Expand Down
67 changes: 50 additions & 17 deletions mobile/src/features/productivity/TodosView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
// then manual position), and Completed is one folded row (features/todos/list.ts). A
// status line says what is left today, what is done today, and how many are snoozed.
// Ticking, snoozing, "not doing" and deleting offer Undo in one inline line at the
// foot of the page, never a toast: the phone shows error toasts only. The task
// detail, a sheet row's read-only detail, the composer and the lifecycle panels are
// foot of the page, never a toast: the phone shows error toasts only. A sheet row
// can be done or snoozed for the owner only (kept in Totem, the sheet unchanged):
// a done one sits in Completed, a snoozed one in the Snoozed panel. The task
// detail, a sheet row's detail, the composer and the lifecycle panels are
// sheets (src/app/todo/*); the top bar carries the title.
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { RefreshControl, StyleSheet, View } from 'react-native'
Expand All @@ -23,11 +25,12 @@ import { impact } from '../../ui/haptics'
import { Hi, PlusIcon } from '../../lib/icons'
import { bulkBoardTodos } from '../../lib/api'
import { filterTodos } from '../../lib/todos/state'
import type { Todo } from '../../lib/todos/types'
import type { SheetItem, Todo } from '../../lib/todos/types'
import { sheetDone, sheetDoneToday, sheetMarkOf, sheetSnoozed } from '../../lib/todos/board.ts'
import { loadProjects } from '../../lib/chat/store'
import { FAB_CLEARANCE } from '../../shell/Screen'
import TodoCard from '../todos/TodoCard'
import SheetCard from '../todos/SheetCard'
import SheetCard, { type SheetMarkChange } from '../todos/SheetCard'
import TodoToolbar, { type LifecyclePanel } from '../todos/TodoToolbar'
import { boardActions } from '../todos/boardActions'
import { afterDone, buildList, byWake, doneToday, nextWake, wakeLabel } from '../todos/board'
Expand All @@ -40,7 +43,7 @@ import { useFolders } from '../todos/useFolders'
import { quote, undoText, type UndoKind } from '../todos/undo'
import { ArchiveLink, BoardSkeleton, ClearNote, EmptyBoard, LoadError, SectionHeader, SheetLine, ShowMore, StatusLine } from '../todos/BoardParts'
import { UndoLine, type UndoState } from '../todos/detail/bits'
import { clearCreated, getBoard, loadBoard, loadIssueStates, loadSheet, setTodos, useBoard } from '../todos/store'
import { clearCreated, getBoard, loadBoard, loadIssueStates, loadSheet, markSheet, setTodos, useBoard } from '../todos/store'
import { openTodo } from '../todos/nav'
import { dateLabel } from '../todos/format'
import { LandFlash, useLandOn } from '../../ui/landing'
Expand Down Expand Up @@ -108,8 +111,9 @@ export default function TodosView({ active }: { active: boolean }) {
const timer = setInterval(() => {
const at = new Date()
setNow(at)
// A snooze that ran out while the page was open: the bridge lists that task on the board again.
// A snooze that ran out while the page was open: the bridge lists that task (or sheet row) again.
if (getBoard().snoozed.some((todo) => todo.snoozedUntil && new Date(todo.snoozedUntil) <= at)) void loadBoard()
if ((getBoard().sheet?.hidden ?? []).some((item) => item.mark.until && new Date(item.mark.until) <= at)) void loadSheet()
}, 60_000)
return () => clearInterval(timer)
}, [active])
Expand All @@ -130,6 +134,9 @@ export default function TodosView({ active }: { active: boolean }) {
return tasks ? scopedTodos(filterTodos(board.todos, tasks, now), shown, projects) : []
}, [board.todos, shown, now, projects])
const visibleRows = useMemo(() => visibleSheet(sheetItems, shown, now, projects), [sheetItems, shown, now, projects])
// Rows marked done for the owner follow the same scope and search, in Completed.
const visibleDone = useMemo(() => visibleSheet(sheetDone(sheet), { ...shown, due: undefined }, now, projects), [sheet, shown, now, projects])
const asleepRows = useMemo(() => sheetSnoozed(sheet, now), [sheet, now])
// The chips count what is open, whatever else is filtered.
const scopes = useMemo(() => {
const open = buildList(board.todos, sheetItems, { now }).sections.flatMap((section) => section.items)
Expand All @@ -140,12 +147,15 @@ export default function TodosView({ active }: { active: boolean }) {
return label === null ? null : { label, project: folderFor(folderId, projects) }
}, [projects, scope])
const rows = useMemo(() => listRows(visible, visibleRows, {
now, completedOpen: view.completedOpen, showAllDone, archiveCount: board.archiveCount, filtered: filtering,
}), [visible, visibleRows, now, view.completedOpen, showAllDone, board.archiveCount, filtering])
now, completedOpen: view.completedOpen, showAllDone, archiveCount: board.archiveCount, filtered: filtering, sheetDone: visibleDone,
}), [visible, visibleRows, visibleDone, now, view.completedOpen, showAllDone, board.archiveCount, filtering])
const near = useMemo(() => orderNeighbours(rows), [rows])
const finishedToday = useMemo(() => doneToday(board.todos, now) + doneToday(board.archivedCompletions, now), [board.todos, board.archivedCompletions, now])
// Sheet rows marked done today count too, as on the web.
const finishedToday = useMemo(() => doneToday(board.todos, now) + doneToday(board.archivedCompletions, now) + sheetDoneToday(board.sheet, now), [board.todos, board.archivedCompletions, board.sheet, now])
const left = useMemo(() => leftToday(board.todos, sheetItems, now), [board.todos, sheetItems, now])
const wakeAt = useMemo(() => nextWake(board.snoozed, now), [board.snoozed, now])
// Snoozed tasks and snoozed sheet rows, as one count and one "next back".
const snoozedCount = board.snoozed.length + asleepRows.length
const wakeAt = useMemo(() => nextWake([...board.snoozed, ...asleepRows.map((item) => ({ snoozedUntil: item.mark.until ?? null }))], now), [board.snoozed, asleepRows, now])
const wakeText = wakeAt ? wakeLabel(wakeAt, now) : null
const note = sheetNote(sheet, board.sheetError)

Expand Down Expand Up @@ -225,6 +235,23 @@ export default function TodosView({ active }: { active: boolean }) {
offer('delete', todo, () => actions.restore(todo))
}

// A sheet row, done or snoozed for the owner only; Undo puts its mark back as it was.
async function markRow(item: SheetItem, next: SheetMarkChange, until?: Date) {
const prior = sheetMarkOf((getBoard().sheet?.hidden ?? []).find((row) => row.id === item.id), new Date())
setMoveError('')
try {
await markSheet(item.id, next, until ?? null)
} catch (cause) {
setMoveError(cause instanceof Error && cause.message ? cause.message : next ? 'The row could not be marked.' : 'The row could not be put back.')
return
}
if (!next) return
const text = next === 'done'
? `Done for you: ${quote(item.title)}. ${source} is unchanged.`
: `Snoozed ${quote(item.title)} until ${until ? wakeLabel(until, new Date()) : 'later'}.`
setUndo({ id: Date.now(), text, action: { label: 'Undo', run: () => { impact(); void markSheet(item.id, prior?.state ?? null, prior?.until ? new Date(prior.until) : null).catch(() => {}) } } })
}

async function bulk(operation: string, value?: unknown) {
if (!selection.size) return
const chosen = getBoard().todos.filter((todo) => selection.has(todo.id))
Expand Down Expand Up @@ -261,14 +288,14 @@ export default function TodosView({ active }: { active: boolean }) {
const fabBottom = Math.max(insets.bottom, 14) + 8 + 5
const error = board.error
const todos = board.todos
const snoozedNote = board.snoozed.length
? `${board.snoozed.length.toLocaleString()} snoozed${wakeText ? `, the next back ${wakeText}` : ''}.`
const snoozedNote = snoozedCount
? `${snoozedCount.toLocaleString()} snoozed${wakeText ? `, the next back ${wakeText}` : ''}.`
: null
const upcoming = useMemo(() => {
const ahead = byWake(board.snoozed)[0]
const ahead = byWake([...board.snoozed, ...asleepRows.map((item) => ({ id: item.id, title: item.title, snoozedUntil: item.mark.until ?? null }))])[0]
if (!ahead) return null
return `Next back: ${quote(ahead.title)}${wakeText ? `, ${wakeText}` : ''}.`
}, [board.snoozed, wakeText])
}, [board.snoozed, asleepRows, wakeText])

// The first date ahead, for "nothing due today"; the tasks themselves are the cards under the line.
const nextUp = useMemo(() => {
Expand All @@ -286,7 +313,13 @@ export default function TodosView({ active }: { active: boolean }) {
if (row.kind === 'sheet') {
// A sheet row names its folder only when filed in a project: Personal on every row would be noise beside the sheet's name.
const folder = folderOf(row.item.folderId)
return <SheetCard item={row.item} source={source} now={now} dueSection={row.section} dim={bulkMode} folder={folder?.project ? { label: folder.label, project: folder.project } : null} />
return (
<SheetCard
item={row.item} source={source} now={now} dueSection={row.section === 'done' ? undefined : row.section} dim={bulkMode}
folder={folder?.project ? { label: folder.label, project: folder.project } : null}
onMark={(item, next, until) => markRow(item, next, until)} swipeable={!bulkMode}
/>
)
}
const todo = row.todo
const pair = row.section !== 'done' ? near.get(todo.id) : undefined
Expand Down Expand Up @@ -343,7 +376,7 @@ export default function TodosView({ active }: { active: boolean }) {
ItemSeparatorComponent={() => <View style={{ height: 6 }} />}
ListHeaderComponent={(
<>
<StatusLine ready={board.loaded} leftToday={left} doneToday={finishedToday} snoozed={board.snoozed.length} nextWake={wakeText} onSnoozed={() => openPanel('snoozed')} />
<StatusLine ready={board.loaded} leftToday={left} doneToday={finishedToday} snoozed={snoozedCount} nextWake={wakeText} onSnoozed={() => openPanel('snoozed')} />
{note?.tone === 'problem' ? <SheetLine tone="problem" text={note.text} onRetry={() => void loadSheet({ refresh: true })} /> : null}
</>
)}
Expand All @@ -365,7 +398,7 @@ export default function TodosView({ active }: { active: boolean }) {
<View style={st.view}>
<TodoToolbar
query={shown} scopes={scopes} bulkMode={bulkMode} selectedCount={selection.size}
lifecycle={{ snoozed: board.snoozed.length, nextWake: wakeText, deleted: board.deleted.length, archived: board.archiveCount }}
lifecycle={{ snoozed: snoozedCount, nextWake: wakeText, deleted: board.deleted.length, archived: board.archiveCount }}
onQuery={setQuery}
onBulkMode={(value) => { setBulkMode(value); if (!value) setSelection(new Set()) }}
onBulk={(operation, value) => void bulk(operation, value)}
Expand Down
Loading
Loading