Watcher: Switchable API environments with per-environment state - #98
Merged
Conversation
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>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Lets a watcher on a lab PC switch between
staging,production, andpreview(and back) without re-uploading its multi-TB historical backlog or corrupting one environment's upload history with another's.WatcherConfig.watcher_idbecomes awatcher_idsmap (one id per environment) with transparent migration from the legacy singlewatcher_id. A derivedwatcher_idproperty returns the active environment's id.~/.data-hub/watcher-<environment>.dbinstead of a sharedwatcher.db; the legacy file is renamed to the active environment on first start.initial_scanmode (resolve_initial_scan()defaults production→full, staging/preview→new-only). Innew-only,seed_baseline_files()records the existing on-disk backlog into a newbaseline_filestable so the initial scan skips it without uploading. Seeding is one-shot, gated onbaseline_established().metatable 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.config set-environment ENVcommand plus an environment re-prompt inconfig edit. The switch validates the target API, reuses or registers a watcher, pushes config to the target, drops awatcher_stoppedbreadcrumb in the old environment, and on Windows rewrites only the service registryEnvPath.docs/reference/watcher.mdgains 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/metatables and scan-skip,build_runtimebaseline gating, theset-environmentCLI matrix (reuse/register/no-register/api-error/preview redeploy), and the Windows registry env-path rewrite.ruff check .andruff format --check watcher— cleanpyright— 0 errorspytest watcher/tests -m "not integration"— 420 passedMade with Cursor