@spooky-sync/cli 0.0.1-canary.98 → 1.0.0-beta.10

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.
package/AGENTS.md CHANGED
@@ -26,45 +26,100 @@ your-app/
26
26
 
27
27
  `spky` finds `sp00ky.yml` in the current directory by default; pass `--config <path>` to override.
28
28
 
29
+ ## Running it as an agent: always pass `-y`
30
+
31
+ You are almost certainly running on a **pseudo-terminal**. The CLI sees a terminal, renders its
32
+ prompt, and waits forever for a keypress you cannot send. Pass `-y` / `--yes` (any subcommand, any
33
+ position; `SPKY_YES=1` also works) and nothing blocks:
34
+
35
+ - **Consent prompts** ("Apply pending migrations to this PRODUCTION database?", "Restart SurrealDB?",
36
+ "Overwrite?") are answered **yes**, and the answer is printed so your log shows what you agreed to.
37
+ - **Preference prompts** ("Initialize git?", "Create a backup before resetting?") take their
38
+ **default**, never a blanket yes.
39
+ - **Menus** in `spky dev` (schema drift, pending migrations) take their unattended path: continue
40
+ with drift, auto-apply pending migrations.
41
+ - **Guided flows** (login, project picker, billing) do not open. They stop and print the exact
42
+ command or env var to use instead, e.g. `SP00KY_CLOUD_PROJECT` or `slug:` in `sp00ky.yml`.
43
+
44
+ Two operations are **not** covered by `-y`, on purpose, because they cannot be undone:
45
+ `spky project destroy` and `spky backup reset`. They need `--confirm <project-slug>`, spelled
46
+ correctly. Do not reach for these unless the user asked for exactly that, by name.
47
+
48
+ Without `-y` and without a terminal, a consent prompt **refuses** rather than proceeding, and the
49
+ error names the flag. If you see "No terminal to ask on", that is this.
50
+
29
51
  ## Subcommands an app developer/agent uses most
30
52
 
31
53
  - **`spky generate` / `spky gen`** — read `sp00ky.yml`, parse all `.surql`, emit `schema.gen.ts` (and Dart equivalents per config). **Run this after every schema edit.**
32
54
  - **`spky migrate create <name>`** — diff current schema against the last applied migration and emit a new `.surql` migration file.
33
- - **`spky migrate apply`** — apply pending migrations against the configured database. `--fix-checksums` updates stored checksums for legitimately-modified migration files.
55
+ - **`spky migrate apply`** — apply pending migrations against the configured database. `--fix-checksums` updates stored checksums for legitimately-modified migration files. `--mode` defaults to `mode` in `sp00ky.yml`. Against a self-hosted database pass `--endpoint <ssp or scheduler URL as SurrealDB reaches it> --secret <SPKY_AUTH_SECRET>`: that also installs the `$sp00ky_endpoint` / `$sp00ky_secret` params the sync events post to, without which every write to a synced table fails.
34
56
  - **`spky migrate status`** — show pending vs applied vs modified-but-applied migrations.
35
57
  - **`spky migrate fix [--fix-checksums]`** — repair schema drift / checksum mismatches.
36
- - **`spky verify [--fix]`** — confirm SSP/scheduler snapshot matches upstream SurrealDB. `--fix` triggers a resync.
37
- - **`spky lint`** — validate `sp00ky.yml` and referenced files exist.
38
- - **`spky dev [--apply-migrations] [--clean]`** — boots a local SurrealDB + SSP + scheduler stack via Docker. `--clean` wipes SSP/scheduler state but preserves user data in SurrealDB.
39
- - **`spky create`** — scaffold a new sp00ky project.
58
+ - **`spky verify [--fix]`** — confirm SSP/scheduler snapshot matches upstream SurrealDB, and print the scheduler's own drift verdict (`/health/snapshot` `drift`). `--fix` re-clones the scheduler replica when its counts are off, otherwise forces every SSP to re-bootstrap. The scheduler runs the same count check itself at startup and after each snapshot drain, repairs a drifted table in place by default, and re-clones only when a repair cannot fix it (`SPKY_DRIFT_AUTO_RECLONE`). Tables added, changed or removed upstream are picked up by a running scheduler and SSP without a restart or re-clone.
59
+ - **`spky lint`** — validate `sp00ky.yml` and referenced files exist, and warn about statements in the app's `DEFINE EVENT` / `DEFINE FUNCTION` bodies that SurrealDB 4.0.1 runs as table scans (`where-on-event-value`, `write-where`, `inside-param`, `composite-index`, `lookup-write-with-call`) and about `FOR select WHERE true` (write `FULL`), each with its rewrite (`src/query_lint.rs`). A `-- spky-lint: allow <rule>` comment above a DEFINE silences a rule for that definition. `spky doctor` reports the same as the `body-index-scans` warning.
60
+ - **`spky dev [--apply-migrations] [--clean] [--verbose]`** — boots a local SurrealDB + SSP + scheduler stack via Docker. `--clean` wipes SSP/scheduler state but preserves user data in SurrealDB. Startup renders as step lines via `src/ui.rs` (indicatif/console; plain lines when not a TTY); after "ready" only ERROR/crash-looking lines (infra and app streams) show unless `--verbose` / `SPKY_VERBOSE=1`. A bare `logLevel` is scoped to sp00ky crates by `backend::scoped_rust_log`.
61
+ - **`spky init`** — scaffold a new sp00ky project in the current directory. (`spky create` is a removed alias that only prints a migration hint.)
40
62
  - **`spky bucket add`** / **`spky api add`** — append a bucket or backend definition to `sp00ky.yml`.
41
- - **`spky mcp`** — start the bundled `@spooky-sync/devtools-mcp` server (so AI assistants can introspect the running app).
63
+ - **`spky mcp`** — start the bundled `@spooky-sync/devtools-mcp` server (so AI assistants can introspect the running app). Its `token` / `tokens` / `revoke` / `install` subcommands manage credentials for the separate Sp00ky Cloud MCP server. A deployed scheduler also serves its own MCP server for operator actions; see `docs/reference/mcp.mdx`.
64
+ - **`spky admin list|add <user>|remove <user>`** — manage the `_00_admin` roster. Roster members can sign in to the scheduler's operator dashboard and administer feature flags. `add` takes an optional `--note`.
65
+
66
+ ## Deployment subcommands
42
67
 
43
- ## Cloud subcommands (deployment)
68
+ These are top level, not under a `cloud` prefix. `spky cloud ...` was removed and now only
69
+ prints a migration hint.
44
70
 
45
- `spky cloud login | create | deploy | status | logs | scale | restart | destroy | backup | env | keys | link | team | vault | credentials`. See `spky cloud --help`. Most app code agents touch never need these.
71
+ `spky login | logout | deploy | release | status | stats | logs | restart | push | scale | backup | env | domain | link | team | billing | token | project | notice`.
72
+ See `spky <command> --help`. Most app code agents touch never need these.
73
+
74
+ Two that come up when a deployment misbehaves:
75
+
76
+ - **`spky restart [TARGET...] [--upgrade] [--clean] [--surreal] [--all-backends] [-y]`** —
77
+ recreate containers. Targets are roles (`db`, `scheduler`, `ssp`, `frontend`) or an app
78
+ name; with none it restarts the scheduler and SSPs. `--upgrade` pulls the latest scheduler
79
+ and SSP images, `--clean` wipes the scheduler's volume (replica and WAL, not SurrealDB
80
+ data). `-y` (the global flag, see above) confirms the SurrealDB prompt; without it and without
81
+ a terminal the restart is refused.
82
+ - **`spky migrate prod -y`** — apply pending migrations plus the internal Sp00ky schema to the
83
+ deployment, without a full deploy. `-y` confirms the production gate, which otherwise refuses
84
+ when there is no terminal. Set `SPKY_DB_HTTP_TIMEOUT_SECS` if the internal schema step times out.
46
85
 
47
86
  ## Schema annotations the parser recognizes
48
87
 
49
88
  In your `.surql` source, comment annotations attached to `DEFINE FIELD` / `DEFINE TABLE` change codegen output:
50
89
 
51
- - `-- @crdt text` (above a `DEFINE FIELD`) — marks a field as a Loro CRDT text field. Consumers must use `useCrdtField` to read/write it; plain `useQuery` will see stale or unmerged content.
90
+ - `-- @crdt text` / `-- @crdt prosemirror` (above a `DEFINE FIELD ... TYPE string`), optionally with `-- @cursor`: a collaborative Loro field. `crdt_schema::expand` (run by every schema pipeline: server schema, events, internal schema, client schema) rewrites the field into a server-written plain-text mirror (`DEFAULT ''` plus a VALUE guard that keeps `$before` for any record-user write) and generates, per parent `P`: `P__crdt_log` (append-only edit log; create follows P's update rule and select P's select rule, both rebased through the `doc` link on the AST by `rebase_permission`; update/delete NONE; impersonation sessions may not create), `P__crdt_presence` (`@cursor` only), the `<field>__crdt` fold stamp on `P`, a cleanup event, and the shared `_00_crdt_doc` (canonical snapshots, SSP-only) and `_00_crdt_peer` (peer id ownership). It refuses a non-string type, a VALUE/ASSERT on the field, nested fields, relation tables, reserved names (`*__crdt_log`, `*__crdt_presence`, `_00_crdt_doc`, `*__crdt` fields) and the `surrealism` deploy mode. Clients edit through `useCrdtField`; the column itself is readable and filterable like any string. Design: `docs/crdt-v2.md`.
52
91
  - `-- @parent` (suffix on `DEFINE FIELD ... TYPE record<...>`) — marks the column as the parent side of a relationship; written automatically from the auth context, never by client code.
53
92
  - `-- @nosync` (above a `DEFINE TABLE`) — marks a table as server-only: it is omitted from generated types and relations (and any `record<...>` link pointing at it is dropped), no sync events are emitted for it, and the scheduler/SSP exclude it from snapshots and bootstrap. The table still lives in the main DB and is still backed up. The CLI bakes a `COMMENT 'sp00ky:nosync'` marker onto the server-side `DEFINE TABLE` so the runtime services detect it via `INFO FOR DB`. Distinct from `PERMISSIONS FOR select WHERE false`, which only locks reads — a permission-locked table is still synced.
93
+ - `-- @nosync` (above a `DEFINE FIELD`) — marks a single field server-only: omitted from generated types and from the client's local cache schema, omitted from sync event payloads, and omitted from the scheduler replica and SSP bootstrap row scans. **Not a read barrier**: a client's down-sync `SELECT` still returns the column over the wire, and it is only discarded on arrival (`cleanRecord`). For real secrecy use `PERMISSIONS FOR select WHERE false` on the field, or move it to a `@nosync` table.
94
+ - `-- @opaque` (above a `DEFINE FIELD`) — the field IS synced to the client (it stays in generated types and the local cache, flagged `opaque: true` on the column) but no server-side component stores the value. Intended for large blobs you render but never query on. Because nothing holds the value it cannot be evaluated: using it in `where`/`orderBy`/a join throws in the query builder and is rejected with a 400 at SSP registration, and a schema whose `PERMISSIONS` or `DEFINE INDEX` references one fails to build. Delivery works because sync payloads carry ids + versions, not field values — the client reads the row body straight from SurrealDB.
95
+
96
+ Both field-level exclusions (`@nosync`, `@opaque`) get `COMMENT 'sp00ky:opaque'` baked onto the server `DEFINE FIELD` (`schema_builder::add_opaque_field_markers`). The scheduler replica and the SSP bootstrap read that marker from `INFO FOR TABLE` and turn it into a `SELECT * OMIT ...` projection. Both halves are required: skipping a field from the ingest payload while the bootstrap still loads it makes the SSP circuit and the scheduler replica disagree about the row's key set permanently (the replica applies updates with `MERGE`, the circuit replaces the whole row), which shows up as an unfixable `spky verify` mismatch. A `@crdt` field is not excluded (its mirror is an ordinary synced column) unless it also carries `@opaque`; the generated log's `data` and presence `state` columns are `@opaque` with the marker baked in, because the internal-schema step re-applies those definitions without the marker pass.
54
97
 
55
98
  Example:
56
99
  ```sql
57
100
  DEFINE TABLE thread SCHEMAFULL ...;
58
101
 
59
- -- @crdt text
60
- DEFINE FIELD content ON TABLE thread TYPE string ASSERT $value != NONE;
102
+ -- @crdt prosemirror
103
+ -- @cursor
104
+ DEFINE FIELD content ON TABLE thread TYPE string;
61
105
 
62
106
  DEFINE FIELD author ON TABLE thread TYPE record<user>; -- @parent
63
107
 
108
+ -- @opaque
109
+ DEFINE FIELD preview_png ON TABLE thread TYPE option<bytes>;
110
+
64
111
  -- @nosync
65
112
  DEFINE TABLE audit_log SCHEMALESS;
66
113
  ```
67
114
 
115
+ A descriptor must sit directly above its statement (no blank line between). One that attaches to nothing is warned about, not silently dropped (`annotations::warn_unattached_annotations`). A descriptor is the marker alone plus at most one value token (`-- @crdt text`); a longer comment that merely starts with a marker name is prose, not an annotation, and `-- @nosync true` is refused with a warning.
116
+
117
+ ## Room relay (`relay:` in `sp00ky.yml`)
118
+
119
+ `relay: true` (or `relay: { image: ... }`, on unless `enabled: false`) runs the room relay (`apps/relay`, image `mono424/spooky-relay` at the tag of this CLI's release channel) for the client's `channels.share`. It is not a service of its own in the CLI: `Sp00kyConfig::expand_relay` (`backend.rs`, called by `parse_config_with_includes`) turns the key into a `type: docker` app named `spky-relay` (`RELAY_APP`) with port 8668, `healthcheck: /health`, `deploy: { expose: true }` and, for dev, `SPKY_DB_URL=http://surrealdb:8000`. So every path that walks docker apps handles it unchanged: `spky dev` starts container `sp00ky-dev-spky-relay` with the other docker apps, `spky deploy` pulls the image and ships it as an exposed backend at `{slug}-spky-relay.<domain>`. Added on top: `SPKY_RELAY_URL` / `VITE_SPKY_RELAY_URL` (`ws://localhost:8668/room`) in the dev env of every app and a "Relay" row in the ready banner (`dev.rs`), `VITE_SPKY_RELAY_URL=wss://{slug}-spky-relay.<domain>/room` as a frontend build arg on deploy (`derive_relay_ws_endpoint` in `cloud.rs`; a user value wins), and a warning plus skip on a Cloudflare project, which runs no containers. The name is the platform's, not the project's: it was `relay` in 1.0.0-beta.9 and met a project's own stream relay, so a user app named `relay` now lives beside it. The cloud's git-linked builder does the same expansion (`spooky-cloud` `internal/linking/relay.go`): keep the two in step. Docs: `/docs/reference/config#relay`, `/docs/reference/relay`.
120
+
121
+ **Reserved app names.** Every public host of a project is `{slug}-{name}.<domain>`, the platform's own among them, so `backend.rs` keeps two kinds of name out of `apps:`. `RESERVED_APP_PREFIX` (`spky-`) is the namespace of the services sp00ky runs for a project (`spky-relay` so far): `refuse_reserved_app_names`, called by `parse_config_with_includes` before `expand_relay`, bails on any app under it, with `relay:` on or off. A new platform service takes a name there, never a plain word. `PLATFORM_HOSTS` (`db`, `admin`, `pool`: the database, the scheduler's admin plane, the pool listener) are refused by `validate_manifest` (`spky lint`, `spky deploy`) for an app that gets a public host (`AppConfig::public_on_deploy`: a deployed frontend, or `deploy.expose`); a private or `devOnly` app may use them. The control plane enforces the same in `pkg/models/appnames.go` (400 `reserved_app_name`).
122
+
68
123
  ## Docker dev apps (`type: docker`)
69
124
 
70
125
  Besides `backend`/`frontend` apps, `sp00ky.yml` can declare `type: docker` apps —
@@ -114,12 +169,84 @@ apps:
114
169
  - "gomod:/go"
115
170
  ```
116
171
 
172
+ ## Worker backends (`apps.<name>.worker`)
173
+
174
+ A `type: backend` app with a `worker:` block runs, on a Cloudflare project, as a Dynamic Worker
175
+ inside the project's SSP Worker instead of a Docker container. It is still a sp00ky backend: it
176
+ needs `spec` and an outbox `method` with a `table`, and jobs reach it at `worker://<name>` (the SSP
177
+ POSTs the payload as JSON, with `Authorization: Bearer <auth.token>` when `auth` is set). Only the
178
+ paths in `expose` are public, on `https://<slug>.<domain>`. Keys: `entry` (required),
179
+ `compatibilityDate` (default `2026-10-01`), `compatibilityFlags`, `textModules` (globs imported as
180
+ strings), `cpuMs` (1..300000), `ai` (env binding for Workers AI), `workflows: [{binding, class}]`
181
+ (Cloudflare Workflows; the class is exported from the entry), `expose` (trailing `*` = prefix).
182
+
183
+ A backend's own `workflows: [{binding, class}]` (not under `worker`) declares durable workflows on
184
+ sp00ky's engine (`@spooky-sync/backend`, every host). `AppConfig::validate_durable_workflows`
185
+ requires an outbox `method` with a `table` and identifier-shaped, unique bindings (also against
186
+ `worker.ai` / `worker.workflows`); it runs for `devOnly` backends too. `AppConfig::spky_app_vars`
187
+ injects `SPKY_OUTBOX_TABLE` into the backend's env in `spky dev`, VM deploys and Worker backends.
188
+ The `_00_wf_instance` / `_00_wf_step` / `_00_wf_event` tables ship in `src/schedule_tables.surql`.
189
+
190
+ - Validation (`WorkerDeployConfig::validate`, `AppConfig::validate_worker` in `src/backend.rs`):
191
+ `hosting: external` and `runOn` are refused; bindings must not repeat. `spky lint`
192
+ (`Sp00kyConfig::worker_lint`) errors on a missing `entry` and warns on `baseUrl` (unused on
193
+ Cloudflare, though `spky dev` uses it), on `expose` overlapping a spec path, and on a manifest
194
+ that can only target VMs.
195
+ - `spky deploy` on a Cloudflare project (`deploy_worker_backend_cloudflare` in `src/cloud.rs`)
196
+ bundles `entry` with a pinned `npx esbuild` (platform neutral; `node:*`, `cloudflare:*` and, under
197
+ `nodejs_compat`, bare Node builtins stay external), uploads it by sha256, and sends
198
+ `worker_backends` in the deploy body. On a VM project the block is ignored with a warning and the
199
+ Dockerfile path runs.
200
+ - The backend's env (the `SPKY_*` base plus its own `env`, vault resolved) reaches it as plain
201
+ strings. No other Cloudflare bindings. `spky dev` does not run it under workerd: it runs from its
202
+ `dev` command at its `baseUrl`, like any backend.
203
+ - Runtime side: `apps/ssp-cf/js/host.mjs`. User docs: `docs/backend/workers.mdx` on the site.
204
+
205
+ ## Sync transport (`sync.transport`)
206
+
207
+ `sync.transport: changefeed` changes what the schema pipeline emits, in three
208
+ places that must agree: `sp00ky::generate_sp00ky_events` keeps the
209
+ `_00_version` bookkeeping but drops the `http::post` (`post_ingest`),
210
+ `schema_builder::add_changefeed_clauses` puts `CHANGEFEED <retention> INCLUDE
211
+ ORIGINAL` on every synced `DEFINE TABLE` in the desired schema (after
212
+ `COMMENT`, before `PERMISSIONS`, the order SurrealDB renders, or `schema
213
+ diff` sees a phantom change forever), and `migrate::apply_internal_schema`
214
+ emits `ALTER TABLE IF EXISTS ... CHANGEFEED` for every synced user table after
215
+ the events (a user migration's `DEFINE TABLE OVERWRITE` without the clause
216
+ drops the feed; the ALTER puts it back on every deploy) plus `REMOVE EVENT
217
+ _00_dbsp_cleanup`. `backend::sync_settings_for(config_path)` is the single
218
+ reader of the setting. The scheduler/SSP get `SPKY_INGEST_TRANSPORT` through
219
+ `deployment.env` (cloud) or the dev launch specs. Retention must be in
220
+ SurrealDB's rendered form (`1d`, not `24h`): `valid_changefeed_retention`.
221
+
222
+ "Synced" means every user table that is not `@nosync`, **including `TYPE RELATION`
223
+ tables**: `schema_builder::table_takes_changefeed` is the one predicate, and it has
224
+ to agree with `Replica::discover_sync_tables`, which clones and drift-checks every
225
+ table that does not carry the `sp00ky:nosync` marker. Relations used to be left out
226
+ of the events and the feed while staying in the replica and the SSP bootstrap, so a
227
+ live query over an edge table never updated. An edge's `in`/`out` are implicit (not
228
+ in `table.fields`), so `sp00ky::relation_endpoints` adds them to the ingest payload.
229
+ The same marker is re-asserted next to the changefeed ALTER
230
+ (`schema_builder::nosync_alter_statements`), for the same reason.
231
+
232
+ Both halves are also applied at the moment a migration defines a table, not only by the
233
+ pass after it: `migrate::SyncIdentity::complete` rewrites each migration's `DEFINE TABLE`
234
+ with the clause and the marker as `LegacyEngine` applies it (`migrate::apply_completing`).
235
+ Without that, rows written between a migration and the internal-schema pass landed in a
236
+ table with no feed. The ephemeral schema-diff replay still uses the verbatim
237
+ `migrate::apply`, so a completed clause never reads as drift, and the recorded checksum
238
+ is always the committed file's.
239
+
117
240
  ## Common gotchas
118
241
 
119
242
  - **`schema.gen.ts` must be regenerated after every `.surql` change.** `spky generate`. CI typically asserts no drift.
120
243
  - **Migrations are checksum-tracked.** Editing a previously-applied migration file won't silently re-run; `spky migrate status` flags it. Use `--fix-checksums` only when you're sure the change is semantically a no-op.
121
244
  - **`sp00ky.yml` is the entry point.** The CLI never crawls for `.surql`; everything is wired explicitly through the config.
122
245
  - **Generation modes matter.** The `--mode` flag (`singlenode`, `cluster`, `surrealism`) changes what the generated client connects to. Default is `singlenode` (HTTP to a single SSP). `surrealism` embeds the WASM stream processor in-browser.
246
+ - **Schema downgrade guard.** `record_schema_hash` stores `cli_version` (`env!("CARGO_PKG_VERSION")`) on `_00_schema_state`, and `migrate::guard_schema_downgrade` reads it before anything is written (`Sp00kyEngine::apply` for `migrate apply`/`prod`, `apply_remote_fns_and_internal_schema` for deploy and restore, `dev.rs` for `spky dev`). A newer stored version (semver precedence, `parse_version`) refuses with both versions and the fix, unless `--allow-schema-downgrade` / `SPKY_ALLOW_SCHEMA_DOWNGRADE`; on a local URL or under `spky dev` it only warns; missing or unparsable versions allow. An older CLI's own push leaves the newer `cli_version` in place (its UPSERT sets hash and updated_at only). Why: on 2026-11-17 a canary.385 `spky` from PATH re-pushed pre-keyed ledger events to WhitePawn on 4.0.1 and pinned its DB at 300% CPU.
247
+ - **Internal indexes are only (re)defined when they changed, and then `CONCURRENTLY`.** `migrate::prune_unchanged_index_defines` drops a `DEFINE INDEX` whose live definition matches (an `OVERWRITE` rebuilds from scratch), and on server modes appends `CONCURRENTLY` to the rest: SurrealDB 4.0.1 makes a blocking build wait up to 60 s for every older write transaction (`WRITE_BARRIER_WAIT`), which held `spky migrate apply` past its 120 s HTTP timeout on a busy database. The apply then polls `INFO FOR INDEX` (`wait_for_index_builds`) and records the schema hash only once every build is `ready`: a failed build (UNIQUE over duplicates) fails the apply, one still running at `SPKY_INDEX_BUILD_TIMEOUT_SECS` (600) warns and leaves the hash unrecorded, and the prune treats an index whose build is in `error` as changed.
248
+ - **Generated event and function bodies must pass `query_lint`.** `cargo test -p sp00ky-cli sp00kys_own_schema_passes` lints everything sp00ky deploys. Inside a body, bind event values with `LET` first, write through `UPDATE / DELETE (SELECT VALUE id FROM t WHERE ...)`, never `INSIDE $list`, give every body lookup a single-column index (4.0.1 uses no composite index for a parameter in a body), keep a function's lookups and writes in helpers that call no other `fn::` (`fn::feature::put` and friends), and write select rules as `FULL`, not `WHERE true` (4.0.1 drops indexes for record users otherwise). A legacy-ledger lookup uses the correlated form `sp00ky::LEDGER_LOOKUP_ROWS`, the only shape 4.0.1 plans as an index read when a record user's write fires the event. Cost tests: `cargo test -p sp00ky-cli body_scan`.
249
+ - **Ledger accesses in generated events are key accesses.** `_00_version` rows are keyed by their record (`type::record('_00_version', [$after.id])`, see `docs/version-ledger.md`). Never add a `WHERE record_id = $after.id` (or any `UPDATE`/`DELETE ... WHERE` on a parameter) to an event body: SurrealDB 4.0.1 scans the table for it inside an event. `cargo test -p sp00ky-cli version_ledger` (plus `-- --include-ignored --test-threads=1` for the Docker 3.3.5/4.0.1 runs) fails if a write's cost grows with the ledger.
123
250
  - **Don't commit the bin output.** The Rust binary is built per-platform and shipped via the npm tarball under `dist/`.
124
251
 
125
252
  ## Pointers