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
133 changes: 133 additions & 0 deletions .agents/skills/bricks-local-cloud-dev/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
---
name: bricks-local-cloud-dev
description: Start or explain the Bricks local manual development environment for UI/style/interaction work using a local Node backend, local Flutter Web frontend, cloud Turso data from .env.local, and Quick Login (Test) via BRICKS_TEST_TOKEN. Use when the user wants to edit code locally and inspect the real app with realistic cloud data, not when creating automated browser evidence.
---

# Bricks Local Cloud Development

Use this skill when the user wants to manually develop Bricks locally and inspect
styles, layout, interaction, navigation, or chat behavior against realistic cloud
data.

This is a manual development workflow, not the evidence harness. For automated
browser proof, use `evidence-driven-browser-test-env` instead.

## Safety Rules

- Never print, copy, commit, or summarize secret values from `.env.local`.
- It is OK to reference uncommitted local paths such as `.env.local`.
- When connecting a local backend to cloud Turso, force `AUTO_MIGRATE=false`.
- Do not write provider keys into cloud Turso for ordinary UI development.
- Prefer local env provider config, if needed: `LOCAL_LLM_CONFIG_ENABLED=true`
with provider keys kept only in `.env.local`.
- Tell the user that rows written through Quick Login belong to `FIXTURE_USER_ID`,
not necessarily their normal production login user.

## Expected Local Files

Read `.env.local` only as an environment source. Do not display its contents.

Required variables:

- `TURSO_DATABASE_URL`
- `TURSO_AUTH_TOKEN`
- `JWT_SECRET`
- `FIXTURE_USER_ID`
- `BRICKS_TEST_TOKEN`

Recommended variables:

- `PORT=3010`
- `BRICKS_API_BASE_URL=http://127.0.0.1:3010`
- `AUTO_MIGRATE=false`
- `BRICKS_LOCAL_DEV=true`
- `LOCAL_LLM_CONFIG_ENABLED=true` when testing real model replies from local env

## Startup Workflow

1. Check the branch and worktree first:

```bash
git status --short --branch
```

2. Create or switch to the user's requested development branch. If they did not
name one, create a short local branch from current `main`, for example:

```bash
git switch -c dev/local-cloud-db-ui
```

3. Start the backend from `apps/node_backend`:

```bash
set -a
source ../../.env.local
set +a
PORT=3010 AUTO_MIGRATE=false npm run dev
```

If the sandbox blocks `tsx` IPC or local server binding, rerun the same
command with required escalation.

4. Start Flutter Web from `apps/mobile_chat_app`:

```bash
set -a
source ../../.env.local
set +a
PATH=/Users/admin/.local/tools/flutter/bin:$PATH flutter run \
-d web-server \
--web-hostname 127.0.0.1 \
--web-port 8082 \
--dart-define=BRICKS_API_BASE_URL=http://127.0.0.1:3010 \
--dart-define=BRICKS_TEST_TOKEN="$BRICKS_TEST_TOKEN"
```

5. Give the user the frontend URL:

```text
http://127.0.0.1:8082
```

## Verification Before Hand-Off

Before telling the user it is ready, verify:

- backend health:

```bash
curl -sS http://127.0.0.1:3010/api/health
```

- Flutter Web printed a serving URL for `127.0.0.1:8082`.
- The login page should show `Quick Login (Test)` because
`BRICKS_TEST_TOKEN` was injected as a Dart define.

If checking `/api/auth/me`, do not print the token. Use a command or script that
only reports HTTP status and whether a user object exists.

## Response Pattern

When the environment is running, answer with:

- current branch name
- frontend URL
- backend URL
- whether cloud Turso is in use
- `AUTO_MIGRATE=false` confirmation
- Quick Login availability
- any caveat about fixture user identity or expected write scope

Keep the response short. The user mainly needs the URL and safety state.

## Troubleshooting

- Backend `listen EPERM` for `tsx` IPC: rerun with escalation.
- `Quick Login (Test)` missing: confirm `BRICKS_TEST_TOKEN` was passed via
`--dart-define`, then hot restart or restart Flutter Web.
- API calls hit production instead of local backend: confirm
`BRICKS_API_BASE_URL=http://127.0.0.1:3010` was passed as a Dart define.
- DB writes are not visible in the user's normal production account: check
`FIXTURE_USER_ID`; Quick Login writes as that fixture user.
- Migration concerns: stop and confirm `AUTO_MIGRATE=false` before continuing.
167 changes: 167 additions & 0 deletions .agents/skills/bricks-turso-branch-migration-test/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
---
name: bricks-turso-branch-migration-test
description: Use when validating Bricks database migrations against a Turso Cloud branch/test database copied from the current cloud database, then running local backend and Flutter Web against that branch database for manual verification. Covers Turso Cloud CLI setup, branch creation with --from-db, local secret-safe env handling, migration verification, and local app startup.
---

# Bricks Turso Branch Migration Test

Use this skill when a schema migration must be validated with realistic cloud data before merging or deploying to production.

## Safety Rules

- Never print `TURSO_AUTH_TOKEN`, `BRICKS_TEST_TOKEN`, `JWT_SECRET`, `ENCRYPTION_KEY`, or provider API keys.
- Keep branch/test DB env in an uncommitted local file such as `.env.migration-test.local`.
- Do not use `.env.local` directly for migration validation unless the user explicitly wants to migrate that database.
- After the branch DB has been migrated, start local backend with `AUTO_MIGRATE=false`.
- Prefer keeping old tables as deprecated rollback backups in risky migrations; drop them only in a separate cleanup migration after production validation.

## Cloud CLI

There are two similarly named tools:

- Homebrew `turso` installs `tursodb`, the embedded SQL shell. It is not the Cloud management CLI.
- Turso Cloud CLI is installed as `~/.turso/turso` by `https://get.tur.so/install.sh` or by downloading `homebrew-tap_Darwin_arm64.tar.gz` from `tursodatabase/homebrew-tap`.

Check the Cloud CLI:

```bash
~/.turso/turso --version
~/.turso/turso auth whoami
```

If not logged in, the user must run:

```bash
~/.turso/turso auth login
```

## Create A Branch/Test Database

1. Derive the source database name from `.env.local` without printing secrets:

```bash
zsh -lc 'set -a; source .env.local; set +a; node -e "const u=new URL(process.env.TURSO_DATABASE_URL||\"\"); console.log(u.hostname);"'
```

2. If the hostname includes an org suffix, switch to the owning org:

```bash
~/.turso/turso org list
~/.turso/turso org switch <org-slug>
~/.turso/turso db list
```

3. Create a short branch DB name. Turso DB names must be at most 26 characters:

```bash
~/.turso/turso db create bricks-mig-0623a --from-db database-bricks --wait
```

4. Get the branch DB URL and token. Do not print the token:

```bash
~/.turso/turso db show bricks-mig-0623a --url
~/.turso/turso db tokens create bricks-mig-0623a > /private/tmp/bricks-mig-0623a.token
```

## Prepare Local Test Env

Create `.env.migration-test.local` from `.env.local`, but replace Turso URL/token with the branch DB values:

```bash
zsh -lc 'set -a; source .env.local; set +a; token=$(tr -d "\n" < /private/tmp/bricks-mig-0623a.token); umask 077; cat > .env.migration-test.local <<EOF
TURSO_DATABASE_URL=<branch-db-url>
TURSO_AUTH_TOKEN=$token
JWT_SECRET=$JWT_SECRET
ENCRYPTION_KEY=$ENCRYPTION_KEY
FIXTURE_USER_ID=$FIXTURE_USER_ID
BRICKS_TEST_TOKEN=$BRICKS_TEST_TOKEN
PORT=3010
BRICKS_LOCAL_DEV=true
LOCAL_LLM_CONFIG_ENABLED=false
AUTO_MIGRATE=true
EOF'
```

Use `LOCAL_LLM_CONFIG_ENABLED=false` unless the test specifically needs local provider keys. If it is `true` without a valid `LOCAL_LLM_PROVIDER` and API key, chat can fail with `Invalid local LLM provider`.

## Run Migration On Branch DB

Run the migration directly against the branch DB:

```bash
cd apps/node_backend
zsh -lc 'set -a; source ../../.env.migration-test.local; set +a; npx tsx src/db/migrate.ts'
```

Verify the result with parameterized SQL so shell quoting does not corrupt string literals:

```bash
cd apps/node_backend
zsh -lc 'set -a; source ../../.env.migration-test.local; set +a; node --input-type=module - <<'"'"'NODE'"'"'
import { createClient } from "@libsql/client";
const client = createClient({ url: process.env.TURSO_DATABASE_URL, authToken: process.env.TURSO_AUTH_TOKEN });
async function scalar(sql, args = []) {
const r = await client.execute({ sql, args });
return Object.values(r.rows[0] ?? {})[0];
}
const tables = await client.execute({
sql: "SELECT name FROM sqlite_schema WHERE name IN (?, ?) ORDER BY name",
args: ["chat_channels", "chat_channel_names"],
});
const migrated = await scalar("SELECT COUNT(*) AS c FROM chat_channels");
const legacy = await scalar("SELECT COUNT(*) AS c FROM chat_channel_names");
const migration = await scalar("SELECT COUNT(*) AS c FROM migrations WHERE version = ?", ["025"]);
console.log(JSON.stringify({
tables: tables.rows.map((r) => r.name),
chatChannelsRows: migrated,
legacyRows: legacy,
migration025Rows: migration,
}, null, 2));
NODE'
```

Expected for the `chat_channels` migration:

- `chat_channels` exists.
- deprecated `chat_channel_names` still exists as rollback backup.
- row counts match immediately after migration.
- migration `025` is recorded once.

## Start Local App Against Branch DB

After migration validation, restart backend with migration disabled:

```bash
cd apps/node_backend
zsh -lc 'set -a; source ../../.env.migration-test.local; set +a; PORT=3010 AUTO_MIGRATE=false npm run dev'
```

Start Flutter Web:

```bash
cd apps/mobile_chat_app
zsh -lc 'set -a; source ../../.env.migration-test.local; set +a; PATH=/Users/admin/.local/tools/flutter/bin:$PATH flutter run \
-d web-server \
--web-hostname 127.0.0.1 \
--web-port 8082 \
--dart-define=BRICKS_API_BASE_URL=http://127.0.0.1:3010 \
--dart-define=BRICKS_TEST_TOKEN="$BRICKS_TEST_TOKEN"'
```

Hand off:

- Frontend: `http://127.0.0.1:8082`
- Backend: `http://127.0.0.1:3010`
- DB: branch/test DB name
- `AUTO_MIGRATE=false` for running backend
- Quick Login writes as `FIXTURE_USER_ID`

## Smoke Checks

- Backend health: `curl -sS http://127.0.0.1:3010/api/health`
- Authenticated `/api/chat/channels` returns 200 and expected row count; do not print tokens.
- Channel create, rename, archive, refresh.
- Thread create, rename, archive, refresh.
- Existing historical message loading still works.
- `/api/chat/scopes` activity does not recreate hidden sidebar entities by itself.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@ pubspec_overrides.yaml
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
!/dev/ci/**/Gemfile.lock.github/aw/logs/
.worktree/
.env.migration-test.local
Loading
Loading