feat(web): create, rename, recolor and delete tags in the companion #189

Merged
maximus merged 29 commits from issue-182-web-tag-crud into master 2026-11-04 02:45:21 +00:00

29 commits

Author SHA1 Message Date
le king fu
ec5832a75b Merge branch 'master' into issue-182-web-tag-crud 2026-11-03 21:42:06 -05:00
le king fu
48218bdf6f docs(review): the outbox also queues during a first sync
Review of PR #185: the Sync rule said writeOutboxEntry writes only while
sync is on. Fixed at the top of the stack so the reviewed links keep their
heads.

Refs #165

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 21:20:25 -05:00
le king fu
99d2323a93 Merge branch 'issue-181-tag-updated-at' into issue-182-web-tag-crud 2026-11-03 21:13:20 -05:00
le king fu
8678775340 Merge branch 'issue-180-tag-link-sync' into issue-181-tag-updated-at 2026-11-03 21:13:20 -05:00
le king fu
26928a498b Merge branch 'issue-179-web-task-tags' into issue-180-tag-link-sync
# Conflicts:
#	src/services/syncClient.ts
#	src/services/syncRules.ts
#	tests/syncRules.test.mjs
2026-11-03 21:13:20 -05:00
le king fu
6388ffa307 Merge branch 'issue-165-account-switch' into issue-179-web-task-tags 2026-11-03 21:12:53 -05:00
le king fu
532b628887 test(sync): pin the write-back of remapped outbox entries
Refs #165

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 21:12:51 -05:00
le king fu
0317d15266 fix(sync): queue the user's writes made during the first sync
Decision of Max at /pr-brief 185 (2026-11-03): a change made during the few
seconds of « Fusionner » (or « Charger ce compte ») must reach the server.
initialMerge and initialReset run while sync is still off, so writeOutboxEntry
dropped such a write. The outbox now also queues while a first sync runs, and
the merge points the pending entries that name the fixed local Inbox at the
server Inbox (remapInboxEntry), otherwise the server refuses them.

Refs #165

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 21:12:24 -05:00
le king fu
d3efeb9b2f Merge branch 'issue-181-tag-updated-at' into issue-182-web-tag-crud 2026-11-03 20:42:41 -05:00
le king fu
9a81322527 Merge branch 'issue-180-tag-link-sync' into issue-181-tag-updated-at 2026-11-03 20:42:41 -05:00
le king fu
706f91d234 test(sync): let the setTagsForTask wipe guard match across lines
Review of PR #187: the regex did not allow the line break between
.delete(taskTags) and .where(...), so the guard could never fail.

Refs #180

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 20:42:41 -05:00
le king fu
fd509fbfac test(web): pin dueDate with a tag filter and a non-integer priority
Review of PR #186: both behaviour changes of the shared task query were
untested; removing either condition left the suite green.

Refs #179

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 20:42:15 -05:00
le king fu
3f444d7725 Merge branch 'issue-179-web-task-tags' into issue-180-tag-link-sync 2026-11-03 20:42:15 -05:00
le king fu
a5d0772345 Merge branch 'issue-178-sync-scheduler' into issue-165-account-switch 2026-11-03 20:41:37 -05:00
le king fu
a09bd68b70 Merge branch 'issue-165-account-switch' into issue-179-web-task-tags 2026-11-03 20:41:37 -05:00
le king fu
f8ee31066c Merge branch 'issue-177-ws-notify' into issue-178-sync-scheduler 2026-11-03 20:41:37 -05:00
le king fu
cc591ba85e fix(web): close a socket whose send throws
Review of PR #183: the socket was dropped from the client set but left open,
outside the heartbeat, so its page was never notified again. terminate()
closes it and the page reconnects through onclose.

Refs #177

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 20:41:32 -05:00
le king fu
dc479e3618 test(sync): pin the two-place rule of the scheduler
A single free place with a queued backlog starts no run until a second
place frees up; the condition alone was not pinned by the latency test.

Refs #178

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 20:02:20 -05:00
le king fu
589c01955a fix(sync): start a run only with room for one POST and the GET
Review of PR #184: when the budget freed up one place at a time (requests
spread by network latency), every place went to a pull-only run with
pushBatches = 0, so a queued backlog was never sent while the device spent
6 GETs a minute. The scheduler now waits for two free places.

Tests: a fake server with 300 ms per request (9-batch queue empties within
4 min, no run without a POST place), the 600 s Retry-After bound, and source
guards for the `more` signal of pushChanges and the budget of initialMerge.

Refs #178

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 20:01:42 -05:00
le king fu
83cf32a561 feat(web): create, rename, recolor and delete tags in the companion
The sidebar's Tags section gets a "Manage tags" mode, on par with the
app's Settings: create a tag (name + color from the app palette),
rename it, change its color, delete it after a confirmation. A deleted
tag leaves the sidebar at once; when it was the active filter, ?tags=
leaves the URL. router.refresh() reloads the server data so the task
detail view offers new tags without a reload.

The logic (palette, name check, list after deletion, URL after the
active filter's tag is deleted) lives in the pure helper
web/src/lib/tagEditing.ts, covered by vitest; the JSX is not tested.
No API route and no dependency change.

Refs #182
Refs #168

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 21:43:49 -05:00
le king fu
acaad3ba6a test(sync): give the migration backfill test room to boot its own PGlite
Refs #181

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 21:38:09 -05:00
le king fu
bb233c8b59 fix(sync): add updated_at to sl_tags so tag renames and deletions reach the app
Migration 0003 adds sl_tags.updated_at (default now(), backfilled from
created_at). Every tag write moves it (PUT/DELETE /api/tags/[id], tag
update/delete in POST /api/sync), and GET /api/sync pulls tags on
updatedAt >= since. Deleting a tag removes its links and moves the
touched tasks' updatedAt in the same transaction, so the app realigns
their links on the next pull.

The user_id ALTERs drizzle-kit re-emitted from the stale 0000 snapshot
are dropped from 0003 (0001 applied them); the new snapshot is current.

Refs #181
Refs #168

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 21:33:14 -05:00
le king fu
55d05046ee fix(sync): propagate tag link removals both ways and refuse foreign ids
App: setTagsForTask diffs with the local links and writes one taskTag
delete per removed link and one create per added link; addTagToTask and
removeTagFromTask write their entry and request a sync. The pull aligns
the links of every pulled task on the set the server sent, by direct
writes on task_tags in one transaction, sparing links with an unsent
taskTag entry (pure rule alignedTagIds in syncRules.ts).

Server: every link add or removal (REST routes and the taskTag case of
POST /api/sync) moves sl_tasks.updatedAt, so GET /api/sync sends the task
with its whole set of links. Task and tag creates in POST /api/sync refuse
an id taken by another account (assertIdNotTaken) instead of answering
applied without writing.

Refs #180
Refs #168

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 21:26:08 -05:00
le king fu
d98b3e5bff fix(web): check the task owner in loadTaskTags too
A link joins two owned rows: REVIEW.md asks for the ownership check on both
sides, so loadTaskTags also joins sl_tasks on the account (still one query).

Refs #179

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 21:19:43 -05:00
le king fu
99cc2fc1c4 feat(web): show, add and remove task tags and filter by tag in the companion
- web/src/lib/taskQueries.ts: list task query (existing filters + tags),
  subtasks, loadTaskTags (one query, live tags of the account only) and the
  account tags, shared by the list page and GET /api/lists/[id]/tasks.
- ?tags= validated by zod (at most 20 UUIDs, count checked first); the tag
  filter joins sl_tags on the account and deleted_at IS NULL; 400 on a
  malformed value.
- TaskItem: tag pills on tasks and subtasks; the detail view adds an
  existing tag and removes one through the task-tag API.
- Sidebar: a click on a tag filters the current view by ?tags=<id>, a second
  click removes it; FilterBar shows the active tag filter.
- FR/EN strings.

Refs #179
Refs #168

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 21:16:47 -05:00
le king fu
7c4292a8bc docs(review): account rule of #165 and the sync's own outbox writes
Refs #165

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 21:10:55 -05:00
le king fu
38bcf8b893 fix(sync): no merge across accounts, sync off until the first-sync choice
Refs #165

A device holding another account's data (dataOwnerId, persisted, kept at
sign-out) only offers « Charger ce compte » (initialReset) or « Annuler »
(sign-out, data untouched), at sign-in and on « Synchroniser ». The rule
lives in syncRules.ts (firstSyncChoice).

Sync stays off until initialMerge or initialReset has succeeded, and the
scheduler refuses every sync while the local data belong to another account
(canSync): the outbox of the old account is never pushed under the new one.
The sync's own outbox writes (kept rows, the Inbox of initialReset) no
longer depend on syncEnabled, and the token getter follows the session, so
that the first sync runs with sync still off.

Sign-out pushes the outbox first (10 s at most, in the first-sync state of
the scheduler, one request reserved outside its budget) and warns with the
number of changes still unsent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 21:06:10 -05:00
le king fu
7265c6cad4 fix(sync): sync on write with a request-budget scheduler and a 30 s interval
Every sync now goes through one scheduler (src/services/syncSchedule.ts,
pure and import-free): one sync at a time, a request during a sync gives a
single relaunch, a sliding budget of 6 real HTTP requests per 60 s (each
POST batch and each GET counted, initialMerge and initialReset included),
pushChanges sends the batches the budget allows (MAX_PUSH_BATCHES becomes a
ceiling) and the rest of the queue follows once the window frees, a 429
suspends the scheduler until Retry-After, and no sync starts during
initialMerge / initialReset.

The repositories call requestSync() (src/services/syncTrigger.ts, 2 s
debounce, single subscriber registered by _layout.tsx) after each outbox
write and after the Inbox repair transaction; outbox.ts and syncClient.ts
never do. _layout.tsx syncs on launch, every 30 s in the foreground, on
return to the foreground and on write through scheduleSync(); the Settings
button too. REVIEW.md and scripts/review-levels.py list the two new files
in the Sync row.

test: reproduces #178 (tests/syncSchedule.test.mjs, smoke guards)

Refs #178
Refs #167

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 20:54:33 -05:00
le king fu
b03f070a51 feat(web): notify open pages over WebSocket after every mutation
The companion never told an open page that its data changed:
broadcastToUser() had no caller, and the client set existed twice
because server.ts is bundled apart from the Next routes, so the routes
(and /api/health) saw an empty set.

- Keep the client set on globalThis.__wsClients, like the ticket store.
- WsMessage sync variant is now { type: 'sync' } with no detail.
- notifyUserChanged(userId) coalesces per account with a 1 s trailing
  debounce; a send that throws drops the socket instead of crashing.
- POST /api/sync notifies once per batch when at least one operation
  is applied; every REST mutation handler of lists, tasks and tags
  notifies after success.
- useSync refreshes only on a sync message, debounced 500 ms;
  auth_expired no longer triggers a refresh.

Tests: ws.test.ts (payload, coalescing, shared set across module
instances, source guard on mutation handlers) and sync route tests
(one notification per applied batch, none for refused or duplicate
batches, never another account).

Refs #177
Refs #167

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 20:43:41 -05:00