Skip to content

Watcher: Switchable API environments with per-environment state - #98

Merged
wasimxyz merged 4 commits into
stagingfrom
cursor/switchable-watcher-environments
Jun 25, 2026
Merged

Watcher: Switchable API environments with per-environment state#98
wasimxyz merged 4 commits into
stagingfrom
cursor/switchable-watcher-environments

Conversation

@wasimxyz

@wasimxyz wasimxyz commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

Lets a watcher on a lab PC switch between staging, production, and preview (and back) without re-uploading its multi-TB historical backlog or corrupting one environment's upload history with another's.

  • Per-environment registrationWatcherConfig.watcher_id becomes a watcher_ids map (one id per environment) with transparent migration from the legacy single watcher_id. A derived watcher_id property returns the active environment's id.
  • Per-environment local state — state now lives in ~/.data-hub/watcher-<environment>.db instead of a shared watcher.db; the legacy file is renamed to the active environment on first start.
  • Baseline instead of an upload cap — new initial_scan mode (resolve_initial_scan() defaults production→full, staging/preview→new-only). In new-only, seed_baseline_files() records the existing on-disk backlog into a new baseline_files table so the initial scan skips it without uploading. Seeding is one-shot, gated on baseline_established().
  • Preview isolation — a meta table tracks the preview deployment URL; switching a preview to a new URL resets that env's DB so the new target gets a clean baseline.
  • Switching UX — new config set-environment ENV command plus an environment re-prompt in config edit. The switch validates the target API, reuses or registers a watcher, pushes config to the target, drops a watcher_stopped breadcrumb in the old environment, and on Windows rewrites only the service registry EnvPath.
  • Docsdocs/reference/watcher.md gains a "Switching environments" section, updated YAML/subcommand table, and refreshed local-state and initial-scan sections.

Test plan

New/updated tests cover: legacy config migration, per-env DB path + legacy rename + reset, baseline_files/meta tables and scan-skip, build_runtime baseline gating, the set-environment CLI matrix (reuse/register/no-register/api-error/preview redeploy), and the Windows registry env-path rewrite.

  • ruff check . and ruff format --check watcher — clean
  • pyright — 0 errors
  • pytest watcher/tests -m "not integration" — 420 passed

Made with Cursor

Allow a watcher to switch between staging, production, and preview and
back without re-uploading a PC's historical backlog or corrupting one
environment's upload history with another's.

- Store one watcher_id per environment (watcher_ids map) with transparent
  migration from the legacy single watcher_id.
- Isolate local state per environment (watcher-<env>.db), renaming the
  legacy watcher.db on first start.
- Add a baseline_files table and new-only initial-scan mode so staging and
  preview skip the existing on-disk backlog instead of uploading it;
  production defaults to a full scan.
- Add `config set-environment` (and env re-prompt in `config edit`) that
  validates the target API, reuses or registers a watcher, resets preview
  state on a deployment URL change, and rewrites the Windows service env path.

Co-authored-by: Cursor <cursoragent@cursor.com>
@vercel

vercel Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
data-hub Ready Ready Preview, Comment Jun 24, 2026 11:52pm

Request Review

@wasimxyz wasimxyz changed the title feat(watcher): switchable API environments with per-environment state Watcher: Switchable API environments with per-environment state Jun 24, 2026
@wasimxyz wasimxyz self-assigned this Jun 24, 2026
- Restore the target environment's API key after the switch breadcrumb so
  config edit's post-edit push targets the new environment, not the old.
- Make the preview redeploy decision read the seed URL from the DB meta
  (falling back to config) so the meta is load-bearing, not redundant.
- Add a baseline_seeded sentinel so an empty new-only watch dir isn't
  re-walked on every start.
- Mirror FileMonitor's is_file check in seed_baseline_files so baseline
  membership matches the live scan.
- Add tests for the edit+switch key flow and baseline sentinel; comment cleanup.

Co-authored-by: Cursor <cursoragent@cursor.com>
Fold the `new-only` backlog baselining into `FileMonitor`'s initial scan
instead of a separate pre-walk in `build_runtime`, so a fresh staging/
preview start pays for one directory walk rather than two (seed + scan).
`build_runtime` now only arms the gate via `seed_baseline`.

Also document the default behavior change prominently: a fresh `init` on
staging/preview skips the pre-existing backlog, while existing installs
(which carry upload/run history) are unaffected.

Co-authored-by: Cursor <cursoragent@cursor.com>
@wasimxyz
wasimxyz merged commit 15b344e into staging Jun 25, 2026
4 checks passed
@wasimxyz
wasimxyz deleted the cursor/switchable-watcher-environments branch June 25, 2026 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant