feat(web): the server creates the next occurrence when a recurring task is completed (#201) #213

Open
maximus wants to merge 4 commits from issue-201-recurring-completion into issue-200-agent-tokens

4 commits

Author SHA1 Message Date
le king fu
8985dcc1dc docs(review): say what no test sees of two simultaneous completions (#201)
The Sync bullet now says that POST /api/sync creates no occurrence (a
completed `task create` still adds its own row), and that the wait of a
second simultaneous request is read, not tested: PGlite has one
connection. The header of the task route test says that the WebSocket
notice is recorded.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 20:50:31 -05:00
le king fu
29d0f22c9c test(web): the Quebec cases of the parity test restore the zone they found (#201)
Their afterEach wrote `UTC` back, so they could stand in for the first
statement of the file: with that statement removed, the parity cases that
ran after them still passed (found by mutation, one red test instead of
five). The hook now restores the zone read when the file is collected.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 20:50:31 -05:00
le king fu
fa0bec2fcd docs(review): who creates the next occurrence of a recurring task (#201)
One bullet in the Sync zone, after the `task create` bullet: the app for
its own completions, completeTask for the site and the MCP tools, never
POST /api/sync; the UTC computation of the server against the local time
of the app; the contract of taskWrites.ts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 20:50:31 -05:00
le king fu
85ce337131 feat(web): the server creates the next occurrence when a recurring task is completed (#201)
Completing a recurring task on the site only set completedAt: the next
occurrence was created by the app alone. PUT /api/tasks/[id] now creates
it, through a function the MCP tools will call too.

- lib/recurrence.ts: RECURRENCES, isRecurrence and nextOccurrence, computed
  in UTC without date-fns (a day, seven days, a month or a year later at the
  same UTC time, ends of months as date-fns).
- lib/taskWrites.ts: completeTask and reopenTask. They take the transaction
  of their caller first, then userId; they open no transaction, send no
  notification and do not import the database client. completeTask moves
  the task from open to done with one UPDATE ... WHERE completed = false
  ... RETURNING, and creates the next occurrence only when that statement
  returns the row.
- PUT /api/tasks/[id]: one transaction for the whole body; `completed` goes
  through completeTask or reopenTask, the other fields are written first.
  Two wanted changes: `completed: true` on a task already done no longer
  rewrites completedAt, and a body that carries `completed` answers 404 for
  a deleted task. The notification leaves once, after the commit.
- POST /api/sync is untouched: the app creates and pushes the next
  occurrence of its own completions; a test locks it.
- Tests: recurrence table (replayed under four time zones), parity with the
  app's getNextOccurrence under TZ=UTC in the folder of the sync harness,
  route tests of the completion, of its refusals and of the module contract.

Resolves #201

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 20:50:31 -05:00