feat(mcp): task write tools and the agent action journal (#203) #216

Open
maximus wants to merge 6 commits from issue-203-mcp-write-tools into issue-202-mcp-endpoint

6 commits

Author SHA1 Message Date
le king fu
93c36c412f test(web): the purge failure test no longer boots a second database (#203)
The test started a second PGlite inside its body to get a real database
error. Under load (every test file boots its own PGlite), that boot
exceeded the 5 s test timeout: one run out of several failed on it.

The real failure now comes from the database of the file, whose journal
table is renamed for the time of one purge, with a control that the error
does carry the text of the query that safePurge must not log.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 20:50:31 -05:00
le king fu
5f2d701c53 test(web): the same tag id in both letter cases counts once (#203)
Found by mutation: without the lower-casing of the tag ids before they
are counted, every test stayed green. createTask and setTaskTags now
receive the same id in lower and upper case in one call.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 20:50:31 -05:00
le king fu
3cdc5e6931 docs(review): the write tools, the journal and its purge in the review rules (#203)
REVIEW.md, zone « API et isolation des comptes »: the write envelope
(journal in the transaction, notification after the commit), the
references checked against the account, the gaps wanted between the REST
API and the tools, the journal and its purge. Zone « Sync »: a write tool
moves updatedAt and notifies like a route.

The « Haut » table (API line) and HIGH_ALWAYS of review-levels.py now
name taskWrites.ts and agentJournal.ts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 20:50:31 -05:00
le king fu
7d6a9b6c5d feat(mcp): task write tools and the agent action journal (#203)
Five write tools, registered for a read-write token only: create_task,
update_task, complete_task, reopen_task and set_task_tags. None deletes
anything.

Each one goes through registerWriteTool, the single envelope of the
writes, inside the envelope of every tool (limit mcp-write): one
transaction, the write of taskWrites.ts, its journal line in the same
transaction when it changed something, then, after the commit, one
notification and the answer. A call that changes nothing writes no journal
line and notifies nobody. A journal line that cannot be written takes the
write back.

A task, a list, a parent or a tag of another account answers like one
that does not exist.

Resolves #203

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 20:50:31 -05:00
le king fu
8a4dbb3eeb feat(web): agent action journal and its purge at server start (#203)
agentJournal.ts: recordAction (in the transaction of the write it
records), listActions (lines of the account of the last 90 days, newest
first, by pages, with the name of the row each line touched read on the
live row of the account, and tokenRevoked for a deleted token),
purgeOldActions (lines older than 90 days) and safePurge (logs the count,
never throws, logs only the class name of an error).

No function imports the database client: each one receives what it runs
on, so that web/server.ts can call the purge from its own bundle.

web/server.ts: once the migrations are done, and outside their try block,
a purge on a pool of its own (max: 1), then one every 24 hours on a timer
that does not hold the process. A purge that fails never stops the
server.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 20:50:31 -05:00
le king fu
605bc58024 feat(web): createTask, updateTask and setTaskTags in taskWrites (#203)
Three task writes for the MCP tools, under the contract of the module:
the transaction of the caller first, then the account; no transaction
opened, no notification, no import of the database client.

- createTask: under a parent (a live top-level task of the account, whose
  list the subtask takes), in a list (a live list of the account), or in
  the live Inbox, created under the account lock when the account has
  none. The task goes to the end of its list or of the subtasks of its
  parent. Its tags must be live tags of the account.
- updateTask: only the keys of the patch; null clears notes, due date and
  recurrence. A top-level task that changes list goes to the end of the new
  one with its live subtasks; a subtask stays in the list of its parent.
- setTaskTags: replaces the set of tags; the set already in place writes
  nothing.

A refusal is a WriteRefusal, a ToolRefusal with a code of mcp/errors.ts:
it is thrown, so the transaction of the caller is rolled back. Every
reference is checked against the account, and a row of another account
answers like a row that does not exist. Ids compared in JavaScript are
the ones the database returns.

completeTask now takes its end-of-list position from the helper the new
functions share (same query).

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