Offline notes queue: capture while offline, send to an agent once online

Closed
AU
2mo ago
+2151-69

Fixes #6483

What

Adds an offline notes queue: users can capture notes while offline, the notes are stored locally and survive app restarts, and once connectivity returns cmux hands each note to an agent. Every note shows a clear status — pending / sending / sent / failed.

How it works

Engine (OfflineNotesStore, fully unit-tested)

  • OfflineNote is a Codable value persisted as a JSON array under Application Support/cmux/offline-notes.json (atomic writes, reloaded on launch → survives restarts).
  • An NWPathMonitor-backed reachability monitor drains pending notes whenever connectivity is (re)gained. Draining is one-at-a-time with a reentrancy guard so overlapping flushes never double-send.
  • Failed notes are preserved with their error and are retryable (per-note or "Retry all"). Notes left as .sending by a crash/relaunch are normalized back to .pending on load.
  • Connectivity and the agent hand-off are injected behind protocols (OfflineNotesReachabilityMonitoring, OfflineNoteDispatching), so the queue logic is exercised deterministically in tests.

Delivery (OfflineNoteAgentDispatcher)

  • Stages each note non-destructively into the active workspace's agent composer (the macOS TextBox) draft — existing composer text is preserved and successive notes accumulate. This is the cleanest hand-off cmux supports natively; injecting a first prompt straight into a freshly-created agent session needs the web-renderer session handshake and is intentionally left as a follow-up. The protocol seam means that can change without touching the queue.

UI (OfflineNotesPanelView)

  • A new "Notes" right-sidebar mode, beta-gated and off by default (same pattern as Feed/Dock — toggle in Settings → Beta Features, or the command palette). Capture field + status badges + retry/send/clear actions. Rows receive immutable snapshots + closure bundles only (snapshot-boundary rule).

Tests

cmuxTests/OfflineNotesStoreTests.swift covers: persistence across store instances (restart), whitespace ignored, .sending→.pending normalization on load, offline does not flush, regaining connectivity flushes pending → sent, failure → failed → retry → sent, concurrent-flush reentrancy, and clearSent.

This is a feature (not a bug fix), so tests land with the implementation rather than as a separate red/green pair.

Localization & wiring

  • All user-facing strings localized in Resources/Localizable.xcstrings (en + ja).
  • No new keyboard shortcut (the mode intentionally has none), so no shortcut docs needed.
  • New files wired into project.pbxproj; normalize-pbxproj.py --check and lint-pbxproj-test-wiring.sh pass.

Notes / scope

  • The store is created lazily when the Notes panel is first opened; once created it lives for the session and keeps monitoring connectivity. Auto-flush on reconnect therefore applies once the feature has been engaged this session (reasonable for an opt-in beta).

🤖 Generated with Claude Code


Summary by cubic

Adds an offline notes queue so you can capture notes while offline, keep them across restarts, and auto-send to an agent once back online or immediately when captured online. Addresses #6483 and adds a beta right‑sidebar Notes mode with clear pending/sending/staged/failed states.

  • New Features

    • Persistent OfflineNotesStore (@Observable) with per-note status and retry. JSON in Application Support, namespaced per bundle ID; single serialized writer (ordered, off-main) with a termination flush; normalizes .sending to .pending on load; uses .staged for delivered notes (legacy .sent supported).
    • Bounded queue: truncate notes to 4k Unicode scalars, keep 100 sent, cap 200 total; extra captures are refused. Load path re‑caps note text, evicts oldest sent beyond cap, keeps newest up to total cap, and skips oversized files.
    • Connectivity and lifecycle: auto‑flush on reconnect via NWPathMonitor, immediate dispatch when captured online, queue starts at app launch (beta‑gated) with startup deferred; flush runs when Notes opens, on app activation, and on workspace selection so deferred notes deliver when their workspace becomes visible.
    • OfflineNoteAgentDispatcher: delivers only to the currently visible workspace the note was captured in; otherwise the note stays pending. Stages text visibly and non‑destructively into that workspace’s focused terminal agent composer; localized errors; fails closed if no target.
    • Notes sidebar (beta, off by default): capture field, online/offline indicator, per‑note Retry/Delete, bulk Retry/Send/Clear Sent. Toggle via Settings → Beta Features, the command palette, or the CLI (cmux right-sidebar set notes). All strings localized (en/ja); CLI and remote help now list notes, and Settings search includes notes.
  • Bug Fixes

    • Isolated queue file per app variant (offline-notes-<bundleId>.json) with safe path sanitization to prevent cross‑bundle overwrites.
    • Reachability stop() now fully resets state and swaps in a fresh monitor so start() can resume; prevents losing connectivity updates after a stop/start cycle.
    • Avoids stranding notes if a flush runs before any window exists or before the captured/visible workspace is available: treated as transient (note stays pending and doesn’t block others) and retried later.
    • Stabilized command‑palette mode tests by clearing the Notes beta key in defaults.
    • Fixed a visibility issue in the Offline Note row helper.

Summary by CodeRabbit

  • New Features
    • Added a beta Notes option to the right sidebar for capturing and viewing offline notes, with command palette and CLI mode support.
    • Notes are queued for persistent delivery when connectivity returns, with online/offline status, empty state, and per-note error messaging.
    • Added Notes beta settings, including localized labels and improved settings search aliases.
  • Bug Fixes
    • Improved Notes-mode right-sidebar focus behavior and ensured queued notes resume delivery reliably after reconnects and app lifecycle events.