Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 0 additions & 67 deletions .env.production.example

This file was deleted.

7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ dist
.next
.env
.env.local
# The production environment holds the database password, the credentials key,
# the model key and the Google client secret. The example file beside it is
# placeholders only and is committed; this one never can be.
.env.production
# pg_dump output: the audit trail and every lab, incident and session. Ignored
# so a backup cannot be committed by accident; the host is where these live.
backups/
*.log
apps/api/generated
coverage
Expand Down
31 changes: 14 additions & 17 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ conflict. This file adds what the rulebook cannot: **how we have been working,
what is built, what is in flight, and what to do next.**

Last updated: 2026-10-16 (phases 0 to 15, the #32 restructure, and #34 to #43:
Google sign-in, GAPS.md, both deploy paths, security headers, the README split,
the demo reset and the VM fixes; sections 8a to 8c keep the per-phase notes as
Google sign-in, GAPS.md, the Render deploy, security headers, the README split
and the demo reset, then the VM path's removal; sections 8a to 8c keep the per-phase notes as
history).

## 0. Current state: start here
Expand All @@ -29,11 +29,9 @@ history).
- **Live at https://labops.onrender.com** (#39): one Render container runs the
API, worker and web app; Redis is Render Key Value, PostgreSQL is Neon.
Every boot resets the database and reseeds the `demo` operator and scenario
(`reset-demo.ts`, `seed-demo.ts`, #42). `render.yaml`, `deploy/render/`,
`docs/infra/DEPLOYMENT.md` §0.
- **The VM path** (`docker-compose.prod.yml` behind Caddy, `scripts/deploy.sh`,
`backup.sh`, `restore.sh`; #38) was run end to end locally in #43, which
fixed eight bugs; it has never run on a real host.
(`reset-demo.ts`, `seed-demo.ts`, #42). `render.yaml`, `deploy/`,
`docs/infra/DEPLOYMENT.md`. It is the only deployment: the owner decided it
never needs more than Render's 512 MB, so the VM path (#38, #43) was removed.
- **Keep docs matching the code.** When code changes, update the doc that
describes it in the same PR, and grep the docs for any path you rename.
- **Open, owner's side only:** rotate the Gemini key, add the
Expand All @@ -46,8 +44,8 @@ history).
platform, and recovery repairs nothing. Read it before describing this
project's capabilities to anyone.
- **`docs/infra/DEPLOYMENT.md` is the deployment context**: the live Render
path (§0), the VM path, every decision, the free-tier risks, and what has
*not* been verified. Read it before deploying.
path, every decision, the free-tier risks, and what has *not* been
verified. Read it before deploying.
- **No phase is planned.** Anything new starts with the plan-first loop in
section 3.

Expand Down Expand Up @@ -80,7 +78,7 @@ Docs: `CLAUDE.md` (rules), `ARCHITECTURE.md` (design, with "How Phase N
implements it" sections), `docs/specs/labops-copilot/SPEC.md` (what and why),
`docs/specs/labops-copilot/PLAN.md` (phase plan, status line, and a recorded
**deviations** paragraph per phase), `docs/infra/INFRA.md` (processes, env,
CI, known gaps), `docs/infra/DEPLOYMENT.md` (both deploy paths),
CI, known gaps), `docs/infra/DEPLOYMENT.md` (the Render deploy),
`docs/GAPS.md` (what the project does not do), `docs/dev/` (setup, endpoints,
testing, roadmap), and `README.md` (the plain-language overview for a reader,
kept non-technical). The git-ignored
Expand Down Expand Up @@ -224,7 +222,7 @@ steps:**.
prospective-employer company name appears in code, comments, tests, docs,
skills or UI; the only mention is the README's closing "About this project"
note. Names of tools and hosts the project uses (Google, Gemini, Render,
Neon, Caddy, Jira) are fine. The integration target is the generic "external
Neon, Jira) are fine. The integration target is the generic "external
lab platform" (provider id `lab-platform`). Never imply that any existing
platform lacks a capability.
- **Deny by default:** every API route needs a session unless it sets
Expand Down Expand Up @@ -427,12 +425,12 @@ them (#31 to #43; #35 was closed unmerged). Jira: story for Phase N is
| — | — | #33, #36 | AGENTS.md handoff and follow-up list |
| — | — | #34 | Optional Google sign-in: OIDC with PKCE, exact-email allow-list, `OperatorIdentity` |
| — | — | #37 | `docs/GAPS.md`: what the project does not do |
| — | — | #38 | VM production stack behind Caddy (`docker-compose.prod.yml`), investigation rate limit (10/min), `TRUST_PROXY_HOPS`, `APP_ENV=production` startup checks, deploy/backup/restore scripts |
| — | — | #39 | Free single-container deploy on Render with Neon (`render.yaml`, `deploy/render/`, `seed-demo.ts`); live at https://labops.onrender.com |
| — | — | #38 | VM production stack behind Caddy (`docker-compose.prod.yml`), investigation rate limit (10/min), `TRUST_PROXY_HOPS`, `APP_ENV=production` startup checks, deploy/backup/restore scripts (VM path removed in the cleanup after #44) |
| — | — | #39 | Free single-container deploy on Render with Neon (`render.yaml`, `deploy/` (then `deploy/render/`), `seed-demo.ts`); live at https://labops.onrender.com |
| — | — | #40 | Security headers sent by the web app (`next.config.mjs`) |
| — | — | #41 | Plain-language README; the technical detail moved to `docs/dev/` |
| — | — | #42 | Demo reset on every Render boot (`reset-demo.ts`, `DEMO_RESET_ON_BOOT`) |
| — | — | #43 | VM stack run end to end locally; eight bugs fixed (exec bits, Caddy config, restore format, first-deploy backup, empty `CREDENTIALS_KEY`, stream via the web relay, Redis `noeviction`, health check) |
| — | — | #43 | VM stack run end to end locally; eight bugs fixed (exec bits, Caddy config, restore format, first-deploy backup, empty `CREDENTIALS_KEY`, stream via the web relay, Redis `noeviction`, health check); VM path removed in the cleanup after #44 |

Key behaviours worth knowing (details in `ARCHITECTURE.md`):

Expand Down Expand Up @@ -586,7 +584,7 @@ follows the plan-first loop above.
address. Fix: forward the client address from the web server and count it as
a trusted hop.
- `TRUST_PROXY_HOPS` is unset locally (trusts nothing); `APP_ENV=production`
refuses to start without it. Both deploys set 1.
refuses to start without it. The Render boot sets 1 (`deploy/start.sh`).
- Google sign-in has never been run against a real OAuth client; the suites
sign ID tokens with a local key and stub the token endpoint. The web flow
cookie binds `state` and `nonce` to the browser, but it is unsigned.
Expand Down Expand Up @@ -627,8 +625,7 @@ WEB_HOST_PORT=3010 docker compose up -d # when another project holds :3000
gh pr create --draft ... ; gh pr ready N ; gh pr checks N
```

Production: `docs/infra/DEPLOYMENT.md` (Render: `render.yaml`, `deploy/render/`;
VM: `docker-compose.prod.yml`, `scripts/deploy.sh`, `backup.sh`, `restore.sh`).
Production: `docs/infra/DEPLOYMENT.md` (Render: `render.yaml`, `deploy/`).

## 12. Jira reference

Expand Down
32 changes: 12 additions & 20 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ flowchart TB
| `postgres` | 5432 | All durable business state | — |
| `redis` | 6379 | Queue transport, sign-in and investigation rate-limit counters | Be the source of truth for business state |

This is the local layout. The two production shapes differ: the VM stack adds
a Caddy proxy in front of `web`, and the Render deploy runs `api`, `worker` and
`web` as three processes in one container (§16).
This is the local layout. The deploy runs `api`, `worker` and `web` as three
processes in one container (§16).

### Why SSE and not WebSockets

Expand Down Expand Up @@ -1003,7 +1002,7 @@ sent; a field added to a view by mistake fails the request with a 500.
| Credential guessing | scrypt hashing; password and Google sign-in each limited to 5 a minute through Redis (fails closed); unknown user and wrong password answer identically and cost the same hash time. The limit keys on the client IP, but every sign-in reaches the API from the web server, which forwards no client address, so in practice the limit is shared by all operators |
| Unauthorised approval | Audit `actorId` comes from the session, never the request body; RBAC if time permits |
| Resource exhaustion | Body size limits; sign-in limited to 5 a minute and investigations (the only route that can spend money) to 10 a minute, both through Redis and failing closed, and both shared by all operators in practice (see above); bounded evidence, bounded queues and retries, timeouts on all outbound calls |
| Wrong client address | `TRUST_PROXY_HOPS` sets how many proxy hops Fastify trusts for the client IP (unset trusts none). Both deploys set 1 |
| Wrong client address | `TRUST_PROXY_HOPS` sets how many proxy hops Fastify trusts for the client IP (unset trusts none). The deploy sets 1 |
| Clickjacking, sniffing, downgrade | The web app sends `X-Frame-Options: DENY`, `Content-Security-Policy: frame-ancestors 'none'`, `nosniff`, `Referrer-Policy` and HSTS on every response, and no `X-Powered-By` (`next.config.mjs`), so every host sends them, not only one behind a proxy |
| Demo endpoints in production | `/api/demo/*` gated behind a flag that is off outside local/demo environments. `APP_ENV=production` refuses to start if `DEMO_ENABLED` is true, the session cookie is not Secure, or `TRUST_PROXY_HOPS` is unset |
| Demo reset wiping a real database | `reset-demo` runs only with both `DEMO_RESET_ON_BOOT=true` and `APP_ENV=production`, and refuses any database holding a lab or event that is not simulated (`modules/demo/reset.ts`) |
Expand Down Expand Up @@ -1065,9 +1064,8 @@ whether a commit touched `apps/web`, `apps/api`, or shared root tooling, then
dispatches only the matching pipeline via `workflow_call`. A frontend-only
change never starts the backend pipeline. Root manifests and the ESLint config
map to **both** services, because a shared-tooling change can break either.
Deploy files (`deploy/`, `render.yaml`, `docker-compose.prod.yml`, `scripts/`)
match no filter, so they start no pipeline, and CI never builds
`deploy/render/Dockerfile`.
Deploy files (`deploy/`, `render.yaml`, `scripts/`) match no filter, so they
start no pipeline, and CI never builds `deploy/Dockerfile`.

`api.yml` — build (`tsc` plus `prisma validate`), lint, unit tests, integration
tests against real PostgreSQL and Redis service containers, coverage with
Expand Down Expand Up @@ -1095,25 +1093,21 @@ Gates are split by ownership: checks that belong to one job run in that job
(lint, coverage thresholds), and checks that span the pipeline run in the gate
(secret scan, dependency audit, required-script contract).

**Production shapes** — two, both with `APP_ENV=production` (Secure cookie,
**Production shape** — one, with `APP_ENV=production` (Secure cookie,
`TRUST_PROXY_HOPS=1`, demo routes off). `docs/infra/DEPLOYMENT.md` has the
steps and the costs.

- **Render (live at https://labops.onrender.com).** One free web service runs
`deploy/render/Dockerfile`: `start.sh` resets the demo database
`deploy/Dockerfile`: `start.sh` resets the demo database
(`DEMO_RESET_ON_BOOT`), migrates, seeds the operator, starts the worker, the
API (on 127.0.0.1 only) and the web app as three processes under `tini`, then
ingests the demo scenario (`seed-demo`). Any process exiting stops the
container, so all three restart together. Redis is Render Key Value
(private, `noeviction`); PostgreSQL is Neon. TLS and the hostname are
Render's. Every push to `main` redeploys it.
- **Single VM (`docker-compose.prod.yml`).** Caddy is the only published port
and proxies everything, the live stream included, to `web`; postgres, redis
(`noeviction`) and the API have no ports. Deployed by hand with
`scripts/deploy.sh`, backed up by `backup.sh`. Run end to end locally only;
never on a public host.

Not configured in either: an OTel export backend, a platform secret store, or
Render's. Every push to `main` redeploys it. 512 MB holds all three
processes (about 145 MB measured locally under the same cap).

Not configured: an OTel export backend, a platform secret store, or
a database role restricted to the app's schema.

---
Expand Down Expand Up @@ -1158,7 +1152,6 @@ Phases refer to `docs/specs/labops-copilot/PLAN.md`.
| React Flow dependency graph | Dropped (owner decision) | — |
| Optional Google sign-in: OIDC code flow, PKCE, exact-email allow-list, `OperatorIdentity` | Done (after Phase 15) | Never run against a real Google client |
| Hardening: `APP_ENV=production` startup checks, `TRUST_PROXY_HOPS`, investigation rate limit, security headers from the web app | Done (after Phase 15) | Forward the client address from the web server, so rate limits are per operator |
| Production stack on one VM: `docker-compose.prod.yml`, Caddy, deploy, backup and restore scripts | Done; run end to end locally | Never stood up on a public host |
| Free deploy on Render + Neon, single container, live | Done (after Phase 15) | — |
| Demo reset on every boot of the live deploy (`reset-demo`, guarded) | Done (after Phase 15) | — |

Expand Down Expand Up @@ -1201,5 +1194,4 @@ end-to-end workflow exists before breadth is added.
5. **Retention** — how long to keep raw event payloads. Default is metadata and
redacted excerpts only, with raw retention opt-in and time-boxed.
6. **Deployment target** — *resolved:* Phase 15 shipped local-only; afterwards
a free Render + Neon deploy went live, and a single-VM stack behind Caddy is
documented (§16).
a free Render + Neon deploy went live (§16).
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ write documentation, commit messages, comments or UI copy that claims any
existing platform lacks a capability, or that names a lab-platform vendor or
the prospective employer (the README's closing "About this project" note is the
only exception). Names of tools and hosts the project uses, such as Google,
Gemini, Render, Neon and Caddy, are fine.
Gemini, Render and Neon, are fine.

**All lab infrastructure is simulated.** There is no live lab platform
connection and the MVP never touches real cloud resources. Any UI or log surface that shows
Expand All @@ -52,7 +52,7 @@ overview, and `docs/dev/` for setup, the API and testing.
| `docs/specs/labops-copilot/SPEC.md` | What is being built and why: rules, scope, acceptance criteria |
| `docs/specs/labops-copilot/PLAN.md` | The phase-by-phase build plan (complete: phases 0-15, and the work since). New work starts a new `docs/specs/<feature>/` |
| `docs/infra/INFRA.md` | Processes, ports, containers, env vars, migrations, CI |
| `docs/infra/DEPLOYMENT.md` | The live Render deploy and the VM path |
| `docs/infra/DEPLOYMENT.md` | The live Render deploy |
| `docs/GAPS.md` | What the project does not do; read before describing its capabilities |
| `docs/dev/` | Setup, design, the API, testing and the roadmap |

Expand Down
4 changes: 2 additions & 2 deletions apps/api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ DEMO_ENABLED=true
# missing proxy hop count, or demo routes being enabled. Set by compose in the
# production stack; unset means development, where none of those apply.
# APP_ENV=production
# How many reverse proxies sit in front of this process, 0 to 10. Behind Caddy
# this is 1. Unset locally, which is correct: nothing proxies there. With this
# How many reverse proxies sit in front of this process, 0 to 10. Behind one
# reverse proxy this is 1. Unset locally, which is correct: nothing proxies there. With this
# unset behind a proxy, every request looks like it came from the proxy, so the
# rate limits stop being per-client and logs record the wrong address.
# TRUST_PROXY_HOPS=1
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export async function buildApp(options: {
}) {
const trustedHops = options.config.TRUST_PROXY_HOPS;

// How many trusted reverse proxies sit in front of this process. Behind Caddy
// or nginx this must be set, or every request looks like it came from the
// How many trusted reverse proxies sit in front of this process. Behind a
// reverse proxy this must be set, or every request looks like it came from the
// proxy: the rate limit stops being per-client and audit logs record the wrong
// address. Fastify takes a trust function rather than a hop count, so the
// count becomes "trust everything except the last hop".
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/platform/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const envSchema = z
// Secure by default; only local http development turns it off.
SESSION_COOKIE_SECURE: z.stringbool().default(true),
// How many reverse proxies sit in front of this process. Unset trusts
// nothing, which is correct locally and wrong behind Caddy or nginx: the
// nothing, which is correct locally and wrong behind a reverse proxy: the
// rate limit keys on the client IP, so it must be the real one.
TRUST_PROXY_HOPS: z.coerce.number().int().min(0).max(10).optional(),
LLM_PROVIDER: z.enum(['fixture', 'gemini']).default('fixture'),
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/reset-demo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// One-shot entrypoint for a demo host: wipes the database so the boot can
// migrate and seed it fresh (deploy/render/start.sh). See modules/demo/reset.ts.
// migrate and seed it fresh (deploy/start.sh). See modules/demo/reset.ts.

import { prisma } from './db.js';
import { resetAllowed, resetDemoDatabase } from './modules/demo/reset.js';
Expand Down
Loading
Loading