@spooky-sync/cli 0.0.1-canary.23 → 0.0.1-canary.231

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 ADDED
@@ -0,0 +1,155 @@
1
+ # `@spooky-sync/cli` (`spky`) — agent guide
2
+
3
+ ## What this package is
4
+
5
+ The sp00ky toolchain. A Rust binary (`spky`) plus a thin npm wrapper. It parses `.surql` schemas, emits typed `schema.gen.ts` (and `.dart`), runs migrations, manages buckets and API backends, drives the local dev environment, and orchestrates Sp00ky Cloud deployments.
6
+
7
+ ## Binary
8
+
9
+ ```
10
+ spky <subcommand> [flags]
11
+ ```
12
+
13
+ Installed via `npx @spooky-sync/cli` or globally as `spky`. The `bin` field in `package.json` is `spky` — *not* `sp00ky`.
14
+
15
+ ## Project layout it expects
16
+
17
+ ```
18
+ your-app/
19
+ ├── sp00ky.yml # config: schema path, generated outputs, backends, buckets
20
+ ├── schema/
21
+ │ └── schema.surql # source of truth — your domain model
22
+ ├── src/
23
+ │ └── schema.gen.ts # GENERATED — never hand-edit
24
+ └── migrations/ # GENERATED migrations; modified files are tracked by checksum
25
+ ```
26
+
27
+ `spky` finds `sp00ky.yml` in the current directory by default; pass `--config <path>` to override.
28
+
29
+ ## Subcommands an app developer/agent uses most
30
+
31
+ - **`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
+ - **`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.
34
+ - **`spky migrate status`** — show pending vs applied vs modified-but-applied migrations.
35
+ - **`spky migrate fix [--fix-checksums]`** — repair schema drift / checksum mismatches.
36
+ - **`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 and auto-reclones by default (`SPKY_DRIFT_AUTO_RECLONE`).
37
+ - **`spky lint`** — validate `sp00ky.yml` and referenced files exist.
38
+ - **`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`.
39
+ - **`spky init`** — scaffold a new sp00ky project in the current directory. (`spky create` is a removed alias that only prints a migration hint.)
40
+ - **`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). 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`.
42
+ - **`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`.
43
+
44
+ ## Deployment subcommands
45
+
46
+ These are top level, not under a `cloud` prefix. `spky cloud ...` was removed and now only
47
+ prints a migration hint.
48
+
49
+ `spky login | logout | deploy | release | status | stats | logs | restart | push | scale | backup | env | domain | link | team | billing | token | project | notice`.
50
+ See `spky <command> --help`. Most app code agents touch never need these.
51
+
52
+ Two that come up when a deployment misbehaves:
53
+
54
+ - **`spky restart [TARGET...] [--upgrade] [--clean] [--surreal] [--all-backends] [-y]`** —
55
+ recreate containers. Targets are roles (`db`, `scheduler`, `ssp`, `frontend`) or an app
56
+ name; with none it restarts the scheduler and SSPs. `--upgrade` pulls the latest scheduler
57
+ and SSP images, `--clean` wipes the scheduler's volume (replica and WAL, not SurrealDB
58
+ data). `-y` is required in CI because the SurrealDB prompt cannot be answered
59
+ non-interactively.
60
+ - **`spky migrate prod`** — apply pending migrations plus the internal Sp00ky schema to the
61
+ deployment, without a full deploy. Set `SPKY_DB_HTTP_TIMEOUT_SECS` if the internal schema
62
+ step times out.
63
+
64
+ ## Schema annotations the parser recognizes
65
+
66
+ In your `.surql` source, comment annotations attached to `DEFINE FIELD` / `DEFINE TABLE` change codegen output:
67
+
68
+ - `-- @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.
69
+ - `-- @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.
70
+ - `-- @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.
71
+ - `-- @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.
72
+ - `-- @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.
73
+
74
+ All three field-level exclusions (`@nosync`, `@crdt`, `@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.
75
+
76
+ Example:
77
+ ```sql
78
+ DEFINE TABLE thread SCHEMAFULL ...;
79
+
80
+ -- @crdt text
81
+ DEFINE FIELD content ON TABLE thread TYPE string ASSERT $value != NONE;
82
+
83
+ DEFINE FIELD author ON TABLE thread TYPE record<user>; -- @parent
84
+
85
+ -- @opaque
86
+ DEFINE FIELD preview_png ON TABLE thread TYPE option<bytes>;
87
+
88
+ -- @nosync
89
+ DEFINE TABLE audit_log SCHEMALESS;
90
+ ```
91
+
92
+ 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`).
93
+
94
+ ## Docker dev apps (`type: docker`)
95
+
96
+ Besides `backend`/`frontend` apps, `sp00ky.yml` can declare `type: docker` apps —
97
+ containers `spky dev` runs alongside SurrealDB/SSP/scheduler on the
98
+ `sp00ky-dev-net` network (each reachable from the others by its app **name**, via
99
+ a `--network-alias`). Use `scope: devOnly` for local-only sidecars: never
100
+ deployed, and they skip the backend spec/method/deploy validation.
101
+
102
+ Fields:
103
+
104
+ - `image` (required) — image to run, e.g. `bluenviron/mediamtx:latest` or `golang:1.22`.
105
+ - `ports` — published to the host: `[1935, "8189/udp", "3000:8080"]` (a bare value maps the same port host:container; `/udp` suffix preserved).
106
+ - `args` — appended after the image (the container command), e.g. `["go", "run", "."]`.
107
+ - `env` — same forms as other apps (inline map / dotenv path / vault). User values **override** the auto-injected `SPKY_*` vars. `${PROJECT_DIR}` (the absolute dir of `sp00ky.yml`) is expanded in values.
108
+ - `volumes` — bind/volume mounts (`-v`), e.g. `["/var/run/docker.sock:/var/run/docker.sock", "${PROJECT_DIR}/../..:/src", "gomod:/go"]`. `${PROJECT_DIR}` is expanded in the host portion (Docker normalizes `..`).
109
+ - `workdir` — working directory inside the container (`-w`).
110
+ - `dependsOn` — names of other docker apps that must be **ready** before this one starts; `spky dev` starts apps in dependency order. Validated at config load — an unknown name, a self-dependency, or a **cycle** is a hard error (`spky lint` reports it).
111
+ - `healthcheck` — an HTTP path (e.g. `/health`) polled on the app's first published host port until it returns 200. Lets a dependency signal real readiness so `dependsOn` waits for "up", not just "container started". Without it, a dependency counts as ready once its container is running.
112
+
113
+ Containers run as `sp00ky-dev-<name>` with `--rm` and are killed on Ctrl-C.
114
+ `dependsOn`/`healthcheck` are `spky dev` concerns; the cloud deploy path ignores
115
+ them (and `cloudOnly` docker apps are skipped by `spky dev`).
116
+
117
+ Example — a relay built from source via `go run`, and a publisher that waits for it:
118
+ ```yaml
119
+ apps:
120
+ relay:
121
+ type: docker
122
+ scope: devOnly
123
+ image: golang:1.22
124
+ workdir: /src/apps/relay
125
+ args: ["go", "run", "."]
126
+ ports: [3670]
127
+ healthcheck: /health
128
+ volumes:
129
+ - "${PROJECT_DIR}/../..:/src"
130
+ - "gomod:/go"
131
+ publisher:
132
+ type: docker
133
+ scope: devOnly
134
+ image: golang:1.22
135
+ workdir: /src/apps/publisher
136
+ args: ["go", "run", "."]
137
+ dependsOn: [relay] # started only after relay's /health returns 200
138
+ volumes:
139
+ - "${PROJECT_DIR}/../..:/src"
140
+ - "gomod:/go"
141
+ ```
142
+
143
+ ## Common gotchas
144
+
145
+ - **`schema.gen.ts` must be regenerated after every `.surql` change.** `spky generate`. CI typically asserts no drift.
146
+ - **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.
147
+ - **`sp00ky.yml` is the entry point.** The CLI never crawls for `.surql`; everything is wired explicitly through the config.
148
+ - **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.
149
+ - **Don't commit the bin output.** The Rust binary is built per-platform and shipped via the npm tarball under `dist/`.
150
+
151
+ ## Pointers
152
+
153
+ - Sync engine the generated client targets: `node_modules/@spooky-sync/core/AGENTS.md`
154
+ - Reactive UI bindings: `node_modules/@spooky-sync/client-solid/AGENTS.md`
155
+ - Live MCP introspection during dev: `node_modules/@spooky-sync/devtools-mcp/AGENTS.md`
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Spooky CLI
1
+ # Sp00ky CLI
2
2
 
3
3
  Generate TypeScript and Dart types from SurrealDB schema files.
4
4
 
@@ -18,28 +18,28 @@ This package wraps a Rust-based code generator that parses SurrealDB `.surql` sc
18
18
 
19
19
  ```bash
20
20
  # Generate TypeScript types
21
- spooky --input schema.surql --output types.ts
21
+ spky --input schema.surql --output types.ts
22
22
 
23
23
  # Generate Dart types
24
- spooky --input schema.surql --output types.dart
24
+ spky --input schema.surql --output types.dart
25
25
 
26
26
  # Generate JSON Schema
27
- spooky --input schema.surql --output schema.json
27
+ spky --input schema.surql --output schema.json
28
28
 
29
29
  # Generate all formats at once
30
- spooky --input schema.surql --output output --all
30
+ spky --input schema.surql --output output --all
31
31
 
32
32
  # Specify format explicitly
33
- spooky --input schema.surql --output output.ts --format typescript
33
+ spky --input schema.surql --output output.ts --format typescript
34
34
  ```
35
35
 
36
36
  ### Programmatic API
37
37
 
38
38
  ```typescript
39
- import { runSpooky } from 'spooky-cli';
39
+ import { runSp00ky } from 'sp00ky-cli';
40
40
 
41
41
  // Generate types
42
- const output = await runSpooky({
42
+ const output = await runSp00ky({
43
43
  input: 'path/to/schema.surql',
44
44
  output: 'path/to/output.ts',
45
45
  format: 'typescript', // or 'dart', 'json'
@@ -95,7 +95,7 @@ cli/
95
95
 
96
96
  ## How It Works
97
97
 
98
- 1. The Rust binary (`spooky`) parses SurrealDB schema files and generates JSON Schema
98
+ 1. The Rust binary (`spky`) parses SurrealDB schema files and generates JSON Schema
99
99
  2. For TypeScript/Dart output, it uses `quicktype` to convert JSON Schema to the target language
100
100
  3. The TypeScript wrapper (`src/index.ts`) spawns the Rust binary as a child process
101
101
  4. Vite bundles the TypeScript wrapper for distribution