Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
perf(dev): preserve Vite dep cache across boots; add --force re-bundle
trohitgd6352e6185cd
diff --git a/cli/cli.py b/cli/cli.pyindex d0075447..84822ec2 100644--- a/cli/cli.py+++ b/cli/cli.py@@ -62,10 +62,15 @@ def _dev("--daemon",help="Bind backend to 0.0.0.0 instead of 127.0.0.1.",),+ force: bool = typer.Option(+ False,+ "--force",+ help="Force Vite to re-bundle dependencies (recovers 'Outdated Optimize Dep' errors).",+ ),) -> None:from cli.commands.dev import dev_command- dev_command(daemon=daemon)+ dev_command(daemon=daemon, force=force)@app.command(diff --git a/cli/commands/dev.py b/cli/commands/dev.pyindex f55b7c4f..411873a1 100644--- a/cli/commands/dev.py+++ b/cli/commands/dev.py@@ -1,9 +1,19 @@"""``company dev`` -- replaces ``scripts/dev.js``.-Development launcher: validates the build, frees ports, clears the-Vite dep cache (fixes "Outdated Optimize Dep" errors), then spawns+Development launcher: validates the build, frees ports, then spawnsVite + uvicorn + temporal-server under ``Manager.run()``.+The Vite dep cache (``client/node_modules/.vite``) is preserved across+boots -- Vite self-invalidates it via the lockfile/config hashes in+``.vite/deps/_metadata.json``, and an unconditional wipe forced a full+esbuild re-optimize (minutes on Windows) on every first page load.+``--force`` maps to Vite's own force-re-bundle mechanism+(``optimizeDeps.force`` via the ``VITE_FORCE`` env var, read in+``client/vite.config.js``) -- the documented recovery for an+"Outdated Optimize Dep" error. Env var rather than argv because the+client spec runs ``pnpm run client:start`` -> ``npm run start`` and a+``--force`` suffix does not survive the double ``npm run`` indirection.+uvicorn ``--reload``-style restarts (exit code 1) used to cascade-killthe frontend under ``concurrently --kill-others``. Our supervisortreats each service independently, so a backend reload doesn't touch@@ -14,7 +24,6 @@ from __future__ import annotationsimport asyncioimport os-import shutilfrom pathlib import Pathimport typer@@ -38,18 +47,9 @@ def _has_vite(root: Path) -> bool:).exists()-def _clear_vite_cache(root: Path) -> None:- cache = root / "client" / "node_modules" / ".vite"- if not cache.exists():- return- try:- shutil.rmtree(cache)- console.print("Cleared Vite cache")- except OSError as exc:- console.print(f"[yellow]Warning: Could not clear Vite cache: {exc}[/]")---def _build_specs(root: Path, cfg, *, daemon: bool, use_vite: bool) -> list[ServiceSpec]:+def _build_specs(+ root: Path, cfg, *, daemon: bool, use_vite: bool, force: bool = False+) -> list[ServiceSpec]:if use_vite:client_spec = ServiceSpec(name="client",@@ -57,6 +57,7 @@ def _build_specs(root: Path, cfg, *, daemon: bool, use_vite: bool) -> list[Servicwd=root,ready_port=cfg.client_port,ready_timeout=60.0,+ env={"VITE_FORCE": "1"} if force else {},)else:client_spec = ServiceSpec(@@ -77,6 +78,11 @@ def dev_command("--daemon",help="Bind backend to 0.0.0.0 instead of 127.0.0.1.",),+ force: bool = typer.Option(+ False,+ "--force",+ help="Force Vite to re-bundle dependencies (recovers 'Outdated Optimize Dep' errors).",+ ),) -> None:# Layer ``.env.dev`` (committed) on top of ``.env.template`` + ``.env``# so dev state lands at ``<repo>/.opencompany/`` (per-checkout) instead@@ -101,14 +107,16 @@ def dev_command(free_all_ports(cfg)console.log("Ports ready")- _clear_vite_cache(root)-use_vite = _has_vite(root)console.print(f"Client: {'Vite dev server' if use_vite else 'Static server'}")+ if force:+ console.print("Vite: forced dependency re-bundle (--force)")console.print()manager = Manager()- manager.add_all(_build_specs(root, cfg, daemon=daemon, use_vite=use_vite))+ manager.add_all(+ _build_specs(root, cfg, daemon=daemon, use_vite=use_vite, force=force)+ )rc = asyncio.run(manager.run())if rc != 0:raise typer.Exit(code=rc)diff --git a/cli/tests/test_dev.py b/cli/tests/test_dev.pyindex bca1043d..57d9d1d3 100644--- a/cli/tests/test_dev.py+++ b/cli/tests/test_dev.py@@ -30,17 +30,30 @@ def test_has_vite_true_when_in_client_node_modules(tmp_path: Path):assert dev._has_vite(tmp_path) is True-def test_clear_vite_cache_no_op_when_missing(tmp_path: Path):- # Just shouldn't raise.- dev._clear_vite_cache(tmp_path)+def test_dev_command_force_flag_defaults_false():+ # The Vite dep cache must survive normal boots -- an unconditional+ # wipe forced a full esbuild re-optimize (minutes on Windows) on+ # every first page load. ``--force`` is the explicit opt-in and maps+ # to Vite's own ``optimizeDeps.force`` via the VITE_FORCE env var.+ import inspect+ params = inspect.signature(dev.dev_command).parameters+ assert "force" in params+ assert params["force"].default.default is False # typer.Option wrapper-def test_clear_vite_cache_removes_present(tmp_path: Path):- cache = tmp_path / "client" / "node_modules" / ".vite"- cache.mkdir(parents=True)- (cache / "deps.json").write_text("{}")- dev._clear_vite_cache(tmp_path)- assert not cache.exists()++def test_build_specs_force_sets_vite_force_env(tmp_path: Path):+ cfg = _cfg()+ specs = dev._build_specs(tmp_path, cfg, daemon=False, use_vite=True, force=True)+ client = next(s for s in specs if s.name == "client")+ assert client.env.get("VITE_FORCE") == "1"+++def test_build_specs_default_does_not_set_vite_force_env(tmp_path: Path):+ cfg = _cfg()+ specs = dev._build_specs(tmp_path, cfg, daemon=False, use_vite=True)+ client = next(s for s in specs if s.name == "client")+ assert "VITE_FORCE" not in client.envdef test_build_specs_dev_uses_vite_when_available(tmp_path: Path):diff --git a/client/vite.config.js b/client/vite.config.jsindex 543e1ff4..795536fa 100644--- a/client/vite.config.js+++ b/client/vite.config.js@@ -93,6 +93,26 @@ export default defineConfig(({ mode }) => {strictPort: false,host: true},+ optimizeDeps: {+ // `company dev --force` sets VITE_FORCE to re-run dependency+ // pre-bundling — Vite's own recovery for "Outdated Optimize Dep"+ // (equivalent to `vite --force`, which can't be threaded through+ // the pnpm run -> npm run indirection as an argv flag).+ force: !!getEnv('VITE_FORCE', ''),+ // Pre-bundle the heavy deps reached through lazily-loaded panels+ // (chat/markdown stack, canvas) so a late discovery can't trigger+ // a mid-session re-optimization — the root cause of the+ // "Outdated Optimize Dep" 504 (vitejs/vite#14284).+ include: [+ 'reactflow',+ 'react-markdown',+ 'remark-gfm',+ 'remark-breaks',+ 'prismjs',+ 'react-simple-code-editor',+ '@uiw/react-json-view',+ ],+ },build: {// ES2022 unlocks native `findLast`, optional-chaining-assignment,// class-fields without polyfills. Browser baseline: Chrome 94+,