Skip to content

Cloudflare-native local development (current state)

Supersedes the GCP-emulator sections of 6. Local development. The platform retargeted from GCP to Cloudflare Workers (see docs/architecture.md); Postgres, Pub/Sub, and Firebase emulators no longer participate in the local dev loop. Local state lives in D1 (SQLite) via wrangler, and the gateway runs under wrangler dev / workerd, not Node.

TL;DR — standing up the stack

Terminal window
cp .env.example .env # then rebrand values (see below)
pnpm install --frozen-lockfile
pnpm dev:bootstrap # D1 migrations + dev tenant seed (local wrangler state)
pnpm dev # package watchers + gateway (wrangler dev) + agent (tsx watch)

Readiness banner: [mnemose-dev] Core runtime ready. Health check: curl localhost:4000/health → {"status":"ok","service":"mnemose-gateway","runtime":"cloudflare-workers",...}

GraphQL at http://localhost:4000/graphql enforces auth: {"errors":[{"message":"Missing Authorization header","extensions":{"code":"UNAUTHENTICATED"}}]} is the expected unauthenticated response.

.env (required by tsx --env-file)

services/*/package.json dev scripts load --env-file=../../.env. Without that file tsx exits 9 (node: ../../.env: not found). Copy the example and rebrand:

  • blackice → mnemose, BLACKICE → MNEMOSE (URLs, project IDs, emails)
  • Ensure DEV_AUTH_BYPASS=true and DEV_AUTH_TENANT_ID=11111111-1111-4111-8111-111111111111 are present (the bootstrap seed relies on them)

What pnpm dev actually runs

scripts/dev-runtime.mjs:

  1. dev:prepare — gen:app-catalog + build of all @mnemose/* packages
  2. 5 package watchers (logger, kernel-protocol, bootstrap, db, domain) in tsc --watch
  3. Gateway via wrangler dev --local --port 4000 (workerd — the D1/R2/KV/ Queues/DO bindings from the root wrangler.toml are available locally)
  4. Agent via tsx watch from services/agent — an exports-only module (command processor), no HTTP listener

pnpm dev:bootstrap applies D1 migrations and seeds the dev tenant via wrangler d1 against local state.

GCP-legacy migration (complete)

All packages that previously imported createGcpPlatform have been migrated to the CF Worker/DO/Queue architecture:

PackageMigration
@mnemose/mcp-mnemose-kernelsHttpEventBus (POSTs to gateway queue endpoint)
@mnemose/mcp-mnemose-servicescreateCloudflarePlatform with sandbox-injected bindings
@mnemose/cliGCP-free (no createGcpPlatform imports)
services/kernel-broker/src/server.tsHttpEventBus + better-sqlite3 for Node runtime
services/loop-host/src/index.tsCfSecrets / CfCloudCredentials with injected bindings
services/agent/src/command-subscriber.tscreateCloudflarePlatform from Worker env bindings

services/commands/bootstrap-cloud-project and services/commands/bootstrap-organization were rewritten CF-native (no GCP IAM minting; workload-identity event fields are undefined).

The agent package (services/agent) still has 12 pre-existing command-subscriber.ts type errors (CI runs continue-on-error); they do not block tsx execution or the dev runtime.

Common failure modes (this container)

SymptomCauseFix
Cannot find module .../node_modules/typescript/bin/tsc during buildnode_modules was installed on Windows (WSL /mnt/d/... absolute symlinks), mounted into the containerrm -rf node_modules && pnpm install --frozen-lockfile
.npmrc WARN Failed to replace env in config: ${NPM_TOKEN}Harmless — token interpolation warning when NPM_TOKEN unset; @freeside-collective/* is public nowIgnore
Address already in use 127.0.0.1:4000Orphaned workerd/wrangler from a previous run (kill parent wrangler process, not only workerd; it respawns)pkill -9 -f "wrangler dev"; pkill -9 -f workerd
Agent exits instantly, No projects matched the filtersConcurrent pnpm --filter workspace-resolution race (7 pnpm processes starting at once)Fixed in scripts/dev-runtime.mjs: processes spawn with per-package cwd instead of --filter
Runtime never reaches Core runtime ready with services healthyReadiness regex didn’t match actual banner (Ready on http://localhost:4000, agent’s silent tsx watch)Fixed in scripts/dev-runtime.mjs (match ready on, tsx watch; test raw chunk + trailing line — chunks can split patterns)
Gateway dev script fails on missing src/server.tsserver.ts deleted in the Cloudflare retarget; worker.ts is the entryFixed: gateway dev now wrangler dev --local --port 4000
node: ../../.env: not found, exit 9Root .env missingSee .env section above
services/agent build fails citing tenantIdPre-existing branch type errorsOut of scope; tracked by CI continue-on-error

D1 local data

Wrangler local D1 state lives under .wrangler/state/. Reset with:

Terminal window
rm -rf .wrangler/state
pnpm dev:bootstrap

Environment parity

The devcontainer remoteEnv still contains GCP-era vars (GCP_PROJECT_ID, DATABASE_URL pointing at Postgres, Pub/Sub and Firebase emulator hosts). They are inert for the CF-native runtime but kept for console/Vite compatibility. The authoritative runtime config is the root wrangler.toml ([vars], D1/R2/KV/Queues/DO bindings).