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
73 changes: 73 additions & 0 deletions .claude/docs/worktree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Worktrees

Git worktrees share tracked files with the main checkout, but ignored local files are separate per worktree. Before running a dev server, browser preview, or private-data test from a worktree, copy or link the local environment and data cache from the main checkout.

## Required local files

The main checkout normally has local-only files that are intentionally ignored by git:

- `.env.local` - private environment variables loaded by Vite/SvelteKit.
- `data/` - local cache for large private datasets, including `data/cleaned-vault-prices-1h.parquet`.

Without these files, vault metadata may still load if `TS_PRIVATE_TOP_VAULTS_URL` is set manually, but chart endpoints that need the historical parquet can fail with 500 responses.

## Environment variables

Copy or symlink `.env.local` from the main checkout so the worktree gets the same private server configuration:

```shell
ln -s /home/mikko/code/frontend/.env.local .env.local
```

The important vault data variables are:

```env
TS_PRIVATE_R2_ACCOUNT_ID=
TS_PRIVATE_R2_ACCESS_KEY_ID=
TS_PRIVATE_R2_SECRET_ACCESS_KEY=
TS_PRIVATE_R2_BUCKET_NAME=
TS_PRIVATE_TOP_VAULTS_URL=
TS_PRIVATE_VAULT_PRICES_PARQUET_URL=
```

R2 credentials are the canonical source for both vault metadata and the historical parquet. `TS_PRIVATE_TOP_VAULTS_URL` and `TS_PRIVATE_VAULT_PRICES_PARQUET_URL` are fallback direct URLs when R2 is not configured.

Restart the dev server after changing `.env.local`; Vite reads these values at process start.

## Data symlink

The historical vault parquet is large and is read from a path relative to the current worktree:

```text
data/cleaned-vault-prices-1h.parquet
```

Use a symlink instead of duplicating the cache:

```shell
ln -s /home/mikko/code/frontend/data data
```

This allows worktree-local endpoints such as `/trading-view/vaults/{id}/metrics` to find the same cached parquet as the main checkout.

## Checks

Confirm ignored local resources are present:

```shell
ls -l .env.local data/cleaned-vault-prices-1h.parquet
git check-ignore -v .env.local data/cleaned-vault-prices-1h.parquet
```

Confirm the running dev server inherited private environment variables:

```shell
ps -eo pid,cmd | rg 'vite|pnpm run dev'
tr '\0' '\n' < /proc/<vite-pid>/environ | rg 'TS_PRIVATE_R2_|TS_PRIVATE_TOP_VAULTS_URL|TS_PRIVATE_VAULT_PRICES_PARQUET_URL'
```

Confirm vault chart data works:

```shell
curl -s 'http://127.0.0.1:5173/trading-view/vaults/<vault-id>/metrics'
```
4 changes: 4 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ working on that area:
| Doc | Description |
| -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| `.claude/docs/agent-tricks-and-troubleshooting.md` | **MANDATORY read before ANY Claude CLI or Codex CLI invocation** (reviews, sanity checks, or one-off runs) |
| `.claude/docs/worktree.md` | Required local env and data symlinks when running dev servers or private-data checks from git worktrees |

## Agent review workflows

Expand Down Expand Up @@ -68,6 +69,7 @@ pnpm run test:integration # Run integration tests (requires build)

- `TS_PUBLIC_` prefix for client-accessible values
- `TS_PRIVATE_` prefix for server-only values
- In git worktrees, copy or symlink ignored local files such as `.env.local` and `data/` from the main checkout before running dev servers; see `.claude/docs/worktree.md`.

**Formatting:**

Expand Down Expand Up @@ -128,6 +130,8 @@ Use it for:

Always develop and verify against the Vite dev server started with `pnpm run dev` (typical local target `http://127.0.0.1:5173/`). Do **not** use `pnpm run preview` (Vite preview) for development or verification: its preview server runs its own prerender/manifest step that can resolve routes differently from both dev and the production adapter-node server (e.g. newly added routes may 404 under preview while working everywhere else). `pnpm run preview` is only for sanity-checking a production build. Integration tests (`pnpm run test:integration`) intentionally run against a build via the test harness; that is separate from manual development.

When using a git worktree, follow `.claude/docs/worktree.md` before starting the dev server so private env vars and cached vault datasets are available in that worktree.

```text
http://127.0.0.1:5173/
```
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ Environment variables required by the app are maintained in a checked-in `.env`
Put local-only secrets and overrides in `.env.local`, which is gitignored and loaded automatically
by Vite/SvelteKit. Variables in `.env.local` override `.env`.

When running from a git worktree, ignored local files are not copied from the main checkout. Symlink
or copy `.env.local` and the `data/` cache before starting the dev server; see
[worktree setup](./.claude/docs/worktree.md).

Use the existing prefixes when adding variables:

- `TS_PUBLIC_` for values that may be exposed client-side
Expand Down
3 changes: 3 additions & 0 deletions docs/chart-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ The dropdown and in-page selector can intentionally have different counts. For e

Use Playwright integration tests for chart page navigation and route rendering. The integration test harness uses a test-mode build and Vite preview; for manual development and visual checks, use `pnpm run dev` instead.

If the dev server runs from a git worktree, follow [worktree setup](../.claude/docs/worktree.md)
first so private env vars and the historical vault parquet cache are available to chart endpoints.

Useful checks:

- Run unit tests for chart payload builders, e.g. `pnpm exec vitest run src/lib/echarts/core3-risk.test.ts`.
Expand Down
6 changes: 6 additions & 0 deletions docs/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ pnpm run test:integration
For normal development, keep checked-in defaults in `.env` and place local-only secrets in
`.env.local`. Vite/SvelteKit loads `.env.local` automatically and it overrides `.env`.

In git worktrees, `.env.local` is not copied from the main checkout. Symlink or copy it before
running private-data tests or local dev servers; see [worktree setup](../.claude/docs/worktree.md).

The regular integration suite intentionally stays deterministic and uses `.env.test` plus mock
APIs. This means secret-backed features should not be added to the default `pnpm run test:integration`
flow unless they can be mocked reliably.
Expand Down Expand Up @@ -100,6 +103,9 @@ You can safely run the dev server and test builds concurrently without cache cor

For manual browser checks from another machine, use the Vite dev server rather than Vite preview:

If the dev server runs from a git worktree, first make sure `.env.local` and the `data/` cache are
available in that worktree; see [worktree setup](../.claude/docs/worktree.md).

```shell
pnpm run dev --host 0.0.0.0
```
Expand Down
4 changes: 4 additions & 0 deletions docs/vault-data-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,7 @@ For local development, ensure R2 credentials are set in `.env.local`. All data s
- Top vaults JSON is fetched on first page load and cached in memory for 1 hour
- Vault prices parquet (~150 MB) is downloaded on first metrics request and cached locally with a 1-hour refresh interval
- Treasury benchmark data is fetched from FRED on demand (no credentials needed) and cached for 24 hours

When developing from a git worktree, `.env.local` and `data/` are ignored local files and are not
created automatically. Symlink or copy them from the main checkout before starting the dev server;
see [worktree setup](../.claude/docs/worktree.md).
Loading
Loading