@delurio/cli 0.3.0 → 0.5.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/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  While the version is 0.x, a release that can judge the same graphs differently (a new check, a stricter schema) bumps the minor; a fix that judges nothing differently bumps the patch.
4
4
 
5
+ ## 0.5.0 (2026-11-01)
6
+
7
+ - A domain may be split across the files of its directory (SPEC.md §5): every `*.yaml` there that says `kind: domain`, read as one, `domain.yaml` first and then the others by name. Maps merge key by key at any depth, `policies` and `invariants` join, and any other value is given in one file only. `check` (the `schema` and `changes` rules), `diff` and `page` read the merged domain; before, a domain file not named `domain.yaml` was read by none of them.
8
+ - New rules of `check`, which fail `--strict`: `domain-twice`, a value or an invariant given in two files of a domain, at the second one's line with a note at the first; `domain-place`, a file whose id is not its directory's domain, or a domain whose files sit in two directories.
9
+ - `diff` heads the domain's changes "The API it calls (its domain)", and names every file of it it compared.
10
+ - An entity may carry `examples` (SPEC.md §5): records of it, each an object of its fields, as JSON Schema's own keyword. The `schema` rule refused it before.
11
+
12
+ ## 0.4.0 (2026-11-01)
13
+
14
+ - An exit (`type: final`) may be named in snake_case, optionally followed by its cause: `signed_out`, `invalid_token.dpop_bound` (SPEC.md §1, Text). The `schema` rule accepts these names on exits only; every other state stays camelCase. `flow.mmd` writes such an id as `invalid_token__dpop_bound`, since Mermaid ids take no dot.
15
+
5
16
  ## 0.3.0 (2026-10-25)
6
17
 
7
18
  - The modules a tool on top of delurio needs are importable, with their types: `@delurio/cli/graph`, `/model`, `/story`, `/wireframe`, `/kit`, `/edges`, `/html`, `/nav` and `/expr`. While the version is 0.x their API may change in any minor release; pin an exact version.
package/README.md CHANGED
@@ -74,7 +74,7 @@ The package ships a JSON Schema (2020-12) for each kind of graph file in `schema
74
74
  "https://unpkg.com/@delurio/cli@0.2.0/schemas/flow.schema.json": "**/flow.yaml",
75
75
  "https://unpkg.com/@delurio/cli@0.2.0/schemas/ui.schema.json": "**/ui.yaml",
76
76
  "https://unpkg.com/@delurio/cli@0.2.0/schemas/nav.schema.json": ["**/nav.yaml", "**/nav.extracted.yaml"],
77
- "https://unpkg.com/@delurio/cli@0.2.0/schemas/domain.schema.json": "**/domain.yaml"
77
+ "https://unpkg.com/@delurio/cli@0.2.0/schemas/domain.schema.json": ["**/domain.yaml", "**/domain/*.yaml"]
78
78
  },
79
79
  "json.schemas": [
80
80
  { "fileMatch": ["**/catalog/*.json"], "url": "https://unpkg.com/@delurio/cli@0.2.0/schemas/catalog.schema.json" }
@@ -82,7 +82,7 @@ The package ships a JSON Schema (2020-12) for each kind of graph file in `schema
82
82
  }
83
83
  ```
84
84
 
85
- With the package installed, `./node_modules/@delurio/cli/schemas/<kind>.schema.json` works the same, offline. `check` reports the same as the editor, as errors of the rule `schema` that fail `--strict`, and finds what a schema cannot see, such as a state that does not exist or a catalog key that is missing.
85
+ A domain may be split across the files of its directory (SPEC.md §5); `**/domain/*.yaml` covers them in a directory named `domain`, and a file elsewhere names its schema on its first line: `# yaml-language-server: $schema=<the domain schema's URL>`. With the package installed, `./node_modules/@delurio/cli/schemas/<kind>.schema.json` works the same, offline. `check` reports the same as the editor, as errors of the rule `schema` that fail `--strict`, and finds what a schema cannot see, such as a state that does not exist or a catalog key that is missing.
86
86
 
87
87
  Next to the editor, keep the pages open and current:
88
88
 
package/SPEC.md CHANGED
@@ -21,14 +21,14 @@ id: learning.enrollment
21
21
  | `flow` | `flow.yaml` | the behaviour: states, events, transitions, a finite context, and guarantees the checker proves |
22
22
  | `ui` | `ui.yaml` | what each state shows: the nodes of the screen, their roles, names, texts and the events they send |
23
23
  | catalog | `catalog/<locale>.json` | the words of the UI, one file per locale |
24
- | `domain` | `domain.yaml` | the data and the API: entities, actions, refusals, policies, invariants |
24
+ | `domain` | `domain.yaml`, and any other file of the domain's directory (§5) | the data and the API: entities, actions, refusals, policies, invariants |
25
25
  | `nav` | `nav.yaml` | the pages of an app, the ways between them, and who may open them |
26
26
  | `binding` | `binding.yaml` | how a flow maps onto a running app, for replay and recording |
27
27
  | `tutorial` | `tutorial.yaml` | an end-user video written against a flow |
28
28
  | `kit` | `kit.yaml` | how the UI components look in one product |
29
29
  | (generated) | `anchors.lock.yaml`, `viz/`, `video/` | written by the tools; never by hand |
30
30
 
31
- A flow directory holds `flow.yaml`; a flow with screens also holds `ui.yaml` and the catalog that `ui.yaml` names. It may hold `domain.yaml`, `binding.yaml` and `tutorial.yaml`. A domain shared by several flows sits in its own directory and each flow names it by id (`domain: learning.api`). A navigation graph is a directory with `nav.yaml` and its catalog.
31
+ A flow directory holds `flow.yaml`; a flow with screens also holds `ui.yaml` and the catalog that `ui.yaml` names. It may hold `domain.yaml`, `binding.yaml` and `tutorial.yaml`. A domain shared by several flows sits in its own directory and each flow names it by id (`domain: learning.api`). A directory holds one domain and a domain sits in one directory, in `domain.yaml` or split across several files (§5). A navigation graph is a directory with `nav.yaml` and its catalog.
32
32
 
33
33
  A flow with no screen (an HTTP endpoint, a webhook, an MCP tool, a CI job) has no `ui.yaml`: it loads and is checked without one, and its page draws no screens. What such a step answers the outside world is written on its state as `response` (§2).
34
34
 
@@ -42,7 +42,7 @@ A flow with no screen (an HTTP endpoint, a webhook, an MCP tool, a CI job) has n
42
42
 
43
43
  ### Text
44
44
 
45
- The graph is written in one language, given by the project. Titles, `say` sentences, descriptions and assertion sentences are in that language. Every word a user of the product sees lives in a catalog, one file per locale; the graph refers to it by key. Identifiers (states, events, guards, effects, nodes, catalog keys) are English camelCase; events are UPPER_SNAKE.
45
+ The graph is written in one language, given by the project. Titles, `say` sentences, descriptions and assertion sentences are in that language. Every word a user of the product sees lives in a catalog, one file per locale; the graph refers to it by key. Identifiers (states, events, guards, effects, nodes, catalog keys) are English camelCase; events are UPPER_SNAKE. An exit (a final state) may instead be named after what the outside world is told, in snake_case, followed by its cause when several exits tell the same thing: `signed_out`, `invalid_token.dpop_bound`, `invalid_token.expired`. A protocol's errors are snake_case, so its exits read as its errors do.
46
46
 
47
47
  ## 2. Flow (`kind: flow`)
48
48
 
@@ -91,7 +91,7 @@ An effect changes the context when a transition is taken: `set` gives variables
91
91
  | `invoke` | the step runs something: `{ action: <domain action> }`, `{ flow: <flow id> }` (another flow runs and this one waits for its outcome), or `{ external: <name> }` |
92
92
  | `on` | event → transition (below) |
93
93
  | `always` | an ordered list of transitions taken at once, with no event. The first whose guard holds is taken; the list must cover every context (the checker fails otherwise) |
94
- | `type: final` | an exit; it has no transitions |
94
+ | `type: final` | an exit; it has no transitions. Its id may be `<snake_case>` or `<error>.<cause>` (§1, Text) |
95
95
  | `redirect`, `code`, `carries` | on an exit of a web protocol flow: `redirect: success \| error \| never`, the error `code`s, and what a success carries back |
96
96
  | `leavesPage: true` | on an exit: the person left (closed the page, went elsewhere) |
97
97
  | `response` | on a step with no screen: what the outside world sees, as data: `status`, `code`, `redirect`, `headers`, `body`, or the fields of a tool's answer. The page shows it beside the step, and a replay over HTTP will read it |
@@ -219,7 +219,7 @@ invariants:
219
219
  - { id: redirect-uri-exact, rule: "...", spec: RFC 6749 §3.1.2.3 }
220
220
  ```
221
221
 
222
- **The data.** An entity's `fields` give each field as a JSON Schema (2020-12), and `required` lists the fields that must be present: an entity is the JSON Schema `{ type: object, properties: <fields>, required: <required> }`. `null` is a type like any other: an optional time is `{ type: [string, "null"], format: date-time }`, and an enum that may be empty lists `null` among its values. A `body` or a `result` written out is a JSON Schema too. delurio adds these keywords, which a JSON Schema validator leaves alone:
222
+ **The data.** An entity's `fields` give each field as a JSON Schema (2020-12), and `required` lists the fields that must be present: an entity is the JSON Schema `{ type: object, properties: <fields>, required: <required> }`. `null` is a type like any other: an optional time is `{ type: [string, "null"], format: date-time }`, and an enum that may be empty lists `null` among its values. A `body` or a `result` written out is a JSON Schema too. An entity may carry `examples`, JSON Schema's own keyword: records of it as the app keeps them, each an object of its fields (decided on 1 Nov 2026). delurio adds these keywords, which a JSON Schema validator leaves alone:
223
223
 
224
224
  | Keyword | On | Meaning |
225
225
  |---|---|---|
@@ -237,7 +237,15 @@ An action, a refusal and an invariant may carry `note`: the author's own words,
237
237
 
238
238
  This form was decided on 22 Oct 2026. Graphs captured before it may still give fields as `{ kind: text }`; they are converted when a tool first reads fields. The OpenAPI export and import are [#8](https://github.com/delurio-labs/delurio/issues/8).
239
239
 
240
- No tool checks a domain yet: the revision diff compares it and anchors lock its `source:` keys. Loading it with the flow and checking policies, secrets and `invoke` names is [#5](https://github.com/delurio-labs/delurio/issues/5); generating it from Drizzle and Zod is [#6](https://github.com/delurio-labs/delurio/issues/6); a registry that every API operation and route is covered by a graph is [#7](https://github.com/delurio-labs/delurio/issues/7).
240
+ **Several files.** A domain may be split across the files of its directory: every `*.yaml` there that says `kind: domain` is a part of it (a file named for another kind, such as `flow.yaml`, never is). Each part starts with `schema`, `kind` and the domain's `id`, and the parts are read as one domain, `domain.yaml` first and then the others by name:
241
+
242
+ - maps merge key by key, at any depth: one file may give an entity's fields, and another add its actions or mark one of its fields `sensitivity: credential`;
243
+ - the lists `policies` and `invariants` join, in that order; an invariant's `id` is given once;
244
+ - any other value (a string, a number, `true`, a list such as `required` or `lifecycle`) is given in one file only.
245
+
246
+ A value given in two files is an error of `check` at the second one's line (`domain-twice`); so is a file whose id is not its directory's domain, and a domain whose files sit in two directories (`domain-place`). A split keeps a large domain one entity per file, and lets a part generated from the code ([#6](https://github.com/delurio-labs/delurio/issues/6)) and a part written by hand sit side by side; how a generator marks the files it owns is decided there. Decided on 1 Nov 2026.
247
+
248
+ `check` validates every file of a domain against its schema and reads its files as one, the `changes` rule (§4) reads its actions, the revision diff compares it, and anchors lock its `source:` keys. Loading it with the flow and checking policies, secrets and `invoke` names is [#5](https://github.com/delurio-labs/delurio/issues/5); generating it from Drizzle and Zod is [#6](https://github.com/delurio-labs/delurio/issues/6); a registry that every API operation and route is covered by a graph is [#7](https://github.com/delurio-labs/delurio/issues/7).
241
249
 
242
250
  ## 6. Navigation (`kind: nav`)
243
251
 
@@ -291,7 +299,7 @@ A kit says how the components of `ui.yaml` look in one product: `tokens` and `da
291
299
  |---|---|
292
300
  | 0 | the graph loads and, under `--strict`, nothing is wrong |
293
301
  | 1 | the graph cannot be loaded: a YAML error, an unknown state, an unknown name in an expression, a non-exhaustive `always`, an unsupported construct |
294
- | 2 | under `--strict`: an assertion is violated, a catalog key or a sample value is missing, a component has no renderer, the kit does not cover a component, or the main story cannot be walked |
302
+ | 2 | under `--strict`: an assertion is violated, a catalog key or a sample value is missing, a component has no renderer, the kit does not cover a component, the main story cannot be walked, or a domain's files clash (§5) |
295
303
 
296
304
  **As text.** A finding is one line in the GNU error format, which compilers, editors and most CI logs read:
297
305
 
package/dist/changes.js CHANGED
@@ -1,10 +1,11 @@
1
1
  // `changes:` in ui.yaml (SPEC.md §4): a flow whose steps write something tells its users, in its own note, what it
2
2
  // changes and what follows. An action writes when its route is not a GET, when a policy lets someone `write` with it, or
3
3
  // when it is a step inside the service (no route) that returns an entity; all three are read from the flow's domain,
4
- // looked up by id among the graphs beside this one. A flow with no screens, or whose domain is not found, is not checked.
4
+ // looked up by id among the graphs beside this one, all its files read as one (SPEC.md §5). A flow with no screens, or
5
+ // whose domain is not found, is not checked.
5
6
  import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
6
7
  import { basename, dirname, join } from 'node:path';
7
- import { parse } from 'yaml';
8
+ import { inReadingOrder, isDomainText, mayBeDomain, mergeDomain } from './domain.js';
8
9
  const SKIP = new Set(['viz', 'video', 'node_modules', '.git']);
9
10
  // the root to search: the nearest folder called `graphs` above the graph, else the graph's parent
10
11
  function rootOf(dir) {
@@ -14,15 +15,18 @@ function rootOf(dir) {
14
15
  return dirname(dir);
15
16
  }
16
17
  function domainUnder(root, id, depth = 4) {
17
- const file = join(root, 'domain.yaml');
18
- if (existsSync(file)) {
19
- const d = parse(readFileSync(file, 'utf8'));
20
- if (d?.id === id)
21
- return d;
18
+ const names = readdirSync(root);
19
+ const parts = inReadingOrder(names.filter((name) => mayBeDomain(name) && statSync(join(root, name)).isFile()))
20
+ .map((name) => ({ file: join(root, name), text: readFileSync(join(root, name), 'utf8') }))
21
+ .filter((p) => isDomainText(p.text));
22
+ if (parts.length > 0) {
23
+ const merged = mergeDomain(parts);
24
+ if (merged.id === id)
25
+ return merged.doc;
22
26
  }
23
27
  if (depth === 0)
24
28
  return null;
25
- for (const name of readdirSync(root)) {
29
+ for (const name of names) {
26
30
  if (SKIP.has(name))
27
31
  continue;
28
32
  const sub = join(root, name);
package/dist/check.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // is found under --strict (and, with --baseline, new since that run).
5
5
  import { createHash } from 'node:crypto';
6
6
  import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
7
- import { join, relative, resolve } from 'node:path';
7
+ import { basename, dirname, join, relative, resolve } from 'node:path';
8
8
  import { parse } from 'yaml';
9
9
  import { GraphError, load } from './graph.js';
10
10
  import { checkAssertions, explore, Model, ModelError } from './model.js';
@@ -15,6 +15,7 @@ import { checkChanges } from './changes.js';
15
15
  import { KitError, resolveKit } from './kit.js';
16
16
  import { checkGoals, findings, loadNav, viewOf } from './nav.js';
17
17
  import { schemaKindOf, validateFile } from './schemas.js';
18
+ import { inReadingOrder, mergeDomain } from './domain.js';
18
19
  export const CHECK_USAGE = [
19
20
  ' node src/cli.ts check <graphs folder> [--strict] [--baseline <sarif>] [--format sarif --output <file>]',
20
21
  ' checks every graph under the folder and writes nothing else: GNU error lines on stdout, or SARIF 2.1.0;',
@@ -26,6 +27,8 @@ const RULES = [
26
27
  { id: 'load', text: 'The graph cannot be loaded', level: 'error' },
27
28
  { id: 'format-newer', text: 'The graph is written for a newer format than this checker reads', level: 'error' },
28
29
  { id: 'schema', text: "A graph file does not follow its kind's schema (SPEC.md)", level: 'error' },
30
+ { id: 'domain-twice', text: 'A value of a domain is given in two of its files (SPEC.md §5)', level: 'error' },
31
+ { id: 'domain-place', text: 'A domain file is not with the rest of its domain (SPEC.md §1)', level: 'error' },
29
32
  { id: 'assertion-violated', text: 'A guarantee of the flow is broken by a reachable situation', level: 'error' },
30
33
  { id: 'main-story-unwalkable', text: 'The declared main story cannot be walked', level: 'error' },
31
34
  { id: 'catalog-key-missing', text: 'A catalog key the screens use is missing', level: 'error' },
@@ -151,6 +154,32 @@ function checkFlow(dir) {
151
154
  out.push(fromWarning(dir, g.flow.id, w));
152
155
  return out;
153
156
  }
157
+ // the domains under root, each the domain files of one directory read as one (SPEC.md §5): a value given in two of
158
+ // them, a file whose id is not its directory's, and a domain whose files sit in two directories
159
+ function checkDomains(files) {
160
+ const byDir = new Map();
161
+ for (const f of files)
162
+ if (schemaKindOf(f) === 'domain')
163
+ byDir.set(dirname(f), [...(byDir.get(dirname(f)) ?? []), f]);
164
+ const out = [];
165
+ const dirsOf = new Map(); // a domain's id -> the directories that hold it
166
+ for (const [dir, list] of byDir) {
167
+ const merged = mergeDomain(inReadingOrder(list).map((file) => ({ file, text: readFileSync(file, 'utf8') })));
168
+ for (const p of merged.problems) {
169
+ const notes = p.first === undefined ? [] : [{ file: rel(p.first.file), line: p.first.line, column: p.first.column, message: 'given first here' }];
170
+ out.push(result(p.rule, p.file, p, p.message, merged.id ?? rel(dir), p.element, notes));
171
+ }
172
+ if (merged.id !== null)
173
+ dirsOf.set(merged.id, [...(dirsOf.get(merged.id) ?? []), dir]);
174
+ }
175
+ for (const [id, dirs] of dirsOf) {
176
+ for (const dir of dirs.slice(1)) {
177
+ const file = inReadingOrder(byDir.get(dir) ?? [])[0];
178
+ out.push(result('domain-place', file, placeOf(file, 'id:'), `the domain ${id} is in ${rel(dirs[0])}/ too: a domain sits in one directory, so every flow that names it reads all of it (SPEC.md §1)`, id, `${basename(file)}#/id`));
179
+ }
180
+ }
181
+ return out;
182
+ }
154
183
  function checkNav(dir) {
155
184
  const file = join(dir, 'nav.yaml');
156
185
  const { g, warnings } = loadNav(dir, undefined);
@@ -255,10 +284,12 @@ export function checkMain(args) {
255
284
  }
256
285
  }
257
286
  // every graph file against its kind's schema: what an editor with the schemas marks, check reports
258
- for (const file of graphFiles(root)) {
287
+ const files = graphFiles(root);
288
+ for (const file of files) {
259
289
  for (const f of validateFile(file))
260
290
  results.push(result('schema', file, f, f.message, f.graph ?? rel(file), f.element));
261
291
  }
292
+ results.push(...checkDomains(files));
262
293
  results.sort((a, b) => a.file.localeCompare(b.file) || a.line - b.line || a.column - b.column || a.rule.localeCompare(b.rule) || a.message.localeCompare(b.message));
263
294
  if (baseline !== undefined) {
264
295
  const prints = baselinePrints(baseline);
package/dist/diff.d.ts CHANGED
@@ -5,6 +5,8 @@ interface Source {
5
5
  rev: string | null;
6
6
  read: (file: string) => string;
7
7
  exists: (file: string) => boolean;
8
+ peek: (file: string) => string;
9
+ list: (dir: string) => string[];
8
10
  texts: Map<string, string>;
9
11
  }
10
12
  export interface Report {
package/dist/diff.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { execFileSync } from 'node:child_process';
2
- import { existsSync, readFileSync } from 'node:fs';
2
+ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
3
3
  import { isAbsolute, join, posix, relative, resolve, sep } from 'node:path';
4
- import { parse } from 'yaml';
5
4
  import { GraphError, humanize, load } from './graph.js';
6
5
  import { loadNav } from './nav.js';
7
6
  import { joinWords } from './compare.js';
8
7
  import { flowBehaviour, flowSameBehaviour, flowStructure, runSide } from './diff-flow.js';
9
8
  import { navBehaviour, navSameBehaviour, navStructure, runNav } from './diff-nav.js';
9
+ import { inReadingOrder, isDomainText, mayBeDomain, mergeDomain } from './domain.js';
10
10
  // `node src/cli.ts diff`: what a revision of a graph changes, for a PR description. Each side is a graph directory on disk
11
11
  // or the same directory at a git revision (read with `git show <commit>:<path>`, nothing is checked out). No model, no
12
12
  // network: the same two revisions give the same bytes.
@@ -43,6 +43,11 @@ function dirSource(dir) {
43
43
  texts.set(posix.normalize(file), text);
44
44
  return text;
45
45
  },
46
+ peek: (file) => readFileSync(join(dir, file), 'utf8'),
47
+ list: (sub) => {
48
+ const path = join(dir, sub);
49
+ return existsSync(path) && statSync(path).isDirectory() ? readdirSync(path).filter((n) => statSync(join(path, n)).isFile()).sort() : [];
50
+ },
46
51
  };
47
52
  }
48
53
  function git(args, cwd) {
@@ -86,19 +91,29 @@ function gitSource(rev, dir) {
86
91
  texts.set(posix.normalize(file), text);
87
92
  return text;
88
93
  },
94
+ peek: (file) => git(['show', `${commit}:${path(file)}`], top) ?? '',
95
+ list: (sub) => {
96
+ // blobs only: `ls-tree` names a directory a tree
97
+ const tree = git(['ls-tree', `${commit}:${path(sub)}`], top);
98
+ if (tree === null)
99
+ return [];
100
+ return tree.split('\n').filter((l) => /^\d+ blob /.test(l)).map((l) => l.slice(l.indexOf('\t') + 1)).sort();
101
+ },
89
102
  };
90
103
  }
91
- // The API description of a flow: domain.yaml beside it, else the shared ../domain/domain.yaml of a capture layout,
92
- // else ../../domain/domain.yaml of graphs/ (graphs/<part>/<flow>). When the flow names its domain, the file must be that domain.
104
+ // The API description of a flow: the domain beside it, else the shared ../domain/ of a capture layout, else
105
+ // ../../domain/ of graphs/ (graphs/<part>/<flow>); all its files read as one (SPEC.md §5). When the flow names its
106
+ // domain, the files must be that domain.
93
107
  function findDomain(src, g) {
94
- for (const file of ['domain.yaml', '../domain/domain.yaml', '../../domain/domain.yaml']) {
95
- if (!src.exists(file))
108
+ for (const dir of ['.', '../domain', '../../domain']) {
109
+ const files = inReadingOrder(src.list(dir).filter(mayBeDomain).map((n) => (dir === '.' ? n : `${dir}/${n}`))).filter((f) => isDomainText(src.peek(f)));
110
+ if (files.length === 0)
96
111
  continue;
97
- const doc = parse(src.read(file));
112
+ const { id, doc } = mergeDomain(files.map((file) => ({ file, text: src.read(file) })));
98
113
  const named = g.flow.domain;
99
- if (typeof named === 'string' && doc?.id !== named)
100
- throw new GraphError(`flow.yaml names the domain ${named}, but ${file} is ${String(doc?.id)}`);
101
- return { file, doc };
114
+ if (typeof named === 'string' && id !== named)
115
+ throw new GraphError(`flow.yaml names the domain ${named}, but ${files.join(', ')} ${files.length === 1 ? 'is' : 'are'} ${String(id)}`);
116
+ return { file: files.join(', '), doc };
102
117
  }
103
118
  return null;
104
119
  }
@@ -136,7 +151,7 @@ const HEADINGS = {
136
151
  facts: 'Facts and conditions',
137
152
  notModeled: 'Not modeled',
138
153
  wording: 'Wording',
139
- domain: 'The API it calls (domain.yaml)',
154
+ domain: 'The API it calls (its domain)',
140
155
  other: 'Other keys',
141
156
  citations: 'Source citations',
142
157
  };
@@ -0,0 +1,25 @@
1
+ export interface DomainPart {
2
+ file: string;
3
+ text: string;
4
+ }
5
+ export interface DomainPlace {
6
+ file: string;
7
+ line: number;
8
+ column: number;
9
+ }
10
+ export interface DomainProblem extends DomainPlace {
11
+ rule: 'domain-twice' | 'domain-place';
12
+ message: string;
13
+ element: string;
14
+ first?: DomainPlace;
15
+ }
16
+ export interface MergedDomain {
17
+ id: string | null;
18
+ doc: Record<string, unknown>;
19
+ problems: DomainProblem[];
20
+ }
21
+ export declare const OTHER_KINDS: Set<string>;
22
+ export declare const mayBeDomain: (name: string) => boolean;
23
+ export declare const isDomainText: (text: string) => boolean;
24
+ export declare function inReadingOrder(names: string[]): string[];
25
+ export declare function mergeDomain(parts: DomainPart[]): MergedDomain;
package/dist/domain.js ADDED
@@ -0,0 +1,135 @@
1
+ // A domain (SPEC.md §1, §5) is every file in its directory that says `kind: domain`, read as one: `domain.yaml` first,
2
+ // then the others by name. `schema`, `kind` and `id` open every file and the id is the same in all; maps merge key by
3
+ // key at any depth; the top-level lists `policies` and `invariants` join in that order; any other value (a string, a
4
+ // number, a list) is given in one file only. A split lets a generated part and a hand-written part sit side by side.
5
+ import { isMap, isSeq, LineCounter, parse, parseDocument } from 'yaml';
6
+ // the files whose name says another kind (SPEC.md §1); only the others are read to see whether they are a domain
7
+ export const OTHER_KINDS = new Set(['flow.yaml', 'ui.yaml', 'nav.yaml', 'nav.extracted.yaml', 'binding.yaml', 'tutorial.yaml', 'kit.yaml', 'anchors.lock.yaml']);
8
+ const OWN = new Set(['schema', 'kind', 'id']);
9
+ const JOINED = new Set(['policies', 'invariants']);
10
+ // a file that may be part of a domain, by its name
11
+ export const mayBeDomain = (name) => name === 'domain.yaml' || (name.endsWith('.yaml') && !OTHER_KINDS.has(name));
12
+ // `kind: domain` at the top of the file; read from the text, so a file that is not YAML is still found and its own
13
+ // schema check says why
14
+ export const isDomainText = (text) => /^kind:[ \t]*(domain|'domain'|"domain")[ \t]*(#.*)?$/m.test(text);
15
+ // the reading order of a domain's files: domain.yaml, then the others by name
16
+ export function inReadingOrder(names) {
17
+ const base = (n) => n.slice(n.lastIndexOf('/') + 1);
18
+ return [...names].sort((a, b) => (base(a) === 'domain.yaml' ? -1 : base(b) === 'domain.yaml' ? 1 : a < b ? -1 : a > b ? 1 : 0));
19
+ }
20
+ const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
21
+ const keyOf = (pair) => String(pair.key?.value ?? pair.key);
22
+ const pointer = (path) => path.map((s) => `/${s.replace(/~/g, '~0').replace(/\//g, '~1')}`).join('');
23
+ const nameOf = (file) => file.slice(file.lastIndexOf('/') + 1);
24
+ // the 1-based line and column of the key at `path` in a YAML text (of the item, for a list index), else the file's start
25
+ function placeOf(text, path) {
26
+ const lineCounter = new LineCounter();
27
+ const doc = parseDocument(text, { lineCounter, prettyErrors: false });
28
+ let node = doc.contents;
29
+ let at;
30
+ for (const step of path) {
31
+ if (isMap(node)) {
32
+ const pair = node.items.find((p) => keyOf(p) === step);
33
+ if (pair === undefined)
34
+ break;
35
+ at = pair.key?.range?.[0] ?? at;
36
+ node = pair.value;
37
+ }
38
+ else if (isSeq(node)) {
39
+ node = node.items[Number(step)];
40
+ at = node?.range?.[0] ?? at;
41
+ }
42
+ else
43
+ break;
44
+ }
45
+ const { line, col } = lineCounter.linePos(at ?? 0);
46
+ return { line, column: col };
47
+ }
48
+ // the files of one directory, read as one domain; a file that is not YAML, or not a map, is left to its schema check
49
+ export function mergeDomain(parts) {
50
+ const doc = {};
51
+ const problems = [];
52
+ const origin = new Map(); // the pointer of a value given -> the part that gave it
53
+ const invariants = new Map();
54
+ let id = null;
55
+ let idFrom = -1;
56
+ const where = (i, path) => ({ file: parts[i].file, ...placeOf(parts[i].text, path) });
57
+ // the part that gave the value at `path`, or the map it sits in
58
+ const giver = (path) => {
59
+ for (let n = path.length; n > 0; n--) {
60
+ const o = origin.get(pointer(path.slice(0, n)));
61
+ if (o !== undefined)
62
+ return o;
63
+ }
64
+ return 0;
65
+ };
66
+ const twice = (i, path, first, said) => {
67
+ const at = where(i, path);
68
+ const firstAt = where(first, path);
69
+ problems.push({ rule: 'domain-twice', ...at, first: firstAt, message: `${said} is given in ${nameOf(parts[first].file)}:${firstAt.line} too: a domain's files give each value once (SPEC.md §5)`, element: `${nameOf(parts[i].file)}#${pointer(path)}` });
70
+ };
71
+ const put = (target, key, value, path, i) => {
72
+ if (!(key in target)) {
73
+ target[key] = value;
74
+ origin.set(pointer(path), i);
75
+ return;
76
+ }
77
+ const here = target[key];
78
+ if (isObject(here) && isObject(value)) {
79
+ for (const [k, v] of Object.entries(value))
80
+ put(here, k, v, [...path, k], i);
81
+ return;
82
+ }
83
+ twice(i, path, giver(path), path.join('.'));
84
+ };
85
+ parts.forEach((part, i) => {
86
+ let data;
87
+ try {
88
+ data = parse(part.text);
89
+ }
90
+ catch {
91
+ return;
92
+ }
93
+ if (!isObject(data))
94
+ return;
95
+ if (typeof data.id === 'string') {
96
+ if (id === null) {
97
+ id = data.id;
98
+ idFrom = i;
99
+ }
100
+ else if (data.id !== id) {
101
+ problems.push({ rule: 'domain-place', ...where(i, ['id']), message: `the id is ${data.id}, and ${nameOf(parts[idFrom].file)} beside it is ${id}: a directory holds one domain, every file of it with its id (SPEC.md §1)`, element: `${nameOf(part.file)}#/id` });
102
+ return;
103
+ }
104
+ }
105
+ for (const [key, value] of Object.entries(data)) {
106
+ if (OWN.has(key)) {
107
+ doc[key] ??= value;
108
+ continue;
109
+ }
110
+ if (JOINED.has(key) && Array.isArray(value) && (doc[key] === undefined || Array.isArray(doc[key]))) {
111
+ if (doc[key] === undefined)
112
+ origin.set(pointer([key]), i);
113
+ doc[key] = [...(doc[key] ?? []), ...value];
114
+ if (key !== 'invariants')
115
+ continue;
116
+ value.forEach((inv, index) => {
117
+ const name = isObject(inv) && typeof inv.id === 'string' ? inv.id : null;
118
+ if (name === null)
119
+ return;
120
+ const seen = invariants.get(name);
121
+ if (seen === undefined)
122
+ invariants.set(name, { part: i, index });
123
+ else if (seen.part !== i) {
124
+ const at = where(i, ['invariants', String(index), 'id']);
125
+ const firstAt = where(seen.part, ['invariants', String(seen.index), 'id']);
126
+ problems.push({ rule: 'domain-twice', ...at, first: firstAt, message: `the invariant ${name} is given in ${nameOf(parts[seen.part].file)}:${firstAt.line} too: a domain's files give each invariant once (SPEC.md §5)`, element: `${nameOf(part.file)}#/invariants/${index}` });
127
+ }
128
+ });
129
+ continue;
130
+ }
131
+ put(doc, key, value, [key], i);
132
+ }
133
+ });
134
+ return { id, doc, problems };
135
+ }
package/dist/mermaid.js CHANGED
@@ -1,19 +1,37 @@
1
1
  import { collectEdges, exitLine, kindOf } from './edges.js';
2
2
  import { titleOf } from './graph.js';
3
3
  const clean = (s) => s.replace(/"/g, "'").replace(/:/g, ' -');
4
+ // Mermaid's ids, which take no dot: an exit named `<error>.<cause>` is written `<error>__<cause>`
5
+ function mermaidIds(names) {
6
+ const ids = new Map();
7
+ const taken = new Set(names.filter((n) => !n.includes('.')));
8
+ for (const n of names) {
9
+ if (!n.includes('.')) {
10
+ ids.set(n, n);
11
+ continue;
12
+ }
13
+ let id = n.replace(/\./g, '__');
14
+ for (let i = 2; taken.has(id); i++)
15
+ id = `${n.replace(/\./g, '__')}_${i}`;
16
+ taken.add(id);
17
+ ids.set(n, id);
18
+ }
19
+ return (name) => ids.get(name) ?? name;
20
+ }
4
21
  // Mermaid stateDiagram-v2 text, for PRs and READMEs. The full page is html.ts.
5
22
  export function renderMermaid(g, ex) {
6
23
  const lines = ['---', `title: ${clean(g.flow.title ?? g.flow.id)}`, '---', 'stateDiagram-v2', ' direction TB'];
7
24
  const names = Object.keys(g.flow.states);
25
+ const id = mermaidIds(names);
8
26
  for (const name of names) {
9
27
  const st = g.flow.states[name];
10
28
  const detail = st.type === 'final' && st.leavesPage !== true ? ` (${exitLine(st)})` : '';
11
- lines.push(` state "${clean(titleOf(g.flow, name))}${clean(detail)}" as ${name}`);
29
+ lines.push(` state "${clean(titleOf(g.flow, name))}${clean(detail)}" as ${id(name)}`);
12
30
  }
13
- lines.push(` [*] --> ${g.flow.initial}`);
31
+ lines.push(` [*] --> ${id(g.flow.initial)}`);
14
32
  for (const e of collectEdges(g, ex)) {
15
33
  const label = e.labels.map(clean).join(', ');
16
- lines.push(` ${e.from} --> ${e.to}${label === '' ? '' : `: ${label}`}${e.unused ? ' (never taken)' : ''}`);
34
+ lines.push(` ${id(e.from)} --> ${id(e.to)}${label === '' ? '' : `: ${label}`}${e.unused ? ' (never taken)' : ''}`);
17
35
  }
18
36
  lines.push(' classDef server fill:#eeeeec,stroke:#6b6560,stroke-dasharray:4 3');
19
37
  lines.push(' classDef screen fill:#ffffff,stroke:#1c1917,stroke-width:2px');
@@ -22,7 +40,7 @@ export function renderMermaid(g, ex) {
22
40
  for (const kind of ['server', 'screen', 'subflow', 'exit']) {
23
41
  const members = names.filter((n) => kindOf(g, n) === kind);
24
42
  if (members.length > 0)
25
- lines.push(` class ${members.join(',')} ${kind}`);
43
+ lines.push(` class ${members.map(id).join(',')} ${kind}`);
26
44
  }
27
45
  return lines.join('\n') + '\n';
28
46
  }
package/dist/schemas.js CHANGED
@@ -8,9 +8,11 @@ import { basename, dirname, join } from 'node:path';
8
8
  import { Ajv2020 } from 'ajv/dist/2020.js';
9
9
  import addFormatsModule from 'ajv-formats';
10
10
  import { isMap, isSeq, LineCounter, parse, parseDocument } from 'yaml';
11
+ import { isDomainText, mayBeDomain } from './domain.js';
11
12
  const FORMAT = 'delurio-graph/0';
12
13
  const KINDS = ['flow', 'ui', 'domain', 'nav', 'catalog'];
13
- // the kind of graph file, by its name: null for a file no schema covers (binding, tutorial, kit, anchors.lock)
14
+ // the kind of graph file, by its name, and a domain also by its `kind` (a domain may be split across files, SPEC.md
15
+ // §5): null for a file no schema covers (binding, tutorial, kit, anchors.lock)
14
16
  export function schemaKindOf(file) {
15
17
  const name = basename(file);
16
18
  if (name === 'flow.yaml' || name === 'ui.yaml' || name === 'domain.yaml')
@@ -19,6 +21,8 @@ export function schemaKindOf(file) {
19
21
  return 'nav';
20
22
  if (name.endsWith('.json') && basename(dirname(file)) === 'catalog')
21
23
  return 'catalog';
24
+ if (mayBeDomain(name) && existsSync(file) && isDomainText(readFileSync(file, 'utf8')))
25
+ return 'domain';
22
26
  return null;
23
27
  }
24
28
  let compiled = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delurio/cli",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "The open checker and page of delurio-graph/0: check every graph in a project's own CI, offline, with GNU error lines and SARIF.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -8,7 +8,7 @@
8
8
  "additionalProperties": false,
9
9
  "properties": {
10
10
  "schema": { "$ref": "#/$defs/formatVersion" },
11
- "kind": { "description": "The kind of graph file. A domain.yaml is `domain`.", "const": "domain" },
11
+ "kind": { "description": "The kind of graph file. A domain file is `domain`: `domain.yaml`, or any other file of a domain split across its directory.", "const": "domain" },
12
12
  "id": { "$ref": "#/$defs/graphId", "description": "The domain's id; a flow names it with `domain:`.", "examples": ["qauth.authorize", "learning.api"] },
13
13
  "title": { "type": "string", "description": "The domain in plain words, for people." },
14
14
  "summary": { "type": "string", "description": "What the domain covers, in a few plain sentences." },
@@ -80,6 +80,12 @@
80
80
  "items": { "type": "string" },
81
81
  "examples": [["none -> active: the first sign-in"]]
82
82
  },
83
+ "examples": {
84
+ "type": "array",
85
+ "description": "Records of the entity as the app keeps them, each an object of its fields: JSON Schema's own `examples`. Pages, docs and generated tests show these instead of made-up values.",
86
+ "items": { "type": "object" },
87
+ "examples": [[{ "userId": "0199f9a0-11aa-7b22-8c33-4d44e55f6601", "clientId": "0199f9b2-3c4d-7e5f-8a6b-7c8d9e0f1a2b", "scopes": ["openid"] }]]
88
+ },
83
89
  "source": { "$ref": "#/$defs/sourceAnchor" }
84
90
  }
85
91
  },
@@ -52,7 +52,20 @@
52
52
  "type": "object",
53
53
  "description": "The states of the flow, by id. Nested, parallel and history states are not part of v0.",
54
54
  "minProperties": 1,
55
- "propertyNames": { "$ref": "#/$defs/identifier" },
55
+ "propertyNames": { "$ref": "#/$defs/stateName" },
56
+ "patternProperties": {
57
+ "[_.]": {
58
+ "type": "object",
59
+ "allOf": [
60
+ { "$ref": "#/$defs/state" },
61
+ {
62
+ "$comment": "a state named in snake_case, or `<error>.<cause>`, is an exit (type: final); every other state is camelCase",
63
+ "if": true,
64
+ "then": { "properties": { "type": { "const": "final" } }, "required": ["type"] }
65
+ }
66
+ ]
67
+ }
68
+ },
56
69
  "additionalProperties": { "$ref": "#/$defs/state" }
57
70
  },
58
71
  "assertions": {
@@ -80,10 +93,15 @@
80
93
  "description": "An identifier of the graph: English camelCase (SPEC.md §1, Text).",
81
94
  "pattern": "^[a-z][A-Za-z0-9]*$"
82
95
  },
96
+ "stateName": {
97
+ "type": "string",
98
+ "description": "The id of a state: English camelCase, or for an exit (type: final) what the outside world is told, in snake_case, optionally followed by its cause: `signed_out`, `invalid_token.dpop_bound` (SPEC.md §1, Text).",
99
+ "pattern": "^([a-z][A-Za-z0-9]*|[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)?)$"
100
+ },
83
101
  "stateRef": {
84
102
  "type": "string",
85
103
  "description": "The id of a state of this flow.",
86
- "pattern": "^[a-z][A-Za-z0-9]*$"
104
+ "pattern": "^([a-z][A-Za-z0-9]*|[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)?)$"
87
105
  },
88
106
  "eventName": {
89
107
  "type": "string",
@@ -93,7 +93,7 @@
93
93
  "stateRef": {
94
94
  "type": "string",
95
95
  "description": "The id of a state of the flow.",
96
- "pattern": "^[a-z][A-Za-z0-9]*$"
96
+ "pattern": "^([a-z][A-Za-z0-9]*|[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)?)$"
97
97
  },
98
98
  "nodeRef": {
99
99
  "type": "string",