feat(web): watch files, store keys and terminals on the host and retire the last seq 0 events

Merged
GN
8d ago
+1792-1301

Summary

  • The host still sends file changes, branch renames and browser-open requests as seq = 0 events. A client can miss one, and a client with no session subscription never gets it.
  • This change moves them to the state watches from the earlier watch PRs. It adds a store-key watch and a terminal-set watch. No seq = 0 event leaves the relay except the auth_required handshake frame.

Related Issue

Refs #1070

Searched open and closed PRs for the same problem. No PR covers it. This is the sixth PR for the read-model work in #1070. It builds on the state watch PRs (#1094, #1096). A follow-up PR adds the host-offline state and closes the issue.

Type of Change

  • feat: new feature
  • fix: bug fix
  • docs: documentation only
  • style: formatting or non-functional styling changes
  • refactor: internal cleanup with no behavior change
  • perf: performance improvement
  • test: adds or updates tests
  • build: build or dependency changes
  • ci: CI/CD workflow changes
  • chore: maintenance or tooling
  • revert: reverts a previous change

What Changed

  • The host has three new watches. fs is scoped by project and sends one debounced batch of changed paths per delta. store is scoped by key and sends the value after each write or delete. It accepts shared/... keys and the device/... keys of the connection's own device. terminals is scoped by project and lists its terminals without claim credentials.
  • watch_project, unwatch_project, fs_changed and fs_watch_ended are gone. The fs watch replaces them.
  • worktree_branch_renamed is a chat_history delta. browser_open_request is an agents delta.
  • A delta that the host cannot queue leaves a revision gap. The client then rebuilds from a fresh state.
  • The web client watches the explorer directories through the fs watch. It arms the watch once per project and re-arms it after a reconnect, a lost delta or a refusal.
  • The web client has a terminal-set hook and a watchStoreKey call. The branch-rename hook reads the chat_history delta.
  • The client no longer accepts events without a session. Only auth_required skips that check.
  • WS_PROTOCOL_VERSION goes from 6 to 7. An old client reloads once.
  • Desktop is unchanged.

How It Was Tested

  • bun run ci (Biome lint + format + imports, strict mode)
  • bun run typecheck
  • bun run test
  • cargo clippy --all-targets -- -D warnings (in src-tauri)
  • cargo test (in src-tauri)
  • Manual verification completed
  • Not applicable

Screenshots or Recordings

No user-visible UI change. The explorer, the terminal list and the branch name stay correct after a missed change or a reconnect. The tests cover the behavior.

CI & Review Gate

  • All CI checks pass (PR Validation, Rust Checks, Build Verification, Security Scans)
  • Code review comments from CodeRabbit / Claude have been addressed or resolved
  • No unresolved review findings remain

Checklist

  • My PR title follows the conventional commit format used by this repo
  • I linked the related issue or explained why none exists
  • I updated docs when needed
  • I added or updated tests when needed
  • I verified the change does not introduce unrelated modifications
  • I read AGENTS.md and followed the contributor guidelines
  • A human reviewed the complete diff before submission