@delurio/cli 0.5.3 → 0.6.1

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,18 @@
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.6.1 (2026-11-11)
6
+
7
+ - `page`: in the flow's diagram, every state's group carries `data-state`, and every edge and its label `data-from` and `data-to`. One edge is drawn per pair of states, so a transition is found by its two states. A tool on top of the CLI can now find a state or a transition in the drawing, to move to it or link to it. The pages of the examples differ from 0.6.0's only by these attributes. Nothing is judged differently.
8
+ - `@delurio/cli/spine` exports `renderSpine`, which draws that diagram, with the states to draw as the story.
9
+ - SPEC.md §7: a tutorial may be told on the flow's diagram instead of its screens (`stage: diagram`), for a flow with no screens. `show` and `end` walk the flow to their state along its normal way, and every other event is given with `after`; an ending needs no card. The checker does not read tutorials, so nothing is judged differently.
10
+
11
+ ## 0.6.0 (2026-11-10)
12
+
13
+ - A graph file with an anchor (`&name`), an alias (`*name`), a tag (`!name`) or a key that is a list or a map cannot be loaded (SPEC.md §1): `check` gives `load` and `schema` errors at its line, "unsupported YAML", and exits 1; `page`, `diff` and the other commands stop the same way. The yaml library resolves these in time far beyond a file's size. On a 40 KB file, maps used as keys kept it busy for more than 30 seconds, and aliases of an anchor that holds only aliases of an empty list for more than two minutes. Its alias limit does not catch these cases. Every reader of a graph file now looks for them first, in one pass that resolves nothing: such a file is refused in under a second. A value is written where it is used, and a key is a string. Of the graphs of delurio, Medaris and QAuth, only QAuth's has them: seven flows use anchors for a `response` they repeat.
14
+ - `@delurio/cli/yaml` exports that reader, `readYaml`, and `unsupported`, which names the first such place. A server that reads graphs it was sent should read them with it.
15
+ - New rule of `check`, which fails `--strict`: `source-missing`, a state of a captured flow (`status: captured`) that names no code (SPEC.md §9). An exit may leave it out, as the transition into it names the code. Flows that are not captured are judged as before.
16
+
5
17
  ## 0.5.3 (2026-11-06)
6
18
 
7
19
  - `page`: the `flow.mmd` it writes now reads whole in Mermaid. Mermaid ends a statement at a `;`, even inside a transition's label, so a label with one lost its rest: those words were drawn as stray states, or, when a `-` or `{` came after the `;`, the diagram did not render at all ("Parse error on line …", QAuth's sign-in in an editor's preview). A `;` in a label is now written as a comma. A transition never taken and with no label of its own now carries "(never taken)" as its label: before, those two words were drawn as two more states. Of the 106 flow diagrams of QAuth, Medaris and delurio, 86 were drawn wrong (36 did not render, 50 had stray states) and none is now, in Mermaid 10.9 and 12.3; their 5 navigation diagrams were right before and are unchanged. `index.html` draws its own diagram and was not affected. Nothing is judged differently.
package/README.md CHANGED
@@ -112,7 +112,7 @@ const g = load('graphs/billing/billing.payment');
112
112
  const configurations = explore(new Model(g.flow)).configs.length;
113
113
  ```
114
114
 
115
- The entry points are `graph`, `model`, `story`, `wireframe`, `kit`, `edges`, `html`, `nav` and `expr`, each with its types. While the version is 0.x their API may change in any minor release: pin an exact version.
115
+ The entry points are `graph`, `model`, `story`, `wireframe`, `kit`, `edges`, `html`, `nav`, `expr` and `yaml`, each with its types. `yaml` reads a graph file's text as the CLI does (`readYaml`), refusing what SPEC.md §1 rules out before the text is resolved; a server that reads graphs it was sent should read them with it. While the version is 0.x their API may change in any minor release: pin an exact version.
116
116
 
117
117
  ## Licence
118
118
 
package/SPEC.md CHANGED
@@ -30,6 +30,8 @@ id: learning.enrollment
30
30
 
31
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
+ A graph file is YAML 1.2 without anchors (`&name`), aliases (`*name`), tags (`!name`) or keys that are lists or maps: a value is written where it is used, and a key is a string. No graph needs them, and a YAML reader can take minutes over a small file that uses them, so a file with one cannot be loaded ("unsupported YAML", at its line). `@delurio/cli/yaml` reads a file this way.
34
+
33
35
  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
36
 
35
37
  ### Common keys
@@ -37,7 +39,7 @@ A flow with no screen (an HTTP endpoint, a webhook, an MCP tool, a CI job) has n
37
39
  | Key | Meaning |
38
40
  |---|---|
39
41
  | `title`, `summary` | the graph in plain words, for people |
40
- | `status` | `proposed`: written before or apart from the code, nobody has approved it. `captured`: read from existing code (capture mode, every element carries `source:`). `approved`: the owner reviewed and accepted it |
42
+ | `status` | `proposed`: written before or apart from the code, nobody has approved it. `captured`: read from existing code (capture mode, every element carries `source:`, §9). `approved`: the owner reviewed and accepted it |
41
43
  | `source` | on any element: `<repo-relative path>:<line>` or a bare `<path>`, the code that makes the element true. See §9 |
42
44
 
43
45
  ### Text
@@ -279,7 +281,9 @@ notModeled: [ "..." ]
279
281
 
280
282
  A **binding** ties a flow to a running app for replay and recording: `apps` (base addresses), `browser`, `data` (JSON or dotenv sources, secrets masked in reports), `signIn`, `accounts`, `scenarios` (each a `given` start, the account, the page to `open`, `setup` and `teardown`), `events` (the actions that cause an event no node on screen sends), `states` (a URL glob or a text a state must show) and `nodes` (a locator for a node that role and name cannot find, or `before` actions such as opening a menu, or `skip` with a reason). It may `extends` a shared binding. An action is one of `goto`, `reload`, `click`, `fill`, `key`, `waitUrl`, `waitText`, `waitResponse`, `run` (a command, with `expect`). A locator is `role`, `name`, `text`, `label`, `testId`, `css`, `hasText`, `within`, `nth`; a string between slashes is a regular expression. Replay over HTTP, with no browser, is an open issue; screenshots of every state on the real app are an open issue.
281
283
 
282
- A **tutorial** is written against a flow: `title`, `audience`, `locale`, `appName`, `voice`, the `scenario` (the starting context), and `steps`. A step is `intro`, `chapter`, `show <state>`, `cut <state>` (jump, through a scenario the binding names), `reveal`/`focus` (nodes), `press <node>`, `after`, `card { title, body }`, `end`, and `say`. Every step is replayed on the flow, so a tutorial that no longer matches the graph stops at that step. `{word}` in `say` is a sample value or a node's visible text.
284
+ A **tutorial** is written against a flow: `title`, `audience`, `locale`, `appName`, `voice`, `stage`, the `scenario` (the starting context), and `steps`. A step is `intro`, `chapter`, `show <state>`, `cut <state>` (jump, through a scenario the binding names), `reveal`/`focus` (nodes), `press <node>`, `after`, `card { title, body }`, `end`, and `say`. Every step is replayed on the flow, so a tutorial that no longer matches the graph stops at that step. `{word}` in `say` is a sample value or a node's visible text.
285
+
286
+ `stage` says what the video shows: the flow's screens (`screen`, the default), or its diagram (`diagram`), for a flow with no screens, such as two programs talking or a job in the background. On the diagram the camera goes from state to state, and the tutorial's own way is drawn as the story, whether or not it is the flow's `main` story; the diagram holds every transition, failures included. No state is passed on its own there: `show <state>` and `end <state>` walk the flow to their state along its normal way (a transition with no event, then `DONE`) and stop the tutorial when that way does not reach it, and every other event is given with `after`. `press`, `reveal` and `focus` point at nodes a diagram does not have, and stop it too. An `end` on the diagram needs no `card`; one it has is shown after the ending.
283
287
 
284
288
  A video is an MP4 file. Its captions are WebVTT (`tutorial.vtt`, what an HTML `<track>` plays, with `tutorial.srt` beside it), and its chapters a WebVTT chapters track (`chapters.vtt`). Every video delurio makes is marked as AI-made in three ways, none of which can be turned off: a first card that says the whole video is made with AI, an imperceptible watermark in the sound and the picture, and signed, time-stamped provenance metadata (C2PA is the candidate). The watermark and the metadata are the machine-readable marking that Art. 50(2) of the EU AI Act asks of a system that generates synthetic audio and video, and the Commission's Code of Practice of 10 June 2026 describes. The disclosure is there because every voice is made from real people's recordings and may resemble one of them, which Art. 50(4) treats as a deep fake to disclose; a catalogue voice is no different from a cloned one in that, and delurio cannot tell which listener would recognise which voice (Taha, 24 Oct 2026: "Klon olmayan sesler de gerçek insan sesinden"). It opens the video, since Art. 50(5) asks for it at the latest at the first exposure, and nothing is burnt into the picture after it (Taha, 25 Oct 2026: "en başta 'videonun tamamı' diye belirtip yazsak yetmez mi"); a clip cut from the middle loses the card but keeps the watermark and the metadata. A lawyer is to confirm this reading. The video tool does not add the watermark or the metadata yet; that is an open issue.
285
289
 
@@ -289,7 +293,7 @@ A kit says how the components of `ui.yaml` look in one product: `tokens` and `da
289
293
 
290
294
  ## 9. Source anchors
291
295
 
292
- `source: <path>:<line>` on a state, a transition, a guard, a node, an entity or an action names the code that makes it true, relative to the application's repository root. A bare `<path>` anchors a whole file. In capture mode every element carries one; in create mode an element carries one when the code already exists.
296
+ `source: <path>:<line>` on a state, a transition, a guard, a node, an entity or an action names the code that makes it true, relative to the application's repository root. A bare `<path>` anchors a whole file. In capture mode every element carries one; in create mode an element carries one when the code already exists. `check` reports a state of a captured flow that names no code (`source-missing`). An exit may leave it out: the transition into it names the code, and an exit such as the person leaving the page has no code of its own.
293
297
 
294
298
  `anchors.lock.yaml`, generated beside the graph, records what each anchor pointed at (the line, its neighbours' hashes, the commit). The check finds every line again and says whether it is unchanged, moved, changed, gone or ambiguous. A `file:line` in a description or a comment is not an anchor.
295
299
 
@@ -298,8 +302,8 @@ A kit says how the components of `ui.yaml` look in one product: `tokens` and `da
298
302
  | Exit | Meaning |
299
303
  |---|---|
300
304
  | 0 | the graph loads and, under `--strict`, nothing is wrong |
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 |
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) |
305
+ | 1 | the graph cannot be loaded: a YAML error, unsupported YAML (§1), an unknown state, an unknown name in an expression, a non-exhaustive `always`, an unsupported construct |
306
+ | 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, a domain's files clash (§5), or a state of a captured flow names no code (§9) |
303
307
 
304
308
  **As text.** A finding is one line in the GNU error format, which compilers, editors and most CI logs read:
305
309
 
package/dist/check.js CHANGED
@@ -5,7 +5,7 @@
5
5
  import { createHash } from 'node:crypto';
6
6
  import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
7
7
  import { basename, dirname, join, relative, resolve } from 'node:path';
8
- import { parse } from 'yaml';
8
+ import { keyAt, readYaml } from './yaml.js';
9
9
  import { GraphError, load } from './graph.js';
10
10
  import { checkAssertions, explore, Model, ModelError } from './model.js';
11
11
  import { stepsByEvents } from './story.js';
@@ -39,6 +39,7 @@ const RULES = [
39
39
  { id: 'hand-over', text: 'A started flow cannot begin with what it is given', level: 'error' },
40
40
  { id: 'changes-note-missing', text: 'A flow whose steps write has no changes note (SPEC.md §4)', level: 'error' },
41
41
  { id: 'changes-note-locale', text: "The changes note is missing from a locale's catalog", level: 'error' },
42
+ { id: 'source-missing', text: 'A state of a captured flow names no code (SPEC.md §9)', level: 'error' },
42
43
  { id: 'graph-warning', text: 'Another warning of the graph', level: 'error' },
43
44
  { id: 'nav-problem', text: 'A problem of the navigation graph', level: 'error' },
44
45
  { id: 'nav-note', text: 'A note on the navigation graph', level: 'warning' },
@@ -85,7 +86,7 @@ function graphFiles(root, out = []) {
85
86
  }
86
87
  // the format the file says it is written in: null when it is this one
87
88
  function newerFormat(abs) {
88
- const doc = parse(readFileSync(abs, 'utf8'));
89
+ const doc = readYaml(readFileSync(abs, 'utf8'));
89
90
  const s = typeof doc?.schema === 'string' ? doc.schema : FORMAT;
90
91
  return s === FORMAT ? null : s;
91
92
  }
@@ -152,6 +153,16 @@ function checkFlow(dir) {
152
153
  warn(p);
153
154
  for (const w of warnings)
154
155
  out.push(fromWarning(dir, g.flow.id, w));
156
+ // a captured flow is read from code, so every state names the code that makes it true; an exit may leave it out, as
157
+ // the transition into it names that code (SPEC.md §9)
158
+ if (g.flow.status === 'captured') {
159
+ const text = readFileSync(file, 'utf8');
160
+ for (const [name, st] of Object.entries(g.flow.states)) {
161
+ if (st.source !== undefined || st.type === 'final')
162
+ continue;
163
+ out.push(result('source-missing', file, keyAt(text, ['states', name]), `state ${name} names no code: in a captured flow every state but an exit carries source: <path>:<line> (SPEC.md §9)`, g.flow.id, `states/${name}`));
164
+ }
165
+ }
155
166
  return out;
156
167
  }
157
168
  // the domains under root, each the domain files of one directory read as one (SPEC.md §5): a value given in two of
package/dist/domain.js CHANGED
@@ -2,7 +2,7 @@
2
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
3
  // key at any depth; the top-level lists `policies` and `invariants` join in that order; any other value (a string, a
4
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';
5
+ import { keyAt, readYaml } from './yaml.js';
6
6
  // the files whose name says another kind (SPEC.md §1); only the others are read to see whether they are a domain
7
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
8
  const OWN = new Set(['schema', 'kind', 'id']);
@@ -18,33 +18,8 @@ export function inReadingOrder(names) {
18
18
  return [...names].sort((a, b) => (base(a) === 'domain.yaml' ? -1 : base(b) === 'domain.yaml' ? 1 : a < b ? -1 : a > b ? 1 : 0));
19
19
  }
20
20
  const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
21
- const keyOf = (pair) => String(pair.key?.value ?? pair.key);
22
21
  const pointer = (path) => path.map((s) => `/${s.replace(/~/g, '~0').replace(/\//g, '~1')}`).join('');
23
22
  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
23
  // 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
24
  export function mergeDomain(parts) {
50
25
  const doc = {};
@@ -53,7 +28,7 @@ export function mergeDomain(parts) {
53
28
  const invariants = new Map();
54
29
  let id = null;
55
30
  let idFrom = -1;
56
- const where = (i, path) => ({ file: parts[i].file, ...placeOf(parts[i].text, path) });
31
+ const where = (i, path) => ({ file: parts[i].file, ...keyAt(parts[i].text, path) });
57
32
  // the part that gave the value at `path`, or the map it sits in
58
33
  const giver = (path) => {
59
34
  for (let n = path.length; n > 0; n--) {
@@ -85,7 +60,7 @@ export function mergeDomain(parts) {
85
60
  parts.forEach((part, i) => {
86
61
  let data;
87
62
  try {
88
- data = parse(part.text);
63
+ data = readYaml(part.text);
89
64
  }
90
65
  catch {
91
66
  return;
package/dist/graph.d.ts CHANGED
@@ -31,6 +31,7 @@ export interface State {
31
31
  includes?: string[];
32
32
  response?: Record<string, unknown>;
33
33
  states?: unknown;
34
+ source?: string;
34
35
  }
35
36
  export interface ContextVar {
36
37
  values: Scalar[];
package/dist/graph.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { existsSync, readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
- import { parse } from 'yaml';
3
+ import { readYaml } from './yaml.js';
4
4
  import { identifiers, parseExpr } from './expr.js';
5
5
  export class GraphError extends Error {
6
6
  }
@@ -18,13 +18,13 @@ export function alternatives(spec) {
18
18
  }
19
19
  // `read` and `exists` take a path relative to `dir`; the revision diff passes ones that read a git revision instead of the disk
20
20
  export function load(dir, read = (file) => readFileSync(join(dir, file), 'utf8'), exists = (file) => existsSync(join(dir, file))) {
21
- const flow = parse(read('flow.yaml'));
21
+ const flow = readYaml(read('flow.yaml'));
22
22
  // a flow with no context, guards or effects leaves the key out; every reader expects an object
23
23
  flow.context ??= {};
24
24
  flow.guards ??= {};
25
25
  flow.effects ??= {};
26
26
  // a flow with no screens (an endpoint, a webhook, a CI job) has no ui.yaml and no catalog
27
- const ui = exists('ui.yaml') ? parse(read('ui.yaml')) : { absent: true, id: flow.id, catalog: '', samples: {}, nodes: {} };
27
+ const ui = exists('ui.yaml') ? readYaml(read('ui.yaml')) : { absent: true, id: flow.id, catalog: '', samples: {}, nodes: {} };
28
28
  const catalog = ui.absent === true ? {} : JSON.parse(read(ui.catalog));
29
29
  if (flow.states[flow.initial] === undefined)
30
30
  throw new GraphError(`initial state ${flow.initial} does not exist`);
package/dist/kit.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // the kit loads.
5
5
  import { existsSync, readFileSync, statSync } from 'node:fs';
6
6
  import { dirname, join, resolve } from 'node:path';
7
- import { parse } from 'yaml';
7
+ import { readYaml } from './yaml.js';
8
8
  export class KitError extends Error {
9
9
  }
10
10
  const esc = (s) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
@@ -589,7 +589,7 @@ export function loadKit(path) {
589
589
  if (!existsSync(file))
590
590
  throw new KitError(`kit ${path} has no kit.yaml`);
591
591
  const dir = dirname(file);
592
- const raw = parse(readFileSync(file, 'utf8'));
592
+ const raw = readYaml(readFileSync(file, 'utf8'));
593
593
  if (raw === null || typeof raw !== 'object')
594
594
  throw new KitError(`${file}: empty`);
595
595
  if (raw.kind !== 'kit')
package/dist/nav.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
- import { parse } from 'yaml';
3
+ import { readYaml } from './yaml.js';
4
4
  import { evaluate, identifiers, parseExpr } from './expr.js';
5
5
  import { GraphError } from './graph.js';
6
6
  const PAGE_KINDS = ['screen', 'placeholder', 'missing', 'redirect', 'external'];
@@ -32,8 +32,8 @@ function mergeDocs(base, hand) {
32
32
  }
33
33
  // `read` takes a path relative to `dir`; the revision diff passes one that reads a git revision instead of the disk
34
34
  export function loadNav(dir, locale, read = (file) => readFileSync(join(dir, file), 'utf8')) {
35
- const raw = parse(read('nav.yaml'));
36
- const doc = raw.extends === undefined ? raw : mergeDocs(parse(read(raw.extends)), raw);
35
+ const raw = readYaml(read('nav.yaml'));
36
+ const doc = raw.extends === undefined ? raw : mergeDocs(readYaml(read(raw.extends)), raw);
37
37
  const warnings = [];
38
38
  if (doc.kind !== 'nav')
39
39
  throw new GraphError(`${join(dir, 'nav.yaml')} is not a navigation graph (kind: nav is missing)`);
package/dist/schemas.js CHANGED
@@ -7,7 +7,8 @@ import { existsSync, readFileSync } from 'node:fs';
7
7
  import { basename, dirname, join } from 'node:path';
8
8
  import { Ajv2020 } from 'ajv/dist/2020.js';
9
9
  import addFormatsModule from 'ajv-formats';
10
- import { isMap, isSeq, LineCounter, parse, parseDocument } from 'yaml';
10
+ import { isMap, isSeq, LineCounter, parseDocument } from 'yaml';
11
+ import { readYaml, unsupported } from './yaml.js';
11
12
  import { isDomainText, mayBeDomain } from './domain.js';
12
13
  const FORMAT = 'delurio-graph/0';
13
14
  const KINDS = ['flow', 'ui', 'domain', 'nav', 'catalog'];
@@ -182,7 +183,7 @@ function graphIdBeside(dir) {
182
183
  if (!existsSync(file))
183
184
  continue;
184
185
  try {
185
- const id = parse(readFileSync(file, 'utf8'))?.id;
186
+ const id = readYaml(readFileSync(file, 'utf8'))?.id;
186
187
  if (typeof id === 'string')
187
188
  return id;
188
189
  }
@@ -199,6 +200,7 @@ export function validateFile(file) {
199
200
  if (kind === null)
200
201
  return [];
201
202
  const text = readFileSync(file, 'utf8');
203
+ const refused = kind === 'catalog' ? null : unsupported(text);
202
204
  const lineCounter = new LineCounter();
203
205
  const doc = parseDocument(text, { lineCounter, prettyErrors: false });
204
206
  const at = (offset) => {
@@ -211,7 +213,9 @@ export function validateFile(file) {
211
213
  graph ??= graphIdBeside(kind === 'catalog' ? dirname(dirname(file)) : dirname(file));
212
214
  return { ...where, message: said, graph, element: `${ownFile}#${pointer}` };
213
215
  };
214
- // the first YAML error only: the ones after it mostly follow from it
216
+ // the first YAML error only: the ones after it mostly follow from it; one before the unsupported place comes first
217
+ if (refused !== null && (doc.errors.length === 0 || refused.offset < doc.errors[0].pos[0]))
218
+ return [failure(refused, refused.message, '')];
215
219
  if (doc.errors.length > 0)
216
220
  return [failure(at(doc.errors[0].pos[0]), `not YAML: ${doc.errors[0].message.split('\n')[0]}`, '')];
217
221
  let data;
package/dist/spine.d.ts CHANGED
@@ -2,4 +2,9 @@ import type { Graph } from './graph.ts';
2
2
  import type { Exploration } from './model.ts';
3
3
  import type { PathStep } from './story.ts';
4
4
  export type View = 'main' | 'full';
5
+ /**
6
+ * The flow's diagram as an SVG. Every state's group carries `data-state`, and every edge and its label `data-from` and
7
+ * `data-to`: one edge is drawn per pair of states, its label holding every transition between them. `story`: the
8
+ * states to draw as the story (`on-main`), in order.
9
+ */
5
10
  export declare function renderSpine(g: Graph, ex: Exploration, view: View, story: PathStep[] | null): Promise<string>;
package/dist/spine.js CHANGED
@@ -13,6 +13,11 @@ const r1 = (n) => Math.round(n * 10) / 10;
13
13
  function labelLines(e, view) {
14
14
  return e.labels.flatMap((l) => wrap(l, LABEL_WRAP[view]));
15
15
  }
16
+ /**
17
+ * The flow's diagram as an SVG. Every state's group carries `data-state`, and every edge and its label `data-from` and
18
+ * `data-to`: one edge is drawn per pair of states, its label holding every transition between them. `story`: the
19
+ * states to draw as the story (`on-main`), in order.
20
+ */
16
21
  export async function renderSpine(g, ex, view, story) {
17
22
  const all = collectEdges(g, ex);
18
23
  // main view: the story without failure branches and without "the user closes the page"
@@ -82,6 +87,8 @@ export async function renderSpine(g, ex, view, story) {
82
87
  edges.forEach((e, i) => byId.set(`e${i}`, e));
83
88
  const drawn = (laid.edges ?? []).filter((e) => e.sections?.[0] !== undefined);
84
89
  const isMain = (e) => e !== undefined && mainEdges.has(`${e.from}>${e.to}`);
90
+ // which states an edge joins, so a tool can find the drawing of a transition: one edge per pair of states
91
+ const ends = (e) => `data-from="${esc(e.from)}" data-to="${esc(e.to)}"`;
85
92
  const path = (e) => {
86
93
  const section = e.sections?.[0];
87
94
  if (section === undefined)
@@ -99,7 +106,7 @@ export async function renderSpine(g, ex, view, story) {
99
106
  if (viz === undefined || isMain(viz) !== pass)
100
107
  continue;
101
108
  const kind = pass ? 'main' : viz.kind;
102
- out.push(`<path class="edge edge-${kind}${viz.unused ? ' edge-unused' : ''}" d="${path(e)}" marker-end="url(#arrow-${view}-${kind})"/>`);
109
+ out.push(`<path class="edge edge-${kind}${viz.unused ? ' edge-unused' : ''}" ${ends(viz)} d="${path(e)}" marker-end="url(#arrow-${view}-${kind})"/>`);
103
110
  }
104
111
  }
105
112
  for (const e of drawn) {
@@ -110,7 +117,7 @@ export async function renderSpine(g, ex, view, story) {
110
117
  const lines = labelLines(viz, view);
111
118
  const x = label.x ?? 0;
112
119
  const y = label.y ?? 0;
113
- out.push(`<g class="elabel${isMain(viz) ? ' elabel-main' : ''}${viz.kind === 'fail' ? ' elabel-fail' : ''}"><rect x="${r1(x)}" y="${r1(y)}" width="${label.width ?? 0}" height="${label.height ?? 0}" rx="4"/>`);
120
+ out.push(`<g class="elabel${isMain(viz) ? ' elabel-main' : ''}${viz.kind === 'fail' ? ' elabel-fail' : ''}" ${ends(viz)}><rect x="${r1(x)}" y="${r1(y)}" width="${label.width ?? 0}" height="${label.height ?? 0}" rx="4"/>`);
114
121
  lines.forEach((l, i) => out.push(`<text x="${r1(x + 7)}" y="${r1(y + 17 + i * 17)}">${esc(l)}</text>`));
115
122
  out.push('</g>');
116
123
  }
@@ -131,7 +138,7 @@ export async function renderSpine(g, ex, view, story) {
131
138
  const close = kind === 'screen' ? '</a>' : '';
132
139
  const by = st.by === undefined ? '' : ` by-${st.by}`;
133
140
  const tip = [st.description ?? n.id, ...(st.includes ?? []).map((s) => `+ ${s}`)].join('\n');
134
- out.push(`${open}<g class="node node-${kind}${by}${st.goal === true ? ' goal' : ''}${exitClass}${mainNodes.has(n.id) ? ' on-main' : ''}${unreachable ? ' node-unreachable' : ''}"><title>${esc(tip)}</title>`);
141
+ out.push(`${open}<g class="node node-${kind}${by}${st.goal === true ? ' goal' : ''}${exitClass}${mainNodes.has(n.id) ? ' on-main' : ''}${unreachable ? ' node-unreachable' : ''}" data-state="${esc(n.id)}"><title>${esc(tip)}</title>`);
135
142
  const rx = kind === 'exit' || st.by === 'ai' ? 28 : st.by === 'ci' ? 0 : 8;
136
143
  out.push(`<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="${rx}"/>`);
137
144
  if (st.by === 'agent')
package/dist/starts.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // transition is taken must give it a beginning it accepts; when it is not written yet, that is a note, not a failure.
4
4
  import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
5
5
  import { basename, dirname, join } from 'node:path';
6
- import { parse } from 'yaml';
6
+ import { readYaml } from './yaml.js';
7
7
  import { alternatives } from './graph.js';
8
8
  const SKIP = new Set(['viz', 'video', 'node_modules', '.git']);
9
9
  // the root to search: the nearest folder called `graphs` above the graph, else the graph's parent
@@ -16,7 +16,7 @@ function rootOf(dir) {
16
16
  function flowsUnder(root, depth = 4, out = new Map()) {
17
17
  const file = join(root, 'flow.yaml');
18
18
  if (existsSync(file)) {
19
- const f = parse(readFileSync(file, 'utf8'));
19
+ const f = readYaml(readFileSync(file, 'utf8'));
20
20
  if (typeof f?.id === 'string')
21
21
  out.set(f.id, { ...f, context: f.context ?? {} });
22
22
  }
package/dist/yaml.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { type ErrorCode } from 'yaml';
2
+ export interface Unsupported {
3
+ offset: number;
4
+ line: number;
5
+ column: number;
6
+ code: ErrorCode;
7
+ message: string;
8
+ }
9
+ export declare function lineAndColumn(text: string, offset: number): {
10
+ line: number;
11
+ column: number;
12
+ };
13
+ export declare function unsupported(text: string): Unsupported | null;
14
+ export declare function readYaml(text: string): unknown;
15
+ export declare function keyAt(text: string, path: string[]): {
16
+ line: number;
17
+ column: number;
18
+ };
package/dist/yaml.js ADDED
@@ -0,0 +1,103 @@
1
+ // YAML as delurio reads it (SPEC.md §1): YAML 1.2 without anchors, aliases, tags, or keys that are lists or maps.
2
+ // No graph needs them, and two of them keep the yaml library busy far beyond a file's size: on a 40 KB file, maps
3
+ // used as keys, or aliases inside keys, held `parse` for more than 30 seconds, which stops a server that reads the
4
+ // file. So the text is first read into the library's concrete syntax tree, which resolves nothing and takes time in
5
+ // proportion to the text, and walked once; a file that holds one of them is refused at its place, as a file that is not
6
+ // YAML is. Every reader of a graph file goes through `readYaml`.
7
+ import { isMap, isSeq, LineCounter, parse, parseDocument, Parser, YAMLParseError } from 'yaml';
8
+ const WHY = 'delurio reads YAML without anchors, aliases, tags or keys that are lists or maps (SPEC.md §1)';
9
+ const PROPS = {
10
+ anchor: ['BAD_ALIAS', 'an anchor', 'write the value where it is used'],
11
+ alias: ['BAD_ALIAS', 'an alias', 'write the value where it is used'],
12
+ tag: ['TAG_RESOLVE_FAILED', 'a tag', 'write the value without it'],
13
+ };
14
+ const COLLECTIONS = new Set(['block-map', 'block-seq', 'flow-collection']);
15
+ // the 1-based line and column of an offset into the text
16
+ export function lineAndColumn(text, offset) {
17
+ let line = 1;
18
+ let from = 0;
19
+ for (let i = text.indexOf('\n'); i >= 0 && i < offset; i = text.indexOf('\n', i + 1)) {
20
+ line++;
21
+ from = i + 1;
22
+ }
23
+ return { line, column: offset - from + 1 };
24
+ }
25
+ // the first place in the text, by offset, that delurio does not read; null when there is none. A text that is not
26
+ // YAML at all is left to the parser, which says why.
27
+ export function unsupported(text) {
28
+ let first = null;
29
+ const found = (offset, code, what) => {
30
+ if (first === null || offset < first.offset)
31
+ first = { offset, code, what };
32
+ };
33
+ // walked with a stack of its own: a deeply nested text must not overflow the call stack here
34
+ const stack = [...new Parser().parse(text)];
35
+ while (stack.length > 0) {
36
+ const v = stack.pop();
37
+ if (Array.isArray(v)) {
38
+ for (const x of v)
39
+ if (x !== null && typeof x === 'object')
40
+ stack.push(x);
41
+ continue;
42
+ }
43
+ if (v === null || typeof v !== 'object')
44
+ continue;
45
+ const t = v;
46
+ const offset = typeof t.offset === 'number' ? t.offset : 0;
47
+ const prop = typeof t.type === 'string' ? PROPS[t.type] : undefined;
48
+ if (prop !== undefined)
49
+ found(offset, prop[0], `${prop[1]} (${String(t.source)}): ${prop[2]}`);
50
+ const key = t.key;
51
+ if (key !== null && key !== undefined && typeof key.type === 'string' && COLLECTIONS.has(key.type)) {
52
+ const list = key.type === 'block-seq' || key.start?.source === '[';
53
+ found(typeof key.offset === 'number' ? key.offset : offset, 'NON_STRING_KEY', `a key that is a ${list ? 'list' : 'map'}: name it with a string`);
54
+ }
55
+ for (const x of Object.values(v))
56
+ if (x !== null && typeof x === 'object')
57
+ stack.push(x);
58
+ }
59
+ if (first === null)
60
+ return null;
61
+ const { offset, code, what } = first;
62
+ return { offset, ...lineAndColumn(text, offset), code, message: `unsupported YAML: ${what}; ${WHY}` };
63
+ }
64
+ // the refusal as the error the yaml library throws for a text that is not YAML, so that every reader that already
65
+ // says "cannot be loaded" for one says it for this too, at the same place
66
+ function refusal(u) {
67
+ const err = new YAMLParseError([u.offset, u.offset + 1], u.code, `${u.message} at line ${u.line}, column ${u.column}`);
68
+ err.linePos = [{ line: u.line, col: u.column }];
69
+ return err;
70
+ }
71
+ // the value of a graph file's text: the yaml library's `parse`, once nothing unsupported is found
72
+ export function readYaml(text) {
73
+ const u = unsupported(text);
74
+ if (u !== null)
75
+ throw refusal(u);
76
+ return parse(text);
77
+ }
78
+ // 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
79
+ // start; for a text `readYaml` has read
80
+ export function keyAt(text, path) {
81
+ const lineCounter = new LineCounter();
82
+ const doc = parseDocument(text, { lineCounter, prettyErrors: false });
83
+ const keyOf = (pair) => String(pair.key?.value ?? pair.key);
84
+ let node = doc.contents;
85
+ let at;
86
+ for (const step of path) {
87
+ if (isMap(node)) {
88
+ const pair = node.items.find((p) => keyOf(p) === step);
89
+ if (pair === undefined)
90
+ break;
91
+ at = pair.key?.range?.[0] ?? at;
92
+ node = pair.value;
93
+ }
94
+ else if (isSeq(node)) {
95
+ node = node.items[Number(step)];
96
+ at = node?.range?.[0] ?? at;
97
+ }
98
+ else
99
+ break;
100
+ }
101
+ const { line, col } = lineCounter.linePos(at ?? 0);
102
+ return { line, column: col };
103
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delurio/cli",
3
- "version": "0.5.3",
3
+ "version": "0.6.1",
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",
@@ -15,6 +15,8 @@
15
15
  "./html": { "types": "./dist/html.d.ts", "default": "./dist/html.js" },
16
16
  "./nav": { "types": "./dist/nav.d.ts", "default": "./dist/nav.js" },
17
17
  "./expr": { "types": "./dist/expr.d.ts", "default": "./dist/expr.js" },
18
+ "./spine": { "types": "./dist/spine.d.ts", "default": "./dist/spine.js" },
19
+ "./yaml": { "types": "./dist/yaml.d.ts", "default": "./dist/yaml.js" },
18
20
  "./package.json": "./package.json"
19
21
  },
20
22
  "files": ["dist", "schemas", "SPEC.md", "NOTICE", "CHANGELOG.md"],