@terreno/mcp 58.0.2 → 58.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +6 -4
  3. package/dist/docs/templates/bootstrap/frontend/app/_layout.template.tsx +2 -0
  4. package/dist/docs/upgrades/58.0.3.md +28 -0
  5. package/dist/docs/versioned/next/explanation/ai-development-loop.md +10 -7
  6. package/dist/docs/versioned/next/explanation/test-isolation.md +2 -1
  7. package/dist/docs/versioned/next/explanation/test-sharding.md +113 -0
  8. package/dist/docs/versioned/next/how-to/README.md +1 -0
  9. package/dist/docs/versioned/next/how-to/circleci.md +12 -4
  10. package/dist/docs/versioned/next/how-to/debug-with-mcp.md +10 -1
  11. package/dist/docs/versioned/next/how-to/fix-code-scanning-alerts.md +43 -0
  12. package/dist/docs/versioned/next/how-to/run-tests-locally.md +5 -0
  13. package/dist/docs/versioned/next/how-to/set-up-terreno-mcp.md +3 -1
  14. package/dist/docs/versioned/next/implementationPlans/mcp-agent-debugger-gaps.md +257 -0
  15. package/dist/docs/versioned/next/reference/environment-variables.md +2 -0
  16. package/dist/docs/versioned/next/reference/mcp-server.md +12 -0
  17. package/dist/docs/versioned/next/reference/test.md +4 -1
  18. package/dist/docs/versioned/next/tasks/mcp-agent-debugger-gaps.md +151 -0
  19. package/dist/local/localTools.d.ts.map +1 -1
  20. package/dist/local/localTools.js +94 -1
  21. package/dist/local/localTools.js.map +1 -1
  22. package/dist/local/metro/metroDevSession.d.ts +1 -0
  23. package/dist/local/metro/metroDevSession.d.ts.map +1 -1
  24. package/dist/local/metro/metroDevSession.js +104 -1
  25. package/dist/local/metro/metroDevSession.js.map +1 -1
  26. package/dist/local/native/nativeLogs.d.ts +12 -0
  27. package/dist/local/native/nativeLogs.d.ts.map +1 -0
  28. package/dist/local/native/nativeLogs.js +103 -0
  29. package/dist/local/native/nativeLogs.js.map +1 -0
  30. package/dist/local/tools/clientDev.d.ts +22 -0
  31. package/dist/local/tools/clientDev.d.ts.map +1 -0
  32. package/dist/local/tools/clientDev.isolated.d.ts +2 -0
  33. package/dist/local/tools/clientDev.isolated.d.ts.map +1 -0
  34. package/dist/local/tools/clientDev.isolated.js +55 -0
  35. package/dist/local/tools/clientDev.isolated.js.map +1 -0
  36. package/dist/local/tools/clientDev.js +224 -0
  37. package/dist/local/tools/clientDev.js.map +1 -0
  38. package/dist/local/tools/readLogs.d.ts.map +1 -1
  39. package/dist/local/tools/readLogs.js +22 -3
  40. package/dist/local/tools/readLogs.js.map +1 -1
  41. package/dist/tools.d.ts.map +1 -1
  42. package/dist/tools.js +3 -1
  43. package/dist/tools.js.map +1 -1
  44. package/package.json +7 -7
  45. package/src/docs/templates/bootstrap/frontend/app/_layout.template.tsx +2 -0
  46. package/src/docs/upgrades/58.0.3.md +28 -0
  47. package/src/docs/versioned/next/explanation/ai-development-loop.md +10 -7
  48. package/src/docs/versioned/next/explanation/test-isolation.md +2 -1
  49. package/src/docs/versioned/next/explanation/test-sharding.md +113 -0
  50. package/src/docs/versioned/next/how-to/README.md +1 -0
  51. package/src/docs/versioned/next/how-to/circleci.md +12 -4
  52. package/src/docs/versioned/next/how-to/debug-with-mcp.md +10 -1
  53. package/src/docs/versioned/next/how-to/fix-code-scanning-alerts.md +43 -0
  54. package/src/docs/versioned/next/how-to/run-tests-locally.md +5 -0
  55. package/src/docs/versioned/next/how-to/set-up-terreno-mcp.md +3 -1
  56. package/src/docs/versioned/next/implementationPlans/mcp-agent-debugger-gaps.md +257 -0
  57. package/src/docs/versioned/next/reference/environment-variables.md +2 -0
  58. package/src/docs/versioned/next/reference/mcp-server.md +12 -0
  59. package/src/docs/versioned/next/reference/test.md +4 -1
  60. package/src/docs/versioned/next/tasks/mcp-agent-debugger-gaps.md +151 -0
package/CHANGELOG.md CHANGED
@@ -20,6 +20,37 @@ Upgrade notes for consumer action live in [`mcp-server/src/docs/upgrades/`](mcp-
20
20
 
21
21
  Unreleased changes live in [`changelog/unreleased/`](changelog/unreleased/). Add one Markdown file per feature (see that directory's README) instead of editing this section.
22
22
 
23
+ ## [58.0.4] - 2026-11-11
24
+
25
+ ### Fixed
26
+
27
+ - The admin consent form list loads again. `ConsentFormList` sorts by `-created` (and by its Title, Type, Version, Active, and Order columns), but `ConsentApp`'s `/consent-forms` router did not declare those as `sortFields`, so every list request returned 400 `sort-field-not-allowed`. Both `/consent-forms` and `/consent-responses` now allow sorting by the fields their admin metadata marks sortable; other fields are still rejected.
28
+
29
+ ## [58.0.3] - 2026-11-11
30
+
31
+ Upgrade note: [`mcp-server/src/docs/upgrades/58.0.3.md`](mcp-server/src/docs/upgrades/58.0.3.md).
32
+
33
+ ### Added
34
+
35
+ - `fix-code-scanning-alerts` skill: clears every open CodeQL alert on one PR. Fixes close on the master rescan; reviewed false positives go in `.github/code-scanning/dismissals.json` and a workflow dismisses them after merge. CodeQL now also scans pull requests and ignores test files. See `docs/how-to/fix-code-scanning-alerts.md`.
36
+ - **@terreno/syncdb:** `registerTerrenoDevClientDispatch`, `registerTerrenoDevStorage`, and `registerTerrenoDevCommand` for `terreno-mcp-local` dev tooling.
37
+ - **@terreno/mcp-server:** `read_logs` sources `network` and `native`; `dispatch_client_action`, storage read/write, and dev command list/invoke; CDP network capture with header redaction.
38
+
39
+ ### Changed
40
+
41
+ - Package tests run as concurrent `bun test --shard` processes through `scripts/test-shards.ts` (half the cores by default, `TERRENO_TEST_SHARDS` to override), and `test:coverage` merges the shards' LCOV. CircleCI now pins Bun 1.4.4, the same version as the local toolchain.
42
+
43
+ ### Fixed
44
+
45
+ - `Avatar` no longer freezes release builds when its image fails to load. The image error handler passed the native error event to `console.warn`, and with Sentry enabled the app hung while turning that event into a breadcrumb. It now logs only the error message.
46
+ - Mongo filters built from request values reject non-string input with 400 instead of running it as a query operator: AI request explorer `model`, observability review `status`, review batch `promptName`, experiment `datasetId`, trace list filters, push-token `platform`, and `loadDocOr404` ids (404). Sync conflict reloads and tombstone lookups match `_id` with `$eq`.
47
+ - Nested-path helpers in `populate`, RBAC field views, and MCP `excludeFields` skip `__proto__`, `constructor`, and `prototype`, so a crafted path can no longer touch `Object.prototype`.
48
+ - Removed polynomial-time regexes from bearer-header parsing, trailing-slash trimming (syncdb, ui `ListDetailLayout`, jobs Cloud Tasks runner, admin route paths), prompt references, judge score ranges, AI JSON fence stripping, and the MCP import parser.
49
+ - Dataset schema validation stops at the first error (`allErrors` off) to bound work on untrusted input.
50
+ - `isTestUser` in `@terreno/ui` matches `nang.io` and `example.com` as the email domain or a subdomain, not as a substring, and always returns a boolean.
51
+ - MCP OAuth metadata responses set an explicit JSON content type.
52
+ - The example app's AI session id comes from `expo-crypto` `randomUUID` instead of `Math.random`.
53
+
23
54
  ## [58.0.2] - 2026-11-09
24
55
 
25
56
  ### Fixed
package/README.md CHANGED
@@ -91,16 +91,18 @@ Restart the editor, then ask the agent to call `terreno_search_docs` or `applica
91
91
  `terreno_get_update_note`, `terreno_ask_update_help`, `terreno_generate_model`,
92
92
  `terreno_generate_route`, `terreno_generate_screen`, `terreno_generate_form_fields`,
93
93
  `terreno_validate_model_schema`, `terreno_validate_ui_blocks`, `terreno_install_admin`
94
- - Local `terreno-mcp-local` tools (11): `application_info`, `database_schema`, `database_query`,
94
+ - Local `terreno-mcp-local` tools (15): `application_info`, `database_schema`, `database_query`,
95
95
  `read_logs`, `last_error`, `get_syncdb_state`, `syncdb_snapshot`, `syncdb_action`, `evaluate`,
96
- `navigate`, `browser`
96
+ `navigate`, `dispatch_client_action`, `read_local_storage`, `write_local_storage`,
97
+ `list_dev_commands`, `invoke_dev_command`, `browser`
97
98
  - Nine workflow prompts (`terreno_bootstrap`, `terreno_create_crud_feature`, `terreno_upgrade`, and
98
99
  more) and `terreno://docs/*` documentation resources on the hosted server
99
100
  - Code generators return text with a target path; the agent writes the files
100
101
  - Rate limiting: the hosted server allows 120 requests per 60 seconds per client IP by default and
101
102
  answers `429` with `Retry-After` beyond that
102
- - `TERRENO_MCP_EVAL` gate: `evaluate`, `navigate`, `syncdb_action`, and the `browser` `evaluate`
103
- action run only when the local server's environment sets `TERRENO_MCP_EVAL=1` (or `true`)
103
+ - `TERRENO_MCP_EVAL` gate: `evaluate`, `navigate`, `syncdb_action`, `dispatch_client_action`,
104
+ `write_local_storage`, `invoke_dev_command`, and the `browser` `evaluate` action run only when
105
+ the local server's environment sets `TERRENO_MCP_EVAL=1` (or `true`)
104
106
 
105
107
  ## Documentation
106
108
 
@@ -7,12 +7,14 @@ import {DefaultTheme, ThemeProvider} from "expo-router/react-navigation";
7
7
  import type React from "react";
8
8
  import {useEffect} from "react";
9
9
  import "react-native-reanimated";
10
+ import {registerTerrenoDevStorage} from "@terreno/syncdb";
10
11
  import {installDevConsoleLogger} from "@terreno/syncdb/app";
11
12
  import {betterAuthClient} from "@/lib/betterAuth";
12
13
  import {apiClient} from "@/store/apiClient";
13
14
  import {setSyncDbReady, syncDb} from "@/store/syncdb";
14
15
 
15
16
  installDevConsoleLogger({baseUrl});
17
+ registerTerrenoDevStorage({asyncStorage: true});
16
18
 
17
19
  export {ErrorBoundary} from "expo-router";
18
20
 
@@ -0,0 +1,28 @@
1
+ # Upgrading to 58.0.3
2
+
3
+ **Action required:** No
4
+ **Affected packages:** None
5
+
6
+ ## Summary
7
+
8
+ A patch release with bug and security fixes. `Avatar` no longer freezes release builds when its image fails to load. Mongo filters built from request values, nested-path helpers, and several regexes are hardened against untrusted input. Consumers only need to bump their `@terreno/*` versions.
9
+
10
+ ## Breaking changes
11
+
12
+ None
13
+
14
+ The only `Changed` entry affects this repository's own test tooling (sharded `bun test` and Bun 1.4.4 on CircleCI). Nothing changes for consumer apps.
15
+
16
+ ## Deprecations
17
+
18
+ None
19
+
20
+ ## New capabilities
21
+
22
+ - **@terreno/syncdb:** `registerTerrenoDevClientDispatch`, `registerTerrenoDevStorage`, and `registerTerrenoDevCommand` for `terreno-mcp-local` dev tooling. These are optional.
23
+ - **@terreno/mcp-server:** `read_logs` sources `network` and `native`, client action dispatch, storage read/write, and dev commands.
24
+
25
+ ## Verification
26
+
27
+ - `bun run compile` and `bun run lint` at the app root
28
+ - In a release build, show an `Avatar` whose `src` fails to load. It falls back to initials and the app stays responsive.
@@ -15,7 +15,7 @@ flowchart LR
15
15
  ASK["1. Ask<br/>terreno_search_docs<br/>terreno_get_component_docs<br/>application_info"]
16
16
  GEN["2. Generate<br/>terreno_generate_*<br/>terreno_validate_model_schema"]
17
17
  RUN["3. Run<br/>backend dev server<br/>Metro (Expo)"]
18
- OBS["4. Observe<br/>read_logs (backend / browser / metro / app)<br/>last_error<br/>get_client_state"]
18
+ OBS["4. Observe<br/>read_logs (backend / browser / metro / app / network / native)<br/>last_error<br/>get_client_state"]
19
19
  FIX["5. Fix<br/>edit, then navigate<br/>browser snapshot + screenshot"]
20
20
  ASK --> GEN --> RUN --> OBS --> FIX
21
21
  FIX -->|"iterate"| ASK
@@ -79,7 +79,7 @@ The agent reads what the app did.
79
79
 
80
80
  | Tool | Contributes |
81
81
  | --- | --- |
82
- | `read_logs` | One merged, time-ordered tail from four sources: `backend` (server JSONL), `browser` (web errors and warnings JSONL), `metro` (bundler events), and `app` (the Hermes console over the Chrome DevTools Protocol). Its `connection` field says which live sources are attached. |
82
+ | `read_logs` | One merged, time-ordered tail from six sources: `backend` (server JSONL), `browser` (web errors and warnings JSONL), `metro` (bundler events), `app` (the Hermes console over CDP), `network` (CDP Network events on the same session), and `native` (adb / iOS Simulator log tail when available). Default sources omit `native`. Its `connection` field says which live sources are attached. |
83
83
  | `last_error` | The newest error-level entry across the same sources, as the raw line. It includes a stack when the entry carries one. |
84
84
  | `get_client_state` | The client data layer in the running app. It reports which `layer` it found (`rtk`, `syncdb`, both, or `none`) and returns the RTK Query cache and auth state, the SyncDB state, or both. `get_rtk_state` is a deprecated alias. |
85
85
  | `get_syncdb_state`, `syncdb_snapshot` | SyncDB entities, outbox, conflicts, cursors, and debug events, plus snapshots to compare before and after a change |
@@ -96,13 +96,16 @@ result.
96
96
  | --- | --- |
97
97
  | `navigate` | Moves a native app to an expo-router path over the same CDP connection the logs use |
98
98
  | `browser` | Drives the web app in a headless WebView: open, click, type, scroll, then `snapshot` the rendered page and save a `screenshot` as proof |
99
- | `evaluate` | Runs a JavaScript expression in the app's Hermes runtime |
99
+ | `dispatch_client_action` | Dispatches a known Redux action on the dev store (prefer over raw `evaluate`) |
100
+ | `read_local_storage` / `write_local_storage` | Read or write AsyncStorage keys registered for MCP dev tooling |
101
+ | `list_dev_commands` / `invoke_dev_command` | List and run app-registered dev-only command handlers |
102
+ | `evaluate` | Runs a JavaScript expression in the app's Hermes runtime when no fixed tool fits |
100
103
  | `syncdb_action` | Changes a live SyncDB client: mutate, flush, resync, resolve conflicts, go offline |
101
104
 
102
- `evaluate`, `navigate`, `syncdb_action`, and the `browser` tool's `evaluate` action run code
103
- or change state inside the app, so they refuse unless the local server was started with
104
- `TERRENO_MCP_EVAL=1`. Generated editor configuration never sets it. The other `browser`
105
- actions do not need it.
105
+ `evaluate`, `navigate`, `dispatch_client_action`, `write_local_storage`, `invoke_dev_command`,
106
+ `syncdb_action`, and the `browser` tool's `evaluate` action run code or change state inside the
107
+ app, so they refuse unless the local server was started with `TERRENO_MCP_EVAL=1`. Generated
108
+ editor configuration never sets it. The other `browser` actions do not need it.
106
109
 
107
110
  After the fix, the loop goes back to Observe. A change is done when the logs and state show
108
111
  the new behavior, not when the edit compiles.
@@ -1,6 +1,7 @@
1
1
  # Test isolation in Bun suites
2
2
 
3
- `bun test` runs every test file of a package in one process. `mock.module` replaces a
3
+ `bun test` runs every test file of a package, or of one [shard](test-sharding.md) of it,
4
+ in one process. `mock.module` replaces a
4
5
  module for that whole process, and `mock.restore()` does not undo it. A test that
5
6
  mocks a module can pass on its own, then break other files, or be broken by them,
6
7
  when the whole package runs. CI always runs the whole package, so this kind of
@@ -0,0 +1,113 @@
1
+ # Test sharding in Bun suites
2
+
3
+ Every package runs its tests through `scripts/test-shards.ts`. The runner starts several
4
+ `bun test --shard=<i>/<n>` processes at once, one per shard, and fails when any of them
5
+ fails. Bun 1.4.4 or newer is required: older versions have no `--shard`.
6
+
7
+ ```bash
8
+ cd api
9
+ bun run test:ci # shards chosen from the machine's cores
10
+ TERRENO_TEST_SHARDS=1 bun run test:ci # one unsplit process
11
+ TERRENO_TEST_SHARDS=3 bun run test:ci # exactly three shards
12
+ bun test ./src/auth.test.ts # one file, no runner
13
+ ```
14
+
15
+ ## Why shards and not `bun test --parallel`
16
+
17
+ A shard is an ordinary `bun test` process. It loads the preload once, keeps one module
18
+ registry, and starts one in-memory Mongo, exactly as an unsplit run does. A test file sees
19
+ the same world either way. Only the set of files that share its process changes.
20
+
21
+ `bun test --parallel` gives each file a fresh global. That re-runs the preload's
22
+ `beforeAll` and `afterAll` for every file, so a backend package starts and stops Mongo once
23
+ per file and reloads every module. Measured on `@terreno/api` (169 files, 4 cores): 648 s
24
+ unsplit, 459 s with `--parallel`, 408 s with two shards.
25
+
26
+ ## How many shards
27
+
28
+ | Source | Shards |
29
+ | --- | --- |
30
+ | `TERRENO_TEST_SHARDS` set | That number |
31
+ | Not set | Half the cores, at least 1, at most 4 |
32
+
33
+ A backend shard keeps a Bun process and a `mongod` busy, about two cores. More shards than
34
+ half the cores slows every shard down and makes timing-sensitive tests fail.
35
+
36
+ CircleCI jobs set `TERRENO_TEST_SHARDS` themselves, because a container reports the host's
37
+ cores and not its own CPU limit. Medium jobs (2 vCPU) run 1 shard. Backend jobs run 1 shard
38
+ even on `large`: CircleCI gives a job one sidecar `mongod`, and every shard connects to the
39
+ same `mongodb://127.0.0.1/terreno` database, so concurrent shards clear each other's
40
+ collections mid-test. `api-ci` ran 2 shards until that broke its tests.
41
+
42
+ Root `bun run test` and `bun run test:agent` set `TERRENO_TEST_SHARDS=1`: they already run
43
+ every package at the same time.
44
+
45
+ ## Measured speedup
46
+
47
+ One 4-core machine, every package's `test:ci` run one after another:
48
+
49
+ | Package | Unsplit | 2 shards |
50
+ | --- | --- | --- |
51
+ | `api` | 648 s | 408 s |
52
+ | `ai` | 314 s | 187 s |
53
+ | `example-backend` | 253 s | 135 s |
54
+ | `admin-frontend` | 142 s | 75 s |
55
+ | `admin-backend` | 124 s | 83 s |
56
+ | `ui` | 95 s | 65 s |
57
+ | All 21 packages | 1849 s | 1163 s |
58
+
59
+ Packages that finish in a few seconds gain nothing and lose nothing.
60
+
61
+ ## Isolated files
62
+
63
+ `ai` and `admin-frontend` pass `--isolated` to the runner. After the shards pass, each
64
+ `src/isolated/*.isolated.ts(x)` file runs in a process of its own, as many at a time as there
65
+ are shards. See [Test isolation](test-isolation.md).
66
+
67
+ ## Coverage
68
+
69
+ `bun run test:coverage` (`scripts/check-coverage.ts`) uses the same shards. Each shard writes
70
+ its own LCOV report. The script merges them, writes `coverage/lcov.info`, and gates the
71
+ merged numbers at 95%.
72
+
73
+ Line coverage merges exactly: a line counts when any shard ran it. The sharded line figure
74
+ equals the unsplit one.
75
+
76
+ Function coverage cannot merge exactly. Bun's LCOV has no per-function records, only a found
77
+ and hit count per file, and Bun counts a nested function only after its parent ran, so shards
78
+ disagree on how many functions a file has. The script takes the largest found count and the
79
+ largest hit count for each file. That estimate usually reads low, because functions hit in
80
+ different shards are not added together. It can read high when one shard runs most of a file
81
+ and another shard finds nested functions that nothing calls.
82
+
83
+ A sharded run that misses 95% is run again as one unsplit process, and the gate uses that
84
+ exact result. A package whose function coverage is near 95% therefore pays for a second pass;
85
+ set `TERRENO_TEST_SHARDS=1` to skip the first. CircleCI gates every package unsplit except
86
+ `api` and `ai`, which run 2 shards.
87
+
88
+ While shards run, their output is held and printed one shard at a time. The runner prints a
89
+ `[shards] still running` line once a minute so CI does not see a silent job.
90
+
91
+ ## When a test fails only in a shard
92
+
93
+ Sharding changes which files share a process. A test that passed only because an earlier
94
+ file left something behind now fails. Run the file alone to confirm:
95
+
96
+ ```bash
97
+ bun test ./src/models/configuration.test.ts
98
+ ```
99
+
100
+ Fix the file so it passes alone. The usual causes:
101
+
102
+ 1. **A missing import.** The test reads state that another file's import registered. Import
103
+ the module in the test.
104
+ 2. **A module mock from another file.** A snapshot or assertion matches another file's
105
+ `mock.module` shape. Register the mock once in the package preload.
106
+ 3. **A timing budget.** Shards load the machine. Freeze the clock with `setSystemTime` or give
107
+ a slow test its own timeout; do not rely on wall-clock windows.
108
+
109
+ To reproduce the exact process a shard ran, pass the shard to Bun directly:
110
+
111
+ ```bash
112
+ bun test --shard=2/3
113
+ ```
@@ -16,6 +16,7 @@ Problem-oriented, practical steps. Use these when you know what you want to do.
16
16
 
17
17
  - [Create a Terreno app](create-a-terreno-app.md) — Scaffold a full-stack app with `create-terreno-app` (Bun or npm)
18
18
  - [Update dependencies](update-dependencies.md) — Daily rolling PR, exercise test, Expo fingerprint freeze
19
+ - [Fix code scanning alerts](fix-code-scanning-alerts.md) — One PR per sweep; fixes close on rescan, reviewed false positives are dismissed after merge
19
20
  - [CircleCI](circleci.md) — Dual-run CI on CircleCI (package CI / policy / e2e; deploys later)
20
21
  - [Release automation](release-automation.md) — Let agents merge release notes and roadmap updates; publish only merged notes
21
22
  - [Set up tests in a Terreno app](set-up-app-tests.md) — Bun backend and frontend tests, Playwright web E2E, Maestro on iOS/Android
@@ -49,10 +49,18 @@ list pipelines on the slug above.
49
49
 
50
50
  ## Bun version is pinned
51
51
 
52
- `install_bun_and_deps` pins Bun with `node/install-bun` `version`. Bun 1.4.4 reports
53
- lower line coverage than 1.4.2 for the same tests, which fails the 95% package
54
- coverage gates. Bump the pin together with the local toolchain and re-run
55
- `bun run test:coverage` in each package first.
52
+ `install_bun_and_deps` pins Bun with `node/install-bun` `version`, currently 1.4.4, the
53
+ same version as the local toolchain and the GitHub workflows. Package tests run through
54
+ `bun test --shard`, which needs 1.4.4 or newer. Bump the pin together with the local
55
+ toolchain and re-run `bun run test:coverage` in each package first: coverage numbers move
56
+ between Bun releases.
57
+
58
+ ## Test shards
59
+
60
+ Each executor sets `TERRENO_TEST_SHARDS`, the number of concurrent `bun test --shard`
61
+ processes a package's tests use. Medium executors set 1. `api-ci`, the longest test
62
+ job, overrides it to 2 and runs on `large`. See
63
+ [Test sharding](../explanation/test-sharding.md).
56
64
 
57
65
  ## Bun install is uncached
58
66
 
@@ -1,5 +1,9 @@
1
1
  # Debug a Terreno app with MCP
2
2
 
3
+ **This is the standard agent workflow** for finding and fixing issues on Terreno apps: run the
4
+ dev stack, call **`terreno-local`** MCP tools to observe and drive the app, edit code, then
5
+ observe again. Installable skill: **`debug-with-mcp`**. SyncDB-only depth: **`debug-syncdb-with-mcp`**.
6
+
3
7
  Use the local MCP server (`terreno-mcp-local`) to go from a symptom to a verified fix without
4
8
  pasting logs into the chat. This guide follows one real failure from start to finish, then lists
5
9
  what each tool does. Every tool output below was copied unchanged from a real run against
@@ -12,6 +16,11 @@ what each tool does. Every tool output below was copied unchanged from a real ru
12
16
  | API returns 500 | `last_error` with `sources: ["backend"]`. The stack is inside `message`. | `read_logs` with `sources: ["backend"]` and `since` to see the requests around it. |
13
17
  | API returns 403 (or another 4xx) | `read_logs` with `sources: ["backend"]` and `level: "warn"`. Every `APIError` under 500 is logged at `warn` as `ForbiddenError(403): <title> — <detail>`, so `last_error` does not show it. | `database_query` to compare the document's `ownerId` with the user in the log line. |
14
18
  | App crashes on a screen | Web: `last_error` with `sources: ["browser"]`. An uncaught error carries a separate `stack` field. A render error caught by an error boundary has no `stack`; its `message` names the component instead (see [A screen crashes on web](#a-screen-crashes-on-web)). Native: `last_error` with `sources: ["app"]`. | Native: `navigate` to the screen and call `last_error` again. Web: the `browser` tool. |
19
+ | Wrong API URL or status on device | `read_logs` with `sources: ["network"]` after reproducing the tap. | `database_query` or backend logs to compare server truth. |
20
+ | Auth/session oddities (token in storage) | `read_local_storage` with `prefix: "persist:"` or known key names. | `write_local_storage` only with `TERRENO_MCP_EVAL=1` to fix dev keys; prefer fixing app code for prod. |
21
+ | Native-only crash (no Hermes console) | `read_logs` with `sources: ["native"]` (needs `adb` or iOS Simulator). | `last_error` with `sources: ["app"]` when Hermes is attached. |
22
+ | Need a one-off dev action in the app | `list_dev_commands`, then `invoke_dev_command` with `TERRENO_MCP_EVAL=1`. | Register handlers with `registerTerrenoDevCommand` in app code. |
23
+ | Redux state wrong but SyncDB OK | `get_client_state` or `dispatch_client_action` with a known action type. | `syncdb_action` only for collection CRUD, not Redux. |
15
24
  | Data looks wrong | `database_query` to read what the server stored. | `get_client_state` (RTK cache) or `get_syncdb_state` (SyncDB) to compare the client's copy. |
16
25
  | Screen renders empty | `get_client_state` or `get_syncdb_state` on native. On web, `browser` with `snapshot`. | `read_logs` with `sources: ["backend"]` to check that the list request ran and returned 200. |
17
26
  | Bundler fails | The terminal that runs `expo start`. The `metro` source is always empty under Expo CLI 57: the `/events` socket connects but Expo never sends on it. | On native, `read_logs` with `sources: ["app"]` once the app loads again. |
@@ -161,7 +170,7 @@ On web this returns `layer: "none"`:
161
170
  ```json
162
171
  {
163
172
  "connection": "CDP: Error: No debuggable Hermes/React Native target with webSocketDebuggerUrl (is the app running?); Metro events: not connected",
164
- "hint": "No client data layer found. For RTK Query, call `registerTerrenoDevStore(store)` from @terreno/rtk in __DEV__. For SyncDB, create the client with `createSyncDb({debug: true})`. Keep the app running; when the MCP process cannot see the app heap, start Metro so CDP can reach Hermes (see `connection`).",
173
+ "hint": "No client data layer found. For SyncDB, create the client with `createSyncDb({debug: true})`. For custom client actions, call `registerTerrenoDevClientDispatch` from `@terreno/syncdb` in __DEV__. Keep the app running; when the MCP process cannot see the app heap, start Metro so CDP can reach Hermes (see `connection`).",
165
174
  "layer": "none",
166
175
  "reasons": {
167
176
  "rtk": "Error: No debuggable Hermes/React Native target with webSocketDebuggerUrl (is the app running?)",
@@ -0,0 +1,43 @@
1
+ # Fix code scanning alerts
2
+
3
+ Run `/fix-code-scanning-alerts` to clear every open CodeQL alert on one PR. When that PR merges, each alert closes: fixes close when CodeQL rescans `master`, and reviewed false positives are dismissed by a workflow.
4
+
5
+ ```bash
6
+ gh api "repos/{owner}/{repo}/code-scanning/alerts?state=open&per_page=100" --paginate \
7
+ | jq -s 'add | group_by(.rule.id) | map({rule: .[0].rule.id, count: length})'
8
+ ```
9
+
10
+ ## How alerts close
11
+
12
+ | Lane | In the PR | After merge |
13
+ | --- | --- | --- |
14
+ | Fix | Code change and a regression test | The CodeQL push scan on `master` no longer reports it, so it closes as **fixed** |
15
+ | Dismiss | An entry in `.github/code-scanning/dismissals.json` | `code-scanning-dismissals.yml` dismisses it with the entry's reason and comment |
16
+
17
+ Dismissals wait for the merge so a reviewer approves each one, and the Security tab never shows an alert closed by an unmerged branch.
18
+
19
+ ## Pieces
20
+
21
+ - `.github/codeql/codeql-config.yml`: CodeQL configuration. Test files are ignored, so their alerts close on the next `master` scan.
22
+ - `.github/workflows/codeql-analysis.yml`: also runs on pull requests (diff-informed: only changed lines) and on manual dispatch. Dispatch it on a branch for a full scan that proves each fix clears its alert before merge.
23
+ - `.github/code-scanning/dismissals.json`: the dismissal ledger. Each entry has `alert`, `rule`, `path`, `reason` (`false positive`, `won't fix`, or `used in tests`), and a `comment` of 280 characters or fewer.
24
+ - `.github/workflows/code-scanning-dismissals.yml`: runs on `master` when the ledger changes, and on manual dispatch.
25
+ - `scripts/ci/codeScanning/applyDismissals.ts`: applies the ledger. It dismisses an entry only when the live alert is still open and its rule and path still match. A mismatch fails the job.
26
+
27
+ ## Check a ledger locally
28
+
29
+ ```bash
30
+ bun test scripts/ci/codeScanning/
31
+ GITHUB_TOKEN="$(gh auth token)" GITHUB_REPOSITORY=TerrenoLabs/terreno \
32
+ bun scripts/ci/codeScanning/applyDismissals.ts --dry-run
33
+ ```
34
+
35
+ The dry run must report `mismatched 0`.
36
+
37
+ ## Rate limiting alerts
38
+
39
+ `js/missing-rate-limiting` flags every Express route because CodeQL only recognizes known limiter libraries. `TerrenoApp` mounts its own limiter before all plugins (see [Rate limiting](rate-limiting.md)), so these alerts go in the ledger as false positives. A route mounted outside `TerrenoApp` has no limiter and needs a real fix.
40
+
41
+ ## Dependabot
42
+
43
+ Dependabot opens **security PRs only**. Routine upgrades go through [Update dependencies](update-dependencies.md). Every workspace package directory is listed in `.github/dependabot.yml`. Add a new package's directory there when you create it.
@@ -52,6 +52,11 @@ bun run test # every workspace `test:ci`
52
52
  bun run test:agent # same suites; passing cases suppressed
53
53
  ```
54
54
 
55
+ Each package's `test`, `test:ci`, `test:agent`, and `test:coverage` scripts split the suite
56
+ into concurrent `bun test --shard` processes, half the cores by default. Set
57
+ `TERRENO_TEST_SHARDS=1` for one unsplit process. See
58
+ [Test sharding](../explanation/test-sharding.md).
59
+
55
60
  Closest package during a red/green cycle:
56
61
 
57
62
  ```bash
@@ -1,7 +1,9 @@
1
1
  # Set up Terreno MCP
2
2
 
3
3
  Configure both Terreno servers: the hosted server supplies documentation and generators; the local
4
- stdio server inspects the app, database, logs, Metro, and SyncDB state.
4
+ stdio server inspects the app, database, logs, Metro, SyncDB state, web and native navigation.
5
+ After setup, invoke **`debug-with-mcp`** (and when applicable **`debug-syncdb-with-mcp`**) for the
6
+ standard diagnostic workflow.
5
7
  - **`terreno`** (hosted, Streamable HTTP) supplies documentation search and code generators.
6
8
  - **`terreno-local`** (stdio, runs in your repository) reads the app's packages, database, logs,
7
9
  Metro, and client state.