Compare commits

...

44 Commits

Author SHA1 Message Date
7153630a2e Audit icons: add 1-word hover tooltips
Some checks failed
file-length / file length <= 250 lines (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
release-apk / release (APK) (push) Has been cancelled
repo-contract / repo contract (push) Has been cancelled
Todo: fe70b845
2026-11-22 18:30:40 +01:00
f20e2ab16f Put my logo everywhere
Some checks failed
file-length / file length <= 250 lines (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
release-apk / release (APK) (push) Has been cancelled
repo-contract / repo contract (push) Has been cancelled
Todo: 7808ee0a
2026-11-21 10:06:22 +01:00
a96babd8f8 Bump Flutter to 3.50.1
Some checks are pending
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 08:38:50 +01:00
5d83ff561e deploy.sh pulls and runs from ~/src/todo
Some checks are pending
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Revert the AGENTS.md deploy line: kuhy has an uncommitted edit there,
so changing the file blocked the pull. deploy.sh itself now redirects a
worktree run to the main checkout, past phone_deploy's exit-49 guard.

Todo: 2556952d

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 20:50:20 +01:00
d5764fce7b Deploy from main checkout, not the worktree
phone_deploy refuses a production install from a worktree (exit 49),
so the board's deploy of this repo always failed on the phone target.

Todo: 2556952d

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 20:48:03 +01:00
660d82282c get rid of github ci/cd version check of package…
Some checks are pending
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Todo: 2556952d
2026-11-19 18:11:08 +01:00
300d50ab11 chore: enable dart-flutter plugin
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-19 17:59:25 +01:00
ea216d4a59 Sync pulls peers at once, off the UI thread
Some checks failed
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
dependency freshness / dependencies on newest stable (push) Has been cancelled
The board reported a 3.9 s sync.run spinner on the Pixel (todo:0c575b891b).
Eight ~2 MB peer logs were fetched, parsed on the UI isolate and merged one
by one, each merge rewriting the whole local store; a device without a
GitHub token still mirrored to GitHub (404s); settings and analytics waited
for the note sync.

Now changed peers download together, logs over 64 KB parse on an isolate
(inline on web), peers merge into one local write, the revision map and
listing share a round trip, the mirror is skipped without a token, and
settings/analytics run alongside the notes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 11:25:22 +01:00
fafefabab6 MCP reads reuse a sync done within 2 s
A board fetch makes 15 MCP calls and each one synced with Firebase
(0.5-1 s), so a fetch took 12 s. Reads skip the sync when one ended
within readFreshness; writes always pull and push.

Todo: 475dc1d1
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWXu5EV5tPkCTEu6nxf
2026-11-19 11:17:50 +01:00
5acd9d4863 Bump flutter, gradle, sync pins; probe retries
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
crdt_sync_flutter 0.9.1, sync_settings_ui 0.8.4 (data_transfer_flutter
0.2.3 lifts the file_picker 13.3.3 hold, so 13.4.0 and the exception go),
Flutter 3.50.0 (.fvmrc + release-apk.yml), Gradle 9.9.1.

LinuxSystemProbe.processCmdlines retried nothing when a pid exited between
readdir and Dart's lstat of it, failing the whole listing (seen in the
suite). It now relists up to three times.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 11:07:19 +01:00
9d2a5a0bd3 list_tasks no_repo lists repo-less notes
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
The board reads open notes through list_tasks, which hides notes
without a repo, so kuhy's ideas never reached it.

Todo: 475dc1d1
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWXu5EV5tPkCTEu6nxf
2026-11-19 10:53:18 +01:00
3a747c2e51 Report errors and slow waits to the board
Some checks failed
dependency freshness / dependencies on newest stable (push) Has been cancelled
file-length / file length <= 250 lines (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
release-apk / release (APK) (push) Has been cancelled
repo-contract / repo contract (push) Has been cancelled
crdt_sync_flutter 0.9.0's installAppErrors in main(): uncaught errors and
every spinner shown over 1 s (WaitWatch: sync.run, mirror.test) upload to
RTDB /todo/errors/<device> with the versionCode, where the PC app-errors
ingest files board tickets (kuhyx/utils DOCS-app-errors.md).

The app moves to material_ui first: sync_settings_ui 0.8.x and
design_system 0.4.x sit on it, and Flutter 3.50 deprecates
flutter/material. Pins: crdt_sync 0.14.1, csf 0.9.0, ssui 0.8.3,
gda 0.5.1, design_system 0.4.1, image 4.13.1, mcp_dart 2.4.4.
file_picker stays 13.3.3, held by data_transfer_flutter 0.2.2
(allowlisted, self-clearing).

appRoute takes a route name so each report names its screen; the
release build passes APP_BUILD/APP_VERSION. Nothing new on screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 23:07:58 +01:00
1f7c31357b Point at android_ui for phone UI driving
Some checks failed
dependency freshness / dependencies on newest stable (push) Has been cancelled
file-length / file length <= 250 lines (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
release-apk / release (APK) (push) Has been cancelled
repo-contract / repo contract (push) Has been cancelled
Tap and type by label via ~/src/testsAndMisc's android_ui CLI or its MCP server, instead of coordinates. No code copied.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 08:46:39 +01:00
b350b3e8c1 Tidy MCP deadline guard for analyzer
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Guard moves to request_guard.dart (file-length gate); README notes
the token reload, deadline and timeouts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWXgrX1QxVjqMiz6KFs
2026-11-16 08:06:05 +01:00
e885465f55 todo-mcp unit raises LimitNOFILE to 65536
The 1024 soft limit was exhausted in the 2026-11-16 outage.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWXgrX1QxVjqMiz6KFs
2026-11-16 08:04:41 +01:00
be6bf6fc48 MCP closes requests that outlive a deadline
Dart's HttpServer never notices a client that hung up on a request
still in flight, so abandoned calls held their sockets (1010 in
CLOSE-WAIT, fd limit hit). POST/DELETE open past 90 s now get 503 and
close; the library's server is private, so idleTimeout stays default.
A zone guard keeps late write errors from killing the process.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWXgrX1QxVjqMiz6KFs
2026-11-16 08:04:40 +01:00
b2ffc346c3 Bound every Firebase and token HTTP call
package:http has no timeout; a dead connection wedged sync forever.
CliSession now wraps its client: 30 s to headers, 30 s per body chunk.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWXgrX1QxVjqMiz6KFs
2026-11-16 08:01:50 +01:00
0ce9c42ff6 MCP tokens load once, keep last good set
A read error no longer clears the accepted tokens; with no good
load the answer is 503, not 403. A request costs one stat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWXgrX1QxVjqMiz6KFs
2026-11-16 07:59:31 +01:00
de5ad7d2dd MCP calls time out instead of wedging
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
A sync stuck on a dead connection held the one-at-a-time queue forever. Abandoned board polls piled up as CLOSE-WAIT sockets until the process hit its fd limit, the tokens file could no longer be opened, and a valid token read as HTTP 403.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWXgrX1QxVjqMiz6KFs
2026-11-16 07:50:43 +01:00
cd50fd0ae2 Wrapper imports the passphrase path, not Flutter
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
dart build cli failed: wrapper_server pulled crdt_sync_flutter (dart:ui)
through e2e_passphrase_source. The path const moves to a dart-only file.

Todo: 656f0d08
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWXgrX1QxVjqMiz6KFs
2026-11-15 21:28:19 +01:00
19f930a93a CLI caches the E2E key (0600)
Some checks failed
dependency freshness / dependencies on newest stable (push) Has been cancelled
file-length / file length <= 250 lines (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
release-apk / release (APK) (push) Has been cancelled
repo-contract / repo contract (push) Has been cancelled
Argon2id ran on every CLI/MCP call; the derived key is now cached
owner-only in the data dir.

Todo: fda71ed1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 10:59:34 +01:00
f7e24bbb1a Desktop adopts the E2E passphrase once
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
The wrapper serves ~/.config/crdt-sync/password once on
/sync-e2e-passphrase; the web app stores it in its keystore, so desktop
todo never asks. Android still unlocks via the lock tile.

Todo: fda71ed1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 09:56:07 +01:00
4423937f5c E2E: key cache, CLI password, lock tile
Argon2id runs once per device (keystore key cache); the CLI/MCP read
~/.config/crdt-sync/password; pull-only merges old and encrypted
prefixes; the settings lock tile follows the last sync and resyncs on
save. Pins crdt_sync 0.14.0, crdt_sync_flutter 0.8.0, sync_settings_ui
0.7.2.

Todo: fda71ed1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 09:52:15 +01:00
f4913daaa8 E2E-encrypt todo sync
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Todo: fda71ed1

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 08:39:05 +01:00
c9eb4d6cff Bump sqflite_common_ffi to 2.4.7
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 16:17:09 +01:00
1010d96426 deploy.sh: wait out phone_deploy load guard
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:57:08 +01:00
319f18d33a deploy.sh: one phone lease owner per run
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:53:55 +01:00
c3ac6ec05d deploy.sh: SDK env and release key for phone
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Ship and systemd units skip ~/.zshenv, so default ANDROID_HOME, and
copy the shared key.properties into a fresh checkout so the release
build installs over CI builds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:47:43 +01:00
0e56cddd47 Add scripts/deploy.sh and the deploy command
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Deploys the MCP service, the desktop pacman package and the phone
release build, each behind its own health check; exits non-zero unless
all pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:15:23 +01:00
203e61d6ac Text-free sync settings via ssui 0.7.0
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Bump sync_settings_ui 0.7.0 and github_device_auth 0.4.0 (glyph +
spoken label). Guard covers the Sync settings screen; degraded sync
gets its own warning glyph; tooltip delegate and copy button tested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 01:32:02 +01:00
edf6969949 Template picker: glyph prefix, not float label
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 01:22:22 +01:00
5ea7ba7b73 Text-free list, editor, sync and image cues
Glyph + spoken label replaces every app-written string the guard
found: empty states, tile meta, sheet dates/fields, date presets,
template/section headings, status footer, snackbars, GitHub and
cloud-image results, upload/download badges, Material tooltips.
Guard tests (text_free_*_test) walk the painted tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 01:17:03 +01:00
091e68a2d9 Text-free UI: glyph chips, icon-only actions
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 01:02:25 +01:00
a30e7b34a9 CLI: --set-text replaces a note's text
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Keeps every other field; text from --text or stdin, empty refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 17:56:23 +01:00
17d6d2a533 Bump file_picker, idb_shim, sqflite_common_ffi
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 17:56:22 +01:00
4e8ccd6bfd Lean gradle.properties for warm daemon
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWZUTC9Zzdzsx7VW7dm
2026-11-10 17:51:44 +01:00
6bd2923f0a Instant page routes; coalesce watch re-emits
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWXdsB7CQPNXVN829G1
2026-11-10 15:57:03 +01:00
4c77dd5d2e Bulk update: diff generated fields only
planBulkUpdate compared fresh field values with the stored text, so a
peer's "...00Z" created_at (or a web build's millisecond date) read as a
change and got a fresh clock, erasing the created_by node signal; a
record without a priority field got one written. Compare the note's own
generated fields before and after instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWXdsB7CQPNXVN829G1
2026-11-10 15:41:35 +01:00
757c54beda Multi-select notes with an icon action bar
An app-bar toggle enters selection mode: a tap toggles a note (tint +
check on grid tiles, ListTile.selected + check in the list), Ctrl/Cmd-
click toggles and Shift-click range-selects on desktop, long-press
outside the mode still opens the per-note sheet. While anything is
selected an icon-only bottom bar sets status or priority for the whole
selection in one bulkUpdate, assigns plain notes to a repo picked from
the repos on notes or typed as owner/name, or clears the selection. A
refused assign (note already in a repo) flashes a block icon. Labels
are semantic only; menus pass an empty tooltip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWXdsB7CQPNXVN829G1
2026-11-10 15:39:13 +01:00
5c1bf75bf9 Bulk note writes and assign-to-repo helper
NoteRepository.bulkUpdate sets status/priority on many notes in one
store write (mergeLogs + replaceAll; only changed fields plus updated_at
get a clock). saveReplacing saves one note and tombstones others in one
write. assignToRepo moves plain notes into the repo's open note as
"## title" sections via addRepoTask, demoting body headings below "##"
so a template note stays one section; notes already in a repo are
refused. The seeded watch stream moved to log_watch.dart for the
250-line cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWXdsB7CQPNXVN829G1
2026-11-10 15:38:54 +01:00
57019eec30 Track who filed a note (created_by)
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
New optional note field created_by (kuhy|claude), stored like by/repo and
omitted when unset so older builds stay wire-compatible. App UI stamps kuhy;
MCP add_task and the CLI stamp claude. list/get/search output includes it.
Human notes sort above Claude's; Claude notes are hidden behind a per-device
eye toggle. CLI --backfill-created-by [--dry-run] classifies old notes by the
node that wrote created_at, writing only the created_by field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 14:18:19 +01:00
cc9789f530 Start exactly the merged item
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file-length / file length <= 250 lines (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
release-apk / release (APK) (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
The board orders cards by column, so a cancelled older item with the
same title could be listed last and was started instead of the item
the merge added (T1866). Start now targets <id8>-<sections - 1> only.

Todo: 64d39ab5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 18:28:17 +01:00
135f3f07ea Start a merged task outside the MCP lock
The board refreshes its notes through this MCP server, and add_task
held the server's serial lock while waiting for the board to show
the merged section, so the board could never see it (T1865). The
Start now runs after the lock is released.

Todo: 64d39ab5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 18:24:24 +01:00
ba25e8f176 Wait for the board before a merged Start
The board's note cache lags ~10 s after a merge, so Start found
"no startable item" (T1863); it now waits up to 30 s for the merged
section's card. A Start POST slower than its timeout that did take
effect was reported "board unreachable" (T1864); it now re-reads the
board and reports ok when the card left Start.

Todo: 64d39ab5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 18:18:30 +01:00
205 changed files with 7297 additions and 1572 deletions

5
.claude/settings.json Normal file
View File

@ -0,0 +1,5 @@
{
"enabledPlugins": {
"dart-flutter@dart-flutter": true
}
}

View File

@ -0,0 +1,2 @@
# Dependency freshness runs locally only (pre-commit hook); no GitHub Actions
# workflow. This marker stops the fleet installer from re-adding it.

2
.fvmrc
View File

@ -1,3 +1,3 @@
{
"flutter": "3.47.9"
"flutter": "3.50.1"
}

View File

@ -1,62 +0,0 @@
name: dependency freshness
# Every dependency on its ecosystem's newest STABLE release, enforced on push
# as well as at commit time. The local pre-commit hook only sees the manifests
# in a commit and can be skipped entirely by a fresh clone that never ran
# `pre-commit install`; this runs `--all` over the whole repo.
#
# `--strict` is CI-only. Offline the gate degrades to its cached answer and
# passes, because `--no-verify` is banned locally and a hook that hard-failed
# on a flaky connection would leave no way to commit. A runner is always
# online, so here an undeterminable answer is a real failure.
#
# Expect this to go red for reasons this repo's commit did not cause: an
# upstream release overnight is enough. That is the chosen behaviour -- the
# alternative is a gate that only notices staleness when someone remembers to
# look.
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
jobs:
dependency-freshness:
name: dependencies on newest stable
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# The gate lives in the shared utils repo so every repo resolves the
# same "latest stable" the same way. Checking it out beats vendoring a
# copy, which is exactly how a gate and its survey start disagreeing.
- name: Check out the shared gate
uses: actions/checkout@v4
with:
repository: kuhyx/utils
path: .utils
# "3.x", never a pinned minor: the Python target IS the interpreter the
# gate runs under (registries/toolchain.python_installed), so a runner
# held a release behind this machine reports a repo's `requires-python`
# as excluding "latest" while the same check passes locally. flax-docs-mcp
# hit exactly that -- `>=3.14` green here, red on a 3.13 runner.
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install the gate's two runtime dependencies
run: python -m pip install --upgrade pyyaml packaging
- name: Cache registry lookups
uses: actions/cache@v4
with:
path: ~/.cache/dep-freshness
key: dep-freshness-${{ hashFiles('**/pubspec.yaml', '**/pyproject.toml',
'**/requirements*.txt', '**/package.json', '**/Cargo.toml', '**/go.mod') }}
restore-keys: dep-freshness-
- name: Every dependency is on newest stable
run: bash .utils/scripts/check_dependency_freshness.sh --all --strict

View File

@ -47,7 +47,7 @@ jobs:
- uses: subosito/flutter-action@v2
with:
flutter-version: 3.47.9
flutter-version: 3.50.1
channel: stable
cache: true
@ -110,7 +110,9 @@ jobs:
flutter build apk --release \
--target-platform android-arm64 \
--build-name="${{ steps.ver.outputs.semver }}" \
--build-number="${{ steps.vc.outputs.code }}"
--build-number="${{ steps.vc.outputs.code }}" \
--dart-define=APP_BUILD="${{ steps.vc.outputs.code }}" \
--dart-define=APP_VERSION="${{ steps.ver.outputs.semver }}"
# Fail closed. `findByName("release") ?: debug` silently falls back to
# the debug key if key.properties is misplaced, producing a green build

View File

@ -106,7 +106,7 @@ repos:
# Runs WITHOUT --strict on purpose. Offline it degrades to the cached
# answer and passes with a loud banner; `--no-verify` is banned here, so
# a hook that hard-failed on a flaky connection would leave no way to
# commit at all. CI, always online, is the strict authority.
# commit at all. Local only: no CI workflow runs this.
- id: dependency-freshness
name: dependencies on newest stable
entry: scripts/check_dependency_freshness.sh

View File

@ -50,6 +50,7 @@ and sync peer-to-peer through a GitHub repo used as dumb storage.
- lint: `flutter analyze`
- coverage: `flutter test --coverage --reporter=compact`
- coverage-gaps: `coverage-gaps coverage/lcov.info`
- deploy: `scripts/deploy.sh` (MCP service, desktop pacman package, phone release; exits non-zero unless every health check passes)
## Architecture
@ -217,3 +218,18 @@ about *this repo*:
Sourced from [flutter/flutter docs/rules/rules.md](https://github.com/flutter/flutter/blob/main/docs/rules/rules.md)
via `~/.claude/CLAUDE.md`'s Flutter AI tooling setup. Re-fetch periodically.
## Driving the app on the phone
Tap and type by label, never by coordinate, with `android_ui` from
`~/src/testsAndMisc` (not copied here):
```bash
cd ~/src/testsAndMisc && .venv/bin/python -m python_pkg.android_ui \
-s 23181JEGR08034 --display self dump
```
The same driver is the `android-ui` MCP server
(`.venv/bin/python -m python_pkg.android_ui.mcp_server`, in that repo's
`.mcp.json`). Tools and error contract:
`~/src/testsAndMisc/python_pkg/android_ui/README.md`.

View File

@ -37,3 +37,18 @@ dart run bin/todo_note.dart --delete <id>
`--list` and `--get` never push; `--data-dir <dir>` selects a throwaway node.
Exit codes: 0 ok, 1 sync/auth failure or note not found, 2 bad arguments.
All logic is in `lib/cli/` (tested in `test/cli/`); `--help` lists every flag.
## Driving the app on the phone
Tap and type by label, never by coordinate, with `android_ui` from
`~/src/testsAndMisc` (not copied here):
```bash
cd ~/src/testsAndMisc && .venv/bin/python -m python_pkg.android_ui \
-s 23181JEGR08034 --display self dump
```
The same driver is the `android-ui` MCP server
(`.venv/bin/python -m python_pkg.android_ui.mcp_server`, in that repo's
`.mcp.json`). Tools and error contract:
`~/src/testsAndMisc/python_pkg/android_ui/README.md`.

View File

@ -1,4 +1,7 @@
org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
org.gradle.jvmargs=-Xmx2G -XX:MaxMetaspaceSize=1G -XX:ReservedCodeCacheSize=256m -XX:+UseSerialGC -XX:TieredStopAtLevel=1
org.gradle.caching=true
org.gradle.parallel=true
kotlin.compiler.execution.strategy=in-process
android.useAndroidX=true
# This newDsl flag was added by the Flutter template
android.newDsl=false

View File

@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.1-all.zip

View File

@ -0,0 +1,4 @@
# todo's own additions to the fleet-wide allowlist
# (~/src/utils/dependency-freshness.allowlist.yaml).
exceptions: []

View File

@ -4,49 +4,12 @@
/// exact-pinned dependency under the freshness gate.
library;
import 'package:todo/cli/cli_mode.dart';
import 'package:todo/data/note.dart';
export 'package:todo/cli/cli_mode.dart';
export 'package:todo/cli/cli_usage.dart';
/// What the CLI was asked to do.
enum CliMode {
/// Create a note and push it.
add,
/// Print every live note, one per line.
list,
/// Print one note in full.
get,
/// Tombstone one note and push the deletion.
delete,
/// Change one note's status and push it.
setStatus,
/// Set a task done with evidence and push it.
close,
/// Print the notes matching a query, as [list] does.
search,
/// Print usage.
help,
}
/// Thrown for a malformed command line; maps to exit code 2.
class UsageError implements Exception {
/// Creates a [UsageError] carrying [message].
UsageError(this.message);
/// What was wrong with the arguments.
final String message;
@override
String toString() => message;
}
/// The parsed command line.
class CliArgs {
/// Creates parsed arguments; see [parse].
@ -58,6 +21,7 @@ class CliArgs {
this.status,
this.dataDir,
this.newNote = false,
this.dryRun = false,
this.opts = (
repo: null,
query: null,
@ -89,12 +53,19 @@ class CliArgs {
opts[arg] = value();
case '--list':
modes.add(CliMode.list);
case '--backfill-created-by':
modes.add(CliMode.backfill);
case '--dry-run':
opts[arg] = 'true';
case '--search':
modes.add(CliMode.search);
opts[arg] = value();
case '--get' || '--delete' || '--close':
modes.add(CliMode.values.byName(arg.substring(2)));
id = value();
case '--set-text':
modes.add(CliMode.setText);
id = value();
case '--set-status':
modes.add(CliMode.setStatus);
id = value();
@ -106,8 +77,9 @@ class CliArgs {
if (modes.contains(CliMode.help)) return const CliArgs(mode: CliMode.help);
if (modes.length > 1) {
throw UsageError(
'--list, --search, --get, --delete, --set-status and --close are '
'mutually exclusive',
'--list, --search, --get, --delete, --set-status, --set-text, '
'--close and '
'--backfill-created-by are mutually exclusive',
);
}
final mode = modes.isEmpty ? CliMode.add : modes.single;
@ -128,6 +100,7 @@ class CliArgs {
opts.containsKey('--new-note') &&
(opts['--repo'] != null ||
(throw UsageError('--new-note needs --repo'))),
dryRun: opts.containsKey('--dry-run'),
opts: (
repo: _repo(opts['--repo']),
query: _nonBlank(opts['--search'], '--search'),
@ -141,7 +114,8 @@ class CliArgs {
/// The selected mode.
final CliMode mode;
/// Note text from `--text`; null means "read stdin" in [CliMode.add].
/// Note text from `--text`; null means "read stdin" in [CliMode.add] and
/// [CliMode.setText].
final String? text;
/// Full id or 8+ character prefix of the note an id mode acts on.
@ -159,6 +133,9 @@ class CliArgs {
/// `--new-note`: the `--repo` task gets its own note.
final bool newNote;
/// Whether `--dry-run` was given: report what would change, change nothing.
final bool dryRun;
/// `--repo`, `--search`, `--done-check`, `--by` and `--evidence` values.
final ({
String? repo,
@ -174,7 +151,7 @@ class CliArgs {
static const _adding = 'when adding a note';
static const Map<String, (String, Set<CliMode>)> _scopes = {
'--text': (_adding, {CliMode.add}),
'--text': ('$_adding or to --set-text', {CliMode.add, CliMode.setText}),
'--done-check': (_adding, {CliMode.add}),
'--by': (_adding, {CliMode.add}),
'--repo': (
@ -183,6 +160,7 @@ class CliArgs {
),
'--evidence': ('to --close', {CliMode.close}),
'--new-note': (_adding, {CliMode.add}),
'--dry-run': ('to --backfill-created-by', {CliMode.backfill}),
};
static void _checkScopes(Iterable<String> flags, CliMode mode) {

View File

@ -38,6 +38,7 @@ class CliCommands {
repo: repo,
doneCheck: args.opts.doneCheck,
by: args.opts.by,
createdBy: 'claude',
);
await session.repository.upsert(note);
if (!await _push('note')) return 1;
@ -57,6 +58,7 @@ class CliCommands {
doneCheck: args.opts.doneCheck,
priority: args.priority,
by: args.opts.by,
createdBy: 'claude',
);
await _save(added.note);
if (!await _push('note')) return 1;
@ -79,6 +81,7 @@ class CliCommands {
doneCheck: args.opts.doneCheck,
priority: args.priority,
by: args.opts.by,
createdBy: 'claude',
);
await _save(added.note);
if (!await _push('note')) return 1;
@ -133,6 +136,15 @@ class CliCommands {
return 0;
}
/// Replaces a note's whole text (title is its first line) and pushes it.
Future<int> setText(String ref, String text) async {
final note = await _pullAndFind(ref);
await _save(note.copyWith(text: text));
if (!await _push('text change')) return 1;
_out.writeln('${note.id}\ttext');
return 0;
}
/// Marks a note done with [evidence], keeping it, and pushes it.
Future<int> close(String ref, String evidence) async {
final note = await _pullAndFind(ref);
@ -142,6 +154,35 @@ class CliCommands {
return 0;
}
/// Sets `created_by` where unset (see [NoteRepository.backfillCreatedBy]).
/// Prints one `<id>\t<value>\t<title>` line per note, then the totals. With
/// [dryRun] nothing is written or pushed, and peers are only read.
Future<int> backfillCreatedBy(
Set<String> claudeNodes, {
required bool dryRun,
}) async {
_report(await session.sync(push: !dryRun));
final plan = await session.repository.backfillCreatedBy(
claudeNodes,
dryRun: dryRun,
);
final titles = {
for (final n in await session.repository.listNotes()) n.id: n,
};
for (final MapEntry(:key, :value) in plan.entries) {
final note = titles[key];
final title = note == null ? '' : note.text.split('\n').first;
_out.writeln(
'${key.substring(0, key.length.clamp(0, 8))}\t$value\t$title',
);
}
final claude = plan.values.where((v) => v == 'claude').length;
final kuhy = plan.length - claude;
_out.writeln('${dryRun ? 'dry run' : 'set'}: claude $claude, kuhy $kuhy');
if (dryRun || plan.isEmpty) return 0;
return await _push('backfill') ? 0 : 1;
}
Future<Note> _pullAndFind(String ref) async {
_report(await session.sync(push: true));
return findNote(await session.repository.listNotes(), ref);

47
lib/cli/cli_mode.dart Normal file
View File

@ -0,0 +1,47 @@
/// What the CLI can be asked to do, and how a bad command line is reported.
library;
/// What the CLI was asked to do.
enum CliMode {
/// Create a note and push it.
add,
/// Print every live note, one per line.
list,
/// Print one note in full.
get,
/// Tombstone one note and push the deletion.
delete,
/// Change one note's status and push it.
setStatus,
/// Replace one note's whole text and push it.
setText,
/// Set a task done with evidence and push it.
close,
/// Print the notes matching a query, as [list] does.
search,
/// Set `created_by` on notes that lack it.
backfill,
/// Print usage.
help,
}
/// Thrown for a malformed command line; maps to exit code 2.
class UsageError implements Exception {
/// Creates a [UsageError] carrying [message].
UsageError(this.message);
/// What was wrong with the arguments.
final String message;
@override
String toString() => message;
}

26
lib/cli/cli_paths.dart Normal file
View File

@ -0,0 +1,26 @@
import 'dart:io';
import 'package:path/path.dart' as p;
import 'package:todo/cli/cli_session.dart' show CliSession;
/// Default data dir: `$XDG_DATA_HOME/todo-cli`, else `~/.local/share/todo-cli`.
String defaultDataDir(Map<String, String> env) {
final xdg = env['XDG_DATA_HOME'] ?? '';
final base = xdg.isNotEmpty
? xdg
: p.join(env['HOME'] ?? '', '.local', 'share');
return p.join(base, 'todo-cli');
}
/// Node ids of the installs Claude files notes through: the MCP server and
/// the CLI under the same data root as [defaultDataDir]. Missing ones are
/// skipped.
Set<String> claudeNodeIds(Map<String, String> env) {
final cli = defaultDataDir(env);
return {
for (final dir in [cli, p.join(p.dirname(cli), 'todo-mcp')])
if (File(p.join(dir, CliSession.nodeIdFileName)) case final f
when f.existsSync())
f.readAsStringSync().trim(),
}..remove('');
}

View File

@ -54,7 +54,7 @@ Future<int> runCli(
return 0;
}
String? text;
if (args.mode == CliMode.add) {
if (args.mode == CliMode.add || args.mode == CliMode.setText) {
text = args.text ?? await readStdin();
if (text.trim().isEmpty) {
err.writeln('error: empty note (pass --text or pipe text on stdin)');
@ -79,7 +79,12 @@ Future<int> runCli(
CliMode.list || CliMode.search => await cli.list(args),
CliMode.get => await cli.get(args.id!),
CliMode.setStatus => await cli.setStatus(args.id!, args.status!),
CliMode.setText => await cli.setText(args.id!, text!),
CliMode.close => await cli.close(args.id!, args.opts.evidence!),
CliMode.backfill => await cli.backfillCreatedBy(
claudeNodeIds(env),
dryRun: args.dryRun,
),
// Only delete is left: help returned above.
_ => await cli.delete(args.id!),
};

View File

@ -7,6 +7,7 @@
/// records hand-written into RTDB.
library;
import 'dart:convert';
import 'dart:io';
import 'package:crdt_sync/crdt_sync.dart';
@ -15,25 +16,33 @@ import 'package:http/http.dart' as http;
import 'package:path/path.dart' as p;
import 'package:todo/cli/file_credential_store.dart';
import 'package:todo/cli/pull_only_store.dart';
import 'package:todo/cli/timeout_client.dart';
import 'package:todo/data/note_repository.dart';
import 'package:todo/sync/firebase_project.dart';
import 'package:todo/sync/sync_service.dart';
import 'package:uuid/uuid.dart';
/// Default data dir: `$XDG_DATA_HOME/todo-cli`, else `~/.local/share/todo-cli`.
String defaultDataDir(Map<String, String> env) {
final xdg = env['XDG_DATA_HOME'] ?? '';
final base = xdg.isNotEmpty
? xdg
: p.join(env['HOME'] ?? '', '.local', 'share');
return p.join(base, 'todo-cli');
}
export 'package:todo/cli/cli_paths.dart';
/// The open state of one CLI invocation. Call [close] when done.
class CliSession {
/// Wraps already-open parts; [open] is the normal way in. Public so a test
/// can subclass the session and script [sync]'s outcome.
CliSession(this.dataDir, this.repository, this._firebase);
CliSession(
this.dataDir,
this.repository,
this._firebase, {
this.passphraseFile,
this.sharedPasswordFile,
});
/// The fleet-wide crdt-sync password the Python daemons read too
/// (`~/.config/crdt-sync/password`), found from the seed's config root.
final File? sharedPasswordFile;
/// Where the passphrase is read from besides the environment: next to the
/// seeded Firebase session, e.g. `~/.config/todo/e2e_passphrase`.
final File? passphraseFile;
/// File holding this install's persisted CRDT node id.
static const nodeIdFileName = 'node_id';
@ -55,13 +64,19 @@ class CliSession {
/// Opens (creating on first use) the session rooted at [dataDir].
///
/// [seedCredentials] is todo's desktop session, read once and never written.
/// [httpClient] replaces the real network client (tests only).
/// [httpClient] replaces the real network client (tests only). Either way
/// every request is bounded by [requestTimeout] (see [TimeoutClient]).
static Future<CliSession> open(
String dataDir, {
required String seedCredentials,
String seedApp = 'todo',
http.Client? httpClient,
Duration requestTimeout = const Duration(seconds: 30),
}) async {
final network = TimeoutClient(
httpClient ?? http.Client(),
timeout: requestTimeout,
);
final dir = Directory(dataDir);
await dir.create(recursive: true);
// Holds a database-write credential: owner-only, like ~/.config/todo.
@ -74,7 +89,7 @@ class CliSession {
);
final auth = FirebaseTokenProvider(
apiKey: kProject.apiKey,
httpClient: httpClient,
httpClient: network,
store: FileCredentialStore(
file: File(p.join(dataDir, credentialsFileName)),
seedFile: File(seedCredentials),
@ -90,9 +105,19 @@ class CliSession {
final firebase = FirebaseRestClient(
databaseUrl: kProject.databaseUrl,
auth: auth,
httpClient: httpClient,
httpClient: network,
);
return CliSession(
dataDir,
repository,
firebase,
passphraseFile: File(
p.join(p.dirname(seedCredentials), e2ePassphraseFileName),
),
sharedPasswordFile: File(
p.join(p.dirname(p.dirname(seedCredentials)), 'crdt-sync', 'password'),
),
);
return CliSession(dataDir, repository, firebase);
}
/// Pull every peer's log and merge it; with [push], also publish this
@ -100,15 +125,91 @@ class CliSession {
///
/// Without [push] nothing is written anywhere remote, and the revision cache
/// is bypassed so a read always sees every peer's current log.
Future<SyncResult> sync({required bool push}) {
Future<SyncResult> sync({required bool push}) async {
final plainService = SyncService(
stateStore: push
? PersistedSyncStateStore(
FileLogPersistence(File(p.join(dataDir, syncStateFileName))),
)
: null,
);
final e2e = await openEncryptedStore(
store: _remote(push: push),
oldPrefix: plainService.notesDir,
readPassphrase: _readPassphrase,
// Argon2id once per install, not on every CLI/MCP call.
keyCache: E2eKeyCache(read: _readCachedKey, write: _writeCachedKey),
);
if (!push) {
return const SyncService().sync(repository, PullOnlyStore(_firebase));
// Read-only during the migration: old builds still write the plaintext
// prefix, so merge it, then the encrypted one when this host has a key.
final plain = await const SyncService().sync(
repository,
_remote(push: false),
);
if (e2e is! E2eReady) return plain;
final layout = E2eLayout.of(plainService.notesDir);
return await SyncService(
notesDir: layout.prefix,
revsPath: layout.revsPath,
).sync(repository, e2e.store);
}
return SyncService(
stateStore: PersistedSyncStateStore(
FileLogPersistence(File(p.join(dataDir, syncStateFileName))),
),
).sync(repository, _firebase);
if (e2e is! E2eReady) {
throw StateError(
'sync is locked: put the crdt-sync passphrase in '
'$e2ePassphraseEnv or ${passphraseFile?.path ?? e2ePassphraseFileName}',
);
}
final layout = E2eLayout.of(plainService.notesDir);
return await SyncService(
notesDir: layout.prefix,
revsPath: layout.revsPath,
stateStore: plainService.stateStore,
).sync(repository, e2e.store);
}
RemoteStore _remote({required bool push}) =>
push ? _firebase : PullOnlyStore(_firebase);
/// Owner-only file in the data dir caching the derived E2E key.
static const e2eKeyFileName = 'e2e_key';
File get _keyFile => File(p.join(dataDir, e2eKeyFileName));
Future<List<int>?> _readCachedKey() async {
final file = _keyFile;
if (!file.existsSync()) return null;
try {
return base64.decode((await file.readAsString()).trim());
} on FormatException {
return null;
}
}
Future<void> _writeCachedKey(List<int> bytes) async {
final file = _keyFile;
// Restrict before the key is written, never after.
await file.writeAsString('');
await Process.run('chmod', ['600', file.path]);
await file.writeAsString(base64.encode(bytes), flush: true);
}
/// Environment variable holding the shared crdt-sync passphrase.
static const e2ePassphraseEnv = 'TODO_E2E_PASSPHRASE';
/// File name of the passphrase, beside the seeded Firebase session.
static const e2ePassphraseFileName = 'e2e_passphrase';
Future<String?> _readPassphrase() async {
final fromEnv = Platform.environment[e2ePassphraseEnv];
if (fromEnv != null && fromEnv.isNotEmpty) return fromEnv;
for (final file in [passphraseFile, sharedPasswordFile]) {
if (file != null && file.existsSync()) {
final text = (await file.readAsString()).trim();
if (text.isNotEmpty) return text;
}
}
return null;
}
/// Releases the log and the HTTP client.

View File

@ -22,9 +22,14 @@ A note with --repo is a repo task; one without is a plain idea.
--get <id> pull, then print one note in full (exit 1 if absent)
--delete <id> pull, tombstone the note, push
--set-status <id> <s> pull, change the note's status (as --status), push
--set-text <id> pull, replace the note's whole text with --text (or
stdin; first line = title), keep its other fields, push
--close <id> --evidence <s>
pull, set status done + evidence (commit sha + done
check exit code), push; refused without --evidence
--backfill-created-by [--dry-run]
pull, set created_by (claude|kuhy) on every note that
has none, push; --dry-run prints the plan only
--data-dir <dir> local log + node id (default
$XDG_DATA_HOME/todo-cli or ~/.local/share/todo-cli)
-h, --help this text

View File

@ -32,7 +32,7 @@ Note findNote(Iterable<Note> notes, String ref) {
return matches.single;
}
/// `<8-char id>\t<status>\t<priority>\t<repo or ->\t<title>`.
/// `<8-char id>\t<status>\t<priority>\t<repo or ->\t<title>\t<created_by>`.
String listLine(Note note) => [
if (note.id.length <= _minPrefix)
note.id
@ -42,6 +42,7 @@ String listLine(Note note) => [
note.priority.name,
note.repo ?? '-',
_title(note),
note.createdBy ?? 'kuhy',
].join('\t');
String _title(Note note) => note.text.split('\n').first;
@ -57,6 +58,7 @@ String noteDetail(Note note) => [
if (note.doneCheck case final v?) 'done_check: $v',
if (note.by case final v?) 'by: $v',
if (note.evidence case final v?) 'evidence: $v',
'created_by: ${note.createdBy ?? 'kuhy'}',
'---',
note.text,
].join('\n');

View File

@ -0,0 +1,58 @@
import 'dart:async';
import 'package:http/http.dart' as http;
/// An HTTP client whose every request is bounded.
///
/// `package:http` has no timeout of its own, and neither do the Firebase and
/// token clients built on it: one dead connection (after boot, a network
/// blip) made a sync wait forever and wedged the MCP server's serial queue.
/// [timeout] bounds the wait for the response headers and then each gap
/// between body chunks, so a large body that keeps moving is never cut off.
class TimeoutClient extends http.BaseClient {
/// Wraps [_inner]; each wait fails with a [TimeoutException] after [timeout].
TimeoutClient(this._inner, {this.timeout = const Duration(seconds: 30)});
final http.Client _inner;
/// Longest wait for the headers, and for the next body chunk.
final Duration timeout;
@override
Future<http.StreamedResponse> send(http.BaseRequest request) async {
final response = await _inner
.send(request)
.timeout(
timeout,
onTimeout: () => throw TimeoutException(
'${request.method} ${request.url.host} got no response',
timeout,
),
);
return http.StreamedResponse(
response.stream.timeout(
timeout,
onTimeout: (sink) {
sink
..addError(
TimeoutException(
'${request.method} ${request.url.host} body stalled',
timeout,
),
)
..close();
},
),
response.statusCode,
contentLength: response.contentLength,
request: response.request,
headers: response.headers,
isRedirect: response.isRedirect,
persistentConnection: response.persistentConnection,
reasonPhrase: response.reasonPhrase,
);
}
@override
void close() => _inner.close();
}

View File

@ -19,10 +19,14 @@ import 'package:shared_preferences/shared_preferences.dart';
/// sibling to `changesets/<nodeId>.json`.
const String kAdvancedModeRemotePath = 'settings/advancedMode';
/// App-wide, non-sync preferences (currently just `advancedMode`).
/// App-wide, non-sync preferences (`advancedMode`, `showClaudeNotes`).
class AppSettings {
/// Creates an [AppSettings] from its stored fields.
const AppSettings({required this.advancedMode, this.advancedModeUpdatedAt});
const AppSettings({
required this.advancedMode,
this.advancedModeUpdatedAt,
this.showClaudeNotes = false,
});
/// Whether the priority/status/template/mode chrome and the routine
/// save/sync status text are shown. Off by default: casual capture needs
@ -35,6 +39,11 @@ class AppSettings {
/// a value that has never round-tripped through Firebase.
final DateTime? advancedModeUpdatedAt;
/// Whether the notes list shows notes Claude filed. Per device: it lives
/// only in this device's preferences and is never mirrored to Firebase.
final bool showClaudeNotes;
static const _kShowClaude = 'app.showClaudeNotes';
static const _kAdvancedMode = 'app.advancedMode';
static const _kAdvancedModeUpdatedAt = 'app.advancedMode.updatedAt';
@ -44,6 +53,7 @@ class AppSettings {
final updatedAtMillis = prefs.getInt(_kAdvancedModeUpdatedAt);
return AppSettings(
advancedMode: prefs.getBool(_kAdvancedMode) ?? false,
showClaudeNotes: prefs.getBool(_kShowClaude) ?? false,
advancedModeUpdatedAt: updatedAtMillis == null
? null
: DateTime.fromMillisecondsSinceEpoch(updatedAtMillis),
@ -71,6 +81,7 @@ class AppSettings {
final updated = AppSettings(
advancedMode: value,
advancedModeUpdatedAt: updatedAt,
showClaudeNotes: showClaudeNotes,
);
if (client != null) {
try {
@ -89,6 +100,17 @@ class AppSettings {
return updated;
}
/// Persists the per-device Claude-notes choice; nothing leaves the device.
Future<AppSettings> withShowClaudeNotes({required bool value}) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_kShowClaude, value);
return AppSettings(
advancedMode: advancedMode,
advancedModeUpdatedAt: advancedModeUpdatedAt,
showClaudeNotes: value,
);
}
/// Pulls the remote value from [client] and, if it is newer than the
/// local one, applies it locally and returns the reconciled settings.
/// Returns this instance unchanged when [client] is null, there is
@ -100,9 +122,7 @@ class AppSettings {
try {
final remote = await client.getStringMap(kAdvancedModeRemotePath);
if (!remote.containsKey('value')) return this;
final remoteUpdatedMillis = int.tryParse(
remote['updatedAtMillis'] ?? '',
);
final remoteUpdatedMillis = int.tryParse(remote['updatedAtMillis'] ?? '');
if (remoteUpdatedMillis == null) return this;
final remoteUpdatedAt = DateTime.fromMillisecondsSinceEpoch(
remoteUpdatedMillis,
@ -110,6 +130,7 @@ class AppSettings {
final candidate = AppSettings(
advancedMode: remote['value'] == 'true',
advancedModeUpdatedAt: remoteUpdatedAt,
showClaudeNotes: showClaudeNotes,
);
final adopted = adopt(candidate);
if (identical(adopted, this)) return this;

View File

@ -0,0 +1,44 @@
/// Who filed a note, for notes written before `created_by` existed.
///
/// The `created_at` field's clock names the node that last wrote it. The MCP
/// and the CLI are the only nodes Claude writes through, so a note created
/// there carries one of their node ids; anything else came from kuhy's own
/// devices.
library;
import 'package:crdt_sync/crdt_sync.dart';
import 'package:todo/data/note_record.dart';
const _createdAt = 'created_at';
/// `claude` when [record]'s `created_at` was written by one of [claudeNodes],
/// else `kuhy`.
String classifyCreatedBy(Record record, Set<String> claudeNodes) {
final node = record.fields[_createdAt]?.$2.nodeId;
return node != null && claudeNodes.contains(node) ? 'claude' : 'kuhy';
}
/// Live records of [log] with no `created_by` yet, mapped to their value.
Map<String, String> planCreatedByBackfill(Log log, Set<String> claudeNodes) => {
for (final record in log.values)
if (!record.deleted &&
((record.fields[kCreatedByField]?.$1 as String?) ?? '').isEmpty)
record.id: classifyCreatedBy(record, claudeNodes),
};
/// [incoming], carrying [existing]'s `created_by` when [incoming] has none.
///
/// A store replaces a record wholesale, so an edit that does not know the
/// field (an import of an old backup) would otherwise drop it locally.
Record keepCreatedBy(Record incoming, Record? existing) {
final kept = existing?.fields[kCreatedByField];
if (kept == null || incoming.fields.containsKey(kCreatedByField)) {
return incoming;
}
return Record(
id: incoming.id,
fields: {...incoming.fields, kCreatedByField: kept},
deleted: incoming.deleted,
deletedHlc: incoming.deletedHlc,
);
}

View File

@ -73,11 +73,7 @@ class LegacySqliteMigration {
}
// coverage:ignore-end
static Future<void> _onUpgrade(
CrdtTableExecutor db,
int from,
int to,
) async {
static Future<void> _onUpgrade(CrdtTableExecutor db, int from, int to) async {
if (from < 2) {
await db.execute(
'ALTER TABLE notes ADD COLUMN status INTEGER NOT NULL DEFAULT 0',

38
lib/data/log_watch.dart Normal file
View File

@ -0,0 +1,38 @@
/// A seeded, coalesced stream over the note log's change events.
library;
import 'dart:async';
/// A stream that emits `compute()` when first listened to (the seed), then
/// again after [changes] fires. Seeding in `onListen` -- rather than lazily in
/// an `async*` body -- avoids a race where a write between `listen` and the
/// first generator tick would swallow the initial snapshot.
///
/// Re-emits are coalesced: the first change of a burst arms one
/// zero-duration timer and every further change before it fires is absorbed,
/// so N back-to-back changes cost ONE `compute()` carrying the latest state
/// instead of N full re-queries (each of which repaints the whole list).
/// The timer fires on the next event-loop turn, so tests stay deterministic
/// under `pumpEventQueue` and the widget tester's `pump`.
Stream<T> watchLog<T>(Stream<void> changes, T Function() compute) {
StreamSubscription<void>? sub;
Timer? pending;
late final StreamController<T> controller;
controller = StreamController<T>(
onListen: () {
controller.add(compute());
sub = changes.listen((_) {
pending ??= Timer(Duration.zero, () {
pending = null;
controller.add(compute());
});
});
},
onCancel: () {
pending?.cancel();
pending = null;
return sub?.cancel();
},
);
return controller.stream;
}

View File

@ -76,7 +76,7 @@ enum Status {
}
}
/// The values the optional `by` field may hold: who owns a repo task.
/// The values the optional `by` and `created_by` fields may hold.
const Set<String> kNoteAuthors = {'claude', 'kuhy'};
/// An immutable idea/note record.
@ -99,6 +99,7 @@ class Note {
this.doneCheck,
this.by,
this.evidence,
this.createdBy,
});
/// Builds a [Note] from a raw CRDT query row.
@ -146,6 +147,12 @@ class Note {
/// Proof the task was closed (commit sha + the done check's exit code).
final String? evidence;
/// Who filed the note: one of [kNoteAuthors]; null (older notes) means kuhy.
final String? createdBy;
/// Whether Claude filed this note (hidden by default, sorted last).
bool get isClaudeMade => createdBy == 'claude';
/// Whether this note is a repo task rather than a plain idea.
bool get isRepoTask => repo != null;
@ -162,6 +169,7 @@ class Note {
String? doneCheck,
String? by,
String? evidence,
String? createdBy,
}) {
return Note(
id: id,
@ -174,6 +182,7 @@ class Note {
doneCheck: doneCheck ?? this.doneCheck,
by: by ?? this.by,
evidence: evidence ?? this.evidence,
createdBy: createdBy ?? this.createdBy,
);
}
}

63
lib/data/note_bulk.dart Normal file
View File

@ -0,0 +1,63 @@
/// Partial logs for the multi-note writes: merged in one store write.
///
/// Each write re-serialises the whole log (over a megabyte on a real
/// device), so a bulk action must be one partial log merged once, never one
/// upsert per note. Merging is per field, so a field left out keeps its value
/// and its clock (`created_by` included).
library;
import 'package:crdt_sync/crdt_sync.dart';
import 'package:todo/data/note.dart';
import 'package:todo/data/note_record.dart';
/// Partial records setting [priority] and/or [status] on the live notes of
/// [log] among [ids], all at [hlc].
///
/// Only fields whose value changes are written, plus `updated_at` = [now]
/// (so "last updated" sorting and newer-wins import see the edit). A note
/// with nothing to change, an unknown id and a deleted note are left out.
Log planBulkUpdate(
Log log,
Set<String> ids, {
required Hlc hlc,
required DateTime now,
Priority? priority,
Status? status,
}) {
final plan = <String, Record>{};
for (final id in ids) {
final current = log[id];
if (current == null || current.deleted) continue;
final note = noteFromRecord(current);
final next = note.copyWith(priority: priority, status: status);
if (next.priority == note.priority && next.status == note.status) continue;
// Generated against generated, never against the stored text: a peer's
// `...00Z` (or a web build's millisecond date) would otherwise read as
// a change and get a fresh clock, erasing the `created_at` node signal.
final before = noteFields(note, hlc);
plan[id] = Record(
id: id,
fields: {
for (final MapEntry(:key, :value) in noteFields(
next.copyWith(updatedAt: now),
hlc,
).entries)
if (before[key]?.$1 != value.$1) key: value,
},
);
}
return plan;
}
/// [note] at [hlc] plus a tombstone for each live note of [log] in
/// [removed] (other than [note] itself).
///
/// A merge, not a replace: a field [note] leaves unset keeps its stored
/// value, so this suits notes that only gain content (the repo note an
/// assign appends to), not edits that clear a field.
Log planReplace(Log log, Note note, Iterable<String> removed, Hlc hlc) => {
for (final id in removed)
if (log[id] case final r? when !r.deleted && id != note.id)
id: Record(id: id, fields: const {}, deleted: true, deletedHlc: hlc),
note.id: Record(id: note.id, fields: noteFields(note, hlc)),
};

View File

@ -37,6 +37,7 @@ class NoteFilter {
this.statuses = const {},
this.repo,
this.repoTasksOnly = false,
this.hideClaude = false,
this.createdFrom,
this.createdTo,
this.updatedFrom,
@ -58,6 +59,10 @@ class NoteFilter {
/// Only notes that have a repo (repo tasks). Ideas are excluded.
final bool repoTasksOnly;
/// Leave out notes Claude filed. A view preference rather than a user
/// facet, so it never counts toward [isEmpty] or [activeCount].
final bool hideClaude;
/// Inclusive lower bound (by calendar day) on the creation date.
final DateTime? createdFrom;
@ -104,6 +109,7 @@ class NoteFilter {
Set<Status>? statuses,
String? repo,
bool? repoTasksOnly,
bool? hideClaude,
DateTime? createdFrom,
DateTime? createdTo,
DateTime? updatedFrom,
@ -117,6 +123,7 @@ class NoteFilter {
statuses: statuses ?? this.statuses,
repo: repo ?? this.repo,
repoTasksOnly: repoTasksOnly ?? this.repoTasksOnly,
hideClaude: hideClaude ?? this.hideClaude,
createdFrom: clearCreated ? null : (createdFrom ?? this.createdFrom),
createdTo: clearCreated ? null : (createdTo ?? this.createdTo),
updatedFrom: clearUpdated ? null : (updatedFrom ?? this.updatedFrom),
@ -138,6 +145,7 @@ bool matchesFilter(Note note, NoteFilter filter) {
}
if (filter.repo != null && note.repo != filter.repo) return false;
if (filter.repoTasksOnly && note.repo == null) return false;
if (filter.hideClaude && note.isClaudeMade) return false;
if (filter.priorities.isNotEmpty &&
!filter.priorities.contains(note.priority)) {
return false;
@ -165,8 +173,17 @@ bool _withinDays(DateTime value, DateTime? from, DateTime? to) {
return true;
}
/// The comparator implementing [sort].
/// The comparator implementing [sort]: human-made notes first, Claude-made
/// ones after, and [sort] orders each group.
Comparator<Note> comparatorFor(NoteSort sort) {
final within = _within(sort);
return (a, b) {
if (a.isClaudeMade != b.isClaudeMade) return a.isClaudeMade ? 1 : -1;
return within(a, b);
};
}
Comparator<Note> _within(NoteSort sort) {
switch (sort) {
case NoteSort.createdDesc:
return (a, b) => b.createdAt.compareTo(a.createdAt);

View File

@ -14,6 +14,9 @@ const _doneCheck = 'done_check';
const _by = 'by';
const _evidence = 'evidence';
/// Record field naming who filed the note (`kuhy` or `claude`).
const kCreatedByField = 'created_by';
/// Record fields for [note], all at [hlc]. Unset task fields are omitted, so
/// an idea's record is exactly the v3 field set (and cannot clear a peer's).
Map<String, Field> noteFields(Note note, Hlc hlc) => {
@ -26,6 +29,7 @@ Map<String, Field> noteFields(Note note, Hlc hlc) => {
if (note.doneCheck case final v?) _doneCheck: (v, hlc),
if (note.by case final v?) _by: (v, hlc),
if (note.evidence case final v?) _evidence: (v, hlc),
if (note.createdBy case final v?) kCreatedByField: (v, hlc),
};
/// Reads [record] as a [Note], ignoring unknown fields.
@ -48,6 +52,7 @@ Note noteFromRecord(Record record) {
doneCheck: task(_doneCheck),
by: task(_by),
evidence: task(_evidence),
createdBy: task(kCreatedByField),
);
}

View File

@ -1,7 +1,8 @@
import 'dart:async';
import 'package:crdt_sync/crdt_sync.dart';
import 'package:todo/data/created_by_backfill.dart';
import 'package:todo/data/log_watch.dart';
import 'package:todo/data/note.dart';
import 'package:todo/data/note_bulk.dart';
import 'package:todo/data/note_import.dart';
import 'package:todo/data/note_query.dart';
import 'package:todo/data/note_record.dart';
@ -114,9 +115,57 @@ class NoteRepository {
/// character-by-character autosave: it is cheap and idempotent. All fields
/// share one fresh monotonic clock (they are written together).
Future<void> upsert(Note note) async {
await _store.upsert(
Record(id: note.id, fields: noteFields(note, _store.nextHlc())),
);
await _put(Record(id: note.id, fields: noteFields(note, _store.nextHlc())));
}
Future<void> _put(Record record) =>
_store.upsert(keepCreatedBy(record, _store.get(record.id)));
/// Sets `created_by` on every live note that has none, from the node that
/// wrote its `created_at` (see [classifyCreatedBy]); returns id -> value.
///
/// Writes only that field, at a fresh clock, so no other field's clock
/// moves (a rewrite of `created_at` would erase the signal itself). With
/// [dryRun] nothing is written.
Future<Map<String, String>> backfillCreatedBy(
Set<String> claudeNodes, {
bool dryRun = false,
}) async {
final plan = planCreatedByBackfill(_store.snapshot(), claudeNodes);
if (dryRun || plan.isEmpty) return plan;
final hlc = _store.nextHlc();
await _patch({
for (final e in plan.entries)
e.key: Record(id: e.key, fields: {kCreatedByField: (e.value, hlc)}),
});
return plan;
}
/// Sets [priority] and/or [status] on the live notes [ids] in ONE store
/// write (see [planBulkUpdate]); a no-op when nothing changes.
Future<void> bulkUpdate(
Set<String> ids, {
Priority? priority,
Status? status,
}) => _patch(
planBulkUpdate(
_store.snapshot(),
ids,
hlc: _store.nextHlc(),
now: DateTime.now(),
priority: priority,
status: status,
),
);
/// Saves [note] and deletes [removed] in ONE store write ([planReplace]).
Future<void> saveReplacing(Note note, Iterable<String> removed) =>
_patch(planReplace(_store.snapshot(), note, removed, _store.nextHlc()));
/// Merges a partial log in one write: untouched fields keep their clocks.
Future<void> _patch(Log partial) async {
if (partial.isEmpty) return;
await _store.replaceAll(mergeLogs(_store.snapshot(), partial));
}
/// Soft-deletes a note. The log keeps a sticky tombstone so the deletion
@ -142,10 +191,10 @@ class NoteRepository {
// the import wins locally; the clock decides whether it wins on *other*
// devices, and an import must not win there simply by being recent.
if (local == null) {
await _store.upsert(recordAtNoteTime(note, _nodeId));
await _put(recordAtNoteTime(note, _nodeId));
added++;
} else if (note.updatedAt.isAfter(local.updatedAt)) {
await _store.upsert(recordAtNoteTime(note, _nodeId));
await _put(recordAtNoteTime(note, _nodeId));
updated++;
} else {
skipped++;
@ -165,27 +214,10 @@ class NoteRepository {
Stream<List<Note>> watchNotes({
NoteSort sort = NoteSort.priorityDesc,
NoteFilter filter = const NoteFilter(),
}) => _watch(() => _query(sort, filter));
}) => watchLog(_store.changes, () => _query(sort, filter));
/// Emits the live count of non-deleted notes immediately and on each change.
Stream<int> watchCount() => _watch(_liveCount);
/// A stream that emits `compute()` synchronously when first listened to (the
/// seed), then again on every log change. Seeding in `onListen` — rather than
/// lazily in an `async*` body — avoids a race where a write between `listen`
/// and the first generator tick would swallow the initial snapshot.
Stream<T> _watch<T>(T Function() compute) {
StreamSubscription<void>? sub;
late final StreamController<T> controller;
controller = StreamController<T>(
onListen: () {
controller.add(compute());
sub = _store.changes.listen((_) => controller.add(compute()));
},
onCancel: () => sub?.cancel(),
);
return controller.stream;
}
Stream<int> watchCount() => watchLog(_store.changes, _liveCount);
/// This device's stable node id. Names its file in the sync repo so two
/// devices never write the same path.

75
lib/data/repo_assign.dart Normal file
View File

@ -0,0 +1,75 @@
/// Assigning plain notes to a repo from the UI: each becomes a `## title`
/// section of the repo's one open note ([addRepoTask]), and the original goes.
///
/// Only the data layer: nothing here talks to the board or starts a task.
library;
import 'package:todo/data/note.dart';
import 'package:todo/data/note_repository.dart';
import 'package:todo/data/repo_note.dart';
final _repoShape = RegExp(r'^[\w.-]+/[\w.-]+$');
final _heading = RegExp(r'^(#+)(\s.*)$');
/// Whether [value] looks like `owner/name`.
bool isRepoName(String value) => _repoShape.hasMatch(value.trim());
/// [body] with every heading outside code fences pushed below `##`.
///
/// A repo note splits into tasks at `##` headings, so a template note's own
/// `## what` / `## must` would otherwise turn into tasks of their own.
String demoteHeadings(String body) {
var fenced = false;
final out = <String>[];
for (final line in body.split('\n')) {
if (line.trimLeft().startsWith('```')) fenced = !fenced;
final m = fenced ? null : _heading.firstMatch(line);
if (m == null) {
out.add(line);
continue;
}
final level = m.group(1)!.length;
out.add('${'#' * (level < 2 ? 3 : level + 1)}${m.group(2)}');
}
return out.join('\n');
}
/// Moves the plain [notes] into [repo]'s open note in one write, creating
/// that note when the repo has none; returns the notes refused because
/// they already belong to a repo (left untouched).
Future<List<Note>> assignToRepo(
NoteRepository repository,
List<Note> notes,
String repo,
) async {
final refused = [
for (final n in notes)
if (n.repo != null) n,
];
final plain = [
for (final n in notes)
if (n.repo == null) n,
];
if (plain.isEmpty) return refused;
final first = splitNote(plain.first.text);
var target = (await addRepoTask(
repository,
repo: repo,
title: first.title,
body: demoteHeadings(first.body),
priority: plain.first.priority,
createdBy: 'kuhy',
)).note;
for (final n in plain.skip(1)) {
final (:title, :body) = splitNote(n.text);
target = target.copyWith(
text: '${target.text}\n\n${repoSection(title, demoteHeadings(body))}',
priority: maxPriority(target.priority, n.priority),
);
}
await repository.saveReplacing(
target.copyWith(updatedAt: DateTime.now()),
plain.map((n) => n.id),
);
return refused;
}

View File

@ -71,6 +71,7 @@ Future<RepoAdd> addRepoTask(
String? doneCheck,
Priority priority = Priority.medium,
String? by,
String? createdBy,
}) async {
final section = repoSection(title, body);
final open = (await repository.listNotes(
@ -99,6 +100,7 @@ Future<RepoAdd> addRepoTask(
repo: repo,
doneCheck: composeDoneCheck(null, doneCheck),
by: by,
createdBy: createdBy,
),
appended: false,
);

View File

@ -26,16 +26,24 @@ typedef SplitAdd = ({Note note, SplitKind kind, String? why});
final _heading = RegExp(r'^##\s+(\[x\]\s+)?(.*)$');
/// The open `## title` headings of [text], outside code fences.
Iterable<String> openSections(String text) sync* {
/// Every `## title` heading of [text] outside code fences, open or done.
Iterable<RegExpMatch> _sections(String text) sync* {
var fenced = false;
for (final line in text.split('\n')) {
if (line.trimLeft().startsWith('```')) fenced = !fenced;
final m = fenced ? null : _heading.firstMatch(line);
if (m != null && m.group(1) == null) yield m.group(2)!.trim();
if (m != null) yield m;
}
}
/// The open `## title` headings of [text], outside code fences.
Iterable<String> openSections(String text) => _sections(
text,
).where((m) => m.group(1) == null).map((m) => m.group(2)!.trim());
/// How many board items [text] splits into: one per section, done or not.
int sectionCount(String text) => _sections(text).length;
/// The separate open note of [repo] with an open section titled [title].
Note? duplicateTarget(Iterable<Note> open, String repo, String title) {
final hits =
@ -69,6 +77,7 @@ Future<SplitAdd> addSeparateTask(
String? doneCheck,
Priority priority = Priority.medium,
String? by,
String? createdBy,
Future<bool> Function(Note note)? busy,
}) async {
final section = repoSection(title, body);
@ -105,6 +114,7 @@ Future<SplitAdd> addSeparateTask(
repo: repo,
doneCheck: composeDoneCheck(null, doneCheck),
by: by,
createdBy: createdBy,
),
kind: why == null ? SplitKind.added : SplitKind.fellBack,
why: why,

View File

@ -21,12 +21,21 @@ class LinuxSystemProbe implements SystemProbe {
/// Creates the default host probe.
///
/// [ssExecutable] exists so a test can point at a missing binary and exercise
/// the "no `ss` on PATH" path.
const LinuxSystemProbe({this.ssExecutable = 'ss'});
/// the "no `ss` on PATH" path. [listProc] lets a test fail the `/proc`
/// listing on demand.
const LinuxSystemProbe({this.ssExecutable = 'ss', this.listProc = _listProc});
/// Name of the socket-listing tool used to find the port owner.
final String ssExecutable;
/// Lists `/proc`'s entries.
final List<FileSystemEntity> Function() listProc;
/// How many `/proc` listings a process exiting mid-listing may spoil.
static const _listAttempts = 3;
static List<FileSystemEntity> _listProc() => Directory('/proc').listSync();
@override
Future<int?> listenerPid(int port) async {
try {
@ -56,7 +65,7 @@ class LinuxSystemProbe implements SystemProbe {
@override
Future<List<List<String>>> processCmdlines() async {
final cmdlines = <List<String>>[];
for (final entry in Directory('/proc').listSync()) {
for (final entry in _listProcRetrying()) {
final pid = int.tryParse(p.basename(entry.path));
if (pid == null) continue;
final cmdline = readCmdline(pid);
@ -65,6 +74,19 @@ class LinuxSystemProbe implements SystemProbe {
return cmdlines;
}
/// Dart's listing lstat()s some entries, so a pid that exits between
/// readdir and that lstat fails the whole listing. A fresh listing no
/// longer holds that pid; a few failures in a row mean a real error.
List<FileSystemEntity> _listProcRetrying() {
for (var attempt = 1; ; attempt++) {
try {
return listProc();
} on PathNotFoundException {
if (attempt >= _listAttempts) rethrow;
}
}
}
@override
Future<bool> portInUse(int port) async {
try {

View File

@ -7,6 +7,9 @@ import 'package:path/path.dart' as p;
import 'package:todo/desktop/static_content_type.dart';
import 'package:todo/desktop/wrapper_image_routes.dart';
import 'package:todo/sync/e2e_passphrase_path.dart';
export 'package:todo/sync/e2e_passphrase_path.dart';
export 'wrapper_paths.dart';
@ -86,6 +89,9 @@ class WrapperServer {
/// wrappers also serve, which stays opt-in.
bool _todoCredentialsServed = false;
/// Whether [kSyncE2ePassphrasePath] has served the passphrase yet.
bool _e2ePassphraseServed = false;
/// `todo`'s own seeded Firebase session, written by
/// `crdt-sync/tool/seed_session.py --app todo` in the same
/// `{id_token, refresh_token, expires_at}` shape every other app's
@ -184,6 +190,9 @@ class WrapperServer {
if (path == kSyncCredentialsPath) {
return await _syncCredentials(request);
}
if (path == kSyncE2ePassphrasePath) {
return await _syncE2ePassphrase(request);
}
if (await images.handle(request)) return;
return await _static(request, path);
}

View File

@ -121,4 +121,23 @@ extension _SyncRoutes on WrapperServer {
// through must remain retryable rather than burning the one serve.
_todoCredentialsServed = true;
}
/// Serves the shared crdt-sync password as the E2E passphrase, once per
/// wrapper process, like [_syncCredentials]: the web app stores it in its
/// keystore on first sync and never asks for it.
Future<void> _syncE2ePassphrase(HttpRequest request) async {
final passwordFile = File(p.join(syncConfigDir, 'password'));
if (_e2ePassphraseServed || !passwordFile.existsSync()) {
request.response.statusCode = HttpStatus.notFound;
return;
}
final text = (await passwordFile.readAsString()).trim();
if (text.isEmpty) {
request.response.statusCode = HttpStatus.notFound;
return;
}
request.response.headers.contentType = ContentType.text;
request.response.write(text);
_e2ePassphraseServed = true;
}
}

View File

@ -1,8 +1,10 @@
// coverage:ignore-file
// App bootstrap: opens the platform's note store and calls runApp. Exercised
// end-to-end by running the app, not unit tests.
import 'package:crdt_sync_flutter/crdt_sync_flutter.dart'
show AppErrors, AppErrorsConfig, AppErrorsRouteObserver, installAppErrors;
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/analytics/analytics_service.dart';
import 'package:todo/attachments/image_store.dart';
import 'package:todo/attachments/image_store_scope.dart';
@ -10,16 +12,36 @@ import 'package:todo/data/app_settings.dart';
import 'package:todo/data/note_repository.dart';
import 'package:todo/data/repository_factory.dart';
import 'package:todo/frame_stats.dart';
import 'package:todo/sync/firebase_client.dart' show openFirebase;
import 'package:todo/ui/capture_screen.dart';
import 'package:todo/ui/text_free_localizations.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// Every error and every wait over 1 s goes to the PC's app-errors ingest,
// which files a board ticket (kuhyx/utils DOCS-app-errors.md). The release
// build passes the versionCode and name as dart-defines (release-apk.yml).
final errors = await installAppErrors(
const AppErrorsConfig(
app: 'todo',
repo: 'kuhyx/todo-app',
package: 'todo',
// 0 unless the build passes --dart-define=APP_BUILD.
// ignore: avoid_redundant_argument_values
build: int.fromEnvironment('APP_BUILD'),
version: String.fromEnvironment('APP_VERSION'),
),
);
installFrameStats();
// Where the log lives, and whether a legacy sqlite DB needs importing, is
// platform-specific and resolved by a conditional import: `dart:io` cannot be
// imported at all in a web compile, and the desktop app is now a web build.
final repository = await openRepository();
errors.connect(
sink: () async => (await openFirebase())?.patchValues,
deviceId: () async => repository.nodeId,
);
final appSettings = ValueNotifier(await AppSettings.load());
final analytics = AnalyticsService(nodeId: repository.nodeId);
// App storage + direct dufs on Android; the wrapper's /images on desktop.
@ -31,6 +53,7 @@ Future<void> main() async {
appSettings: appSettings,
analytics: analytics,
imageStore: imageStore,
errors: errors,
),
);
}
@ -45,6 +68,7 @@ class TodoApp extends StatelessWidget {
required this.appSettings,
required this.analytics,
required this.imageStore,
this.errors,
super.key,
});
@ -62,6 +86,9 @@ class TodoApp extends StatelessWidget {
/// The single, app-wide store for attached images.
final ImageStore imageStore;
/// App-wide error reporting; null in widget tests.
final AppErrors? errors;
@override
Widget build(BuildContext context) {
// Above MaterialApp so pushed routes (note detail) see it too.
@ -69,8 +96,12 @@ class TodoApp extends StatelessWidget {
store: imageStore,
child: MaterialApp(
title: 'todo',
localizationsDelegates: kTextFreeLocalizations,
theme: buildLightTheme(),
darkTheme: buildDarkTheme(),
navigatorObservers: [
if (errors case final errors?) AppErrorsRouteObserver(errors),
],
home: CaptureScreen(
repository: repository,
appSettings: appSettings,

View File

@ -5,6 +5,7 @@
/// a board that is down must not lose the task that was just saved.
library;
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
@ -19,17 +20,34 @@ final _csrf = RegExp(r'<meta\s+name="todoimpl-csrf"\s+content="([^"]+)"');
/// Talks to the board over [client] at [base].
class BoardClient {
/// [client] is injectable so tests need no network.
BoardClient({http.Client? client, Uri? base})
: _http = client ?? http.Client(),
base = base ?? kBoardBase;
/// [client] is injectable so tests need no network. [wait] bounds how
/// long Start waits for the board to see a merged section (its note cache
/// lags ~10 s, T1863) and to confirm a Start whose reply outran
/// [startTimeout] (T1864); [poll] is the gap between board reads.
BoardClient({
http.Client? client,
Uri? base,
this.wait = const Duration(seconds: 30),
this.poll = const Duration(seconds: 1),
this.startTimeout = const Duration(seconds: 30),
}) : _http = client ?? http.Client(),
base = base ?? kBoardBase;
final http.Client _http;
/// The board's origin; also the `Origin` header of a POST.
final Uri base;
static const _timeout = Duration(seconds: 5);
/// Longest wait for the board to catch up with the note.
final Duration wait;
/// Gap between two board reads while waiting.
final Duration poll;
/// Longest wait for the reply to a Start POST.
final Duration startTimeout;
static const _timeout = Duration(seconds: 10);
Future<List<Map<String, dynamic>>> _cards(String noteId) async {
final res = await _http.get(base.resolve('/api/board')).timeout(_timeout);
@ -54,30 +72,79 @@ class BoardClient {
}
}
/// Clicks Start on the note's last startable item titled [title].
Future<StartResult> start(String noteId, String title) async {
/// Clicks Start on the note's last startable item titled [title]. With
/// [sections], that is the note's last section (`<id8>-<sections - 1>`),
/// which a merge just added: waits until the board shows it.
Future<StartResult> start(
String noteId,
String title, {
int? sections,
}) async {
try {
final card = (await _cards(noteId)).reversed
.where((c) => c['title'] == title && _startable(c))
.firstOrNull;
final last = sections == null ? null : _item(noteId, sections - 1);
bool seen(List<Map<String, dynamic>> cs) =>
last == null || cs.any((c) => c['id'] == last);
final cards = await _until(noteId, seen);
// Exactly the merged item: never an older same-titled one, which the
// board may list last (it orders by column, T1866).
final card = seen(cards)
? cards.reversed
.where((c) => last == null || c['id'] == last)
.where((c) => c['title'] == title && _startable(c))
.firstOrNull
: null;
if (card == null) return _no('no startable item');
final page = await _http.get(base).timeout(_timeout);
final token = _csrf.firstMatch(page.body)?.group(1);
if (token == null) return _no('no CSRF token on the board page');
final id = card['id']! as String;
final res = await _http
.post(
base.resolve('/api/task/$id/start'),
headers: {'Origin': base.origin, 'X-Todoimpl-Token': token},
)
.timeout(_timeout);
if (res.statusCode == 200) return (ok: true, reason: null, item: id);
return _no('board refused start: ${res.statusCode} ${_message(res)}');
return await _post(noteId, id, token);
} on Object catch (e) {
return _no('board unreachable: $e');
}
}
Future<StartResult> _post(String noteId, String id, String token) async {
final http.Response res;
try {
res = await _http
.post(
base.resolve('/api/task/$id/start'),
headers: {'Origin': base.origin, 'X-Todoimpl-Token': token},
)
.timeout(startTimeout);
} on TimeoutException catch (e) {
// The board may still be starting it: a card that left Start took it.
final cards = await _until(
noteId,
(cs) => cs.any((c) => c['id'] == id && !_startable(c)),
);
if (cards.any((c) => c['id'] == id && !_startable(c))) {
return (ok: true, reason: null, item: id);
}
return _no('board unreachable: $e');
}
if (res.statusCode == 200) return (ok: true, reason: null, item: id);
return _no('board refused start: ${res.statusCode} ${_message(res)}');
}
/// The note's cards once [done] holds, or the last read after [wait].
Future<List<Map<String, dynamic>>> _until(
String noteId,
bool Function(List<Map<String, dynamic>>) done,
) async {
final deadline = DateTime.now().add(wait);
var cards = await _cards(noteId);
while (!done(cards) && DateTime.now().isBefore(deadline)) {
await Future<void>.delayed(poll);
cards = await _cards(noteId);
}
return cards;
}
static String _item(String noteId, int index) =>
'${noteId.substring(0, 8)}-$index';
static bool _startable(Map<String, dynamic> card) => (card['actions'] as List)
.cast<Map<String, dynamic>>()
.any((a) => a['id'] == 'start' && a['enabled'] == true);

View File

@ -0,0 +1,40 @@
import 'dart:async';
import 'dart:io';
/// Answers 503 here because the library can only say 403 for a refusal; it
/// then fails to write its own 403 ("Header already sent", swallowed by the
/// zone guard in `TodoMcpServer.start`) and the request stays refused.
bool answerUnavailable(HttpRequest request) {
request.response
..statusCode = HttpStatus.serviceUnavailable
..write('Service Unavailable')
..close().ignore();
return false;
}
/// Closes [request]'s response with 503 once [deadline] passes, unless it was
/// answered first. Safe on any state: a response already closed or a dead
/// socket is ignored.
void guardDeadline(HttpRequest request, Duration deadline) {
if (request.method == 'GET') return;
final response = request.response;
final timer = Timer(deadline, () async {
try {
response
..statusCode = HttpStatus.serviceUnavailable
..write('Request timed out');
} on Object {
// Headers already sent: just end the stream.
}
try {
await response.close();
} on Object {
// The peer is gone; the socket is released either way.
}
});
unawaited(
response.done
.then<void>((_) {}, onError: (_) {})
.whenComplete(timer.cancel),
);
}

View File

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:todo/cli/cli_args.dart';
import 'package:todo/cli/cli_session.dart';
import 'package:todo/cli/note_lookup.dart';
@ -6,46 +8,84 @@ import 'package:todo/data/note_repository.dart';
import 'package:todo/data/repo_note.dart';
import 'package:todo/mcp/board_client.dart';
import 'package:todo/mcp/task_split.dart';
import 'package:todo/sync/sync_service.dart';
/// The six task tools over one persistent sync node; calls run one at a time.
class TaskService {
/// Serves [_session]'s notes; every call pulls first, writes then push.
/// [board] is the todoImplementer board `new_note` checks and starts on.
TaskService(this._session, {this._board});
///
/// A call that outlives [callTimeout] (a sync stuck on a dead connection)
/// fails with a TimeoutException instead of holding every later call, so
/// the queue never wedges and abandoned requests do not pile up sockets.
TaskService(
this._session, {
this._board,
this.callTimeout = const Duration(seconds: 60),
this.readFreshness = const Duration(seconds: 2),
});
final CliSession _session;
final BoardClient? _board;
/// Longest one call may run before it fails with a TimeoutException.
final Duration callTimeout;
/// How long a finished sync still counts for the read calls (list, search,
/// get). The board reads 15 times per fetch and each sync is a Firebase
/// round trip of 0.5-1 s, so reads inside the window skip it; every write
/// still pulls and pushes. [Duration.zero] syncs on every read.
final Duration readFreshness;
final Stopwatch _since = Stopwatch();
Future<void> _tail = Future.value();
Future<String> _serial(Future<String> Function() body) {
final run = _tail.then((_) => body());
Future<T> _serial<T>(Future<T> Function() body) {
final run = _tail.then((_) => body()).timeout(callTimeout);
_tail = run.then((_) {}, onError: (_) {});
return run;
}
Future<List<Note>> _pull() async {
final skipped = (await _session.sync(push: true)).skippedFiles;
if (skipped.isNotEmpty) throw StateError('sync: unmergeable $skipped');
Future<SyncResult> _sync() async {
final result = await _session.sync(push: true);
_since
..reset()
..start();
return result;
}
/// Pulls every peer, unless [read] and a sync ended within [readFreshness].
Future<List<Note>> _pull({bool read = false}) async {
final fresh = _since.isRunning && _since.elapsed < readFreshness;
if (!read || !fresh) {
final skipped = (await _sync()).skippedFiles;
if (skipped.isNotEmpty) throw StateError('sync: unmergeable $skipped');
}
return await _session.repository.listNotes();
}
Future<String> _save(Note note, String verb) async {
await _session.repository.upsert(note.copyWith(updatedAt: DateTime.now()));
await _session.sync(push: true);
await _sync();
return '$verb ${note.id}\n${listLine(note)}';
}
Future<Note> _find(_Args a) async {
Future<Note> _find(_Args a, {bool read = false}) async {
final id = a.required('id');
try {
return findNote(await _pull(), id);
return findNote(await _pull(read: read), id);
} on NoteLookupError catch (e) {
throw FormatException('id: $e');
}
}
/// `add_task`: joins the repo's open note (by: claude), or creates it.
Future<String> add(Map<String, dynamic> args) => _serial(() async {
/// `add_task`: joins the repo's open note (by: claude), or creates it. A
/// board Start after a merge runs once the other calls may go again.
Future<String> add(Map<String, dynamic> args) async {
final (:reply, :start) = await _serial(() => _add(args));
return start == null ? reply : '$reply\n${await start()}';
}
Future<SplitReply> _add(Map<String, dynamic> args) async {
final a = _Args(args);
final repo = a.repo(required: true)!;
final title = a.required('title');
@ -70,27 +110,30 @@ class TaskService {
doneCheck: a.optional('done_check'),
priority: a.priority() ?? Priority.medium,
by: 'claude',
createdBy: 'claude',
);
return await _save(added.note, added.appended ? 'appended to' : 'added');
});
final verb = added.appended ? 'appended to' : 'added';
return (reply: await _save(added.note, verb), start: null);
}
/// `list_tasks`: repo tasks, open ones unless `status` says otherwise.
/// `list_tasks`: repo tasks, open ones unless `status` says otherwise;
/// `no_repo: true` lists the repo-less notes (ideas) instead.
Future<String> list(Map<String, dynamic> args) => _serial(() async {
final a = _Args(args);
final repo = a.repo();
final statuses = a.statuses();
await _pull();
return _lines(
await _session.repository.listNotes(
filter: NoteFilter(statuses: statuses, repo: repo, repoTasksOnly: true),
),
final ideas = a.flag('no_repo');
await _pull(read: true);
final notes = await _session.repository.listNotes(
filter: NoteFilter(statuses: statuses, repo: repo, repoTasksOnly: !ideas),
);
return _lines(ideas ? notes.where((n) => n.repo == null).toList() : notes);
});
/// `search_tasks`: repo tasks of any status whose text or repo matches.
Future<String> search(Map<String, dynamic> args) => _serial(() async {
final query = _Args(args).required('query');
await _pull();
await _pull(read: true);
return _lines(
await _session.repository.listNotes(
filter: NoteFilter(query: query, repoTasksOnly: true),
@ -100,7 +143,7 @@ class TaskService {
/// `get_task`: one note in full.
Future<String> get(Map<String, dynamic> args) =>
_serial(() async => noteDetail(await _find(_Args(args))));
_serial(() async => noteDetail(await _find(_Args(args), read: true)));
/// `update_task`: changes only the keys given; `done_check: ""` clears it.
Future<String> update(Map<String, dynamic> args) => _serial(() async {

View File

@ -10,9 +10,14 @@ import 'package:todo/mcp/board_client.dart';
/// Saves [note] and returns `<verb> <id>` plus its list line.
typedef SaveNote = Future<String> Function(Note note, String verb);
/// Adds a separate task, merging into a duplicate's note when it is idle,
/// and clicks Start on the board after a merge that may run.
Future<String> addSplit(
/// A saved split add: its reply so far, and the board Start still to run.
/// The caller runs [start] after releasing its lock, since the board learns
/// about the merged section by calling this same server (T1865).
typedef SplitReply = ({String reply, Future<String> Function()? start});
/// Adds a separate task, merging into a duplicate's note when it is idle;
/// a merge that may run comes back with the Start to click on the board.
Future<SplitReply> addSplit(
NoteRepository repository,
BoardClient? board,
SaveNote save, {
@ -30,19 +35,33 @@ Future<String> addSplit(
doneCheck: doneCheck,
priority: priority,
by: 'claude',
createdBy: 'claude',
busy: board == null ? null : (n) => board.running(n.id),
);
if (added.kind != SplitKind.merged) {
final reply = await save(added.note, 'added');
return added.why == null ? reply : '$reply\n${added.why}';
return (
reply: added.why == null ? reply : '$reply\n${added.why}',
start: null,
);
}
final reply = await save(added.note, 'merged into');
final block = startBlock(doneCheck, body);
if (block != null) return '$reply\nstart: skipped ($block)';
final start = board == null
? (ok: false, reason: 'no board configured', item: null)
: await board.start(added.note.id, title.trim());
if (start.ok) return '$reply\nstart: ok ${start.item}';
return '$reply\nstart: {ok: false, reason: "${start.reason}"}; '
'the merge is saved, click Start on the board by hand';
if (block != null) {
return (reply: '$reply\nstart: skipped ($block)', start: null);
}
Future<String> start() async {
final s = board == null
? (ok: false, reason: 'no board configured', item: null)
: await board.start(
added.note.id,
title.trim(),
sections: sectionCount(added.note.text),
);
if (s.ok) return 'start: ok ${s.item}';
return 'start: {ok: false, reason: "${s.reason}"}; '
'the merge is saved, click Start on the board by hand';
}
return (reply: reply, start: start);
}

View File

@ -1,6 +1,8 @@
import 'dart:async';
import 'dart:io';
import 'package:mcp_dart/mcp_dart.dart';
import 'package:todo/mcp/request_guard.dart';
import 'package:todo/mcp/task_service.dart';
import 'package:todo/mcp/token_file.dart';
@ -34,26 +36,50 @@ class TodoMcpServer {
/// `http://<host>:<bound port>/mcp`.
Uri get uri => Uri.parse('http://${_http.host}:${_http.boundPort}/mcp');
/// Binds [host]:[port] (0 = any free port); [tokens] is read per request.
/// Binds [host]:[port] (0 = any free port); [tokens] is loaded once and
/// re-read when its mtime changes, errors going to [log] (default stderr).
///
/// A POST or DELETE that has no answer after [requestDeadline] is closed
/// with 503, which also frees its socket when the client already gave up
/// (Dart's HttpServer never notices a half-closed idle request). Keep it
/// above [TaskService.callTimeout] so a stuck tool call reports its own
/// error first. GET streams are long-lived by design and exempt.
static Future<TodoMcpServer> start({
required TaskService tasks,
required File tokens,
String host = '127.0.0.1',
int port = kTodoMcpPort,
Duration requestDeadline = const Duration(seconds: 90),
void Function(String)? log,
}) async {
final out = log ?? (String line) => stderr.writeln(line);
final store = TokenStore(tokens, log: out);
final http = StreamableMcpServer(
serverFactory: (_) => _server(tasks),
host: host,
port: port,
authenticator: (request) => tokenAccepted(
tokens,
request is HttpRequest
? request.headers.value(HttpHeaders.authorizationHeader)
: null,
),
authenticator: (request) {
if (request is! HttpRequest) return false;
guardDeadline(request, requestDeadline);
return switch (store.verdict(
request.headers.value(HttpHeaders.authorizationHeader),
)) {
TokenVerdict.accepted => true,
TokenVerdict.rejected => false,
TokenVerdict.unavailable => answerUnavailable(request),
};
},
allowedHosts: const {'localhost', '127.0.0.1', '::1', _publicHost},
);
await http.start();
// The library runs each request as an unawaited future in the zone that
// called start(): without a guard, one failed write (a response we closed
// first) would be an uncaught error and kill the process.
await runZonedGuarded(http.start, (error, stack) {
if (error is StateError && '$error'.contains('Header already sent')) {
return; // the library answering a request we already answered
}
out('todo-mcp: request error: $error');
});
return TodoMcpServer._(http);
}
@ -116,9 +142,14 @@ McpServer _server(TaskService tasks) {
tool(
'list_tasks',
'List repo tasks, one line each: 8-char id, status, priority, repo, '
'title. Default status "open" (todo + in_progress).',
'title, created_by (kuhy|claude). Default status "open" '
'(todo + in_progress). no_repo: true lists the notes WITHOUT a repo '
'(ideas) instead.',
{
'repo': repo,
'no_repo': JsonSchema.boolean(
description: 'List only notes that have no repo (repo shows as -).',
),
'status': JsonSchema.string(
description: 'open | all | todo | in_progress | done | abandoned.',
),

View File

@ -5,27 +5,78 @@ import 'package:crdt_sync/crdt_sync.dart';
/// sha256 hex of [token] (crdt_sync's `revisionOf` is exactly that).
String tokenHash(String token) => revisionOf(token);
Set<String> _hashes(File tokens) {
final String text;
try {
text = tokens.readAsStringSync();
} on FileSystemException {
return const {};
/// What the tokens file says about one `Authorization` header.
enum TokenVerdict {
/// A listed token: let the request in.
accepted,
/// Missing, malformed or unlisted: HTTP 403.
rejected,
/// No token set has ever loaded, so nothing can be judged: HTTP 503.
unavailable,
}
/// The sha256-hashed bearer tokens of [file], loaded once.
///
/// A request costs one `stat`; the file is re-read only when its mtime or
/// size changed. A failed read keeps the last good set (an exhausted fd table
/// once made every valid token read as "no tokens", i.e. 403) and is logged
/// once per distinct error. Until a first good load every well-formed bearer
/// is [TokenVerdict.unavailable], never a refusal.
class TokenStore {
/// Watches [file]; [log] gets read errors.
TokenStore(this.file, {required this.log});
/// The `<sha256> <name>` lines, `#` comments allowed.
final File file;
/// Receives read errors, one line each.
final void Function(String) log;
Set<String>? _hashes;
(DateTime, int)? _seen;
String? _lastError;
/// Judges [authorization] (an `Authorization` header value or null).
TokenVerdict verdict(String? authorization) {
const scheme = 'bearer ';
if (authorization == null ||
!authorization.toLowerCase().startsWith(scheme)) {
return TokenVerdict.rejected;
}
final token = authorization.substring(scheme.length).trim();
if (token.isEmpty) return TokenVerdict.rejected;
_refresh();
final hashes = _hashes;
if (hashes == null) return TokenVerdict.unavailable;
return hashes.contains(tokenHash(token))
? TokenVerdict.accepted
: TokenVerdict.rejected;
}
return {
void _refresh() {
try {
final stat = file.statSync();
if (stat.type == FileSystemEntityType.notFound) {
throw FileSystemException('no such file', file.path);
}
final key = (stat.modified, stat.size);
if (key == _seen) return;
_hashes = _parse(file.readAsStringSync());
_seen = key;
_lastError = null;
} on FileSystemException catch (e) {
// Keep the last good set; `_seen` stays, so the next request retries.
final message = '${e.message} ${e.path} ${e.osError?.errorCode}';
if (message != _lastError) log('tokens: keeping last set: $message');
_lastError = message;
}
}
static Set<String> _parse(String text) => {
for (final line in text.split('\n'))
if (line.trim() case final t when t.isNotEmpty && !t.startsWith('#'))
t.split(RegExp(r'\s+')).first.toLowerCase(),
};
}
/// Whether [authorization] bears a token hashed in [tokens], read per call.
bool tokenAccepted(File tokens, String? authorization) {
const scheme = 'bearer ';
if (authorization == null ||
!authorization.toLowerCase().startsWith(scheme)) {
return false;
}
final token = authorization.substring(scheme.length).trim();
return token.isNotEmpty && _hashes(tokens).contains(tokenHash(token));
}

View File

@ -0,0 +1,9 @@
/// Path of the wrapper's one-shot passphrase route.
///
/// Kept apart from `e2e_passphrase_source.dart` (which needs Flutter) so the
/// dart-only desktop wrapper can import it; `dart build cli` fails on any
/// transitive `dart:ui`.
library;
/// The route the wrapper serves the passphrase on, once.
const kSyncE2ePassphrasePath = '/sync-e2e-passphrase';

View File

@ -0,0 +1,38 @@
/// Where todo gets the shared crdt-sync passphrase its E2E key comes from.
///
/// The keystore first. On the desktop (a web build behind the local
/// wrapper) an empty keystore adopts the wrapper's one-shot
/// `/sync-e2e-passphrase` route, which serves `~/.config/crdt-sync/password`,
/// so the desktop app never asks. Android has no wrapper (`Uri.base` is
/// `file:///`) and is unlocked through the settings lock tile instead.
library;
import 'package:crdt_sync_flutter/crdt_sync_flutter.dart'
show kE2ePassphraseKey, kSecureStorage, saveE2ePassphrase;
import 'package:http/http.dart' as http;
import 'package:todo/sync/e2e_passphrase_path.dart';
export 'package:todo/sync/e2e_passphrase_path.dart';
/// Returns the passphrase, adopting the wrapper's once; null when none.
Future<String?> readE2ePassphrase({Uri? base, http.Client? client}) async {
final stored = await kSecureStorage.read(key: kE2ePassphraseKey);
if (stored != null && stored.isNotEmpty) return stored;
final origin = base ?? Uri.base;
if (origin.scheme != 'http' && origin.scheme != 'https') return null;
final httpClient = client ?? http.Client();
try {
final response = await httpClient.get(
origin.resolve(kSyncE2ePassphrasePath),
);
final text = response.body.trim();
if (response.statusCode != 200 || text.isEmpty) return null;
await saveE2ePassphrase(text);
return text;
} on Object {
// No wrapper, or it already served: this device is simply locked.
return null;
} finally {
if (client == null) httpClient.close();
}
}

View File

@ -92,6 +92,7 @@ class NotesMarkdown {
doneCheck: attrs['done_check'],
by: attrs['by'],
evidence: attrs['evidence'],
createdBy: attrs['created_by'],
),
);
}
@ -113,6 +114,7 @@ class NotesMarkdown {
('done_check', note.doneCheck),
('by', note.by),
('evidence', note.evidence),
('created_by', note.createdBy),
])
if (value != null) ' $name="${_escape(value)}"',
].join();

7
lib/sync/off_thread.dart Normal file
View File

@ -0,0 +1,7 @@
/// Runs CPU-heavy, pure work away from the UI thread where the platform can.
///
/// Conditional export because `dart:isolate` does not run in a browser: the
/// web desktop build runs the work inline, everything else on a fresh isolate.
library;
export 'off_thread_io.dart' if (dart.library.js_interop) 'off_thread_web.dart';

View File

@ -0,0 +1,7 @@
import 'dart:isolate';
/// Runs [work] on a short-lived isolate and returns its result.
///
/// The result comes back through `Isolate.exit`, so a large parsed log is
/// handed over rather than copied.
Future<R> offThread<R>(R Function() work) => Isolate.run(work);

View File

@ -0,0 +1,2 @@
/// Runs [work] inline: a browser has no isolates for it.
Future<R> offThread<R>(R Function() work) async => work();

78
lib/sync/peer_pull.dart Normal file
View File

@ -0,0 +1,78 @@
/// Pulls the peers whose logs changed, all at once and off the UI thread.
///
/// Split out of `sync_service.dart` for file size. A peer's log is about
/// 2 MB; pulling eight of them one after another, each parsed on the UI
/// isolate, kept the phone's sync spinner up for 3.9 s (todo:0c575b891b).
library;
import 'package:crdt_sync/crdt_sync.dart';
import 'package:todo/sync/off_thread.dart';
/// One peer file's pull result: its decoded [log] and revision, or a null
/// [log] when the file vanished, failed decryption or did not parse.
typedef PulledPeer = ({String name, String peer, Log? log, String? rev});
/// Fetches [names] (file names under [dir]) concurrently.
///
/// [knownRevs] holds each peer's published revision; a peer without one gets
/// its revision computed from the downloaded text. Any failure other than an
/// [E2eDecryptError] fails the pull, exactly as a sequential loop would.
Future<List<PulledPeer>> pullPeers(
RemoteStore remote,
String dir,
List<String> names,
Map<String, String> knownRevs,
) => Future.wait([
for (final name in names) _pull(remote, dir, name, knownRevs[peerOf(name)]),
], eagerError: true);
/// Peer id of a `<peer>.json` file name.
String peerOf(String name) =>
name.endsWith('.json') ? name.substring(0, name.length - 5) : name;
Future<PulledPeer> _pull(
RemoteStore remote,
String dir,
String name,
String? knownRev,
) async {
final peer = peerOf(name);
final String? text;
try {
text = await remote.getFileText('$dir/$name');
} on E2eDecryptError {
// Wrong key, tampered blob or a newer format: skipped and reported,
// never merged and never fatal.
return (name: name, peer: peer, log: null, rev: null);
}
if (text == null) return (name: name, peer: peer, log: null, rev: null);
final (log, rev) = await _decodeOffThread(text, knownRev);
return (name: name, peer: peer, log: log, rev: rev);
}
/// Below this many characters a log parses faster than an isolate starts.
const int _offThreadMinLength = 64 * 1024;
/// Kept separate so the isolate closure captures only [text] and [knownRev].
Future<(Log?, String)> _decodeOffThread(String text, String? knownRev) async {
(Log?, String) decode() => (decodeLog(text), knownRev ?? revisionOf(text));
return text.length < _offThreadMinLength ? decode() : await offThread(decode);
}
/// Parses a remote note log, returning `null` for a corrupt or wrong-shape
/// payload so one bad device file never aborts the whole sync.
Log? decodeLog(String text) {
try {
return logFromJson(text);
} on FormatException {
return null;
}
// crdt_sync's logFromJson throws a raw TypeError (not a custom
// exception) for a wrong-shape JSON payload from an untrusted peer
// file; must be caught too so one bad device file never aborts the
// whole sync (see doc comment above).
// ignore: avoid_catching_errors
on TypeError {
return null;
}
}

View File

@ -7,15 +7,26 @@
library;
import 'package:crdt_sync/crdt_sync.dart';
import 'package:crdt_sync_flutter/crdt_sync_flutter.dart' show keystoreKeyCache;
import 'package:flutter/foundation.dart' show ValueNotifier, visibleForTesting;
import 'package:http/http.dart' as http;
import 'package:todo/analytics/analytics_service.dart';
import 'package:todo/data/app_settings.dart';
import 'package:todo/data/note_repository.dart';
import 'package:todo/sync/e2e_passphrase_source.dart';
import 'package:todo/sync/firebase_backend.dart';
import 'package:todo/sync/sync_service.dart';
import 'package:todo/sync/sync_settings.dart';
import 'package:todo/sync/sync_state_factory.dart';
/// Argon2id cost for new headers; only tests lower it.
@visibleForTesting
Argon2Params e2eArgon2Params = Argon2Params.recommended;
/// Whether the last sync found no usable end-to-end key; drives the lock
/// tile in settings.
final ValueNotifier<bool> e2eLocked = ValueNotifier<bool>(false);
/// Bundles a [SyncResult] with the [AppSettings] as reconciled against the
/// same Firebase session — so a settings change made on another device is
/// picked up without a second authenticated round trip.
@ -44,8 +55,12 @@ class SyncRunResult {
/// rather than each concern (notes, settings, analytics) opening and
/// closing its own.
///
/// [firebaseFactory] and [stateStore] exist for tests, which must not reach
/// the OS keystore or an application-support directory.
/// [firebaseFactory], [stateStore] and [readPassphrase] exist for tests, which
/// must not reach the OS keystore or an application-support directory.
///
/// Everything pushed is end-to-end encrypted under the shared crdt-sync
/// passphrase; without a usable key the run is a no-op flagged
/// [SyncResult.locked] rather than a plaintext sync.
Future<SyncRunResult> runSync(
NoteRepository repository,
SyncSettings settings, {
@ -54,6 +69,7 @@ Future<SyncRunResult> runSync(
http.Client? httpClient,
Future<FirebaseRestClient?> Function()? firebaseFactory,
SyncStateStore? stateStore,
Future<String?> Function()? readPassphrase,
}) async {
final github = GitHubClient(
owner: settings.owner,
@ -72,16 +88,48 @@ Future<SyncRunResult> runSync(
stateStore: stateStore ?? await openSyncStateStore(),
// coverage:ignore-end
);
final result = await service.sync(
repository,
firebase == null
? github
: MirrorStore(primary: firebase, mirror: github),
// No GitHub token means nothing to mirror: an unconfigured client still
// spends two round trips per call on 404s.
final backend = switch (firebase) {
null => github,
_ when !settings.isConfigured => firebase,
_ => MirrorStore(primary: firebase, mirror: github),
};
final e2e = await openEncryptedStore(
store: backend,
oldPrefix: service.notesDir,
readPassphrase: readPassphrase ?? readE2ePassphrase,
params: e2eArgon2Params,
// Argon2id once per device, not once per tick.
keyCache: keystoreKeyCache(service.notesDir),
);
await analytics?.flush(firebase);
e2eLocked.value = e2e is! E2eReady;
if (e2e is! E2eReady) {
return const SyncRunResult(
syncResult: SyncResult(mergedDevices: 0, pushed: false, locked: true),
);
}
final layout = E2eLayout.of(service.notesDir);
// Settings and analytics touch other Firebase paths than the notes, so
// they ride alongside the note sync instead of after it.
final reconciled = appSettings?.reconcileWithRemote(firebase);
final flushed = analytics?.flush(firebase);
final notes = SyncService(
notesDir: layout.prefix,
revsPath: layout.revsPath,
stateStore: service.stateStore,
).sync(repository, e2e.store);
final done = await Future.wait<Object?>([
notes,
?reconciled,
?flushed,
// Not eager: the clients are closed below, so nothing may still be in
// flight when this returns or throws.
]);
final result = done.first! as SyncResult;
return SyncRunResult(
syncResult: result.withFirebaseConnected(value: firebase != null),
appSettings: await appSettings?.reconcileWithRemote(firebase),
appSettings: await reconciled,
);
} finally {
// Close both: unlike the long-lived desktop callers, each screen builds

View File

@ -1,6 +1,7 @@
import 'package:crdt_sync/crdt_sync.dart';
import 'package:todo/data/note_repository.dart';
import 'package:todo/sync/peer_pull.dart';
/// Outcome of a sync run, for surfacing in the UI.
class SyncResult {
@ -11,6 +12,7 @@ class SyncResult {
this.skippedFiles = const [],
this.skippedUnchanged = 0,
this.firebaseConnected = false,
this.locked = false,
});
/// How many other devices' logs were pulled and merged.
@ -41,6 +43,10 @@ class SyncResult {
/// device dropping out.
final int skippedUnchanged;
/// True when end-to-end encryption has no usable key on this device, so
/// nothing was pulled, merged or pushed.
final bool locked;
/// Returns a copy with [firebaseConnected] set. [SyncService] never sets
/// it -- only [runSync], which is the layer that knows which [RemoteStore]
/// it built -- so this is the seam that lets it do that without
@ -51,6 +57,7 @@ class SyncResult {
skippedFiles: skippedFiles,
skippedUnchanged: skippedUnchanged,
firebaseConnected: value,
locked: locked,
);
@override
@ -73,7 +80,11 @@ class SyncResult {
/// two never share a path and an old client can't misread a new file.
class SyncService {
/// Creates a [SyncService], optionally overriding [notesDir].
const SyncService({this.notesDir = 'todo-sync/notes', this.stateStore});
const SyncService({
this.notesDir = 'todo-sync/notes',
this.stateStore,
this.revsPath,
});
/// Directory in the repo under which per-device note-log files live.
final String notesDir;
@ -87,7 +98,11 @@ class SyncService {
final SyncStateStore? stateStore;
/// Where revisions live, as a sibling of [notesDir].
String get revsDir => defaultRevsPath(notesDir);
/// Revision cache directory; null derives it from [notesDir].
final String? revsPath;
/// Where peers publish their revisions.
String get revsDir => revsPath ?? defaultRevsPath(notesDir);
/// Runs a full pull-merge-push cycle. Safe to call repeatedly.
///
@ -99,45 +114,61 @@ class SyncService {
final ownFileName = '$nodeId.json';
final state = await stateStore?.load() ?? const SyncState();
final remoteRevs = stateStore == null
? const <String, String>{}
: await _revisions(remote);
// Independent reads, so one round trip instead of two. eagerError keeps
// the first failure's own type, which callers catch.
final reads = await Future.wait<Object>([
if (stateStore == null)
Future.value(const <String, String>{})
else
_revisions(remote),
remote.listDirectory(notesDir),
], eagerError: true);
final remoteRevs = reads[0] as Map<String, String>;
final names = reads[1] as List<String>;
final seenRevs = <String, String>{};
// 1. Pull: list all device log files, merge everyone else's.
final names = await remote.listDirectory(notesDir);
var merged = 0;
// 1. Pull: every other device's log that changed since we merged it.
var skippedUnchanged = 0;
final skipped = <String>[];
final changed = <String>[];
for (final name in names) {
if (name == ownFileName) continue; // our own file; skip it.
final peer = name.endsWith('.json')
? name.substring(0, name.length - 5)
: name;
final peer = peerOf(name);
final remoteRev = remoteRevs[peer];
if (remoteRev != null && remoteRev == state.peerRevs[peer]) {
// Unchanged since we last merged it, and that merge is already in the
// local log — so the ~150 KB download is pure waste. Carry the
// revision forward so it stays skipped next time.
// local log -- so the download is pure waste. Carry the revision
// forward so it stays skipped next time.
seenRevs[peer] = remoteRev;
skippedUnchanged++;
continue;
}
final text = await remote.getFileText('$notesDir/$name');
final remoteLog = text == null ? null : _decodeLog(text);
if (remoteLog == null) {
// A vanished or undecodable peer file must not abort the sync, but
// it must not vanish silently either — that's how a device drops
// out of sync unnoticed. Report it in the result instead.
// Deliberately not recorded as seen: a corrupt push must be retried
// next run, not remembered as merged.
skipped.add(name);
changed.add(name);
}
var merged = 0;
final skipped = <String>[];
Log? incoming;
for (final pulled in await pullPeers(
remote,
notesDir,
changed,
remoteRevs,
)) {
final log = pulled.log;
if (log == null) {
// A vanished, undecryptable or undecodable peer file must not abort
// the sync, but it must not vanish silently either -- that's how a
// device drops out of sync unnoticed. Reported, and deliberately not
// recorded as seen: a corrupt push must be retried next run.
skipped.add(pulled.name);
continue;
}
await repo.importLog(remoteLog);
seenRevs[peer] = remoteRev ?? revisionOf(text!);
// Peers merge with each other first (commutative, idempotent), so the
// local store is rewritten once rather than once per peer.
incoming = incoming == null ? log : mergeLogs(incoming, log);
seenRevs[pulled.peer] = pulled.rev!;
merged++;
}
if (incoming != null) await repo.importLog(incoming);
// 2. Push: upload our own (now-merged) log under our node id.
// putFileText resolves our file's current sha itself.
@ -184,22 +215,4 @@ class SyncService {
if (remote is! BulkMapReader) return const {};
return await (remote as BulkMapReader).getStringMap(revsDir);
}
/// Parses a remote note log, returning `null` for a corrupt or wrong-shape
/// payload so one bad device file never aborts the whole sync.
Log? _decodeLog(String text) {
try {
return logFromJson(text);
} on FormatException {
return null;
}
// crdt_sync's logFromJson throws a raw TypeError (not a custom
// exception) for a wrong-shape JSON payload from an untrusted peer
// file; must be caught too so one bad device file never aborts the
// whole sync (see doc comment above).
// ignore: avoid_catching_errors
on TypeError {
return null;
}
}
}

View File

@ -1,28 +1,32 @@
/// The one page route every screen is pushed with, on the shared motion tokens.
/// The one page route every screen is pushed with.
library;
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:todo/ui/motion.dart';
import 'package:material_ui/material_ui.dart';
/// A route for [builder]: fade plus a short rise over [AppDuration.slow],
/// instant under the OS "remove animations" setting.
Route<T> appRoute<T>(BuildContext context, WidgetBuilder builder) =>
/// A route for [builder] that switches screens instantly: no fade, no slide.
///
/// Without a GPU the desktop web build repaints the whole 4K canvas in
/// software on every frame, so a 320 ms transition cost ~600 ms of main
/// thread and a 260-300 ms frame stall on every tab switch and note open.
/// The same instant switch applies on the phone. The context is unused but
/// kept so every call site stays as it was.
///
/// [name] is a route pattern (`/notes/detail`), never an id or a title: the
/// app-errors reporter stamps it on every report made on that screen.
Route<T> appRoute<T>(BuildContext _, WidgetBuilder builder, {String? name}) =>
_AppPageRoute<T>(
builder: builder,
duration: motionDuration(context, AppDuration.slow),
settings: RouteSettings(name: name),
);
class _AppPageRoute<T> extends MaterialPageRoute<T> {
_AppPageRoute({required super.builder, required this.duration});
final Duration duration;
_AppPageRoute({required super.builder, super.settings});
@override
Duration get transitionDuration => duration;
Duration get transitionDuration => Duration.zero;
@override
Duration get reverseTransitionDuration => duration;
Duration get reverseTransitionDuration => Duration.zero;
@override
Widget buildTransitions(
@ -30,21 +34,5 @@ class _AppPageRoute<T> extends MaterialPageRoute<T> {
Animation<double> animation,
Animation<double> secondaryAnimation,
Widget child,
) {
final enter = CurvedAnimation(
parent: animation,
curve: AppCurve.decelerate,
reverseCurve: AppCurve.accelerate,
);
return FadeTransition(
opacity: enter,
child: SlideTransition(
position: Tween<Offset>(
begin: const Offset(0, 0.04),
end: Offset.zero,
).animate(enter),
child: child,
),
);
}
) => child;
}

View File

@ -5,8 +5,8 @@ library;
import 'package:file_picker/file_picker.dart' show FilePicker;
import 'package:file_selector/file_selector.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:material_ui/material_ui.dart';
export 'package:file_selector/file_selector.dart' show XFile;
@ -44,18 +44,24 @@ Future<List<XFile>> pickAttachments(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: const Icon(Icons.photo_camera_outlined),
title: const Text('Camera'),
leading: const Icon(
Icons.photo_camera_outlined,
semanticLabel: 'Camera',
),
onTap: () => Navigator.pop(context, AttachmentPickSource.camera),
),
ListTile(
leading: const Icon(Icons.photo_library_outlined),
title: const Text('Gallery'),
leading: const Icon(
Icons.photo_library_outlined,
semanticLabel: 'Gallery',
),
onTap: () => Navigator.pop(context, AttachmentPickSource.gallery),
),
ListTile(
leading: const Icon(Icons.insert_drive_file_outlined),
title: const Text('File'),
leading: const Icon(
Icons.insert_drive_file_outlined,
semanticLabel: 'File',
),
onTap: () => Navigator.pop(context, AttachmentPickSource.file),
),
],
@ -102,8 +108,8 @@ class AttachButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return IconButton(
tooltip: 'Attach',
icon: const Icon(Icons.attach_file),
tooltip: 'attach',
icon: const Icon(Icons.attach_file, semanticLabel: 'Attach'),
onPressed: () async {
final files = await (picking ?? pickAttachments)(context);
if (files.isNotEmpty) onFiles(files);

View File

@ -4,8 +4,9 @@
/// screen still owns every action; this just lays the row out.
library;
import 'package:crdt_sync_flutter/crdt_sync_flutter.dart' show WaitWatch;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note_repository.dart';
import 'package:todo/frame_stats.dart';
@ -86,26 +87,29 @@ class CaptureAppBar extends StatelessWidget implements PreferredSizeWidget {
// Not gated on advanced mode: attaching is basic capture.
AttachButton(onFiles: onAttachFiles, picking: attachmentPicking),
IconButton(
tooltip: 'New note',
tooltip: 'new',
onPressed: onNewNote,
icon: const Icon(Icons.check),
icon: const Icon(Icons.check, semanticLabel: 'New note'),
),
if (advanced)
IconButton(
tooltip: 'Sync',
tooltip: 'sync',
onPressed: syncing ? null : onSync,
icon: syncing
? const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2),
? const WaitWatch(
operation: 'sync.run',
child: SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2),
),
)
: const Icon(Icons.sync),
: const Icon(Icons.sync, semanticLabel: 'Sync'),
),
IconButton(
tooltip: 'Notes',
tooltip: 'notes',
onPressed: onOpenList,
icon: const Icon(Icons.list),
icon: const Icon(Icons.list, semanticLabel: 'Notes'),
),
// Live count of stored notes, proving local persistence. Sits directly
// right of the Notes button it belongs to, and carries no icon of its
@ -122,9 +126,9 @@ class CaptureAppBar extends StatelessWidget implements PreferredSizeWidget {
),
CaptureConfirmMark(captured: captured),
IconButton(
tooltip: 'Settings',
tooltip: 'settings',
onPressed: onOpenSettings,
icon: const Icon(Icons.settings),
icon: const Icon(Icons.settings, semanticLabel: 'Settings'),
),
],
);

View File

@ -3,7 +3,7 @@ library;
import 'package:design_system/design_system.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
/// Plays once each time [captured] changes value.
class CaptureConfirmMark extends StatefulWidget {

View File

@ -102,6 +102,7 @@ class CaptureDraft {
status: status,
createdAt: _createdAt!,
updatedAt: now,
createdBy: 'kuhy',
),
);
if (live()) lastSavedAt.value = now;

View File

@ -1,10 +1,9 @@
import 'dart:async';
import 'package:crdt_sync/crdt_sync.dart';
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'package:material_ui/material_ui.dart';
import 'package:todo/analytics/analytics_event.dart';
import 'package:todo/analytics/analytics_service.dart';
import 'package:todo/attachments/image_store_scope.dart';
@ -22,6 +21,7 @@ import 'package:todo/ui/capture_draft.dart';
import 'package:todo/ui/capture_status.dart';
import 'package:todo/ui/capture_status_footer.dart';
import 'package:todo/ui/capture_sync_runner.dart';
import 'package:todo/ui/cue_snack.dart';
import 'package:todo/ui/image_attach.dart';
import 'package:todo/ui/image_input.dart';
import 'package:todo/ui/note_form.dart';
@ -194,7 +194,14 @@ class _CaptureScreenState extends State<CaptureScreen>
Future<void> _sync() async {
final settings = _settings ?? await SyncSettings.load();
if (!settings.isConfigured && await openFirebase() == null) {
_showSnack('Connect Firebase (or add a GitHub token) in settings');
// The cue plus the settings screen opening is the whole message.
if (mounted) {
showCue(
context,
Icons.cloud_off,
'Connect Firebase (or add a GitHub token) in settings',
);
}
await _openSettings();
return;
}
@ -215,12 +222,7 @@ class _CaptureScreenState extends State<CaptureScreen>
if (outcome.ok) 'detail': outcome.detail,
},
);
_showSnack(
outcome.ok
? 'Synced: ${outcome.detail}'
: 'Sync failed: ${outcome.detail}',
isError: !outcome.ok,
);
_showSyncCue(outcome);
} finally {
if (mounted) setState(() => _syncing = false);
}

View File

@ -75,6 +75,7 @@ extension _CaptureSyncBehaviour on _CaptureScreenState {
analytics: widget.analytics,
httpClient: widget.httpClient,
),
name: '/settings',
),
);
if (!mounted) return;
@ -94,6 +95,7 @@ extension _CaptureSyncBehaviour on _CaptureScreenState {
repository: widget.repository,
appSettings: widget.appSettings,
),
name: '/notes',
),
);
}
@ -104,13 +106,20 @@ extension _CaptureSyncBehaviour on _CaptureScreenState {
/// replace-don't-queue behaviour match every other app; [isError] picks
/// the danger hue and the longer duration, because an error the user
/// missed is an error they will hit again.
void _showSnack(String message, {bool isError = false}) {
/// A manual sync's result as a glyph: done, done-but-degraded (Firebase
/// off or a peer unreadable, in the danger hue), or failed. The summary
/// sentence is spoken only; the status line keeps the failure time.
void _showSyncCue(CaptureSyncOutcome outcome) {
if (!mounted) return;
if (isError) {
showError(context, message);
} else {
showToast(context, message);
}
final spoken = outcome.ok
? 'Synced: ${outcome.detail}'
: 'Sync failed: ${outcome.detail}';
final (icon, error) = !outcome.ok
? (Icons.sync_problem, true)
: outcome.degraded
? (Icons.warning_amber, true)
: (Icons.cloud_done, false);
showCue(context, icon, spoken, error: error);
}
/// Reloads the persisted last-sync outcome so the status line survives a

View File

@ -6,7 +6,7 @@
/// library-scoped.
library;
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:todo/sync/sync_service.dart';
@ -98,6 +98,7 @@ class SyncStatusStore {
/// precisely how a desktop stuck syncing over the GitHub mirror alone
/// went unnoticed for days.
String describeSyncResult(SyncResult result) {
if (result.locked) return '🔒';
final skipped = result.skippedFiles.length;
final backend = result.firebaseConnected
? ''

View File

@ -5,7 +5,7 @@
library;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/ui/capture_status.dart';
@ -44,16 +44,16 @@ class CaptureStatusFooter extends StatelessWidget {
if (status == null || status.ok) {
return const SizedBox.shrink();
}
// Glyph + time in the danger hue; the error itself is spoken.
return Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
child: _cueLine(
Icons.sync_problem,
formatSyncTime(status.time),
'Sync failed at ${formatSyncTime(status.time)} · '
'${status.detail}',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.error,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
theme.textTheme.bodySmall,
theme.colorScheme.error,
),
);
},
@ -63,15 +63,45 @@ class CaptureStatusFooter extends StatelessWidget {
padding: const EdgeInsets.only(top: 4),
child: ValueListenableBuilder<DateTime?>(
valueListenable: lastSavedAt,
builder: (context, savedAt, _) => Text(
savedAt == null
? 'Autosaves as you type'
: 'Saved locally at ${formatSyncTime(savedAt)}',
style: theme.textTheme.bodySmall,
),
// Before the first save: the save glyph alone, muted.
builder: (context, savedAt, _) => savedAt == null
? _cueLine(
Icons.save_outlined,
'',
'Autosaves as you type',
theme.textTheme.bodySmall,
theme.colorScheme.outline,
)
: _cueLine(
Icons.save,
formatSyncTime(savedAt),
'Saved locally at ${formatSyncTime(savedAt)}',
theme.textTheme.bodySmall,
null,
),
),
),
],
);
}
/// One status line: a small glyph and a time, spoken as [spoken].
Widget _cueLine(
IconData icon,
String time,
String spoken,
TextStyle? style,
Color? color,
) => Semantics(
label: spoken,
excludeSemantics: true,
container: true,
child: Row(
children: [
Icon(icon, size: 16, color: color),
const SizedBox(width: 4),
Text(time, style: style?.copyWith(color: color)),
],
),
);
}

View File

@ -26,11 +26,16 @@ class CaptureSyncOutcome {
required this.ok,
required this.detail,
this.reconciled,
this.degraded = false,
});
/// Whether the pass completed without throwing.
final bool ok;
/// A pass that completed but not fully: Firebase was not connected, or a
/// peer's file could not be read. Shown as a warning, not a plain success.
final bool degraded;
/// One-line summary: merged/skipped counts on success, the error otherwise.
final String detail;
@ -90,10 +95,15 @@ class CaptureSyncRunner {
);
final detail = describeSyncResult(result.syncResult);
await status.record(ok: true, detail: detail, live: live());
final synced = result.syncResult;
return CaptureSyncOutcome(
ok: true,
detail: detail,
reconciled: result.appSettings,
degraded:
synced.locked ||
!synced.firebaseConnected ||
synced.skippedFiles.isNotEmpty,
);
} on Exception catch (e) {
await status.record(ok: false, detail: '$e', live: live());

View File

@ -10,14 +10,15 @@ library;
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'package:material_ui/material_ui.dart';
import 'package:todo/attachments/image_password_store.dart';
import 'package:todo/attachments/image_store_api.dart';
import 'package:todo/attachments/image_store_scope.dart';
import 'package:todo/images/dufs_image_client.dart';
import 'package:todo/ui/app_route.dart';
import 'package:todo/ui/status_cue.dart';
/// The command that creates the login, shown wherever it is missing.
const kAddLoginCommand =
@ -34,11 +35,14 @@ class CloudImagesTile extends StatelessWidget {
@override
Widget build(BuildContext context) => ListTile(
contentPadding: EdgeInsets.zero,
title: const Text('Cloud images'),
subtitle: const Text('Where attached images and files upload (dufs)'),
leading: const Icon(Icons.cloud, semanticLabel: 'Cloud images'),
trailing: const Icon(Icons.chevron_right),
onTap: () => Navigator.of(context).push<void>(
appRoute(context, (_) => CloudImagesScreen(httpClient: httpClient)),
appRoute(
context,
(_) => CloudImagesScreen(httpClient: httpClient),
name: '/settings/images',
),
),
);
}
@ -69,7 +73,7 @@ class CloudImagesScreen extends StatefulWidget {
class _CloudImagesScreenState extends State<CloudImagesScreen> {
final _password = TextEditingController();
ImageStoreStatus? _status;
String? _checkResult;
StatusCue? _checkResult;
bool _checking = false;
@override
@ -98,7 +102,11 @@ class _CloudImagesScreenState extends State<CloudImagesScreen> {
final password = _password.text.trim();
setState(() => _checking = true);
final saved = await widget.passwords.write(password);
var result = 'Could not save: the keystore is unavailable';
var result = const StatusCue(
Icons.no_encryption,
'Could not save: the keystore is unavailable',
error: true,
);
if (saved) {
final client = DufsImageClient(
DufsLogin(user: kDufsImagesUser, password: password),
@ -106,9 +114,17 @@ class _CloudImagesScreenState extends State<CloudImagesScreen> {
);
final check = await client.check();
result = switch (check) {
DufsCheck.ok => 'Saved — dufs accepted the login',
DufsCheck.rejected => 'Saved, but dufs rejected the password',
DufsCheck.unreachable => 'Saved — dufs is unreachable right now',
DufsCheck.ok => const StatusCue.ok('Saved — dufs accepted the login'),
DufsCheck.rejected => const StatusCue(
Icons.lock,
'Saved, but dufs rejected the password',
error: true,
),
DufsCheck.unreachable => const StatusCue(
Icons.cloud_off,
'Saved — dufs is unreachable right now',
error: true,
),
};
// Upload what queued up while there was no password, now rather than
// on the next sync. No note texts: an empty ref set only uploads, it
@ -129,7 +145,9 @@ class _CloudImagesScreenState extends State<CloudImagesScreen> {
Widget build(BuildContext context) {
final status = _status;
return Scaffold(
appBar: AppBar(title: const Text('Cloud images')),
appBar: AppBar(
title: const Icon(Icons.cloud_outlined, semanticLabel: 'Cloud images'),
),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
@ -138,36 +156,79 @@ class _CloudImagesScreenState extends State<CloudImagesScreen> {
controller: _password,
obscureText: true,
decoration: const InputDecoration(
labelText: 'Password for the "todo" dufs login',
prefixIcon: Icon(
Icons.lock_outline,
semanticLabel: 'Password for the "todo" dufs login',
),
),
),
const SizedBox(height: 12),
FilledButton(
onPressed: _checking ? null : _saveAndTest,
child: const Text('Save & test'),
child: const Icon(Icons.save, semanticLabel: 'Save & test'),
),
if (_checkResult case final result?) ...[
const SizedBox(height: 8),
Text(result),
StatusCueView(result),
],
const SizedBox(height: 16),
],
if (status != null) ...[
Text(
status.configured
? 'Login: configured'
: 'Login: missing — create it on the PC with',
// Shape + colour: a filled check, or a red error ring followed by
// a copy button that puts the fixing command on the clipboard.
Row(
children: [
Icon(
status.configured ? Icons.check_circle : Icons.error_outline,
color: status.configured
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.error,
semanticLabel: status.configured
? 'Login: configured'
: 'Login: missing — create it on the PC with',
),
if (!status.configured)
IconButton(
tooltip: 'copy',
onPressed: () => unawaited(
Clipboard.setData(
const ClipboardData(text: kAddLoginCommand),
),
),
icon: const Icon(
Icons.content_copy,
semanticLabel: 'Copy: $kAddLoginCommand',
),
),
],
),
if (!status.configured) const SelectableText(kAddLoginCommand),
const SizedBox(height: 8),
Text('Waiting to upload: ${status.pending}'),
// Icon + the count itself: the number is the information.
Row(
children: [
const Icon(Icons.cloud_upload_outlined),
const SizedBox(width: 8),
Text(
'${status.pending}',
semanticsLabel: 'Waiting to upload: ${status.pending}',
),
],
),
],
const SizedBox(height: 16),
Text(
'Images are shrunk to 2560px JPEGs without location data before '
'they leave this device. Other files upload unchanged, at any '
'size.',
style: Theme.of(context).textTheme.bodySmall,
// Shrunk + no location, as glyphs; the sentence is spoken only.
const Row(
children: [
Icon(
Icons.photo_size_select_large,
semanticLabel:
'Images are shrunk to 2560px JPEGs without location data '
'before they leave this device. Other files upload '
'unchanged, at any size.',
),
SizedBox(width: 8),
Icon(Icons.location_off),
],
),
],
),

View File

@ -0,0 +1,60 @@
/// Icon-only confirmation before deleting a note.
///
/// Replaces design_system's `confirmDestructive` here because that dialog
/// paints its title, message and button labels as text. The safety contract
/// is kept: Cancel is autofocused (a reflexive Return keeps the note), Escape
/// and the barrier answer "no", and the confirm glyph wears the error colour.
library;
import 'package:flutter/services.dart';
import 'package:material_ui/material_ui.dart';
/// Asks whether to delete a note; true only when the delete glyph is pressed.
Future<bool> confirmDeleteNote(BuildContext context) async {
final confirmed = await showDialog<bool>(
context: context,
builder: (_) => const _ConfirmDeleteDialog(),
);
return confirmed ?? false;
}
class _ConfirmDeleteDialog extends StatelessWidget {
const _ConfirmDeleteDialog();
@override
Widget build(BuildContext context) {
final error = Theme.of(context).colorScheme.error;
return CallbackShortcuts(
bindings: {
const SingleActivator(LogicalKeyboardKey.escape): () =>
Navigator.of(context).pop(false),
},
child: AlertDialog(
// Spoken when the dialog opens; the old written body.
semanticLabel: 'This cannot be undone.',
title: Icon(
Icons.delete_forever,
size: 40,
color: error,
semanticLabel: 'Delete note?',
),
actionsAlignment: MainAxisAlignment.spaceEvenly,
actions: [
IconButton(
key: const ValueKey('confirm-cancel'),
tooltip: 'cancel',
autofocus: true,
onPressed: () => Navigator.of(context).pop(false),
icon: const Icon(Icons.close, semanticLabel: 'Cancel'),
),
IconButton(
key: const ValueKey('confirm-delete'),
tooltip: 'delete',
onPressed: () => Navigator.of(context).pop(true),
icon: Icon(Icons.delete, color: error, semanticLabel: 'Delete'),
),
],
),
);
}
}

58
lib/ui/cue_snack.dart Normal file
View File

@ -0,0 +1,58 @@
/// Transient feedback as a glyph, not a sentence (kuhy's textgate rule).
///
/// The design system's `showToast`/`showError` paint a message; this paints
/// an icon (plus an optional number) and keeps the old sentence as the
/// spoken label only. Colour is the second channel: errors use the danger
/// hue and stay up longer, as `showError` does.
library;
import 'package:design_system/design_system.dart';
import 'package:material_ui/material_ui.dart';
const Duration _toastDuration = Duration(seconds: 3);
const Duration _errorDuration = Duration(seconds: 5);
/// Shows [icon] (and [count], if given) in a snack bar; [spoken] is what a
/// screen reader says. Returns quietly when no `ScaffoldMessenger` is above
/// [context] (an async callback outliving its screen).
void showCue(
BuildContext context,
IconData icon,
String spoken, {
bool error = false,
int? count,
}) {
final messenger = ScaffoldMessenger.maybeOf(context);
if (messenger == null) return;
final colors = context.statusColors;
final fg = error ? colors.onStatus : null;
// Replace rather than queue: a queued cue describes an action the user
// has already moved on from.
messenger
..clearSnackBars()
..showSnackBar(
SnackBar(
content: Semantics(
label: spoken,
excludeSemantics: true,
// Its own node: otherwise the label merges into the snack bar's.
container: true,
child: Row(
children: [
Icon(icon, color: fg),
if (count != null) ...[
const SizedBox(width: AppSpacing.sm),
Text('$count', style: TextStyle(color: fg)),
],
],
),
),
backgroundColor: error ? colors.danger : null,
duration: error ? _errorDuration : _toastDuration,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppRadius.sm),
),
),
);
}

View File

@ -0,0 +1,23 @@
/// The notes list's empty state as a picture, not a sentence.
library;
import 'package:material_ui/material_ui.dart';
/// A large muted glyph: an empty inbox when there are no notes at all, a
/// crossed-out filter when the current filter hides every note (the filter
/// button's badge is the second channel saying a filter is on).
class EmptyNotesCue extends StatelessWidget {
/// Creates the cue; [filtered] picks the filter variant.
const EmptyNotesCue({required this.filtered, super.key});
/// Whether a filter is active (notes may exist but none match).
final bool filtered;
@override
Widget build(BuildContext context) => Icon(
filtered ? Icons.filter_alt_off_outlined : Icons.inbox_outlined,
size: 64,
color: Theme.of(context).colorScheme.outline,
semanticLabel: filtered ? 'No notes match these filters' : 'No notes yet',
);
}

105
lib/ui/enum_glyphs.dart Normal file
View File

@ -0,0 +1,105 @@
/// Glyphs for the Priority and Status enums, and the chip row that picks
/// them, so every picker shows the same shape + colour for the same value.
///
/// The enum's `label` survives only as the spoken (semantics) label.
library;
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note.dart';
import 'package:todo/ui/note_grid_tile.dart';
/// Shape channel for a priority: up for high, level for medium, down for low.
/// Colour ([priorityColor]) is the second channel.
IconData priorityIcon(Priority p) => switch (p) {
Priority.high => Icons.keyboard_double_arrow_up,
Priority.medium => Icons.drag_handle,
Priority.low => Icons.keyboard_double_arrow_down,
};
/// Heading glyph standing for "status" (matches the bulk-status button).
const IconData kStatusHeadingIcon = Icons.task_alt;
/// Heading glyph standing for "priority" (matches the bulk-priority button).
const IconData kPriorityHeadingIcon = Icons.flag_outlined;
/// [s] as its glyph, spoken as its label.
Widget statusGlyph(Status s, {double? size}) =>
Icon(statusIcon(s), size: size, semanticLabel: s.label);
/// [p] as its tinted glyph, spoken as its label.
Widget priorityGlyph(BuildContext context, Priority p, {double? size}) => Icon(
priorityIcon(p),
size: size,
color: priorityColor(p, Theme.of(context).colorScheme),
semanticLabel: p.label,
);
/// A heading glyph followed by one chip per value, each chip a glyph.
///
/// [multi] switches between FilterChips (toggle many) and ChoiceChips (pick
/// one); either way the selected chips are filled and checked.
class GlyphChips<T> extends StatelessWidget {
/// Creates a chip row for [values].
const GlyphChips({
required this.heading,
required this.semanticLabel,
required this.values,
required this.selected,
required this.glyphOf,
required this.onTap,
this.multi = false,
super.key,
});
/// Glyph shown in front of the chips in place of a written heading.
final IconData heading;
/// Spoken name of the row (the old written heading).
final String semanticLabel;
/// Every value offered.
final List<T> values;
/// Values currently selected.
final Set<T> selected;
/// Builds the glyph for one value.
final Widget Function(T) glyphOf;
/// Called with the tapped value.
final ValueChanged<T> onTap;
/// Whether this is a multi-select (filter) row.
final bool multi;
@override
Widget build(BuildContext context) {
return Row(
children: [
Icon(heading, semanticLabel: semanticLabel),
const SizedBox(width: 12),
Expanded(
child: Wrap(
spacing: 8,
children: [
for (final v in values)
if (multi)
FilterChip(
label: glyphOf(v),
selected: selected.contains(v),
onSelected: (_) => onTap(v),
)
else
ChoiceChip(
label: glyphOf(v),
selected: selected.contains(v),
onSelected: (_) => onTap(v),
),
],
),
),
],
);
}
}

View File

@ -1,33 +1,27 @@
import 'dart:async';
import 'package:crdt_sync/crdt_sync.dart';
import 'package:flutter/material.dart';
import 'package:crdt_sync_flutter/crdt_sync_flutter.dart' show WaitWatch;
import 'package:github_device_auth/github_device_auth.dart';
import 'package:http/http.dart' as http;
import 'package:material_ui/material_ui.dart';
import 'package:todo/analytics/analytics_service.dart';
import 'package:todo/data/app_settings.dart';
import 'package:todo/data/note_repository.dart';
import 'package:todo/sync/run_sync.dart';
import 'package:todo/sync/sync_settings.dart';
import 'package:todo/ui/status_cue.dart';
part 'github_mirror_screen_widget.dart';
class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
late final TextEditingController _owner = TextEditingController(
text: widget.initial.owner,
);
late final TextEditingController _repo = TextEditingController(
text: widget.initial.repo,
);
late final TextEditingController _token = TextEditingController(
text: widget.initial.token,
);
late final TextEditingController _clientId = TextEditingController(
text: widget.initial.clientId,
);
late final _owner = TextEditingController(text: widget.initial.owner);
late final _repo = TextEditingController(text: widget.initial.repo);
late final _token = TextEditingController(text: widget.initial.token);
late final _clientId = TextEditingController(text: widget.initial.clientId);
bool _testing = false;
String? _status;
StatusCue? _status;
@override
void dispose() {
@ -49,8 +43,13 @@ class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
Future<void> _connectGitHub() async {
final clientId = _clientId.text.trim();
if (clientId.isEmpty) {
setState(() => _status = 'Enter the OAuth App client id first.');
return;
return _show(
const StatusCue(
Icons.key_off,
'Enter the OAuth App client id first.',
error: true,
),
);
}
final auth = GitHubDeviceAuth(
clientId: clientId,
@ -67,20 +66,19 @@ class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
if (token != null && token.isNotEmpty) {
setState(() {
_token.text = token;
_status = 'Connected — syncing…';
_status = const StatusCue(Icons.sync, 'Connected — syncing…');
});
await _current.save();
await _syncAfterConnect();
}
} on Exception catch (e) {
if (mounted) setState(() => _status = 'Could not start device flow: $e');
_show(StatusCue.failed('Could not start device flow: $e'));
} finally {
auth.close();
}
}
/// Runs a sync right after connecting so the user's notes download
/// immediately and they get clear confirmation it worked.
/// Syncs right after connecting so notes download at once, with a cue.
Future<void> _syncAfterConnect() async {
final s = _current;
try {
@ -96,19 +94,29 @@ class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
widget.appSettings.value = widget.appSettings.value.adopt(
run.appSettings,
);
if (mounted) {
setState(
() => _status =
'Connected and synced (merged '
'${run.syncResult.mergedDevices} device(s)). Your notes are '
'up to date.',
);
}
_show(
StatusCue.ok(
'Connected and synced (merged '
'${run.syncResult.mergedDevices} device(s)). Your notes are '
'up to date.',
),
);
} on Exception catch (e) {
if (mounted) setState(() => _status = 'Connected, but sync failed: $e');
_show(
StatusCue(
Icons.sync_problem,
'Connected, but sync failed: $e',
error: true,
),
);
}
}
/// Shows [cue] as the screen's latest result, if still mounted.
void _show(StatusCue cue) {
if (mounted) setState(() => _status = cue);
}
Future<void> _test() async {
setState(() {
_testing = true;
@ -123,13 +131,17 @@ class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
);
try {
final ok = await client.canAccessRepo();
setState(
() => _status = ok
? 'Connected — repo is reachable.'
: 'Could not access ${s.owner}/${s.repo}. Check token scope.',
_show(
ok
? const StatusCue.ok('Connected — repo is reachable.')
: StatusCue(
Icons.lock,
'Could not access ${s.owner}/${s.repo}. Check token scope.',
error: true,
),
);
} on Exception catch (e) {
setState(() => _status = 'Error: $e');
_show(StatusCue.failed('Error: $e'));
} finally {
client.close();
if (mounted) setState(() => _testing = false);
@ -145,29 +157,28 @@ class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Advanced sync (GitHub)')),
appBar: AppBar(
title: const Icon(
Icons.cloud_sync,
semanticLabel: 'Advanced sync (GitHub)',
),
),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
Text(
'Authorize in your browser — no token to paste. Syncs to '
'kuhyx/syncs by default.',
style: Theme.of(context).textTheme.bodySmall,
),
const SizedBox(height: 12),
Align(
alignment: Alignment.centerLeft,
child: FilledButton.icon(
child: IconButton.filled(
tooltip: 'connect',
onPressed: _connectGitHub,
icon: const Icon(Icons.login),
label: const Text('Connect GitHub'),
icon: const Icon(Icons.login, semanticLabel: 'Connect GitHub'),
),
),
const SizedBox(height: 16),
TextField(
controller: _owner,
decoration: const InputDecoration(
labelText: 'GitHub owner',
prefixIcon: Icon(Icons.person, semanticLabel: 'GitHub owner'),
border: OutlineInputBorder(),
),
),
@ -175,7 +186,7 @@ class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
TextField(
controller: _repo,
decoration: const InputDecoration(
labelText: 'Repository name',
prefixIcon: Icon(Icons.folder, semanticLabel: 'Repository name'),
border: OutlineInputBorder(),
),
),
@ -183,8 +194,7 @@ class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
TextField(
controller: _clientId,
decoration: const InputDecoration(
labelText: 'OAuth App client id',
helperText: 'Leave as the baked-in default unless self-hosting',
prefixIcon: Icon(Icons.key, semanticLabel: 'OAuth App client id'),
border: OutlineInputBorder(),
),
),
@ -193,36 +203,44 @@ class _GitHubMirrorScreenState extends State<GitHubMirrorScreen> {
controller: _token,
obscureText: true,
decoration: const InputDecoration(
labelText: 'Access token (fallback)',
helperText: 'Contents: read/write on the sync repo only',
prefixIcon: Icon(
Icons.vpn_key,
semanticLabel: 'Access token (fallback)',
),
border: OutlineInputBorder(),
),
),
const SizedBox(height: 12),
Row(
children: [
OutlinedButton.icon(
IconButton.outlined(
tooltip: 'test',
onPressed: _testing ? null : _test,
icon: _testing
? const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2),
? const WaitWatch(
operation: 'mirror.test',
child: SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2),
),
)
: const Icon(Icons.wifi_tethering),
label: const Text('Test connection'),
: const Icon(
Icons.wifi_tethering,
semanticLabel: 'Test connection',
),
),
const SizedBox(width: 12),
FilledButton.icon(
IconButton.filled(
tooltip: 'save',
onPressed: _save,
icon: const Icon(Icons.save),
label: const Text('Save'),
icon: const Icon(Icons.save, semanticLabel: 'Save'),
),
],
),
if (_status != null) ...[
const SizedBox(height: 16),
Text(_status!, style: Theme.of(context).textTheme.bodyMedium),
StatusCueView(_status!),
],
],
),

View File

@ -9,12 +9,12 @@ library;
import 'dart:typed_data';
import 'package:design_system/design_system.dart';
import 'package:flutter/widgets.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/attachments/image_store_api.dart';
import 'package:todo/attachments/image_store_scope.dart';
import 'package:todo/images/attachment_ref.dart';
import 'package:todo/ui/cue_snack.dart';
/// Lets a screen insert lines into whichever editor is currently mounted.
class ImageAttachController {
@ -73,11 +73,15 @@ Future<void> attachImages(
target.insert([for (final ref in refs) ref.imageMarkdown]);
if (!context.mounted) return;
if (failure != null) {
showError(context, failure);
showCue(context, Icons.cloud_off, failure, error: true);
} else if (notImages > 0) {
showError(
// A broken-image glyph plus how many were refused.
showCue(
context,
Icons.broken_image_outlined,
notImages == 1 ? 'Not an image' : '$notImages files were not images',
error: true,
count: notImages,
);
}
}
@ -104,5 +108,7 @@ Future<void> attachFiles(
}
}
target.insert([for (final attachment in attached) attachment.markdown]);
if (failure != null && context.mounted) showError(context, failure);
if (failure != null && context.mounted) {
showCue(context, Icons.cloud_off, failure, error: true);
}
}

View File

@ -1,5 +1,5 @@
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/images/attachment_links.dart';
import 'package:todo/ui/images/file_embed.dart';

View File

@ -3,11 +3,12 @@
library;
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/attachments/image_store_api.dart';
import 'package:todo/attachments/image_store_scope.dart';
import 'package:todo/images/attachment_ref.dart';
import 'package:todo/ui/cue_snack.dart';
import 'package:todo/ui/images/file_opening.dart';
import 'package:todo/ui/images/image_embed.dart';
@ -51,7 +52,9 @@ class _FileEmbedState extends State<FileEmbed> {
Future<void> _open(ImageSource source) async {
final failure = await widget.opening(source, widget.attachment.name);
if (failure != null && mounted) showError(context, failure);
if (failure != null && mounted) {
showCue(context, Icons.block, failure, error: true);
}
}
@override
@ -73,9 +76,10 @@ class _FileEmbedState extends State<FileEmbed> {
style: widget.compact ? theme.textTheme.bodySmall : null,
);
final pending = store.isPending(attachment.ref)
? const Tooltip(
message: kImageWaitingToUpload,
child: Icon(Icons.cloud_upload_outlined, size: 18),
? const Icon(
Icons.cloud_upload_outlined,
size: 18,
semanticLabel: kImageWaitingToUpload,
)
: null;
final content = widget.compact
@ -104,15 +108,21 @@ class _FileEmbedState extends State<FileEmbed> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
name,
Text(detail, style: theme.textTheme.bodySmall),
// Not downloaded: a download glyph; else the size.
if (size == null)
const Icon(Icons.cloud_download_outlined, size: 16)
else
Text(detail, style: theme.textTheme.bodySmall),
],
),
),
?pending,
],
);
// Spoken only: nothing paints this string.
final semanticLabel = 'Attached file ${attachment.name}, $detail';
return Semantics(
label: 'Attached file ${attachment.name}, $detail',
label: semanticLabel,
button: size != null,
child: Material(
color: theme.colorScheme.surfaceContainerHighest,

View File

@ -2,7 +2,7 @@
/// saying why it is not here yet. Tapping opens it full screen.
library;
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/attachments/image_store_api.dart';
import 'package:todo/attachments/image_store_scope.dart';
@ -33,14 +33,20 @@ class ImageEmbed extends StatelessWidget {
final store = ImageStoreScope.of(context);
final source = store.sourceFor(ref);
final picture = imageFor(source, fit: fit);
// Spoken only: nothing paints this string.
const semanticLabel = 'Attached image';
return Semantics(
label: 'Attached image',
label: semanticLabel,
button: source is! MissingImageSource,
child: GestureDetector(
onTap: source is MissingImageSource
? null
: () => Navigator.of(context).push<void>(
appRoute(context, (_) => ImageViewerScreen(source: source)),
appRoute(
context,
(_) => ImageViewerScreen(source: source),
name: '/image',
),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
@ -52,9 +58,10 @@ class ImageEmbed extends StatelessWidget {
const Positioned(
right: 4,
top: 4,
child: Tooltip(
message: kImageWaitingToUpload,
child: Icon(Icons.cloud_upload_outlined, size: 18),
child: Icon(
Icons.cloud_upload_outlined,
size: 18,
semanticLabel: kImageWaitingToUpload,
),
),
],
@ -85,7 +92,7 @@ Widget imageFor(ImageSource source, {required BoxFit fit}) {
};
}
/// Grey box with [kImageNotDownloaded].
/// Grey box with a download glyph, spoken as [kImageNotDownloaded].
class ImagePlaceholder extends StatelessWidget {
/// Creates the placeholder.
const ImagePlaceholder({super.key});
@ -98,10 +105,10 @@ class ImagePlaceholder extends StatelessWidget {
child: Center(
child: Padding(
padding: const EdgeInsets.all(8),
child: Text(
kImageNotDownloaded,
textAlign: TextAlign.center,
style: theme.textTheme.bodySmall,
child: Icon(
Icons.cloud_download_outlined,
color: theme.colorScheme.outline,
semanticLabel: kImageNotDownloaded,
),
),
),

View File

@ -1,4 +1,4 @@
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/attachments/image_store_api.dart';
import 'package:todo/ui/images/image_embed.dart';

View File

@ -1,5 +1,5 @@
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/images/attachment_links.dart';
import 'package:todo/ui/images/file_embed.dart';

View File

@ -6,10 +6,11 @@ library;
import 'dart:async';
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note.dart';
import 'package:todo/data/note_template.dart';
import 'package:todo/ui/confirm_delete.dart';
import 'package:todo/ui/enum_glyphs.dart';
import 'package:todo/ui/note_sheet_details.dart';
import 'package:todo/ui/note_task_details.dart';
@ -61,53 +62,55 @@ class _NoteActionsSheetState extends State<NoteActionsSheet> {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
firstLine.isEmpty ? '(empty)' : firstLine,
style: Theme.of(context).textTheme.titleMedium,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
// User content; untitled shows nothing, not a placeholder.
if (firstLine.isNotEmpty)
Text(
firstLine,
style: Theme.of(context).textTheme.titleMedium,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
NoteSheetDetails(note: widget.note),
const SizedBox(height: 16),
_EnumChips<Status>(
label: 'Status',
GlyphChips<Status>(
heading: kStatusHeadingIcon,
semanticLabel: 'Status',
values: Status.values,
selected: {_status},
labelOf: (s) => s.label,
onSelected: (s) {
glyphOf: statusGlyph,
onTap: (s) {
setState(() => _status = s);
unawaited(_persist());
},
),
const SizedBox(height: 12),
_EnumChips<Priority>(
label: 'Priority',
GlyphChips<Priority>(
heading: kPriorityHeadingIcon,
semanticLabel: 'Priority',
values: Priority.values,
selected: {_priority},
labelOf: (p) => p.label,
onSelected: (p) {
glyphOf: (p) => priorityGlyph(context, p),
onTap: (p) {
setState(() => _priority = p);
unawaited(_persist());
},
),
NoteTaskDetails(note: widget.note),
const SizedBox(height: 16),
OutlinedButton.icon(
icon: const Icon(Icons.delete_outline),
label: const Text('Delete note'),
style: OutlinedButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.error,
Align(
child: IconButton.outlined(
tooltip: 'delete',
color: Theme.of(context).colorScheme.error,
icon: const Icon(
Icons.delete_outline,
semanticLabel: 'Delete note',
),
onPressed: () async {
if (!await confirmDeleteNote(context)) return;
await widget.onDelete();
if (context.mounted) Navigator.of(context).pop();
},
),
onPressed: () async {
final confirmed = await confirmDestructive(
context,
title: 'Delete note?',
message: 'This cannot be undone.',
);
if (!confirmed) return;
await widget.onDelete();
if (context.mounted) Navigator.of(context).pop();
},
),
],
),
@ -116,42 +119,3 @@ class _NoteActionsSheetState extends State<NoteActionsSheet> {
);
}
}
/// Single-select chip row for an enum (used for per-note priority/status).
class _EnumChips<T> extends StatelessWidget {
const _EnumChips({
required this.label,
required this.values,
required this.selected,
required this.labelOf,
required this.onSelected,
});
final String label;
final List<T> values;
final Set<T> selected;
final String Function(T) labelOf;
final ValueChanged<T> onSelected;
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label, style: Theme.of(context).textTheme.labelLarge),
const SizedBox(height: 8),
Wrap(
spacing: 8,
children: [
for (final v in values)
ChoiceChip(
label: Text(labelOf(v)),
selected: selected.contains(v),
onSelected: (_) => onSelected(v),
),
],
),
],
);
}
}

View File

@ -7,21 +7,33 @@ library;
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
/// Glyph for "created" (a note added), shared by the filter and sort menus.
const IconData kCreatedIcon = Icons.post_add;
/// Glyph for "last updated", shared by the filter and sort menus.
const IconData kUpdatedIcon = Icons.update;
/// A labelled date range shown as one preset menu plus a custom picker.
///
/// One-word tooltips on hover/long-press per textgate rule.
class DateRangeField extends StatelessWidget {
/// Creates a labelled date-range control.
const DateRangeField({
required this.label,
required this.icon,
required this.semanticLabel,
required this.from,
required this.to,
required this.onChanged,
super.key,
});
/// Heading shown above the control (e.g. 'Created').
final String label;
/// Glyph shown in the control's border in place of a written heading.
final IconData icon;
/// Spoken name of the control (e.g. 'Created'); never painted.
final String semanticLabel;
/// Start of the selected range, or null when unbounded.
final DateTime? from;
@ -86,15 +98,33 @@ class DateRangeField extends StatelessWidget {
// A popup menu rather than DropdownButton: re-picking "Custom…" while a
// custom range is shown must still reopen the picker.
return PopupMenuButton<_Preset>(
tooltip: label,
tooltip: 'range',
onSelected: (p) => _select(context, p),
itemBuilder: (_) => [
for (final p in _Preset.values)
PopupMenuItem(value: p, child: Text(p.label)),
PopupMenuItem(
value: _Preset.any,
child: Tooltip(message: 'any', child: _Preset.any.glyph()),
),
PopupMenuItem(
value: _Preset.today,
child: Tooltip(message: 'today', child: _Preset.today.glyph()),
),
PopupMenuItem(
value: _Preset.week,
child: Tooltip(message: 'week', child: _Preset.week.glyph()),
),
PopupMenuItem(
value: _Preset.month,
child: Tooltip(message: 'month', child: _Preset.month.glyph()),
),
PopupMenuItem(
value: _Preset.custom,
child: Tooltip(message: 'custom', child: _Preset.custom.glyph()),
),
],
child: InputDecorator(
decoration: InputDecoration(
labelText: label,
prefixIcon: Icon(icon, semanticLabel: semanticLabel),
isDense: true,
border: const OutlineInputBorder(),
contentPadding: const EdgeInsets.symmetric(
@ -103,10 +133,9 @@ class DateRangeField extends StatelessWidget {
),
suffixIcon: const Icon(Icons.arrow_drop_down),
),
child: Text(
current == _Preset.custom ? _rangeLabel() : current.label,
style: theme.textTheme.bodyMedium,
),
child: current == _Preset.custom
? Text(_rangeLabel(), style: theme.textTheme.bodyMedium)
: current.glyph(),
),
);
}
@ -131,8 +160,26 @@ enum _Preset {
const _Preset(this.label, this.days);
/// Spoken name only; what is painted is [glyph].
final String label;
final int? days;
/// "Any" is an infinity sign, "today" the today-calendar, a span its day
/// count beside a range-calendar, "custom" the edit-calendar.
Widget glyph() => Semantics(
label: label,
excludeSemantics: true,
container: true,
child: switch (this) {
any => const Icon(Icons.all_inclusive),
today => const Icon(Icons.today),
custom => const Icon(Icons.edit_calendar),
week || month => Row(
mainAxisSize: MainAxisSize.min,
children: [const Icon(Icons.date_range), Text(' $days')],
),
},
);
static const List<_Preset> dayPresets = [today, week, month];
}

View File

@ -1,13 +1,13 @@
import 'dart:async';
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/app_settings.dart';
import 'package:todo/data/note.dart';
import 'package:todo/data/note_repository.dart';
import 'package:todo/data/note_template.dart';
import 'package:todo/ui/attachment_picking.dart';
import 'package:todo/ui/confirm_delete.dart';
import 'package:todo/ui/image_attach.dart';
import 'package:todo/ui/image_input.dart';
import 'package:todo/ui/note_form.dart';
@ -85,12 +85,7 @@ class _NoteDetailScreenState extends State<NoteDetailScreen> {
_persist(_note.copyWith(text: text, updatedAt: DateTime.now()));
Future<void> _delete() async {
final confirmed = await confirmDestructive(
context,
title: 'Delete note?',
message: 'This cannot be undone.',
);
if (!confirmed) return;
if (!await confirmDeleteNote(context)) return;
await widget.repository.delete(_note.id);
if (mounted) Navigator.of(context).pop();
}
@ -100,13 +95,15 @@ class _NoteDetailScreenState extends State<NoteDetailScreen> {
final title = noteTitle(_note.text);
return Scaffold(
appBar: AppBar(
title: Text(title.isEmpty ? '(empty)' : title),
// An untitled note shows no title rather than a written placeholder.
title: title.isEmpty ? null : Text(title),
actions: [
AttachButton(
onFiles: _attachFiles,
picking: widget.attachmentPicking,
),
IconButton(
tooltip: 'copy',
icon: Icon(
_copied ? Icons.check : Icons.copy_all,
semanticLabel: 'Copy',
@ -114,8 +111,11 @@ class _NoteDetailScreenState extends State<NoteDetailScreen> {
onPressed: _copy,
),
IconButton(
tooltip: 'Delete note',
icon: const Icon(Icons.delete_outline),
tooltip: 'delete',
icon: const Icon(
Icons.delete_outline,
semanticLabel: 'Delete note',
),
onPressed: _delete,
),
],

View File

@ -1,8 +1,8 @@
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note.dart';
import 'package:todo/data/note_template.dart';
import 'package:todo/ui/cue_snack.dart';
import 'package:todo/ui/image_attach.dart';
import 'package:todo/ui/markdown_view.dart';
import 'package:todo/ui/note_editor_chrome.dart';
@ -127,9 +127,12 @@ class _NoteEditorState extends State<NoteEditor> {
case NoteEditorMode.guided:
// raw -> guided: only if the edited text still fits the template.
if (!_doc.tryAdoptGuided()) {
showError(
// The mode toggle staying on raw is the second channel.
showCue(
context,
Icons.rule,
"Text doesn't match the template — staying in raw",
error: true,
);
return;
}

View File

@ -6,10 +6,11 @@
/// built in Preview and Raw.
library;
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note_template.dart';
import 'package:todo/ui/note_editor_mode.dart';
import 'package:todo/ui/template_glyphs.dart';
/// Template dropdown above a segmented View / Guided / Raw selector.
class NoteEditorChrome extends StatelessWidget {
@ -43,20 +44,20 @@ class NoteEditorChrome extends StatelessWidget {
DropdownButtonFormField<String>(
initialValue: template.id,
decoration: const InputDecoration(
labelText: 'Template',
// A prefix, not a floating label: a floated icon sat on the
// border on top of the selected template's glyph.
prefixIcon: Icon(Icons.description, semanticLabel: 'Template'),
isDense: true,
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
),
items: [
for (final t in NoteTemplate.all)
DropdownMenuItem(value: t.id, child: Text(t.label)),
DropdownMenuItem(value: t.id, child: templateGlyph(t)),
],
onChanged: (id) {
if (id == null) return;
onTemplateSelected(
NoteTemplate.all.firstWhere((t) => t.id == id),
);
onTemplateSelected(NoteTemplate.all.firstWhere((t) => t.id == id));
},
),
const SizedBox(height: 8),
@ -67,8 +68,7 @@ class NoteEditorChrome extends StatelessWidget {
segments: [
const ButtonSegment(
value: NoteEditorMode.preview,
icon: Icon(Icons.visibility_outlined),
label: Text('View'),
icon: Icon(Icons.visibility_outlined, semanticLabel: 'View'),
),
// Guided is offered for any structured template; tapping it
// on an empty draft opens the wizard, and is blocked at
@ -76,13 +76,11 @@ class NoteEditorChrome extends StatelessWidget {
if (!template.isFreeform)
const ButtonSegment(
value: NoteEditorMode.guided,
icon: Icon(Icons.checklist),
label: Text('Guided'),
icon: Icon(Icons.checklist, semanticLabel: 'Guided'),
),
const ButtonSegment(
value: NoteEditorMode.raw,
icon: Icon(Icons.notes),
label: Text('Raw'),
icon: Icon(Icons.notes, semanticLabel: 'Raw'),
),
],
selected: {mode},

View File

@ -12,7 +12,7 @@
/// [body] and the editor shows the raw field instead.
library;
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note_template.dart';

View File

@ -5,7 +5,7 @@
library;
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
/// A full-height plain-text field for the note's assembled Markdown.
class NoteEditorRawField extends StatelessWidget {
@ -44,10 +44,8 @@ class NoteEditorRawField extends StatelessWidget {
textAlignVertical: TextAlignVertical.top,
keyboardType: TextInputType.multiline,
style: Theme.of(context).textTheme.bodyLarge,
decoration: const InputDecoration(
border: InputBorder.none,
hintText: 'Write your idea…',
),
// No hint: the cursor in an empty full-height box says "type".
decoration: const InputDecoration(border: InputBorder.none),
onChanged: (_) => onChanged(),
),
),

View File

@ -12,10 +12,11 @@
library;
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note_template.dart';
import 'package:todo/ui/motion.dart';
import 'package:todo/ui/template_glyphs.dart';
/// One step of the guided editor: label, guidance, input, and navigation.
class NoteEditorStepPage extends StatelessWidget {
@ -66,8 +67,8 @@ class NoteEditorStepPage extends StatelessWidget {
Align(
alignment: Alignment.centerLeft,
child: IconButton(
icon: const Icon(Icons.arrow_back),
tooltip: 'Exit guided',
tooltip: 'exit',
icon: const Icon(Icons.arrow_back, semanticLabel: 'Exit guided'),
onPressed: onExit,
),
),
@ -96,16 +97,14 @@ class NoteEditorStepPage extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
section.isTitle ? 'title' : section.label,
style: theme.textTheme.titleMedium,
),
const SizedBox(height: 4),
Text(
section.helper,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
// A glyph per section; its label (the note's `## heading`) and
// the helper sentence are spoken only.
Icon(
sectionIcon(section),
color: theme.colorScheme.primary,
semanticLabel: section.isTitle
? section.helper
: '${section.label}: ${section.helper}',
),
const SizedBox(height: 12),
],
@ -123,9 +122,10 @@ class NoteEditorStepPage extends StatelessWidget {
maxLines: null,
keyboardType: TextInputType.multiline,
textAlignVertical: TextAlignVertical.top,
decoration: InputDecoration(
hintText: section.hint,
border: const OutlineInputBorder(),
// No hintText: a hint is painted text. The section glyph
// above already names the field.
decoration: const InputDecoration(
border: OutlineInputBorder(),
isDense: true,
),
onChanged: (_) => onChanged(),
@ -140,16 +140,22 @@ class NoteEditorStepPage extends StatelessWidget {
if (index > 0)
TextButton(
onPressed: () => onGoToStep(index - 1),
child: const Text('Back'),
child: const Icon(
Icons.navigate_before,
semanticLabel: 'Back',
),
),
const Spacer(),
if (index < total - 1)
FilledButton(
onPressed: () => onGoToStep(index + 1),
child: const Text('Next'),
child: const Icon(Icons.navigate_next, semanticLabel: 'Next'),
)
else
FilledButton(onPressed: onExit, child: const Text('Done')),
FilledButton(
onPressed: onExit,
child: const Icon(Icons.check, semanticLabel: 'Done'),
),
],
),
),

View File

@ -9,10 +9,12 @@
/// make sense before there is anything to guide.
library;
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note.dart';
import 'package:todo/data/note_template.dart';
import 'package:todo/ui/enum_glyphs.dart';
import 'package:todo/ui/template_glyphs.dart';
/// Asks for a priority, then a template, then hands both back via [onStart].
class NoteEditorWizard extends StatefulWidget {
@ -48,7 +50,7 @@ class _NoteEditorWizardState extends State<NoteEditorWizard> {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final semanticLabel = 'Step ${_step + 1} of 2';
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
@ -56,11 +58,25 @@ class _NoteEditorWizardState extends State<NoteEditorWizard> {
Row(
children: [
IconButton(
icon: const Icon(Icons.close),
tooltip: 'Cancel',
tooltip: 'cancel',
icon: const Icon(Icons.close, semanticLabel: 'Cancel'),
onPressed: widget.onCancel,
),
Text('Step ${_step + 1} of 2', style: theme.textTheme.labelLarge),
// Two step dots, the current one filled: position by shape.
Semantics(
label: semanticLabel,
child: ExcludeSemantics(
child: Row(
children: [
for (var i = 0; i < 2; i++)
Icon(
i == _step ? Icons.circle : Icons.circle_outlined,
size: 12,
),
],
),
),
),
],
),
const SizedBox(height: 8),
@ -74,14 +90,14 @@ class _NoteEditorWizardState extends State<NoteEditorWizard> {
DropdownButtonFormField<Priority>(
initialValue: _priority,
decoration: const InputDecoration(
labelText: 'Priority',
prefixIcon: Icon(kPriorityHeadingIcon, semanticLabel: 'Priority'),
isDense: true,
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
),
items: [
for (final p in Priority.values)
DropdownMenuItem(value: p, child: Text(p.label)),
DropdownMenuItem(value: p, child: priorityGlyph(context, p)),
],
onChanged: (p) {
if (p != null) setState(() => _priority = p);
@ -92,7 +108,7 @@ class _NoteEditorWizardState extends State<NoteEditorWizard> {
alignment: Alignment.centerRight,
child: FilledButton(
onPressed: () => setState(() => _step = 1),
child: const Text('Next'),
child: const Icon(Icons.navigate_next, semanticLabel: 'Next'),
),
),
];
@ -104,14 +120,14 @@ class _NoteEditorWizardState extends State<NoteEditorWizard> {
DropdownButtonFormField<String>(
initialValue: _template.id,
decoration: const InputDecoration(
labelText: 'Template',
prefixIcon: Icon(Icons.description, semanticLabel: 'Template'),
isDense: true,
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 8),
),
items: [
for (final t in templates)
DropdownMenuItem(value: t.id, child: Text(t.label)),
DropdownMenuItem(value: t.id, child: templateGlyph(t)),
],
onChanged: (id) {
if (id == null) return;
@ -124,12 +140,12 @@ class _NoteEditorWizardState extends State<NoteEditorWizard> {
children: [
TextButton(
onPressed: () => setState(() => _step = 0),
child: const Text('Back'),
child: const Icon(Icons.arrow_back, semanticLabel: 'Back'),
),
const SizedBox(width: 8),
FilledButton(
onPressed: () => widget.onStart(_priority, _template),
child: const Text('Start'),
child: const Icon(Icons.play_arrow, semanticLabel: 'Start'),
),
],
),

View File

@ -8,7 +8,7 @@
/// defaults to false.
library;
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note.dart';
import 'package:todo/data/note_template.dart';

View File

@ -5,7 +5,7 @@
/// lives here so both surfaces resolve visibility by the same rule.
library;
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
/// Holds the editor's chrome-visibility signal and resolves it against
/// advanced mode.

View File

@ -2,10 +2,29 @@
library;
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note.dart';
import 'package:todo/data/note_template.dart';
import 'package:todo/ui/enum_glyphs.dart';
/// Danger for high, the accent for medium, muted for low.
Color priorityColor(Priority p, ColorScheme scheme) => switch (p) {
Priority.high => scheme.error,
Priority.medium => scheme.primary,
Priority.low => scheme.outline,
};
/// Painted in place of an empty note's title: a mark, not a word.
const String kEmptyTitle = '…';
/// The glyph standing for [s] wherever a status is shown without words.
IconData statusIcon(Status s) => switch (s) {
Status.todo => Icons.radio_button_unchecked,
Status.inProgress => Icons.timelapse,
Status.done => Icons.check_circle_outline,
Status.abandoned => Icons.cancel_outlined,
};
/// A note as a grid cell. It fills whatever cell it is given.
class NoteGridTile extends StatelessWidget {
@ -14,9 +33,13 @@ class NoteGridTile extends StatelessWidget {
required this.note,
required this.onTap,
required this.onActions,
this.selected = false,
super.key,
});
/// Whether the note is part of the multi-selection: a tint and a check.
final bool selected;
/// The note this tile displays.
final Note note;
@ -27,18 +50,7 @@ class NoteGridTile extends StatelessWidget {
final VoidCallback onActions;
/// Danger for high, the accent for medium, muted for low.
Color accentFor(ColorScheme scheme) => switch (note.priority) {
Priority.high => scheme.error,
Priority.medium => scheme.primary,
Priority.low => scheme.outline,
};
static IconData _statusIcon(Status s) => switch (s) {
Status.todo => Icons.radio_button_unchecked,
Status.inProgress => Icons.timelapse,
Status.done => Icons.check_circle_outline,
Status.abandoned => Icons.cancel_outlined,
};
Color accentFor(ColorScheme scheme) => priorityColor(note.priority, scheme);
@override
Widget build(BuildContext context) {
@ -49,7 +61,7 @@ class NoteGridTile extends StatelessWidget {
final closed =
note.status == Status.done || note.status == Status.abandoned;
return Material(
color: scheme.surfaceContainerHigh,
color: selected ? scheme.secondaryContainer : scheme.surfaceContainerHigh,
borderRadius: BorderRadius.circular(AppRadius.md),
clipBehavior: Clip.antiAlias,
child: InkWell(
@ -72,14 +84,30 @@ class NoteGridTile extends StatelessWidget {
children: [
// Expanded: a big text scale shortens the title, never overflows.
Expanded(
child: Text(
title.isEmpty ? '(empty)' : title,
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.bodyMedium?.copyWith(
color: closed ? scheme.onSurfaceVariant : null,
decoration: closed ? TextDecoration.lineThrough : null,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Text(
title.isEmpty ? kEmptyTitle : title,
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.bodyMedium?.copyWith(
color: closed ? scheme.onSurfaceVariant : null,
decoration: closed
? TextDecoration.lineThrough
: null,
),
),
),
if (selected)
Icon(
Icons.check_circle,
size: 20,
color: scheme.primary,
semanticLabel: 'Selected',
),
],
),
),
if (note.repoName case final repo?)
@ -91,25 +119,20 @@ class NoteGridTile extends StatelessWidget {
),
Row(
children: [
// Shape + the tile's accent border carry status/priority;
// the enum words survive only as spoken labels.
Icon(
_statusIcon(note.status),
statusIcon(note.status),
size: 14,
color: scheme.onSurfaceVariant,
),
const SizedBox(width: AppSpacing.xs),
Flexible(
child: Text(
note.status.label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: cue,
),
semanticLabel: note.status.label,
),
const Spacer(),
Text(
note.priority.label,
maxLines: 1,
style: cue?.copyWith(color: accentFor(scheme)),
Icon(
priorityIcon(note.priority),
size: 14,
color: accentFor(scheme),
semanticLabel: note.priority.label,
),
],
),

View File

@ -5,27 +5,33 @@
/// two cannot drift apart. Public only because Dart privacy is library-scoped.
library;
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note.dart';
import 'package:todo/ui/enum_glyphs.dart';
/// A compact labelled dropdown for picking an enum value (priority/status).
/// A compact dropdown for picking an enum value (priority/status), headed by
/// a glyph and showing each value as its glyph.
///
/// Generic over the enum type [T] so the same control drives both pickers
/// without duplication; [labelOf] maps a value to its display string.
/// without duplication; [glyphOf] maps a value to its glyph.
class MetaDropdown<T> extends StatelessWidget {
/// Creates a dropdown showing [value] out of [values].
const MetaDropdown({
required this.label,
required this.heading,
required this.semanticLabel,
required this.value,
required this.values,
required this.labelOf,
required this.glyphOf,
required this.onChanged,
super.key,
});
/// Label shown above the control.
final String label;
/// Glyph in the control's border in place of a written heading.
final IconData heading;
/// Spoken name of the control; never painted.
final String semanticLabel;
/// Currently selected value.
final T value;
@ -33,8 +39,8 @@ class MetaDropdown<T> extends StatelessWidget {
/// Every selectable value.
final List<T> values;
/// Maps a value to its display string.
final String Function(T) labelOf;
/// Maps a value to its glyph.
final Widget Function(T) glyphOf;
/// Called with the newly picked value.
final ValueChanged<T> onChanged;
@ -43,7 +49,7 @@ class MetaDropdown<T> extends StatelessWidget {
Widget build(BuildContext context) {
return InputDecorator(
decoration: InputDecoration(
labelText: label,
prefixIcon: Icon(heading, semanticLabel: semanticLabel),
isDense: true,
border: const OutlineInputBorder(),
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
@ -55,7 +61,7 @@ class MetaDropdown<T> extends StatelessWidget {
isExpanded: true,
items: [
for (final v in values)
DropdownMenuItem<T>(value: v, child: Text(labelOf(v))),
DropdownMenuItem<T>(value: v, child: glyphOf(v)),
],
onChanged: (v) {
if (v != null) onChanged(v);
@ -98,20 +104,22 @@ class NoteMetaRow extends StatelessWidget {
children: [
Expanded(
child: MetaDropdown<Priority>(
label: 'Priority',
heading: kPriorityHeadingIcon,
semanticLabel: 'Priority',
value: priority,
values: Priority.values,
labelOf: (p) => p.label,
glyphOf: (p) => priorityGlyph(context, p),
onChanged: onPriorityChanged,
),
),
const SizedBox(width: 12),
Expanded(
child: MetaDropdown<Status>(
label: 'Status',
heading: kStatusHeadingIcon,
semanticLabel: 'Status',
value: status,
values: Status.values,
labelOf: (s) => s.label,
glyphOf: statusGlyph,
onChanged: onStatusChanged,
),
),

View File

@ -0,0 +1,86 @@
/// Which notes of the list are selected, and whether a tap selects.
library;
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:todo/data/note.dart';
/// The notes list's multi-select state.
///
/// Holds ids, not notes, so a selection survives the list re-emitting
/// (a bulk status change rebuilds every tile). Selection order is kept, so
/// an assign appends the notes in the order they were picked.
class NoteSelection extends ChangeNotifier {
final Set<String> _ids = {};
bool _active = false;
String? _anchor;
/// Whether a plain tap selects rather than opens.
bool get active => _active;
/// The selected ids, in the order they were picked.
Set<String> get ids => Set.unmodifiable(_ids);
/// Whether [id] is selected.
bool contains(String id) => _ids.contains(id);
/// Enters selection mode, or leaves it and drops the selection.
void toggleMode() {
if (_active) return clear();
_active = true;
notifyListeners();
}
/// Flips [id] in or out of the selection; enters the mode.
void toggle(String id) {
_active = true;
if (!_ids.remove(id)) _ids.add(id);
_anchor = id;
notifyListeners();
}
/// Selects every note of [order] from the last toggled one to [id]
/// (Shift-click); without an anchor in [order] it is a [toggle].
void extendTo(String id, List<Note> order) {
final from = order.indexWhere((n) => n.id == _anchor);
final to = order.indexWhere((n) => n.id == id);
if (from < 0 || to < 0) return toggle(id);
final (lo, hi) = from < to ? (from, to) : (to, from);
_ids.addAll(order.sublist(lo, hi + 1).map((n) => n.id));
_anchor = id;
notifyListeners();
}
/// Keeps only the selected ids in [keep] (e.g. the notes an assign
/// refused); an empty result is a [clear].
void retain(Set<String> keep) {
_ids.retainWhere(keep.contains);
if (_ids.isEmpty) return clear();
notifyListeners();
}
/// Drops the selection and leaves the mode.
void clear() {
_ids.clear();
_active = false;
_anchor = null;
notifyListeners();
}
/// Handles a tap on [note] of the list [order]; false means "open it".
///
/// Shift extends, Ctrl/Cmd toggles even outside the mode (desktop), and in
/// the mode a plain tap toggles.
bool handleTap(Note note, List<Note> order) {
final keys = HardwareKeyboard.instance;
if (keys.isShiftPressed) {
extendTo(note.id, order);
} else if (_active || keys.isControlPressed || keys.isMetaPressed) {
toggle(note.id);
} else {
return false;
}
return true;
}
}

View File

@ -1,4 +1,4 @@
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note.dart';
import 'package:todo/images/attachment_links.dart';
@ -39,12 +39,25 @@ class NoteSheetDetails extends StatelessWidget {
Text(body, style: theme.bodyMedium),
],
const SizedBox(height: 12),
Text(
'Edited ${_stamp(note.updatedAt)}'
' · Created ${_stamp(note.createdAt)}',
style: theme.bodySmall,
Wrap(
spacing: 12,
children: [
_dated(Icons.history, 'Edited', note.updatedAt, theme.bodySmall),
_dated(Icons.add, 'Created', note.createdAt, theme.bodySmall),
],
),
],
);
}
/// A glyph (edited = history, created = plus) before its timestamp.
Widget _dated(IconData icon, String spoken, DateTime t, TextStyle? style) =>
Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(icon, size: 16, semanticLabel: spoken),
const SizedBox(width: 4),
Text(_stamp(t), style: style),
],
);
}

View File

@ -1,4 +1,4 @@
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note.dart';
/// Read-only repo-task fields of [note]; empty for a plain idea.
@ -12,20 +12,27 @@ class NoteTaskDetails extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context).textTheme;
// A glyph per field in place of its written name (kept spoken only);
// the values are content and stay as typed.
final rows = [
('Repo', note.repo),
('Done check', note.doneCheck),
('By', note.by),
('Evidence', note.evidence),
].where((row) => row.$2 != null);
(Icons.folder_outlined, 'Repo', note.repo),
(Icons.fact_check_outlined, 'Done check', note.doneCheck),
(Icons.person_outline, 'By', note.by),
(Icons.verified_outlined, 'Evidence', note.evidence),
].where((row) => row.$3 != null);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
for (final (label, value) in rows) ...[
for (final (icon, label, value) in rows) ...[
const SizedBox(height: 12),
Text(label, style: theme.labelLarge),
const SizedBox(height: 4),
Text(value!, style: theme.bodyMedium),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(icon, size: 20, semanticLabel: label),
const SizedBox(width: 8),
Expanded(child: Text(value!, style: theme.bodyMedium)),
],
),
],
],
);

View File

@ -4,10 +4,12 @@
/// Dart privacy is library-scoped.
library;
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note.dart';
import 'package:todo/data/note_template.dart';
import 'package:todo/ui/enum_glyphs.dart';
import 'package:todo/ui/note_grid_tile.dart';
/// One row in the notes list: title, metadata line, and an actions button.
class NoteTile extends StatelessWidget {
@ -16,9 +18,13 @@ class NoteTile extends StatelessWidget {
required this.note,
required this.onTap,
required this.onActions,
this.selected = false,
super.key,
});
/// Whether the row is part of the multi-selection: highlighted + a check.
final bool selected;
/// The note this row displays.
final Note note;
@ -33,23 +39,20 @@ class NoteTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
final firstLine = noteTitle(note.text);
// Every note has a status and a priority now, so both are always shown.
final meta = <String>[
note.status.label,
note.priority.label,
'edited ${_relative(note.updatedAt)}',
?note.repoName,
].join(' · ');
return ListTile(
selected: selected,
leading: selected
? const Icon(Icons.check_circle, semanticLabel: 'Selected')
: null,
title: Text(
firstLine.isEmpty ? '(empty)' : firstLine,
firstLine.isEmpty ? kEmptyTitle : firstLine,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
subtitle: Text(meta),
subtitle: _meta(context),
trailing: IconButton(
icon: const Icon(Icons.more_vert),
tooltip: 'Quick actions',
tooltip: 'actions',
icon: const Icon(Icons.more_vert, semanticLabel: 'Quick actions'),
onPressed: onActions,
),
onTap: onTap,
@ -57,14 +60,28 @@ class NoteTile extends StatelessWidget {
);
}
/// Compact relative time like "2m ago" for the list subtitle.
String _relative(DateTime t) {
final d = DateTime.now().difference(t);
if (d.inMinutes < 1) return 'just now';
if (d.inHours < 1) return '${d.inMinutes}m ago';
if (d.inDays < 1) return '${d.inHours}h ago';
return '${d.inDays}d ago';
}
/// Status and priority glyphs, the edit age, and the repo (content).
/// Every note has a status and a priority, so both are always shown.
Widget _meta(BuildContext context) => Row(
children: [
statusGlyph(note.status, size: 16),
const SizedBox(width: 6),
priorityGlyph(context, note.priority, size: 16),
const SizedBox(width: 6),
const Icon(Icons.history, size: 16, semanticLabel: 'Edited'),
Text(relativeAge(note.updatedAt)),
if (note.repoName case final repo?) ...[
const SizedBox(width: 6),
Flexible(child: Text(repo, overflow: TextOverflow.ellipsis)),
],
],
);
}
/// Bottom sheet for editing one note's priority/status or deleting it.
/// Compact age like "2m" / "3h" / "4d": a number plus a unit symbol.
String relativeAge(DateTime t) {
final d = DateTime.now().difference(t);
if (d.inHours < 1) return '${d.inMinutes}m';
if (d.inDays < 1) return '${d.inHours}h';
return '${d.inDays}d';
}

View File

@ -0,0 +1,37 @@
/// The selection bar's assign flow: pick a repo, move the notes into it.
///
/// Data-layer only ([assignToRepo]); the UI never reaches the board, so an
/// assign never starts a task.
library;
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note_repository.dart';
import 'package:todo/data/repo_assign.dart';
import 'package:todo/ui/note_selection.dart';
import 'package:todo/ui/repo_picker_sheet.dart';
/// Asks for a repo and assigns the selected plain notes to it, in
/// selection order. True when some notes were refused (already in a repo);
/// those stay selected, the moved ones leave the selection.
Future<bool> assignSelection(
BuildContext context,
NoteRepository repository,
NoteSelection selection,
) async {
final all = await repository.listNotes();
final repos = {for (final n in all) ?n.repo}.toList()..sort();
if (!context.mounted) return false;
final repo = await showModalBottomSheet<String>(
context: context,
isScrollControlled: true,
showDragHandle: true,
builder: (_) => RepoPickerSheet(repos: repos),
);
if (repo == null) return false;
final byId = {for (final n in all) n.id: n};
final chosen = [for (final id in selection.ids) ?byId[id]];
final refused = await assignToRepo(repository, chosen, repo);
selection.retain({for (final n in refused) n.id});
return refused.isNotEmpty;
}

View File

@ -6,10 +6,11 @@
/// `_NotesListScreenState._openFilters`.
library;
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note.dart';
import 'package:todo/data/note_repository.dart';
import 'package:todo/ui/enum_glyphs.dart';
import 'package:todo/ui/note_date_range_field.dart';
import 'package:todo/ui/notes_list_defaults.dart';
@ -66,7 +67,6 @@ class _FilterSheetState extends State<FilterSheet> {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return SafeArea(
child: Padding(
padding: EdgeInsets.fromLTRB(
@ -82,33 +82,38 @@ class _FilterSheetState extends State<FilterSheet> {
children: [
Row(
children: [
Text('Filters', style: theme.textTheme.titleLarge),
const Icon(Icons.filter_list, semanticLabel: 'Filters'),
const Spacer(),
TextButton(
onPressed: _clearAll,
child: const Text('Clear all'),
child: const Icon(Icons.clear, semanticLabel: 'Clear all'),
),
],
),
const SizedBox(height: 8),
_MultiChips<Status>(
label: 'Status',
GlyphChips<Status>(
multi: true,
heading: kStatusHeadingIcon,
semanticLabel: 'Status',
values: Status.values,
selected: _statuses,
labelOf: (s) => s.label,
onToggle: (s) => _toggle(_statuses, s),
glyphOf: statusGlyph,
onTap: (s) => _toggle(_statuses, s),
),
const SizedBox(height: 12),
_MultiChips<Priority>(
label: 'Priority',
GlyphChips<Priority>(
multi: true,
heading: kPriorityHeadingIcon,
semanticLabel: 'Priority',
values: Priority.values,
selected: _priorities,
labelOf: (p) => p.label,
onToggle: (p) => _toggle(_priorities, p),
glyphOf: (p) => priorityGlyph(context, p),
onTap: (p) => _toggle(_priorities, p),
),
const SizedBox(height: 12),
DateRangeField(
label: 'Created',
icon: kCreatedIcon,
semanticLabel: 'Created',
from: _createdFrom,
to: _createdTo,
onChanged: (from, to) => setState(() {
@ -118,7 +123,8 @@ class _FilterSheetState extends State<FilterSheet> {
),
const SizedBox(height: 12),
DateRangeField(
label: 'Last updated',
icon: kUpdatedIcon,
semanticLabel: 'Last updated',
from: _updatedFrom,
to: _updatedTo,
onChanged: (from, to) => setState(() {
@ -129,7 +135,7 @@ class _FilterSheetState extends State<FilterSheet> {
const SizedBox(height: 20),
FilledButton(
onPressed: () => Navigator.of(context).pop(_build()),
child: const Text('Apply'),
child: const Icon(Icons.check, semanticLabel: 'Apply'),
),
],
),
@ -139,45 +145,6 @@ class _FilterSheetState extends State<FilterSheet> {
}
}
/// Multi-select chip group for an enum (used by the filter sheet).
class _MultiChips<T> extends StatelessWidget {
const _MultiChips({
required this.label,
required this.values,
required this.selected,
required this.labelOf,
required this.onToggle,
});
final String label;
final List<T> values;
final Set<T> selected;
final String Function(T) labelOf;
final ValueChanged<T> onToggle;
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label, style: Theme.of(context).textTheme.labelLarge),
const SizedBox(height: 8),
Wrap(
spacing: 8,
children: [
for (final v in values)
FilterChip(
label: Text(labelOf(v)),
selected: selected.contains(v),
onSelected: (_) => onToggle(v),
),
],
),
],
);
}
}
/// A date-range control offering quick presets plus a custom range picker.
///
/// Reports the chosen [from]/[to] (day granularity, both inclusive) back to

View File

@ -1,7 +1,7 @@
import 'dart:math' as math;
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note.dart';
import 'package:todo/ui/note_grid_tile.dart';
@ -26,9 +26,13 @@ class NotesGrid extends StatelessWidget {
required this.notes,
required this.onOpen,
required this.onActions,
required this.isSelected,
super.key,
});
/// Whether the note with this id is in the multi-selection.
final bool Function(String id) isSelected;
/// Notes in display order.
final List<Note> notes;
@ -42,6 +46,7 @@ class NotesGrid extends StatelessWidget {
return NoteGridTile(
key: ValueKey(note.id),
note: note,
selected: isSelected(note.id),
onTap: () => onOpen(note),
onActions: () => onActions(note),
);

View File

@ -3,7 +3,7 @@
/// Split out of `notes_list_screen.dart` for file size.
library;
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note.dart';
import 'package:todo/ui/note_tile.dart';
@ -16,9 +16,13 @@ class NotesListBody extends StatelessWidget {
required this.notes,
required this.onOpen,
required this.onActions,
required this.isSelected,
super.key,
});
/// Whether the note with this id is in the multi-selection.
final bool Function(String id) isSelected;
/// Notes in display order.
final List<Note> notes;
@ -32,13 +36,19 @@ class NotesListBody extends StatelessWidget {
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, box) => box.maxWidth < kNotesGridMaxWidth
? NotesGrid(notes: notes, onOpen: onOpen, onActions: onActions)
? NotesGrid(
notes: notes,
onOpen: onOpen,
onActions: onActions,
isSelected: isSelected,
)
: ListView.separated(
itemCount: notes.length,
separatorBuilder: (_, _) => const Divider(height: 1),
itemBuilder: (context, i) => NoteTile(
key: ValueKey(notes[i].id),
note: notes[i],
selected: isSelected(notes[i].id),
onTap: () => onOpen(notes[i]),
onActions: () => onActions(notes[i]),
),

View File

@ -5,7 +5,7 @@
/// context, the note, and the store.
library;
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/app_settings.dart';
import 'package:todo/data/note.dart';
@ -32,6 +32,7 @@ Future<void> openNote(
repository: repository,
appSettings: appSettings,
),
name: '/notes/detail',
),
);
}

View File

@ -1,17 +1,23 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/app_settings.dart';
import 'package:todo/data/note.dart';
import 'package:todo/data/note_repository.dart';
import 'package:todo/ui/empty_notes_cue.dart';
import 'package:todo/ui/note_selection.dart';
import 'package:todo/ui/notes_assign_flow.dart';
import 'package:todo/ui/notes_filter_sheet.dart';
import 'package:todo/ui/notes_list_body.dart';
import 'package:todo/ui/notes_list_defaults.dart';
import 'package:todo/ui/notes_list_navigation.dart';
import 'package:todo/ui/notes_selection_bar.dart';
export 'package:todo/ui/notes_list_defaults.dart';
part 'notes_list_screen_select.dart';
/// Searchable, filterable, sortable list of stored/synced notes.
///
/// The heavy lifting (WHERE/ORDER BY) lives in [NoteRepository]; this screen
@ -53,25 +59,46 @@ class _NotesListScreenState extends State<NotesListScreen> {
/// Memoised stream; only replaced when [_sort]/[_filter] actually change.
late Stream<List<Note>> _stream;
/// Multi-select; any change rebuilds the screen (tiles + bottom bar).
late final _selection = NoteSelection()..addListener(() => setState(() {}));
@override
void initState() {
super.initState();
_stream = widget.repository.watchNotes(sort: _sort, filter: _filter);
_stream = _watch();
}
@override
void dispose() {
_debounce?.cancel();
_searchController.dispose();
_selection.dispose();
super.dispose();
}
/// Rebuilds the watch stream for the current sort + filter. Call only
/// from handlers that change those, never from [build].
void _applyState() {
setState(() {
_stream = widget.repository.watchNotes(sort: _sort, filter: _filter);
});
setState(() => _stream = _watch());
}
/// The query for the current sort + filter, minus Claude-made notes unless
/// this device's eye toggle is on.
Stream<List<Note>> _watch() => widget.repository.watchNotes(
sort: _sort,
filter: _filter.copyWith(
hideClaude: !widget.appSettings.value.showClaudeNotes,
),
);
Future<void> _toggleClaudeNotes() async {
final settings = widget.appSettings.value;
final next = await settings.withShowClaudeNotes(
value: !settings.showClaudeNotes,
);
if (!mounted) return;
widget.appSettings.value = next;
_applyState();
}
void _onSearchChanged(String value) {
@ -108,32 +135,21 @@ class _NotesListScreenState extends State<NotesListScreen> {
final badgeCount = userFacetCount(_filter);
return Scaffold(
appBar: AppBar(
title: const Text('Notes'),
title: const Icon(Icons.note, semanticLabel: 'Notes'),
actions: [
PopupMenuButton<NoteSort>(
tooltip: 'Sort',
icon: const Icon(Icons.sort),
initialValue: _sort,
onSelected: _setSort,
itemBuilder: (_) => const [
PopupMenuItem(
value: NoteSort.modifiedDesc,
child: Text('Last updated'),
),
PopupMenuItem(
value: NoteSort.createdDesc,
child: Text('Newest created'),
),
PopupMenuItem(
value: NoteSort.alphabetical,
child: Text('Alphabetical'),
),
PopupMenuItem(
value: NoteSort.priorityDesc,
child: Text('Priority'),
),
],
_selectButton(),
// Eye, no label: open = Claude-made notes shown, slashed = hidden.
IconButton(
tooltip: 'claude',
icon: Icon(
widget.appSettings.value.showClaudeNotes
? Icons.visibility
: Icons.visibility_off,
semanticLabel: 'Claude notes',
),
onPressed: _toggleClaudeNotes,
),
_sortButton(),
// Filter icon with a badge counting user-applied facets. The
// trailing padding + inward offset keep the badge from being
// clipped at the screen edge.
@ -144,8 +160,8 @@ class _NotesListScreenState extends State<NotesListScreen> {
label: Text('$badgeCount'),
offset: const Offset(-8, 4),
child: IconButton(
tooltip: 'Filter',
icon: const Icon(Icons.filter_list),
tooltip: 'filter',
icon: const Icon(Icons.filter_list, semanticLabel: 'Filter'),
onPressed: _openFilters,
),
),
@ -161,15 +177,16 @@ class _NotesListScreenState extends State<NotesListScreen> {
onChanged: _onSearchChanged,
textInputAction: TextInputAction.search,
decoration: InputDecoration(
hintText: 'Search notes…',
prefixIcon: const Icon(Icons.search),
isDense: true,
border: const OutlineInputBorder(),
suffixIcon: _searchController.text.isEmpty
? null
: IconButton(
tooltip: 'Clear search',
icon: const Icon(Icons.clear),
icon: const Icon(
Icons.clear,
semanticLabel: 'Clear search',
),
onPressed: () {
_searchController.clear();
_onSearchChanged('');
@ -186,27 +203,21 @@ class _NotesListScreenState extends State<NotesListScreen> {
final notes = snapshot.data ?? const <Note>[];
if (notes.isEmpty) {
return Center(
child: Text(
_filter.isEmpty
? 'No notes yet'
: 'No notes match these filters',
),
child: EmptyNotesCue(filtered: !_filter.isEmpty),
);
}
void open(Note n) =>
openNote(context, n, widget.repository, widget.appSettings);
void actions(Note n) =>
openNoteActions(context, n, widget.repository);
return NotesListBody(
notes: notes,
onOpen: open,
onActions: actions,
onOpen: (n) => _tap(n, notes),
onActions: _longPress,
isSelected: _selection.contains,
);
},
),
),
],
),
bottomNavigationBar: _selectionBar(),
);
}
}

View File

@ -0,0 +1,83 @@
/// The notes list's multi-select wiring: the app-bar toggle, taps, and the
/// bottom action bar.
///
/// A `part` of `notes_list_screen.dart` because it reads the screen's
/// private selection and repository; split out for file size.
part of 'notes_list_screen.dart';
extension _Selecting on _NotesListScreenState {
/// App-bar toggle into and out of selection mode (tinted while on).
Widget _selectButton() => IconButton(
key: const ValueKey('select-mode'),
tooltip: 'select',
isSelected: _selection.active,
onPressed: _selection.toggleMode,
icon: const Icon(Icons.checklist, semanticLabel: 'Select'),
);
/// A tap on [note] of [notes]: selects in the mode or with Shift/Ctrl,
/// else opens it.
void _tap(Note note, List<Note> notes) {
if (_selection.handleTap(note, notes)) return;
unawaited(openNote(context, note, widget.repository, widget.appSettings));
}
/// A long-press: toggles in the mode, else the per-note sheet.
void _longPress(Note note) {
if (_selection.active) return _selection.toggle(note.id);
unawaited(openNoteActions(context, note, widget.repository));
}
/// The bar, only while something is selected. Status and priority are
/// ONE store write for the whole selection ([NoteRepository.bulkUpdate]).
Widget? _selectionBar() {
if (_selection.ids.isEmpty) return null;
final repo = widget.repository;
return NotesSelectionBar(
onStatus: (s) => unawaited(repo.bulkUpdate(_selection.ids, status: s)),
onPriority: (p) =>
unawaited(repo.bulkUpdate(_selection.ids, priority: p)),
onAssign: () => assignSelection(context, repo, _selection),
onClear: _selection.clear,
);
}
/// App-bar sort menu: one icon per order, each with a one-word tooltip.
Widget _sortButton() => PopupMenuButton<NoteSort>(
// One word, not omitted: null falls back to the painted "Show menu".
tooltip: 'sort',
icon: const Icon(Icons.sort, semanticLabel: 'Sort'),
initialValue: _sort,
onSelected: _setSort,
itemBuilder: (_) => const [
PopupMenuItem(
value: NoteSort.modifiedDesc,
child: Tooltip(
message: 'updated',
child: Icon(Icons.update, semanticLabel: 'Last updated'),
),
),
PopupMenuItem(
value: NoteSort.createdDesc,
child: Tooltip(
message: 'newest',
child: Icon(Icons.post_add, semanticLabel: 'Newest created'),
),
),
PopupMenuItem(
value: NoteSort.alphabetical,
child: Tooltip(
message: 'alphabetical',
child: Icon(Icons.sort_by_alpha, semanticLabel: 'Alphabetical'),
),
),
PopupMenuItem(
value: NoteSort.priorityDesc,
child: Tooltip(
message: 'priority',
child: Icon(Icons.flag_outlined, semanticLabel: 'Priority'),
),
),
],
);
}

View File

@ -0,0 +1,128 @@
/// The icon-only action bar shown while notes are selected.
library;
import 'dart:async';
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/note.dart';
import 'package:todo/ui/note_grid_tile.dart';
/// How long the assign icon shows the refusal block.
const kRefusalFlash = Duration(milliseconds: 1500);
/// Set status, set priority, assign to repo, clear: icons only.
///
/// One-word tooltips on hover/long-press per textgate rule.
class NotesSelectionBar extends StatefulWidget {
/// Creates the bar; every callback acts on the whole selection.
const NotesSelectionBar({
required this.onStatus,
required this.onPriority,
required this.onAssign,
required this.onClear,
super.key,
});
/// Sets every selected note's status.
final ValueChanged<Status> onStatus;
/// Sets every selected note's priority.
final ValueChanged<Priority> onPriority;
/// Runs the assign flow; true when some notes were refused.
final Future<bool> Function() onAssign;
/// Drops the selection.
final VoidCallback onClear;
@override
State<NotesSelectionBar> createState() => _NotesSelectionBarState();
}
class _NotesSelectionBarState extends State<NotesSelectionBar> {
Timer? _flash;
@override
void dispose() {
_flash?.cancel();
super.dispose();
}
Future<void> _assign() async {
if (!await widget.onAssign() || !mounted) return;
_flash?.cancel();
setState(() => _flash = Timer(kRefusalFlash, () => setState(() {})));
}
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final refused = _flash?.isActive ?? false;
return Material(
key: const ValueKey('selection-bar'),
color: scheme.surfaceContainer,
child: SafeArea(
top: false,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
PopupMenuButton<Status>(
key: const ValueKey('bulk-status'),
tooltip: 'status',
icon: const Icon(Icons.task_alt, semanticLabel: 'Set status'),
onSelected: widget.onStatus,
itemBuilder: (_) => [
for (final s in Status.values)
PopupMenuItem(
key: ValueKey('status-${s.name}'),
value: s,
child: Icon(statusIcon(s), semanticLabel: s.label),
),
],
),
PopupMenuButton<Priority>(
key: const ValueKey('bulk-priority'),
tooltip: 'priority',
icon: const Icon(
Icons.flag_outlined,
semanticLabel: 'Set priority',
),
onSelected: widget.onPriority,
itemBuilder: (_) => [
for (final p in Priority.values.reversed)
PopupMenuItem(
key: ValueKey('priority-${p.name}'),
value: p,
child: Icon(
Icons.flag,
color: priorityColor(p, scheme),
semanticLabel: p.label,
),
),
],
),
IconButton(
key: const ValueKey('bulk-assign'),
tooltip: 'assign',
onPressed: _assign,
icon: Icon(
refused ? Icons.block : Icons.drive_file_move_outline,
color: refused ? scheme.error : null,
semanticLabel: 'Assign to repo',
),
),
IconButton(
key: const ValueKey('bulk-clear'),
onPressed: widget.onClear,
icon: const Icon(
Icons.deselect,
semanticLabel: 'Clear selection',
),
),
],
),
),
);
}
}

View File

@ -0,0 +1,98 @@
/// Bottom sheet picking the repo selected notes are assigned to.
library;
import 'package:material_ui/material_ui.dart';
import 'package:todo/data/repo_assign.dart';
/// The repos already on notes, plus a field for a new `kuhyx/<name>`.
///
/// Pops with the chosen `owner/name`; dismissing it pops null. The field
/// starts at `kuhyx/` (content, not a label) and refuses anything that is
/// not `owner/name` with an error icon rather than words.
class RepoPickerSheet extends StatefulWidget {
/// Creates the picker listing [repos].
const RepoPickerSheet({required this.repos, super.key});
/// Distinct repos already present on notes, in display order.
final List<String> repos;
@override
State<RepoPickerSheet> createState() => _RepoPickerSheetState();
}
class _RepoPickerSheetState extends State<RepoPickerSheet> {
final _field = TextEditingController(text: 'kuhyx/');
bool _bad = false;
@override
void dispose() {
_field.dispose();
super.dispose();
}
void _submit() {
final value = _field.text.trim();
if (!isRepoName(value)) return setState(() => _bad = true);
Navigator.of(context).pop(value);
}
@override
Widget build(BuildContext context) {
return Padding(
key: const ValueKey('repo-picker'),
padding: EdgeInsets.only(bottom: MediaQuery.viewInsetsOf(context).bottom),
child: SafeArea(
top: false,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
child: ListView(
shrinkWrap: true,
children: [
for (final repo in widget.repos)
ListTile(
key: ValueKey('repo-$repo'),
leading: const Icon(Icons.folder_outlined),
title: Text(repo),
onTap: () => Navigator.of(context).pop(repo),
),
],
),
),
Padding(
padding: const EdgeInsets.all(12),
child: TextField(
key: const ValueKey('repo-new'),
controller: _field,
textInputAction: TextInputAction.done,
onSubmitted: (_) => _submit(),
onChanged: (_) {
if (_bad) setState(() => _bad = false);
},
decoration: InputDecoration(
border: const OutlineInputBorder(),
prefixIcon: const Icon(Icons.create_new_folder_outlined),
error: _bad
? const Icon(
Icons.error_outline,
size: 16,
semanticLabel: 'Not owner/name',
)
: null,
suffixIcon: IconButton(
key: const ValueKey('repo-new-submit'),
tooltip: 'use',
onPressed: _submit,
icon: const Icon(Icons.check, semanticLabel: 'Use repo'),
),
),
),
),
],
),
),
);
}
}

View File

@ -1,9 +1,12 @@
import 'dart:async';
import 'package:crdt_sync/crdt_sync.dart';
import 'package:crdt_sync_flutter/crdt_sync_flutter.dart'
show E2ePassphraseButton;
import 'package:file_selector/file_selector.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:kuhy_credit/kuhy_credit.dart';
import 'package:material_ui/material_ui.dart';
import 'package:sync_settings_ui/sync_settings_ui.dart';
import 'package:todo/analytics/analytics_event.dart';
import 'package:todo/analytics/analytics_service.dart';
@ -13,11 +16,14 @@ import 'package:todo/sync/backlog_export.dart';
import 'package:todo/sync/firebase_backend.dart';
import 'package:todo/sync/google_sign_in_backend.dart';
import 'package:todo/sync/notes_markdown.dart';
import 'package:todo/sync/run_sync.dart';
import 'package:todo/sync/sync_settings.dart';
import 'package:todo/ui/app_route.dart';
import 'package:todo/ui/cloud_images_settings.dart';
import 'package:todo/ui/github_mirror_screen.dart';
part 'settings_screen_actions.dart';
/// Settings screen: the "Enable advanced" toggle plus links to the two sync
/// surfaces.
///
@ -105,11 +111,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
/// session is available, best-effort mirrors it so the choice follows the
/// user to their other devices.
///
/// The local write always lands — a signed-in-as-wrong-account device
/// throwing [FirebaseAuthError] out of `openFirebase()` must not take the
/// toggle down with it, so opening the client has its own try/catch,
/// separate from (and preceding) the try that guards the local write and
/// mirror push.
/// The local write always lands: a [FirebaseAuthError] from opening the
/// client (wrong account) is caught on its own, before the write.
Future<void> _setAdvancedMode(bool value) async {
final analytics = widget.analytics;
if (analytics != null) {
@ -140,73 +143,12 @@ class _SettingsScreenState extends State<SettingsScreen> {
}
}
/// Exports every note to a single Markdown file. On mobile this opens the
/// system share sheet; on desktop it writes the canonical `~/src/todo/
/// BACKLOG.md` so a future tool/agent has a stable path to read.
Future<void> _export() async {
final notes = await widget.repository.listNotes();
final markdown = NotesMarkdown.export(notes);
await exportBacklog(markdown, notes.length);
}
/// Imports notes from a user-picked Markdown file, merging by id so a
/// stale backup never clobbers a newer local edit (see
/// [NoteRepository.importNotes]).
Future<void> _import() async {
const group = XTypeGroup(
label: 'Markdown',
extensions: ['md', 'markdown', 'txt'],
// UTIs/MIME so the picker accepts the file on iOS/Android too.
uniformTypeIdentifiers: ['net.daringfireball.markdown', 'public.text'],
mimeTypes: ['text/markdown', 'text/plain'],
);
final file = await openFile(acceptedTypeGroups: const [group]);
if (file == null) return; // user cancelled
final content = await file.readAsString();
final notes = NotesMarkdown.parse(content);
await widget.repository.importNotes(notes);
}
Future<void> _openSyncSettings() async {
await Navigator.of(context).push<void>(
appRoute(
context,
(_) => SyncSettingsScreen(
accountLoader: widget.accountLoader ?? loadAccount,
accountSaver: widget.accountSaver ?? saveAccount,
accountClearer: widget.accountClearer ?? clearAccount,
sessionProbe: widget.sessionProbe ?? isFirebaseConfigured,
firebaseFactory: widget.firebaseFactory ?? openFirebase,
googleFirebaseFactory:
widget.googleFirebaseFactory ?? openFirebaseWithGoogle,
googleAvailable: widget.googleAvailable ?? googleSignInSupported,
backup: BackupSlot(label: 'notes', export: _export, import: _import),
),
),
);
}
Future<void> _openGitHubMirror() async {
await Navigator.of(context).push<SyncSettings>(
appRoute(
context,
(_) => GitHubMirrorScreen(
initial: widget.initial,
repository: widget.repository,
appSettings: widget.appSettings,
analytics: widget.analytics,
httpClient: widget.httpClient,
firebaseFactory: widget.firebaseFactory,
stateStore: widget.stateStore,
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Settings')),
appBar: AppBar(
title: const Icon(Icons.settings, semanticLabel: 'Settings'),
),
body: ListView(
padding: const EdgeInsets.all(16),
children: [
@ -214,33 +156,57 @@ class _SettingsScreenState extends State<SettingsScreen> {
valueListenable: widget.appSettings,
builder: (context, settings, _) => SwitchListTile(
contentPadding: EdgeInsets.zero,
title: const Text('Enable advanced'),
subtitle: const Text(
'Priority/status, templates, view modes, and sync details '
'in the capture screen',
),
secondary: const Icon(Icons.tune, semanticLabel: _advanced),
value: settings.advancedMode,
onChanged: (value) => unawaited(_setAdvancedMode(value)),
),
),
const Divider(),
ListTile(
contentPadding: EdgeInsets.zero,
title: const Text('Sync settings'),
subtitle: const Text('Firebase sync and notes backup'),
trailing: const Icon(Icons.chevron_right),
onTap: () => unawaited(_openSyncSettings()),
_link(
const Icon(Icons.sync, semanticLabel: 'Sync settings: Firebase'),
_openSyncSettings,
),
ValueListenableBuilder<bool>(
valueListenable: e2eLocked,
builder: (context, locked, _) => ListTile(
contentPadding: EdgeInsets.zero,
leading: E2ePassphraseButton(
locked: locked,
// A new passphrase is only proven by a sync that unlocks.
onSaved: () => unawaited(_syncNow()),
),
),
),
CloudImagesTile(httpClient: widget.httpClient),
ListTile(
contentPadding: EdgeInsets.zero,
title: const Text('Advanced sync (GitHub)'),
subtitle: const Text('Cutover mirror — not recommended'),
trailing: const Icon(Icons.chevron_right),
onTap: () => unawaited(_openGitHubMirror()),
_link(
Icon(
Icons.cloud_sync,
color: Theme.of(context).colorScheme.outline,
semanticLabel: 'Advanced sync (GitHub): not recommended',
),
_openGitHubMirror,
),
// kuhy's credit closes the list; its panel opens above the logo.
const Padding(
padding: EdgeInsets.all(16),
child: Align(
alignment: Alignment.centerLeft,
child: KuhyCredit(alignStart: true),
),
),
],
),
);
}
// Spoken only: what the advanced switch turns on.
static const _advanced = 'Enable advanced: priority, status, view modes';
/// A row that opens a sub-screen: its glyph (muted = not recommended).
Widget _link(Icon icon, Future<void> Function() open) => ListTile(
contentPadding: EdgeInsets.zero,
leading: icon,
trailing: const Icon(Icons.chevron_right),
onTap: () => unawaited(open()),
);
}

Some files were not shown because too many files have changed in this diff Show More