hyperdx/.config/wt.toml
Warren Lee dea1b669e6
Fix dev env port resolution and improve multi-worktree support (#2025)
## Summary

- Fix dev environment port isolation so OTel collector, MongoDB, and ClickHouse resolve to the correct worktree-specific ports
- Add slot-specific session cookies so multiple worktrees on localhost don't interfere with each other's login sessions
- Share NX build cache across worktrees for faster builds
- Add worktrunk project config for automated worktree lifecycle management

## Changes

### Port resolution fix

**Root `.env`**: Replace self-referential `HDX_DEV_*` vars (e.g. `HDX_DEV_OTEL_HTTP_PORT=${HDX_DEV_OTEL_HTTP_PORT:-4318}`) with plain default values. The `${VAR:-default}` syntax caused `dotenv-expand` infinite recursion, preventing `dev-env.sh` port overrides from taking effect.

**`packages/api/.env.development`**: Remove redundant self-referential port declarations and `:-default` fallbacks from `${HDX_DEV_*}` references. Ports now come exclusively from `dev-env.sh` exports or root `.env` defaults.

**`packages/app/.env.development`**: Set `HYPERDX_API_KEY` to `super-secure-ingestion-api-key` (matching the API/collector) instead of a placeholder. Remove self-referential port declarations.

**`packages/app/src/config.ts`**: Add `process.env.OTEL_EXPORTER_OTLP_ENDPOINT` as fallback for `HDX_COLLECTOR_URL` so the browser OTel SDK picks up the correct collector endpoint.

### Session cookie isolation

**`packages/api/src/api-app.ts`**: Use `connect.sid.<slot>` as the session cookie name in dev mode so multiple worktrees on `localhost` maintain independent sessions. Guarded behind `config.IS_DEV && process.env.HDX_DEV_SLOT` — production uses the default `connect.sid`.

### Shared NX build cache

**`scripts/dev-env.sh`**: Set `NX_CACHE_DIRECTORY=~/.config/hyperdx/nx-cache` so all worktrees share a single content-hash-based build cache. Unchanged packages get cache hits regardless of worktree; changed packages rebuild correctly.

### Worktrunk project config

**`.config/wt.toml`**: New project config for [worktrunk](https://worktrunk.dev) (`wt`) worktree lifecycle hooks:
- `pre-start`: Symlink `node_modules/` from primary worktree (instant, no copy)
- `post-start`: Copy `.env.local` from primary worktree
- `post-remove`: Tear down Docker stacks (`dev-down`, `dev-int-down`, `dev-e2e-down`) for the removed worktree's slot
2026-04-01 20:53:09 +00:00

27 lines
1.4 KiB
TOML

# HyperDX worktrunk project config
# See: https://worktrunk.dev
#
# This file is committed and shared with the team. It configures lifecycle
# hooks that run when creating/switching/removing worktrees via `wt`.
# ---------------------------------------------------------------------------
# pre-start: blocking — symlink node_modules from primary worktree for
# instant dependency access. If the branch needs different deps:
# rm node_modules && yarn install
# ---------------------------------------------------------------------------
pre-start = "ln -sf {{ primary_worktree_path }}/node_modules {{ worktree_path }}/node_modules"
# ---------------------------------------------------------------------------
# post-start: background tasks
# ---------------------------------------------------------------------------
[post-start]
env = "cp {{ primary_worktree_path }}/.env.local {{ worktree_path }}/.env.local 2>/dev/null && echo 'Copied .env.local' || true"
# ---------------------------------------------------------------------------
# post-remove: clean up all Docker resources for this worktree's slot
# (dev stack, integration tests, E2E tests)
# ---------------------------------------------------------------------------
[post-remove]
dev-down = "make dev-down 2>/dev/null || true"
int-down = "make dev-int-down 2>/dev/null || true"
e2e-down = "make dev-e2e-down 2>/dev/null || true"