@modeldesk/cli 0.5.0 → 0.7.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
@@ -1,9 +1,13 @@
1
1
  # ModelDesk CLI
2
2
 
3
- The [ModelDesk](https://modeldesk.io) command-line interface pulls a model's generated documentation
4
- **content bundle** into your repository, so your own documentation pipeline (for example ReSpec with
5
- GitHub Actions) can render and publish it. ModelDesk generates the content and hands it off; it does
6
- not render, host, or publish documents.
3
+ The [ModelDesk](https://modeldesk.io) command-line interface reads, edits, branches, merges and
4
+ releases ModelDesk models from a terminal, from CI, and from an AI agent with a shell. Every edit is
5
+ staged in your draft, which you or the person you work for review and commit, in the CLI or in the
6
+ app.
7
+
8
+ It also pulls a model's generated documentation **content bundle** into your repository, so your own
9
+ documentation pipeline (for example ReSpec with GitHub Actions) can render and publish it. ModelDesk
10
+ generates the content and hands it off; it does not render, host, or publish documents.
7
11
 
8
12
  ## Install
9
13
 
@@ -25,15 +29,81 @@ signed scripts for your own account with `Set-ExecutionPolicy -Scope CurrentUser
25
29
  ## Commands
26
30
 
27
31
  ```
28
- modeldesk bundle pull Materialize a model's content bundle into the repository
29
- modeldesk bundle templates List a model's document templates (its stack/template pairs)
30
- modeldesk auth login Log in through the browser (OAuth authorization code + PKCE)
31
- modeldesk auth logout Remove the stored credential for the active host
32
- modeldesk auth status Show the active host, identity, and token validity
32
+ modeldesk auth login|logout|status
33
+ modeldesk bundle pull|templates
34
+ modeldesk note add <name>
35
+ modeldesk template lint <dir>
36
+
37
+ modeldesk model list [--metamodel <id>] [--owner <organization|me>] [--kind model|metamodel|all]
38
+ modeldesk model show <model[@ref]> identity at the ref; overview and releases are main's
39
+ modeldesk model tree <model[@ref]> [--depth <n>] [--type <type>] [--internal]
40
+ modeldesk model log <model[@ref]> [--include-system] [--changes]
41
+ modeldesk model create --name <name> --metamodel <metamodel[@release]>
42
+ [--extension <extension[@release]>]... [--owner <organization|me>]
43
+ [--kind model|metamodel] [--standard-version <version>]
44
+ modeldesk model delete <model>
45
+ modeldesk model import [<file>] | --url <uri> --metamodel <metamodel[@release]> [--name <name>]
46
+ [--owner <organization>] [--extension <extension[@release]>]... [--loader <name>]
47
+ [--review] [--timeout <seconds>]
48
+ modeldesk model imports list [--owner <organization>] | show <import-id>
49
+ | complete <import-id> --name <name> | delete <import-id>
50
+ modeldesk model export <model> --format <name|id> [--mapping <id>] [-o <path>] [--compressed] [--lenient]
51
+ modeldesk model pull <model[@ref]> [<dir>] [--force] [--format yaml|json]
52
+ modeldesk model diff [<dir>] [--exit-code]
53
+ modeldesk model push [<dir>] -m <message> [--plan <hash>] [--allow-delete] [--request-id <id>]
54
+ [--commit [--with-staged]]
55
+
56
+ modeldesk metamodel list
57
+ modeldesk metamodel extensions <metamodel>
58
+
59
+ modeldesk el show <model[@ref]> <element> [--internal]
60
+ modeldesk el create <model[@ref]> <parent> [<attr=value>...] --type <type> [--relation <r>]
61
+ [--json-value <attr=json>]... [--lang <tag>] [--relate <rel=target>]... [--from <file>]
62
+ modeldesk el set <model[@ref]> <element> [<attr=value>...] [--json-value <attr=json>]... [--lang <tag>]
63
+ modeldesk el unset <model[@ref]> <element> <name>...
64
+ modeldesk el rm <model[@ref]> <element> [--recursive]
65
+ modeldesk el mv <model[@ref]> <element> <new-parent> [--relation <r>] [--position <n>] [--from-owner <el>]
66
+ modeldesk el relate <model[@ref]> <element> <relation> <target> [--unowned] [--group <g>] [--target-model <m>]
67
+ modeldesk el unrelate <model[@ref]> <element> <relation> <target>
68
+ modeldesk el bulk <model[@ref]> --where <criterion>... [--set <attr=value>]... [--json-value <attr=json>]...
69
+ [--unset <attr>]... [--lang <tag>]
70
+ every el write takes -m <message> [--request-id <id>] [--commit [--with-staged]]
71
+
72
+ modeldesk search <model[@ref]> <text> [--type <type>] [--internal]
73
+ modeldesk describe <model> [<type>] [--internal]
74
+ modeldesk validate <model[@ref]> [--fail-on error|warning] [--limit <n>]
75
+
76
+ modeldesk draft open <model@branch>
77
+ modeldesk draft status <resource[@branch]>
78
+ modeldesk draft diff <resource[@branch]> [--changes]
79
+ modeldesk draft undo <resource[@branch]> [--any-surface]
80
+ modeldesk draft commit <resource[@branch]> [-m <message>] [--expect <draft-head>] [--any-surface]
81
+ modeldesk draft discard <resource[@branch]> [--any-surface]
82
+ modeldesk draft rebase <resource[@branch]> [--drop <change-id>]...
83
+
84
+ modeldesk branch list <model>
85
+ modeldesk branch create <model[@from]> <name> [--open] [--exist-ok]
86
+ modeldesk branch delete <model@branch> [--force]
87
+ modeldesk branch diff <model[@branch]> [--base <branch>]
88
+ modeldesk branch merge <model@target> <source> [-m <message>] [--resolve <file|->]
89
+ [--take <element>[#<field>]=target|source]... [--take-others target|source]
90
+ [--expect <target-head>] [--expect-source <source-head>]
91
+
92
+ modeldesk release create <model[@commit]> [--name <name>] [--description <text>]
93
+ modeldesk release list <model>
94
+ modeldesk release cascade <base> [--timeout <seconds>] [--instance-limit <n>] [--verify-all]
95
+ modeldesk pin list <model>
96
+ modeldesk pin set <model> <dependency@release|main>
33
97
  ```
34
98
 
35
- Global options: `--help` (`-h`), `--version` (`-v`). Every command takes named flags only; there are
36
- no positional arguments.
99
+ A listing also takes `--limit <n>`, `--cursor <cursor>` and `--all`. `<model[@ref]>` is a model's
100
+ [address](#address-a-model). `modeldesk <command> --help` describes every command with its flags and
101
+ examples.
102
+
103
+ Global options, accepted by every command: `--json` and `--no-json` (see
104
+ [Scripting and agents](#scripting-and-agents)), `--host <host>`, `--yes` (answer confirmations),
105
+ `--dry-run` (only on commands that write; elsewhere it is refused rather than ignored), `--help`
106
+ (`-h`) and `--version` (`-v`). Every command prints its full flag list with `--help`.
37
107
 
38
108
  ## Log in
39
109
 
@@ -61,7 +131,7 @@ so a PR-editable file can never decide where a credential is sent: against `mode
61
131
  `host` out of the committed config in a repository that pulls from CI. Model, stack, template, and
62
132
  version still come from the committed config.
63
133
 
64
- **GitHub Actions (federated — no stored secrets).** Add a trust rule to the service account, grant
134
+ **GitHub Actions (federated, no stored secrets).** Add a trust rule to the service account, grant
65
135
  the workflow `id-token: write`, and run the CLI; it exchanges the workflow's own OIDC token itself:
66
136
 
67
137
  ```yaml
@@ -79,14 +149,16 @@ steps:
79
149
  CLI mints short-lived tokens itself; nothing is written to disk.
80
150
 
81
151
  Selection is deterministic (secret vars > GitHub federation > interactive) and a machine run never
82
- falls back to browser login — a CI runner without machine credentials fails immediately with
152
+ falls back to browser login: a CI runner without machine credentials fails immediately with
83
153
  guidance. `modeldesk auth status` verifies the credential with a real mint (exit non-zero on
84
154
  rejection); use it sparingly, since each probe counts as credential use. Never set `NODE_DEBUG=http`
85
155
  or `DEBUG=*` in CI: Node's HTTP diagnostics print the `Authorization` header.
86
156
 
87
157
  ## Configuration
88
158
 
89
- The model, stack, template, host, and version each resolve by precedence: a command-line flag, then
159
+ These settings serve `bundle pull`, `bundle templates` and `note add`; every other command takes the
160
+ model as an [address](#address-a-model). The model, stack, template, host, and version each resolve
161
+ by precedence: a command-line flag, then
90
162
  a `MODELDESK_*` environment variable, then a committed `.modeldesk/config.json`, then (for the host
91
163
  only) a built-in default. A configured repository therefore runs `modeldesk bundle pull` with no
92
164
  arguments, while CI can override any value per build with an environment variable.
@@ -115,16 +187,27 @@ searched, and a pull writes its content and manifest under the directory you run
115
187
  | Version | `--version` | `MODELDESK_VERSION` | `version` | live HEAD |
116
188
 
117
189
  - **`model`** is the model's UUID (copy it from the model's "Command-line access" panel in the app).
118
- - **`host`** is your instance's domain — `modeldesk.io` resolves to `https://api.modeldesk.io` and
190
+ - **`host`** is your instance's domain; `modeldesk.io` resolves to `https://api.modeldesk.io` and
119
191
  `https://auth.modeldesk.io`. Use `localhost` against a local development stack.
120
192
  - **`stack`** and **`template`** together identify the document shape to pull. A template slug is
121
- unique only within its stack, so both are required — pass `--stack`/`--template`, set the env
193
+ unique only within its stack, so both are required. Pass `--stack`/`--template`, set the env
122
194
  vars, or commit them. Run `modeldesk bundle templates` to list the valid `stack` / `template`
123
195
  pairs for a model.
124
196
  - Machine credentials (`MODELDESK_CLIENT_ID`, `MODELDESK_CLIENT_SECRET`) are read from the
125
197
  environment only and are never placed in the committed config. In a machine run the host must
126
198
  also come from `--host` or `MODELDESK_HOST` (see [Authenticate in CI](#authenticate-in-ci)).
127
199
 
200
+ Two more keys serve [notes](#note-add). They are read from the config file only, and each folder is a path
201
+ relative to the repository root:
202
+
203
+ - **`notesDir`** (default `md-notes/` at the repository root): the notes folder. A pull places every Markdown
204
+ file in it as a note, by its path, and `note add` creates note files in it; `--dir` overrides it for one
205
+ note. It cannot be the repository root, lie in the content root or hold it, or be a symlink.
206
+ - **`publishDirs`** (no default): the folders your document's publish step copies, such as
207
+ `["data", "media", "js", "css"]` for Geonovum's NL-ReSpec-template. A ReSpec snapshot inlines the note
208
+ Markdown, but an image a note links must sit in a copied folder; with `publishDirs` set, a pull warns
209
+ about every image outside them.
210
+
128
211
  ## `bundle pull`
129
212
 
130
213
  A pull is a **full sync** of the content root (for ReSpec, `data/model/`). It writes every
@@ -138,6 +221,11 @@ modeldesk bundle pull # in a configured repository (model, stack
138
221
  modeldesk bundle pull --model <modelId> --stack respec --template conceptueel-toc --host modeldesk.io
139
222
  ```
140
223
 
224
+ A pull also writes `index.json` beside the model's `index.md` (`data/model/index.json`): every element
225
+ the document shows, with its anchor, the file that holds it, its kind and the elements it refers to, and
226
+ every diagram with the elements it draws, read from the diagram's SVG. Commit it with the fragments. A pull
227
+ with `--no-diagrams` writes it without what each diagram draws.
228
+
141
229
  > **The content root is CLI-managed.** Everything under the content root (`data/model/`) is owned by
142
230
  > the CLI: hand edits there are overwritten, and stale files are removed. Keep hand-authored prose
143
231
  > outside the content root (your template references the generated files with `data-include`). Run
@@ -171,7 +259,7 @@ bake time until you run a full pull.
171
259
 
172
260
  > **Ignore the manifest.** Each pull records what it wrote in `.modeldesk/<stack>.manifest.json`
173
261
  > (for ReSpec, `.modeldesk/respec.manifest.json`). It is regenerated every pull and is used for
174
- > precise cleanup and rename hints, so add `.modeldesk/*.manifest.json` to your `.gitignore` —
262
+ > precise cleanup and rename hints, so add `.modeldesk/*.manifest.json` to your `.gitignore`;
175
263
  > committing it is unnecessary and a stale committed copy can only mislead a later pull.
176
264
 
177
265
  ### Portable file names
@@ -186,7 +274,7 @@ naming the type to rename.
186
274
 
187
275
  ### Safe removal
188
276
 
189
- A pull's one destructive step — removing orphaned files — is guarded so a misconfiguration cannot
277
+ A pull's one destructive step, removing orphaned files, is guarded so a misconfiguration cannot
190
278
  delete files the CLI did not create:
191
279
 
192
280
  - A pull that returns **no fragments** (usually a wrong model or template) writes and deletes nothing
@@ -202,10 +290,10 @@ The removal list is always printed. In CI, run a `--dry-run` first as a safety g
202
290
 
203
291
  ## `bundle templates`
204
292
 
205
- Lists the document templates available for a model — the shapes you can pass to `--template`. The
293
+ Lists the document templates available for a model: the shapes you can pass to `--template`. The
206
294
  output is a table: the content `STACK`, the `TEMPLATE` slug (the `--template` value), and its display
207
295
  `NAME`. A **stack** (for example `respec`) is the render engine and content root a template produces
208
- for; a template slug is unique only _within_ a stack, so the stack namespaces it — read a row as
296
+ for; a template slug is unique only _within_ a stack, so the stack namespaces it; read a row as
209
297
  `stack / template`.
210
298
 
211
299
  ```bash
@@ -223,6 +311,892 @@ respec logisch-toc MIM logisch (TOC hiërarchisch)
223
311
  Take a `STACK` / `TEMPLATE` pair from the table straight into a pull. Pass `--stack <id>` to list
224
312
  only the templates of one stack.
225
313
 
314
+ ## `note add`
315
+
316
+ A **note** is your own Markdown under a generated element, a package, or the model root, kept outside the
317
+ content root so a pull never removes it. `intro` sits after the element's heading and diagrams, `after` at
318
+ the end of the element's own content (before nested subtypes).
319
+
320
+ A note file names its element by its path: the element's generated file under `data/model/`, with the notes
321
+ folder (`notesDir`, default `md-notes/`) in its place, ending in `.after.md` for the `after` slot. So
322
+ `md-notes/bestuurlijk-gebied/objecttype/gemeentegebied.md` is the `intro` note of the object type whose file is
323
+ `data/model/bestuurlijk-gebied/objecttype/gemeentegebied.md`, and `md-notes/bestuurlijk-gebied/index.after.md`
324
+ the `after` note of that domain. Creating the file is all an editor does, in the GitHub web editor if need be.
325
+
326
+ Every pull, CI's included, matches new note files against the manifest the server sends and records them in
327
+ `.modeldesk/notes.json` (committed: add `.modeldesk` to the workflow's commit beside `data/model`), keyed by
328
+ element id so a rename keeps the note in place. An entry can also name a file elsewhere, written by hand:
329
+
330
+ ```json
331
+ {
332
+ "notes": {
333
+ "dafddbaf-9e2a-4eda-88f7-9fae3a47362f": {
334
+ "name": "Gemeentegebied",
335
+ "intro": "md-notes/bestuurlijk-gebied/objecttype/gemeentegebied.md"
336
+ },
337
+ "125cd721-c388-49ef-bc26-d9ee56964357": {
338
+ "name": "Domein Bestuurlijk gebied",
339
+ "intro": "data/model-overzicht.md",
340
+ "after": "md-notes/bestuurlijk-gebied/index.after.md"
341
+ }
342
+ }
343
+ }
344
+ ```
345
+
346
+ `name` is refreshed by every pull and read by nothing. A package's or the model's `after` note comes under a
347
+ heading of its own, which becomes a numbered section in the table of contents; the note names it on its
348
+ first line, `<!-- heading: Afsluiting -->`, an HTML comment the document does not show.
349
+
350
+ Note paths are relative to the repository root, outside `data/model/`, and free of `..`, `%`, `#`, `?`,
351
+ backslashes and leading or trailing spaces. Editing a note's text needs no pull; adding or removing one, or
352
+ changing a heading line, does. Notes need a server that renders the `respec` stack at 1.4 or later with a
353
+ MIM template; a bundle without any note slot fails the pull once, naming its stack version.
354
+
355
+ ```bash
356
+ modeldesk note add <name> [--slot intro|after] [--heading <text>] [--dir <dir>] [--element <id>] [--stack <id>]
357
+ ```
358
+
359
+ `note add` creates the note at its path under `--dir` or `notesDir` (holding only the heading line for a
360
+ container's `after`, empty otherwise) and adds its entry to `notes.json`. It finds the element in the last
361
+ pull's manifest, so run `bundle pull` first; it contacts no server. A name several elements share is asked
362
+ about on a terminal and refused elsewhere, listing the ids for `--element`. `--heading` is required for a
363
+ package's or the model's `after` slot and refused elsewhere. It never overwrites a file, replaces a filled
364
+ slot, or names a file another entry names.
365
+
366
+ On pull, the CLI checks `notes.json` and the files it names before contacting the server. Once the bundle
367
+ has arrived, it stops before writing on a note file that matches no element (naming close paths), a note
368
+ file for a slot another file already fills, a missing note file, a path inside the content root, a slot the
369
+ element does not carry, or a container's `after` note without a heading line. It warns on an element not in
370
+ the bundle (the entry is kept), a heading line in a note that takes none, a missing image, an image outside
371
+ `publishDirs` or without alt text, a heading text two notes share without an explicit `{#id}`, and one file
372
+ filling several slots. `--dry-run` prints an `adopt <file>: <title> <slot>` line per new note file and a
373
+ `fill <title> <slot>: <path>` line per placed note, and writes nothing.
374
+
375
+ ## `template lint`
376
+
377
+ Checks a rendered document against the marker convention, the attributes a script in the document finds
378
+ its elements and links by. It is the check the built-in templates are held to, for a document a template
379
+ of your own rendered.
380
+
381
+ ```bash
382
+ modeldesk template lint data/model
383
+ ```
384
+
385
+ The folder is the one that holds `index.json` beside the fragments. Every element the index lists has to
386
+ be declared in its file by the element that carries its markers (`<h2 id="…" data-md-element="…">`, or any
387
+ other element with both the id and the markers), every link to one of them has to carry `data-md-ref`, and no markers
388
+ may name an element the index leaves out. A heading or link written in Markdown cannot carry the markers,
389
+ so it counts as a problem. Each problem is printed with its file and line, and the command exits with 4
390
+ when there is one. It contacts no server.
391
+
392
+ ## Address a model
393
+
394
+ Every command that works on one model takes the model as one argument, its **address**:
395
+
396
+ ```
397
+ <model>[@<ref>] a model, at a ref when one is given
398
+ dataset/<id> a dataset (the draft commands only; a dataset has no branches, so it takes no ref)
399
+ <element> an element: its id, or its label path from the model root
400
+ ```
401
+
402
+ `<model>` is the model's id, which `model list` prints. Names are not unique, so a model, a metamodel
403
+ and an extension are always addressed by id: `--metamodel` takes an id from `metamodel list`,
404
+ `--extension` one from `metamodel extensions <metamodel>`, and the dependency of `pin set` one from
405
+ `pin list`. A name in any of these exits 2 (`id-required`) before any request, saying where the id is.
406
+ The ref says what to read or write:
407
+
408
+ | Ref | Means |
409
+ | -------------------- | ---------------------------------------------------------------------------------------- |
410
+ | `@draft` | Your draft, as the server holds it. |
411
+ | `@head` | The head of your [working branch](#which-branch-a-command-works-on), without your draft. |
412
+ | `@main`, `@<branch>` | The head of that branch, by name, ignoring case. |
413
+ | `@<commit id>` | That commit. Any UUID in the ref position is a commit. |
414
+ | `@<release>` | That release, on `--metamodel`, `--extension` and the dependency of `pin set`. |
415
+
416
+ The address splits at the first `@`. A branch name may contain `@`, so `<model>@feat@2` is the branch
417
+ `feat@2`. An element's label path
418
+ is `/`-separated (`SHACL/NodeShape/severity`), with a `/` inside a label written as `\/`.
419
+
420
+ Each argument accepts some refs and gives a missing ref a meaning. **Working** means your draft
421
+ while it holds staged changes, and the head of your working branch otherwise.
422
+
423
+ | Argument of | Accepts | Without a ref |
424
+ | ---------------------------------------------------------- | ------------------------------------- | ----------------------------------- |
425
+ | `model tree`, `el show`, `search` | `@draft`, `@head`, a branch, a commit | Working |
426
+ | `model show`, `validate` | `@draft`, `@head`, a branch | Working |
427
+ | `model log` | `@draft`, `@head`, a branch | The working branch head |
428
+ | every `el` write, `model pull` | `@draft`, `@head`, a branch | Working |
429
+ | `branch create` (the branch to start from), `branch diff` | `@head`, a branch | The working branch head |
430
+ | `draft open`, `branch delete`, `branch merge` (the target) | a branch | Required |
431
+ | the other `draft` commands | a branch, as an assertion | Your draft, wherever it aims |
432
+ | `release create` | a commit, which must be main's head | Main's head |
433
+ | `pin set` (the dependency) | a release, or `@main` | Required |
434
+ | `--metamodel`, `--extension` | a release | The latest stable or newest release |
435
+ | the commands that read main | no ref | Main |
436
+
437
+ `model show` reads the model's identity and head at the ref. Its overview and releases are always
438
+ main's, and the result labels them so (`overview.ref`). The commands that read main are
439
+ `model export`, `model delete`, `describe`, `branch list`, `release list`, `release cascade`,
440
+ `pin list` and the model of `pin set`. They take no ref at all, `@main` included: a ref there exits 2
441
+ (`ref-unsupported`), so nothing reads main under an address that said otherwise. `describe` reads the committed metamodel resolution, which a draft cannot change, and
442
+ `model export` encodes main only. When your draft aims at another branch, both say so in the `ref`
443
+ block's `note` (on stderr in text mode).
444
+
445
+ A malformed address, a name where an id belongs, a ref the argument does not accept, a missing
446
+ required ref and an `@` on a dataset each exit 2 before any request. `@draft` without a draft, and a branch name the model does
447
+ not have, exit 3 (`ref-not-found`).
448
+
449
+ A result that resolved an address reports what it read as `ref`: `{kind: 'branch', id, name}`,
450
+ `{kind: 'draft', id, branch: {id, name}}` or `{kind: 'commit', id}`, with `draftIgnored: true` when
451
+ the read skipped your draft because it aims at another branch. The id is the key and the name is what
452
+ the branch was called when the CLI printed it. A branch deleted and recreated under its name gets a
453
+ new id: an address by branch name follows the new branch, and a workspace, which records the id, refuses.
454
+
455
+ ## Which branch a command works on
456
+
457
+ An invocation works on the ref it names. When it names none, it works on your **working branch**:
458
+ the branch your draft aims at, or `main` when you hold no draft. Nothing else holds a branch. There
459
+ is no config key, no environment variable and no state file in your shell's directory. The app
460
+ applies the same rule (your draft's branch wins over the page you opened), so the CLI and the app
461
+ always agree on where you are. The one file that records a branch is a
462
+ [workspace's](#model-workspaces) `workspace.json`, and it records the address the files came from.
463
+
464
+ **After a commit, main.** Committing a draft deletes it, from the CLI and from the app alike. After
465
+ `draft commit` of a draft aimed at `feat/x` you hold no draft, so invocations that name no ref work on
466
+ `main` again. The result says so in `landed` and `next`:
467
+
468
+ ```json
469
+ {
470
+ "landed": {
471
+ "branch": { "id": "0c7958d0-56cb-4699-b168-9da5d777c204", "name": "feat/x" },
472
+ "commit": { "id": "7ce739ab-49a9-4948-ad03-c9bc226f5035", "message": "Add the severity binding" }
473
+ },
474
+ "next": "Unaddressed invocations now default to main. Address 8d9a04e0-a822-4442-a40c-24cf67eec398@feat/x, or run: modeldesk draft open 8d9a04e0-a822-4442-a40c-24cf67eec398@feat/x"
475
+ }
476
+ ```
477
+
478
+ The CLI does not open an empty draft to keep your place, because a commit from the app does not
479
+ either. A script or an agent that works on a branch writes the ref on every invocation.
480
+
481
+ ## Drafts: stage, then commit
482
+
483
+ You hold one draft per model, aimed at one branch. Every write stages into it, and the app shows the
484
+ same user the same draft. A commit lands everything the draft holds on its branch as one commit.
485
+
486
+ ### Open your draft on a branch
487
+
488
+ `draft open <model@branch>` aims your draft at the branch, so the writes that name no branch stage
489
+ there:
490
+
491
+ - A draft already on the branch is left as it is (`opened: false`).
492
+ - A draft on another branch that holds nothing is discarded and opened on this one. That loses
493
+ nothing, and `reopenedFrom` names where it was.
494
+ - A draft holding staged changes on another branch is refused with `draft-target-taken`, exit 5.
495
+ Commit or discard those changes first.
496
+
497
+ `draft open` and `branch create --open` are the only commands that discard a draft on your behalf,
498
+ and both say so. `draft open` takes a model only.
499
+
500
+ The other draft commands take `<resource[@branch]>`. Without a ref they act on your draft wherever
501
+ it aims. With `@<branch>` they assert where it aims: a draft aimed at another branch exits 5 before
502
+ the command does anything, so a script cannot land on the wrong branch by mistake.
503
+
504
+ `draft status` reports the branch the draft aims at (`draft.target`), its baseline and head, how many
505
+ changes it holds against `maxChanges` (500), whether the branch moved past its baseline (`behind`: a
506
+ commit then needs `draft rebase` first), and `reads`: what an invocation that names no ref reads now
507
+ (`default: 'draft'` or `'head'`, and `head`, the branch). Holding no draft is reported, not refused.
508
+
509
+ ### Stage a change
510
+
511
+ Every `el` write and `model push` stage into your draft on the branch the address names, or on your
512
+ working branch. They follow these rules:
513
+
514
+ - **The draft's branch decides.** With no draft, the first change opens one on the branch. With a
515
+ draft aimed at that branch, the change is staged there. With a draft aimed at another branch, the
516
+ write exits 5 (`draft-target-taken`) before any request, and the hint names the ways out: with
517
+ staged changes, `draft commit <model>@<other>`, `draft discard <model>@<other>`, or address
518
+ `<model>@<other>` to work where the draft aims; with none, `draft open <model>@<branch>`, which
519
+ loses nothing. A write never discards a draft. A write at a commit exits 2.
520
+ - **A message on every change.** `-m` is required on every write. A missing, blank or over-long
521
+ (more than 2,000 characters) one exits 2 and says why. It is the rationale the reviewer reads
522
+ first, so nothing invents one.
523
+ - **The current state comes from one read.** A change is planned from your draft at its ref, or from
524
+ the branch head while you hold none, and that head is the `draftHeadId` the change is sent against.
525
+ - **A lost race is planned again, never resent.** A `draft-head-conflict` whose sent head is still an
526
+ ancestor (another session staged in between) reads the target again and plans the change again
527
+ from it (coercion, translation, a bulk selection), keeping the `changeRequestId` and the minted
528
+ element ids, then sends it once more. What a plan computed from the first read (the other languages
529
+ a value keeps, a whole relation key) is never resent over a state that moved, since it would revert
530
+ the concurrent edit. A second loss, or `ancestor: false`, exits 5 with the gap in `details`.
531
+ `change-validation-failed` exits 4 with `errors[]`. `chain-too-long` exits 4 naming `draft commit`.
532
+ - **`--request-id` makes a retry idempotent.** A change whose outcome is unknown exits 7 with its
533
+ `changeRequestId` in `details`. Run the command again with `--request-id <that id>`: it first looks
534
+ for a change staged under that id in the draft (and in a conflict's gap) and reports it as
535
+ `alreadyStaged` instead of staging it twice. The id is 1 to 200 printable characters without
536
+ spaces. The CLI mints `cli-<uuid>`, or `cli-<session>-<uuid>` when `MODELDESK_AGENT_SESSION` names
537
+ an agent session. Every id it sends has that shape, so the app attributes the change to the CLI and
538
+ the session's undo, discard and landing take it as its own: an id the CLI minted for the same
539
+ session is sent as given, and any other `--request-id` seeds an id of that shape derived from it,
540
+ the same one on every run, so `--request-id fix-42` and the id it reported retry alike. `model
541
+ create` has no idempotency key: after an exit 7, check `model list` before you retry.
542
+
543
+ ### Commit your draft
544
+
545
+ `draft commit <resource[@branch]>` lands every change the draft holds, whichever surface staged it.
546
+ `--commit` on an `el` write or on `model push` lands the draft right after staging, under the write's
547
+ own `-m`. The landing rules:
548
+
549
+ - **The landing names the head it read.** Every landing sends the draft head the command staged or
550
+ read as `expectedDraftHeadId`, or the head `draft commit --expect <draft-head>` gives. A draft
551
+ that moved since exits 5 (`draft-moved`) with nothing written.
552
+ - **`--with-staged` covers what was there before.** A landing with `--commit` covers changes the
553
+ draft held before this run only when `--with-staged` says so. Without it such a landing exits 1
554
+ naming the flag, so an agent's message never silently covers edits a person made in the app.
555
+ `draft commit` lands what was staged before it by definition, so it has no such flag.
556
+ - **The landing message.** `-m` is optional on `draft commit` of a model. Without it the message is
557
+ composed from the staged changes' own messages, oldest first: the first line of each, a push's
558
+ ` (n/N)` suffix removed, equal neighbours collapsed. One line is the message as it stands. Several
559
+ lines are a subject (the lines joined with `; ` when that fits in 72 characters, else the first line
560
+ and ` (and N more)`), a blank line, and every line as a `- ` item, cut at 2,000 characters with
561
+ `- and N more`. A change staged without a message (the app sends none) adds no line, and when no
562
+ change carries one the command exits 2 naming `-m`. A dataset draft takes `-m` (exit 2 without it).
563
+
564
+ ```
565
+ Add the severity binding; Rename Assoc to Association
566
+
567
+ - Add the severity binding
568
+ - Rename Assoc to Association
569
+ ```
570
+
571
+ - **A branch that moved needs a rebase.** A draft whose baseline the branch left behind cannot be
572
+ committed: `draft rebase` replays its changes onto the branch head first. `model push --commit`
573
+ checks this before it stages anything and exits 5 (`draft-baseline-stale`).
574
+ - **A commit is recognised, not repeated.** After an outcome the CLI cannot know (the network, a
575
+ 5xx), it looks for its own commit request id on the draft's branch, down to the draft's baseline,
576
+ and takes a match as the landing before it sends the same request again. When that branch cannot
577
+ be read, it sends the request again all the same; if that answer is lost too, or finds the draft
578
+ gone, it exits 7 saying whether the draft landed is unknown, and `model log` shows it.
579
+ - **Nothing to commit.** A draft with no staged changes, or no draft, exits 1 (`nothing-to-commit`).
580
+
581
+ Under an agent host a landing has a gate of its own; see [The agent policy](#the-agent-policy).
582
+
583
+ ### See what a landing held
584
+
585
+ A commit landed from a draft records every change it landed: its request id, its message and its
586
+ action types, in the order they were staged. `model log` counts them in the `CHANGES` column.
587
+ `model log --changes` lists them beneath each landing, one line per change: the surface it came from,
588
+ read off the request id (`cli`, `mcp`, `web` for the app, `api` for anything else), the agent session
589
+ when the request id names one, the message, and the action types:
590
+
591
+ ```
592
+ $ modeldesk model log <model>@agent/nightly-pass --changes
593
+ ID DATE AUTHOR CHANGES MESSAGE REQUEST
594
+ 98c4377f-8da2-438b-a54e-cebba0551168 2026-10-02T16:30:00Z Ada 3 Add severity cli-1f0c
595
+ cli nightly-pass Add the severity binding [ELEMENT_CREATE]
596
+ web [ELEMENT_UPDATE]
597
+ mcp nightly-pass Rename Assoc to Association [ELEMENT_DELETE, ELEMENT_UPDATE]
598
+ ```
599
+
600
+ `--changes` reads one request per listed landing, which `--limit` bounds. Under `--json` each
601
+ landing's row carries the record as `stagedChanges`. A commit that is no landing (a merge, an import, a
602
+ `pin set`), and a landing made before the record existed, have no count and nothing to list.
603
+ `model log <model>@draft` lists your draft's staged chain instead.
604
+
605
+ ### `el bulk` criteria
606
+
607
+ `--where` takes the app's bulk-update criteria in a text form, one criterion per flag, all of which
608
+ must hold:
609
+
610
+ | Clause | The app's criterion |
611
+ | -------------------------- | ----------------------------------------------------------- |
612
+ | `type=<T>[,<T>…]` | `type`: the types, their instantiable subtypes and appliers |
613
+ | `<attr>=<value>` | `equalTo` |
614
+ | `<attr>~<text>` | `contains`, ignoring case |
615
+ | `<attr>><n>`, `<attr><<n>` | `greaterThan`, `lessThan` |
616
+ | `<attr>:empty` | `empty` |
617
+ | `<attr>:not-empty` | `notEmpty` |
618
+
619
+ A `--where` that starts with `{` is the app's `SelectionCriteria` verbatim as JSON
620
+ (`{"type": [...], "conditions": [{"attribute", "operator", "value"}]}`) and stands alone. It is the
621
+ escape hatch for a value the text form cannot carry, such as a JSON boolean, or an attribute named
622
+ `type`. A comparison holds when any stored value matches by its text; metamodel defaults are not
623
+ stored values. The type filter is resolved by the schema endpoint (`instantiableTypes`), so it
624
+ matches the app's trait- and subtype-aware filter. The notation sweep in both forms:
625
+
626
+ ```bash
627
+ modeldesk el bulk <model> --where type=ElementType --where notation:empty --set notation=uml \
628
+ -m "Default the notation" --dry-run
629
+ modeldesk el bulk <model> \
630
+ --where '{"type":["ElementType"],"conditions":[{"attribute":"notation","operator":"empty"}]}' \
631
+ --set notation=uml -m "Default the notation" --dry-run
632
+ ```
633
+
634
+ ## Branches
635
+
636
+ - **`branch list <model>`** lists the branches, `main` first, each with its head, how many drafts aim
637
+ at it (whoever owns them) and how many of its commits `main` does not reach. `working` marks the
638
+ branch your draft aims at (`*` in the table).
639
+ - **`branch create <model[@from]> <name>`** creates a branch at the head of your working branch, or
640
+ of the branch the address names. `--open` then aims your draft at it, as `draft open` does. A name
641
+ another branch already has, in any case, exits 5 (`branch-name-taken`) unless `--exist-ok`, which
642
+ answers that branch with `created: false`, so a retried script converges. A name the server refuses
643
+ exits 4 (`invalid-branch-name`) with its `rule`. So do `draft`, `head`, `main` and a UUID, which an
644
+ address cannot reach as a branch. `--dry-run` checks the name and creates nothing.
645
+ - **`branch delete <model@branch>`** deletes the branch with every draft that aims at it. It restates
646
+ how many drafts go with it and how many of its commits `main` does not reach, and asks at a
647
+ terminal (`--yes` elsewhere). While other users' drafts on it hold staged changes, or it holds
648
+ commits `main` does not reach, it exits 5 (`branch-has-drafts`, `branch-unmerged`) unless `--force`,
649
+ which loses them. `main` cannot be deleted (exit 2). It needs the token scope `model:delete`
650
+ (exit 1 naming the scope otherwise).
651
+ - **`branch diff <model[@branch]> [--base <branch>]`** shows the branch's net change since it
652
+ diverged from the base (`main` by default), per element as `draft diff` shows a draft, with the
653
+ `mergeBaseId`. Two branches each merged into the other have no single point where they split: that
654
+ exits 1 (`ambiguous-merge-base`), naming the candidate commits.
655
+
656
+ ## Merge a branch
657
+
658
+ `branch merge <model@target> <source>` merges the source branch into the target as one commit with
659
+ both heads as parents. The target is always in the address, because a landing names where it lands.
660
+ The source is a branch of the same model, by name (ignoring case) or id. `-m` defaults to
661
+ `Merged <source> into <target>`.
662
+
663
+ **Preview first.** `branch merge --dry-run` reads the merge preview and prints a report. It exits 0
664
+ when the merge would land clean, 5 when the branches conflict, and 4 when the merged model would
665
+ break a rule no pick resolves (`blockers`). The report under `--json` is the **resolution file**:
666
+
667
+ ```bash
668
+ modeldesk branch merge <model>@main feat/x --dry-run --json > merge.json
669
+ ```
670
+
671
+ ```json
672
+ {
673
+ "schemaVersion": 1,
674
+ "model": { "id": "8d9a04e0-a822-4442-a40c-24cf67eec398", "name": "Shapes" },
675
+ "ref": { "kind": "branch", "id": "a93956d0-772d-40a3-a1c8-2e04d68d2597", "name": "main" },
676
+ "target": {
677
+ "id": "a93956d0-772d-40a3-a1c8-2e04d68d2597",
678
+ "name": "main",
679
+ "head": "7ce739ab-49a9-4948-ad03-c9bc226f5035"
680
+ },
681
+ "source": {
682
+ "id": "0c7958d0-56cb-4699-b168-9da5d777c204",
683
+ "name": "feat/x",
684
+ "head": "e283ab5c-c8bc-4d97-ba8b-4280d5bb6b7b"
685
+ },
686
+ "outcome": "conflicts",
687
+ "mergeBaseId": "d2a1e707-b54a-4b9f-a582-a98a9db7503a",
688
+ "blockers": [],
689
+ "names": {
690
+ "b15f995b-fc4e-4edc-bb18-1f59d46dc2d3": "SHACL",
691
+ "6dfdb74d-729b-408e-b71e-4596f2166db9": "NodeShape",
692
+ "77e2e4f5-0c01-40a4-8d04-c83518b357b1": "Shape",
693
+ "1426d601-7311-4a5c-8400-575bff282c61": "severity"
694
+ },
695
+ "resolutions": [
696
+ {
697
+ "elementId": "6dfdb74d-729b-408e-b71e-4596f2166db9",
698
+ "label": "SHACL/NodeShape",
699
+ "reason": "both-changed",
700
+ "target": { "present": true, "type": "ElementType", "owners": ["b15f995b-fc4e-4edc-bb18-1f59d46dc2d3"] },
701
+ "source": { "present": true, "type": "ElementType", "owners": ["b15f995b-fc4e-4edc-bb18-1f59d46dc2d3"] },
702
+ "take": "fields",
703
+ "fields": {
704
+ "name": {
705
+ "kind": "attribute",
706
+ "base": ["NodeShape"],
707
+ "target": ["NodeShape"],
708
+ "source": ["Node"],
709
+ "take": "source"
710
+ },
711
+ "extends": {
712
+ "kind": "relation",
713
+ "target": ["77e2e4f5-0c01-40a4-8d04-c83518b357b1"],
714
+ "source": [],
715
+ "take": "target"
716
+ }
717
+ }
718
+ },
719
+ {
720
+ "elementId": "1426d601-7311-4a5c-8400-575bff282c61",
721
+ "label": "NodeShape/severity",
722
+ "reason": "changed-and-deleted",
723
+ "target": { "present": false, "owners": [] },
724
+ "source": { "present": true, "type": "AttributeTypeBinding", "owners": ["6dfdb74d-729b-408e-b71e-4596f2166db9"] },
725
+ "take": "source",
726
+ "fields": { "minCount": { "kind": "attribute", "base": [0], "source": [1] } }
727
+ }
728
+ ]
729
+ }
730
+ ```
731
+
732
+ The CLI writes no `take`. The `take` members above are what a person or an agent added:
733
+ on each entry `target`, `source`, or `fields`, and with `fields` a side on each field to pick. An entry
734
+ that takes `fields` and names no field takes the target's version. Pass the file back:
735
+
736
+ ```bash
737
+ modeldesk branch merge <model>@main feat/x --resolve merge.json # or --resolve - to read stdin
738
+ ```
739
+
740
+ `--resolve` reads only `model.id`, the two branches' ids and heads, `takeOthers`, and each entry's
741
+ `elementId`, `take` and field takes. Every value is context and is ignored, so a resolution picks
742
+ sides and never carries content. A file for another model or another pair of branches exits 2. So
743
+ does an entry without a `take`, unless `--take-others target|source` takes every entry the file does
744
+ not resolve from one side, and so does an entry with both a `take` of a side and field takes
745
+ (`fields-unexpected`). The file carries both heads, so the merge lands only on the heads the preview
746
+ reported: a branch that moved since exits 5 (`branch-head-conflict`), and the hint says to run the
747
+ preview again.
748
+
749
+ **Pick inline.** A person resolves without a file with `--take <element>[#<field>]=target|source`,
750
+ repeatable. The element is an id or its label path on the target branch. A field pick makes that
751
+ entry `fields`. `--take` and `--take-others` need both heads the preview reported, as
752
+ `--expect <target-head>` and `--expect-source <source-head>`, or a `--resolve` file to carry them, so a
753
+ pick always binds to heads someone reviewed. Beside `--resolve`, a `--take` edits that file's entry.
754
+
755
+ ```bash
756
+ modeldesk branch merge <model>@main feat/x --take SHACL/NodeShape#name=source --take-others target \
757
+ --expect 7ce739ab-49a9-4948-ad03-c9bc226f5035 --expect-source e283ab5c-c8bc-4d97-ba8b-4280d5bb6b7b
758
+ ```
759
+
760
+ **What comes back.** A merge that lands reports `outcome: 'merged'` with the `commit` and the number of
761
+ resolutions it `resolved`. A merge with nothing to merge reports `outcome: 'already-merged'` and exits
762
+ 0, so a re-run after a lost answer converges. A merge refused with conflicts prints the same report on
763
+ stdout (with `rejected: [{rule, message}]` on each entry whose pick the server could not apply) and
764
+ the error object on stderr (`merge-conflict`), and exits 5. So `--json > merge.json` captures the file
765
+ to fill in whether the conflicts came from the preview or from the merge. `--dry-run` with
766
+ `--resolve`, `--take`, `--take-others` or either `--expect` flag exits 2, as does `--resolve` beside
767
+ an `--expect` flag. Under an agent host a real merge is refused (exit 6) unless
768
+ `MODELDESK_ALLOW_COMMIT=1`; the preview runs.
769
+
770
+ ## Model workspaces
771
+
772
+ `model pull <model[@ref]> [dir]` writes a model as files, `model diff [dir]` shows what changed, and
773
+ `model push [dir] -m <message>` stages it on your draft. The format below is a contract, versioned by
774
+ `schemaVersion` in `workspace.json`.
775
+
776
+ ```
777
+ shacl-workspace/
778
+ ├── .modeldesk/workspace.json what was pulled: host, model, branch, base commit, the files written
779
+ ├── model.yaml the root element; its pins and dependencies under readOnly:
780
+ └── shacl/ a package-like element is a directory
781
+ ├── _element.yaml its own block; each child it owns is `- ref: <id>` + `owned: true`
782
+ ├── nodeshape.yaml one element per file, with everything it owns inline
783
+ └── shape-3cda7c98.yaml siblings whose names meet get an id suffix
784
+ ```
785
+
786
+ - **Files.** Each file starts with a `# modeldesk: …` header and holds one element block: `id`,
787
+ `type`, `attributes` (name to a list of values), `relations`, and `readOnly`. A package-typed element
788
+ that owns a package-typed one is a directory; anything else is one file with what it owns nested
789
+ inline, so an ElementType file holds its bindings. File names come from labels and mean nothing: an
790
+ element is known by its `id`, and a file may be renamed or moved freely. Elements nest at most 100
791
+ deep, a YAML file weighs at most 8 MiB and `model.json` at most 128 MiB; past that a model is not
792
+ written and a file not read.
793
+ - **Which files are the workspace.** A `.yaml` file belongs to it when pull wrote it (`workspace.json`
794
+ lists it with the SHA-256 of what was written), when it lies in a top-level directory that holds a
795
+ file pull wrote (`shacl/` above, where you add files freely), or when its first line is the
796
+ `# modeldesk` header (copy it into a file you add anywhere else). Dot-directories and `node_modules`
797
+ are never searched, `.yml` and other files never read. Nothing else in the directory is read,
798
+ changed or removed, so a workspace can live beside a repository's own YAML. No path inside the
799
+ workspace may be a symbolic link: one is refused before anything is read or written.
800
+ - **Values.** Every string is double-quoted (`"no"`, `"1.0"` stay strings) and kept on one line in
801
+ JSON escapes. Keys are sorted, lists keep the server's order, and the same model always writes the
802
+ same bytes. Files are read as YAML 1.2; aliases are limited, and an attribute, relation or group may
803
+ not be named after a member every JavaScript object has (`__proto__`, `constructor`, `toString`).
804
+ - **Relations.** An ungrouped relation is a list; a grouped one is a mapping of group to list. An item
805
+ is a bare id (`- "<id>" # label`, an unowned reference to this model), `{ref, model}` for an element
806
+ of another model, `{ref, owned: true}` for an owned element written elsewhere, or a nested block (a
807
+ mapping with a `type`) for an owned element written here. An element owned twice is written once,
808
+ under its first owner, and referenced from the other. Comments are never pushed.
809
+ - **Read-only.** `external`, `extensionLayer` and `lineage`, and the root's `@` relations other than
810
+ `@element` (metamodel pin, extensions, dependencies, namespaces), sit under `readOnly:`. A diff
811
+ that changes them is refused (exit 4) naming the field.
812
+ - **New elements.** A block without `id` is created with a minted id, which the push writes back
813
+ into the block. A block with an id the model does not hold is created with that id, so a new
814
+ element can be referenced before it exists.
815
+
816
+ ### The branch a workspace tracks
817
+
818
+ A workspace tracks one branch. `model pull` takes a branch, `@head` or `@draft` (a commit exits 2,
819
+ since a workspace tracks a branch to push to) and records the branch the address resolved to, your
820
+ working branch without a ref. `model diff` and `model push` address that branch by its id from disk
821
+ and never read a branch from anywhere else. Push opens your draft there when you hold none, and a
822
+ draft aimed at another branch exits 5 (`draft-target-taken`). A draft the branch has moved past is
823
+ what a change stages on, even an empty one, so `model pull` reads it as it stands, says so in `ref`
824
+ and warns; run `draft rebase`, then pull again, to work on what moved.
825
+
826
+ `.modeldesk/workspace.json`, format 2:
827
+
828
+ ```json
829
+ {
830
+ "schemaVersion": 2,
831
+ "host": "modeldesk.io",
832
+ "model": { "id": "8d9a04e0-a822-4442-a40c-24cf67eec398", "name": "Shapes" },
833
+ "branch": { "id": "0c7958d0-56cb-4699-b168-9da5d777c204", "name": "feat/x" },
834
+ "baseCommitId": "98c4377f-8da2-438b-a54e-cebba0551168",
835
+ "baseRootRevision": "26eb0d3b-23fd-46d7-9d0e-94c702dab13d",
836
+ "format": "yaml",
837
+ "files": { "model.yaml": "<sha-256 hex>", "shacl/_element.yaml": "<sha-256 hex>" }
838
+ }
839
+ ```
840
+
841
+ - `branch.id` is the address. `branch.name` is advisory: it is refreshed on every read and never used
842
+ to resolve. A branch id that no longer exists exits 3 (`branch-gone`). A branch with the same name on
843
+ another id is named in the hint (`model pull <model>@<name> <dir> --force`) and never adopted.
844
+ - `baseCommitId` is the one tip the files reflect: your draft's head while you hold a draft on the
845
+ branch, else the branch head. `baseRootRevision` is the model root's revision at that tip. It is
846
+ absent when the last change a push recorded was found already staged, since that answer names no
847
+ root revision.
848
+ - `host` is a bare host name. `--host` and `MODELDESK_HOST` must name the workspace's host; without
849
+ them the host comes from this file. A machine-auth run follows the committed `config.json` rule: it
850
+ takes the host from the flag, the environment or the built-in default, so it refuses a workspace of
851
+ another instance unless the host is named.
852
+ - A format 1 file is refused (exit 1) with a hint to pull again into an empty directory. There is no
853
+ migration.
854
+
855
+ **Stale or rebound.** The base must equal the tip of what the workspace writes to, or the workspace
856
+ is stale: `model diff` says so first, marks itself not pushable and gives no plan hash, and
857
+ `model push` exits 5 (`workspace-stale`) before any write. Two cases move the base to the tip instead,
858
+ reported as `rebound: {from}` and recorded in `workspace.json` by `model diff` and `model push` (not
859
+ under `--dry-run`):
860
+
861
+ - **The tip keeps the base's root revision.** Every change renews the revisions from the changed
862
+ element up to the root, so a tip with the same root revision holds exactly what the base held. A
863
+ commit keeps the root revision of the draft head it lands. So a workspace whose draft was
864
+ committed, from the CLI or the app, rebinds with its local edits intact and pushes on without a
865
+ pull.
866
+ - **The files plan to no operation against the tip.** Building on a tip that already says what the
867
+ files say reverts nothing, whatever the base was. This covers a tip whose content was recorded again
868
+ (a rebase re-records every change) or moved to what the files hold.
869
+
870
+ Anything else is stale, and a pull is the remedy.
871
+
872
+ - **Diff.** Operations come in the order a push stages them: creates (a new subtree is one, in the
873
+ files' order; for a push of several changes, ordered so no change references what a later one
874
+ creates), moves (to a new owner, or to a new place in the list, each element once, with the
875
+ position the server expects; an element can move out of an owner the push deletes, since moves come
876
+ first), updates (whole attribute and relation keys), and deletes (the topmost element of what is
877
+ gone). Adding an owner to an element, or dropping one that is not deleted, is refused. A grouped
878
+ relation is not reordered: its group is the server's to choose, and a reorder in the files is
879
+ reported as a warning. On a stale workspace a change it cannot plan against the moved head is a
880
+ note rather than a refusal. `--exit-code` exits 1 on differences.
881
+ - **Push.** The operations are cut into changes of at most 1000 actions and about 7.2 MiB, messages
882
+ suffixed `(n/m)`. After each change lands, minted ids are written into the files and only then does
883
+ the base move on; a change that landed but cannot be recorded (an id that cannot be written) stops
884
+ the push (exit 1) naming the landed commit, with the base left behind so the workspace reads as
885
+ stale. A refused change (exit 4, the landed ones in `details`) leaves a diff of what is left. Each
886
+ change is staged under a `cli-…` id derived from `--request-id` and its number (a push of one change
887
+ takes `--request-id` as an `el` write does), or from the plan hash; an answer lost to the network is
888
+ looked up on the draft by its request id, and when it is not found the push exits 7 saying the
889
+ outcome is unknown. Run it again, with the same `--request-id`, only after `model diff`: a change
890
+ that landed leaves the workspace stale, which is what stops a push staging it twice, not its id. Deletes
891
+ need `--allow-delete`. `--dry-run` sends each change with `dryRun: true` and prints the plan and its
892
+ hash (SHA-256 over the operations and the base); a later change that stands on an earlier one (it
893
+ names an element that one creates, updates, moves or deletes, or places an element in a list that
894
+ one changes) is `client-checked`, since a dry run keeps nothing. `--plan <hash>` (12 or more characters) pushes only
895
+ that plan. `--commit` lands the draft under the [landing rules](#commit-your-draft). After a
896
+ complete push the files stay as written, comments included, unless the server holds something they
897
+ do not (a default it filled in): then they are rewritten from it, and comments in them are lost.
898
+ - **Pull.** A workspace without local changes is pulled again in place, moving the base; one with
899
+ local changes is refused unless `--force`. A pull replaces and removes only files
900
+ it wrote, and only ones unchanged since: a file it wrote that the model no longer needs but that was
901
+ edited is kept (and named), and a file it did not write standing where it would write stops the pull
902
+ before anything is written. A pull without a ref follows your working branch, so it can move a
903
+ workspace to another branch. `--format json` writes `model.json`, the element map exactly as served,
904
+ which diff and push read too.
905
+
906
+ ## Scripting and agents
907
+
908
+ The CLI's primary user is an AI agent with a shell, then CI, then a person at a terminal. Every
909
+ command therefore has a machine contract alongside its human output.
910
+
911
+ **`--json`.** stdout carries exactly one JSON document, an object led by `schemaVersion`, and
912
+ nothing else. Shapes are stable: fields are added, never renamed or removed, and `schemaVersion`
913
+ is bumped only for an additive change worth detecting. Help and version output stay text.
914
+
915
+ **Exit codes.** A script retries on 7, asks a person on 6, and treats every other non-zero code as
916
+ final. The table is frozen: codes are added, never renumbered, and 126, 127 and 128+N are never used.
917
+
918
+ | Code | Meaning |
919
+ | ---- | -------------------------------------------------------------------------------- |
920
+ | 0 | Success |
921
+ | 1 | Failure, generic or on the server |
922
+ | 2 | Usage error: unknown command or flag, a missing, malformed or ambiguous argument |
923
+ | 3 | Not found (HTTP 404) |
924
+ | 4 | Validation or check failure: input refused, or an assertion failed |
925
+ | 5 | Conflict: a stale base or a lost compare-and-set (HTTP 409) |
926
+ | 6 | Needs a human: log in, confirm, or commit in the app |
927
+ | 7 | Transient, safe to retry: the network, HTTP 429, or a 5xx |
928
+
929
+ The HTTP status decides the code unless the problem type is one of the few the CLI maps itself
930
+ (`PROBLEM_EXIT_CODES` in `src/http/client.ts`). The outcomes of drafts, branches and merges:
931
+
932
+ | Code | Outcomes |
933
+ | ---- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
934
+ | 0 | `branch merge` with nothing to merge (`outcome: 'already-merged'`); `branch merge --dry-run` that would land clean; `draft open` on a draft already there (`opened: false`); `branch create --exist-ok` on a taken name (`created: false`); `branch create` of a name outside `agent/` under an agent host, with a `note` |
935
+ | 1 | `nothing-to-commit`; a landing without `--with-staged` over changes staged before the run; `ambiguous-merge-base`; a real merge the server refuses because the merged model would break a rule; a 403 for a missing token scope, the scope named; a `workspace.json` of format 1 |
936
+ | 2 | A malformed address; `id-required` (a name where an id belongs); a name that fits several things (a label path, a type, an organization), with `candidates` in `details`; a ref the argument does not accept, `ref-unsupported` included; a missing required ref; `@` on a dataset; a write at a commit; `branch delete` of `main`; `draft commit` without `-m` when no staged change carries a message, or on a dataset; a resolution file for another model or pair of branches; an entry left open without `--take-others`; `fields-unexpected`; `--take` or `--take-others` without both heads; `--dry-run` beside a resolution flag |
937
+ | 3 | `ref-not-found` (an unknown branch name, `@draft` without a draft); `branch-gone` (a workspace's branch was deleted) |
938
+ | 4 | `change-validation-failed`, with a value that fits several attributes as `ambiguous-attribute` in `errors[]`; `chain-too-long`; `invalid-branch-name`, the names `draft`, `head`, `main` and a UUID included; `branch-limit-reached`; `invalid-resolution`; `branch merge --dry-run` with `blockers` |
939
+ | 5 | `draft-target-taken`; `draft-moved`; `draft-head-conflict` lost twice; `draft-baseline-stale`; `rebase-conflict`; `workspace-stale`; `merge-conflict` (and `branch merge --dry-run` with conflicts); `branch-head-conflict`; `branch-has-drafts`; `branch-unmerged`; `branch-name-taken` |
940
+ | 6 | A refusal of [the agent policy](#the-agent-policy) (`agent-policy`) |
941
+
942
+ **Errors.** Under `--json`, a failure prints one line on stderr instead of the `error:` text, and it
943
+ is the last line there:
944
+
945
+ ```json
946
+ {
947
+ "error": {
948
+ "code": 4,
949
+ "message": "…",
950
+ "hint": "…",
951
+ "retryable": false,
952
+ "type": "change-validation-failed",
953
+ "details": { "errors": [{ "actionIndex": 0, "message": "…", "elementId": "…", "property": "…" }] }
954
+ }
955
+ }
956
+ ```
957
+
958
+ `retryable` is true exactly for code 7. `type` is the server's problem type, and `details` carries
959
+ the server's structured members verbatim, so a caller corrects from the same data the app gets.
960
+
961
+ **Listings** return at most `--limit` rows (default 50; 20 for `model log`). When more exist the document carries
962
+ `truncated: true`, a `nextCursor` to pass as `--cursor`, and a `hint`; `--all` returns every row,
963
+ as one JSON object per line (NDJSON) under `--json`.
964
+
965
+ **Agent mode.** When `CLAUDECODE`, `CLAUDE_CODE_CHILD_SESSION`, `CURSOR_AGENT` or `AI_AGENT` is
966
+ set, output is JSON by default (a one-line note on stderr says so; `--no-json` opts out) and the
967
+ agent host is named in the `User-Agent` the CLI sends. The CLI prompts only with a terminal on
968
+ stdin and stdout, outside CI and outside an agent host. Anywhere else a command that needs a
969
+ confirmation exits 6 unless `--yes` is given, and a missing login exits 6 instead of opening a
970
+ browser. `modeldesk auth login --device` logs in by approving a code on another device, for SSH
971
+ sessions, containers and remote agents, on instances where device login is enabled; it shows a code
972
+ only for a verification address on the auth server itself. A login without a terminal takes its host
973
+ only from `--host` or `MODELDESK_HOST`, never from the committed config, and in CI a browser login is
974
+ refused (exit 6). Human output is stripped of terminal control characters, so text a server sends
975
+ cannot drive your terminal.
976
+
977
+ ### The agent policy
978
+
979
+ Under an agent host the CLI leaves to a person what lands content on a shared branch without a
980
+ person's review, and what destroys other users' work. Every command declares the **effect** it has
981
+ on the server, and one table (`POLICY` in `src/commands/policy.ts`) decides what each effect needs:
982
+
983
+ | Effect | Under an agent host | Commands |
984
+ | ------------- | ---------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
985
+ | `read` | Runs | `auth status`, `bundle templates`, `model list`, `show`, `tree`, `log`, `export`, `diff`, `model imports list`, `show`, `el show`, `search`, `describe`, `validate`, `draft status`, `diff`, `branch list`, `diff`, `release list`, `pin list`, and every `--dry-run` |
986
+ | `local` | Runs | `auth login`, `logout`, `bundle pull`, `note add`, `model pull` |
987
+ | `stage` | Runs | `el create`, `set`, `unset`, `rm`, `mv`, `relate`, `unrelate`, `bulk`, `model push`, `draft open`, `draft rebase` |
988
+ | `create` | Runs | `model create`, `model import`, `model imports complete`, `delete`, `branch create` |
989
+ | `unstage` | Runs on the agent's own changes only | `draft undo`, `draft discard`, `draft rebase --drop` |
990
+ | `land-draft` | Runs on a branch named `agent/…`; elsewhere needs `MODELDESK_ALLOW_COMMIT=1`. Own changes only | `draft commit`, `--commit` on an `el` write or `model push` |
991
+ | `land-direct` | Needs `MODELDESK_ALLOW_COMMIT=1` | `branch merge` (into or from any branch, `agent/…` included), `release create`, `release cascade`, `pin set` |
992
+ | `destroy` | Refused, with no override | `model delete`, `branch delete` |
993
+
994
+ A refusal exits 6 with `type: agent-policy`, `details: {effect, gate}`, and a hint naming the way
995
+ out. `MODELDESK_ALLOW_COMMIT` counts only when it is exactly `1`. Outside an agent host none of this
996
+ applies, so CI without an agent host commits as any script does.
997
+
998
+ - **An agent's own branch.** A branch whose name starts with `agent/` (in any case) is an agent's own
999
+ by convention: the server knows no branch owner. Under an agent host a draft landing on such a
1000
+ branch passes without `MODELDESK_ALLOW_COMMIT=1`, because a person reviews and merges that branch
1001
+ in the app, so nothing lands unreviewed on a shared branch. The gate runs where the landing knows
1002
+ its branch and before anything is staged, so a refusal means nothing changed. On any other branch
1003
+ the refusal's hint names both ways out: `MODELDESK_ALLOW_COMMIT=1` from the person, or
1004
+ `branch create <model> agent/<topic> --open` and committing there. A dataset has no branches, so a
1005
+ dataset landing keeps the plain gate. `branch create` of another name is not refused: it adds the
1006
+ note `An agent commits without MODELDESK_ALLOW_COMMIT=1 only on a branch named agent/…`.
1007
+ - **Own changes only.** `unstage` and `land-draft` act only on changes the agent staged itself. With
1008
+ `MODELDESK_AGENT_SESSION` set, a change is the agent's own when its request id carries the same
1009
+ session (`cli-<session>-<uuid>` or `mcp-<session>-<uuid>`). Without it, any change from the `cli`
1010
+ or `mcp` surface is. `--any-surface` on `draft undo`, `draft discard` and `draft commit` lifts the
1011
+ check. `--commit` on a write, `model push --commit` and `draft rebase --drop` have no such flag:
1012
+ their refusal says to run `draft commit <model> --any-surface` from a plain shell. The check holds
1013
+ on an `agent/` branch too, so another session's or a person's changes there need `--any-surface`.
1014
+ A dataset's staged changes cannot be listed, so under an agent host a dataset's undo, discard or
1015
+ landing always needs `--any-surface`.
1016
+
1017
+ The policy is a convention the user controls, not a security boundary. The server's token scopes
1018
+ (`model:write`, and `model:delete` on a branch delete) are the boundary.
1019
+
1020
+ ### Guidance for agents
1021
+
1022
+ An agent with a shell drives the CLI directly. Agents without a shell will connect through a
1023
+ ModelDesk-hosted MCP server, specified separately. Work on a branch of your own:
1024
+
1025
+ 1. **Start on a branch of your own.** Run `modeldesk branch create <model> agent/<topic> --open`. You
1026
+ share the person's draft, one per user per model, so while it holds changes on another branch
1027
+ this exits 5 (`draft-target-taken`). Ask the person to commit or discard them, or run as a service
1028
+ account, which holds a draft of its own.
1029
+ 2. **Always write the ref.** Address `<model>@agent/<topic>` on every invocation, never leave it out.
1030
+ A commit from any surface, the app included, deletes the draft, and unaddressed invocations then
1031
+ work on `main`.
1032
+ 3. **Stage small steps, each with a message** (`-m`). The message is what the person reads first, in
1033
+ the app and in `model log --changes`.
1034
+ 4. **Commit on the branch as you go.** Run `modeldesk draft commit <model>@agent/<topic>`, with `-m`,
1035
+ or without it to compose the message from your staged messages. Commit before the draft's
1036
+ `changeCount` in `draft status` nears `maxChanges`, since a draft holds at most 500 changes.
1037
+ 5. **End by handing the branch to the person.** Ask them to review and merge it in the app (the
1038
+ branch menu's **Review and merge into main**). Once `draft handoff` exists, end with it instead.
1039
+ 6. **Never run `branch merge`.** A merge lands on a shared branch with no draft to review, so it is
1040
+ refused under an agent host unless the person set `MODELDESK_ALLOW_COMMIT=1`, and even then the
1041
+ merge is theirs to make.
1042
+
1043
+ ## Contributing
1044
+
1045
+ The CLI is a small framework plus the commands declared on it. Run the checks from the repository
1046
+ root with `npm run test -w packages/cli`, `npm run typecheck -w packages/cli` and
1047
+ `npm run lint -w packages/cli`.
1048
+
1049
+ **Add a command** with one declaration, one typed API call and one formatter. Declare it with
1050
+ `defineCommand` (`src/commands/spec.ts`) and add it to `COMMANDS` in `src/commands/registry.ts`:
1051
+
1052
+ ```ts
1053
+ export const elWhere = defineCommand({
1054
+ path: ['el', 'where'],
1055
+ effect: 'read',
1056
+ summary: 'Show which element an address names',
1057
+ positionals: [MODEL_ARG(CONTENT), ELEMENT_ARG('element')],
1058
+ flags: { ...INTERNAL_FLAG },
1059
+ run: async context => {
1060
+ const { model, ref, tree } = await readModelContent(context, context.args.model, CONTENT);
1061
+ const id = resolveElement(tree, context.args.element, { internal: context.flags.internal });
1062
+ return { result: { model, ref, id } };
1063
+ },
1064
+ render: ({ model, id }) => `${id} in ${model.name}`,
1065
+ });
1066
+ ```
1067
+
1068
+ Dispatch, strict parsing, `--help` at every level, the globals, `--json`, the error object, the exit
1069
+ codes and the agent policy all follow from the declaration. Its rules:
1070
+
1071
+ - Flags and positionals take a type from a closed set (`string`, `number`, `boolean`, `{ enum }`,
1072
+ `{ list }`, `{ address, slot }`) and a one-sentence description; the same data is what a tool schema
1073
+ is generated from (an address is one string field whose description carries the grammar), so a
1074
+ declaration good enough for `--help` is good enough for a tool.
1075
+ - Every command declares its `effect` (`src/commands/policy.ts`); a command without one does not
1076
+ compile. A flag that changes the effect declares `escalate: { flag, to }`, as `--commit` raises an
1077
+ `el` write to `land-draft` and `--drop` raises `draft rebase` to `unstage`. The dispatcher applies
1078
+ the gate before the handler runs. A landing applies `requireLandingAllowed` itself, once it knows
1079
+ the branch and before it stages anything, and a command that removes or lands staged changes runs
1080
+ `requireOwnChanges` where it knows the draft.
1081
+ - The handler returns `{ result, exitCode? }`, or `{ result, refusal }` when a refused command's
1082
+ report is its result (a merge refused with conflicts). `result` is the `--json` document, always an
1083
+ object; arrays travel inside it. Text goes through `render`, or through `context.print` when a
1084
+ command reports progressively. Never write to `process.stdout`.
1085
+ - Throw `CliError` (`src/errors.ts`) with the exit code that means what happened; the HTTP layer
1086
+ already maps statuses and problem types (`PROBLEM_EXIT_CODES` in `src/http/client.ts`).
1087
+ - A command that gates CI (`validate`) does not throw when its check fails: it returns the full
1088
+ result with `exitCode: ExitCode.Validation`, so the findings still reach stdout and exit 4 carries
1089
+ the verdict.
1090
+ - A command that writes declares `dryRun: true` and honors `context.globals.dryRun`. The exceptions
1091
+ are a single `el` write, which only stages and `draft undo` takes back, and `draft commit`,
1092
+ `undo`, `open` and `rebase`, whose target `draft status` and `draft diff` show; `policy.test.ts` holds
1093
+ the list. A question only
1094
+ `--yes` answers goes through `requireConfirmation` (`src/commands/confirm.ts`).
1095
+ - A listing declares `listing` and passes its rows or a page fetcher to `context.list()`;
1096
+ `listing.defaultLimit` replaces the shared `--limit` default where it does not fit, and
1097
+ `idCursorPages` (`src/api/paging.ts`) turns a route paged by an id cursor into the page fetcher.
1098
+ - A command that addresses one model declares `MODEL_ARG(slot)`, and a draft command
1099
+ `RESOURCE_ARG(slot)`, from `src/commands/args.ts`. The grammar lives in `src/resolve/address.ts`
1100
+ and is parsed before any request; the slots (`CONTENT`, `CONTENT_REF`, `HEAD`, `WRITE`, `BRANCH`,
1101
+ `BRANCH_REQUIRED`, `DRAFT`, `RELEASE`, `PINNED`, `METAMODEL`, `MAIN_ONLY`) are in
1102
+ `src/resolve/ref.ts`. The command resolves the address through `resolveRef` (the model, your draft
1103
+ and the branch, one `GET /branches` per invocation for a name), sends `readParams(ref)` and reports
1104
+ `refReport(resolved)` as `ref`. A content read goes through `readModelContent`. An element argument
1105
+ is `ELEMENT_ARG`, resolved by `resolveElement` (`src/resolve/labelPath.ts`), never matched by hand;
1106
+ like the app, it leaves out the platform's internal `@` elements unless the caller passes
1107
+ `INTERNAL_FLAG`'s `--internal`, and an id reaches them either way.
1108
+ - A command that changes server state prints and returns the app link from `webUrl` (`src/webUrl.ts`),
1109
+ and takes every idempotency key from `src/requestId.ts`: `mintRequestId`, `deriveRequestId`, or
1110
+ `requestIdFor` for a caller's `--request-id`.
1111
+ - A command that stages a model change goes through `runChange` (`src/commands/el/stage.ts`), or its
1112
+ parts (`beginChange`, `stageChange`, `landStaged`) where its result differs, as `el bulk` does. The
1113
+ write target comes from `resolveWriteTarget` (`src/resolve/writeTarget.ts`), every change from the
1114
+ one engine, `stage` (`src/stage/engine.ts`), and every landing from `land`
1115
+ (`src/commands/draft/land.ts`). A change is described as edits for the translation in
1116
+ `src/actions/`, with every attribute value typed by `src/coerce/`; nothing builds a `StagedAction`
1117
+ or parses a value by hand. A draft command addresses a model or a dataset through `draftHolder`
1118
+ (`src/commands/draft/resource.ts`), so one declaration serves both kinds.
1119
+ - Config comes from `context.instance()` and the settings table in `src/config/types.ts`; a new
1120
+ setting is a new row there.
1121
+
1122
+ **Merges.** `src/merge/report.ts` parses the preview and the `merge-conflict` problem into one
1123
+ `MergeReport`, a union by `outcome`. `src/merge/resolution.ts` is pure: `parseResolutionFile` reads
1124
+ back only ids, takes and heads, and `toWireResolutions` builds the request. Their tests are the place
1125
+ for a new resolution rule.
1126
+
1127
+ **Import and export.** `model import <file>` drives the three-step import (create, parse, complete) as
1128
+ one command, `model imports list|show|complete|delete` handles the imports it or the app left
1129
+ pending, and `model export` the synchronous encoding. Their pure parts live in `src/importFlow/`
1130
+ and `src/exportFlow/`, each beside its tests:
1131
+
1132
+ - A command that waits on server-side work polls through `pollUntil` (`src/importFlow/poller.ts`):
1133
+ a bounded, growing interval, a deadline from `--timeout <seconds>`, and the clock from
1134
+ `src/importFlow/clock.ts`, which a test replaces so a timeout runs without waiting. A timeout exits
1135
+ 7 and says how to resume, since the work goes on server-side.
1136
+ - `--metamodel` and `--extension` (on `model import` and `model create`) take the address grammar
1137
+ with a release ref, `<id>[@<release>]`, split at the first `@`. The owner is `--owner <organization>`.
1138
+ - A transient failure never leaves a caller guessing whether to start over: status checks retry
1139
+ until `--timeout`, and every exit 7 names the import and the command that resumes it, or, when the
1140
+ creation itself failed, says to run `model imports list` first. A `--url` is shown with its user
1141
+ info and credential-like query values redacted; only the request body carries it as given.
1142
+ - Loader inference reads the CLI's own extension table (`src/importFlow/loaderTable.ts`), because
1143
+ the loader routes carry no file extensions. A loader the server adds to
1144
+ `ModelImport.SUPPORTED_LOADERS` fails the table's unit test until it is mapped.
1145
+ - Files written from server data go through `writeDocuments` or `writeFileThroughTemp`
1146
+ (`src/exportFlow/documents.ts`): staged as temporary files, then renamed into place, files 0644 and
1147
+ created directories 0755 whatever the umask. `checkSafeNames` first accepts only portable basenames
1148
+ (no path, control character, Windows-forbidden character or device name, trailing dot or space), so
1149
+ a write never lands outside the directory the caller gave, and `checkDistinctNames` refuses names
1150
+ that differ only in case or Unicode normalization. A document for stdout goes out through
1151
+ `context.io.out`, never `print`, with control characters dropped only when `context.stdoutIsTTY`.
1152
+ - Server text an import returns (problem details, error messages, log entries) passes through
1153
+ `scrubberFor` (`src/importFlow/display.ts`), which replaces the `--url` and its secret-bearing
1154
+ pieces with their redacted form.
1155
+
1156
+ **Releases and pins.** `release create|list|cascade` and `pin list|set` serve ordinary models and
1157
+ metamodel-models alike. `releaseTarget` (`src/commands/release/target.ts`) tells them apart by the
1158
+ metamodel the overview names, and a caller who is not a super-admin addressing a metamodel-model is
1159
+ refused with exit 6 (`super-admin-required`) before any `/metamodel-models` route, since those answer
1160
+ super-admins only and no service account. `release create`, `pin set` and `release cascade` change
1161
+ committed state with no draft to review, so they declare the effect `land-direct`: under an agent host
1162
+ they exit 6 before any write unless `MODELDESK_ALLOW_COMMIT=1`, and `--yes` alone never confirms a
1163
+ cascade there. `--dry-run`, `release list` and `pin list` stay open.
1164
+
1165
+ - The cascade lives in `src/cascade/`: `read.ts` reads the family into a `CascadeGraph`, `plan.ts`
1166
+ decides from it as a pure function, `execute.ts` runs the steps and stops at the first failure,
1167
+ and `verify.ts` waits for the platform's instance re-pins through `pollUntil`. Resuming is
1168
+ re-planning: a finished step leaves a pin that is current and a release at its head, so it plans
1169
+ as a no-op. A planner case is a hand-built graph in `plan.test.ts`.
1170
+ - Before its first write the cascade re-reads the heads and releases the plan rests on and exits 5
1171
+ when one moved. Verification waits only on the instance models pinning a release this run moved
1172
+ in place (the platform re-pins nothing else), at most `READ_CONCURRENCY` reads at a time; an
1173
+ instance never read, or still behind, exits 7. `--verify-all` checks every release of the family.
1174
+ - A metamodel release is named after the standard version its head declares (`readStandardVersion`),
1175
+ so the release it overwrites is known before the call (`releaseOverwritten`), and its description
1176
+ is re-sent when none is given: the server stores what the request carries.
1177
+ - The repository side of a metamodel release (`regenerate.sh`, commit, `push-metamodels`) is printed
1178
+ as `nextSteps` by `repositorySteps`, and never run.
1179
+
1180
+ **Model workspaces.** The engine is `src/workspace/`, pure apart from `files.ts` and `session.ts`:
1181
+ `materialize.ts` writes the files, `parse.ts` reads them, `opDiff.ts` compares them with the target,
1182
+ `plan.ts` translates the operations through `src/actions/` and cuts them into changes, and
1183
+ `session.ts` resolves the recorded branch (`resolveWorkspaceTarget`) and decides stale or rebound
1184
+ (`freshnessOf`). Its round-trip test runs over every bundle in `config/metamodels/` the way production
1185
+ lays them out, and a property test checks random edits against a small server applying the same
1186
+ create, move, position and delete rules.
1187
+
1188
+ **Call the API through the resource layer** (`src/api/`): `context.api().models.get(id)`, never a
1189
+ path string. Its types are generated from the backend contract,
1190
+ `backend/api/src/main/resources/static/openapi.yaml`, into `src/api/schema.d.ts`. After the contract
1191
+ changes, run `npm run generate:api -w packages/cli` and commit the result; `typecheck` fails while
1192
+ the two disagree. A route a command wraps needs a response-shape sync test on the backend
1193
+ (`CliSurfaceOpenApiSyncTest`), so the generated types stay true.
1194
+
1195
+ **Third-party code** may enter the bundle only under a license `scripts/lib/license-policy.mjs`
1196
+ accepts. The build (`esbuild.config.mjs`) then writes `THIRD-PARTY-NOTICES.txt` from what the bundle
1197
+ actually contains and fails if any bundled package is unattributed. `@modeldesk/core` stays out of
1198
+ the bundle: it is private ModelDesk code and pulls in an EPL-licensed dependency.
1199
+
226
1200
  ---
227
1201
 
228
1202
  Learn more at [modeldesk.io](https://modeldesk.io).