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