Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
fix(deploy): delink deploy state + stale refs from build/clean paths
trohitg465a8374814c
diff --git a/.npmignore b/.npmignoreindex 4b1e85cc..331b62c4 100644--- a/.npmignore+++ b/.npmignore@@ -102,6 +102,3 @@ MachinaOS/# Package lock filespackage-lock.json**/package-lock.json--# Build/deploy scripts not needed for users-deploy.shdiff --git a/CLAUDE.md b/CLAUDE.mdindex f376e6a4..1284943c 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -2599,22 +2599,33 @@ python test_websocket.py## Production Deployment-### Docker Deployment-The project deploys using Docker Compose with nginx reverse proxy.+### Self-Deploy CLI (`machina deploy`) — current path+One command provisions a login-gated MachinaOs VM on a cloud provider. Two stages: the+operator's **cloud CLI** (gcloud; aws planned) handles auth + project/region/zone resolution ++ADC verification + API enablement, then **Terraform** (`cli/terraform/gcp/`) owns all resources —+VM (always named `machinaos`), firewall, artifact bucket (local `npm pack` source), service+account, and a cloud-init startup script that installs Node 22 + uv + the package and runs+`machina serve` under systemd. Login gate = built-in auth (`VITE_AUTH_ENABLED=true`,+`AUTH_MODE=single`) with the owner credential generated at deploy time and seeded on first boot.-#### Deploy Script (`deploy.sh`)```bash-# Deploy to server (configure DEPLOY_HOST in .env)-./deploy.sh [HOST]+machina deploy up --provider gcp --owner-email [email protected] # provision + install + print URL/creds+machina deploy status # URL + /health+machina deploy destroy # terraform destroy + clear state```-**Deployment Steps:**-1. Build Docker images locally (`docker-compose -f docker-compose.prod.yml build`)-2. Save and compress images (`docker save | gzip`)-3. Upload to GCP via SCP-4. Deploy on remote (`docker-compose up -d`)-5. Configure nginx reverse proxy with SSL-6. Auto-cleanup dangling Docker images+Key files: `cli/commands/serve.py` (single-port runtime: uvicorn fronts API + WS + built SPA, plus+the node sidecar), `cli/commands/deploy/` (verbs, secrets, Terraform driver, provider CLI adapters),+`cli/terraform/gcp/` (HCL module + `startup.sh.tftpl`). Deployment state lives at+`<user-data>/deploy/machinaos/` (preserved by `machina clean` — see `_MACHINA_KEEP`); only+`machina deploy destroy` removes it. The deploy code is fully delinked from `machina build` /+`machina clean` (lazy verb stubs in `cli/cli.py`; nothing in the build pipeline imports it).++The legacy `deploy.sh` (docker-compose images over SCP to a GCE box) was removed. The Docker+Compose notes below are retained for reference for the historical container topology.++### Docker Deployment (legacy reference)+The project previously deployed using Docker Compose with nginx reverse proxy.#### Docker Configuration (4-Container Stack)diff --git a/cli/commands/clean.py b/cli/commands/clean.pyindex 086cbb4f..087f8610 100644--- a/cli/commands/clean.py+++ b/cli/commands/clean.py@@ -44,10 +44,14 @@ _TARGETS = [# ``.machina`` entry can't go in ``_TARGETS`` anymore because the# ``workflows/`` subtree holds shipped example seeds (git-tracked,# imported on first launch by ``services.example_loader``) -- wiping-# it would force the operator to re-clone to recover. Anything else-# under ``.machina/`` (claude state, workspaces, credentials.db, ...)-# is transient runtime state and is fair game.-_MACHINA_KEEP = frozenset({"workflows"})+# it would force the operator to re-clone to recover. ``deploy/``+# holds ``machina deploy``'s Terraform working dirs + state files:+# deleting state for LIVE cloud resources orphans the VM/firewall+# (``machina deploy destroy`` could no longer find them) -- only+# ``deploy destroy`` removes that tree. Anything else under+# ``.machina/`` (claude state, workspaces, credentials.db, ...) is+# transient runtime state and is fair game.+_MACHINA_KEEP = frozenset({"workflows", "deploy"})def _rmtree_with_retry(path: Path, *, attempts: int = 3, delay: float = 0.1) -> bool:diff --git a/cli/tests/test_clean.py b/cli/tests/test_clean.pyindex 0fa0f854..a14884bf 100644--- a/cli/tests/test_clean.py+++ b/cli/tests/test_clean.py@@ -20,11 +20,13 @@ def test_targets_list_is_stable():]-def test_machina_keep_preserves_workflows():- """``workflows/`` lives under ``.machina/`` (shipped example seeds);- ``clean`` must never wipe it. Pin the keep list so accidental- additions/removals surface in review."""- assert clean._MACHINA_KEEP == frozenset({"workflows"})+def test_machina_keep_preserves_workflows_and_deploy_state():+ """``workflows/`` (shipped example seeds) and ``deploy/`` (``machina+ deploy``'s Terraform working dirs + state for LIVE cloud resources —+ wiping it orphans the VM/firewall; only ``deploy destroy`` removes it)+ live under ``.machina/``; ``clean`` must never wipe either. Pin the+ keep list so accidental additions/removals surface in review."""+ assert clean._MACHINA_KEEP == frozenset({"workflows", "deploy"})def test_rmtree_with_retry_handles_oserror(tmp_path: Path):diff --git a/docs-internal/SCRIPTS.md b/docs-internal/SCRIPTS.mdindex f63e94cd..3966ac5e 100644--- a/docs-internal/SCRIPTS.md+++ b/docs-internal/SCRIPTS.md@@ -81,8 +81,10 @@ Temporal server lifecycle is managed by `machina start` / `machina dev` / `machi| Script | Command | Description ||--------|---------|-------------|-| `deploy` | `bash deploy.sh` | Deploy to production server |-| `deploy:gcp` | `bash deploy.sh` | Deploy to GCP |+| `deploy` | `python -m cli deploy` | Self-deploy to a cloud VM (`machina deploy up/status/destroy` — gcloud preflight + Terraform; see `cli/commands/deploy/`) |++The legacy `deploy.sh` (SCP + docker-compose to a GCE box) was removed; `machina deploy`+provisions a login-gated VM natively via the operator's cloud CLI + Terraform.---