@dashai/cli 0.2.5 → 0.3.0

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/README.md CHANGED
@@ -87,17 +87,21 @@ One-command local dev loop — collapses the historical two-terminal flow into a
87
87
 
88
88
  Both children inherit a pre-populated env with `DASHWISE_API_URL`, `DASHWISE_API_TOKEN`, and `DASHWISE_INSTALLATION_ID` automatically resolved from your saved CLI config (`~/.config/dashwise/auth.json`). No more copying tokens into `.env.local` by hand.
89
89
 
90
+ **HH-CC-LDI-7:** when the current module has been provisioned via `dashwise init` (LDI-6), the per-module runtime token cached at `~/.config/dashwise/auth.json#modules[<slug>]` is automatically injected as `DASHWISE_RUNTIME_TOKEN` into both children. `DASHWISE_INSTALLATION_ID` flips to the literal `sandbox` (the URL placeholder the backend's runtime-token guard accepts) so the SDK can hit the data plane without you passing `--installation-id`. The pre-flight banner prints which auth source is in use.
91
+
92
+ If the manifest's slug isn't in `auth.json#modules`, `dashwise dev` still starts (SSO + watcher work fine), but it prints a one-line warning that data-plane calls (db, qb) will 401 — pointing you to re-run `dashwise init <slug> --force` to provision.
93
+
90
94
  Output from both children is line-prefixed (`[sdk]` cyan, `[next]` magenta) so a single terminal stays readable. Ctrl-C cleanly terminates both.
91
95
 
92
96
  Flags:
93
97
  - `--dir <path>` — Project root (default: current directory).
94
- - `--installation-id <id>` — Override `DASHWISE_INSTALLATION_ID` (default `"local"`).
98
+ - `--installation-id <id>` — Override `DASHWISE_INSTALLATION_ID` (default `"sandbox"` if a runtime token is found, else `"local"`). Useful for prod-mode SSO testing against a real installed module.
95
99
  - `--api-url <url>` — Override `DASHWISE_API_URL` (default: saved config value).
96
100
  - `--port <number>` — Port for `next dev` (default: Next picks 3000 / next free).
97
101
  - `--sdk-only` — Run only the manifest watcher; skip `next dev`.
98
102
  - `--next-only` — Run only `next dev`; skip the watcher.
99
103
 
100
- Requires `dashwise login` first — the command refuses to start if no token is resolvable.
104
+ Requires `dashwise login` first — the command refuses to start if no token is resolvable. The runtime-token injection requires `dashwise init <slug>` (LDI-6); the dev session SSO setup works without it.
101
105
 
102
106
  ### `dashwise module init [slug]`
103
107
 
@@ -113,6 +117,11 @@ Flags:
113
117
  - `--force` — Overwrite an existing non-empty directory.
114
118
  - `--custom` — Use the full Next.js custom-module scaffold.
115
119
  - `--git <url>` — Initial Git repository URL. Written to `module.json#repository.url`.
120
+ - `--description <text>` — Module description forwarded to the backend when provisioning the dev installation (HH-CC-LDI-6). No effect under `--no-provision`.
121
+ - `--workspace <slug-or-id>` — Target workspace for the dev installation (HH-CC-LDI-6). When omitted in a TTY, the CLI prompts; auto-picked if your account has one workspace; in non-interactive mode with multiple workspaces, errors with the list.
122
+ - `--no-provision` — Skip the `POST /api/installations/dev` step (HH-CC-LDI-6). Local scaffold is still written, but the module won't have a backing dev installation — `dashwise dev` data-plane calls will fail with `UnauthenticatedError` until you re-run `dashwise init --force` or (once it ships) `dashwise module provision-dev-install`.
123
+
124
+ **Provisioning behavior (HH-CC-LDI-6):** by default, after the local scaffold is written, `dashwise init` provisions a real local-dev installation by calling `POST /api/installations/dev`. The returned runtime token (90-day JWT) is cached in `~/.config/dashwise/auth.json#modules[<slug>]` where `@dashai/sdk`'s `createDevClient({ moduleSlug })` reads it on every dev-server boot. Provisioning failures are surfaced as warnings; the local scaffold remains usable so you can retry later.
116
125
 
117
126
  ### `dashwise module connect-git <repo-url>`
118
127
 
@@ -176,6 +185,51 @@ Flags:
176
185
  - `--dir <path>` — Project root (default: current directory).
177
186
  - `--json` — Emit the structured diff as JSON `{ ok, current_version, unchanged, meta_changes, tables_added, tables_removed, tables_changed, deps_added, deps_removed }` instead of the human-readable summary. Useful for CI gates ("fail PR if any field-removal lands without a major bump").
178
187
 
188
+ ### `dashwise module destroy-dev-install` (HH-CC-LDI-9)
189
+
190
+ Tear down the local-dev installation for the current module. Calls `DELETE /api/installations/dev/:installationId` and then removes the `auth.json#modules[slug]` entry. If the module had no other installs AND was never published, the backend also drops the module + its versions — tidies up dev-only modules that never shipped.
191
+
192
+ ```bash
193
+ dashwise module destroy-dev-install
194
+ ```
195
+
196
+ Local `module.json` is preserved — only the cached runtime token + install id get cleared. Re-run `dashwise init <slug> --force` to provision a fresh install.
197
+
198
+ Flags:
199
+ - `--dir <path>` — Project root (default: current directory).
200
+ - `--module <slug>` — Override the module slug (default: read from local `module.json`). Useful when the project directory is gone but `auth.json` still has the entry.
201
+ - `-y, --yes` — Skip the confirmation prompt — for CI.
202
+
203
+ Errors map to user-friendly messages: `INSTALLATION_NOT_FOUND` (already destroyed elsewhere — local cache is cleaned up anyway), `INSTALLATION_KIND_NOT_LOCAL` (refuses non-local installs — use the dashboard's uninstall flow), `NOT_WORKSPACE_MEMBER`.
204
+
205
+ ### `dashwise module reset-dev-install` (HH-CC-LDI-9)
206
+
207
+ Destroy + re-provision the local-dev install in a single command. Useful for:
208
+
209
+ - Nuking accumulated test data
210
+ - Refreshing a compromised runtime token
211
+ - Recovering from a wedged schema state
212
+
213
+ ```bash
214
+ dashwise module reset-dev-install
215
+ ```
216
+
217
+ Local `module.json` (scaffold + manifest) stays intact — only the backend install + cached token get recycled. The freshly-provisioned install starts with the current `module.json`'s schema.
218
+
219
+ Flags:
220
+ - `--dir <path>` — Project root.
221
+ - `--module <slug>` — Override slug (default: from local `module.json`).
222
+ - `--workspace <slug-or-id>` — Target workspace for re-provisioning (passed through to `dashwise init`).
223
+ - `-y, --yes` — Skip prompts in both destroy + re-init phases.
224
+
225
+ If the destroy phase fails, the reset aborts (no point trying to provision over a still-existing install — the backend would 409 `SLUG_ALREADY_EXISTS`).
226
+
227
+ ### Idle GC (server-side, HH-CC-LDI-9)
228
+
229
+ The backend runs a sweeper every 6h (configurable via `LOCAL_DEV_INSTALL_GC_INTERVAL_MIN`) that destroys local-dev installs idle for more than 30 days (configurable via `LOCAL_DEV_INSTALL_IDLE_DAYS`). "Idle" means no schema mutations in that window — pure data-plane queries don't refresh the timer in v1 (see `local-dev-installs-v1.md` §5 LDI-9 notes for the v1.1 follow-up).
230
+
231
+ Disable with `LOCAL_DEV_INSTALL_GC_DISABLED=true` on the backend. CI fixtures, compliance freezes, etc.
232
+
179
233
  ### `dashwise module pull-data`
180
234
 
181
235
  Export the module's own-table rows from the owner-workspace installation to a local JSON file. Rows are keyed by manifest field slug (NOT `field_<id>` internals), so the output is reusable as test fixtures or local-dev seeds.
@@ -289,6 +343,96 @@ Flags:
289
343
  - `--tail` — Poll every 5s for new entries. Stops on Ctrl-C.
290
344
  - `--json` — Compact JSON output (ignored with `--tail`).
291
345
 
346
+ ### `dashwise table` / `dashwise field` (HH-CC-LDI-8)
347
+
348
+ Schema-mutation commands for the current module — add or drop tables, add/remove/retype fields in the dev installation. Each command:
349
+
350
+ 1. Calls the LDI-4 REST endpoint at `/api/installations/:id/schema/...` using the runtime token cached by `dashwise init` (LDI-6).
351
+ 2. Asks the backend to apply the change (manifest + physical Postgres tables update atomically server-side).
352
+ 3. Calls `GET /api/installations/:id/schema` to fetch the new manifest.
353
+ 4. Writes the response to local `module.json`.
354
+
355
+ If step 2 fails, no local changes are made (REST-first / write-back-from-GET model). If step 3 fails after step 2 succeeds, local `module.json` is left stale — `dashwise dev` reconciles automatically on next startup.
356
+
357
+ **Prerequisite**: run `dashwise init <slug>` once. Without a cached per-module dev install, these commands fail with a clear "run init first" error.
358
+
359
+ #### `dashwise table create <slug> --field <spec> [...]`
360
+
361
+ Create a new table.
362
+
363
+ ```bash
364
+ dashwise table create tasks \
365
+ --field title:text:required \
366
+ --field done:boolean \
367
+ --field due_at:datetime
368
+ ```
369
+
370
+ Field spec: `<slug>:<type>[:flags]` where `flags` is comma-separated (`required`, `unique`). Allowed types: `text`, `long_text`, `number`, `boolean`, `date`, `datetime`, `email`, `url`, `phone`, `single_select`, `multi_select`, `link_row`, `file`, `multi_file`, `formula`, `ai`.
371
+
372
+ For types that need extra config (`single_select` + `options`, `link_row` + `target`, etc.), use `--field-json '{...}'`:
373
+
374
+ ```bash
375
+ dashwise table create tasks \
376
+ --field title:text:required \
377
+ --field-json '{"slug":"priority","type":"single_select","options":["low","medium","high"]}'
378
+ ```
379
+
380
+ Flags:
381
+ - `--dir <path>` — Project root.
382
+ - `-f, --field <spec>` — Repeatable.
383
+ - `--field-json <json>` — Repeatable.
384
+
385
+ Errors: 409 `TABLE_SLUG_EXISTS`, 400 for malformed inputs, plus generic auth errors with hints to re-run `dashwise init`.
386
+
387
+ #### `dashwise table delete <slug>`
388
+
389
+ Drop a table. The backend soft-deletes the physical Postgres table — recoverable for 30 days via the dashboard's trash. Updates local `module.json`.
390
+
391
+ ```bash
392
+ dashwise table delete tasks
393
+ ```
394
+
395
+ Flags: `--dir <path>`.
396
+ Errors: 404 `TABLE_NOT_FOUND`.
397
+
398
+ #### `dashwise field add <table-slug> <field-spec>`
399
+
400
+ Add a field to an existing table. Same `<slug>:<type>[:flags]` syntax as `table create --field`.
401
+
402
+ ```bash
403
+ dashwise field add tasks done:boolean
404
+ dashwise field add tasks priority --field-json '{"slug":"priority","type":"single_select","options":["low","medium"]}'
405
+ ```
406
+
407
+ Flags: `--dir <path>`, `--field-json <json>` (mutually exclusive with positional spec).
408
+ Errors: 404 `TABLE_NOT_FOUND`, 409 `FIELD_SLUG_EXISTS`.
409
+
410
+ #### `dashwise field remove <table-slug> <field-slug>`
411
+
412
+ Remove a field. The backend includes M2-C-FIX cascading-index-cleanup: indexes referencing the removed field are trimmed; empty indexes are dropped entirely.
413
+
414
+ ```bash
415
+ dashwise field remove tasks priority
416
+ ```
417
+
418
+ Flags: `--dir <path>`.
419
+ Errors: 404 `TABLE_NOT_FOUND` / `FIELD_NOT_FOUND`.
420
+
421
+ #### `dashwise field set-type <table-slug> <field-slug> <new-type>`
422
+
423
+ Change a field's type.
424
+
425
+ ```bash
426
+ dashwise field set-type tasks title long_text
427
+ ```
428
+
429
+ Lossy changes (e.g. `text → number` with non-numeric data) are rejected by the backend's manifest validator today. v1.1 will add a structured `RETYPE_UNSAFE` precheck.
430
+
431
+ Flags: `--dir <path>`.
432
+ Errors: 404 `TABLE_NOT_FOUND` / `FIELD_NOT_FOUND`.
433
+
434
+ **Not in v1**: `dashwise field rename` — per `local-dev-installs-v1.md` §7, slug renames need proper schema-migration support and land in v1.1.
435
+
292
436
  ### `dashwise deps`
293
437
 
294
438
  Manage cross-module dependencies declared in `module.json#dependencies`.